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

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

Portage sur SGI IRIX64 , Reza 11/10/99

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