gwenhywfar  4.3.1
w_tabbook.mm
Go to the documentation of this file.
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 "CocoaTabView.h"
00011 
00012 
00013 static GWENHYWFAR_CB
00014 int CocoaGui_WTabBook_SetIntProperty(GWEN_WIDGET *w,
00015                                                                          GWEN_DIALOG_PROPERTY prop,
00016                                                                          int index,
00017                                                                          int value,
00018                                                                          int doSignal) {
00019         CocoaTabView *tabView;
00020         
00021         tabView=(CocoaTabView*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00022         assert(tabView);
00023         
00024         switch(prop) {
00025                 case GWEN_DialogProperty_Enabled:
00026                         return 0;
00027                         
00028                 case GWEN_DialogProperty_Focus:
00029                         return 0;
00030                         
00031                 case GWEN_DialogProperty_Value:
00032                         if (value >= 0 && value < [tabView numberOfTabViewItems]) {
00033                                 [tabView selectTabViewItemAtIndex:value];
00034                         }
00035                         return 0;
00036                         
00037                 default:
00038                         break;
00039         }
00040         
00041         DBG_WARN(GWEN_LOGDOMAIN,
00042                          "Function is not appropriate for this type of widget (%s)",
00043                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00044         return GWEN_ERROR_INVALID;
00045 }
00046 
00047 
00048 
00049 
00050 static GWENHYWFAR_CB
00051 int CocoaGui_WTabBook_GetIntProperty(GWEN_WIDGET *w,
00052                                                                          GWEN_DIALOG_PROPERTY prop,
00053                                                                          int index,
00054                                                                          int defaultValue) {
00055         CocoaTabView *tabView;
00056         
00057         tabView=(CocoaTabView*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00058         assert(tabView);
00059         
00060         switch(prop) {
00061                 case GWEN_DialogProperty_Enabled:
00062                         return 1;
00063                         
00064                 case GWEN_DialogProperty_Focus:
00065                         return 0;
00066                         
00067                 case GWEN_DialogProperty_Value:
00068                         return [tabView indexOfTabViewItem:[tabView selectedTabViewItem]];
00069                         
00070                 default:
00071                         break;
00072         }
00073         
00074         DBG_WARN(GWEN_LOGDOMAIN,
00075                          "Function is not appropriate for this type of widget (%s)",
00076                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00077         return defaultValue;
00078 }
00079 
00080 
00081 
00082 static GWENHYWFAR_CB
00083 int CocoaGui_WTabBook_SetCharProperty(GWEN_WIDGET *w,
00084                                                                           GWEN_DIALOG_PROPERTY prop,
00085                                                                           int index,
00086                                                                           const char *value,
00087                                                                           int doSignal) {
00088         CocoaTabView *tabView;
00089         
00090         tabView=(CocoaTabView*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00091         assert(tabView);
00092         
00093         DBG_WARN(GWEN_LOGDOMAIN,
00094                          "Function is not appropriate for this type of widget (%s)",
00095                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00096         return GWEN_ERROR_INVALID;
00097 }
00098 
00099 
00100 
00101 static GWENHYWFAR_CB
00102 const char* CocoaGui_WTabBook_GetCharProperty(GWEN_WIDGET *w,
00103                                                                                           GWEN_DIALOG_PROPERTY prop,
00104                                                                                           int index,
00105                                                                                           const char *defaultValue) {
00106         CocoaTabView *tabView;
00107         
00108         tabView=(CocoaTabView*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00109         assert(tabView);
00110         
00111         DBG_WARN(GWEN_LOGDOMAIN,
00112                          "Function is not appropriate for this type of widget (%s)",
00113                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00114         return defaultValue;
00115 }
00116 
00117 
00118 
00119 static GWENHYWFAR_CB
00120 int CocoaGui_WTabBook_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) {
00121         CocoaTabView *tabView;
00122         const char *s;
00123         
00124         
00125         tabView=(CocoaTabView*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00126         assert(tabView);
00127         
00128         NSView *subview =(NSView*)(GWEN_Widget_GetImplData(wChild, COCOA_DIALOG_WIDGET_REAL));
00129         assert(subview);
00130         
00131         s=GWEN_Widget_GetText(wChild, 0);
00132         
00133         
00134         NSTabViewItem *item = [[NSTabViewItem alloc] init];
00135 
00136         if (s && *s) {
00137                 NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
00138                 [item setLabel:title];
00139                 [title release];
00140         }
00141         
00142         [item setView:subview];
00143         
00144         [tabView addTabViewItem:item];
00145         [item release];
00146         
00147         
00148         return 0;
00149 }
00150 
00151 
00152 
00153 int CocoaGui_WTabBook_Setup(GWEN_WIDGET *w) {
00154         CocoaTabView *tabView;
00155         uint32_t flags;
00156         GWEN_WIDGET *wParent;
00157         
00158         flags=GWEN_Widget_GetFlags(w);
00159         wParent=GWEN_Widget_Tree_GetParent(w);
00160         
00161         tabView=[[[CocoaTabView alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 22.0)] autorelease];
00162         if (flags & GWEN_WIDGET_FLAGS_FILLX) tabView.fillX = YES;
00163         if (flags & GWEN_WIDGET_FLAGS_FILLY) tabView.fillY = YES;
00164                 
00165         GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) tabView);
00166         GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) tabView);
00167         
00168         GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WTabBook_SetIntProperty);
00169         GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WTabBook_GetIntProperty);
00170         GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WTabBook_SetCharProperty);
00171         GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WTabBook_GetCharProperty);
00172         GWEN_Widget_SetAddChildGuiWidgetFn(w, CocoaGui_WTabBook_AddChildGuiWidget);
00173         
00174         if (wParent)
00175                 GWEN_Widget_AddChildGuiWidget(wParent, w);
00176         
00177         return 0;
00178 }
00179 
00180