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