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