00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "CocoaPopUpButton.h"
00010 #import "CocoaComboBox.h"
00011
00012
00013
00014 static GWENHYWFAR_CB
00015 int CocoaGui_WComboBox_SetIntProperty(GWEN_WIDGET *w,
00016 GWEN_DIALOG_PROPERTY prop,
00017 int index,
00018 int value,
00019 int doSignal) {
00020 CocoaComboBox *comboBox = nil;
00021 CocoaPopUpButton *popUp = nil;
00022
00023 NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00024 assert(control);
00025
00026 if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
00027 else popUp = (CocoaPopUpButton*)control;
00028
00029 switch(prop) {
00030 case GWEN_DialogProperty_Enabled:
00031 [control setEnabled:(value!=0)];
00032 return 0;
00033
00034 case GWEN_DialogProperty_Focus:
00035 [[control window] makeFirstResponder:control];
00036 return 0;
00037
00038 case GWEN_DialogProperty_Value:
00039 if (comboBox) {
00040 [comboBox selectItemAtIndex:value];
00041 }
00042 else if (popUp) {
00043 [popUp selectItemAtIndex:value];
00044 }
00045
00046 return 0;
00047
00048 case GWEN_DialogProperty_ClearValues: {
00049 if (comboBox) [comboBox removeAllItems];
00050 else if (popUp) [popUp removeAllItems];
00051 return 0;
00052 }
00053
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_WComboBox_GetIntProperty(GWEN_WIDGET *w,
00070 GWEN_DIALOG_PROPERTY prop,
00071 int index,
00072 int defaultValue) {
00073 CocoaComboBox *comboBox = nil;
00074 CocoaPopUpButton *popUp = nil;
00075
00076 NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00077 assert(control);
00078
00079 if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
00080 else popUp = (CocoaPopUpButton*)control;
00081
00082 switch(prop) {
00083 case GWEN_DialogProperty_Enabled:
00084 return ([control isEnabled])?1:0;
00085
00086 case GWEN_DialogProperty_Focus:
00087 if ([control window]) {
00088 if ([[control window] firstResponder] == control) return 1;
00089 }
00090 return 0;
00091
00092 case GWEN_DialogProperty_Value: {
00093 if (comboBox) {
00094 return [comboBox indexOfSelectedItem];
00095 }
00096 else if (popUp) {
00097 return [popUp indexOfSelectedItem];
00098 }
00099 return defaultValue;
00100 }
00101
00102 case GWEN_DialogProperty_ValueCount: {
00103 int i = -1;
00104 if (comboBox) {
00105 i = [comboBox numberOfItems];
00106 }
00107 else if (popUp) {
00108 i = [popUp numberOfItems];
00109 }
00110
00111 DBG_ERROR(0, "Number: %d", i);
00112 return i;
00113 }
00114
00115 default:
00116 break;
00117 }
00118
00119 DBG_WARN(GWEN_LOGDOMAIN,
00120 "Function is not appropriate for this type of widget (%s)",
00121 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00122 return defaultValue;
00123 }
00124
00125
00126
00127 static GWENHYWFAR_CB
00128 int CocoaGui_WComboBox_SetCharProperty(GWEN_WIDGET *w,
00129 GWEN_DIALOG_PROPERTY prop,
00130 int index,
00131 const char *value,
00132 int doSignal) {
00133 CocoaComboBox *comboBox = nil;
00134 CocoaPopUpButton *popUp = nil;
00135
00136 NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00137 assert(control);
00138
00139 if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
00140 else popUp = (CocoaPopUpButton*)control;
00141
00142 switch(prop) {
00143 case GWEN_DialogProperty_Value: {
00144 return GWEN_ERROR_NOT_FOUND;
00145 }
00146
00147 case GWEN_DialogProperty_AddValue: {
00148
00149 NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
00150 if (popUp && stringValue) {
00151 [popUp addItemWithTitle:stringValue];
00152 }
00153 else if (comboBox && stringValue) {
00154 [comboBox addItemWithObjectValue:stringValue];
00155 }
00156
00157 [stringValue release];
00158 return 0;
00159 }
00160
00161 case GWEN_DialogProperty_ClearValues: {
00162 if (comboBox) [comboBox removeAllItems];
00163 else if (popUp) [popUp removeAllItems];
00164 return 0;
00165 }
00166
00167 default:
00168 break;
00169 }
00170
00171 DBG_WARN(GWEN_LOGDOMAIN,
00172 "Function is not appropriate for this type of widget (%s)",
00173 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00174 return GWEN_ERROR_INVALID;
00175 }
00176
00177
00178
00179 static GWENHYWFAR_CB
00180 const char* CocoaGui_WComboBox_GetCharProperty(GWEN_WIDGET *w,
00181 GWEN_DIALOG_PROPERTY prop,
00182 int index,
00183 const char *defaultValue) {
00184 CocoaComboBox *comboBox = nil;
00185 CocoaPopUpButton *popUp = nil;
00186
00187 NSControl *control = (NSControl*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00188 assert(control);
00189
00190 if ([control isKindOfClass:[CocoaComboBox class]]) comboBox = (CocoaComboBox*)control;
00191 else popUp = (CocoaPopUpButton*)control;
00192
00193 switch(prop) {
00194 case GWEN_DialogProperty_Value: {
00195 NSString *value = nil;
00196
00197 if (popUp) {
00198 value = [popUp titleOfSelectedItem];
00199 }
00200 else if (comboBox && [[comboBox itemObjectValueAtIndex:index] isKindOfClass:[NSString class]]) {
00201 value = [comboBox itemObjectValueAtIndex:index];
00202 }
00203
00204 if (value) return [value cStringUsingEncoding:NSUTF8StringEncoding];
00205 return NULL;
00206 }
00207
00208 default:
00209 break;
00210 }
00211
00212 DBG_WARN(GWEN_LOGDOMAIN,
00213 "Function is not appropriate for this type of widget (%s)",
00214 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00215 return defaultValue;
00216 }
00217
00218
00219
00220 static void CocoaGui_WComboBox_Changed_handler(NSControl *comboBoxOrPopUp, void* data) {
00221 GWEN_WIDGET *w;
00222 int rv;
00223
00224 DBG_ERROR(0, "Changed");
00225 w=(GWEN_WIDGET*)data;
00226 assert(w);
00227 rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w),
00228 GWEN_DialogEvent_TypeActivated,
00229 GWEN_Widget_GetName(w));
00230 if (rv==GWEN_DialogEvent_ResultAccept)
00231 CocoaGui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 1);
00232 else if (rv==GWEN_DialogEvent_ResultReject)
00233 CocoaGui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 0);
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 int CocoaGui_WComboBox_Setup(GWEN_WIDGET *w) {
00255
00256
00257
00258 uint32_t flags;
00259 GWEN_WIDGET *wParent;
00260
00261
00262 flags=GWEN_Widget_GetFlags(w);
00263 wParent=GWEN_Widget_Tree_GetParent(w);
00264
00265
00266 if (flags & GWEN_WIDGET_FLAGS_READONLY) {
00267
00268 CocoaPopUpButton *popUp = [[[CocoaPopUpButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0) pullsDown:NO] autorelease];
00269 if (flags & GWEN_WIDGET_FLAGS_FILLX) popUp.fillX = YES;
00270 if (flags & GWEN_WIDGET_FLAGS_FILLY) popUp.fillY = YES;
00271
00272 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) popUp);
00273 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) popUp);
00274
00275 gwenPopUpActionPtr ptr = CocoaGui_WComboBox_Changed_handler;
00276 [popUp setC_PopUpActionPtr:ptr Data:w];
00277 }
00278 else {
00279
00280 CocoaComboBox *comboBox = [[[CocoaComboBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
00281 if (flags & GWEN_WIDGET_FLAGS_FILLX) comboBox.fillX = YES;
00282 if (flags & GWEN_WIDGET_FLAGS_FILLY) comboBox.fillY = YES;
00283
00284 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) comboBox);
00285 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) comboBox);
00286
00287 gwenComboBoxActionPtr ptr = CocoaGui_WComboBox_Changed_handler;
00288 [comboBox setC_ComboBoxActionPtr:ptr Data:w];
00289 }
00290
00291 GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WComboBox_SetIntProperty);
00292 GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WComboBox_GetIntProperty);
00293 GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WComboBox_SetCharProperty);
00294 GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WComboBox_GetCharProperty);
00295
00296 #pragma mark NOCH MACHEN Action setzen
00297
00298
00299
00300
00301
00302
00303 if (wParent)
00304 GWEN_Widget_AddChildGuiWidget(wParent, w);
00305
00306 return 0;
00307 }
00308
00309