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

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

Suppression des PIPUMenu et PIPDMenu (Version X11) - A faire pour Mac
Modification des PIOptMenu, en particulier PIOptMenuX Reza 12/06/98

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