gwenhywfar 4.0.3

w_label.mm

Go to the documentation of this file.
00001 /***************************************************************************
00002  begin       : August 09 2010
00003  copyright   : (C) 2010 by Samuel Strupp
00004  
00005  ***************************************************************************
00006  *          Please see toplevel file COPYING for license details           *
00007  ***************************************************************************/
00008 
00009 
00010 #import "CocoaLabel.h"
00011 
00012 
00013 static GWENHYWFAR_CB
00014 int CocoaGui_WLabel_SetIntProperty(GWEN_WIDGET *w,
00015                                                                    GWEN_DIALOG_PROPERTY prop,
00016                                                                    int index,
00017                                                                    int value,
00018                                                                    int doSignal) {
00019         CocoaLabel *labelTextField;
00020         
00021         labelTextField=(CocoaLabel*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00022         assert(labelTextField);
00023         
00024         switch(prop) {
00025                 case GWEN_DialogProperty_Enabled:
00026                         [labelTextField setEnabled:(value==0)?NO:YES];
00027                         return 0;
00028                         
00029                 case GWEN_DialogProperty_Focus:
00030                         if ([labelTextField window]) {
00031                                 [[labelTextField window] makeFirstResponder:labelTextField];
00032                         }
00033                         return 0;
00034                         
00035                 case GWEN_DialogProperty_Width: {
00036                         NSRect frame = [labelTextField frame];
00037                         frame.size.width = value;
00038                         [labelTextField setFrame:frame];
00039                 }
00040                         return 0;
00041                         
00042                 case GWEN_DialogProperty_Height:{
00043                         NSRect frame = [labelTextField frame];
00044                         frame.size.height = value;
00045                         [labelTextField setFrame:frame];
00046                 }
00047                         return 0;
00048                         
00049                 default:
00050                         break;
00051         }
00052         
00053         DBG_WARN(GWEN_LOGDOMAIN,
00054                          "Function is not appropriate for this type of widget (%s)",
00055                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00056         return GWEN_ERROR_INVALID;
00057 }
00058 
00059 
00060 
00061 
00062 static GWENHYWFAR_CB
00063 int CocoaGui_WLabel_GetIntProperty(GWEN_WIDGET *w,
00064                                                                    GWEN_DIALOG_PROPERTY prop,
00065                                                                    int index,
00066                                                                    int defaultValue) {
00067         CocoaLabel *labelTextField;
00068         
00069         labelTextField=(CocoaLabel*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00070         assert(labelTextField);
00071         
00072         switch(prop) {
00073                 case GWEN_DialogProperty_Enabled:
00074                         return ([labelTextField isEnabled])?1:0;
00075                         
00076                 case GWEN_DialogProperty_Focus:
00077                         if ([labelTextField window]) {
00078                                 if ([[labelTextField window] firstResponder] == labelTextField) {
00079                                         return 1;
00080                                 }
00081                         }
00082                         return 0;
00083                         
00084                 case GWEN_DialogProperty_Width:
00085                         return [labelTextField frame].size.width;
00086                         
00087                 case GWEN_DialogProperty_Height:
00088                         return [labelTextField 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_WLabel_SetCharProperty(GWEN_WIDGET *w,
00104                                                                         GWEN_DIALOG_PROPERTY prop,
00105                                                                         int index,
00106                                                                         const char *value,
00107                                                                         int doSignal) {
00108         CocoaLabel *labelTextField;
00109         
00110         labelTextField=(CocoaLabel*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00111         assert(labelTextField);
00112         
00113         switch(prop) {
00114                 case GWEN_DialogProperty_Title: {
00115                         NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
00116                         [labelTextField setStringValue:stringValue];
00117                         NSLog(@"%@", stringValue);
00118                         [stringValue release];
00119                 }
00120                         return 0;
00121                 default:
00122                         break;
00123         }
00124         
00125         DBG_WARN(GWEN_LOGDOMAIN,
00126                          "Function is not appropriate for this type of widget (%s)",
00127                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00128         return GWEN_ERROR_INVALID;
00129 }
00130 
00131 
00132 
00133 static GWENHYWFAR_CB
00134 const char* CocoaGui_WLabel_GetCharProperty(GWEN_WIDGET *w,
00135                                                                                         GWEN_DIALOG_PROPERTY prop,
00136                                                                                         int index,
00137                                                                                         const char *defaultValue) {
00138         CocoaLabel *labelTextField;
00139         
00140         labelTextField=(CocoaLabel*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00141         assert(labelTextField);
00142         
00143         switch(prop) {
00144                 case GWEN_DialogProperty_Title:
00145                         return [[labelTextField stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
00146                 default:
00147                         break;
00148         }
00149         
00150         DBG_WARN(GWEN_LOGDOMAIN,
00151                          "Function is not appropriate for this type of widget (%s)",
00152                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00153         return defaultValue;
00154 }
00155 
00156 
00157 
00158 int CocoaGui_WLabel_Setup(GWEN_WIDGET *w) {
00159         
00160         CocoaLabel *labelTextField;
00161         const char *s;
00162         uint32_t flags;
00163         GWEN_WIDGET *wParent;
00164         
00165         flags=GWEN_Widget_GetFlags(w);
00166         wParent=GWEN_Widget_Tree_GetParent(w);
00167         s=GWEN_Widget_GetText(w, 0);
00168         
00169         labelTextField = [[[CocoaLabel alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 24.0)] autorelease];
00170         if (flags & GWEN_WIDGET_FLAGS_FILLX) labelTextField.fillX = YES;
00171         if (flags & GWEN_WIDGET_FLAGS_FILLY) labelTextField.fillY = YES;
00172         [labelTextField setDrawsBackground:NO];
00173         [labelTextField setBordered:NO];
00174         [labelTextField setEditable:NO];
00175         if (s && *s) {
00176                 NSString *stringValue = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
00177                 [labelTextField setStringValue:stringValue];
00178                 //NSLog(@"%@", stringValue);
00179                 [stringValue release];
00180         }
00181         
00182         
00183         GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) labelTextField);
00184         GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) labelTextField);
00185         
00186         GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WLabel_SetIntProperty);
00187         GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WLabel_GetIntProperty);
00188         GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WLabel_SetCharProperty);
00189         GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WLabel_GetCharProperty);
00190         
00191         if (wParent)
00192                 GWEN_Widget_AddChildGuiWidget(wParent, w);
00193         
00194         
00195         
00196         return 0;
00197 }
00198 
00199