gwenhywfar
4.3.3
|
00001 /*************************************************************************** 00002 begin : August 16 2010 00003 copyright : (C) 2010 by Samuel Strupp 00004 00005 *************************************************************************** 00006 * Please see toplevel file COPYING for license details * 00007 ***************************************************************************/ 00008 00009 00010 #import "CocoaWindowContentView.h" 00011 #import "CocoaGroupBox.h" 00012 00013 00014 static GWENHYWFAR_CB 00015 int CocoaGui_WGroupBox_SetIntProperty(GWEN_WIDGET *w, 00016 GWEN_DIALOG_PROPERTY prop, 00017 int index, 00018 int value, 00019 int doSignal) { 00020 CocoaGroupBox *box; 00021 00022 box = (CocoaGroupBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00023 assert(box); 00024 00025 switch(prop) { 00026 case GWEN_DialogProperty_Enabled: 00027 return 0; 00028 00029 case GWEN_DialogProperty_Focus: 00030 return 0; 00031 00032 case GWEN_DialogProperty_Width: { 00033 NSRect frame = [box frame]; 00034 frame.size.width = value; 00035 [box setFrame:frame]; 00036 } 00037 return 0; 00038 00039 case GWEN_DialogProperty_Height: { 00040 NSRect frame = [box frame]; 00041 frame.size.height = value; 00042 [box setFrame:frame]; 00043 } 00044 return 0; 00045 00046 default: 00047 break; 00048 } 00049 00050 DBG_WARN(GWEN_LOGDOMAIN, 00051 "Function is not appropriate for this type of widget (%s)", 00052 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00053 return GWEN_ERROR_INVALID; 00054 } 00055 00056 00057 00058 00059 static GWENHYWFAR_CB 00060 int CocoaGui_WGroupBox_GetIntProperty(GWEN_WIDGET *w, 00061 GWEN_DIALOG_PROPERTY prop, 00062 int index, 00063 int defaultValue) { 00064 CocoaGroupBox *box; 00065 00066 box = (CocoaGroupBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00067 assert(box); 00068 00069 switch(prop) { 00070 case GWEN_DialogProperty_Enabled: 00071 //return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0; 00072 return 1; 00073 00074 case GWEN_DialogProperty_Focus: 00075 //return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0; 00076 return 0; 00077 00078 case GWEN_DialogProperty_Width: 00079 return [box frame].size.width; 00080 00081 case GWEN_DialogProperty_Height: 00082 return [box frame].size.height; 00083 00084 default: 00085 break; 00086 } 00087 00088 DBG_WARN(GWEN_LOGDOMAIN, 00089 "Function is not appropriate for this type of widget (%s)", 00090 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00091 return defaultValue; 00092 } 00093 00094 00095 00096 static GWENHYWFAR_CB 00097 int CocoaGui_WGroupBox_SetCharProperty(GWEN_WIDGET *w, 00098 GWEN_DIALOG_PROPERTY prop, 00099 int index, 00100 const char *value, 00101 int doSignal) { 00102 CocoaGroupBox *box; 00103 00104 box = (CocoaGroupBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00105 assert(box); 00106 00107 switch(prop) { 00108 case GWEN_DialogProperty_Title: { 00109 NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding]; 00110 [box setTitle:stringValue]; 00111 [stringValue release]; 00112 } 00113 return 0; 00114 default: 00115 break; 00116 } 00117 00118 DBG_WARN(GWEN_LOGDOMAIN, 00119 "Function is not appropriate for this type of widget (%s)", 00120 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00121 return GWEN_ERROR_INVALID; 00122 } 00123 00124 00125 00126 static GWENHYWFAR_CB 00127 const char* CocoaGui_WGroupBox_GetCharProperty(GWEN_WIDGET *w, 00128 GWEN_DIALOG_PROPERTY prop, 00129 int index, 00130 const char *defaultValue) { 00131 CocoaGroupBox *box; 00132 00133 box = (CocoaGroupBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00134 assert(box); 00135 00136 switch(prop) { 00137 case GWEN_DialogProperty_Title: 00138 return [[box title] cStringUsingEncoding:NSUTF8StringEncoding]; 00139 default: 00140 break; 00141 } 00142 00143 DBG_WARN(GWEN_LOGDOMAIN, 00144 "Function is not appropriate for this type of widget (%s)", 00145 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00146 return defaultValue; 00147 } 00148 00149 00150 00151 static GWENHYWFAR_CB 00152 int CocoaGui_WGroupBox_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) { 00153 CocoaGroupBox *box; 00154 //GtkWidget *gChild; 00155 //uint32_t cflags; 00156 00157 box = (CocoaGroupBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00158 assert(box); 00159 00160 NSView *subview = (NSView*)(GWEN_Widget_GetImplData(wChild, COCOA_DIALOG_WIDGET_REAL)); 00161 assert(subview); 00162 00163 [(CocoaWindowContentView*)[box contentView] addLayoutSubview:subview]; 00164 00165 //cflags=GWEN_Widget_GetFlags(wChild); 00166 00167 /*gtk_box_pack_start(GTK_BOX(g), gChild, 00168 (cflags & GWEN_WIDGET_FLAGS_FILLY)?TRUE:FALSE, 00169 (cflags & GWEN_WIDGET_FLAGS_FILLY)?TRUE:FALSE, 00170 0);*/ 00171 00172 return 0; 00173 } 00174 00175 00176 00177 int CocoaGui_WGroupBox_Setup(GWEN_WIDGET *w) { 00178 CocoaGroupBox *box; 00179 const char *s; 00180 uint32_t flags; 00181 GWEN_WIDGET *wParent; 00182 00183 flags=GWEN_Widget_GetFlags(w); 00184 wParent=GWEN_Widget_Tree_GetParent(w); 00185 s=GWEN_Widget_GetText(w, 0); 00186 00187 00188 box = [[[CocoaGroupBox alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 22.0)] autorelease]; 00189 if (flags & GWEN_WIDGET_FLAGS_FILLX) box.fillX = YES; 00190 if (flags & GWEN_WIDGET_FLAGS_FILLY) box.fillY = YES; 00191 00192 CocoaWindowContentView *newContentView = [[CocoaWindowContentView alloc] initWithFrame:[[box contentView] frame]]; 00193 [newContentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; 00194 [box setContentView:newContentView]; 00195 [newContentView release]; 00196 00197 if (s && *s) { 00198 NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding]; 00199 [box setTitle:title]; 00200 [title release]; 00201 } 00202 00203 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) box); 00204 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) box); 00205 00206 GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WGroupBox_SetIntProperty); 00207 GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WGroupBox_GetIntProperty); 00208 GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WGroupBox_SetCharProperty); 00209 GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WGroupBox_GetCharProperty); 00210 GWEN_Widget_SetAddChildGuiWidgetFn(w, CocoaGui_WGroupBox_AddChildGuiWidget); 00211 00212 if (wParent) 00213 GWEN_Widget_AddChildGuiWidget(wParent, w); 00214 00215 return 0; 00216 } 00217 00218