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

Last change on this file since 106 was 106, checked in by ansari, 27 years ago

1/ Optimisation LUT et P2DArrAdapter 2/ CheckItem et PullDownMenu comme
elements des Menus, 3/Possibilite de rajouter et de supprimer des Menus
dans le MenuBar
4/ Possibilite de rendre non-sensible (Sensitive/Unsensitive) les PIWdg
5/ Debut de commentaires de pistdwdg Reza 12/05/98

File size: 5.1 KB
Line 
1#include <stdio.h>
2#include <X11/cursorfont.h>
3#include "piapplx.h"
4#include "picontainerx.h"
5
6
7// Pour rediriger stdout
8#include <unistd.h>
9#include <fcntl.h>
10
11
12// #define DEBUG_APPLX
13
14static Cursor a_curs[3];
15static bool a_fgcur=false;
16
17// Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
18void SetTopWdgForMenuX(SysDWdg mtw);
19
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);
34// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
35SetTopWdgForMenuX(intcont->XtWdg());
36
37menubar = new PIMenubar(this, "DefMenubar");
38Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
39sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
40syt = ( sy > 0 ) ? sy : 0;
41int msx,msy;
42PrefCompSz(msx, msy);
43//syt += Menubar()->YSize();
44syt += msy;
45MBCont()->SetSize(sxt, syt);
46if ( (sx > 0) && (sy > 0) )
47 {
48 topcont = new PIContainerX(MBCont(), "TopLevelCont",
49 sx, sy, 0, msy);
50 topcont->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
51 topcont->Show();
52 }
53else topcont = MBCont();
54
55MBCont()->Show();
56topwdg->Manage();
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();
69}
70
71/* --Methode-- */
72PIApplicationX::~PIApplicationX()
73{
74#ifdef DEBUG_APPLX
75puts("PIApplicationX::~PIApplicationX()_info : App delete");
76#endif
77Display *mdsp;
78mdsp = XtDisplay (topwdg->XtWdg());
79topwdg->UnManage();
80delete menubar;
81if (topcont != MBCont()) delete topcont;
82delete intcont;
83delete topwdg;
84XtCloseDisplay(mdsp);
85return;
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
98int szx, szy;
99XtAppContext * appctx = PIXtAppCtx(szx, szy);
100
101while (mStop)
102 {
103 XtAppNextEvent(*appctx, &evt);
104 XtDispatchEvent(&evt);
105 }
106return;
107}
108
109
110/* --Methode-- */
111void PIApplicationX::SetReady()
112{
113if (mState != kReadyState)
114 {
115 Display * mdsp;
116 mState = kReadyState;
117 Menubar()->SetSensitive();
118 mdsp = XtDisplay (topwdg->XtWdg());
119 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
120 XFlush(mdsp);
121 }
122}
123
124/* --Methode-- */
125void PIApplicationX::SetBusy()
126{
127if (mState != kBusyState)
128 {
129 Display * mdsp;
130 mState = kBusyState;
131 Menubar()->SetSensitive();
132 mdsp = XtDisplay (topwdg->XtWdg());
133// if ( XtIsRealized(topwdg->XtWdg()) )
134 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
135 XFlush(mdsp);
136 }
137return;
138}
139
140/* --Methode-- */
141void PIApplicationX::SetBlocked()
142{
143if (mState != kBlockedState)
144 {
145 Display * mdsp;
146 mState = kBlockedState;
147 Menubar()->SetUnSensitive();
148 mdsp = XtDisplay (topwdg->XtWdg());
149 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
150 XFlush(mdsp);
151 }
152}
153
154
155/* --Methode-- */
156void PIApplicationX::PrefCompSz(int& szx, int& szy)
157{
158PIXtAppCtx(szx, szy);
159return;
160}
161
162/* --Methode-- */
163void PIApplicationX::ScreenSz(int& szx, int& szy)
164{
165Display * dsp = PIXDisplay();
166szx = DisplayWidth(dsp, DefaultScreen(dsp));
167szy = DisplayHeight(dsp, DefaultScreen(dsp));
168}
169
170
171
172/* Call-Back - Fonction privee de ce fichier */
173static void redirectstream_callback(XtPointer, int *, XtInputId*);
174
175static PIConsole* consstream[2] = {NULL, NULL};
176static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
177static int streamno[2] = {0,1};
178
179static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
180{
181char buff[128];
182int nr;
183
184int idx = *((int*)cld);
185if (idx != 1) idx = 0;
186while ( (nr=read(*fd, buff, 127)) > 0 ) {
187 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
188 }
189consstream[idx]->Refresh();
190}
191
192/* --Methode-- */
193void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
194{
195if (!cons) return;
196
197if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
198consstream[0] = cons; streamva[0] = va;
199
200int p[2];
201pipe(p);
202// Redirection de stdout (fid=1) :
203close(1);
204dup(p[1]);
205close(p[1]);
206fcntl(p[0], F_SETFL, O_NONBLOCK);
207setlinebuf(stdout);
208
209int szx, szy;
210XtAppContext * appctx = PIXtAppCtx(szx, szy);
211XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
212}
213
214/* --Methode-- */
215void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
216{
217if (!cons) return;
218
219if (consstream[1]) { consstream[1] = cons; streamva[1] = va; return; }
220consstream[1] = cons; streamva[1] = va;
221
222int p[2];
223pipe(p);
224// Redirection de stderr (fid=0) :
225close(2);
226dup(p[1]);
227close(p[1]);
228fcntl(p[0], F_SETFL, O_NONBLOCK);
229setlinebuf(stderr);
230
231int szx, szy;
232XtAppContext * appctx = PIXtAppCtx(szx, szy);
233XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
234}
235
Note: See TracBrowser for help on using the repository browser.