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

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

PIStackWindow et PIZoneWindow, appel a AddChild() deplace de PIWdgGen
vers PIWdgX - A faire pour Mac , Reza 10/08/98

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