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

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

Modifs pour les drawers - Utilisation des Drawers ds PIImage,
Introduction des fichiers pour le dessin 3D Reza 18/06/98

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