Logo ROOT   master
Reference Guide
TGClient.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 27/12/97
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 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGClient //
26 // //
27 // Window client. In client server windowing systems, like X11 this //
28 // class is used to make the initial connection to the window server. //
29 // //
30 //////////////////////////////////////////////////////////////////////////
31 
32 #include "RConfigure.h"
33 
34 #include "TGClient.h"
35 #include "TROOT.h"
36 #include "TApplication.h"
37 #include "TSystem.h"
38 #include "TEnv.h"
39 #include "THashList.h"
40 #include "TSysEvtHandler.h"
41 #include "TVirtualX.h"
42 #include "TGWindow.h"
43 #include "TGResourcePool.h"
44 #include "TGGC.h"
45 #include "TGFont.h"
46 #include "TGMimeTypes.h"
47 #include "TGFrame.h"
48 #include "TGIdleHandler.h"
49 #include "TError.h"
50 #include "TGlobal.h"
51 
52 // Global pointer to the TGClient object
53 static TGClient *gClientGlobal = nullptr;
54 
55 namespace {
56 static struct AddPseudoGlobals {
57 AddPseudoGlobals() {
58  // User "gCling" as synonym for "libCore static initialization has happened".
59  // This code here must not trigger it
60  TGlobalMappedFunction::MakeFunctor("gClient", "TGClient*", TGClient::Instance, [] {
61  TGClient::Instance(); // first ensure object is created;
62  return (void *) &gClientGlobal;
63  });
64 }
65 } gAddPseudoGlobals;
66 }
67 
68 // Initialize gClient in case libGui is loaded in batch mode
70 class TGClientInit {
71 public:
72  TGClientInit() {
73  TROOT *rootlocal = ROOT::Internal::gROOTLocal;
74  if (rootlocal && rootlocal->IsBatch()) {
75  // For now check if the heaeder files (or the module containing them)
76  // has been loaded in Cling.
77  // This is required because the dictionaries must be initialized
78  // __before__ the TGClient creation which will induce the creation
79  // of a TClass object which will need the dictionary for TGClient!
81  new TGClient();
82  }
84  }
85 };
86 static TGClientInit gClientInit;
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Returns global gClient (initialize graphics first, if not already done)
90 
92 {
95  return gClientGlobal;
96 }
97 
98 //----- Graphics Input handler -------------------------------------------------
99 ////////////////////////////////////////////////////////////////////////////////
100 
101 class TGInputHandler : public TFileHandler {
102 private:
103  TGClient *fClient; // connection to display server
104 public:
105  TGInputHandler(TGClient *c, Int_t fd) : TFileHandler(fd, 1) { fClient = c; }
106  Bool_t Notify();
107  // Important: don't override ReadNotify()
108 };
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Notify input from the display server.
112 
113 Bool_t TGInputHandler::Notify()
114 {
115  return fClient->HandleInput();
116 }
117 
118 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Create a connection with the display sever on host dpyName and setup
123 /// the complete GUI system, i.e., graphics contexts, fonts, etc. for all
124 /// widgets.
125 
126 TGClient::TGClient(const char *dpyName)
127 {
128  fRoot = 0;
129  fPicturePool = 0;
130  fMimeTypeList = 0;
131  fWlist = 0;
132  fPlist = 0;
133  fUWHandlers = 0;
134  fIdleHandlers = 0;
135 
136  if (gClientGlobal) {
137  Error("TGClient", "only one instance of TGClient allowed");
138  MakeZombie();
139  return;
140  }
141 
142  // Set DISPLAY based on utmp (only if DISPLAY is not yet set).
143  gSystem->SetDisplay();
144 
145  // Open the connection to the display
146  if ((fXfd = gVirtualX->OpenDisplay(dpyName)) < 0) {
147  Error("TGClient", "can't open display \"%s\", switching to batch mode...\n In case you run from a remote ssh session, reconnect with ssh -Y",
148  gVirtualX->DisplayName(dpyName));
149  MakeZombie();
150  return;
151  }
152 
153  if (fXfd >= 0 && !ROOT::Internal::gROOTLocal->IsBatch()) {
154  TGInputHandler *xi = new TGInputHandler(this, fXfd);
155  if (fXfd) gSystem->AddFileHandler(xi);
156  // X11 events are handled via gXDisplay->Notify() in
157  // TUnixSystem::DispatchOneEvent(). When no events available we wait for
158  // events on all TFileHandlers including this one via a select() call.
159  // However, X11 events are always handled via gXDisplay->Notify() and not
160  // via the ReadNotify() (therefore TGInputHandler should not override
161  // TFileHandler::ReadNotify()).
162  gXDisplay = xi;
163  }
164 
165  // Initialize internal window list. Use a THashList for fast
166  // finding of windows based on window id (see GetWindowById()).
167 
168  fWlist = new THashList(200);
169  fPlist = new TList;
170 
171  // Create root window
172 
173  fDefaultRoot = fRoot = new TGFrame(this, gVirtualX->GetDefaultRootWindow());
174 
175  // Setup some atoms (defined in TVirtualX)...
176 
177  gWM_DELETE_WINDOW = gVirtualX->InternAtom("WM_DELETE_WINDOW", kFALSE);
178  gMOTIF_WM_HINTS = gVirtualX->InternAtom("_MOTIF_WM_HINTS", kFALSE);
179  gROOT_MESSAGE = gVirtualX->InternAtom("_ROOT_MESSAGE", kFALSE);
180 
181  // Create the graphics event handler, an object for the root window,
182  // a picture pool, mimetype list, etc...
183 
188 
189  fResourcePool = new TGResourcePool(this);
190 
194 
197 
198  // Set some color defaults...
199 
208 
209  fStyle = 0;
210  TString style = gEnv->GetValue("Gui.Style", "modern");
211  if (style.Contains("flat", TString::kIgnoreCase))
212  fStyle = 2;
213  else if (style.Contains("modern", TString::kIgnoreCase))
214  fStyle = 1;
215 
216  gClientGlobal = this;
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Returns current root (i.e. base) window. By changing the root
221 /// window one can change the window hierarchy, e.g. a top level
222 /// frame (TGMainFrame) can be embedded in another window.
223 
225 {
226  return fRoot;
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Returns the root (i.e. desktop) window. Should only be used as parent
231 /// for frames that will never be embedded, like popups, message boxes,
232 /// etc. (like TGToolTips, TGMessageBox, etc.).
233 
235 {
236  return fDefaultRoot;
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Sets the current root (i.e. base) window. By changing the root
241 /// window one can change the window hierarchy, e.g. a top level
242 /// frame (TGMainFrame) can be embedded in another window.
243 
245 {
246  fRoot = root ? root : fDefaultRoot;
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 /// Set the button style (modern or classic).
251 
252 void TGClient::SetStyle(const char *style)
253 {
254  fStyle = 0;
255  if (style && strstr(style, "modern"))
256  fStyle = 1;
257 }
258 
259 ////////////////////////////////////////////////////////////////////////////////
260 /// Get display width.
261 
263 {
264  Int_t x, y;
265  UInt_t w, h;
266 
267  gVirtualX->GetGeometry(-1, x, y, w, h);
268 
269  return w;
270 }
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 /// Get display height.
274 
276 {
277  Int_t x, y;
278  UInt_t w, h;
279 
280  gVirtualX->GetGeometry(-1, x, y, w, h);
281 
282  return h;
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// Get picture from the picture pool. Picture must be freed using
287 /// TGClient::FreePicture(). If picture is not found 0 is returned.
288 
290 {
291  return fPicturePool->GetPicture(name);
292 }
293 
294 ////////////////////////////////////////////////////////////////////////////////
295 /// Get picture with specified size from pool (picture will be scaled if
296 /// necessary). Picture must be freed using TGClient::FreePicture(). If
297 /// picture is not found 0 is returned.
298 
300  UInt_t new_width, UInt_t new_height)
301 {
302  return fPicturePool->GetPicture(name, new_width, new_height);
303 }
304 
305 ////////////////////////////////////////////////////////////////////////////////
306 /// Free picture resource.
307 
309 {
310  if (pic) fPicturePool->FreePicture(pic);
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Get graphics context from the gc pool. Context must be freed via
315 /// TGClient::FreeGC(). If rw is true a new read/write-able GC
316 /// is returned, otherwise a shared read-only context is returned.
317 /// For historical reasons it is also possible to create directly a
318 /// TGGC object, but it is advised to use this new interface only.
319 
321 {
322  return fGCPool->GetGC(values, rw);
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Free a graphics context.
327 
328 void TGClient::FreeGC(const TGGC *gc)
329 {
330  fGCPool->FreeGC(gc);
331 }
332 
333 ////////////////////////////////////////////////////////////////////////////////
334 /// Free a graphics context.
335 
337 {
338  fGCPool->FreeGC(gc);
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Get a font from the font pool. Fonts must be freed via
343 /// TGClient::FreeFont(). Returns 0 in case of error or if font
344 /// does not exist. If fixedDefault is false the "fixed" font
345 /// will not be substituted as fallback when the asked for font
346 /// does not exist.
347 
348 TGFont *TGClient::GetFont(const char *font, Bool_t fixedDefault)
349 {
350  return fFontPool->GetFont(font, fixedDefault);
351 }
352 
353 ////////////////////////////////////////////////////////////////////////////////
354 /// Get again specified font. Will increase its usage count.
355 
357 {
358  return fFontPool->GetFont(font);
359 }
360 
361 ////////////////////////////////////////////////////////////////////////////////
362 /// Free a font.
363 
364 void TGClient::FreeFont(const TGFont *font)
365 {
366  fFontPool->FreeFont(font);
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 /// Set redraw flags.
371 
373 {
374  if (gVirtualX->NeedRedraw((ULong_t)w,force)) return;
375  if (force) {
376  w->DoRedraw();
377  return;
378  }
379  w->fNeedRedraw = kTRUE;
381 }
382 
383 ////////////////////////////////////////////////////////////////////////////////
384 
386 {
387  w->fNeedRedraw = kFALSE;
388 }
389 
390 ////////////////////////////////////////////////////////////////////////////////
391 /// Get a color by name. If color is found return kTRUE and pixel is
392 /// set to the color's pixel value, kFALSE otherwise.
393 
394 Bool_t TGClient::GetColorByName(const char *name, Pixel_t &pixel) const
395 {
396  ColorStruct_t color;
397  WindowAttributes_t attributes = WindowAttributes_t();
398  Bool_t status = kTRUE;
399 
400  gVirtualX->GetWindowAttributes(fRoot->GetId(), attributes);
401  color.fPixel = 0;
402  if (!gVirtualX->ParseColor(attributes.fColormap, name, color)) {
403  Error("GetColorByName", "couldn't parse color %s", name);
404  status = kFALSE;
405  } else if (!gVirtualX->AllocColor(attributes.fColormap, color)) {
406  Warning("GetColorByName", "couldn't retrieve color %s.\n"
407  "Please close any other application, like netscape, "
408  "that might exhaust\nthe colormap and start ROOT again", name);
409  status = kFALSE;
410  }
411 
412  pixel = color.fPixel;
413 
414  return status;
415 }
416 
417 ////////////////////////////////////////////////////////////////////////////////
418 /// Get a font by name. If font is not found, fixed font is returned,
419 /// if fixed font also does not exist return 0 and print error.
420 /// The loaded font needs to be freed using TVirtualX::DeleteFont().
421 /// If fixedDefault is false the "fixed" font will not be substituted
422 /// as fallback when the asked for font does not exist.
423 
424 FontStruct_t TGClient::GetFontByName(const char *name, Bool_t fixedDefault) const
425 {
426  if (gROOT->IsBatch())
427  return (FontStruct_t) -1;
428 
429  FontStruct_t font = gVirtualX->LoadQueryFont(name);
430 
431  if (!font && fixedDefault) {
432  font = gVirtualX->LoadQueryFont("fixed");
433  if (font)
434  Warning("GetFontByName", "couldn't retrieve font %s, using \"fixed\"", name);
435  }
436  if (!font) {
437  if (fixedDefault)
438  Error("GetFontByName", "couldn't retrieve font %s nor backup font \"fixed\"", name);
439  else
440  Warning("GetFontByName", "couldn't retrieve font %s", name);
441  }
442 
443  return font;
444 }
445 
446 ////////////////////////////////////////////////////////////////////////////////
447 /// Return pixel value of hilite color based on base_color.
448 
450 {
451  ColorStruct_t color, white_p;
452  WindowAttributes_t attributes = WindowAttributes_t();
453 
454  gVirtualX->GetWindowAttributes(fRoot->GetId(), attributes);
455 
456  color.fPixel = base_color;
457  gVirtualX->QueryColor(attributes.fColormap, color);
458 
459  GetColorByName("white", white_p.fPixel);
460  gVirtualX->QueryColor(attributes.fColormap, white_p);
461 
462  color.fRed = TMath::Max((UShort_t)(white_p.fRed/5), color.fRed);
463  color.fGreen = TMath::Max((UShort_t)(white_p.fGreen/5), color.fGreen);
464  color.fBlue = TMath::Max((UShort_t)(white_p.fBlue/5), color.fBlue);
465 
466  color.fRed = (UShort_t)TMath::Min((Int_t)white_p.fRed, (Int_t)(color.fRed*140)/100);
467  color.fGreen = (UShort_t)TMath::Min((Int_t)white_p.fGreen, (Int_t)(color.fGreen*140)/100);
468  color.fBlue = (UShort_t)TMath::Min((Int_t)white_p.fBlue, (Int_t)(color.fBlue*140)/100);
469 
470  if (!gVirtualX->AllocColor(attributes.fColormap, color))
471  Error("GetHilite", "couldn't allocate hilight color");
472 
473  return color.fPixel;
474 }
475 
476 ////////////////////////////////////////////////////////////////////////////////
477 /// Return pixel value of shadow color based on base_color.
478 /// Shadow is 60% of base_color intensity.
479 
481 {
482  ColorStruct_t color;
483  WindowAttributes_t attributes = WindowAttributes_t();
484 
485  gVirtualX->GetWindowAttributes(fRoot->GetId(), attributes);
486 
487  color.fPixel = base_color;
488  gVirtualX->QueryColor(attributes.fColormap, color);
489 
490  color.fRed = (UShort_t)((color.fRed*60)/100);
491  color.fGreen = (UShort_t)((color.fGreen*60)/100);
492  color.fBlue = (UShort_t)((color.fBlue*60)/100);
493 
494  if (!gVirtualX->AllocColor(attributes.fColormap, color))
495  Error("GetShadow", "couldn't allocate shadow color");
496 
497  return color.fPixel;
498 }
499 
500 ////////////////////////////////////////////////////////////////////////////////
501 /// Free color.
502 
503 void TGClient::FreeColor(Pixel_t color) const
504 {
505  gVirtualX->FreeColor(fDefaultColormap, color);
506 }
507 
508 ////////////////////////////////////////////////////////////////////////////////
509 /// Add a TGWindow to the clients list of windows.
510 
512 {
513  fWlist->Add(w);
514 
515  // Emits signal
516  RegisteredWindow(w->GetId());
517 }
518 
519 ////////////////////////////////////////////////////////////////////////////////
520 /// Remove a TGWindow from the list of windows.
521 
523 {
524  fWlist->Remove(w);
525 }
526 
527 ////////////////////////////////////////////////////////////////////////////////
528 /// Add a popup menu to the list of popups. This list is used to pass
529 /// events to popup menus that are popped up over a transient window which
530 /// is waited for (see WaitFor()).
531 
533 {
534  fPlist->Add(w);
535 
536  // Emits signal
537  RegisteredWindow(w->GetId());
538 }
539 
540 ////////////////////////////////////////////////////////////////////////////////
541 /// Remove a popup menu from the list of popups.
542 
544 {
545  fPlist->Remove(w);
546 }
547 
548 ////////////////////////////////////////////////////////////////////////////////
549 /// Add handler for unknown (i.e. unregistered) windows.
550 
552 {
553  if (!fUWHandlers) {
554  fUWHandlers = new TList;
556  }
557 
558  fUWHandlers->Add(h);
559 }
560 
561 ////////////////////////////////////////////////////////////////////////////////
562 /// Remove handler for unknown (i.e. unregistered) windows.
563 
565 {
566  fUWHandlers->Remove(h);
567 }
568 
569 ////////////////////////////////////////////////////////////////////////////////
570 /// Add handler for idle events.
571 
573 {
574  if (!fIdleHandlers) {
575  fIdleHandlers = new TList;
577  }
578 
579  fIdleHandlers->Add(h);
580 }
581 
582 ////////////////////////////////////////////////////////////////////////////////
583 /// Remove handler for idle events.
584 
586 {
588 }
589 
590 ////////////////////////////////////////////////////////////////////////////////
591 /// Find a TGWindow via its handle. If window is not found return 0.
592 
594 {
595  TGWindow wt(wid);
596 
597  return (TGWindow *) fWlist->FindObject(&wt);
598 }
599 
600 ////////////////////////////////////////////////////////////////////////////////
601 /// Find a TGWindow via its name (unique name used in TGWindow::SavePrimitive).
602 /// If window is not found return 0.
603 
605 {
606  TIter next(fWlist);
607 
608  TObject *obj;
609  while ((obj = next())) {
610  TString n = obj->GetName();
611  if (n == name) {
612  return (TGWindow*)obj;
613  }
614  }
615  return 0;
616 }
617 
618 ////////////////////////////////////////////////////////////////////////////////
619 /// Closing down client: cleanup and close X connection.
620 
622 {
623  if (IsZombie())
624  return;
625 
626  if (fWlist)
627  fWlist->Delete("slow");
628  delete fWlist;
629  delete fPlist;
630  delete fUWHandlers;
631  delete fIdleHandlers;
632  delete fResourcePool;
633 
634  gVirtualX->CloseDisplay(); // this should do a cleanup of the remaining
635  // X allocated objects...
636 }
637 
638 ////////////////////////////////////////////////////////////////////////////////
639 /// Process one event. This method should only be called when there is
640 /// a GUI event ready to be processed. If event has been processed
641 /// kTRUE is returned. If processing of a specific event type for a specific
642 /// window was requested kFALSE is returned when specific event has been
643 /// processed, kTRUE otherwise. If no more pending events return kFALSE.
644 
646 {
647  Event_t event;
648 
649  if (!fRoot) return kFALSE;
650  if (gVirtualX->EventsPending()) {
651  gVirtualX->NextEvent(event);
652  if (fWaitForWindow == kNone) {
653  HandleEvent(&event);
654  if (fForceRedraw)
655  DoRedraw();
656  return kTRUE;
657  } else {
659  if ((event.fType == fWaitForEvent) && (event.fWindow == fWaitForWindow))
661  if (fForceRedraw)
662  DoRedraw();
663  return kTRUE;
664  }
665  }
666 
667  // if nothing else to do redraw windows that need redrawing
668  if (DoRedraw()) return kTRUE;
669 
670  // process one idle event if there is nothing else to do
671  if (ProcessIdleEvent()) return kTRUE;
672 
673  return kFALSE;
674 }
675 
676 ////////////////////////////////////////////////////////////////////////////////
677 /// Process one idle event.
678 
680 {
681  if (fIdleHandlers) {
683  if (ih) {
684  RemoveIdleHandler(ih);
685  ih->HandleEvent();
686  return kTRUE;
687  }
688  }
689  return kFALSE;
690 }
691 
692 ////////////////////////////////////////////////////////////////////////////////
693 /// Handles input from the display server. Returns kTRUE if one or more
694 /// events have been processed, kFALSE otherwise.
695 
697 {
698  Bool_t handledevent = kFALSE;
699 
700  while (ProcessOneEvent())
701  handledevent = kTRUE;
702  return handledevent;
703 }
704 
705 ////////////////////////////////////////////////////////////////////////////////
706 /// Wait for window to be destroyed.
707 
709 {
710  Window_t wsave = fWaitForWindow;
711  EGEventType esave = fWaitForEvent;
712 
713  fWaitForWindow = w->GetId();
715 
716  //Let VirtualX know, that we are
717  //in a nested loop for a window w.
718  //Noop on X11/win32gdk.
719  if (gVirtualX)
720  gVirtualX->BeginModalSessionFor(w->GetId());
721 
722  while (fWaitForWindow != kNone) {
723  if (esave == kUnmapNotify)
724  wsave = kNone;
725  gSystem->ProcessEvents();//gSystem->InnerLoop();
726  gSystem->Sleep(5);
727  }
728 
729  fWaitForWindow = wsave;
730  fWaitForEvent = esave;
731 }
732 
733 ////////////////////////////////////////////////////////////////////////////////
734 /// Wait for window to be unmapped.
735 
737 {
738  Window_t wsave = fWaitForWindow;
739  EGEventType esave = fWaitForEvent;
740 
741  fWaitForWindow = w->GetId();
743 
744  //Let VirtualX know, that we are
745  //in a nested loop for a window w.
746  //Noop on X11/win32gdk.
747  if (gVirtualX)
748  gVirtualX->BeginModalSessionFor(w->GetId());
749 
750  while (fWaitForWindow != kNone) {
751  gSystem->ProcessEvents();//gSystem->InnerLoop();
752  gSystem->Sleep(5);
753  }
754 
755  fWaitForWindow = wsave;
756  fWaitForEvent = esave;
757 }
758 
759 ////////////////////////////////////////////////////////////////////////////////
760 /// reset waiting
761 
763 {
764  if (fWaitForWindow == w->GetId()) fWaitForWindow = kNone;
765 }
766 
767 ////////////////////////////////////////////////////////////////////////////////
768 /// Like gSystem->ProcessEvents() but then only allow events for w to
769 /// be processed. For example to interrupt the processing and destroy
770 /// the window, call gROOT->SetInterrupt() before destroying the window.
771 
773 {
774  Window_t wsave = fWaitForWindow;
775  EGEventType esave = fWaitForEvent;
776 
777  fWaitForWindow = w->GetId();
779 
780  Bool_t intr = gSystem->ProcessEvents();
781 
782  fWaitForWindow = wsave;
783  fWaitForEvent = esave;
784 
785  return intr;
786 }
787 
788 ////////////////////////////////////////////////////////////////////////////////
789 /// Redraw all windows that need redrawing. Returns kFALSE if no redraw
790 /// was needed, kTRUE otherwise.
791 /// Only redraw the application's windows when the event queue
792 /// does not contain expose event anymore.
793 
795 {
796  if (!fGlobalNeedRedraw) return kFALSE;
797 
798  TGWindow *w;
799  TObjLink *lnk = fWlist->FirstLink();
800  while (lnk) {
801  w = (TGWindow *) lnk->GetObject();
802  if (w->fNeedRedraw) {
803  w->DoRedraw();
804  w->fNeedRedraw = kFALSE;
805  }
806  lnk = lnk->Next();
807  }
808 
811 
812  return kTRUE;
813 }
814 
815 ////////////////////////////////////////////////////////////////////////////////
816 /// Handle a GUI event.
817 
819 {
820  TGWindow *w;
821 
822  // Emit signal for event recorder(s)
823  if (event->fType != kConfigureNotify) {
824  ProcessedEvent(event, 0);
825  }
826 
827  // Find window where event happened
828  if ((w = GetWindowById(event->fWindow)) == 0) {
829  if (fUWHandlers && fUWHandlers->GetSize() > 0) {
830  TGUnknownWindowHandler *unkwh;
832  while ((unkwh = (TGUnknownWindowHandler*)it.Next())) {
833  if (unkwh->HandleEvent(event))
834  return kTRUE;
835  }
836  }
837  //Warning("HandleEvent", "unknown window %ld not handled\n",
838  // event->fWindow);
839  return kFALSE;
840  }
841 
842  // and let it handle the event
843  w->HandleEvent(event);
844 
845  return kTRUE;
846 }
847 
848 ////////////////////////////////////////////////////////////////////////////////
849 /// Handle masked events only if window wid is the window for which the
850 /// event was reported or if wid is a parent of the event window. The not
851 /// masked event are handled directly. The masked events are:
852 /// kButtonPress, kButtonRelease, kKeyPress, kKeyRelease, kEnterNotify,
853 /// kLeaveNotify, kMotionNotify.
854 
856 {
857  TGWindow *w, *ptr, *pop;
858 
859  if ((w = GetWindowById(event->fWindow)) == 0) return kFALSE;
860 
861  // Emit signal for event recorder(s)
862  if (event->fType != kConfigureNotify) {
863  ProcessedEvent(event, wid);
864  }
865 
866  // This breaks class member protection, but TGClient is a friend of
867  // TGWindow and _should_ know what to do and what *not* to do...
868 
869  for (ptr = w; ptr->fParent != 0; ptr = (TGWindow *) ptr->fParent) {
870  if ((ptr->fId == wid) ||
871  ((event->fType != kButtonPress) &&
872  (event->fType != kButtonRelease) &&
873  (event->fType != kGKeyPress) &&
874  (event->fType != kKeyRelease) &&
875  (event->fType != kEnterNotify) &&
876  (event->fType != kLeaveNotify) &&
877  (event->fType != kMotionNotify))) {
878  w->HandleEvent(event);
879  return kTRUE;
880  }
881  }
882 
883  // check if this is a popup menu
884  TIter next(fPlist);
885  while ((pop = (TGWindow *) next())) {
886  for (ptr = w; ptr->fParent != 0; ptr = (TGWindow *) ptr->fParent) {
887  if ((ptr->fId == pop->fId) &&
888  ((event->fType == kButtonPress) ||
889  (event->fType == kButtonRelease) ||
890  (event->fType == kGKeyPress) ||
891  (event->fType == kKeyRelease) ||
892  (event->fType == kEnterNotify) ||
893  (event->fType == kLeaveNotify) ||
894  (event->fType == kMotionNotify))) {
895  w->HandleEvent(event);
896  return kTRUE;
897  }
898  }
899  }
900 
901  if (event->fType == kButtonPress || event->fType == kGKeyPress)
902  gVirtualX->Bell(0);
903 
904  return kFALSE;
905 }
906 
907 ////////////////////////////////////////////////////////////////////////////////
908 /// Execute string "cmd" via the interpreter. Before executing replace
909 /// in the command string the token $MSG, $PARM1 and $PARM2 by msg,
910 /// parm1 and parm2, respectively. The function in cmd string must accept
911 /// these as longs.
912 
913 void TGClient::ProcessLine(TString cmd, Long_t msg, Long_t parm1, Long_t parm2)
914 {
915  if (cmd.IsNull()) return;
916 
917  char s[32];
918 
919  snprintf(s, sizeof(s), "%ld", msg);
920  cmd.ReplaceAll("$MSG", s);
921 
922  snprintf(s, sizeof(s), "%ld", parm1);
923  cmd.ReplaceAll("$PARM1", s);
924 
925  snprintf(s, sizeof(s), "%ld", parm2);
926  cmd.ReplaceAll("$PARM2", s);
927 
928  gROOT->ProcessLine(cmd.Data());
929 }
930 
931 ////////////////////////////////////////////////////////////////////////////////
932 /// Returns kTRUE if edit/guibuilding is forbidden.
933 
935 {
936  return (fDefaultRoot->GetEditDisabled() == 1);
937 }
938 
939 ////////////////////////////////////////////////////////////////////////////////
940 /// If on is kTRUE editting/guibuilding is forbidden.
941 
943 {
945 }
946 
947 ////////////////////////////////////////////////////////////////////////////////
948 /// Emits a signal when an event has been processed.
949 /// Used in TRecorder.
950 
952 {
953  Long_t args[2];
954  args[0] = (Long_t) event;
955  args[1] = (Long_t) wid;
956 
957  Emit("ProcessedEvent(Event_t*, Window_t)", args);
958 }
959 
960 ////////////////////////////////////////////////////////////////////////////////
961 /// Emits a signal when a Window has been registered in TGClient.
962 /// Used in TRecorder.
963 
965 {
966  Emit("RegisteredWindow(Window_t)", w);
967 }
UShort_t fBlue
Definition: GuiTypes.h:313
void ProcessedEvent(Event_t *event, Window_t wid)
Emits a signal when an event has been processed.
Definition: TGClient.cxx:951
Pixel_t fHilite
Definition: TGClient.h:53
Pixel_t fBlack
Definition: TGClient.h:58
Bool_t IsEditDisabled() const
Returns kTRUE if edit/guibuilding is forbidden.
Definition: TGClient.cxx:934
Handle_t FontStruct_t
Definition: GuiTypes.h:38
const TGWindow * fParent
Definition: TGWindow.h:36
virtual UInt_t GetEditDisabled() const
Definition: TGWindow.h:113
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:410
Bool_t HandleEvent(Event_t *event)
Handle a GUI event.
Definition: TGClient.cxx:818
ROOT top level object description.
Definition: TROOT.h:102
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
TGPicturePool * fPicturePool
Definition: TGClient.h:65
void SetRoot(TGWindow *root=0)
Sets the current root (i.e.
Definition: TGClient.cxx:244
virtual ~TGClient()
Closing down client: cleanup and close X connection.
Definition: TGClient.cxx:621
THashList * fWlist
Definition: TGClient.h:70
TGFontPool * GetFontPool() const
void RemoveIdleHandler(TGIdleHandler *h)
Remove handler for idle events.
Definition: TGClient.cxx:585
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition: TGClient.cxx:224
void FreeColor(Pixel_t color) const
Free color.
Definition: TGClient.cxx:503
Pixel_t GetFrameBgndColor() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
unsigned short UShort_t
Definition: RtypesCore.h:36
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void TriggerDictionaryInitialization_libGui()
Bool_t fNeedRedraw
Definition: TGWindow.h:37
TGWindow * fRoot
Definition: TGClient.h:60
EGEventType
Definition: GuiTypes.h:58
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition: TGClient.cxx:480
void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: THashList.cxx:207
#define gROOT
Definition: TROOT.h:415
Handle_t GContext_t
Definition: GuiTypes.h:37
virtual Bool_t HandleEvent()
Handle the idle event.
R__EXTERN Atom_t gWM_DELETE_WINDOW
Definition: TVirtualX.h:38
Basic string class.
Definition: TString.h:131
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
int Int_t
Definition: RtypesCore.h:41
Pixel_t fBackColor
Definition: TGClient.h:51
bool Bool_t
Definition: RtypesCore.h:59
Bool_t GetColorByName(const char *name, Pixel_t &pixel) const
Get a color by name.
Definition: TGClient.cxx:394
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
Definition: TList.cxx:1110
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
static TGClientInit gClientInit
Definition: TGClient.cxx:86
Window_t fWindow
Definition: GuiTypes.h:175
void WaitForUnmap(TGWindow *w)
Wait for window to be unmapped.
Definition: TGClient.cxx:736
void CancelRedraw(TGWindow *w)
Definition: TGClient.cxx:385
Handle_t GetId() const
Definition: TGObject.h:47
void UnregisterWindow(TGWindow *w)
Remove a TGWindow from the list of windows.
Definition: TGClient.cxx:522
Iterator of linked list.
Definition: TList.h:197
Bool_t ProcessIdleEvent()
Process one idle event.
Definition: TGClient.cxx:679
UShort_t fRed
Definition: GuiTypes.h:311
UInt_t GetDisplayWidth() const
Get display width.
Definition: TGClient.cxx:262
TGWindow * fDefaultRoot
Definition: TGClient.h:59
void RegisterPopup(TGWindow *w)
Add a popup menu to the list of popups.
Definition: TGClient.cxx:532
TGWindow * GetWindowByName(const char *name) const
Find a TGWindow via its name (unique name used in TGWindow::SavePrimitive).
Definition: TGClient.cxx:604
Double_t x[n]
Definition: legend1.C:17
TGClient(const TGClient &)
ULong_t Pixel_t
Definition: GuiTypes.h:39
Pixel_t fSelForeColor
Definition: TGClient.h:56
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:431
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
Pixel_t GetFrameFgndColor() const
void RegisterWindow(TGWindow *w)
Add a TGWindow to the clients list of windows.
Definition: TGClient.cxx:511
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:308
void ProcessLine(TString cmd, Long_t msg, Long_t parm1, Long_t parm2)
Execute string "cmd" via the interpreter.
Definition: TGClient.cxx:913
Pixel_t GetSelectedFgndColor() const
R__EXTERN TFileHandler * gXDisplay
Definition: TSystem.h:558
Colormap_t fColormap
Definition: GuiTypes.h:127
Pixel_t GetBlackColor() const
void SetStyle(UInt_t newstyle)
Definition: TGClient.h:151
virtual Bool_t HandleEvent(Event_t *)=0
Pixel_t fSelBackColor
Definition: TGClient.h:55
virtual void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
Definition: TSystem.cxx:225
TGPicturePool * GetPicturePool() const
void FreePicture(const TGPicture *pic)
Remove picture from cache if nobody is using it anymore.
Definition: TGPicture.cxx:275
TList * fIdleHandlers
Definition: TGClient.h:73
Bool_t DoRedraw()
Redraw all windows that need redrawing.
Definition: TGClient.cxx:794
void FreeGC(const TGGC *gc)
Free a graphics context.
Definition: TGClient.cxx:328
static constexpr double s
void RegisteredWindow(Window_t w)
Emits a signal when a Window has been registered in TGClient.
Definition: TGClient.cxx:964
Bool_t fForceRedraw
Definition: TGClient.h:69
Pixel_t fForeColor
Definition: TGClient.h:52
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:134
void WaitFor(TGWindow *w)
Wait for window to be destroyed.
Definition: TGClient.cxx:708
A doubly linked list.
Definition: TList.h:44
UShort_t fGreen
Definition: GuiTypes.h:312
TGMimeTypes * GetMimeTypes() const
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:388
void FreeFont(const TGFont *font)
Free a font.
Definition: TGClient.cxx:364
Pixel_t GetSelectedBgndColor() const
TGResourcePool * fResourcePool
Definition: TGClient.h:62
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:656
static void NeedGraphicsLibs()
Static method.
void FreeFont(const TGFont *font)
Free font. If ref count is 0 delete font.
Definition: TGFont.cxx:1703
R__EXTERN TSystem * gSystem
Definition: TSystem.h:557
Bool_t HandleMaskEvent(Event_t *event, Window_t wid)
Handle masked events only if window wid is the window for which the event was reported or if wid is a...
Definition: TGClient.cxx:855
EGEventType fType
Definition: GuiTypes.h:174
static TGClient * gClientGlobal
Definition: TGClient.cxx:53
void RemoveUnknownWindowHandler(TGUnknownWindowHandler *h)
Remove handler for unknown (i.e. unregistered) windows.
Definition: TGClient.cxx:564
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
void AddUnknownWindowHandler(TGUnknownWindowHandler *h)
Add handler for unknown (i.e. unregistered) windows.
Definition: TGClient.cxx:551
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:378
Bool_t ProcessOneEvent()
Process one event.
Definition: TGClient.cxx:645
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:887
const Handle_t kNone
Definition: GuiTypes.h:87
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
Bool_t fGlobalNeedRedraw
Definition: TGClient.h:68
virtual void DoRedraw()
Definition: TGWindow.h:53
static TGClient * Instance()
Returns global gClient (initialize graphics first, if not already done)
Definition: TGClient.cxx:91
Bool_t HandleInput()
Handles input from the display server.
Definition: TGClient.cxx:696
ULong_t fPixel
Definition: GuiTypes.h:310
#define gVirtualX
Definition: TVirtualX.h:338
virtual TObjLink * FirstLink() const
Definition: TList.h:108
#define h(i)
Definition: RSha256.hxx:106
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get graphics context from the gc pool.
Definition: TGClient.cxx:320
const Bool_t kFALSE
Definition: RtypesCore.h:88
void InitializeGraphics()
Initialize the graphics environment.
long Long_t
Definition: RtypesCore.h:50
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
Definition: TGFont.cxx:1543
Pixel_t fWhite
Definition: TGClient.h:57
TGMimeTypes * fMimeTypeList
Definition: TGClient.h:66
Pixel_t GetHilite(Pixel_t base_color) const
Return pixel value of hilite color based on base_color.
Definition: TGClient.cxx:449
void ResetWaitFor(TGWindow *w)
reset waiting
Definition: TGClient.cxx:762
TList * fUWHandlers
Definition: TGClient.h:72
#define ClassImp(name)
Definition: Rtypes.h:365
virtual Bool_t HandleEvent(Event_t *)
Definition: TGWindow.h:104
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:289
Int_t fXfd
Definition: TGClient.h:61
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
Definition: TGFont.h:149
unsigned long ULong_t
Definition: RtypesCore.h:51
TCanvas * style()
Definition: style.C:1
Double_t y[n]
Definition: legend1.C:17
UInt_t GetDisplayHeight() const
Get display height.
Definition: TGClient.cxx:275
Bool_t IsNull() const
Definition: TString.h:402
Handle_t fId
Definition: TGObject.h:36
void AddIdleHandler(TGIdleHandler *h)
Add handler for idle events.
Definition: TGClient.cxx:572
Mother of all ROOT objects.
Definition: TObject.h:37
FontStruct_t GetFontByName(const char *name, Bool_t fixedDefault=kTRUE) const
Get a font by name.
Definition: TGClient.cxx:424
R__EXTERN Atom_t gMOTIF_WM_HINTS
Definition: TVirtualX.h:39
TGGCPool * GetGCPool() const
Bool_t IsBatch() const
Definition: TROOT.h:289
Handle_t Window_t
Definition: GuiTypes.h:28
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition: TGWindow.h:114
TGFontPool * fFontPool
Definition: TGClient.h:64
virtual void Add(TObject *obj)
Definition: TList.h:87
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
void MakeZombie()
Definition: TObject.h:49
Bool_t ProcessEventsFor(TGWindow *w)
Like gSystem->ProcessEvents() but then only allow events for w to be processed.
Definition: TGClient.cxx:772
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
#define snprintf
Definition: civetweb.c:1540
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
EGEventType fWaitForEvent
Definition: TGClient.h:74
TList * fPlist
Definition: TGClient.h:71
#define c(i)
Definition: RSha256.hxx:101
static void MakeFunctor(const char *name, const char *type, GlobFunc &func)
Definition: TGlobal.h:73
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
Definition: TSystem.cxx:548
Colormap_t fDefaultColormap
Definition: TGClient.h:67
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
Pixel_t GetWhiteColor() const
Window_t fWaitForWindow
Definition: TGClient.h:75
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:356
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TGGCPool * fGCPool
Definition: TGClient.h:63
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
Pixel_t fShadow
Definition: TGClient.h:54
const Bool_t kTRUE
Definition: RtypesCore.h:87
void SetEditDisabled(Bool_t on=kTRUE)
If on is kTRUE editting/guibuilding is forbidden.
Definition: TGClient.cxx:942
Definition: TGGC.h:31
const Int_t n
Definition: legend1.C:16
void UnregisterPopup(TGWindow *w)
Remove a popup menu from the list of popups.
Definition: TGClient.cxx:543
char name[80]
Definition: TGX11.cxx:109
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition: TGClient.cxx:348
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:873
R__EXTERN Atom_t gROOT_MESSAGE
Definition: TVirtualX.h:40
void FreeGC(const TGGC *gc)
Delete graphics context if it is not used anymore.
Definition: TGGC.cxx:916
Colormap_t GetDefaultColormap() const
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition: TGGC.cxx:985
const char * Data() const
Definition: TString.h:364
TGWindow * GetWindowById(Window_t sw) const
Find a TGWindow via its handle. If window is not found return 0.
Definition: TGClient.cxx:593
UInt_t fStyle
Definition: TGClient.h:76