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

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

1/ Adaptation pour modif Eric PIGraphicGen - PIGraphicWin
2/ Utilisation XtApp...() et determination de la taille preferee
des composantes graphiques Reza 12/03/98

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