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