Logo ROOT  
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/** \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();
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 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",
150 gVirtualX->DisplayName(dpyName));
151 MakeZombie();
152 return;
153 }
154
155 if (fXfd >= 0 && !ROOT::Internal::gROOTLocal->IsBatch()) {
156 TGInputHandler *xi = new TGInputHandler(this, fXfd);
157 if (fXfd) gSystem->AddFileHandler(xi);
158 // X11 events are handled via gXDisplay->Notify() in
159 // TUnixSystem::DispatchOneEvent(). When no events available we wait for
160 // events on all TFileHandlers including this one via a select() call.
161 // However, X11 events are always handled via gXDisplay->Notify() and not
162 // via the ReadNotify() (therefore TGInputHandler should not override
163 // TFileHandler::ReadNotify()).
164 gXDisplay = xi;
165 }
166
167 // Initialize internal window list. Use a THashList for fast
168 // finding of windows based on window id (see GetWindowById()).
169
170 fWlist = new THashList(200);
171 fPlist = new TList;
172
173 // Create root window
174
175 fDefaultRoot = fRoot = new TGFrame(this, gVirtualX->GetDefaultRootWindow());
176
177 // Setup some atoms (defined in TVirtualX)...
178
179 gWM_DELETE_WINDOW = gVirtualX->InternAtom("WM_DELETE_WINDOW", kFALSE);
180 gMOTIF_WM_HINTS = gVirtualX->InternAtom("_MOTIF_WM_HINTS", kFALSE);
181 gROOT_MESSAGE = gVirtualX->InternAtom("_ROOT_MESSAGE", kFALSE);
182
183 // Create the graphics event handler, an object for the root window,
184 // a picture pool, mimetype list, etc...
185
190
191 fResourcePool = new TGResourcePool(this);
192
196
199
200 // Set some color defaults...
201
210
211 fStyle = 0;
212 TString style = gEnv->GetValue("Gui.Style", "modern");
213 if (style.Contains("flat", TString::kIgnoreCase))
214 fStyle = 2;
215 else if (style.Contains("modern", TString::kIgnoreCase))
216 fStyle = 1;
217
218 gClientGlobal = this;
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Returns current root (i.e. base) window. By changing the root
223/// window one can change the window hierarchy, e.g. a top level
224/// frame (TGMainFrame) can be embedded in another window.
225
227{
228 return fRoot;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Returns the root (i.e. desktop) window. Should only be used as parent
233/// for frames that will never be embedded, like popups, message boxes,
234/// etc. (like TGToolTips, TGMessageBox, etc.).
235
237{
238 return fDefaultRoot;
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Sets the current root (i.e. base) window. By changing the root
243/// window one can change the window hierarchy, e.g. a top level
244/// frame (TGMainFrame) can be embedded in another window.
245
247{
248 fRoot = root ? root : fDefaultRoot;
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Set the button style (modern or classic).
253
254void TGClient::SetStyle(const char *style)
255{
256 fStyle = 0;
257 if (style && strstr(style, "modern"))
258 fStyle = 1;
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Get display width.
263
265{
266 Int_t x, y;
267 UInt_t w, h;
268
269 gVirtualX->GetGeometry(-1, x, y, w, h);
270
271 return w;
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Get display height.
276
278{
279 Int_t x, y;
280 UInt_t w, h;
281
282 gVirtualX->GetGeometry(-1, x, y, w, h);
283
284 return h;
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Get picture from the picture pool. Picture must be freed using
289/// TGClient::FreePicture(). If picture is not found 0 is returned.
290
292{
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Get picture with specified size from pool (picture will be scaled if
298/// necessary). Picture must be freed using TGClient::FreePicture(). If
299/// picture is not found 0 is returned.
300
302 UInt_t new_width, UInt_t new_height)
303{
304 return fPicturePool->GetPicture(name, new_width, new_height);
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Free picture resource.
309
311{
312 if (pic) fPicturePool->FreePicture(pic);
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Get graphics context from the gc pool. Context must be freed via
317/// TGClient::FreeGC(). If rw is true a new read/write-able GC
318/// is returned, otherwise a shared read-only context is returned.
319/// For historical reasons it is also possible to create directly a
320/// TGGC object, but it is advised to use this new interface only.
321
323{
324 return fGCPool->GetGC(values, rw);
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Free a graphics context.
329
330void TGClient::FreeGC(const TGGC *gc)
331{
332 fGCPool->FreeGC(gc);
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Free a graphics context.
337
339{
340 fGCPool->FreeGC(gc);
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Get a font from the font pool. Fonts must be freed via
345/// TGClient::FreeFont(). Returns 0 in case of error or if font
346/// does not exist. If fixedDefault is false the "fixed" font
347/// will not be substituted as fallback when the asked for font
348/// does not exist.
349
350TGFont *TGClient::GetFont(const char *font, Bool_t fixedDefault)
351{
352 return fFontPool->GetFont(font, fixedDefault);
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Get again specified font. Will increase its usage count.
357
359{
360 return fFontPool->GetFont(font);
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Free a font.
365
366void TGClient::FreeFont(const TGFont *font)
367{
368 fFontPool->FreeFont(font);
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Set redraw flags.
373
375{
376 if (!w) return;
377 if (gVirtualX->NeedRedraw((ULong_t)w,force)) return;
378 if (force) {
379 w->DoRedraw();
380 return;
381 }
382 w->fNeedRedraw = kTRUE;
384}
385
386////////////////////////////////////////////////////////////////////////////////
387
389{
390 w->fNeedRedraw = kFALSE;
391}
392
393////////////////////////////////////////////////////////////////////////////////
394/// Get a color by name. If color is found return kTRUE and pixel is
395/// set to the color's pixel value, kFALSE otherwise.
396
397Bool_t TGClient::GetColorByName(const char *name, Pixel_t &pixel) const
398{
399 ColorStruct_t color;
401 Bool_t status = kTRUE;
402
403 gVirtualX->GetWindowAttributes(fRoot->GetId(), attributes);
404 color.fPixel = 0;
405 if (!gVirtualX->ParseColor(attributes.fColormap, name, color)) {
406 Error("GetColorByName", "couldn't parse color %s", name);
407 status = kFALSE;
408 } else if (!gVirtualX->AllocColor(attributes.fColormap, color)) {
409 Warning("GetColorByName", "couldn't retrieve color %s.\n"
410 "Please close any other application, like web browsers, "
411 "that might exhaust\nthe colormap and start ROOT again", name);
412 status = kFALSE;
413 }
414
415 pixel = color.fPixel;
416
417 return status;
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Get a font by name. If font is not found, fixed font is returned,
422/// if fixed font also does not exist return 0 and print error.
423/// The loaded font needs to be freed using TVirtualX::DeleteFont().
424/// If fixedDefault is false the "fixed" font will not be substituted
425/// as fallback when the asked for font does not exist.
426
427FontStruct_t TGClient::GetFontByName(const char *name, Bool_t fixedDefault) const
428{
429 if (gROOT->IsBatch())
430 return (FontStruct_t) -1;
431
432 FontStruct_t font = gVirtualX->LoadQueryFont(name);
433
434 if (!font && fixedDefault) {
435 font = gVirtualX->LoadQueryFont("fixed");
436 if (font)
437 Warning("GetFontByName", "couldn't retrieve font %s, using \"fixed\"", name);
438 }
439 if (!font) {
440 if (fixedDefault)
441 Error("GetFontByName", "couldn't retrieve font %s nor backup font \"fixed\"", name);
442 else
443 Warning("GetFontByName", "couldn't retrieve font %s", name);
444 }
445
446 return font;
447}
448
449////////////////////////////////////////////////////////////////////////////////
450/// Return pixel value of hilite color based on base_color.
451
453{
454 ColorStruct_t color, white_p;
456
457 gVirtualX->GetWindowAttributes(fRoot->GetId(), attributes);
458
459 color.fPixel = base_color;
460 gVirtualX->QueryColor(attributes.fColormap, color);
461
462 GetColorByName("white", white_p.fPixel);
463 gVirtualX->QueryColor(attributes.fColormap, white_p);
464
465 color.fRed = TMath::Max((UShort_t)(white_p.fRed/5), color.fRed);
466 color.fGreen = TMath::Max((UShort_t)(white_p.fGreen/5), color.fGreen);
467 color.fBlue = TMath::Max((UShort_t)(white_p.fBlue/5), color.fBlue);
468
469 color.fRed = (UShort_t)TMath::Min((Int_t)white_p.fRed, (Int_t)(color.fRed*140)/100);
470 color.fGreen = (UShort_t)TMath::Min((Int_t)white_p.fGreen, (Int_t)(color.fGreen*140)/100);
471 color.fBlue = (UShort_t)TMath::Min((Int_t)white_p.fBlue, (Int_t)(color.fBlue*140)/100);
472
473 if (!gVirtualX->AllocColor(attributes.fColormap, color))
474 Error("GetHilite", "couldn't allocate hilight color");
475
476 return color.fPixel;
477}
478
479////////////////////////////////////////////////////////////////////////////////
480/// Return pixel value of shadow color based on base_color.
481/// Shadow is 60% of base_color intensity.
482
484{
485 ColorStruct_t color;
487
488 gVirtualX->GetWindowAttributes(fRoot->GetId(), attributes);
489
490 color.fPixel = base_color;
491 gVirtualX->QueryColor(attributes.fColormap, color);
492
493 color.fRed = (UShort_t)((color.fRed*60)/100);
494 color.fGreen = (UShort_t)((color.fGreen*60)/100);
495 color.fBlue = (UShort_t)((color.fBlue*60)/100);
496
497 if (!gVirtualX->AllocColor(attributes.fColormap, color))
498 Error("GetShadow", "couldn't allocate shadow color");
499
500 return color.fPixel;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// Free color.
505
507{
508 gVirtualX->FreeColor(fDefaultColormap, color);
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// Add a TGWindow to the clients list of windows.
513
515{
516 fWlist->Add(w);
517
518 // Emits signal
520}
521
522////////////////////////////////////////////////////////////////////////////////
523/// Remove a TGWindow from the list of windows.
524
526{
527 fWlist->Remove(w);
528}
529
530////////////////////////////////////////////////////////////////////////////////
531/// Add a popup menu to the list of popups. This list is used to pass
532/// events to popup menus that are popped up over a transient window which
533/// is waited for (see WaitFor()).
534
536{
537 fPlist->Add(w);
538
539 // Emits signal
541}
542
543////////////////////////////////////////////////////////////////////////////////
544/// Remove a popup menu from the list of popups.
545
547{
548 fPlist->Remove(w);
549}
550
551////////////////////////////////////////////////////////////////////////////////
552/// Add handler for unknown (i.e. unregistered) windows.
553
555{
556 if (!fUWHandlers) {
557 fUWHandlers = new TList;
559 }
560
561 fUWHandlers->Add(h);
562}
563
564////////////////////////////////////////////////////////////////////////////////
565/// Remove handler for unknown (i.e. unregistered) windows.
566
568{
570}
571
572////////////////////////////////////////////////////////////////////////////////
573/// Add handler for idle events.
574
576{
577 if (!fIdleHandlers) {
578 fIdleHandlers = new TList;
580 }
581
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// Remove handler for idle events.
587
589{
591}
592
593////////////////////////////////////////////////////////////////////////////////
594/// Find a TGWindow via its handle. If window is not found return 0.
595
597{
598 TGWindow wt(wid);
599
600 return (TGWindow *) fWlist->FindObject(&wt);
601}
602
603////////////////////////////////////////////////////////////////////////////////
604/// Find a TGWindow via its name (unique name used in TGWindow::SavePrimitive).
605/// If window is not found return 0.
606
608{
609 TIter next(fWlist);
610
611 TObject *obj;
612 while ((obj = next())) {
613 TString n = obj->GetName();
614 if (n == name) {
615 return (TGWindow*)obj;
616 }
617 }
618 return 0;
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// Closing down client: cleanup and close X connection.
623
625{
626 if (IsZombie())
627 return;
628
629 if (fWlist)
630 fWlist->Delete("slow");
631 delete fWlist;
632 delete fPlist;
633 delete fUWHandlers;
634 delete fIdleHandlers;
635 delete fResourcePool;
636
637 gVirtualX->CloseDisplay(); // this should do a cleanup of the remaining
638 // X allocated objects...
639}
640
641////////////////////////////////////////////////////////////////////////////////
642/// Process one event. This method should only be called when there is
643/// a GUI event ready to be processed. If event has been processed
644/// kTRUE is returned. If processing of a specific event type for a specific
645/// window was requested kFALSE is returned when specific event has been
646/// processed, kTRUE otherwise. If no more pending events return kFALSE.
647
649{
651
652 if (!fRoot) return kFALSE;
653 if (gVirtualX->EventsPending()) {
654 gVirtualX->NextEvent(event);
655 if (fWaitForWindow == kNone) {
657 if (fForceRedraw)
658 DoRedraw();
659 return kTRUE;
660 } else {
662 if ((event.fType == fWaitForEvent) && (event.fWindow == fWaitForWindow))
664 if (fForceRedraw)
665 DoRedraw();
666 return kTRUE;
667 }
668 }
669
670 // if nothing else to do redraw windows that need redrawing
671 if (DoRedraw()) return kTRUE;
672
673 // process one idle event if there is nothing else to do
674 if (ProcessIdleEvent()) return kTRUE;
675
676 return kFALSE;
677}
678
679////////////////////////////////////////////////////////////////////////////////
680/// Process one idle event.
681
683{
684 if (fIdleHandlers) {
686 if (ih) {
688 ih->HandleEvent();
689 return kTRUE;
690 }
691 }
692 return kFALSE;
693}
694
695////////////////////////////////////////////////////////////////////////////////
696/// Handles input from the display server. Returns kTRUE if one or more
697/// events have been processed, kFALSE otherwise.
698
700{
701 Bool_t handledevent = kFALSE;
702
703 while (ProcessOneEvent())
704 handledevent = kTRUE;
705 return handledevent;
706}
707
708////////////////////////////////////////////////////////////////////////////////
709/// Wait for window to be destroyed.
710
712{
713 Window_t wsave = fWaitForWindow;
715
716 fWaitForWindow = w->GetId();
718
719 //Let VirtualX know, that we are
720 //in a nested loop for a window w.
721 //Noop on X11/win32gdk.
722 if (gVirtualX)
723 gVirtualX->BeginModalSessionFor(w->GetId());
724
725 while (fWaitForWindow != kNone) {
726 if (esave == kUnmapNotify)
727 wsave = kNone;
728 gSystem->ProcessEvents();//gSystem->InnerLoop();
729 gSystem->Sleep(5);
730 }
731
732 fWaitForWindow = wsave;
733 fWaitForEvent = esave;
734}
735
736////////////////////////////////////////////////////////////////////////////////
737/// Wait for window to be unmapped.
738
740{
741 Window_t wsave = fWaitForWindow;
743
744 fWaitForWindow = w->GetId();
746
747 //Let VirtualX know, that we are
748 //in a nested loop for a window w.
749 //Noop on X11/win32gdk.
750 if (gVirtualX)
751 gVirtualX->BeginModalSessionFor(w->GetId());
752
753 while (fWaitForWindow != kNone) {
754 gSystem->ProcessEvents();//gSystem->InnerLoop();
755 gSystem->Sleep(5);
756 }
757
758 fWaitForWindow = wsave;
759 fWaitForEvent = esave;
760}
761
762////////////////////////////////////////////////////////////////////////////////
763/// reset waiting
764
766{
768}
769
770////////////////////////////////////////////////////////////////////////////////
771/// Like gSystem->ProcessEvents() but then only allow events for w to
772/// be processed. For example to interrupt the processing and destroy
773/// the window, call gROOT->SetInterrupt() before destroying the window.
774
776{
777 Window_t wsave = fWaitForWindow;
779
780 fWaitForWindow = w->GetId();
782
783 Bool_t intr = gSystem->ProcessEvents();
784
785 fWaitForWindow = wsave;
786 fWaitForEvent = esave;
787
788 return intr;
789}
790
791////////////////////////////////////////////////////////////////////////////////
792/// Redraw all windows that need redrawing. Returns kFALSE if no redraw
793/// was needed, kTRUE otherwise.
794/// Only redraw the application's windows when the event queue
795/// does not contain expose event anymore.
796
798{
799 if (!fGlobalNeedRedraw) return kFALSE;
800
801 TGWindow *w;
802 TObjLink *lnk = fWlist->FirstLink();
803 while (lnk) {
804 w = (TGWindow *) lnk->GetObject();
805 if (w->fNeedRedraw) {
806 w->DoRedraw();
807 w->fNeedRedraw = kFALSE;
808 }
809 lnk = lnk->Next();
810 }
811
814
815 return kTRUE;
816}
817
818////////////////////////////////////////////////////////////////////////////////
819/// Handle a GUI event.
820
822{
823 TGWindow *w;
824
825 // Emit signal for event recorder(s)
826 if (event->fType != kConfigureNotify) {
828 }
829
830 // Find window where event happened
831 if ((w = GetWindowById(event->fWindow)) == 0) {
832 if (fUWHandlers && fUWHandlers->GetSize() > 0) {
835 while ((unkwh = (TGUnknownWindowHandler*)it.Next())) {
836 if (unkwh->HandleEvent(event))
837 return kTRUE;
838 }
839 }
840 //Warning("HandleEvent", "unknown window %ld not handled\n",
841 // event->fWindow);
842 return kFALSE;
843 }
844
845 // and let it handle the event
846 w->HandleEvent(event);
847
848 return kTRUE;
849}
850
851////////////////////////////////////////////////////////////////////////////////
852/// Handle masked events only if window wid is the window for which the
853/// event was reported or if wid is a parent of the event window. The not
854/// masked event are handled directly. The masked events are:
855/// kButtonPress, kButtonRelease, kKeyPress, kKeyRelease, kEnterNotify,
856/// kLeaveNotify, kMotionNotify.
857
859{
860 TGWindow *w, *ptr, *pop;
861
862 if ((w = GetWindowById(event->fWindow)) == 0) return kFALSE;
863
864 // Emit signal for event recorder(s)
865 if (event->fType != kConfigureNotify) {
866 ProcessedEvent(event, wid);
867 }
868
869 // This breaks class member protection, but TGClient is a friend of
870 // TGWindow and _should_ know what to do and what *not* to do...
871
872 for (ptr = w; ptr->fParent != 0; ptr = (TGWindow *) ptr->fParent) {
873 if ((ptr->fId == wid) ||
874 ((event->fType != kButtonPress) &&
875 (event->fType != kButtonRelease) &&
876 (event->fType != kGKeyPress) &&
877 (event->fType != kKeyRelease) &&
878 (event->fType != kEnterNotify) &&
879 (event->fType != kLeaveNotify) &&
880 (event->fType != kMotionNotify))) {
881 w->HandleEvent(event);
882 return kTRUE;
883 }
884 }
885
886 // check if this is a popup menu
887 TIter next(fPlist);
888 while ((pop = (TGWindow *) next())) {
889 for (ptr = w; ptr->fParent != 0; ptr = (TGWindow *) ptr->fParent) {
890 if ((ptr->fId == pop->fId) &&
891 ((event->fType == kButtonPress) ||
892 (event->fType == kButtonRelease) ||
893 (event->fType == kGKeyPress) ||
894 (event->fType == kKeyRelease) ||
895 (event->fType == kEnterNotify) ||
896 (event->fType == kLeaveNotify) ||
897 (event->fType == kMotionNotify))) {
898 w->HandleEvent(event);
899 return kTRUE;
900 }
901 }
902 }
903
904 if (event->fType == kButtonPress || event->fType == kGKeyPress)
905 gVirtualX->Bell(0);
906
907 return kFALSE;
908}
909
910////////////////////////////////////////////////////////////////////////////////
911/// Execute string "cmd" via the interpreter. Before executing replace
912/// in the command string the token $MSG, $PARM1 and $PARM2 by msg,
913/// parm1 and parm2, respectively. The function in cmd string must accept
914/// these as longs.
915
917{
918 if (cmd.IsNull()) return;
919
920 char s[32];
921
922 snprintf(s, sizeof(s), "%ld", msg);
923 cmd.ReplaceAll("$MSG", s);
924
925 snprintf(s, sizeof(s), "%ld", parm1);
926 cmd.ReplaceAll("$PARM1", s);
927
928 snprintf(s, sizeof(s), "%ld", parm2);
929 cmd.ReplaceAll("$PARM2", s);
930
931 gROOT->ProcessLine(cmd.Data());
932}
933
934////////////////////////////////////////////////////////////////////////////////
935/// Returns kTRUE if edit/guibuilding is forbidden.
936
938{
939 return (fDefaultRoot->GetEditDisabled() == 1);
940}
941
942////////////////////////////////////////////////////////////////////////////////
943/// If on is kTRUE editting/guibuilding is forbidden.
944
946{
948}
949
950////////////////////////////////////////////////////////////////////////////////
951/// Emits a signal when an event has been processed.
952/// Used in TRecorder.
953
955{
956 Long_t args[2];
957 args[0] = (Long_t) event;
958 args[1] = (Long_t) wid;
959
960 Emit("ProcessedEvent(Event_t*, Window_t)", args);
961}
962
963////////////////////////////////////////////////////////////////////////////////
964/// Emits a signal when a Window has been registered in TGClient.
965/// Used in TRecorder.
966
968{
969 Emit("RegisteredWindow(Window_t)", w);
970}
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
const Handle_t kNone
Definition: GuiTypes.h:88
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
Handle_t Window_t
Window handle.
Definition: GuiTypes.h:29
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
unsigned short UShort_t
Definition: RtypesCore.h:40
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
unsigned long ULong_t
Definition: RtypesCore.h:55
long Long_t
Definition: RtypesCore.h:54
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
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()
char name[80]
Definition: TGX11.cxx:110
#define gROOT
Definition: TROOT.h:404
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
R__EXTERN TFileHandler * gXDisplay
Definition: TSystem.h:560
#define gVirtualX
Definition: TVirtualX.h:338
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()
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.
Definition: TCollection.h:184
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:236
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition: TGClient.cxx:226
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:682
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:858
void FreeColor(Pixel_t color) const
Free color.
Definition: TGClient.cxx:506
Pixel_t fWhite
white color index
Definition: TGClient.h:48
void CancelRedraw(TGWindow *w)
Definition: TGClient.cxx:388
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:916
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
virtual ~TGClient()
Closing down client: cleanup and close X connection.
Definition: TGClient.cxx:624
void RegisterPopup(TGWindow *w)
Add a popup menu to the list of popups.
Definition: TGClient.cxx:535
void WaitForUnmap(TGWindow *w)
Wait for window to be unmapped.
Definition: TGClient.cxx:739
TGFontPool * fFontPool
font pool
Definition: TGClient.h:55
void UnregisterPopup(TGWindow *w)
Remove a popup menu from the list of popups.
Definition: TGClient.cxx:546
void ResetWaitFor(TGWindow *w)
reset waiting
Definition: TGClient.cxx:765
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get graphics context from the gc pool.
Definition: TGClient.cxx:322
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:350
void FreeGC(const TGGC *gc)
Free a graphics context.
Definition: TGClient.cxx:330
void AddUnknownWindowHandler(TGUnknownWindowHandler *h)
Add handler for unknown (i.e. unregistered) windows.
Definition: TGClient.cxx:554
Pixel_t fForeColor
default foreground color
Definition: TGClient.h:43
void SetStyle(UInt_t newstyle)
Definition: TGClient.h:142
void RemoveUnknownWindowHandler(TGUnknownWindowHandler *h)
Remove handler for unknown (i.e. unregistered) windows.
Definition: TGClient.cxx:567
UInt_t fStyle
GUI style (modern or classic)
Definition: TGClient.h:67
void AddIdleHandler(TGIdleHandler *h)
Add handler for idle events.
Definition: TGClient.cxx:575
void FreeFont(const TGFont *font)
Free a font.
Definition: TGClient.cxx:366
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:945
Bool_t ProcessEventsFor(TGWindow *w)
Like gSystem->ProcessEvents() but then only allow events for w to be processed.
Definition: TGClient.cxx:775
Bool_t HandleEvent(Event_t *event)
Handle a GUI event.
Definition: TGClient.cxx:821
Bool_t ProcessOneEvent()
Process one event.
Definition: TGClient.cxx:648
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:954
TGMimeTypes * fMimeTypeList
mimetype list
Definition: TGClient.h:57
Bool_t DoRedraw()
Redraw all windows that need redrawing.
Definition: TGClient.cxx:797
UInt_t GetDisplayHeight() const
Get display height.
Definition: TGClient.cxx:277
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:711
void RegisterWindow(TGWindow *w)
Add a TGWindow to the clients list of windows.
Definition: TGClient.cxx:514
TList * fIdleHandlers
list of idle handlers
Definition: TGClient.h:64
TGWindow * GetWindowById(Window_t sw) const
Find a TGWindow via its handle. If window is not found return 0.
Definition: TGClient.cxx:596
void RegisteredWindow(Window_t w)
Emits a signal when a Window has been registered in TGClient.
Definition: TGClient.cxx:967
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:291
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:397
void SetRoot(TGWindow *root=nullptr)
Sets the current root (i.e.
Definition: TGClient.cxx:246
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:588
Bool_t IsEditDisabled() const
Returns kTRUE if edit/guibuilding is forbidden.
Definition: TGClient.cxx:937
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:374
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:452
FontStruct_t GetFontByName(const char *name, Bool_t fixedDefault=kTRUE) const
Get a font by name.
Definition: TGClient.cxx:427
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:699
UInt_t GetDisplayWidth() const
Get display width.
Definition: TGClient.cxx:264
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:483
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:310
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:525
TGWindow * GetWindowByName(const char *name) const
Find a TGWindow via its name (unique name used in TGWindow::SavePrimitive).
Definition: TGClient.cxx:607
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.
Definition: TGIdleHandler.h:21
virtual Bool_t HandleEvent()
Handle the idle event.
TGClient * fClient
Definition: TGClient.cxx:105
TGInputHandler(TGClient *c, Int_t fd)
Definition: TGClient.cxx:107
Bool_t Notify()
Notify input from the display server.
Definition: TGClient.cxx:115
Handle_t GetId() const
Definition: TGObject.h:37
Handle_t fId
X11/Win32 Window identifier.
Definition: TGObject.h:26
void FreePicture(const TGPicture *pic)
Remove picture from cache if nobody is using it anymore.
Definition: TGPicture.cxx:277
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:82
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:134
virtual Bool_t HandleEvent(Event_t *)=0
ROOT GUI Window base class.
Definition: TGWindow.h:23
virtual void DoRedraw()
Definition: TGWindow.h:45
virtual Bool_t HandleEvent(Event_t *)
Definition: TGWindow.h:96
virtual UInt_t GetEditDisabled() const
Definition: TGWindow.h:105
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition: TGWindow.h:106
const TGWindow * fParent
Parent window.
Definition: TGWindow.h:28
Bool_t fNeedRedraw
kTRUE if window needs to be redrawn
Definition: TGWindow.h:29
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
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:378
void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: THashList.cxx:207
Iterator of linked list.
Definition: TList.h:200
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
Definition: TList.cxx:1111
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:822
virtual TObjLink * FirstLink() const
Definition: TList.h:108
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:659
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:879
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:149
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
void MakeZombie()
Definition: TObject.h:49
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:136
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
@ kIgnoreCase
Definition: TString.h:268
Bool_t IsNull() const
Definition: TString.h:407
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
Definition: TSystem.cxx:557
virtual void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
Definition: TSystem.cxx:234
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:440
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:419
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:377
static constexpr double s
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
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
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
TCanvas * style()
Definition: style.C:1