source: Sophya/trunk/SophyaPI/PI/piapplx.cc@ 114

Last change on this file since 114 was 114, checked in by ansari, 27 years ago

Meilleure gestion des tailles de fontes X Reza 03/07/98

File size: 5.4 KB
Line 
1#include <stdio.h>
2#include <X11/cursorfont.h>
3#include "piapplx.h"
4#include "picontainerx.h"
5
6
7// Pour rediriger stdout
8#include <unistd.h>
9#include <fcntl.h>
10
11
12// #define DEBUG_APPLX
13
14static Cursor a_curs[3];
15static bool a_fgcur=false;
16
17// Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
18void SetTopWdgForMenuX(SysDWdg mtw);
19
20static PIApplication* cur_piapp = NULL;
21PIApplication* PIApplicationGetApp() { return cur_piapp; }
22
23/* --Methode-- */
24PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
25: PIApplicationGen()
26{
27int sxt, syt;
28
29#ifdef DEBUG_APPLX
30puts("PIApplicationX::PIApplicationX()_info : App creation");
31#endif
32mStop = true;
33topwdg = new PIWdgX(narg, arg);
34
35intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
36 10, 10, 0, 0);
37// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
38SetTopWdgForMenuX(intcont->XtWdg());
39
40menubar = new PIMenubar(this, "DefMenubar");
41Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
42sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
43syt = ( sy > 0 ) ? sy : 0;
44int msx,msy;
45PrefCompSz(msx, msy);
46//syt += Menubar()->YSize();
47syt += msy;
48MBCont()->SetSize(sxt, syt);
49if ( (sx > 0) && (sy > 0) )
50 {
51 topcont = new PIContainerX(MBCont(), "TopLevelCont",
52 sx, sy, 0, msy);
53 topcont->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
54 topcont->Show();
55 }
56else topcont = MBCont();
57
58MBCont()->Show();
59topwdg->Manage();
60
61if (!a_fgcur)
62 {
63 Display *mdsp;
64 mdsp = XtDisplay (topwdg->XtWdg());
65 a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
66 a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
67 a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
68 }
69
70cur_piapp = this;
71mState = -1;
72SetReady();
73}
74
75/* --Methode-- */
76PIApplicationX::~PIApplicationX()
77{
78#ifdef DEBUG_APPLX
79puts("PIApplicationX::~PIApplicationX()_info : App delete");
80#endif
81Display *mdsp;
82mdsp = XtDisplay (topwdg->XtWdg());
83topwdg->UnManage();
84delete menubar;
85if (topcont != MBCont()) delete topcont;
86delete intcont;
87delete topwdg;
88XtCloseDisplay(mdsp);
89cur_piapp = NULL;
90return;
91}
92
93/* --Methode-- */
94void PIApplicationX::Run()
95{
96XEvent evt;
97#ifdef DEBUG_APPLX
98puts("PIApplicationX::Run()_info : App Run ");
99#endif
100
101topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
102
103int szx, szy, szf;
104XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
105
106// Pour appeler FinishCreate() des objets dans la fenetre principale
107MBCont()->FinishCreate();
108while (mStop)
109 {
110 XtAppNextEvent(*appctx, &evt);
111 XtDispatchEvent(&evt);
112 }
113return;
114}
115
116
117/* --Methode-- */
118void PIApplicationX::SetReady()
119{
120if (mState != kReadyState)
121 {
122 Display * mdsp;
123 mState = kReadyState;
124 Menubar()->SetSensitive();
125 mdsp = XtDisplay (topwdg->XtWdg());
126 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
127 XFlush(mdsp);
128 }
129}
130
131/* --Methode-- */
132void PIApplicationX::SetBusy()
133{
134if (mState != kBusyState)
135 {
136 Display * mdsp;
137 mState = kBusyState;
138 Menubar()->SetSensitive();
139 mdsp = XtDisplay (topwdg->XtWdg());
140// if ( XtIsRealized(topwdg->XtWdg()) )
141 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
142 XFlush(mdsp);
143 }
144return;
145}
146
147/* --Methode-- */
148void PIApplicationX::SetBlocked()
149{
150if (mState != kBlockedState)
151 {
152 Display * mdsp;
153 mState = kBlockedState;
154 Menubar()->SetUnSensitive();
155 mdsp = XtDisplay (topwdg->XtWdg());
156 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
157 XFlush(mdsp);
158 }
159}
160
161
162/* --Methode-- */
163void PIApplicationX::PrefCompSz(int& szx, int& szy)
164{
165int szf;
166PIXtAppCtx(szx, szy, szf);
167return;
168}
169
170/* --Methode-- */
171void PIApplicationX::ScreenSz(int& szx, int& szy)
172{
173Display * dsp = PIXDisplay();
174szx = DisplayWidth(dsp, DefaultScreen(dsp));
175szy = DisplayHeight(dsp, DefaultScreen(dsp));
176}
177
178
179
180/* Call-Back - Fonction privee de ce fichier */
181static void redirectstream_callback(XtPointer, int *, XtInputId*);
182
183static PIConsole* consstream[2] = {NULL, NULL};
184static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
185static int streamno[2] = {0,1};
186
187static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
188{
189char buff[128];
190int nr;
191
192int idx = *((int*)cld);
193if (idx != 1) idx = 0;
194while ( (nr=read(*fd, buff, 127)) > 0 ) {
195 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
196 }
197consstream[idx]->Refresh();
198}
199
200/* --Methode-- */
201void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
202{
203if (!cons) return;
204
205if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
206consstream[0] = cons; streamva[0] = va;
207
208int p[2];
209pipe(p);
210// Redirection de stdout (fid=1) :
211close(1);
212dup(p[1]);
213close(p[1]);
214fcntl(p[0], F_SETFL, O_NONBLOCK);
215setlinebuf(stdout);
216
217int szx, szy, szf;
218XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
219XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
220}
221
222/* --Methode-- */
223void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
224{
225if (!cons) return;
226
227if (consstream[1]) { consstream[1] = cons; streamva[1] = va; return; }
228consstream[1] = cons; streamva[1] = va;
229
230int p[2];
231pipe(p);
232// Redirection de stderr (fid=0) :
233close(2);
234dup(p[1]);
235close(p[1]);
236fcntl(p[0], F_SETFL, O_NONBLOCK);
237setlinebuf(stderr);
238
239int szx, szy, szf;
240XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
241XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
242}
243
Note: See TracBrowser for help on using the repository browser.