gwenhywfar  4.6.0beta
w_combobox.mm
Go to the documentation of this file.
1 /***************************************************************************
2  begin : August 16 2010
3  copyright : (C) 2010 by Samuel Strupp
4 
5  ***************************************************************************
6  * Please see toplevel file COPYING for license details *
7  ***************************************************************************/
8 
9 #import "CocoaPopUpButton.h"
10 #import "CocoaComboBox.h"
11 
12 
13 
14 static GWENHYWFAR_CB
17  int index,
18  int value,
19  int doSignal) {
20  CocoaComboBox *comboBox = nil;
21  CocoaPopUpButton *popUp = nil;
22 
23  NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
24  assert(control);
25 
26  if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
27  else popUp = (CocoaPopUpButton*)control;
28 
29  switch(prop) {
31  [control setEnabled:(value!=0)];
32  return 0;
33 
35  [[control window] makeFirstResponder:control];
36  return 0;
37 
39  if (comboBox) {
40  [comboBox selectItemAtIndex:value];
41  }
42  else if (popUp) {
43  [popUp selectItemAtIndex:value];
44  }
45 
46  return 0;
47 
49  if (comboBox) [comboBox removeAllItems];
50  else if (popUp) [popUp removeAllItems];
51  return 0;
52  }
53 
54 
55  default:
56  break;
57  }
58 
60  "Function is not appropriate for this type of widget (%s)",
62  return GWEN_ERROR_INVALID;
63 }
64 
65 
66 
67 
68 static GWENHYWFAR_CB
71  int index,
72  int defaultValue) {
73  CocoaComboBox *comboBox = nil;
74  CocoaPopUpButton *popUp = nil;
75 
76  NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
77  assert(control);
78 
79  if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
80  else popUp = (CocoaPopUpButton*)control;
81 
82  switch(prop) {
84  return ([control isEnabled])?1:0;
85 
87  if ([control window]) {
88  if ([[control window] firstResponder] == control) return 1;
89  }
90  return 0;
91 
93  if (comboBox) {
94  return [comboBox indexOfSelectedItem];
95  }
96  else if (popUp) {
97  return [popUp indexOfSelectedItem];
98  }
99  return defaultValue;
100  }
101 
103  int i = -1;
104  if (comboBox) {
105  i = [comboBox numberOfItems];
106  }
107  else if (popUp) {
108  i = [popUp numberOfItems];
109  }
110 
111  DBG_ERROR(0, "Number: %d", i);
112  return i;
113  }
114 
115  default:
116  break;
117  }
118 
120  "Function is not appropriate for this type of widget (%s)",
122  return defaultValue;
123 }
124 
125 
126 
127 static GWENHYWFAR_CB
130  int index,
131  const char *value,
132  int doSignal) {
133  CocoaComboBox *comboBox = nil;
134  CocoaPopUpButton *popUp = nil;
135 
136  NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
137  assert(control);
138 
139  if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
140  else popUp = (CocoaPopUpButton*)control;
141 
142  switch(prop) {
144  return GWEN_ERROR_NOT_FOUND;
145  }
146 
148 
149  NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
150  if (popUp && stringValue) {
151  [popUp addItemWithTitle:stringValue];
152  }
153  else if (comboBox && stringValue) {
154  [comboBox addItemWithObjectValue:stringValue];
155  }
156 
157  [stringValue release];
158  return 0;
159  }
160 
162  if (comboBox) [comboBox removeAllItems];
163  else if (popUp) [popUp removeAllItems];
164  return 0;
165  }
166 
167  default:
168  break;
169  }
170 
172  "Function is not appropriate for this type of widget (%s)",
174  return GWEN_ERROR_INVALID;
175 }
176 
177 
178 
179 static GWENHYWFAR_CB
182  int index,
183  const char *defaultValue) {
184  CocoaComboBox *comboBox = nil;
185  CocoaPopUpButton *popUp = nil;
186 
187  NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
188  assert(control);
189 
190  if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
191  else popUp = (CocoaPopUpButton*)control;
192 
193  switch(prop) {
195  NSString *value = nil;
196 
197  if (popUp) {
198  value = [popUp titleOfSelectedItem];
199  }
200  else if (comboBox && [[comboBox itemObjectValueAtIndex:index] isKindOfClass:[NSString class]]) {
201  value = [comboBox itemObjectValueAtIndex:index];
202  }
203 
204  if (value) return [value cStringUsingEncoding:NSUTF8StringEncoding];
205  return NULL;
206  }
207 
208  default:
209  break;
210  }
211 
213  "Function is not appropriate for this type of widget (%s)",
215  return defaultValue;
216 }
217 
218 
219 
220 static void CocoaGui_WComboBox_Changed_handler(NSControl *comboBoxOrPopUp, void* data) {
221  GWEN_WIDGET *w;
222  int rv;
223 
224  DBG_ERROR(0, "Changed");
225  w=(GWEN_WIDGET*)data;
226  assert(w);
232  else if (rv==GWEN_DialogEvent_ResultReject)
234 }
235 
236 /*static void changed_handler(GtkWidget *comboBox, gpointer data) {
237  GWEN_WIDGET *w;
238  int rv;
239 
240  DBG_ERROR(0, "Changed");
241  w=data;
242  assert(w);
243  rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w),
244  GWEN_DialogEvent_TypeActivated,
245  GWEN_Widget_GetName(w));
246  if (rv==GWEN_DialogEvent_ResultAccept)
247  Gtk2Gui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 1);
248  else if (rv==GWEN_DialogEvent_ResultReject)
249  Gtk2Gui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 0);
250 }*/
251 
252 
253 
255  // GtkWidget *g;
256  //GtkCellRenderer *cr;
257  //GtkListStore *store;
258  uint32_t flags;
259  GWEN_WIDGET *wParent;
260  //gulong changed_handler_id;
261 
262  flags=GWEN_Widget_GetFlags(w);
263  wParent=GWEN_Widget_Tree_GetParent(w);
264 
265 
266  if (flags & GWEN_WIDGET_FLAGS_READONLY) {
267  //NSPopUpButton
268  CocoaPopUpButton *popUp = [[[CocoaPopUpButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0) pullsDown:NO] autorelease];
269  if (flags & GWEN_WIDGET_FLAGS_FILLX) popUp.fillX = YES;
270  if (flags & GWEN_WIDGET_FLAGS_FILLY) popUp.fillY = YES;
271 
274 
276  [popUp setC_PopUpActionPtr:ptr Data:w];
277  }
278  else {
279  //NSComboBox
280  CocoaComboBox *comboBox = [[[CocoaComboBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
281  if (flags & GWEN_WIDGET_FLAGS_FILLX) comboBox.fillX = YES;
282  if (flags & GWEN_WIDGET_FLAGS_FILLY) comboBox.fillY = YES;
283 
286 
288  [comboBox setC_ComboBoxActionPtr:ptr Data:w];
289  }
290 
295 
296 #pragma mark NOCH MACHEN Action setzen
297 
298  /*changed_handler_id=g_signal_connect(g,
299  "changed",
300  G_CALLBACK (changed_handler),
301  w);*/
302 
303  if (wParent)
304  GWEN_Widget_AddChildGuiWidget(wParent, w);
305 
306  return 0;
307 }
308 
309