105 const TGGC *TGButton::fgHibckgndGC = 0;
106 const TGGC *TGButton::fgDefaultGC = 0;
108 const TGFont *TGTextButton::fgDefaultFont = 0;
110 const TGFont *TGCheckButton::fgDefaultFont = 0;
111 const TGGC *TGCheckButton::fgDefaultGC = 0;
113 const TGFont *TGRadioButton::fgDefaultFont = 0;
114 const TGGC *TGRadioButton::fgDefaultGC = 0;
116 Window_t TGButton::fgReleaseBtn = 0;
119 ClassImp(TGTextButton);
120 ClassImp(TGPictureButton);
121 ClassImp(TGCheckButton);
122 ClassImp(TGRadioButton);
123 ClassImp(TGSplitButton);
128 TGButton::TGButton(
const TGWindow *p, Int_t
id, GContext_t norm, UInt_t options)
129 : TGFrame(p, 1, 1, options)
132 fWidgetFlags = kWidgetWantFocus;
138 fTWidth = fTHeight = 0;
143 fWidgetFlags = kWidgetIsEnabled;
152 if (p && p->IsA()->InheritsFrom(TGButtonGroup::Class())) {
153 TGButtonGroup *bg = (TGButtonGroup*) p;
154 bg->Insert(
this,
id);
157 fBgndColor = fBackground;
158 fHighColor = gClient->GetResourcePool()->GetHighLightColor();
160 gVirtualX->GrabButton(fId, kButton1, kAnyModifier,
161 kButtonPressMask | kButtonReleaseMask,
164 AddInput(kEnterWindowMask | kLeaveWindowMask);
171 TGButton::~TGButton()
175 fGroup->Remove(
this);
179 if (fTip)
delete fTip;
185 void TGButton::SetState(EButtonState state, Bool_t emit)
187 Bool_t was = !IsDown();
189 if (state == kButtonDisabled)
190 fWidgetFlags &= ~kWidgetIsEnabled;
192 fWidgetFlags |= kWidgetIsEnabled;
193 if (state != fState) {
197 fOptions &= ~kRaisedFrame;
198 fOptions |= kSunkenFrame;
200 case kButtonDisabled:
203 fOptions &= ~kRaisedFrame;
204 fOptions &= ~kSunkenFrame;
207 fOptions &= ~kSunkenFrame;
208 fOptions |= kRaisedFrame;
214 if (emit || fGroup) EmitSignals(was);
221 void TGButton::SetStyle(UInt_t newstyle)
224 fBgndColor = fBackground;
226 ChangeOptions(GetOptions() & ~kRaisedFrame);
229 ChangeOptions(GetOptions() | kRaisedFrame);
236 void TGButton::SetStyle(
const char *style)
238 fBgndColor = fBackground;
239 if (style && strstr(style,
"modern")) {
241 ChangeOptions(GetOptions() & ~kRaisedFrame);
245 ChangeOptions(GetOptions() | kRaisedFrame);
251 Bool_t TGButton::IsDown()
const
254 return (fOptions & kSunkenFrame);
255 return !(fOptions & kRaisedFrame);
260 void TGButton::SetDown(Bool_t on, Bool_t emit)
264 if (GetState() == kButtonDisabled)
return;
266 SetState(on ? kButtonDown : kButtonUp, emit);
272 void TGButton::SetGroup(TGButtonGroup *group)
280 Bool_t TGButton::HandleButton(Event_t *event)
282 Bool_t click = kFALSE;
284 if (fTip) fTip->Hide();
286 if (fState == kButtonDisabled)
return kTRUE;
288 Bool_t in = (
event->fX >= 0) && (event->fY >= 0) &&
289 (
event->fX <= (Int_t)fWidth) && (
event->fY <= (Int_t)fHeight);
293 if (event->fType == kButtonPress) {
296 if (fState == kButtonEngaged) {
299 if (in) SetState(kButtonDown, kTRUE);
301 if (fState == kButtonEngaged) {
302 if (in) SetState(kButtonUp, kTRUE);
305 click = (fState == kButtonDown) && in;
306 if (click && fStayDown) {
308 SetState(kButtonEngaged, kTRUE);
313 SetState(kButtonUp, kTRUE);
320 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
322 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
325 if ((fStyle > 0) && (event->fType == kButtonRelease)) {
326 fBgndColor = fBackground;
335 void TGButton::EmitSignals(Bool_t was)
337 Bool_t now = !IsDown();
342 if (fStayDown) Clicked();
348 if ((was != now) && IsToggleButton()) Toggled(!now);
354 Bool_t TGButton::HandleCrossing(Event_t *event)
357 if (event->fType == kEnterNotify)
364 if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
365 fBgndColor = fHighColor;
367 fBgndColor = fBackground;
369 if (event->fType == kLeaveNotify) {
370 fBgndColor = fBackground;
375 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow))
return kTRUE;
377 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
380 if (fState == kButtonEngaged || fState == kButtonDisabled)
return kTRUE;
382 if (event->fType == kLeaveNotify) {
384 SetState(kButtonUp, kFALSE);
395 void TGButton::SetToolTipText(
const char *text, Long_t delayms)
402 if (text && strlen(text))
403 fTip =
new TGToolTip(fClient->GetDefaultRoot(),
this, text, delayms);
409 void TGButton::SetEnabled(Bool_t e)
411 SetState(e ? kButtonUp : kButtonDisabled);
413 if (e) fWidgetFlags |= kWidgetIsEnabled;
414 else fWidgetFlags &= ~kWidgetIsEnabled;
420 const TGGC &TGButton::GetDefaultGC()
423 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
430 const TGGC &TGButton::GetHibckgndGC()
434 gval.fMask = kGCForeground | kGCBackground | kGCTile |
435 kGCFillStyle | kGCGraphicsExposures;
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);
443 return *fgHibckgndGC;
451 TGTextButton::TGTextButton(
const TGWindow *p, TGHotString *s, Int_t
id,
452 GContext_t norm, FontStruct_t font,
453 UInt_t options) : TGButton(p, id, norm, options)
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)
468 fLabel =
new TGHotString(!p && !s ? GetName() : s);
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)
481 fLabel =
new TGHotString(s);
491 void TGTextButton::Init()
495 fTMode = kTextCenterX | kTextCenterY;
497 fHasOwnFont = kFALSE;
501 fMLeft = fMRight = fMTop = fMBottom = 0;
503 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
505 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
506 if (font) fFontStruct = font->GetFontStruct();
509 fTLayout = font->ComputeTextLayout(fLabel->GetString(), fLabel->GetLength(),
510 fWrapLength, kTextLeft, 0,
511 &fTWidth, &fTHeight);
517 if ((hotchar = fLabel->GetHotChar()) != 0) {
518 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
519 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
521 main->BindKey(
this, fHKeycode, kKeyMod1Mask);
522 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
523 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
524 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
526 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
527 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
528 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
529 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
533 SetWindowAttributes_t wattr;
534 wattr.fMask = kWAWinGravity | kWABitGravity;
535 wattr.fBitGravity = 5;
536 wattr.fWinGravity = 1;
537 gVirtualX->ChangeWindowAttributes(fId, &wattr);
545 TGTextButton::~TGTextButton()
547 if (fHKeycode && (fParent->MustCleanup() != kDeepCleanup)) {
548 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
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);
555 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
556 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
557 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
558 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
561 if (fLabel)
delete fLabel;
563 TGGCPool *pool = fClient->GetGCPool();
564 TGGC *gc = pool->FindGC(fNormGC);
574 void TGTextButton::Layout()
578 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
580 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
581 if (font) fFontStruct = font->GetFontStruct();
584 fTLayout = font->ComputeTextLayout(fLabel->GetString(), fLabel->GetLength(),
585 fWrapLength, kTextLeft, 0,
586 &fTWidth, &fTHeight);
588 fClient->NeedRedraw(
this);
594 void TGTextButton::SetText(TGHotString *new_label)
597 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
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);
606 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
607 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
608 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
609 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
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);
620 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
622 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
623 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
624 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
625 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
635 void TGTextButton::SetText(
const TString &new_label)
637 SetText(
new TGHotString(new_label));
645 void TGTextButton::SetTextJustify(Int_t mode)
649 SetWindowAttributes_t wattr;
650 wattr.fMask = kWAWinGravity | kWABitGravity;
651 wattr.fWinGravity = 1;
654 case kTextTop | kTextLeft:
655 wattr.fBitGravity = 1;
657 case kTextTop | kTextCenterX:
659 wattr.fBitGravity = 2;
661 case kTextTop | kTextRight:
662 wattr.fBitGravity = 3;
664 case kTextLeft | kTextCenterY:
666 wattr.fBitGravity = 4;
668 case kTextCenterY | kTextCenterX:
669 wattr.fBitGravity = 5;
671 case kTextRight | kTextCenterY:
673 wattr.fBitGravity = 6;
675 case kTextBottom | kTextLeft:
676 wattr.fBitGravity = 7;
678 case kTextBottom | kTextCenterX:
680 wattr.fBitGravity = 8;
682 case kTextBottom | kTextRight:
683 wattr.fBitGravity = 9;
686 wattr.fBitGravity = 5;
690 gVirtualX->ChangeWindowAttributes(fId, &wattr);
697 void TGTextButton::DoRedraw()
700 UInt_t w = GetWidth() - 1;
701 UInt_t h = GetHeight()- 1;
703 if ((fStyle > 0) && !(fOptions & kOwnBackground))
704 gVirtualX->SetWindowBackground(fId, fBgndColor);
707 if (fTMode & kTextLeft) {
709 }
else if (fTMode & kTextRight) {
710 x = fWidth - fTWidth - fMRight - 4;
712 x = (fWidth - fTWidth + fMLeft - fMRight) >> 1;
715 if (fTMode & kTextTop) {
717 }
else if (fTMode & kTextBottom) {
718 y = fHeight - fTHeight - fMBottom - 3;
720 y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
723 if (fState == kButtonDown || fState == kButtonEngaged) {
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);
734 Int_t hotpos = fLabel->GetHotPos();
737 gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
739 if (fState == kButtonDisabled) {
740 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
741 TGGC *gc = pool->FindGC(fNormGC);
743 Pixel_t fore = gc->GetForeground();
744 Pixel_t hi = GetHilightGC().GetForeground();
745 Pixel_t sh = GetShadowGC().GetForeground();
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);
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);
757 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
758 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
765 Bool_t TGTextButton::HandleKey(Event_t *event)
767 Bool_t click = kFALSE;
768 Bool_t was = !IsDown();
770 if (event->fType == kGKeyPress) {
771 gVirtualX->SetKeyAutoRepeat(kFALSE);
773 gVirtualX->SetKeyAutoRepeat(kTRUE);
776 if (fTip && event->fType == kGKeyPress) fTip->Hide();
778 if (fState == kButtonDisabled)
return kTRUE;
783 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
784 if (fState == kButtonEngaged)
return kTRUE;
785 SetState(kButtonDown);
786 }
else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
787 if (fState == kButtonEngaged )
return kTRUE;
788 click = (fState == kButtonDown);
789 if (click && fStayDown) {
790 SetState(kButtonEngaged);
796 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
798 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
809 TGDimension TGTextButton::GetDefaultSize()
const
811 UInt_t w = GetOptions() & kFixedWidth ? fWidth : fTWidth + fMLeft + fMRight + 8;
812 UInt_t h = GetOptions() & kFixedHeight ? fHeight : fTHeight + fMTop + fMBottom + 7;
813 return TGDimension(w, h);
819 FontStruct_t TGTextButton::GetDefaultFontStruct()
822 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
823 return fgDefaultFont->GetFontStruct();
830 void TGTextButton::SetFont(FontStruct_t font, Bool_t global)
832 if (font != fFontStruct) {
833 FontH_t v = gVirtualX->GetFontHandle(font);
837 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
838 TGGC *gc = pool->FindGC(fNormGC);
841 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
846 fNormGC = gc->GetGC();
856 void TGTextButton::SetFont(
const char *fontName, Bool_t global)
858 TGFont *font = fClient->GetFont(fontName);
860 SetFont(font->GetFontStruct(), global);
868 void TGTextButton::SetTextColor(Pixel_t color, Bool_t global)
870 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
871 TGGC *gc = pool->FindGC(fNormGC);
874 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
878 gc->SetForeground(color);
879 fNormGC = gc->GetGC();
881 fClient->NeedRedraw(
this);
888 Bool_t TGTextButton::HasOwnFont()
const
898 TGPictureButton::TGPictureButton(
const TGWindow *p,
const TGPicture *pic,
899 Int_t
id, GContext_t norm, UInt_t option) : TGButton(p, id, norm, option)
902 Error(
"TGPictureButton",
"pixmap not found for button %d",
id);
903 fPic = fClient->GetPicture(
"mb_question_s.xpm");
909 fTWidth = fPic->GetWidth();
910 fTHeight = fPic->GetHeight();
912 Resize(fTWidth + (fBorderWidth << 1) + fBorderWidth + 1,
913 fTHeight + (fBorderWidth << 1) + fBorderWidth);
916 fOwnDisabledPic = kFALSE;
926 TGPictureButton::TGPictureButton(
const TGWindow *p,
const TGPicture *pic,
927 const char *cmd, Int_t
id, GContext_t norm, UInt_t option)
928 : TGButton(p, id, norm, option)
931 Error(
"TGPictureButton",
"pixmap not found for button\n%s",
933 fPic = fClient->GetPicture(
"mb_question_s.xpm");
941 fTWidth = fPic->GetWidth();
942 fTHeight = fPic->GetHeight();
944 Resize(fTWidth + (fBorderWidth << 1) + fBorderWidth + 1,
945 fTHeight + (fBorderWidth << 1) + fBorderWidth);
948 fOwnDisabledPic = kFALSE;
955 TGPictureButton::TGPictureButton(
const TGWindow *p,
const char *pic,
956 Int_t
id, GContext_t norm, UInt_t option) : TGButton(p, id, norm, option)
958 if (!pic || !pic[0]) {
959 if (p) Error(
"TGPictureButton",
"pixmap not found for button");
960 fPic = fClient->GetPicture(
"mb_question_s.xpm");
962 fPic = fClient->GetPicture(pic);
966 fTWidth = fPic->GetWidth();
967 fTHeight = fPic->GetHeight();
969 Resize(fTWidth + (fBorderWidth << 1) + fBorderWidth + 1,
970 fTHeight + (fBorderWidth << 1) + fBorderWidth);
973 fOwnDisabledPic = kFALSE;
980 TGPictureButton::~TGPictureButton()
982 if (fOwnDisabledPic) fClient->FreePicture(fPicD);
990 void TGPictureButton::SetPicture(
const TGPicture *new_pic)
993 Error(
"SetPicture",
"pixmap not found for button %d\n%s",
994 fWidgetId, fCommand.Data());
1000 if (fState == kButtonDisabled) {
1001 fClient->FreePicture(fPicD);
1005 fTWidth = fPic->GetWidth();
1006 fTHeight = fPic->GetHeight();
1008 fClient->NeedRedraw(
this);
1014 void TGPictureButton::DoRedraw()
1017 TGFrame::DoRedraw();
1021 int x = (fWidth - fTWidth) >> 1;
1022 int y = (fHeight - fTHeight) >> 1;
1023 UInt_t w = GetWidth() - 1;
1024 UInt_t h = GetHeight()- 1;
1026 if ((fStyle > 0) && !(fOptions & kOwnBackground))
1027 gVirtualX->SetWindowBackground(fId, fBgndColor);
1028 TGFrame::DoRedraw();
1030 if (fState == kButtonDown || fState == kButtonEngaged) {
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);
1041 const TGPicture *pic = fPic;
1042 if (fState == kButtonDisabled) {
1043 if (!fPicD) CreateDisabledPicture();
1044 pic = fPicD ? fPicD : fPic;
1047 if (fBgndColor == fHighColor) {
1048 gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
1052 pic->Draw(fId, fNormGC, x, y);
1058 void TGPictureButton::CreateDisabledPicture()
1060 TImage *img = TImage::Create();
1062 TImage *img2 = TImage::Create();
1064 if (img)
delete img;
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");
1073 TString name =
"disbl_";
1074 name += fPic->GetName();
1075 fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), img2->GetPixmap(),
1077 fOwnDisabledPic = kTRUE;
1085 void TGPictureButton::SetDisabledPicture(
const TGPicture *pic)
1089 if (fOwnDisabledPic && fPicD) fClient->FreePicture(fPicD);
1091 ((TGPicture*)pic)->AddReference();
1092 fOwnDisabledPic = kFALSE;
1099 TGCheckButton::TGCheckButton(
const TGWindow *p, TGHotString *s, Int_t
id,
1100 GContext_t norm, FontStruct_t font, UInt_t option)
1101 : TGTextButton(p, s, id, norm, font, option)
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)
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)
1129 void TGCheckButton::Init()
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");
1143 Error(
"TGCheckButton",
"checked_t.xpm not found");
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");
1153 if ((hotchar = fLabel->GetHotChar()) != 0) {
1154 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
1155 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
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);
1162 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
1163 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
1164 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
1165 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
1175 TGCheckButton::~TGCheckButton()
1177 if (fOn) fClient->FreePicture(fOn);
1178 if (fOff) fClient->FreePicture(fOff);
1179 if (fDisOn) fClient->FreePicture(fDisOn);
1180 if (fDisOff) fClient->FreePicture(fDisOff);
1186 TGDimension TGCheckButton::GetDefaultSize()
const
1188 UInt_t w = !fTWidth ? fOff->GetWidth() : fTWidth + fOff->GetWidth() + 9;
1189 UInt_t h = !fTHeight ? fOff->GetHeight() : fTHeight + 2;
1191 w = GetOptions() & kFixedWidth ? fWidth : w;
1192 h = GetOptions() & kFixedHeight ? fHeight : h;
1194 return TGDimension(w, h);
1200 void TGCheckButton::SetState(EButtonState state, Bool_t emit)
1202 if (state == kButtonDisabled)
1203 fWidgetFlags &= ~kWidgetIsEnabled;
1205 fWidgetFlags |= kWidgetIsEnabled;
1206 PSetState(state, emit);
1212 void TGCheckButton::EmitSignals(Bool_t )
1214 if (fState == kButtonUp) Released();
1215 if (fState == kButtonDown) Pressed();
1223 void TGCheckButton::PSetState(EButtonState state, Bool_t emit)
1225 if (state != fState) {
1226 if (state == kButtonUp) {
1227 if (fPrevState == kButtonDisabled) {
1229 fState = kButtonDown;
1230 fPrevState = kButtonDown;
1235 }
else if (fPrevState == kButtonDown) {
1240 }
else if (state == kButtonDown) {
1260 void TGCheckButton::SetDisabledAndSelected(Bool_t enable)
1263 if (fState == kButtonDisabled && fStateOn) {
1264 PSetState(kButtonUp, kFALSE);
1265 PSetState(kButtonUp, kFALSE);
1266 PSetState(kButtonDisabled, kFALSE);
1268 PSetState(kButtonUp, kFALSE);
1269 PSetState(kButtonDisabled, kFALSE);
1272 PSetState(kButtonDown, kFALSE);
1273 PSetState(kButtonDisabled, kFALSE);
1280 Bool_t TGCheckButton::HandleButton(Event_t *event)
1282 Bool_t click = kFALSE;
1284 if (fTip) fTip->Hide();
1286 if (fState == kButtonDisabled)
return kTRUE;
1288 Bool_t in = (
event->fX >= 0) && (event->fY >= 0) &&
1289 (
event->fX <= (Int_t)fWidth) && (
event->fY <= (Int_t)fHeight);
1293 if (event->fType == kButtonPress) {
1296 fOptions |= kSunkenFrame;
1301 PSetState((fPrevState == kButtonUp) ? kButtonDown : kButtonUp, kFALSE);
1303 fPrevStateOn = fStateOn;
1307 fOptions &= ~kSunkenFrame;
1312 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_CHECKBUTTON),
1313 fWidgetId, (Long_t) fUserData);
1314 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_CHECKBUTTON),
1315 fWidgetId, (Long_t) fUserData);
1324 Bool_t TGCheckButton::HandleCrossing(Event_t *event)
1327 if (event->fType == kEnterNotify)
1333 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow))
return kTRUE;
1335 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
1338 if (fState == kButtonDisabled)
return kTRUE;
1340 if (event->fType == kEnterNotify) {
1341 fOptions |= kSunkenFrame;
1343 fOptions &= ~kSunkenFrame;
1353 Bool_t TGCheckButton::HandleKey(Event_t *event)
1355 Bool_t click = kFALSE;
1357 if (event->fType == kGKeyPress)
1358 gVirtualX->SetKeyAutoRepeat(kFALSE);
1360 gVirtualX->SetKeyAutoRepeat(kTRUE);
1362 if (fTip && event->fType == kGKeyPress) fTip->Hide();
1364 if (fState == kButtonDisabled)
return kTRUE;
1369 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
1370 PSetState((fPrevState == kButtonUp) ? kButtonDown : kButtonUp, kTRUE);
1371 }
else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
1372 click = (fState != fPrevState);
1373 fPrevState = fState;
1376 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_CHECKBUTTON), fWidgetId,
1377 (Long_t) fUserData);
1378 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_CHECKBUTTON), fWidgetId,
1379 (Long_t) fUserData);
1387 void TGCheckButton::DoRedraw()
1391 TGFrame::DoRedraw();
1394 y = (fHeight - fTHeight) >> 1;
1396 y0 = !fTHeight ? 0 : y + 1;
1398 Int_t smax = TMath::Max(fOn->GetHeight(), fOff->GetHeight());
1399 y0 = ((Int_t)fHeight <= smax) ? 0 : 1 + (((Int_t)fHeight - smax) >> 1);
1403 if (fOn) fOn->Draw(fId, fNormGC, 0, y0);
1405 if (fOff) fOff->Draw(fId, fNormGC, 0, y0);
1408 Int_t hotpos = fLabel->GetHotPos();
1410 if (fState == kButtonDisabled) {
1411 if (fStateOn == kTRUE) {
1412 if (fDisOn) fDisOn->Draw(fId, fNormGC, 0, y0);
1414 if (fDisOff) fDisOff->Draw(fId, fNormGC, 0, y0);
1417 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
1418 TGGC *gc = pool->FindGC(fNormGC);
1420 Pixel_t fore = gc->GetForeground();
1421 Pixel_t hi = GetHilightGC().GetForeground();
1422 Pixel_t sh = GetShadowGC().GetForeground();
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);
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);
1432 gc->SetForeground(fore);
1435 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
1436 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
1443 FontStruct_t TGCheckButton::GetDefaultFontStruct()
1446 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1447 return fgDefaultFont->GetFontStruct();
1453 const TGGC &TGCheckButton::GetDefaultGC()
1456 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1457 return *fgDefaultGC;
1465 TGRadioButton::TGRadioButton(
const TGWindow *p, TGHotString *s, Int_t
id,
1466 GContext_t norm, FontStruct_t font, UInt_t option)
1467 : TGTextButton(p, s, id, norm, font, option)
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)
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)
1495 void TGRadioButton::Init()
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");
1506 if (!fOn || !fOff || !fDisOn || !fDisOff)
1507 Error(
"TGRadioButton",
"rbutton_*.xpm not found");
1513 if ((hotchar = fLabel->GetHotChar()) != 0) {
1514 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
1515 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
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);
1522 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
1523 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
1524 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
1525 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
1530 if (fParent->IsA()->InheritsFrom(TGButtonGroup::Class())) {
1531 ((TGButtonGroup*)fParent)->SetRadioButtonExclusive(kTRUE);
1539 TGRadioButton::~TGRadioButton()
1541 if (fOn) fClient->FreePicture(fOn);
1542 if (fOff) fClient->FreePicture(fOff);
1543 if (fDisOn) fClient->FreePicture(fDisOn);
1544 if (fDisOff) fClient->FreePicture(fDisOff);
1550 TGDimension TGRadioButton::GetDefaultSize()
const
1552 UInt_t w = !fTWidth ? fOff->GetWidth() : fTWidth + fOff->GetWidth() + 10;
1553 UInt_t h = !fTHeight ? fOff->GetHeight() : fTHeight + 2;
1555 w = GetOptions() & kFixedWidth ? fWidth : w;
1556 h = GetOptions() & kFixedHeight ? fHeight : h;
1558 return TGDimension(w, h);
1563 void TGRadioButton::SetState(EButtonState state, Bool_t emit)
1565 if (state == kButtonDisabled)
1566 fWidgetFlags &= ~kWidgetIsEnabled;
1568 fWidgetFlags |= kWidgetIsEnabled;
1569 PSetState(state, emit);
1576 void TGRadioButton::SetDisabledAndSelected(Bool_t enable)
1579 if (fState == kButtonDisabled && fStateOn) {
1580 PSetState(kButtonUp, kFALSE);
1581 PSetState(kButtonUp, kFALSE);
1582 PSetState(kButtonDisabled, kFALSE);
1584 PSetState(kButtonUp, kFALSE);
1585 PSetState(kButtonDisabled, kFALSE);
1588 PSetState(kButtonDown, kFALSE);
1589 PSetState(kButtonDisabled, kFALSE);
1596 void TGRadioButton::EmitSignals(Bool_t )
1598 if (fState == kButtonUp) Released();
1599 if (fState == kButtonDown) Pressed();
1607 void TGRadioButton::PSetState(EButtonState state, Bool_t emit)
1609 if (state != fState) {
1611 if (state == kButtonUp) {
1612 if (fPrevState == kButtonDisabled) {
1614 fState = kButtonDown;
1615 fPrevState = kButtonDown;
1620 }
else if (fPrevState == kButtonDown) {
1625 }
else if (state == kButtonDown) {
1644 Bool_t TGRadioButton::HandleButton(Event_t *event)
1646 Bool_t click = kFALSE;
1647 Bool_t toggled = kFALSE;
1649 if (fTip) fTip->Hide();
1651 if (fState == kButtonDisabled)
return kFALSE;
1654 Bool_t in = (
event->fX >= 0) && (event->fY >= 0) &&
1655 (
event->fX <= (Int_t)fWidth) && (
event->fY <= (Int_t)fHeight);
1657 if (event->fType == kButtonPress) {
1660 fOptions |= kSunkenFrame;
1666 PSetState(kButtonDown, kFALSE);
1669 fPrevStateOn = fStateOn;
1673 fOptions &= ~kSunkenFrame;
1678 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_RADIOBUTTON),
1679 fWidgetId, (Long_t) fUserData);
1680 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_RADIOBUTTON),
1681 fWidgetId, (Long_t) fUserData);
1693 Bool_t TGRadioButton::HandleCrossing(Event_t *event)
1696 if (event->fType == kEnterNotify)
1702 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow))
return kTRUE;
1704 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
1707 if (fState == kButtonDisabled)
return kTRUE;
1709 if (event->fType == kEnterNotify) {
1710 fOptions |= kSunkenFrame;
1712 fOptions &= ~kSunkenFrame;
1722 Bool_t TGRadioButton::HandleKey(Event_t *event)
1724 if (event->fType == kGKeyPress)
1725 gVirtualX->SetKeyAutoRepeat(kFALSE);
1727 gVirtualX->SetKeyAutoRepeat(kTRUE);
1729 if (fTip && event->fType == kGKeyPress)
1732 if (fState == kButtonDisabled)
return kTRUE;
1737 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
1738 PSetState(kButtonDown, kTRUE);
1739 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_RADIOBUTTON),
1740 fWidgetId, (Long_t) fUserData);
1741 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_RADIOBUTTON),
1742 fWidgetId, (Long_t) fUserData);
1743 }
else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
1744 fPrevState = fState;
1752 void TGRadioButton::DoRedraw()
1756 TGFrame::DoRedraw();
1759 ty = (fHeight - fTHeight) >> 1;
1762 y0 = !fTHeight ? 0 : ty + 1;
1764 Int_t smax = TMath::Max(fOn->GetHeight(), fOff->GetHeight());
1765 y0 = ((Int_t)fHeight <= smax) ? 0 : 1 + (((Int_t)fHeight - smax) >> 1);
1769 if (fOn) fOn->Draw(fId, fNormGC, 0, y0);
1771 if (fOff) fOff->Draw(fId, fNormGC, 0, y0);
1774 Int_t hotpos = fLabel->GetHotPos();
1776 if (fState == kButtonDisabled) {
1777 if (fStateOn == kTRUE) {
1778 if (fDisOn) fDisOn->Draw(fId, fNormGC, 0, y0);
1780 if (fDisOff) fDisOff->Draw(fId, fNormGC, 0, y0);
1783 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
1784 TGGC *gc = pool->FindGC(fNormGC);
1786 Pixel_t fore = gc->GetForeground();
1787 Pixel_t hi = GetHilightGC().GetForeground();
1788 Pixel_t sh = GetShadowGC().GetForeground();
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);
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);
1798 gc->SetForeground(fore);
1801 fTLayout->DrawText(fId, fNormGC, tx, ty, 0, -1);
1802 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, tx, ty, hotpos-1);
1809 FontStruct_t TGRadioButton::GetDefaultFontStruct()
1812 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1813 return fgDefaultFont->GetFontStruct();
1819 const TGGC &TGRadioButton::GetDefaultGC()
1822 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1823 return *fgDefaultGC;
1829 void TGButton::SavePrimitive(std::ostream &out, Option_t *option )
1833 if (option && strstr(option,
"keep_names"))
1834 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
1836 if (fState == kButtonDown) {
1837 out <<
" " << GetName() <<
"->SetState(kButtonDown);" << std::endl;
1839 if (fState == kButtonDisabled) {
1840 out <<
" " << GetName() <<
"->SetState(kButtonDisabled);" << std::endl;
1842 if (fState == kButtonEngaged) {
1843 out <<
" " << GetName() <<
"->SetState(kButtonEngaged);" << std::endl;
1845 if (fBackground != fgDefaultFrameBackground) {
1846 SaveUserColor(out, option);
1847 out <<
" " << GetName() <<
"->ChangeBackground(ucolor);" << std::endl;
1851 TString tiptext = fTip->GetText()->GetString();
1852 tiptext.ReplaceAll(
"\n",
"\\n");
1854 out << GetName() <<
"->SetToolTipText(" << quote
1855 << tiptext << quote <<
");" << std::endl;
1857 if (strlen(fCommand)) {
1858 out <<
" " << GetName() <<
"->SetCommand(" << quote << fCommand
1859 << quote <<
");" << std::endl;
1866 void TGTextButton::SavePrimitive(std::ostream &out, Option_t *option )
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");
1876 option = GetName()+5;
1877 TString parGC, parFont;
1878 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
1879 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
1881 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
1882 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
1884 ufont->SavePrimitive(out, option);
1885 parFont.Form(
"ufont->GetFontStruct()");
1888 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
1890 userGC->SavePrimitive(out, option);
1891 parGC.Form(
"uGC->GetGC()");
1895 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
1897 out <<
" TGTextButton *";
1898 out << GetName() <<
" = new TGTextButton(" << fParent->GetName()
1899 <<
"," << quote << outext.Data() << quote;
1901 if (GetOptions() == (kRaisedFrame | kDoubleBorder)) {
1902 if (fFontStruct == GetDefaultFontStruct()) {
1903 if (fNormGC == GetDefaultGC()()) {
1904 if (fWidgetId == -1) {
1905 out <<
");" << std::endl;
1907 out <<
"," << fWidgetId <<
");" << std::endl;
1910 out <<
"," << fWidgetId <<
"," << parGC <<
");" << std::endl;
1913 out <<
"," << fWidgetId <<
"," << parGC <<
"," << parFont <<
");" << std::endl;
1916 out <<
"," << fWidgetId <<
"," << parGC <<
"," << parFont <<
"," << GetOptionString() <<
");" << std::endl;
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;
1924 out <<
" " << GetName() <<
"->Resize(" << GetWidth() <<
"," << GetHeight()
1925 <<
");" << std::endl;
1927 TGButton::SavePrimitive(out,option);
1933 void TGPictureButton::SavePrimitive(std::ostream &out, Option_t *option )
1936 Error(
"SavePrimitive()",
"pixmap not found for picture button %d ", fWidgetId);
1941 option = GetName()+5;
1943 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
1945 if (GetDefaultGC()() != fNormGC) {
1946 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
1948 userGC->SavePrimitive(out, option);
1949 parGC.Form(
"uGC->GetGC()");
1954 const char *picname = fPic->GetName();
1956 out <<
" TGPictureButton *";
1958 out << GetName() <<
" = new TGPictureButton(" << fParent->GetName()
1959 <<
",gClient->GetPicture(" << quote
1960 << gSystem->ExpandPathName(gSystem->UnixPathName(picname)) << quote <<
")";
1962 if (GetOptions() == (kRaisedFrame | kDoubleBorder)) {
1963 if (fNormGC == GetDefaultGC()()) {
1964 if (fWidgetId == -1) {
1965 out <<
");" << std::endl;
1967 out <<
"," << fWidgetId <<
");" << std::endl;
1970 out <<
"," << fWidgetId <<
"," << parGC.Data() <<
");" << std::endl;
1973 out <<
"," << fWidgetId <<
"," << parGC.Data() <<
"," << GetOptionString()
1974 <<
");" << std::endl;
1977 TGButton::SavePrimitive(out,option);
1983 void TGCheckButton::SavePrimitive(std::ostream &out, Option_t *option )
1987 TString outext(fLabel->GetString());
1988 if (fLabel->GetHotPos() > 0)
1989 outext.Insert(fLabel->GetHotPos()-1,
"&");
1990 if (outext.First(
'\n') >= 0)
1991 outext.ReplaceAll(
"\n",
"\\n");
1993 out <<
" TGCheckButton *";
1994 out << GetName() <<
" = new TGCheckButton(" << fParent->GetName()
1995 <<
"," << quote << outext.Data() << quote;
1998 option = GetName()+5;
1999 TString parGC, parFont;
2000 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
2001 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
2003 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
2004 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
2006 ufont->SavePrimitive(out, option);
2007 parFont.Form(
"ufont->GetFontStruct()");
2010 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
2012 userGC->SavePrimitive(out, option);
2013 parGC.Form(
"uGC->GetGC()");
2017 if (GetOptions() == kChildFrame) {
2018 if (fFontStruct == GetDefaultFontStruct()) {
2019 if (fNormGC == GetDefaultGC()()) {
2020 if (fWidgetId == -1) {
2021 out <<
");" << std::endl;
2023 out <<
"," << fWidgetId <<
");" << std::endl;
2026 out <<
"," << fWidgetId <<
"," << parGC <<
");" << std::endl;
2029 out <<
"," << fWidgetId <<
"," << parGC <<
"," << parFont <<
");" << std::endl;
2032 out <<
"," << fWidgetId <<
"," << parGC <<
"," << parFont <<
"," << GetOptionString() <<
");" << std::endl;
2035 TGButton::SavePrimitive(out,option);
2036 if (fState == kButtonDisabled) {
2037 if (IsDisabledAndSelected())
2038 out <<
" " << GetName() <<
"->SetDisabledAndSelected(kTRUE);" << std::endl;
2040 out <<
" " << GetName() <<
"->SetDisabledAndSelected(kFALSE);" << std::endl;
2042 out <<
" " << GetName() <<
"->SetTextJustify(" << fTMode <<
");" << std::endl;
2043 out <<
" " << GetName() <<
"->SetMargins(" << fMLeft <<
"," << fMRight <<
",";
2044 out << fMTop <<
"," << fMBottom <<
");" << std::endl;
2045 out <<
" " << GetName() <<
"->SetWrapLength(" << fWrapLength <<
");" << std::endl;
2051 void TGRadioButton::SavePrimitive(std::ostream &out, Option_t *option )
2055 TString outext(fLabel->GetString());
2056 if (fLabel->GetHotPos() > 0)
2057 outext.Insert(fLabel->GetHotPos()-1,
"&");
2058 if (outext.First(
'\n') >= 0)
2059 outext.ReplaceAll(
"\n",
"\\n");
2061 out <<
" TGRadioButton *";
2062 out << GetName() <<
" = new TGRadioButton(" << fParent->GetName()
2063 <<
"," << quote << outext.Data() << quote;
2066 option = GetName()+5;
2067 TString parGC, parFont;
2068 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
2069 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
2071 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
2072 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
2074 ufont->SavePrimitive(out, option);
2075 parFont.Form(
"ufont->GetFontStruct()");
2078 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
2080 userGC->SavePrimitive(out, option);
2081 parGC.Form(
"uGC->GetGC()");
2085 if (GetOptions() == (kChildFrame)) {
2086 if (fFontStruct == GetDefaultFontStruct()) {
2087 if (fNormGC == GetDefaultGC()()) {
2088 if (fWidgetId == -1) {
2089 out <<
");" << std::endl;
2091 out <<
"," << fWidgetId <<
");" << std::endl;
2094 out <<
"," << fWidgetId <<
"," << parGC <<
");" << std::endl;
2097 out <<
"," << fWidgetId <<
"," << parGC <<
"," << parFont <<
");" << std::endl;
2100 out <<
"," << fWidgetId <<
"," << parGC <<
"," << parFont <<
"," << GetOptionString() <<
");" << std::endl;
2103 TGButton::SavePrimitive(out,option);
2104 if (fState == kButtonDisabled) {
2105 if (IsDisabledAndSelected())
2106 out <<
" " << GetName() <<
"->SetDisabledAndSelected(kTRUE);" << std::endl;
2108 out <<
" " << GetName() <<
"->SetDisabledAndSelected(kFALSE);" << std::endl;
2110 out <<
" " << GetName() <<
"->SetTextJustify(" << fTMode <<
");" << std::endl;
2111 out <<
" " << GetName() <<
"->SetMargins(" << fMLeft <<
"," << fMRight <<
",";
2112 out << fMTop <<
"," << fMBottom <<
");" << std::endl;
2113 out <<
" " << GetName() <<
"->SetWrapLength(" << fWrapLength <<
");" << std::endl;
2122 TGSplitButton::TGSplitButton(
const TGWindow *p, TGHotString* menulabel,
2123 TGPopupMenu *popmenu, Bool_t split, Int_t
id,
2124 GContext_t norm, FontStruct_t fontstruct, UInt_t options)
2125 : TGTextButton(p, menulabel, id, norm, fontstruct, options)
2127 fFontStruct = fontstruct;
2129 fMenuLabel =
new TGHotString(*menulabel);
2131 fPopMenu->fSplitButton =
this;
2135 fMBState = kButtonUp; fDefaultCursor = fClient->GetResourcePool()->GetGrabCursor();
2136 fKeyNavigate = kFALSE;
2138 fHeighestLabel =
"";
2141 TGMenuEntry *entry = 0;
2142 TGHotString lstring(*fMenuLabel);
2143 TGHotString hstring(*fMenuLabel);
2144 const TList *list = fPopMenu->GetListOfEntries();
2145 UInt_t lwidth = 0, lheight = 0;
2146 UInt_t twidth = 0, theight = 0;
2148 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
2150 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
2151 if (font) fFontStruct = font->GetFontStruct();
2154 if (font) font->ComputeTextLayout(lstring, lstring.GetLength(),
2155 fWrapLength, kTextLeft, 0,
2159 entry = (TGMenuEntry *)iter.Next();
2160 while (entry != 0) {
2161 if (entry->GetType() == kMenuEntry) {
2162 const TGHotString string(*(entry->GetLabel()));
2163 if (font) font->ComputeTextLayout(
string,
string.GetLength(),
2164 fWrapLength, kTextLeft, 0,
2166 if(twidth > lwidth) {
2169 if(theight > lheight) {
2173 entry = (TGMenuEntry *)iter.Next();
2175 fWidestLabel = lstring;
2176 fHeighestLabel = hstring;
2180 font->ComputeTextLayout(lstring, lstring.GetLength(),
2181 fWrapLength, kTextLeft, 0,
2183 font->ComputeTextLayout(hstring, hstring.GetLength(),
2184 fWrapLength, kTextLeft, 0,
2187 fTBWidth = fTWidth + 8;
2188 fHeight = fTHeight + 7;
2189 Resize(fTBWidth + fMBWidth, fHeight);
2191 ChangeOptions(GetOptions() | kFixedSize);
2196 entry = (TGMenuEntry *)iter1.Next();
2197 if ((entry) && (entry->GetStatus() & kMenuEnableMask) &&
2198 !(entry->GetStatus() & kMenuHideMask) &&
2199 (entry->GetType() != kMenuSeparator) &&
2200 (entry->GetType() != kMenuLabel))
break;
2201 entry = (TGMenuEntry *)iter1.Next();
2203 if (entry) fEntryId = entry->GetEntryId();
2206 fPopMenu->Connect(
"Activated(Int_t)",
"TGSplitButton",
this,
"HandleMenu(Int_t)");
2216 void TGSplitButton::Init()
2220 fTMode = kTextCenterX | kTextCenterY;
2222 fHasOwnFont = kFALSE;
2225 fMBState = kButtonUp;
2227 SetSize(TGDimension(fWidth, fHeight));
2229 if ((hotchar = fLabel->GetHotChar()) != 0) {
2230 if ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0) {
2231 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
2233 main->BindKey(
this, fHKeycode, kKeyMod1Mask);
2234 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2235 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2236 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
2238 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2239 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
2240 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
2241 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
2245 SetWindowAttributes_t wattr;
2246 wattr.fMask = kWAWinGravity | kWABitGravity;
2247 wattr.fBitGravity = 5;
2248 wattr.fWinGravity = 1;
2249 gVirtualX->ChangeWindowAttributes(fId, &wattr);
2252 AddInput(kPointerMotionMask | kEnterWindowMask | kLeaveWindowMask);
2260 TGSplitButton::~TGSplitButton()
2262 if (fPopMenu)
delete fPopMenu;
2263 if (fMenuLabel)
delete fMenuLabel;
2269 void TGSplitButton::DrawTriangle(
const GContext_t gc, Int_t x, Int_t y)
2275 points[1].fX = x + 5;
2277 points[2].fX = x + 2;
2278 points[2].fY = y + 3;
2280 gVirtualX->FillPolygon(fId, gc, points, 3);
2286 void TGSplitButton::CalcSize()
2288 Int_t max_ascent, max_descent;
2289 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
2290 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2291 fTHeight = max_ascent + max_descent;
2293 fTBWidth = fTWidth + 8;
2294 fHeight = fTHeight + 7;
2301 Bool_t TGSplitButton::HandleSButton(Event_t *event)
2303 if (fState == kButtonDisabled)
return kFALSE;
2305 Bool_t activate = kFALSE;
2306 Bool_t bclick = kFALSE;
2307 static Bool_t mbpress = kFALSE;
2308 static Bool_t tbpress = kFALSE;
2309 static Bool_t outpress = kFALSE;
2311 Bool_t inTB = (
event->fX >= 0) && (event->fY >= 0) &&
2312 (
event->fX <= (Int_t)fTBWidth) && (
event->fY <= (Int_t)fHeight);
2314 Bool_t inMB = (
event->fX >= (Int_t)(fWidth -fMBWidth)) && (event->fY >= 0) &&
2315 (
event->fX <= (Int_t)fWidth) && (
event->fY <= (Int_t)fHeight);
2321 if (event->fType == kButtonPress) {
2325 if (fState == kButtonEngaged) {
2328 SetState(kButtonDown);
2331 if (fMBState == kButtonDown) {
2332 SetMBState(kButtonUp);
2334 if (fState == kButtonEngaged && tbpress) {
2335 SetState(kButtonUp);
2338 }
else if (fState == kButtonDown && tbpress) {
2342 SetState(kButtonEngaged);
2346 SetState(kButtonUp);
2351 SetState(kButtonUp);
2355 if (event->fType == kButtonPress) {
2359 if (fMBState == kButtonEngaged) {
2362 SetMBState(kButtonDown);
2364 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
2365 kPointerMotionMask, kNone, fDefaultCursor);
2367 if (fState == kButtonDown) {
2368 SetState(kButtonUp);
2370 if (fMBState == kButtonEngaged && mbpress) {
2372 SetMBState(kButtonUp);
2373 SetMenuState(kFALSE);
2376 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
2377 }
else if (fMBState == kButtonDown && mbpress) {
2379 SetMBState(kButtonEngaged);
2380 SetMenuState(kTRUE);
2383 SetMBState(kButtonUp);
2387 if (event->fType == kButtonPress) {
2393 SetMBState(kButtonUp);
2394 SetMenuState(kFALSE);
2395 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
2402 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2403 (Long_t) fUserData);
2404 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2405 (Long_t) fUserData);
2408 TGMenuEntry *entry = fPopMenu->GetCurrent();
2410 if ((entry->GetStatus() & kMenuEnableMask) &&
2411 !(entry->GetStatus() & kMenuHideMask) &&
2412 (entry->GetType() != kMenuSeparator) &&
2413 (entry->GetType() != kMenuLabel)) {
2414 Int_t
id = entry->GetEntryId();
2415 fPopMenu->Activated(
id);
2432 Bool_t TGSplitButton::HandleSCrossing(Event_t *event)
2435 if (event->fType == kEnterNotify)
2441 if ((fgDbw != event->fWindow) || (fgReleaseBtn == event->fWindow))
return kTRUE;
2443 if (!(event->fState & (kButton1Mask | kButton2Mask | kButton3Mask)))
2446 if (fState == kButtonEngaged || fState == kButtonDisabled)
return kTRUE;
2448 Bool_t inTB = (
event->fX <= (Int_t)fTBWidth);
2453 if (event->fType == kEnterNotify) {
2455 SetState(kButtonDown, kFALSE);
2457 if(fMBState == kButtonEngaged)
return kTRUE;
2458 SetMBState(kButtonDown);
2462 if(fState == kButtonDown) {
2463 SetState(kButtonUp, kFALSE);
2465 if (fMBState == kButtonEngaged)
return kTRUE;
2466 SetMBState(kButtonUp);
2474 Bool_t TGSplitButton::HandleSKey(Event_t *event)
2476 if (fState == kButtonDisabled)
return kFALSE;
2478 Bool_t click = kFALSE;
2480 if (event->fType == kGKeyPress) {
2481 gVirtualX->SetKeyAutoRepeat(kFALSE);
2483 gVirtualX->SetKeyAutoRepeat(kTRUE);
2486 if (fTip && event->fType == kGKeyPress) fTip->Hide();
2491 if ((event->fType == kGKeyPress) && (event->fState & kKeyMod1Mask)) {
2492 if (fState == kButtonEngaged)
return kTRUE;
2493 SetState(kButtonDown);
2495 }
else if ((event->fType == kKeyRelease) && (event->fState & kKeyMod1Mask)) {
2496 if (fState == kButtonEngaged) {
2497 SetState(kButtonUp);
2501 SetState(kButtonEngaged);
2503 SetState(kButtonUp);
2510 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2511 (Long_t) fUserData);
2512 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2513 (Long_t) fUserData);
2522 void TGSplitButton::SetMenuState(Bool_t state)
2529 Int_t n_entries = 0;
2530 TGMenuEntry *entry = 0;
2531 TIter next(fPopMenu->GetListOfEntries());
2533 while ((entry = (TGMenuEntry *) next())) {
2534 if ((entry->GetType() != kMenuSeparator) &&
2535 (entry->GetType() != kMenuLabel)) {
2539 if (n_entries <= 1) {
2540 Info(
"TGSplitButton",
"Only one entry in the menu.");
2545 gVirtualX->TranslateCoordinates(fId, fPopMenu->GetParent()->GetId(),
2546 0, 0, ax, ay, wdummy);
2549 fPopMenu->PlaceMenu(ax-1, ay+fHeight, kTRUE, kFALSE);
2551 BindMenuKeys(kTRUE);
2553 fPopMenu->EndMenu(fUserData);
2555 BindMenuKeys(kFALSE);
2556 fPopMenu->EndMenu(fUserData);
2563 void TGSplitButton::DoRedraw()
2566 TGFrame::DoRedraw();
2568 if (fState == kButtonDisabled) fMBState = kButtonDisabled;
2569 else if (fMBState == kButtonDisabled) fMBState = kButtonUp;
2571 if (fTMode & kTextLeft) {
2573 }
else if (fTMode & kTextRight) {
2574 x = fWidth - fTWidth -fMBWidth - fMRight - 4;
2576 x = (fWidth - fTWidth -fMBWidth + fMLeft - fMRight) >> 1;
2579 if (fTMode & kTextTop) {
2581 }
else if (fTMode & kTextBottom) {
2582 y = fHeight - fTHeight - fMBottom - 3;
2584 y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
2587 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
2588 if (fState == kButtonEngaged) {
2589 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), 2, 2, fWidth-4, fHeight-4);
2590 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 2, fWidth-3, 2);
2593 Int_t hotpos = fLabel->GetHotPos();
2595 if (fState == kButtonDisabled) {
2596 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
2597 TGGC *gc = pool->FindGC(fNormGC);
2599 Pixel_t fore = gc->GetForeground();
2600 Pixel_t hi = GetHilightGC().GetForeground();
2601 Pixel_t sh = GetShadowGC().GetForeground();
2603 gc->SetForeground(hi);
2604 fTLayout->DrawText(fId, gc->GetGC(), x + 1, y + 1, 0, -1);
2605 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x + 1, y + 1, hotpos - 1);
2607 gc->SetForeground(sh);
2608 fTLayout->DrawText(fId, gc->GetGC(), x, y, 0, -1);
2609 if (hotpos) fTLayout->UnderlineChar(fId, gc->GetGC(), x, y, hotpos - 1);
2610 gc->SetForeground(fore);
2613 fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
2614 if (hotpos) fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
2625 Int_t lx = fWidth - fMBWidth;
2627 Int_t lh = fHeight - 2;
2629 if(fMBState == kButtonDown || fMBState == kButtonEngaged) {
2634 gVirtualX->DrawLine(fId, GetShadowGC()(), lx, ly + 2, lx, lh - 4);
2635 gVirtualX->DrawLine(fId, GetHilightGC()(), lx + 1, ly + 2, lx + 1, lh - 3);
2636 gVirtualX->DrawLine(fId, GetHilightGC()(), lx, lh - 3, lx + 1, lh - 3);
2638 if (fMBState == kButtonEngaged) {
2639 gVirtualX->FillRectangle(fId, GetHibckgndGC()(), fTBWidth + 1, 1, fMBWidth - 3, fHeight - 3);
2642 if (fMBState == kButtonDisabled) {
2643 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
2644 DrawTriangle(GetShadowGC()(), x, y);
2646 DrawTriangle(fNormGC, x, y);
2651 if(fState == kButtonDown || fState == kButtonEngaged) {
2655 if (fState == kButtonDisabled) {
2656 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
2657 DrawTriangle(GetShadowGC()(), x, y);
2659 DrawTriangle(fNormGC, x, y);
2669 void TGSplitButton::BindKeys(Bool_t on)
2671 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up), kAnyModifier, on);
2672 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down), kAnyModifier, on);
2673 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter), kAnyModifier, on);
2674 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return), kAnyModifier, on);
2675 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Escape), kAnyModifier, on);
2681 void TGSplitButton::BindMenuKeys(Bool_t on)
2684 TIter next(fPopMenu->GetListOfEntries());
2686 while ((e = (TGMenuEntry*)next())) {
2688 if (e->GetLabel()) {
2689 hot = e->GetLabel()->GetHotChar();
2692 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), 0, on);
2693 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask, on);
2694 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask, on);
2695 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyMod2Mask, on);
2696 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask, on);
2697 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyMod2Mask, on);
2698 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask | kKeyMod2Mask, on);
2699 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask | kKeyMod2Mask, on);
2706 TGDimension TGSplitButton::GetDefaultSize()
const
2708 UInt_t w = GetOptions() & kFixedWidth ? fWidth + fMBWidth : fTWidth + fMLeft + fMRight + fMBWidth + 8;
2709 UInt_t h = GetOptions() & kFixedHeight ? fHeight : fTHeight + fMTop + fMBottom + 7;
2710 return TGDimension(w, h);
2716 void TGSplitButton::SetText(TGHotString *new_label)
2719 static Bool_t longlabeltip = kFALSE;
2720 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
2722 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
2724 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
2725 if (font) fFontStruct = font->GetFontStruct();
2728 UInt_t width = 0, bwidth = 0, dummy;
2730 font->ComputeTextLayout(new_label->GetString(), new_label->GetLength(),
2731 fWrapLength, kTextLeft, 0,
2733 font->ComputeTextLayout(fWidestLabel.GetString(), fWidestLabel.GetLength(),
2734 fWrapLength, kTextLeft, 0,
2737 if (width > bwidth) {
2739 SetToolTipText(new_label->GetString());
2740 longlabeltip = kTRUE;
2742 Info(
"TGSplitbutton",
"Length of new label to long, label truncated.");
2743 new_label->Resize(fWidestLabel.GetLength());
2744 }
else if (new_label->GetLength() <= fWidestLabel.GetLength() && longlabeltip) {
2745 if (fTip)
delete fTip;
2747 longlabeltip = kFALSE;
2751 if (main && fHKeycode) {
2752 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask);
2753 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2754 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2755 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
2757 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2758 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
2759 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
2760 main->RemoveBind(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
2766 if ((hotchar = fLabel->GetHotChar()) != 0) {
2767 if (main && ((fHKeycode = gVirtualX->KeysymToKeycode(hotchar)) != 0)) {
2768 main->BindKey(
this, fHKeycode, kKeyMod1Mask);
2769 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask);
2770 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyLockMask);
2771 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
2773 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask);
2774 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
2775 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
2776 main->BindKey(
this, fHKeycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
2786 void TGSplitButton::SetText(
const TString &new_label)
2788 SetText(
new TGHotString(new_label));
2795 void TGSplitButton::SetFont(FontStruct_t font, Bool_t global)
2797 if (font != fFontStruct) {
2798 FontH_t v = gVirtualX->GetFontHandle(font);
2802 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
2803 TGGC *gc = pool->FindGC(fNormGC);
2805 if ((gc) && !global) {
2806 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
2807 fHasOwnFont = kTRUE;
2811 fNormGC = gc->GetGC();
2813 fClient->NeedRedraw(
this);
2821 void TGSplitButton::SetFont(
const char *fontName, Bool_t global)
2823 TGFont *font = fClient->GetFont(fontName);
2825 SetFont(font->GetFontStruct(), global);
2832 void TGSplitButton::SetMBState(EButtonState state)
2834 if (state != fMBState) {
2843 void TGSplitButton::SetSplit(Bool_t split)
2847 Disconnect(fPopMenu,
"PoppedDown()");
2848 fPopMenu->Connect(
"PoppedDown()",
"TGSplitButton",
this,
"SetMBState(=kButtonUp)");
2849 fPopMenu->Connect(
"PoppedDown()",
"TGSplitButton",
this,
"MBReleased()");
2851 TGMenuEntry *entry = fPopMenu->GetEntry(fEntryId);
2853 TGHotString *tmp =
new TGHotString(*(entry->GetLabel()));
2856 TString str(
"ItemClicked(=");
2857 str += entry->GetEntryId();
2859 Connect(
"Clicked()",
"TGSplitButton",
this, str);
2860 fEntryId = entry->GetEntryId();
2861 fPopMenu->HideEntry(fEntryId);
2865 Disconnect(fPopMenu,
"PoppedDown()");
2866 Disconnect(
this,
"Clicked()",
this);
2867 fPopMenu->Connect(
"PoppedDown()",
"TGSplitButton",
this,
"SetState(=kButtonUp)");
2868 fPopMenu->Connect(
"PoppedDown()",
"TGSplitButton",
this,
"Released()");
2869 fPopMenu->EnableEntry(fEntryId);
2870 TGHotString *tmp =
new TGHotString(*fMenuLabel);
2881 Bool_t TGSplitButton::HandleButton(Event_t *event)
2883 if (fState == kButtonDisabled)
return kFALSE;
2885 if (fSplit)
return HandleSButton(event);
2887 Bool_t in = (
event->fX >= 0) && (event->fY >= 0) &&
2888 (
event->fX <= (Int_t)fWidth) && (
event->fY <= (Int_t)fHeight);
2890 Bool_t activate = kFALSE;
2891 Bool_t click = kFALSE;
2894 if (event->fType == kButtonPress) {
2896 if (fState == kButtonEngaged) {
2899 SetState(kButtonDown);
2901 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
2902 kPointerMotionMask, kNone, fDefaultCursor);
2904 if (fState == kButtonEngaged) {
2905 SetState(kButtonUp);
2906 SetMenuState(kFALSE);
2909 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
2911 click = (fState == kButtonDown);
2912 if (click && fStayDown) {
2913 SetState(kButtonEngaged);
2914 SetMenuState(kTRUE);
2917 SetState(kButtonUp);
2922 fKeyNavigate = kFALSE;
2925 if (event->fType == kButtonPress) {
2928 SetState(kButtonUp);
2929 SetMenuState(kFALSE);
2930 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
2936 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2937 (Long_t) fUserData);
2938 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
2939 (Long_t) fUserData);
2941 if (activate && !fKeyNavigate) {
2942 TGMenuEntry *entry = fPopMenu->GetCurrent();
2944 if ((entry->GetStatus() & kMenuEnableMask) &&
2945 !(entry->GetStatus() & kMenuHideMask) &&
2946 (entry->GetType() != kMenuSeparator) &&
2947 (entry->GetType() != kMenuLabel)) {
2948 Int_t
id = entry->GetEntryId();
2949 fPopMenu->Activated(
id);
2961 Bool_t TGSplitButton::HandleCrossing(Event_t *event)
2964 return HandleSCrossing(event);
2966 return TGButton::HandleCrossing(event);
2973 Bool_t TGSplitButton::HandleKey(Event_t *event)
2975 Bool_t click = kFALSE;
2977 if (fState == kButtonDisabled)
return kTRUE;
2979 if(fSplit)
return HandleSKey(event);
2981 if (event->fType == kGKeyPress) {
2982 gVirtualX->SetKeyAutoRepeat(kFALSE);
2984 gVirtualX->SetKeyAutoRepeat(kTRUE);
2987 if (fTip && event->fType == kGKeyPress) fTip->Hide();
2991 if (event->fState & kKeyMod1Mask) {
2993 fKeyNavigate = kTRUE;
2994 if (event->fType == kGKeyPress) {
2995 if (fState == kButtonEngaged)
return kTRUE;
2996 SetState(kButtonDown);
2998 }
else if (event->fType == kKeyRelease) {
3000 if (fState == kButtonEngaged) {
3001 SetState(kButtonUp);
3002 SetMenuState(kFALSE);
3003 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3004 }
else if (fState == kButtonDown && fStayDown) {
3005 SetState(kButtonEngaged);
3006 SetMenuState(kTRUE);
3007 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
3008 kPointerMotionMask, kNone, fDefaultCursor);
3009 TGMenuEntry *entry = 0;
3010 TIter next(fPopMenu->GetListOfEntries());
3012 while ((entry = (TGMenuEntry *) next())) {
3013 if ((entry->GetStatus() & kMenuEnableMask) &&
3014 !(entry->GetStatus() & kMenuHideMask) &&
3015 (entry->GetType() != kMenuSeparator) &&
3016 (entry->GetType() != kMenuLabel))
break;
3019 fPopMenu->Activate(entry);
3023 SetState(kButtonUp);
3027 fKeyNavigate = kTRUE;
3028 if (event->fType == kGKeyPress) {
3034 gVirtualX->LookupString(event, tmp,
sizeof(tmp), keysym);
3036 TGMenuEntry *ce = 0;
3037 TIter next(fPopMenu->GetListOfEntries());
3039 while ((ce = (TGMenuEntry*)next())) {
3041 if (ce->GetLabel()) hot = ce->GetLabel()->GetHotChar();
3042 if (!hot || (hot != keysym))
continue;
3044 fPopMenu->Activate(ce);
3045 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3046 SetMenuState(kFALSE);
3047 ev.fType = kButtonRelease;
3048 ev.fWindow = fPopMenu->GetId();
3049 fKeyNavigate = kFALSE;
3050 return HandleButton(&ev);
3053 ce = fPopMenu->GetCurrent();
3055 switch ((EKeySym)keysym) {
3057 if (ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Before(ce);
3058 while (ce && ((ce->GetType() == kMenuSeparator) ||
3059 (ce->GetType() == kMenuLabel) ||
3060 !(ce->GetStatus() & kMenuEnableMask))) {
3061 ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Before(ce);
3063 if (!ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->Last();
3066 if (ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->After(ce);
3067 while (ce && ((ce->GetType() == kMenuSeparator) ||
3068 (ce->GetType() == kMenuLabel) ||
3069 !(ce->GetStatus() & kMenuEnableMask))) {
3070 ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->After(ce);
3072 if (!ce) ce = (TGMenuEntry*)fPopMenu->GetListOfEntries()->First();
3076 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3077 SetMenuState(kFALSE);
3078 ev.fType = kButtonRelease;
3079 ev.fWindow = fPopMenu->GetId();
3080 fKeyNavigate = kFALSE;
3084 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
3085 SetMenuState(kFALSE);
3090 if (ce) fPopMenu->Activate(ce);
3095 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
3096 (Long_t) fUserData);
3097 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_BUTTON), fWidgetId,
3098 (Long_t) fUserData);
3107 Bool_t TGSplitButton::HandleMotion(Event_t *event)
3109 if (fKeyNavigate)
return kTRUE;
3112 if (fMBState == kButtonDown) {
3113 if (event->fX < (Int_t)fTBWidth) {
3114 SetMBState(kButtonUp);
3115 SetState(kButtonDown);
3117 }
else if (fState == kButtonDown) {
3118 if (event->fX > (Int_t)fTBWidth) {
3119 SetState(kButtonUp);
3120 SetMBState(kButtonDown);
3131 void TGSplitButton::Layout()
3133 UInt_t dummya = 0, dummyb = 0;
3136 TGFont *font = fClient->GetFontPool()->FindFont(fFontStruct);
3138 font = fClient->GetFontPool()->GetFont(fgDefaultFont);
3139 if (font) fFontStruct = font->GetFontStruct();
3142 fTLayout = font->ComputeTextLayout(fLabel->GetString(),
3143 fLabel->GetLength(),
3144 fWrapLength, kTextLeft, 0,
3147 font->ComputeTextLayout(fWidestLabel.GetString(), fWidestLabel.GetLength(),
3148 fWrapLength, kTextLeft, 0,
3150 font->ComputeTextLayout(fHeighestLabel.GetString(), fHeighestLabel.GetLength(),
3151 fWrapLength, kTextLeft, 0,
3154 fTBWidth = fTWidth + 8;
3155 fWidth = fTBWidth + fMBWidth;
3156 fHeight = fTHeight + 7;
3157 fClient->NeedRedraw(
this);
3163 void TGSplitButton::HandleMenu(Int_t
id)
3165 SetMenuState(kFALSE);
3168 SetMBState(kButtonUp);
3169 Disconnect(
this,
"Clicked()",
this);
3171 Connect(
"Clicked()",
"TGSplitButton",
this,
3172 TString::Format(
"ItemClicked(=%d)",
id));
3175 const TList *list = fPopMenu->GetListOfEntries();
3177 fPopMenu->EnableEntry(fEntryId);
3178 TGMenuEntry *entry = fPopMenu->GetEntry(
id);
3180 TGHotString *label = entry->GetLabel();
3181 TGHotString *tmp =
new TGHotString(*label);
3184 fPopMenu->HideEntry(
id);
3185 if (entry) fEntryId = entry->GetEntryId();
3187 SetState(kButtonUp);