gwenhywfar 5.14.1
w_radiobutton.mm
Go to the documentation of this file.
1/***************************************************************************
2 begin : Aug 10 2010
3 copyright : (C) 2010 by Samuel Strupp
4
5 ***************************************************************************
6 * Please see toplevel file COPYING for license details *
7 ***************************************************************************/
8
9
10#import "CocoaRadioButton.h"
11
12
13static GWENHYWFAR_CB
16 int index,
17 int value,
18 int doSignal) {
19 NSButton *radioButton;
20
21 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
22 assert(radioButton);
23
24 switch(prop) {
26 [radioButton setEnabled:(value==0)?NO:YES];
27 return 0;
28
30 if ([radioButton window]) {
31 [[radioButton window] makeFirstResponder:radioButton];
32 }
33 return 0;
34
36 NSRect frame = [radioButton frame];
37 frame.size.width = value;
38 [radioButton setFrame:frame];
39 }
40 return 0;
41
43 NSRect frame = [radioButton frame];
44 frame.size.height = value;
45 [radioButton setFrame:frame];
46 }
47 return 0;
48
50 if (value==0) [radioButton setState:NSOffState];
51 else [radioButton setState:NSOnState];
52 }
53 return 0;
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 NSButton *radioButton;
74
75 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
76 assert(radioButton);
77
78 switch(prop) {
80 return ([radioButton isEnabled]==YES)?1:0;
81
83 if ([radioButton window]) {
84 if ([[radioButton window] firstResponder] == radioButton) return 1;
85 }
86 return 0;
87
89 return [radioButton frame].size.width;
90
92 return [radioButton frame].size.height;
93
95 return ([radioButton state]==NSOnState)?1:0;
96
97 default:
98 break;
99 }
100
102 "Function is not appropriate for this type of widget (%s)",
104 return defaultValue;
105}
106
107
108
109static GWENHYWFAR_CB
112 int index,
113 const char *value,
114 int doSignal) {
115 NSButton *radioButton;
116
117 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
118 assert(radioButton);
119
120 switch(prop) {
122 NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
123 [radioButton setTitle:stringValue];
124 [stringValue release];
125 }
126 return 0;
127 default:
128 break;
129 }
130
132 "Function is not appropriate for this type of widget (%s)",
134 return GWEN_ERROR_INVALID;
135}
136
137
138
139static GWENHYWFAR_CB
142 int index,
143 const char *defaultValue) {
144 NSButton *radioButton;
145
146 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
147 assert(radioButton);
148
149 switch(prop) {
151 return [[radioButton stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
152 default:
153 break;
154 }
155
157 "Function is not appropriate for this type of widget (%s)",
159 return defaultValue;
160}
161
162
163
164static void CocoaGui_WRadioButton_Toggled_handler(NSButton *button, void* data) {
165 GWEN_WIDGET *w;
166 int rv;
167
168 DBG_ERROR(0, "Toggled");
169 w=data;
170 assert(w);
178}
179
180
181
183 CocoaRadioButton *radioButton;
184 const char *s;
185 uint32_t flags;
186 GWEN_WIDGET *wParent;
187
188 GWEN_WIDGET *wT;
189 int groupId;
190
191 flags=GWEN_Widget_GetFlags(w);
192 wParent=GWEN_Widget_Tree_GetParent(w);
193 groupId=GWEN_Widget_GetGroupId(w);
194
195 s=GWEN_Widget_GetText(w, 0);
196
197 //Create Button
198 radioButton = [[[CocoaRadioButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
199 if (flags & GWEN_WIDGET_FLAGS_FILLX) radioButton.fillX = YES;
200 if (flags & GWEN_WIDGET_FLAGS_FILLY) radioButton.fillY = YES;
201 if (s && *s) {
202 NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
203 [radioButton setTitle:title];
204 [title release];
205 }
206
207 /* get root widget */
208 wT=wParent;
209 while(GWEN_Widget_Tree_GetParent(wT))
210 wT=GWEN_Widget_Tree_GetParent(wT);
211
212 // get first radio button of the same group
213 while(wT) {
215 GWEN_Widget_GetGroupId(wT)==groupId)
216 break;
217 wT=GWEN_Widget_Tree_GetBelow(wT);
218 }
219
220 if (wT && wT!=w) {
222 [radioButton setGroupManager:[sameGroupRadioButton getGroupManager]];
223 }
224 else {
225 [radioButton createNewGroupManagerWithGroupID:groupId];
226 }
227
228
229 // set pointers
230 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) radioButton);
232
237
239 [radioButton setC_ActionPtr:ptr Data:w];
240
241 if (wParent)
243
244 return 0;
245}
246
247
void(* gwenActionPtr)(NSButton *button, void *data)
Definition CocoaButton.h:14
#define COCOA_DIALOG_WIDGET_REAL
void CocoaGui_Dialog_Leave(GWEN_DIALOG *dlg, int result)
#define COCOA_DIALOG_WIDGET_CONTENT
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
#define DBG_WARN(dbg_logger, format,...)
Definition debug.h:125
int GWEN_Dialog_EmitSignal(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition dialog.c:321
#define GWEN_WIDGET_FLAGS_FILLY
Definition dialog.h:62
#define GWEN_WIDGET_FLAGS_FILLX
Definition dialog.h:61
GWEN_DIALOG_PROPERTY
Definition dialog.h:260
@ GWEN_DialogProperty_Title
Definition dialog.h:263
@ GWEN_DialogProperty_Height
Definition dialog.h:273
@ GWEN_DialogProperty_Enabled
Definition dialog.h:267
@ GWEN_DialogProperty_Value
Definition dialog.h:264
@ GWEN_DialogProperty_Focus
Definition dialog.h:276
@ GWEN_DialogProperty_Width
Definition dialog.h:272
@ GWEN_DialogEvent_TypeActivated
Definition dialog.h:102
@ GWEN_DialogEvent_ResultAccept
Definition dialog.h:122
@ GWEN_DialogEvent_ResultReject
Definition dialog.h:123
#define GWEN_ERROR_INVALID
Definition error.h:67
#define GWENHYWFAR_CB
#define GWEN_LOGDOMAIN
Definition logger.h:32
static GWENHYWFAR_CB int CocoaGui_WRadioButton_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
static void CocoaGui_WRadioButton_Toggled_handler(NSButton *button, void *data)
static GWENHYWFAR_CB int CocoaGui_WRadioButton_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
int CocoaGui_WRadioButton_Setup(GWEN_WIDGET *w)
static GWENHYWFAR_CB const char * CocoaGui_WRadioButton_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
static GWENHYWFAR_CB int CocoaGui_WRadioButton_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition widget.c:740
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:710
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition widget.c:836
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:695
const char * GWEN_Widget_GetText(const GWEN_WIDGET *w, int idx)
Definition widget.c:293
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:456
GWEN_DIALOG * GWEN_Widget_GetDialog(const GWEN_WIDGET *w)
Definition widget.c:92
int GWEN_Widget_GetGroupId(const GWEN_WIDGET *w)
Definition widget.c:239
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:725
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34
@ GWEN_Widget_TypeRadioButton
Definition widget_be.h:57