Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
168
169////////////////////////////////////////////////////////////////////////////////
170/// Create button base class part.
171
173 : TGFrame(p, 1, 1, options)
174{
175 fWidgetId = id;
177 fMsgWindow = p;
178 fUserData = 0;
179 fTip = 0;
180 fGroup = 0;
181 fStyle = 0;
182 fTWidth = fTHeight = 0;
183
184 fNormGC = norm;
188
189// fStyle = gClient->GetStyle();
190// if (fStyle > 0) {
191// fOptions &= ~(kRaisedFrame | kDoubleBorder);
192// }
193
194 // coverity[returned_null]
195 // coverity[dereference]
196 if (p && p->IsA()->InheritsFrom(TGButtonGroup::Class())) {
197 TGButtonGroup *bg = (TGButtonGroup*) p;
198 bg->Insert(this, id);
199 }
200
202 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
203
204 gVirtualX->GrabButton(fId, kButton1, kAnyModifier,
206 kNone, kNone);
207
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Delete button.
214
216{
217 // remove from button group
218 if (fGroup) {
219 fGroup->Remove(this);
220 fGroup = 0;
221 }
222
223 if (fTip) delete fTip;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Set button state.
228
230{
231 Bool_t was = !IsDown(); // kTRUE if button was off
232
233 if (state == kButtonDisabled)
235 else
237 if (state != fState) {
238 switch (state) {
239 case kButtonEngaged:
240 case kButtonDown:
243 break;
244 case kButtonDisabled:
245 case kButtonUp:
246 if (fStyle > 0) {
249 }
250 else {
253 }
254 break;
255 }
256 fState = state;
257 DoRedraw();
258 if (emit || fGroup) EmitSignals(was);
259 }
260}
261
262////////////////////////////////////////////////////////////////////////////////
263/// Set the button style (modern or classic).
264
266{
267 fStyle = newstyle;
269 if (fStyle > 0) {
271 }
272 else {
274 }
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Set the button style (modern or classic).
279
280void TGButton::SetStyle(const char *style)
281{
283 if (style && strstr(style, "modern")) {
284 fStyle = 1;
286 }
287 else {
288 fStyle = 0;
290 }
291}
292
293////////////////////////////////////////////////////////////////////////////////
294
296{
297 if (fStyle > 0)
298 return (fOptions & kSunkenFrame);
299 return !(fOptions & kRaisedFrame);
300}
301
302////////////////////////////////////////////////////////////////////////////////
303
305{
306 // Set button state down according to the parameter 'on'.
307
308 if (GetState() == kButtonDisabled) return;
309
310 SetState(on ? kButtonDown : kButtonUp, emit);
311}
312
313////////////////////////////////////////////////////////////////////////////////
314/// Sets new button-group for this button.
315
320
321////////////////////////////////////////////////////////////////////////////////
322/// Handle mouse button event.
323
325{
326 Bool_t click = kFALSE;
327
328 if (fTip) fTip->Hide();
329
330 if (fState == kButtonDisabled) return kTRUE;
331
332 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
333 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
334
335 // We don't need to check the button number as GrabButton will
336 // only allow button1 events
337 if (event->fType == kButtonPress) {
338 fgReleaseBtn = 0;
339
340 if (fState == kButtonEngaged) {
341 return kTRUE;
342 }
343 if (in) SetState(kButtonDown, kTRUE);
344 } else { // ButtonRelease
345 if (fState == kButtonEngaged) {
346 if (in) SetState(kButtonUp, kTRUE);
347 click = kTRUE;
348 } else {
349 click = (fState == kButtonDown) && in;
350 if (click && fStayDown) {
351 if (in) {
353 fgReleaseBtn = 0;
354 }
355 } else {
356 if (in) {
359 }
360 }
361 }
362 }
363 if (click) {
368 }
369 if ((fStyle > 0) && (event->fType == kButtonRelease)) {
371 }
372 DoRedraw();
373 return kTRUE;
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// Emit button signals.
378
380{
381 Bool_t now = !IsDown(); // kTRUE if button now is off
382
383 // emit signals
384 if (was && !now) {
385 Pressed(); // emit Pressed = was off , now on
386 if (fStayDown) Clicked(); // emit Clicked
387 }
388 if (!was && now) {
389 Released(); // emit Released = was on , now off
390 Clicked(); // emit Clicked
391 }
392 if ((was != now) && IsToggleButton()) Toggled(!now); // emit Toggled = was != now
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Handle mouse crossing event.
397
399{
400 if (fTip) {
401 if (event->fType == kEnterNotify)
402 fTip->Reset();
403 else
404 fTip->Hide();
405 }
406
407 if (fStyle > 0) {
408 if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
410 } else {
412 }
413 if (event->fType == kLeaveNotify) {
415 }
416 DoRedraw();
417 }
418
419 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
420
421 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
422 return kTRUE;
423
424 if (fState == kButtonEngaged || fState == kButtonDisabled) return kTRUE;
425
426 if (event->fType == kLeaveNotify) {
429 }
430 DoRedraw();
431 return kTRUE;
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Set tool tip text associated with this button. The delay is in
436/// milliseconds (minimum 250). To remove tool tip call method with
437/// text = 0.
438
439void TGButton::SetToolTipText(const char *text, Long_t delayms)
440{
441 if (fTip) {
442 delete fTip;
443 fTip = 0;
444 }
445
446 if (text && strlen(text))
447 fTip = new TGToolTip(fClient->GetDefaultRoot(), this, text, delayms);
448}
449
450////////////////////////////////////////////////////////////////////////////////
451/// Set enabled or disabled state of button
452
460
461////////////////////////////////////////////////////////////////////////////////
462/// Return default graphics context.
463
465{
466 if (!fgDefaultGC)
467 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
468 return *fgDefaultGC;
469}
470
471////////////////////////////////////////////////////////////////////////////////
472/// Return graphics context for highlighted frame background.
473
475{
476 if (!fgHibckgndGC) {
477 GCValues_t gval;
480 gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
481 gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
482 gval.fFillStyle = kFillTiled;
483 gval.fTile = gClient->GetResourcePool()->GetCheckeredPixmap();
485 fgHibckgndGC = gClient->GetGC(&gval, kTRUE);
486 }
487 return *fgHibckgndGC;
488}
489
490
491////////////////////////////////////////////////////////////////////////////////
492/// Create a text button widget. The hotstring will be adopted and deleted
493/// by the text button.
494
496 GContext_t norm, FontStruct_t font,
497 UInt_t options) : TGButton(p, id, norm, options)
498{
499 fLabel = s;
500 fFontStruct = font;
501
502 Init();
503}
504
505////////////////////////////////////////////////////////////////////////////////
506/// Create a text button widget.
507
508TGTextButton::TGTextButton(const TGWindow *p, const char *s, Int_t id,
509 GContext_t norm, FontStruct_t font,
510 UInt_t options) : TGButton(p, id, norm, options)
511{
512 fLabel = new TGHotString(!p && !s ? GetName() : s);
513 fFontStruct = font;
514
515 Init();
516}
517
518////////////////////////////////////////////////////////////////////////////////
519/// Create a text button widget and set cmd string at same time.
520
521TGTextButton::TGTextButton(const TGWindow *p, const char *s, const char *cmd,
522 Int_t id, GContext_t norm, FontStruct_t font,
523 UInt_t options) : TGButton(p, id, norm, options)
524{
525 fLabel = new TGHotString(s);
526 fFontStruct = font;
527 fCommand = cmd;
528
529 Init();
530}
531
532////////////////////////////////////////////////////////////////////////////////
533/// Common initialization used by the different ctors.
534
536{
537 int hotchar;
538
540 fHKeycode = 0;
544 fWrapLength = -1;
545 fMLeft = fMRight = fMTop = fMBottom = 0;
546
547 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
548 if (!font) {
549 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
550 if (font) fFontStruct = font->GetFontStruct();
551 }
552 if (font) {
553 fTLayout = font->ComputeTextLayout(fLabel->GetString(), fLabel->GetLength(),
555 &fTWidth, &fTHeight);
556 }
557 Resize();
558 fWidth = fTWidth;
560
561 if ((hotchar = fLabel->GetHotChar()) != 0) {
562 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
564 if (main) {
565 main->BindKey(this, fHKeycode, kKeyMod1Mask);
566 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
567 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
569
570 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
574 }
575 }
576 }
579 wattr.fBitGravity = 5; // center
580 wattr.fWinGravity = 1;
581 gVirtualX->ChangeWindowAttributes(fId, &wattr);
582
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Delete a text button widget.
588
590{
591 if (fHKeycode && (fParent->MustCleanup() != kDeepCleanup)) {
593 if (main) {
594 main->RemoveBind(this, fHKeycode, kKeyMod1Mask);
595 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
596 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
597 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
598
599 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
600 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
601 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
603 }
604 }
605 if (fLabel) delete fLabel;
606 if (fHasOwnFont) {
607 TGGCPool *pool = fClient->GetGCPool();
608 TGGC *gc = pool->FindGC(fNormGC);
609 pool->FreeGC(gc);
610 }
611
612 delete fTLayout;
613}
614
615////////////////////////////////////////////////////////////////////////////////
616/// layout text button
617
619{
621
622 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
623 if (!font) {
624 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
625 if (font) fFontStruct = font->GetFontStruct();
626 }
627 if (font) {
628 fTLayout = font->ComputeTextLayout(fLabel->GetString(), fLabel->GetLength(),
630 &fTWidth, &fTHeight);
631 }
632 fClient->NeedRedraw(this);
633}
634
635////////////////////////////////////////////////////////////////////////////////
636/// Set new button text.
637
639{
640 int hotchar;
642
643 if (fLabel) {
644 if (main && fHKeycode) {
645 main->RemoveBind(this, fHKeycode, kKeyMod1Mask);
646 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
647 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
648 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
649
650 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
651 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
652 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
654 }
655 delete fLabel;
656 }
657
658 fLabel = new_label;
659 if ((hotchar = fLabel->GetHotChar()) != 0) {
660 if (main && ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0)) {
661 main->BindKey(this, fHKeycode, kKeyMod1Mask);
662 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
663 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
665
666 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
670 }
671 }
672
673 Layout();
674}
675
676////////////////////////////////////////////////////////////////////////////////
677/// Set new button text.
678
679void TGTextButton::SetText(const TString &new_label)
680{
681 SetText(new TGHotString(new_label));
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Set text justification. Mode is an OR of the bits:
686/// kTextTop, kTextBottom, kTextLeft, kTextRight, kTextCenterX and
687/// kTextCenterY.
688
690{
691 fTMode = mode;
692
695 wattr.fWinGravity = 1;
696
697 switch (mode) {
698 case kTextTop | kTextLeft:
699 wattr.fBitGravity = 1; //NorthWestGravity
700 break;
701 case kTextTop | kTextCenterX:
702 case kTextTop:
703 wattr.fBitGravity = 2; //NorthGravity
704 break;
705 case kTextTop | kTextRight:
706 wattr.fBitGravity = 3; //NorthEastGravity
707 break;
708 case kTextLeft | kTextCenterY:
709 case kTextLeft:
710 wattr.fBitGravity = 4; //WestGravity
711 break;
713 wattr.fBitGravity = 5; //CenterGravity
714 break;
716 case kTextRight:
717 wattr.fBitGravity = 6; //EastGravity
718 break;
719 case kTextBottom | kTextLeft:
720 wattr.fBitGravity = 7; //SouthWestGravity
721 break;
723 case kTextBottom:
724 wattr.fBitGravity = 8; //SouthGravity
725 break;
726 case kTextBottom | kTextRight:
727 wattr.fBitGravity = 9; //SouthEastGravity
728 break;
729 default:
730 wattr.fBitGravity = 5; //CenterGravity
731 break;
732 }
733
734 gVirtualX->ChangeWindowAttributes(fId, &wattr);
735 Layout();
736}
737
738////////////////////////////////////////////////////////////////////////////////
739/// Draw the text button.
740
742{
743 int x, y;
744 UInt_t w = GetWidth() - 1;
745 UInt_t h = GetHeight()- 1;
746
747 if ((fStyle > 0) && !(fOptions & kOwnBackground))
748 gVirtualX->SetWindowBackground(fId, fBgndColor);
750
751 if (fTMode & kTextLeft) {
752 x = fMLeft + 4;
753 } else if (fTMode & kTextRight) {
754 x = fWidth - fTWidth - fMRight - 4;
755 } else {
756 x = (fWidth - fTWidth + fMLeft - fMRight) >> 1;
757 }
758
759 if (fTMode & kTextTop) {
760 y = fMTop + 3;
761 } else if (fTMode & kTextBottom) {
762 y = fHeight - fTHeight - fMBottom - 3;
763 } else {
764 y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
765 }
766
768 ++x; ++y;
769 w--; h--;
770 }
771 if (fStyle == 0) {
772 if (fState == kButtonEngaged) {
773 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
774 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
775 }
776 }
777
778 Int_t hotpos = fLabel->GetHotPos();
779
780 if (fStyle > 0) {
781 gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
782 }
783 if (fState == kButtonDisabled) {
784 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
785 TGGC *gc = pool->FindGC(fNormGC);
786 if (gc) {
787 Pixel_t fore = gc->GetForeground();
790
791 gc->SetForeground(hi);
792 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
793 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x + 1, y + 1, hotpos - 1);
794
795 gc->SetForeground(sh);
796 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
797 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
798 gc->SetForeground(fore);
799 }
800 } else {
801 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
802 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
803 }
804}
805
806////////////////////////////////////////////////////////////////////////////////
807/// Handle key event. This function will be called when the hotkey is hit.
808
810{
811 if (fState == kButtonDisabled || !(event->fState & kKeyMod1Mask)) return kFALSE;
812
813 Bool_t click = kFALSE;
814 Bool_t was = !IsDown(); // kTRUE if button was off
815
816 if (event->fType == kGKeyPress) {
817 gVirtualX->SetKeyAutoRepeat(kFALSE);
818 } else {
819 gVirtualX->SetKeyAutoRepeat(kTRUE);
820 }
821
822 if (fTip && event->fType == kGKeyPress) fTip->Hide();
823
824 // We don't need to check the key number as GrabKey will only
825 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
826
827 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
828 if (fState == kButtonEngaged) return kTRUE;
830 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
831 if (fState == kButtonEngaged /*&& !allowRelease*/) return kTRUE;
832 click = (fState == kButtonDown);
833 if (click && fStayDown) {
835 } else {
837 }
838 }
839 if (click) {
844 }
845 EmitSignals(was);
846
847 return kTRUE;
848}
849
850////////////////////////////////////////////////////////////////////////////////
851/// returns default size
852
859
860////////////////////////////////////////////////////////////////////////////////
861/// Return default font structure.
862
864{
865 if (!fgDefaultFont)
866 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
867 return fgDefaultFont->GetFontStruct();
868}
869
870////////////////////////////////////////////////////////////////////////////////
871/// Changes text font.
872/// If global is kTRUE font is changed globally, otherwise - locally.
873
875{
876 if (font != fFontStruct) {
877 FontH_t v = gVirtualX->GetFontHandle(font);
878 if (!v) return;
879
880 fFontStruct = font;
881 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
882 TGGC *gc = pool->FindGC(fNormGC);
883
884 if (gc && !global) {
885 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
887 }
888 if (gc) {
889 gc->SetFont(v);
890 fNormGC = gc->GetGC();
891 }
892 Layout();
893 }
894}
895
896////////////////////////////////////////////////////////////////////////////////
897/// Changes text font specified by name.
898/// If global is true color is changed globally, otherwise - locally.
899
900void TGTextButton::SetFont(const char *fontName, Bool_t global)
901{
902 TGFont *font = fClient->GetFont(fontName);
903 if (font) {
904 SetFont(font->GetFontStruct(), global);
905 }
906}
907
908////////////////////////////////////////////////////////////////////////////////
909/// Changes text color.
910/// If global is true color is changed globally, otherwise - locally.
911
913{
914 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
915 TGGC *gc = pool->FindGC(fNormGC);
916
917 if (gc && !global) {
918 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
920 }
921 if (gc) {
922 gc->SetForeground(color);
923 fNormGC = gc->GetGC();
924 }
925 fClient->NeedRedraw(this);
926}
927
928////////////////////////////////////////////////////////////////////////////////
929/// Returns kTRUE if text attributes are unique,
930/// returns kFALSE if text attributes are shared (global).
931
933{
934 return fHasOwnFont;
935}
936
937////////////////////////////////////////////////////////////////////////////////
938/// Create a picture button widget. The picture is not adopted and must
939/// later be freed by the user once the picture button is deleted (a single
940/// picture reference might be used by other buttons).
941
943 Int_t id, GContext_t norm, UInt_t option) : TGButton(p, id, norm, option)
944{
945 if (!pic) {
946 Error("TGPictureButton", "pixmap not found or the file format is not supported for button %d", id);
947 fPic = fClient->GetPicture("mb_question_s.xpm");
948 } else {
949 fPic = pic;
950 }
951
952 if (fPic) {
953 fTWidth = fPic->GetWidth();
954 fTHeight = fPic->GetHeight();
955
957 fTHeight + (fBorderWidth << 1) + fBorderWidth); // *3
958 }
959 fPicD = 0;
962}
963
964////////////////////////////////////////////////////////////////////////////////
965/// Create a picture button widget and set action command. The picture is
966/// not adopted and must later be freed by the user once the picture button
967/// is deleted (a single picture reference might be used by other
968/// buttons).
969
971 const char *cmd, Int_t id, GContext_t norm, UInt_t option)
972 : TGButton(p, id, norm, option)
973{
974 if (!pic) {
975 Error("TGPictureButton", "pixmap not found or the file format is not supported for button\n%s",
976 cmd ? cmd : "");
977 fPic = fClient->GetPicture("mb_question_s.xpm");
978 } else {
979 fPic = pic;
980 }
981
982 fCommand = cmd;
983
984 if (fPic) {
985 fTWidth = fPic->GetWidth();
986 fTHeight = fPic->GetHeight();
987
989 fTHeight + (fBorderWidth << 1) + fBorderWidth); // *3
990 }
991 fPicD = 0;
994}
995
996////////////////////////////////////////////////////////////////////////////////
997/// Create a picture button. Where pic is the file name of the picture.
998
1000 Int_t id, GContext_t norm, UInt_t option) : TGButton(p, id, norm, option)
1001{
1002 if (!pic || !pic[0]) {
1003 if (p) Error("TGPictureButton", "pixmap not found or the file format is not supported for button");
1004 fPic = fClient->GetPicture("mb_question_s.xpm");
1005 } else {
1006 fPic = fClient->GetPicture(pic);
1007 }
1008
1009 if (fPic) {
1010 fTWidth = fPic->GetWidth();
1011 fTHeight = fPic->GetHeight();
1012
1013 Resize(fTWidth + (fBorderWidth << 1) + fBorderWidth + 1,
1014 fTHeight + (fBorderWidth << 1) + fBorderWidth); // *3
1015 }
1016 fPicD = 0;
1018 SetWindowName();
1019}
1020
1021////////////////////////////////////////////////////////////////////////////////
1022/// Destructor.
1023
1028
1029////////////////////////////////////////////////////////////////////////////////
1030/// Change a picture in a picture button. The picture is not adopted and
1031/// must later be freed by the user once the picture button is deleted
1032/// (a single picture reference might be used by other buttons).
1033
1035{
1036 if (!new_pic) {
1037 Error("SetPicture", "pixmap not found or the file format is not supported for button %d\n%s",
1038 fWidgetId, fCommand.Data());
1039 return;
1040 }
1041
1042 fPic = new_pic;
1043
1044 if (fState == kButtonDisabled) {
1045 fClient->FreePicture(fPicD);
1046 fPicD = 0;
1047 }
1048
1049 fTWidth = fPic->GetWidth();
1050 fTHeight = fPic->GetHeight();
1051
1052 fClient->NeedRedraw(this);
1053}
1054
1055////////////////////////////////////////////////////////////////////////////////
1056/// Redraw picture button.
1057
1059{
1060 if (!fPic) {
1062 return;
1063 }
1064
1065 int x = (fWidth - fTWidth) >> 1;
1066 int y = (fHeight - fTHeight) >> 1;
1067 UInt_t w = GetWidth() - 1;
1068 UInt_t h = GetHeight()- 1;
1069
1070 if ((fStyle > 0) && !(fOptions & kOwnBackground))
1071 gVirtualX->SetWindowBackground(fId, fBgndColor);
1073
1074 if (fState == kButtonDown || fState == kButtonEngaged) {
1075 ++x; ++y;
1076 w--; h--;
1077 }
1078 if (fStyle == 0) {
1079 if (fState == kButtonEngaged) {
1080 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
1081 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
1082 }
1083 }
1084
1085 const TGPicture *pic = fPic;
1086 if (fState == kButtonDisabled) {
1088 pic = fPicD ? fPicD : fPic;
1089 }
1090 if (fStyle > 0) {
1091 if (fBgndColor == fHighColor) {
1092 gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
1093 }
1094 }
1095
1096 pic->Draw(fId, fNormGC, x, y);
1097}
1098
1099////////////////////////////////////////////////////////////////////////////////
1100/// Creates disabled picture.
1101
1103{
1104 TImage *img = TImage::Create();
1105 if (!img) return;
1106 TImage *img2 = TImage::Create();
1107 if (!img2) {
1108 if (img) delete img;
1109 return;
1110 }
1111 TString back = gEnv->GetValue("Gui.BackgroundColor", "#c0c0c0");
1112 img2->FillRectangle(back.Data(), 0, 0, fPic->GetWidth(), fPic->GetHeight());
1113 img->SetImage(fPic->GetPicture(), fPic->GetMask());
1114 Pixmap_t mask = img->GetMask();
1115 img2->Merge(img, "overlay");
1116
1117 TString name = "disbl_";
1118 name += fPic->GetName();
1119 fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), img2->GetPixmap(),
1120 mask);
1122 delete img;
1123 delete img2;
1124}
1125
1126////////////////////////////////////////////////////////////////////////////////
1127/// Changes disabled picture.
1128
1130{
1131 if (!pic) return;
1132
1133 if (fOwnDisabledPic && fPicD) fClient->FreePicture(fPicD);
1134 fPicD = pic;
1135 ((TGPicture*)pic)->AddReference();
1137}
1138
1139////////////////////////////////////////////////////////////////////////////////
1140/// Create a check button widget. The hotstring will be adopted and deleted
1141/// by the check button.
1142
1144 GContext_t norm, FontStruct_t font, UInt_t option)
1145 : TGTextButton(p, s, id, norm, font, option)
1146{
1147 Init();
1148}
1149
1150////////////////////////////////////////////////////////////////////////////////
1151/// Create a check button widget.
1152
1153TGCheckButton::TGCheckButton(const TGWindow *p, const char *s, Int_t id,
1154 GContext_t norm, FontStruct_t font, UInt_t option)
1155 : TGTextButton(p, s, id, norm, font, option)
1156{
1157 Init();
1158}
1159
1160////////////////////////////////////////////////////////////////////////////////
1161/// Create a check button widget.
1162
1163TGCheckButton::TGCheckButton(const TGWindow *p, const char *s, const char *cmd,
1164 Int_t id, GContext_t norm, FontStruct_t font,
1165 UInt_t option) : TGTextButton(p, s, cmd, id, norm, font, option)
1166{
1167 Init();
1168}
1169
1170////////////////////////////////////////////////////////////////////////////////
1171/// Common check button initialization.
1172
1174{
1175 fPrevState =
1176 fState = kButtonUp;
1177 fHKeycode = 0;
1178
1179 fOn = fClient->GetPicture("checked_t.xpm");
1180 fOff = fClient->GetPicture("unchecked_t.xpm");
1181 fDisOn = fClient->GetPicture("checked_dis_t.xpm");
1182 fDisOff = fClient->GetPicture("unchecked_dis_t.xpm");
1183
1184 Resize();
1185
1186 if (!fOn || !fOff || !fDisOn || !fDisOff)
1187 Error("Init", "checked*_t.xpm not found or the file format is not supported.");
1188
1189 int hotchar;
1190
1191 if ((hotchar = fLabel->GetHotChar()) != 0) {
1192 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
1194 if (main) {
1195 main->BindKey(this, fHKeycode, kKeyMod1Mask);
1196 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
1197 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
1199
1200 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
1204 }
1205 }
1206 }
1207 SetWindowName();
1208}
1209
1210////////////////////////////////////////////////////////////////////////////////
1211/// Delete a check button.
1212
1214{
1215 if (fOn) fClient->FreePicture(fOn);
1216 if (fOff) fClient->FreePicture(fOff);
1217 if (fDisOn) fClient->FreePicture(fDisOn);
1218 if (fDisOff) fClient->FreePicture(fDisOff);
1219}
1220
1221////////////////////////////////////////////////////////////////////////////////
1222/// default size
1223
1225{
1226 UInt_t pic_width = fOff ? fOff->GetWidth() : 10;
1227 UInt_t pic_height = fOff ? fOff->GetHeight() : 2;
1228
1229 UInt_t w = !fTWidth ? pic_width : fTWidth + pic_width + 9;
1230 UInt_t h = !fTHeight ? pic_height : fTHeight + 2;
1231
1232 w = GetOptions() & kFixedWidth ? fWidth : w;
1233 h = GetOptions() & kFixedHeight ? fHeight : h;
1234
1235 return TGDimension(w, h);
1236}
1237
1238////////////////////////////////////////////////////////////////////////////////
1239/// Set check button state.
1240
1242{
1243 if (state == kButtonDisabled)
1245 else
1247 PSetState(state, emit);
1248}
1249
1250////////////////////////////////////////////////////////////////////////////////
1251/// Emit signals.
1252
1254{
1255 if (fState == kButtonUp) Released(); // emit Released
1256 if (fState == kButtonDown) Pressed(); // emit Pressed
1257 Clicked(); // emit Clicked
1258 Toggled(fStateOn); // emit Toggled
1259}
1260
1261////////////////////////////////////////////////////////////////////////////////
1262/// Set check button state.
1263
1265{
1266 if (state != fState) {
1267 if (state == kButtonUp) {
1268 if (fPrevState == kButtonDisabled) {
1269 if (fStateOn) {
1272 } else {
1273 fState = state;
1274 fPrevState = state;
1275 }
1276 } else if (fPrevState == kButtonDown) {
1277 fStateOn = kFALSE;
1278 fState = state;
1279 fPrevState = state;
1280 }
1281 } else if (state == kButtonDown) {
1282 fStateOn = kTRUE;
1283 fState = state;
1284 fPrevState = state;
1285 } else {
1286 fState = state;
1287 fPrevState = state;
1288 }
1289 if (emit) {
1290 // button signals
1291 EmitSignals();
1292 }
1293 DoRedraw();
1294 }
1295}
1296
1297////////////////////////////////////////////////////////////////////////////////
1298/// Set the state of a check button to disabled and either on or
1299/// off.
1300
1302{
1303 if (!enable) {
1304 if (fState == kButtonDisabled && fStateOn) {
1305 PSetState(kButtonUp, kFALSE); // enable button
1306 PSetState(kButtonUp, kFALSE); // set button up
1307 PSetState(kButtonDisabled, kFALSE); // disable button
1308 } else {
1311 }
1312 } else {
1313 PSetState(kButtonDown, kFALSE); // set button down
1314 PSetState(kButtonDisabled, kFALSE); // disable button
1315 }
1316}
1317
1318////////////////////////////////////////////////////////////////////////////////
1319/// Handle mouse button event.
1320
1322{
1323 Bool_t click = kFALSE;
1324
1325 if (fTip) fTip->Hide();
1326
1327 if (fState == kButtonDisabled) return kTRUE;
1328
1329 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
1330 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
1331
1332 // We don't need to check the button number as GrabButton will
1333 // only allow button1 events
1334 if (event->fType == kButtonPress) {
1335 fgReleaseBtn = 0;
1336 if (in) {
1338 Pressed();
1339 }
1340 } else { // ButtonRelease
1341 if (in) {
1343 click = kTRUE;
1345 Released();
1346 }
1347 fgReleaseBtn = fId;
1349 }
1350 if (click) {
1351 Clicked();
1357 }
1358 DoRedraw();
1359 return kTRUE;
1360}
1361
1362////////////////////////////////////////////////////////////////////////////////
1363/// Handle mouse crossing event.
1364
1366{
1367 if (fTip) {
1368 if (event->fType == kEnterNotify)
1369 fTip->Reset();
1370 else
1371 fTip->Hide();
1372 }
1373
1374 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
1375
1376 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
1377 return kTRUE;
1378
1379 if (fState == kButtonDisabled) return kTRUE;
1380
1381 if (event->fType == kEnterNotify) {
1383 } else {
1385 }
1386 DoRedraw();
1387
1388 return kTRUE;
1389}
1390
1391////////////////////////////////////////////////////////////////////////////////
1392/// Handle key event. This function will be called when the hotkey is hit.
1393
1395{
1396 Bool_t click = kFALSE;
1397
1398 if (event->fType == kGKeyPress)
1399 gVirtualX->SetKeyAutoRepeat(kFALSE);
1400 else
1401 gVirtualX->SetKeyAutoRepeat(kTRUE);
1402
1403 if (fTip && event->fType == kGKeyPress) fTip->Hide();
1404
1405 if (fState == kButtonDisabled) return kTRUE;
1406
1407 // We don't need to check the key number as GrabKey will only
1408 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
1409
1410 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
1412 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
1413 click = (fState != fPrevState);
1415 }
1416 if (click) {
1421 }
1422 return kTRUE;
1423}
1424
1425////////////////////////////////////////////////////////////////////////////////
1426/// Draw the check button widget.
1427
1429{
1430 int x, y, y0;
1431
1433
1434 x = 20;
1435 y = (fHeight - fTHeight) >> 1;
1436
1437 y0 = !fTHeight ? 0 : y + 1;
1438 if (fOn && fOff) {
1439 Int_t smax = std::max(fOn->GetHeight(), fOff->GetHeight());
1440 y0 = ((Int_t)fHeight <= smax) ? 0 : 1 + (((Int_t)fHeight - smax) >> 1);
1441 }
1442
1443 if (fStateOn) {
1444 if (fOn) fOn->Draw(fId, fNormGC, 0, y0);
1445 } else {
1446 if (fOff) fOff->Draw(fId, fNormGC, 0, y0);
1447 }
1448
1449 Int_t hotpos = fLabel->GetHotPos();
1450
1451 if (fState == kButtonDisabled) {
1452 if (fStateOn == kTRUE) {
1453 if (fDisOn) fDisOn->Draw(fId, fNormGC, 0, y0);
1454 } else {
1455 if (fDisOff) fDisOff->Draw(fId, fNormGC, 0, y0);
1456 }
1457
1458 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
1459 TGGC *gc = pool->FindGC(fNormGC);
1460 if (gc) {
1461 Pixel_t fore = gc->GetForeground();
1464
1465 gc->SetForeground(hi);
1466 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
1467 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
1468
1469 gc->SetForeground(sh);
1470 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
1471 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
1472
1473 gc->SetForeground(fore);
1474 }
1475 } else {
1476 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
1477 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
1478 }
1479}
1480
1481////////////////////////////////////////////////////////////////////////////////
1482/// Return default font structure.
1483
1485{
1486 if (!fgDefaultFont)
1487 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1488 return fgDefaultFont->GetFontStruct();
1489}
1490
1491////////////////////////////////////////////////////////////////////////////////
1492/// Return default graphics context.
1493
1495{
1496 if (!fgDefaultGC)
1497 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1498 return *fgDefaultGC;
1499}
1500
1501
1502////////////////////////////////////////////////////////////////////////////////
1503/// Create a radio button widget. The hotstring will be adopted and deleted
1504/// by the radio button.
1505
1507 GContext_t norm, FontStruct_t font, UInt_t option)
1508 : TGTextButton(p, s, id, norm, font, option)
1509{
1510 Init();
1511}
1512
1513////////////////////////////////////////////////////////////////////////////////
1514/// Create a radio button widget.
1515
1516TGRadioButton::TGRadioButton(const TGWindow *p, const char *s, Int_t id,
1517 GContext_t norm, FontStruct_t font, UInt_t option)
1518 : TGTextButton(p, s, id, norm, font, option)
1519{
1520 Init();
1521}
1522////////////////////////////////////////////////////////////////////////////////
1523/// Create a radio button widget.
1524
1525TGRadioButton::TGRadioButton(const TGWindow *p, const char *s, const char *cmd,
1526 Int_t id, GContext_t norm,
1527 FontStruct_t font, UInt_t option)
1528 : TGTextButton(p, s, cmd, id, norm, font, option)
1529{
1530 Init();
1531}
1532
1533////////////////////////////////////////////////////////////////////////////////
1534/// Common radio button initialization.
1535
1537{
1538 fPrevState =
1539 fState = kButtonUp;
1540 fHKeycode = 0;
1541
1542 fOn = fClient->GetPicture("rbutton_on.xpm");
1543 fOff = fClient->GetPicture("rbutton_off.xpm");
1544 fDisOn = fClient->GetPicture("rbutton_dis_on.xpm");
1545 fDisOff = fClient->GetPicture("rbutton_dis_off.xpm");
1546
1547 if (!fOn || !fOff || !fDisOn || !fDisOff)
1548 Error("Init", "rbutton_*.xpm not found or the file format is not supported.");
1549
1550 Resize();
1551
1552 int hotchar;
1553
1554 if ((hotchar = fLabel->GetHotChar()) != 0) {
1555 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
1557 if (main) {
1558 main->BindKey(this, fHKeycode, kKeyMod1Mask);
1559 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
1560 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
1562
1563 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
1567 }
1568 }
1569 }
1570
1571 if (fParent->IsA()->InheritsFrom(TGButtonGroup::Class())) {
1572 ((TGButtonGroup*)fParent)->SetRadioButtonExclusive(kTRUE);
1573 }
1574 SetWindowName();
1575}
1576
1577////////////////////////////////////////////////////////////////////////////////
1578/// Delete a radio button.
1579
1581{
1582 if (fOn) fClient->FreePicture(fOn);
1583 if (fOff) fClient->FreePicture(fOff);
1584 if (fDisOn) fClient->FreePicture(fDisOn);
1585 if (fDisOff) fClient->FreePicture(fDisOff);
1586}
1587
1588////////////////////////////////////////////////////////////////////////////////
1589/// default size
1590
1592{
1593 UInt_t pic_width = fOff ? fOff->GetWidth() : 10;
1594 UInt_t pic_height = fOff ? fOff->GetHeight() : 2;
1595
1596 UInt_t w = !fTWidth ? pic_width : fTWidth + pic_width + 10;
1597 UInt_t h = !fTHeight ? pic_height : fTHeight + 2;
1598
1599 w = GetOptions() & kFixedWidth ? fWidth : w;
1600 h = GetOptions() & kFixedHeight ? fHeight : h;
1601
1602 return TGDimension(w, h);
1603}
1604
1605////////////////////////////////////////////////////////////////////////////////
1606/// Set radio button state.
1607
1609{
1610 if (state == kButtonDisabled)
1612 else
1614 PSetState(state, emit);
1615}
1616
1617////////////////////////////////////////////////////////////////////////////////
1618/// Set the state of a radio button to disabled and either on or
1619/// off.
1620
1622{
1623 if (!enable) {
1624 if (fState == kButtonDisabled && fStateOn) {
1625 PSetState(kButtonUp, kFALSE); // enable button
1626 PSetState(kButtonUp, kFALSE); // set button up
1627 PSetState(kButtonDisabled, kFALSE); // disable button
1628 } else {
1631 }
1632 } else {
1633 PSetState(kButtonDown, kFALSE); // set button down
1634 PSetState(kButtonDisabled, kFALSE); // disable button
1635 }
1636}
1637
1638////////////////////////////////////////////////////////////////////////////////
1639/// Emit signals.
1640
1642{
1643 if (fState == kButtonUp) Released(); // emit Released
1644 if (fState == kButtonDown) Pressed(); // emit Pressed
1645 Clicked(); // emit Clicked
1646 Toggled(fStateOn); // emit Toggled
1647}
1648
1649////////////////////////////////////////////////////////////////////////////////
1650/// Set radio button state.
1651
1653{
1654 if (state != fState) {
1655 // fPrevState = fState = state;
1656 if (state == kButtonUp) {
1657 if (fPrevState == kButtonDisabled) {
1658 if (fStateOn) {
1661 } else {
1662 fState = state;
1663 fPrevState = state;
1664 }
1665 } else if (fPrevState == kButtonDown) {
1666 fStateOn = kFALSE;
1667 fState = state;
1668 fPrevState = state;
1669 }
1670 } else if (state == kButtonDown) {
1671 fStateOn = kTRUE;
1672 fState = state;
1673 fPrevState = state;
1674 } else {
1675 fState = state;
1676 fPrevState = state;
1677 }
1678 if (emit) {
1679 // button signals
1680 EmitSignals();
1681 }
1682 DoRedraw();
1683 }
1684}
1685
1686////////////////////////////////////////////////////////////////////////////////
1687/// Handle mouse button event.
1688
1690{
1691 Bool_t click = kFALSE;
1692 Bool_t toggled = kFALSE;
1693
1694 if (fTip) fTip->Hide();
1695
1696 if (fState == kButtonDisabled) return kFALSE;
1697
1698
1699 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
1700 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
1701
1702 if (event->fType == kButtonPress) { // button pressed
1703 fgReleaseBtn = 0;
1704 if (in) {
1706 Pressed();
1707 }
1708 } else { // ButtonRelease
1709 if (in) {
1710 if (!fStateOn) {
1712 toggled = kTRUE;
1713 }
1715 Released();
1716 click = kTRUE;
1717 }
1719 fgReleaseBtn = fId;
1720 }
1721 if (click) {
1722 Clicked();
1727 }
1728 if (toggled) {
1730 }
1731 DoRedraw();
1732 return kTRUE;
1733}
1734
1735////////////////////////////////////////////////////////////////////////////////
1736/// Handle mouse crossing event.
1737
1739{
1740 if (fTip) {
1741 if (event->fType == kEnterNotify)
1742 fTip->Reset();
1743 else
1744 fTip->Hide();
1745 }
1746
1747 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
1748
1749 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
1750 return kTRUE;
1751
1752 if (fState == kButtonDisabled) return kTRUE;
1753
1754 if (event->fType == kEnterNotify) {
1756 } else {
1758 }
1759 DoRedraw();
1760
1761 return kTRUE;
1762}
1763
1764////////////////////////////////////////////////////////////////////////////////
1765/// Handle key event. This function will be called when the hotkey is hit.
1766
1768{
1769 if (event->fType == kGKeyPress)
1770 gVirtualX->SetKeyAutoRepeat(kFALSE);
1771 else
1772 gVirtualX->SetKeyAutoRepeat(kTRUE);
1773
1774 if (fTip && event->fType == kGKeyPress)
1775 fTip->Hide();
1776
1777 if (fState == kButtonDisabled) return kTRUE;
1778
1779 // We don't need to check the key number as GrabKey will only
1780 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
1781
1782 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
1788 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
1790 }
1791 return kTRUE;
1792}
1793
1794////////////////////////////////////////////////////////////////////////////////
1795/// Draw a radio button.
1796
1798{
1799 Int_t tx, ty, y0;
1800
1802
1803 tx = 20;
1804 ty = (fHeight - fTHeight) >> 1;
1805
1806// pw = 12;
1807 y0 = !fTHeight ? 0 : ty + 1;
1808 if (fOn && fOff) {
1809 Int_t smax = std::max(fOn->GetHeight(), fOff->GetHeight());
1810 y0 = ((Int_t)fHeight <= smax) ? 0 : 1 + (((Int_t)fHeight - smax) >> 1);
1811 }
1812
1813 if (fStateOn) {
1814 if (fOn) fOn->Draw(fId, fNormGC, 0, y0);
1815 } else {
1816 if (fOff) fOff->Draw(fId, fNormGC, 0, y0);
1817 }
1818
1819 Int_t hotpos = fLabel->GetHotPos();
1820
1821 if (fState == kButtonDisabled) {
1822 if (fStateOn == kTRUE) {
1823 if (fDisOn) fDisOn->Draw(fId, fNormGC, 0, y0);
1824 } else {
1825 if (fDisOff) fDisOff->Draw(fId, fNormGC, 0, y0);
1826 }
1827
1828 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
1829 TGGC *gc = pool->FindGC(fNormGC);
1830 if (gc) {
1831 Pixel_t fore = gc->GetForeground();
1834
1835 gc->SetForeground(hi);
1836 fTLayout->DrawText(fId, gc->GetGC(), tx + 1, ty + 1, 0, -1);
1837 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), tx, ty, hotpos - 1);
1838
1839 gc->SetForeground(sh);
1840 fTLayout->DrawText(fId, gc->GetGC(), tx, ty, 0, -1);
1841 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), tx, ty, hotpos - 1);
1842
1843 gc->SetForeground(fore);
1844 }
1845 } else {
1846 fTLayout->DrawText(fId, fNormGC, tx, ty, 0, -1);
1847 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, tx, ty, hotpos-1);
1848 }
1849}
1850
1851////////////////////////////////////////////////////////////////////////////////
1852/// Return default font structure.
1853
1855{
1856 if (!fgDefaultFont)
1857 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1858 return fgDefaultFont->GetFontStruct();
1859}
1860
1861////////////////////////////////////////////////////////////////////////////////
1862/// Return default graphics context.
1863
1865{
1866 if (!fgDefaultGC)
1867 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1868 return *fgDefaultGC;
1869}
1870
1871////////////////////////////////////////////////////////////////////////////////
1872/// Save a button widget as a C++ statement(s) on output stream out.
1873
1874void TGButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1875{
1876 if (option && strstr(option, "keep_names"))
1877 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
1878
1879 if (fState == kButtonDown)
1880 out << " " << GetName() << "->SetState(kButtonDown);\n";
1881 if (fState == kButtonDisabled)
1882 out << " " << GetName() << "->SetState(kButtonDisabled);\n";
1883 if (fState == kButtonEngaged)
1884 out << " " << GetName() << "->SetState(kButtonEngaged);\n";
1885
1887 SaveUserColor(out, option);
1888 out << " " << GetName() << "->ChangeBackground(ucolor);\n";
1889 }
1890
1891 if (fTip)
1892 out << " " << GetName() << "->SetToolTipText(\""
1893 << TString(fTip->GetText()->GetString()).ReplaceSpecialCppChars() << "\");\n";
1894 if (fCommand.Length() > 0)
1895 out << " " << GetName() << "->SetCommand(\"" << TString(fCommand).ReplaceSpecialCppChars() << "\");\n";
1896}
1897
1898////////////////////////////////////////////////////////////////////////////////
1899/// Save a text button widget as a C++ statement(s) on output stream out.
1900
1901void TGTextButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1902{
1903 TString outext(fLabel->GetString());
1904 if (fLabel->GetHotPos() > 0)
1905 outext.Insert(fLabel->GetHotPos()-1, "&");
1906
1907 // font + GC
1908 option = GetName()+5; // unique digit id of the name
1909 TString parGC, parFont;
1910 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
1911 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
1912
1913 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
1914 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
1915 if (ufont) {
1916 ufont->SavePrimitive(out, option);
1917 parFont.Form("ufont->GetFontStruct()");
1918 }
1919
1920 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
1921 if (userGC) {
1922 userGC->SavePrimitive(out, option);
1923 parGC.Form("uGC->GetGC()");
1924 }
1925 }
1926
1927 out << " TGTextButton *" << GetName() << " = new TGTextButton(" << fParent->GetName()
1928 << ", \"" << outext.ReplaceSpecialCppChars() << "\"";
1929
1930 if (GetOptions() == (kRaisedFrame | kDoubleBorder)) {
1932 if (fNormGC == GetDefaultGC()()) {
1933 if (fWidgetId == -1) {
1934 out << ");\n";
1935 } else {
1936 out << "," << fWidgetId <<");\n";
1937 }
1938 } else {
1939 out << "," << fWidgetId << "," << parGC << ");\n";
1940 }
1941 } else {
1942 out << "," << fWidgetId << "," << parGC << "," << parFont << ");\n";
1943 }
1944 } else {
1945 out << "," << fWidgetId << "," << parGC << "," << parFont << "," << GetOptionString() << ");\n";
1946 }
1947
1948 out << " " << GetName() << "->SetTextJustify(" << fTMode << ");\n";
1949 out << " " << GetName() << "->SetMargins(" << fMLeft << "," << fMRight << "," << fMTop << "," << fMBottom
1950 << ");\n";
1951 out << " " << GetName() << "->SetWrapLength(" << fWrapLength << ");\n";
1952
1953 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
1954
1955 TGButton::SavePrimitive(out,option);
1956}
1957
1958////////////////////////////////////////////////////////////////////////////////
1959/// Save a picture button widget as a C++ statement(s) on output stream out.
1960
1961void TGPictureButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1962{
1963 if (!fPic) {
1964 Error("SavePrimitive", "pixmap not found or the file format is not supported for picture button %d ", fWidgetId);
1965 return;
1966 }
1967
1968 // GC
1969 option = GetName()+5; // unique digit id of the name
1970 TString parGC;
1971 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
1972
1973 if (GetDefaultGC()() != fNormGC) {
1974 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
1975 if (userGC) {
1976 userGC->SavePrimitive(out, option);
1977 parGC.Form("uGC->GetGC()");
1978 }
1979 }
1980
1981 TString picname = gSystem->UnixPathName(fPic->GetName());
1982 gSystem->ExpandPathName(picname);
1983
1984 out << " TGPictureButton *" << GetName() << " = new TGPictureButton(" << fParent->GetName()
1985 << ", gClient->GetPicture(\"" << picname.ReplaceSpecialCppChars() << "\")";
1986
1987 if (GetOptions() == (kRaisedFrame | kDoubleBorder)) {
1988 if (fNormGC == GetDefaultGC()()) {
1989 if (fWidgetId == -1) {
1990 out << ");\n";
1991 } else {
1992 out << "," << fWidgetId << ");\n";
1993 }
1994 } else {
1995 out << "," << fWidgetId << "," << parGC << ");\n";
1996 }
1997 } else {
1998 out << "," << fWidgetId << "," << parGC << "," << GetOptionString() << ");\n";
1999 }
2000
2001 TGButton::SavePrimitive(out,option);
2002}
2003
2004////////////////////////////////////////////////////////////////////////////////
2005/// Save a check button widget as a C++ statement(s) on output stream out.
2006
2007void TGCheckButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2008{
2009 TString outext(fLabel->GetString());
2010 if (fLabel->GetHotPos() > 0)
2011 outext.Insert(fLabel->GetHotPos()-1, "&");
2012
2013 out <<" TGCheckButton *" << GetName() << " = new TGCheckButton(" << fParent->GetName()
2014 << ", \"" << outext.ReplaceSpecialCppChars() << "\"";
2015
2016 // font + GC
2017 option = GetName()+5; // unique digit id of the name
2018 TString parGC, parFont;
2019 parFont.Form("%s::GetDefaultFontStruct()", IsA()->GetName());
2020 parGC.Form("%s::GetDefaultGC()()", IsA()->GetName());
2021
2022 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
2023 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
2024 if (ufont) {
2025 ufont->SavePrimitive(out, option);
2026 parFont.Form("ufont->GetFontStruct()");
2027 }
2028
2029 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
2030 if (userGC) {
2031 userGC->SavePrimitive(out, option);
2032 parGC.Form("uGC->GetGC()");
2033 }
2034 }
2035
2036 if (GetOptions() == kChildFrame) {
2038 if (fNormGC == GetDefaultGC()()) {
2039 if (fWidgetId == -1) {
2040 out << ");\n";
2041 } else {
2042 out << "," << fWidgetId << ");\n";
2043 }
2044 } else {
2045 out << "," << fWidgetId << "," << parGC << ");\n";
2046 }
2047 } else {
2048 out << "," << fWidgetId << "," << parGC << "," << parFont << ");\n";
2049 }
2050 } else {
2051 out << "," << fWidgetId << "," << parGC << "," << parFont << "," << GetOptionString() << ");\n";
2052 }
2053
2054 TGButton::SavePrimitive(out,option);
2055 if (fState == kButtonDisabled) {
2057 out << " " << GetName() << "->SetDisabledAndSelected(kTRUE);\n";
2058 else
2059 out << " " << GetName() << "->SetDisabledAndSelected(kFALSE);\n";
2060 }
2061 out << " " << GetName() << "->SetTextJustify(" << fTMode << ");\n";
2062 out << " " << GetName() << "->SetMargins(" << fMLeft << "," << fMRight << "," << fMTop << "," << fMBottom
2063 << ");\n";
2064 out << " " << GetName() << "->SetWrapLength(" << fWrapLength << ");\n";
2065}
2066
2067////////////////////////////////////////////////////////////////////////////////
2068/// Save a radio button widget as a C++ statement(s) on output stream out.
2069
2070void TGRadioButton::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2071{
2072 TString outext(fLabel->GetString());
2073 if (fLabel->GetHotPos() > 0)
2074 outext.Insert(fLabel->GetHotPos() - 1, "&");
2075
2076 out << " TGRadioButton *" << GetName() << " = new TGRadioButton(" << fParent->GetName() << ", \""
2077 << outext.ReplaceSpecialCppChars() << "\"";
2078
2079 // font + GC
2080 option = GetName() + 5; // unique digit id of the name
2081 TString parGC, parFont;
2082 parFont.Form("%s::GetDefaultFontStruct()", IsA()->GetName());
2083 parGC.Form("%s::GetDefaultGC()()", IsA()->GetName());
2084
2085 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
2086 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
2087 if (ufont) {
2088 ufont->SavePrimitive(out, option);
2089 parFont.Form("ufont->GetFontStruct()");
2090 }
2091
2092 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
2093 if (userGC) {
2094 userGC->SavePrimitive(out, option);
2095 parGC.Form("uGC->GetGC()");
2096 }
2097 }
2098
2099 if (GetOptions() == (kChildFrame)) {
2101 if (fNormGC == GetDefaultGC()()) {
2102 if (fWidgetId == -1) {
2103 out << ");\n";
2104 } else {
2105 out << "," << fWidgetId << ");\n";
2106 }
2107 } else {
2108 out << "," << fWidgetId << "," << parGC << ");\n";
2109 }
2110 } else {
2111 out << "," << fWidgetId << "," << parGC << "," << parFont << ");\n";
2112 }
2113 } else {
2114 out << "," << fWidgetId << "," << parGC << "," << parFont << "," << GetOptionString() << ");\n";
2115 }
2116
2117 TGButton::SavePrimitive(out, option);
2118 if (fState == kButtonDisabled) {
2120 out << " " << GetName() << "->SetDisabledAndSelected(kTRUE);\n";
2121 else
2122 out << " " << GetName() << "->SetDisabledAndSelected(kFALSE);\n";
2123 }
2124 out << " " << GetName() << "->SetTextJustify(" << fTMode << ");\n";
2125 out << " " << GetName() << "->SetMargins(" << fMLeft << "," << fMRight << "," << fMTop << "," << fMBottom
2126 << ");\n";
2127 out << " " << GetName() << "->SetWrapLength(" << fWrapLength << ");\n";
2128}
2129
2130////////////////////////////////////////////////////////////////////////////////
2131/// Create a menu button widget. The hotstring will be adopted and
2132/// deleted by the menu button. This constructor creates a
2133/// menubutton with a popup menu attached that appears when the
2134/// button for it is clicked. The popup menu is adopted.
2135
2137 TGPopupMenu *popmenu, Bool_t split, Int_t id,
2138 GContext_t norm, FontStruct_t fontstruct, UInt_t options)
2139 : TGTextButton(p, menulabel, id, norm, fontstruct, options)
2140{
2141 fFontStruct = fontstruct;
2142 fMBWidth = 16;
2143 fMenuLabel = new TGHotString(*menulabel);
2144 fPopMenu = popmenu;
2145 fPopMenu->fSplitButton = this;
2146 fSplit = split;
2147 fTMode = 0;
2148 fHKeycode = 0;
2149 fMBState = kButtonUp; fDefaultCursor = fClient->GetResourcePool()->GetGrabCursor();
2151 fWidestLabel = "";
2152 fHeighestLabel = "";
2153
2154 // Find and set the correct size for the menu and the button.
2155 TGMenuEntry *entry = 0;
2156 TGHotString lstring(*fMenuLabel);
2157 TGHotString hstring(*fMenuLabel);
2158 const TList *list = fPopMenu->GetListOfEntries();
2159 UInt_t lwidth = 0, lheight = 0;
2160 UInt_t twidth = 0, theight = 0;
2161
2162 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
2163 if (!font) {
2164 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
2165 if (font) fFontStruct = font->GetFontStruct();
2166 }
2167
2168 if (font) font->ComputeTextLayout(lstring, lstring.GetLength(),
2170 &lwidth, &lheight);
2171
2172 TIter iter(list);
2173 entry = (TGMenuEntry *)iter.Next();
2174 while (entry != 0) {
2175 if (entry->GetType() == kMenuEntry) {
2176 const TGHotString string(*(entry->GetLabel()));
2177 if (font) font->ComputeTextLayout(string, string.GetLength(),
2179 &twidth, &theight);
2180 if(twidth > lwidth) {
2181 lstring = string;
2182 }
2183 if(theight > lheight) {
2184 hstring = string;
2185 }
2186 }
2187 entry = (TGMenuEntry *)iter.Next();
2188 }
2189 fWidestLabel = lstring;
2190 fHeighestLabel = hstring;
2191
2192 if (font) {
2193 UInt_t dummy = 0;
2194 font->ComputeTextLayout(lstring, lstring.GetLength(),
2196 &fTWidth, &dummy);
2197 font->ComputeTextLayout(hstring, hstring.GetLength(),
2199 &dummy, &fTHeight);
2200 }
2201 fTBWidth = fTWidth + 8;
2202 fHeight = fTHeight + 7;
2204
2206
2207 // Save the id of the 1st item on the menu.
2208 TIter iter1(list);
2209 do {
2210 entry = (TGMenuEntry *)iter1.Next();
2211 if ((entry) && (entry->GetStatus() & kMenuEnableMask) &&
2212 !(entry->GetStatus() & kMenuHideMask) &&
2213 (entry->GetType() != kMenuSeparator) &&
2214 (entry->GetType() != kMenuLabel)) break;
2215 entry = (TGMenuEntry *)iter1.Next();
2216 } while (entry);
2217 if (entry) fEntryId = entry->GetEntryId();
2218
2219 // An additional connection that is needed.
2220 fPopMenu->Connect("Activated(Int_t)", "TGSplitButton", this, "HandleMenu(Int_t)");
2222
2223 Init();
2224}
2225
2226
2227////////////////////////////////////////////////////////////////////////////////
2228/// Common initialization used by the different ctors.
2229
2231{
2232 Int_t hotchar;
2233
2235 fHKeycode = 0;
2237 fPrevStateOn =
2238 fStateOn = kFALSE;
2240
2242
2243 if ((hotchar = fLabel->GetHotChar()) != 0) {
2244 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
2246 if (main) {
2247 main->BindKey(this, fHKeycode, kKeyMod1Mask);
2248 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2249 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2251
2252 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2256 }
2257 }
2258 }
2261 wattr.fBitGravity = 5; // center
2262 wattr.fWinGravity = 1;
2263 gVirtualX->ChangeWindowAttributes(fId, &wattr);
2264
2265 // Make sure motion is detected too.
2267
2268 SetWindowName();
2269}
2270
2271////////////////////////////////////////////////////////////////////////////////
2272/// Delete a split button widget.
2273
2275{
2276 if (fPopMenu) delete fPopMenu;
2277 if (fMenuLabel) delete fMenuLabel;
2278}
2279
2280////////////////////////////////////////////////////////////////////////////////
2281/// Draw triangle (arrow) on which user can click to open Popup.
2282
2284{
2285 Point_t points[3];
2286
2287 points[0].fX = x;
2288 points[0].fY = y;
2289 points[1].fX = x + 5;
2290 points[1].fY = y;
2291 points[2].fX = x + 2;
2292 points[2].fY = y + 3;
2293
2294 gVirtualX->FillPolygon(fId, gc, points, 3);
2295}
2296
2297////////////////////////////////////////////////////////////////////////////////
2298/// Calculate the size of the button.
2299
2301{
2302 Int_t max_ascent, max_descent;
2303 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
2304 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2305 fTHeight = max_ascent + max_descent;
2306
2307 fTBWidth = fTWidth + 8;
2308 fHeight = fTHeight + 7;
2309 fWidth = fTBWidth;
2310}
2311
2312////////////////////////////////////////////////////////////////////////////////
2313/// Handle mouse button event in case the button is split.
2314
2316{
2317 if (fState == kButtonDisabled) return kFALSE;
2318
2319 Bool_t activate = kFALSE;
2320 Bool_t bclick = kFALSE;
2321 static Bool_t mbpress = kFALSE;
2322 static Bool_t tbpress = kFALSE;
2323 static Bool_t outpress = kFALSE;
2324
2325 Bool_t inTB = (event->fX >= 0) && (event->fY >= 0) &&
2326 (event->fX <= (Int_t)fTBWidth) && (event->fY <= (Int_t)fHeight);
2327
2328 Bool_t inMB = (event->fX >= (Int_t)(fWidth -fMBWidth)) && (event->fY >= 0) &&
2329 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
2330
2331 // We don't need to check the button number as GrabButton will
2332 // only allow button1 events
2333
2334 if (inTB) {
2335 if (event->fType == kButtonPress) {
2336 mbpress = kFALSE;
2337 tbpress = kTRUE;
2338 fgReleaseBtn = 0;
2339 if (fState == kButtonEngaged) {
2340 return kTRUE;
2341 }
2343 Pressed();
2344 } else { // ButtonRelease
2345 if (fMBState == kButtonDown) {
2347 }
2348 if (fState == kButtonEngaged && tbpress) {
2350 Released();
2351 bclick = kTRUE;
2352 } else if (fState == kButtonDown && tbpress) {
2353 tbpress = kFALSE;
2354 if (fStayDown) {
2355 bclick = kTRUE;
2357 fgReleaseBtn = 0;
2358 } else {
2359 bclick = kTRUE;
2361 Released();
2362 fgReleaseBtn = fId;
2363 }
2364 }else {
2366 }
2367 }
2368 } else if (inMB) {
2369 if (event->fType == kButtonPress) {
2370 fgReleaseBtn = 0;
2371 mbpress = kTRUE;
2372 tbpress = kFALSE;
2373 if (fMBState == kButtonEngaged) {
2374 return kTRUE;
2375 }
2377 MBPressed();
2380 } else { // ButtonRelease
2381 if (fState == kButtonDown) {
2383 }
2384 if (fMBState == kButtonEngaged && mbpress) {
2385 mbpress = kFALSE;
2388 MBReleased();
2389 MBClicked();
2390 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2391 } else if (fMBState == kButtonDown && mbpress) {
2392 MBClicked();
2395 fgReleaseBtn = 0;
2396 } else {
2398 }
2399 }
2400 } else {
2401 if (event->fType == kButtonPress) {
2402 fgReleaseBtn = 0;
2403 outpress = kTRUE;
2404 } else { // ButtonRelease
2405 if(outpress) {
2406 outpress = kFALSE;
2409 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2410 activate = kTRUE;
2411 }
2412 }
2413 }
2414 if (bclick) {
2415 Clicked();
2420 }
2421 if (activate) {
2422 TGMenuEntry *entry = fPopMenu->GetCurrent();
2423 if (entry) {
2424 if ((entry->GetStatus() & kMenuEnableMask) &&
2425 !(entry->GetStatus() & kMenuHideMask) &&
2426 (entry->GetType() != kMenuSeparator) &&
2427 (entry->GetType() != kMenuLabel)) {
2428 Int_t id = entry->GetEntryId();
2429 fPopMenu->Activated(id);
2430 }
2431 }
2432 }
2433 // if (mbclick) {
2434 // MBClicked();
2435 // SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2436 // (Longptr_t) fUserData);
2437 // fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2438 // (Longptr_t) fUserData);
2439 // }
2440 return kTRUE;
2441}
2442
2443////////////////////////////////////////////////////////////////////////////////
2444/// Handle mouse crossing event in case of split menu.
2445
2447{
2448 if (fTip) {
2449 if (event->fType == kEnterNotify)
2450 fTip->Reset();
2451 else
2452 fTip->Hide();
2453 }
2454
2455 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow)) return kTRUE;
2456
2457 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
2458 return kTRUE;
2459
2460 if (fState == kButtonEngaged || fState == kButtonDisabled) return kTRUE;
2461
2462 Bool_t inTB = (event->fX <= (Int_t)fTBWidth);
2463
2464 // Bool_t inMB = (event->fX >= (Int_t)(fWidth -fMBWidth)) && (event->fY >= 0) &&
2465 // (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
2466
2467 if (event->fType == kEnterNotify) {
2468 if (inTB) {
2470 } else {
2471 if(fMBState == kButtonEngaged) return kTRUE;
2473 }
2474 } else {
2475 // kLeaveNotify
2476 if(fState == kButtonDown) {
2478 }
2479 if (fMBState == kButtonEngaged) return kTRUE;
2481 }
2482 return kTRUE;
2483}
2484
2485////////////////////////////////////////////////////////////////////////////////
2486/// Handle key event. This function will be called when the hotkey is hit.
2487
2489{
2490 if (fState == kButtonDisabled) return kFALSE;
2491
2492 Bool_t click = kFALSE;
2493
2494 if (event->fType == kGKeyPress) {
2495 gVirtualX->SetKeyAutoRepeat(kFALSE);
2496 } else {
2497 gVirtualX->SetKeyAutoRepeat(kTRUE);
2498 }
2499
2500 if (fTip && event->fType == kGKeyPress) fTip->Hide();
2501
2502 // We don't need to check the key number as GrabKey will only
2503 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
2504
2505 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
2506 if (fState == kButtonEngaged) return kTRUE;
2508 Pressed();
2509 } else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
2510 if (fState == kButtonEngaged) {
2512 Released();
2513 }
2514 if (fStayDown) {
2516 } else {
2518 Released();
2519 }
2520 click = kTRUE;
2521 }
2522 if (click) {
2523 Clicked();
2528 }
2529
2530 return kTRUE;
2531}
2532
2533////////////////////////////////////////////////////////////////////////////////
2534/// Popup the attached menu.
2535
2537{
2538 if (state) {
2539 Int_t ax, ay;
2540 Window_t wdummy;
2541
2542 if (fSplit) {
2543 Int_t n_entries = 0;
2544 TGMenuEntry *entry = 0;
2545 TIter next(fPopMenu->GetListOfEntries());
2546
2547 while ((entry = (TGMenuEntry *) next())) {
2548 if ((entry->GetType() != kMenuSeparator) &&
2549 (entry->GetType() != kMenuLabel)) {
2550 n_entries++;
2551 }
2552 }
2553 if (n_entries <= 1) {
2554 Info("TGSplitButton", "Only one entry in the menu.");
2555 return;
2556 }
2557 }
2558
2559 gVirtualX->TranslateCoordinates(fId, fPopMenu->GetParent()->GetId(),
2560 0, 0, ax, ay, wdummy);
2561
2562 // place the menu just under the window:
2563 fPopMenu->PlaceMenu(ax-1, ay+fHeight, kTRUE, kFALSE); //kTRUE);
2564 BindKeys(kTRUE);
2566 } else {
2567 fPopMenu->EndMenu(fUserData);
2570 fPopMenu->EndMenu(fUserData);
2571 }
2572}
2573
2574////////////////////////////////////////////////////////////////////////////////
2575/// Draw the text button.
2576
2578{
2579 int x, y;
2581
2584
2585 if (fTMode & kTextLeft) {
2586 x = fMLeft + 4;
2587 } else if (fTMode & kTextRight) {
2588 x = fWidth - fTWidth -fMBWidth - fMRight - 4;
2589 } else {
2590 x = (fWidth - fTWidth -fMBWidth + fMLeft - fMRight) >> 1;
2591 }
2592
2593 if (fTMode & kTextTop) {
2594 y = fMTop + 3;
2595 } else if (fTMode & kTextBottom) {
2596 y = fHeight - fTHeight - fMBottom - 3;
2597 } else {
2598 y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
2599 }
2600
2601 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
2602 if (fState == kButtonEngaged) {
2603 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
2604 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
2605 }
2606
2607 Int_t hotpos = fLabel->GetHotPos();
2608
2609 if (fState == kButtonDisabled) {
2610 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
2611 TGGC *gc = pool->FindGC(fNormGC);
2612 if (gc) {
2613 Pixel_t fore = gc->GetForeground();
2616
2617 gc->SetForeground(hi);
2618 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
2619 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x + 1, y + 1, hotpos - 1);
2620
2621 gc->SetForeground(sh);
2622 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
2623 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
2624 gc->SetForeground(fore);
2625 }
2626 } else {
2627 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
2628 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
2629 }
2630
2631 // Draw the parts of the button needed when a menu is attached.
2632
2633 // triangle position
2634 x = fWidth - 11;
2635 y = fHeight - 10;
2636
2637 if (fSplit) {
2638 // separator position
2639 Int_t lx = fWidth - fMBWidth;
2640 Int_t ly = 2;
2641 Int_t lh = fHeight - 2;
2642
2644 x++;
2645 y++;
2646 }
2647
2648 gVirtualX->DrawLine(fId, GetShadowGC()(), lx, ly + 2, lx, lh - 4);
2649 gVirtualX->DrawLine(fId, GetHilightGC()(), lx + 1, ly + 2, lx + 1, lh - 3);
2650 gVirtualX->DrawLine(fId, GetHilightGC()(), lx, lh - 3, lx + 1, lh - 3);
2651
2652 if (fMBState == kButtonEngaged) {
2653 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), fTBWidth + 1, 1, fMBWidth - 3, fHeight - 3);
2654 }
2655
2656 if (fMBState == kButtonDisabled) {
2657 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
2658 DrawTriangle(GetShadowGC()(), x, y);
2659 } else {
2661 }
2662
2663 } else {
2664 x -= 2;
2666 x++;
2667 y++;
2668 }
2669 if (fState == kButtonDisabled) {
2670 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
2671 DrawTriangle(GetShadowGC()(), x, y);
2672 } else {
2674 }
2675 }
2676
2677}
2678
2679////////////////////////////////////////////////////////////////////////////////
2680/// If on kTRUE bind arrow, popup menu hot keys, otherwise
2681/// remove key bindings.
2682
2684{
2685 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up), kAnyModifier, on);
2686 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down), kAnyModifier, on);
2687 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter), kAnyModifier, on);
2688 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return), kAnyModifier, on);
2689 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Escape), kAnyModifier, on);
2690}
2691
2692////////////////////////////////////////////////////////////////////////////////
2693/// If on kTRUE bind Menu hot keys, otherwise remove key bindings.
2694
2696{
2697 TGMenuEntry *e = 0;
2698 TIter next(fPopMenu->GetListOfEntries());
2699
2700 while ((e = (TGMenuEntry*)next())) {
2701 Int_t hot = 0;
2702 if (e->GetLabel()) {
2703 hot = e->GetLabel()->GetHotChar();
2704 }
2705 if (!hot) continue;
2706 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), 0, on);
2707 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask, on);
2708 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask, on);
2709 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyMod2Mask, on);
2710 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask, on);
2711 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyMod2Mask, on);
2712 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask | kKeyMod2Mask, on);
2713 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask | kKeyMod2Mask, on);
2714 }
2715}
2716
2717////////////////////////////////////////////////////////////////////////////////
2718/// returns default size
2719
2726
2727////////////////////////////////////////////////////////////////////////////////
2728/// Set new button text.
2729
2731{
2732 Int_t hotchar;
2733 static Bool_t longlabeltip = kFALSE;
2735
2736 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
2737 if (!font) {
2738 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
2739 if (font) fFontStruct = font->GetFontStruct();
2740 }
2741
2742 UInt_t width = 0, bwidth = 0, dummy;
2743 if (font) {
2744 font->ComputeTextLayout(new_label->GetString(), new_label->GetLength(),
2746 &width, &dummy);
2747 font->ComputeTextLayout(fWidestLabel.GetString(), fWidestLabel.GetLength(),
2749 &bwidth, &dummy);
2750 }
2751 if (width > bwidth) {
2752 if (!fTip) {
2753 SetToolTipText(new_label->GetString());
2754 longlabeltip = kTRUE;
2755 }
2756 Info("TGSplitbutton", "Length of new label to long, label truncated.");
2757 new_label->Resize(fWidestLabel.GetLength());
2758 } else if (new_label->GetLength() <= fWidestLabel.GetLength() && longlabeltip) {
2759 if (fTip) delete fTip;
2760 fTip = 0;
2761 longlabeltip = kFALSE;
2762 }
2763
2764 if (fLabel) {
2765 if (main && fHKeycode) {
2766 main->RemoveBind(this, fHKeycode, kKeyMod1Mask);
2767 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2768 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2769 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
2770
2771 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2772 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
2773 main->RemoveBind(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
2775 }
2776 delete fLabel;
2777 }
2778
2779 fLabel = new_label;
2780 if ((hotchar = fLabel->GetHotChar()) != 0) {
2781 if (main && ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0)) {
2782 main->BindKey(this, fHKeycode, kKeyMod1Mask);
2783 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2784 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2786
2787 main->BindKey(this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2791 }
2792 }
2793
2794 Layout();
2795}
2796
2797////////////////////////////////////////////////////////////////////////////////
2798/// Set new button text.
2799
2800void TGSplitButton::SetText(const TString &new_label)
2801{
2802 SetText(new TGHotString(new_label));
2803}
2804
2805////////////////////////////////////////////////////////////////////////////////
2806/// Changes text font.
2807/// If global is kTRUE font is changed globally, otherwise - locally.
2808
2810{
2811 if (font != fFontStruct) {
2812 FontH_t v = gVirtualX->GetFontHandle(font);
2813 if (!v) return;
2814
2815 fFontStruct = font;
2816 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
2817 TGGC *gc = pool->FindGC(fNormGC);
2818
2819 if ((gc) && !global) {
2820 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
2822 }
2823 if (gc) {
2824 gc->SetFont(v);
2825 fNormGC = gc->GetGC();
2826 }
2827 fClient->NeedRedraw(this);
2828 }
2829}
2830
2831////////////////////////////////////////////////////////////////////////////////
2832/// Changes text font specified by name.
2833/// If global is true color is changed globally, otherwise - locally.
2834
2835void TGSplitButton::SetFont(const char *fontName, Bool_t global)
2836{
2837 TGFont *font = fClient->GetFont(fontName);
2838 if (font) {
2839 SetFont(font->GetFontStruct(), global);
2840 }
2841}
2842
2843////////////////////////////////////////////////////////////////////////////////
2844/// Set the state of the Menu Button part
2845
2847{
2848 if (state != fMBState) {
2849 fMBState = state;
2850 DoRedraw();
2851 }
2852}
2853
2854////////////////////////////////////////////////////////////////////////////////
2855/// Set the split status of a button.
2856
2858{
2859 if(split) {
2860 fStayDown = kFALSE;
2861 Disconnect(fPopMenu, "PoppedDown()");
2862 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "SetMBState(=kButtonUp)");
2863 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "MBReleased()");
2864
2865 TGMenuEntry *entry = fPopMenu->GetEntry(fEntryId);
2866 if (entry) {
2867 TGHotString *tmp = new TGHotString(*(entry->GetLabel()));
2868 SetText(tmp);
2869
2870 TString str("ItemClicked(=");
2871 str += entry->GetEntryId();
2872 str += ")";
2873 Connect("Clicked()", "TGSplitButton", this, str);
2874 fEntryId = entry->GetEntryId();
2875 fPopMenu->HideEntry(fEntryId);
2876 }
2877 } else {
2878 fStayDown = kTRUE;
2879 Disconnect(fPopMenu, "PoppedDown()");
2880 Disconnect(this, "Clicked()", this);
2881 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "SetState(=kButtonUp)");
2882 fPopMenu->Connect("PoppedDown()", "TGSplitButton", this, "Released()");
2883 fPopMenu->EnableEntry(fEntryId);
2884 TGHotString *tmp = new TGHotString(*fMenuLabel);
2885 SetText(tmp);
2886 }
2887
2888 fSplit = split;
2889 DoRedraw();
2890}
2891
2892////////////////////////////////////////////////////////////////////////////////
2893/// Handle button events.
2894
2896{
2897 if (fState == kButtonDisabled) return kFALSE;
2898
2899 if (fSplit) return HandleSButton(event);
2900
2901 Bool_t in = (event->fX >= 0) && (event->fY >= 0) &&
2902 (event->fX <= (Int_t)fWidth) && (event->fY <= (Int_t)fHeight);
2903
2904 Bool_t activate = kFALSE;
2905 Bool_t click = kFALSE;
2906
2907 if (in) {
2908 if (event->fType == kButtonPress) {
2909 fgReleaseBtn = 0;
2910 if (fState == kButtonEngaged) {
2911 return kTRUE;
2912 }
2914 Pressed();
2917 } else { // ButtonRelease
2918 if (fState == kButtonEngaged) {
2921 Released();
2922 click = kTRUE;
2923 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2924 } else {
2925 click = (fState == kButtonDown);
2926 if (click && fStayDown) {
2929 fgReleaseBtn = 0;
2930 } else {
2932 Released();
2933 fgReleaseBtn = fId;
2934 }
2935 }
2937 }
2938 } else {
2939 if (event->fType == kButtonPress) {
2940 fgReleaseBtn = 0;
2941 } else { // ButtonRelease
2944 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
2945 activate = kTRUE;
2946 }
2947 }
2948 if (click) {
2949 Clicked();
2954 }
2955 if (activate && !fKeyNavigate) {
2956 TGMenuEntry *entry = fPopMenu->GetCurrent();
2957 if (entry) {
2958 if ((entry->GetStatus() & kMenuEnableMask) &&
2959 !(entry->GetStatus() & kMenuHideMask) &&
2960 (entry->GetType() != kMenuSeparator) &&
2961 (entry->GetType() != kMenuLabel)) {
2962 Int_t id = entry->GetEntryId();
2963 fPopMenu->Activated(id);
2964 }
2965 }
2966 }
2967
2968 return kTRUE;
2969
2970}
2971
2972////////////////////////////////////////////////////////////////////////////////
2973/// Handle mouse crossing event.
2974
2976{
2977 if (fSplit) {
2978 return HandleSCrossing(event);
2979 } else {
2980 return TGButton::HandleCrossing(event);
2981 }
2982}
2983
2984////////////////////////////////////////////////////////////////////////////////
2985/// Handle key event. This function will be called when the hotkey is hit.
2986
2988{
2989 Bool_t click = kFALSE;
2990
2991 if (fState == kButtonDisabled) return kTRUE;
2992
2993 if(fSplit) return HandleSKey(event);
2994
2995 if (event->fType == kGKeyPress) {
2996 gVirtualX->SetKeyAutoRepeat(kFALSE);
2997 } else {
2998 gVirtualX->SetKeyAutoRepeat(kTRUE);
2999 }
3000
3001 if (fTip && event->fType == kGKeyPress) fTip->Hide();
3002
3003 // We don't need to check the key number as GrabKey will only
3004 // allow fHotchar events if Alt button is pressed (kKeyMod1Mask)
3005 if (event->fState & kKeyMod1Mask) {
3006 RequestFocus();
3008 if (event->fType == kGKeyPress) {
3009 if (fState == kButtonEngaged) return kTRUE;
3011 Pressed();
3012 } else if (event->fType == kKeyRelease) {
3013 click = kTRUE;
3014 if (fState == kButtonEngaged) {
3017 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3018 } else if (fState == kButtonDown && fStayDown) {
3023 TGMenuEntry *entry = 0;
3024 TIter next(fPopMenu->GetListOfEntries());
3025
3026 while ((entry = (TGMenuEntry *) next())) {
3027 if ((entry->GetStatus() & kMenuEnableMask) &&
3028 !(entry->GetStatus() & kMenuHideMask) &&
3029 (entry->GetType() != kMenuSeparator) &&
3030 (entry->GetType() != kMenuLabel)) break;
3031 }
3032 if (entry) {
3033 fPopMenu->Activate(entry);
3034 }
3035 } else {
3036 Released();
3038 }
3039 }
3040 } else {
3042 if (event->fType == kGKeyPress) {
3043 Event_t ev;
3044 ev.fX = ev.fY = 1;
3045 UInt_t keysym;
3046 char tmp[2];
3047
3048 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
3049
3050 TGMenuEntry *ce = 0;
3051 TIter next(fPopMenu->GetListOfEntries());
3052
3053 while ((ce = (TGMenuEntry*)next())) {
3054 UInt_t hot = 0;
3055 if (ce->GetLabel()) hot = ce->GetLabel()->GetHotChar();
3056 if (!hot || (hot != keysym)) continue;
3057
3058 fPopMenu->Activate(ce);
3059 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3061 ev.fType = kButtonRelease;
3062 ev.fWindow = fPopMenu->GetId();
3064 return HandleButton(&ev);
3065 }
3066
3067 ce = fPopMenu->GetCurrent();
3068
3069 switch ((EKeySym)keysym) {
3070 case kKey_Up:
3071 if (ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Before(ce);
3072 while (ce && ((ce->GetType() == kMenuSeparator) ||
3073 (ce->GetType() == kMenuLabel) ||
3074 !(ce->GetStatus() & kMenuEnableMask))) {
3075 ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Before(ce);
3076 }
3077 if (!ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Last();
3078 break;
3079 case kKey_Down:
3080 if (ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->After(ce);
3081 while (ce && ((ce->GetType() == kMenuSeparator) ||
3082 (ce->GetType() == kMenuLabel) ||
3083 !(ce->GetStatus() & kMenuEnableMask))) {
3084 ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->After(ce);
3085 }
3086 if (!ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->First();
3087 break;
3088 case kKey_Enter:
3089 case kKey_Return:
3090 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3092 ev.fType = kButtonRelease;
3093 ev.fWindow = fPopMenu->GetId();
3095 HandleButton(&ev);
3096 break;
3097 case kKey_Escape:
3098 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3100 break;
3101 default:
3102 break;
3103 }
3104 if (ce) fPopMenu->Activate(ce);
3105 }
3106 }
3107 if (click) {
3108 Clicked();
3113 }
3114
3115 return kTRUE;
3116}
3117
3118////////////////////////////////////////////////////////////////////////////////
3119/// Handle a motion event in a TGSplitButton.
3120
3122{
3123 if (fKeyNavigate) return kTRUE;
3124
3125 if (fSplit) {
3126 if (fMBState == kButtonDown) {
3127 if (event->fX < (Int_t)fTBWidth) {
3130 }
3131 } else if (fState == kButtonDown) {
3132 if (event->fX > (Int_t)fTBWidth) {
3135 }
3136
3137 }
3138 }
3139 return kTRUE;
3140}
3141
3142////////////////////////////////////////////////////////////////////////////////
3143/// layout text button
3144
3146{
3147 UInt_t dummya = 0, dummyb = 0;
3149
3150 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
3151 if (!font) {
3152 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
3153 if (font) fFontStruct = font->GetFontStruct();
3154 }
3155 if (font) {
3156 fTLayout = font->ComputeTextLayout(fLabel->GetString(),
3157 fLabel->GetLength(),
3159 &dummya, &dummyb);
3160 UInt_t dummy = 0;
3161 font->ComputeTextLayout(fWidestLabel.GetString(), fWidestLabel.GetLength(),
3163 &fTWidth, &dummy);
3164 font->ComputeTextLayout(fHeighestLabel.GetString(), fHeighestLabel.GetLength(),
3166 &dummy, &fTHeight);
3167 }
3168 fTBWidth = fTWidth + 8;
3170 fHeight = fTHeight + 7;
3171 fClient->NeedRedraw(this);
3172}
3173
3174////////////////////////////////////////////////////////////////////////////////
3175/// Handle a menu item activation.
3176
3178{
3180
3181 if (fSplit) {
3183 Disconnect(this, "Clicked()", this);
3184 // connect clicked to the ItemClicked signal with the correct id
3185 Connect("Clicked()", "TGSplitButton", this,
3186 TString::Format("ItemClicked(=%d)", id));
3187
3188 // reenable hidden entries
3189 const TList *list = fPopMenu->GetListOfEntries();
3190 TIter iter(list);
3191 fPopMenu->EnableEntry(fEntryId);
3192 TGMenuEntry *entry = fPopMenu->GetEntry(id);
3193 if (entry) {
3194 TGHotString *label = entry->GetLabel();
3195 TGHotString *tmp = new TGHotString(*label);
3196 SetText(tmp);
3197 }
3198 fPopMenu->HideEntry(id);
3199 if (entry) fEntryId = entry->GetEntryId();
3200 } else {
3202 ItemClicked(id);
3203 }
3204 DoRedraw();
3205}
@ kGKeyPress
Definition GuiTypes.h:61
@ kButtonRelease
Definition GuiTypes.h:61
@ kButtonPress
Definition GuiTypes.h:61
@ kEnterNotify
Definition GuiTypes.h:62
@ kKeyRelease
Definition GuiTypes.h:61
@ kLeaveNotify
Definition GuiTypes.h:62
const Mask_t kWABitGravity
Definition GuiTypes.h:145
const Mask_t kGCBackground
Definition GuiTypes.h:290
const Mask_t kGCForeground
Definition GuiTypes.h:289
const Mask_t kGCTile
Definition GuiTypes.h:297
const Mask_t kKeyLockMask
Definition GuiTypes.h:197
const Mask_t kButtonPressMask
Definition GuiTypes.h:162
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index).
Definition GuiTypes.h:36
const Mask_t kKeyMod1Mask
typically the Alt key
Definition GuiTypes.h:199
const Mask_t kGCFillStyle
Definition GuiTypes.h:295
const Mask_t kWAWinGravity
Definition GuiTypes.h:146
const Mask_t kAnyModifier
Definition GuiTypes.h:211
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
const Mask_t kButton1Mask
Definition GuiTypes.h:204
const Mask_t kPointerMotionMask
Definition GuiTypes.h:164
const Mask_t kKeyShiftMask
Definition GuiTypes.h:196
@ kChildFrame
Definition GuiTypes.h:380
@ kRaisedFrame
Definition GuiTypes.h:385
@ kSunkenFrame
Definition GuiTypes.h:384
@ kDoubleBorder
Definition GuiTypes.h:386
@ kFixedWidth
Definition GuiTypes.h:388
@ kFixedHeight
Definition GuiTypes.h:390
@ kFixedSize
Definition GuiTypes.h:391
@ kOwnBackground
Definition GuiTypes.h:392
const Handle_t kNone
Definition GuiTypes.h:89
const Mask_t kKeyMod2Mask
typically mod on numeric keys
Definition GuiTypes.h:200
const Mask_t kButton3Mask
Definition GuiTypes.h:206
const Mask_t kLeaveWindowMask
Definition GuiTypes.h:169
@ kFillTiled
Definition GuiTypes.h:52
const Mask_t kButton2Mask
Definition GuiTypes.h:205
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:39
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:163
const Mask_t kGCGraphicsExposures
Definition GuiTypes.h:303
const Mask_t kEnterWindowMask
Definition GuiTypes.h:168
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:40
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
@ kButton1
Definition GuiTypes.h:215
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:525
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
externTEnv * gEnv
Definition TEnv.h:170
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
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:147
char name[80]
Definition TGX11.cxx:148
#define hi
externTSystem * gSystem
Definition TSystem.h:582
#define gVirtualX
Definition TVirtualX.h:375
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kC_COMMAND
@ kCM_BUTTON
@ kCM_RADIOBUTTON
@ kCM_CHECKBUTTON
point * points
Definition X3DBuffer.c:22
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4932
static TClass * Class()
virtual void SetGroup(TGButtonGroup *gr)
Sets new button-group for this button.
Definition TGButton.cxx:316
virtual void Pressed()
Definition TGButton.h:133
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition TGButton.cxx:464
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:439
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:474
virtual void SetDown(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition TGButton.cxx:304
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a button widget as a C++ statement(s) on output stream out.
static Window_t fgReleaseBtn
Definition TGButton.h:91
Pixel_t fHighColor
highlight color
Definition TGButton.h:82
virtual void Released()
Definition TGButton.h:134
Bool_t HandleButton(Event_t *event) override
Handle mouse button event.
Definition TGButton.cxx:324
virtual void EmitSignals(Bool_t wasUp)
Emit button signals.
Definition TGButton.cxx:379
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:265
void * fUserData
pointer to user data structure
Definition TGButton.h:78
static const TGGC * fgHibckgndGC
Definition TGButton.h:89
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:453
static const TGGC * fgDefaultGC
Definition TGButton.h:88
~TGButton() override
Delete button.
Definition TGButton.cxx:215
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition TGButton.cxx:229
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:295
friend class TGButtonGroup
Definition TGButton.h:70
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
Definition TGButton.cxx:398
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
const TGPicture * fOff
button OFF picture
Definition TGButton.h:274
static const TGFont * fgDefaultFont
Definition TGButton.h:283
static const TGGC * fgDefaultGC
Definition TGButton.h:284
Bool_t HandleKey(Event_t *event) override
Handle key event. This function will be called when the hotkey is hit.
const TGPicture * fOn
button ON picture
Definition TGButton.h:273
void Init()
Common check button initialization.
Bool_t HandleButton(Event_t *event) override
Handle mouse button event.
static const TGGC & GetDefaultGC()
Return default graphics context.
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
virtual void SetDisabledAndSelected(Bool_t)
Set the state of a check button to disabled and either on or off.
virtual Bool_t IsDisabledAndSelected() const
Definition TGButton.h:312
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
TClass * IsA() const override
Definition TGButton.h:317
~TGCheckButton() override
Delete a check button.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a check button widget as a C++ statement(s) on output stream out.
TGCheckButton(const TGCheckButton &)=delete
void EmitSignals(Bool_t wasUp=kTRUE) override
Emit signals.
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set check button state.
EButtonState fPrevState
previous check button state
Definition TGButton.h:272
void DoRedraw() override
Draw the check button widget.
const TGPicture * fDisOff
button disabled and was OFF picture
Definition TGButton.h:276
const TGPicture * fDisOn
button disabled and was ON picture
Definition TGButton.h:275
TGDimension GetDefaultSize() const override
default size
void PSetState(EButtonState state, Bool_t emit)
Set check button state.
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
void SavePrimitive(std::ostream &out, Option_t *="") override
Save the used font as a C++ statement(s) on output stream out.
Definition TGFont.cxx:1881
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:658
virtual void ChangeOptions(UInt_t options)
Change frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:313
virtual void SetSize(const TGDimension &s)
Definition TGFrame.h:254
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:331
UInt_t fOptions
frame options
Definition TGFrame.h:94
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
TGFrame(const TGFrame &)=delete
UInt_t fHeight
frame height
Definition TGFrame.h:88
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:422
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:747
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:675
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2512
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:637
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:757
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
static Window_t fgDbw
Definition TGFrame.h:113
UInt_t GetWidth() const
Definition TGFrame.h:226
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2471
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition TGGC.cxx:969
void FreeGC(const TGGC *gc)
Delete graphics context if it is not used anymore.
Definition TGGC.cxx:900
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition TGGC.cxx:933
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
GContext_t GetGC() const
Definition TGGC.h:41
void SetFont(FontH_t v)
Set font.
Definition TGGC.cxx:403
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save graphics context info as a C++ statement(s) on output stream out.
Definition TGGC.cxx:619
Pixel_t GetForeground() const
Definition TGGC.h:73
void SetForeground(Pixel_t v)
Set foreground color.
Definition TGGC.cxx:270
const GCValues_t * GetAttributes() const
Definition TGGC.h:69
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
Int_t GetHotChar() const
Definition TGString.h:57
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:399
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:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
virtual void SetPicture(const TGPicture *new_pic)
Change a picture in a picture button.
virtual void CreateDisabledPicture()
Creates disabled picture.
virtual void SetDisabledPicture(const TGPicture *pic)
Changes disabled picture.
TClass * IsA() const override
Definition TGButton.h:260
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a picture button widget as a C++ statement(s) on output stream out.
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
~TGPictureButton() override
Destructor.
TGPictureButton(const TGPictureButton &)=delete
void DoRedraw() override
Redraw picture button.
Bool_t fOwnDisabledPic
kTRUE if disabled picture was autogenerated
Definition TGButton.h:233
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
void Draw(Option_t *="") override
Default Draw method for all objects.
Definition TGPicture.h:46
const TGPicture * fOn
button ON picture
Definition TGButton.h:329
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
static const TGGC * fgDefaultGC
Definition TGButton.h:340
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set radio button state.
void DoRedraw() override
Draw a radio button.
const TGPicture * fDisOn
button disabled and was ON picture
Definition TGButton.h:331
Bool_t HandleButton(Event_t *event) override
Handle mouse button event.
TClass * IsA() const override
Definition TGButton.h:374
EButtonState fPrevState
previous radio button state
Definition TGButton.h:328
void EmitSignals(Bool_t wasUp=kTRUE) override
Emit signals.
static const TGGC & GetDefaultGC()
Return default graphics context.
const TGPicture * fDisOff
button disabled and was OFF picture
Definition TGButton.h:332
static const TGFont * fgDefaultFont
Definition TGButton.h:339
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
virtual Bool_t IsDisabledAndSelected() const
Definition TGButton.h:371
virtual void SetDisabledAndSelected(Bool_t)
Set the state of a radio button to disabled and either on or off.
const TGPicture * fOff
button OFF picture
Definition TGButton.h:330
~TGRadioButton() override
Delete a radio button.
void PSetState(EButtonState state, Bool_t emit)
Set radio button state.
void Init()
Common radio button initialization.
Bool_t HandleKey(Event_t *event) override
Handle key event. This function will be called when the hotkey is hit.
TGDimension GetDefaultSize() const override
default size
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a radio button widget as a C++ statement(s) on output stream out.
TGRadioButton(const TGRadioButton &)=delete
void CalcSize()
Calculate the size of the button.
virtual void ItemClicked(Int_t id)
Definition TGButton.h:441
Bool_t HandleSKey(Event_t *event)
Handle key event. This function will be called when the hotkey is hit.
Bool_t HandleMotion(Event_t *event) override
Handle a motion event in a TGSplitButton.
~TGSplitButton() override
Delete a split button widget.
TGPopupMenu * fPopMenu
pointer to popup menu
Definition TGButton.h:400
void DrawTriangle(const GContext_t gc, Int_t x, Int_t y)
Draw triangle (arrow) on which user can click to open Popup.
void Layout() override
layout text button
Int_t fEntryId
Id of the currently active menu entry.
Definition TGButton.h:401
Bool_t HandleButton(Event_t *event) override
Handle button events.
Bool_t fSplit
kTRUE if menu is in split mode
Definition TGButton.h:396
virtual void MBClicked()
Definition TGButton.h:440
EButtonState fMBState
state for menu button in split mode
Definition TGButton.h:397
TGSplitButton(const TGSplitButton &)=delete
void Init()
Common initialization used by the different ctors.
Bool_t HandleSButton(Event_t *event)
Handle mouse button event in case the button is split.
void BindKeys(Bool_t on=kTRUE)
If on kTRUE bind arrow, popup menu hot keys, otherwise remove key bindings.
Cursor_t fDefaultCursor
Default Cursor.
Definition TGButton.h:403
void SetMenuState(Bool_t state)
Popup the attached menu.
UInt_t fMBWidth
width of menu button
Definition TGButton.h:399
TGDimension GetDefaultSize() const override
returns default size
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
Bool_t HandleSCrossing(Event_t *event)
Handle mouse crossing event in case of split menu.
void BindMenuKeys(Bool_t on=kTRUE)
If on kTRUE bind Menu hot keys, otherwise remove key bindings.
void SetFont(FontStruct_t font, Bool_t global=kFALSE) override
Changes text font.
Bool_t HandleKey(Event_t *event) override
Handle key event. This function will be called when the hotkey is hit.
virtual void MBReleased()
Definition TGButton.h:439
TGHotString * fMenuLabel
Label of the menu;.
Definition TGButton.h:402
void HandleMenu(Int_t id)
Handle a menu item activation.
void DoRedraw() override
]
TGString fHeighestLabel
highest label that can be on the button
Definition TGButton.h:406
UInt_t fTBWidth
width of text button
Definition TGButton.h:398
virtual void MBPressed()
Definition TGButton.h:438
virtual void SetMBState(EButtonState state)
Set the state of the Menu Button part.
Bool_t fKeyNavigate
kTRUE if key navigation is being used
Definition TGButton.h:404
friend class TGPopupMenu
Definition TGButton.h:380
virtual void SetSplit(Bool_t split)
Set the split status of a button.
TGString fWidestLabel
longest label that can be on the button
Definition TGButton.h:405
void SetText(TGHotString *new_label) override
Set new button text.
Int_t GetLength() const
Definition TGString.h:29
const char * GetString() const
Definition TGString.h:30
void Init()
Common initialization used by the different ctors.
Definition TGButton.cxx:535
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
Definition TGButton.cxx:863
void Layout() override
layout text button
Definition TGButton.cxx:618
Bool_t HandleKey(Event_t *event) override
Handle key event. This function will be called when the hotkey is hit.
Definition TGButton.cxx:809
Int_t fMTop
Definition TGButton.h:148
TClass * IsA() const override
Definition TGButton.h:224
Int_t fMBottom
Definition TGButton.h:149
virtual void SetTextJustify(Int_t tmode)
Set text justification.
Definition TGButton.cxx:689
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:638
TGTextButton(const TGTextButton &)=delete
static const TGFont * fgDefaultFont
Definition TGButton.h:159
Int_t fMRight
Definition TGButton.h:147
TGDimension GetDefaultSize() const override
returns default size
Definition TGButton.cxx:853
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a text button widget as a C++ statement(s) on output stream out.
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:932
Bool_t fPrevStateOn
Definition TGButton.h:157
virtual void SetFont(FontStruct_t font, Bool_t global=kFALSE)
Changes text font.
Definition TGButton.cxx:874
Int_t fTMode
Definition TGButton.h:150
~TGTextButton() override
Delete a text button widget.
Definition TGButton.cxx:589
void DoRedraw() override
Draw the text button.
Definition TGButton.cxx:741
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:912
Int_t fMLeft
Definition TGButton.h:146
A tooltip can be a one or multiple lines help text that is displayed in a window when the mouse curso...
Definition TGToolTip.h:24
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 const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:150
virtual void RequestFocus()
request focus
Definition TGWindow.cxx:230
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
TGWindow(Window_t id)
Definition TGWindow.h:34
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:127
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
TClass * IsA() const override
Definition TGWindow.h:128
An abstract interface to image processing library.
Definition TImage.h:29
virtual void FillRectangle(const char *=nullptr, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition TImage.h:192
static TImage * Create()
Create an image.
Definition TImage.cxx:34
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:236
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=nullptr)
Definition TImage.h:116
virtual Pixmap_t GetMask()
Definition TImage.h:237
TObject * Next()
A doubly linked list.
Definition TList.h:38
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:865
Bool_t Disconnect(const char *signal=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
void AddReference()
Definition TRefCnt.h:40
Basic string class.
Definition TString.h:138
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:670
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
const char * Data() const
Definition TString.h:384
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1159
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:2385
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
STL class.
TText * text
int main(int argc, char **argv)
Definition hadd.cxx:631
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Event structure.
Definition GuiTypes.h:175
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:179
Window_t fWindow
window reported event is relative to
Definition GuiTypes.h:177
UInt_t fState
key or button mask
Definition GuiTypes.h:182
Int_t fX
Definition GuiTypes.h:179
Graphics context structure.
Definition GuiTypes.h:225
ULong_t fBackground
background pixel
Definition GuiTypes.h:229
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:252
Pixmap_t fTile
tile pixmap for tiling operations
Definition GuiTypes.h:239
Bool_t fGraphicsExposures
boolean, should exposures be generated
Definition GuiTypes.h:245
ULong_t fForeground
foreground pixel
Definition GuiTypes.h:228
Int_t fFillStyle
kFillSolid, kFillTiled, kFillStippled, kFillOpaeueStippled
Definition GuiTypes.h:235
Point structure (maps to the X11 XPoint structure).
Definition GuiTypes.h:357
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:94
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:111
Int_t fWinGravity
one of the window gravity values
Definition GuiTypes.h:101
Int_t fBitGravity
one of bit gravity values
Definition GuiTypes.h:100
TCanvas * style()
Definition style.C:1