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

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

Tentative de capture de CloseWindow sur la fenetre principale - Reza 31/10/2000

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