ROOT  6.06/09
Reference Guide
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 // //
25 // TGComboBox, TGComboBoxPopup //
26 // //
27 // A combobox (also known as a drop down listbox) allows the selection //
28 // of one item out of a list of items. The selected item is visible in //
29 // a little window. To view the list of possible items one has to click //
30 // on a button on the right of the little window. This will drop down //
31 // a listbox. After selecting an item from the listbox the box will //
32 // disappear and the newly selected item will be shown in the little //
33 // window. //
34 // //
35 // The TGComboBox is user callable. The TGComboBoxPopup is a service //
36 // class of the combobox. //
37 // //
38 // Selecting an item in the combobox will generate the event: //
39 // kC_COMMAND, kCM_COMBOBOX, combobox id, item id. //
40 // //
41 //////////////////////////////////////////////////////////////////////////
42 
43 #include "TGComboBox.h"
44 #include "TGScrollBar.h"
45 #include "TGPicture.h"
46 #include "TGResourcePool.h"
47 #include "Riostream.h"
48 #include "TGTextEntry.h"
49 #include "KeySymbols.h"
50 #include "RConfigure.h"
51 
52 
55 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Create a combo box popup frame.
62 
64  UInt_t options, ULong_t back) :
65  TGCompositeFrame (p, w, h, options, back), fListBox(0), fSelected(0)
66 {
68 
71  wattr.fOverrideRedirect = kTRUE;
72  wattr.fSaveUnder = kTRUE;
73  wattr.fBorderPixel = fgBlackPixel;
74  wattr.fBorderWidth = 1;
75  gVirtualX->ChangeWindowAttributes(fId, &wattr);
76 
77  AddInput(kStructureNotifyMask);
78  fEditDisabled = kEditDisable | kEditDisableGrab | kEditDisableBtnEnable;
79  SetWindowName();
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Handle mouse button event in combo box popup.
84 
86 {
87  if (event->fType == kButtonPress && event->fCode == kButton1) {
88  if ((fListBox != 0) && (fSelected != 0) &&
90  // in the case the combo box popup is closed by clicking outside the
91  // list box, then select the previously selected entry
93  }
94  EndPopup();
95  }
96  else {
97  // reset the dragging flag of the scrollbar when the button is
98  // released outside the scrollbar itself
100  }
101  return kTRUE;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Ungrab pointer and unmap popup window.
106 
108 {
109  if (IsMapped()) {
110  Handle_t id = fListBox->GetContainer()->GetId();
111  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Up),
113  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Down),
115  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Enter),
117  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Return),
119  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Escape),
121  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Space),
123  gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
124  UnmapWindow();
125  }
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Popup combo box popup window at the specified place.
130 
132 {
133  Int_t rx, ry;
134  UInt_t rw, rh;
135 
136  // Parent is root window for the popup:
137  gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
138 
139  if (x < 0) x = 0;
140  if (x + fWidth > rw) x = rw - fWidth;
141  if (y < 0) y = 0;
142  if (y + fHeight > rh) y = rh - fHeight;
143 
144  // remember the current selected entry
145  if (fListBox == 0) {
146  // the listbox should be the first in the list
148  fListBox = dynamic_cast<TGListBox *>(el->fFrame);
149  }
151 
152  MoveResize(x, y, w, h);
153  MapSubwindows();
154  Layout();
155  MapRaised();
156 
157  Handle_t id = fListBox->GetContainer()->GetId();
158  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Up),
160  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Down),
162  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Enter),
164  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Return),
166  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Escape),
168  gVirtualX->GrabKey(id, gVirtualX->KeysymToKeycode(kKey_Space),
171 
175 
176  if (fClient->IsEditable()) {
177  fClient->RegisterPopup(this);
178  }
179 
180  fClient->WaitForUnmap(this);
181  EndPopup();
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Slot handling the key press events.
186 
188 {
189  switch ((EKeySym)keysym) {
190  case kKey_Enter:
191  case kKey_Return:
192  case kKey_Space:
193  if (fListBox && f) {
194  TGLBEntry *entry = dynamic_cast<TGLBEntry *>(f);
195  if (entry) {
196  fListBox->Select(entry->EntryId());
198  entry->EntryId(), 0);
199  }
200  }
201  EndPopup();
202  break;
203  case kKey_Escape:
204  if (fListBox)
205  ((TGContainer *)fListBox->GetContainer())->UnSelectAll();
206  EndPopup();
207  break;
208  default:
209  break;
210  }
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Create a combo box widget.
215 
217  ULong_t back) :
218  TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
219 {
220  fWidgetId = id;
221  fMsgWindow = p;
222  fTextEntry = 0;
223 
224  fSelEntry = new TGTextLBEntry(this, new TGString(""), 0);
226 
229  Init();
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Create an editable combo box widget.
234 
235 TGComboBox::TGComboBox(const TGWindow *p, const char *text, Int_t id,
236  UInt_t options, ULong_t back) :
237  TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
238 {
239  fWidgetId = id;
240  fMsgWindow = p;
241  fSelEntry = 0;
242 
243  fTextEntry = new TGTextEntry(this, text, id);
245  fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
246 
249  Init();
250 }
251 
252 ////////////////////////////////////////////////////////////////////////////////
253 /// Delete a combo box widget.
254 
256 {
258 
259  if (!MustCleanup()) {
263  SafeDelete(fLhs);
264  SafeDelete(fLhb);
265  }
266 
267  SafeDelete(fLhdd);
269  if (fComboFrame) {
270  fComboFrame->EndPopup(); // force popdown in case of Qt interface
272  }
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Initiate the internal classes of a combo box.
277 
279 {
280  fBpic = fClient->GetPicture("arrow_down.xpm");
281 
282  if (!fBpic)
283  Error("TGComboBox", "arrow_down.xpm not found");
284 
287 
289  kLHintsExpandY));
290 
292 
294 
295  fListBox->Resize(100, 100);
296  fListBox->Associate(this);
297  fListBox->GetScrollBar()->GrabPointer(kFALSE); // combobox will do a pointergrab
298 
300  kLHintsExpandY));
301  fComboFrame->SetListBox(fListBox);
304 
307 
308  fListBox->GetContainer()->Connect("KeyPressed(TGFrame*, UInt_t, UInt_t)",
309  "TGComboBoxPopup", fComboFrame,
310  "KeyPressed(TGFrame*, UInt_t, UInt_t)");
311  // Drop down listbox of combo box should react to pointer motion
312  // so it will be able to Activate() (i.e. highlight) the different
313  // items when the mouse crosses.
314  fListBox->GetContainer()->AddInput(kButtonPressMask | kButtonReleaseMask |
316 
317  fListBox->SetEditDisabled(kEditDisable);
318  fListBox->GetContainer()->SetEditDisabled(kEditDisable);
323 
324  SetWindowName();
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Draw border of combo box widget.
329 
331 {
334  gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
335  gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
336  gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
337  gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
338  if (gClient->GetStyle() > 1) break;
339  gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
340  gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
341  gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
342  gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
343  break;
344 
345  default:
347  break;
348  }
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Switch text input or readonly mode of combobox (not perfect yet).
353 
355 {
356  // UInt_t w, h;
357  const char *text = "";
358  Pixel_t back = TGFrame::GetWhitePixel(); // default
359 
360  if (on) {
361  if (fSelEntry) {
362  back = fSelEntry->GetBackground();
363  text = ((TGTextLBEntry*)fSelEntry)->GetText()->GetString();
365  fTextEntry->SetText(text);
366  }
368  //w = fSelEntry->GetWidth();
369  //h = fSelEntry->GetHeight();
371  delete fSelEntry;
372  fSelEntry = 0;
373  }
374  if (!fTextEntry) {
375  fTextEntry = new TGTextEntry(this, text, 0);
377  fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
380  }
382  MapSubwindows();
383  // coverity[returned_null]
384  // coverity[dereference]
386  } else {
387  if (fTextEntry) {
388  back = fTextEntry->GetBackground();
389  text = fTextEntry->GetText();
392  //w = fTextEntry->GetWidth();
393  //h = fTextEntry->GetHeight();
394  delete fTextEntry;
395  fTextEntry = 0;
396  }
397  if (!fSelEntry) {
398  fSelEntry = new TGTextLBEntry(this, new TGString(text), 0);
402  }
404  MapSubwindows();
405  // coverity[returned_null]
406  // coverity[dereference]
408  }
409 }
410 
411 ////////////////////////////////////////////////////////////////////////////////
412 /// Find entry by name.
413 
414 TGLBEntry *TGComboBox::FindEntry(const char *s) const
415 {
416  TGLBEntry *sel = 0;
417  sel = fListBox->FindEntry(s);
418  return sel;
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 /// Set a new combo box value (normally update of text string in
423 /// fSelEntry is done via fSelEntry::Update()).
424 
426 {
427  if (!fSelEntry) return;
428 
431  delete fSelEntry;
432  delete fLhs;
433  fSelEntry = e;
434  fLhs = lh;
436  Layout();
437 }
438 
439 ////////////////////////////////////////////////////////////////////////////////
440 /// Make the selected item visible in the combo box window
441 /// and emit signals according to the second parameter.
442 
444 {
445  if (id!=GetSelected()) {
446  TGLBEntry *e;
447  e = fListBox->Select(id);
448  if (e) {
449  if (fSelEntry) {
450  fSelEntry->Update(e);
451  Layout();
452  if (emit) {
453  Selected(fWidgetId, id);
454  Selected(id);
455  }
456  }
457  }
458  }
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Handle mouse button events in the combo box.
463 
465 {
466  if (!fDDButton || !fDDButton->IsEnabled()) return kFALSE;
467 
468  if (event->fType == kButtonPress) {
469  Window_t child = (Window_t)event->fUser[0]; // fUser[0] = child window
470 
471  if (child == fDDButton->GetId() || (fSelEntry && child == fSelEntry->GetId())) {
473 
474  if (fTextEntry && (child == fTextEntry->GetId())) {
475  return fTextEntry->HandleButton(event);
476  }
477  int ax, ay;
478  Window_t wdummy;
479  gVirtualX->TranslateCoordinates(fId, fComboFrame->GetParent()->GetId(),
480  0, fHeight, ax, ay, wdummy);
481  // Drop down listbox of combo box should react to pointer motion...
483 #ifdef R__HAS_COCOA
484  gVirtualX->SetWMTransientHint(fComboFrame->GetId(), GetId());
485 #endif
488 #ifdef R__HAS_COCOA
489  //tp: I need this modification - "button" is not repainted correctly
490  //with Cocoa, when combobox is closed (reason is quite complex), happens
491  //when item is wider than combobox.
492  //TODO: find another way :)
494 #endif
495  } else if (fTextEntry) {
496  return fTextEntry->HandleButton(event);
497  }
498  }
499  return kTRUE;
500 }
501 
502 ////////////////////////////////////////////////////////////////////////////////
503 /// Remove entry. If id == -1, the currently selected entry is removed
504 
506 {
507  fListBox->RemoveEntry(id);
508 
509  if (id < 0) {
510  if (fSelEntry) {
511  ((TGTextLBEntry*)fSelEntry)->SetTitle("");
512  fClient->NeedRedraw(fSelEntry);
513  } else {
514  fTextEntry->SetTitle("");
516  }
517  }
518  Resize();
519 }
520 
521 ////////////////////////////////////////////////////////////////////////////////
522 /// layout combobox
523 
525 {
528 
529  if (h && (h < 100)) {
531  }
532 }
533 
534 ////////////////////////////////////////////////////////////////////////////////
535 /// Handle double click in text entry.
536 
538 {
539  return fTextEntry ? fTextEntry->HandleDoubleClick(event) : kTRUE;
540 }
541 
542 ////////////////////////////////////////////////////////////////////////////////
543 /// Handle pointer motion in text entry.
544 
546 {
547  return fTextEntry ? fTextEntry->HandleMotion(event) : kTRUE;
548 }
549 
550 ////////////////////////////////////////////////////////////////////////////////
551 /// Handle selection in text entry.
552 
554 {
555  return fTextEntry ? fTextEntry->HandleSelection(event) : kTRUE;
556 }
557 
558 ////////////////////////////////////////////////////////////////////////////////
559 /// Handle selection request in text entry.
560 
562 {
564 }
565 
566 ////////////////////////////////////////////////////////////////////////////////
567 /// Process messages generated by the listbox and forward
568 /// messages to the combobox message handling window. Parm2 contains
569 /// the id of the selected listbox entry.
570 
572 {
573  TGLBEntry *e;
574 
575  switch (GET_MSG(msg)) {
576  case kC_COMMAND:
577  switch (GET_SUBMSG(msg)) {
578  case kCM_LISTBOX:
579  e = fListBox->GetSelectedEntry();
580  if (fSelEntry) {
581  fSelEntry->Update(e);
582  } else if (fTextEntry &&
584  TGTextLBEntry *te = (TGTextLBEntry*)e;
585  fTextEntry->SetText(te->GetText()->GetString());
586  }
587  // coverity[returned_null]
588  // coverity[dereference]
593  fWidgetId, parm2);
595  const char *text;
596  text = ((TGTextLBEntry*)e)->GetText()->GetString();
597  Selected(text);
598  }
599  Selected(fWidgetId, (Int_t)parm2);
600  Selected((Int_t)parm2);
601  fClient->NeedRedraw(this);
602  break;
603  }
604  break;
605 
606  default:
607  break;
608  }
609  return kTRUE;
610 }
611 
612 ////////////////////////////////////////////////////////////////////////////////
613 /// Emit signal.
614 
615 void TGComboBox::Selected(Int_t widgetId, Int_t id)
616 {
617  Long_t args[2];
618 
619  args[0] = widgetId;
620  args[1] = id;
621 
622  Emit("Selected(Int_t,Int_t)", args);
623 }
624 
625 ////////////////////////////////////////////////////////////////////////////////
626 /// Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
627 
629 {
630  fDDButton->SetEnabled(on);
631  if (on) {
634  } else {
637  }
639 }
640 
641 ////////////////////////////////////////////////////////////////////////////////
642 /// Add new entry to combo box when return key pressed inside text entry
643 /// ReturnPressed signal is emitted.
644 
646 {
647  if (!fTextEntry) return;
648 
651 
652  TIter next(lbc->GetList());
653  TGFrameElement *el;
654 
655  Emit("ReturnPressed()");
656 
657  while ((el = (TGFrameElement *)next())) {
658  TGTextLBEntry *lbe = (TGTextLBEntry *)el->fFrame;
659  if (lbe->GetText()->GetString() == text) {
660  return;
661  }
662  }
663 
664  Int_t nn = GetNumberOfEntries() + 1;
665  AddEntry(text.Data(), nn);
666  Select(nn);
667 }
668 
669 ////////////////////////////////////////////////////////////////////////////////
670 /// Remove all entries from combo box.
671 
673 {
674  fListBox->RemoveAll();
675 
676  if (fSelEntry) {
677  ((TGTextLBEntry*)fSelEntry)->SetTitle("");
678  fClient->NeedRedraw(fSelEntry);
679  } else {
680  fTextEntry->SetTitle("");
682  }
683 }
684 
685 ////////////////////////////////////////////////////////////////////////////////
686 /// Save a combo box widget as a C++ statement(s) on output stream out.
687 
688 void TGComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
689 {
690  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
691 
692  out << std::endl << " // combo box" << std::endl;
693  out << " TGComboBox *";
694 
695  if (!fTextEntry) {
696  out << GetName() << " = new TGComboBox(" << fParent->GetName() << "," << fWidgetId;
697  } else {
698  out << GetName() << " = new TGComboBox(" << fParent->GetName() << ",";
699  out << '\"' << fTextEntry->GetText() << '\"' << "," <<fWidgetId;
700  }
701 
702  if (fBackground == GetWhitePixel()) {
704  out <<");" << std::endl;
705  } else {
706  out << "," << GetOptionString() << ");" << std::endl;
707  }
708  } else {
709  out << "," << GetOptionString() << ",ucolor);" << std::endl;
710  }
711  if (option && strstr(option, "keep_names"))
712  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
713 
714  TGTextLBEntry *b;
715  TGFrameElement *el;
716  TGListBox *lb = GetListBox();
717 
719 
720  while ((el = (TGFrameElement *) next())) {
721  b = (TGTextLBEntry *) el->fFrame;
722  out << " " << GetName() << "->AddEntry(";
723  b->SavePrimitive(out, option);
724  out << ");" << std::endl;
725  }
726 
727  out << " " << GetName() << "->Resize(" << GetWidth() << ","
728  << GetHeight() << ");" << std::endl;
729  out << " " << GetName() << "->Select(" << GetSelected() << ");" << std::endl;
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),
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 
750  SetWindowName();
751 }
752 
753 ////////////////////////////////////////////////////////////////////////////////
754 /// Save a line style combo box widget as a C++ statement(s).
755 
756 void TGLineStyleComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
757 {
758  out << std::endl << " // line style combo box" << std::endl;
759  out << " TGLineStyleComboBox *";
760 
761  out << GetName() << " = new TGLineStyleComboBox(" << fParent->GetName()
762  << "," << fWidgetId << ");" << std::endl;
763  if (option && strstr(option, "keep_names"))
764  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
765  out << " " << GetName() << "->Resize(" << GetWidth() << ","
766  << GetHeight() << ");" << std::endl;
767  out << " " << GetName() << "->Select(" << GetSelected() << ");" << std::endl;
768 }
769 
770 ////////////////////////////////////////////////////////////////////////////////
771 /// Create a line width combo box.
772 /// If "none" is equal to kTRUE the first entry is "None".
773 
775  UInt_t options, Pixel_t back, Bool_t none)
776  : TGComboBox(p, id, options, back)
777 {
778  SetTopEntry(new TGLineLBEntry(this,0),
781 
782  if (none) {
783  AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), 0, "None", 0, 0),
785  }
786 
787  for (Int_t i = 0; i < 16; i++)
788  AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
789  TString::Format("%d",i), i, 0),
791  Select(1, kFALSE); // to have first entry selected
792  SetWindowName();
793 }
794 
795 ////////////////////////////////////////////////////////////////////////////////
796 /// Save a line width combo box widget as a C++ statement(s).
797 
798 void TGLineWidthComboBox::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
799 {
800  out << std::endl << " // line width combo box" << std::endl;
801  out << " TGLineWidthComboBox *";
802 
803  out << GetName() << " = new TGLineWidthComboBox(" << fParent->GetName()
804  << "," << fWidgetId << ");" << std::endl;
805  if (option && strstr(option, "keep_names"))
806  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
807  out << " " << GetName() << "->Resize(" << GetWidth() << ","
808  << GetHeight() << ");" << std::endl;
809  out << " " << GetName() << "->Select(" << GetSelected() << ");" << std::endl;
810 }
811 
812 static const char *gFonts[][2] = { // unix name, name
813  { "", "" }, //not used
814  { "-*-times-medium-i-*-*-12-*-*-*-*-*-*-*", "1. times italic" },
815  { "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*", "2. times bold" },
816  { "-*-times-bold-i-*-*-12-*-*-*-*-*-*-*", "3. times bold italic" },
817  { "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*", "4. helvetica" },
818  { "-*-helvetica-medium-o-*-*-12-*-*-*-*-*-*-*", "5. helvetica italic" },
819  { "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*", "6. helvetica bold" },
820  { "-*-helvetica-bold-o-*-*-12-*-*-*-*-*-*-*", "7. helvetica bold italic" },
821  { "-*-courier-medium-r-*-*-12-*-*-*-*-*-*-*", "8. courier" },
822  { "-*-courier-medium-o-*-*-12-*-*-*-*-*-*-*", "9. courier italic" },
823  { "-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*", "10. courier bold" },
824  { "-*-courier-bold-o-*-*-12-*-*-*-*-*-*-*", "11. courier bold italic" },
825  { "-*-symbol-medium-r-*-*-12-*-*-*-*-*-*-*", "12. symbol" },
826  { "-*-times-medium-r-*-*-12-*-*-*-*-*-*-*", "13. times" },
827  { 0, 0}
828 };
829 
830 ////////////////////////////////////////////////////////////////////////////////
831 /// Create a text font combo box.
832 
834  UInt_t options, Pixel_t back) :
835  TGComboBox(p, id, options, back)
836 {
837  Int_t noFonts = 0;
838 
839  for (Int_t i = 1; gFonts[i][0] != 0 && noFonts < kMaxFonts; i++) {
840 
841  fFonts[noFonts] = gVirtualX->LoadQueryFont(gFonts[i][0]);
842 
843  if (fFonts[noFonts] == 0)
845 
846  GCValues_t gval;
847  gval.fMask = kGCFont;
848  gval.fFont = gVirtualX->GetFontHandle(fFonts[noFonts]);
849 
850  AddEntry(new TGTextLBEntry(GetListBox()->GetContainer(),
851  new TGString(gFonts[i][1]), i,
852  fClient->GetGC(&gval, kTRUE)->GetGC(), fFonts[noFonts]),
854  noFonts++;
855  }
856 
857  if (noFonts < kMaxFonts - 1)
858  fFonts[noFonts] = 0;
859 
860  Select(1, kFALSE); // to have first entry selected
861  SetWindowName();
862 }
863 
864 ////////////////////////////////////////////////////////////////////////////////
865 /// Text font combo box dtor.
866 
868 {
869  for (int i = 0; i < kMaxFonts && fFonts[i] != 0; i++) {
870  if (fFonts[i] != TGTextLBEntry::GetDefaultFontStruct()) gVirtualX->DeleteFont(fFonts[i]);
871  }
872 }
virtual Int_t GetNumberOfEntries() const
Definition: TGListBox.h:339
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle request to send current clipboard contents to requestor window.
const TGWindow * fParent
Definition: TGWindow.h:43
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a list box entry widget as a C++ statement(s) on output stream out.
Definition: TGListBox.cxx:1700
virtual void Resize(UInt_t w, UInt_t h)
Resize the listbox widget.
Definition: TGListBox.cxx:1419
virtual TGLBEntry * FindEntry(const char *s) const
Find entry by name.
Definition: TGListBox.cxx:1643
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
Move and/or resize the frame.
Definition: TGFrame.cxx:611
TGScrollBarElement * fDDButton
Definition: TGComboBox.h:78
virtual Bool_t HandleMotion(Event_t *event)
Handle pointer motion in text entry.
Definition: TGComboBox.cxx:545
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
const TGWindow * GetParent() const
Definition: TGWindow.h:87
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
virtual Bool_t IsEnabled() const
Definition: TGScrollBar.h:75
FontH_t fFont
Definition: GuiTypes.h:243
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:321
const char Option_t
Definition: RtypesCore.h:62
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:737
virtual Bool_t HandleSelection(Event_t *event)
Handle text selection event.
void EndPopup()
Ungrab pointer and unmap popup window.
Definition: TGComboBox.cxx:107
TH1 * h
Definition: legend2.C:5
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
virtual void Update(TGLBEntry *)
Definition: TGListBox.h:75
UInt_t GetWidth() const
Definition: TGFrame.h:287
TGComboBox(const TGComboBox &)
const Mask_t kWABorderPixel
Definition: GuiTypes.h:143
Int_t SetFlags(Int_t flags)
Definition: TGWidget.h:76
virtual void SetDragging(Bool_t drag)
Definition: TGScrollBar.h:131
virtual void DrawBorder()
Draw border of combo box widget.
Definition: TGComboBox.cxx:330
virtual void DrawBorder()
Draw frame border.
Definition: TGFrame.cxx:403
virtual void SetTitle(const char *label)
Definition: TGTextEntry.h:176
Basic string class.
Definition: TString.h:137
Pixel_t fBackground
Definition: TGFrame.h:158
virtual TList * GetList() const
Definition: TGFrame.h:385
#define gClient
Definition: TGClient.h:174
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Int_t GetNumberOfEntries() const
Definition: TGComboBox.h:129
TGLineStyleComboBox(const TGWindow *p=0, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel())
Create a line style combo box.
Definition: TGComboBox.cxx:735
virtual void SetEnabled(Bool_t on=kTRUE)
Enable/Disable scroll bar button chaging the state.
UInt_t GetHeight() const
Definition: TGFrame.h:288
virtual void MapRaised()
Definition: TGFrame.h:268
Int_t fWidgetId
Definition: TGWidget.h:64
void WaitForUnmap(TGWindow *w)
Wait for window to be unmapped.
Definition: TGClient.cxx:734
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1239
TGComboBoxPopup * fComboFrame
Definition: TGComboBox.h:79
ClassImp(TGComboBoxPopup) ClassImp(TGComboBox) ClassImp(TGLineStyleComboBox) ClassImp(TGLineWidthComboBox) ClassImp(TGFontTypeComboBox) TGComboBoxPopup
Create a combo box popup frame.
Definition: TGComboBox.cxx:53
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1131
Bool_t IsEditable() const
Definition: TGClient.h:106
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:164
const char * Data() const
Definition: TString.h:349
TGLBEntry * fSelEntry
Definition: TGComboBox.h:76
TGLayoutHints * fLhdd
Definition: TGComboBox.h:84
#define SafeDelete(p)
Definition: RConfig.h:436
void RegisterPopup(TGWindow *w)
Add a popup menu to the list of popups.
Definition: TGClient.cxx:530
Double_t x[n]
Definition: legend1.C:17
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
ULong_t Pixel_t
Definition: GuiTypes.h:41
void Class()
Definition: Class.C:29
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual UInt_t GetOptions() const
Definition: TGFrame.h:260
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
const TGPicture * fBpic
Definition: TGComboBox.h:81
const char * GetText() const
Definition: TGTextEntry.h:140
const Mask_t kGCFont
Definition: GuiTypes.h:301
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...
Definition: TGComboBox.cxx:443
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text entry 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(...
Definition: TGComboBox.cxx:425
if(pyself &&pyself!=Py_None)
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
virtual ~TGComboBox()
Delete a combo box widget.
Definition: TGComboBox.cxx:255
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text entry widget.
TGLayoutHints * fLhb
Definition: TGComboBox.h:83
XFontStruct * id
Definition: TGX11.cxx:108
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual TGFrame * GetContainer() const
Definition: TGListBox.h:343
virtual void RemoveAll()
Remove all entries from combo box.
Definition: TGComboBox.cxx:672
virtual void RequestFocus()
Definition: TGWindow.h:100
const TGWindow * fMsgWindow
Definition: TGWidget.h:66
char * out
Definition: TBase64.cxx:29
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:559
virtual TGLBEntry * Select(Int_t id, Bool_t sel=kTRUE)
Definition: TGListBox.h:360
virtual Int_t GetSelected() const
Definition: TGComboBox.h:136
const Mask_t kButtonPressMask
Definition: GuiTypes.h:162
Bool_t fOverrideRedirect
Definition: GuiTypes.h:108
virtual Int_t MustCleanup() const
Definition: TGFrame.h:436
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1135
virtual void RemoveAll()
Remove all entries.
Definition: TGListBox.cxx:1352
virtual void SetFrameDrawn(Bool_t flag=kTRUE)
Sets the text entry to draw itself inside a two-pixel frame if enable is kTRUE, and to draw itself wi...
TList * fList
Definition: TGFrame.h:367
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click in text entry.
Definition: TGComboBox.cxx:537
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
Popup combo box popup window at the specified place.
Definition: TGComboBox.cxx:131
UInt_t fOptions
Definition: TGFrame.h:157
const Mask_t kWASaveUnder
Definition: GuiTypes.h:151
virtual TGLBEntry * FindEntry(const char *s) const
Find entry by name.
Definition: TGComboBox.cxx:414
Int_t EntryId() const
Definition: TGListBox.h:76
Int_t ClearFlags(Int_t flags)
Definition: TGWidget.h:77
EGEventType fType
Definition: GuiTypes.h:176
Int_t GET_SUBMSG(Long_t val)
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a line style combo box widget as a C++ statement(s).
Definition: TGComboBox.cxx:756
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:389
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a combo box widget as a C++ statement(s) on output stream out.
Definition: TGComboBox.cxx:688
TGListBox * fListBox
Definition: TGComboBox.h:80
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual TGListBox * GetListBox() const
Definition: TGComboBox.h:132
const Handle_t kNone
Definition: GuiTypes.h:89
TGListBox * fListBox
Definition: TGComboBox.h:46
TGFrame * fFrame
Definition: TGLayout.h:125
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle mouse double click event in the text entry widget.
virtual void EnableTextInput(Bool_t on)
Switch text input or readonly mode of combobox (not perfect yet).
Definition: TGComboBox.cxx:354
virtual ~TGFontTypeComboBox()
Text font combo box dtor.
Definition: TGComboBox.cxx:867
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in the combo box.
Definition: TGComboBox.cxx:464
static const TGGC & GetBlackGC()
Get black graphics context.
Definition: TGFrame.cxx:717
Long64_t entry
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
Definition: TGComboBox.cxx:628
#define gVirtualX
Definition: TVirtualX.h:362
UInt_t fWidth
Definition: TGFrame.h:150
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get graphics context from the gc pool.
Definition: TGClient.cxx:318
Int_t GET_MSG(Long_t val)
EKeySym
Definition: KeySymbols.h:27
long Long_t
Definition: RtypesCore.h:50
TGFrame * fSelected
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
TGFontTypeComboBox(const TGWindow *p=0, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t bask=GetWhitePixel())
Create a text font combo box.
Definition: TGComboBox.cxx:833
void SetListBox(TGListBox *lb)
Definition: TGComboBox.h:61
double f(double x)
virtual void SetEditDisabled(UInt_t on=1)
Set edit disable flag for this frame and subframes.
Definition: TGFrame.cxx:1004
const Mask_t kStructureNotifyMask
Definition: GuiTypes.h:167
const TGResourcePool * GetResourcePool() const
Definition: TGClient.h:141
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:108
TText * text
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:163
UInt_t fCode
Definition: GuiTypes.h:181
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:287
virtual Bool_t HandleSelection(Event_t *event)
Handle selection in text entry.
Definition: TGComboBox.cxx:553
virtual void Selected(Int_t widgetId, Int_t id)
Emit signal.
Definition: TGComboBox.cxx:615
const Mask_t kWAOverrideRedirect
Definition: GuiTypes.h:150
unsigned long ULong_t
Definition: RtypesCore.h:51
Double_t y[n]
Definition: legend1.C:17
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:180
virtual TGLBEntry * GetSelectedEntry() const
Definition: TGListBox.h:364
UInt_t fHeight
Definition: TGFrame.h:151
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGLayoutHints * fLhs
Definition: TGComboBox.h:82
Long_t fUser[5]
Definition: GuiTypes.h:188
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
Cursor_t GetGrabCursor() const
Handle_t fId
Definition: TGObject.h:40
ULong_t fBorderPixel
Definition: GuiTypes.h:98
TGLineWidthComboBox(const TGWindow *p=0, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel(), Bool_t none=kFALSE)
Create a line width combo box.
Definition: TGComboBox.cxx:774
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:556
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a line width combo box widget as a C++ statement(s).
Definition: TGComboBox.cxx:798
TGTextEntry * fTextEntry
Definition: TGComboBox.h:77
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:255
Handle_t Window_t
Definition: GuiTypes.h:30
virtual void UnmapWindow()
Definition: TGFrame.h:269
virtual void SetBackgroundColor(Pixel_t col)
Set background color (override from TGWindow base class).
Definition: TGListBox.h:78
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition: TGWindow.h:119
Mask_t fMask
Definition: GuiTypes.h:252
virtual void ReturnPressed()
Add new entry to combo box when return key pressed inside text entry ReturnPressed signal is emitted...
Definition: TGComboBox.cxx:645
const Mask_t kWABorderWidth
Definition: GuiTypes.h:144
TGClient * fClient
Definition: TGObject.h:41
static const char * gFonts[][2]
Definition: TGComboBox.cxx:812
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages generated by the listbox and forward messages to the combobox message handling windo...
Definition: TGComboBox.cxx:571
virtual Bool_t HandleButton(Event_t *)
Handle mouse button event in combo box popup.
Definition: TGComboBox.cxx:85
virtual void Layout()=0
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
UInt_t fEditDisabled
Definition: TGWindow.h:47
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2433
const char * GetString() const
Definition: TGString.h:44
virtual void RemoveEntry(Int_t id=-1)
Remove entry. If id == -1, the currently selected entry is removed.
Definition: TGComboBox.cxx:505
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:391
virtual void Init()
Initiate the internal classes of a combo box.
Definition: TGComboBox.cxx:278
const TGString * GetText() const
Definition: TGListBox.h:123
FontStruct_t fFonts[kMaxFonts]
Definition: TGComboBox.h:211
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line...
virtual void Layout()
layout combobox
Definition: TGComboBox.cxx:524
const Bool_t kTRUE
Definition: Rtypes.h:91
const Mask_t kAnyModifier
Definition: GuiTypes.h:211
virtual void SetState(Int_t state)
Change state of scrollbar element (either up or down).
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use for a text listbox entry.
Definition: TGListBox.cxx:189
Handle_t GetId() const
Definition: TGObject.h:52
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle selection request in text entry.
Definition: TGComboBox.cxx:561
const Int_t kMaxFonts
Definition: TGComboBox.h:206
virtual void ChangeOptions(UInt_t options)
Change frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:303
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2460
GContext_t GetGC() const
Definition: TGGC.h:54
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:747
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition: TGFrame.cxx:757
virtual void DestroyWindow()
Definition: TGWindow.h:94
void KeyPressed(TGFrame *, UInt_t, UInt_t)
Slot handling the key press events.
Definition: TGComboBox.cxx:187
virtual void RemoveEntry(Int_t id=-1)
remove entry with id.
Definition: TGListBox.cxx:1326
UInt_t GetItemVsize() const
Definition: TGListBox.h:366
virtual TGLayoutManager * GetLayoutManager() const
Definition: TGFrame.h:413
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:118
TGLBEntry * fSelected
Definition: TGComboBox.h:47
virtual TGScrollBar * GetScrollBar() const
Definition: TGListBox.h:345
ULong_t Handle_t
Definition: GuiTypes.h:27