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

Last change on this file since 365 was 365, checked in by ercodmgr, 26 years ago

Pb avec Fenetre ppale sur Sun - Reza 9/8/99

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