00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #import "CocoaRadioButton.h"
00011
00012
00013 static GWENHYWFAR_CB
00014 int CocoaGui_WRadioButton_SetIntProperty(GWEN_WIDGET *w,
00015 GWEN_DIALOG_PROPERTY prop,
00016 int index,
00017 int value,
00018 int doSignal) {
00019 NSButton *radioButton;
00020
00021 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00022 assert(radioButton);
00023
00024 switch(prop) {
00025 case GWEN_DialogProperty_Enabled:
00026 [radioButton setEnabled:(value==0)?NO:YES];
00027 return 0;
00028
00029 case GWEN_DialogProperty_Focus:
00030 if ([radioButton window]) {
00031 [[radioButton window] makeFirstResponder:radioButton];
00032 }
00033 return 0;
00034
00035 case GWEN_DialogProperty_Width: {
00036 NSRect frame = [radioButton frame];
00037 frame.size.width = value;
00038 [radioButton setFrame:frame];
00039 }
00040 return 0;
00041
00042 case GWEN_DialogProperty_Height: {
00043 NSRect frame = [radioButton frame];
00044 frame.size.height = value;
00045 [radioButton setFrame:frame];
00046 }
00047 return 0;
00048
00049 case GWEN_DialogProperty_Value:{
00050 if (value==0) [radioButton setState:NSOffState];
00051 else [radioButton setState:NSOnState];
00052 }
00053 return 0;
00054
00055 default:
00056 break;
00057 }
00058
00059 DBG_WARN(GWEN_LOGDOMAIN,
00060 "Function is not appropriate for this type of widget (%s)",
00061 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00062 return GWEN_ERROR_INVALID;
00063 }
00064
00065
00066
00067
00068 static GWENHYWFAR_CB
00069 int CocoaGui_WRadioButton_GetIntProperty(GWEN_WIDGET *w,
00070 GWEN_DIALOG_PROPERTY prop,
00071 int index,
00072 int defaultValue) {
00073 NSButton *radioButton;
00074
00075 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00076 assert(radioButton);
00077
00078 switch(prop) {
00079 case GWEN_DialogProperty_Enabled:
00080 return ([radioButton isEnabled]==YES)?1:0;
00081
00082 case GWEN_DialogProperty_Focus:
00083 if ([radioButton window]) {
00084 if ([[radioButton window] firstResponder] == radioButton) return 1;
00085 }
00086 return 0;
00087
00088 case GWEN_DialogProperty_Width:
00089 return [radioButton frame].size.width;
00090
00091 case GWEN_DialogProperty_Height:
00092 return [radioButton frame].size.height;
00093
00094 case GWEN_DialogProperty_Value:
00095 return ([radioButton state]==NSOnState)?1:0;
00096
00097 default:
00098 break;
00099 }
00100
00101 DBG_WARN(GWEN_LOGDOMAIN,
00102 "Function is not appropriate for this type of widget (%s)",
00103 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00104 return defaultValue;
00105 }
00106
00107
00108
00109 static GWENHYWFAR_CB
00110 int CocoaGui_WRadioButton_SetCharProperty(GWEN_WIDGET *w,
00111 GWEN_DIALOG_PROPERTY prop,
00112 int index,
00113 const char *value,
00114 int doSignal) {
00115 NSButton *radioButton;
00116
00117 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00118 assert(radioButton);
00119
00120 switch(prop) {
00121 case GWEN_DialogProperty_Title: {
00122 NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
00123 [radioButton setTitle:stringValue];
00124 [stringValue release];
00125 }
00126 return 0;
00127 default:
00128 break;
00129 }
00130
00131 DBG_WARN(GWEN_LOGDOMAIN,
00132 "Function is not appropriate for this type of widget (%s)",
00133 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00134 return GWEN_ERROR_INVALID;
00135 }
00136
00137
00138
00139 static GWENHYWFAR_CB
00140 const char* CocoaGui_WRadioButton_GetCharProperty(GWEN_WIDGET *w,
00141 GWEN_DIALOG_PROPERTY prop,
00142 int index,
00143 const char *defaultValue) {
00144 NSButton *radioButton;
00145
00146 radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00147 assert(radioButton);
00148
00149 switch(prop) {
00150 case GWEN_DialogProperty_Title:
00151 return [[radioButton stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
00152 default:
00153 break;
00154 }
00155
00156 DBG_WARN(GWEN_LOGDOMAIN,
00157 "Function is not appropriate for this type of widget (%s)",
00158 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00159 return defaultValue;
00160 }
00161
00162
00163
00164 static void CocoaGui_WRadioButton_Toggled_handler(NSButton *button, void* data) {
00165 GWEN_WIDGET *w;
00166 int rv;
00167
00168 DBG_ERROR(0, "Toggled");
00169 w=data;
00170 assert(w);
00171 rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w),
00172 GWEN_DialogEvent_TypeActivated,
00173 GWEN_Widget_GetName(w));
00174 if (rv==GWEN_DialogEvent_ResultAccept)
00175 CocoaGui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 1);
00176 else if (rv==GWEN_DialogEvent_ResultReject)
00177 CocoaGui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 0);
00178 }
00179
00180
00181
00182 int CocoaGui_WRadioButton_Setup(GWEN_WIDGET *w) {
00183 CocoaRadioButton *radioButton;
00184 const char *s;
00185 uint32_t flags;
00186 GWEN_WIDGET *wParent;
00187
00188 GWEN_WIDGET *wT;
00189 int groupId;
00190
00191 flags=GWEN_Widget_GetFlags(w);
00192 wParent=GWEN_Widget_Tree_GetParent(w);
00193 groupId=GWEN_Widget_GetGroupId(w);
00194
00195 s=GWEN_Widget_GetText(w, 0);
00196
00197
00198 radioButton = [[[CocoaRadioButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
00199 if (flags & GWEN_WIDGET_FLAGS_FILLX) radioButton.fillX = YES;
00200 if (flags & GWEN_WIDGET_FLAGS_FILLY) radioButton.fillY = YES;
00201 if (s && *s) {
00202 NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
00203 [radioButton setTitle:title];
00204 [title release];
00205 }
00206
00207
00208 wT=wParent;
00209 while(GWEN_Widget_Tree_GetParent(wT))
00210 wT=GWEN_Widget_Tree_GetParent(wT);
00211
00212
00213 while(wT) {
00214 if ((GWEN_Widget_GetType(wT)==GWEN_Widget_TypeRadioButton) &&
00215 GWEN_Widget_GetGroupId(wT)==groupId)
00216 break;
00217 wT=GWEN_Widget_Tree_GetBelow(wT);
00218 }
00219
00220 if (wT && wT!=w) {
00221 CocoaRadioButton *sameGroupRadioButton = (CocoaRadioButton*)(GWEN_Widget_GetImplData(wT, COCOA_DIALOG_WIDGET_REAL));
00222 [radioButton setGroupManager:[sameGroupRadioButton getGroupManager]];
00223 }
00224 else {
00225 [radioButton createNewGroupManagerWithGroupID:groupId];
00226 }
00227
00228
00229
00230 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) radioButton);
00231 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) radioButton);
00232
00233 GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WRadioButton_SetIntProperty);
00234 GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WRadioButton_GetIntProperty);
00235 GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WRadioButton_SetCharProperty);
00236 GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WRadioButton_GetCharProperty);
00237
00238 gwenActionPtr ptr = CocoaGui_WRadioButton_Toggled_handler;
00239 [radioButton setC_ActionPtr:ptr Data:w];
00240
00241 if (wParent)
00242 GWEN_Widget_AddChildGuiWidget(wParent, w);
00243
00244 return 0;
00245 }
00246
00247