gwenhywfar 5.10.1
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
14static 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
68static 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
127static 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) {
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
179static 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
220static 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);
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)
305
306 return 0;
307}
308
309
void(* gwenComboBoxActionPtr)(NSComboBox *comboBox, void *data)
Definition: CocoaComboBox.h:16
void(* gwenPopUpActionPtr)(NSPopUpButton *button, void *data)
#define NULL
Definition: binreloc.c:300
#define COCOA_DIALOG_WIDGET_REAL
void CocoaGui_Dialog_Leave(GWEN_DIALOG *dlg, int result)
#define COCOA_DIALOG_WIDGET_CONTENT
#define DBG_WARN(dbg_logger, format, args...)
Definition: debug.h:125
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
int GWEN_Dialog_EmitSignal(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition: dialog.c:321
@ GWEN_DialogEvent_ResultAccept
Definition: dialog.h:122
@ GWEN_DialogEvent_ResultReject
Definition: dialog.h:123
#define GWEN_WIDGET_FLAGS_FILLY
Definition: dialog.h:62
#define GWEN_WIDGET_FLAGS_FILLX
Definition: dialog.h:61
#define GWEN_WIDGET_FLAGS_READONLY
Definition: dialog.h:63
GWEN_DIALOG_PROPERTY
Definition: dialog.h:260
@ GWEN_DialogProperty_AddValue
Definition: dialog.h:268
@ GWEN_DialogProperty_ValueCount
Definition: dialog.h:270
@ GWEN_DialogProperty_ClearValues
Definition: dialog.h:269
@ GWEN_DialogProperty_Enabled
Definition: dialog.h:267
@ GWEN_DialogProperty_Value
Definition: dialog.h:264
@ GWEN_DialogProperty_Focus
Definition: dialog.h:276
@ GWEN_DialogEvent_TypeActivated
Definition: dialog.h:102
#define GWEN_ERROR_INVALID
Definition: error.h:67
#define GWEN_ERROR_NOT_FOUND
Definition: error.h:89
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
#define GWEN_LOGDOMAIN
Definition: logger.h:35
static GWENHYWFAR_CB int CocoaGui_WComboBox_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: w_combobox.mm:128
static GWENHYWFAR_CB int CocoaGui_WComboBox_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: w_combobox.mm:15
static void CocoaGui_WComboBox_Changed_handler(NSControl *comboBoxOrPopUp, void *data)
Definition: w_combobox.mm:220
static GWENHYWFAR_CB const char * CocoaGui_WComboBox_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
Definition: w_combobox.mm:180
static GWENHYWFAR_CB int CocoaGui_WComboBox_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Definition: w_combobox.mm:69
int CocoaGui_WComboBox_Setup(GWEN_WIDGET *w)
Definition: w_combobox.mm:254
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition: widget.c:732
GWEN_DIALOG * GWEN_Widget_GetTopDialog(const GWEN_WIDGET *w)
Definition: widget.c:102
const char * GWEN_Widget_GetName(const GWEN_WIDGET *w)
Definition: widget.c:320
GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)
Definition: widget.c:702
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition: widget.c:828
void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
Definition: widget.c:136
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition: widget.c:122
GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
Definition: widget.c:687
uint32_t GWEN_Widget_GetFlags(const GWEN_WIDGET *w)
Definition: widget.c:149
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition: widget.c:452
GWEN_DIALOG * GWEN_Widget_GetDialog(const GWEN_WIDGET *w)
Definition: widget.c:92
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition: widget.c:185
GWEN_WIDGET_SETCHARPROPERTY_FN GWEN_Widget_SetSetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETCHARPROPERTY_FN fn)
Definition: widget.c:717
struct GWEN_WIDGET GWEN_WIDGET
Definition: widget_be.h:34