Logo ROOT  
Reference Guide
TGButton.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id: ee86415852b0e43b57190b9645717cf508b7920e $
2// Author: Fons Rademakers 06/01/98
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 TGButton
25 \ingroup guiwidgets
26
27A button abstract base class. It defines general button behaviour.
28
29*/
30
31
32/** \class TGTextButton
33 \ingroup guiwidgets
34
35Yield an action as soon as it is clicked. This buttons usually provides fast access to
36frequently used or critical commands. It may appear alone or placed in a group.
37
38The action it performs can be inscribed with a meaningful tooltip
39set by `SetToolTipText(const char* text, Long_t delayms=400).
40
41The text button has a label indicating the action to be taken when
42the button is pressed. The text can be a hot string ("&Exit") that
43defines the label "Exit" and keyboard mnemonics Alt+E for button
44selection. A button label can be changed by SetText(new_label).
45
46Selecting a text or picture button will generate the event:
47 - kC_COMMAND, kCM_BUTTON, button id, user data.
48*/
49
50
51/** \class TGPictureButton
52 \ingroup guiwidgets
53
54Yield an action as soon as it is clicked. This buttons usually provides fast access to
55frequently used or critical commands. It may appear alone or placed in a group.
56
57The action it performs can be inscribed with a meaningful tooltip
58set by `SetToolTipText(const char* text, Long_t delayms=400).
59
60The text button has a label indicating the action to be taken when
61the button is pressed. The text can be a hot string ("&Exit") that
62defines the label "Exit" and keyboard mnemonics Alt+E for button
63selection. A button label can be changed by SetText(new_label).
64
65Selecting a text or picture button will generate the event:
66 - kC_COMMAND, kCM_BUTTON, button id, user data.
67*/
68
69
70/** \class TGCheckButton
71 \ingroup guiwidgets
72
73Selects different options. Like text buttons, they have text or hot string as a label.
74
75Selecting a check button will generate the event:
76 - kC_COMMAND, kCM_CHECKBUTTON, button id, user data.
77
78If a command string has been specified (via SetCommand()) then this
79command string will be executed via the interpreter whenever a
80button is selected. A command string can contain the macros:
81
82 - $MSG -- kC_COMMAND, kCMCHECKBUTTON packed message
83 (use GET_MSG() and GET_SUBMSG() to unpack)
84 - $PARM1 -- button id
85 - $PARM2 -- user data pointer
86
87Before executing these macros are expanded into the respective Long_t's
88*/
89
90
91/** \class TGRadioButton
92 \ingroup guiwidgets
93
94Selects different options. Like text buttons, they have text or hot string as a label.
95
96Radio buttons are grouped usually in logical sets of two or more
97buttons to present mutually exclusive choices.
98
99Selecting a radio button will generate the event:
100 - kC_COMMAND, kCM_RADIOBUTTON, button id, user data.
101
102If a command string has been specified (via SetCommand()) then this
103command string will be executed via the interpreter whenever a
104button is selected. A command string can contain the macros:
105
106 - $MSG -- kC_COMMAND, kCMRADIOBUTTON packed message
107 (use GET_MSG() and GET_SUBMSG() to unpack)
108 - $PARM1 -- button id
109 - $PARM2 -- user data pointer
110
111Before executing these macros are expanded into the respective Long_t's
112*/
113
114
115/** \class TGSplitButton
116 \ingroup guiwidgets
117
118Implements a button with added menu functionality.
119There are 2 modes of operation available.
120
121If the button is split, a menu will popup when the menu area of the
122button is clicked. Activating a menu item changes the functionality
123of the button by having it emit a additional signal when it is
124clicked. The signal emitted when the button is clicked, is the
125ItemClicked(Int_t) signal with a different fixed value for the
126Int_t that corresponds to the id of the activated menu entry.
127
128If the button is not split, clicking it will popup the menu and the
129ItemClicked(Int_t) signal will be emitted when a menu entry is
130activated. The value of the Int_t is again equal to the value of
131the id of the activated menu entry.
132
133The mode of operation of a SplitButton can be changed on the fly
134by calling the SetSplit(Bool_t) method.
135*/
136
137
138#include "TGButton.h"
139#include "TGWidget.h"
140#include "TGPicture.h"
141#include "TGToolTip.h"
142#include "TGButtonGroup.h"
143#include "TGResourcePool.h"
144#include "TSystem.h"
145#include "TImage.h"
146#include "TEnv.h"
147#include "TClass.h"
148#include "TGMenu.h"
149#include "KeySymbols.h"
150#include "TVirtualX.h"
151
152#include <iostream>
153
154
155const TGGC *TGButton::fgHibckgndGC = nullptr;
156const TGGC *TGButton::fgDefaultGC = nullptr;
157
158const TGFont *TGTextButton::fgDefaultFont = nullptr;
159
160const TGFont *TGCheckButton::fgDefaultFont = nullptr;
161const TGGC *TGCheckButton::fgDefaultGC = nullptr;
162
163const TGFont *TGRadioButton::fgDefaultFont = nullptr;
164const TGGC *TGRadioButton::fgDefaultGC = nullptr;
165
167
174
175////////////////////////////////////////////////////////////////////////////////
176/// Create button base class part.
177
179 : TGFrame(p, 1, 1, options)
180{
181 fWidgetId = id;
183 fMsgWindow = p;
184 fUserData = 0;
185 fTip = 0;
186 fGroup = 0;
187 fStyle = 0;
188 fTWidth = fTHeight = 0;
189
190 fNormGC = norm;
194
195// fStyle = gClient->GetStyle();
196// if (fStyle > 0) {
197// fOptions &= ~(kRaisedFrame | kDoubleBorder);
198// }
199
200 // coverity[returned_null]
201 // coverity[dereference]
202 if (p && p->IsA()->InheritsFrom(TGButtonGroup::Class())) {
203 TGButtonGroup *bg = (TGButtonGroup*) p;
204 bg->Insert(this, id);
205 }
206
208 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
209
210 gVirtualX->GrabButton(fId, kButton1, kAnyModifier,
212 kNone, kNone);
213
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Delete button.
220
222{
223 // remove from button group
224 if (fGroup) {
225 fGroup->Remove(this);
226 fGroup = 0;
227 }
228
229 if (fTip) delete fTip;
230}
231
232////////////////////////////////////////////////////////////////////////////////
233/// Set button state.
234
236{
237 Bool_t was = !IsDown(); // kTRUE if button was off
238
239 if (state == kButtonDisabled)
240 fWidgetFlags &= ~kWidgetIsEnabled;
241 else
243 if (state != fState) {
244 switch (state) {
245 case kButtonEngaged:
246 case kButtonDown:
247 fOptions &= ~kRaisedFrame;
249 break;
250 case kButtonDisabled:
251 case kButtonUp:
252 if (fStyle > 0) {
253 fOptions &= ~kRaisedFrame;
254 fOptions &= ~kSunkenFrame;
255 }
256 else {
257 fOptions &= ~kSunkenFrame;
259 }
260 break;
261 }
262 fState = state;
263 DoRedraw();
264 if (emit || fGroup) EmitSignals(was);
265 }
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set the button style (modern or classic).
270
272{
273 fStyle = newstyle;
275 if (fStyle > 0) {
277 }
278 else {
280 }
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Set the button style (modern or classic).
285
286void TGButton::SetStyle(const char *style)
287{
289 if (style && strstr(style, "modern")) {
290 fStyle = 1;
292 }
293 else {
294 fStyle = 0;
296 }
297}
298
299////////////////////////////////////////////////////////////////////////////////
300
302{
303 if (fStyle > 0)
304 return (fOptions & kSunkenFrame);
305 return !(fOptions & kRaisedFrame);
306}
307
308////////////////////////////////////////////////////////////////////////////////
309
311{
312 // Set button state down according to the parameter 'on'.
313
314 if (GetState() == kButtonDisabled) return;
315
316 SetState(on ? kButtonDown : kButtonUp, emit);
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Sets new button-group for this button.
321
323{
324 fGroup = group;
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Handle mouse button event.
329
331{
332 Bool_t click = kFALSE;
333
334 if (fTip) fTip->Hide();
335
336 if (fState == kButtonDisabled) return kTRUE;
337
338 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
339 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
340
341 // We don't need to check the button number as GrabButton will
342 // only allow button1 events
343 if (event->fType == kButtonPress) {
344 fgReleaseBtn = 0;
345
346 if (fState == kButtonEngaged) {
347 return kTRUE;
348 }
349 if (in) SetState(kButtonDown, kTRUE);
350 } else { // ButtonRelease
351 if (fState == kButtonEngaged) {
352 if (in) SetState(kButtonUp, kTRUE);
353 click = kTRUE;
354 } else {
355 click = (fState == kButtonDown) && in;
356 if (click && fStayDown) {
357 if (in) {
359 fgReleaseBtn = 0;
360 }
361 } else {
362 if (in) {
365 }
366 }
367 }
368 }
369 if (click) {
371 (Long_t) fUserData);
373 (Long_t) fUserData);
374 }
375 if ((fStyle > 0) && (event->fType == kButtonRelease)) {
377 }
378 DoRedraw();
379 return kTRUE;
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Emit button signals.
384
386{
387 Bool_t now = !IsDown(); // kTRUE if button now is off
388
389 // emit signals
390 if (was && !now) {
391 Pressed(); // emit Pressed = was off , now on
392 if (fStayDown) Clicked(); // emit Clicked
393 }
394 if (!was && now) {
395 Released(); // emit Released = was on , now off
396 Clicked(); // emit Clicked
397 }
398 if ((was != now) && IsToggleButton()) Toggled(!now); // emit Toggled = was != now
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// Handle mouse crossing event.
403
405{
406 if (fTip) {
407 if (event->fType == kEnterNotify)
408 fTip->Reset();
409 else
410 fTip->Hide();
411 }
412
413 if (fStyle > 0) {
414 if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
416 } else {
418 }
419 if (event->fType == kLeaveNotify) {
421 }
422 DoRedraw();
423 }
424
425 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
426
427 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
428 return kTRUE;
429
430 if (fState == kButtonEngaged || fState == kButtonDisabled) return kTRUE;
431
432 if (event->fType == kLeaveNotify) {
435 }
436 DoRedraw();
437 return kTRUE;
438}
439
440////////////////////////////////////////////////////////////////////////////////
441/// Set tool tip text associated with this button. The delay is in
442/// milliseconds (minimum 250). To remove tool tip call method with
443/// text = 0.
444
445void TGButton::SetToolTipText(const char *text, Long_t delayms)
446{
447 if (fTip) {
448 delete fTip;
449 fTip = 0;
450 }
451
452 if (text && strlen(text))
453 fTip = new TGToolTip(fClient->GetDefaultRoot(), this, text, delayms);
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Set enabled or disabled state of button
458
460{
462
464 else fWidgetFlags &= ~kWidgetIsEnabled;
465}
466
467////////////////////////////////////////////////////////////////////////////////
468/// Return default graphics context.
469
471{
472 if (!fgDefaultGC)
473 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
474 return *fgDefaultGC;
475}
476
477////////////////////////////////////////////////////////////////////////////////
478/// Return graphics context for highlighted frame background.
479
481{
482 if (!fgHibckgndGC) {
483 GCValues_t gval;
486 gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
487 gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
488 gval.fFillStyle = kFillTiled;
489 gval.fTile = gClient->GetResourcePool()->GetCheckeredPixmap();
491 fgHibckgndGC = gClient->GetGC(&gval, kTRUE);
492 }
493 return *fgHibckgndGC;
494}
495
496
497////////////////////////////////////////////////////////////////////////////////
498/// Create a text button widget. The hotstring will be adopted and deleted
499/// by the text button.
500
502 GContext_t norm, FontStruct_t font,
503 UInt_t options) : TGButton(p, id, norm, options)
504{
505 fLabel = s;
506 fFontStruct = font;
507
508 Init();
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// Create a text button widget.
513
514TGTextButton::TGTextButton(const TGWindow *p, const char *s, Int_t id,
515 GContext_t norm, FontStruct_t font,
516 UInt_t options) : TGButton(p, id, norm, options)
517{
518 fLabel = new TGHotString(!p && !s ? GetName() : s);
519 fFontStruct = font;
520
521 Init();
522}
523
524////////////////////////////////////////////////////////////////////////////////
525/// Create a text button widget and set cmd string at same time.
526
527TGTextButton::TGTextButton(const TGWindow *p, const char *s, const char *cmd,
528 Int_t id, GContext_t norm, FontStruct_t font,
529 UInt_t options) : TGButton(p, id, norm, options)
530{
531 fLabel = new TGHotString(s);
532 fFontStruct = font;
533 fCommand = cmd;
534
535 Init();
536}
537
538////////////////////////////////////////////////////////////////////////////////
539/// Common initialization used by the different ctors.
540
542{
543 int hotchar;
544
546 fHKeycode = 0;
550 fWrapLength = -1;
551 fMLeft = fMRight = fMTop = fMBottom = 0;
552
554 if (!font) {
556 if (font) fFontStruct = font->GetFontStruct();
557 }
558 if (font) {
561 &fTWidth, &fTHeight);
562 }
563 Resize();
564 fWidth = fTWidth;
566
567 if ((hotchar = fLabel->GetHotChar()) != 0) {
568 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
570 if (main) {
571 main->BindKey(this, fHKeycode, kKeyMod1Mask);
572 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
573 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
575
576 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
580 }
581 }
582 }
585 wattr.fBitGravity = 5; // center
586 wattr.fWinGravity = 1;
587 gVirtualX->ChangeWindowAttributes(fId, &wattr);
588
590}
591
592////////////////////////////////////////////////////////////////////////////////
593/// Delete a text button widget.
594
596{
597 if (fHKeycode && (fParent->MustCleanup() != kDeepCleanup)) {
599 if (main) {
600 main->RemoveBind(this, fHKeycode, kKeyMod1Mask);
601 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
602 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
603 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
604
605 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
606 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
607 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
609 }
610 }
611 if (fLabel) delete fLabel;
612 if (fHasOwnFont) {
613 TGGCPool *pool = fClient->GetGCPool();
614 TGGC *gc = pool->FindGC(fNormGC);
615 pool->FreeGC(gc);
616 }
617
618 delete fTLayout;
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// layout text button
623
625{
627
629 if (!font) {
631 if (font) fFontStruct = font->GetFontStruct();
632 }
633 if (font) {
636 &fTWidth, &fTHeight);
637 }
638 fClient->NeedRedraw(this);
639}
640
641////////////////////////////////////////////////////////////////////////////////
642/// Set new button text.
643
645{
646 int hotchar;
648
649 if (fLabel) {
650 if (main && fHKeycode) {
651 main->RemoveBind(this, fHKeycode, kKeyMod1Mask);
652 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
653 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
654 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
655
656 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
657 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
658 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
660 }
661 delete fLabel;
662 }
663
664 fLabel = new_label;
665 if ((hotchar = fLabel->GetHotChar()) != 0) {
666 if (main && ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0)) {
667 main->BindKey(this, fHKeycode, kKeyMod1Mask);
668 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
669 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
671
672 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
676 }
677 }
678
679 Layout();
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// Set new button text.
684
685void TGTextButton::SetText(const TString &new_label)
686{
687 SetText(new TGHotString(new_label));
688}
689
690////////////////////////////////////////////////////////////////////////////////
691/// Set text justification. Mode is an OR of the bits:
692/// kTextTop, kTextBottom, kTextLeft, kTextRight, kTextCenterX and
693/// kTextCenterY.
694
696{
697 fTMode = mode;
698
701 wattr.fWinGravity = 1;
702
703 switch (mode) {
704 case kTextTop | kTextLeft:
705 wattr.fBitGravity = 1; //NorthWestGravity
706 break;
707 case kTextTop | kTextCenterX:
708 case kTextTop:
709 wattr.fBitGravity = 2; //NorthGravity
710 break;
711 case kTextTop | kTextRight:
712 wattr.fBitGravity = 3; //NorthEastGravity
713 break;
714 case kTextLeft | kTextCenterY:
715 case kTextLeft:
716 wattr.fBitGravity = 4; //WestGravity
717 break;
719 wattr.fBitGravity = 5; //CenterGravity
720 break;
722 case kTextRight:
723 wattr.fBitGravity = 6; //EastGravity
724 break;
725 case kTextBottom | kTextLeft:
726 wattr.fBitGravity = 7; //SouthWestGravity
727 break;
729 case kTextBottom:
730 wattr.fBitGravity = 8; //SouthGravity
731 break;
732 case kTextBottom | kTextRight:
733 wattr.fBitGravity = 9; //SouthEastGravity
734 break;
735 default:
736 wattr.fBitGravity = 5; //CenterGravity
737 break;
738 }
739
740 gVirtualX->ChangeWindowAttributes(fId, &wattr);
741 Layout();
742}
743
744////////////////////////////////////////////////////////////////////////////////
745/// Draw the text button.
746
748{
749 int x, y;
750 UInt_t w = GetWidth() - 1;
751 UInt_t h = GetHeight()- 1;
752
753 if ((fStyle > 0) && !(fOptions & kOwnBackground))
754 gVirtualX->SetWindowBackground(fId, fBgndColor);
756
757 if (fTMode & kTextLeft) {
758 x = fMLeft + 4;
759 } else if (fTMode & kTextRight) {
760 x = fWidth - fTWidth - fMRight - 4;
761 } else {
762 x = (fWidth - fTWidth + fMLeft - fMRight) >> 1;
763 }
764
765 if (fTMode & kTextTop) {
766 y = fMTop + 3;
767 } else if (fTMode & kTextBottom) {
768 y = fHeight - fTHeight - fMBottom - 3;
769 } else {
770 y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
771 }
772
774 ++x; ++y;
775 w--; h--;
776 }
777 if (fStyle == 0) {
778 if (fState == kButtonEngaged) {
779 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
780 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
781 }
782 }
783
784 Int_t hotpos = fLabel->GetHotPos();
785
786 if (fStyle > 0) {
787 gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
788 }
789 if (fState == kButtonDisabled) {
791 TGGC *gc = pool->FindGC(fNormGC);
792 if (gc) {
793 Pixel_t fore = gc->GetForeground();
796
797 gc->SetForeground(hi);
798 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
799 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x + 1, y + 1, hotpos - 1);
800
801 gc->SetForeground(sh);
802 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
803 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
804 gc->SetForeground(fore);
805 }
806 } else {
807 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
808 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
809 }
810}
811
812////////////////////////////////////////////////////////////////////////////////
813/// Handle key event. This function will be called when the hotkey is hit.
814
816{
817 if (fState == kButtonDisabled || !(event->fState & kKeyMod1Mask)) return kFALSE;
818
819 Bool_t click = kFALSE;
820 Bool_t was = !IsDown(); // kTRUE if button was off
821
822 if (event->fType == kGKeyPress) {
823 gVirtualX->SetKeyAutoRepeat(kFALSE);
824 } else {
825 gVirtualX->SetKeyAutoRepeat(kTRUE);
826 }
827
828 if (fTip && event->fType == kGKeyPress) fTip->Hide();
829
830 // We don't need to check the key number as GrabKey will only
831 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
832
833 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
834 if (fState == kButtonEngaged) return kTRUE;
836 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
837 if (fState == kButtonEngaged /*&& !allowRelease*/) return kTRUE;
838 click = (fState == kButtonDown);
839 if (click && fStayDown) {
841 } else {
843 }
844 }
845 if (click) {
847 (Long_t) fUserData);
849 (Long_t) fUserData);
850 }
851 EmitSignals(was);
852
853 return kTRUE;
854}
855
856////////////////////////////////////////////////////////////////////////////////
857/// returns default size
858
860{
863 return TGDimension(w, h);
864}
865
866////////////////////////////////////////////////////////////////////////////////
867/// Return default font structure.
868
870{
871 if (!fgDefaultFont)
872 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
874}
875
876////////////////////////////////////////////////////////////////////////////////
877/// Changes text font.
878/// If global is kTRUE font is changed globally, otherwise - locally.
879
881{
882 if (font != fFontStruct) {
883 FontH_t v = gVirtualX->GetFontHandle(font);
884 if (!v) return;
885
886 fFontStruct = font;
888 TGGC *gc = pool->FindGC(fNormGC);
889
890 if (gc && !global) {
891 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
893 }
894 if (gc) {
895 gc->SetFont(v);
896 fNormGC = gc->GetGC();
897 }
898 Layout();
899 }
900}
901
902////////////////////////////////////////////////////////////////////////////////
903/// Changes text font specified by name.
904/// If global is true color is changed globally, otherwise - locally.
905
906void TGTextButton::SetFont(const char *fontName, Bool_t global)
907{
908 TGFont *font = fClient->GetFont(fontName);
909 if (font) {
910 SetFont(font->GetFontStruct(), global);
911 }
912}
913
914////////////////////////////////////////////////////////////////////////////////
915/// Changes text color.
916/// If global is true color is changed globally, otherwise - locally.
917
919{
921 TGGC *gc = pool->FindGC(fNormGC);
922
923 if (gc && !global) {
924 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
926 }
927 if (gc) {
928 gc->SetForeground(color);
929 fNormGC = gc->GetGC();
930 }
931 fClient->NeedRedraw(this);
932}
933
934////////////////////////////////////////////////////////////////////////////////
935/// Returns kTRUE if text attributes are unique,
936/// returns kFALSE if text attributes are shared (global).
937
939{
940 return fHasOwnFont;
941}
942
943////////////////////////////////////////////////////////////////////////////////
944/// Create a picture button widget. The picture is not adopted and must
945/// later be freed by the user once the picture button is deleted (a single
946/// picture reference might be used by other buttons).
947
949 Int_t id, GContext_t norm, UInt_t option) : TGButton(p, id, norm, option)
950{
951 if (!pic) {
952 Error("TGPictureButton", "pixmap not found or the file format is not supported for button %d", id);
953 fPic = fClient->GetPicture("mb_question_s.xpm");
954 } else {
955 fPic = pic;
956 }
957
958 if (fPic) {
959 fTWidth = fPic->GetWidth();
961
963 fTHeight + (fBorderWidth << 1) + fBorderWidth); // *3
964 }
965 fPicD = 0;
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Create a picture button widget and set action command. The picture is
972/// not adopted and must later be freed by the user once the picture button
973/// is deleted (a single picture reference might be used by other
974/// buttons).
975
977 const char *cmd, Int_t id, GContext_t norm, UInt_t option)
978 : TGButton(p, id, norm, option)
979{
980 if (!pic) {
981 Error("TGPictureButton", "pixmap not found or the file format is not supported for button\n%s",
982 cmd ? cmd : "");
983 fPic = fClient->GetPicture("mb_question_s.xpm");
984 } else {
985 fPic = pic;
986 }
987
988 fCommand = cmd;
989
990 if (fPic) {
991 fTWidth = fPic->GetWidth();
993
995 fTHeight + (fBorderWidth << 1) + fBorderWidth); // *3
996 }
997 fPicD = 0;
1000}
1001
1002////////////////////////////////////////////////////////////////////////////////
1003/// Create a picture button. Where pic is the file name of the picture.
1004
1006 Int_t id, GContext_t norm, UInt_t option) : TGButton(p, id, norm, option)
1007{
1008 if (!pic || !pic[0]) {
1009 if (p) Error("TGPictureButton", "pixmap not found or the file format is not supported for button");
1010 fPic = fClient->GetPicture("mb_question_s.xpm");
1011 } else {
1012 fPic = fClient->GetPicture(pic);
1013 }
1014
1015 if (fPic) {
1016 fTWidth = fPic->GetWidth();
1017 fTHeight = fPic->GetHeight();
1018
1019 Resize(fTWidth + (fBorderWidth << 1) + fBorderWidth + 1,
1020 fTHeight + (fBorderWidth << 1) + fBorderWidth); // *3
1021 }
1022 fPicD = 0;
1024 SetWindowName();
1025}
1026
1027////////////////////////////////////////////////////////////////////////////////
1028/// Destructor.
1029
1031{
1033}
1034
1035////////////////////////////////////////////////////////////////////////////////
1036/// Change a picture in a picture button. The picture is not adopted and
1037/// must later be freed by the user once the picture button is deleted
1038/// (a single picture reference might be used by other buttons).
1039
1041{
1042 if (!new_pic) {
1043 Error("SetPicture", "pixmap not found or the file format is not supported for button %d\n%s",
1045 return;
1046 }
1047
1048 fPic = new_pic;
1049
1050 if (fState == kButtonDisabled) {
1052 fPicD = 0;
1053 }
1054
1055 fTWidth = fPic->GetWidth();
1056 fTHeight = fPic->GetHeight();
1057
1058 fClient->NeedRedraw(this);
1059}
1060
1061////////////////////////////////////////////////////////////////////////////////
1062/// Redraw picture button.
1063
1065{
1066 if (!fPic) {
1068 return;
1069 }
1070
1071 int x = (fWidth - fTWidth) >> 1;
1072 int y = (fHeight - fTHeight) >> 1;
1073 UInt_t w = GetWidth() - 1;
1074 UInt_t h = GetHeight()- 1;
1075
1076 if ((fStyle > 0) && !(fOptions & kOwnBackground))
1077 gVirtualX->SetWindowBackground(fId, fBgndColor);
1079
1080 if (fState == kButtonDown || fState == kButtonEngaged) {
1081 ++x; ++y;
1082 w--; h--;
1083 }
1084 if (fStyle == 0) {
1085 if (fState == kButtonEngaged) {
1086 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
1087 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
1088 }
1089 }
1090
1091 const TGPicture *pic = fPic;
1092 if (fState == kButtonDisabled) {
1094 pic = fPicD ? fPicD : fPic;
1095 }
1096 if (fStyle > 0) {
1097 if (fBgndColor == fHighColor) {
1098 gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
1099 }
1100 }
1101
1102 pic->Draw(fId, fNormGC, x, y);
1103}
1104
1105////////////////////////////////////////////////////////////////////////////////
1106/// Creates disabled picture.
1107
1109{
1110 TImage *img = TImage::Create();
1111 if (!img) return;
1112 TImage *img2 = TImage::Create();
1113 if (!img2) {
1114 if (img) delete img;
1115 return;
1116 }
1117 TString back = gEnv->GetValue("Gui.BackgroundColor", "#c0c0c0");
1118 img2->FillRectangle(back.Data(), 0, 0, fPic->GetWidth(), fPic->GetHeight());
1119 img->SetImage(fPic->GetPicture(), fPic->GetMask());
1120 Pixmap_t mask = img->GetMask();
1121 img2->Merge(img, "overlay");
1122
1123 TString name = "disbl_";
1124 name += fPic->GetName();
1125 fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), img2->GetPixmap(),
1126 mask);
1128 delete img;
1129 delete img2;
1130}
1131
1132////////////////////////////////////////////////////////////////////////////////
1133/// Changes disabled picture.
1134
1136{
1137 if (!pic) return;
1138
1140 fPicD = pic;
1141 ((TGPicture*)pic)->AddReference();
1143}
1144
1145////////////////////////////////////////////////////////////////////////////////
1146/// Create a check button widget. The hotstring will be adopted and deleted
1147/// by the check button.
1148
1150 GContext_t norm, FontStruct_t font, UInt_t option)
1151 : TGTextButton(p, s, id, norm, font, option)
1152{
1153 Init();
1154}
1155
1156////////////////////////////////////////////////////////////////////////////////
1157/// Create a check button widget.
1158
1160 GContext_t norm, FontStruct_t font, UInt_t option)
1161 : TGTextButton(p, s, id, norm, font, option)
1162{
1163 Init();
1164}
1165
1166////////////////////////////////////////////////////////////////////////////////
1167/// Create a check button widget.
1168
1169TGCheckButton::TGCheckButton(const TGWindow *p, const char *s, const char *cmd,
1170 Int_t id, GContext_t norm, FontStruct_t font,
1171 UInt_t option) : TGTextButton(p, s, cmd, id, norm, font, option)
1172{
1173 Init();
1174}
1175
1176////////////////////////////////////////////////////////////////////////////////
1177/// Common check button initialization.
1178
1180{
1181 fPrevState =
1182 fState = kButtonUp;
1183 fHKeycode = 0;
1184
1185 fOn = fClient->GetPicture("checked_t.xpm");
1186 fOff = fClient->GetPicture("unchecked_t.xpm");
1187 fDisOn = fClient->GetPicture("checked_dis_t.xpm");
1188 fDisOff = fClient->GetPicture("unchecked_dis_t.xpm");
1189
1190 Resize();
1191
1192 if (!fOn) {
1193 Error("TGCheckButton", "checked_t.xpm not found or the file format is not supported.");
1194 } else if (!fOff) {
1195 Error("TGCheckButton", "unchecked_t.xpm not found or the file format is not supported.");
1196 } else if (!fDisOn) {
1197 Error("TGCheckButton", "checked_dis_t.xpm not found or the file format is not supported.");
1198 } else if (!fDisOff) {
1199 Error("TGCheckButton", "unchecked_dis_t.xpm not found or the file format is not supported.");
1200 }
1201 int hotchar;
1202
1203 if ((hotchar = fLabel->GetHotChar()) != 0) {
1204 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
1206 if (main) {
1207 main->BindKey(this, fHKeycode, kKeyMod1Mask);
1208 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
1209 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
1211
1212 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
1216 }
1217 }
1218 }
1219 SetWindowName();
1220}
1221
1222////////////////////////////////////////////////////////////////////////////////
1223/// Delete a check button.
1224
1226{
1227 if (fOn) fClient->FreePicture(fOn);
1231}
1232
1233////////////////////////////////////////////////////////////////////////////////
1234/// default size
1235
1237{
1238 UInt_t w = !fTWidth ? fOff->GetWidth() : fTWidth + fOff->GetWidth() + 9;
1239 UInt_t h = !fTHeight ? fOff->GetHeight() : fTHeight + 2;
1240
1241 w = GetOptions() & kFixedWidth ? fWidth : w;
1242 h = GetOptions() & kFixedHeight ? fHeight : h;
1243
1244 return TGDimension(w, h);
1245}
1246
1247////////////////////////////////////////////////////////////////////////////////
1248/// Set check button state.
1249
1251{
1252 if (state == kButtonDisabled)
1253 fWidgetFlags &= ~kWidgetIsEnabled;
1254 else
1256 PSetState(state, emit);
1257}
1258
1259////////////////////////////////////////////////////////////////////////////////
1260/// Emit signals.
1261
1263{
1264 if (fState == kButtonUp) Released(); // emit Released
1265 if (fState == kButtonDown) Pressed(); // emit Pressed
1266 Clicked(); // emit Clicked
1267 Toggled(fStateOn); // emit Toggled
1268}
1269
1270////////////////////////////////////////////////////////////////////////////////
1271/// Set check button state.
1272
1274{
1275 if (state != fState) {
1276 if (state == kButtonUp) {
1277 if (fPrevState == kButtonDisabled) {
1278 if (fStateOn) {
1281 } else {
1282 fState = state;
1283 fPrevState = state;
1284 }
1285 } else if (fPrevState == kButtonDown) {
1286 fStateOn = kFALSE;
1287 fState = state;
1288 fPrevState = state;
1289 }
1290 } else if (state == kButtonDown) {
1291 fStateOn = kTRUE;
1292 fState = state;
1293 fPrevState = state;
1294 } else {
1295 fState = state;
1296 fPrevState = state;
1297 }
1298 if (emit) {
1299 // button signals
1300 EmitSignals();
1301 }
1302 DoRedraw();
1303 }
1304}
1305
1306////////////////////////////////////////////////////////////////////////////////
1307/// Set the state of a check button to disabled and either on or
1308/// off.
1309
1311{
1312 if (!enable) {
1313 if (fState == kButtonDisabled && fStateOn) {
1314 PSetState(kButtonUp, kFALSE); // enable button
1315 PSetState(kButtonUp, kFALSE); // set button up
1316 PSetState(kButtonDisabled, kFALSE); // disable button
1317 } else {
1320 }
1321 } else {
1322 PSetState(kButtonDown, kFALSE); // set button down
1323 PSetState(kButtonDisabled, kFALSE); // disable button
1324 }
1325}
1326
1327////////////////////////////////////////////////////////////////////////////////
1328/// Handle mouse button event.
1329
1331{
1332 Bool_t click = kFALSE;
1333
1334 if (fTip) fTip->Hide();
1335
1336 if (fState == kButtonDisabled) return kTRUE;
1337
1338 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
1339 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
1340
1341 // We don't need to check the button number as GrabButton will
1342 // only allow button1 events
1343 if (event->fType == kButtonPress) {
1344 fgReleaseBtn = 0;
1345 if (in) {
1347 Pressed();
1348 }
1349 } else { // ButtonRelease
1350 if (in) {
1352 click = kTRUE;
1354 Released();
1355 }
1356 fgReleaseBtn = fId;
1357 fOptions &= ~kSunkenFrame;
1358 }
1359 if (click) {
1360 Clicked();
1366 }
1367 DoRedraw();
1368 return kTRUE;
1369}
1370
1371////////////////////////////////////////////////////////////////////////////////
1372/// Handle mouse crossing event.
1373
1375{
1376 if (fTip) {
1377 if (event->fType == kEnterNotify)
1378 fTip->Reset();
1379 else
1380 fTip->Hide();
1381 }
1382
1383 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
1384
1385 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
1386 return kTRUE;
1387
1388 if (fState == kButtonDisabled) return kTRUE;
1389
1390 if (event->fType == kEnterNotify) {
1392 } else {
1393 fOptions &= ~kSunkenFrame;
1394 }
1395 DoRedraw();
1396
1397 return kTRUE;
1398}
1399
1400////////////////////////////////////////////////////////////////////////////////
1401/// Handle key event. This function will be called when the hotkey is hit.
1402
1404{
1405 Bool_t click = kFALSE;
1406
1407 if (event->fType == kGKeyPress)
1408 gVirtualX->SetKeyAutoRepeat(kFALSE);
1409 else
1410 gVirtualX->SetKeyAutoRepeat(kTRUE);
1411
1412 if (fTip && event->fType == kGKeyPress) fTip->Hide();
1413
1414 if (fState == kButtonDisabled) return kTRUE;
1415
1416 // We don't need to check the key number as GrabKey will only
1417 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
1418
1419 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
1421 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
1422 click = (fState != fPrevState);
1424 }
1425 if (click) {
1427 (Long_t) fUserData);
1429 (Long_t) fUserData);
1430 }
1431 return kTRUE;
1432}
1433
1434////////////////////////////////////////////////////////////////////////////////
1435/// Draw the check button widget.
1436
1438{
1439 int x, y, y0;
1440
1442
1443 x = 20;
1444 y = (fHeight - fTHeight) >> 1;
1445
1446 y0 = !fTHeight ? 0 : y + 1;
1447 if (fOn && fOff) {
1448 Int_t smax = TMath::Max(fOn->GetHeight(), fOff->GetHeight());
1449 y0 = ((Int_t)fHeight <= smax) ? 0 : 1 + (((Int_t)fHeight - smax) >> 1);
1450 }
1451
1452 if (fStateOn) {
1453 if (fOn) fOn->Draw(fId, fNormGC, 0, y0);
1454 } else {
1455 if (fOff) fOff->Draw(fId, fNormGC, 0, y0);
1456 }
1457
1458 Int_t hotpos = fLabel->GetHotPos();
1459
1460 if (fState == kButtonDisabled) {
1461 if (fStateOn == kTRUE) {
1462 if (fDisOn) fDisOn->Draw(fId, fNormGC, 0, y0);
1463 } else {
1464 if (fDisOff) fDisOff->Draw(fId, fNormGC, 0, y0);
1465 }
1466
1468 TGGC *gc = pool->FindGC(fNormGC);
1469 if (gc) {
1470 Pixel_t fore = gc->GetForeground();
1473
1474 gc->SetForeground(hi);
1475 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
1476 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
1477
1478 gc->SetForeground(sh);
1479 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
1480 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
1481
1482 gc->SetForeground(fore);
1483 }
1484 } else {
1485 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
1486 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
1487 }
1488}
1489
1490////////////////////////////////////////////////////////////////////////////////
1491/// Return default font structure.
1492
1494{
1495 if (!fgDefaultFont)
1496 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1497 return fgDefaultFont->GetFontStruct();
1498}
1499
1500////////////////////////////////////////////////////////////////////////////////
1501/// Return default graphics context.
1502
1504{
1505 if (!fgDefaultGC)
1506 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1507 return *fgDefaultGC;
1508}
1509
1510
1511////////////////////////////////////////////////////////////////////////////////
1512/// Create a radio button widget. The hotstring will be adopted and deleted
1513/// by the radio button.
1514
1516 GContext_t norm, FontStruct_t font, UInt_t option)
1517 : TGTextButton(p, s, id, norm, font, option)
1518{
1519 Init();
1520}
1521
1522////////////////////////////////////////////////////////////////////////////////
1523/// Create a radio button widget.
1524
1526 GContext_t norm, FontStruct_t font, UInt_t option)
1527 : TGTextButton(p, s, id, norm, font, option)
1528{
1529 Init();
1530}
1531////////////////////////////////////////////////////////////////////////////////
1532/// Create a radio button widget.
1533
1534TGRadioButton::TGRadioButton(const TGWindow *p, const char *s, const char *cmd,
1535 Int_t id, GContext_t norm,
1536 FontStruct_t font, UInt_t option)
1537 : TGTextButton(p, s, cmd, id, norm, font, option)
1538{
1539 Init();
1540}
1541
1542////////////////////////////////////////////////////////////////////////////////
1543/// Common radio button initialization.
1544
1546{
1547 fPrevState =
1548 fState = kButtonUp;
1549 fHKeycode = 0;
1550
1551 fOn = fClient->GetPicture("rbutton_on.xpm");
1552 fOff = fClient->GetPicture("rbutton_off.xpm");
1553 fDisOn = fClient->GetPicture("rbutton_dis_on.xpm");
1554 fDisOff = fClient->GetPicture("rbutton_dis_off.xpm");
1555
1556 if (!fOn || !fOff || !fDisOn || !fDisOff)
1557 Error("TGRadioButton", "rbutton_*.xpm not found or the file format is not supported.");
1558
1559 Resize();
1560
1561 int hotchar;
1562
1563 if ((hotchar = fLabel->GetHotChar()) != 0) {
1564 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
1566 if (main) {
1567 main->BindKey(this, fHKeycode, kKeyMod1Mask);
1568 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
1569 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
1571
1572 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
1576 }
1577 }
1578 }
1579
1580 if (fParent->IsA()->InheritsFrom(TGButtonGroup::Class())) {
1581 ((TGButtonGroup*)fParent)->SetRadioButtonExclusive(kTRUE);
1582 }
1583 SetWindowName();
1584}
1585
1586////////////////////////////////////////////////////////////////////////////////
1587/// Delete a radio button.
1588
1590{
1591 if (fOn) fClient->FreePicture(fOn);
1595}
1596
1597////////////////////////////////////////////////////////////////////////////////
1598/// default size
1599
1601{
1602 UInt_t w = !fTWidth ? ( fOff?fOff->GetWidth():10) : fTWidth + fOff->GetWidth() + 10;
1603 UInt_t h = !fTHeight ? ( fOff?fOff->GetHeight():2) : fTHeight + 2;
1604
1605 w = GetOptions() & kFixedWidth ? fWidth : w;
1606 h = GetOptions() & kFixedHeight ? fHeight : h;
1607
1608 return TGDimension(w, h);
1609}
1610////////////////////////////////////////////////////////////////////////////////
1611/// Set radio button state.
1612
1614{
1615 if (state == kButtonDisabled)
1616 fWidgetFlags &= ~kWidgetIsEnabled;
1617 else
1619 PSetState(state, emit);
1620}
1621
1622////////////////////////////////////////////////////////////////////////////////
1623/// Set the state of a radio button to disabled and either on or
1624/// off.
1625
1627{
1628 if (!enable) {
1629 if (fState == kButtonDisabled && fStateOn) {
1630 PSetState(kButtonUp, kFALSE); // enable button
1631 PSetState(kButtonUp, kFALSE); // set button up
1632 PSetState(kButtonDisabled, kFALSE); // disable button
1633 } else {
1636 }
1637 } else {
1638 PSetState(kButtonDown, kFALSE); // set button down
1639 PSetState(kButtonDisabled, kFALSE); // disable button
1640 }
1641}
1642
1643////////////////////////////////////////////////////////////////////////////////
1644/// Emit signals.
1645
1647{
1648 if (fState == kButtonUp) Released(); // emit Released
1649 if (fState == kButtonDown) Pressed(); // emit Pressed
1650 Clicked(); // emit Clicked
1651 Toggled(fStateOn); // emit Toggled
1652}
1653
1654////////////////////////////////////////////////////////////////////////////////
1655/// Set radio button state.
1656
1658{
1659 if (state != fState) {
1660 // fPrevState = fState = state;
1661 if (state == kButtonUp) {
1662 if (fPrevState == kButtonDisabled) {
1663 if (fStateOn) {
1666 } else {
1667 fState = state;
1668 fPrevState = state;
1669 }
1670 } else if (fPrevState == kButtonDown) {
1671 fStateOn = kFALSE;
1672 fState = state;
1673 fPrevState = state;
1674 }
1675 } else if (state == kButtonDown) {
1676 fStateOn = kTRUE;
1677 fState = state;
1678 fPrevState = state;
1679 } else {
1680 fState = state;
1681 fPrevState = state;
1682 }
1683 if (emit) {
1684 // button signals
1685 EmitSignals();
1686 }
1687 DoRedraw();
1688 }
1689}
1690
1691////////////////////////////////////////////////////////////////////////////////
1692/// Handle mouse button event.
1693
1695{
1696 Bool_t click = kFALSE;
1697 Bool_t toggled = kFALSE;
1698
1699 if (fTip) fTip->Hide();
1700
1701 if (fState == kButtonDisabled) return kFALSE;
1702
1703
1704 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
1705 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
1706
1707 if (event->fType == kButtonPress) { // button pressed
1708 fgReleaseBtn = 0;
1709 if (in) {
1711 Pressed();
1712 }
1713 } else { // ButtonRelease
1714 if (in) {
1715 if (!fStateOn) {
1717 toggled = kTRUE;
1718 }
1720 Released();
1721 click = kTRUE;
1722 }
1723 fOptions &= ~kSunkenFrame;
1724 fgReleaseBtn = fId;
1725 }
1726 if (click) {
1727 Clicked();
1732 }
1733 if (toggled) {
1735 }
1736 DoRedraw();
1737 return kTRUE;
1738}
1739
1740////////////////////////////////////////////////////////////////////////////////
1741/// Handle mouse crossing event.
1742
1744{
1745 if (fTip) {
1746 if (event->fType == kEnterNotify)
1747 fTip->Reset();
1748 else
1749 fTip->Hide();
1750 }
1751
1752 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
1753
1754 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
1755 return kTRUE;
1756
1757 if (fState == kButtonDisabled) return kTRUE;
1758
1759 if (event->fType == kEnterNotify) {
1761 } else {
1762 fOptions &= ~kSunkenFrame;
1763 }
1764 DoRedraw();
1765
1766 return kTRUE;
1767}
1768
1769////////////////////////////////////////////////////////////////////////////////
1770/// Handle key event. This function will be called when the hotkey is hit.
1771
1773{
1774 if (event->fType == kGKeyPress)
1775 gVirtualX->SetKeyAutoRepeat(kFALSE);
1776 else
1777 gVirtualX->SetKeyAutoRepeat(kTRUE);
1778
1779 if (fTip && event->fType == kGKeyPress)
1780 fTip->Hide();
1781
1782 if (fState == kButtonDisabled) return kTRUE;
1783
1784 // We don't need to check the key number as GrabKey will only
1785 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
1786
1787 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
1793 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
1795 }
1796 return kTRUE;
1797}
1798
1799////////////////////////////////////////////////////////////////////////////////
1800/// Draw a radio button.
1801
1803{
1804 Int_t tx, ty, y0;
1805
1807
1808 tx = 20;
1809 ty = (fHeight - fTHeight) >> 1;
1810
1811// pw = 12;
1812 y0 = !fTHeight ? 0 : ty + 1;
1813 if (fOn && fOff) {
1814 Int_t smax = TMath::Max(fOn->GetHeight(), fOff->GetHeight());
1815 y0 = ((Int_t)fHeight <= smax) ? 0 : 1 + (((Int_t)fHeight - smax) >> 1);
1816 }
1817
1818 if (fStateOn) {
1819 if (fOn) fOn->Draw(fId, fNormGC, 0, y0);
1820 } else {
1821 if (fOff) fOff->Draw(fId, fNormGC, 0, y0);
1822 }
1823
1824 Int_t hotpos = fLabel->GetHotPos();
1825
1826 if (fState == kButtonDisabled) {
1827 if (fStateOn == kTRUE) {
1828 if (fDisOn) fDisOn->Draw(fId, fNormGC, 0, y0);
1829 } else {
1830 if (fDisOff) fDisOff->Draw(fId, fNormGC, 0, y0);
1831 }
1832
1834 TGGC *gc = pool->FindGC(fNormGC);
1835 if (gc) {
1836 Pixel_t fore = gc->GetForeground();
1839
1840 gc->SetForeground(hi);
1841 fTLayout->DrawText(fId, gc->GetGC(), tx + 1, ty + 1, 0, -1);
1842 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), tx, ty, hotpos - 1);
1843
1844 gc->SetForeground(sh);
1845 fTLayout->DrawText(fId, gc->GetGC(), tx, ty, 0, -1);
1846 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), tx, ty, hotpos - 1);
1847
1848 gc->SetForeground(fore);
1849 }
1850 } else {
1851 fTLayout->DrawText(fId, fNormGC, tx, ty, 0, -1);
1852 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, tx, ty, hotpos-1);
1853 }
1854}
1855
1856////////////////////////////////////////////////////////////////////////////////
1857/// Return default font structure.
1858
1860{
1861 if (!fgDefaultFont)
1862 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1863 return fgDefaultFont->GetFontStruct();
1864}
1865
1866////////////////////////////////////////////////////////////////////////////////
1867/// Return default graphics context.
1868
1870{
1871 if (!fgDefaultGC)
1872 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1873 return *fgDefaultGC;
1874}
1875
1876////////////////////////////////////////////////////////////////////////////////
1877/// Save a button widget as a C++ statement(s) on output stream out.
1878
1879void TGButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1880{
1881 char quote = '"';
1882
1883 if (option && strstr(option, "keep_names"))
1884 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
1885
1886 if (fState == kButtonDown) {
1887 out << " " << GetName() << "->SetState(kButtonDown);" << std::endl;
1888 }
1889 if (fState == kButtonDisabled) {
1890 out << " " << GetName() << "->SetState(kButtonDisabled);" << std::endl;
1891 }
1892 if (fState == kButtonEngaged) {
1893 out << " " << GetName() << "->SetState(kButtonEngaged);" << std::endl;
1894 }
1896 SaveUserColor(out, option);
1897 out << " " << GetName() << "->ChangeBackground(ucolor);" << std::endl;
1898 }
1899
1900 if (fTip) {
1901 TString tiptext = fTip->GetText()->GetString();
1902 tiptext.ReplaceAll("\n", "\\n");
1903 out << " ";
1904 out << GetName() << "->SetToolTipText(" << quote
1905 << tiptext << quote << ");" << std::endl;
1906 }
1907 if (strlen(fCommand)) {
1908 out << " " << GetName() << "->SetCommand(" << quote << fCommand
1909 << quote << ");" << std::endl;
1910 }
1911}
1912
1913////////////////////////////////////////////////////////////////////////////////
1914/// Save a text button widget as a C++ statement(s) on output stream out.
1915
1916void TGTextButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1917{
1918 char quote = '"';
1919 TString outext(fLabel->GetString());
1920 if (fLabel->GetHotPos() > 0)
1921 outext.Insert(fLabel->GetHotPos()-1, "&");
1922 if (outext.First('\n') >= 0)
1923 outext.ReplaceAll("\n", "\\n");
1924
1925 // font + GC
1926 option = GetName()+5; // unique digit id of the name
1927 TString parGC, parFont;
1928 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
1929 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
1930
1931 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
1932 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
1933 if (ufont) {
1934 ufont->SavePrimitive(out, option);
1935 parFont.Form("ufont->GetFontStruct()");
1936 }
1937
1938 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
1939 if (userGC) {
1940 userGC->SavePrimitive(out, option);
1941 parGC.Form("uGC->GetGC()");
1942 }
1943 }
1944
1946
1947 out << " TGTextButton *";
1948 out << GetName() << " = new TGTextButton(" << fParent->GetName()
1949 << "," << quote << outext.Data() << quote;
1950
1951 if (GetOptions() == (kRaisedFrame | kDoubleBorder)) {
1953 if (fNormGC == GetDefaultGC()()) {
1954 if (fWidgetId == -1) {
1955 out << ");" << std::endl;
1956 } else {
1957 out << "," << fWidgetId <<");" << std::endl;
1958 }
1959 } else {
1960 out << "," << fWidgetId << "," << parGC << ");" << std::endl;
1961 }
1962 } else {
1963 out << "," << fWidgetId << "," << parGC << "," << parFont << ");" << std::endl;
1964 }
1965 } else {
1966 out << "," << fWidgetId << "," << parGC << "," << parFont << "," << GetOptionString() << ");" << std::endl;
1967 }
1968
1969 out << " " << GetName() << "->SetTextJustify(" << fTMode << ");" << std::endl;
1970 out << " " << GetName() << "->SetMargins(" << fMLeft << "," << fMRight << ",";
1971 out << fMTop << "," << fMBottom << ");" << std::endl;
1972 out << " " << GetName() << "->SetWrapLength(" << fWrapLength << ");" << std::endl;
1973
1974 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight()
1975 << ");" << std::endl;
1976
1977 TGButton::SavePrimitive(out,option);
1978}
1979
1980////////////////////////////////////////////////////////////////////////////////
1981/// Save a picture button widget as a C++ statement(s) on output stream out.
1982
1983void TGPictureButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1984{
1985 if (!fPic) {
1986 Error("SavePrimitive()", "pixmap not found or the file format is not supported for picture button %d ", fWidgetId);
1987 return;
1988 }
1989
1990 // GC
1991 option = GetName()+5; // unique digit id of the name
1992 TString parGC;
1993 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
1994
1995 if (GetDefaultGC()() != fNormGC) {
1996 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
1997 if (userGC) {
1998 userGC->SavePrimitive(out, option);
1999 parGC.Form("uGC->GetGC()");
2000 }
2001 }
2002
2003 char quote = '"';
2004 TString picname = gSystem->UnixPathName(fPic->GetName());
2005 gSystem->ExpandPathName(picname);
2006
2007 out <<" TGPictureButton *";
2008
2009 out << GetName() << " = new TGPictureButton(" << fParent->GetName()
2010 << ",gClient->GetPicture(" << quote
2011 << picname << quote << ")";
2012
2013 if (GetOptions() == (kRaisedFrame | kDoubleBorder)) {
2014 if (fNormGC == GetDefaultGC()()) {
2015 if (fWidgetId == -1) {
2016 out << ");" << std::endl;
2017 } else {
2018 out << "," << fWidgetId << ");" << std::endl;
2019 }
2020 } else {
2021 out << "," << fWidgetId << "," << parGC.Data() << ");" << std::endl;
2022 }
2023 } else {
2024 out << "," << fWidgetId << "," << parGC.Data() << "," << GetOptionString()
2025 << ");" << std::endl;
2026 }
2027
2028 TGButton::SavePrimitive(out,option);
2029}
2030
2031////////////////////////////////////////////////////////////////////////////////
2032/// Save a check button widget as a C++ statement(s) on output stream out.
2033
2034void TGCheckButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2035{
2036 char quote = '"';
2037
2038 TString outext(fLabel->GetString());
2039 if (fLabel->GetHotPos() > 0)
2040 outext.Insert(fLabel->GetHotPos()-1, "&");
2041 if (outext.First('\n') >= 0)
2042 outext.ReplaceAll("\n", "\\n");
2043
2044 out <<" TGCheckButton *";
2045 out << GetName() << " = new TGCheckButton(" << fParent->GetName()
2046 << "," << quote << outext.Data() << quote;
2047
2048 // font + GC
2049 option = GetName()+5; // unique digit id of the name
2050 TString parGC, parFont;
2051 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
2052 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
2053
2054 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
2055 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
2056 if (ufont) {
2057 ufont->SavePrimitive(out, option);
2058 parFont.Form("ufont->GetFontStruct()");
2059 }
2060
2061 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
2062 if (userGC) {
2063 userGC->SavePrimitive(out, option);
2064 parGC.Form("uGC->GetGC()");
2065 }
2066 }
2067
2068 if (GetOptions() == kChildFrame) {
2070 if (fNormGC == GetDefaultGC()()) {
2071 if (fWidgetId == -1) {
2072 out << ");" << std::endl;
2073 } else {
2074 out << "," << fWidgetId << ");" << std::endl;
2075 }
2076 } else {
2077 out << "," << fWidgetId << "," << parGC << ");" << std::endl;
2078 }
2079 } else {
2080 out << "," << fWidgetId << "," << parGC << "," << parFont << ");" << std::endl;
2081 }
2082 } else {
2083 out << "," << fWidgetId << "," << parGC << "," << parFont << "," << GetOptionString() << ");" << std::endl;
2084 }
2085
2086 TGButton::SavePrimitive(out,option);
2087 if (fState == kButtonDisabled) {
2089 out << " " << GetName() << "->SetDisabledAndSelected(kTRUE);" << std::endl;
2090 else
2091 out << " " << GetName() << "->SetDisabledAndSelected(kFALSE);" << std::endl;
2092 }
2093 out << " " << GetName() << "->SetTextJustify(" << fTMode << ");" << std::endl;
2094 out << " " << GetName() << "->SetMargins(" << fMLeft << "," << fMRight << ",";
2095 out << fMTop << "," << fMBottom << ");" << std::endl;
2096 out << " " << GetName() << "->SetWrapLength(" << fWrapLength << ");" << std::endl;
2097}
2098
2099////////////////////////////////////////////////////////////////////////////////
2100/// Save a radio button widget as a C++ statement(s) on output stream out.
2101
2102void TGRadioButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2103{
2104 char quote = '"';
2105
2106 TString outext(fLabel->GetString());
2107 if (fLabel->GetHotPos() > 0)
2108 outext.Insert(fLabel->GetHotPos()-1, "&");
2109 if (outext.First('\n') >= 0)
2110 outext.ReplaceAll("\n", "\\n");
2111
2112 out << " TGRadioButton *";
2113 out << GetName() << " = new TGRadioButton(" << fParent->GetName()
2114 << "," << quote << outext.Data() << quote;
2115
2116 // font + GC
2117 option = GetName()+5; // unique digit id of the name
2118 TString parGC, parFont;
2119 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
2120 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
2121
2122 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
2123 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
2124 if (ufont) {
2125 ufont->SavePrimitive(out, option);
2126 parFont.Form("ufont->GetFontStruct()");
2127 }
2128
2129 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
2130 if (userGC) {
2131 userGC->SavePrimitive(out, option);
2132 parGC.Form("uGC->GetGC()");
2133 }
2134 }
2135
2136 if (GetOptions() == (kChildFrame)) {
2138 if (fNormGC == GetDefaultGC()()) {
2139 if (fWidgetId == -1) {
2140 out <<");" << std::endl;
2141 } else {
2142 out << "," << fWidgetId << ");" << std::endl;
2143 }
2144 } else {
2145 out << "," << fWidgetId << "," << parGC << ");" << std::endl;
2146 }
2147 } else {
2148 out << "," << fWidgetId << "," << parGC << "," << parFont << ");" << std::endl;
2149 }
2150 } else {
2151 out << "," << fWidgetId << "," << parGC << "," << parFont << "," << GetOptionString() << ");" << std::endl;
2152 }
2153
2154 TGButton::SavePrimitive(out,option);
2155 if (fState == kButtonDisabled) {
2157 out << " " << GetName() << "->SetDisabledAndSelected(kTRUE);" << std::endl;
2158 else
2159 out << " " << GetName() << "->SetDisabledAndSelected(kFALSE);" << std::endl;
2160 }
2161 out << " " << GetName() << "->SetTextJustify(" << fTMode << ");" << std::endl;
2162 out << " " << GetName() << "->SetMargins(" << fMLeft << "," << fMRight << ",";
2163 out << fMTop << "," << fMBottom << ");" << std::endl;
2164 out << " " << GetName() << "->SetWrapLength(" << fWrapLength << ");" << std::endl;
2165}
2166
2167////////////////////////////////////////////////////////////////////////////////
2168/// Create a menu button widget. The hotstring will be adopted and
2169/// deleted by the menu button. This constructor creates a
2170/// menubutton with a popup menu attached that appears when the
2171/// button for it is clicked. The popup menu is adopted.
2172
2174 TGPopupMenu *popmenu, Bool_t split, Int_t id,
2175 GContext_t norm, FontStruct_t fontstruct, UInt_t options)
2176 : TGTextButton(p, menulabel, id, norm, fontstruct, options)
2177{
2178 fFontStruct = fontstruct;
2179 fMBWidth = 16;
2180 fMenuLabel = new TGHotString(*menulabel);
2181 fPopMenu = popmenu;
2182 fPopMenu->fSplitButton = this;
2183 fSplit = split;
2184 fTMode = 0;
2185 fHKeycode = 0;
2188 fWidestLabel = "";
2189 fHeighestLabel = "";
2190
2191 // Find and set the correct size for the menu and the button.
2192 TGMenuEntry *entry = 0;
2193 TGHotString lstring(*fMenuLabel);
2194 TGHotString hstring(*fMenuLabel);
2195 const TList *list = fPopMenu->GetListOfEntries();
2196 UInt_t lwidth = 0, lheight = 0;
2197 UInt_t twidth = 0, theight = 0;
2198
2200 if (!font) {
2202 if (font) fFontStruct = font->GetFontStruct();
2203 }
2204
2205 if (font) font->ComputeTextLayout(lstring, lstring.GetLength(),
2207 &lwidth, &lheight);
2208
2209 TIter iter(list);
2210 entry = (TGMenuEntry *)iter.Next();
2211 while (entry != 0) {
2212 if (entry->GetType() == kMenuEntry) {
2213 const TGHotString string(*(entry->GetLabel()));
2214 if (font) font->ComputeTextLayout(string, string.GetLength(),
2216 &twidth, &theight);
2217 if(twidth > lwidth) {
2218 lstring = string;
2219 }
2220 if(theight > lheight) {
2221 hstring = string;
2222 }
2223 }
2224 entry = (TGMenuEntry *)iter.Next();
2225 }
2226 fWidestLabel = lstring;
2227 fHeighestLabel = hstring;
2228
2229 if (font) {
2230 UInt_t dummy = 0;
2231 font->ComputeTextLayout(lstring, lstring.GetLength(),
2233 &fTWidth, &dummy);
2234 font->ComputeTextLayout(hstring, hstring.GetLength(),
2236 &dummy, &fTHeight);
2237 }
2238 fTBWidth = fTWidth + 8;
2239 fHeight = fTHeight + 7;
2241
2243
2244 // Save the id of the 1st item on the menu.
2245 TIter iter1(list);
2246 do {
2247 entry = (TGMenuEntry *)iter1.Next();
2248 if ((entry) && (entry->GetStatus() & kMenuEnableMask) &&
2249 !(entry->GetStatus() & kMenuHideMask) &&
2250 (entry->GetType() != kMenuSeparator) &&
2251 (entry->GetType() != kMenuLabel)) break;
2252 entry = (TGMenuEntry *)iter1.Next();
2253 } while (entry);
2254 if (entry) fEntryId = entry->GetEntryId();
2255
2256 // An additional connection that is needed.
2257 fPopMenu->Connect("Activated(Int_t)", "TGSplitButton", this, "HandleMenu(Int_t)");
2259
2260 Init();
2261}
2262
2263
2264////////////////////////////////////////////////////////////////////////////////
2265/// Common initialization used by the different ctors.
2266
2268{
2269 Int_t hotchar;
2270
2272 fHKeycode = 0;
2274 fPrevStateOn =
2275 fStateOn = kFALSE;
2277
2279
2280 if ((hotchar = fLabel->GetHotChar()) != 0) {
2281 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
2283 if (main) {
2284 main->BindKey(this, fHKeycode, kKeyMod1Mask);
2285 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2286 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2288
2289 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2293 }
2294 }
2295 }
2298 wattr.fBitGravity = 5; // center
2299 wattr.fWinGravity = 1;
2300 gVirtualX->ChangeWindowAttributes(fId, &wattr);
2301
2302 // Make sure motion is detected too.
2304
2305 SetWindowName();
2306}
2307
2308////////////////////////////////////////////////////////////////////////////////
2309/// Delete a split button widget.
2310
2312{
2313 if (fPopMenu) delete fPopMenu;
2314 if (fMenuLabel) delete fMenuLabel;
2315}
2316
2317////////////////////////////////////////////////////////////////////////////////
2318/// Draw triangle (arrow) on which user can click to open Popup.
2319
2321{
2322 Point_t points[3];
2323
2324 points[0].fX = x;
2325 points[0].fY = y;
2326 points[1].fX = x + 5;
2327 points[1].fY = y;
2328 points[2].fX = x + 2;
2329 points[2].fY = y + 3;
2330
2331 gVirtualX->FillPolygon(fId, gc, points, 3);
2332}
2333
2334////////////////////////////////////////////////////////////////////////////////
2335/// Calculate the size of the button.
2336
2338{
2339 Int_t max_ascent, max_descent;
2341 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2342 fTHeight = max_ascent + max_descent;
2343
2344 fTBWidth = fTWidth + 8;
2345 fHeight = fTHeight + 7;
2346 fWidth = fTBWidth;
2347}
2348
2349////////////////////////////////////////////////////////////////////////////////
2350/// Handle mouse button event in case the button is split.
2351
2353{
2354 if (fState == kButtonDisabled) return kFALSE;
2355
2356 Bool_t activate = kFALSE;
2357 Bool_t bclick = kFALSE;
2358 static Bool_t mbpress = kFALSE;
2359 static Bool_t tbpress = kFALSE;
2360 static Bool_t outpress = kFALSE;
2361
2362 Bool_t inTB = (event->fX >= 0) && (event->fY >= 0) &&
2363 (event->fX <= (Int_t)fTBWidth) && (event->fY <= (Int_t)fHeight);
2364
2365 Bool_t inMB = (event->fX >= (Int_t)(fWidth -fMBWidth)) && (event->fY >= 0) &&
2366 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
2367
2368 // We don't need to check the button number as GrabButton will
2369 // only allow button1 events
2370
2371 if (inTB) {
2372 if (event->fType == kButtonPress) {
2373 mbpress = kFALSE;
2374 tbpress = kTRUE;
2375 fgReleaseBtn = 0;
2376 if (fState == kButtonEngaged) {
2377 return kTRUE;
2378 }
2380 Pressed();
2381 } else { // ButtonRelease
2382 if (fMBState == kButtonDown) {
2384 }
2385 if (fState == kButtonEngaged && tbpress) {
2387 Released();
2388 bclick = kTRUE;
2389 } else if (fState == kButtonDown && tbpress) {
2390 tbpress = kFALSE;
2391 if (fStayDown) {
2392 bclick = kTRUE;
2394 fgReleaseBtn = 0;
2395 } else {
2396 bclick = kTRUE;
2398 Released();
2399 fgReleaseBtn = fId;
2400 }
2401 }else {
2403 }
2404 }
2405 } else if (inMB) {
2406 if (event->fType == kButtonPress) {
2407 fgReleaseBtn = 0;
2408 mbpress = kTRUE;
2409 tbpress = kFALSE;
2410 if (fMBState == kButtonEngaged) {
2411 return kTRUE;
2412 }
2414 MBPressed();
2417 } else { // ButtonRelease
2418 if (fState == kButtonDown) {
2420 }
2421 if (fMBState == kButtonEngaged && mbpress) {
2422 mbpress = kFALSE;
2425 MBReleased();
2426 MBClicked();
2427 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2428 } else if (fMBState == kButtonDown && mbpress) {
2429 MBClicked();
2432 fgReleaseBtn = 0;
2433 } else {
2435 }
2436 }
2437 } else {
2438 if (event->fType == kButtonPress) {
2439 fgReleaseBtn = 0;
2440 outpress = kTRUE;
2441 } else { // ButtonRelease
2442 if(outpress) {
2443 outpress = kFALSE;
2446 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2447 activate = kTRUE;
2448 }
2449 }
2450 }
2451 if (bclick) {
2452 Clicked();
2454 (Long_t) fUserData);
2456 (Long_t) fUserData);
2457 }
2458 if (activate) {
2459 TGMenuEntry *entry = fPopMenu->GetCurrent();
2460 if (entry) {
2461 if ((entry->GetStatus() & kMenuEnableMask) &&
2462 !(entry->GetStatus() & kMenuHideMask) &&
2463 (entry->GetType() != kMenuSeparator) &&
2464 (entry->GetType() != kMenuLabel)) {
2465 Int_t id = entry->GetEntryId();
2466 fPopMenu->Activated(id);
2467 }
2468 }
2469 }
2470 // if (mbclick) {
2471 // MBClicked();
2472 // SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2473 // (Long_t) fUserData);
2474 // fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2475 // (Long_t) fUserData);
2476 // }
2477 return kTRUE;
2478}
2479
2480////////////////////////////////////////////////////////////////////////////////
2481/// Handle mouse crossing event in case of split menu.
2482
2484{
2485 if (fTip) {
2486 if (event->fType == kEnterNotify)
2487 fTip->Reset();
2488 else
2489 fTip->Hide();
2490 }
2491
2492 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
2493
2494 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
2495 return kTRUE;
2496
2497 if (fState == kButtonEngaged || fState == kButtonDisabled) return kTRUE;
2498
2499 Bool_t inTB = (event->fX <= (Int_t)fTBWidth);
2500
2501 // Bool_t inMB = (event->fX >= (Int_t)(fWidth -fMBWidth)) && (event->fY >= 0) &&
2502 // (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
2503
2504 if (event->fType == kEnterNotify) {
2505 if (inTB) {
2507 } else {
2508 if(fMBState == kButtonEngaged) return kTRUE;
2510 }
2511 } else {
2512 // kLeaveNotify
2513 if(fState == kButtonDown) {
2515 }
2516 if (fMBState == kButtonEngaged) return kTRUE;
2518 }
2519 return kTRUE;
2520}
2521
2522////////////////////////////////////////////////////////////////////////////////
2523/// Handle key event. This function will be called when the hotkey is hit.
2524
2526{
2527 if (fState == kButtonDisabled) return kFALSE;
2528
2529 Bool_t click = kFALSE;
2530
2531 if (event->fType == kGKeyPress) {
2532 gVirtualX->SetKeyAutoRepeat(kFALSE);
2533 } else {
2534 gVirtualX->SetKeyAutoRepeat(kTRUE);
2535 }
2536
2537 if (fTip && event->fType == kGKeyPress) fTip->Hide();
2538
2539 // We don't need to check the key number as GrabKey will only
2540 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
2541
2542 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
2543 if (fState == kButtonEngaged) return kTRUE;
2545 Pressed();
2546 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
2547 if (fState == kButtonEngaged) {
2549 Released();
2550 }
2551 if (fStayDown) {
2553 } else {
2555 Released();
2556 }
2557 click = kTRUE;
2558 }
2559 if (click) {
2560 Clicked();
2562 (Long_t) fUserData);
2564 (Long_t) fUserData);
2565 }
2566
2567 return kTRUE;
2568}
2569
2570////////////////////////////////////////////////////////////////////////////////
2571/// Popup the attached menu.
2572
2574{
2575 if (state) {
2576 Int_t ax, ay;
2577 Window_t wdummy;
2578
2579 if (fSplit) {
2580 Int_t n_entries = 0;
2581 TGMenuEntry *entry = 0;
2583
2584 while ((entry = (TGMenuEntry *) next())) {
2585 if ((entry->GetType() != kMenuSeparator) &&
2586 (entry->GetType() != kMenuLabel)) {
2587 n_entries++;
2588 }
2589 }
2590 if (n_entries <= 1) {
2591 Info("TGSplitButton", "Only one entry in the menu.");
2592 return;
2593 }
2594 }
2595
2596 gVirtualX->TranslateCoordinates(fId, fPopMenu->GetParent()->GetId(),
2597 0, 0, ax, ay, wdummy);
2598
2599 // place the menu just under the window:
2600 fPopMenu->PlaceMenu(ax-1, ay+fHeight, kTRUE, kFALSE); //kTRUE);
2601 BindKeys(kTRUE);
2603 } else {
2608 }
2609}
2610
2611////////////////////////////////////////////////////////////////////////////////
2612/// Draw the text button.
2613
2615{
2616 int x, y;
2618
2621
2622 if (fTMode & kTextLeft) {
2623 x = fMLeft + 4;
2624 } else if (fTMode & kTextRight) {
2625 x = fWidth - fTWidth -fMBWidth - fMRight - 4;
2626 } else {
2627 x = (fWidth - fTWidth -fMBWidth + fMLeft - fMRight) >> 1;
2628 }
2629
2630 if (fTMode & kTextTop) {
2631 y = fMTop + 3;
2632 } else if (fTMode & kTextBottom) {
2633 y = fHeight - fTHeight - fMBottom - 3;
2634 } else {
2635 y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
2636 }
2637
2638 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
2639 if (fState == kButtonEngaged) {
2640 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
2641 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
2642 }
2643
2644 Int_t hotpos = fLabel->GetHotPos();
2645
2646 if (fState == kButtonDisabled) {
2648 TGGC *gc = pool->FindGC(fNormGC);
2649 if (gc) {
2650 Pixel_t fore = gc->GetForeground();
2653
2654 gc->SetForeground(hi);
2655 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
2656 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x + 1, y + 1, hotpos - 1);
2657
2658 gc->SetForeground(sh);
2659 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
2660 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
2661 gc->SetForeground(fore);
2662 }
2663 } else {
2664 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
2665 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
2666 }
2667
2668 // Draw the parts of the button needed when a menu is attached.
2669
2670 // triangle position
2671 x = fWidth - 11;
2672 y = fHeight - 10;
2673
2674 if (fSplit) {
2675 // separator position
2676 Int_t lx = fWidth - fMBWidth;
2677 Int_t ly = 2;
2678 Int_t lh = fHeight - 2;
2679
2681 x++;
2682 y++;
2683 }
2684
2685 gVirtualX->DrawLine(fId, GetShadowGC()(), lx, ly + 2, lx, lh - 4);
2686 gVirtualX->DrawLine(fId, GetHilightGC()(), lx + 1, ly + 2, lx + 1, lh - 3);
2687 gVirtualX->DrawLine(fId, GetHilightGC()(), lx, lh - 3, lx + 1, lh - 3);
2688
2689 if (fMBState == kButtonEngaged) {
2690 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), fTBWidth + 1, 1, fMBWidth - 3, fHeight - 3);
2691 }
2692
2693 if (fMBState == kButtonDisabled) {
2694 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
2695 DrawTriangle(GetShadowGC()(), x, y);
2696 } else {
2698 }
2699
2700 } else {
2701 x -= 2;
2703 x++;
2704 y++;
2705 }
2706 if (fState == kButtonDisabled) {
2707 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
2708 DrawTriangle(GetShadowGC()(), x, y);
2709 } else {
2711 }
2712 }
2713
2714}
2715
2716////////////////////////////////////////////////////////////////////////////////
2717/// If on kTRUE bind arrow, popup menu hot keys, otherwise
2718/// remove key bindings.
2719
2721{
2722 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up), kAnyModifier, on);
2723 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down), kAnyModifier, on);
2724 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter), kAnyModifier, on);
2725 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return), kAnyModifier, on);
2726 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Escape), kAnyModifier, on);
2727}
2728
2729////////////////////////////////////////////////////////////////////////////////
2730/// If on kTRUE bind Menu hot keys, otherwise remove key bindings.
2731
2733{
2734 TGMenuEntry *e = 0;
2736
2737 while ((e = (TGMenuEntry*)next())) {
2738 Int_t hot = 0;
2739 if (e->GetLabel()) {
2740 hot = e->GetLabel()->GetHotChar();
2741 }
2742 if (!hot) continue;
2743 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), 0, on);
2744 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask, on);
2745 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask, on);
2746 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyMod2Mask, on);
2747 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask, on);
2748 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyMod2Mask, on);
2749 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask | kKeyMod2Mask, on);
2750 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask | kKeyMod2Mask, on);
2751 }
2752}
2753
2754////////////////////////////////////////////////////////////////////////////////
2755/// returns default size
2756
2758{
2761 return TGDimension(w, h);
2762}
2763
2764////////////////////////////////////////////////////////////////////////////////
2765/// Set new button text.
2766
2768{
2769 Int_t hotchar;
2770 static Bool_t longlabeltip = kFALSE;
2772
2774 if (!font) {
2776 if (font) fFontStruct = font->GetFontStruct();
2777 }
2778
2779 UInt_t width = 0, bwidth = 0, dummy;
2780 if (font) {
2781 font->ComputeTextLayout(new_label->GetString(), new_label->GetLength(),
2783 &width, &dummy);
2786 &bwidth, &dummy);
2787 }
2788 if (width > bwidth) {
2789 if (!fTip) {
2790 SetToolTipText(new_label->GetString());
2791 longlabeltip = kTRUE;
2792 }
2793 Info("TGSplitbutton", "Length of new label to long, label truncated.");
2794 new_label->Resize(fWidestLabel.GetLength());
2795 } else if (new_label->GetLength() <= fWidestLabel.GetLength() && longlabeltip) {
2796 if (fTip) delete fTip;
2797 fTip = 0;
2798 longlabeltip = kFALSE;
2799 }
2800
2801 if (fLabel) {
2802 if (main && fHKeycode) {
2803 main->RemoveBind(this, fHKeycode, kKeyMod1Mask);
2804 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2805 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2806 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
2807
2808 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2809 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
2810 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
2812 }
2813 delete fLabel;
2814 }
2815
2816 fLabel = new_label;
2817 if ((hotchar = fLabel->GetHotChar()) != 0) {
2818 if (main && ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0)) {
2819 main->BindKey(this, fHKeycode, kKeyMod1Mask);
2820 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2821 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2823
2824 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2828 }
2829 }
2830
2831 Layout();
2832}
2833
2834////////////////////////////////////////////////////////////////////////////////
2835/// Set new button text.
2836
2837void TGSplitButton::SetText(const TString &new_label)
2838{
2839 SetText(new TGHotString(new_label));
2840}
2841
2842////////////////////////////////////////////////////////////////////////////////
2843/// Changes text font.
2844/// If global is kTRUE font is changed globally, otherwise - locally.
2845
2847{
2848 if (font != fFontStruct) {
2849 FontH_t v = gVirtualX->GetFontHandle(font);
2850 if (!v) return;
2851
2852 fFontStruct = font;
2854 TGGC *gc = pool->FindGC(fNormGC);
2855
2856 if ((gc) && !global) {
2857 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
2859 }
2860 if (gc) {
2861 gc->SetFont(v);
2862 fNormGC = gc->GetGC();
2863 }
2864 fClient->NeedRedraw(this);
2865 }
2866}
2867
2868////////////////////////////////////////////////////////////////////////////////
2869/// Changes text font specified by name.
2870/// If global is true color is changed globally, otherwise - locally.
2871
2872void TGSplitButton::SetFont(const char *fontName, Bool_t global)
2873{
2874 TGFont *font = fClient->GetFont(fontName);
2875 if (font) {
2876 SetFont(font->GetFontStruct(), global);
2877 }
2878}
2879
2880////////////////////////////////////////////////////////////////////////////////
2881/// Set the state of the Menu Button part
2882
2884{
2885 if (state != fMBState) {
2886 fMBState = state;
2887 DoRedraw();
2888 }
2889}
2890
2891////////////////////////////////////////////////////////////////////////////////
2892/// Set the split status of a button.
2893
2895{
2896 if(split) {
2897 fStayDown = kFALSE;
2898 Disconnect(fPopMenu, "PoppedDown()");
2899 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "SetMBState(=kButtonUp)");
2900 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "MBReleased()");
2901
2903 if (entry) {
2904 TGHotString *tmp = new TGHotString(*(entry->GetLabel()));
2905 SetText(tmp);
2906
2907 TString str("ItemClicked(=");
2908 str += entry->GetEntryId();
2909 str += ")";
2910 Connect("Clicked()", "TGSplitButton", this, str);
2911 fEntryId = entry->GetEntryId();
2913 }
2914 } else {
2915 fStayDown = kTRUE;
2916 Disconnect(fPopMenu, "PoppedDown()");
2917 Disconnect(this, "Clicked()", this);
2918 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "SetState(=kButtonUp)");
2919 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "Released()");
2921 TGHotString *tmp = new TGHotString(*fMenuLabel);
2922 SetText(tmp);
2923 }
2924
2925 fSplit = split;
2926 DoRedraw();
2927}
2928
2929////////////////////////////////////////////////////////////////////////////////
2930/// Handle button events.
2931
2933{
2934 if (fState == kButtonDisabled) return kFALSE;
2935
2936 if (fSplit) return HandleSButton(event);
2937
2938 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
2939 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
2940
2941 Bool_t activate = kFALSE;
2942 Bool_t click = kFALSE;
2943
2944 if (in) {
2945 if (event->fType == kButtonPress) {
2946 fgReleaseBtn = 0;
2947 if (fState == kButtonEngaged) {
2948 return kTRUE;
2949 }
2951 Pressed();
2954 } else { // ButtonRelease
2955 if (fState == kButtonEngaged) {
2958 Released();
2959 click = kTRUE;
2960 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2961 } else {
2962 click = (fState == kButtonDown);
2963 if (click && fStayDown) {
2966 fgReleaseBtn = 0;
2967 } else {
2969 Released();
2970 fgReleaseBtn = fId;
2971 }
2972 }
2974 }
2975 } else {
2976 if (event->fType == kButtonPress) {
2977 fgReleaseBtn = 0;
2978 } else { // ButtonRelease
2981 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2982 activate = kTRUE;
2983 }
2984 }
2985 if (click) {
2986 Clicked();
2988 (Long_t) fUserData);
2990 (Long_t) fUserData);
2991 }
2992 if (activate && !fKeyNavigate) {
2993 TGMenuEntry *entry = fPopMenu->GetCurrent();
2994 if (entry) {
2995 if ((entry->GetStatus() & kMenuEnableMask) &&
2996 !(entry->GetStatus() & kMenuHideMask) &&
2997 (entry->GetType() != kMenuSeparator) &&
2998 (entry->GetType() != kMenuLabel)) {
2999 Int_t id = entry->GetEntryId();
3000 fPopMenu->Activated(id);
3001 }
3002 }
3003 }
3004
3005 return kTRUE;
3006
3007}
3008
3009////////////////////////////////////////////////////////////////////////////////
3010/// Handle mouse crossing event.
3011
3013{
3014 if (fSplit) {
3015 return HandleSCrossing(event);
3016 } else {
3018 }
3019}
3020
3021////////////////////////////////////////////////////////////////////////////////
3022/// Handle key event. This function will be called when the hotkey is hit.
3023
3025{
3026 Bool_t click = kFALSE;
3027
3028 if (fState == kButtonDisabled) return kTRUE;
3029
3030 if(fSplit) return HandleSKey(event);
3031
3032 if (event->fType == kGKeyPress) {
3033 gVirtualX->SetKeyAutoRepeat(kFALSE);
3034 } else {
3035 gVirtualX->SetKeyAutoRepeat(kTRUE);
3036 }
3037
3038 if (fTip && event->fType == kGKeyPress) fTip->Hide();
3039
3040 // We don't need to check the key number as GrabKey will only
3041 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
3042 if (event->fState & kKeyMod1Mask) {
3043 RequestFocus();
3045 if (event->fType == kGKeyPress) {
3046 if (fState == kButtonEngaged) return kTRUE;
3048 Pressed();
3049 } else if (event->fType == kKeyRelease) {
3050 click = kTRUE;
3051 if (fState == kButtonEngaged) {
3054 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3055 } else if (fState == kButtonDown && fStayDown) {
3060 TGMenuEntry *entry = 0;
3062
3063 while ((entry = (TGMenuEntry *) next())) {
3064 if ((entry->GetStatus() & kMenuEnableMask) &&
3065 !(entry->GetStatus() & kMenuHideMask) &&
3066 (entry->GetType() != kMenuSeparator) &&
3067 (entry->GetType() != kMenuLabel)) break;
3068 }
3069 if (entry) {
3070 fPopMenu->Activate(entry);
3071 }
3072 } else {
3073 Released();
3075 }
3076 }
3077 } else {
3079 if (event->fType == kGKeyPress) {
3080 Event_t ev;
3081 ev.fX = ev.fY = 1;
3082 UInt_t keysym;
3083 char tmp[2];
3084
3085 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
3086
3087 TGMenuEntry *ce = 0;
3089
3090 while ((ce = (TGMenuEntry*)next())) {
3091 UInt_t hot = 0;
3092 if (ce->GetLabel()) hot = ce->GetLabel()->GetHotChar();
3093 if (!hot || (hot != keysym)) continue;
3094
3095 fPopMenu->Activate(ce);
3096 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3098 ev.fType = kButtonRelease;
3099 ev.fWindow = fPopMenu->GetId();
3101 return HandleButton(&ev);
3102 }
3103
3104 ce = fPopMenu->GetCurrent();
3105
3106 switch ((EKeySym)keysym) {
3107 case kKey_Up:
3108 if (ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Before(ce);
3109 while (ce && ((ce->GetType() == kMenuSeparator) ||
3110 (ce->GetType() == kMenuLabel) ||
3111 !(ce->GetStatus() & kMenuEnableMask))) {
3113 }
3114 if (!ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Last();
3115 break;
3116 case kKey_Down:
3117 if (ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->After(ce);
3118 while (ce && ((ce->GetType() == kMenuSeparator) ||
3119 (ce->GetType() == kMenuLabel) ||
3120 !(ce->GetStatus() & kMenuEnableMask))) {
3122 }
3123 if (!ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->First();
3124 break;
3125 case kKey_Enter:
3126 case kKey_Return:
3127 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3129 ev.fType = kButtonRelease;
3130 ev.fWindow = fPopMenu->GetId();
3132 HandleButton(&ev);
3133 break;
3134 case kKey_Escape:
3135 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3137 break;
3138 default:
3139 break;
3140 }
3141 if (ce) fPopMenu->Activate(ce);
3142 }
3143 }
3144 if (click) {
3145 Clicked();
3147 (Long_t) fUserData);
3149 (Long_t) fUserData);
3150 }
3151
3152 return kTRUE;
3153}
3154
3155////////////////////////////////////////////////////////////////////////////////
3156/// Handle a motion event in a TGSplitButton.
3157
3159{
3160 if (fKeyNavigate) return kTRUE;
3161
3162 if (fSplit) {
3163 if (fMBState == kButtonDown) {
3164 if (event->fX < (Int_t)fTBWidth) {
3167 }
3168 } else if (fState == kButtonDown) {
3169 if (event->fX > (Int_t)fTBWidth) {
3172 }
3173
3174 }
3175 }
3176 return kTRUE;
3177}
3178
3179////////////////////////////////////////////////////////////////////////////////
3180/// layout text button
3181
3183{
3184 UInt_t dummya = 0, dummyb = 0;
3186
3188 if (!font) {
3190 if (font) fFontStruct = font->GetFontStruct();
3191 }
3192 if (font) {
3194 fLabel->GetLength(),
3196 &dummya, &dummyb);
3197 UInt_t dummy = 0;
3200 &fTWidth, &dummy);
3203 &dummy, &fTHeight);
3204 }
3205 fTBWidth = fTWidth + 8;
3207 fHeight = fTHeight + 7;
3208 fClient->NeedRedraw(this);
3209}
3210
3211////////////////////////////////////////////////////////////////////////////////
3212/// Handle a menu item activation.
3213
3215{
3217
3218 if (fSplit) {
3220 Disconnect(this, "Clicked()", this);
3221 // connect clicked to the ItemClicked signal with the correct id
3222 Connect("Clicked()", "TGSplitButton", this,
3223 TString::Format("ItemClicked(=%d)", id));
3224
3225 // reenable hidden entries
3226 const TList *list = fPopMenu->GetListOfEntries();
3227 TIter iter(list);
3229 TGMenuEntry *entry = fPopMenu->GetEntry(id);
3230 if (entry) {
3231 TGHotString *label = entry->GetLabel();
3232 TGHotString *tmp = new TGHotString(*label);
3233 SetText(tmp);
3234 }
3235 fPopMenu->HideEntry(id);
3236 if (entry) fEntryId = entry->GetEntryId();
3237 } else {
3239 ItemClicked(id);
3240 }
3241 DoRedraw();
3242}
void Class()
Definition: Class.C:29
@ kGKeyPress
Definition: GuiTypes.h:60
@ kButtonRelease
Definition: GuiTypes.h:60
@ kButtonPress
Definition: GuiTypes.h:60
@ kEnterNotify
Definition: GuiTypes.h:61
@ kKeyRelease
Definition: GuiTypes.h:60
@ kLeaveNotify
Definition: GuiTypes.h:61
const Mask_t kWABitGravity
Definition: GuiTypes.h:144
const Mask_t kGCBackground
Definition: GuiTypes.h:289
const Mask_t kGCForeground
Definition: GuiTypes.h:288
const Mask_t kGCTile
Definition: GuiTypes.h:296
const Mask_t kKeyLockMask
Definition: GuiTypes.h:196
const Mask_t kButtonPressMask
Definition: GuiTypes.h:161
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition: GuiTypes.h:35
const Mask_t kKeyMod1Mask
typically the Alt key
Definition: GuiTypes.h:198
const Mask_t kGCFillStyle
Definition: GuiTypes.h:294
const Mask_t kWAWinGravity
Definition: GuiTypes.h:145
const Mask_t kAnyModifier
Definition: GuiTypes.h:210
Handle_t Pixmap_t
Pixmap handle.
Definition: GuiTypes.h:30
const Mask_t kButton1Mask
Definition: GuiTypes.h:203
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:163
const Mask_t kKeyShiftMask
Definition: GuiTypes.h:195
@ kChildFrame
Definition: GuiTypes.h:379
@ kRaisedFrame
Definition: GuiTypes.h:384
@ kSunkenFrame
Definition: GuiTypes.h:383
@ kDoubleBorder
Definition: GuiTypes.h:385
@ kFixedWidth
Definition: GuiTypes.h:387
@ kFixedHeight
Definition: GuiTypes.h:389
@ kFixedSize
Definition: GuiTypes.h:390
@ kOwnBackground
Definition: GuiTypes.h:391
const Handle_t kNone
Definition: GuiTypes.h:88
const Mask_t kKeyMod2Mask
typically mod on numeric keys
Definition: GuiTypes.h:199
const Mask_t kButton3Mask
Definition: GuiTypes.h:205
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:168
@ kFillTiled
Definition: GuiTypes.h:51
const Mask_t kButton2Mask
Definition: GuiTypes.h:204
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:162
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:302
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:167
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
@ kButton1
Definition: GuiTypes.h:214
Handle_t Window_t
Window handle.
Definition: GuiTypes.h:29
EKeySym
Definition: KeySymbols.h:25
@ kKey_Down
Definition: KeySymbols.h:43
@ kKey_Up
Definition: KeySymbols.h:41
@ kKey_Return
Definition: KeySymbols.h:30
@ kKey_Escape
Definition: KeySymbols.h:26
@ kKey_Enter
Definition: KeySymbols.h:31
#define SafeDelete(p)
Definition: RConfig.hxx:536
#define h(i)
Definition: RSha256.hxx:106
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
long Long_t
Definition: RtypesCore.h:54
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
EButtonState
Definition: TGButton.h:52
@ kButtonDown
Definition: TGButton.h:54
@ kButtonDisabled
Definition: TGButton.h:56
@ kButtonUp
Definition: TGButton.h:53
@ kButtonEngaged
Definition: TGButton.h:55
#define gClient
Definition: TGClient.h:157
@ kDeepCleanup
Definition: TGFrame.h:42
@ kMenuHideMask
Definition: TGMenu.h:29
@ kMenuEnableMask
Definition: TGMenu.h:25
@ kMenuEntry
Definition: TGMenu.h:38
@ kMenuSeparator
Definition: TGMenu.h:36
@ kMenuLabel
Definition: TGMenu.h:37
@ kTextCenterX
Definition: TGWidget.h:25
@ kTextLeft
Definition: TGWidget.h:23
@ kTextBottom
Definition: TGWidget.h:27
@ kTextTop
Definition: TGWidget.h:26
@ kTextRight
Definition: TGWidget.h:24
@ kTextCenterY
Definition: TGWidget.h:28
@ kWidgetIsEnabled
Definition: TGWidget.h:37
@ kWidgetWantFocus
Definition: TGWidget.h:35
XFontStruct * id
Definition: TGX11.cxx:109
char name[80]
Definition: TGX11.cxx:110
float type_of_call hi(const int &, const int &)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
#define gVirtualX
Definition: TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kC_COMMAND
@ kCM_BUTTON
@ kCM_RADIOBUTTON
@ kCM_CHECKBUTTON
point * points
Definition: X3DBuffer.c:22
int main(int argc, char *argv[])
Definition: cef_main.cxx:54
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
Organizes TGButton widgets in a group.
Definition: TGButtonGroup.h:21
virtual void Remove(TGButton *button)
Removes a button from the button group.
virtual Int_t Insert(TGButton *button, int id=-1)
Inserts a button with the identifier id into the button group.
A button abstract base class.
Definition: TGButton.h:68
virtual void SetGroup(TGButtonGroup *gr)
Sets new button-group for this button.
Definition: TGButton.cxx:322
virtual void Pressed()
Definition: TGButton.h:133
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition: TGButton.cxx:470
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:445
virtual EButtonState GetState() const
Definition: TGButton.h:112
UInt_t fStyle
button style (modern or classic)
Definition: TGButton.h:83
TGButtonGroup * fGroup
button group this button belongs to
Definition: TGButton.h:80
Pixel_t fBgndColor
actual background color
Definition: TGButton.h:81
static const TGGC & GetHibckgndGC()
Return graphics context for highlighted frame background.
Definition: TGButton.cxx:480
virtual void SetDown(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.cxx:310
static Window_t fgReleaseBtn
Definition: TGButton.h:91
Pixel_t fHighColor
highlight color
Definition: TGButton.h:82
virtual void Released()
Definition: TGButton.h:134
virtual void EmitSignals(Bool_t wasUp)
Emit button signals.
Definition: TGButton.cxx:385
UInt_t fTWidth
button width
Definition: TGButton.h:73
UInt_t fTHeight
button height
Definition: TGButton.h:74
virtual void SetStyle(UInt_t newstyle)
Set the button style (modern or classic).
Definition: TGButton.cxx:271
void * fUserData
pointer to user data structure
Definition: TGButton.h:78
static const TGGC * fgHibckgndGC
Definition: TGButton.h:89
virtual ~TGButton()
Delete button.
Definition: TGButton.cxx:221
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGButton.cxx:404
virtual Bool_t IsToggleButton() const
Definition: TGButton.h:121
virtual void Clicked()
Definition: TGButton.h:135
TGButton(const TGButton &)=delete
EButtonState fState
button state
Definition: TGButton.h:75
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:459
static const TGGC * fgDefaultGC
Definition: TGButton.h:88
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition: TGButton.cxx:235
TGToolTip * fTip
tool tip associated with button
Definition: TGButton.h:79
virtual void Toggled(Bool_t on)
Definition: TGButton.h:136
virtual Bool_t IsDown() const
Definition: TGButton.cxx:301
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGButton.cxx:330
Bool_t fStayDown
true if button has to stay down
Definition: TGButton.h:76
GContext_t fNormGC
graphics context used for drawing button
Definition: TGButton.h:77
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a button widget as a C++ statement(s) on output stream out.
Definition: TGButton.cxx:1879
Selects different options.
Definition: TGButton.h:264
const TGPicture * fOff
button OFF picture
Definition: TGButton.h:274
virtual ~TGCheckButton()
Delete a check button.
Definition: TGButton.cxx:1225
virtual void EmitSignals(Bool_t wasUp=kTRUE)
Emit signals.
Definition: TGButton.cxx:1262
static const TGFont * fgDefaultFont
Definition: TGButton.h:284
static const TGGC * fgDefaultGC
Definition: TGButton.h:285
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGButton.cxx:1330
const TGPicture * fOn
button ON picture
Definition: TGButton.h:273
void Init()
Common check button initialization.
Definition: TGButton.cxx:1179
virtual void DoRedraw()
Draw the check button widget.
Definition: TGButton.cxx:1437
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition: TGButton.cxx:1503
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
Definition: TGButton.cxx:1493
virtual void SetDisabledAndSelected(Bool_t)
Set the state of a check button to disabled and either on or off.
Definition: TGButton.cxx:1310
virtual Bool_t IsDisabledAndSelected() const
Definition: TGButton.h:313
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1250
TGCheckButton(const TGCheckButton &)=delete
virtual Bool_t HandleKey(Event_t *event)
Handle key event. This function will be called when the hotkey is hit.
Definition: TGButton.cxx:1403
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a check button widget as a C++ statement(s) on output stream out.
Definition: TGButton.cxx:2034
EButtonState fPrevState
previous check button state
Definition: TGButton.h:272
const TGPicture * fDisOff
button disabled and was OFF picture
Definition: TGButton.h:276
virtual TGDimension GetDefaultSize() const
default size
Definition: TGButton.cxx:1236
const TGPicture * fDisOn
button disabled and was ON picture
Definition: TGButton.h:275
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGButton.cxx:1374
void PSetState(EButtonState state, Bool_t emit)
Set check button state.
Definition: TGButton.cxx:1273
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:236
void ProcessLine(TString cmd, Long_t msg, Long_t parm1, Long_t parm2)
Execute string "cmd" via the interpreter.
Definition: TGClient.cxx:916
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition: TGClient.cxx:350
const TGResourcePool * GetResourcePool() const
Definition: TGClient.h:124
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:291
TGGCPool * GetGCPool() const
Definition: TGClient.h:131
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:374
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:126
TGFontPool * GetFontPool() const
Definition: TGClient.h:136
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:310
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get the specified font.
Definition: TGFont.cxx:1558
TGFont * FindFont(FontStruct_t font) const
Find font based on its font struct. Returns 0 if font is not found.
Definition: TGFont.cxx:1744
Encapsulate fonts used in the GUI system.
Definition: TGFont.h:140
FontStruct_t GetFontStruct() const
Definition: TGFont.h:184
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save the used font as a C++ statement(s) on output stream out.
Definition: TGFont.cxx:1884
TGTextLayout * ComputeTextLayout(const char *string, Int_t numChars, Int_t wrapLength, Int_t justify, Int_t flags, UInt_t *width, UInt_t *height) const
Computes the amount of screen space needed to display a multi-line, justified string of text.
Definition: TGFont.cxx:661
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition: TGFrame.h:80
virtual void ChangeOptions(UInt_t options)
Change frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:321
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:252
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:339
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:430
UInt_t fOptions
frame options
Definition: TGFrame.h:94
UInt_t fHeight
frame height
Definition: TGFrame.h:88
Int_t fBorderWidth
frame border width
Definition: TGFrame.h:93
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:755
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:645
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition: TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2504
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:765
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
UInt_t fWidth
frame width
Definition: TGFrame.h:87
UInt_t GetHeight() const
Definition: TGFrame.h:225
static Window_t fgDbw
Definition: TGFrame.h:113
UInt_t GetWidth() const
Definition: TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2477
Pixel_t fBackground
frame background color
Definition: TGFrame.h:95
static Pixel_t fgDefaultFrameBackground
Definition: TGFrame.h:101
Definition: TGGC.h:103
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
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition: TGGC.cxx:951
Encapsulate a graphics context used in the low level graphics.
Definition: TGGC.h:22
GContext_t GetGC() const
Definition: TGGC.h:41
void SavePrimitive(std::ostream &out, Option_t *option="")
Save graphics context info as a C++ statement(s) on output stream out.
Definition: TGGC.cxx:627
void SetFont(FontH_t v)
Set font.
Definition: TGGC.cxx:411
Pixel_t GetForeground() const
Definition: TGGC.h:73
void SetForeground(Pixel_t v)
Set foreground color.
Definition: TGGC.cxx:278
const GCValues_t * GetAttributes() const
Definition: TGGC.h:69
TGHotString is a string with a "hot" character underlined.
Definition: TGString.h:42
Int_t GetHotPos() const
Definition: TGString.h:58
Int_t GetHotChar() const
Definition: TGString.h:57
Defines top level windows that interact with the system Window Manager.
Definition: TGFrame.h:398
This class contains all information about a menu entry.
Definition: TGMenu.h:57
TGHotString * GetLabel() const
Definition: TGMenu.h:89
virtual Int_t GetStatus() const
Definition: TGMenu.h:86
EMenuEntryType GetType() const
Definition: TGMenu.h:87
Int_t GetEntryId() const
Definition: TGMenu.h:83
TGClient * fClient
Connection to display server.
Definition: TGObject.h:27
Handle_t GetId() const
Definition: TGObject.h:37
Handle_t fId
X11/Win32 Window identifier.
Definition: TGObject.h:26
Yield an action as soon as it is clicked.
Definition: TGButton.h:228
virtual void SetPicture(const TGPicture *new_pic)
Change a picture in a picture button.
Definition: TGButton.cxx:1040
virtual void CreateDisabledPicture()
Creates disabled picture.
Definition: TGButton.cxx:1108
virtual void SetDisabledPicture(const TGPicture *pic)
Changes disabled picture.
Definition: TGButton.cxx:1135
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a picture button widget as a C++ statement(s) on output stream out.
Definition: TGButton.cxx:1983
const TGPicture * fPicD
picture shown when button disabled
Definition: TGButton.h:232
const TGPicture * fPic
picture to be put in button
Definition: TGButton.h:231
virtual ~TGPictureButton()
Destructor.
Definition: TGButton.cxx:1030
TGPictureButton(const TGPictureButton &)=delete
Bool_t fOwnDisabledPic
kTRUE if disabled picture was autogenerated
Definition: TGButton.h:233
virtual void DoRedraw()
Redraw picture button.
Definition: TGButton.cxx:1064
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
Pixmap_t GetMask() const
Definition: TGPicture.h:55
const char * GetName() const
Returns name of object.
Definition: TGPicture.h:51
UInt_t GetHeight() const
Definition: TGPicture.h:53
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:46
Pixmap_t GetPicture() const
Definition: TGPicture.h:54
UInt_t GetWidth() const
Definition: TGPicture.h:52
This class creates a popup menu object.
Definition: TGMenu.h:110
virtual void HideEntry(Int_t id)
Hide entry (hidden entries are not shown in the menu).
Definition: TGMenu.cxx:1751
virtual TGMenuEntry * GetEntry(Int_t id)
Find entry with specified id.
Definition: TGMenu.cxx:1897
TGSplitButton * fSplitButton
split button (if any)
Definition: TGMenu.h:134
virtual void Activate(Bool_t)
Definition: TGMenu.h:209
virtual void EnableEntry(Int_t id)
Enable entry. By default entries are enabled.
Definition: TGMenu.cxx:1705
virtual Int_t EndMenu(void *&userData)
Close menu and return ID of selected menu item.
Definition: TGMenu.cxx:1289
virtual TGMenuEntry * GetCurrent() const
Definition: TGMenu.h:198
virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
Popup a popup menu.
Definition: TGMenu.cxx:1241
const TList * GetListOfEntries() const
Definition: TGMenu.h:200
virtual void Activated(Int_t id)
Definition: TGMenu.h:219
Selects different options.
Definition: TGButton.h:322
const TGPicture * fOn
button ON picture
Definition: TGButton.h:330
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
Definition: TGButton.cxx:1859
static const TGGC * fgDefaultGC
Definition: TGButton.h:341
const TGPicture * fDisOn
button disabled and was ON picture
Definition: TGButton.h:332
virtual void DoRedraw()
Draw a radio button.
Definition: TGButton.cxx:1802
virtual Bool_t HandleKey(Event_t *event)
Handle key event. This function will be called when the hotkey is hit.
Definition: TGButton.cxx:1772
virtual ~TGRadioButton()
Delete a radio button.
Definition: TGButton.cxx:1589
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGButton.cxx:1743
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGButton.cxx:1694
EButtonState fPrevState
previous radio button state
Definition: TGButton.h:329
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set radio button state.
Definition: TGButton.cxx:1613
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition: TGButton.cxx:1869
const TGPicture * fDisOff
button disabled and was OFF picture
Definition: TGButton.h:333
virtual TGDimension GetDefaultSize() const
default size
Definition: TGButton.cxx:1600
static const TGFont * fgDefaultFont
Definition: TGButton.h:340
virtual Bool_t IsDisabledAndSelected() const
Definition: TGButton.h:372
virtual void SetDisabledAndSelected(Bool_t)
Set the state of a radio button to disabled and either on or off.
Definition: TGButton.cxx:1626
const TGPicture * fOff
button OFF picture
Definition: TGButton.h:331
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a radio button widget as a C++ statement(s) on output stream out.
Definition: TGButton.cxx:2102
void PSetState(EButtonState state, Bool_t emit)
Set radio button state.
Definition: TGButton.cxx:1657
void Init()
Common radio button initialization.
Definition: TGButton.cxx:1545
virtual void EmitSignals(Bool_t wasUp=kTRUE)
Emit signals.
Definition: TGButton.cxx:1646
TGRadioButton(const TGRadioButton &)=delete
Cursor_t GetGrabCursor() const
TGGCPool * GetGCPool() const
Implements a button with added menu functionality.
Definition: TGButton.h:379
void CalcSize()
Calculate the size of the button.
Definition: TGButton.cxx:2337
virtual Bool_t HandleKey(Event_t *event)
Handle key event. This function will be called when the hotkey is hit.
Definition: TGButton.cxx:3024
virtual void ItemClicked(Int_t id)
Definition: TGButton.h:442
Bool_t HandleSKey(Event_t *event)
Handle key event. This function will be called when the hotkey is hit.
Definition: TGButton.cxx:2525
TGPopupMenu * fPopMenu
pointer to popup menu
Definition: TGButton.h:401
virtual void Layout()
layout text button
Definition: TGButton.cxx:3182
void DrawTriangle(const GContext_t gc, Int_t x, Int_t y)
Draw triangle (arrow) on which user can click to open Popup.
Definition: TGButton.cxx:2320
Int_t fEntryId
Id of the currently active menu entry.
Definition: TGButton.h:402
Bool_t fSplit
kTRUE if menu is in split mode
Definition: TGButton.h:397
virtual void MBClicked()
Definition: TGButton.h:441
EButtonState fMBState
state for menu button in split mode
Definition: TGButton.h:398
TGSplitButton(const TGSplitButton &)=delete
void Init()
Common initialization used by the different ctors.
Definition: TGButton.cxx:2267
virtual Bool_t HandleButton(Event_t *event)
Handle button events.
Definition: TGButton.cxx:2932
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGButton.cxx:3012
virtual Bool_t HandleMotion(Event_t *event)
Handle a motion event in a TGSplitButton.
Definition: TGButton.cxx:3158
Bool_t HandleSButton(Event_t *event)
Handle mouse button event in case the button is split.
Definition: TGButton.cxx:2352
void BindKeys(Bool_t on=kTRUE)
If on kTRUE bind arrow, popup menu hot keys, otherwise remove key bindings.
Definition: TGButton.cxx:2720
Cursor_t fDefaultCursor
Default Cursor.
Definition: TGButton.h:404
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:2767
void SetMenuState(Bool_t state)
Popup the attached menu.
Definition: TGButton.cxx:2573
UInt_t fMBWidth
width of menu button
Definition: TGButton.h:400
Bool_t HandleSCrossing(Event_t *event)
Handle mouse crossing event in case of split menu.
Definition: TGButton.cxx:2483
void BindMenuKeys(Bool_t on=kTRUE)
If on kTRUE bind Menu hot keys, otherwise remove key bindings.
Definition: TGButton.cxx:2732
virtual ~TGSplitButton()
Delete a split button widget.
Definition: TGButton.cxx:2311
virtual void MBReleased()
Definition: TGButton.h:440
TGHotString * fMenuLabel
Label of the menu;.
Definition: TGButton.h:403
void HandleMenu(Int_t id)
Handle a menu item activation.
Definition: TGButton.cxx:3214
virtual void SetFont(FontStruct_t font, Bool_t global=kFALSE)
Changes text font.
Definition: TGButton.cxx:2846
virtual TGDimension GetDefaultSize() const
returns default size
Definition: TGButton.cxx:2757
TGString fHeighestLabel
highest label that can be on the button
Definition: TGButton.h:407
UInt_t fTBWidth
width of text button
Definition: TGButton.h:399
virtual void MBPressed()
Definition: TGButton.h:439
virtual void SetMBState(EButtonState state)
Set the state of the Menu Button part.
Definition: TGButton.cxx:2883
Bool_t fKeyNavigate
kTRUE if key navigation is being used
Definition: TGButton.h:405
virtual void SetSplit(Bool_t split)
Set the split status of a button.
Definition: TGButton.cxx:2894
TGString fWidestLabel
longest label that can be on the button
Definition: TGButton.h:406
virtual void DoRedraw()
@]
Definition: TGButton.cxx:2614
Int_t GetLength() const
Definition: TGString.h:29
const char * GetString() const
Definition: TGString.h:30
Yield an action as soon as it is clicked.
Definition: TGButton.h:142
void Init()
Common initialization used by the different ctors.
Definition: TGButton.cxx:541
virtual void Layout()
layout text button
Definition: TGButton.cxx:624
virtual Bool_t HandleKey(Event_t *event)
Handle key event. This function will be called when the hotkey is hit.
Definition: TGButton.cxx:815
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
Definition: TGButton.cxx:869
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a text button widget as a C++ statement(s) on output stream out.
Definition: TGButton.cxx:1916
Int_t fMTop
Definition: TGButton.h:148
Int_t fMBottom
Definition: TGButton.h:149
virtual void SetTextJustify(Int_t tmode)
Set text justification.
Definition: TGButton.cxx:695
Bool_t fHasOwnFont
Definition: TGButton.h:155
Bool_t fStateOn
Definition: TGButton.h:156
Int_t fHKeycode
Definition: TGButton.h:152
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:644
TGTextButton(const TGTextButton &)=delete
static const TGFont * fgDefaultFont
Definition: TGButton.h:159
Int_t fMRight
Definition: TGButton.h:147
virtual ~TGTextButton()
Delete a text button widget.
Definition: TGButton.cxx:595
TGHotString * fLabel
Definition: TGButton.h:145
Bool_t HasOwnFont() const
Returns kTRUE if text attributes are unique, returns kFALSE if text attributes are shared (global).
Definition: TGButton.cxx:938
virtual void DoRedraw()
Draw the text button.
Definition: TGButton.cxx:747
Bool_t fPrevStateOn
Definition: TGButton.h:157
virtual void SetFont(FontStruct_t font, Bool_t global=kFALSE)
Changes text font.
Definition: TGButton.cxx:880
virtual TGDimension GetDefaultSize() const
returns default size
Definition: TGButton.cxx:859
Int_t fTMode
Definition: TGButton.h:150
Int_t fWrapLength
Definition: TGButton.h:151
TGTextLayout * fTLayout
Definition: TGButton.h:153
FontStruct_t fFontStruct
Definition: TGButton.h:154
virtual void SetTextColor(Pixel_t color, Bool_t global=kFALSE)
Changes text color.
Definition: TGButton.cxx:918
Int_t fMLeft
Definition: TGButton.h:146
void DrawText(Drawable_t dst, GContext_t gc, Int_t x, Int_t y, Int_t firstChar, Int_t lastChar) const
Use the information in the TGTextLayout object to display a multi-line, justified string of text.
Definition: TGFont.cxx:923
void UnderlineChar(Drawable_t dst, GContext_t gc, Int_t x, Int_t y, Int_t underline) const
Use the information in the TGTextLayout object to display an underline below an individual character.
Definition: TGFont.cxx:970
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:250
const TGString * GetText() const
Get the tool tip text.
Definition: TGToolTip.cxx:430
void Reset()
Reset tool tip popup delay timer.
Definition: TGToolTip.cxx:263
Int_t fWidgetId
the widget id (used for event processing)
Definition: TGWidget.h:46
TString fCommand
command to be executed
Definition: TGWidget.h:49
Int_t fWidgetFlags
widget status flags (OR of EWidgetStatus)
Definition: TGWidget.h:47
const TGWindow * fMsgWindow
window which handles widget events
Definition: TGWidget.h:48
ROOT GUI Window base class.
Definition: TGWindow.h:23
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:129
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:152
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:336
virtual void RequestFocus()
request focus
Definition: TGWindow.cxx:232
const TGWindow * fParent
Parent window.
Definition: TGWindow.h:28
virtual Int_t MustCleanup() const
Definition: TGWindow.h:109
const TGWindow * GetParent() const
Definition: TGWindow.h:76
An abstract interface to image processing library.
Definition: TImage.h:29
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
static TImage * Create()
Create an image.
Definition: TImage.cxx:35
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:172
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
virtual void FillRectangle(const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:192
virtual Pixmap_t GetMask()
Definition: TImage.h:236
TObject * Next()
Definition: TCollection.h:251
A doubly linked list.
Definition: TList.h:44
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition: TList.cxx:330
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:693
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition: TList.cxx:371
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:659
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:867
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:869
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1027
void AddReference()
Definition: TRefCnt.h:40
Basic string class.
Definition: TString.h:136
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:649
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:523
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1120
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2336
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2314
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1274
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition: TSystem.cxx:1063
TText * text
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
static constexpr double s
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Event structure.
Definition: GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition: GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition: GuiTypes.h:178
Window_t fWindow
window reported event is relative to
Definition: GuiTypes.h:176
Int_t fX
Definition: GuiTypes.h:178
Graphics context structure.
Definition: GuiTypes.h:224
ULong_t fBackground
background pixel
Definition: GuiTypes.h:228
Mask_t fMask
bit mask specifying which fields are valid
Definition: GuiTypes.h:251
Pixmap_t fTile
tile pixmap for tiling operations
Definition: GuiTypes.h:238
Bool_t fGraphicsExposures
boolean, should exposures be generated
Definition: GuiTypes.h:244
ULong_t fForeground
foreground pixel
Definition: GuiTypes.h:227
Int_t fFillStyle
kFillSolid, kFillTiled, kFillStippled, kFillOpaeueStippled
Definition: GuiTypes.h:234
Point structure (maps to the X11 XPoint structure)
Definition: GuiTypes.h:356
Attributes that can be used when creating or changing a window.
Definition: GuiTypes.h:93
Mask_t fMask
bit mask specifying which fields are valid
Definition: GuiTypes.h:110
Int_t fWinGravity
one of the window gravity values
Definition: GuiTypes.h:100
Int_t fBitGravity
one of bit gravity values
Definition: GuiTypes.h:99
TCanvas * style()
Definition: style.C:1