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

Last change on this file since 1074 was 1074, checked in by ercodmgr, 25 years ago

Pb de XmForm fenetre principale sur Linux-PPC , Reza 17/7/2000

File size: 8.0 KB
RevLine 
[2]1#include <stdio.h>
[18]2#include <X11/cursorfont.h>
[1074]3#include <X11/IntrinsicP.h>
[2]4#include "piapplx.h"
5#include "picontainerx.h"
6
[365]7// $CHECK$ - Reza Aout 99
8// Il y a un probleme sur la gestion de la taille de la fenetre principale
9// SetBinding(elastic) ne marche correctement pas sur la fenetre principale
10// et Des SetSize intempestive peuvent generer des comportements bizarres !
[2]11
[78]12// Pour rediriger stdout
13#include <unistd.h>
14#include <fcntl.h>
[2]15
[135]16#include <iostream.h>
[78]17
[135]18
[78]19// #define DEBUG_APPLX
20
[18]21static Cursor a_curs[3];
22static bool a_fgcur=false;
23
[60]24// Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
25void SetTopWdgForMenuX(SysDWdg mtw);
26
[111]27static PIApplication* cur_piapp = NULL;
28PIApplication* PIApplicationGetApp() { return cur_piapp; }
29
[126]30
[132]31// Classe de container special pour top-container de Application X
[126]32
[132]33class PITopContAppX : public PIContainer {
34public :
[457]35 PITopContAppX(PIContainer *par, char *nom, PIWdg* topw,
[132]36 int sx=10, int sy=10, int px=0, int py=0);
37 virtual ~PITopContAppX();
38
39 virtual void SetSize(int sx, int sy);
40 virtual void SetPos(int px, int py);
[457]41
42PIWdg* mTopWdg;
[132]43};
44
[1074]45
[2]46/* --Methode-- */
[457]47PITopContAppX::PITopContAppX(PIContainer *par, char *nom, PIWdg* topw, int sx, int sy, int px, int py)
[365]48 : PIContainer(par, nom, (sx>10)?sx:10, (sy>10)?sy:10, px, py)
[132]49{
[457]50 mTopWdg = topw;
[365]51 SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
[132]52}
53
54/* --Methode-- */
55PITopContAppX::~PITopContAppX()
56{
57}
58
59/* --Methode-- */
60void PITopContAppX::SetSize(int sx, int sy)
61{
[365]62if ((sx <10) || (sy < 10) ) return;
[1074]63
64int px = XPos();
65int py = YPos();
[458]66#if !defined(SunOS)
67// Probleme sur Sun - Reza 10/99
[1074]68mTopWdg->SetSize(sx+px, sy+py);
[458]69#endif
[1074]70
71XtConfigureWidget(Parent()->XtWdg(), 0, 0, sx+px, sy+py, 0);
72
73// Parent()->SetPos(0, 0);
74// Parent()->SetSize(sx+px, sy+py);
[365]75// PIContainer::SetSize(sx, sy); Probleme sur Sun - Reza 9/08/99
[1074]76
77XtConfigureWidget(XtWdg(), px, py, sx, sy, 0);
78
79// SetPos(px, py);
80// PIContainer::SetSize(sx, sy);
[132]81}
82
[365]83
[132]84/* --Methode-- */
85void PITopContAppX::SetPos(int px, int py)
86{
87}
88
89/* --Methode-- */
[2]90PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
91: PIApplicationGen()
92{
93int sxt, syt;
94
95#ifdef DEBUG_APPLX
96puts("PIApplicationX::PIApplicationX()_info : App creation");
97#endif
98mStop = true;
[365]99
100
[2]101topwdg = new PIWdgX(narg, arg);
102
[365]103int msx,msy;
104PrefCompSz(msx, msy);
105msy+=5;
106topwdg->SetSize(sx, sy+msy);
107//DBG printf("PIApplicationX-DBG:: Size=%d %d \n", topwdg->XSize(), topwdg->YSize());
108
[2]109intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
[365]110 sx, sy+msy, 0, 0);
[60]111// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
112SetTopWdgForMenuX(intcont->XtWdg());
113
[2]114menubar = new PIMenubar(this, "DefMenubar");
[23]115Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
[2]116sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
[365]117syt = ( sy > 10 ) ? sy : 10;
118// syt += Menubar()->YSize();
119// syt += msy;
120// topwdg->SetSize(sxt, syt);
121// MBCont()->SetSize(sxt, syt);
[132]122if (sx < sxt) sx = sxt;
123if (sy < 10) sy = 10;
[457]124topcont = new PITopContAppX(MBCont(), "TopLevelCont", topwdg,
[132]125 sx, sy, 0, msy);
[163]126MBCont()->Show();
[365]127//DBG printf("PIApplicationX-DBG2:: MBContSize=%d %d \n", MBCont()->XSize(), MBCont()->YSize());
[2]128
[1074]129
[365]130topcont->Show();
[18]131
[365]132
[18]133if (!a_fgcur)
134 {
135 Display *mdsp;
136 mdsp = XtDisplay (topwdg->XtWdg());
137 a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
138 a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
139 a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
140 }
141
[365]142topwdg->Manage();
[111]143cur_piapp = this;
[18]144mState = -1;
145SetReady();
[2]146}
147
148/* --Methode-- */
149PIApplicationX::~PIApplicationX()
150{
151#ifdef DEBUG_APPLX
152puts("PIApplicationX::~PIApplicationX()_info : App delete");
153#endif
[18]154Display *mdsp;
155mdsp = XtDisplay (topwdg->XtWdg());
[52]156topwdg->UnManage();
[6]157delete menubar;
158if (topcont != MBCont()) delete topcont;
159delete intcont;
[2]160delete topwdg;
[18]161XtCloseDisplay(mdsp);
[111]162cur_piapp = NULL;
[18]163return;
[2]164}
165
166/* --Methode-- */
167void PIApplicationX::Run()
168{
169XEvent evt;
170#ifdef DEBUG_APPLX
171puts("PIApplicationX::Run()_info : App Run ");
172#endif
173
174
[114]175int szx, szy, szf;
176XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
[90]177
[110]178// Pour appeler FinishCreate() des objets dans la fenetre principale
[365]179if (mStop) { // C'est la premiere fois
[1074]180 topcont->SetSize(topcont->XSize(), topcont->YSize());
181 // topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
[365]182 MBCont()->FinishCreate();
183 }
[141]184else mStop = true; // On rerentre apres un stop
[2]185while (mStop)
186 {
[90]187 XtAppNextEvent(*appctx, &evt);
[2]188 XtDispatchEvent(&evt);
189 }
190return;
191}
[18]192
193
194/* --Methode-- */
195void PIApplicationX::SetReady()
196{
[138]197Display * mdsp = XtDisplay (topwdg->XtWdg());
[18]198if (mState != kReadyState)
199 {
200 mState = kReadyState;
[106]201 Menubar()->SetSensitive();
[18]202 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
203 }
[138]204XFlush(mdsp);
[18]205}
206
207/* --Methode-- */
208void PIApplicationX::SetBusy()
209{
[138]210Display * mdsp = XtDisplay (topwdg->XtWdg());
[18]211if (mState != kBusyState)
212 {
213 mState = kBusyState;
[106]214 Menubar()->SetSensitive();
[18]215// if ( XtIsRealized(topwdg->XtWdg()) )
216 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
217 }
[138]218XFlush(mdsp);
[18]219}
220
221/* --Methode-- */
222void PIApplicationX::SetBlocked()
223{
[138]224Display * mdsp = XtDisplay (topwdg->XtWdg());
[18]225if (mState != kBlockedState)
226 {
227 mState = kBlockedState;
[106]228 Menubar()->SetUnSensitive();
[18]229 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
230 }
[138]231XFlush(mdsp);
232return;
[18]233}
[75]234
235
236/* --Methode-- */
[90]237void PIApplicationX::PrefCompSz(int& szx, int& szy)
[75]238{
[114]239int szf;
240PIXtAppCtx(szx, szy, szf);
[90]241return;
[75]242}
243
[92]244/* --Methode-- */
245void PIApplicationX::ScreenSz(int& szx, int& szy)
246{
247Display * dsp = PIXDisplay();
248szx = DisplayWidth(dsp, DefaultScreen(dsp));
249szy = DisplayHeight(dsp, DefaultScreen(dsp));
250}
[75]251
[92]252
253
[78]254/* Call-Back - Fonction privee de ce fichier */
[81]255static void redirectstream_callback(XtPointer, int *, XtInputId*);
[78]256
[81]257static PIConsole* consstream[2] = {NULL, NULL};
258static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
259static int streamno[2] = {0,1};
[135]260static XtInputId inputid[2];
261static int origfiledes[2]={-1, -1}; // descripteurs de fichiers de depart
[78]262
[81]263static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
[78]264{
265char buff[128];
266int nr;
[81]267
268int idx = *((int*)cld);
269if (idx != 1) idx = 0;
[135]270if (!consstream[idx]) return;
[78]271while ( (nr=read(*fd, buff, 127)) > 0 ) {
[81]272 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
[78]273 }
[81]274consstream[idx]->Refresh();
[78]275}
276
277/* --Methode-- */
[81]278void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
[78]279{
[135]280if ( origfiledes[0]<0 ) origfiledes[0] = fcntl(1, F_DUPFD);
281if ( cons == consstream[0]) return;
282if ( (consstream[0]) && (cons) ) { consstream[0] = cons; streamva[0] = va; return; }
283else if (!cons) {
284 consstream[0] = NULL;
285 XtRemoveInput(inputid[0]);
286 dup2(origfiledes[0], 1);
287 return;
288 }
[78]289
[81]290consstream[0] = cons; streamva[0] = va;
291
[78]292int p[2];
293pipe(p);
[90]294// Redirection de stdout (fid=1) :
[78]295close(1);
296dup(p[1]);
297close(p[1]);
298fcntl(p[0], F_SETFL, O_NONBLOCK);
[135]299
[365]300#if (!defined(__GNUG__) && !defined(HPUX))
[85]301setlinebuf(stdout);
[163]302#endif
[135]303ios::sync_with_stdio();
[78]304
[114]305int szx, szy, szf;
306XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
[135]307inputid[0] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
308 redirectstream_callback, (XtPointer) streamno);
[78]309}
[81]310
311/* --Methode-- */
312void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
313{
[135]314if ( origfiledes[1]<0 ) origfiledes[1] = fcntl(2, F_DUPFD);
315if ( cons == consstream[1]) return;
316if ( (consstream[1]) && (cons) ) { consstream[1] = cons; streamva[1] = va; return; }
317else if (!cons) {
318 consstream[1] = NULL;
319 XtRemoveInput(inputid[1]);
320 dup2(origfiledes[1], 2);
321 return;
322 }
[81]323
324consstream[1] = cons; streamva[1] = va;
325
326int p[2];
327pipe(p);
[135]328// Redirection de stderr (fid=2) :
[81]329close(2);
330dup(p[1]);
331close(p[1]);
332fcntl(p[0], F_SETFL, O_NONBLOCK);
[135]333
[365]334#if (!defined(__GNUG__) && !defined(HPUX))
[85]335setlinebuf(stderr);
[163]336#endif
[135]337ios::sync_with_stdio();
[81]338
[114]339int szx, szy, szf;
340XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
[135]341inputid[1] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
342 redirectstream_callback, (XtPointer) (streamno+1));
[81]343}
344
Note: See TracBrowser for help on using the repository browser.