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