Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGX11.h
Go to the documentation of this file.
1 // @(#)root/x11:$Id$
2 // Author: Rene Brun, Olivier Couet, Fons Rademakers 28/11/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #ifndef ROOT_TGX11
13 #define ROOT_TGX11
14 
15 #include "TVirtualX.h"
16 
17 #if !defined(__CINT__)
18 
19 #ifdef Status
20 // Convert Status from a CPP macro to a typedef:
21 typedef Status X11Status_t;
22 #undef Status
23 typedef X11Status_t Status;
24 #endif
25 
26 #ifdef None
27 // Convert None from a CPP macro to a static const int:
28 static const unsigned long gX11None = None;
29 #undef None
30 static const unsigned long None = gX11None;
31 #endif
32 
33 #endif
34 
35 typedef unsigned long XID;
36 typedef XID Drawable;
37 typedef XID Cursor;
38 typedef XID Colormap;
39 typedef XID Window;
40 
41 struct RXGCValues;
42 struct RXColor;
43 struct RXImage;
44 struct RXPoint;
45 struct RXpmAttributes;
46 struct RXSetWindowAttributes;
47 struct RXVisualInfo;
48 struct RVisual;
49 
50 /// Description of a X11 window.
51 struct XWindow_t {
52  Int_t fOpen; ///< 1 if the window is open, 0 if not
53  Int_t fDoubleBuffer; ///< 1 if the double buffer is on, 0 if not
54  Int_t fIsPixmap; ///< 1 if pixmap, 0 if not
55  Drawable fDrawing; ///< drawing area, equal to window or buffer
56  Drawable fWindow; ///< X11 window
57  Drawable fBuffer; ///< pixmap used for double buffer
58  UInt_t fWidth; ///< width of the window
59  UInt_t fHeight; ///< height of the window
60  Int_t fClip; ///< 1 if the clipping is on
61  Int_t fXclip; ///< x coordinate of the clipping rectangle
62  Int_t fYclip; ///< y coordinate of the clipping rectangle
63  UInt_t fWclip; ///< width of the clipping rectangle
64  UInt_t fHclip; ///< height of the clipping rectangle
65  ULong_t *fNewColors; ///< new image colors (after processing)
66  Int_t fNcolors; ///< number of different colors
67  Bool_t fShared; ///< notify when window is shared
68 };
69 
70 /// Description of a X11 color.
71 struct XColor_t {
72  ULong_t fPixel; ///< color pixel value
73  UShort_t fRed; ///< red value in range [0,kBIGGEST_RGB_VALUE]
74  UShort_t fGreen; ///< green value
75  UShort_t fBlue; ///< blue value
76  Bool_t fDefined; ///< true if pixel value is defined
77  XColor_t() { fPixel = 0; fRed = fGreen = fBlue = 0; fDefined = kFALSE; }
78 };
79 
80 class TExMap;
81 
82 
83 class TGX11 : public TVirtualX {
84 
85 private:
86  Int_t fMaxNumberOfWindows; ///< Maximum number of windows
87  XWindow_t *fWindows; ///< List of windows
88  TExMap *fColors; ///< Hash list of colors
89  Cursor fCursors[kNumCursors]; ///< List of cursors
90  void *fXEvent; ///< Current native (X11) event
91 
92  void CloseWindow1();
93  void ClearPixmap(Drawable *pix);
94  void CopyWindowtoPixmap(Drawable *pix, Int_t xpos, Int_t ypos);
95  void FindBestVisual();
96  void FindUsableVisual(RXVisualInfo *vlist, Int_t nitems);
97  void PutImage(Int_t offset, Int_t itran, Int_t x0, Int_t y0, Int_t nx,
98  Int_t ny, Int_t xmin, Int_t ymin, Int_t xmax, Int_t ymax,
99  UChar_t *image, Drawable_t id);
100  void RemovePixmap(Drawable *pix);
101  void SetColor(void *gc, Int_t ci);
102  void SetFillStyleIndex(Int_t style, Int_t fasi);
103  void SetInput(Int_t inp);
104  void SetMarkerType(Int_t type, Int_t n, RXPoint *xy);
105  void CollectImageColors(ULong_t pixel, ULong_t *&orgcolors, Int_t &ncolors,
106  Int_t &maxcolors);
107  void MakeOpaqueColors(Int_t percent, ULong_t *orgcolors, Int_t ncolors);
108  Int_t FindColor(ULong_t pixel, ULong_t *orgcolors, Int_t ncolors);
109  void ImgPickPalette(RXImage *image, Int_t &ncol, Int_t *&R, Int_t *&G, Int_t *&B);
110 
111  //---- Private methods used for GUI ----
112  void MapGCValues(GCValues_t &gval, ULong_t &xmask, RXGCValues &xgval, Bool_t tox = kTRUE);
113  void MapSetWindowAttributes(SetWindowAttributes_t *attr,
114  ULong_t &xmask, RXSetWindowAttributes &xattr);
115  void MapCursor(ECursor cursor, Int_t &xcursor);
116  void MapColorStruct(ColorStruct_t *color, RXColor &xcolor);
117  void MapPictureAttributes(PictureAttributes_t &attr, RXpmAttributes &xpmattr,
118  Bool_t toxpm = kTRUE);
119  void MapModifierState(UInt_t &state, UInt_t &xstate, Bool_t tox = kTRUE);
120 
121  // void MapEvent(Event_t &ev, XEvent &xev, Bool_t tox = kTRUE);
122  void MapEvent(Event_t &ev, void *xev, Bool_t tox = kTRUE);
123 
124  void MapEventMask(UInt_t &emask, UInt_t &xemask, Bool_t tox = kTRUE);
125  void MapKeySym(UInt_t &keysym, UInt_t &xkeysym, Bool_t tox = kTRUE);
126 
127 protected:
128  void *fDisplay; ///< Pointer to display
129  RVisual *fVisual; ///< Pointer to visual used by all windows
130  Drawable fRootWin; ///< Root window used as parent of all windows
131  Drawable fVisRootWin; ///< Root window with fVisual to be used to create GC's and XImages
132  Colormap fColormap; ///< Default colormap, 0 if b/w
133  ULong_t fBlackPixel; ///< Value of black pixel in colormap
134  ULong_t fWhitePixel; ///< Value of white pixel in colormap
135  Int_t fScreenNumber; ///< Screen number
136  Int_t fTextAlignH; ///< Text Alignment Horizontal
137  Int_t fTextAlignV; ///< Text Alignment Vertical
138  Int_t fTextAlign; ///< Text alignment (set in SetTextAlign)
139  Float_t fCharacterUpX; ///< Character Up vector along X
140  Float_t fCharacterUpY; ///< Character Up vector along Y
141  Float_t fTextMagnitude; ///< Text Magnitude
142  Int_t fDepth; ///< Number of color planes
143  Int_t fRedDiv; ///< Red value divider, -1 if no TrueColor visual
144  Int_t fGreenDiv; ///< Green value divider
145  Int_t fBlueDiv; ///< Blue value divider
146  Int_t fRedShift; ///< Bits to left shift red, -1 if no TrueColor visual
147  Int_t fGreenShift; ///< Bits to left shift green
148  Int_t fBlueShift; ///< Bits to left shift blue
149  Bool_t fHasTTFonts; ///< True when TrueType fonts are used
150  Bool_t fHasXft; ///< True when XftFonts are used
151 
152  // needed by TGX11TTF
153  Bool_t AllocColor(Colormap cmap, RXColor *color);
154  void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors);
155  void *GetGC(Int_t which) const;
156  XColor_t &GetColor(Int_t cid);
157 
158 public:
159  TGX11();
160  TGX11(const TGX11 &org);
161  TGX11(const char *name, const char *title);
162  virtual ~TGX11();
163 
164  Bool_t Init(void *display);
165  void ClearWindow();
166  void ClosePixmap();
167  void CloseWindow();
168  void CopyPixmap(Int_t wid, Int_t xpos, Int_t ypos);
169  void DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode);
170  void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, Int_t *ic);
171  void DrawFillArea(Int_t n, TPoint *xy);
172  void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2);
173  void DrawPolyLine(Int_t n, TPoint *xy);
174  void DrawPolyMarker(Int_t n, TPoint *xy);
175  virtual void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode);
176  virtual void DrawText(Int_t, Int_t, Float_t, Float_t, const wchar_t *, ETextMode) {}
177  void GetCharacterUp(Float_t &chupx, Float_t &chupy);
178  Int_t GetDoubleBuffer(Int_t wid);
179  void GetGeometry(Int_t wid, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h);
180  const char *DisplayName(const char *dpyName = 0);
181  Handle_t GetNativeEvent() const { return (Handle_t) fXEvent; }
182  ULong_t GetPixel(Color_t cindex);
183  void GetPlanes(Int_t &nplanes);
184  void GetRGB(Int_t index, Float_t &r, Float_t &g, Float_t &b);
185  virtual void GetTextExtent(UInt_t &w, UInt_t &h, char *mess);
186  virtual void GetTextExtent(UInt_t &, UInt_t &, wchar_t *){}
187  Float_t GetTextMagnitude() { return fTextMagnitude; }
188  Window_t GetWindowID(Int_t wid);
189  Bool_t HasTTFonts() const { return fHasTTFonts; }
190  Int_t InitWindow(ULong_t window);
191  Int_t AddWindow(ULong_t qwid, UInt_t w, UInt_t h);
192  Int_t AddPixmap(ULong_t pixid, UInt_t w, UInt_t h);
193  void RemoveWindow(ULong_t qwid);
194  void MoveWindow(Int_t wid, Int_t x, Int_t y);
195  Int_t OpenDisplay(void *display);
196  Int_t OpenPixmap(UInt_t w, UInt_t h);
197  void QueryPointer(Int_t &ix, Int_t &iy);
198  Pixmap_t ReadGIF(Int_t x0, Int_t y0, const char *file, Window_t id=0);
199  Int_t RequestLocator(Int_t mode, Int_t ctyp, Int_t &x, Int_t &y);
200  Int_t RequestString(Int_t x, Int_t y, char *text);
201  void RescaleWindow(Int_t wid, UInt_t w, UInt_t h);
202  Int_t ResizePixmap(Int_t wid, UInt_t w, UInt_t h);
203  void ResizeWindow(Int_t wid);
204  void SelectWindow(Int_t wid);
205  void SetCharacterUp(Float_t chupx, Float_t chupy);
206  void SetClipOFF(Int_t wid);
207  void SetClipRegion(Int_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h);
208  void SetCursor(Int_t win, ECursor cursor);
209  void SetDoubleBuffer(Int_t wid, Int_t mode);
210  void SetDoubleBufferOFF();
211  void SetDoubleBufferON();
212  void SetDrawMode(EDrawMode mode);
213  void SetFillColor(Color_t cindex);
214  void SetFillStyle(Style_t style);
215  void SetLineColor(Color_t cindex);
216  void SetLineType(Int_t n, Int_t *dash);
217  void SetLineStyle(Style_t linestyle);
218  void SetLineWidth(Width_t width);
219  void SetMarkerColor(Color_t cindex);
220  void SetMarkerSize(Float_t markersize);
221  void SetMarkerStyle(Style_t markerstyle);
222  void SetOpacity(Int_t percent);
223  void SetRGB(Int_t cindex, Float_t r, Float_t g, Float_t b);
224  void SetTextAlign(Short_t talign=11);
225  void SetTextColor(Color_t cindex);
226  virtual Int_t SetTextFont(char *fontname, ETextSetMode mode);
227  virtual void SetTextFont(Font_t fontnumber);
228  void SetTextMagnitude(Float_t mgn=1) { fTextMagnitude = mgn;}
229  virtual void SetTextSize(Float_t textsize);
230  void Sync(Int_t mode);
231  void UpdateWindow(Int_t mode);
232  void Warp(Int_t ix, Int_t iy, Window_t id = 0);
233  Int_t WriteGIF(char *name);
234  void WritePixmap(Int_t wid, UInt_t w, UInt_t h, char *pxname);
235  Window_t GetCurrentWindow() const;
236  Int_t SupportsExtension(const char *ext) const;
237 
238  //---- Methods used for GUI -----
239  void GetWindowAttributes(Window_t id, WindowAttributes_t &attr);
240  void MapWindow(Window_t id);
241  void MapSubwindows(Window_t id);
242  void MapRaised(Window_t id);
243  void UnmapWindow(Window_t id);
244  void DestroyWindow(Window_t id);
245  void DestroySubwindows(Window_t id);
246  void RaiseWindow(Window_t id);
247  void LowerWindow(Window_t id);
248  void MoveWindow(Window_t id, Int_t x, Int_t y);
249  void MoveResizeWindow(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h);
250  void ResizeWindow(Window_t id, UInt_t w, UInt_t h);
251  void IconifyWindow(Window_t id);
252  void ReparentWindow(Window_t id, Window_t pid, Int_t x, Int_t y);
253  void SetWindowBackground(Window_t id, ULong_t color);
254  void SetWindowBackgroundPixmap(Window_t id, Pixmap_t pxm);
255  Window_t CreateWindow(Window_t parent, Int_t x, Int_t y,
256  UInt_t w, UInt_t h, UInt_t border,
257  Int_t depth, UInt_t clss,
258  void *visual, SetWindowAttributes_t *attr,
259  UInt_t wtype);
260  Int_t OpenDisplay(const char *dpyName);
261  void CloseDisplay();
262  Display_t GetDisplay() const;
263  Visual_t GetVisual() const;
264  Int_t GetScreen() const;
265  Int_t GetDepth() const;
266  Colormap_t GetColormap() const;
267  Atom_t InternAtom(const char *atom_name, Bool_t only_if_exist);
268  Window_t GetDefaultRootWindow() const;
269  Window_t GetParent(Window_t id) const;
270  FontStruct_t LoadQueryFont(const char *font_name);
271  FontH_t GetFontHandle(FontStruct_t fs);
272  void DeleteFont(FontStruct_t fs);
273  GContext_t CreateGC(Drawable_t id, GCValues_t *gval);
274  void ChangeGC(GContext_t gc, GCValues_t *gval);
275  void CopyGC(GContext_t org, GContext_t dest, Mask_t mask);
276  void DeleteGC(GContext_t gc);
277  Cursor_t CreateCursor(ECursor cursor);
278  void SetCursor(Window_t id, Cursor_t curid);
279  Pixmap_t CreatePixmap(Drawable_t id, UInt_t w, UInt_t h);
280  Pixmap_t CreatePixmap(Drawable_t id, const char *bitmap, UInt_t width,
281  UInt_t height, ULong_t forecolor, ULong_t backcolor,
282  Int_t depth);
283  unsigned char *GetColorBits(Drawable_t wid, Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0);
284  Pixmap_t CreatePixmapFromData(unsigned char *bits, UInt_t width, UInt_t height);
285  Pixmap_t CreateBitmap(Drawable_t id, const char *bitmap,
286  UInt_t width, UInt_t height);
287  void DeletePixmap(Pixmap_t pmap);
288  Bool_t CreatePictureFromFile(Drawable_t id, const char *filename,
289  Pixmap_t &pict, Pixmap_t &pict_mask,
290  PictureAttributes_t &attr);
291  Bool_t CreatePictureFromData(Drawable_t id, char **data,
292  Pixmap_t &pict, Pixmap_t &pict_mask,
293  PictureAttributes_t &attr);
294  Bool_t ReadPictureDataFromFile(const char *filename, char ***ret_data);
295  void DeletePictureData(void *data);
296  void SetDashes(GContext_t gc, Int_t offset, const char *dash_list, Int_t n);
297  Bool_t ParseColor(Colormap_t cmap, const char *cname, ColorStruct_t &color);
298  Bool_t AllocColor(Colormap_t cmap, ColorStruct_t &color);
299  void QueryColor(Colormap_t cmap, ColorStruct_t &color);
300  void FreeColor(Colormap_t cmap, ULong_t pixel);
301  Int_t EventsPending();
302  void NextEvent(Event_t &event);
303  void Bell(Int_t percent);
304  void CopyArea(Drawable_t src, Drawable_t dest, GContext_t gc,
305  Int_t src_x, Int_t src_y, UInt_t width, UInt_t height,
306  Int_t dest_x, Int_t dest_y);
307  void ChangeWindowAttributes(Window_t id, SetWindowAttributes_t *attr);
308  void ChangeProperty(Window_t id, Atom_t property, Atom_t type,
309  UChar_t *data, Int_t len);
310  void DrawLine(Drawable_t id, GContext_t gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
311  void ClearArea(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h);
312  Bool_t CheckEvent(Window_t id, EGEventType type, Event_t &ev);
313  void SendEvent(Window_t id, Event_t *ev);
314  void WMDeleteNotify(Window_t id);
315  void SetKeyAutoRepeat(Bool_t on = kTRUE);
316  void GrabKey(Window_t id, Int_t keycode, UInt_t modifier, Bool_t grab = kTRUE);
317  void GrabButton(Window_t id, EMouseButton button, UInt_t modifier,
318  UInt_t evmask, Window_t confine, Cursor_t cursor,
319  Bool_t grab = kTRUE);
320  void GrabPointer(Window_t id, UInt_t evmask, Window_t confine,
321  Cursor_t cursor, Bool_t grab = kTRUE,
322  Bool_t owner_events = kTRUE);
323  void SetWindowName(Window_t id, char *name);
324  void SetIconName(Window_t id, char *name);
325  void SetIconPixmap(Window_t id, Pixmap_t pic);
326  void SetClassHints(Window_t id, char *className, char *resourceName);
327  void SetMWMHints(Window_t id, UInt_t value, UInt_t funcs, UInt_t input);
328  void SetWMPosition(Window_t id, Int_t x, Int_t y);
329  void SetWMSize(Window_t id, UInt_t w, UInt_t h);
330  void SetWMSizeHints(Window_t id, UInt_t wmin, UInt_t hmin,
331  UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc);
332  void SetWMState(Window_t id, EInitialState state);
333  void SetWMTransientHint(Window_t id, Window_t main_id);
334  void DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y,
335  const char *s, Int_t len);
336  Int_t TextWidth(FontStruct_t font, const char *s, Int_t len);
337  void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent);
338  void GetGCValues(GContext_t gc, GCValues_t &gval);
339  FontStruct_t GetFontStruct(FontH_t fh);
340  void FreeFontStruct(FontStruct_t fs);
341  void ClearWindow(Window_t id);
342  Int_t KeysymToKeycode(UInt_t keysym);
343  void FillRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y,
344  UInt_t w, UInt_t h);
345  void DrawRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y,
346  UInt_t w, UInt_t h);
347  void DrawSegments(Drawable_t id, GContext_t gc, Segment_t *seg, Int_t nseg);
348  void SelectInput(Window_t id, UInt_t evmask);
349  Window_t GetInputFocus();
350  void SetInputFocus(Window_t id);
351  Window_t GetPrimarySelectionOwner();
352  void SetPrimarySelectionOwner(Window_t id);
353  void ConvertPrimarySelection(Window_t id, Atom_t clipboard, Time_t when);
354  void LookupString(Event_t *event, char *buf, Int_t buflen, UInt_t &keysym);
355  void GetPasteBuffer(Window_t id, Atom_t atom, TString &text,
356  Int_t &nchar, Bool_t del);
357  void TranslateCoordinates(Window_t src, Window_t dest, Int_t src_x,
358  Int_t src_y, Int_t &dest_x, Int_t &dest_y, Window_t &child);
359  void GetWindowSize(Drawable_t id, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h);
360  void FillPolygon(Window_t id, GContext_t gc, Point_t *points, Int_t npnt);
361  void QueryPointer(Window_t id, Window_t &rootw, Window_t &childw,
362  Int_t &root_x, Int_t &root_y, Int_t &win_x,
363  Int_t &win_y, UInt_t &mask);
364  void SetForeground(GContext_t gc, ULong_t foreground);
365  void SetClipRectangles(GContext_t gc, Int_t x, Int_t y, Rectangle_t *recs, Int_t n);
366  void Update(Int_t mode = 0);
367  Region_t CreateRegion();
368  void DestroyRegion(Region_t reg);
369  void UnionRectWithRegion(Rectangle_t *rect, Region_t src, Region_t dest);
370  Region_t PolygonRegion(Point_t *points, Int_t np, Bool_t winding);
371  void UnionRegion(Region_t rega, Region_t regb, Region_t result);
372  void IntersectRegion(Region_t rega, Region_t regb, Region_t result);
373  void SubtractRegion(Region_t rega, Region_t regb, Region_t result);
374  void XorRegion(Region_t rega, Region_t regb, Region_t result);
375  Bool_t EmptyRegion(Region_t reg);
376  Bool_t PointInRegion(Int_t x, Int_t y, Region_t reg);
377  Bool_t EqualRegion(Region_t rega, Region_t regb);
378  void GetRegionBox(Region_t reg, Rectangle_t *);
379  char **ListFonts(const char *fontname, Int_t max, Int_t &count);
380  void FreeFontNames(char **fontlist);
381  Drawable_t CreateImage(UInt_t width, UInt_t height);
382  void GetImageSize(Drawable_t id, UInt_t &width, UInt_t &height);
383  void PutPixel(Drawable_t id, Int_t x, Int_t y, ULong_t pixel);
384  void PutImage(Drawable_t id, GContext_t gc, Drawable_t img,
385  Int_t dx, Int_t dy, Int_t x, Int_t y,
386  UInt_t w, UInt_t h);
387  void DeleteImage(Drawable_t img);
388  void ShapeCombineMask(Window_t id, Int_t x, Int_t y, Pixmap_t mask);
389  UInt_t ScreenWidthMM() const;
390 
391  void DeleteProperty(Window_t, Atom_t&);
392  Int_t GetProperty(Window_t, Atom_t, Long_t, Long_t, Bool_t, Atom_t,
393  Atom_t*, Int_t*, ULong_t*, ULong_t*, unsigned char**);
394  void ChangeActivePointerGrab(Window_t, UInt_t, Cursor_t);
395  void ConvertSelection(Window_t, Atom_t&, Atom_t&, Atom_t&, Time_t&);
396  Bool_t SetSelectionOwner(Window_t, Atom_t&);
397  void ChangeProperties(Window_t id, Atom_t property, Atom_t type,
398  Int_t format, UChar_t *data, Int_t len);
399  void SetDNDAware(Window_t, Atom_t *);
400  void SetTypeList(Window_t win, Atom_t prop, Atom_t *typelist);
401  Window_t FindRWindow(Window_t win, Window_t dragwin, Window_t input, int x, int y, int maxd);
402  Bool_t IsDNDAware(Window_t win, Atom_t *typelist);
403 
404  ClassDef(TGX11,0) //Interface to X11
405 };
406 
407 #endif