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

Last change on this file since 132 was 132, checked in by ercodmgr, 27 years ago

PIStackWindow et PIZoneWindow, appel a AddChild() deplace de PIWdgGen
vers PIWdgX - A faire pour Mac , Reza 10/08/98

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