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