Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGComboBox.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 13/01/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11/**************************************************************************
12
13 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23
24/** \class TGComboBox
25 \ingroup guiwidgets
26
27A combobox (also known as a drop down listbox) allows the selection
28of one item out of a list of items. The selected item is visible in
29a little window. To view the list of possible items one has to click
30on a button on the right of the little window. This will drop down
31a listbox. After selecting an item from the listbox the box will
32disappear and the newly selected item will be shown in the little
33window.
34
35The TGComboBox is user callable.
36
37\class TGComboBoxPopup
38\ingroup guiwidgets
39
40A service class of the combobox.
41
42Selecting an item in the combobox will generate the event:
43 - kC_COMMAND, kCM_COMBOBOX, combobox id, item id.
44
45*/
46
47
48#include "TGComboBox.h"
49#include "TGScrollBar.h"
50#include "TGResourcePool.h"
51#include "TGTextEntry.h"
52#include "KeySymbols.h"
53#include "TVirtualX.h"
54#include "RConfigure.h"
55
56#include <iostream>
57
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Create a combo box popup frame.
63
65 UInt_t options, Pixel_t back) :
66 TGCompositeFrame (p, w, h, options, back), fListBox(0), fSelected(0)
67{
69
73 wattr.fSaveUnder = kTRUE;
75 wattr.fBorderWidth = 1;
76 gVirtualX->ChangeWindowAttributes(fId, &wattr);
77 gVirtualX->SetWindowHint(fId, TVirtualX::kHintCombo);
78
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Handle mouse button event in combo box popup.
86
88{
89 if (event->fType == kButtonPress && event->fCode == kButton1) {
90 if ((fListBox != 0) && (fSelected != 0) &&
91 fListBox->GetSelectedEntry() != fSelected) {
92 // in the case the combo box popup is closed by clicking outside the
93 // list box, then select the previously selected entry
94 fListBox->Select(fSelected->EntryId());
95 }
96 EndPopup();
97 }
98 else {
99 // reset the dragging flag of the scrollbar when the button is
100 // released outside the scrollbar itself
101 fListBox->GetScrollBar()->SetDragging(kFALSE);
102 }
103 return kTRUE;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Ungrab pointer and unmap popup window.
108
110{
111 if (IsMapped()) {
112 Handle_t id = fListBox->GetContainer()->GetId();
113 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Up),
115 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Down),
117 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Enter),
119 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Return),
121 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Escape),
123 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Space),
125 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
126 UnmapWindow();
127 }
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Popup combo box popup window at the specified place.
132
134{
135 Int_t rx, ry;
136 UInt_t rw, rh;
137
138 // Parent is root window for the popup:
139 gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
140
141 if (gVirtualX->InheritsFrom("TGWin32")) {
142 if ((x > 0) && ((x + abs(rx) + (Int_t)fWidth) > (Int_t)rw))
143 x = rw - abs(rx) - fWidth;
144 if ((y > 0) && (y + abs(ry) + (Int_t)fHeight > (Int_t)rh))
145 y = rh - fHeight;
146 } else {
147 if (x < 0) x = 0;
148 if (x + fWidth > rw) x = rw - fWidth;
149 if (y < 0) y = 0;
150 if (y + fHeight > rh) y = rh - fHeight;
151 }
152
153 // remember the current selected entry
154 if (fListBox == 0) {
155 // the listbox should be the first in the list
156 TGFrameElement *el = (TGFrameElement *)fList->First();
157 fListBox = dynamic_cast<TGListBox *>(el->fFrame);
158 }
159 fSelected = fListBox ? fListBox->GetSelectedEntry() : 0;
160
161 MoveResize(x, y, w, h);
163 Layout();
164 MapRaised();
165
166 Handle_t id = fListBox->GetContainer()->GetId();
167 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Up),
169 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Down),
171 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Enter),
173 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Return),
175 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Escape),
177 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Space),
179 fListBox->GetContainer()->RequestFocus();
180
183 fClient->GetResourcePool()->GetGrabCursor());
184
185 if (fClient->IsEditable()) {
186 fClient->RegisterPopup(this);
187 }
188
189 fClient->WaitForUnmap(this);
190 EndPopup();
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Slot handling the key press events.
195
197{
198 switch ((EKeySym)keysym) {
199 case kKey_Enter:
200 case kKey_Return:
201 case kKey_Space:
202 if (fListBox && f) {
203 TGLBEntry *entry = dynamic_cast<TGLBEntry *>(f);
204 if (entry) {
205 fListBox->Select(entry->EntryId());
207 entry->EntryId(), 0);
208 }
209 }
210 EndPopup();
211 break;
212 case kKey_Escape:
213 if (fListBox)
214 ((TGContainer *)fListBox->GetContainer())->UnSelectAll();
215 EndPopup();
216 break;
217 default:
218 break;
219 }
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Create a combo box widget.
224
226 Pixel_t back) :
227 TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
228{
229 fWidgetId = id;
230 fMsgWindow = p;
231 fTextEntry = 0;
232
233 fSelEntry = new TGTextLBEntry(this, new TGString(""), 0);
234 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
235
238 Init();
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Create an editable combo box widget.
243
244TGComboBox::TGComboBox(const TGWindow *p, const char *text, Int_t id,
245 UInt_t options, Pixel_t back) :
246 TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
247{
248 fWidgetId = id;
249 fMsgWindow = p;
250 fSelEntry = nullptr;
251
252 fTextEntry = new TGTextEntry(this, text, id);
253 fTextEntry->SetFrameDrawn(kFALSE);
254 fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
255
258 Init();
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Delete a combo box widget.
263
265{
266 fClient->FreePicture(fBpic);
267
268 if (!MustCleanup()) {
274 }
275
278 if (fComboFrame) {
279 fComboFrame->EndPopup(); // force popdown in case of Qt interface
281 }
282}
283
284////////////////////////////////////////////////////////////////////////////////
285/// Initiate the internal classes of a combo box.
286
288{
289 fBpic = fClient->GetPicture("arrow_down.xpm");
290
291 if (!fBpic)
292 Error("TGComboBox", "arrow_down.xpm not found");
293
296
299
300 fComboFrame = new TGComboBoxPopup(fClient->GetDefaultRoot(), 100, 100, kVerticalFrame);
301
303
304 fListBox->Resize(100, 100);
305 fListBox->Associate(this);
306 fListBox->GetScrollBar()->GrabPointer(kFALSE); // combobox will do a pointergrab
307
310 fComboFrame->SetListBox(fListBox);
311 fComboFrame->MapSubwindows();
312 fComboFrame->Resize(fComboFrame->GetDefaultSize());
313
316
317 fListBox->GetContainer()->Connect("KeyPressed(TGFrame*, UInt_t, UInt_t)",
318 "TGComboBoxPopup", fComboFrame,
319 "KeyPressed(TGFrame*, UInt_t, UInt_t)");
320 // Drop down listbox of combo box should react to pointer motion
321 // so it will be able to Activate() (i.e. highlight) the different
322 // items when the mouse crosses.
323 fListBox->GetContainer()->AddInput(kButtonPressMask | kButtonReleaseMask |
325
326 fListBox->SetEditDisabled(kEditDisable);
327 fListBox->GetContainer()->SetEditDisabled(kEditDisable);
330 fDDButton->SetEditDisabled(kEditDisable | kEditDisableGrab);
332
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Draw border of combo box widget.
338
340{
343 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
344 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
345 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
346 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
347 if (gClient->GetStyle() > 1) break;
348 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
349 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
350 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
351 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
352 break;
353
354 default:
356 break;
357 }
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Switch text input or readonly mode of combobox (not perfect yet).
362
364{
365 // UInt_t w, h;
366 TString text = "";
367 Pixel_t back = TGFrame::GetWhitePixel(); // default
368
369 if (on) {
370 if (fSelEntry) {
371 back = fSelEntry->GetBackground();
372 text = ((TGTextLBEntry*)fSelEntry)->GetText()->GetString();
373 if (fTextEntry && fSelEntry->InheritsFrom(TGTextLBEntry::Class())) {
374 fTextEntry->SetText(text.Data());
375 }
377 //w = fSelEntry->GetWidth();
378 //h = fSelEntry->GetHeight();
379 fSelEntry->DestroyWindow();
380 delete fSelEntry;
381 fSelEntry = 0;
382 }
383 if (!fTextEntry) {
384 fTextEntry = new TGTextEntry(this, text.Data(), 0);
385 fTextEntry->SetFrameDrawn(kFALSE);
386 fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
389 }
390 fTextEntry->SetBackgroundColor(back);
392 // coverity[returned_null]
393 // coverity[dereference]
395 } else {
396 if (fTextEntry) {
397 back = fTextEntry->GetBackground();
398 text = fTextEntry->GetText();
400 fTextEntry->DestroyWindow();
401 //w = fTextEntry->GetWidth();
402 //h = fTextEntry->GetHeight();
403 delete fTextEntry;
404 fTextEntry = 0;
405 }
406 if (!fSelEntry) {
407 fSelEntry = new TGTextLBEntry(this, new TGString(text.Data()), 0);
408 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
410 fSelEntry->SetEditDisabled(kEditDisable | kEditDisableGrab);
411 }
412 fSelEntry->SetBackgroundColor(back);
414 // coverity[returned_null]
415 // coverity[dereference]
417 }
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Find entry by name.
422
423TGLBEntry *TGComboBox::FindEntry(const char *s) const
424{
425 TGLBEntry *sel = 0;
426 sel = fListBox->FindEntry(s);
427 return sel;
428}
429
430////////////////////////////////////////////////////////////////////////////////
431/// Set a new combo box value (normally update of text string in
432/// fSelEntry is done via fSelEntry::Update()).
433
435{
436 if (!fSelEntry) return;
437
439 fSelEntry->DestroyWindow();
440 delete fSelEntry;
441 delete fLhs;
442 fSelEntry = e;
443 fLhs = lh;
445 Layout();
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Make the selected item visible in the combo box window
450/// and emit signals according to the second parameter.
451
453{
454 if (id!=GetSelected()) {
455 TGLBEntry *e;
456 e = fListBox->Select(id);
457 if (e) {
458 if (fSelEntry) {
459 fSelEntry->Update(e);
460 Layout();
461 } else if (fTextEntry && e->InheritsFrom(TGTextLBEntry::Class())) {
463 fTextEntry->SetText(te->GetText()->GetString());
464 }
465 if (emit) {
466 Selected(fWidgetId, id);
467 Selected(id);
468 Changed();
469 }
470 }
471 }
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Handle mouse button events in the combo box.
476
478{
479 if (!fDDButton || !fDDButton->IsEnabled()) return kFALSE;
480
481 if (event->fType == kButtonPress) {
482 Window_t child = (Window_t)event->fUser[0]; // fUser[0] = child window
483
484 if (child == fDDButton->GetId() || (fSelEntry && child == fSelEntry->GetId())) {
485 fDDButton->SetState(kButtonDown);
486
487 if (fTextEntry && (child == fTextEntry->GetId())) {
488 return fTextEntry->HandleButton(event);
489 }
490 int ax, ay;
491 Window_t wdummy;
492 gVirtualX->TranslateCoordinates(fId, fComboFrame->GetParent()->GetId(),
493 0, fHeight, ax, ay, wdummy);
494 // Drop down listbox of combo box should react to pointer motion...
495 fListBox->GetContainer()->AddInput(kPointerMotionMask);
496#ifdef R__HAS_COCOA
497 gVirtualX->SetWMTransientHint(fComboFrame->GetId(), GetId());
498#endif
499 fComboFrame->PlacePopup(ax, ay, fWidth-2, fComboFrame->GetDefaultHeight());
500 fDDButton->SetState(kButtonUp);
501#ifdef R__HAS_COCOA
502 //tp: I need this modification - "button" is not repainted correctly
503 //with Cocoa, when combobox is closed (reason is quite complex), happens
504 //when item is wider than combobox.
505 //TODO: find another way :)
506 fClient->NeedRedraw(fDDButton);
507#endif
508 } else if (fTextEntry) {
509 return fTextEntry->HandleButton(event);
510 }
511 }
512 return kTRUE;
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// Remove entry. If id == -1, the currently selected entry is removed
517
519{
520 fListBox->RemoveEntry(id);
521
522 if (id < 0) {
523 if (fSelEntry) {
524 ((TGTextLBEntry*)fSelEntry)->SetTitle("");
525 fClient->NeedRedraw(fSelEntry);
526 } else {
527 fTextEntry->SetTitle("");
528 fClient->NeedRedraw(fTextEntry);
529 }
530 }
531 Resize();
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// layout combobox
536
538{
540 UInt_t h = fListBox->GetNumberOfEntries()*fListBox->GetItemVsize();
541
542 if (h && (h < 100)) {
543 fListBox->Resize(fListBox->GetWidth(), h);
544 }
545}
546
547////////////////////////////////////////////////////////////////////////////////
548/// Handle double click in text entry.
549
551{
552 return fTextEntry ? fTextEntry->HandleDoubleClick(event) : kTRUE;
553}
554
555////////////////////////////////////////////////////////////////////////////////
556/// Handle pointer motion in text entry.
557
559{
560 return fTextEntry ? fTextEntry->HandleMotion(event) : kTRUE;
561}
562
563////////////////////////////////////////////////////////////////////////////////
564/// Handle selection in text entry.
565
567{
568 return fTextEntry ? fTextEntry->HandleSelection(event) : kTRUE;
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Handle selection request in text entry.
573
575{
576 return fTextEntry ? fTextEntry->HandleSelectionRequest(event) : kTRUE;
577}
578
579////////////////////////////////////////////////////////////////////////////////
580/// Process messages generated by the listbox and forward
581/// messages to the combobox message handling window. Parm2 contains
582/// the id of the selected listbox entry.
583
585{
586 TGLBEntry *e;
587
588 switch (GET_MSG(msg)) {
589 case kC_COMMAND:
590 switch (GET_SUBMSG(msg)) {
591 case kCM_LISTBOX:
592 e = fListBox->GetSelectedEntry();
593 if (fSelEntry) {
594 fSelEntry->Update(e);
595 } else if (fTextEntry &&
596 e->InheritsFrom(TGTextLBEntry::Class())) {
598 fTextEntry->SetText(te->GetText()->GetString());
599 }
600 // coverity[returned_null]
601 // coverity[dereference]
603 fComboFrame->EndPopup();
604 fDDButton->SetState(kButtonUp);
606 fWidgetId, parm2);
607 if (e->InheritsFrom(TGTextLBEntry::Class())) {
608 const char *text;
609 text = ((TGTextLBEntry*)e)->GetText()->GetString();
610 Selected(text);
611 }
612 Selected(fWidgetId, (Int_t)parm2);
613 Selected((Int_t)parm2);
614 Changed();
615 fClient->NeedRedraw(this);
616 break;
617 }
618 break;
619
620 default:
621 break;
622 }
623 return kTRUE;
624}
625
626////////////////////////////////////////////////////////////////////////////////
627/// Emit signal, done only when selected entry changed.
628
630{
631 Longptr_t args[2];
632
633 args[0] = widgetId;
634 args[1] = id;
635
636 Emit("Selected(Int_t,Int_t)", args);
637}
638
639////////////////////////////////////////////////////////////////////////////////
640/// Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
641
643{
644 fDDButton->SetEnabled(on);
645 if (on) {
647 if (fSelEntry) fSelEntry->SetBackgroundColor(GetBackground());
648 } else {
650 if (fSelEntry) fSelEntry->SetBackgroundColor(GetDefaultFrameBackground());
651 }
652 fClient->NeedRedraw(fSelEntry);
653}
654
655////////////////////////////////////////////////////////////////////////////////
656/// Add new entry to combo box when return key pressed inside text entry
657/// ReturnPressed signal is emitted.
658
660{
661 if (!fTextEntry) return;
662
663 TGLBContainer *lbc = (TGLBContainer *)fListBox->GetContainer();
664 TString text = fTextEntry->GetText();
665
666 TIter next(lbc->GetList());
667 TGFrameElement *el;
668
669 Emit("ReturnPressed()");
670
671 while ((el = (TGFrameElement *)next())) {
672 TGTextLBEntry *lbe = (TGTextLBEntry *)el->fFrame;
673 if (lbe->GetText()->GetString() == text) {
674 return;
675 }
676 }
677
678 Int_t nn = GetNumberOfEntries() + 1;
679 AddEntry(text.Data(), nn);
680 Select(nn);
681}
682
683////////////////////////////////////////////////////////////////////////////////
684/// Remove all entries from combo box.
685
687{
688 fListBox->RemoveAll();
689
690 if (fSelEntry) {
691 ((TGTextLBEntry*)fSelEntry)->SetTitle("");
692 fClient->NeedRedraw(fSelEntry);
693 } else {
694 fTextEntry->SetTitle("");
695 fClient->NeedRedraw(fTextEntry);
696 }
697}
698
699////////////////////////////////////////////////////////////////////////////////
700/// Save a combo box widget as a C++ statement(s) on output stream out.
701
702void TGComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
703{
704 // save options and custom color if not default
705 auto extra_args = SaveCtorArgs(out, kHorizontalFrame | kSunkenFrame | kDoubleBorder);
706
707 out << "\n // combo box\n";
708
709 out << " TGComboBox *" << GetName() << " = new TGComboBox(" << fParent->GetName();
710 if (fTextEntry)
711 out << ", \"" << TString(fTextEntry->GetText()).ReplaceSpecialCppChars() << "\"";
712 out << ", " << fWidgetId << extra_args << ");\n";
713
714 if (option && strstr(option, "keep_names"))
715 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
716
717 TGListBox *lb = GetListBox();
718
719 TIter next(((TGLBContainer *)lb->GetContainer())->GetList());
720
721 while (auto el = (TGFrameElement *)next()) {
722 auto b = (TGTextLBEntry *)el->fFrame;
723 out << " " << GetName() << "->AddEntry(";
724 b->SavePrimitive(out, option);
725 out << ");" << std::endl;
726 }
727
728 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
729 out << " " << GetName() << "->Select(" << GetSelected() << ");\n";
730}
731
732////////////////////////////////////////////////////////////////////////////////
733/// Create a line style combo box.
734
736 UInt_t options, Pixel_t back)
737 : TGComboBox(p, id, options, back)
738{
739 SetTopEntry(new TGLineLBEntry(this, 0),
741 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
742
743 for (Int_t i = 1; i <= 10; i++)
744 AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
745 TString::Format("%d",i), 0, i),
747
748 Select(1, kFALSE); // to have first entry selected
749
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Save a line style combo box widget as a C++ statement(s).
755
756void TGLineStyleComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
757{
758 out << "\n // line style combo box\n";
759 out << " TGLineStyleComboBox *" << GetName() << " = new TGLineStyleComboBox(" << fParent->GetName() << ","
760 << fWidgetId << ");\n";
761 if (option && strstr(option, "keep_names"))
762 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
763 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
764 out << " " << GetName() << "->Select(" << GetSelected() << ");\n";
765}
766
767////////////////////////////////////////////////////////////////////////////////
768/// Create a line width combo box.
769/// If "none" is equal to kTRUE the first entry is "None".
770
772 UInt_t options, Pixel_t back, Bool_t none)
773 : TGComboBox(p, id, options, back)
774{
775 SetTopEntry(new TGLineLBEntry(this,0),
777 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
778
779 if (none) {
780 AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), 0, "None", 0, 0),
782 }
783
784 for (Int_t i = 0; i < 16; i++)
785 AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
786 TString::Format("%d",i), i, 0),
788 Select(1, kFALSE); // to have first entry selected
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Save a line width combo box widget as a C++ statement(s).
794
795void TGLineWidthComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
796{
797 out << "\n // line width combo box\n";
798 out << " TGLineWidthComboBox *" << GetName() << " = new TGLineWidthComboBox(" << fParent->GetName() << ","
799 << fWidgetId << ");\n";
800 if (option && strstr(option, "keep_names"))
801 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
802 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
803 out << " " << GetName() << "->Select(" << GetSelected() << ");\n";
804}
805
806static const char *gFonts[][2] = { // unix name, name
807 { "", "" }, //not used
808 { "-*-times-medium-i-*-*-12-*-*-*-*-*-*-*", "1. times italic" },
809 { "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*", "2. times bold" },
810 { "-*-times-bold-i-*-*-12-*-*-*-*-*-*-*", "3. times bold italic" },
811 { "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*", "4. helvetica" },
812 { "-*-helvetica-medium-o-*-*-12-*-*-*-*-*-*-*", "5. helvetica italic" },
813 { "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*", "6. helvetica bold" },
814 { "-*-helvetica-bold-o-*-*-12-*-*-*-*-*-*-*", "7. helvetica bold italic" },
815 { "-*-courier-medium-r-*-*-12-*-*-*-*-*-*-*", "8. courier" },
816 { "-*-courier-medium-o-*-*-12-*-*-*-*-*-*-*", "9. courier italic" },
817 { "-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*", "10. courier bold" },
818 { "-*-courier-bold-o-*-*-12-*-*-*-*-*-*-*", "11. courier bold italic" },
819 { "-*-symbol-medium-r-*-*-12-*-*-*-*-*-*-*", "12. symbol" },
820 { "-*-times-medium-r-*-*-12-*-*-*-*-*-*-*", "13. times" },
821 { nullptr, nullptr }
822};
823
824////////////////////////////////////////////////////////////////////////////////
825/// Create a text font combo box.
826
828 UInt_t options, Pixel_t back) :
829 TGComboBox(p, id, options, back)
830{
831 Int_t noFonts = 0;
832
833 for (Int_t i = 1; gFonts[i][0] != 0 && noFonts < kMaxFonts; i++) {
834
835 fFonts[noFonts] = gVirtualX->LoadQueryFont(gFonts[i][0]);
836
837 if (fFonts[noFonts] == 0)
839
841 gval.fMask = kGCFont;
842 gval.fFont = gVirtualX->GetFontHandle(fFonts[noFonts]);
843
844 AddEntry(new TGTextLBEntry(GetListBox()->GetContainer(),
845 new TGString(gFonts[i][1]), i,
846 fClient->GetGC(&gval, kTRUE)->GetGC(), fFonts[noFonts]),
848 noFonts++;
849 }
850
851 if (noFonts < kMaxFonts - 1)
852 fFonts[noFonts] = 0;
853
854 Select(1, kFALSE); // to have first entry selected
856}
857
858////////////////////////////////////////////////////////////////////////////////
859/// Text font combo box dtor.
860
862{
863 for (int i = 0; i < kMaxFonts && fFonts[i] != 0; i++) {
864 if (fFonts[i] != TGTextLBEntry::GetDefaultFontStruct()) gVirtualX->DeleteFont(fFonts[i]);
865 }
866}
@ kButtonPress
Definition GuiTypes.h:61
const Mask_t kWABorderPixel
Definition GuiTypes.h:143
const Mask_t kWAOverrideRedirect
Definition GuiTypes.h:150
const Mask_t kButtonPressMask
Definition GuiTypes.h:162
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
const Mask_t kWASaveUnder
Definition GuiTypes.h:151
const Mask_t kAnyModifier
Definition GuiTypes.h:211
const Mask_t kGCFont
Definition GuiTypes.h:301
const Mask_t kPointerMotionMask
Definition GuiTypes.h:164
@ kChildFrame
Definition GuiTypes.h:380
@ kRaisedFrame
Definition GuiTypes.h:385
@ kSunkenFrame
Definition GuiTypes.h:384
@ kVerticalFrame
Definition GuiTypes.h:382
@ kDoubleBorder
Definition GuiTypes.h:386
@ kHorizontalFrame
Definition GuiTypes.h:383
@ kOwnBackground
Definition GuiTypes.h:392
const Handle_t kNone
Definition GuiTypes.h:89
const Mask_t kStructureNotifyMask
Definition GuiTypes.h:167
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:163
@ kDefaultScrollBarWidth
Definition GuiTypes.h:87
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
@ kButton1
Definition GuiTypes.h:215
const Mask_t kWABorderWidth
Definition GuiTypes.h:144
ULongptr_t Handle_t
Generic resource handle.
Definition GuiTypes.h:26
EKeySym
Definition KeySymbols.h:25
@ kKey_Down
Definition KeySymbols.h:43
@ kKey_Space
Definition KeySymbols.h:93
@ kKey_Up
Definition KeySymbols.h:41
@ kKey_Return
Definition KeySymbols.h:30
@ kKey_Escape
Definition KeySymbols.h:26
@ kKey_Enter
Definition KeySymbols.h:31
#define SafeDelete(p)
Definition RConfig.hxx:525
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
static const char * gFonts[][2]
const Int_t kMaxFonts
Definition TGComboBox.h:176
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kWidgetIsEnabled
Definition TGWidget.h:37
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void w
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t gval
Option_t Option_t TPoint TPoint const char text
#define gVirtualX
Definition TVirtualX.h:377
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
Int_t GET_MSG(Long_t val)
@ kCM_COMBOBOX
@ kCT_ITEMCLICK
@ kC_COMMAND
@ kCM_LISTBOX
@ kC_CONTAINER
Int_t GET_SUBMSG(Long_t val)
A service class of the combobox.
Definition TGComboBox.h:21
void KeyPressed(TGFrame *, UInt_t, UInt_t)
Slot handling the key press events.
TGLBEntry * fSelected
Definition TGComboBox.h:25
void EndPopup()
Ungrab pointer and unmap popup window.
TGComboBoxPopup(const TGComboBoxPopup &)=delete
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
Popup combo box popup window at the specified place.
Bool_t HandleButton(Event_t *) override
Handle mouse button event in combo box popup.
TGListBox * fListBox
Definition TGComboBox.h:24
virtual Int_t GetSelected() const
Definition TGComboBox.h:114
void Layout() override
layout combobox
Bool_t HandleSelection(Event_t *event) override
Handle selection in text entry.
TGLBEntry * fSelEntry
selected item frame
Definition TGComboBox.h:54
TGComboBox(const TGComboBox &)=delete
void RemoveAll() override
Remove all entries from combo box.
virtual void AddEntry(TGString *s, Int_t id)
Definition TGComboBox.h:86
void DrawBorder() override
Draw border of combo box widget.
virtual void Changed()
Definition TGComboBox.h:126
TGListBox * fListBox
the listbox with text items
Definition TGComboBox.h:58
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a combo box widget as a C++ statement(s) on output stream out.
Bool_t HandleDoubleClick(Event_t *event) override
Handle double click in text entry.
~TGComboBox() override
Delete a combo box widget.
virtual void SetTopEntry(TGLBEntry *e, TGLayoutHints *lh)
Set a new combo box value (normally update of text string in fSelEntry is done via fSelEntry::Update(...
virtual void RemoveEntry(Int_t id=-1)
Remove entry. If id == -1, the currently selected entry is removed.
virtual TGListBox * GetListBox() const
Definition TGComboBox.h:110
TGTextEntry * fTextEntry
text entry
Definition TGComboBox.h:55
TGScrollBarElement * fDDButton
button controlling drop down of popup
Definition TGComboBox.h:56
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
TGLayoutHints * fLhs
layout hints for selected item frame
Definition TGComboBox.h:60
TGLayoutHints * fLhdd
layout hints for fListBox
Definition TGComboBox.h:62
Bool_t HandleSelectionRequest(Event_t *event) override
Handle selection request in text entry.
virtual void ReturnPressed()
Add new entry to combo box when return key pressed inside text entry ReturnPressed signal is emitted.
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process messages generated by the listbox and forward messages to the combobox message handling windo...
Bool_t HandleButton(Event_t *event) override
Handle mouse button events in the combo box.
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
virtual void Selected(Int_t widgetId, Int_t id)
Emit signal, done only when selected entry changed.
virtual TGLBEntry * FindEntry(const char *s) const
Find entry by name.
Bool_t HandleMotion(Event_t *event) override
Handle pointer motion in text entry.
virtual void EnableTextInput(Bool_t on)
Switch text input or readonly mode of combobox (not perfect yet).
virtual Int_t GetNumberOfEntries() const
Definition TGComboBox.h:107
virtual void Init()
Initiate the internal classes of a combo box.
TGComboBoxPopup * fComboFrame
popup containing a listbox
Definition TGComboBox.h:57
const TGPicture * fBpic
down arrow picture used in fDDButton
Definition TGComboBox.h:59
TGLayoutHints * fLhb
layout hints for fDDButton
Definition TGComboBox.h:61
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1110
virtual TList * GetList() const
Definition TGFrame.h:312
virtual TGLayoutManager * GetLayoutManager() const
Definition TGFrame.h:340
Int_t MustCleanup() const override
Definition TGFrame.h:362
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1157
TGCompositeFrame(const TGCompositeFrame &)=delete
void Layout() override
Layout the elements of the composite frame.
Definition TGFrame.cxx:1250
TList * fList
container of frame elements
Definition TGFrame.h:294
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1142
Manages a content area.
Definition TGCanvas.h:31
TGFontTypeComboBox(const TGWindow *p=nullptr, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t bask=GetWhitePixel())
Create a text font combo box.
~TGFontTypeComboBox() override
Text font combo box dtor.
FontStruct_t fFonts[kMaxFonts]
Definition TGComboBox.h:181
TGFrame * fFrame
Definition TGLayout.h:112
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:332
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:622
static const TGGC & GetBlackGC()
Get black graphics context.
Definition TGFrame.cxx:728
UInt_t fOptions
frame options
Definition TGFrame.h:94
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:598
TGFrame(const TGFrame &)=delete
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:702
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:414
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:748
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:676
void UnmapWindow() override
unmap window
Definition TGFrame.h:208
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:638
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:758
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
TString SaveCtorArgs(std::ostream &out, UInt_t dflt_options=kChildFrame, Bool_t check_white_pixel=kFALSE)
Return options and custom color as constructor args Used in the SavePrimitive methods,...
Definition TGFrame.cxx:2496
virtual Pixel_t GetBackground() const
Definition TGFrame.h:194
UInt_t GetWidth() const
Definition TGFrame.h:226
static Pixel_t fgBlackPixel
Definition TGFrame.h:104
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:768
void MapRaised() override
map raised
Definition TGFrame.h:207
A Composite frame that contains a list of TGLBEnties.
Definition TGListBox.h:163
Basic listbox entries.
Definition TGListBox.h:24
Int_t EntryId() const
Definition TGListBox.h:40
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
virtual void Layout()=0
Line style and width listbox entries.
Definition TGListBox.h:97
TGLineStyleComboBox(const TGWindow *p=nullptr, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel())
Create a line style combo box.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a line style combo box widget as a C++ statement(s).
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a line width combo box widget as a C++ statement(s).
TGLineWidthComboBox(const TGWindow *p=nullptr, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel(), Bool_t none=kFALSE)
Create a line width combo box.
A listbox is a box, possibly with scrollbar, containing entries.
Definition TGListBox.h:221
virtual TGFrame * GetContainer() const
Definition TGListBox.h:267
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
const char * GetString() const
Definition TGString.h:30
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
Text string listbox entries.
Definition TGListBox.h:48
const TGString * GetText() const
Definition TGListBox.h:79
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use for a text listbox entry.
static TClass * Class()
Int_t fWidgetId
the widget id (used for event processing)
Definition TGWidget.h:46
Int_t ClearFlags(Int_t flags)
Definition TGWidget.h:59
Int_t SetFlags(Int_t flags)
Definition TGWidget.h:58
const TGWindow * fMsgWindow
window which handles widget events
Definition TGWidget.h:48
ROOT GUI Window base class.
Definition TGWindow.h:23
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
@ kEditDisableHeight
window height cannot be edited
Definition TGWindow.h:62
@ kEditDisableLayout
window layout cannot be edited
Definition TGWindow.h:60
@ kEditDisableBtnEnable
window can handle mouse button events
Definition TGWindow.h:64
@ kEditDisableGrab
window grab cannot be edited
Definition TGWindow.h:59
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
@ kEditDisableEvents
window events cannot be edited
Definition TGWindow.h:58
TGWindow(Window_t id)
Definition TGWindow.h:34
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:127
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition TGWindow.cxx:293
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Basic string class.
Definition TString.h:138
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
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:2459
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Event structure.
Definition GuiTypes.h:175
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
UInt_t fCode
key or button code
Definition GuiTypes.h:181
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Definition GuiTypes.h:188
Graphics context structure.
Definition GuiTypes.h:225
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:94
UInt_t fBorderWidth
border width in pixels
Definition GuiTypes.h:99
Bool_t fOverrideRedirect
boolean value for override-redirect
Definition GuiTypes.h:108
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:111
ULong_t fBorderPixel
border pixel value
Definition GuiTypes.h:98
Bool_t fSaveUnder
should bits under be saved (popups)?
Definition GuiTypes.h:105