gwenhywfar 4.0.3
|
00001 /*************************************************************************** 00002 begin : Aug 17 2010 00003 copyright : (C) 2010 by Samuel Strupp 00004 00005 *************************************************************************** 00006 * Please see toplevel file COPYING for license details * 00007 ***************************************************************************/ 00008 00009 00010 #import "CocoaScrollBox.h" 00011 #import "CocoaListBox.h" 00012 00013 00014 #define W_LISTBOX_MAX_TYPES 256 00015 00016 00017 00018 static GWENHYWFAR_CB 00019 int CocoaGui_WListBox_SetIntProperty(GWEN_WIDGET *w, 00020 GWEN_DIALOG_PROPERTY prop, 00021 int index, 00022 int value, 00023 int doSignal) { 00024 CocoaListBox *listbox; 00025 CocoaScrollBox *scrollView; 00026 00027 scrollView = (CocoaScrollBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00028 assert(scrollView); 00029 00030 listbox = [scrollView documentView]; 00031 assert(listbox); 00032 00033 switch(prop) { 00034 case GWEN_DialogProperty_Enabled: 00035 [listbox setEnabled:(value==0)?NO:YES]; 00036 return 0; 00037 00038 case GWEN_DialogProperty_Focus: { 00039 if ([listbox window]) { 00040 [[listbox window] makeFirstResponder:listbox]; 00041 } 00042 } 00043 return 0; 00044 00045 case GWEN_DialogProperty_SelectionMode: { 00046 switch(value) { 00047 case GWEN_Dialog_SelectionMode_None: 00048 [listbox setAllowsEmptySelection:YES]; 00049 [listbox setAllowsMultipleSelection:NO]; 00050 [listbox deselectAll:listbox]; 00051 return 0; 00052 case GWEN_Dialog_SelectionMode_Single: 00053 [listbox setAllowsEmptySelection:NO]; 00054 [listbox setAllowsMultipleSelection:NO]; 00055 return 0; 00056 case GWEN_Dialog_SelectionMode_Multi: 00057 [listbox setAllowsEmptySelection:NO]; 00058 [listbox setAllowsMultipleSelection:YES]; 00059 return 0; 00060 } 00061 DBG_ERROR(GWEN_LOGDOMAIN, "Unknown SelectionMode %d", value); 00062 return GWEN_ERROR_INVALID; 00063 } 00064 00065 case GWEN_DialogProperty_ColumnWidth: { 00066 00067 if ([listbox setColumnWidthTo:value forColumn:index]) return 0; 00068 return GWEN_ERROR_INVALID; 00069 } 00070 00071 case GWEN_DialogProperty_SortDirection: { 00072 00073 if ([listbox setSortOrderTo:(value == GWEN_DialogSortDirection_Up) ForColumnWithIndex:index]) return 0; 00074 return GWEN_ERROR_INVALID; 00075 } 00076 00077 case GWEN_DialogProperty_Sort: 00078 // NOOP, we use auto-sorting for now (TODO: figure out how to manually sort) 00079 return 0; 00080 00081 default: 00082 break; 00083 } 00084 00085 DBG_WARN(GWEN_LOGDOMAIN, 00086 "Function is not appropriate for this type of widget (%s)", 00087 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00088 return GWEN_ERROR_INVALID; 00089 } 00090 00091 00092 00093 00094 static GWENHYWFAR_CB 00095 int CocoaGui_WListBox_GetIntProperty(GWEN_WIDGET *w, 00096 GWEN_DIALOG_PROPERTY prop, 00097 int index, 00098 int defaultValue) { 00099 CocoaListBox *listbox; 00100 CocoaScrollBox *scrollView; 00101 00102 scrollView = (CocoaScrollBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00103 assert(scrollView); 00104 00105 listbox = [scrollView documentView]; 00106 assert(listbox); 00107 00108 switch(prop) { 00109 case GWEN_DialogProperty_Enabled: 00110 return ([listbox isEnabled])?1:0; 00111 00112 case GWEN_DialogProperty_Focus: 00113 if ([listbox window]) { 00114 if ([[listbox window] firstResponder] == listbox) 00115 return 1; 00116 } 00117 return 0; 00118 00119 case GWEN_DialogProperty_Value: { 00120 return [listbox selectedRow]; 00121 return -1; 00122 } 00123 00124 case GWEN_DialogProperty_ColumnWidth: { 00125 return [listbox widthOfColumn:index]; 00126 } 00127 00128 case GWEN_DialogProperty_SortDirection: { 00129 00130 NSInteger sortOrder = [listbox sortOrderForColumnAtIndex:index]; 00131 switch (sortOrder) { 00132 case 1: 00133 return GWEN_DialogSortDirection_Up; 00134 case 0: 00135 return GWEN_DialogSortDirection_Down; 00136 default: 00137 break; 00138 } 00139 return GWEN_DialogSortDirection_None; 00140 } 00141 00142 default: 00143 break; 00144 } 00145 00146 DBG_WARN(GWEN_LOGDOMAIN, 00147 "Function is not appropriate for this type of widget (%s)", 00148 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00149 return defaultValue; 00150 } 00151 00152 00153 00154 static GWENHYWFAR_CB 00155 int CocoaGui_WListBox_SetCharProperty(GWEN_WIDGET *w, 00156 GWEN_DIALOG_PROPERTY prop, 00157 int index, 00158 const char *value, 00159 int doSignal) { 00160 CocoaListBox *listbox; 00161 CocoaScrollBox *scrollView; 00162 00163 scrollView = (CocoaScrollBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00164 assert(scrollView); 00165 00166 listbox = [scrollView documentView]; 00167 assert(listbox); 00168 00169 switch(prop) { 00170 case GWEN_DialogProperty_Title: { 00171 00172 if (value && *value) { 00173 NSString *titleString = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding]; 00174 [listbox setTitelsAndCreateColumns:titleString]; 00175 [titleString release]; 00176 } 00177 return 0; 00178 } 00179 00180 case GWEN_DialogProperty_ClearValues: { 00181 [listbox clearDataRows]; 00182 return 0; 00183 } 00184 00185 case GWEN_DialogProperty_AddValue: { 00186 00187 if (value && *value) { 00188 NSString *dataRowString = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding]; 00189 [listbox addDataRowString:dataRowString]; 00190 [dataRowString release]; 00191 } 00192 return 0; 00193 } 00194 00195 default: 00196 break; 00197 } 00198 00199 DBG_WARN(GWEN_LOGDOMAIN, 00200 "Function is not appropriate for this type of widget (%s)", 00201 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00202 return GWEN_ERROR_INVALID; 00203 } 00204 00205 00206 00207 static GWENHYWFAR_CB 00208 const char* CocoaGui_WListBox_GetCharProperty(GWEN_WIDGET *w, 00209 GWEN_DIALOG_PROPERTY prop, 00210 int index, 00211 const char *defaultValue) { 00212 CocoaListBox *listbox; 00213 CocoaScrollBox *scrollView; 00214 00215 scrollView = (CocoaScrollBox*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL)); 00216 assert(scrollView); 00217 00218 listbox = [scrollView documentView]; 00219 assert(listbox); 00220 00221 switch(prop) { 00222 case GWEN_DialogProperty_Title: { 00223 NSString *titlesString = [listbox titlesString]; 00224 if (titlesString) { 00225 return [titlesString cStringUsingEncoding:NSUTF8StringEncoding]; 00226 } 00227 return defaultValue; 00228 } 00229 00230 case GWEN_DialogProperty_Value: { 00231 NSString *dataRowString = [listbox dataRowStringForRow:index]; 00232 if (dataRowString) { 00233 return [dataRowString cStringUsingEncoding:NSUTF8StringEncoding]; 00234 } 00235 return defaultValue; 00236 } 00237 00238 default: 00239 break; 00240 } 00241 00242 00243 DBG_WARN(GWEN_LOGDOMAIN, 00244 "Function is not appropriate for this type of widget (%s)", 00245 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00246 return defaultValue; 00247 } 00248 00249 00250 00251 static void CocoaGui_WListBox_Changed_handler(NSTableView *tableView, void* data) { 00252 GWEN_WIDGET *w; 00253 int rv; 00254 00255 DBG_ERROR(0, "ListBox Changed"); 00256 w=data; 00257 assert(w); 00258 rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w), 00259 GWEN_DialogEvent_TypeActivated, 00260 GWEN_Widget_GetName(w)); 00261 if (rv==GWEN_DialogEvent_ResultAccept) 00262 CocoaGui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 1); 00263 else if (rv==GWEN_DialogEvent_ResultReject) 00264 CocoaGui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 0); 00265 } 00266 00267 00268 00269 int CocoaGui_WListBox_Setup(GWEN_WIDGET *w) { 00270 CocoaListBox *listBox; 00271 uint32_t flags; 00272 GWEN_WIDGET *wParent; 00273 //gulong changed_handler_id; 00274 00275 flags=GWEN_Widget_GetFlags(w); 00276 wParent=GWEN_Widget_Tree_GetParent(w); 00277 00278 CocoaScrollBox *scrollView = [[[CocoaScrollBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 100.0, 100.0)] autorelease]; 00279 [scrollView setHasVerticalScroller:YES]; 00280 [scrollView setHasHorizontalScroller:YES]; 00281 [scrollView setAutohidesScrollers:YES]; 00282 if (flags & GWEN_WIDGET_FLAGS_FILLX) scrollView.fillX = YES; 00283 if (flags & GWEN_WIDGET_FLAGS_FILLY) scrollView.fillY = YES; 00284 00285 listBox = [[[CocoaListBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 100.0, 100.0)] autorelease]; 00286 [listBox setFocusRingType:NSFocusRingTypeNone]; 00287 [scrollView setLayoutedDocumentView:listBox]; 00288 00289 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) scrollView); 00290 GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) scrollView); 00291 00292 GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WListBox_SetIntProperty); 00293 GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WListBox_GetIntProperty); 00294 GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WListBox_SetCharProperty); 00295 GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WListBox_GetCharProperty); 00296 00297 00298 #pragma mark NOCH MACHEN 00299 /*changed_handler_id=g_signal_connect(g, 00300 "cursor-changed", 00301 G_CALLBACK (Gtk2Gui_WListBox_CursorChanged_handler), 00302 w);*/ 00303 00304 gwenListBoxActionPtr ptr = CocoaGui_WListBox_Changed_handler; 00305 [listBox setC_ActionPtr:ptr Data:w]; 00306 00307 if (wParent) 00308 GWEN_Widget_AddChildGuiWidget(wParent, w); 00309 00310 return 0; 00311 } 00312 00313