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

Last change on this file since 126 was 126, checked in by ercodmgr, 27 years ago

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