| 1 | #include <stdlib.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 |
|
|---|
| 4 | #include <X11/Intrinsic.h>
|
|---|
| 5 | #include <X11/StringDefs.h>
|
|---|
| 6 | #include <X11/IntrinsicP.h>
|
|---|
| 7 | #include <X11/Shell.h>
|
|---|
| 8 | #include <X11/Core.h>
|
|---|
| 9 | #include <X11/CoreP.h>
|
|---|
| 10 |
|
|---|
| 11 | #include <Xm/Xm.h> // A cause des container XmForm
|
|---|
| 12 | #include <Xm/Form.h> // Idem
|
|---|
| 13 |
|
|---|
| 14 | #include "piwdgx.h"
|
|---|
| 15 | #include "picontainerx.h"
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | // #define DEBUG_PIWdgX
|
|---|
| 19 |
|
|---|
| 20 | // Quelques variables statiques globales, Connection Display, Top Widget Xt, AppContext Xt ...
|
|---|
| 21 | // et leurs fonctions d'acces
|
|---|
| 22 | static SysDWdg top = NULL;
|
|---|
| 23 | static Display * dpy = NULL;
|
|---|
| 24 | // static char appname[64];
|
|---|
| 25 | static char appclass[64];
|
|---|
| 26 | static XtAppContext appctx;
|
|---|
| 27 | static int appSzX = 10;
|
|---|
| 28 | static int appSzY = 10;
|
|---|
| 29 | static XFontStruct * stdfnt = NULL;
|
|---|
| 30 |
|
|---|
| 31 | /* Nouvelle-Fonction */
|
|---|
| 32 | XtAppContext* PIXtAppCtx(int& szx, int& szy)
|
|---|
| 33 | {
|
|---|
| 34 | szx = appSzX; szy = appSzY;
|
|---|
| 35 | return(&appctx);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | /* Nouvelle-Fonction */
|
|---|
| 39 | SysDWdg PIXtTopWdg()
|
|---|
| 40 | {
|
|---|
| 41 | return (top);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | /* Nouvelle-Fonction */
|
|---|
| 45 | Display * PIXDisplay()
|
|---|
| 46 | {
|
|---|
| 47 | return(dpy);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | /* Nouvelle-Fonction */
|
|---|
| 51 | void PIBeep()
|
|---|
| 52 | {
|
|---|
| 53 | XBell(dpy, 0);
|
|---|
| 54 | return;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /* Nouvelle-Fonction */
|
|---|
| 58 | int CStrFrXmStr(XmString xms, char* buff, int nmx)
|
|---|
| 59 | /* Pour recuperer le contenu d'un string Motif */
|
|---|
| 60 | {
|
|---|
| 61 | int n,l,m;
|
|---|
| 62 | XmStringContext cntx;
|
|---|
| 63 | char *txs;
|
|---|
| 64 | XmStringDirection dir;
|
|---|
| 65 | XmStringCharSet cset;
|
|---|
| 66 | Boolean sep;
|
|---|
| 67 |
|
|---|
| 68 | if (nmx < 2) return(0);
|
|---|
| 69 | n = 0; m = nmx-1; buff[0] = buff[m] = '\0';
|
|---|
| 70 | XmStringInitContext (&cntx, xms);
|
|---|
| 71 | while (m > 0)
|
|---|
| 72 | {
|
|---|
| 73 | if (XmStringGetNextSegment( cntx, &txs, &cset, &dir, &sep) )
|
|---|
| 74 | {
|
|---|
| 75 | l = strlen(txs);
|
|---|
| 76 | if (m < l) txs[m] = '\0';
|
|---|
| 77 | strcpy(buff+n, txs);
|
|---|
| 78 | n += l; m -= l;
|
|---|
| 79 | if (sep) m = -2;
|
|---|
| 80 | XtFree(txs);
|
|---|
| 81 | }
|
|---|
| 82 | else m = -1;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | return(n);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | /* --Methode-- */
|
|---|
| 90 | PIWdgX::PIWdgX(int narg, char *arg[])
|
|---|
| 91 | :PIWdgGen(NULL, "PITopLevel")
|
|---|
| 92 | {
|
|---|
| 93 | if (top == NULL) InitXt(narg, arg);
|
|---|
| 94 | sdw = top;
|
|---|
| 95 | wmis = k_wmi_appshell;
|
|---|
| 96 | stmng = false;
|
|---|
| 97 | #ifdef DEBUG_PIWdgX
|
|---|
| 98 | printf("Debug_PIWdgX::PIWdgX(int , char * []) this=%lx top=%lx \n", (long)this, (long)sdw);
|
|---|
| 99 | #endif
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | /* --Methode-- */
|
|---|
| 105 | PIWdgX::PIWdgX(PIContainerGen *par, char *nom,
|
|---|
| 106 | int sx, int sy, int px, int py)
|
|---|
| 107 | :PIWdgGen(par, nom, sx, sy, px, py)
|
|---|
| 108 | {
|
|---|
| 109 | sdw = NULL;
|
|---|
| 110 | wmis = k_wmi_unknown;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | /* --Methode-- */
|
|---|
| 114 | int PIWdgX::CreateXtWdg(char *nom, SysDWdgClass wdgcl, SysDWdg pwdg,
|
|---|
| 115 | int sx, int sy, int px, int py)
|
|---|
| 116 | {
|
|---|
| 117 | Arg wargs[5];
|
|---|
| 118 | int n=0;
|
|---|
| 119 |
|
|---|
| 120 | if (pwdg == NULL)
|
|---|
| 121 | {
|
|---|
| 122 | if (parent == NULL)
|
|---|
| 123 | {
|
|---|
| 124 | if (top == NULL) InitXt();
|
|---|
| 125 | pwdg = top;
|
|---|
| 126 | }
|
|---|
| 127 | // else pwdg = ((PIContainerX *)parent)->sdw;
|
|---|
| 128 | else pwdg = ((PIWdgX *)parent)->sdw;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | n=0;
|
|---|
| 132 | if ((sx >= 0) && (sy >= 0))
|
|---|
| 133 | {
|
|---|
| 134 | XtSetArg(wargs[n],XtNwidth,sx); n++;
|
|---|
| 135 | XtSetArg(wargs[n],XtNheight,sy); n++;
|
|---|
| 136 | }
|
|---|
| 137 | XtSetArg(wargs[n],XtNx,px); n++;
|
|---|
| 138 | XtSetArg(wargs[n],XtNy,py); n++;
|
|---|
| 139 |
|
|---|
| 140 | if (wdgcl == NULL) wdgcl = coreWidgetClass;
|
|---|
| 141 |
|
|---|
| 142 | if ( (wdgcl == topLevelShellWidgetClass) ||
|
|---|
| 143 | (wdgcl == transientShellWidgetClass) ||
|
|---|
| 144 | (wdgcl == overrideShellWidgetClass) )
|
|---|
| 145 | {
|
|---|
| 146 | sdw = XtCreatePopupShell(nom, wdgcl, pwdg, wargs, n);
|
|---|
| 147 | }
|
|---|
| 148 | else
|
|---|
| 149 | {
|
|---|
| 150 | sdw = XtCreateWidget(nom, wdgcl, pwdg, wargs, n);
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | if (wdgcl == topLevelShellWidgetClass) wmis = k_wmi_toplevel;
|
|---|
| 154 | else if (wdgcl == transientShellWidgetClass) wmis = k_wmi_transient;
|
|---|
| 155 | else if (wdgcl == overrideShellWidgetClass) wmis = k_wmi_override;
|
|---|
| 156 | else wmis = k_wmi_normal ;
|
|---|
| 157 |
|
|---|
| 158 | stmng = false;
|
|---|
| 159 | #ifdef DEBUG_PIWdgX
|
|---|
| 160 | printf("Debug_PIWdgX::CreateXtWdg(%s) this=%lx sdw=%lx pere=%lx wmis=%d\n", nom,
|
|---|
| 161 | (long)this, (long)sdw, (long)pwdg, wmis);
|
|---|
| 162 | #endif
|
|---|
| 163 |
|
|---|
| 164 | SetBinding(PIBK_free, PIBK_free, PIBK_free, PIBK_free);
|
|---|
| 165 | return(0);
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 | /* --Methode-- */
|
|---|
| 170 | PIWdgX::~PIWdgX()
|
|---|
| 171 | {
|
|---|
| 172 | #ifdef DEBUG_PIWdgX
|
|---|
| 173 | printf("Debug_PIWdgX::~PIWdgX() %lx %lx \n", (long)this, (long)sdw);
|
|---|
| 174 | #endif
|
|---|
| 175 | if (!sdw) XtDestroyWidget(sdw);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | /* --Methode-- */
|
|---|
| 180 | void PIWdgX::FinishCreate()
|
|---|
| 181 | {
|
|---|
| 182 | #ifdef DEBUG_PIWdgX
|
|---|
| 183 | printf("Debug_PIWdgX::FinishCreate() ne fait rien ! \n");
|
|---|
| 184 | #endif
|
|---|
| 185 | return;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | /* --Methode-- */
|
|---|
| 190 | void PIWdgX::Manage()
|
|---|
| 191 | {
|
|---|
| 192 | #ifdef DEBUG_PIWdgX
|
|---|
| 193 | printf("Debug_PIWdgX::Manage this=%lx sdw=%lx \n", (long)this, (long)sdw);
|
|---|
| 194 | #endif
|
|---|
| 195 | if (!sdw) return;
|
|---|
| 196 | if (wmis != k_wmi_appshell) XtManageChild(sdw);
|
|---|
| 197 | else if (!XtIsRealized(sdw)) XtRealizeWidget(sdw);
|
|---|
| 198 | stmng = true;
|
|---|
| 199 | return;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | /* --Methode-- */
|
|---|
| 203 | void PIWdgX::UnManage()
|
|---|
| 204 | {
|
|---|
| 205 | #ifdef DEBUG_PIWdgX
|
|---|
| 206 | printf("Debug_PIWdgX::UnManage this=%lx sdw=%lx \n", (long)this, (long)sdw);
|
|---|
| 207 | #endif
|
|---|
| 208 | if (!sdw) return;
|
|---|
| 209 | if (wmis != k_wmi_appshell)
|
|---|
| 210 | XtUnmanageChild(sdw);
|
|---|
| 211 | stmng = false;
|
|---|
| 212 | return;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | /* --Methode-- */
|
|---|
| 216 | bool PIWdgX::IfManaged()
|
|---|
| 217 | {
|
|---|
| 218 | return(stmng);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | /* --Methode-- */
|
|---|
| 222 | bool PIWdgX::IsVisible()
|
|---|
| 223 | {
|
|---|
| 224 | if ( (XtIsRealized(XtWdg())) &&
|
|---|
| 225 | ( (this->XtWdg())->core.visible) ) return(true);
|
|---|
| 226 | else return(false);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /* --Methode-- */
|
|---|
| 230 | void PIWdgX::SetSensitive()
|
|---|
| 231 | {
|
|---|
| 232 | XtSetSensitive(XtWdg(), TRUE);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | /* --Methode-- */
|
|---|
| 236 | void PIWdgX::SetUnSensitive()
|
|---|
| 237 | {
|
|---|
| 238 | XtSetSensitive(XtWdg(), FALSE);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | /* --Methode-- */
|
|---|
| 242 | bool PIWdgX::IfSensitive()
|
|---|
| 243 | {
|
|---|
| 244 | if (XtIsSensitive(XtWdg()) == TRUE) return(true);
|
|---|
| 245 | else return(false);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | /* --Methode-- */
|
|---|
| 249 | void PIWdgX::SetSize(int sx, int sy)
|
|---|
| 250 | {
|
|---|
| 251 | #ifdef DEBUG_PIWdgX
|
|---|
| 252 | printf("Debug_PIWdgX::SetSize this=%lx sdw=%lx \n", (long)this, (long)sdw);
|
|---|
| 253 | #endif
|
|---|
| 254 |
|
|---|
| 255 | if (!sdw) return;
|
|---|
| 256 | /*
|
|---|
| 257 | Arg wargs[2];
|
|---|
| 258 | XtSetArg(wargs[0],XtNwidth,sx);
|
|---|
| 259 | XtSetArg(wargs[1],XtNheight,sy);
|
|---|
| 260 | XtSetValues(this->sdw, wargs, 2);
|
|---|
| 261 | */
|
|---|
| 262 | XtResizeWidget(sdw, sx, sy, BorderWidth());
|
|---|
| 263 |
|
|---|
| 264 | return;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | /* --Methode-- */
|
|---|
| 268 | void PIWdgX::SetPos(int px, int py)
|
|---|
| 269 | {
|
|---|
| 270 | if (!sdw) return;
|
|---|
| 271 | /*
|
|---|
| 272 | Arg wargs[2];
|
|---|
| 273 | XtSetArg(wargs[0],XtNx,px);
|
|---|
| 274 | XtSetArg(wargs[1],XtNy,py);
|
|---|
| 275 | XtSetValues(this->sdw, wargs, 2);
|
|---|
| 276 | */
|
|---|
| 277 | XtMoveWidget(sdw, px, py);
|
|---|
| 278 |
|
|---|
| 279 | return;
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | /* --Methode-- */
|
|---|
| 283 | void PIWdgX::SetBinding(PIBindingKind left, PIBindingKind top,
|
|---|
| 284 | PIBindingKind right, PIBindingKind bottom)
|
|---|
| 285 | {
|
|---|
| 286 | Arg wargs[9];
|
|---|
| 287 | int n=0;
|
|---|
| 288 | if (!sdw) return;
|
|---|
| 289 | if (!parent) return;
|
|---|
| 290 |
|
|---|
| 291 | int fbase = 1000 ; // Valeur de XmNfractionBase des XmForm ds PIContainerX
|
|---|
| 292 | int frpos = 0;
|
|---|
| 293 | float frac;
|
|---|
| 294 |
|
|---|
| 295 | n = 0;
|
|---|
| 296 | XtSetArg(wargs[n],XmNfractionBase, fbase); n++;
|
|---|
| 297 | XtSetValues(parent->XtWdg(), wargs, n);
|
|---|
| 298 |
|
|---|
| 299 | // printf(" DEBUG_SetBinding: C-Sz= %d %d - Sz=%d %d , Pos= %d %d \n", parent->XSize(),
|
|---|
| 300 | // parent->YSize(), XSize(), YSize(), XPos(), YPos());
|
|---|
| 301 | switch (left)
|
|---|
| 302 | {
|
|---|
| 303 | case PIBK_free :
|
|---|
| 304 | XtSetArg(wargs[n],XmNleftAttachment, XmATTACH_NONE); n++;
|
|---|
| 305 | break;
|
|---|
| 306 | case PIBK_fixed :
|
|---|
| 307 | XtSetArg(wargs[n],XmNleftAttachment, XmATTACH_FORM); n++;
|
|---|
| 308 | XtSetArg(wargs[n],XmNleftOffset, XPos() ); n++;
|
|---|
| 309 | break;
|
|---|
| 310 | case PIBK_elastic :
|
|---|
| 311 | XtSetArg(wargs[n],XmNleftAttachment, XmATTACH_POSITION); n++;
|
|---|
| 312 | frac = (float)(XPos())/(float)parent->XSize() ;
|
|---|
| 313 | frpos = frac*fbase;
|
|---|
| 314 | XtSetArg(wargs[n],XmNleftPosition, frpos ); n++;
|
|---|
| 315 | break;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | switch (top)
|
|---|
| 319 | {
|
|---|
| 320 | case PIBK_free :
|
|---|
| 321 | XtSetArg(wargs[n],XmNtopAttachment, XmATTACH_NONE); n++;
|
|---|
| 322 | break;
|
|---|
| 323 | case PIBK_fixed :
|
|---|
| 324 | XtSetArg(wargs[n],XmNtopAttachment, XmATTACH_FORM); n++;
|
|---|
| 325 | XtSetArg(wargs[n],XmNtopOffset, YPos() ); n++;
|
|---|
| 326 | break;
|
|---|
| 327 | case PIBK_elastic :
|
|---|
| 328 | XtSetArg(wargs[n],XmNtopAttachment, XmATTACH_POSITION); n++;
|
|---|
| 329 | frac = (float)(YPos())/(float)parent->YSize() ;
|
|---|
| 330 | frpos = frac*fbase;
|
|---|
| 331 | XtSetArg(wargs[n],XmNtopPosition, frpos ); n++;
|
|---|
| 332 | break;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | switch (right)
|
|---|
| 336 | {
|
|---|
| 337 | case PIBK_free :
|
|---|
| 338 | XtSetArg(wargs[n],XmNrightAttachment, XmATTACH_NONE); n++;
|
|---|
| 339 | break;
|
|---|
| 340 | case PIBK_fixed :
|
|---|
| 341 | XtSetArg(wargs[n],XmNrightAttachment, XmATTACH_FORM); n++;
|
|---|
| 342 | XtSetArg(wargs[n],XmNrightOffset, parent->XSize()-(XSize()+XPos()) ); n++;
|
|---|
| 343 | break;
|
|---|
| 344 | case PIBK_elastic :
|
|---|
| 345 | XtSetArg(wargs[n],XmNrightAttachment, XmATTACH_POSITION); n++;
|
|---|
| 346 | frac = (float)(XPos()+XSize())/(float)parent->XSize() ;
|
|---|
| 347 | frpos = frac*fbase;
|
|---|
| 348 | XtSetArg(wargs[n],XmNrightPosition, frpos ); n++;
|
|---|
| 349 | break;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | switch (bottom)
|
|---|
| 353 | {
|
|---|
| 354 | case PIBK_free :
|
|---|
| 355 | XtSetArg(wargs[n],XmNbottomAttachment, XmATTACH_NONE); n++;
|
|---|
| 356 | break;
|
|---|
| 357 | case PIBK_fixed :
|
|---|
| 358 | XtSetArg(wargs[n],XmNbottomAttachment, XmATTACH_FORM); n++;
|
|---|
| 359 | XtSetArg(wargs[n],XmNbottomOffset, parent->YSize()-(YSize()+YPos()) ); n++;
|
|---|
| 360 | break;
|
|---|
| 361 | case PIBK_elastic :
|
|---|
| 362 | XtSetArg(wargs[n],XmNbottomAttachment, XmATTACH_POSITION); n++;
|
|---|
| 363 | frac = (float)(YPos()+YSize())/(float)parent->YSize() ;
|
|---|
| 364 | frpos = frac*fbase;
|
|---|
| 365 | XtSetArg(wargs[n],XmNbottomPosition, frpos ); n++;
|
|---|
| 366 | break;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | XtSetValues(this->sdw, wargs, n);
|
|---|
| 370 |
|
|---|
| 371 | // printf(" Out_SetBinding: C-Sz= %d %d - Sz=%d %d , Pos= %d %d \n", parent->XSize(),
|
|---|
| 372 | // parent->YSize(), XSize(), YSize(), XPos(), YPos());
|
|---|
| 373 |
|
|---|
| 374 | return;
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 | /* --Methode-- */
|
|---|
| 379 | void PIWdgX::SetBorderWidth(int bw)
|
|---|
| 380 | {
|
|---|
| 381 | if (!sdw) return;
|
|---|
| 382 |
|
|---|
| 383 | Arg wargs[2];
|
|---|
| 384 | int n=0;
|
|---|
| 385 |
|
|---|
| 386 | XtSetArg(wargs[n],XtNborderWidth,bw); n++;
|
|---|
| 387 | XtSetValues(this->sdw, wargs, n);
|
|---|
| 388 | return;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | /* --Methode-- */
|
|---|
| 392 | void PIWdgX::SetLabel(string const& lab)
|
|---|
| 393 | {
|
|---|
| 394 | XmString xmstr;
|
|---|
| 395 | xmstr = XmStringLtoRCreate((char *)lab.c_str(), XmSTRING_DEFAULT_CHARSET);
|
|---|
| 396 | int n=0;
|
|---|
| 397 | Arg warg[2];
|
|---|
| 398 |
|
|---|
| 399 | XtSetArg(warg[n], XmNlabelString, xmstr); n++;
|
|---|
| 400 | XtSetValues(XtWdg(), warg, n);
|
|---|
| 401 | XmStringFree(xmstr);
|
|---|
| 402 | return;
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 | /* --Methode-- */
|
|---|
| 408 | int PIWdgX::XSize()
|
|---|
| 409 | {
|
|---|
| 410 | if (!sdw) return(-1);
|
|---|
| 411 | else return((int)this->sdw->core.width);
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | /* --Methode-- */
|
|---|
| 415 | int PIWdgX::YSize()
|
|---|
| 416 | {
|
|---|
| 417 | if (!sdw) return(-1);
|
|---|
| 418 | else return((int)this->sdw->core.height);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | /* --Methode-- */
|
|---|
| 422 | int PIWdgX::XPos()
|
|---|
| 423 | {
|
|---|
| 424 | if (!sdw) return(-1);
|
|---|
| 425 | else return((int)this->sdw->core.x);
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | /* --Methode-- */
|
|---|
| 429 | int PIWdgX::YPos()
|
|---|
| 430 | {
|
|---|
| 431 | if (!sdw) return(-1);
|
|---|
| 432 | else return((int)this->sdw->core.y);
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 | /* --Methode-- */
|
|---|
| 437 | int PIWdgX::BorderWidth()
|
|---|
| 438 | {
|
|---|
| 439 | if (!sdw) return(-1);
|
|---|
| 440 | Arg wargs[2];
|
|---|
| 441 | int bw;
|
|---|
| 442 | XtSetArg(wargs[0],XtNborderWidth, &bw);
|
|---|
| 443 | XtGetValues(this->sdw, wargs, 1);
|
|---|
| 444 | return(bw);
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | /* --Methode-- */
|
|---|
| 448 | string PIWdgX::Nom()
|
|---|
| 449 | {
|
|---|
| 450 | return(XtName(this->sdw));
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | /* --Methode-- */
|
|---|
| 454 | void PIWdgX::GetScreenPos(int & spx, int & spy)
|
|---|
| 455 | {
|
|---|
| 456 | PIWdgX * wc;
|
|---|
| 457 | Display *mdsp;
|
|---|
| 458 | Window w, rw, pw, *cw;
|
|---|
| 459 | unsigned int ncw;
|
|---|
| 460 | Status st;
|
|---|
| 461 | int x,y;
|
|---|
| 462 | unsigned int bw, l, h, d;
|
|---|
| 463 |
|
|---|
| 464 | spx = 0; spy = 0;
|
|---|
| 465 | wc = this;
|
|---|
| 466 |
|
|---|
| 467 | while (wc)
|
|---|
| 468 | { spx += wc->XPos();
|
|---|
| 469 | spy += wc->YPos(); wc = (PIWdgX *)wc->Parent();
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | mdsp = XtDisplay(XtWdg());
|
|---|
| 473 | w = XtWindow(XtWdg());
|
|---|
| 474 | ncw = 0;
|
|---|
| 475 | st = XQueryTree(mdsp, w, &rw, &pw, &cw, &ncw);
|
|---|
| 476 | if (st)
|
|---|
| 477 | { XFree(cw);
|
|---|
| 478 | if (pw == rw) return; }
|
|---|
| 479 |
|
|---|
| 480 | while (st && (pw != rw))
|
|---|
| 481 | {
|
|---|
| 482 | w = pw;
|
|---|
| 483 | st = XQueryTree(mdsp, w, &rw, &pw, &cw, &ncw);
|
|---|
| 484 | if (st) XFree(cw);
|
|---|
| 485 | XGetGeometry(mdsp, w, &rw, &x, &y, &l, &h, &bw, &d);
|
|---|
| 486 | spy += y; spx += x;
|
|---|
| 487 | }
|
|---|
| 488 | return;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 | // Ressources X si non definis
|
|---|
| 493 | static String fallback_res[22] = {
|
|---|
| 494 | "PeidaInt*default*background: LightGrey" ,
|
|---|
| 495 | "PeidaInt*background: LightGrey" ,
|
|---|
| 496 | "PeidaInt*bottomShadowColor: Black" ,
|
|---|
| 497 | "PeidaInt*default*bottomShadowColor: Black" ,
|
|---|
| 498 | "PeidaInt*Foreground: Black",
|
|---|
| 499 | "PeidaInt*default*Foreground: Black",
|
|---|
| 500 | "PeidaInt*topShadowColor: White",
|
|---|
| 501 | "PeidaInt*default*topShadowColor: White",
|
|---|
| 502 | "PeidaInt*borderColor: Black",
|
|---|
| 503 | "PeidaInt*XmLabel.borderWidth: 0",
|
|---|
| 504 | "PeidaInt*XmScrollBar*background: LightGrey",
|
|---|
| 505 | "PeidaInt*XmDrawingArea*background: Black",
|
|---|
| 506 | "PeidaInt*XmPushButton*borderWidth: 0",
|
|---|
| 507 | "PeidaInt*XmText*shadowThickness: 2",
|
|---|
| 508 | "PeidaInt*XmText*highlightThickness: 0",
|
|---|
| 509 | "PeidaInt*XmText*marginHeigt: 0",
|
|---|
| 510 | "PeidaInt*XmText*marginWidth: 3",
|
|---|
| 511 | // "PeidaInt*DefMenubar*XtNwidth: 250",
|
|---|
| 512 | // "PeidaInt*DefMenubar*XtNheight: 30",
|
|---|
| 513 | "PeidaInt*fontList: -*-courier-bold-r-normal-*-12-*-*-*-*-*-ISO8859-1",
|
|---|
| 514 | "PeidaInt*default*fontList: -*-courier-bold-r-normal-*-12-*-*-*-*-*-ISO8859-1"
|
|---|
| 515 | "PeidaInt*fontFamilyName: *-courier", // Pas de blanc apres le nom de font
|
|---|
| 516 | "PeidaInt*XmToggleButton*selectColor: Red",
|
|---|
| 517 | ""
|
|---|
| 518 | };
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 | /* --Methode-- */
|
|---|
| 522 | int PIWdgX::InitXt(int narg, char *arg[])
|
|---|
| 523 | {
|
|---|
| 524 | if (top != NULL) return(0);
|
|---|
| 525 | // Initialisation ...
|
|---|
| 526 | int n;
|
|---|
| 527 | char *pc = "PIWdgX";
|
|---|
| 528 | char **ppc;
|
|---|
| 529 | if (narg > 0) { n = narg, ppc = arg; }
|
|---|
| 530 | else { ppc = &pc; n = 1; }
|
|---|
| 531 | // strncpy(appname, ppc[0], 63); appname[63] = '\0';
|
|---|
| 532 | strncpy(appclass,"PeidaInt",63); appclass[63] = '\0';
|
|---|
| 533 | // top = XtAppInitialize(&appctx, appclass, NULL, 0, &n, ppc);
|
|---|
| 534 | top = XtVaAppInitialize(&appctx, appclass, NULL, 0, &n, ppc, fallback_res, NULL);
|
|---|
| 535 | dpy = XtDisplay(top);
|
|---|
| 536 |
|
|---|
| 537 | // On va recuperer la fonte par defaut des composantes Motif
|
|---|
| 538 | XtResource res[] = {
|
|---|
| 539 | { "fontList", "FontList", XtRString, sizeof(String),
|
|---|
| 540 | 0, XtRString, "-*-courier-bold-*-*-*-*-*-*-*-*-*-*-*" }
|
|---|
| 541 | };
|
|---|
| 542 |
|
|---|
| 543 | String fntname;
|
|---|
| 544 | XtGetApplicationResources(top, &fntname, res, XtNumber(res), NULL, 0);
|
|---|
| 545 | // scr = XDefaultScreen(dpy);
|
|---|
| 546 | int count;
|
|---|
| 547 | char **list;
|
|---|
| 548 | char buff[256];
|
|---|
| 549 | strcpy(buff, fntname);
|
|---|
| 550 | list = XListFonts(dpy, buff, 15, &count);
|
|---|
| 551 | XFreeFontNames(list);
|
|---|
| 552 | if (count < 1) strcpy(buff,"-*-*-*-*-*-*-*-*-*-*-*-*-*-*" );
|
|---|
| 553 | stdfnt = XLoadQueryFont(dpy, buff);
|
|---|
| 554 |
|
|---|
| 555 | // On calcule la taille de la chaine CANCEL (6 caracteres)
|
|---|
| 556 | char a[2];
|
|---|
| 557 | XCharStruct ovr;
|
|---|
| 558 | int hd, fa, fd, len; // direction, font-ascent, font-descent len("CANCEL")
|
|---|
| 559 | XTextExtents(stdfnt, a, 0, &hd, &fa, &fd, &ovr);
|
|---|
| 560 | len = XTextWidth(stdfnt, "CANCEL", 6);
|
|---|
| 561 | appSzY = (float)(fa+fd)*1.4+10; // pour les shadow
|
|---|
| 562 | appSzX = (float)len*1.5;
|
|---|
| 563 | // Taille multiple de 5 pixels
|
|---|
| 564 | if ( (appSzX % 5) != 0 ) appSzX = 5*(appSzX/5 + 1);
|
|---|
| 565 | if ( (appSzY % 5) != 0 ) appSzY = 5*(appSzY/5 + 1);
|
|---|
| 566 | if(appSzY < 10) appSzY = 10;
|
|---|
| 567 | if(appSzX < 30) appSzX = 30;
|
|---|
| 568 |
|
|---|
| 569 | // printf("PIWdgX::InitXt(Font=%s- %d %d , %d ) SzX,Y= %d %d \n", buff, fa,fd,len,appSzX, appSzY);
|
|---|
| 570 | return(0);
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | /* .................................................................*/
|
|---|
| 574 | /* ................... Gestion de Copier/Coller ....................*/
|
|---|
| 575 | /* .................................................................*/
|
|---|
| 576 |
|
|---|
| 577 | // Les Call-Backs Xt
|
|---|
| 578 |
|
|---|
| 579 | static Boolean forXt_ConvertSelection(Widget w, Atom* sel, Atom *targ, Atom* typ,
|
|---|
| 580 | XtPointer* value, unsigned long* len, int* format);
|
|---|
| 581 |
|
|---|
| 582 | static void forXt_LoseSelection(Widget w, Atom* sel);
|
|---|
| 583 | static void forXt_DoneSelection(Widget w, Atom* sel, Atom *targ);
|
|---|
| 584 | static void forXt_SelectionValue(Widget w, XtPointer usd, Atom* sel, Atom* typ,
|
|---|
| 585 | XtPointer value, unsigned long* len, int* format );
|
|---|
| 586 |
|
|---|
| 587 | static PIWdgX* curselwdg = NULL; // Le PIWdg qui possede la selection
|
|---|
| 588 | static unsigned int curseltype = PICP_string; // Type de selcetion qu'il peut fournir
|
|---|
| 589 | static unsigned int reqseltype = PICP_string; // Type de selection demande
|
|---|
| 590 | static unsigned int provseltype = PICP_string; // Type de selection fourni
|
|---|
| 591 |
|
|---|
| 592 | /* Nouvelle-Fonction */
|
|---|
| 593 | Boolean forXt_ConvertSelection(Widget w, Atom* sel, Atom *targ, Atom* typ,
|
|---|
| 594 | XtPointer* value, unsigned long* len, int* format)
|
|---|
| 595 | {
|
|---|
| 596 | if (*targ != XA_STRING) return(FALSE);
|
|---|
| 597 | if (!curselwdg) return(FALSE);
|
|---|
| 598 | unsigned int ll = 0;
|
|---|
| 599 | unsigned int styp = reqseltype;
|
|---|
| 600 | *value = curselwdg->ProvideSelection(styp, ll);
|
|---|
| 601 | *len=ll;
|
|---|
| 602 | *typ = XA_STRING;
|
|---|
| 603 | *format = 8;
|
|---|
| 604 | provseltype = (styp != 0) ? styp : PICP_string;
|
|---|
| 605 | return(TRUE);
|
|---|
| 606 | }
|
|---|
| 607 |
|
|---|
| 608 | /* Nouvelle-Fonction */
|
|---|
| 609 | void forXt_LoseSelection(Widget w, Atom* sel)
|
|---|
| 610 | {
|
|---|
| 611 | if (curselwdg) curselwdg->SelectionLost();
|
|---|
| 612 | curselwdg = NULL; curseltype = PICP_string;
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | /* Nouvelle-Fonction */
|
|---|
| 616 | void forXt_DoneSelection(Widget w, Atom* sel, Atom *targ)
|
|---|
| 617 | {
|
|---|
| 618 | if (curselwdg) curselwdg->SelectionTransferEnd();
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | /* Nouvelle-Fonction */
|
|---|
| 622 | void forXt_SelectionValue(Widget w, XtPointer usd, Atom* sel, Atom* typ,
|
|---|
| 623 | XtPointer value, unsigned long* len, int* format )
|
|---|
| 624 | {
|
|---|
| 625 | if ( (value != NULL) && (*len > 0) )
|
|---|
| 626 | ((PIWdgX*)usd)->PasteSelection(provseltype, (void*)value, (*len)) ;
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 | // Gestion de Copier/Coller
|
|---|
| 632 | /* --Methode-- */
|
|---|
| 633 | bool PIWdgX::ClaimSelection(unsigned int typ)
|
|---|
| 634 | // Pour prendre possession du buffer copier/coller
|
|---|
| 635 | {
|
|---|
| 636 | if (XtOwnSelection(XtWdg(), XA_PRIMARY, PIXGetLastEventTime(), forXt_ConvertSelection,
|
|---|
| 637 | forXt_LoseSelection, forXt_DoneSelection) ) {
|
|---|
| 638 | #ifdef DEBUG_PIWdgX
|
|---|
| 639 | printf("PIWdgX::ClaimSelection(%d) - OK (Wdg= %lx)\n", typ, (unsigned long)this);
|
|---|
| 640 | #endif
|
|---|
| 641 | curselwdg = this;
|
|---|
| 642 | curseltype = (typ != 0) ? typ : PICP_string;
|
|---|
| 643 | return (true);
|
|---|
| 644 | }
|
|---|
| 645 | else {
|
|---|
| 646 | #ifdef DEBUG_PIWdgX
|
|---|
| 647 | printf("PIWdgX::ClaimSelection() - Probleme (Wdg= %lx)\n", (unsigned long)this);
|
|---|
| 648 | #endif
|
|---|
| 649 | curselwdg = NULL;
|
|---|
| 650 | curseltype = PICP_string;
|
|---|
| 651 | return (false);
|
|---|
| 652 | }
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | /* --Methode-- */
|
|---|
| 656 | void PIWdgX::SelectionLost()
|
|---|
| 657 | // Appele quand le PIWdg perd la possession du buffer copier/coller
|
|---|
| 658 | {
|
|---|
| 659 | return;
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | /* --Methode-- */
|
|---|
| 663 | unsigned int PIWdgX::RequestSelection(unsigned int typ)
|
|---|
| 664 | {
|
|---|
| 665 | // Pour demander le contenu du buffer de copier/coller
|
|---|
| 666 | #ifdef DEBUG_PIWdgX
|
|---|
| 667 | printf("PIWdgX::RequestSelection(%d) (Wdg= %lx - %lx) \n", typ,
|
|---|
| 668 | (unsigned long)this, (unsigned long)curselwdg);
|
|---|
| 669 | #endif
|
|---|
| 670 | reqseltype = (typ != 0) ? typ : PICP_string;
|
|---|
| 671 | XtGetSelectionValue(XtWdg(), XA_PRIMARY, XA_STRING, forXt_SelectionValue,
|
|---|
| 672 | (XtPointer)this, PIXGetLastEventTime());
|
|---|
| 673 | return(reqseltype);
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | static char* rs = NULL;
|
|---|
| 677 |
|
|---|
| 678 | /* --Methode-- */
|
|---|
| 679 | void* PIWdgX::ProvideSelection(unsigned int& typ, unsigned int& len)
|
|---|
| 680 | // Le widget doit fournier une l zone memoire contenant la selection
|
|---|
| 681 | // en un type donne
|
|---|
| 682 | // Renvoie le pointeur de cette zone, sa taille et son typ
|
|---|
| 683 | {
|
|---|
| 684 | rs = new char[128];
|
|---|
| 685 | sprintf(rs, "Test-of-PIWdgX::ProvideSelection(%d)- %lx", typ,(long)rs);
|
|---|
| 686 | len = strlen(rs);
|
|---|
| 687 | return(rs);
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 | /* --Methode-- */
|
|---|
| 691 | void PIWdgX::SelectionTransferEnd()
|
|---|
| 692 | {
|
|---|
| 693 | delete[] rs;
|
|---|
| 694 | }
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 | /* --Methode-- */
|
|---|
| 698 | void PIWdgX::PasteSelection(unsigned int typ, void *buff, unsigned int l)
|
|---|
| 699 | {
|
|---|
| 700 | // Methode appele apres que le widget ait fait RequestSelection
|
|---|
| 701 | // Le typ de donnees fourni ainsi que les donnees et leur taille
|
|---|
| 702 | // sont en argument
|
|---|
| 703 | #ifdef DEBUG_PIWdgX
|
|---|
| 704 | char* mbuff = new char[l+1];
|
|---|
| 705 | strncpy(mbuff, (char *)buff, l);
|
|---|
| 706 | mbuff[l] = '\0';
|
|---|
| 707 | printf("PIWdgX::PasteSelection(%d, %lx, %d) [%s] \n", typ, (long)buff, l, mbuff);
|
|---|
| 708 | delete[] mbuff;
|
|---|
| 709 | #endif
|
|---|
| 710 | return;
|
|---|
| 711 | }
|
|---|