GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUIUtils.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <sstream>
12 
13 #include <TList.h>
14 
17 
18 using std::ostringstream;
19 
20 //____________________________________________________________________________
21 
22 void genie::utils::gui::FillListBox(TGListBox * lb, const char * lbitems[] )
23 {
24  int i = 0;
25  while( lbitems[i] )
26  {
27  lb->AddEntry(lbitems[i], i);
28  i++;
29  }
30 }
31 //____________________________________________________________________________
33  TGListBox * lb, const vector<string> * lbitems)
34 {
35  int i = 0;
36  vector<string>::const_iterator lbiter;
37 
38  for(lbiter = lbitems->begin(); lbiter != lbitems->end(); ++lbiter) {
39 
40  if( lbiter->size() > 0 ) {
41 
42  lb->AddEntry( lbiter->c_str(), i);
43  i++;
44  }
45  }
46 }
47 //____________________________________________________________________________
49 {
50  SLOG("GuiUtils", pDEBUG) << "Selecting all listbox entries";
51  SLOG("GuiUtils", pDEBUG) << "n-entries = " << lb->GetNumberOfEntries();
52 
53  for(int i = 0; i < lb->GetNumberOfEntries(); i++) lb->Select(i);
54 
55  lb->SelectionChanged();
56 }
57 //____________________________________________________________________________
59 {
60  SLOG("GuiUtils", pDEBUG) << "Reseting all listbox entries";
61  SLOG("GuiUtils", pDEBUG) << "n-entries = " << lb->GetNumberOfEntries();
62 
63  TList * selected_entries = new TList();
64  TGLBEntry * selected_entry = 0;
65 
66  lb->GetSelectedEntries(selected_entries);
67 
68  TIter lbentry(selected_entries);
69 
70  while( (selected_entry = (TGLBEntry *) lbentry.Next()) )
71  lb->Select( selected_entry->EntryId() , kFALSE);
72 
73  delete selected_entries;
74 
75  lb->SelectionChanged();
76 }
77 //____________________________________________________________________________
79  TGListBox * lb, const char * lbitems[])
80 {
81  TList selections;
82 
83  lb->GetSelectedEntries( &selections );
84 
85  TGLBEntry * lbentry = 0;
86 
87  TIter selection_iter(&selections);
88 
89  int i = 0;
90 
91  ostringstream str_select;
92 
93  while( (lbentry = (TGLBEntry *) selection_iter.Next()) ) {
94 
95  str_select << lbitems[ lbentry->EntryId() ];
96 
97  if(++i < selections.GetSize() ) str_select << ", ";
98  }
99 
100  if(i==0) return "empty";
101 
102  return str_select.str();
103 }
104 //____________________________________________________________________________
106  const char * lbitems[], const char * selection)
107 {
108  int i = 0;
109  while( lbitems[i] )
110  {
111  if ( strcmp(lbitems[i], selection) == 0 ) return i;
112  i++;
113  }
114  return 0;
115 }
116 //____________________________________________________________________________
117 void genie::utils::gui::FillComboBox(TGComboBox * cb, const char * cbitems[])
118 {
119  int i = 0;
120  while( cbitems[i] )
121  {
122  cb->AddEntry(cbitems[i], i);
123  i++;
124  }
125 }
126 //____________________________________________________________________________
128  TGComboBox * cb, const vector<string> * cbitems)
129 {
130  int i = 0;
131  vector<string>::const_iterator cbiter;
132 
133  for(cbiter = cbitems->begin(); cbiter != cbitems->end(); ++cbiter) {
134 
135  if( cbiter->size() > 0 ) {
136  cb->AddEntry( cbiter->c_str(), i);
137  i++;
138  }
139  }
140 }
141 //____________________________________________________________________________
143  TGComboBox * cb, const char * cbitems[])
144 {
145  TGLBEntry * selected_entry = cb->GetSelectedEntry();
146 
147  if(selected_entry) return string(cbitems[selected_entry->EntryId()]);
148  else return "";
149 }
150 //____________________________________________________________________________
152  const char * cbitems[], const char * selection)
153 {
154  int i = 0;
155  while( cbitems[i] ) {
156  if ( strcmp(cbitems[i], selection) == 0 ) return i;
157  i++;
158  }
159  return 0;
160 }
161 //____________________________________________________________________________
void FillComboBox(TGComboBox *cb, const char *cbitems[])
Definition: GUIUtils.cxx:117
void SelectAllListBoxEntries(TGListBox *lb)
Definition: GUIUtils.cxx:48
void ResetAllListBoxSelections(TGListBox *lb)
Definition: GUIUtils.cxx:58
string ListBoxSelectionAsString(TGListBox *lb, const char *lbitems[])
Definition: GUIUtils.cxx:78
string ComboBoxSelectionAsString(TGComboBox *cb, const char *cbitems[])
Definition: GUIUtils.cxx:142
int ComboBoxSelectionId(const char *cbitems[], const char *sel)
Definition: GUIUtils.cxx:151
void FillListBox(TGListBox *lb, const char *lbitems[])
Definition: GUIUtils.cxx:22
int ListBoxSelectionId(const char *lbitems[], const char *sel)
Definition: GUIUtils.cxx:105
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
#define pDEBUG
Definition: Messenger.h:63