Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #import "CocoaTextBrowser.h"
00011
00012
00013
00014 static GWENHYWFAR_CB
00015 int CocoaGui_WTextBrowser_SetIntProperty(GWEN_WIDGET *w,
00016 GWEN_DIALOG_PROPERTY prop,
00017 int index,
00018 int value,
00019 int doSignal) {
00020
00021 CocoaTextBrowser *textBrowser;
00022 textBrowser = (CocoaTextBrowser*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_CONTENT));
00023 assert(textBrowser);
00024
00025
00026 switch(prop) {
00027 case GWEN_DialogProperty_Enabled:
00028 return 0;
00029
00030 case GWEN_DialogProperty_Focus:
00031 return 0;
00032
00033 case GWEN_DialogProperty_Width: {
00034 NSRect frame = [textBrowser frame];
00035 frame.size.width = value;
00036 [textBrowser setFrame:frame];
00037 }
00038 return 0;
00039
00040 case GWEN_DialogProperty_Height: {
00041 NSRect frame = [textBrowser frame];
00042 frame.size.height = value;
00043 [textBrowser setFrame:frame];
00044 }
00045 return 0;
00046
00047
00048 default:
00049 break;
00050 }
00051
00052 DBG_WARN(GWEN_LOGDOMAIN,
00053 "Function is not appropriate for this type of widget (%s)",
00054 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00055 return GWEN_ERROR_INVALID;
00056 }
00057
00058
00059
00060
00061 static GWENHYWFAR_CB
00062 int CocoaGui_WTextBrowser_GetIntProperty(GWEN_WIDGET *w,
00063 GWEN_DIALOG_PROPERTY prop,
00064 int index,
00065 int defaultValue) {
00066 CocoaTextBrowser *textBrowser;
00067 textBrowser = (CocoaTextBrowser*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_CONTENT));
00068 assert(textBrowser);
00069
00070 switch(prop) {
00071 case GWEN_DialogProperty_Enabled:
00072 return 1;
00073
00074 case GWEN_DialogProperty_Focus:
00075 return 0;
00076
00077 case GWEN_DialogProperty_Width:
00078 return [textBrowser frame].size.width;
00079
00080 case GWEN_DialogProperty_Height:
00081 return [textBrowser frame].size.height;
00082
00083 default:
00084 break;
00085 }
00086
00087 DBG_WARN(GWEN_LOGDOMAIN,
00088 "Function is not appropriate for this type of widget (%s)",
00089 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00090 return defaultValue;
00091 }
00092
00093
00094
00095 static GWENHYWFAR_CB
00096 int CocoaGui_WTextBrowser_SetCharProperty(GWEN_WIDGET *w,
00097 GWEN_DIALOG_PROPERTY prop,
00098 int index,
00099 const char *value,
00100 int doSignal) {
00101 CocoaTextBrowser *textBrowser;
00102 textBrowser = (CocoaTextBrowser*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_CONTENT));
00103 assert(textBrowser);
00104
00105 switch(prop) {
00106 case GWEN_DialogProperty_Value: {
00107 if (value && *value) {
00108 GWEN_STRINGLIST *sl;
00109
00110
00111 sl=GWEN_Dialog_GetMediaPaths(GWEN_Widget_GetDialog(w));
00112 const char * basePath = GWEN_StringListEntry_Data(GWEN_StringList_FirstEntry(sl));
00113 NSString *basePathString = nil;
00114 if (basePath && *basePath) {
00115 basePathString = [[NSString alloc] initWithCString:basePath encoding:NSUTF8StringEncoding];
00116 }
00117
00118 NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
00119 [textBrowser setStringValue:stringValue BasePath:basePathString];
00120 [stringValue release];
00121 [basePathString release];
00122 }
00123 return 0;
00124 }
00125 default:
00126 break;
00127 }
00128
00129 DBG_WARN(GWEN_LOGDOMAIN,
00130 "Function is not appropriate for this type of widget (%s)",
00131 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00132 return GWEN_ERROR_INVALID;
00133 }
00134
00135
00136
00137 static GWENHYWFAR_CB
00138 const char* CocoaGui_WTextBrowser_GetCharProperty(GWEN_WIDGET *w,
00139 GWEN_DIALOG_PROPERTY prop,
00140 int index,
00141 const char *defaultValue) {
00142 CocoaTextBrowser *textBrowser;
00143 textBrowser = (CocoaTextBrowser*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_CONTENT));
00144 assert(textBrowser);
00145
00146 switch(prop) {
00147 case GWEN_DialogProperty_Value: {
00148 NSString* stringValue = [textBrowser stringValue];
00149 if (stringValue && [stringValue length] > 0)
00150 return [stringValue cStringUsingEncoding:NSUTF8StringEncoding];
00151 return defaultValue;
00152 }
00153
00154 default:
00155 break;
00156 }
00157
00158 DBG_WARN(GWEN_LOGDOMAIN,
00159 "Function is not appropriate for this type of widget (%s)",
00160 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00161 return defaultValue;
00162 }
00163
00164
00165
00166 int CocoaGui_WTextBrowser_Setup(GWEN_WIDGET *w) {
00167 CocoaTextBrowser *textBrowser;
00168 const char *s;
00169 uint32_t flags;
00170 GWEN_WIDGET *wParent;
00171
00172 flags=GWEN_Widget_GetFlags(w);
00173 wParent=GWEN_Widget_Tree_GetParent(w);
00174 s=GWEN_Widget_GetText(w, 0);
00175
00176
00177 textBrowser = [[[CocoaTextBrowser alloc] initWithFrame:NSMakeRect(0.0, 0.0, 30.0, 30.0) frameName:nil groupName:nil] autorelease];
00178 if (flags & GWEN_WIDGET_FLAGS_FILLX) textBrowser.fillX = YES;
00179 if (flags & GWEN_WIDGET_FLAGS_FILLY) textBrowser.fillY = YES;
00180
00181 if (s && *s) {
00182 NSString *stringValue = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
00183 [textBrowser setStringValue:stringValue];
00184 [stringValue release];
00185 }
00186
00187 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) textBrowser);
00188 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) textBrowser);
00189
00190 GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WTextBrowser_SetIntProperty);
00191 GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WTextBrowser_GetIntProperty);
00192 GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WTextBrowser_SetCharProperty);
00193 GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WTextBrowser_GetCharProperty);
00194
00195 if (wParent)
00196 GWEN_Widget_AddChildGuiWidget(wParent, w);
00197
00198 return 0;
00199 }
00200
00201