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

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

petit nettoyage lie a SunOS/XmForm - Reza 23/8/2000

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