Logo ROOT   6.08/07
Reference Guide
TGWin32.cxx
Go to the documentation of this file.
1 // @(#)root/win32gdk:$Id$
2 // Author: Rene Brun, Olivier Couet, Fons Rademakers, Valeri Onuchin, Bertrand Bellenot 27/11/01
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /// \defgroup win32 Win32 backend
13 /// \brief Interface to Windows graphics.
14 /// \ingroup GraphicsBackends
15 
16 /** \class TGWin32
17 \ingroup win32
18 This class is the basic interface to the Win32 graphics system.
19 It is an implementation of the abstract TVirtualX class.
20 
21 This code was initially developed in the context of HIGZ and PAW
22 by Olivier Couet (package X11INT).
23 */
24 
25 #include <ft2build.h>
26 #include FT_FREETYPE_H
27 #include FT_GLYPH_H
28 #include "TGWin32.h"
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include <limits.h>
34 #include <process.h>
35 #include <wchar.h>
36 #include "gdk/gdkkeysyms.h"
37 #include "xatom.h"
38 #include <winuser.h>
39 
40 #include "TROOT.h"
41 #include "TApplication.h"
42 #include "TColor.h"
43 #include "TPoint.h"
44 #include "TMath.h"
45 #include "TStorage.h"
46 #include "TStyle.h"
47 #include "TSystem.h"
48 #include "TGFrame.h"
49 #include "TError.h"
50 #include "TException.h"
51 #include "TClassTable.h"
52 #include "KeySymbols.h"
53 #include "TWinNTSystem.h"
54 #include "TGWin32VirtualXProxy.h"
56 #include "TWin32SplashThread.h"
57 #include "TString.h"
58 #include "TObjString.h"
59 #include "TObjArray.h"
60 #include "TExMap.h"
61 #include "TEnv.h"
62 #include "RStipples.h"
63 #include "TEnv.h"
64 
65 // DND protocol version
66 #define XDND_PROTOCOL_VERSION 5
67 #ifndef IDC_HAND
68 #define IDC_HAND MAKEINTRESOURCE(32649)
69 #endif
70 
71 extern "C" {
72 void gdk_win32_draw_rectangle (GdkDrawable *drawable,
73  GdkGC *gc,
74  gint filled,
75  gint x,
76  gint y,
77  gint width,
78  gint height);
79 void gdk_win32_draw_arc (GdkDrawable *drawable,
80  GdkGC *gc,
81  gint filled,
82  gint x,
83  gint y,
84  gint width,
85  gint height,
86  gint angle1,
87  gint angle2);
88 void gdk_win32_draw_polygon (GdkDrawable *drawable,
89  GdkGC *gc,
90  gint filled,
91  GdkPoint *points,
92  gint npoints);
93 void gdk_win32_draw_text (GdkDrawable *drawable,
94  GdkFont *font,
95  GdkGC *gc,
96  gint x,
97  gint y,
98  const gchar *text,
99  gint text_length);
100 void gdk_win32_draw_points (GdkDrawable *drawable,
101  GdkGC *gc,
102  GdkPoint *points,
103  gint npoints);
104 void gdk_win32_draw_segments (GdkDrawable *drawable,
105  GdkGC *gc,
106  GdkSegment *segs,
107  gint nsegs);
108 void gdk_win32_draw_lines (GdkDrawable *drawable,
109  GdkGC *gc,
110  GdkPoint *points,
111  gint npoints);
112 
113 };
114 
115 //////////// internal classes & structures (very private) ////////////////
116 
117 struct XWindow_t {
118  Int_t open; // 1 if the window is open, 0 if not
119  Int_t double_buffer; // 1 if the double buffer is on, 0 if not
120  Int_t ispixmap; // 1 if pixmap, 0 if not
121  GdkDrawable *drawing; // drawing area, equal to window or buffer
122  GdkDrawable *window; // win32 window
123  GdkDrawable *buffer; // pixmap used for double buffer
124  UInt_t width; // width of the window
125  UInt_t height; // height of the window
126  Int_t clip; // 1 if the clipping is on
127  Int_t xclip; // x coordinate of the clipping rectangle
128  Int_t yclip; // y coordinate of the clipping rectangle
129  UInt_t wclip; // width of the clipping rectangle
130  UInt_t hclip; // height of the clipping rectangle
131  ULong_t *new_colors; // new image colors (after processing)
132  Int_t ncolors; // number of different colors
133 };
134 
135 
136 /////////////////////////////////// globals //////////////////////////////////
138 
139 namespace {
140 /////////////////////////////////// globals //////////////////////////////////
141 
142 GdkAtom gClipboardAtom = GDK_NONE;
143 static XWindow_t *gCws; // gCws: pointer to the current window
144 static XWindow_t *gTws; // gTws: temporary pointer
145 
146 //
147 // gColors[0] : background also used for b/w screen
148 // gColors[1] : foreground also used for b/w screen
149 // gColors[2..kMAXCOL-1]: colors which can be set by SetColor
150 //
151 const Int_t kBIGGEST_RGB_VALUE = 65535;
152 //const Int_t kMAXCOL = 1000;
153 //static struct {
154 // Int_t defined;
155 // GdkColor color;
156 //} gColors[kMAXCOL];
157 
158 //
159 // Primitives Graphic Contexts global for all windows
160 //
161 const int kMAXGC = 7;
162 static GdkGC *gGClist[kMAXGC];
163 static GdkGC *gGCline; // = gGClist[0]; // PolyLines
164 static GdkGC *gGCmark; // = gGClist[1]; // PolyMarker
165 static GdkGC *gGCfill; // = gGClist[2]; // Fill areas
166 static GdkGC *gGCtext; // = gGClist[3]; // Text
167 static GdkGC *gGCinvt; // = gGClist[4]; // Inverse text
168 static GdkGC *gGCdash; // = gGClist[5]; // Dashed lines
169 static GdkGC *gGCpxmp; // = gGClist[6]; // Pixmap management
170 
171 static GdkGC *gGCecho; // Input echo
172 
173 static Int_t gFillHollow; // Flag if fill style is hollow
174 static GdkPixmap *gFillPattern; // Fill pattern
175 
176 //
177 // Text management
178 //
179 static char *gTextFont = "arial.ttf"; // Current font
180 
181 //
182 // Markers
183 //
184 const Int_t kMAXMK = 100;
185 static struct {
186  int type;
187  int n;
188  GdkPoint xy[kMAXMK];
189 } gMarker; // Point list to draw marker
190 
191 //
192 // Keep style values for line GdkGC
193 //
194 static int gLineStyle = GDK_LINE_SOLID;
195 static int gCapStyle = GDK_CAP_BUTT;
196 static int gJoinStyle = GDK_JOIN_MITER;
197 static char gDashList[10];
198 static int gDashLength = 0;
199 static int gDashOffset = 0;
200 static int gDashSize = 0;
201 
202 //
203 // Event masks
204 //
205 static ULong_t gMouseMask =
206  GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK
207  | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK
208  | GDK_KEY_RELEASE_MASK;
209 static ULong_t gKeybdMask =
210  GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_ENTER_NOTIFY_MASK |
211  GDK_LEAVE_NOTIFY_MASK;
212 
213 //
214 // Data to create an invisible cursor
215 //
216 const char null_cursor_bits[] = {
217  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
220 };
221 static GdkCursor *gNullCursor;
222 
223 static bool gdk_initialized = false;
224 
225 //---- MWM Hints stuff
226 
227 struct MWMHintsProperty_t {
228  Handle_t fFlags;
229  Handle_t fFunctions;
230  Handle_t fDecorations;
231  Int_t fInputMode;
232 };
233 
234 //---- hints
235 
236 const ULong_t kMWMHintsFunctions = BIT(0);
237 const ULong_t kMWMHintsDecorations = BIT(1);
238 const ULong_t kMWMHintsInputMode = BIT(2);
239 
242 
243 
244 //---- Key symbol mapping
245 
246 struct KeySymbolMap_t {
247  KeySym fXKeySym;
248  EKeySym fKeySym;
249 };
250 
251 static char *keyCodeToString[] = {
252  "", /* 0x000 */
253  "", /* 0x001, VK_LBUTTON */
254  "", /* 0x002, VK_RBUTTON */
255  "", /* 0x003, VK_CANCEL */
256  "", /* 0x004, VK_MBUTTON */
257  "", /* 0x005 */
258  "", /* 0x006 */
259  "", /* 0x007 */
260  "\015", /* 0x008, VK_BACK */
261  "\t", /* 0x009, VK_TAB */
262  "", /* 0x00A */
263  "", /* 0x00B */
264  "", /* 0x00C, VK_CLEAR */
265  "\r", /* 0x00D, VK_RETURN */
266  "", /* 0x00E */
267  "", /* 0x00F */
268  "", /* 0x010, VK_SHIFT */
269  "", /* 0x011, VK_CONTROL */
270  "", /* 0x012, VK_MENU */
271  "", /* 0x013, VK_PAUSE */
272  "", /* 0x014, VK_CAPITAL */
273  "", /* 0x015, VK_KANA */
274  "", /* 0x016 */
275  "", /* 0x017 */
276  "", /* 0x018 */
277  "", /* 0x019, VK_KANJI */
278  "", /* 0x01A */
279  "", /* 0x01B, VK_ESCAPE */
280  "", /* 0x01C, VK_CONVERT */
281  "", /* 0x01D, VK_NONCONVERT */
282  "", /* 0x01E */
283  "", /* 0x01F */
284  " ", /* 0x020, VK_SPACE */
285  "", /* 0x021, VK_PRIOR */
286  "", /* 0x022, VK_NEXT */
287  "", /* 0x023, VK_END */
288  "", /* 0x024, VK_HOME */
289  "", /* 0x025, VK_LEFT */
290  "", /* 0x026, VK_UP */
291  "", /* 0x027, VK_RIGHT */
292  "", /* 0x028, VK_DOWN */
293  "", /* 0x029, VK_SELECT */
294  "", /* 0x02A, VK_PRINT */
295  "", /* 0x02B, VK_EXECUTE */
296  "", /* 0x02C, VK_SNAPSHOT */
297  "", /* 0x02D, VK_INSERT */
298  "\037", /* 0x02E, VK_DELETE */
299  "", /* 0x02F, VK_HELP */
300 };
301 
302 //---- Mapping table of all non-trivial mappings (the ASCII keys map
303 //---- one to one so are not included)
304 
305 static KeySymbolMap_t gKeyMap[] = {
306  {GDK_Escape, kKey_Escape},
307  {GDK_Tab, kKey_Tab},
308 #ifndef GDK_ISO_Left_Tab
309  {0xFE20, kKey_Backtab},
310 #else
311  {GDK_ISO_Left_Tab, kKey_Backtab},
312 #endif
313  {GDK_BackSpace, kKey_Backspace},
314  {GDK_Return, kKey_Return},
315  {GDK_Insert, kKey_Insert},
316  {GDK_Delete, kKey_Delete},
317  {GDK_Clear, kKey_Delete},
318  {GDK_Pause, kKey_Pause},
319  {GDK_Print, kKey_Print},
320  {0x1005FF60, kKey_SysReq}, // hardcoded Sun SysReq
321  {0x1007ff00, kKey_SysReq}, // hardcoded X386 SysReq
322  {GDK_Home, kKey_Home}, // cursor movement
323  {GDK_End, kKey_End},
324  {GDK_Left, kKey_Left},
325  {GDK_Up, kKey_Up},
326  {GDK_Right, kKey_Right},
327  {GDK_Down, kKey_Down},
328  {GDK_Prior, kKey_Prior},
329  {GDK_Next, kKey_Next},
330  {GDK_Shift_L, kKey_Shift}, // modifiers
331  {GDK_Shift_R, kKey_Shift},
332  {GDK_Shift_Lock, kKey_Shift},
333  {GDK_Control_L, kKey_Control},
334  {GDK_Control_R, kKey_Control},
335  {GDK_Meta_L, kKey_Meta},
336  {GDK_Meta_R, kKey_Meta},
337  {GDK_Alt_L, kKey_Alt},
338  {GDK_Alt_R, kKey_Alt},
339  {GDK_Caps_Lock, kKey_CapsLock},
340  {GDK_Num_Lock, kKey_NumLock},
341  {GDK_Scroll_Lock, kKey_ScrollLock},
342  {GDK_KP_Space, kKey_Space}, // numeric keypad
343  {GDK_KP_Tab, kKey_Tab},
344  {GDK_KP_Enter, kKey_Enter},
345  {GDK_KP_Equal, kKey_Equal},
346  {GDK_KP_Multiply, kKey_Asterisk},
347  {GDK_KP_Add, kKey_Plus},
348  {GDK_KP_Separator, kKey_Comma},
349  {GDK_KP_Subtract, kKey_Minus},
350  {GDK_KP_Decimal, kKey_Period},
351  {GDK_KP_Divide, kKey_Slash},
352  {0, (EKeySym) 0}
353 };
354 
355 
356 /////////////////////static auxilary functions /////////////////////////////////
357 ////////////////////////////////////////////////////////////////////////////////
358 
359 static Int_t _lookup_string(Event_t * event, char *buf, Int_t buflen)
360 {
361  int i;
362  int n = event->fUser[1];
363  if (n > 0) {
364  for (i = 0; i < n; i++) {
365  buf[i] = event->fUser[2 + i];
366  }
367  buf[n] = 0;
368  } else {
369  buf[0] = 0;
370  }
371  if (event->fCode <= 0x20) {
372  strncpy(buf, keyCodeToString[event->fCode], buflen - 1);
373  }
374  return n;
375 }
376 
377 ////////////////////////////////////////////////////////////////////////////////
378 
379 inline void SplitLong(Long_t ll, Long_t & i1, Long_t & i2)
380 {
381  union {
382  Long_t l;
383  Int_t i[2];
384  } conv;
385 
386  conv.l = 0L;
387  conv.i[0] = 0;
388  conv.i[1] = 0;
389 
390  conv.l = ll;
391  i1 = conv.i[0];
392  i2 = conv.i[1];
393 }
394 
395 ////////////////////////////////////////////////////////////////////////////////
396 
397 inline void AsmLong(Long_t i1, Long_t i2, Long_t & ll)
398 {
399  union {
400  Long_t l;
401  Int_t i[2];
402  } conv;
403 
404  conv.i[0] = (Int_t) i1;
405  conv.i[1] = (Int_t) i2;
406  ll = conv.l;
407 }
408 
409 ////////////////////////////////////////////////////////////////////////////////
410 /// Make sure the child window is visible.
411 
412 static BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
413 {
414  ::ShowWindow(hwndChild, SW_SHOWNORMAL);
415  GdkWindow *child = gdk_window_lookup(hwndChild);
416  if (child)
417  ((GdkWindowPrivate *) child)->mapped = TRUE;
418  return TRUE;
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 
423 static void _ChangeProperty(HWND w, char *np, char *dp, int n, Atom_t type)
424 {
425  HGLOBAL hMem;
426  char *p;
427 
428  hMem = ::GetProp(w, np);
429  if (hMem != NULL) {
430  ::GlobalFree(hMem);
431  }
432  hMem = ::GlobalAlloc(GHND, n + sizeof(Atom_t));
433  p = (char *) ::GlobalLock(hMem);
434  memcpy(p, &type, sizeof(Atom_t));
435  memcpy(p + sizeof(Atom_t), dp, n);
436  ::GlobalUnlock(hMem);
437  ::SetProp(w, np, hMem);
438  ::GlobalFree(hMem);
439 }
440 
441 ////////////////////////////////////////////////////////////////////////////////
442 ///
443 
444 static void W32ChangeProperty(HWND w, Atom_t property, Atom_t type,
445  int format, int mode, const unsigned char *data,
446  int nelements)
447 {
448  char *atomName;
449  char buffer[256];
450  int len;
451  char propName[32];
452 
453  if (mode == GDK_PROP_MODE_REPLACE || mode == GDK_PROP_MODE_PREPEND) {
454  len = (int) ::GlobalGetAtomName(property, buffer, sizeof(buffer));
455  if ((atomName = (char *) malloc(len + 1)) == NULL) {
456  return;
457  } else {
458  strcpy(atomName, buffer);
459  }
460  sprintf(propName, "#0x%0.4x", atomName);
461  _ChangeProperty(w, propName, (char *) data, nelements, type);
462  free(atomName);
463  }
464 }
465 
466 ////////////////////////////////////////////////////////////////////////////////
467 ///
468 
469 static int _GetWindowProperty(GdkWindow * id, Atom_t property, Long_t long_offset,
470  Long_t long_length, Bool_t delete_it, Atom_t req_type,
471  Atom_t * actual_type_return,
472  Int_t * actual_format_return, ULong_t * nitems_return,
473  ULong_t * bytes_after_return, UChar_t ** prop_return)
474 {
475  if (!id) return 0;
476 
477  char *data, *destPtr;
478  char propName[32];
479  HGLOBAL handle;
480  HWND w;
481 
482  w = (HWND) GDK_DRAWABLE_XID(id);
483 
484  if (::IsClipboardFormatAvailable(CF_TEXT) && ::OpenClipboard(NULL)) {
485  handle = ::GetClipboardData(CF_TEXT);
486  if (handle != NULL) {
487  data = (char *) ::GlobalLock(handle);
488  *nitems_return = strlen(data);
489  *prop_return = (UChar_t *) malloc(*nitems_return + 1);
490  destPtr = (char *) *prop_return;
491  while (*data != '\0') {
492  if (*data != '\r') {
493  *destPtr = *data;
494  destPtr++;
495  }
496  data++;
497  }
498  *destPtr = '\0';
499  ::GlobalUnlock(handle);
500  *actual_type_return = XA_STRING;
501  *bytes_after_return = 0;
502  }
503  ::CloseClipboard();
504  return 1;
505  }
506  if (delete_it) {
507  ::RemoveProp(w, propName);
508  }
509  return 1;
510 }
511 
512 ////////////////////////////////////////////////////////////////////////////////
513 ///
514 
515 static ULong_t GetPixelImage(Drawable_t id, Int_t x, Int_t y)
516 {
517  if (!id) return 0;
518 
519  GdkImage *image = (GdkImage *)id;
520  ULong_t pixel;
521 
522  if (image->depth == 1) {
523  pixel = (((char *) image->mem)[y * image->bpl + (x >> 3)] & (1 << (7 - (x & 0x7)))) != 0;
524  } else {
525  UChar_t *pixelp = (UChar_t *) image->mem + y * image->bpl + x * image->bpp;
526  switch (image->bpp) {
527  case 1:
528  pixel = *pixelp;
529  break;
530  // Windows is always LSB, no need to check image->byte_order.
531  case 2:
532  pixel = pixelp[0] | (pixelp[1] << 8);
533  break;
534  case 3:
535  pixel = pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16);
536  break;
537  case 4:
538  pixel = pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16);
539  break;
540  }
541  }
542  return pixel;
543 }
544 
545 ////////////////////////////////////////////////////////////////////////////////
546 /// Collect in orgcolors all different original image colors.
547 
548 static void CollectImageColors(ULong_t pixel, ULong_t * &orgcolors,
549  Int_t & ncolors, Int_t & maxcolors)
550 {
551  if (maxcolors == 0) {
552  ncolors = 0;
553  maxcolors = 100;
554  orgcolors = (ULong_t*) ::operator new(maxcolors*sizeof(ULong_t));
555  }
556 
557  for (int i = 0; i < ncolors; i++) {
558  if (pixel == orgcolors[i]) return;
559  }
560  if (ncolors >= maxcolors) {
561  orgcolors = (ULong_t *) TStorage::ReAlloc(orgcolors,
562  maxcolors * 2 *
563  sizeof(ULong_t),
564  maxcolors *
565  sizeof(ULong_t));
566  maxcolors *= 2;
567  }
568  orgcolors[ncolors++] = pixel;
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// debug function for printing event mask
573 
574 static char *EventMask2String(UInt_t evmask)
575 {
576  static char bfr[500];
577  char *p = bfr;
578 
579  *p = '\0';
580 #define BITmask(x) \
581  if (evmask & k##x##Mask) \
582  p += sprintf (p, "%s" #x, (p > bfr ? " " : ""))
583  BITmask(Exposure);
584  BITmask(PointerMotion);
585  BITmask(ButtonMotion);
586  BITmask(ButtonPress);
587  BITmask(ButtonRelease);
588  BITmask(KeyPress);
589  BITmask(KeyRelease);
590  BITmask(EnterWindow);
591  BITmask(LeaveWindow);
592  BITmask(FocusChange);
593  BITmask(StructureNotify);
594 #undef BITmask
595 
596  return bfr;
597 }
598 
599 ///////////////////////////////////////////////////////////////////////////////
600 class TGWin32MainThread {
601 
602 public:
603  void *fHandle; // handle of server (aka command) thread
604  DWORD fId; // id of server (aka command) thread
605  static LPCRITICAL_SECTION fCritSec; // general mutex
606  static LPCRITICAL_SECTION fMessageMutex; // message queue mutex
607 
608  TGWin32MainThread();
609  ~TGWin32MainThread();
610  static void LockMSG();
611  static void UnlockMSG();
612 };
613 
614 TGWin32MainThread *gMainThread = 0;
615 LPCRITICAL_SECTION TGWin32MainThread::fCritSec = 0;
616 LPCRITICAL_SECTION TGWin32MainThread::fMessageMutex = 0;
617 
618 
619 ////////////////////////////////////////////////////////////////////////////////
620 /// dtor
621 
622 TGWin32MainThread::~TGWin32MainThread()
623 {
624  if (fCritSec) {
625  ::LeaveCriticalSection(fCritSec);
626  ::DeleteCriticalSection(fCritSec);
627  delete fCritSec;
628  }
629  fCritSec = 0;
630 
631  if (fMessageMutex) {
632  ::LeaveCriticalSection(fMessageMutex);
633  ::DeleteCriticalSection(fMessageMutex);
634  delete fMessageMutex;
635  }
636  fMessageMutex = 0;
637 
638  if(fHandle) {
639  ::PostThreadMessage(fId, WM_QUIT, 0, 0);
640  ::CloseHandle(fHandle);
641  }
642  fHandle = 0;
643 }
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// lock message queue
647 
648 void TGWin32MainThread::LockMSG()
649 {
650  if (fMessageMutex) ::EnterCriticalSection(fMessageMutex);
651 }
652 
653 ////////////////////////////////////////////////////////////////////////////////
654 /// unlock message queue
655 
656 void TGWin32MainThread::UnlockMSG()
657 {
658  if (fMessageMutex) ::LeaveCriticalSection(fMessageMutex);
659 }
660 
661 ///////////////////////////////////////////////////////////////////////////////
662 class TGWin32RefreshTimer : public TTimer {
663 
664 public:
665  TGWin32RefreshTimer() : TTimer(10, kTRUE) { if (gSystem) gSystem->AddTimer(this); }
666  ~TGWin32RefreshTimer() { if (gSystem) gSystem->RemoveTimer(this); }
667  Bool_t Notify()
668  {
669  Reset();
670  MSG msg;
671 
672  while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) {
673  ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE);
674  if (!gVirtualX)
675  Sleep(200); // avoid start-up race
676  if (gVirtualX)
677  ((TGWin32*)gVirtualX)->GUIThreadMessageFunc(&msg);
678  }
679  return kFALSE;
680  }
681 };
682 /*
683 ////////////////////////////////////////////////////////////////////////////////
684 /// thread for processing windows messages (aka Main/Server thread)
685 
686 static DWORD WINAPI MessageProcessingLoop(void *p)
687 {
688  MSG msg;
689  Int_t erret;
690  Bool_t endLoop = kFALSE;
691  TGWin32RefreshTimer *refersh = 0;
692 
693  // force to create message queue
694  ::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
695 
696  // periodically we refresh windows
697  // Don't create refresh timer if the application has been created inside PVSS
698  if (gApplication) {
699  TString arg = gSystem->BaseName(gApplication->Argv(0));
700  if (!arg.Contains("PVSS"))
701  refersh = new TGWin32RefreshTimer();
702  }
703 
704  while (!endLoop) {
705  erret = ::GetMessage(&msg, NULL, NULL, NULL);
706  if (erret <= 0) endLoop = kTRUE;
707  endLoop = MessageProcessingFunc(&msg);
708  }
709 
710  TGWin32::Instance()->CloseDisplay();
711  if (refersh)
712  delete refersh;
713 
714  // exit thread
715  if (erret == -1) {
716  erret = ::GetLastError();
717  Error("MsgLoop", "Error in GetMessage");
718  ::ExitThread(-1);
719  } else {
720  ::ExitThread(0);
721  }
722  return 0;
723 }
724 */
725 
726 Bool_t GUIThreadMessageWrapper(MSG* msg)
727 {
728  // Static wrapper for handling GUI messages.
729  // Forwards from TWinNTSystem's GUIThreadMessageProcessingLoop()
730  // to TGWin32::GUIThreadMessageFunc()
731 
732  return ((TGWin32*)gVirtualX)->GUIThreadMessageFunc(msg);
733 }
734 
735 ////////////////////////////////////////////////////////////////////////////////
736 /// constructor
737 
738 TGWin32MainThread::TGWin32MainThread()
739 {
740  fCritSec = new CRITICAL_SECTION;
741  ::InitializeCriticalSection(fCritSec);
742  fMessageMutex = new CRITICAL_SECTION;
743  ::InitializeCriticalSection(fMessageMutex);
744  fHandle = ((TWinNTSystem*)gSystem)->GetGUIThreadHandle();
745  fId = ((TWinNTSystem*)gSystem)->GetGUIThreadId();
746  ((TWinNTSystem*)gSystem)->SetGUIThreadMsgHandler(GUIThreadMessageWrapper);
747 }
748 
749 } // unnamed namespace
750 
751 ///////////////////////// TGWin32 implementation ///////////////////////////////
753 
754 ////////////////////////////////////////////////////////////////////////////////
755 /// Default constructor.
756 
757 TGWin32::TGWin32(): fRefreshTimer(0)
758 {
759  fScreenNumber = 0;
760  fWindows = 0;
761  fColors = 0;
762 }
763 
764 ////////////////////////////////////////////////////////////////////////////////
765 /// Normal Constructor.
766 
767 TGWin32::TGWin32(const char *name, const char *title) : TVirtualX(name,title), fRefreshTimer(0)
768 {
769  fScreenNumber = 0;
772  fTextAlignH = 1;
773  fTextAlignV = 1;
774  fTextAlign = 7;
775  fTextMagnitude = 1;
776  fCharacterUpX = 1;
777  fCharacterUpY = 1;
778  fDrawMode = kCopy;
779  fWindows = 0;
780  fMaxNumberOfWindows = 10;
781  fXEvent = 0;
788 
789  fWindows = (XWindow_t*) TStorage::Alloc(fMaxNumberOfWindows*sizeof(XWindow_t));
790  for (int i = 0; i < fMaxNumberOfWindows; i++) fWindows[i].open = 0;
791 
792  fColors = new TExMap;
793 
794  if (gApplication) {
796  if (!arg.Contains("PVSS"))
797  fRefreshTimer = new TGWin32RefreshTimer();
798  } else {
799  fRefreshTimer = new TGWin32RefreshTimer();
800  }
801 
802  // initialize GUI thread and proxy objects
803  if (!gROOT->IsBatch() && !gMainThread) {
804  gMainThread = new TGWin32MainThread();
805  TGWin32ProxyBase::fgMainThreadId = ::GetCurrentThreadId(); // gMainThread->fId;
808 #ifdef OLD_THREAD_IMPLEMENTATION
809  gPtr2Interpreter = &TGWin32InterpreterProxy::ProxyObject;
810 #endif
811  }
812 }
813 
814 ////////////////////////////////////////////////////////////////////////////////
815 /// destructor.
816 
818 {
819  CloseDisplay();
820  if (fRefreshTimer)
821  delete fRefreshTimer;
822  if (!fColors) return;
823  Long64_t key, value;
824  TExMapIter it(fColors);
825  while (it.Next(key, value)) {
826  XColor_t *col = (XColor_t *) value;
827  delete col;
828  }
829  delete fColors;
830 }
831 
832 ////////////////////////////////////////////////////////////////////////////////
833 /// Windows timer handling events while moving/resizing windows
834 
835 VOID CALLBACK MyTimerProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime)
836 {
838  //gVirtualX->UpdateWindow(1); // cause problems with OpenGL in pad...
839 }
840 
841 ////////////////////////////////////////////////////////////////////////////////
842 /// Message processing function for the GUI thread.
843 /// Kicks in once TGWin32 becomes active, and "replaces" the dummy one
844 /// in TWinNTSystem; see TWinNTSystem.cxx's GUIThreadMessageProcessingLoop().
845 
847 {
848  Bool_t ret = kFALSE;
849  static Int_t m_timer = 0;
850 
851  if ( (msg->message == WM_NCLBUTTONDOWN) ) {
852  if (m_timer == 0)
853  m_timer = SetTimer(NULL, 1, 20, (TIMERPROC) MyTimerProc);
854  }
855  else if (msg->message == WM_NCMOUSELEAVE ) {
856  if (m_timer) {
857  KillTimer(NULL, m_timer);
858  }
859  m_timer = 0;
860  }
861 
862  if (msg->message == TGWin32ProxyBase::fgPostMessageId) {
863  if (msg->wParam) {
864  TGWin32ProxyBase *proxy = (TGWin32ProxyBase*)msg->wParam;
865  proxy->ExecuteCallBack(kTRUE);
866  } else {
867  ret = kTRUE;
868  }
869  } else if (msg->message == TGWin32ProxyBase::fgPingMessageId) {
871  } else {
872  //if ( (msg->message >= WM_NCMOUSEMOVE) &&
873  // (msg->message <= WM_NCMBUTTONDBLCLK) ) {
874  // TGWin32ProxyBase::GlobalLock();
875  //}
876  TGWin32MainThread::LockMSG();
877  TranslateMessage(msg);
878  DispatchMessage(msg);
879  TGWin32MainThread::UnlockMSG();
880  }
881  return ret;
882 }
883 
884 ////////////////////////////////////////////////////////////////////////////////
885 /// returns kTRUE if we are inside cmd/server thread
886 
888 {
889 #ifdef OLD_THREAD_IMPLEMENTATION
890  return ((::GetCurrentThreadId() == TGWin32ProxyBase::fgMainThreadId) ||
891  (::GetCurrentThreadId() == TGWin32ProxyBase::fgUserThreadId));
892 #else
893  return kTRUE;
894 #endif
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////
898 /// close display (terminate server/gMainThread thread)
899 
901 {
902  // disable any processing while exiting
904 
905  // terminate server thread
906  gPtr2VirtualX = 0;
907 #if ROOT_VERSION_CODE < ROOT_VERSION(6,00,00)
908  gPtr2Interpreter = 0;
909 #endif
911  // Following the change in revision 47611,
912  // gInterpreter is a read-only variable but its value
913  // is overridden by gPtr2Interpreter when it is not null.
914  // gInterpreter = TGWin32InterpreterProxy::RealObject();
915 
916  // The lock above does not work, so at least
917  // minimize the risk
918  TGWin32MainThread *delThread = gMainThread;
919  if (gMainThread) {
920  gMainThread = 0;
921  delete delThread;
922  }
923 
925 
926  // terminate ROOT logo splash thread
927  TWin32SplashThread *delSplash = gSplash;
928  if (gSplash) {
929  gSplash = 0;
930  delete delSplash;
931  }
932 
934  fWindows = 0;
935 
936  if (fXEvent) gdk_event_free((GdkEvent*)fXEvent);
937 
939 
940  gROOT->SetBatch(kTRUE); // no GUI is possible
941 }
942 
943 ////////////////////////////////////////////////////////////////////////////////
944 ///
945 
947 {
948  if (gMainThread && gMainThread->fCritSec) ::EnterCriticalSection(gMainThread->fCritSec);
949 }
950 
951 ////////////////////////////////////////////////////////////////////////////////
952 ///
953 
955 {
956  if (gMainThread && gMainThread->fCritSec) ::LeaveCriticalSection(gMainThread->fCritSec);
957 }
958 
959 ////////////////////////////////////////////////////////////////////////////////
960 /// Initialize Win32 system. Returns kFALSE in case of failure.
961 
962 Bool_t TGWin32::Init(void *display)
963 {
964  if (!gdk_initialized) {
965  if (!gdk_init_check(NULL, NULL)) return kFALSE;
966  gdk_initialized = true;
967  }
968 
969  if (!gClipboardAtom) {
970  gClipboardAtom = gdk_atom_intern("CLIPBOARD", kFALSE);
971  }
972 
973  return kTRUE;
974 }
975 
976 ////////////////////////////////////////////////////////////////////////////////
977 /// Open the display. Return -1 if the opening fails, 0 when ok.
978 
979 Int_t TGWin32::OpenDisplay(const char *dpyName)
980 {
981  GdkPixmap *pixmp1, *pixmp2;
982  GdkColor fore, back;
983  GdkColor color;
984  GdkGCValues gcvals;
985  int i;
986 
987  if (!Init((void*)dpyName)) {
988  return -1;
989  }
990 
991  if (gDebug <= 4) {
993  } else {
994  gdk_debug_level = 0;
995  }
996 
997  fore.red = fore.green = fore.blue = 0;
998  back.red = back.green = back.blue = 0;
999  color.red = color.green = color.blue = 0;
1000 
1001  fScreenNumber = 0; //DefaultScreen(fDisplay);
1002  fVisual = gdk_visual_get_best();
1003  fColormap = gdk_colormap_get_system();
1004  fDepth = gdk_visual_get_best_depth();
1005 
1006  GetColor(1).fDefined = kTRUE; // default foreground
1007  gdk_color_black((GdkColormap *)fColormap, &GetColor(1).color);
1008 
1009  GetColor(0).fDefined = kTRUE; // default background
1010  gdk_color_white((GdkColormap *)fColormap, &GetColor(0).color);
1011 
1012  // Create primitives graphic contexts
1013  for (i = 0; i < kMAXGC; i++) {
1014  gGClist[i] = gdk_gc_new(GDK_ROOT_PARENT());
1015  gdk_gc_set_foreground(gGClist[i], &GetColor(1).color);
1016  gdk_gc_set_background(gGClist[i], &GetColor(0).color);
1017  }
1018 
1019  gGCline = gGClist[0]; // PolyLines
1020  gGCmark = gGClist[1]; // PolyMarker
1021  gGCfill = gGClist[2]; // Fill areas
1022  gGCtext = gGClist[3]; // Text
1023  gGCinvt = gGClist[4]; // Inverse text
1024  gGCdash = gGClist[5]; // Dashed lines
1025  gGCpxmp = gGClist[6]; // Pixmap management
1026 
1027  gdk_gc_get_values(gGCtext, &gcvals);
1028  gdk_gc_set_foreground(gGCinvt, &gcvals.background);
1029  gdk_gc_set_background(gGCinvt, &gcvals.foreground);
1030 
1031  // Create input echo graphic context
1032  GdkGCValues echov;
1033  gdk_color_black(fColormap, &echov.foreground); // = BlackPixel(fDisplay, fScreenNumber);
1034  gdk_color_white(fColormap, &echov.background); // = WhitePixel(fDisplay, fScreenNumber);
1035  echov.function = GDK_INVERT;
1036  echov.subwindow_mode = GDK_CLIP_BY_CHILDREN;
1037  gGCecho =
1038  gdk_gc_new_with_values((GdkWindow *) GDK_ROOT_PARENT(), &echov,
1039  (GdkGCValuesMask) (GDK_GC_FOREGROUND |
1040  GDK_GC_BACKGROUND |
1041  GDK_GC_FUNCTION |
1042  GDK_GC_SUBWINDOW));
1043  // Create a null cursor
1044  pixmp1 = gdk_bitmap_create_from_data(GDK_ROOT_PARENT(),
1045  (const char *)null_cursor_bits, 16,16);
1046 
1047  pixmp2 = gdk_bitmap_create_from_data(GDK_ROOT_PARENT(),
1048  (const char *)null_cursor_bits, 16, 16);
1049 
1050  gNullCursor = gdk_cursor_new_from_pixmap((GdkDrawable *)pixmp1, (GdkDrawable *)pixmp2,
1051  &fore, &back, 0, 0);
1052  // Create cursors
1053  if (gEnv->GetValue("Win32.UseSysPointers", 0)) {
1055  fCursors[kBottomLeft] = gdk_syscursor_new((ULong_t)IDC_SIZENESW);
1056  fCursors[kBottomRight] = gdk_syscursor_new((ULong_t)IDC_SIZENWSE);
1057  fCursors[kTopLeft] = gdk_syscursor_new((ULong_t)IDC_SIZENWSE);
1058  fCursors[kTopRight] = gdk_syscursor_new((ULong_t)IDC_SIZENESW);
1059  fCursors[kBottomSide] = gdk_syscursor_new((ULong_t)IDC_SIZENS);
1060  fCursors[kLeftSide] = gdk_syscursor_new((ULong_t)IDC_SIZEWE);
1061  fCursors[kTopSide] = gdk_syscursor_new((ULong_t)IDC_SIZENS);
1062  fCursors[kRightSide] = gdk_syscursor_new((ULong_t)IDC_SIZEWE);
1063  fCursors[kMove] = gdk_syscursor_new((ULong_t)IDC_SIZEALL);
1064  fCursors[kCross] =gdk_syscursor_new((ULong_t)IDC_CROSS);
1065  fCursors[kArrowHor] = gdk_syscursor_new((ULong_t)IDC_SIZEWE);
1066  fCursors[kArrowVer] = gdk_syscursor_new((ULong_t)IDC_SIZENS);
1067  fCursors[kHand] = gdk_syscursor_new((ULong_t)IDC_HAND);
1068  fCursors[kPointer] = gdk_syscursor_new((ULong_t)IDC_ARROW);
1069  fCursors[kCaret] = gdk_syscursor_new((ULong_t)IDC_IBEAM);
1070  fCursors[kWatch] = gdk_syscursor_new((ULong_t)IDC_WAIT);
1071  fCursors[kNoDrop] = gdk_syscursor_new((ULong_t)IDC_NO);
1072  }
1073  else {
1075  fCursors[kBottomLeft] = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
1076  fCursors[kBottomRight] = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
1077  fCursors[kTopLeft] = gdk_cursor_new(GDK_TOP_LEFT_CORNER);
1078  fCursors[kTopRight] = gdk_cursor_new(GDK_TOP_RIGHT_CORNER);
1079  fCursors[kBottomSide] = gdk_cursor_new(GDK_BOTTOM_SIDE);
1080  fCursors[kLeftSide] = gdk_cursor_new(GDK_LEFT_SIDE);
1081  fCursors[kTopSide] = gdk_cursor_new(GDK_TOP_SIDE);
1082  fCursors[kRightSide] = gdk_cursor_new(GDK_RIGHT_SIDE);
1083  fCursors[kMove] = gdk_cursor_new(GDK_FLEUR);
1084  fCursors[kCross] =gdk_cursor_new(GDK_CROSSHAIR);
1085  fCursors[kArrowHor] = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
1086  fCursors[kArrowVer] = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
1087  fCursors[kHand] = gdk_cursor_new(GDK_HAND2);
1088  fCursors[kPointer] = gdk_cursor_new(GDK_LEFT_PTR);
1089  fCursors[kCaret] = gdk_cursor_new(GDK_XTERM);
1090  //fCursors[kWatch] = gdk_cursor_new(GDK_WATCH);
1091  fCursors[kWatch] = gdk_cursor_new(GDK_BUSY);
1092  fCursors[kNoDrop] = gdk_cursor_new(GDK_PIRATE);
1093  }
1094  fCursors[kRotate] = gdk_cursor_new(GDK_EXCHANGE);
1095  fCursors[kArrowRight] = gdk_cursor_new(GDK_ARROW);
1096 
1097  // Setup color information
1099 
1100  if ( gdk_visual_get_best_type() == GDK_VISUAL_TRUE_COLOR) {
1101  int i;
1102  for (i = 0; i < int(sizeof(fVisual->blue_mask)*kBitsPerByte); i++) {
1103  if (fBlueShift == -1 && ((fVisual->blue_mask >> i) & 1)) {
1104  fBlueShift = i;
1105  }
1106  if ((fVisual->blue_mask >> i) == 1) {
1107  fBlueDiv = sizeof(UShort_t)*kBitsPerByte - i - 1 + fBlueShift;
1108  break;
1109  }
1110  }
1111  for (i = 0; i < int(sizeof(fVisual->green_mask)*kBitsPerByte); i++) {
1112  if (fGreenShift == -1 && ((fVisual->green_mask >> i) & 1)) {
1113  fGreenShift = i;
1114  }
1115  if ((fVisual->green_mask >> i) == 1) {
1116  fGreenDiv = sizeof(UShort_t)*kBitsPerByte - i - 1 + fGreenShift;
1117  break;
1118  }
1119  }
1120  for (i = 0; i < int(sizeof(fVisual->red_mask)*kBitsPerByte); i++) {
1121  if (fRedShift == -1 && ((fVisual->red_mask >> i) & 1)) {
1122  fRedShift = i;
1123  }
1124  if ((fVisual->red_mask >> i) == 1) {
1125  fRedDiv = sizeof(UShort_t)*kBitsPerByte - i - 1 + fRedShift;
1126  break;
1127  }
1128  }
1129  }
1130 
1131  SetName("Win32TTF");
1132  SetTitle("ROOT interface to Win32 with TrueType fonts");
1133 
1134  if (!TTF::IsInitialized()) TTF::Init();
1135 
1136  if (fDepth > 8) {
1138  } else {
1140  }
1141 
1143  fHasTTFonts = kTRUE;
1144  return 0;
1145 }
1146 
1147 ////////////////////////////////////////////////////////////////////////////////
1148 /// Allocate color in colormap. If we are on an <= 8 plane machine
1149 /// we will use XAllocColor. If we are on a >= 15 (15, 16 or 24) plane
1150 /// true color machine we will calculate the pixel value using:
1151 /// for 15 and 16 bit true colors have 6 bits precision per color however
1152 /// only the 5 most significant bits are used in the color index.
1153 /// Except for 16 bits where green uses all 6 bits. I.e.:
1154 /// 15 bits = rrrrrgggggbbbbb
1155 /// 16 bits = rrrrrggggggbbbbb
1156 /// for 24 bits each r, g and b are represented by 8 bits.
1157 ///
1158 /// Since all colors are set with a max of 65535 (16 bits) per r, g, b
1159 /// we just right shift them by 10, 11 and 10 bits for 16 planes, and
1160 /// (10, 10, 10 for 15 planes) and by 8 bits for 24 planes.
1161 /// Returns kFALSE in case color allocation failed.
1162 
1163 Bool_t TGWin32::AllocColor(GdkColormap *cmap, GdkColor *color)
1164 {
1165  if (fRedDiv == -1) {
1166  if ( gdk_color_alloc((GdkColormap *)cmap, (GdkColor *)color) ) return kTRUE;
1167  } else {
1168  color->pixel = (color->red >> fRedDiv) << fRedShift |
1169  (color->green >> fGreenDiv) << fGreenShift |
1170  (color->blue >> fBlueDiv) << fBlueShift;
1171  return kTRUE;
1172  }
1173 
1174  return kFALSE;
1175 }
1176 
1177 ////////////////////////////////////////////////////////////////////////////////
1178 /// Returns the current RGB value for the pixel in the XColor structure.
1179 
1180 void TGWin32::QueryColors(GdkColormap *cmap, GdkColor *color, Int_t ncolors)
1181 {
1182  ULong_t r, g, b;
1183 
1184  if (fRedDiv == -1) {
1185  GdkColorContext *cc = gdk_color_context_new(gdk_visual_get_system(), cmap);
1186  gdk_color_context_query_colors(cc, color, ncolors);
1187  gdk_color_context_free(cc);
1188  } else {
1189  for (Int_t i = 0; i < ncolors; i++) {
1190  r = (color[i].pixel & fVisual->red_mask) >> fRedShift;
1191  color[i].red = UShort_t(r*kBIGGEST_RGB_VALUE/(fVisual->red_mask >> fRedShift));
1192 
1193  g = (color[i].pixel & fVisual->green_mask) >> fGreenShift;
1194  color[i].green = UShort_t(g*kBIGGEST_RGB_VALUE/(fVisual->green_mask >> fGreenShift));
1195 
1196  b = (color[i].pixel & fVisual->blue_mask) >> fBlueShift;
1197  color[i].blue = UShort_t(b*kBIGGEST_RGB_VALUE/(fVisual->blue_mask >> fBlueShift));
1198  }
1199  }
1200 }
1201 
1202 ////////////////////////////////////////////////////////////////////////////////
1203 /// Compute alignment variables. The alignment is done on the horizontal string
1204 /// then the rotation is applied on the alignment variables.
1205 /// SetRotation and LayoutGlyphs should have been called before.
1206 
1207 void TGWin32::Align(void)
1208 {
1209  EAlign align = (EAlign) fTextAlign;
1210 
1211  // vertical alignment
1212  if (align == kTLeft || align == kTCenter || align == kTRight) {
1213  fAlign.y = TTF::GetAscent();
1214  } else if (align == kMLeft || align == kMCenter || align == kMRight) {
1215  fAlign.y = TTF::GetAscent()/2;
1216  } else {
1217  fAlign.y = 0;
1218  }
1219  // horizontal alignment
1220  if (align == kTRight || align == kMRight || align == kBRight) {
1221  fAlign.x = TTF::GetWidth();
1222  } else if (align == kTCenter || align == kMCenter || align == kBCenter) {
1223  fAlign.x = TTF::GetWidth()/2;
1224  } else {
1225  fAlign.x = 0;
1226  }
1227 
1228  FT_Vector_Transform(&fAlign, TTF::GetRotMatrix());
1229  fAlign.x = fAlign.x >> 6;
1230  fAlign.y = fAlign.y >> 6;
1231 }
1232 
1233 ////////////////////////////////////////////////////////////////////////////////
1234 /// Draw FT_Bitmap bitmap to xim image at position bx,by using specified
1235 /// foreground color.
1236 
1237 void TGWin32::DrawImage(FT_Bitmap *source, ULong_t fore, ULong_t back,
1238  GdkImage *xim, Int_t bx, Int_t by)
1239 {
1240  UChar_t d = 0, *s = source->buffer;
1241 
1242  if (TTF::GetSmoothing()) {
1243 
1244  static GdkColor col[5];
1245  GdkColor *bcol = 0, *bc;
1246  Int_t x, y;
1247 
1248  // background kClear, i.e. transparent, we take as background color
1249  // the average of the rgb values of all pixels covered by this character
1250  if (back == (ULong_t) -1 && (UInt_t)source->width) {
1251  ULong_t r, g, b;
1252  Int_t dots, dotcnt;
1253  const Int_t maxdots = 50000;
1254 
1255  dots = Int_t(source->width * source->rows);
1256  dots = dots > maxdots ? maxdots : dots;
1257  bcol = new GdkColor[dots];
1258  if (!bcol) return;
1259 
1260  bc = bcol;
1261  dotcnt = 0;
1262  for (y = 0; y < (int) source->rows; y++) {
1263  for (x = 0; x < (int) source->width; x++, bc++) {
1264  bc->pixel = GetPixelImage((Drawable_t)xim, bx + x, by + y);
1265  if (++dotcnt >= maxdots) break;
1266  }
1267  }
1268  QueryColors(fColormap, bcol, dots);
1269  r = g = b = 0;
1270  bc = bcol;
1271  dotcnt = 0;
1272  for (y = 0; y < (int) source->rows; y++) {
1273  for (x = 0; x < (int) source->width; x++, bc++) {
1274  r += bc->red;
1275  g += bc->green;
1276  b += bc->blue;
1277  if (++dotcnt >= maxdots) break;
1278  }
1279  }
1280  if (dots != 0) {
1281  r /= dots;
1282  g /= dots;
1283  b /= dots;
1284  }
1285  bc = &col[0];
1286  if (bc->red == r && bc->green == g && bc->blue == b) {
1287  bc->pixel = back;
1288  } else {
1289  bc->pixel = ~back;
1290  bc->red = (UShort_t) r;
1291  bc->green = (UShort_t) g;
1292  bc->blue = (UShort_t) b;
1293  }
1294  }
1295  delete [] bcol;
1296 
1297  // if fore or background have changed from previous character
1298  // recalculate the 3 smooting colors (interpolation between fore-
1299  // and background colors)
1300  if (fore != col[4].pixel || back != col[0].pixel) {
1301  col[4].pixel = fore;
1302  if (back != (ULong_t) -1) {
1303  col[3].pixel = back;
1304  QueryColors(fColormap, &col[3], 2);
1305  col[0] = col[3];
1306  } else {
1307  QueryColors(fColormap, &col[4], 1);
1308  }
1309 
1310  // interpolate between fore and backgound colors
1311  for (x = 3; x > 0; x--) {
1312  col[x].red = (col[4].red *x + col[0].red *(4-x)) /4;
1313  col[x].green = (col[4].green*x + col[0].green*(4-x)) /4;
1314  col[x].blue = (col[4].blue *x + col[0].blue *(4-x)) /4;
1315  if (!AllocColor(fColormap, &col[x])) {
1316  Warning("DrawImage", "cannot allocate smoothing color");
1317  col[x].pixel = col[x+1].pixel;
1318  }
1319  }
1320  }
1321 
1322  // put smoothed character, character pixmap values are an index
1323  // into the 5 colors used for aliasing (4 = foreground, 0 = background)
1324  for (y = 0; y < (int) source->rows; y++) {
1325  for (x = 0; x < (int) source->width; x++) {
1326  d = *s++ & 0xff;
1327  d = ((d + 10) * 5) / 256;
1328  if (d > 4) d = 4;
1329  if (d && x < (int) source->width) {
1330  ULong_t p = col[d].pixel;
1331  PutPixel((Drawable_t)xim, bx + x, by + y, p);
1332  }
1333  }
1334  }
1335  } else {
1336  // no smoothing, just put character using foreground color
1337  UChar_t* row=s;
1338  for (int y = 0; y < (int) source->rows; y++) {
1339  int n = 0;
1340  s = row;
1341  for (int x = 0; x < (int) source->width; x++) {
1342  if (n == 0) d = *s++;
1343  if (TESTBIT(d,7-n)) {
1344  PutPixel((Drawable_t)xim, bx + x, by + y, fore);
1345  }
1346  if (++n == (int) kBitsPerByte) n = 0;
1347  }
1348  row += source->pitch;
1349  }
1350  }
1351 }
1352 
1353 ////////////////////////////////////////////////////////////////////////////////
1354 /// Draw text using TrueType fonts. If TrueType fonts are not available the
1355 /// text is drawn with TGWin32::DrawText.
1356 
1358  const char *text, ETextMode mode)
1359 {
1360  if (!TTF::IsInitialized()) TTF::Init();
1361  TTF::SetRotationMatrix(angle);
1362  TTF::PrepareString(text);
1364  Align();
1365  RenderString(x, y, mode);
1366 }
1367 
1368 ////////////////////////////////////////////////////////////////////////////////
1369 /// Draw text using TrueType fonts. If TrueType fonts are not available the
1370 /// text is drawn with TGWin32::DrawText.
1371 
1373  const wchar_t *text, ETextMode mode)
1374 {
1375  if (!TTF::IsInitialized()) TTF::Init();
1376  TTF::SetRotationMatrix(angle);
1377  TTF::PrepareString(text);
1379  Align();
1380  RenderString(x, y, mode);
1381 }
1382 
1383 ////////////////////////////////////////////////////////////////////////////////
1384 /// Get the background of the current window in an XImage.
1385 
1387 {
1388  Window_t cws = GetCurrentWindow();
1389  UInt_t width;
1390  UInt_t height;
1391  Int_t xy;
1392  gVirtualX->GetWindowSize(cws, xy, xy, width, height);
1393 
1394  if (x < 0) {
1395  w += x;
1396  x = 0;
1397  }
1398  if (y < 0) {
1399  h += y;
1400  y = 0;
1401  }
1402 
1403  if (x+w > width) w = width - x;
1404  if (y+h > height) h = height - y;
1405 
1406  return gdk_image_get((GdkDrawable*)cws, x, y, w, h);
1407 }
1408 
1409 ////////////////////////////////////////////////////////////////////////////////
1410 /// Test if there is really something to render
1411 
1413 {
1414  Window_t cws = GetCurrentWindow();
1415  UInt_t width;
1416  UInt_t height;
1417  Int_t xy;
1418  gVirtualX->GetWindowSize(cws, xy, xy, width, height);
1419 
1420  // If w or h is 0, very likely the string is only blank characters
1421  if ((int)w == 0 || (int)h == 0) return kFALSE;
1422 
1423  // If string falls outside window, there is probably no need to draw it.
1424  if (x + (int)w <= 0 || x >= (int)width) return kFALSE;
1425  if (y + (int)h <= 0 || y >= (int)height) return kFALSE;
1426 
1427  return kTRUE;
1428 }
1429 
1430 ////////////////////////////////////////////////////////////////////////////////
1431 /// Perform the string rendering in the pad.
1432 /// LayoutGlyphs should have been called before.
1433 
1435 {
1436  TTF::TTGlyph* glyph = TTF::GetGlyphs();
1437  GdkGCValues gcvals;
1438 
1439  // compute the size and position of the XImage that will contain the text
1440  Int_t Xoff = 0; if (TTF::GetBox().xMin < 0) Xoff = -TTF::GetBox().xMin;
1441  Int_t Yoff = 0; if (TTF::GetBox().yMin < 0) Yoff = -TTF::GetBox().yMin;
1442  Int_t w = TTF::GetBox().xMax + Xoff;
1443  Int_t h = TTF::GetBox().yMax + Yoff;
1444  Int_t x1 = x-Xoff-fAlign.x;
1445  Int_t y1 = y+Yoff+fAlign.y-h;
1446 
1447  if (!IsVisible(x1, y1, w, h)) {
1448  return;
1449  }
1450 
1451  // create the XImage that will contain the text
1452  UInt_t depth = fDepth;
1453  GdkImage *xim = gdk_image_new(GDK_IMAGE_SHARED, gdk_visual_get_best(), w, h);
1454 
1455  // use malloc since Xlib will use free() in XDestroyImage
1456 // xim->data = (char *) malloc(xim->bytes_per_line * h);
1457 // memset(xim->data, 0, xim->bytes_per_line * h);
1458 
1459  ULong_t pixel;
1460  ULong_t bg;
1461 
1462  gdk_gc_get_values((GdkGC*)GetGC(3), &gcvals);
1463 
1464  // get the background
1465  if (mode == kClear) {
1466  // if mode == kClear we need to get an image of the background
1467  GdkImage *bim = GetBackground(x1, y1, w, h);
1468  if (!bim) {
1469  Error("DrawText", "error getting background image");
1470  return;
1471  }
1472 
1473  // and copy it into the text image
1474  Int_t xo = 0, yo = 0;
1475  if (x1 < 0) xo = -x1;
1476  if (y1 < 0) yo = -y1;
1477 
1478  for (int yp = 0; yp < (int) bim->height; yp++) {
1479  for (int xp = 0; xp < (int) bim->width; xp++) {
1480  pixel = GetPixelImage((Drawable_t)bim, xp, yp);
1481  PutPixel((Drawable_t)xim, xo+xp, yo+yp, pixel);
1482  }
1483  }
1484 
1485  gdk_image_unref((GdkImage *)bim);
1486 
1487  bg = (ULong_t) -1;
1488  } else {
1489  // if mode == kOpaque its simple, we just draw the background
1490 
1491  GdkImage *bim = GetBackground(x1, y1, w, h);
1492  if (!bim) {
1493  pixel = gcvals.background.pixel;
1494  } else {
1495  pixel = GetPixelImage((Drawable_t)bim, 0, 0);
1496  }
1497  Int_t xo = 0, yo = 0;
1498  if (x1 < 0) xo = -x1;
1499  if (y1 < 0) yo = -y1;
1500 
1501  for (int yp = 0; yp < h; yp++) {
1502  for (int xp = 0; xp < (int) w; xp++) {
1503  PutPixel((Drawable_t)xim, xo+xp, yo+yp, pixel);
1504  }
1505  }
1506  if (bim) {
1507  gdk_image_unref((GdkImage *)bim);
1508  bg = (ULong_t) -1;
1509  } else {
1510  bg = pixel;
1511  }
1512  }
1513 
1514  // paint the glyphs in the XImage
1515  glyph = TTF::GetGlyphs();
1516  for (int n = 0; n < TTF::GetNumGlyphs(); n++, glyph++) {
1517  if (FT_Glyph_To_Bitmap(&glyph->fImage,
1518  TTF::GetSmoothing() ? ft_render_mode_normal
1519  : ft_render_mode_mono,
1520  0, 1 )) continue;
1521  FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->fImage;
1522  FT_Bitmap* source = &bitmap->bitmap;
1523  Int_t bx, by;
1524 
1525  bx = bitmap->left+Xoff;
1526  by = h - bitmap->top-Yoff;
1527  DrawImage(source, gcvals.foreground.pixel, bg, xim, bx, by);
1528  }
1529 
1530  // put the Ximage on the screen
1531  Window_t cws = GetCurrentWindow();
1532  gdk_draw_image((GdkDrawable *)cws, GetGC(6), xim, 0, 0, x1, y1, w, h);
1533 
1534  gdk_image_unref(xim);
1535 }
1536 
1537 ////////////////////////////////////////////////////////////////////////////////
1538 /// Set specified font.
1539 
1541 {
1542  fTextFont = fontnumber;
1543  TTF::SetTextFont(fontnumber);
1544 }
1545 
1546 ////////////////////////////////////////////////////////////////////////////////
1547 /// Set text font to specified name.
1548 /// mode : loading flag
1549 /// mode=0 : search if the font exist (kCheck)
1550 /// mode=1 : search the font and load it if it exists (kLoad)
1551 /// font : font name
1552 ///
1553 /// Set text font to specified name. This function returns 0 if
1554 /// the specified font is found, 1 if not.
1555 
1557 {
1558  return TTF::SetTextFont(fontname);
1559 }
1560 
1561 ////////////////////////////////////////////////////////////////////////////////
1562 /// Set current text size.
1563 
1565 {
1566  fTextSize = textsize;
1567  TTF::SetTextSize(textsize);
1568 }
1569 
1570 ////////////////////////////////////////////////////////////////////////////////
1571 /// Clear current window.
1572 
1574 {
1575  if (!fWindows) return;
1576 
1577  if (!gCws->ispixmap && !gCws->double_buffer) {
1578  gdk_window_set_background(gCws->drawing, (GdkColor *) & GetColor(0).color);
1579  gdk_window_clear(gCws->drawing);
1580  GdiFlush();
1581  } else {
1582  SetColor(gGCpxmp, 0);
1583  gdk_win32_draw_rectangle(gCws->drawing, gGCpxmp, 1,
1584  0, 0, gCws->width, gCws->height);
1585  SetColor(gGCpxmp, 1);
1586  }
1587 }
1588 
1589 ////////////////////////////////////////////////////////////////////////////////
1590 /// Delete current pixmap.
1591 
1593 {
1594  CloseWindow1();
1595 }
1596 
1597 ////////////////////////////////////////////////////////////////////////////////
1598 /// Delete current window.
1599 
1601 {
1602  CloseWindow1();
1603 }
1604 
1605 ////////////////////////////////////////////////////////////////////////////////
1606 /// Delete current window.
1607 
1609 {
1610  int wid;
1611 
1612  if (gCws->ispixmap) {
1613  gdk_pixmap_unref(gCws->window);
1614  } else {
1615  gdk_window_destroy(gCws->window, kTRUE);
1616  }
1617 
1618  if (gCws->buffer) {
1619  gdk_pixmap_unref(gCws->buffer);
1620  }
1621  if (gCws->new_colors) {
1622  gdk_colormap_free_colors((GdkColormap *) fColormap,
1623  (GdkColor *)gCws->new_colors, gCws->ncolors);
1624 
1625  delete [] gCws->new_colors;
1626  gCws->new_colors = 0;
1627  }
1628 
1629  GdiFlush();
1630  gCws->open = 0;
1631 
1632  if (!fWindows) return;
1633 
1634  // make first window in list the current window
1635  for (wid = 0; wid < fMaxNumberOfWindows; wid++) {
1636  if (fWindows[wid].open) {
1637  gCws = &fWindows[wid];
1638  return;
1639  }
1640  }
1641  gCws = 0;
1642 }
1643 
1644 ////////////////////////////////////////////////////////////////////////////////
1645 /// Copy the pixmap wid at the position xpos, ypos in the current window.
1646 
1647 void TGWin32::CopyPixmap(int wid, int xpos, int ypos)
1648 {
1649  if (!fWindows) return;
1650 
1651  gTws = &fWindows[wid];
1652  gdk_window_copy_area(gCws->drawing, gGCpxmp, xpos, ypos, gTws->drawing,
1653  0, 0, gTws->width, gTws->height);
1654  GdiFlush();
1655 }
1656 
1657 ////////////////////////////////////////////////////////////////////////////////
1658 /// Draw a box.
1659 /// mode=0 hollow (kHollow)
1660 /// mode=1 solid (kSolid)
1661 
1662 void TGWin32::DrawBox(int x1, int y1, int x2, int y2, EBoxMode mode)
1663 {
1664  if (!fWindows) return;
1665 
1666  Int_t x = TMath::Min(x1, x2);
1667  Int_t y = TMath::Min(y1, y2);
1668  Int_t w = TMath::Abs(x2 - x1);
1669  Int_t h = TMath::Abs(y2 - y1);
1670 
1671  switch (mode) {
1672 
1673  case kHollow:
1676  gdk_win32_draw_rectangle(gCws->drawing, gGCline, 0, x, y, w, h);
1677  break;
1678 
1679  case kFilled:
1682  gdk_win32_draw_rectangle(gCws->drawing, gGCfill, 1, x, y, w, h);
1683  break;
1684 
1685  default:
1686  break;
1687  }
1688 }
1689 
1690 ////////////////////////////////////////////////////////////////////////////////
1691 /// Draw a cell array.
1692 /// x1,y1 : left down corner
1693 /// x2,y2 : right up corner
1694 /// nx,ny : array size
1695 /// ic : array
1696 ///
1697 /// Draw a cell array. The drawing is done with the pixel presicion
1698 /// if (X2-X1)/NX (or Y) is not a exact pixel number the position of
1699 /// the top rigth corner may be wrong.
1700 
1702  Int_t nx, Int_t ny, Int_t *ic)
1703 {
1704  int i, j, icol, ix, iy, w, h, current_icol;
1705 
1706  if (!fWindows) return;
1707 
1708  current_icol = -1;
1709  w = TMath::Max((x2 - x1) / (nx), 1);
1710  h = TMath::Max((y1 - y2) / (ny), 1);
1711  ix = x1;
1712 
1715 
1716  for (i = 0; i < nx; i++) {
1717  iy = y1 - h;
1718  for (j = 0; j < ny; j++) {
1719  icol = ic[i + (nx * j)];
1720  if (icol != current_icol) {
1721  gdk_gc_set_foreground(gGCfill, (GdkColor *) & GetColor(icol).color);
1722  current_icol = icol;
1723  }
1724 
1725  gdk_win32_draw_rectangle(gCws->drawing, gGCfill, kTRUE, ix, iy, w, h);
1726  iy = iy - h;
1727  }
1728  ix = ix + w;
1729  }
1730 }
1731 
1732 ////////////////////////////////////////////////////////////////////////////////
1733 /// Fill area described by polygon.
1734 /// n : number of points
1735 /// xy(2,n) : list of points
1736 
1738 {
1739  int i;
1740  static int lastn = 0;
1741  static GdkPoint *xy = 0;
1742 
1743  if (!fWindows) return;
1744 
1747 
1748  if (lastn!=n) {
1749  delete [] (GdkPoint *)xy;
1750  xy = new GdkPoint[n];
1751  lastn = n;
1752  }
1753  for (i = 0; i < n; i++) {
1754  xy[i].x = xyt[i].fX;
1755  xy[i].y = xyt[i].fY;
1756  }
1757 
1758  if (gFillHollow) {
1759  gdk_win32_draw_lines(gCws->drawing, gGCfill, xy, n);
1760  } else {
1761  gdk_win32_draw_polygon(gCws->drawing, gGCfill, 1, xy, n);
1762  }
1763 }
1764 
1765 ////////////////////////////////////////////////////////////////////////////////
1766 /// Draw a line.
1767 /// x1,y1 : begin of line
1768 /// x2,y2 : end of line
1769 
1770 void TGWin32::DrawLine(int x1, int y1, int x2, int y2)
1771 {
1772  if (!fWindows) return;
1773 
1776 
1777  if (gLineStyle == GDK_LINE_SOLID) {
1778  gdk_draw_line(gCws->drawing, gGCline, x1, y1, x2, y2);
1779  } else {
1780  int i;
1781  gint8 dashes[32];
1782  for (i = 0; i < gDashSize; i++) {
1783  dashes[i] = (gint8) gDashList[i];
1784  }
1785  for (i = gDashSize; i < 32; i++) {
1786  dashes[i] = (gint8) 0;
1787  }
1788  gdk_gc_set_dashes(gGCdash, gDashOffset, dashes, gDashSize);
1789  gdk_draw_line(gCws->drawing, gGCdash, x1, y1, x2, y2);
1790  }
1791 }
1792 
1793 ////////////////////////////////////////////////////////////////////////////////
1794 /// Draw a line through all points.
1795 /// n : number of points
1796 /// xy : list of points
1797 
1799 {
1800  int i;
1801 
1802  if (!fWindows) return;
1803 
1804  Point_t *xy = new Point_t[n];
1805 
1806  for (i = 0; i < n; i++) {
1807  xy[i].fX = xyt[i].fX;
1808  xy[i].fY = xyt[i].fY;
1809  }
1810 
1813 
1814  if (n > 1) {
1815  if (gLineStyle == GDK_LINE_SOLID) {
1816  gdk_win32_draw_lines(gCws->drawing, gGCline, (GdkPoint *)xy, n);
1817  } else {
1818  int i;
1819  gint8 dashes[32];
1820 
1821  for (i = 0; i < gDashSize; i++) {
1822  dashes[i] = (gint8) gDashList[i];
1823  }
1824  for (i = gDashSize; i < 32; i++) {
1825  dashes[i] = (gint8) 0;
1826  }
1827 
1828  gdk_gc_set_dashes(gGCdash, gDashOffset, dashes, gDashSize);
1829  gdk_win32_draw_lines(gCws->drawing, (GdkGC*)gGCdash, (GdkPoint *)xy, n);
1830 
1831  // calculate length of line to update dash offset
1832  for (i = 1; i < n; i++) {
1833  int dx = xy[i].fX - xy[i - 1].fX;
1834  int dy = xy[i].fY - xy[i - 1].fY;
1835 
1836  if (dx < 0) dx = -dx;
1837  if (dy < 0) dy = -dy;
1838  gDashOffset += dx > dy ? dx : dy;
1839  }
1841  }
1842  } else {
1843  gdk_win32_draw_points( gCws->drawing, gLineStyle == GDK_LINE_SOLID ?
1844  gGCline : gGCdash, (GdkPoint *)xy,1);
1845  }
1846  delete [] xy;
1847 }
1848 
1849 ////////////////////////////////////////////////////////////////////////////////
1850 /// Draw n markers with the current attributes at position x, y.
1851 /// n : number of markers to draw
1852 /// xy : x,y coordinates of markers
1853 
1855 {
1856  int i;
1857  static int lastn = 0;
1858  static GdkPoint *xy = 0;
1859 
1860  if (!fWindows) return;
1861 
1864 
1865  if (lastn!=n) {
1866  delete [] (GdkPoint *)xy;
1867  xy = new GdkPoint[n];
1868  lastn = n;
1869  }
1870 
1871  for (i = 0; i < n; i++) {
1872  xy[i].x = xyt[i].fX;
1873  xy[i].y = xyt[i].fY;
1874  }
1875 
1876  if (gMarker.n <= 0) {
1877  gdk_win32_draw_points(gCws->drawing, gGCmark, xy, n);
1878  } else {
1879  int r = gMarker.n / 2;
1880  int m;
1881 
1882  for (m = 0; m < n; m++) {
1883  int hollow = 0;
1884  switch (gMarker.type) {
1885  int i;
1886 
1887  case 0: // hollow circle
1888  gdk_win32_draw_arc(gCws->drawing, gGCmark, kFALSE, xy[m].x-r, xy[m].y-r,
1889  gMarker.n, gMarker.n, 0, 23040);
1890  break;
1891 
1892  case 1: // filled circle
1893  gdk_win32_draw_arc(gCws->drawing, gGCmark, kTRUE, xy[m].x-r, xy[m].y-r,
1894  gMarker.n, gMarker.n, 0, 23040);
1895  break;
1896 
1897  case 2: // hollow polygon
1898  hollow = 1;
1899  case 3: // filled polygon
1900  for (i = 0; i < gMarker.n; i++) {
1901  gMarker.xy[i].x += xy[m].x;
1902  gMarker.xy[i].y += xy[m].y;
1903  }
1904  if (hollow) {
1905  gdk_win32_draw_lines(gCws->drawing, gGCmark, (GdkPoint *)gMarker.xy, gMarker.n);
1906  } else {
1907  gdk_win32_draw_polygon(gCws->drawing, gGCmark, 1, (GdkPoint *)gMarker.xy, gMarker.n);
1908  }
1909  for (i = 0; i < gMarker.n; i++) {
1910  gMarker.xy[i].x -= xy[m].x;
1911  gMarker.xy[i].y -= xy[m].y;
1912  }
1913  break;
1914 
1915  case 4: // segmented line
1916  for (i = 0; i < gMarker.n; i += 2) {
1917  gdk_draw_line(gCws->drawing, gGCmark,
1918  xy[m].x + gMarker.xy[i].x,
1919  xy[m].y + gMarker.xy[i].y,
1920  xy[m].x + gMarker.xy[i + 1].x,
1921  xy[m].y + gMarker.xy[i + 1].y);
1922  }
1923  break;
1924  }
1925  }
1926  }
1927 }
1928 
1929 ////////////////////////////////////////////////////////////////////////////////
1930 /// Return character up vector.
1931 
1933 {
1934  chupx = fCharacterUpX;
1935  chupy = fCharacterUpY;
1936 }
1937 
1938 ////////////////////////////////////////////////////////////////////////////////
1939 /// Return reference to internal color structure associated
1940 /// to color index cid.
1941 
1943 {
1944  XColor_t *col = (XColor_t*) fColors->GetValue(cid);
1945  if (!col) {
1946  col = new XColor_t;
1947  fColors->Add(cid, (Long_t) col);
1948  }
1949  return *col;
1950 }
1951 
1952 ////////////////////////////////////////////////////////////////////////////////
1953 /// Return current window pointer. Protected method used by TGWin32TTF.
1954 
1956 {
1957  return (Window_t)(gCws ? gCws->drawing : 0);
1958 }
1959 
1960 ////////////////////////////////////////////////////////////////////////////////
1961 /// Return desired Graphics Context ("which" maps directly on gGCList[]).
1962 /// Protected method used by TGWin32TTF.
1963 
1964 GdkGC *TGWin32::GetGC(Int_t which) const
1965 {
1966  if (which >= kMAXGC || which < 0) {
1967  Error("GetGC", "trying to get illegal GdkGC (which = %d)", which);
1968  return 0;
1969  }
1970 
1971  return gGClist[which];
1972 }
1973 
1974 ////////////////////////////////////////////////////////////////////////////////
1975 /// Query the double buffer value for the window wid.
1976 
1978 {
1979  if (!fWindows) return 0;
1980 
1981  gTws = &fWindows[wid];
1982 
1983  if (!gTws->open) {
1984  return -1;
1985  } else {
1986  return gTws->double_buffer;
1987  }
1988 }
1989 
1990 ////////////////////////////////////////////////////////////////////////////////
1991 /// Return position and size of window wid.
1992 /// wid : window identifier
1993 /// x,y : window position (output)
1994 /// w,h : window size (output)
1995 /// if wid < 0 the size of the display is returned
1996 
1997 void TGWin32::GetGeometry(int wid, int &x, int &y, unsigned int &w,
1998  unsigned int &h)
1999 {
2000  if (!fWindows) return;
2001 
2002  if (wid < 0) {
2003  x = 0;
2004  y = 0;
2005 
2006  w = gdk_screen_width();
2007  h = gdk_screen_height();
2008  } else {
2009  int depth;
2010  int width, height;
2011 
2012  gTws = &fWindows[wid];
2013  gdk_window_get_geometry((GdkDrawable *) gTws->window, &x, &y,
2014  &width, &height, &depth);
2015 
2016  gdk_window_get_deskrelative_origin((GdkDrawable *) gTws->window, &x, &y);
2017 
2018  if (width > 0 && height > 0) {
2019  gTws->width = width;
2020  gTws->height = height;
2021  }
2022  w = gTws->width;
2023  h = gTws->height;
2024  }
2025 }
2026 
2027 ////////////////////////////////////////////////////////////////////////////////
2028 /// Return hostname on which the display is opened.
2029 
2030 const char *TGWin32::DisplayName(const char *dpyName)
2031 {
2032  return "localhost"; //return gdk_get_display();
2033 }
2034 
2035 ////////////////////////////////////////////////////////////////////////////////
2036 /// Get maximum number of planes.
2037 
2038 void TGWin32::GetPlanes(int &nplanes)
2039 {
2040  nplanes = gdk_visual_get_best_depth();
2041 }
2042 
2043 ////////////////////////////////////////////////////////////////////////////////
2044 /// Get rgb values for color "index".
2045 
2046 void TGWin32::GetRGB(int index, float &r, float &g, float &b)
2047 {
2048  if (index == 0) {
2049  r = g = b = 1.0;
2050  } else if (index == 1) {
2051  r = g = b = 0.0;
2052  } else {
2053  XColor_t &col = GetColor(index);
2054  r = ((float) col.color.red) / ((float) kBIGGEST_RGB_VALUE);
2055  g = ((float) col.color.green) / ((float) kBIGGEST_RGB_VALUE);
2056  b = ((float) col.color.blue) / ((float) kBIGGEST_RGB_VALUE);
2057  }
2058 }
2059 
2060 ////////////////////////////////////////////////////////////////////////////////
2061 /// Return the size of a character string.
2062 /// iw : text width
2063 /// ih : text height
2064 /// mess : message
2065 
2066 void TGWin32::GetTextExtent(unsigned int &w, unsigned int &h, char *mess)
2067 {
2070  TTF::GetTextExtent(w, h, mess);
2071 }
2072 
2073 ////////////////////////////////////////////////////////////////////////////////
2074 /// Return the X11 window identifier.
2075 /// wid : Workstation identifier (input)
2076 
2078 {
2079  if (!fWindows) return 0;
2080  return (Window_t) fWindows[wid].window;
2081 }
2082 
2083 ////////////////////////////////////////////////////////////////////////////////
2084 /// Move the window wid.
2085 /// wid : GdkWindow identifier.
2086 /// x : x new window position
2087 /// y : y new window position
2088 
2089 void TGWin32::MoveWindow(int wid, int x, int y)
2090 {
2091  if (!fWindows) return;
2092 
2093  gTws = &fWindows[wid];
2094  if (!gTws->open) return;
2095 
2096  gdk_window_move((GdkDrawable *) gTws->window, x, y);
2097 }
2098 
2099 ////////////////////////////////////////////////////////////////////////////////
2100 /// Open a new pixmap.
2101 /// w,h : Width and height of the pixmap.
2102 
2103 Int_t TGWin32::OpenPixmap(unsigned int w, unsigned int h)
2104 {
2105  int wval, hval;
2106  int i, wid;
2107  int ww, hh, depth;
2108  wval = w;
2109  hval = h;
2110 
2111  // Select next free window number
2112  again:
2113  for (wid = 0; wid < fMaxNumberOfWindows; wid++) {
2114  if (!fWindows[wid].open) {
2115  fWindows[wid].open = 1;
2116  gCws = &fWindows[wid];
2117  break;
2118  }
2119  }
2120  if (wid == fMaxNumberOfWindows) {
2121  int newsize = fMaxNumberOfWindows + 10;
2122  fWindows = (XWindow_t *) TStorage::ReAlloc(fWindows,
2123  newsize * sizeof(XWindow_t),
2124  fMaxNumberOfWindows *
2125  sizeof(XWindow_t));
2126 
2127  for (i = fMaxNumberOfWindows; i < newsize; i++) fWindows[i].open = 0;
2128  fMaxNumberOfWindows = newsize;
2129  goto again;
2130  }
2131 
2132  depth =gdk_visual_get_best_depth();
2133  gCws->window = (GdkPixmap *) gdk_pixmap_new(GDK_ROOT_PARENT(),wval,hval,depth);
2134  gdk_drawable_get_size((GdkDrawable *) gCws->window, &ww, &hh);
2135 
2136  for (i = 0; i < kMAXGC; i++) {
2137  gdk_gc_set_clip_mask((GdkGC *) gGClist[i], (GdkDrawable *)None);
2138  }
2139 
2140  SetColor(gGCpxmp, 0);
2141  gdk_win32_draw_rectangle(gCws->window,(GdkGC *)gGCpxmp, kTRUE,
2142  0, 0, ww, hh);
2143  SetColor(gGCpxmp, 1);
2144 
2145  // Initialise the window structure
2146  gCws->drawing = gCws->window;
2147  gCws->buffer = 0;
2148  gCws->double_buffer = 0;
2149  gCws->ispixmap = 1;
2150  gCws->clip = 0;
2151  gCws->width = wval;
2152  gCws->height = hval;
2153  gCws->new_colors = 0;
2154 
2155  return wid;
2156 }
2157 
2158 ////////////////////////////////////////////////////////////////////////////////
2159 /// Open window and return window number.
2160 /// Return -1 if window initialization fails.
2161 
2163 {
2164  GdkWindowAttr attributes;
2165  unsigned long attr_mask = 0;
2166  int wid;
2167  int xval, yval;
2168  int wval, hval, depth;
2169 
2170  GdkWindow *wind = (GdkWindow *) win;
2171 
2172  gdk_window_get_geometry(wind, &xval, &yval, &wval, &hval, &depth);
2173 
2174  // Select next free window number
2175 
2176  again:
2177  for (wid = 0; wid < fMaxNumberOfWindows; wid++) {
2178  if (!fWindows[wid].open) {
2179  fWindows[wid].open = 1;
2180  fWindows[wid].double_buffer = 0;
2181  gCws = &fWindows[wid];
2182  break;
2183  }
2184  }
2185 
2186  if (wid == fMaxNumberOfWindows) {
2187  int newsize = fMaxNumberOfWindows + 10;
2188  fWindows =
2189  (XWindow_t *) TStorage::ReAlloc(fWindows,
2190  newsize * sizeof(XWindow_t),
2191  fMaxNumberOfWindows *
2192  sizeof(XWindow_t));
2193 
2194  for (int i = fMaxNumberOfWindows; i < newsize; i++) {
2195  fWindows[i].open = 0;
2196  }
2197 
2198  fMaxNumberOfWindows = newsize;
2199  goto again;
2200  }
2201  // Create window
2202  attributes.wclass = GDK_INPUT_OUTPUT;
2203  attributes.event_mask = 0L; //GDK_ALL_EVENTS_MASK;
2204  attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK |
2205  GDK_PROPERTY_CHANGE_MASK;
2206 // GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
2207  if (xval >= 0) {
2208  attributes.x = xval;
2209  } else {
2210  attributes.x = -1.0 * xval;
2211  }
2212 
2213  if (yval >= 0) {
2214  attributes.y = yval;
2215  } else {
2216  attributes.y = -1.0 * yval;
2217  }
2218  attributes.width = wval;
2219  attributes.height = hval;
2220  attributes.colormap = gdk_colormap_get_system();
2221  attributes.visual = gdk_window_get_visual(wind);
2222  attributes.override_redirect = TRUE;
2223 
2224  if ((attributes.y > 0) && (attributes.x > 0)) {
2225  attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP |
2226  GDK_WA_WMCLASS | GDK_WA_NOREDIR;
2227  } else {
2228  attr_mask = GDK_WA_COLORMAP | GDK_WA_WMCLASS | GDK_WA_NOREDIR;
2229  }
2230 
2231  if (attributes.visual != NULL) {
2232  attr_mask |= GDK_WA_VISUAL;
2233  }
2234  attributes.window_type = GDK_WINDOW_CHILD;
2235  gCws->window = gdk_window_new(wind, &attributes, attr_mask);
2236  HWND window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)gCws->window);
2237  ::ShowWindow(window, SW_SHOWNORMAL);
2238  ::ShowWindow(window, SW_RESTORE);
2239  ::BringWindowToTop(window);
2240 
2241  if (!fUseSysPointers) {
2242  ::SetClassLong(window, GCL_HCURSOR,
2243  (LONG)GDK_CURSOR_XID(fCursors[kPointer]));
2244  }
2245 
2246  // Initialise the window structure
2247 
2248  gCws->drawing = gCws->window;
2249  gCws->buffer = 0;
2250  gCws->double_buffer = 0;
2251  gCws->ispixmap = 0;
2252  gCws->clip = 0;
2253  gCws->width = wval;
2254  gCws->height = hval;
2255  gCws->new_colors = 0;
2256 
2257  return wid;
2258 }
2259 
2260 ////////////////////////////////////////////////////////////////////////////////
2261 /// Query pointer position.
2262 /// ix : X coordinate of pointer
2263 /// iy : Y coordinate of pointer
2264 /// (both coordinates are relative to the origin of the root window)
2265 
2266 void TGWin32::QueryPointer(int &ix, int &iy)
2267 {
2268  //GdkModifierType mask;
2269  //GdkWindow *retw = gdk_window_get_pointer((GdkWindow *) gCws->window,
2270  // &ix, &iy, &mask);
2271  POINT cpt;
2272  GetCursorPos(&cpt);
2273  ix = cpt.x;
2274  iy = cpt.y;
2275 }
2276 
2277 ////////////////////////////////////////////////////////////////////////////////
2278 /// Remove the pixmap pix.
2279 
2280 void TGWin32::RemovePixmap(GdkDrawable *pix)
2281 {
2282  gdk_pixmap_unref((GdkPixmap *)pix);
2283 }
2284 
2285 ////////////////////////////////////////////////////////////////////////////////
2286 /// Request Locator position.
2287 /// x,y : cursor position at moment of button press (output)
2288 /// ctyp : cursor type (input)
2289 /// ctyp=1 tracking cross
2290 /// ctyp=2 cross-hair
2291 /// ctyp=3 rubber circle
2292 /// ctyp=4 rubber band
2293 /// ctyp=5 rubber rectangle
2294 ///
2295 /// mode : input mode
2296 /// mode=0 request
2297 /// mode=1 sample
2298 ///
2299 /// Request locator:
2300 /// return button number 1 = left is pressed
2301 /// 2 = middle is pressed
2302 /// 3 = right is pressed
2303 /// in sample mode:
2304 /// 11 = left is released
2305 /// 12 = middle is released
2306 /// 13 = right is released
2307 /// -1 = nothing is pressed or released
2308 /// -2 = leave the window
2309 /// else = keycode (keyboard is pressed)
2310 
2312 {
2313  static int xloc = 0;
2314  static int yloc = 0;
2315  static int xlocp = 0;
2316  static int ylocp = 0;
2317  static GdkCursor *cursor = NULL;
2318  Int_t xtmp, ytmp;
2319 
2320  GdkEvent *event;
2321  int button_press;
2322  int radius;
2323 
2324  // Change the cursor shape
2325  if (cursor == NULL) {
2326  if (ctyp > 1) {
2327  gdk_window_set_cursor((GdkWindow *)gCws->window, (GdkCursor *)gNullCursor);
2328  gdk_gc_set_foreground((GdkGC *) gGCecho, &GetColor(0).color);
2329  } else {
2330  if (fUseSysPointers)
2331  cursor = gdk_syscursor_new((ULong_t)IDC_CROSS);
2332  else
2333  cursor = gdk_cursor_new((GdkCursorType)GDK_CROSSHAIR);
2334  gdk_window_set_cursor((GdkWindow *)gCws->window, (GdkCursor *)cursor);
2335  }
2336  }
2337 
2338  // Event loop
2339  button_press = 0;
2340 
2341  // Set max response time to 2 minutes to avoid timeout
2342  // in TGWin32ProxyBase::ForwardCallBack during RequestLocator
2344  while (button_press == 0) {
2345  event = gdk_event_get();
2346 
2347  switch (ctyp) {
2348 
2349  case 1:
2350  break;
2351 
2352  case 2:
2353  gdk_draw_line(gCws->window, gGCecho, xloc, 0, xloc, gCws->height);
2354  gdk_draw_line(gCws->window, gGCecho, 0, yloc, gCws->width, yloc);
2355  break;
2356 
2357  case 3:
2358  radius = (int) TMath::Sqrt((double)((xloc - xlocp) * (xloc - xlocp) +
2359  (yloc - ylocp) * (yloc - ylocp)));
2360 
2362  xlocp - radius, ylocp - radius,
2363  2 * radius, 2 * radius, 0, 23040);
2364  break;
2365 
2366  case 4:
2367  gdk_draw_line(gCws->window, gGCecho, xlocp, ylocp, xloc, yloc);
2368  break;
2369 
2370  case 5:
2372  TMath::Min(xlocp, xloc), TMath::Min(ylocp, yloc),
2373  TMath::Abs(xloc - xlocp), TMath::Abs(yloc - ylocp));
2374  break;
2375 
2376  default:
2377  break;
2378  }
2379 
2380  xloc = event->button.x;
2381  yloc = event->button.y;
2382 
2383  switch (event->type) {
2384 
2385  case GDK_LEAVE_NOTIFY:
2386  if (mode == 0) {
2387  while (1) {
2388  event = gdk_event_get();
2389 
2390  if (event->type == GDK_ENTER_NOTIFY) {
2391  gdk_event_free(event);
2392  break;
2393  }
2394  gdk_event_free(event);
2395  }
2396  } else {
2397  button_press = -2;
2398  }
2399  break;
2400 
2401  case GDK_BUTTON_PRESS:
2402  button_press = event->button.button;
2403  xlocp = event->button.x;
2404  ylocp = event->button.y;
2405  gdk_cursor_unref(cursor);
2406  cursor = 0;
2407  break;
2408 
2409  case GDK_BUTTON_RELEASE:
2410  if (mode == 1) {
2411  button_press = 10 + event->button.button;
2412  xlocp = event->button.x;
2413  ylocp = event->button.y;
2414  }
2415  break;
2416 
2417  case GDK_KEY_PRESS:
2418  if (mode == 1) {
2419  button_press = event->key.keyval;
2420  xlocp = event->button.x;
2421  ylocp = event->button.y;
2422  }
2423  break;
2424 
2425  case GDK_KEY_RELEASE:
2426  if (mode == 1) {
2427  button_press = -1 * (int)(event->key.keyval);
2428  xlocp = event->button.x;
2429  ylocp = event->button.y;
2430  }
2431  break;
2432 
2433  default:
2434  break;
2435  }
2436 
2437  xtmp = event->button.x;
2438  ytmp = event->button.y;
2439 
2440  gdk_event_free(event);
2441 
2442  if (mode == 1) {
2443  if (button_press == 0) {
2444  button_press = -1;
2445  }
2446  break;
2447  }
2448  }
2450 
2451  x = xtmp;
2452  y = ytmp;
2453 
2454  return button_press;
2455 }
2456 
2457 ////////////////////////////////////////////////////////////////////////////////
2458 /// Request a string.
2459 /// x,y : position where text is displayed
2460 /// text : text displayed (input), edited text (output)
2461 ///
2462 /// Request string:
2463 /// text is displayed and can be edited with Emacs-like keybinding
2464 /// return termination code (0 for ESC, 1 for RETURN)
2465 
2467 {
2468  static GdkCursor *cursor = NULL;
2469  static int percent = 0; // bell volume
2470  static GdkWindow *CurWnd;
2471  HWND focuswindow;
2472  GdkEvent *event;
2473  KeySym keysym;
2474  int key = -1;
2475  int len_text = strlen(text);
2476  int nt; // defined length of text
2477  int pt; // cursor position in text
2478 
2479  CurWnd = (GdkWindow *)gCws->window;
2480  // change the cursor shape
2481  if (cursor == NULL) {
2482  if (fUseSysPointers)
2483  cursor = gdk_syscursor_new((ULong_t)IDC_HELP);
2484  else
2485  cursor = gdk_cursor_new((GdkCursorType)GDK_QUESTION_ARROW);
2486  }
2487  if (cursor != 0) {
2488  gdk_window_set_cursor(CurWnd, cursor);
2489  }
2490  for (nt = len_text; nt > 0 && text[nt - 1] == ' '; nt--);
2491 
2492  pt = nt;
2493  focuswindow = ::SetFocus((HWND)GDK_DRAWABLE_XID(CurWnd));
2494 
2495  // Set max response time to 2 minutes to avoid timeout
2496  // in TGWin32ProxyBase::ForwardCallBack during RequestString
2500  do {
2501  char tmp[2];
2502  char keybuf[8];
2503  char nbytes;
2504  UInt_t dx, ddx, h;
2505  int i;
2506 
2507  if (EventsPending()) {
2508  event = gdk_event_get();
2509  } else {
2511  ::SleepEx(10, kTRUE);
2512  continue;
2513  }
2514 
2515  DrawText(x, y, 0.0, 1.0, text, kOpaque);
2516  TTF::GetTextExtent(dx, h, text);
2517  DrawText(x+dx, y, 0.0, 1.0, " ", kOpaque);
2518 
2519  if (pt == 0) {
2520  dx = 0;
2521  } else {
2522  char *stmp = new char[pt+1];
2523  strncpy(stmp, text, pt);
2524  stmp[pt] = '\0';
2525  TTF::GetTextExtent(ddx, h, stmp);
2526  dx = ddx;
2527  delete[] stmp;
2528  }
2529 
2530  if (pt < len_text) {
2531  tmp[0] = text[pt];
2532  tmp[1] = '\0';
2533  DrawText(x+dx, y, 0.0, 1.0, tmp, kOpaque);
2534  } else {
2535  DrawText(x+dx, y, 0.0, 1.0, " ", kOpaque);
2536  }
2537 
2538  if (event != NULL) {
2539  switch (event->type) {
2540  case GDK_BUTTON_PRESS:
2541  case GDK_ENTER_NOTIFY:
2542  focuswindow = ::SetFocus((HWND)GDK_DRAWABLE_XID(CurWnd));
2543  break;
2544 
2545  case GDK_LEAVE_NOTIFY:
2546  ::SetFocus(focuswindow);
2547  break;
2548  case GDK_KEY_PRESS:
2549  nbytes = event->key.length;
2550  for (i = 0; i < nbytes; i++) {
2551  keybuf[i] = event->key.string[i];
2552  }
2553  keysym = event->key.keyval;
2554  switch (keysym) { // map cursor keys
2555  case GDK_BackSpace:
2556  keybuf[0] = 0x08; // backspace
2557  nbytes = 1;
2558  break;
2559  case GDK_Return:
2560  keybuf[0] = 0x0d; // return
2561  nbytes = 1;
2562  break;
2563  case GDK_Delete:
2564  keybuf[0] = 0x7f; // del
2565  nbytes = 1;
2566  break;
2567  case GDK_Escape:
2568  keybuf[0] = 0x1b; // esc
2569  nbytes = 1;
2570  break;
2571  case GDK_Home:
2572  keybuf[0] = 0x01; // home
2573  nbytes = 1;
2574  break;
2575  case GDK_Left:
2576  keybuf[0] = 0x02; // backward
2577  nbytes = 1;
2578  break;
2579  case GDK_Right:
2580  keybuf[0] = 0x06; // forward
2581  nbytes = 1;
2582  break;
2583  case GDK_End:
2584  keybuf[0] = 0x05; // end
2585  nbytes = 1;
2586  break;
2587  }
2588  if (nbytes == 1) {
2589  if (isascii(keybuf[0]) && isprint(keybuf[0])) {
2590  // insert character
2591  if (nt < len_text) {
2592  nt++;
2593  }
2594  for (i = nt - 1; i > pt; i--) {
2595  text[i] = text[i - 1];
2596  }
2597  if (pt < len_text) {
2598  text[pt] = keybuf[0];
2599  pt++;
2600  }
2601  } else {
2602  switch (keybuf[0]) {
2603  // Emacs-like editing keys
2604 
2605  case 0x08: //'\010': // backspace
2606  case 0x7f: //'\177': // delete
2607  // delete backward
2608  if (pt > 0) {
2609  for (i = pt; i < nt; i++) {
2610  text[i - 1] = text[i];
2611  }
2612  text[nt - 1] = ' ';
2613  nt--;
2614  pt--;
2615  }
2616  break;
2617  case 0x01: //'\001': // ^A
2618  // beginning of line
2619  pt = 0;
2620  break;
2621  case 0x02: //'\002': // ^B
2622  // move backward
2623  if (pt > 0) {
2624  pt--;
2625  }
2626  break;
2627  case 0x04: //'\004': // ^D
2628  // delete forward
2629  if (pt > 0) {
2630  for (i = pt; i < nt; i++) {
2631  text[i - 1] = text[i];
2632  }
2633  text[nt - 1] = ' ';
2634  pt--;
2635  }
2636  break;
2637  case 0x05: //'\005': // ^E
2638  // end of line
2639  pt = nt;
2640  break;
2641 
2642  case 0x06: //'\006': // ^F
2643  // move forward
2644  if (pt < nt) {
2645  pt++;
2646  }
2647  break;
2648  case 0x0b: //'\013': // ^K
2649  // delete to end of line
2650  for (i = pt; i < nt; i++)
2651  text[i] = ' ';
2652  nt = pt;
2653  break;
2654  case 0x14: //'\024': // ^T
2655  // transpose
2656  if (pt > 0) {
2657  char c = text[pt];
2658  text[pt] = text[pt - 1];
2659  text[pt - 1] = c;
2660  }
2661  break;
2662  case 0x0A: //'\012': // newline
2663  case 0x0D: //'\015': // return
2664  key = 1;
2665  break;
2666  case 0x1B: //'\033': // escape
2667  key = 0;
2668  break;
2669 
2670  default:
2671  gSystem->Beep();
2672  break;
2673  }
2674  }
2675  }
2676  default:
2677  SetInputFocus((Window_t)gCws->window);
2678  break;
2679  }
2680  gdk_event_free(event);
2681  }
2682  } while (key < 0);
2684  ::SetFocus(focuswindow);
2685  SetInputFocus((Window_t)CurWnd);
2686 
2687  gdk_window_set_cursor(CurWnd, (GdkCursor *)fCursors[kPointer]);
2688  if (cursor != 0) {
2689  gdk_cursor_unref(cursor);
2690  cursor = 0;
2691  }
2692 
2693  return key;
2694 }
2695 
2696 ////////////////////////////////////////////////////////////////////////////////
2697 /// Rescale the window wid.
2698 /// wid : GdkWindow identifier
2699 /// w : Width
2700 /// h : Heigth
2701 
2702 void TGWin32::RescaleWindow(int wid, unsigned int w, unsigned int h)
2703 {
2704  int i;
2705 
2706  if (!fWindows) return;
2707 
2708  gTws = &fWindows[wid];
2709  if (!gTws->open)
2710  return;
2711 
2712  // don't do anything when size did not change
2713  if (gTws->width == w && gTws->height == h)
2714  return;
2715 
2716  gdk_window_resize((GdkWindow *) gTws->window, w, h);
2717 
2718  if (gTws->buffer) {
2719  // don't free and recreate pixmap when new pixmap is smaller
2720  if (gTws->width < w || gTws->height < h) {
2721  gdk_pixmap_unref(gTws->buffer);
2722  gTws->buffer = gdk_pixmap_new(GDK_ROOT_PARENT(), // NULL,
2723  w, h, gdk_visual_get_best_depth());
2724  }
2725  for (i = 0; i < kMAXGC; i++) {
2726  gdk_gc_set_clip_mask(gGClist[i], None);
2727  }
2728  SetColor(gGCpxmp, 0);
2729  gdk_win32_draw_rectangle(gTws->buffer, gGCpxmp, 1, 0, 0, w, h);
2730  SetColor(gGCpxmp, 1);
2731 
2732  if (gTws->double_buffer) gTws->drawing = gTws->buffer;
2733  }
2734  gTws->width = w;
2735  gTws->height = h;
2736 }
2737 
2738 ////////////////////////////////////////////////////////////////////////////////
2739 /// Resize a pixmap.
2740 /// wid : pixmap to be resized
2741 /// w,h : Width and height of the pixmap
2742 
2743 int TGWin32::ResizePixmap(int wid, unsigned int w, unsigned int h)
2744 {
2745  int wval, hval;
2746  int i;
2747  int ww, hh, depth;
2748  wval = w;
2749  hval = h;
2750 
2751  if (!fWindows) return 0;
2752 
2753  gTws = &fWindows[wid];
2754 
2755  // don't do anything when size did not change
2756  // if (gTws->width == wval && gTws->height == hval) return 0;
2757 
2758  // due to round-off errors in TPad::Resize() we might get +/- 1 pixel
2759  // change, in those cases don't resize pixmap
2760  if (gTws->width >= wval - 1 && gTws->width <= wval + 1 &&
2761  gTws->height >= hval - 1 && gTws->height <= hval + 1)
2762  return 0;
2763 
2764  // don't free and recreate pixmap when new pixmap is smaller
2765  if (gTws->width < wval || gTws->height < hval) {
2766  gdk_pixmap_unref((GdkPixmap *)gTws->window);
2767  depth = gdk_visual_get_best_depth();
2768  gTws->window = gdk_pixmap_new(GDK_ROOT_PARENT(), wval, hval, depth);
2769  }
2770 
2771  gdk_drawable_get_size(gTws->window, &ww, &hh);
2772 
2773  for (i = 0; i < kMAXGC; i++) {
2774  gdk_gc_set_clip_mask((GdkGC *) gGClist[i], (GdkDrawable *)None);
2775  }
2776 
2777  SetColor(gGCpxmp, 0);
2778  gdk_win32_draw_rectangle(gTws->window,(GdkGC *)gGCpxmp, kTRUE, 0, 0, ww, hh);
2779  SetColor(gGCpxmp, 1);
2780 
2781  // Initialise the window structure
2782  gTws->drawing = gTws->window;
2783  gTws->width = wval;
2784  gTws->height = hval;
2785  return 1;
2786 }
2787 
2788 ////////////////////////////////////////////////////////////////////////////////
2789 /// Resize the current window if necessary.
2790 
2792 {
2793  int i;
2794  int xval = 0, yval = 0;
2795  GdkWindow *win, *root = NULL;
2796  int wval = 0, hval = 0, depth = 0;
2797 
2798  if (!fWindows) return;
2799 
2800  gTws = &fWindows[wid];
2801 
2802  win = (GdkWindow *) gTws->window;
2803  gdk_window_get_geometry(win, &xval, &yval,
2804  &wval, &hval, &depth);
2805 
2806  // don't do anything when size did not change
2807  if (gTws->width == wval && gTws->height == hval) {
2808  return;
2809  }
2810 
2811  gdk_window_resize((GdkWindow *) gTws->window, wval, hval);
2812 
2813  if (gTws->buffer) {
2814  if (gTws->width < wval || gTws->height < hval) {
2815  gdk_pixmap_unref((GdkPixmap *)gTws->buffer);
2816  depth = gdk_visual_get_best_depth();
2817  gTws->buffer = (GdkPixmap *) gdk_pixmap_new(GDK_ROOT_PARENT(),
2818  wval, hval, depth);
2819  }
2820 
2821  for (i = 0; i < kMAXGC; i++) {
2822  gdk_gc_set_clip_mask((GdkGC *) gGClist[i], (GdkDrawable *)None);
2823  }
2824 
2825  SetColor(gGCpxmp, 0);
2826  gdk_win32_draw_rectangle(gTws->buffer,(GdkGC *)gGCpxmp, kTRUE, 0, 0, wval, hval);
2827 
2828  SetColor(gGCpxmp, 1);
2829 
2830  if (gTws->double_buffer) gTws->drawing = gTws->buffer;
2831  }
2832 
2833  gTws->width = wval;
2834  gTws->height = hval;
2835 }
2836 
2837 ////////////////////////////////////////////////////////////////////////////////
2838 /// Select window to which subsequent output is directed.
2839 
2841 {
2842  int i;
2843  GdkRectangle rect;
2844 
2845  if (!fWindows || wid < 0 || wid >= fMaxNumberOfWindows || !fWindows[wid].open) {
2846  return;
2847  }
2848 
2849  gCws = &fWindows[wid];
2850 
2851  if (gCws->clip && !gCws->ispixmap && !gCws->double_buffer) {
2852  rect.x = gCws->xclip;
2853  rect.y = gCws->yclip;
2854  rect.width = gCws->wclip;
2855  rect.height = gCws->hclip;
2856 
2857  for (i = 0; i < kMAXGC; i++) {
2858  gdk_gc_set_clip_rectangle((GdkGC *) gGClist[i], &rect);
2859  }
2860  } else {
2861  for (i = 0; i < kMAXGC; i++) {
2862  gdk_gc_set_clip_mask((GdkGC *) gGClist[i], (GdkDrawable *)None);
2863  }
2864  }
2865 }
2866 
2867 ////////////////////////////////////////////////////////////////////////////////
2868 /// Set character up vector.
2869 
2871 {
2872  if (chupx == fCharacterUpX && chupy == fCharacterUpY) return;
2873 
2874  if (chupx == 0 && chupy == 0) {
2875  fTextAngle = 0;
2876  } else if (chupx == 0 && chupy == 1) {
2877  fTextAngle = 0;
2878  } else if (chupx == -1 && chupy == 0) {
2879  fTextAngle = 90;
2880  } else if (chupx == 0 && chupy == -1) {
2881  fTextAngle = 180;
2882  } else if (chupx == 1 && chupy == 0) {
2883  fTextAngle = 270;
2884  } else {
2885  fTextAngle =
2886  ((TMath::
2887  ACos(chupx / TMath::Sqrt(chupx * chupx + chupy * chupy)) *
2888  180.) / 3.14159) - 90;
2889  if (chupy < 0) fTextAngle = 180 - fTextAngle;
2890  if (TMath::Abs(fTextAngle) <= 0.01) fTextAngle = 0;
2891  }
2892  fCharacterUpX = chupx;
2893  fCharacterUpY = chupy;
2894 }
2895 
2896 ////////////////////////////////////////////////////////////////////////////////
2897 /// Turn off the clipping for the window wid.
2898 
2899 void TGWin32::SetClipOFF(int wid)
2900 {
2901  if (!fWindows) return;
2902 
2903  gTws = &fWindows[wid];
2904  gTws->clip = 0;
2905 
2906  for (int i = 0; i < kMAXGC; i++) {
2907  gdk_gc_set_clip_mask((GdkGC *) gGClist[i], (GdkDrawable *)None);
2908  }
2909 }
2910 
2911 ////////////////////////////////////////////////////////////////////////////////
2912 /// Set clipping region for the window wid.
2913 /// wid : GdkWindow indentifier
2914 /// x,y : origin of clipping rectangle
2915 /// w,h : size of clipping rectangle;
2916 
2917 void TGWin32::SetClipRegion(int wid, int x, int y, unsigned int w,
2918  unsigned int h)
2919 {
2920  if (!fWindows) return;
2921 
2922  gTws = &fWindows[wid];
2923  gTws->xclip = x;
2924  gTws->yclip = y;
2925  gTws->wclip = w;
2926  gTws->hclip = h;
2927  gTws->clip = 1;
2928  GdkRectangle rect;
2929 
2930  if (gTws->clip && !gTws->ispixmap && !gTws->double_buffer) {
2931  rect.x = gTws->xclip;
2932  rect.y = gTws->yclip;
2933  rect.width = gTws->wclip;
2934  rect.height = gTws->hclip;
2935 
2936  for (int i = 0; i < kMAXGC; i++) {
2937  gdk_gc_set_clip_rectangle((GdkGC *)gGClist[i], &rect);
2938  }
2939  }
2940 }
2941 
2942 ////////////////////////////////////////////////////////////////////////////////
2943 /// Return pixel value associated to specified ROOT color number.
2944 
2946 {
2947  TColor *color = gROOT->GetColor(ci);
2948  if (color)
2949  SetRGB(ci, color->GetRed(), color->GetGreen(), color->GetBlue());
2950  XColor_t &col = GetColor(ci);
2951  return col.color.pixel;
2952 }
2953 
2954 ////////////////////////////////////////////////////////////////////////////////
2955 /// Set the foreground color in GdkGC.
2956 
2957 void TGWin32::SetColor(GdkGC *gc, int ci)
2958 {
2959  GdkGCValues gcvals;
2960  GdkColor color;
2961 
2962  if (ci<=0) ci = 10; //white
2963 
2964  TColor *clr = gROOT->GetColor(ci);
2965  if (clr)
2966  SetRGB(ci, clr->GetRed(), clr->GetGreen(), clr->GetBlue());
2967 
2968  XColor_t &col = GetColor(ci);
2969  if (fColormap && !col.fDefined) {
2970  col = GetColor(0);
2971  } else if (!fColormap && (ci < 0 || ci > 1)) {
2972  col = GetColor(0);
2973  }
2974 
2975  if (fDrawMode == kXor) {
2976  gdk_gc_get_values(gc, &gcvals);
2977 
2978  color.pixel = col.color.pixel ^ gcvals.background.pixel;
2979  color.red = GetRValue(color.pixel);
2980  color.green = GetGValue(color.pixel);
2981  color.blue = GetBValue(color.pixel);
2982  gdk_gc_set_foreground(gc, &color);
2983 
2984  } else {
2985  gdk_gc_set_foreground(gc, &col.color);
2986 
2987  // make sure that foreground and background are different
2988  gdk_gc_get_values(gc, &gcvals);
2989 
2990  if (gcvals.foreground.pixel != gcvals.background.pixel) {
2991  gdk_gc_set_background(gc, &GetColor(!ci).color);
2992  }
2993  }
2994 }
2995 
2996 ////////////////////////////////////////////////////////////////////////////////
2997 /// Set the cursor.
2998 
2999 void TGWin32::SetCursor(int wid, ECursor cursor)
3000 {
3001  if (!fWindows) return;
3002 
3003  gTws = &fWindows[wid];
3004  gdk_window_set_cursor((GdkWindow *)gTws->window, (GdkCursor *)fCursors[cursor]);
3005 }
3006 
3007 ////////////////////////////////////////////////////////////////////////////////
3008 /// Set the specified cursor.
3009 
3011 {
3012  if (!id) return;
3013 
3014  static GdkWindow *lid = 0;
3015  static GdkCursor *lcur = 0;
3016 
3017  if ((lid == (GdkWindow *)id) && (lcur==(GdkCursor *)curid)) return;
3018  lid = (GdkWindow *)id;
3019  lcur = (GdkCursor *)curid;
3020 
3021  gdk_window_set_cursor((GdkWindow *) id, (GdkCursor *)curid);
3022 }
3023 
3024 ////////////////////////////////////////////////////////////////////////////////
3025 /// Set the double buffer on/off on window wid.
3026 /// wid : GdkWindow identifier.
3027 /// 999 means all the opened windows.
3028 /// mode : 1 double buffer is on
3029 /// 0 double buffer is off
3030 
3031 void TGWin32::SetDoubleBuffer(int wid, int mode)
3032 {
3033  if (!fWindows) return;
3034 
3035  if (wid == 999) {
3036  for (int i = 0; i < fMaxNumberOfWindows; i++) {
3037  gTws = &fWindows[i];
3038  if (gTws->open) {
3039  switch (mode) {
3040  case 1:
3042  break;
3043  default:
3045  break;
3046  }
3047  }
3048  }
3049  } else {
3050  gTws = &fWindows[wid];
3051  if (!gTws->open) return;
3052 
3053  switch (mode) {
3054  case 1:
3056  return;
3057  default:
3059  return;
3060  }
3061  }
3062 }
3063 
3064 ////////////////////////////////////////////////////////////////////////////////
3065 /// Turn double buffer mode off.
3066 
3068 {
3069  if (!gTws->double_buffer) return;
3070  gTws->double_buffer = 0;
3071  gTws->drawing = gTws->window;
3072 }
3073 
3074 ////////////////////////////////////////////////////////////////////////////////
3075 /// Turn double buffer mode on.
3076 
3078 {
3079  if (!fWindows || gTws->double_buffer || gTws->ispixmap) return;
3080 
3081  if (!gTws->buffer) {
3082  gTws->buffer = gdk_pixmap_new(GDK_ROOT_PARENT(), //NULL,
3083  gTws->width, gTws->height,
3084  gdk_visual_get_best_depth());
3085  SetColor(gGCpxmp, 0);
3086  gdk_win32_draw_rectangle(gTws->buffer, gGCpxmp, 1, 0, 0, gTws->width,
3087  gTws->height);
3088  SetColor(gGCpxmp, 1);
3089  }
3090  for (int i = 0; i < kMAXGC; i++) {
3091  gdk_gc_set_clip_mask(gGClist[i], None);
3092  }
3093  gTws->double_buffer = 1;
3094  gTws->drawing = gTws->buffer;
3095 }
3096 
3097 ////////////////////////////////////////////////////////////////////////////////
3098 /// Set the drawing mode.
3099 /// mode : drawing mode
3100 /// mode=1 copy
3101 /// mode=2 xor
3102 /// mode=3 invert
3103 /// mode=4 set the suitable mode for cursor echo according to
3104 /// the vendor
3105 
3107 {
3108  int i;
3109 
3110  switch (mode) {
3111  case kCopy:
3112  for (i = 0; i < kMAXGC; i++) {
3113  gdk_gc_set_function(gGClist[i], GDK_COPY);
3114  }
3115  break;
3116 
3117  case kXor:
3118  for (i = 0; i < kMAXGC; i++) {
3119  gdk_gc_set_function(gGClist[i], GDK_XOR);
3120  }
3121  break;
3122 
3123  case kInvert:
3124  for (i = 0; i < kMAXGC; i++) {
3125  gdk_gc_set_function(gGClist[i], GDK_INVERT);
3126  }
3127  break;
3128  }
3129  fDrawMode = mode;
3130 }
3131 
3132 ////////////////////////////////////////////////////////////////////////////////
3133 /// Set color index for fill areas.
3134 
3136 {
3137  Int_t indx = Int_t(cindex);
3138 
3139  if (!gStyle->GetFillColor() && cindex > 1) {
3140  indx = 0;
3141  }
3142 
3143  fFillColor = indx;
3145 }
3146 
3147 ////////////////////////////////////////////////////////////////////////////////
3148 ///
3149 
3151 {
3152  if (fFillColor >= 0) {
3154  }
3155 
3156  // invalidate fill pattern
3157  if (gFillPattern != NULL) {
3158  gdk_pixmap_unref(gFillPattern);
3159  gFillPattern = NULL;
3160  }
3162 }
3163 
3164 ////////////////////////////////////////////////////////////////////////////////
3165 /// Set fill area style.
3166 /// fstyle : compound fill area interior style
3167 /// fstyle = 1000*interiorstyle + styleindex
3168 
3170 {
3171  if (fFillStyle==fstyle) return;
3172 
3173  fFillStyle = fstyle;
3175 }
3176 
3177 ////////////////////////////////////////////////////////////////////////////////
3178 /// Set fill area style index.
3179 
3181 {
3182  static int current_fasi = 0;
3183 
3184  Int_t style = fFillStyle / 1000;
3185  Int_t fasi = fFillStyle % 1000;
3186 
3187  switch (style) {
3188 
3189  case 1: // solid
3190  gFillHollow = 0;
3191  gdk_gc_set_fill(gGCfill, GDK_SOLID);
3192  break;
3193 
3194  case 2: // pattern
3195  gFillHollow = 1;
3196  break;
3197 
3198  case 3: // hatch
3199  gFillHollow = 0;
3200  gdk_gc_set_fill(gGCfill, GDK_STIPPLED);
3201 
3202  if (fasi != current_fasi) {
3203  if (gFillPattern != NULL) {
3204  gdk_pixmap_unref(gFillPattern);
3205  gFillPattern = NULL;
3206  }
3207  int stn = (fasi >= 1 && fasi <=25) ? fasi : 2;
3208  gFillPattern = gdk_bitmap_create_from_data(GDK_ROOT_PARENT(),
3209  (const char *)gStipples[stn], 16, 16);
3210  gdk_gc_set_stipple(gGCfill, gFillPattern);
3211  current_fasi = fasi;
3212  }
3213  break;
3214 
3215  default:
3216  gFillHollow = 1;
3217  }
3218 
3220 }
3221 
3222 ////////////////////////////////////////////////////////////////////////////////
3223 /// Set input on or off.
3224 
3225 void TGWin32::SetInput(int inp)
3226 {
3227  EnableWindow((HWND) GDK_DRAWABLE_XID(gCws->window), inp);
3228 }
3229 
3230 ////////////////////////////////////////////////////////////////////////////////
3231 /// Set color index for lines.
3232 
3234 {
3235  if ((cindex < 0) || (cindex==fLineColor)) return;
3236 
3237  fLineColor = cindex;
3239 }
3240 
3241 ////////////////////////////////////////////////////////////////////////////////
3242 ///
3243 
3245 {
3249 }
3250 
3251 ////////////////////////////////////////////////////////////////////////////////
3252 /// Set line type.
3253 /// n : length of dash list
3254 /// dash(n) : dash segment lengths
3255 ///
3256 /// if n <= 0 use solid lines
3257 /// if n > 0 use dashed lines described by DASH(N)
3258 /// e.g. N=4,DASH=(6,3,1,3) gives a dashed-dotted line with dash length 6
3259 /// and a gap of 7 between dashes
3260 
3261 void TGWin32::SetLineType(int n, int *dash)
3262 {
3263  if (n <= 0) {
3264  gLineStyle = GDK_LINE_SOLID;
3265  gdk_gc_set_line_attributes(gGCline, fLineWidth,
3266  (GdkLineStyle)gLineStyle,
3267  (GdkCapStyle) gCapStyle,
3268  (GdkJoinStyle) gJoinStyle);
3269  } else {
3270  int i;
3271  gDashSize = TMath::Min((int)sizeof(gDashList),n);
3272  gDashLength = 0;
3273  for (i = 0; i < gDashSize; i++) {
3274  gDashList[i] = dash[i];
3275  gDashLength += gDashList[i];
3276  }
3277  gDashOffset = 0;
3278  gLineStyle = GDK_LINE_ON_OFF_DASH;
3279  gdk_gc_set_line_attributes(gGCdash, fLineWidth,
3280  (GdkLineStyle) gLineStyle,
3281  (GdkCapStyle) gCapStyle,
3282  (GdkJoinStyle) gJoinStyle);
3283  }
3284  fPenModified = kFALSE;
3285 }
3286 
3287 ////////////////////////////////////////////////////////////////////////////////
3288 /// Set line style.
3289 
3291 {
3292  if (fLineStyle == lstyle) return;
3293 
3294  fLineStyle = lstyle;
3295  fPenModified = kTRUE;
3296 }
3297 
3298 ////////////////////////////////////////////////////////////////////////////////
3299 /// Update line style
3300 
3302 {
3303  static Int_t dashed[2] = { 3, 3 };
3304  static Int_t dotted[2] = { 1, 2 };
3305  static Int_t dasheddotted[4] = { 3, 4, 1, 4 };
3306 
3307  if (fLineStyle <= 1) {
3308  SetLineType(0, 0);
3309  } else if (fLineStyle == 2) {
3310  SetLineType(2, dashed);
3311  } else if (fLineStyle == 3) {
3312  SetLineType(2, dotted);
3313  } else if (fLineStyle == 4) {
3314  SetLineType(4, dasheddotted);
3315  } else {
3317  TObjArray *tokens = st.Tokenize(" ");
3318  Int_t nt;
3319  nt = tokens->GetEntries();
3320  Int_t *linestyle = new Int_t[nt];
3321  for (Int_t j = 0; j<nt; j++) {
3322  Int_t it;
3323  sscanf(((TObjString*)tokens->At(j))->GetName(), "%d", &it);
3324  linestyle[j] = (Int_t)(it/4);
3325  }
3326  SetLineType(nt,linestyle);
3327  delete [] linestyle;
3328  delete tokens;
3329  }
3330  fPenModified = kFALSE;
3331 }
3332 
3333 ////////////////////////////////////////////////////////////////////////////////
3334 /// Set line width.
3335 /// width : line width in pixels
3336 
3338 {
3339  if ((fLineWidth==width) || (width<0)) return;
3340 
3341  if (width == 1) {
3342  fLineWidth = 0;
3343  } else {
3344  fLineWidth = width;
3345  }
3346 
3347  fPenModified = kTRUE;
3348 }
3349 
3350 ////////////////////////////////////////////////////////////////////////////////
3351 /// Set color index for markers.
3352 
3354 {
3355  if ((cindex<0) || (cindex==fMarkerColor)) return;
3356  fMarkerColor = cindex;
3358 }
3359 
3360 ////////////////////////////////////////////////////////////////////////////////
3361 ///
3362 
3364 {
3367 }
3368 
3369 ////////////////////////////////////////////////////////////////////////////////
3370 /// Set marker size index.
3371 /// msize : marker scale factor
3372 
3374 {
3375  if ((msize==fMarkerSize) || (msize<0)) return;
3376 
3377  fMarkerSize = msize;
3379 }
3380 
3381 ////////////////////////////////////////////////////////////////////////////////
3382 /// Set marker type.
3383 /// type : marker type
3384 /// n : length of marker description
3385 /// xy : list of points describing marker shape
3386 ///
3387 /// if n == 0 marker is a single point
3388 /// if TYPE == 0 marker is hollow circle of diameter N
3389 /// if TYPE == 1 marker is filled circle of diameter N
3390 /// if TYPE == 2 marker is a hollow polygon describe by line XY
3391 /// if TYPE == 3 marker is a filled polygon describe by line XY
3392 /// if TYPE == 4 marker is described by segmented line XY
3393 /// e.g. TYPE=4,N=4,XY=(-3,0,3,0,0,-3,0,3) sets a plus shape of 7x7 pixels
3394 
3395 void TGWin32::SetMarkerType(int type, int n, GdkPoint * xy)
3396 {
3397  gMarker.type = type;
3398  gMarker.n = n < kMAXMK ? n : kMAXMK;
3399  if (gMarker.type >= 2) {
3400  for (int i = 0; i < gMarker.n; i++) {
3401  gMarker.xy[i] = xy[i];
3402  }
3403  }
3404 }
3405 
3406 ////////////////////////////////////////////////////////////////////////////////
3407 /// Set marker style.
3408 
3410 {
3411  if ((fMarkerStyle==markerstyle) || (markerstyle >= 35)) return;
3412  fMarkerStyle = TMath::Abs(markerstyle);
3414 }
3415 
3416 ////////////////////////////////////////////////////////////////////////////////
3417 ///
3418 
3420 {
3421  static GdkPoint shape[15];
3422 
3423  Int_t im = Int_t(4 * fMarkerSize + 0.5);
3424 
3425  if (fMarkerStyle == 2) {
3426  // + shaped marker
3427  shape[0].x = -im;
3428  shape[0].y = 0;
3429  shape[1].x = im;
3430  shape[1].y = 0;
3431  shape[2].x = 0;
3432  shape[2].y = -im;
3433  shape[3].x = 0;
3434  shape[3].y = im;
3435  SetMarkerType(4, 4, shape);
3436  } else if (fMarkerStyle == 3 || fMarkerStyle == 31) {
3437  // * shaped marker
3438  shape[0].x = -im;
3439  shape[0].y = 0;
3440  shape[1].x = im;
3441  shape[1].y = 0;
3442  shape[2].x = 0;
3443  shape[2].y = -im;
3444  shape[3].x = 0;
3445  shape[3].y = im;
3446  im = Int_t(0.707 * Float_t(im) + 0.5);
3447  shape[4].x = -im;
3448  shape[4].y = -im;
3449  shape[5].x = im;
3450  shape[5].y = im;
3451  shape[6].x = -im;
3452  shape[6].y = im;
3453  shape[7].x = im;
3454  shape[7].y = -im;
3455  SetMarkerType(4, 8, shape);
3456  } else if (fMarkerStyle == 4 || fMarkerStyle == 24) {
3457  // O shaped marker
3458  SetMarkerType(0, im * 2, shape);
3459  } else if (fMarkerStyle == 5) {
3460  // X shaped marker
3461  im = Int_t(0.707 * Float_t(im) + 0.5);
3462  shape[0].x = -im;
3463  shape[0].y = -im;
3464  shape[1].x = im;
3465  shape[1].y = im;
3466  shape[2].x = -im;
3467  shape[2].y = im;
3468  shape[3].x = im;
3469  shape[3].y = -im;
3470  SetMarkerType(4, 4, shape);
3471  } else if (fMarkerStyle == 6) {
3472  // + shaped marker (with 1 pixel)
3473  shape[0].x = -1;
3474  shape[0].y = 0;
3475  shape[1].x = 1;
3476  shape[1].y = 0;
3477  shape[2].x = 0;
3478  shape[2].y = -1;
3479  shape[3].x = 0;
3480  shape[3].y = 1;
3481  SetMarkerType(4, 4, shape);
3482  } else if (fMarkerStyle == 7) {
3483  // . shaped marker (with 9 pixel)
3484  shape[0].x = -1;
3485  shape[0].y = 1;
3486  shape[1].x = 1;
3487  shape[1].y = 1;
3488  shape[2].x = -1;
3489  shape[2].y = 0;
3490  shape[3].x = 1;
3491  shape[3].y = 0;
3492  shape[4].x = -1;
3493  shape[4].y = -1;
3494  shape[5].x = 1;
3495  shape[5].y = -1;
3496  SetMarkerType(4, 6, shape);
3497  } else if (fMarkerStyle == 8 || fMarkerStyle == 20) {
3498  // O shaped marker (filled)
3499  SetMarkerType(1, im * 2, shape);
3500  } else if (fMarkerStyle == 21) {
3501  // full square
3502  shape[0].x = -im;
3503  shape[0].y = -im;
3504  shape[1].x = im;
3505  shape[1].y = -im;
3506  shape[2].x = im;
3507  shape[2].y = im;
3508  shape[3].x = -im;
3509  shape[3].y = im;
3510  shape[4].x = -im;
3511  shape[4].y = -im;
3512  SetMarkerType(3, 5, shape);
3513  } else if (fMarkerStyle == 22) {
3514  // full triangle up
3515  shape[0].x = -im;
3516  shape[0].y = im;
3517  shape[1].x = im;
3518  shape[1].y = im;
3519  shape[2].x = 0;
3520  shape[2].y = -im;
3521  shape[3].x = -im;
3522  shape[3].y = im;
3523  SetMarkerType(3, 4, shape);
3524  } else if (fMarkerStyle == 23) {
3525  // full triangle down
3526  shape[0].x = 0;
3527  shape[0].y = im;
3528  shape[1].x = im;
3529  shape[1].y = -im;
3530  shape[2].x = -im;
3531  shape[2].y = -im;
3532  shape[3].x = 0;
3533  shape[3].y = im;
3534  SetMarkerType(3, 4, shape);
3535  } else if (fMarkerStyle == 25) {
3536  // open square
3537  shape[0].x = -im;
3538  shape[0].y = -im;
3539  shape[1].x = im;
3540  shape[1].y = -im;
3541  shape[2].x = im;
3542  shape[2].y = im;
3543  shape[3].x = -im;
3544  shape[3].y = im;
3545  shape[4].x = -im;
3546  shape[4].y = -im;
3547  SetMarkerType(2, 5, shape);
3548  } else if (fMarkerStyle == 26) {
3549  // open triangle up
3550  shape[0].x = -im;
3551  shape[0].y = im;
3552  shape[1].x = im;
3553  shape[1].y = im;
3554  shape[2].x = 0;
3555  shape[2].y = -im;
3556  shape[3].x = -im;
3557  shape[3].y = im;
3558  SetMarkerType(2, 4, shape);
3559  } else if (fMarkerStyle == 27) {
3560  // open losange
3561  Int_t imx = Int_t(2.66 * fMarkerSize + 0.5);
3562  shape[0].x = -imx;
3563  shape[0].y = 0;
3564  shape[1].x = 0;
3565  shape[1].y = -im;
3566  shape[2].x = imx;
3567  shape[2].y = 0;
3568  shape[3].x = 0;
3569  shape[3].y = im;
3570  shape[4].x = -imx;
3571  shape[4].y = 0;
3572  SetMarkerType(2, 5, shape);
3573  } else if (fMarkerStyle == 28) {
3574  // open cross
3575  Int_t imx = Int_t(1.33 * fMarkerSize + 0.5);
3576  shape[0].x = -im;
3577  shape[0].y = -imx;
3578  shape[1].x = -imx;
3579  shape[1].y = -imx;
3580  shape[2].x = -imx;
3581  shape[2].y = -im;
3582  shape[3].x = imx;
3583  shape[3].y = -im;
3584  shape[4].x = imx;
3585  shape[4].y = -imx;
3586  shape[5].x = im;
3587  shape[5].y = -imx;
3588  shape[6].x = im;
3589  shape[6].y = imx;
3590  shape[7].x = imx;
3591  shape[7].y = imx;
3592  shape[8].x = imx;
3593  shape[8].y = im;
3594  shape[9].x = -imx;
3595  shape[9].y = im;
3596  shape[10].x = -imx;
3597  shape[10].y = imx;
3598  shape[11].x = -im;
3599  shape[11].y = imx;
3600  shape[12].x = -im;
3601  shape[12].y = -imx;
3602  SetMarkerType(2, 13, shape);
3603  } else if (fMarkerStyle == 29) {
3604  // full star pentagone
3605  Int_t im1 = Int_t(0.66 * fMarkerSize + 0.5);
3606  Int_t im2 = Int_t(2.00 * fMarkerSize + 0.5);
3607  Int_t im3 = Int_t(2.66 * fMarkerSize + 0.5);
3608  Int_t im4 = Int_t(1.33 * fMarkerSize + 0.5);
3609  shape[0].x = -im;
3610  shape[0].y = im4;
3611  shape[1].x = -im2;
3612  shape[1].y = -im1;
3613  shape[2].x = -im3;
3614  shape[2].y = -im;
3615  shape[3].x = 0;
3616  shape[3].y = -im2;
3617  shape[4].x = im3;
3618  shape[4].y = -im;
3619  shape[5].x = im2;
3620  shape[5].y = -im1;
3621  shape[6].x = im;
3622  shape[6].y = im4;
3623  shape[7].x = im4;
3624  shape[7].y = im4;
3625  shape[8].x = 0;
3626  shape[8].y = im;
3627  shape[9].x = -im4;
3628  shape[9].y = im4;
3629  shape[10].x = -im;
3630  shape[10].y = im4;
3631  SetMarkerType(3, 11, shape);
3632  } else if (fMarkerStyle == 30) {
3633  // open star pentagone
3634  Int_t im1 = Int_t(0.66 * fMarkerSize + 0.5);
3635  Int_t im2 = Int_t(2.00 * fMarkerSize + 0.5);
3636  Int_t im3 = Int_t(2.66 * fMarkerSize + 0.5);
3637  Int_t im4 = Int_t(1.33 * fMarkerSize + 0.5);
3638  shape[0].x = -im;
3639  shape[0].y = im4;
3640  shape[1].x = -im2;
3641  shape[1].y = -im1;
3642  shape[2].x = -im3;
3643  shape[2].y = -im;
3644  shape[3].x = 0;
3645  shape[3].y = -im2;
3646  shape[4].x = im3;
3647  shape[4].y = -im;
3648  shape[5].x = im2;
3649  shape[5].y = -im1;
3650  shape[6].x = im;
3651  shape[6].y = im4;
3652  shape[7].x = im4;
3653  shape[7].y = im4;
3654  shape[8].x = 0;
3655  shape[8].y = im;
3656  shape[9].x = -im4;
3657  shape[9].y = im4;
3658  shape[10].x = -im;
3659  shape[10].y = im4;
3660  SetMarkerType(2, 11, shape);
3661  } else if (fMarkerStyle == 32) {
3662  // open triangle down
3663  shape[0].x = 0; shape[0].y = im;
3664  shape[1].x = im; shape[1].y = -im;
3665  shape[2].x = -im; shape[2].y = -im;
3666  shape[3].x = 0; shape[3].y = im;
3667  SetMarkerType(2,4,shape);
3668  } else if (fMarkerStyle == 33) {
3669  // full losange
3670  Int_t imx = Int_t(2.66*fMarkerSize + 0.5);
3671  shape[0].x =-imx; shape[0].y = 0;
3672  shape[1].x = 0; shape[1].y = -im;
3673  shape[2].x = imx; shape[2].y = 0;
3674  shape[3].x = 0; shape[3].y = im;
3675  shape[4].x =-imx; shape[4].y = 0;
3676  SetMarkerType(3,5,shape);
3677  } else if (fMarkerStyle == 34) {
3678  // full cross
3679  Int_t imx = Int_t(1.33*fMarkerSize + 0.5);
3680  shape[0].x = -im; shape[0].y =-imx;
3681  shape[1].x =-imx; shape[1].y =-imx;
3682  shape[2].x =-imx; shape[2].y = -im;
3683  shape[3].x = imx; shape[3].y = -im;
3684  shape[4].x = imx; shape[4].y =-imx;
3685  shape[5].x = im; shape[5].y =-imx;
3686  shape[6].x = im; shape[6].y = imx;
3687  shape[7].x = imx; shape[7].y = imx;
3688  shape[8].x = imx; shape[8].y = im;
3689  shape[9].x =-imx; shape[9].y = im;
3690  shape[10].x=-imx; shape[10].y= imx;
3691  shape[11].x= -im; shape[11].y= imx;
3692  shape[12].x= -im; shape[12].y=-imx;
3693  SetMarkerType(3,13,shape);
3694  } else {
3695  // single dot
3696  SetMarkerType(0, 0, shape);
3697  }
3699 }
3700 
3701 ////////////////////////////////////////////////////////////////////////////////
3702 /// Set opacity of a window. This image manipulation routine works
3703 /// by adding to a percent amount of neutral to each pixels RGB.
3704 /// Since it requires quite some additional color map entries is it
3705 /// only supported on displays with more than > 8 color planes (> 256
3706 /// colors)
3707 
3709 {
3710  Int_t depth = gdk_visual_get_best_depth();
3711 
3712  if (depth <= 8) return;
3713  if (percent == 0) return;
3714 
3715  // if 100 percent then just make white
3716  ULong_t *orgcolors = 0, *tmpc = 0;
3717  Int_t maxcolors = 0, ncolors, ntmpc = 0;
3718 
3719  // save previous allocated colors, delete at end when not used anymore
3720  if (gCws->new_colors) {
3721  tmpc = gCws->new_colors;
3722  ntmpc = gCws->ncolors;
3723  }
3724  // get pixmap from server as image
3725  GdkImage *image = gdk_image_get((GdkDrawable*)gCws->drawing, 0, 0,
3726  gCws->width, gCws->height);
3727 
3728  // collect different image colors
3729  int x, y;
3730  for (y = 0; y < (int) gCws->height; y++) {
3731  for (x = 0; x < (int) gCws->width; x++) {
3732  ULong_t pixel = GetPixelImage((Drawable_t)image, x, y);
3733  CollectImageColors(pixel, orgcolors, ncolors, maxcolors);
3734  }
3735  }
3736  if (ncolors == 0) {
3737  gdk_image_unref(image);
3738  ::operator delete(orgcolors);
3739  return;
3740  }
3741  // create opaque counter parts
3742  MakeOpaqueColors(percent, orgcolors, ncolors);
3743 
3744  // put opaque colors in image
3745  for (y = 0; y < (int) gCws->height; y++) {
3746  for (x = 0; x < (int) gCws->width; x++) {
3747  ULong_t pixel = GetPixelImage((Drawable_t)image, x, y);
3748  Int_t idx = FindColor(pixel, orgcolors, ncolors);
3749  PutPixel((Drawable_t)image, x, y, gCws->new_colors[idx]);
3750  }
3751  }
3752 
3753  // put image back in pixmap on server
3754  gdk_draw_image(gCws->drawing, gGCpxmp, (GdkImage *)image,
3755  0, 0, 0, 0, gCws->width, gCws->height);
3756  GdiFlush();
3757 
3758  // clean up
3759  if (tmpc) {
3760  gdk_colors_free((GdkColormap *)fColormap, tmpc, ntmpc, 0);
3761  delete[]tmpc;
3762  }
3763  gdk_image_unref(image);
3764  ::operator delete(orgcolors);
3765 }
3766 
3767 ////////////////////////////////////////////////////////////////////////////////
3768 /// Get RGB values for orgcolors, add percent neutral to the RGB and
3769 /// allocate new_colors.
3770 
3771 void TGWin32::MakeOpaqueColors(Int_t percent, ULong_t *orgcolors, Int_t ncolors)
3772 {
3773  Int_t ret;
3774  if (ncolors <= 0) return;
3775  GdkColor *xcol = new GdkColor[ncolors];
3776 
3777  int i;
3778  for (i = 0; i < ncolors; i++) {
3779  xcol[i].pixel = orgcolors[i];
3780  xcol[i].red = xcol[i].green = xcol[i].blue = 0;
3781  }
3782 
3783  GdkColorContext *cc;
3784  cc = gdk_color_context_new(gdk_visual_get_system(), (GdkColormap *)fColormap);
3785  gdk_color_context_query_colors(cc, xcol, ncolors);
3786  gdk_color_context_free(cc);
3787 
3788  UShort_t add = percent * kBIGGEST_RGB_VALUE / 100;
3789 
3790  Int_t val;
3791  for (i = 0; i < ncolors; i++) {
3792  val = xcol[i].red + add;
3793  if (val > kBIGGEST_RGB_VALUE) {
3794  val = kBIGGEST_RGB_VALUE;
3795  }
3796  xcol[i].red = (UShort_t) val;
3797  val = xcol[i].green + add;
3798  if (val > kBIGGEST_RGB_VALUE) {
3799  val = kBIGGEST_RGB_VALUE;
3800  }
3801  xcol[i].green = (UShort_t) val;
3802  val = xcol[i].blue + add;
3803  if (val > kBIGGEST_RGB_VALUE) {
3804  val = kBIGGEST_RGB_VALUE;
3805  }
3806  xcol[i].blue = (UShort_t) val;
3807 
3808  ret = gdk_color_alloc((GdkColormap *)fColormap, &xcol[i]);
3809 
3810  if (!ret) {
3811  Warning("MakeOpaqueColors",
3812  "failed to allocate color %hd, %hd, %hd", xcol[i].red,
3813  xcol[i].green, xcol[i].blue);
3814  // assumes that in case of failure xcol[i].pixel is not changed
3815  }
3816  }
3817 
3818  gCws->new_colors = new ULong_t[ncolors];
3819  gCws->ncolors = ncolors;
3820 
3821  for (i = 0; i < ncolors; i++) {
3822  gCws->new_colors[i] = xcol[i].pixel;
3823  }
3824 
3825  delete []xcol;
3826 }
3827 
3828 ////////////////////////////////////////////////////////////////////////////////
3829 /// Returns index in orgcolors (and new_colors) for pixel.
3830 
3831 Int_t TGWin32::FindColor(ULong_t pixel, ULong_t * orgcolors, Int_t ncolors)
3832 {
3833  for (int i = 0; i < ncolors; i++) {
3834  if (pixel == orgcolors[i]) return i;
3835  }
3836  Error("FindColor", "did not find color, should never happen!");
3837 
3838  return 0;
3839 }
3840 
3841 ////////////////////////////////////////////////////////////////////////////////
3842 /// Set color intensities for given color index.
3843 /// cindex : color index
3844 /// r,g,b : red, green, blue intensities between 0.0 and 1.0
3845 
3846 void TGWin32::SetRGB(int cindex, float r, float g, float b)
3847 {
3848  GdkColor xcol;
3849 
3850  if (fColormap && cindex >= 0) {
3851  xcol.red = (unsigned short) (r * kBIGGEST_RGB_VALUE);
3852  xcol.green = (unsigned short) (g * kBIGGEST_RGB_VALUE);
3853  xcol.blue = (unsigned short) (b * kBIGGEST_RGB_VALUE);
3854  xcol.pixel = RGB(xcol.red, xcol.green, xcol.blue);
3855 
3856  XColor_t &col = GetColor(cindex);
3857  if (col.fDefined) {
3858  // if color is already defined with same rgb just return
3859  if (col.color.red == xcol.red && col.color.green == xcol.green &&
3860  col.color.blue == xcol.blue)
3861  return;
3862  col.fDefined = kFALSE;
3863  gdk_colormap_free_colors((GdkColormap *) fColormap,
3864  (GdkColor *)&col, 1);
3865  }
3866 
3867  Int_t ret = gdk_colormap_alloc_color(fColormap, &xcol, 1, 1);
3868  if (ret != 0) {
3869  col.fDefined = kTRUE;
3870  col.color.pixel = xcol.pixel;
3871  col.color.red = xcol.red;
3872  col.color.green = xcol.green;
3873  col.color.blue = xcol.blue;
3874  }
3875  }
3876 }
3877 
3878 ////////////////////////////////////////////////////////////////////////////////
3879 /// Set text alignment.
3880 /// txalh : horizontal text alignment
3881 /// txalv : vertical text alignment
3882 
3884 {
3885  static Short_t current = 0;
3886  if (talign==current) return;
3887  current = talign;
3888 
3889  Int_t txalh = talign / 10;
3890  Int_t txalv = talign % 10;
3891  fTextAlignH = txalh;
3892  fTextAlignV = txalv;
3893 
3894  switch (txalh) {
3895 
3896  case 0:
3897  case 1:
3898  switch (txalv) { //left
3899  case 1:
3900  fTextAlign = 7; //bottom
3901  break;
3902  case 2:
3903  fTextAlign = 4; //center
3904  break;
3905  case 3:
3906  fTextAlign = 1; //top
3907  break;
3908  }
3909  break;
3910  case 2:
3911  switch (txalv) { //center
3912  case 1:
3913  fTextAlign = 8; //bottom
3914  break;
3915  case 2:
3916  fTextAlign = 5; //center
3917  break;
3918  case 3:
3919  fTextAlign = 2; //top
3920  break;
3921  }
3922  break;
3923  case 3:
3924  switch (txalv) { //right
3925  case 1:
3926  fTextAlign = 9; //bottom
3927  break;
3928  case 2:
3929  fTextAlign = 6; //center
3930  break;
3931  case 3:
3932  fTextAlign = 3; //top
3933  break;
3934  }
3935  break;
3936  }
3938 }
3939 
3940 ////////////////////////////////////////////////////////////////////////////////
3941 /// Set color index for text.
3942 
3944 {
3945  static Int_t current = 0;
3946  GdkGCValues values;
3947  if ((cindex < 0) || (Int_t(cindex)==current)) return;
3948 
3949  TAttText::SetTextColor(cindex);
3950 
3951  SetColor(gGCtext, Int_t(cindex));
3952  gdk_gc_get_values(gGCtext, &values);
3953  gdk_gc_set_foreground(gGCinvt, &values.background);
3954  gdk_gc_set_background(gGCinvt, &values.foreground);
3955  gdk_gc_set_background(gGCtext, (GdkColor *) & GetColor(0).color);
3956  current = Int_t(cindex);
3957 }
3958 
3959 ////////////////////////////////////////////////////////////////////////////////
3960 
3961 void TGWin32::Sync(int mode)
3962 {
3963 }
3964 
3965 ////////////////////////////////////////////////////////////////////////////////
3966 /// Update display.
3967 /// mode : (1) update
3968 /// (0) sync
3969 ///
3970 /// Synchronise client and server once (not permanent).
3971 /// Copy the pixmap gCws->drawing on the window gCws->window
3972 /// if the double buffer is on.
3973 
3975 {
3976  if (gCws && gCws->double_buffer) {
3977  gdk_window_copy_area(gCws->window, gGCpxmp, 0, 0,
3978  gCws->drawing, 0, 0, gCws->width, gCws->height);
3979  }
3980  Update(mode);
3981 }
3982 
3983 ////////////////////////////////////////////////////////////////////////////////
3984 /// Set pointer position.
3985 /// ix : New X coordinate of pointer
3986 /// iy : New Y coordinate of pointer
3987 /// Coordinates are relative to the origin of the window id
3988 /// or to the origin of the current window if id == 0.
3989 
3990 void TGWin32::Warp(int ix, int iy, Window_t id)
3991 {
3992  if (!id) return;
3993 
3994  POINT cpt, tmp;
3995  HWND dw;
3996  if (!id)
3997  dw = (HWND) GDK_DRAWABLE_XID((GdkWindow *)gCws->window);
3998  else
3999  dw = (HWND) GDK_DRAWABLE_XID((GdkWindow *)id);
4000  GetCursorPos(&cpt);
4001  tmp.x = ix > 0 ? ix : cpt.x;
4002  tmp.y = iy > 0 ? iy : cpt.y;
4003  ClientToScreen(dw, &tmp);
4004  SetCursorPos(tmp.x, tmp.y);
4005 }
4006 
4007 ////////////////////////////////////////////////////////////////////////////////
4008 /// Write the pixmap wid in the bitmap file pxname.
4009 /// wid : Pixmap address
4010 /// w,h : Width and height of the pixmap.
4011 /// lenname : pixmap name length
4012 /// pxname : pixmap name
4013 
4014 void TGWin32::WritePixmap(int wid, unsigned int w, unsigned int h,
4015  char *pxname)
4016 {
4017  int wval, hval;
4018  wval = w;
4019  hval = h;
4020 
4021  if (!fWindows) return;
4022  gTws = &fWindows[wid];
4023 // XWriteBitmapFile(fDisplay,pxname,(Pixmap)gTws->drawing,wval,hval,-1,-1);
4024 }
4025 
4026 
4027 //
4028 // Functions for GIFencode()
4029 //
4030 
4031 static FILE *gGifFile; // output unit used WriteGIF and PutByte
4032 static GdkImage *gGifImage = 0; // image used in WriteGIF and GetPixel
4033 
4034 extern "C" {
4035  int GIFquantize(UInt_t width, UInt_t height, Int_t * ncol, Byte_t * red,
4036  Byte_t * green, Byte_t * blue, Byte_t * outputBuf,
4037  Byte_t * outputCmap);
4038  long GIFencode(int Width, int Height, Int_t Ncol, Byte_t R[],
4039  Byte_t G[], Byte_t B[], Byte_t ScLine[],
4040  void (*get_scline) (int, int, Byte_t *),
4041  void (*pb) (Byte_t));
4042  int GIFdecode(Byte_t * GIFarr, Byte_t * PIXarr, int *Width, int *Height,
4043  int *Ncols, Byte_t * R, Byte_t * G, Byte_t * B);
4044  int GIFinfo(Byte_t * GIFarr, int *Width, int *Height, int *Ncols);
4045 }
4046 
4047 
4048 ////////////////////////////////////////////////////////////////////////////////
4049 /// Get pixels in line y and put in array scline.
4050 
4051 static void GetPixel(int y, int width, Byte_t * scline)
4052 {
4053  for (int i = 0; i < width; i++) {
4054  scline[i] = Byte_t(GetPixelImage((Drawable_t)gGifImage, i, y));
4055  }
4056 }
4057 
4058 ////////////////////////////////////////////////////////////////////////////////
4059 /// Put byte b in output stream.
4060 
4061 static void PutByte(Byte_t b)
4062 {
4063  if (ferror(gGifFile) == 0) fputc(b, gGifFile);
4064 }
4065 
4066 ////////////////////////////////////////////////////////////////////////////////
4067 /// Returns in R G B the ncol colors of the palette used by the image.
4068 /// The image pixels are changed to index values in these R G B arrays.
4069 /// This produces a colormap with only the used colors (so even on displays
4070 /// with more than 8 planes we will be able to create GIF's when the image
4071 /// contains no more than 256 different colors). If it does contain more
4072 /// colors we will have to use GIFquantize to reduce the number of colors.
4073 /// The R G B arrays must be deleted by the caller.
4074 
4075 void TGWin32::ImgPickPalette(GdkImage * image, Int_t & ncol, Int_t * &R,
4076  Int_t * &G, Int_t * &B)
4077 {
4078  ULong_t *orgcolors = 0;
4079  Int_t maxcolors = 0, ncolors;
4080 
4081  // collect different image colors
4082  int x, y;
4083  for (x = 0; x < (int) gCws->width; x++) {
4084  for (y = 0; y < (int) gCws->height; y++) {
4085  ULong_t pixel = GetPixelImage((Drawable_t)image, x, y);
4086  CollectImageColors(pixel, orgcolors, ncolors, maxcolors);
4087  }
4088  }
4089 
4090  // get RGB values belonging to pixels
4091  GdkColor *xcol = new GdkColor[ncolors];
4092 
4093  int i;
4094  for (i = 0; i < ncolors; i++) {
4095  xcol[i].pixel = orgcolors[i];
4096 // xcol[i].red = xcol[i].green = xcol[i].blue = 0;
4097  xcol[i].red = GetRValue(xcol[i].pixel);
4098  xcol[i].green = GetGValue(xcol[i].pixel);
4099  xcol[i].blue = GetBValue(xcol[i].pixel);
4100  }
4101 
4102  GdkColorContext *cc;
4103  cc = gdk_color_context_new(gdk_visual_get_system(), (GdkColormap *)fColormap);
4104  gdk_color_context_query_colors(cc, xcol, ncolors);
4105  gdk_color_context_free(cc);
4106 
4107  // create RGB arrays and store RGB's for each color and set number of colors
4108  // (space must be delete by caller)
4109  R = new Int_t[ncolors];
4110  G = new Int_t[ncolors];
4111  B = new Int_t[ncolors];
4112 
4113  for (i = 0; i < ncolors; i++) {
4114  R[i] = xcol[i].red;
4115  G[i] = xcol[i].green;
4116  B[i] = xcol[i].blue;
4117  }
4118  ncol = ncolors;
4119 
4120  // update image with indices (pixels) into the new RGB colormap
4121  for (x = 0; x < (int) gCws->width; x++) {
4122  for (y = 0; y < (int) gCws->height; y++) {
4123  ULong_t pixel = GetPixelImage((Drawable_t)image, x, y);
4124  Int_t idx = FindColor(pixel, orgcolors, ncolors);
4125  PutPixel((Drawable_t)image, x, y, idx);
4126  }
4127  }
4128 
4129  // cleanup
4130  delete[]xcol;
4131  ::operator delete(orgcolors);
4132 }
4133 
4134 ////////////////////////////////////////////////////////////////////////////////
4135 /// Writes the current window into GIF file.
4136 
4138 {
4139  Byte_t scline[2000], r[256], b[256], g[256];
4140  Int_t *R, *G, *B;
4141  Int_t ncol, maxcol, i;
4142 
4143  if (gGifImage) {
4144  gdk_image_unref((GdkImage *)gGifImage);
4145  }
4146 
4147  gGifImage = gdk_image_get((GdkDrawable*)gCws->drawing, 0, 0,
4148  gCws->width, gCws->height);
4149 
4150  ImgPickPalette(gGifImage, ncol, R, G, B);
4151 
4152  if (ncol > 256) {
4153  //GIFquantize(...);
4154  Error("WriteGIF",
4155  "can not create GIF of image containing more than 256 colors");
4156  delete[]R;
4157  delete[]G;
4158  delete[]B;
4159  return 0;
4160  }
4161 
4162  maxcol = 0;
4163  for (i = 0; i < ncol; i++) {
4164  if (maxcol < R[i]) maxcol = R[i];
4165  if (maxcol < G[i]) maxcol = G[i];
4166  if (maxcol < B[i]) maxcol = B[i];
4167  r[i] = 0;
4168  g[i] = 0;
4169  b[i] = 0;
4170  }
4171  if (maxcol != 0) {
4172  for (i = 0; i < ncol; i++) {
4173  r[i] = R[i] * 255 / maxcol;
4174  g[i] = G[i] * 255 / maxcol;
4175  b[i] = B[i] * 255 / maxcol;
4176  }
4177  }
4178 
4179  gGifFile = fopen(name, "wb");
4180 
4181  if (gGifFile) {
4182  GIFencode(gCws->width, gCws->height,
4183  ncol, r, g, b, scline, ::GetPixel, PutByte);
4184  fclose(gGifFile);
4185  i = 1;
4186  } else {
4187  Error("WriteGIF","cannot write file: %s",name);
4188  i = 0;
4189  }
4190  delete[]R;
4191  delete[]G;
4192  delete[]B;
4193 
4194  return i;
4195 }
4196 
4197 ////////////////////////////////////////////////////////////////////////////////
4198 /// Draw image.
4199 
4200 void TGWin32::PutImage(int offset, int itran, int x0, int y0, int nx,
4201  int ny, int xmin, int ymin, int xmax, int ymax,
4202  unsigned char *image, Drawable_t wid)
4203 {
4204  const int MAX_SEGMENT = 20;
4205  int i, n, x, y, xcur, x1, x2, y1, y2;
4206  unsigned char *jimg, *jbase, icol;
4207  int nlines[256];
4208  GdkSegment lines[256][MAX_SEGMENT];
4209  GdkDrawable *id;
4210 
4211  if (wid) {
4212  id = (GdkDrawable*)wid;
4213  } else {
4214  id = gCws->drawing;
4215  }
4216 
4217  for (i = 0; i < 256; i++) nlines[i] = 0;
4218 
4219  x1 = x0 + xmin;
4220  y1 = y0 + ny - ymax - 1;
4221  x2 = x0 + xmax;
4222  y2 = y0 + ny - ymin - 1;
4223  jbase = image + (ymin - 1) * nx + xmin;
4224 
4225  for (y = y2; y >= y1; y--) {
4226  xcur = x1;
4227  jbase += nx;
4228  for (jimg = jbase, icol = *jimg++, x = x1 + 1; x <= x2; jimg++, x++) {
4229  if (icol != *jimg) {
4230  if (icol != itran) {
4231  n = nlines[icol]++;
4232  lines[icol][n].x1 = xcur;
4233  lines[icol][n].y1 = y;
4234  lines[icol][n].x2 = x - 1;
4235  lines[icol][n].y2 = y;
4236  if (nlines[icol] == MAX_SEGMENT) {
4237  SetColor(gGCline, (int) icol + offset);
4238  gdk_win32_draw_segments(id, (GdkGC *) gGCline,
4239  (GdkSegment *) &lines[icol][0], MAX_SEGMENT);
4240  nlines[icol] = 0;
4241  }
4242  }
4243  icol = *jimg;
4244  xcur = x;
4245  }
4246  }
4247  if (icol != itran) {
4248  n = nlines[icol]++;
4249  lines[icol][n].x1 = xcur;
4250  lines[icol][n].y1 = y;
4251  lines[icol][n].x2 = x - 1;
4252  lines[icol][n].y2 = y;
4253  if (nlines[icol] == MAX_SEGMENT) {
4254  SetColor(gGCline, (int) icol + offset);
4255  gdk_win32_draw_segments(id, (GdkGC *) gGCline,
4256  (GdkSegment *)&lines[icol][0], MAX_SEGMENT);
4257  nlines[icol] = 0;
4258  }
4259  }
4260  }
4261 
4262  for (i = 0; i < 256; i++) {
4263  if (nlines[i] != 0) {
4264  SetColor(gGCline, i + offset);
4265  gdk_win32_draw_segments(id, (GdkGC *) gGCline,
4266  (GdkSegment *)&lines[icol][0], nlines[i]);
4267  }
4268  }
4269 }
4270 
4271 ////////////////////////////////////////////////////////////////////////////////
4272 /// If id is NULL - loads the specified gif file at position [x0,y0] in the
4273 /// current window. Otherwise creates pixmap from gif file
4274 
4275 Pixmap_t TGWin32::ReadGIF(int x0, int y0, const char *file, Window_t id)
4276 {
4277  FILE *fd;
4278  Seek_t filesize;
4279  unsigned char *GIFarr, *PIXarr, R[256], G[256], B[256], *j1, *j2, icol;
4280  int i, j, k, width, height, ncolor, irep, offset;
4281  float rr, gg, bb;
4282  Pixmap_t pic = 0;
4283 
4284  fd = fopen(file, "r+b");
4285  if (!fd) {
4286  Error("ReadGIF", "unable to open GIF file");
4287  return pic;
4288  }
4289 
4290  fseek(fd, 0L, 2);
4291  filesize = Seek_t(ftell(fd));
4292  fseek(fd, 0L, 0);
4293 
4294  if (!(GIFarr = (unsigned char *) calloc(filesize + 256, 1))) {
4295  fclose(fd);
4296  Error("ReadGIF", "unable to allocate array for gif");
4297  return pic;
4298  }
4299 
4300  if (fread(GIFarr, filesize, 1, fd) != 1) {
4301  fclose(fd);
4302  Error("ReadGIF", "GIF file read failed");
4303  return pic;
4304  }
4305  fclose(fd);
4306 
4307  irep = GIFinfo(GIFarr, &width, &height, &ncolor);
4308  if (irep != 0) {
4309  return pic;
4310  }
4311 
4312  if (!(PIXarr = (unsigned char *) calloc((width * height), 1))) {
4313  Error("ReadGIF", "unable to allocate array for image");
4314  return pic;
4315  }
4316 
4317  irep = GIFdecode(GIFarr, PIXarr, &width, &height, &ncolor, R, G, B);
4318  if (irep != 0) {
4319  return pic;
4320  }
4321  // S E T P A L E T T E
4322 
4323  offset = 8;
4324 
4325  for (i = 0; i < ncolor; i++) {
4326  rr = R[i] / 255.;
4327  gg = G[i] / 255.;
4328  bb = B[i] / 255.;
4329  j = i + offset;
4330  SetRGB(j, rr, gg, bb);
4331  }
4332 
4333  // O U T P U T I M A G E
4334 
4335  for (i = 1; i <= height / 2; i++) {
4336  j1 = PIXarr + (i - 1) * width;
4337  j2 = PIXarr + (height - i) * width;
4338  for (k = 0; k < width; k++) {
4339  icol = *j1;
4340  *j1++ = *j2;
4341  *j2++ = icol;
4342  }
4343  }
4344 
4345  if (id) pic = CreatePixmap(id, width, height);
4346  PutImage(offset, -1, x0, y0, width, height, 0, 0, width-1, height-1, PIXarr, pic);
4347 
4348  if (pic) return pic;
4349  else if (gCws->drawing) return (Pixmap_t)gCws->drawing;
4350  else return 0;
4351 }
4352 
4353 //////////////////////////// GWin32Gui //////////////////////////////////////////
4354 ////////////////////////////////////////////////////////////////////////////////
4355 /// Map window on screen.
4356 
4358 {
4359  if (!id) return;
4360 
4361  gdk_window_show((GdkWindow *)id);
4362  if ((GDK_DRAWABLE_TYPE((GdkWindow *)id) != GDK_WINDOW_TEMP) &&
4363  (GetParent(id) == GetDefaultRootWindow())) {
4364  HWND window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)id);
4365  ::SetForegroundWindow(window);
4366  }
4367 }
4368 
4369 ////////////////////////////////////////////////////////////////////////////////
4370 ///
4371 
4373 {
4374  if (!id) return;
4375 
4376  EnumChildWindows((HWND)GDK_DRAWABLE_XID((GdkWindow *)id),
4377  EnumChildProc, (LPARAM) NULL);
4378 }
4379 
4380 ////////////////////////////////////////////////////////////////////////////////
4381 /// Map window on screen and put on top of all windows.
4382 
4384 {
4385  if (!id) return;
4386 
4387  HWND hwnd = ::GetForegroundWindow();
4388  HWND window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)id);
4389  gdk_window_show((GdkWindow *)id);
4390  if (GDK_DRAWABLE_TYPE((GdkWindow *)id) != GDK_WINDOW_TEMP) {
4391  ::BringWindowToTop(window);
4392  if (GDK_DRAWABLE_TYPE((GdkWindow *)id) != GDK_WINDOW_CHILD)
4393  ::SetForegroundWindow(window);
4394  }
4395 
4396  if (gConsoleWindow && (hwnd == (HWND)gConsoleWindow)) {
4397  RECT r1, r2, r3;
4398  ::GetWindowRect((HWND)gConsoleWindow, &r1);
4399  HWND fore = ::GetForegroundWindow();
4400  ::GetWindowRect(fore, &r2);
4401  if (!::IntersectRect(&r3, &r2, &r1)) {
4402  ::SetForegroundWindow((HWND)gConsoleWindow);
4403  }
4404  }
4405 }
4406 
4407 ////////////////////////////////////////////////////////////////////////////////
4408 /// Unmap window from screen.
4409 
4411 {
4412  if (!id) return;
4413 
4414  gdk_window_hide((GdkWindow *) id);
4415 }
4416 
4417 ////////////////////////////////////////////////////////////////////////////////
4418 /// Destroy window.
4419 
4421 {
4422  if (!id) return;
4423 
4424  // we need to unmap the window before to destroy it, in order to properly
4425  // receive kUnmapNotify needed by gClient->WaitForUnmap()...
4426  gdk_window_hide((GdkWindow *) id);
4427  gdk_window_destroy((GdkDrawable *) id, kTRUE);
4428 }
4429 
4430 ////////////////////////////////////////////////////////////////////////////////
4431 /// Destroy all internal subwindows
4432 
4434 {
4435  if (!id) return;
4436 
4437  gdk_window_destroy((GdkDrawable *) id, kFALSE);
4438 }
4439 
4440 ////////////////////////////////////////////////////////////////////////////////
4441 /// Put window on top of window stack.
4442 
4444 {
4445  if (!id) return;
4446 
4447  HWND window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)id);
4448  if (GDK_DRAWABLE_TYPE((GdkWindow *)id) == GDK_WINDOW_TEMP) {
4449  ::SetWindowPos(window, HWND_TOPMOST, 0, 0, 0, 0,
4450  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
4451  }
4452  else {
4453  ::BringWindowToTop(window);
4454  if (GDK_DRAWABLE_TYPE((GdkWindow *)id) != GDK_WINDOW_CHILD)
4455  ::SetForegroundWindow(window);
4456  }
4457 }
4458 
4459 ////////////////////////////////////////////////////////////////////////////////
4460 /// Lower window so it lays below all its siblings.
4461 
4463 {
4464  if (!id) return;
4465 
4466  HWND window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)id);
4467  ::SetWindowPos(window, HWND_BOTTOM, 0, 0, 0, 0,
4468  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
4469 }
4470 
4471 ////////////////////////////////////////////////////////////////////////////////
4472 /// Move a window.
4473 
4475 {
4476  if (!id) return;
4477 
4478  gdk_window_move((GdkDrawable *) id, x, y);
4479 }
4480 
4481 ////////////////////////////////////////////////////////////////////////////////
4482 /// Move and resize a window.
4483 
4485  UInt_t h)
4486 {
4487  if (!id) return;
4488 
4489  gdk_window_move_resize((GdkWindow *) id, x, y, w, h);
4490 }
4491 
4492 ////////////////////////////////////////////////////////////////////////////////
4493 /// Resize the window.
4494 
4496 {
4497  if (!id) return;
4498 
4499  // protect against potential negative values
4500  if (w >= (UInt_t)INT_MAX || h >= (UInt_t)INT_MAX)
4501  return;
4502  gdk_window_resize((GdkWindow *) id, w, h);
4503 }
4504 
4505 ////////////////////////////////////////////////////////////////////////////////
4506 /// Iconify the window.
4507 
4509 {
4510  if (!id) return;
4511 
4512  gdk_window_lower((GdkWindow *) id);
4513  ::CloseWindow((HWND)GDK_DRAWABLE_XID((GdkWindow *)id));
4514 }
4515 
4516 ////////////////////////////////////////////////////////////////////////////////
4517 /// Reparent window, make pid the new parent and position the window at
4518 /// position (x,y) in new parent.
4519 
4521 {
4522  if (!id) return;
4523 
4524  gdk_window_reparent((GdkWindow *)id, (GdkWindow *)pid, x, y);
4525 }
4526 
4527 ////////////////////////////////////////////////////////////////////////////////
4528 /// Set the window background color.
4529 
4531 {
4532  if (!id) return;
4533 
4534  GdkColor back;
4535  back.pixel = color;
4536  back.red = GetRValue(color);
4537  back.green = GetGValue(color);
4538  back.blue = GetBValue(color);
4539 
4540  gdk_window_set_background((GdkWindow *) id, &back);
4541 }
4542 
4543 ////////////////////////////////////////////////////////////////////////////////
4544 /// Set pixmap as window background.
4545 
4547 {
4548  if (!id) return;
4549 
4550  gdk_window_set_back_pixmap((GdkWindow *) id, (GdkPixmap *) pxm, 0);
4551 }
4552 
4553 ////////////////////////////////////////////////////////////////////////////////
4554 /// Return handle to newly created gdk window.
4555 
4557  UInt_t w, UInt_t h, UInt_t border,
4558  Int_t depth, UInt_t clss,
4559  void *visual, SetWindowAttributes_t * attr,
4560  UInt_t wtype)
4561 {
4562  GdkWindowAttr xattr;
4563  GdkWindow *newWin;
4564  GdkColor background_color;
4565  ULong_t xmask = 0;
4566 
4567  if (attr) {
4568  MapSetWindowAttributes(attr, xmask, xattr);
4569  xattr.window_type = GDK_WINDOW_CHILD;
4570  if (wtype & kMainFrame) {
4571  xattr.window_type = GDK_WINDOW_TOPLEVEL;
4572  }
4573  if (wtype & kTransientFrame) {
4574  xattr.window_type = GDK_WINDOW_DIALOG;
4575  }
4576  if (wtype & kTempFrame) {
4577  xattr.window_type = GDK_WINDOW_TEMP;
4578  }
4579  newWin = gdk_window_new((GdkWindow *) parent, &xattr, xmask);
4580  } else {
4581  xattr.width = w;
4582  xattr.height = h;
4583  xattr.wclass = GDK_INPUT_OUTPUT;
4584  xattr.event_mask = 0L; //GDK_ALL_EVENTS_MASK;
4585  xattr.event_mask |= GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK |
4586  GDK_PROPERTY_CHANGE_MASK;
4587 // GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK;
4588  if (x >= 0) {
4589  xattr.x = x;
4590  } else {
4591  xattr.x = -1.0 * x;
4592  }
4593  if (y >= 0) {
4594  xattr.y = y;
4595  } else {
4596  xattr.y = -1.0 * y;
4597  }
4598  xattr.colormap = gdk_colormap_get_system();
4599  xattr.cursor = NULL;
4600  xattr.override_redirect = TRUE;
4601  if ((xattr.y > 0) && (xattr.x > 0)) {
4602  xmask = GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP |
4603  GDK_WA_WMCLASS | GDK_WA_NOREDIR;
4604  } else {
4605  xmask = GDK_WA_COLORMAP | GDK_WA_WMCLASS | GDK_WA_NOREDIR;
4606  }
4607  if (visual != NULL) {
4608  xattr.visual = (GdkVisual *) visual;
4609  xmask |= GDK_WA_VISUAL;
4610  } else {
4611  xattr.visual = gdk_visual_get_system();
4612  xmask |= GDK_WA_VISUAL;
4613  }
4614  xattr.window_type = GDK_WINDOW_CHILD;
4615  if (wtype & kMainFrame) {
4616  xattr.window_type = GDK_WINDOW_TOPLEVEL;
4617  }
4618  if (wtype & kTransientFrame) {
4619  xattr.window_type = GDK_WINDOW_DIALOG;
4620  }
4621  if (wtype & kTempFrame) {
4622  xattr.window_type = GDK_WINDOW_TEMP;
4623  }
4624  newWin = gdk_window_new((GdkWindow *) parent, &xattr, xmask);
4625  gdk_window_set_events(newWin, (GdkEventMask) 0L);
4626  }
4627  if (border > 0) {
4628  gdk_window_set_decorations(newWin,
4629  (GdkWMDecoration) GDK_DECOR_BORDER);
4630  }
4631  if (attr) {
4632  if ((attr->fMask & kWABackPixmap)) {
4633  if (attr->fBackgroundPixmap == kNone) {
4634  gdk_window_set_back_pixmap(newWin, (GdkPixmap *) GDK_NONE, 0);
4635  } else if (attr->fBackgroundPixmap == kParentRelative) {
4636  gdk_window_set_back_pixmap(newWin, (GdkPixmap *) GDK_NONE, 1);
4637  } else {
4638  gdk_window_set_back_pixmap(newWin,
4639  (GdkPixmap *) attr->
4640  fBackgroundPixmap, 0);
4641  }
4642  }
4643  if ((attr->fMask & kWABackPixel)) {
4644  background_color.pixel = attr->fBackgroundPixel;
4645  background_color.red = GetRValue(attr->fBackgroundPixel);
4646  background_color.green = GetGValue(attr->fBackgroundPixel);
4647  background_color.blue = GetBValue(attr->fBackgroundPixel);
4648  gdk_window_set_background(newWin, &background_color);
4649  }
4650  }
4651  if (!fUseSysPointers) {
4652  ::SetClassLong((HWND)GDK_DRAWABLE_XID(newWin), GCL_HCURSOR,
4653  (LONG)GDK_CURSOR_XID(fCursors[kPointer]));
4654  }
4655  return (Window_t) newWin;
4656 }
4657 
4658 ////////////////////////////////////////////////////////////////////////////////
4659 /// Map event mask to or from gdk.
4660 
4661 void TGWin32::MapEventMask(UInt_t & emask, UInt_t & xemask, Bool_t tox)
4662 {
4663  if (tox) {
4664  Long_t lxemask = 0L;
4665  if ((emask & kKeyPressMask)) {
4666  lxemask |= GDK_KEY_PRESS_MASK;
4667  }
4668  if ((emask & kKeyReleaseMask)) {
4669  lxemask |= GDK_KEY_RELEASE_MASK;
4670  }
4671  if ((emask & kButtonPressMask)) {
4672  lxemask |= GDK_BUTTON_PRESS_MASK;
4673  }
4674  if ((emask & kButtonReleaseMask)) {
4675  lxemask |= GDK_BUTTON_RELEASE_MASK;
4676  }
4677  if ((emask & kPointerMotionMask)) {
4678  lxemask |= GDK_POINTER_MOTION_MASK;
4679  }
4680  if ((emask & kButtonMotionMask)) {
4681  lxemask |= GDK_BUTTON_MOTION_MASK;
4682  }
4683  if ((emask & kExposureMask)) {
4684  lxemask |= GDK_EXPOSURE_MASK;
4685  }
4686  if ((emask & kStructureNotifyMask)) {
4687  lxemask |= GDK_STRUCTURE_MASK;
4688  }
4689  if ((emask & kEnterWindowMask)) {
4690  lxemask |= GDK_ENTER_NOTIFY_MASK;
4691  }
4692  if ((emask & kLeaveWindowMask)) {
4693  lxemask |= GDK_LEAVE_NOTIFY_MASK;
4694  }
4695  if ((emask & kFocusChangeMask)) {
4696  lxemask |= GDK_FOCUS_CHANGE_MASK;
4697  }
4698  xemask = (UInt_t) lxemask;
4699  } else {
4700  emask = 0;
4701  if ((xemask & GDK_KEY_PRESS_MASK)) {
4702  emask |= kKeyPressMask;
4703  }
4704  if ((xemask & GDK_KEY_RELEASE_MASK)) {
4705  emask |= kKeyReleaseMask;
4706  }
4707  if ((xemask & GDK_BUTTON_PRESS_MASK)) {
4708  emask |= kButtonPressMask;
4709  }
4710  if ((xemask & GDK_BUTTON_RELEASE_MASK)) {
4711  emask |= kButtonReleaseMask;
4712  }
4713  if ((xemask & GDK_POINTER_MOTION_MASK)) {
4714  emask |= kPointerMotionMask;
4715  }
4716  if ((xemask & GDK_BUTTON_MOTION_MASK)) {
4717  emask |= kButtonMotionMask;
4718  }
4719  if ((xemask & GDK_EXPOSURE_MASK)) {
4720  emask |= kExposureMask;
4721  }
4722  if ((xemask & GDK_STRUCTURE_MASK)) {
4723  emask |= kStructureNotifyMask;
4724  }
4725  if ((xemask & GDK_ENTER_NOTIFY_MASK)) {
4726  emask |= kEnterWindowMask;
4727  }
4728  if ((xemask & GDK_LEAVE_NOTIFY_MASK)) {
4729  emask |= kLeaveWindowMask;
4730  }
4731  if ((xemask & GDK_FOCUS_CHANGE_MASK)) {
4732  emask |= kFocusChangeMask;
4733  }
4734  }
4735 }
4736 
4737 ////////////////////////////////////////////////////////////////////////////////
4738 /// Map a SetWindowAttributes_t to a GdkWindowAttr structure.
4739 
4741  ULong_t & xmask,
4742  GdkWindowAttr & xattr)
4743 {
4744  Mask_t mask = attr->fMask;
4745  xmask = 0;
4746 
4747  if ((mask & kWAOverrideRedirect)) {
4748  xmask |= GDK_WA_NOREDIR;
4749  xattr.override_redirect = attr->fOverrideRedirect;
4750  }
4751  if ((mask & kWAEventMask)) {
4752  UInt_t xmsk, msk = (UInt_t) attr->fEventMask;
4753  MapEventMask(msk, xmsk, kTRUE);
4754  xattr.event_mask = xmsk;
4755  }
4756  if ((mask & kWAColormap)) {
4757  xmask |= GDK_WA_COLORMAP;
4758  xattr.colormap = (GdkColormap *) attr->fColormap;
4759  }
4760  if ((mask & kWACursor)) {
4761  xmask |= GDK_WA_CURSOR;
4762  if (attr->fCursor != kNone) {
4763  xattr.cursor = (GdkCursor *) attr->fCursor;
4764  }
4765  }
4766  xattr.wclass = GDK_INPUT_OUTPUT;
4767 }
4768 
4769 ////////////////////////////////////////////////////////////////////////////////
4770 /// Map a GCValues_t to a XCGValues structure if tox is true. Map
4771 /// the other way in case tox is false.
4772 
4774  ULong_t & xmask, GdkGCValues & xgval, Bool_t tox)
4775 {
4776  if (tox) {
4777  // map GCValues_t to XGCValues
4778  Mask_t mask = gval.fMask;
4779  xmask = 0;
4780 
4781  if ((mask & kGCFunction)) {
4782  xmask |= GDK_GC_FUNCTION;
4783  switch (gval.fFunction) {
4784  case kGXclear:
4785  xgval.function = GDK_CLEAR;
4786  break;
4787  case kGXand:
4788  xgval.function = GDK_AND;
4789  break;
4790  case kGXandReverse:
4791  xgval.function = GDK_AND_REVERSE;
4792  break;
4793  case kGXcopy:
4794  xgval.function = GDK_COPY;
4795  break;
4796  case kGXandInverted:
4797  xgval.function = GDK_AND_INVERT;
4798  break;
4799  case kGXnoop:
4800  xgval.function = GDK_NOOP;
4801  break;
4802  case kGXxor:
4803  xgval.function = GDK_XOR;
4804  break;
4805  case kGXor:
4806  xgval.function = GDK_OR;
4807  break;
4808  case kGXequiv:
4809  xgval.function = GDK_EQUIV;
4810  break;
4811  case kGXinvert:
4812  xgval.function = GDK_INVERT;
4813  break;
4814  case kGXorReverse:
4815  xgval.function = GDK_OR_REVERSE;
4816  break;
4817  case kGXcopyInverted:
4818  xgval.function = GDK_COPY_INVERT;
4819  break;
4820  case kGXorInverted:
4821  xgval.function = GDK_OR_INVERT;
4822  break;
4823  case kGXnand:
4824  xgval.function = GDK_NAND;
4825  break;
4826  case kGXset:
4827  xgval.function = GDK_SET;
4828  break;
4829  }
4830  }
4831  if (mask & kGCSubwindowMode) {
4832  xmask |= GDK_GC_SUBWINDOW;
4833  if (gval.fSubwindowMode == kIncludeInferiors) {
4834  xgval.subwindow_mode = GDK_INCLUDE_INFERIORS;
4835  } else {
4836  xgval.subwindow_mode = GDK_CLIP_BY_CHILDREN;
4837  }
4838  }
4839  if (mask & kGCForeground) {
4840  xmask |= GDK_GC_FOREGROUND;
4841  xgval.foreground.pixel = gval.fForeground;
4842  xgval.foreground.red = GetRValue(gval.fForeground);
4843  xgval.foreground.green = GetGValue(gval.fForeground);
4844  xgval.foreground.blue = GetBValue(gval.fForeground);
4845  }
4846  if (mask & kGCBackground) {
4847  xmask |= GDK_GC_BACKGROUND;
4848  xgval.background.pixel = gval.fBackground;
4849  xgval.background.red = GetRValue(gval.fBackground);
4850  xgval.background.green = GetGValue(gval.fBackground);
4851  xgval.background.blue = GetBValue(gval.fBackground);
4852  }
4853  if (mask & kGCLineWidth) {
4854  xmask |= GDK_GC_LINE_WIDTH;
4855  xgval.line_width = gval.fLineWidth;
4856  }
4857  if (mask & kGCLineStyle) {
4858  xmask |= GDK_GC_LINE_STYLE;
4859  xgval.line_style = (GdkLineStyle) gval.fLineStyle; // ident mapping
4860  }
4861  if (mask & kGCCapStyle) {
4862  xmask |= GDK_GC_CAP_STYLE;
4863  xgval.cap_style = (GdkCapStyle) gval.fCapStyle; // ident mapping
4864  }
4865  if (mask & kGCJoinStyle) {
4866  xmask |= GDK_GC_JOIN_STYLE;
4867  xgval.join_style = (GdkJoinStyle) gval.fJoinStyle; // ident mapping
4868  }
4869  if ((mask & kGCFillStyle)) {
4870  xmask |= GDK_GC_FILL;
4871  xgval.fill = (GdkFill) gval.fFillStyle; // ident mapping
4872  }
4873  if ((mask & kGCTile)) {
4874  xmask |= GDK_GC_TILE;
4875  xgval.tile = (GdkPixmap *) gval.fTile;
4876  }
4877  if ((mask & kGCStipple)) {
4878  xmask |= GDK_GC_STIPPLE;
4879  xgval.stipple = (GdkPixmap *) gval.fStipple;
4880  }
4881  if ((mask & kGCTileStipXOrigin)) {
4882  xmask |= GDK_GC_TS_X_ORIGIN;
4883  xgval.ts_x_origin = gval.fTsXOrigin;
4884  }
4885  if ((mask & kGCTileStipYOrigin)) {
4886  xmask |= GDK_GC_TS_Y_ORIGIN;
4887  xgval.ts_y_origin = gval.fTsYOrigin;
4888  }
4889  if ((mask & kGCFont)) {
4890  xmask |= GDK_GC_FONT;
4891  xgval.font = (GdkFont *) gval.fFont;
4892  }
4893  if ((mask & kGCGraphicsExposures)) {
4894  xmask |= GDK_GC_EXPOSURES;
4895  xgval.graphics_exposures = gval.fGraphicsExposures;
4896  }
4897  if ((mask & kGCClipXOrigin)) {
4898  xmask |= GDK_GC_CLIP_X_ORIGIN;
4899  xgval.clip_x_origin = gval.fClipXOrigin;
4900  }
4901  if ((mask & kGCClipYOrigin)) {
4902  xmask |= GDK_GC_CLIP_Y_ORIGIN;
4903  xgval.clip_y_origin = gval.fClipYOrigin;
4904  }
4905  if ((mask & kGCClipMask)) {
4906  xmask |= GDK_GC_CLIP_MASK;
4907  xgval.clip_mask = (GdkPixmap *) gval.fClipMask;
4908  }
4909  } else {
4910  // map XValues to GCValues_t
4911  Mask_t mask = 0;
4912 
4913  if ((xmask & GDK_GC_FUNCTION)) {
4914  mask |= kGCFunction;
4915  gval.fFunction = (EGraphicsFunction) xgval.function; // ident mapping
4916  switch (xgval.function) {
4917  case GDK_CLEAR:
4918  gval.fFunction = kGXclear;
4919  break;
4920  case GDK_AND:
4921  gval.fFunction = kGXand;
4922  break;
4923  case GDK_AND_REVERSE:
4924  gval.fFunction = kGXandReverse;
4925  break;
4926  case GDK_COPY:
4927  gval.fFunction = kGXcopy;
4928  break;
4929  case GDK_AND_INVERT:
4930  gval.fFunction = kGXandInverted;
4931  break;
4932  case GDK_NOOP:
4933  gval.fFunction = kGXnoop;
4934  break;
4935  case GDK_XOR:
4936  gval.fFunction = kGXxor;
4937  break;
4938  case GDK_OR:
4939  gval.fFunction = kGXor;
4940  break;
4941  case GDK_EQUIV:
4942  gval.fFunction = kGXequiv;
4943  break;
4944  case GDK_INVERT:
4945  gval.fFunction = kGXinvert;
4946  break;
4947  case GDK_OR_REVERSE:
4948  gval.fFunction = kGXorReverse;
4949  break;
4950  case GDK_COPY_INVERT:
4951  gval.fFunction = kGXcopyInverted;
4952  break;
4953  case GDK_OR_INVERT:
4954  gval.fFunction = kGXorInverted;
4955  break;
4956  case GDK_NAND:
4957  gval.fFunction = kGXnand;
4958  break;
4959  case GDK_SET:
4960  gval.fFunction = kGXset;
4961  break;
4962  }
4963  }
4964  if (xmask & GDK_GC_SUBWINDOW) {
4965  mask |= kGCSubwindowMode;
4966  if (xgval.subwindow_mode == GDK_INCLUDE_INFERIORS)
4968  else
4970  }
4971  if ((xmask & GDK_GC_FOREGROUND)) {
4972  mask |= kGCForeground;
4973  gval.fForeground = xgval.foreground.pixel;
4974  }
4975  if ((xmask & GDK_GC_BACKGROUND)) {
4976  mask |= kGCBackground;
4977  gval.fBackground = xgval.background.pixel;
4978  }
4979  if ((xmask & GDK_GC_LINE_WIDTH)) {
4980  mask |= kGCLineWidth;
4981  gval.fLineWidth = xgval.line_width;
4982  }
4983  if ((xmask & GDK_GC_LINE_STYLE)) {
4984  mask |= kGCLineStyle;
4985  gval.fLineStyle = xgval.line_style; // ident mapping
4986  }
4987  if ((xmask & GDK_GC_CAP_STYLE)) {
4988  mask |= kGCCapStyle;
4989  gval.fCapStyle = xgval.cap_style; // ident mapping
4990  }
4991  if ((xmask & GDK_GC_JOIN_STYLE)) {
4992  mask |= kGCJoinStyle;
4993  gval.fJoinStyle = xgval.join_style; // ident mapping
4994  }
4995  if ((xmask & GDK_GC_FILL)) {
4996  mask |= kGCFillStyle;
4997  gval.fFillStyle = xgval.fill; // ident mapping
4998  }
4999  if ((xmask & GDK_GC_TILE)) {
5000  mask |= kGCTile;
5001  gval.fTile = (Pixmap_t) xgval.tile;
5002  }
5003  if ((xmask & GDK_GC_STIPPLE)) {
5004  mask |= kGCStipple;
5005  gval.fStipple = (Pixmap_t) xgval.stipple;
5006  }
5007  if ((xmask & GDK_GC_TS_X_ORIGIN)) {
5008  mask |= kGCTileStipXOrigin;
5009  gval.fTsXOrigin = xgval.ts_x_origin;
5010  }
5011  if ((xmask & GDK_GC_TS_Y_ORIGIN)) {
5012  mask |= kGCTileStipYOrigin;
5013  gval.fTsYOrigin = xgval.ts_y_origin;
5014  }
5015  if ((xmask & GDK_GC_FONT)) {
5016  mask |= kGCFont;
5017  gval.fFont = (FontH_t) xgval.font;
5018  }
5019  if ((xmask & GDK_GC_EXPOSURES)) {
5020  mask |= kGCGraphicsExposures;
5021  gval.fGraphicsExposures = (Bool_t) xgval.graphics_exposures;
5022  }
5023  if ((xmask & GDK_GC_CLIP_X_ORIGIN)) {
5024  mask |= kGCClipXOrigin;
5025  gval.fClipXOrigin = xgval.clip_x_origin;
5026  }
5027  if ((xmask & GDK_GC_CLIP_Y_ORIGIN)) {
5028  mask |= kGCClipYOrigin;
5029  gval.fClipYOrigin = xgval.clip_y_origin;
5030  }
5031  if ((xmask & GDK_GC_CLIP_MASK)) {
5032  mask |= kGCClipMask;
5033  gval.fClipMask = (Pixmap_t) xgval.clip_mask;
5034  }
5035  gval.fMask = mask;
5036  }
5037 }
5038 
5039 ////////////////////////////////////////////////////////////////////////////////
5040 /// Get window attributes and return filled in attributes structure.
5041 
5043 {
5044  if (!id) return;
5045 
5046  RECT rcClient, rcWind;
5047  ::GetClientRect((HWND)GDK_DRAWABLE_XID((GdkWindow *) id), &rcClient);
5048  ::GetWindowRect((HWND)GDK_DRAWABLE_XID((GdkWindow *) id), &rcWind);
5049 
5050  gdk_window_get_geometry((GdkWindow *) id, &attr.fX, &attr.fY,
5051  &attr.fWidth, &attr.fHeight, &attr.fDepth);
5052  attr.fX = ((rcWind.right - rcWind.left) - rcClient.right) / 2;
5053  attr.fY = ((rcWind.bottom - rcWind.top) - rcClient.bottom) - attr.fX;
5054 
5055  attr.fRoot = (Window_t) GDK_ROOT_PARENT();
5056  attr.fColormap = (Colormap_t) gdk_window_get_colormap((GdkWindow *) id);
5057  attr.fBorderWidth = 0;
5058  attr.fVisual = gdk_window_get_visual((GdkWindow *) id);
5059  attr.fClass = kInputOutput;
5060  attr.fBackingStore = kNotUseful;
5061  attr.fSaveUnder = kFALSE;
5062  attr.fMapInstalled = kTRUE;
5063  attr.fOverrideRedirect = kFALSE; // boolean value for override-redirect
5064 
5065  if (!gdk_window_is_visible((GdkWindow *) id)) {
5066  attr.fMapState = kIsUnmapped;
5067  } else if (!gdk_window_is_viewable((GdkWindow *) id)) {
5068  attr.fMapState = kIsUnviewable;
5069  } else {
5070  attr.fMapState = kIsViewable;
5071  }
5072 
5073  UInt_t tmp_mask = (UInt_t)gdk_window_get_events((GdkWindow *) id);
5074  UInt_t evmask;
5075  MapEventMask(evmask, tmp_mask, kFALSE);
5076 
5077  attr.fYourEventMask = evmask;
5078 }
5079 
5080 ////////////////////////////////////////////////////////////////////////////////
5081 ///
5082 
5084 {
5085  return 0;
5086 }
5087 
5088 ////////////////////////////////////////////////////////////////////////////////
5089 /// Get maximum number of planes.
5090 
5092 {
5093  return gdk_visual_get_best_depth();
5094 }
5095 
5096 ////////////////////////////////////////////////////////////////////////////////
5097 /// Return atom handle for atom_name. If it does not exist
5098 /// create it if only_if_exist is false. Atoms are used to communicate
5099 /// between different programs (i.e. window manager) via the X server.
5100 
5101 Atom_t TGWin32::InternAtom(const char *atom_name, Bool_t only_if_exist)
5102 {
5103  GdkAtom a = gdk_atom_intern((const gchar *) atom_name, only_if_exist);
5104 
5105  if (a == None) return kNone;
5106  return (Atom_t) a;
5107 }
5108 
5109 ////////////////////////////////////////////////////////////////////////////////
5110 /// Return handle to the default root window created when calling
5111 /// XOpenDisplay().
5112 
5114 {
5115  return (Window_t) GDK_ROOT_PARENT();
5116 }
5117 
5118 ////////////////////////////////////////////////////////////////////////////////
5119 /// Return the parent of the window.
5120 
5122 {
5123  if (!id) return (Window_t)0;
5124 
5125  return (Window_t)gdk_window_get_parent((GdkWindow *) id);
5126 }
5127 
5128 ////////////////////////////////////////////////////////////////////////////////
5129 /// Load font and query font. If font is not found 0 is returned,
5130 /// otherwise an opaque pointer to the FontStruct_t.
5131 /// Free the loaded font using DeleteFont().
5132 
5133 FontStruct_t TGWin32::LoadQueryFont(const char *font_name)
5134 {
5135  char family[100], weight[32], slant[32], fontname[256];
5136  Int_t n1, pixel, numfields;
5137 
5138  numfields = sscanf(font_name, "%s -%d%n", family, &pixel, &n1);
5139  if (numfields == 2) {
5140  sprintf(weight,"medium");
5141  if (strstr(font_name, "bold"))
5142  sprintf(weight,"bold");
5143  sprintf(slant,"r");
5144  if (strstr(font_name, "italic"))
5145  sprintf(slant,"i");
5146  sprintf(fontname, "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-iso8859-1",
5147  family, weight, slant, pixel);
5148  }
5149  else
5150  sprintf(fontname, "%s", font_name);
5151  return (FontStruct_t) gdk_font_load(fontname);
5152 }
5153 
5154 ////////////////////////////////////////////////////////////////////////////////
5155 /// Return handle to font described by font structure.
5156 
5158 {
5159  if (fs) {
5160  return (FontH_t)gdk_font_ref((GdkFont *) fs);
5161  }
5162  return 0;
5163 }
5164 
5165 ////////////////////////////////////////////////////////////////////////////////
5166 /// Explicitely delete font structure obtained with LoadQueryFont().
5167 
5169 {
5170  gdk_font_unref((GdkFont *) fs);
5171 }
5172 
5173 ////////////////////////////////////////////////////////////////////////////////
5174 /// Create a graphics context using the values set in gval (but only for
5175 /// those entries that are in the mask).
5176 
5178 {
5179  if (!id) return (GContext_t)0;
5180 
5181  GdkGCValues xgval;
5182  ULong_t xmask = 0;
5183 
5184  if (gval) MapGCValues(*gval, xmask, xgval, kTRUE);
5185 
5186  xgval.subwindow_mode = GDK_CLIP_BY_CHILDREN; // GDK_INCLUDE_INFERIORS;
5187 
5188  GdkGC *gc = gdk_gc_new_with_values((GdkDrawable *) id,
5189  &xgval, (GdkGCValuesMask)xmask);
5190  return (GContext_t) gc;
5191 }
5192 
5193 ////////////////////////////////////////////////////////////////////////////////
5194 /// Change entries in an existing graphics context, gc, by values from gval.
5195 
5197 {
5198  GdkGCValues xgval;
5199  ULong_t xmask = 0;
5200  Mask_t mask = 0;
5201 
5202  if (gval) {
5203  mask = gval->fMask;
5204  MapGCValues(*gval, xmask, xgval, kTRUE);
5205  }
5206  if (mask & kGCForeground) {
5207  gdk_gc_set_foreground((GdkGC *) gc, &xgval.foreground);
5208  }
5209  if (mask & kGCBackground) {
5210  gdk_gc_set_background((GdkGC *) gc, &xgval.background);
5211  }
5212  if (mask & kGCFont) {
5213  gdk_gc_set_font((GdkGC *) gc, xgval.font);
5214  }
5215  if (mask & kGCFunction) {
5216  gdk_gc_set_function((GdkGC *) gc, xgval.function);
5217  }
5218  if (mask & kGCFillStyle) {
5219  gdk_gc_set_fill((GdkGC *) gc, xgval.fill);
5220  }
5221  if (mask & kGCTile) {
5222  gdk_gc_set_tile((GdkGC *) gc, xgval.tile);
5223  }
5224  if (mask & kGCStipple) {
5225  gdk_gc_set_stipple((GdkGC *) gc, xgval.stipple);
5226  }
5227  if ((mask & kGCTileStipXOrigin) || (mask & kGCTileStipYOrigin)) {
5228  gdk_gc_set_ts_origin((GdkGC *) gc, xgval.ts_x_origin,
5229  xgval.ts_y_origin);
5230  }
5231  if ((mask & kGCClipXOrigin) || (mask & kGCClipYOrigin)) {
5232  gdk_gc_set_clip_origin((GdkGC *) gc, xgval.clip_x_origin,
5233  xgval.clip_y_origin);
5234  }
5235  if (mask & kGCClipMask) {
5236  gdk_gc_set_clip_mask((GdkGC *) gc, xgval.clip_mask);
5237  }
5238  if (mask & kGCGraphicsExposures) {
5239  gdk_gc_set_exposures((GdkGC *) gc, xgval.graphics_exposures);
5240  }
5241  if (mask & kGCLineWidth) {
5242  gdk_gc_set_values((GdkGC *) gc, &xgval, GDK_GC_LINE_WIDTH);
5243  }
5244  if (mask & kGCLineStyle) {
5245  gdk_gc_set_values((GdkGC *) gc, &xgval, GDK_GC_LINE_STYLE);
5246  }
5247  if (mask & kGCCapStyle) {
5248  gdk_gc_set_values((GdkGC *) gc, &xgval, GDK_GC_CAP_STYLE);
5249  }
5250  if (mask & kGCJoinStyle) {
5251  gdk_gc_set_values((GdkGC *) gc, &xgval, GDK_GC_JOIN_STYLE);
5252  }
5253  if (mask & kGCSubwindowMode) {
5254  gdk_gc_set_subwindow((GdkGC *) gc, xgval.subwindow_mode);
5255  }
5256 }
5257 
5258 ////////////////////////////////////////////////////////////////////////////////
5259 /// Copies graphics context from org to dest. Only the values specified
5260 /// in mask are copied. Both org and dest must exist.
5261 
5263 {
5264  GCValues_t gval;
5265  GdkGCValues xgval;
5266  ULong_t xmask;
5267 
5268  if (!mask) {
5269  // in this case copy all fields
5270  mask = (Mask_t) - 1;
5271  }
5272 
5273  gval.fMask = mask; // only set fMask used to convert to xmask
5274  MapGCValues(gval, xmask, xgval, kTRUE);
5275 
5276  gdk_gc_copy((GdkGC *) dest, (GdkGC *) org);
5277 }
5278 
5279 ////////////////////////////////////////////////////////////////////////////////
5280 /// Explicitely delete a graphics context.
5281 
5283 {
5284  gdk_gc_unref((GdkGC *) gc);
5285 }
5286 
5287 ////////////////////////////////////////////////////////////////////////////////
5288 /// Create cursor handle (just return cursor from cursor pool fCursors).
5289 
5291 {
5292  return (Cursor_t) fCursors[cursor];
5293 }
5294 
5295 ////////////////////////////////////////////////////////////////////////////////
5296 /// Creates a pixmap of the width and height you specified
5297 /// and returns a pixmap ID that identifies it.
5298 
5300 {
5301  GdkWindow *wid = (GdkWindow *)id;
5302  if (!id) wid = GDK_ROOT_PARENT();
5303 
5304  return (Pixmap_t) gdk_pixmap_new(wid, w, h, gdk_visual_get_best_depth());
5305 }
5306 
5307 ////////////////////////////////////////////////////////////////////////////////
5308 /// Create a pixmap from bitmap data. Ones will get foreground color and
5309 /// zeroes background color.
5310 
5312  UInt_t width, UInt_t height,
5313  ULong_t forecolor, ULong_t backcolor,
5314  Int_t depth)
5315 {
5316  GdkColor fore, back;
5317  fore.pixel = forecolor;
5318  fore.red = GetRValue(forecolor);
5319  fore.green = GetGValue(forecolor);
5320  fore.blue = GetBValue(forecolor);
5321 
5322  back.pixel = backcolor;
5323  back.red = GetRValue(backcolor);
5324  back.green = GetGValue(backcolor);
5325  back.blue = GetBValue(backcolor);
5326 
5327  GdkWindow *wid = (GdkWindow *)id;
5328  if (!id) wid = GDK_ROOT_PARENT();
5329 
5330  return (Pixmap_t) gdk_pixmap_create_from_data(wid, (char *) bitmap, width,
5331  height, depth, &fore, &back);
5332 }
5333 
5334 ////////////////////////////////////////////////////////////////////////////////
5335 /// Create a bitmap (i.e. pixmap with depth 1) from the bitmap data.
5336 
5338  UInt_t width, UInt_t height)
5339 {
5340  GdkWindow *wid = (GdkWindow *)id;
5341  if (!id) wid = GDK_ROOT_PARENT();
5342 
5343  Pixmap_t ret = (Pixmap_t) gdk_bitmap_create_from_data(wid,
5344  (char *)bitmap, width, height);
5345  return ret;
5346 }
5347 
5348 ////////////////////////////////////////////////////////////////////////////////
5349 /// Explicitely delete pixmap resource.
5350 
5352 {
5353  gdk_pixmap_unref((GdkPixmap *) pmap);
5354 }
5355 
5356 ////////////////////////////////////////////////////////////////////////////////
5357 /// Create a picture pixmap from data on file. The picture attributes
5358 /// are used for input and output. Returns kTRUE in case of success,
5359 /// kFALSE otherwise. If mask does not exist it is set to kNone.
5360 
5362  Pixmap_t & pict,
5363  Pixmap_t & pict_mask,
5364  PictureAttributes_t & attr)
5365 {
5366  GdkBitmap *gdk_pixmap_mask;
5367  if (strstr(filename, ".xpm") || strstr(filename, ".XPM")) {
5368  GdkWindow *wid = (GdkWindow *)id;
5369  if (!id) wid = GDK_ROOT_PARENT();
5370 
5371  pict = (Pixmap_t) gdk_pixmap_create_from_xpm(wid, &gdk_pixmap_mask, 0,
5372  filename);
5373  pict_mask = (Pixmap_t) gdk_pixmap_mask;
5374  } else if (strstr(filename, ".gif") || strstr(filename, ".GIF")) {
5375  pict = ReadGIF(0, 0, filename, id);
5376  pict_mask = kNone;
5377  }
5378 
5379  gdk_drawable_get_size((GdkPixmap *) pict, (int *) &attr.fWidth,
5380  (int *) &attr.fHeight);
5381  if (pict) {
5382  return kTRUE;
5383  }
5384  if (pict_mask) {
5385  pict_mask = kNone;
5386  }
5387  return kFALSE;
5388 }
5389 
5390 ////////////////////////////////////////////////////////////////////////////////
5391 /// Create a pixture pixmap from data. The picture attributes
5392 /// are used for input and output. Returns kTRUE in case of success,
5393 /// kFALSE otherwise. If mask does not exist it is set to kNone.
5394 
5396  Pixmap_t & pict,
5397  Pixmap_t & pict_mask,
5398  PictureAttributes_t & attr)
5399 {
5400  GdkBitmap *gdk_pixmap_mask;
5401  GdkWindow *wid = (GdkWindow *)id;
5402  if (!id) wid = GDK_ROOT_PARENT();
5403 
5404  pict = (Pixmap_t) gdk_pixmap_create_from_xpm_d(wid, &gdk_pixmap_mask, 0,
5405  data);
5406  pict_mask = (Pixmap_t) gdk_pixmap_mask;
5407 
5408  if (pict) {
5409  return kTRUE;
5410  }
5411  if (pict_mask) {
5412  pict_mask = kNone;
5413  }
5414  return kFALSE;
5415 }
5416 
5417 ////////////////////////////////////////////////////////////////////////////////
5418 /// Read picture data from file and store in ret_data. Returns kTRUE in
5419 /// case of success, kFALSE otherwise.
5420 
5421 Bool_t TGWin32::ReadPictureDataFromFile(const char *filename, char ***ret_data)
5422 {
5423  Bool_t ret = kFALSE;
5424  GdkPixmap *pxm = gdk_pixmap_create_from_xpm(NULL, NULL, NULL, filename);
5425  ret_data = 0;
5426 
5427  if (pxm==NULL) return kFALSE;
5428 
5429  HBITMAP hbm = (HBITMAP)GDK_DRAWABLE_XID(pxm);
5430  BITMAP bitmap;
5431 
5432  ret = ::GetObject(hbm, sizeof(HBITMAP), (LPVOID)&bitmap);
5433  ret_data = (char ***)&bitmap.bmBits;
5434  gdk_pixmap_unref(pxm);
5435  return ret;
5436 }
5437 
5438 ////////////////////////////////////////////////////////////////////////////////
5439 /// Delete picture data created by the function ReadPictureDataFromFile.
5440 
5442 {
5443  free(data);
5444 }
5445 
5446 ////////////////////////////////////////////////////////////////////////////////
5447 /// Specify a dash pattertn. Offset defines the phase of the pattern.
5448 /// Each element in the dash_list array specifies the length (in pixels)
5449 /// of a segment of the pattern. N defines the length of the list.
5450 
5451 void TGWin32::SetDashes(GContext_t gc, Int_t offset, const char *dash_list,
5452  Int_t n)
5453 {
5454  int i;
5455  gint8 dashes[32];
5456  for (i = 0; i < n; i++) {
5457  dashes[i] = (gint8) dash_list[i];
5458  }
5459  for (i = n; i < 32; i++) {
5460  dashes[i] = (gint8) 0;
5461  }
5462 
5463  gdk_gc_set_dashes((GdkGC *) gc, offset, dashes, n);
5464 }
5465 
5466 ////////////////////////////////////////////////////////////////////////////////
5467 /// Map a ColorStruct_t to a XColor structure.
5468 
5469 void TGWin32::MapColorStruct(ColorStruct_t * color, GdkColor & xcolor)
5470 {
5471  xcolor.pixel = color->fPixel;
5472  xcolor.red = color->fRed;
5473  xcolor.green = color->fGreen;
5474  xcolor.blue = color->fBlue;
5475 }
5476 
5477 ////////////////////////////////////////////////////////////////////////////////
5478 /// Parse string cname containing color name, like "green" or "#00FF00".
5479 /// It returns a filled in ColorStruct_t. Returns kFALSE in case parsing
5480 /// failed, kTRUE in case of success. On success, the ColorStruct_t
5481 /// fRed, fGreen and fBlue fields are all filled in and the mask is set
5482 /// for all three colors, but fPixel is not set.
5483 
5484 Bool_t TGWin32::ParseColor(Colormap_t cmap, const char *cname,
5485  ColorStruct_t & color)
5486 {
5487  GdkColor xc;
5488 
5489  if (gdk_color_parse((char *)cname, &xc)) {
5490  color.fPixel = xc.pixel = RGB(xc.red, xc.green, xc.blue);
5491  color.fRed = xc.red;
5492  color.fGreen = xc.green;
5493  color.fBlue = xc.blue;
5494  return kTRUE;
5495  }
5496  return kFALSE;
5497 }
5498 
5499 ////////////////////////////////////////////////////////////////////////////////
5500 /// Find and allocate a color cell according to the color values specified
5501 /// in the ColorStruct_t. If no cell could be allocated it returns kFALSE,
5502 /// otherwise kTRUE.
5503 
5505 {
5506  int status;
5507  GdkColor xc;
5508 
5509  xc.red = color.fRed;
5510  xc.green = color.fGreen;
5511  xc.blue = color.fBlue;
5512 
5513  status = gdk_colormap_alloc_color((GdkColormap *) cmap, &xc, FALSE, TRUE);
5514  color.fPixel = xc.pixel;
5515 
5516  return kTRUE; // status != 0 ? kTRUE : kFALSE;
5517 }
5518 
5519 ////////////////////////////////////////////////////////////////////////////////
5520 /// Fill in the primary color components for a specific pixel value.
5521 /// On input fPixel should be set on return the fRed, fGreen and
5522 /// fBlue components will be set.
5523 
5525 {
5526  GdkColor xc;
5527  xc.pixel = color.fPixel;
5528 
5529  GdkColorContext *cc = gdk_color_context_new(gdk_visual_get_system(), fColormap);
5530  gdk_color_context_query_color(cc, &xc);
5531  gdk_color_context_free(cc);
5532 
5533  color.fPixel = xc.pixel;
5534  color.fRed = xc.red;
5535  color.fGreen = xc.green;
5536  color.fBlue = xc.blue;
5537 }
5538 
5539 ////////////////////////////////////////////////////////////////////////////////
5540 /// Free color cell with specified pixel value.
5541 
5543 {
5544  // FIXME: to be implemented.
5545 }
5546 
5547 ////////////////////////////////////////////////////////////////////////////////
5548 /// Check if there is for window "id" an event of type "type". If there
5549 /// is fill in the event structure and return true. If no such event
5550 /// return false.
5551 
5553 {
5554  if (!id) return kFALSE;
5555 
5556  Event_t tev;
5557  GdkEvent xev;
5558 
5559  tev.fType = type;
5560  tev.fWindow = (Window_t) id;
5561  tev.fTime = 0;
5562  tev.fX = tev.fY = 0;
5563  tev.fXRoot = tev.fYRoot = 0;
5564  tev.fCode = 0;
5565  tev.fState = 0;
5566  tev.fWidth = tev.fHeight = 0;
5567  tev.fCount = 0;
5568  tev.fSendEvent = kFALSE;
5569  tev.fHandle = 0;
5570  tev.fFormat = 0;
5571  tev.fUser[0] = tev.fUser[1] = tev.fUser[2] = tev.fUser[3] = tev.fUser[4] = 0L;
5572 
5573  TGWin32MainThread::LockMSG();
5574  MapEvent(tev, xev, kTRUE);
5575  Bool_t r = gdk_check_typed_window_event((GdkWindow *) id, xev.type, &xev);
5576 
5577  if (r) MapEvent(ev, xev, kFALSE);
5578  TGWin32MainThread::UnlockMSG();
5579 
5580  return r ? kTRUE : kFALSE;
5581 }
5582 
5583 ////////////////////////////////////////////////////////////////////////////////
5584 /// Send event ev to window id.
5585 
5587 {
5588  if (!ev || !id) return;
5589 
5590  TGWin32MainThread::LockMSG();
5591  GdkEvent xev;
5592  MapEvent(*ev, xev, kTRUE);
5593  gdk_event_put(&xev);
5594  TGWin32MainThread::UnlockMSG();
5595 }
5596 
5597 ////////////////////////////////////////////////////////////////////////////////
5598 /// Returns number of pending events.
5599 
5601 {
5602  Int_t ret;
5603 
5604  TGWin32MainThread::LockMSG();
5605  ret = (Int_t)gdk_event_queue_find_first();
5606  TGWin32MainThread::UnlockMSG();
5607 
5608  return ret;
5609 }
5610 
5611 ////////////////////////////////////////////////////////////////////////////////
5612 /// Copies first pending event from event queue to Event_t structure
5613 /// and removes event from queue. Not all of the event fields are valid
5614 /// for each event type, except fType and fWindow.
5615 
5617 {
5618  TGWin32MainThread::LockMSG();
5619  GdkEvent *xev = gdk_event_unqueue();
5620 
5621  // fill in Event_t
5622  event.fType = kOtherEvent; // bb add
5623  if (xev == NULL) {
5624  TGWin32MainThread::UnlockMSG();
5625  return;
5626  }
5627  MapEvent(event, *xev, kFALSE);
5628  gdk_event_free (xev);
5629  TGWin32MainThread::UnlockMSG();
5630 }
5631 
5632 ////////////////////////////////////////////////////////////////////////////////
5633 /// Map modifier key state to or from X.
5634 
5635 void TGWin32::MapModifierState(UInt_t & state, UInt_t & xstate, Bool_t tox)
5636 {
5637  if (tox) {
5638  xstate = state;
5639  if (state & kAnyModifier) {
5640  xstate = GDK_MODIFIER_MASK;
5641  }
5642  } else {
5643  state = xstate;
5644  }
5645 }
5646 
5647 static void _set_event_time(GdkEvent &event, UInt_t time)
5648 {
5649  // set gdk event time
5650 
5651  switch (event.type) {
5652  case GDK_MOTION_NOTIFY:
5653  event.motion.time = time;
5654  case GDK_BUTTON_PRESS:
5655  case GDK_2BUTTON_PRESS:
5656  case GDK_3BUTTON_PRESS:
5657  case GDK_BUTTON_RELEASE:
5658  case GDK_SCROLL:
5659  event.button.time = time;
5660  case GDK_KEY_PRESS:
5661  case GDK_KEY_RELEASE:
5662  event.key.time = time;
5663  case GDK_ENTER_NOTIFY:
5664  case GDK_LEAVE_NOTIFY:
5665  event.crossing.time = time;
5666  case GDK_PROPERTY_NOTIFY:
5667  event.property.time = time;
5668  case GDK_SELECTION_CLEAR:
5669  case GDK_SELECTION_REQUEST:
5670  case GDK_SELECTION_NOTIFY:
5671  event.selection.time = time;
5672  case GDK_PROXIMITY_IN:
5673  case GDK_PROXIMITY_OUT:
5674  event.proximity.time = time;
5675  case GDK_DRAG_ENTER:
5676  case GDK_DRAG_LEAVE:
5677  case GDK_DRAG_MOTION:
5678  case GDK_DRAG_STATUS:
5679  case GDK_DROP_START:
5680  case GDK_DROP_FINISHED:
5681  event.dnd.time = time;
5682  default: /* use current time */
5683  break;
5684  }
5685 }
5686 
5687 ////////////////////////////////////////////////////////////////////////////////
5688 /// Map Event_t structure to gdk_event structure. If tox is false
5689 /// map the other way.
5690 
5691 void TGWin32::MapEvent(Event_t & ev, GdkEvent & xev, Bool_t tox)
5692 {
5693  if (tox) {
5694  // map from Event_t to gdk_event
5695  xev.type = GDK_NOTHING;
5696  if (ev.fType == kGKeyPress)
5697  xev.type = GDK_KEY_PRESS;
5698  if (ev.fType == kKeyRelease)
5699  xev.type = GDK_KEY_RELEASE;
5700  if (ev.fType == kButtonPress)
5701  xev.type = GDK_BUTTON_PRESS;
5702  if (ev.fType == kButtonRelease)
5703  xev.type = GDK_BUTTON_RELEASE;
5704  if (ev.fType == kMotionNotify)
5705  xev.type = GDK_MOTION_NOTIFY;
5706  if (ev.fType == kEnterNotify)
5707  xev.type = GDK_ENTER_NOTIFY;
5708  if (ev.fType == kLeaveNotify)
5709  xev.type = GDK_LEAVE_NOTIFY;
5710  if (ev.fType == kExpose)
5711  xev.type = GDK_EXPOSE;
5712  if (ev.fType == kConfigureNotify)
5713  xev.type = GDK_CONFIGURE;
5714  if (ev.fType == kMapNotify)
5715  xev.type = GDK_MAP;
5716  if (ev.fType == kUnmapNotify)
5717  xev.type = GDK_UNMAP;
5718  if (ev.fType == kDestroyNotify)
5719  xev.type = GDK_DESTROY;
5720  if (ev.fType == kClientMessage)
5721  xev.type = GDK_CLIENT_EVENT;
5722  if (ev.fType == kSelectionClear)
5723  xev.type = GDK_SELECTION_CLEAR;
5724  if (ev.fType == kSelectionRequest)
5725  xev.type = GDK_SELECTION_REQUEST;
5726  if (ev.fType == kSelectionNotify)
5727  xev.type = GDK_SELECTION_NOTIFY;
5728 
5729  xev.any.type = xev.type;
5730  xev.any.send_event = ev.fSendEvent;
5731  if (ev.fType == kDestroyNotify) {
5732  xev.any.window = (GdkWindow *) ev.fWindow;
5733  }
5734  if (ev.fType == kFocusIn) {
5735  xev.type = GDK_FOCUS_CHANGE;
5736  xev.focus_change.type = xev.type;
5737  xev.focus_change.window = (GdkWindow *) ev.fWindow;
5738  xev.focus_change.in = TRUE;
5739  }
5740  if (ev.fType == kFocusOut) {
5741  xev.type = GDK_FOCUS_CHANGE;
5742  xev.focus_change.type = xev.type;
5743  xev.focus_change.window = (GdkWindow *) ev.fWindow;
5744  xev.focus_change.in = FALSE;
5745  }
5746  if (ev.fType == kGKeyPress || ev.fType == kKeyRelease) {
5747  xev.key.window = (GdkWindow *) ev.fWindow;
5748  xev.key.type = xev.type;
5749  MapModifierState(ev.fState, xev.key.state, kTRUE); // key mask
5750  xev.key.keyval = ev.fCode; // key code
5751  }
5752  if (ev.fType == kButtonPress || ev.fType == kButtonRelease) {
5753  xev.button.window = (GdkWindow *) ev.fWindow;
5754  xev.button.type = xev.type;
5755  xev.button.x = ev.fX;
5756  xev.button.y = ev.fY;
5757  xev.button.x_root = ev.fXRoot;
5758  xev.button.y_root = ev.fYRoot;
5759  MapModifierState(ev.fState, xev.button.state, kTRUE); // button mask
5760  xev.button.button = ev.fCode; // button code
5761  }
5762  if (ev.fType == kSelectionNotify) {
5763  xev.selection.window = (GdkWindow *) ev.fUser[0];
5764  xev.selection.requestor = (guint32) ev.fUser[0];
5765  xev.selection.selection = (GdkAtom) ev.fUser[1];
5766  xev.selection.target = (GdkAtom) ev.fUser[2];
5767  xev.selection.property = (GdkAtom) ev.fUser[3];
5768  xev.selection.type = xev.type;
5769  }
5770  if (ev.fType == kClientMessage) {
5771  if ((ev.fFormat == 32) && (ev.fHandle == gWM_DELETE_WINDOW)) {
5772  xev.type = GDK_DELETE;
5773  xev.any.type = xev.type;
5774  xev.any.window = (GdkWindow *) ev.fWindow;
5775  } else {
5776  xev.client.window = (GdkWindow *) ev.fWindow;
5777  xev.client.type = xev.type;
5778  xev.client.message_type = (GdkAtom) ev.fHandle;
5779  xev.client.data_format = ev.fFormat;
5780  xev.client.data.l[0] = ev.fUser[0];
5781  if (sizeof(ev.fUser[0]) > 4) {
5782  SplitLong(ev.fUser[1], xev.client.data.l[1],
5783  xev.client.data.l[3]);
5784  SplitLong(ev.fUser[2], xev.client.data.l[2],
5785  xev.client.data.l[4]);
5786  } else {
5787  xev.client.data.l[1] = ev.fUser[1];
5788  xev.client.data.l[2] = ev.fUser[2];
5789  xev.client.data.l[3] = ev.fUser[3];
5790  xev.client.data.l[4] = ev.fUser[4];
5791  }
5792  }
5793  }
5794  if (ev.fType == kMotionNotify) {
5795  xev.motion.window = (GdkWindow *) ev.fWindow;
5796  xev.motion.type = xev.type;
5797  xev.motion.x = ev.fX;
5798  xev.motion.y = ev.fY;
5799  xev.motion.x_root = ev.fXRoot;
5800  xev.motion.y_root = ev.fYRoot;
5801  }
5802  if ((ev.fType == kEnterNotify) || (ev.fType == kLeaveNotify)) {
5803  xev.crossing.window = (GdkWindow *) ev.fWindow;
5804  xev.crossing.type = xev.type;
5805  xev.crossing.x = ev.fX;
5806  xev.crossing.y = ev.fY;
5807  xev.crossing.x_root = ev.fXRoot;
5808  xev.crossing.y_root = ev.fYRoot;
5809  xev.crossing.mode = (GdkCrossingMode) ev.fCode; // NotifyNormal, NotifyGrab, NotifyUngrab
5810  MapModifierState(ev.fState, xev.crossing.state, kTRUE); // key or button mask
5811  }
5812  if (ev.fType == kExpose) {
5813  xev.expose.window = (GdkWindow *) ev.fWindow;
5814  xev.expose.type = xev.type;
5815  xev.expose.area.x = ev.fX;
5816  xev.expose.area.y = ev.fY;
5817  xev.expose.area.width = ev.fWidth; // width and
5818  xev.expose.area.height = ev.fHeight; // height of exposed area
5819  xev.expose.count = ev.fCount; // number of expose events still to come
5820  }
5821  if (ev.fType == kConfigureNotify) {
5822  xev.configure.window = (GdkWindow *) ev.fWindow;
5823  xev.configure.type = xev.type;
5824  xev.configure.x = ev.fX;
5825  xev.configure.y = ev.fY;
5826  xev.configure.width = ev.fWidth;
5827  xev.configure.height = ev.fHeight;
5828  }
5829  if (ev.fType == kSelectionClear) {
5830  xev.selection.window = (GdkWindow *) ev.fWindow;
5831  xev.selection.type = xev.type;
5832  xev.selection.selection = ev.fUser[0];
5833  }
5834  if (ev.fType == kSelectionRequest) {
5835  xev.selection.window = (GdkWindow *) ev.fUser[0];
5836  xev.selection.type = xev.type;
5837  xev.selection.selection = ev.fUser[1];
5838  xev.selection.target = ev.fUser[2];
5839  xev.selection.property = ev.fUser[3];
5840  }
5841  if ((ev.fType == kMapNotify) || (ev.fType == kUnmapNotify)) {
5842  xev.any.window = (GdkWindow *) ev.fWindow;
5843  }
5844  if (xev.type != GDK_CLIENT_EVENT)
5845  _set_event_time(xev, ev.fTime);
5846  } else {
5847  // map from gdk_event to Event_t
5848  ev.fType = kOtherEvent;
5849  if (xev.type == GDK_KEY_PRESS)
5850  ev.fType = kGKeyPress;
5851  if (xev.type == GDK_KEY_RELEASE)
5852  ev.fType = kKeyRelease;
5853  if (xev.type == GDK_BUTTON_PRESS)
5854  ev.fType = kButtonPress;
5855  if (xev.type == GDK_BUTTON_RELEASE)
5856  ev.fType = kButtonRelease;
5857  if (xev.type == GDK_MOTION_NOTIFY)
5858  ev.fType = kMotionNotify;
5859  if (xev.type == GDK_ENTER_NOTIFY)
5860  ev.fType = kEnterNotify;
5861  if (xev.type == GDK_LEAVE_NOTIFY)
5862  ev.fType = kLeaveNotify;
5863  if (xev.type == GDK_EXPOSE)
5864  ev.fType = kExpose;
5865  if (xev.type == GDK_CONFIGURE)
5866  ev.fType = kConfigureNotify;
5867  if (xev.type == GDK_MAP)
5868  ev.fType = kMapNotify;
5869  if (xev.type == GDK_UNMAP)
5870  ev.fType = kUnmapNotify;
5871  if (xev.type == GDK_DESTROY)
5872  ev.fType = kDestroyNotify;
5873  if (xev.type == GDK_SELECTION_CLEAR)
5874  ev.fType = kSelectionClear;
5875  if (xev.type == GDK_SELECTION_REQUEST)
5876  ev.fType = kSelectionRequest;
5877  if (xev.type == GDK_SELECTION_NOTIFY)
5878  ev.fType = kSelectionNotify;
5879 
5880  ev.fSendEvent = kFALSE; //xev.any.send_event ? kTRUE : kFALSE;
5881  ev.fTime = gdk_event_get_time((GdkEvent *)&xev);
5882  ev.fWindow = (Window_t) xev.any.window;
5883 
5884  if ((xev.type == GDK_MAP) || (xev.type == GDK_UNMAP)) {
5885  ev.fWindow = (Window_t) xev.any.window;
5886  }
5887  if (xev.type == GDK_DELETE) {
5888  ev.fWindow = (Window_t) xev.any.window;
5889  ev.fType = kClientMessage;
5890  ev.fFormat = 32;
5892  ev.fUser[0] = (Long_t) gWM_DELETE_WINDOW;
5893  if (sizeof(ev.fUser[0]) > 4) {
5894  AsmLong(xev.client.data.l[1], xev.client.data.l[3],
5895  ev.fUser[1]);
5896  AsmLong(xev.client.data.l[2], xev.client.data.l[4],
5897  ev.fUser[2]);
5898  } else {
5899  ev.fUser[1] = 0; //xev.client.data.l[1];
5900  ev.fUser[2] = 0; //xev.client.data.l[2];
5901  ev.fUser[3] = 0; //xev.client.data.l[3];
5902  ev.fUser[4] = 0; //xev.client.data.l[4];
5903  }
5904  }
5905  if (xev.type == GDK_DESTROY) {
5906  ev.fType = kDestroyNotify;
5907  ev.fHandle = (Window_t) xev.any.window; // window to be destroyed
5908  ev.fWindow = (Window_t) xev.any.window;
5909  }
5910  if (xev.type == GDK_FOCUS_CHANGE) {
5911  ev.fWindow = (Window_t) xev.focus_change.window;
5912  ev.fCode = kNotifyNormal;
5913  ev.fState = 0;
5914  if (xev.focus_change.in == TRUE) {
5915  ev.fType = kFocusIn;
5916  } else {
5917  ev.fType = kFocusOut;
5918  }
5919  }
5920  if (ev.fType == kGKeyPress || ev.fType == kKeyRelease) {
5921  ev.fWindow = (Window_t) xev.key.window;
5922  MapModifierState(ev.fState, xev.key.state, kFALSE); // key mask
5923  ev.fCode = xev.key.keyval; // key code
5924  ev.fUser[1] = xev.key.length;
5925  if (xev.key.length > 0) ev.fUser[2] = xev.key.string[0];
5926  if (xev.key.length > 1) ev.fUser[3] = xev.key.string[1];
5927  if (xev.key.length > 2) ev.fUser[4] = xev.key.string[2];
5928  HWND tmpwin = (HWND) GetWindow((HWND) GDK_DRAWABLE_XID((GdkWindow *)xev.key.window), GW_CHILD);
5929  if (tmpwin) {
5930  ev.fUser[0] = (ULong_t) gdk_xid_table_lookup((HANDLE)tmpwin);
5931  } else {
5932  ev.fUser[0] = (ULong_t) xev.key.window;
5933  }
5934  }
5935  if (ev.fType == kButtonPress || ev.fType == kButtonRelease) {
5936  ev.fWindow = (Window_t) xev.button.window;
5937  ev.fX = xev.button.x;
5938  ev.fY = xev.button.y;
5939  ev.fXRoot = xev.button.x_root;
5940  ev.fYRoot = xev.button.y_root;
5941  MapModifierState(ev.fState, xev.button.state, kFALSE); // button mask
5942  ev.fCode = xev.button.button; // button code
5943  POINT tpoint;
5944  tpoint.x = xev.button.x;
5945  tpoint.y = xev.button.y;
5946  HWND tmpwin = ChildWindowFromPoint((HWND) GDK_DRAWABLE_XID((GdkWindow *)xev.button.window), tpoint);
5947  if (tmpwin) {
5948  ev.fUser[0] = (ULong_t) gdk_xid_table_lookup((HANDLE)tmpwin);
5949  } else {
5950  ev.fUser[0] = (ULong_t) 0;
5951  }
5952  }
5953  if (ev.fType == kMotionNotify) {
5954  ev.fWindow = (Window_t) xev.motion.window;
5955  ev.fX = xev.motion.x;
5956  ev.fY = xev.motion.y;
5957  ev.fXRoot = xev.motion.x_root;
5958  ev.fYRoot = xev.motion.y_root;
5959  MapModifierState(ev.fState, xev.motion.state, kFALSE); // key or button mask
5960 
5961  POINT tpoint;
5962  tpoint.x = xev.button.x;
5963  tpoint.y = xev.button.y;
5964  HWND tmpwin = ChildWindowFromPoint((HWND) GDK_DRAWABLE_XID((GdkWindow *)xev.motion.window), tpoint);
5965  if (tmpwin) {
5966  ev.fUser[0] = (ULong_t)gdk_xid_table_lookup((HANDLE)tmpwin);
5967  } else {
5968  ev.fUser[0] = (ULong_t) xev.motion.window;
5969  }
5970  }
5971  if (ev.fType == kEnterNotify || ev.fType == kLeaveNotify) {
5972  ev.fWindow = (Window_t) xev.crossing.window;
5973  ev.fX = xev.crossing.x;
5974  ev.fY = xev.crossing.y;
5975  ev.fXRoot = xev.crossing.x_root;
5976  ev.fYRoot = xev.crossing.y_root;
5977  ev.fCode = xev.crossing.mode; // NotifyNormal, NotifyGrab, NotifyUngrab
5978  MapModifierState(ev.fState, xev.crossing.state, kFALSE); // key or button mask
5979  }
5980  if (ev.fType == kExpose) {
5981  ev.fWindow = (Window_t) xev.expose.window;
5982  ev.fX = xev.expose.area.x;
5983  ev.fY = xev.expose.area.y;
5984  ev.fWidth = xev.expose.area.width; // width and
5985  ev.fHeight = xev.expose.area.height; // height of exposed area
5986  ev.fCount = xev.expose.count; // number of expose events still to come
5987  }
5988  if (ev.fType == kConfigureNotify) {
5989  ev.fWindow = (Window_t) xev.configure.window;
5990  ev.fX = xev.configure.x;
5991  ev.fY = xev.configure.y;
5992  ev.fWidth = xev.configure.width;
5993  ev.fHeight = xev.configure.height;
5994  }
5995  if (xev.type == GDK_CLIENT_EVENT) {
5996  ev.fWindow = (Window_t) xev.client.window;
5997  ev.fType = kClientMessage;
5998  ev.fHandle = xev.client.message_type;
5999  ev.fFormat = xev.client.data_format;
6000  ev.fUser[0] = xev.client.data.l[0];
6001  if (sizeof(ev.fUser[0]) > 4) {
6002  AsmLong(xev.client.data.l[1], xev.client.data.l[3],
6003  ev.fUser[1]);
6004  AsmLong(xev.client.data.l[2], xev.client.data.l[4],
6005  ev.fUser[2]);
6006  } else {
6007  ev.fUser[1] = xev.client.data.l[1];
6008  ev.fUser[2] = xev.client.data.l[2];
6009  ev.fUser[3] = xev.client.data.l[3];
6010  ev.fUser[4] = xev.client.data.l[4];
6011  }
6012  }
6013  if (ev.fType == kSelectionClear) {
6014  ev.fWindow = (Window_t) xev.selection.window;
6015  ev.fUser[0] = xev.selection.selection;
6016  }
6017  if (ev.fType == kSelectionRequest) {
6018  ev.fWindow = (Window_t) xev.selection.window;
6019  ev.fUser[0] = (ULong_t) xev.selection.window;
6020  ev.fUser[1] = xev.selection.selection;
6021  ev.fUser[2] = xev.selection.target;
6022  ev.fUser[3] = xev.selection.property;
6023  }
6024  if (ev.fType == kSelectionNotify) {
6025  ev.fWindow = (Window_t) xev.selection.window;
6026  ev.fUser[0] = (ULong_t) xev.selection.window;
6027  ev.fUser[1] = xev.selection.selection;
6028  ev.fUser[2] = xev.selection.target;
6029  ev.fUser[3] = xev.selection.property;
6030  }
6031  if (xev.type == GDK_SCROLL) {
6032  ev.fType = kButtonRelease;
6033  if (xev.scroll.direction == GDK_SCROLL_UP) {
6034  ev.fCode = kButton4;
6035  } else if (xev.scroll.direction == GDK_SCROLL_DOWN) {
6036  ev.fCode = kButton5;
6037  }
6038  ev.fWindow = (Window_t) xev.scroll.window;
6039  ev.fX = xev.scroll.x;
6040  ev.fY = xev.scroll.y;
6041  ev.fXRoot = xev.scroll.x_root;
6042  ev.fYRoot = xev.scroll.y_root;
6043  POINT tpoint;
6044  tpoint.x = xev.scroll.x;
6045  tpoint.y = xev.scroll.y;
6046  HWND tmpwin = ChildWindowFromPoint((HWND) GDK_DRAWABLE_XID((GdkWindow *)xev.scroll.window), tpoint);
6047  if (tmpwin) {
6048  ev.fUser[0] = (ULong_t)gdk_xid_table_lookup((HANDLE)tmpwin);
6049  } else {
6050  ev.fUser[0] = (ULong_t) 0;
6051  }
6052  }
6053  }
6054 }
6055 
6056 ////////////////////////////////////////////////////////////////////////////////
6057 ///
6058 
6059 void TGWin32::Bell(Int_t percent)
6060 {
6061  gSystem->Beep();
6062 }
6063 
6064 ////////////////////////////////////////////////////////////////////////////////
6065 /// Copy a drawable (i.e. pixmap) to another drawable (pixmap, window).
6066 /// The graphics context gc will be used and the source will be copied
6067 /// from src_x,src_y,src_x+width,src_y+height to dest_x,dest_y.
6068 
6070  Int_t src_x, Int_t src_y, UInt_t width,
6071  UInt_t height, Int_t dest_x, Int_t dest_y)
6072 {
6073  if (!src || !dest) return;
6074 
6075  gdk_window_copy_area((GdkDrawable *) dest, (GdkGC *) gc, dest_x, dest_y,
6076  (GdkDrawable *) src, src_x, src_y, width, height);
6077 }
6078 
6079 ////////////////////////////////////////////////////////////////////////////////
6080 /// Change window attributes.
6081 
6083 {
6084  if (!id) return;
6085 
6086  GdkColor color;
6087  UInt_t xevmask;
6088  Mask_t evmask;
6089 
6090  if (attr && (attr->fMask & kWAEventMask)) {
6091  evmask = (Mask_t) attr->fEventMask;
6092  MapEventMask(evmask, xevmask);
6093  gdk_window_set_events((GdkWindow *) id, (GdkEventMask) xevmask);
6094  }
6095  if (attr && (attr->fMask & kWABackPixel)) {
6096  color.pixel = attr->fBackgroundPixel;
6097  color.red = GetRValue(attr->fBackgroundPixel);
6098  color.green = GetGValue(attr->fBackgroundPixel);
6099  color.blue = GetBValue(attr->fBackgroundPixel);
6100  gdk_window_set_background((GdkWindow *) id, &color);
6101  }
6102 // if (attr && (attr->fMask & kWAOverrideRedirect))
6103 // gdk_window_set_override_redirect ((GdkWindow *) id, attr->fOverrideRedirect);
6104  if (attr && (attr->fMask & kWABackPixmap)) {
6105  gdk_window_set_back_pixmap((GdkWindow *) id,
6106  (GdkPixmap *) attr->fBackgroundPixmap, 0);
6107  }
6108  if (attr && (attr->fMask & kWACursor)) {
6109  gdk_window_set_cursor((GdkWindow *) id, (GdkCursor *) attr->fCursor);
6110  }
6111  if (attr && (attr->fMask & kWAColormap)) {
6112  gdk_window_set_colormap((GdkWindow *) id,(GdkColormap *) attr->fColormap);
6113  }
6114  if (attr && (attr->fMask & kWABorderWidth)) {
6115  if (attr->fBorderWidth > 0) {
6116  gdk_window_set_decorations((GdkWindow *) id,
6117  (GdkWMDecoration) GDK_DECOR_BORDER);
6118  }
6119  }
6120 }
6121 
6122 ////////////////////////////////////////////////////////////////////////////////
6123 /// This function alters the property for the specified window and
6124 /// causes the X server to generate a PropertyNotify event on that
6125 /// window.
6126 
6128  UChar_t * data, Int_t len)
6129 {
6130  if (!id) return;
6131 
6132  gdk_property_change((GdkWindow *) id, (GdkAtom) property,
6133  (GdkAtom) type, 8, GDK_PROP_MODE_REPLACE, data,len);
6134 }
6135 
6136 ////////////////////////////////////////////////////////////////////////////////
6137 /// Draw a line.
6138 
6140  Int_t x2, Int_t y2)
6141 {
6142  if (!id) return;
6143 
6144  gdk_draw_line((GdkDrawable *) id, (GdkGC *) gc, x1, y1, x2, y2);
6145 }
6146 
6147 ////////////////////////////////////////////////////////////////////////////////
6148 /// Clear a window area to the bakcground color.
6149 
6151 {
6152  if (!id) return;
6153 
6154  gdk_window_clear_area((GdkWindow *) id, x, y, w, h);
6155 }
6156 
6157 ////////////////////////////////////////////////////////////////////////////////
6158 /// Tell WM to send message when window is closed via WM.
6159 
6161 {
6162  if (!id) return;
6163 
6164  Atom prop;
6165  prop = (Atom_t) gdk_atom_intern("WM_DELETE_WINDOW", FALSE);
6166 
6167  W32ChangeProperty((HWND) GDK_DRAWABLE_XID((GdkWindow *) id),
6168  prop, XA_ATOM, 32, GDK_PROP_MODE_REPLACE,
6169  (unsigned char *) &gWM_DELETE_WINDOW, 1);
6170 }
6171 
6172 ////////////////////////////////////////////////////////////////////////////////
6173 /// Turn key auto repeat on or off.
6174 
6176 {
6177  if (on) {
6178  gdk_key_repeat_restore();
6179  } else {
6180  gdk_key_repeat_disable();
6181  }
6182 }
6183 
6184 ////////////////////////////////////////////////////////////////////////////////
6185 /// Establish passive grab on a certain key. That is, when a certain key
6186 /// keycode is hit while certain modifier's (Shift, Control, Meta, Alt)
6187 /// are active then the keyboard will be grabed for window id.
6188 /// When grab is false, ungrab the keyboard for this key and modifier.
6189 
6190 void TGWin32::GrabKey(Window_t id, Int_t keycode, UInt_t modifier, Bool_t grab)
6191 {
6192  UInt_t xmod;
6193 
6194  MapModifierState(modifier, xmod);
6195 
6196  if (grab) {
6197  gdk_key_grab(keycode, (GdkEventMask)xmod, (GdkWindow *)id);
6198  } else {
6199  gdk_key_ungrab(keycode, (GdkEventMask)xmod, (GdkWindow *)id);
6200  }
6201 }
6202 
6203 ////////////////////////////////////////////////////////////////////////////////
6204 /// Establish passive grab on a certain mouse button. That is, when a
6205 /// certain mouse button is hit while certain modifier's (Shift, Control,
6206 /// Meta, Alt) are active then the mouse will be grabed for window id.
6207 /// When grab is false, ungrab the mouse button for this button and modifier.
6208 
6210  UInt_t evmask, Window_t confine, Cursor_t cursor,
6211  Bool_t grab)
6212 {
6213  UInt_t xevmask;
6214  UInt_t xmod;
6215 
6216  if (!id) return;
6217 
6218  MapModifierState(modifier, xmod);
6219 
6220  if (grab) {
6221  MapEventMask(evmask, xevmask);
6222  gdk_button_grab(button, xmod, ( GdkWindow *)id, 1, (GdkEventMask)xevmask,
6223  (GdkWindow*)confine, (GdkCursor*)cursor);
6224  } else {
6225  gdk_button_ungrab(button, xmod, ( GdkWindow *)id);
6226  }
6227 }
6228 
6229 ////////////////////////////////////////////////////////////////////////////////
6230 /// Establish an active pointer grab. While an active pointer grab is in
6231 /// effect, further pointer events are only reported to the grabbing
6232 /// client window.
6233 
6235  Cursor_t cursor, Bool_t grab, Bool_t owner_events)
6236 {
6237  UInt_t xevmask;
6238  MapEventMask(evmask, xevmask);
6239 
6240  if (grab) {
6241  if(!::IsWindowVisible((HWND)GDK_DRAWABLE_XID(id))) return;
6242  gdk_pointer_grab((GdkWindow *) id, owner_events, (GdkEventMask) xevmask,
6243  (GdkWindow *) confine, (GdkCursor *) cursor,
6244  GDK_CURRENT_TIME);
6245  } else {
6246  gdk_pointer_ungrab(GDK_CURRENT_TIME);
6247  ::SetCursor((HCURSOR)GDK_CURSOR_XID(fCursors[kPointer]));
6248  }
6249 }
6250 
6251 ////////////////////////////////////////////////////////////////////////////////
6252 /// Set window name.
6253 
6255 {
6256  if (!id) return;
6257 
6258  gdk_window_set_title((GdkWindow *) id, name);
6259 }
6260 
6261 ////////////////////////////////////////////////////////////////////////////////
6262 /// Set window icon name.
6263 
6265 {
6266  if (!id) return;
6267 
6268  gdk_window_set_icon_name((GdkWindow *) id, name);
6269 }
6270 
6271 ////////////////////////////////////////////////////////////////////////////////
6272 /// Set pixmap the WM can use when the window is iconized.
6273 
6275 {
6276  if (!id) return;
6277 
6278  gdk_window_set_icon((GdkWindow *)id, NULL, (GdkPixmap *)pic, (GdkPixmap *)pic);
6279 }
6280 
6281 #define safestrlen(s) ((s) ? strlen(s) : 0)
6282 
6283 ////////////////////////////////////////////////////////////////////////////////
6284 /// Set the windows class and resource name.
6285 
6286 void TGWin32::SetClassHints(Window_t id, char *className, char *resourceName)
6287 {
6288  if (!id) return;
6289 
6290  char *class_string;
6291  char *s;
6292  int len_nm, len_cl;
6293  GdkAtom prop;
6294 
6295  prop = gdk_atom_intern("WM_CLASS", kFALSE);
6296 
6297  len_nm = safestrlen(resourceName);
6298  len_cl = safestrlen(className);
6299 
6300  if ((class_string = s =
6301  (char *) malloc((unsigned) (len_nm + len_cl + 2)))) {
6302  if (len_nm) {
6303  strcpy(s, resourceName);
6304  s += len_nm + 1;
6305  } else
6306  *s++ = '\0';
6307  if (len_cl) {
6308  strcpy(s, className);
6309  } else {
6310  *s = '\0';
6311  }
6312 
6313  W32ChangeProperty((HWND) GDK_DRAWABLE_XID((GdkWindow *) id),
6314  (Atom) XA_WM_CLASS, (Atom) XA_WM_CLASS, 8,
6315  GDK_PROP_MODE_REPLACE,
6316  (unsigned char *) class_string,
6317  len_nm + len_cl + 2);
6318  free(class_string);
6319  }
6320 }
6321 
6322 ////////////////////////////////////////////////////////////////////////////////
6323 /// Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
6324 
6326  UInt_t input)
6327 {
6328  if (!id) return;
6329 
6330  gdk_window_set_decorations((GdkDrawable *) id, (GdkWMDecoration) value);
6331  gdk_window_set_functions((GdkDrawable *) id, (GdkWMFunction) funcs);
6332 }
6333 
6334 ////////////////////////////////////////////////////////////////////////////////
6335 ///
6336 
6338 {
6339  if (!id) return;
6340 
6341  gdk_window_move((GdkDrawable *) id, x, y);
6342 }
6343 
6344 ////////////////////////////////////////////////////////////////////////////////
6345 ///
6346 
6348 {
6349  if (!id) return;
6350 
6351  gdk_window_resize((GdkWindow *) id, w, h);
6352 }
6353 
6354 ////////////////////////////////////////////////////////////////////////////////
6355 /// Give the window manager minimum and maximum size hints. Also
6356 /// specify via winc and hinc the resize increments.
6357 
6359  UInt_t wmax, UInt_t hmax,
6360  UInt_t winc, UInt_t hinc)
6361 {
6362  if (!id) return;
6363 
6364  GdkGeometry hints;
6365  GdkWindowHints flags;
6366 
6367  flags = (GdkWindowHints) (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE |
6368  GDK_HINT_RESIZE_INC);
6369  hints.min_width = (Int_t) wmin;
6370  hints.max_width = (Int_t) wmax;
6371  hints.min_height = (Int_t) hmin;
6372  hints.max_height = (Int_t) hmax;
6373  hints.width_inc = (Int_t) winc;
6374  hints.height_inc = (Int_t) hinc;
6375 
6376  gdk_window_set_geometry_hints((GdkWindow *) id, (GdkGeometry *) &hints,
6377  (GdkWindowHints) flags);
6378 }
6379 
6380 ////////////////////////////////////////////////////////////////////////////////
6381 /// Set the initial state of the window. Either kNormalState or kIconicState.
6382 
6384 {
6385  if (!id) return;
6386 
6387 #if 0
6388  XWMHints hints;
6389  Int_t xstate = NormalState;
6390 
6391  if (state == kNormalState)
6392  xstate = NormalState;
6393  if (state == kIconicState)
6394  xstate = IconicState;
6395 
6396  hints.flags = StateHint;
6397  hints.initial_state = xstate;
6398 
6399  XSetWMHints((GdkWindow *) id, &hints);
6400 #endif
6401 }
6402 
6403 ////////////////////////////////////////////////////////////////////////////////
6404 /// Tell window manager that window is a transient window of gdk_parent_root.
6405 
6407 {
6408  if (!id) return;
6409 
6410  gdk_window_set_transient_for((GdkWindow *) id, (GdkWindow *) main_id);
6411 }
6412 
6413 ////////////////////////////////////////////////////////////////////////////////
6414 /// Draw a string using a specific graphics context in position (x,y).
6415 
6417  const char *s, Int_t len)
6418 {
6419  if (!id) return;
6420 
6421  GdkGCValues values;
6422  gdk_gc_get_values((GdkGC *) gc, &values);
6423  gdk_win32_draw_text((GdkDrawable *) id, (GdkFont *) values.font,
6424  (GdkGC *) gc, x, y, (const gchar *)s, len);
6425 }
6426 
6427 ////////////////////////////////////////////////////////////////////////////////
6428 /// Return length of string in pixels. Size depends on font.
6429 
6430 Int_t TGWin32::TextWidth(FontStruct_t font, const char *s, Int_t len)
6431 {
6432  return gdk_text_width((GdkFont *)font, s, len);
6433 }
6434 
6435 ////////////////////////////////////////////////////////////////////////////////
6436 /// Return some font properties.
6437 
6439  Int_t & max_descent)
6440 {
6441  GdkFont *f = (GdkFont *) font;
6442  max_ascent = f->ascent;
6443  max_descent = f->descent;
6444 }
6445 
6446 ////////////////////////////////////////////////////////////////////////////////
6447 /// Get current values from graphics context gc. Which values of the
6448 /// context to get is encoded in the GCValues::fMask member.
6449 
6451 {
6452  GdkGCValues xgval;
6453  ULong_t xmask;
6454 
6455  MapGCValues(gval, xmask, xgval, kTRUE);
6456  gdk_gc_get_values((GdkGC *) gc, &xgval);
6457  MapGCValues(gval, xmask, xgval, kFALSE);
6458 }
6459 
6460 ////////////////////////////////////////////////////////////////////////////////
6461 /// Retrieve associated font structure once we have the font handle.
6462 /// Free returned FontStruct_t using FreeFontStruct().
6463 
6465 {
6466  return (FontStruct_t) gdk_font_ref((GdkFont *) fh);
6467 }
6468 
6469 ////////////////////////////////////////////////////////////////////////////////
6470 /// Free font structure returned by GetFontStruct().
6471 
6473 {
6474  gdk_font_unref((GdkFont *) fs);
6475 }
6476 
6477 ////////////////////////////////////////////////////////////////////////////////
6478 /// Clear window.
6479 
6481 {
6482  if (!id) return;
6483 
6484  gdk_window_clear((GdkDrawable *) id);
6485 }
6486 
6487 ////////////////////////////////////////////////////////////////////////////////
6488 /// Convert a keysym to the appropriate keycode. For example keysym is
6489 /// a letter and keycode is the matching keyboard key (which is dependend
6490 /// on the current keyboard mapping).
6491 
6493 {
6494  UInt_t xkeysym;
6495  MapKeySym(keysym, xkeysym);
6496  return xkeysym;
6497 }
6498 
6499 ////////////////////////////////////////////////////////////////////////////////
6500 /// Draw a filled rectangle. Filling is done according to the gc.
6501 
6503  UInt_t w, UInt_t h)
6504 {
6505  if (!id) return;
6506 
6507  gdk_win32_draw_rectangle((GdkDrawable *) id, (GdkGC *) gc, kTRUE, x, y, w, h);
6508 }
6509 
6510 ////////////////////////////////////////////////////////////////////////////////
6511 /// Draw a rectangle outline.
6512 
6514  UInt_t w, UInt_t h)
6515 {
6516  if (!id) return;
6517 
6518  gdk_win32_draw_rectangle((GdkDrawable *) id, (GdkGC *) gc, kFALSE, x, y, w, h);
6519 }
6520 
6521 ////////////////////////////////////////////////////////////////////////////////
6522 /// Draws multiple line segments. Each line is specified by a pair of points.
6523 
6525  Int_t nseg)
6526 {
6527  if (!id) return;
6528 
6529  gdk_win32_draw_segments((GdkDrawable *) id, (GdkGC *) gc, (GdkSegment *)seg, nseg);
6530 }
6531 
6532 ////////////////////////////////////////////////////////////////////////////////
6533 /// Defines which input events the window is interested in. By default
6534 /// events are propageted up the window stack. This mask can also be
6535 /// set at window creation time via the SetWindowAttributes_t::fEventMask
6536 /// attribute.
6537 
6539 {
6540  if (!id) return;
6541 
6542  UInt_t xevmask;
6543  MapEventMask(evmask, xevmask, kTRUE);
6544  gdk_window_set_events((GdkWindow *) id, (GdkEventMask)xevmask);
6545 }
6546 
6547 ////////////////////////////////////////////////////////////////////////////////
6548 /// Returns the window id of the window having the input focus.
6549 
6551 {
6552  HWND hwnd = ::GetFocus();
6553  return (Window_t) gdk_xid_table_lookup(hwnd);
6554 }
6555 
6556 ////////////////////////////////////////////////////////////////////////////////
6557 /// Set keyboard input focus to window id.
6558 
6560 {
6561  if (!id) return;
6562 
6563  HWND hwnd = (HWND)GDK_DRAWABLE_XID((GdkWindow *)id);
6564  ::SetFocus(hwnd);
6565 }
6566 
6567 ////////////////////////////////////////////////////////////////////////////////
6568 /// Returns the window id of the current owner of the primary selection.
6569 /// That is the window in which, for example some text is selected.
6570 
6572 {
6573  return (Window_t)gdk_selection_owner_get(gClipboardAtom);
6574 }
6575 
6576 ////////////////////////////////////////////////////////////////////////////////
6577 /// Makes the window id the current owner of the primary selection.
6578 /// That is the window in which, for example some text is selected.
6579 
6581 {
6582  if (!id) return;
6583 
6584  gdk_selection_owner_set((GdkWindow *) id, gClipboardAtom, GDK_CURRENT_TIME, 0);
6585 }
6586 
6587 ////////////////////////////////////////////////////////////////////////////////
6588 /// XConvertSelection() causes a SelectionRequest event to be sent to the
6589 /// current primary selection owner. This event specifies the selection
6590 /// property (primary selection), the format into which to convert that
6591 /// data before storing it (target = XA_STRING), the property in which
6592 /// the owner will place the information (sel_property), the window that
6593 /// wants the information (id), and the time of the conversion request
6594 /// (when).
6595 /// The selection owner responds by sending a SelectionNotify event, which
6596 /// confirms the selected atom and type.
6597 
6599 {
6600  if (!id) return;
6601 
6602  gdk_selection_convert((GdkWindow *) id, clipboard,
6603  gdk_atom_intern("GDK_TARGET_STRING", 0), when);
6604 }
6605 
6606 ////////////////////////////////////////////////////////////////////////////////
6607 /// Convert the keycode from the event structure to a key symbol (according
6608 /// to the modifiers specified in the event structure and the current
6609 /// keyboard mapping). In buf a null terminated ASCII string is returned
6610 /// representing the string that is currently mapped to the key code.
6611 
6612 void TGWin32::LookupString(Event_t * event, char *buf, Int_t buflen,
6613  UInt_t & keysym)
6614 {
6615  _lookup_string(event, buf, buflen);
6616  UInt_t ks, xks = (UInt_t) event->fCode;
6617  MapKeySym(ks, xks, kFALSE);
6618  keysym = (Int_t) ks;
6619 }
6620 
6621 ////////////////////////////////////////////////////////////////////////////////
6622 /// Map to and from X key symbols. Keysym are the values returned by
6623 /// XLookUpString.
6624 
6625 void TGWin32::MapKeySym(UInt_t & keysym, UInt_t & xkeysym, Bool_t tox)
6626 {
6627  if (tox) {
6628  xkeysym = GDK_VoidSymbol;
6629  if (keysym < 127) {
6630  xkeysym = keysym;
6631  } else if (keysym >= kKey_F1 && keysym <= kKey_F35) {
6632  xkeysym = GDK_F1 + (keysym - (UInt_t) kKey_F1); // function keys
6633  } else {
6634  for (int i = 0; gKeyMap[i].fKeySym; i++) { // any other keys
6635  if (keysym == (UInt_t) gKeyMap[i].fKeySym) {
6636  xkeysym = (UInt_t) gKeyMap[i].fXKeySym;
6637  break;
6638  }
6639  }
6640  }
6641  } else {
6642  keysym = kKey_Unknown;
6643  // commentary in X11/keysymdef says that X codes match ASCII
6644  if (xkeysym < 127) {
6645  keysym = xkeysym;
6646  } else if (xkeysym >= GDK_F1 && xkeysym <= GDK_F35) {
6647  keysym = kKey_F1 + (xkeysym - GDK_F1); // function keys
6648  } else if (xkeysym >= GDK_KP_0 && xkeysym <= GDK_KP_9) {
6649  keysym = kKey_0 + (xkeysym - GDK_KP_0); // numeric keypad keys
6650  } else {
6651  for (int i = 0; gKeyMap[i].fXKeySym; i++) { // any other keys
6652  if (xkeysym == gKeyMap[i].fXKeySym) {
6653  keysym = (UInt_t) gKeyMap[i].fKeySym;
6654  break;
6655  }
6656  }
6657  }
6658  }
6659 }
6660 
6661 ////////////////////////////////////////////////////////////////////////////////
6662 /// Get contents of paste buffer atom into string. If del is true delete
6663 /// the paste buffer afterwards.
6664 
6666  Int_t & nchar, Bool_t del)
6667 {
6668  if (!id) return;
6669 
6670  char *data;
6671  int nread, actual_format;
6672 
6673  nread = gdk_selection_property_get((GdkWindow *) id,
6674  (unsigned char **) &data,
6675  (GdkAtom *) & atom, &actual_format);
6676 
6677  if ((nread == 0) || (data == NULL)) {
6678  nchar = 0;
6679  return;
6680  }
6681 
6682  text.Insert(0, (const char *) data);
6683  nchar = 1; //strlen(data);
6684  g_free(data);
6685 
6686  // if (del)
6687  gdk_property_delete((GdkWindow *) id,
6688  gdk_atom_intern("GDK_SELECTION", FALSE));
6689 }
6690 
6691 ////////////////////////////////////////////////////////////////////////////////
6692 /// TranslateCoordinates translates coordinates from the frame of
6693 /// reference of one window to another. If the point is contained
6694 /// in a mapped child of the destination, the id of that child is
6695 /// returned as well.
6696 
6698  Int_t src_x, Int_t src_y,
6699  Int_t &dest_x, Int_t &dest_y,
6700  Window_t &child)
6701 {
6702  if (!src || !dest) return;
6703 
6704  HWND sw, dw, ch = NULL;
6705  POINT point;
6706  sw = (HWND)GDK_DRAWABLE_XID((GdkWindow *)src);
6707  dw = (HWND)GDK_DRAWABLE_XID((GdkWindow *)dest);
6708  point.x = src_x;
6709  point.y = src_y;
6710  ::MapWindowPoints(sw, // handle of window to be mapped from
6711  dw, // handle to window to be mapped to
6712  &point, // pointer to array with points to map
6713  1); // number of structures in array
6714  ch = ::ChildWindowFromPointEx(dw, point, CWP_SKIPDISABLED | CWP_SKIPINVISIBLE);
6715  child = (Window_t)gdk_xid_table_lookup(ch);
6716 
6717  if (child == src) {
6718  child = (Window_t) 0;
6719  }
6720  dest_x = point.x;
6721  dest_y = point.y;
6722 }
6723 
6724 ////////////////////////////////////////////////////////////////////////////////
6725 /// Return geometry of window (should be called GetGeometry but signature
6726 /// already used).
6727 
6729  UInt_t & w, UInt_t & h)
6730 {
6731  if (!id) return;
6732 
6733  Int_t ddum;
6734  if (GDK_DRAWABLE_TYPE(id) == GDK_DRAWABLE_PIXMAP) {
6735  x = y = 0;
6736  gdk_drawable_get_size((GdkDrawable *)id, (int*)&w, (int*)&h);
6737  }
6738  else {
6739  gdk_window_get_geometry((GdkDrawable *) id, &x, &y, (int*)&w,
6740  (int*)&h, &ddum);
6741  }
6742 }
6743 
6744 ////////////////////////////////////////////////////////////////////////////////
6745 /// FillPolygon fills the region closed by the specified path.
6746 /// The path is closed automatically if the last point in the list does
6747 /// not coincide with the first point. All point coordinates are
6748 /// treated as relative to the origin. For every pair of points
6749 /// inside the polygon, the line segment connecting them does not
6750 /// intersect the path.
6751 
6753  Int_t npnt)
6754 {
6755  if (!id) return;
6756 
6757  gdk_win32_draw_polygon((GdkWindow *) id, (GdkGC *) gc, 1, (GdkPoint *) points, npnt);
6758 }
6759 
6760 ////////////////////////////////////////////////////////////////////////////////
6761 /// Returns the root window the pointer is logically on and the pointer
6762 /// coordinates relative to the root window's origin.
6763 /// The pointer coordinates returned to win_x and win_y are relative to
6764 /// the origin of the specified window. In this case, QueryPointer returns
6765 /// the child that contains the pointer, if any, or else kNone to
6766 /// childw. QueryPointer returns the current logical state of the
6767 /// keyboard buttons and the modifier keys in mask.
6768 
6770  Window_t &childw, Int_t &root_x,
6771  Int_t &root_y, Int_t &win_x, Int_t &win_y,
6772  UInt_t &mask)
6773 {
6774  if (!id) return;
6775 
6776  POINT currPt;
6777  HWND chw, window;
6778  UInt_t umask = 0;
6779  BYTE kbd[256];
6780 
6781  window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)id);
6782  rootw = (Window_t)GDK_ROOT_PARENT();
6783  ::GetCursorPos(&currPt);
6784  chw = ::WindowFromPoint(currPt);
6785  childw = (Window_t)gdk_xid_table_lookup(chw);
6786  root_x = currPt.x;
6787  root_y = currPt.y;
6788 
6789  ::ScreenToClient(window, &currPt);
6790  win_x = currPt.x;
6791  win_y = currPt.y;
6792 
6793  ::GetKeyboardState (kbd);
6794 
6795  if (kbd[VK_SHIFT] & 0x80) {
6796  umask |= GDK_SHIFT_MASK;
6797  }
6798  if (kbd[VK_CAPITAL] & 0x80) {
6799  umask |= GDK_LOCK_MASK;
6800  }
6801  if (kbd[VK_CONTROL] & 0x80) {
6802  umask |= GDK_CONTROL_MASK;
6803  }
6804  if (kbd[VK_MENU] & 0x80) {
6805  umask |= GDK_MOD1_MASK;
6806  }
6807  if (kbd[VK_LBUTTON] & 0x80) {
6808  umask |= GDK_BUTTON1_MASK;
6809  }
6810  if (kbd[VK_MBUTTON] & 0x80) {
6811  umask |= GDK_BUTTON2_MASK;
6812  }
6813  if (kbd[VK_RBUTTON] & 0x80) {
6814  umask |= GDK_BUTTON3_MASK;
6815  }
6816 
6817  MapModifierState(mask, umask, kFALSE);
6818 }
6819 
6820 ////////////////////////////////////////////////////////////////////////////////
6821 /// Set foreground color in graphics context (shortcut for ChangeGC with
6822 /// only foreground mask set).
6823 
6825 {
6826  GdkColor fore;
6827  fore.pixel = foreground;
6828  fore.red = GetRValue(foreground);
6829  fore.green = GetGValue(foreground);
6830  fore.blue = GetBValue(foreground);
6831  gdk_gc_set_foreground((GdkGC *) gc, &fore);
6832 }
6833 
6834 ////////////////////////////////////////////////////////////////////////////////
6835 /// Set clipping rectangles in graphics context. X, Y specify the origin
6836 /// of the rectangles. Recs specifies an array of rectangles that define
6837 /// the clipping mask and n is the number of rectangles.
6838 
6840  Rectangle_t * recs, Int_t n)
6841 {
6842  Int_t i;
6843  GdkRectangle *grects = new GdkRectangle[n];
6844 
6845  for (i = 0; i < n; i++) {
6846  grects[i].x = x+recs[i].fX;
6847  grects[i].y = y+recs[i].fY;
6848  grects[i].width = recs[i].fWidth;
6849  grects[i].height = recs[i].fHeight;
6850  }
6851 
6852  for (i = 0; i < n; i++) {
6853  gdk_gc_set_clip_rectangle((GdkGC *)gc, (GdkRectangle*)recs);
6854  }
6855  delete [] grects;
6856 }
6857 
6858 ////////////////////////////////////////////////////////////////////////////////
6859 /// Flush (mode = 0, default) or synchronize (mode = 1) X output buffer.
6860 /// Flush flushes output buffer. Sync flushes buffer and waits till all
6861 /// requests have been processed by X server.
6862 
6864 {
6865  GdiFlush();
6866 }
6867 
6868 ////////////////////////////////////////////////////////////////////////////////
6869 /// Create a new empty region.
6870 
6872 {
6873  return (Region_t) gdk_region_new();
6874 }
6875 
6876 ////////////////////////////////////////////////////////////////////////////////
6877 /// Destroy region.
6878 
6880 {
6881  gdk_region_destroy((GdkRegion *) reg);
6882 }
6883 
6884 ////////////////////////////////////////////////////////////////////////////////
6885 /// Union of rectangle with a region.
6886 
6888 {
6889  GdkRectangle r;
6890  r.x = rect->fX;
6891  r.y = rect->fY;
6892  r.width = rect->fWidth;
6893  r.height = rect->fHeight;
6894  dest = (Region_t) gdk_region_union_with_rect((GdkRegion *) src, &r);
6895 }
6896 
6897 ////////////////////////////////////////////////////////////////////////////////
6898 /// Create region for the polygon defined by the points array.
6899 /// If winding is true use WindingRule else EvenOddRule as fill rule.
6900 
6902 {
6903  return (Region_t) gdk_region_polygon((GdkPoint*)points, np,
6904  winding ? GDK_WINDING_RULE : GDK_EVEN_ODD_RULE);
6905 }
6906 
6907 ////////////////////////////////////////////////////////////////////////////////
6908 /// Compute the union of rega and regb and return result region.
6909 /// The output region may be the same result region.
6910 
6912 {
6913  result = (Region_t) gdk_regions_union((GdkRegion *) rega, (GdkRegion *) regb);
6914 }
6915 
6916 ////////////////////////////////////////////////////////////////////////////////
6917 /// Compute the intersection of rega and regb and return result region.
6918 /// The output region may be the same as the result region.
6919 
6921  Region_t result)
6922 {
6923  result = (Region_t) gdk_regions_intersect((GdkRegion *) rega,(GdkRegion *) regb);
6924 }
6925 
6926 ////////////////////////////////////////////////////////////////////////////////
6927 /// Subtract rega from regb.
6928 
6930 {
6931  result = (Region_t)gdk_regions_subtract((GdkRegion *) rega,(GdkRegion *) regb);
6932 }
6933 
6934 ////////////////////////////////////////////////////////////////////////////////
6935 /// Calculate the difference between the union and intersection of
6936 /// two regions.
6937 
6939 {
6940  result = (Region_t) gdk_regions_xor((GdkRegion *) rega, (GdkRegion *) regb);
6941 }
6942 
6943 ////////////////////////////////////////////////////////////////////////////////
6944 /// Return true if the region is empty.
6945 
6947 {
6948  return (Bool_t) gdk_region_empty((GdkRegion *) reg);
6949 }
6950 
6951 ////////////////////////////////////////////////////////////////////////////////
6952 /// Returns true if the point x,y is in the region.
6953 
6955 {
6956  return (Bool_t) gdk_region_point_in((GdkRegion *) reg, x, y);
6957 }
6958 
6959 ////////////////////////////////////////////////////////////////////////////////
6960 /// Returns true if two regions are equal.
6961 
6963 {
6964  return (Bool_t) gdk_region_equal((GdkRegion *) rega, (GdkRegion *) regb);
6965 }
6966 
6967 ////////////////////////////////////////////////////////////////////////////////
6968 /// Return smallest enclosing rectangle.
6969 
6971 {
6972  GdkRectangle r;
6973  gdk_region_get_clipbox((GdkRegion *) reg, &r);
6974  rect->fX = r.x;
6975  rect->fY = r.y;
6976  rect->fWidth = r.width;
6977  rect->fHeight = r.height;
6978 }
6979 
6980 ////////////////////////////////////////////////////////////////////////////////
6981 /// Return list of font names matching "fontname".
6982 
6983 char **TGWin32::ListFonts(const char *fontname, Int_t /*max*/, Int_t &count)
6984 {
6985  char foundry[32], family[100], weight[32], slant[32], font_name[256];
6986  char **fontlist;
6987  Int_t n1, fontcount = 0;
6988 
6989  sscanf(fontname, "-%30[^-]-%100[^-]-%30[^-]-%30[^-]-%n",
6990  foundry, family, weight, slant, &n1);
6991  // replace "medium" by "normal"
6992  if(!stricmp(weight,"medium")) {
6993  sprintf(weight,"normal");
6994  }
6995  // since all sizes are allowed with TTF, just forget it...
6996  sprintf(font_name, "-%s-%s-%s-%s-*", foundry, family, weight, slant);
6997  fontlist = gdk_font_list_new(font_name, &fontcount);
6998  count = fontcount;
6999 
7000  if (fontcount > 0) return fontlist;
7001  return 0;
7002 }
7003 
7004 ////////////////////////////////////////////////////////////////////////////////
7005 ///
7006 
7007 void TGWin32::FreeFontNames(char **fontlist)
7008 {
7009  gdk_font_list_free(fontlist);
7010 }
7011 
7012 ////////////////////////////////////////////////////////////////////////////////
7013 ///
7014 
7016 {
7017  return (Drawable_t) gdk_image_new(GDK_IMAGE_SHARED, gdk_visual_get_best(),
7018  width, height);
7019 }
7020 
7021 ////////////////////////////////////////////////////////////////////////////////
7022 ///
7023 
7025 {
7026  width = ((GdkImage*)id)->width;
7027  height = ((GdkImage*)id)->height;
7028 }
7029 
7030 ////////////////////////////////////////////////////////////////////////////////
7031 ///
7032 
7034 {
7035  if (!id) return;
7036 
7037  GdkImage *image = (GdkImage *)id;
7038  if (image->depth == 1) {
7039  if (pixel & 1) {
7040  ((UChar_t *) image->mem)[y * image->bpl + (x >> 3)] |= (1 << (7 - (x & 0x7)));
7041  } else {
7042  ((UChar_t *) image->mem)[y * image->bpl + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
7043  }
7044  } else {
7045  UChar_t *pixelp = (UChar_t *) image->mem + y * image->bpl + x * image->bpp;
7046  // Windows is always LSB, no need to check image->byte_order.
7047  switch (image->bpp) {
7048  case 4:
7049  pixelp[3] = 0;
7050  case 3:
7051  pixelp[2] = ((pixel >> 16) & 0xFF);
7052  case 2:
7053  pixelp[1] = ((pixel >> 8) & 0xFF);
7054  case 1:
7055  pixelp[0] = (pixel & 0xFF);
7056  }
7057  }
7058 }
7059 
7060 ////////////////////////////////////////////////////////////////////////////////
7061 ///
7062 
7064  Int_t dy, Int_t x, Int_t y, UInt_t w, UInt_t h)
7065 {
7066  if (!id) return;
7067 
7068  gdk_draw_image((GdkDrawable *) id, (GdkGC *)gc, (GdkImage *)img,
7069  x, y, dx, dy, w, h);
7070  ::GdiFlush();
7071 }
7072 
7073 ////////////////////////////////////////////////////////////////////////////////
7074 ///
7075 
7077 {
7078  gdk_image_unref((GdkImage *)img);
7079 }
7080 
7081 ////////////////////////////////////////////////////////////////////////////////
7082 /// Gets DIB bits
7083 /// x, y, width, height - position of bitmap
7084 /// returns a pointer on bitmap bits array
7085 /// in format:
7086 /// b1, g1, r1, 0, b2, g2, r2, 0 ... bn, gn, rn, 0 ..
7087 ///
7088 /// Pixels are numbered from left to right and from top to bottom.
7089 /// By default all pixels from the whole drawable are returned.
7090 
7092  UInt_t width, UInt_t height)
7093 {
7094  HDC hdc, memdc;
7095  BITMAPINFO bmi;
7096  HGDIOBJ oldbitmap1, oldbitmap2;
7097  BITMAP bm;
7098  HBITMAP ximage = 0;
7099  VOID *bmbits = 0;
7100  unsigned char *ret = 0;
7101 
7102  if (GDK_DRAWABLE_TYPE(wid) == GDK_DRAWABLE_PIXMAP) {
7103  hdc = ::CreateCompatibleDC(NULL);
7104  oldbitmap1 = ::SelectObject(hdc, GDK_DRAWABLE_XID(wid));
7105  ::GetObject(GDK_DRAWABLE_XID(wid), sizeof(BITMAP), &bm);
7106  } else {
7107  hdc = ::GetDC((HWND)GDK_DRAWABLE_XID(wid));
7108  }
7109  memdc = ::CreateCompatibleDC(hdc);
7110 
7111  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
7112  bmi.bmiHeader.biWidth = width;
7113  bmi.bmiHeader.biHeight = -1 * (int)(height);
7114  bmi.bmiHeader.biPlanes = 1;
7115  bmi.bmiHeader.biBitCount = 32;
7116  bmi.bmiHeader.biCompression = BI_RGB;
7117  bmi.bmiHeader.biSizeImage = 0;
7118  bmi.bmiHeader.biXPelsPerMeter = bmi.bmiHeader.biYPelsPerMeter = 0;
7119  bmi.bmiHeader.biClrUsed = 0;
7120  bmi.bmiHeader.biClrImportant = 0;
7121 
7122  ximage = ::CreateDIBSection(hdc, (BITMAPINFO *) &bmi, DIB_RGB_COLORS, &bmbits, NULL, 0);
7123 
7124  if (ximage && bmbits) {
7125  oldbitmap2 = ::SelectObject(memdc, ximage);
7126  ::BitBlt(memdc, x, y, width, height, hdc, 0, 0, SRCCOPY);
7127  ::SelectObject(memdc, oldbitmap2);
7128  }
7129  ::DeleteDC(memdc);
7130  if (GDK_DRAWABLE_TYPE(wid) == GDK_DRAWABLE_PIXMAP) {
7131  ::SelectObject(hdc, oldbitmap1);
7132  ::DeleteDC(hdc);
7133  } else {
7134  ::ReleaseDC((HWND)GDK_DRAWABLE_XID(wid), hdc);
7135  }
7136  if (ximage && bmbits) {
7137  ULong_t sz = width*height*4;
7138  ret = new unsigned char[sz];
7139  memcpy(ret, bmbits, sz);
7140  ::DeleteObject(ximage);
7141  }
7142  return ret;
7143 }
7144 
7145 ////////////////////////////////////////////////////////////////////////////////
7146 /// create an image from RGB data. RGB data is in format :
7147 /// b1, g1, r1, 0, b2, g2, r2, 0 ... bn, gn, rn, 0 ..
7148 ///
7149 /// Pixels are numbered from left to right and from top to bottom.
7150 /// Note that data must be 32-bit aligned
7151 
7152 Pixmap_t TGWin32::CreatePixmapFromData(unsigned char *bits, UInt_t width, UInt_t height)
7153 {
7154  BITMAPINFO bmp_info;
7155  bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
7156  bmp_info.bmiHeader.biWidth = width;
7157  bmp_info.bmiHeader.biHeight = -1 * (int)(height);
7158  bmp_info.bmiHeader.biPlanes = 1;
7159  bmp_info.bmiHeader.biBitCount = 32;
7160  bmp_info.bmiHeader.biCompression = BI_RGB;
7161  bmp_info.bmiHeader.biSizeImage = 0;
7162  bmp_info.bmiHeader.biClrUsed = 0;
7163  bmp_info.bmiHeader.biXPelsPerMeter = 0L;
7164  bmp_info.bmiHeader.biYPelsPerMeter = 0L;
7165  bmp_info.bmiHeader.biClrImportant = 0;
7166  bmp_info.bmiColors[0].rgbRed = 0;
7167  bmp_info.bmiColors[0].rgbGreen = 0;
7168  bmp_info.bmiColors[0].rgbBlue = 0;
7169  bmp_info.bmiColors[0].rgbReserved = 0;
7170 
7171  HDC hdc = ::GetDC(NULL);
7172  HBITMAP hbitmap = ::CreateDIBitmap(hdc, &bmp_info.bmiHeader, CBM_INIT,
7173  (void *)bits, &bmp_info, DIB_RGB_COLORS);
7174  ::ReleaseDC(NULL, hdc);
7175 
7176  SIZE size;
7177  // For an obscure reason, we have to set the size of the
7178  // bitmap this way before to call gdk_pixmap_foreign_new
7179  // otherwise, it fails...
7180  ::SetBitmapDimensionEx(hbitmap,width, height, &size);
7181 
7182  return (Pixmap_t)gdk_pixmap_foreign_new((guint32)hbitmap);
7183 }
7184 
7185 ////////////////////////////////////////////////////////////////////////////////
7186 ///register pixmap created by TGWin32GLManager
7187 
7189 {
7190  HBITMAP hBmp = reinterpret_cast<HBITMAP>(pix);
7191  SIZE sz = SIZE();
7192 
7193  SetBitmapDimensionEx(hBmp, w, h, &sz);
7194  GdkPixmap *newPix = gdk_pixmap_foreign_new(reinterpret_cast<guint32>(hBmp));
7195 
7196  Int_t wid = 0;
7197  for(; wid < fMaxNumberOfWindows; ++wid)
7198  if (!fWindows[wid].open)
7199  break;
7200 
7201  if (wid == fMaxNumberOfWindows) {
7202  Int_t newSize = fMaxNumberOfWindows + 10;
7203 
7204  fWindows = (XWindow_t *)TStorage::ReAlloc(fWindows, newSize * sizeof(XWindow_t),
7205  fMaxNumberOfWindows * sizeof(XWindow_t));
7206 
7207  for (Int_t i = fMaxNumberOfWindows; i < newSize; ++i)
7208  fWindows[i].open = 0;
7209 
7210  fMaxNumberOfWindows = newSize;
7211  }
7212 
7213  fWindows[wid].open = 1;
7214  gCws = fWindows + wid;
7215  gCws->window = newPix;
7216  gCws->drawing = gCws->window;
7217  gCws->buffer = 0;
7218  gCws->double_buffer = 0;
7219  gCws->ispixmap = 1;
7220  gCws->clip = 0;
7221  gCws->width = w;
7222  gCws->height = h;
7223  gCws->new_colors = 0;
7224 
7225  return wid;
7226 }
7227 
7228 ////////////////////////////////////////////////////////////////////////////////
7229 /// Register a window created by Qt as a ROOT window (like InitWindow()).
7230 
7232 {
7233  Int_t wid;
7234  // Select next free window number
7235 
7236  again:
7237  for (wid = 0; wid < fMaxNumberOfWindows; wid++) {
7238  if (!fWindows[wid].open) {
7239  fWindows[wid].open = 1;
7240  fWindows[wid].double_buffer = 0;
7241  gCws = &fWindows[wid];
7242  break;
7243  }
7244  }
7245 
7246  if (wid == fMaxNumberOfWindows) {
7247  int newsize = fMaxNumberOfWindows + 10;
7248  fWindows =
7249  (XWindow_t *) TStorage::ReAlloc(fWindows,
7250  newsize * sizeof(XWindow_t),
7251  fMaxNumberOfWindows *
7252  sizeof(XWindow_t));
7253 
7254  for (int i = fMaxNumberOfWindows; i < newsize; i++) {
7255  fWindows[i].open = 0;
7256  }
7257 
7258  fMaxNumberOfWindows = newsize;
7259  goto again;
7260  }
7261 
7262  gCws->window = gdk_window_foreign_new((guint32)qwid);
7263 
7264  gCws->drawing = gCws->window;
7265  gCws->buffer = 0;
7266  gCws->double_buffer = 0;
7267  gCws->ispixmap = 0;
7268  gCws->clip = 0;
7269  gCws->width = w;
7270  gCws->height = h;
7271  gCws->new_colors = 0;
7272 
7273  return wid;
7274 }
7275 
7276 ////////////////////////////////////////////////////////////////////////////////
7277 /// Remove a window created by Qt (like CloseWindow1()).
7278 
7280 {
7281  int wid;
7282 
7283  SelectWindow((int)qwid);
7284 
7285  if (gCws->buffer) {
7286  gdk_pixmap_unref(gCws->buffer);
7287  }
7288  if (gCws->new_colors) {
7289  gdk_colormap_free_colors((GdkColormap *) fColormap,
7290  (GdkColor *)gCws->new_colors, gCws->ncolors);
7291 
7292  delete [] gCws->new_colors;
7293  gCws->new_colors = 0;
7294  }
7295 
7296  GdiFlush();
7297  gCws->open = 0;
7298 
7299  if (!fWindows) return;
7300 
7301  // make first window in list the current window
7302  for (wid = 0; wid < fMaxNumberOfWindows; wid++) {
7303  if (fWindows[wid].open) {
7304  gCws = &fWindows[wid];
7305  return;
7306  }
7307  }
7308  gCws = 0;
7309 }
7310 
7311 ////////////////////////////////////////////////////////////////////////////////
7312 /// The Nonrectangular Window Shape Extension adds nonrectangular
7313 /// windows to the System.
7314 /// This allows for making shaped (partially transparent) windows
7315 
7317 {
7318  gdk_window_shape_combine_mask((GdkWindow *)id, (GdkBitmap *) mask, x, y);
7319 }
7320 
7321 ////////////////////////////////////////////////////////////////////////////////
7322 /// Returns the width of the screen in millimeters.
7323 
7325 {
7326  return (UInt_t)gdk_screen_width_mm();
7327 }
7328 
7329 //------------------------------ Drag and Drop ---------------------------------
7330 
7331 ////////////////////////////////////////////////////////////////////////////////
7332 /// Deletes the specified property on the specified window.
7333 
7335 {
7336  HWND hWnd = (HWND)GDK_DRAWABLE_XID((GdkWindow *)win);
7337  Atom_t atom = (Atom_t)GetProp(hWnd,(LPCTSTR)MAKELONG(prop,0));
7338  if (atom != 0) {
7339  GlobalDeleteAtom(atom);
7340  }
7341  RemoveProp(hWnd,(LPCTSTR)MAKELONG(prop,0));
7342 }
7343 
7344 ////////////////////////////////////////////////////////////////////////////////
7345 /// Returns the actual type of the property, the actual format of the property,
7346 /// and a pointer to the data actually returned.
7347 
7349  Bool_t del, Atom_t req_type, Atom_t *act_type,
7350  Int_t *act_format, ULong_t *nitems, ULong_t *bytes,
7351  unsigned char **prop_list)
7352 {
7353  HGLOBAL hdata;
7354  UChar_t *ptr, *data;
7355  UInt_t i, n, length;
7356 
7357  HWND hWnd = (HWND)GDK_DRAWABLE_XID((GdkWindow *)win);
7358  if (hWnd == NULL)
7359  return 0;
7360 
7361  Atom_t dndproxy = InternAtom("XdndProxy", kFALSE);
7362  Atom_t dndtypelist = InternAtom("XdndTypeList", kFALSE);
7363 
7364  if (prop == dndproxy)
7365  return 0;
7366  if (prop == dndtypelist) {
7367  *act_type = XA_ATOM;
7368  *prop_list = (unsigned char *)GetProp(hWnd, (LPCTSTR)MAKELONG(prop,0));
7369  for (n = 0; prop_list[n]; n++);
7370  *nitems = n;
7371  return n;
7372  }
7373  else {
7374  if (!OpenClipboard((HWND)GDK_DRAWABLE_XID((GdkWindow *)win))) {
7375  return 0;
7376  }
7377  hdata = GetClipboardData(CF_PRIVATEFIRST);
7378  ptr = (UChar_t *)GlobalLock(hdata);
7379  length = GlobalSize(hdata);
7380  data = (UChar_t *)malloc(length + 1);
7381  for (i = 0; i < length; i++) {
7382  data[i] = ptr[i];
7383  }
7384  GlobalUnlock(hdata);
7385  CloseClipboard();
7386  *prop_list = data;
7387  *bytes = *nitems = length;
7388  return length;
7389  }
7390  return 0;
7391 }
7392 
7393 ////////////////////////////////////////////////////////////////////////////////
7394 /// Changes the active cursor of the specified window.
7395 
7397 {
7398  UInt_t xevmask;
7399  MapEventMask(mask, xevmask);
7400  if (cur == kNone)
7401  gdk_window_set_cursor((GdkWindow *) win, fCursors[kHand]);
7402  else
7403  gdk_window_set_cursor((GdkWindow *) win, (GdkCursor *)cur);
7404 }
7405 
7406 ////////////////////////////////////////////////////////////////////////////////
7407 /// Get Clipboard data.
7408 
7410  Atom_t &prop, Time_t &stamp)
7411 {
7412  HGLOBAL hdata;
7413 
7414  static UINT gdk_selection_notify_msg =
7415  RegisterWindowMessage("gdk-selection-notify");
7416  HWND hWnd = (HWND)GDK_DRAWABLE_XID((GdkWindow *)win);
7417  if (!OpenClipboard((HWND)GDK_DRAWABLE_XID((GdkWindow *)win))) {
7418  return;
7419  }
7420  hdata = GetClipboardData(CF_PRIVATEFIRST);
7421  CloseClipboard();
7422  if (hdata == 0)
7423  return;
7424  /* Send ourselves an ersatz selection notify message so that we actually
7425  * fetch the data.
7426  */
7427  PostMessage(hWnd, gdk_selection_notify_msg, sel, target);
7428 }
7429 
7430 ////////////////////////////////////////////////////////////////////////////////
7431 /// Assigns owner of Clipboard.
7432 
7434 {
7435  static UINT gdk_selection_request_msg =
7436  RegisterWindowMessage("gdk-selection-request");
7437  HWND hWnd = (HWND)GDK_DRAWABLE_XID((GdkWindow *)owner);
7438  OpenClipboard(hWnd);
7439  EmptyClipboard();
7440  CloseClipboard();
7441  if (owner) {
7442  ::PostMessage(hWnd, gdk_selection_request_msg, sel, 0);
7443  }
7444  return kTRUE;
7445 }
7446 
7447 ////////////////////////////////////////////////////////////////////////////////
7448 /// Put data into Clipboard.
7449 
7451  Int_t format, UChar_t *data, Int_t len)
7452 {
7453  HGLOBAL hdata;
7454  Int_t i;
7455  UChar_t *ptr;
7456 
7457  if (data == 0 || len == 0)
7458  return;
7459  if (!OpenClipboard((HWND)GDK_DRAWABLE_XID((GdkWindow *)id))) {
7460  return;
7461  }
7462  hdata = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, len + 1);
7463  ptr = (UChar_t *)GlobalLock(hdata);
7464  for (i = 0; i < len; i++) {
7465  *ptr++ = *data++;
7466  }
7467  GlobalUnlock(hdata);
7468  SetClipboardData(CF_PRIVATEFIRST, hdata);
7469  CloseClipboard();
7470 }
7471 
7472 ////////////////////////////////////////////////////////////////////////////////
7473 /// Add the list of drag and drop types to the Window win.
7474 
7475 void TGWin32::SetTypeList(Window_t win, Atom_t prop, Atom_t *typelist)
7476 {
7477  SetProp((HWND)GDK_DRAWABLE_XID((GdkWindow *)win),
7478  (LPCTSTR)MAKELONG(prop,0),
7479  (HANDLE)typelist);
7480 }
7481 
7482 ////////////////////////////////////////////////////////////////////////////////
7483 /// Recursively search in the children of Window for a Window which is at
7484 /// location x, y and is DND aware, with a maximum depth of maxd.
7485 /// Possibility to exclude dragwin and input.
7486 
7488  int x, int y, int maxd)
7489 {
7490  POINT point;
7491  POINT cpt;
7492  RECT rect;
7493  HWND hwnd, hwndc;
7494  HWND hwndt;
7495  Window_t win, retwin = kNone;
7496  Atom_t version = 0;
7497  Atom_t dndaware = InternAtom("XdndAware", kFALSE);
7498 
7499  cpt.x = x;
7500  cpt.y = y;
7501  hwnd = ::ChildWindowFromPointEx((HWND)GDK_DRAWABLE_XID((GdkWindow *)root),
7502  cpt, CWP_ALL);
7503  while (hwnd) {
7504  GetWindowRect(hwnd, &rect);
7505  if (PtInRect(&rect, cpt)) {
7506  if (GetProp(hwnd,(LPCTSTR)MAKELONG(dndaware,0))) {
7507  win = (Window_t) gdk_xid_table_lookup(hwnd);
7508  if (win && win != dragwin && win != input)
7509  return win;
7510  }
7511  Bool_t done = kFALSE;
7512  hwndt = hwnd;
7513  while (!done) {
7514  point = cpt;
7515  ::MapWindowPoints(NULL, hwndt, &point, 1);
7516  hwndc = ChildWindowFromPoint (hwndt, point);
7517  if (GetProp(hwnd,(LPCTSTR)MAKELONG(dndaware,0))) {
7518  win = (Window_t) gdk_xid_table_lookup(hwndc);
7519  if (win && win != dragwin && win != input)
7520  return win;
7521  }
7522  if (hwndc == NULL)
7523  done = TRUE;
7524  else if (hwndc == hwndt)
7525  done = TRUE;
7526  else
7527  hwndt = hwndc;
7528  if (GetProp(hwndt,(LPCTSTR)MAKELONG(dndaware,0))) {
7529  win = (Window_t) gdk_xid_table_lookup(hwndt);
7530  if (win && win != dragwin && win != input)
7531  return win;
7532  }
7533  }
7534  }
7535  hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
7536  }
7537  return kNone;
7538 }
7539 
7540 ////////////////////////////////////////////////////////////////////////////////
7541 /// Checks if Window win is DND aware, and knows any of the DND formats
7542 /// passed in argument.
7543 
7545 {
7546  if (!win) return kFALSE;
7547 
7548  Atom_t version = 0;
7549  Atom_t dndaware = InternAtom("XdndAware", kFALSE);
7550  HWND window = (HWND)GDK_DRAWABLE_XID((GdkWindow *)win);
7551  while (window) {
7552  version = (Atom_t)GetProp(window,(LPCTSTR)MAKELONG(dndaware,0));
7553  if (version) return kTRUE;
7554  window = ::GetParent(window);
7555  }
7556  return kFALSE;
7557 }
7558 
7559 ////////////////////////////////////////////////////////////////////////////////
7560 /// Add XdndAware property and the list of drag and drop types to the
7561 /// Window win.
7562 
7564 {
7565  int n;
7566  if (!id) return;
7567 
7568  DWORD dwStyle = GetWindowLong((HWND)GDK_DRAWABLE_XID((GdkWindow *)id),
7569  GWL_EXSTYLE);
7570  SetWindowLong((HWND)GDK_DRAWABLE_XID((GdkWindow *)id), GWL_EXSTYLE,
7571  dwStyle | WS_EX_ACCEPTFILES);
7572  Atom_t dndaware = InternAtom("XdndAware", kFALSE);
7573  SetProp((HWND)GDK_DRAWABLE_XID((GdkWindow *)id),
7574  (LPCTSTR)MAKELONG(dndaware,0),
7575  (HANDLE)XDND_PROTOCOL_VERSION);
7576 
7577  if (typelist == 0)
7578  return;
7579  for (n = 0; typelist[n]; n++);
7580  Atom_t dndtypelist = InternAtom("XdndTypeList", kFALSE);
7581  SetProp((HWND)GDK_DRAWABLE_XID((GdkWindow *)id),
7582  (LPCTSTR)MAKELONG(dndtypelist,0),
7583  (HANDLE)typelist);
7584 
7585 }
7586 
7587 ////////////////////////////////////////////////////////////////////////////////
7588 /// Set user thread id. This is used when an extra thread is created
7589 /// to process events.
7590 
7592 {
7593  if (id == 0) {
7594  TGWin32ProxyBase::fgMainThreadId = ((TWinNTSystem*)gSystem)->GetGUIThreadId();
7595  }
7596  else {
7598  }
7599 }
7600 
Int_t fClipXOrigin
Definition: GuiTypes.h:246
UShort_t fBlue
Definition: GuiTypes.h:315
const int nx
Definition: kalman.C:16
EAlign
Definition: TGWin32.h:74
Pixmap_t ReadGIF(Int_t x0, Int_t y0, const char *file, Window_t id=0)
If id is NULL - loads the specified gif file at position [x0,y0] in the current window.
Definition: TGWin32.cxx:4275
static void Dealloc(void *ptr)
De-allocate block of memory, that was allocated via TStorage::Alloc().
Definition: TStorage.cxx:165
virtual void ExecuteCallBack(Bool_t sync)
Executes all batched callbacks and the latest callback This method is executed by server thread...
void CloseWindow1()
Delete current window.
Definition: TGWin32.cxx:1608
const Mask_t kKeyReleaseMask
Definition: GuiTypes.h:161
UShort_t fWidth
Definition: GuiTypes.h:364
void MapColorStruct(ColorStruct_t *color, GdkColor &xcolor)
Map a ColorStruct_t to a XColor structure.
Definition: TGWin32.cxx:5469
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
Definition: GuiTypes.h:76
void RescaleWindow(Int_t wid, UInt_t w, UInt_t h)
Rescale the window wid.
Definition: TGWin32.cxx:2702
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Int_t fLineStyle
Definition: GuiTypes.h:231
Bool_t fSendEvent
Definition: GuiTypes.h:185
Handle_t FontStruct_t
Definition: GuiTypes.h:40
const char * DisplayName(const char *dpyName=0)
Return hostname on which the display is opened.
Definition: TGWin32.cxx:2030
virtual ~TGWin32()
destructor.
Definition: TGWin32.cxx:817
void SetMarkerSize(Float_t markersize)
Set marker size index.
Definition: TGWin32.cxx:3373
static void Init()
Initialise the TrueType fonts interface.
Definition: TTF.cxx:67
void XorRegion(Region_t rega, Region_t regb, Region_t result)
Calculate the difference between the union and intersection of two regions.
Definition: TGWin32.cxx:6938
EDrawMode fDrawMode
Definition: TVirtualX.h:79
static double B[]
Int_t GetDepth() const
Get maximum number of planes.
Definition: TGWin32.cxx:5091
void Add(ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table. The key should be unique.
Definition: TExMap.cxx:87
void FillPolygon(Window_t id, GContext_t gc, Point_t *points, Int_t npnt)
FillPolygon fills the region closed by the specified path.
Definition: TGWin32.cxx:6752
static void Lock()
Definition: TGWin32.cxx:946
void SetClipRectangles(GContext_t gc, Int_t x, Int_t y, Rectangle_t *recs, Int_t n)
Set clipping rectangles in graphics context.
Definition: TGWin32.cxx:6839
void SetWMSize(Window_t id, UInt_t w, UInt_t h)
Tells window manager the desired size of window "id".
Definition: TGWin32.cxx:6347
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
Definition: TVirtualX.h:70
void SetLineWidth(Width_t width)
Set line width.
Definition: TGWin32.cxx:3337
static GC * gGCpxmp
Definition: TGX11.cxx:96
An array of TObjects.
Definition: TObjArray.h:39
Short_t fY
Definition: GuiTypes.h:363
Bool_t Init(void *display=0)
Initialize Win32 system. Returns kFALSE in case of failure.
Definition: TGWin32.cxx:962
void ConvertSelection(Window_t, Atom_t &, Atom_t &, Atom_t &, Time_t &)
Get Clipboard data.
Definition: TGWin32.cxx:7409
float xmin
Definition: THbookFile.cxx:93
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:421
void MoveWindow(Int_t wid, Int_t x, Int_t y)
Move the window wid.
Definition: TGWin32.cxx:2089
Int_t EventsPending()
Returns number of pending events.
Definition: TGWin32.cxx:5600
void SetWindowBackground(Window_t id, ULong_t color)
Set the window background color.
Definition: TGWin32.cxx:4530
void SetLineType(Int_t n, Int_t *dash)
Set line type.
Definition: TGWin32.cxx:3261
void SetOpacity(Int_t percent)
Set opacity of a window.
Definition: TGWin32.cxx:3708
Pixmap_t fTile
Definition: GuiTypes.h:239
void SetLineColor(Color_t cindex)
Set color index for lines.
Definition: TGWin32.cxx:3233
void SelectWindow(Int_t wid)
Select window to which subsequent output is directed.
Definition: TGWin32.cxx:2840
XWindow_t * fWindows
List of windows.
Definition: TGWin32.h:87
XColor_t & GetColor(Int_t cid)
Return reference to internal color structure associated to color index cid.
Definition: TGWin32.cxx:1942
static GC * gGCline
Definition: TGX11.cxx:90
Bool_t ParseColor(Colormap_t cmap, const char *cname, ColorStruct_t &color)
Parse string cname containing color name, like "green" or "#00FF00".
Definition: TGWin32.cxx:5484
void ClosePixmap()
Delete current pixmap.
Definition: TGWin32.cxx:1592
void DeleteProperty(Window_t, Atom_t &)
Deletes the specified property on the specified window.
Definition: TGWin32.cxx:7334
long long Long64_t
Definition: RtypesCore.h:69
UShort_t fHeight
Definition: GuiTypes.h:364
EInitialState
Definition: GuiTypes.h:346
void SetDashes(GContext_t gc, Int_t offset, const char *dash_list, Int_t n)
Specify a dash pattertn.
Definition: TGWin32.cxx:5451
Float_t GetRed() const
Definition: TColor.h:60
void UpdateFillStyle()
Set fill area style index.
Definition: TGWin32.cxx:3180
short Style_t
Definition: RtypesCore.h:76
Window_t GetDefaultRootWindow() const
Return handle to the default root window created when calling XOpenDisplay().
Definition: TGWin32.cxx:5113
void CloseWindow()
Delete current window.
Definition: TGWin32.cxx:1600
Bool_t IsVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
Test if there is really something to render.
Definition: TGWin32.cxx:1412
void ReparentWindow(Window_t id, Window_t pid, Int_t x, Int_t y)
Reparent window, make pid the new parent and position the window at position (x,y) in new parent...
Definition: TGWin32.cxx:4520
Bool_t fHasTTFonts
True when TrueType fonts are used.
Definition: TGWin32.h:118
Bool_t fFillColorModified
Definition: TGWin32.h:136
void SetUserThreadId(ULong_t id)
Set user thread id.
Definition: TGWin32.cxx:7591
FontStruct_t LoadQueryFont(const char *font_name)
Load font and query font.
Definition: TGWin32.cxx:5133
Collectable string class.
Definition: TObjString.h:32
FontH_t fFont
Definition: GuiTypes.h:243
float Float_t
Definition: RtypesCore.h:53
void SetMarkerColor(Color_t cindex)
Set color index for markers.
Definition: TGWin32.cxx:3353
static Int_t gFillHollow
Definition: TGX11.cxx:100
static void GlobalUnlock()
unlock any proxy (client thread)
void MapRaised(Window_t id)
Map window on screen and put on top of all windows.
Definition: TGWin32.cxx:4383
UInt_t Mask_t
Definition: GuiTypes.h:42
return c
RooArgList L(const RooAbsArg &v1)
Pixmap_t fBackgroundPixmap
Definition: GuiTypes.h:95
void Update(Int_t mode=0)
Flush (mode = 0, default) or synchronize (mode = 1) X output buffer.
Definition: TGWin32.cxx:6863
float ymin
Definition: THbookFile.cxx:93
void GrabPointer(Window_t id, UInt_t evmask, Window_t confine, Cursor_t cursor, Bool_t grab=kTRUE, Bool_t owner_events=kTRUE)
Establish an active pointer grab.
Definition: TGWin32.cxx:6234
GContext_t CreateGC(Drawable_t id, GCValues_t *gval)
Create a graphics context using the values set in gval (but only for those entries that are in the ma...
Definition: TGWin32.cxx:5177
const Mask_t kButtonMotionMask
Definition: GuiTypes.h:165
const Mask_t kWACursor
Definition: GuiTypes.h:155
#define IDC_HAND
Definition: TGWin32.cxx:68
Float_t fTextMagnitude
Text Magnitude.
Definition: TGWin32.h:125
Int_t fCount
Definition: GuiTypes.h:184
void GetGeometry(Int_t wid, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
Return position and size of window wid.
Definition: TGWin32.cxx:1997
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
static Bool_t IsInitialized()
Definition: TTF.cxx:618
FT_Glyph fImage
glyph image
Definition: TTF.h:71
unsigned short UShort_t
Definition: RtypesCore.h:36
void ShapeCombineMask(Window_t id, Int_t x, Int_t y, Pixmap_t mask)
The Nonrectangular Window Shape Extension adds nonrectangular windows to the System.
Definition: TGWin32.cxx:7316
ULong_t Time_t
Definition: GuiTypes.h:43
void SetDoubleBufferOFF()
Turn double buffer mode off.
Definition: TGWin32.cxx:3067
Window_t GetInputFocus()
Returns the window id of the window having the input focus.
Definition: TGWin32.cxx:6550
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
void SetMarkerType(Int_t type, Int_t n, GdkPoint *xy)
Set marker type.
Definition: TGWin32.cxx:3395
#define BIT(n)
Definition: Rtypes.h:120
TH1 * h
Definition: legend2.C:5
Description of a X11 color.
Definition: TGWin32.h:63
void DeleteImage(Drawable_t img)
Deallocates the memory associated with the image img.
Definition: TGWin32.cxx:7076
Bool_t ReadPictureDataFromFile(const char *filename, char ***ret_data)
Read picture data from file and store in ret_data.
Definition: TGWin32.cxx:5421
void CloseDisplay()
close display (terminate server/gMainThread thread)
Definition: TGWin32.cxx:900
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:169
EGEventType
Definition: GuiTypes.h:60
Handle_t Cursor_t
Definition: GuiTypes.h:35
const Mask_t kWABackPixmap
Definition: GuiTypes.h:140
static XWindow_t * gTws
Definition: TGX11.cxx:81
void SetColor(GdkGC *gc, Int_t ci)
Set the foreground color in GdkGC.
Definition: TGWin32.cxx:2957
Bool_t fUseSysPointers
True when using system mouse pointers.
Definition: TGWin32.h:119
Bool_t CheckEvent(Window_t id, EGEventType type, Event_t &ev)
Check if there is for window "id" an event of type "type".
Definition: TGWin32.cxx:5552
Window_t FindRWindow(Window_t win, Window_t dragwin, Window_t input, int x, int y, int maxd)
Recursively search in the children of Window for a Window which is at location x, y and is DND aware...
Definition: TGWin32.cxx:7487
Int_t fTsYOrigin
Definition: GuiTypes.h:242
SCoord_t fX
Definition: TPoint.h:37
void SetWMSizeHints(Window_t id, UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: TGWin32.cxx:6358
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:29
Bool_t fMarkerColorModified
Definition: TGWin32.h:141
static UInt_t fMaxResponseTime
max period for waiting response from server thread
static KeySymbolMap_t gKeyMap[]
Definition: GX11Gui.cxx:73
#define gROOT
Definition: TROOT.h:364
Int_t fY
Definition: GuiTypes.h:179
void RaiseWindow(Window_t id)
Put window on top of window stack.
Definition: TGWin32.cxx:4443
void UpdateLineStyle()
Update line style.
Definition: TGWin32.cxx:3301
Handle_t GContext_t
Definition: GuiTypes.h:39
Colormap_t fColormap
Definition: GuiTypes.h:109
void SetWindowName(Window_t id, char *name)
Set window name.
Definition: TGWin32.cxx:6254
ULong_t GetPixel(Color_t cindex)
Return pixel value associated to specified ROOT color number.
Definition: TGWin32.cxx:2945
SCoord_t fY
Definition: TPoint.h:38
void DrawFillArea(Int_t n, TPoint *xy)
Fill area described by polygon.
Definition: TGWin32.cxx:1737
R__EXTERN Atom_t gWM_DELETE_WINDOW
Definition: TVirtualX.h:51
Basic string class.
Definition: TString.h:137
static Cursor gNullCursor
Definition: TGX11.cxx:154
void ChangeGC(GContext_t gc, GCValues_t *gval)
Change entries in an existing graphics context, gc, by values from gval.
Definition: TGWin32.cxx:5196
const Mask_t kGCLineStyle
Definition: GuiTypes.h:292
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
Short_t fX
Definition: GuiTypes.h:358
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition: TSystem.cxx:486
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
void UpdateLineColor()
Definition: TGWin32.cxx:3244
FT_Vector fAlign
alignment vector
Definition: TGWin32.h:77
Int_t fRedDiv
Red value divider, -1 if no TrueColor visual.
Definition: TGWin32.h:127
void GetWindowAttributes(Window_t id, WindowAttributes_t &attr)
Get window attributes and return filled in attributes structure.
Definition: TGWin32.cxx:5042
Handle_t Drawable_t
Definition: GuiTypes.h:32
static GC * gGCmark
Definition: TGX11.cxx:91
static int gJoinStyle
Definition: TGX11.cxx:131
Int_t fClipYOrigin
Definition: GuiTypes.h:247
void SetWMState(Window_t id, EInitialState state)
Set the initial state of the window. Either kNormalState or kIconicState.
Definition: TGWin32.cxx:6383
void DrawImage(FT_Bitmap *source, ULong_t fore, ULong_t back, GdkImage *xim, Int_t bx, Int_t by)
Draw FT_Bitmap bitmap to xim image at position bx,by using specified foreground color.
Definition: TGWin32.cxx:1237
Int_t fFillStyle
Definition: GuiTypes.h:235
Int_t AddWindow(ULong_t qwid, UInt_t w, UInt_t h)
Register a window created by Qt as a ROOT window (like InitWindow()).
Definition: TGWin32.cxx:7231
void UnmapWindow(Window_t id)
Unmap window from screen.
Definition: TGWin32.cxx:4410
Pixmap_t fClipMask
Definition: GuiTypes.h:248
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
Int_t fRedShift
Bits to left shift red, -1 if no TrueColor visual.
Definition: TGWin32.h:130
static std::string format(double x, double y, int digits, int width)
ECursor
Definition: TVirtualX.h:56
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
This class is the basic interface to the Win32 graphics system.
Definition: TGWin32.h:71
Proxy classes provide thread-safe interface to global objects.
#define XDND_PROTOCOL_VERSION
Definition: TGWin32.cxx:66
#define safestrlen(s)
Definition: TGWin32.cxx:6281
short Font_t
Definition: RtypesCore.h:75
void MapSubwindows(Window_t id)
Maps all subwindows for the specified window "id" in top-to-bottom stacking order.
Definition: TGWin32.cxx:4372
void FreeFontStruct(FontStruct_t fs)
Free font structure returned by GetFontStruct().
Definition: TGWin32.cxx:6472
Window_t fWindow
Definition: GuiTypes.h:177
#define malloc
Definition: civetweb.c:818
Handle_t Display_t
Definition: GuiTypes.h:28
Int_t fTextAlignV
Text Alignment Vertical.
Definition: TGWin32.h:121
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:592
void DeletePictureData(void *data)
Delete picture data created by the function ReadPictureDataFromFile.
Definition: TGWin32.cxx:5441
void MapKeySym(UInt_t &keysym, UInt_t &xkeysym, Bool_t tox=kTRUE)
Map to and from X key symbols.
Definition: TGWin32.cxx:6625
Float_t GetBlue() const
Definition: TColor.h:62
Int_t TextWidth(FontStruct_t font, const char *s, Int_t len)
Return length of string in pixels. Size depends on font.
Definition: TGWin32.cxx:6430
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
void gdk_win32_draw_lines(GdkDrawable *drawable, GdkGC *gc, GdkPoint *points, gint npoints)
void PutPixel(Drawable_t id, Int_t x, Int_t y, ULong_t pixel)
Overwrites the pixel in the image with the specified pixel value.
Definition: TGWin32.cxx:7033
EGraphicsFunction fFunction
Definition: GuiTypes.h:226
#define G(x, y, z)
Int_t OpenDisplay(const char *dpyName=0)
Open the display. Return -1 if the opening fails, 0 when ok.
Definition: TGWin32.cxx:979
int GIFquantize(UInt_t width, UInt_t height, Int_t *ncol, Byte_t *red, Byte_t *green, Byte_t *blue, Byte_t *outputBuf, Byte_t *outputCmap)
const ULong_t kMWMHintsFunctions
Definition: GX11Gui.cxx:55
static GC * gGCtext
Definition: TGX11.cxx:93
void SendEvent(Window_t id, Event_t *ev)
Send event ev to window id.
Definition: TGWin32.cxx:5586
Handle_t FontH_t
Definition: GuiTypes.h:36
const uint32_t SIZE
Definition: stressVdt.cxx:21
Int_t fBlueDiv
Blue value divider.
Definition: TGWin32.h:129
void Align(void)
Compute alignment variables.
Definition: TGWin32.cxx:1207
void GetPasteBuffer(Window_t id, Atom_t atom, TString &text, Int_t &nchar, Bool_t del)
Get contents of paste buffer atom into string.
Definition: TGWin32.cxx:6665
ULong_t fBackgroundPixel
Definition: GuiTypes.h:96
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:164
Bool_t fMapInstalled
Definition: GuiTypes.h:130
void SetDoubleBuffer(Int_t wid, Int_t mode)
Set the double buffer on/off on window wid.
Definition: TGWin32.cxx:3031
Region_t CreateRegion()
Create a new empty region.
Definition: TGWin32.cxx:6871
UShort_t fRed
Definition: GuiTypes.h:313
const Mask_t kGCClipMask
Definition: GuiTypes.h:306
void LowerWindow(Window_t id)
Lower window so it lays below all its siblings.
Definition: TGWin32.cxx:4462
long GIFencode(int Width, int Height, Int_t Ncol, Byte_t R[], Byte_t G[], Byte_t B[], Byte_t ScLine[], void(*get_scline)(int, int, Byte_t *), void(*pb)(Byte_t))
Pixmap_t CreatePixmapFromData(unsigned char *bits, UInt_t width, UInt_t height)
create an image from RGB data.
Definition: TGWin32.cxx:7152
static const double x2[5]
Int_t fGreenDiv
Green value divider.
Definition: TGWin32.h:128
Double_t x[n]
Definition: legend1.C:17
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition: TTF.cxx:183
void SetTextFont(Font_t fontnumber)
Set specified font.
Definition: TGWin32.cxx:1540
unsigned long KeySym
Definition: TGWin32.h:57
void QueryPointer(Int_t &ix, Int_t &iy)
Query pointer position.
Definition: TGWin32.cxx:2266
Display_t GetDisplay() const
Returns handle to display (might be useful in some cases where direct X11 manipulation outside of TVi...
Definition: TGWin32.cxx:5083
void SetDoubleBufferON()
Turn double buffer mode on.
Definition: TGWin32.cxx:3077
void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode)
Draw text using TrueType fonts.
Definition: TGWin32.cxx:1357
void SetFillColor(Color_t cindex)
Set color index for fill areas.
Definition: TGWin32.cxx:3135
static void SetTextFont(Font_t fontnumber)
Set specified font.
Definition: TTF.cxx:496
Float_t GetGreen() const
Definition: TColor.h:61
unsigned char Byte_t
Definition: RtypesCore.h:60
void UpdateFillColor()
Definition: TGWin32.cxx:3150
void GetPlanes(Int_t &nplanes)
Get maximum number of planes.
Definition: TGWin32.cxx:2038
Handle_t fXEvent
Current native (GDK) event.
Definition: TGWin32.h:133
Int_t GetProperty(Window_t, Atom_t, Long_t, Long_t, Bool_t, Atom_t, Atom_t *, Int_t *, ULong_t *, ULong_t *, unsigned char **)
Returns the actual type of the property, the actual format of the property, and a pointer to the data...
Definition: TGWin32.cxx:7348
static void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Get width (w) and height (h) when text is horizontal.
Definition: TTF.cxx:134
static TVirtualX * fgRealObject
unsigned int r3[N_CITIES]
Definition: simanTSP.cxx:323
const int ny
Definition: kalman.C:17
void DeletePixmap(Pixmap_t pmap)
Explicitely delete pixmap resource.
Definition: TGWin32.cxx:5351
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Definition: TTF.cxx:249
void SetInput(Int_t inp)
Set input on or off.
Definition: TGWin32.cxx:3225
Handle_t fHandle
Definition: GuiTypes.h:186
static FILE * gGifFile
Definition: TGWin32.cxx:4031
Handle_t Atom_t
Definition: GuiTypes.h:38
const Int_t kMAXMK
Definition: TGX11.cxx:118
ULong_t fForeground
Definition: GuiTypes.h:228
Colormap_t fColormap
Definition: GuiTypes.h:129
Bool_t CreatePictureFromFile(Drawable_t id, const char *filename, Pixmap_t &pict, Pixmap_t &pict_mask, PictureAttributes_t &attr)
Create a picture pixmap from data on file.
Definition: TGWin32.cxx:5361
const Mask_t kGCFont
Definition: GuiTypes.h:301
Int_t fXRoot
Definition: GuiTypes.h:180
void CopyGC(GContext_t org, GContext_t dest, Mask_t mask)
Copies graphics context from org to dest.
Definition: TGWin32.cxx:5262
Int_t WriteGIF(char *name)
Writes the current window into GIF file.
Definition: TGWin32.cxx:4137
Bool_t fPenModified
line syle || width modified
Definition: TGWin32.h:139
const Mask_t kGCLineWidth
Definition: GuiTypes.h:291
static void Unlock()
Definition: TGWin32.cxx:954
void MapGCValues(GCValues_t &gval, ULong_t &xmask, GdkGCValues &xgval, Bool_t tox=kTRUE)
Map a GCValues_t to a XCGValues structure if tox is true.
Definition: TGWin32.cxx:4773
const Mask_t kWAColormap
Definition: GuiTypes.h:154
void ChangeProperty(Window_t id, Atom_t property, Atom_t type, UChar_t *data, Int_t len)
This function alters the property for the specified window and causes the X server to generate a Prop...
Definition: TGWin32.cxx:6127
static TVirtualX * RealObject()
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:303
static void GlobalLock()
lock any proxy (client thread)
const ULong_t kMWMHintsInputMode
Definition: GX11Gui.cxx:57
void GetImageSize(Drawable_t id, UInt_t &width, UInt_t &height)
Returns the width and height of the image id.
Definition: TGWin32.cxx:7024
Pixmap_t CreatePixmap(Drawable_t id, UInt_t w, UInt_t h)
Creates a pixmap of the width and height you specified and returns a pixmap ID that identifies it...
Definition: TGWin32.cxx:5299
void GrabButton(Window_t id, EMouseButton button, UInt_t modifier, UInt_t evmask, Window_t confine, Cursor_t cursor, Bool_t grab=kTRUE)
Establish passive grab on a certain mouse button.
Definition: TGWin32.cxx:6209
void gdk_win32_draw_arc(GdkDrawable *drawable, GdkGC *gc, gint filled, gint x, gint y, gint width, gint height, gint angle1, gint angle2)
Bool_t fLineColorModified
Definition: TGWin32.h:138
void IntersectRegion(Region_t rega, Region_t regb, Region_t result)
Compute the intersection of rega and regb and return result region.
Definition: TGWin32.cxx:6920
void UpdateMarkerColor()
Definition: TGWin32.cxx:3363
Bool_t CreatePictureFromData(Drawable_t id, char **data, Pixmap_t &pict, Pixmap_t &pict_mask, PictureAttributes_t &attr)
Create a pixture pixmap from data.
Definition: TGWin32.cxx:5395
R__EXTERN ULong_t gConsoleWindow
Definition: TWinNTSystem.h:267
static void PutByte(Byte_t b)
Put byte b in output stream.
Definition: TGWin32.cxx:4061
void FreeColor(Colormap_t cmap, ULong_t pixel)
Free color cell with specified pixel value.
Definition: TGWin32.cxx:5542
static GC * gGCfill
Definition: TGX11.cxx:92
static TTGlyph * GetGlyphs()
Definition: TTF.cxx:660
you should not use this method at all Int_t Int_t Double_t bm
Definition: TRolke.cxx:630
Int_t OpenPixmap(UInt_t w, UInt_t h)
Open a new pixmap.
Definition: TGWin32.cxx:2103
void SetCursor(Int_t win, ECursor cursor)
Set the cursor.
Definition: TGWin32.cxx:2999
void MapEventMask(UInt_t &emask, UInt_t &xemask, Bool_t tox=kTRUE)
Map event mask to or from gdk.
Definition: TGWin32.cxx:4661
XFontStruct * id
Definition: TGX11.cxx:108
Int_t fGreenShift
Bits to left shift green.
Definition: TGWin32.h:131
static TVirtualX * ProxyObject()
void RenderString(Int_t x, Int_t y, ETextMode mode)
Perform the string rendering in the pad.
Definition: TGWin32.cxx:1434
static ULong_t fgMainThreadId
main thread ID
static GC * gGCdash
Definition: TGX11.cxx:95
int GIFdecode(Byte_t *GIFarr, Byte_t *PIXarr, int *Width, int *Height, int *Ncols, Byte_t *R, Byte_t *G, Byte_t *B)
Definition: gifdecode.c:149
void SetMWMHints(Window_t id, UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGWin32.cxx:6325
void GrabKey(Window_t id, Int_t keycode, UInt_t modifier, Bool_t grab=kTRUE)
Establish passive grab on a certain key.
Definition: TGWin32.cxx:6190
Int_t fTsXOrigin
Definition: GuiTypes.h:241
short Color_t
Definition: RtypesCore.h:79
Short_t fX
Definition: GuiTypes.h:363
void GetRGB(Int_t index, Float_t &r, Float_t &g, Float_t &b)
Get rgb values for color "index".
Definition: TGWin32.cxx:2046
virtual void GetTextExtent(UInt_t &w, UInt_t &h, char *mess)
Return the size of a character string.
Definition: TGWin32.cxx:2066
static int gDashOffset
Definition: TGX11.cxx:134
Bool_t IsDNDAware(Window_t win, Atom_t *typelist)
Checks if Window win is DND aware, and knows any of the DND formats passed in argument.
Definition: TGWin32.cxx:7544
void Warp(Int_t ix, Int_t iy, Window_t id=0)
Set pointer position.
Definition: TGWin32.cxx:3990
const ULong_t kMWMHintsDecorations
Definition: GX11Gui.cxx:56
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:47
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
Definition: TTF.cxx:364
void SetFillStyle(Style_t style)
Set fill area style.
Definition: TGWin32.cxx:3169
Int_t KeysymToKeycode(UInt_t keysym)
Convert a keysym to the appropriate keycode.
Definition: TGWin32.cxx:6492
void SetDrawMode(EDrawMode mode)
Set the drawing mode.
Definition: TGWin32.cxx:3106
Definition: TPoint.h:33
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:28
void SetIconName(Window_t id, char *name)
Set window icon name.
Definition: TGWin32.cxx:6264
Bool_t PointInRegion(Int_t x, Int_t y, Region_t reg)
Returns true if the point x,y is in the region.
Definition: TGWin32.cxx:6954
#define None
Definition: TGWin32.h:59
void SetLineStyle(Style_t linestyle)
Set line style.
Definition: TGWin32.cxx:3290
point * points
Definition: X3DBuffer.c:20
UShort_t fGreen
Definition: GuiTypes.h:314
const Mask_t kButtonPressMask
Definition: GuiTypes.h:162
void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, Int_t *ic)
Draw a cell array.
Definition: TGWin32.cxx:1701
Bool_t fOverrideRedirect
Definition: GuiTypes.h:108
void SetTextSize(Float_t textsize)
Set current text size.
Definition: TGWin32.cxx:1564
void GetCharacterUp(Float_t &chupx, Float_t &chupy)
Return character up vector.
Definition: TGWin32.cxx:1932
Int_t RequestLocator(Int_t mode, Int_t ctyp, Int_t &x, Int_t &y)
Request Locator position.
Definition: TGWin32.cxx:2311
void SetDNDAware(Window_t win, Atom_t *typelist)
Add XdndAware property and the list of drag and drop types to the Window win.
Definition: TGWin32.cxx:7563
Int_t fTextAlign
Text alignment (set in SetTextAlign)
Definition: TGWin32.h:122
const Mask_t kKeyPressMask
Definition: GuiTypes.h:160
void DrawPolyLine(Int_t n, TPoint *xy)
Draw a line through all points.
Definition: TGWin32.cxx:1798
void CopyPixmap(Int_t wid, Int_t xpos, Int_t ypos)
Copy the pixmap wid at the position xpos, ypos in the current window.
Definition: TGWin32.cxx:1647
static XWindow_t * gCws
Definition: TGX11.cxx:80
Bool_t fGraphicsExposures
Definition: GuiTypes.h:245
Int_t fTextAlignH
Text Alignment Horizontal.
Definition: TGWin32.h:120
void DrawSegments(Drawable_t id, GContext_t gc, Segment_t *seg, Int_t nseg)
Draws multiple line segments. Each line is specified by a pair of points.
Definition: TGWin32.cxx:6524
Float_t fTextAngle
Text angle.
Definition: TAttText.h:27
static ULong_t fgPostMessageId
post message ID
char ** ListFonts(const char *fontname, Int_t max, Int_t &count)
Return list of font names matching "fontname".
Definition: TGWin32.cxx:6983
float ymax
Definition: THbookFile.cxx:93
const Int_t kPropMWMHintElements
Definition: GX11Gui.cxx:60
static struct @69 gMarker
Bool_t AllocColor(GdkColormap *cmap, GdkColor *color)
Allocate color in colormap.
Definition: TGWin32.cxx:1163
Style_t fLineStyle
Line style.
Definition: TAttLine.h:28
void SetClipOFF(Int_t wid)
Turn off the clipping for the window wid.
Definition: TGWin32.cxx:2899
void SetWindowBackgroundPixmap(Window_t id, Pixmap_t pxm)
Set pixmap as window background.
Definition: TGWin32.cxx:4546
EMouseButton
Definition: GuiTypes.h:215
void MapModifierState(UInt_t &state, UInt_t &xstate, Bool_t tox=kTRUE)
Map modifier key state to or from X.
Definition: TGWin32.cxx:5635
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Definition: TExMap.cxx:173
TPaveText * pt
static Int_t GetWidth()
Definition: TTF.cxx:625
void FreeFontNames(char **fontlist)
Frees the specified the array of strings "fontlist".
Definition: TGWin32.cxx:7007
TRandom2 r(17)
GdkVisual * fVisual
Definition: TGWin32.h:115
const Mask_t kWAEventMask
Definition: GuiTypes.h:152
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Time_t fTime
Definition: GuiTypes.h:178
EGEventType fType
Definition: GuiTypes.h:176
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
void DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode)
Draw a box.
Definition: TGWin32.cxx:1662
UInt_t fHeight
Definition: GuiTypes.h:183
Bool_t SetSelectionOwner(Window_t, Atom_t &)
Assigns owner of Clipboard.
Definition: TGWin32.cxx:7433
Bool_t fFillStyleModified
Definition: TGWin32.h:137
const Mask_t kGCClipXOrigin
Definition: GuiTypes.h:304
const char * GetLineStyleString(Int_t i=1) const
Return line style string (used by PostScript).
Definition: TStyle.cxx:792
Color_t fLineColor
Line color.
Definition: TAttLine.h:27
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:496
VOID CALLBACK MyTimerProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime)
Windows timer handling events while moving/resizing windows.
Definition: TGWin32.cxx:835
static ULong_t fgUserThreadId
user (e.g. python) thread ID
void gdk_win32_draw_rectangle(GdkDrawable *drawable, GdkGC *gc, gint filled, gint x, gint y, gint width, gint height)
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
void gdk_win32_draw_points(GdkDrawable *drawable, GdkGC *gc, GdkPoint *points, gint npoints)
R__EXTERN TVirtualX *(* gPtr2VirtualX)()
Definition: TVirtualX.h:363
const Mask_t kExposureMask
Definition: GuiTypes.h:166
static FT_Matrix * GetRotMatrix()
Definition: TTF.cxx:646
Float_t fCharacterUpX
Character Up vector along X.
Definition: TGWin32.h:123
unsigned int UInt_t
Definition: RtypesCore.h:42
Width_t fLineWidth
Line width.
Definition: TAttLine.h:29
TTF helper class containing glyphs description.
Definition: TTF.h:67
TMarker * m
Definition: textangle.C:8
void SetCharacterUp(Float_t chupx, Float_t chupy)
Set character up vector.
Definition: TGWin32.cxx:2870
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
void ChangeActivePointerGrab(Window_t, UInt_t, Cursor_t)
Changes the active cursor of the specified window.
Definition: TGWin32.cxx:7396
static GdkImage * gGifImage
Definition: TGWin32.cxx:4032
void MakeOpaqueColors(Int_t percent, ULong_t *orgcolors, Int_t ncolors)
Get RGB values for orgcolors, add percent neutral to the RGB and allocate new_colors.
Definition: TGWin32.cxx:3771
#define calloc
Definition: civetweb.c:819
short Short_t
Definition: RtypesCore.h:35
void ClearWindow()
Clear current window.
Definition: TGWin32.cxx:1573
Int_t fYRoot
Definition: GuiTypes.h:180
TLine * l
Definition: textangle.C:4
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
const Mask_t kGCClipYOrigin
Definition: GuiTypes.h:305
#define CALLBACK
Definition: TGLFaceSet.cxx:30
const Mask_t kGCJoinStyle
Definition: GuiTypes.h:294
Double_t ACos(Double_t)
Definition: TMath.h:445
float xmax
Definition: THbookFile.cxx:93
GdkImage * GetBackground(Int_t x, Int_t y, UInt_t w, UInt_t h)
Get the background of the current window in an XImage.
Definition: TGWin32.cxx:1386
void QueryColors(GdkColormap *cmap, GdkColor *colors, Int_t ncolors)
Returns the current RGB value for the pixel in the XColor structure.
Definition: TGWin32.cxx:1180
Font_t fTextFont
Text font.
Definition: TAttText.h:31
void SetTextColor(Color_t cindex)
Set color index for text.
Definition: TGWin32.cxx:3943
void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Draw a line.
Definition: TGWin32.cxx:1770
void Reset(Detail::TBranchProxy *x)
GdkCursor * fCursors[kNumCursors]
List of cursors.
Definition: TGWin32.h:89
#define XA_ATOM
Definition: xatom.h:13
void DestroySubwindows(Window_t id)
Destroy all internal subwindows.
Definition: TGWin32.cxx:4433
#define VOID
Definition: triangle.h:286
void GetRegionBox(Region_t reg, Rectangle_t *)
Return smallest enclosing rectangle.
Definition: TGWin32.cxx:6970
void Bell(Int_t percent)
Sets the sound bell. Percent is loudness from -100% to 100%.
Definition: TGWin32.cxx:6059
void RemoveWindow(ULong_t qwid)
Remove a window created by Qt (like CloseWindow1()).
Definition: TGWin32.cxx:7279
ULong_t fPixel
Definition: GuiTypes.h:312
void SetMarkerStyle(Style_t markerstyle)
Set marker style.
Definition: TGWin32.cxx:3409
Int_t GetDoubleBuffer(Int_t wid)
Query the double buffer value for the window wid.
Definition: TGWin32.cxx:1977
const unsigned char gStipples[26][32]
Definition: RStipples.h:28
#define gVirtualX
Definition: TVirtualX.h:362
void MapEvent(Event_t &ev, GdkEvent &xev, Bool_t tox=kTRUE)
Map Event_t structure to gdk_event structure.
Definition: TGWin32.cxx:5691
Pixmap_t fStipple
Definition: GuiTypes.h:240
Handle_t Colormap_t
Definition: GuiTypes.h:34
short Width_t
Definition: RtypesCore.h:78
Cursor_t CreateCursor(ECursor cursor)
Create cursor handle (just return cursor from cursor pool fCursors).
Definition: TGWin32.cxx:5290
void ChangeWindowAttributes(Window_t id, SetWindowAttributes_t *attr)
Change window attributes.
Definition: TGWin32.cxx:6082
EKeySym
Definition: KeySymbols.h:27
static void * Alloc(size_t size)
Allocate a block of memory, that later can be resized using TStorage::ReAlloc().
Definition: TStorage.cxx:147
void LookupString(Event_t *event, char *buf, Int_t buflen, UInt_t &keysym)
Convert the keycode from the event structure to a key symbol (according to the modifiers specified in...
Definition: TGWin32.cxx:6612
void DestroyWindow(Window_t id)
Destroy window.
Definition: TGWin32.cxx:4420
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:168
long Long_t
Definition: RtypesCore.h:50
FontH_t GetFontHandle(FontStruct_t fs)
Return handle to font described by font structure.
Definition: TGWin32.cxx:5157
void DrawPolyMarker(Int_t n, TPoint *xy)
Draw n markers with the current attributes at position x, y.
Definition: TGWin32.cxx:1854
void ImgPickPalette(GdkImage *image, Int_t &ncol, Int_t *&R, Int_t *&G, Int_t *&B)
Returns in R G B the ncol colors of the palette used by the image.
Definition: TGWin32.cxx:4075
void RemovePixmap(GdkDrawable *pix)
Remove the pixmap pix.
Definition: TGWin32.cxx:2280
void FillRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a filled rectangle. Filling is done according to the gc.
Definition: TGWin32.cxx:6502
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2241
#define XA_WM_CLASS
Definition: xatom.h:76
void DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y, const char *s, Int_t len)
Draw a string using a specific graphics context in position (x,y).
Definition: TGWin32.cxx:6416
ULong_t fBackground
Definition: GuiTypes.h:229
static const double x1[5]
Int_t fDepth
Number of color planes.
Definition: TGWin32.h:126
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
void gdk_win32_draw_segments(GdkDrawable *drawable, GdkGC *gc, GdkSegment *segs, gint nsegs)
const Mask_t kGCFillStyle
Definition: GuiTypes.h:295
const Mask_t kStructureNotifyMask
Definition: GuiTypes.h:167
void WritePixmap(Int_t wid, UInt_t w, UInt_t h, char *pxname)
Write the pixmap wid in the bitmap file pxname.
Definition: TGWin32.cxx:4014
void ChangeProperties(Window_t id, Atom_t property, Atom_t type, Int_t format, UChar_t *data, Int_t len)
Put data into Clipboard.
Definition: TGWin32.cxx:7450
static Int_t GetAscent()
Definition: TTF.cxx:632
R__EXTERN TWin32SplashThread * gSplash
void DrawRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a rectangle outline.
Definition: TGWin32.cxx:6513
void SetInputFocus(Window_t id)
Set keyboard input focus to window id.
Definition: TGWin32.cxx:6559
Bool_t GUIThreadMessageFunc(MSG *msg)
Message processing function for the GUI thread.
Definition: TGWin32.cxx:846
TText * text
Bool_t EqualRegion(Region_t rega, Region_t regb)
Returns true if two regions are equal.
Definition: TGWin32.cxx:6962
void SetWMPosition(Window_t id, Int_t x, Int_t y)
Tells the window manager the desired position [x,y] of window "id".
Definition: TGWin32.cxx:6337
Float_t fCharacterUpY
Character Up vector along Y.
Definition: TGWin32.h:124
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:163
void ClearArea(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
Clear a window area to the bakcground color.
Definition: TGWin32.cxx:6150
static GC gGCecho
Definition: TGX11.cxx:98
UInt_t fCode
Definition: GuiTypes.h:181
Pixmap_t CreateBitmap(Drawable_t id, const char *bitmap, UInt_t width, UInt_t height)
Create a bitmap (i.e. pixmap with depth 1) from the bitmap data.
Definition: TGWin32.cxx:5337
const Handle_t kParentRelative
Definition: GuiTypes.h:91
int type
Definition: TGX11.cxx:120
#define TRUE
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
const Mask_t kGCTile
Definition: GuiTypes.h:297
void WMDeleteNotify(Window_t id)
Tell WM to send message when window is closed via WM.
Definition: TGWin32.cxx:6160
Int_t RequestString(Int_t x, Int_t y, char *text)
Request a string.
Definition: TGWin32.cxx:2466
#define free
Definition: civetweb.c:821
const Mask_t kWAOverrideRedirect
Definition: GuiTypes.h:150
unsigned long ULong_t
Definition: RtypesCore.h:51
Int_t fJoinStyle
Definition: GuiTypes.h:234
TGWin32()
Default constructor.
Definition: TGWin32.cxx:757
Window_t fRoot
Definition: GuiTypes.h:121
TCanvas * style()
Definition: style.C:1
Double_t y[n]
Definition: legend1.C:17
char ** Argv() const
Definition: TApplication.h:142
void AsmLong(Long_t i1, Long_t i2, Long_t &ll)
Definition: GX11Gui.cxx:159
const Mask_t kGCFunction
Definition: GuiTypes.h:287
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:35
const Mask_t kGCCapStyle
Definition: GuiTypes.h:293
void MapSetWindowAttributes(SetWindowAttributes_t *attr, ULong_t &xmask, GdkWindowAttr &xattr)
Map a SetWindowAttributes_t to a GdkWindowAttr structure.
Definition: TGWin32.cxx:4740
Bool_t IsCmdThread() const
returns kTRUE if we are inside cmd/server thread
Definition: TGWin32.cxx:887
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
static int gDashSize
Definition: TGX11.cxx:135
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE)
Beep for duration milliseconds with a tone of frequency freq.
Definition: TSystem.cxx:329
const Mask_t kGCForeground
Definition: GuiTypes.h:289
The color creation and management class.
Definition: TColor.h:23
void SelectInput(Window_t id, UInt_t evmask)
Defines which input events the window is interested in.
Definition: TGWin32.cxx:6538
GdkColormap * fColormap
Default colormap, 0 if b/w.
Definition: TGWin32.h:116
Window_t CreateWindow(Window_t parent, Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth, UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype)
Return handle to newly created gdk window.
Definition: TGWin32.cxx:4556
void GetGCValues(GContext_t gc, GCValues_t &gval)
Get current values from graphics context gc.
Definition: TGWin32.cxx:6450
const char null_cursor_bits[]
Definition: TGX11.cxx:150
Bool_t fMarkerStyleModified
Definition: TGWin32.h:140
Int_t fCapStyle
Definition: GuiTypes.h:232
Float_t fTextSize
Text size.
Definition: TAttText.h:28
static GC gGClist[kMAXGC]
Definition: TGX11.cxx:89
void PutImage(Int_t offset, Int_t itran, Int_t x0, Int_t y0, Int_t nx, Int_t ny, Int_t xmin, Int_t ymin, Int_t xmax, Int_t ymax, UChar_t *image, Drawable_t id)
Draw image.
Definition: TGWin32.cxx:4200
void SetWMTransientHint(Window_t id, Window_t main_id)
Tell window manager that window is a transient window of gdk_parent_root.
Definition: TGWin32.cxx:6406
Long_t fUser[5]
Definition: GuiTypes.h:188
void MapWindow(Window_t id)
Map window on screen.
Definition: TGWin32.cxx:4357
void UnionRegion(Region_t rega, Region_t regb, Region_t result)
Compute the union of rega and regb and return result region.
Definition: TGWin32.cxx:6911
static ULong_t fgPingMessageId
ping message ID
void SetIconPixmap(Window_t id, Pixmap_t pic)
Set pixmap the WM can use when the window is iconized.
Definition: TGWin32.cxx:6274
static Pixmap gFillPattern
Definition: TGX11.cxx:101
#define org(otri, vertexptr)
Definition: triangle.c:1037
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
Return some font properties.
Definition: TGWin32.cxx:6438
Window_t GetCurrentWindow() const
Return current window pointer. Protected method used by TGWin32TTF.
Definition: TGWin32.cxx:1955
static void * ReAlloc(void *vp, size_t size)
Reallocate (i.e.
Definition: TStorage.cxx:178
const Mask_t kGCStipple
Definition: GuiTypes.h:298
UInt_t fWidth
Definition: GuiTypes.h:183
Int_t InitWindow(ULong_t window)
Open window and return window number.
Definition: TGWin32.cxx:2162
static char gDashList[10]
Definition: TGX11.cxx:132
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition: TTF.cxx:341
Int_t fMaxNumberOfWindows
Maximum number of windows.
Definition: TGWin32.h:86
void DeleteFont(FontStruct_t fs)
Explicitely delete font structure obtained with LoadQueryFont().
Definition: TGWin32.cxx:5168
#define FALSE
Bool_t fOverrideRedirect
Definition: GuiTypes.h:135
Handle_t Window_t
Definition: GuiTypes.h:30
void UpdateMarkerStyle()
Definition: TGWin32.cxx:3419
GdkColor color
Definition: TGWin32.h:64
Int_t fFormat
Definition: GuiTypes.h:187
Mask_t fMask
Definition: GuiTypes.h:252
Window_t GetWindowID(Int_t wid)
Return the X11 window identifier.
Definition: TGWin32.cxx:2077
unsigned char * GetColorBits(Drawable_t wid, Int_t x, Int_t y, UInt_t width, UInt_t height)
Gets DIB bits x, y, width, height - position of bitmap returns a pointer on bitmap bits array in form...
Definition: TGWin32.cxx:7091
void DestroyRegion(Region_t reg)
Destroy region.
Definition: TGWin32.cxx:6879
void SplitLong(Long_t ll, Long_t &i1, Long_t &i2)
Definition: GX11Gui.cxx:148
Bool_t EmptyRegion(Region_t reg)
Return true if the region is empty.
Definition: TGWin32.cxx:6946
const Mask_t kGCTileStipYOrigin
Definition: GuiTypes.h:300
void GetWindowSize(Drawable_t id, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
Return geometry of window (should be called GetGeometry but signature already used).
Definition: TGWin32.cxx:6728
void MoveResizeWindow(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize a window.
Definition: TGWin32.cxx:4484
void ResizeWindow(Int_t wid)
Resize the current window if necessary.
Definition: TGWin32.cxx:2791
const Mask_t kGCSubwindowMode
Definition: GuiTypes.h:302
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:476
Int_t fScreenNumber
Screen number.
Definition: TGWin32.h:117
Definition: file.py:1
Bool_t Next(ULong64_t &hash, Long64_t &key, Long64_t &value)
Get next entry from TExMap. Returns kFALSE at end of map.
Definition: TExMap.cxx:411
const Mask_t kWABorderWidth
Definition: GuiTypes.h:144
Region_t PolygonRegion(Point_t *points, Int_t np, Bool_t winding)
Create region for the polygon defined by the points array.
Definition: TGWin32.cxx:6901
const size_t kBitsPerByte
Definition: Rtypes.h:114
#define dest(otri, vertexptr)
Definition: triangle.c:1040
Color_t fFillColor
Fill area color.
Definition: TAttFill.h:27
#define XA_STRING
Definition: xatom.h:40
const Mask_t kGCBackground
Definition: GuiTypes.h:290
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Window_t GetPrimarySelectionOwner()
Returns the window id of the current owner of the primary selection.
Definition: TGWin32.cxx:6571
Int_t AddPixmap(ULong_t pix, UInt_t w, UInt_t h)
register pixmap created by TGWin32GLManager
Definition: TGWin32.cxx:7188
#define BITmask(x)
Window_t GetParent(Window_t id) const
Return the parent of the window.
Definition: TGWin32.cxx:5121
UInt_t ScreenWidthMM() const
Returns the width of the screen in millimeters.
Definition: TGWin32.cxx:7324
Handle_t Region_t
Definition: GuiTypes.h:33
const Mask_t kGCTileStipXOrigin
Definition: GuiTypes.h:299
void SetForeground(GContext_t gc, ULong_t foreground)
Set foreground color in graphics context (shortcut for ChangeGC with only foreground mask set)...
Definition: TGWin32.cxx:6824
const Mask_t kFocusChangeMask
Definition: GuiTypes.h:170
Handle_t Pixmap_t
Definition: GuiTypes.h:31
int Seek_t
Definition: RtypesCore.h:49
void Sync(Int_t mode)
Set synchronisation on or off.
Definition: TGWin32.cxx:3961
Int_t fLineWidth
Definition: GuiTypes.h:230
static int gLineStyle
Definition: TGX11.cxx:129
Int_t FindColor(ULong_t pixel, ULong_t *orgcolors, Int_t ncolors)
Returns index in orgcolors (and new_colors) for pixel.
Definition: TGWin32.cxx:3831
const Int_t kPropMotifWMHintsElements
Definition: GX11Gui.cxx:59
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void SubtractRegion(Region_t rega, Region_t regb, Region_t result)
Subtract rega from regb.
Definition: TGWin32.cxx:6929
const Int_t kBIGGEST_RGB_VALUE
Definition: TGX11.cxx:83
#define NULL
Definition: Rtypes.h:82
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:494
UInt_t fState
Definition: GuiTypes.h:182
static ULong_t gKeybdMask
Definition: TGX11.cxx:144
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:49
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
TExMap * fColors
Hash list of colors.
Definition: TGWin32.h:88
Bool_t fDefined
true if pixel value is defined
Definition: TGWin32.h:65
#define TESTBIT(n, i)
Definition: Rtypes.h:123
static int gDashLength
Definition: TGX11.cxx:133
void NextEvent(Event_t &event)
Copies first pending event from event queue to Event_t structure and removes event from queue...
Definition: TGWin32.cxx:5616
static void SetTextSize(Float_t textsize)
Set current text size.
Definition: TTF.cxx:572
void ConvertPrimarySelection(Window_t id, Atom_t clipboard, Time_t when)
XConvertSelection() causes a SelectionRequest event to be sent to the current primary selection owner...
Definition: TGWin32.cxx:6598
void UnionRectWithRegion(Rectangle_t *rect, Region_t src, Region_t dest)
Union of rectangle with a region.
Definition: TGWin32.cxx:6887
void gdk_win32_draw_polygon(GdkDrawable *drawable, GdkGC *gc, gint filled, GdkPoint *points, gint npoints)
const Mask_t kWABackPixel
Definition: GuiTypes.h:141
static void _set_event_time(GdkEvent &event, UInt_t time)
Definition: TGWin32.cxx:5647
Int_t fSubwindowMode
Definition: GuiTypes.h:244
void SetClassHints(Window_t id, char *className, char *resourceName)
Set the windows class and resource name.
Definition: TGWin32.cxx:6286
GdkGC * GetGC(Int_t which) const
Return desired Graphics Context ("which" maps directly on gGCList[]).
Definition: TGWin32.cxx:1964
double result[121]
unsigned char UChar_t
Definition: RtypesCore.h:34
Int_t fBlueShift
Bits to left shift blue.
Definition: TGWin32.h:132
void UpdateWindow(Int_t mode)
Update display.
Definition: TGWin32.cxx:3974
static int gCapStyle
Definition: TGX11.cxx:130
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
void SetClipRegion(Int_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h)
Set clipping region for the window wid.
Definition: TGWin32.cxx:2917
unsigned long Atom
Definition: xatom.h:9
Drawable_t CreateImage(UInt_t width, UInt_t height)
Allocates the memory needed for an drawable.
Definition: TGWin32.cxx:7015
Int_t ResizePixmap(Int_t wid, UInt_t w, UInt_t h)
Resize a pixmap.
Definition: TGWin32.cxx:2743
FontStruct_t GetFontStruct(FontH_t fh)
Retrieve associated font structure once we have the font handle.
Definition: TGWin32.cxx:6464
static Int_t GetNumGlyphs()
Definition: TTF.cxx:639
const Bool_t kTRUE
Definition: Rtypes.h:91
void SetTypeList(Window_t win, Atom_t prop, Atom_t *typelist)
Add the list of drag and drop types to the Window win.
Definition: TGWin32.cxx:7475
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:27
const Mask_t kAnyModifier
Definition: GuiTypes.h:211
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
Atom_t InternAtom(const char *atom_name, Bool_t only_if_exist)
Return atom handle for atom_name.
Definition: TGWin32.cxx:5101
void SetKeyAutoRepeat(Bool_t on=kTRUE)
Turn key auto repeat on or off.
Definition: TGWin32.cxx:6175
const int kMAXGC
Definition: TGX11.cxx:88
void gdk_win32_draw_text(GdkDrawable *drawable, GdkFont *font, GdkGC *gc, gint x, gint y, const gchar *text, gint text_length)
void QueryColor(Colormap_t cmap, ColorStruct_t &color)
Fill in the primary color components for a specific pixel value.
Definition: TGWin32.cxx:5524
Long_t fYourEventMask
Definition: GuiTypes.h:133
int GIFinfo(Byte_t *GIFarr, int *Width, int *Height, int *Ncols)
Definition: gifdecode.c:80
static XFontStruct * gTextFont
Definition: TGX11.cxx:112
const Int_t n
Definition: legend1.C:16
Int_t fX
Definition: GuiTypes.h:179
EGraphicsFunction
Definition: GuiTypes.h:68
void TranslateCoordinates(Window_t src, Window_t dest, Int_t src_x, Int_t src_y, Int_t &dest_x, Int_t &dest_y, Window_t &child)
TranslateCoordinates translates coordinates from the frame of reference of one window to another...
Definition: TGWin32.cxx:6697
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
R__EXTERN TInterpreter *(* gPtr2Interpreter)()
Definition: TInterpreter.h:518
TObject * fRefreshTimer
TGWin32RefreshTimer for GUI thread message handler.
Definition: TGWin32.h:134
void SetTextAlign(Short_t talign=11)
Set text alignment.
Definition: TGWin32.cxx:3883
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
char name[80]
Definition: TGX11.cxx:109
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:35
static ULong_t gMouseMask
Definition: TGX11.cxx:140
void CopyArea(Drawable_t src, Drawable_t dest, GContext_t gc, Int_t src_x, Int_t src_y, UInt_t width, UInt_t height, Int_t dest_x, Int_t dest_y)
Copy a drawable (i.e.
Definition: TGWin32.cxx:6069
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
void DeleteGC(GContext_t gc)
Explicitely delete a graphics context.
Definition: TGWin32.cxx:5282
void SetPrimarySelectionOwner(Window_t id)
Makes the window id the current owner of the primary selection.
Definition: TGWin32.cxx:6580
static const FT_BBox & GetBox()
Definition: TTF.cxx:653
Style_t fFillStyle
Fill area style.
Definition: TAttFill.h:28
static Bool_t GetSmoothing()
Definition: TTF.cxx:611
void IconifyWindow(Window_t id)
Iconify the window.
Definition: TGWin32.cxx:4508
int gdk_debug_level
Definition: TGWin32.cxx:137
segment * segs
Definition: X3DBuffer.c:21
static GC * gGCinvt
Definition: TGX11.cxx:94
Short_t fY
Definition: GuiTypes.h:358
ULong_t Handle_t
Definition: GuiTypes.h:27
void SetRGB(Int_t cindex, Float_t r, Float_t g, Float_t b)
Set color intensities for given color index.
Definition: TGWin32.cxx:3846