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

Last change on this file since 92 was 92, checked in by ansari, 28 years ago

MAJ doc et fonction PIApplicationScreenSize() Reza 16/03/98

File size: 5.0 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
[2]20/* --Methode-- */
21PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
22: PIApplicationGen()
23{
24int sxt, syt;
25
26#ifdef DEBUG_APPLX
27puts("PIApplicationX::PIApplicationX()_info : App creation");
28#endif
29mStop = true;
30topwdg = new PIWdgX(narg, arg);
31
32intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
33 10, 10, 0, 0);
[60]34// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
35SetTopWdgForMenuX(intcont->XtWdg());
36
[2]37menubar = new PIMenubar(this, "DefMenubar");
[23]38Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
[2]39sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
40syt = ( sy > 0 ) ? sy : 0;
[92]41int msx,msy;
42PrefCompSz(msx, msy);
[7]43//syt += Menubar()->YSize();
[92]44syt += msy;
[2]45MBCont()->SetSize(sxt, syt);
46if ( (sx > 0) && (sy > 0) )
47 {
48 topcont = new PIContainerX(MBCont(), "TopLevelCont",
[92]49 sx, sy, 0, msy);
[23]50 topcont->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
[2]51 topcont->Show();
52 }
53else topcont = MBCont();
54
55MBCont()->Show();
56topwdg->Manage();
[18]57
58if (!a_fgcur)
59 {
60 Display *mdsp;
61 mdsp = XtDisplay (topwdg->XtWdg());
62 a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
63 a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
64 a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
65 }
66
67mState = -1;
68SetReady();
[2]69}
70
71/* --Methode-- */
72PIApplicationX::~PIApplicationX()
73{
74#ifdef DEBUG_APPLX
75puts("PIApplicationX::~PIApplicationX()_info : App delete");
76#endif
[18]77Display *mdsp;
78mdsp = XtDisplay (topwdg->XtWdg());
[52]79topwdg->UnManage();
[6]80delete menubar;
81if (topcont != MBCont()) delete topcont;
82delete intcont;
[2]83delete topwdg;
[18]84XtCloseDisplay(mdsp);
85return;
[2]86}
87
88/* --Methode-- */
89void PIApplicationX::Run()
90{
91XEvent evt;
92#ifdef DEBUG_APPLX
93puts("PIApplicationX::Run()_info : App Run ");
94#endif
95
96topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
97
[90]98int szx, szy;
99XtAppContext * appctx = PIXtAppCtx(szx, szy);
100
[2]101while (mStop)
102 {
[90]103 XtAppNextEvent(*appctx, &evt);
[2]104 XtDispatchEvent(&evt);
105 }
106return;
107}
[18]108
109
110/* --Methode-- */
111void PIApplicationX::SetReady()
112{
113if (mState != kReadyState)
114 {
115 Display * mdsp;
116 mState = kReadyState;
117 mdsp = XtDisplay (topwdg->XtWdg());
118 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
119 XFlush(mdsp);
120 }
121}
122
123/* --Methode-- */
124void PIApplicationX::SetBusy()
125{
126if (mState != kBusyState)
127 {
128 Display * mdsp;
129 mState = kBusyState;
130 mdsp = XtDisplay (topwdg->XtWdg());
131// if ( XtIsRealized(topwdg->XtWdg()) )
132 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
133 XFlush(mdsp);
134 }
135return;
136}
137
138/* --Methode-- */
139void PIApplicationX::SetBlocked()
140{
141if (mState != kBlockedState)
142 {
143 Display * mdsp;
144 mState = kBlockedState;
145 mdsp = XtDisplay (topwdg->XtWdg());
146 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
147 XFlush(mdsp);
148 }
149}
[75]150
151
152/* --Methode-- */
[90]153void PIApplicationX::PrefCompSz(int& szx, int& szy)
[75]154{
[90]155PIXtAppCtx(szx, szy);
156return;
[75]157}
158
[92]159/* --Methode-- */
160void PIApplicationX::ScreenSz(int& szx, int& szy)
161{
162Display * dsp = PIXDisplay();
163szx = DisplayWidth(dsp, DefaultScreen(dsp));
164szy = DisplayHeight(dsp, DefaultScreen(dsp));
165}
[75]166
[92]167
168
[78]169/* Call-Back - Fonction privee de ce fichier */
[81]170static void redirectstream_callback(XtPointer, int *, XtInputId*);
[78]171
[81]172static PIConsole* consstream[2] = {NULL, NULL};
173static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
174static int streamno[2] = {0,1};
[78]175
[81]176static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
[78]177{
178char buff[128];
179int nr;
[81]180
181int idx = *((int*)cld);
182if (idx != 1) idx = 0;
[78]183while ( (nr=read(*fd, buff, 127)) > 0 ) {
[81]184 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
[78]185 }
[81]186consstream[idx]->Refresh();
[78]187}
188
189/* --Methode-- */
[81]190void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
[78]191{
192if (!cons) return;
193
[81]194if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
195consstream[0] = cons; streamva[0] = va;
196
[78]197int p[2];
198pipe(p);
[90]199// Redirection de stdout (fid=1) :
[78]200close(1);
201dup(p[1]);
202close(p[1]);
203fcntl(p[0], F_SETFL, O_NONBLOCK);
[85]204setlinebuf(stdout);
[78]205
[90]206int szx, szy;
207XtAppContext * appctx = PIXtAppCtx(szx, szy);
208XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
[78]209}
[81]210
211/* --Methode-- */
212void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
213{
214if (!cons) return;
215
216if (consstream[1]) { consstream[1] = cons; streamva[1] = va; return; }
217consstream[1] = cons; streamva[1] = va;
218
219int p[2];
220pipe(p);
[90]221// Redirection de stderr (fid=0) :
[81]222close(2);
223dup(p[1]);
224close(p[1]);
225fcntl(p[0], F_SETFL, O_NONBLOCK);
[85]226setlinebuf(stderr);
[81]227
[90]228int szx, szy;
229XtAppContext * appctx = PIXtAppCtx(szx, szy);
230XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
[81]231}
232
Note: See TracBrowser for help on using the repository browser.