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
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Handle mouse button event in combo box popup.
85
87{
88 if (event->fType == kButtonPress && event->fCode == kButton1) {
89 if ((fListBox != 0) && (fSelected != 0) &&
90 fListBox->GetSelectedEntry() != fSelected) {
91 // in the case the combo box popup is closed by clicking outside the
92 // list box, then select the previously selected entry
93 fListBox->Select(fSelected->EntryId());
94 }
95 EndPopup();
96 }
97 else {
98 // reset the dragging flag of the scrollbar when the button is
99 // released outside the scrollbar itself
100 fListBox->GetScrollBar()->SetDragging(kFALSE);
101 }
102 return kTRUE;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Ungrab pointer and unmap popup window.
107
109{
110 if (IsMapped()) {
111 Handle_t id = fListBox->GetContainer()->GetId();
112 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Up),
114 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Down),
116 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Enter),
118 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Return),
120 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Escape),
122 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Space),
124 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
125 UnmapWindow();
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Popup combo box popup window at the specified place.
131
133{
134 Int_t rx, ry;
135 UInt_t rw, rh;
136
137 // Parent is root window for the popup:
138 gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
139
140 if (gVirtualX->InheritsFrom("TGWin32")) {
141 if ((x > 0) && ((x + abs(rx) + (Int_t)fWidth) > (Int_t)rw))
142 x = rw - abs(rx) - fWidth;
143 if ((y > 0) && (y + abs(ry) + (Int_t)fHeight > (Int_t)rh))
144 y = rh - fHeight;
145 } else {
146 if (x < 0) x = 0;
147 if (x + fWidth > rw) x = rw - fWidth;
148 if (y < 0) y = 0;
149 if (y + fHeight > rh) y = rh - fHeight;
150 }
151
152 // remember the current selected entry
153 if (fListBox == 0) {
154 // the listbox should be the first in the list
155 TGFrameElement *el = (TGFrameElement *)fList->First();
156 fListBox = dynamic_cast<TGListBox *>(el->fFrame);
157 }
158 fSelected = fListBox ? fListBox->GetSelectedEntry() : 0;
159
160 MoveResize(x, y, w, h);
162 Layout();
163 MapRaised();
164
165 Handle_t id = fListBox->GetContainer()->GetId();
166 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Up),
168 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Down),
170 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Enter),
172 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Return),
174 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Escape),
176 gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Space),
178 fListBox->GetContainer()->RequestFocus();
179
182 fClient->GetResourcePool()->GetGrabCursor());
183
184 if (fClient->IsEditable()) {
185 fClient->RegisterPopup(this);
186 }
187
188 fClient->WaitForUnmap(this);
189 EndPopup();
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Slot handling the key press events.
194
196{
197 switch ((EKeySym)keysym) {
198 case kKey_Enter:
199 case kKey_Return:
200 case kKey_Space:
201 if (fListBox && f) {
202 TGLBEntry *entry = dynamic_cast<TGLBEntry *>(f);
203 if (entry) {
204 fListBox->Select(entry->EntryId());
206 entry->EntryId(), 0);
207 }
208 }
209 EndPopup();
210 break;
211 case kKey_Escape:
212 if (fListBox)
213 ((TGContainer *)fListBox->GetContainer())->UnSelectAll();
214 EndPopup();
215 break;
216 default:
217 break;
218 }
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Create a combo box widget.
223
225 Pixel_t back) :
226 TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
227{
228 fWidgetId = id;
229 fMsgWindow = p;
230 fTextEntry = 0;
231
232 fSelEntry = new TGTextLBEntry(this, new TGString(""), 0);
233 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
234
237 Init();
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Create an editable combo box widget.
242
243TGComboBox::TGComboBox(const TGWindow *p, const char *text, Int_t id,
244 UInt_t options, Pixel_t back) :
245 TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
246{
247 fWidgetId = id;
248 fMsgWindow = p;
249 fSelEntry = nullptr;
250
251 fTextEntry = new TGTextEntry(this, text, id);
252 fTextEntry->SetFrameDrawn(kFALSE);
253 fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
254
257 Init();
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Delete a combo box widget.
262
264{
265 fClient->FreePicture(fBpic);
266
267 if (!MustCleanup()) {
273 }
274
277 if (fComboFrame) {
278 fComboFrame->EndPopup(); // force popdown in case of Qt interface
280 }
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Initiate the internal classes of a combo box.
285
287{
288 fBpic = fClient->GetPicture("arrow_down.xpm");
289
290 if (!fBpic)
291 Error("TGComboBox", "arrow_down.xpm not found");
292
295
298
299 fComboFrame = new TGComboBoxPopup(fClient->GetDefaultRoot(), 100, 100, kVerticalFrame);
300
302
303 fListBox->Resize(100, 100);
304 fListBox->Associate(this);
305 fListBox->GetScrollBar()->GrabPointer(kFALSE); // combobox will do a pointergrab
306
309 fComboFrame->SetListBox(fListBox);
310 fComboFrame->MapSubwindows();
311 fComboFrame->Resize(fComboFrame->GetDefaultSize());
312
315
316 fListBox->GetContainer()->Connect("KeyPressed(TGFrame*, UInt_t, UInt_t)",
317 "TGComboBoxPopup", fComboFrame,
318 "KeyPressed(TGFrame*, UInt_t, UInt_t)");
319 // Drop down listbox of combo box should react to pointer motion
320 // so it will be able to Activate() (i.e. highlight) the different
321 // items when the mouse crosses.
322 fListBox->GetContainer()->AddInput(kButtonPressMask | kButtonReleaseMask |
324
325 fListBox->SetEditDisabled(kEditDisable);
326 fListBox->GetContainer()->SetEditDisabled(kEditDisable);
329 fDDButton->SetEditDisabled(kEditDisable | kEditDisableGrab);
331
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Draw border of combo box widget.
337
339{
342 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
343 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
344 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
345 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
346 if (gClient->GetStyle() > 1) break;
347 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
348 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
349 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
350 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
351 break;
352
353 default:
355 break;
356 }
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// Switch text input or readonly mode of combobox (not perfect yet).
361
363{
364 // UInt_t w, h;
365 TString text = "";
366 Pixel_t back = TGFrame::GetWhitePixel(); // default
367
368 if (on) {
369 if (fSelEntry) {
370 back = fSelEntry->GetBackground();
371 text = ((TGTextLBEntry*)fSelEntry)->GetText()->GetString();
372 if (fTextEntry && fSelEntry->InheritsFrom(TGTextLBEntry::Class())) {
373 fTextEntry->SetText(text.Data());
374 }
376 //w = fSelEntry->GetWidth();
377 //h = fSelEntry->GetHeight();
378 fSelEntry->DestroyWindow();
379 delete fSelEntry;
380 fSelEntry = 0;
381 }
382 if (!fTextEntry) {
383 fTextEntry = new TGTextEntry(this, text.Data(), 0);
384 fTextEntry->SetFrameDrawn(kFALSE);
385 fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
388 }
389 fTextEntry->SetBackgroundColor(back);
391 // coverity[returned_null]
392 // coverity[dereference]
394 } else {
395 if (fTextEntry) {
396 back = fTextEntry->GetBackground();
397 text = fTextEntry->GetText();
399 fTextEntry->DestroyWindow();
400 //w = fTextEntry->GetWidth();
401 //h = fTextEntry->GetHeight();
402 delete fTextEntry;
403 fTextEntry = 0;
404 }
405 if (!fSelEntry) {
406 fSelEntry = new TGTextLBEntry(this, new TGString(text.Data()), 0);
407 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
409 fSelEntry->SetEditDisabled(kEditDisable | kEditDisableGrab);
410 }
411 fSelEntry->SetBackgroundColor(back);
413 // coverity[returned_null]
414 // coverity[dereference]
416 }
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Find entry by name.
421
422TGLBEntry *TGComboBox::FindEntry(const char *s) const
423{
424 TGLBEntry *sel = 0;
425 sel = fListBox->FindEntry(s);
426 return sel;
427}
428
429////////////////////////////////////////////////////////////////////////////////
430/// Set a new combo box value (normally update of text string in
431/// fSelEntry is done via fSelEntry::Update()).
432
434{
435 if (!fSelEntry) return;
436
438 fSelEntry->DestroyWindow();
439 delete fSelEntry;
440 delete fLhs;
441 fSelEntry = e;
442 fLhs = lh;
444 Layout();
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// Make the selected item visible in the combo box window
449/// and emit signals according to the second parameter.
450
452{
453 if (id!=GetSelected()) {
454 TGLBEntry *e;
455 e = fListBox->Select(id);
456 if (e) {
457 if (fSelEntry) {
458 fSelEntry->Update(e);
459 Layout();
460 } else if (fTextEntry && e->InheritsFrom(TGTextLBEntry::Class())) {
462 fTextEntry->SetText(te->GetText()->GetString());
463 }
464 if (emit) {
465 Selected(fWidgetId, id);
466 Selected(id);
467 Changed();
468 }
469 }
470 }
471}
472
473////////////////////////////////////////////////////////////////////////////////
474/// Handle mouse button events in the combo box.
475
477{
478 if (!fDDButton || !fDDButton->IsEnabled()) return kFALSE;
479
480 if (event->fType == kButtonPress) {
481 Window_t child = (Window_t)event->fUser[0]; // fUser[0] = child window
482
483 if (child == fDDButton->GetId() || (fSelEntry && child == fSelEntry->GetId())) {
484 fDDButton->SetState(kButtonDown);
485
486 if (fTextEntry && (child == fTextEntry->GetId())) {
487 return fTextEntry->HandleButton(event);
488 }
489 int ax, ay;
490 Window_t wdummy;
491 gVirtualX->TranslateCoordinates(fId, fComboFrame->GetParent()->GetId(),
492 0, fHeight, ax, ay, wdummy);
493 // Drop down listbox of combo box should react to pointer motion...
494 fListBox->GetContainer()->AddInput(kPointerMotionMask);
495#ifdef R__HAS_COCOA
496 gVirtualX->SetWMTransientHint(fComboFrame->GetId(), GetId());
497#endif
498 fComboFrame->PlacePopup(ax, ay, fWidth-2, fComboFrame->GetDefaultHeight());
499 fDDButton->SetState(kButtonUp);
500#ifdef R__HAS_COCOA
501 //tp: I need this modification - "button" is not repainted correctly
502 //with Cocoa, when combobox is closed (reason is quite complex), happens
503 //when item is wider than combobox.
504 //TODO: find another way :)
505 fClient->NeedRedraw(fDDButton);
506#endif
507 } else if (fTextEntry) {
508 return fTextEntry->HandleButton(event);
509 }
510 }
511 return kTRUE;
512}
513
514////////////////////////////////////////////////////////////////////////////////
515/// Remove entry. If id == -1, the currently selected entry is removed
516
518{
519 fListBox->RemoveEntry(id);
520
521 if (id < 0) {
522 if (fSelEntry) {
523 ((TGTextLBEntry*)fSelEntry)->SetTitle("");
524 fClient->NeedRedraw(fSelEntry);
525 } else {
526 fTextEntry->SetTitle("");
527 fClient->NeedRedraw(fTextEntry);
528 }
529 }
530 Resize();
531}
532
533////////////////////////////////////////////////////////////////////////////////
534/// layout combobox
535
537{
539 UInt_t h = fListBox->GetNumberOfEntries()*fListBox->GetItemVsize();
540
541 if (h && (h < 100)) {
542 fListBox->Resize(fListBox->GetWidth(), h);
543 }
544}
545
546////////////////////////////////////////////////////////////////////////////////
547/// Handle double click in text entry.
548
550{
551 return fTextEntry ? fTextEntry->HandleDoubleClick(event) : kTRUE;
552}
553
554////////////////////////////////////////////////////////////////////////////////
555/// Handle pointer motion in text entry.
556
558{
559 return fTextEntry ? fTextEntry->HandleMotion(event) : kTRUE;
560}
561
562////////////////////////////////////////////////////////////////////////////////
563/// Handle selection in text entry.
564
566{
567 return fTextEntry ? fTextEntry->HandleSelection(event) : kTRUE;
568}
569
570////////////////////////////////////////////////////////////////////////////////
571/// Handle selection request in text entry.
572
574{
575 return fTextEntry ? fTextEntry->HandleSelectionRequest(event) : kTRUE;
576}
577
578////////////////////////////////////////////////////////////////////////////////
579/// Process messages generated by the listbox and forward
580/// messages to the combobox message handling window. Parm2 contains
581/// the id of the selected listbox entry.
582
584{
585 TGLBEntry *e;
586
587 switch (GET_MSG(msg)) {
588 case kC_COMMAND:
589 switch (GET_SUBMSG(msg)) {
590 case kCM_LISTBOX:
591 e = fListBox->GetSelectedEntry();
592 if (fSelEntry) {
593 fSelEntry->Update(e);
594 } else if (fTextEntry &&
595 e->InheritsFrom(TGTextLBEntry::Class())) {
597 fTextEntry->SetText(te->GetText()->GetString());
598 }
599 // coverity[returned_null]
600 // coverity[dereference]
602 fComboFrame->EndPopup();
603 fDDButton->SetState(kButtonUp);
605 fWidgetId, parm2);
606 if (e->InheritsFrom(TGTextLBEntry::Class())) {
607 const char *text;
608 text = ((TGTextLBEntry*)e)->GetText()->GetString();
609 Selected(text);
610 }
611 Selected(fWidgetId, (Int_t)parm2);
612 Selected((Int_t)parm2);
613 Changed();
614 fClient->NeedRedraw(this);
615 break;
616 }
617 break;
618
619 default:
620 break;
621 }
622 return kTRUE;
623}
624
625////////////////////////////////////////////////////////////////////////////////
626/// Emit signal, done only when selected entry changed.
627
629{
630 Longptr_t args[2];
631
632 args[0] = widgetId;
633 args[1] = id;
634
635 Emit("Selected(Int_t,Int_t)", args);
636}
637
638////////////////////////////////////////////////////////////////////////////////
639/// Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
640
642{
643 fDDButton->SetEnabled(on);
644 if (on) {
646 if (fSelEntry) fSelEntry->SetBackgroundColor(GetBackground());
647 } else {
649 if (fSelEntry) fSelEntry->SetBackgroundColor(GetDefaultFrameBackground());
650 }
651 fClient->NeedRedraw(fSelEntry);
652}
653
654////////////////////////////////////////////////////////////////////////////////
655/// Add new entry to combo box when return key pressed inside text entry
656/// ReturnPressed signal is emitted.
657
659{
660 if (!fTextEntry) return;
661
662 TGLBContainer *lbc = (TGLBContainer *)fListBox->GetContainer();
663 TString text = fTextEntry->GetText();
664
665 TIter next(lbc->GetList());
666 TGFrameElement *el;
667
668 Emit("ReturnPressed()");
669
670 while ((el = (TGFrameElement *)next())) {
671 TGTextLBEntry *lbe = (TGTextLBEntry *)el->fFrame;
672 if (lbe->GetText()->GetString() == text) {
673 return;
674 }
675 }
676
677 Int_t nn = GetNumberOfEntries() + 1;
678 AddEntry(text.Data(), nn);
679 Select(nn);
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// Remove all entries from combo box.
684
686{
687 fListBox->RemoveAll();
688
689 if (fSelEntry) {
690 ((TGTextLBEntry*)fSelEntry)->SetTitle("");
691 fClient->NeedRedraw(fSelEntry);
692 } else {
693 fTextEntry->SetTitle("");
694 fClient->NeedRedraw(fTextEntry);
695 }
696}
697
698////////////////////////////////////////////////////////////////////////////////
699/// Save a combo box widget as a C++ statement(s) on output stream out.
700
701void TGComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
702{
703 // save options and custom color if not default
704 auto extra_args = SaveCtorArgs(out, kHorizontalFrame | kSunkenFrame | kDoubleBorder);
705
706 out << "\n // combo box\n";
707
708 out << " TGComboBox *" << GetName() << " = new TGComboBox(" << fParent->GetName();
709 if (fTextEntry)
710 out << ", \"" << TString(fTextEntry->GetText()).ReplaceSpecialCppChars() << "\"";
711 out << ", " << fWidgetId << extra_args << ");\n";
712
713 if (option && strstr(option, "keep_names"))
714 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
715
716 TGListBox *lb = GetListBox();
717
718 TIter next(((TGLBContainer *)lb->GetContainer())->GetList());
719
720 while (auto el = (TGFrameElement *)next()) {
721 auto b = (TGTextLBEntry *)el->fFrame;
722 out << " " << GetName() << "->AddEntry(";
723 b->SavePrimitive(out, option);
724 out << ");" << std::endl;
725 }
726
727 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
728 out << " " << GetName() << "->Select(" << GetSelected() << ");\n";
729}
730
731////////////////////////////////////////////////////////////////////////////////
732/// Create a line style combo box.
733
735 UInt_t options, Pixel_t back)
736 : TGComboBox(p, id, options, back)
737{
738 SetTopEntry(new TGLineLBEntry(this, 0),
740 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
741
742 for (Int_t i = 1; i <= 10; i++)
743 AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
744 TString::Format("%d",i), 0, i),
746
747 Select(1, kFALSE); // to have first entry selected
748
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Save a line style combo box widget as a C++ statement(s).
754
755void TGLineStyleComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
756{
757 out << "\n // line style combo box\n";
758 out << " TGLineStyleComboBox *" << GetName() << " = new TGLineStyleComboBox(" << fParent->GetName() << ","
759 << fWidgetId << ");\n";
760 if (option && strstr(option, "keep_names"))
761 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
762 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
763 out << " " << GetName() << "->Select(" << GetSelected() << ");\n";
764}
765
766////////////////////////////////////////////////////////////////////////////////
767/// Create a line width combo box.
768/// If "none" is equal to kTRUE the first entry is "None".
769
771 UInt_t options, Pixel_t back, Bool_t none)
772 : TGComboBox(p, id, options, back)
773{
774 SetTopEntry(new TGLineLBEntry(this,0),
776 fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
777
778 if (none) {
779 AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), 0, "None", 0, 0),
781 }
782
783 for (Int_t i = 0; i < 16; i++)
784 AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
785 TString::Format("%d",i), i, 0),
787 Select(1, kFALSE); // to have first entry selected
789}
790
791////////////////////////////////////////////////////////////////////////////////
792/// Save a line width combo box widget as a C++ statement(s).
793
794void TGLineWidthComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
795{
796 out << "\n // line width combo box\n";
797 out << " TGLineWidthComboBox *" << GetName() << " = new TGLineWidthComboBox(" << fParent->GetName() << ","
798 << fWidgetId << ");\n";
799 if (option && strstr(option, "keep_names"))
800 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
801 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
802 out << " " << GetName() << "->Select(" << GetSelected() << ");\n";
803}
804
805static const char *gFonts[][2] = { // unix name, name
806 { "", "" }, //not used
807 { "-*-times-medium-i-*-*-12-*-*-*-*-*-*-*", "1. times italic" },
808 { "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*", "2. times bold" },
809 { "-*-times-bold-i-*-*-12-*-*-*-*-*-*-*", "3. times bold italic" },
810 { "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*", "4. helvetica" },
811 { "-*-helvetica-medium-o-*-*-12-*-*-*-*-*-*-*", "5. helvetica italic" },
812 { "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*", "6. helvetica bold" },
813 { "-*-helvetica-bold-o-*-*-12-*-*-*-*-*-*-*", "7. helvetica bold italic" },
814 { "-*-courier-medium-r-*-*-12-*-*-*-*-*-*-*", "8. courier" },
815 { "-*-courier-medium-o-*-*-12-*-*-*-*-*-*-*", "9. courier italic" },
816 { "-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*", "10. courier bold" },
817 { "-*-courier-bold-o-*-*-12-*-*-*-*-*-*-*", "11. courier bold italic" },
818 { "-*-symbol-medium-r-*-*-12-*-*-*-*-*-*-*", "12. symbol" },
819 { "-*-times-medium-r-*-*-12-*-*-*-*-*-*-*", "13. times" },
820 { nullptr, nullptr }
821};
822
823////////////////////////////////////////////////////////////////////////////////
824/// Create a text font combo box.
825
827 UInt_t options, Pixel_t back) :
828 TGComboBox(p, id, options, back)
829{
830 Int_t noFonts = 0;
831
832 for (Int_t i = 1; gFonts[i][0] != 0 && noFonts < kMaxFonts; i++) {
833
834 fFonts[noFonts] = gVirtualX->LoadQueryFont(gFonts[i][0]);
835
836 if (fFonts[noFonts] == 0)
838
839 GCValues_t gval;
840 gval.fMask = kGCFont;
841 gval.fFont = gVirtualX->GetFontHandle(fFonts[noFonts]);
842
843 AddEntry(new TGTextLBEntry(GetListBox()->GetContainer(),
844 new TGString(gFonts[i][1]), i,
845 fClient->GetGC(&gval, kTRUE)->GetGC(), fFonts[noFonts]),
847 noFonts++;
848 }
849
850 if (noFonts < kMaxFonts - 1)
851 fFonts[noFonts] = 0;
852
853 Select(1, kFALSE); // to have first entry selected
855}
856
857////////////////////////////////////////////////////////////////////////////////
858/// Text font combo box dtor.
859
861{
862 for (int i = 0; i < kMaxFonts && fFonts[i] != 0; i++) {
863 if (fFonts[i] != TGTextLBEntry::GetDefaultFontStruct()) gVirtualX->DeleteFont(fFonts[i]);
864 }
865}
@ 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
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
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
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
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
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
@ 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
XFontStruct * id
Definition TGX11.cxx:147
#define gVirtualX
Definition TVirtualX.h:375
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:1109
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:1156
TGCompositeFrame(const TGCompositeFrame &)=delete
void Layout() override
Layout the elements of the composite frame.
Definition TGFrame.cxx:1249
TList * fList
container of frame elements
Definition TGFrame.h:294
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1141
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:331
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:621
static const TGGC & GetBlackGC()
Get black graphics context.
Definition TGFrame.cxx:727
UInt_t fOptions
frame options
Definition TGFrame.h:94
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
TGFrame(const TGFrame &)=delete
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:701
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:413
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:747
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:675
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:637
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:757
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
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:2493
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:767
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:2385
TText * text
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
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:252
FontH_t fFont
default text font for text operations
Definition GuiTypes.h:243
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