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
RevLine 
[2]1#include <stdio.h>
[18]2#include <X11/cursorfont.h>
[2]3#include "piapplx.h"
4#include "picontainerx.h"
5
6
[78]7// Pour rediriger stdout
8#include <unistd.h>
9#include <fcntl.h>
[2]10
[78]11
12// #define DEBUG_APPLX
13
[18]14static Cursor a_curs[3];
15static bool a_fgcur=false;
16
[60]17// Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
18void SetTopWdgForMenuX(SysDWdg mtw);
19
[111]20static PIApplication* cur_piapp = NULL;
21PIApplication* PIApplicationGetApp() { return cur_piapp; }
22
[126]23
24
[2]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);
[60]39// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
40SetTopWdgForMenuX(intcont->XtWdg());
41
[2]42menubar = new PIMenubar(this, "DefMenubar");
[23]43Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
[2]44sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
45syt = ( sy > 0 ) ? sy : 0;
[92]46int msx,msy;
47PrefCompSz(msx, msy);
[7]48//syt += Menubar()->YSize();
[92]49syt += msy;
[2]50MBCont()->SetSize(sxt, syt);
51if ( (sx > 0) && (sy > 0) )
52 {
53 topcont = new PIContainerX(MBCont(), "TopLevelCont",
[92]54 sx, sy, 0, msy);
[23]55 topcont->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
[2]56 topcont->Show();
57 }
58else topcont = MBCont();
59
60MBCont()->Show();
61topwdg->Manage();
[18]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
[111]72cur_piapp = this;
[18]73mState = -1;
74SetReady();
[2]75}
76
77/* --Methode-- */
78PIApplicationX::~PIApplicationX()
79{
80#ifdef DEBUG_APPLX
81puts("PIApplicationX::~PIApplicationX()_info : App delete");
82#endif
[18]83Display *mdsp;
84mdsp = XtDisplay (topwdg->XtWdg());
[52]85topwdg->UnManage();
[6]86delete menubar;
87if (topcont != MBCont()) delete topcont;
88delete intcont;
[2]89delete topwdg;
[18]90XtCloseDisplay(mdsp);
[111]91cur_piapp = NULL;
[18]92return;
[2]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
[114]105int szx, szy, szf;
106XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
[90]107
[110]108// Pour appeler FinishCreate() des objets dans la fenetre principale
109MBCont()->FinishCreate();
[2]110while (mStop)
111 {
[90]112 XtAppNextEvent(*appctx, &evt);
[2]113 XtDispatchEvent(&evt);
114 }
115return;
116}
[18]117
118
119/* --Methode-- */
120void PIApplicationX::SetReady()
121{
122if (mState != kReadyState)
123 {
124 Display * mdsp;
125 mState = kReadyState;
[106]126 Menubar()->SetSensitive();
[18]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;
[106]140 Menubar()->SetSensitive();
[18]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;
[106]156 Menubar()->SetUnSensitive();
[18]157 mdsp = XtDisplay (topwdg->XtWdg());
158 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
159 XFlush(mdsp);
160 }
161}
[75]162
163
164/* --Methode-- */
[90]165void PIApplicationX::PrefCompSz(int& szx, int& szy)
[75]166{
[114]167int szf;
168PIXtAppCtx(szx, szy, szf);
[90]169return;
[75]170}
171
[92]172/* --Methode-- */
173void PIApplicationX::ScreenSz(int& szx, int& szy)
174{
175Display * dsp = PIXDisplay();
176szx = DisplayWidth(dsp, DefaultScreen(dsp));
177szy = DisplayHeight(dsp, DefaultScreen(dsp));
178}
[75]179
[92]180
181
[78]182/* Call-Back - Fonction privee de ce fichier */
[81]183static void redirectstream_callback(XtPointer, int *, XtInputId*);
[78]184
[81]185static PIConsole* consstream[2] = {NULL, NULL};
186static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
187static int streamno[2] = {0,1};
[78]188
[81]189static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
[78]190{
191char buff[128];
192int nr;
[81]193
194int idx = *((int*)cld);
195if (idx != 1) idx = 0;
[78]196while ( (nr=read(*fd, buff, 127)) > 0 ) {
[81]197 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
[78]198 }
[81]199consstream[idx]->Refresh();
[78]200}
201
202/* --Methode-- */
[81]203void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
[78]204{
205if (!cons) return;
206
[81]207if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
208consstream[0] = cons; streamva[0] = va;
209
[78]210int p[2];
211pipe(p);
[90]212// Redirection de stdout (fid=1) :
[78]213close(1);
214dup(p[1]);
215close(p[1]);
216fcntl(p[0], F_SETFL, O_NONBLOCK);
[85]217setlinebuf(stdout);
[78]218
[114]219int szx, szy, szf;
220XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
[90]221XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
[78]222}
[81]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);
[90]234// Redirection de stderr (fid=0) :
[81]235close(2);
236dup(p[1]);
237close(p[1]);
238fcntl(p[0], F_SETFL, O_NONBLOCK);
[85]239setlinebuf(stderr);
[81]240
[114]241int szx, szy, szf;
242XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
[90]243XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
[81]244}
245
Note: See TracBrowser for help on using the repository browser.