gwenhywfar  4.3.3
w_dialog.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 "CocoaWindow.h"
00011 
00012 #import "CocoaWindowContentView.h"
00013 
00014 
00015 static GWENHYWFAR_CB
00016 int CocoaGui_WDialog_SetIntProperty(GWEN_WIDGET *w,
00017                                                                         GWEN_DIALOG_PROPERTY prop,
00018                                                                         int index,
00019                                                                         int value,
00020                                                                         int doSignal) {
00021         NSWindow *window = nil;
00022         
00023         window=(NSWindow*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00024         assert(window);
00025         
00026         if (window) {
00027                 switch(prop) {
00028                         case GWEN_DialogProperty_Enabled:
00029                                 // just ignore
00030                                 return 0;
00031                                 
00032                         case GWEN_DialogProperty_Focus:
00033                                 //[window makeKeyAndOrderFront:nil];
00034                                 return 0;
00035                                 
00036                         case GWEN_DialogProperty_Width: {
00037                                 NSLog(@"setWidth %i", value);
00038                                 NSRect frame = [window frame];
00039                                 frame.size.width = value;
00040                                 [window setFrame:frame display:YES];
00041                         }
00042                                 return 0;
00043                                 
00044                         case GWEN_DialogProperty_Height: {
00045                                 NSRect frame = [window frame];
00046                                 frame.size.height = value;
00047                                 [window setFrame:frame display:YES];
00048                         }
00049                                 return 0;
00050                                 
00051                         default:
00052                                 break;
00053                 }
00054         }
00055         
00056         DBG_WARN(GWEN_LOGDOMAIN,
00057                          "Function is not appropriate for this type of widget (%s)",
00058                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00059         return GWEN_ERROR_INVALID;
00060 }
00061 
00062 
00063 
00064 
00065 static GWENHYWFAR_CB
00066 int CocoaGui_WDialog_GetIntProperty(GWEN_WIDGET *w,
00067                                                                         GWEN_DIALOG_PROPERTY prop,
00068                                                                         int index,
00069                                                                         int defaultValue) {
00070         NSWindow *window = nil;
00071         
00072         window=(NSWindow*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00073         assert(window);
00074         
00075         switch(prop) {
00076                 case GWEN_DialogProperty_Enabled:
00077                         return 1;
00078                         
00079                 case GWEN_DialogProperty_Focus:
00080                         return [window isKeyWindow];
00081                         
00082                 case GWEN_DialogProperty_Width:
00083                         return [window frame].size.width;
00084                         
00085                 case GWEN_DialogProperty_Height:
00086                         return [window frame].size.height;
00087                         
00088                 default:
00089                         break;
00090         }
00091         
00092         DBG_WARN(GWEN_LOGDOMAIN,
00093                          "Function is not appropriate for this type of widget (%s)",
00094                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00095         return defaultValue;
00096 }
00097 
00098 
00099 
00100 static GWENHYWFAR_CB
00101 int CocoaGui_WDialog_SetCharProperty(GWEN_WIDGET *w,
00102                                                                          GWEN_DIALOG_PROPERTY prop,
00103                                                                          int index,
00104                                                                          const char *value,
00105                                                                          int doSignal) {
00106         NSWindow *window = nil;
00107         
00108         NSLog(@"CocoaGui_WDialog_SetCharProperty");
00109         
00110         window=(NSWindow*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00111         assert(window);
00112         
00113         switch(prop) {
00114                 case GWEN_DialogProperty_Title: {
00115                         NSString *newTitle = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
00116                         [window setTitle:newTitle];
00117                         [newTitle release];
00118                 }
00119                         return 0;
00120                 default:
00121                         break;
00122         }
00123         
00124         DBG_WARN(GWEN_LOGDOMAIN,
00125                          "Function is not appropriate for this type of widget (%s)",
00126                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00127         return GWEN_ERROR_INVALID;
00128 }
00129 
00130 
00131 
00132 static GWENHYWFAR_CB
00133 const char* CocoaGui_WDialog_GetCharProperty(GWEN_WIDGET *w,
00134                                                                                          GWEN_DIALOG_PROPERTY prop,
00135                                                                                          int index,
00136                                                                                          const char *defaultValue) {
00137         NSWindow *window = nil;
00138         
00139         window=(NSWindow*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00140         assert(window);
00141         
00142         switch(prop) {
00143                 case GWEN_DialogProperty_Title:
00144                         return [[window title] cStringUsingEncoding:NSUTF8StringEncoding];
00145                 default:
00146                         break;
00147         }
00148         
00149         DBG_WARN(GWEN_LOGDOMAIN,
00150                          "Function is not appropriate for this type of widget (%s)",
00151                          GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00152         return defaultValue;
00153 }
00154 
00155 
00156 
00157 static GWENHYWFAR_CB
00158 int CocoaGui_WDialog_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) {
00159         
00160         NSLog(@"CocoaGui_WDialog_AddChildGuiWidget");
00161         
00162         NSWindow *window = nil;
00163         window=(NSWindow*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
00164         assert(window);
00165         
00166         NSView *subview = (NSView*)(GWEN_Widget_GetImplData(wChild, COCOA_DIALOG_WIDGET_REAL));
00167         assert(subview);
00168         
00169         NSRect bounds = [[window contentView] bounds];
00170         [subview setFrame:bounds];
00171         [subview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
00172         
00173         CocoaWindowContentView *contentView = (CocoaWindowContentView*)[window contentView];
00174         [contentView addLayoutSubview:subview];
00175         
00176         return 0;
00177 }
00178 
00179 
00180 
00181 int CocoaGui_WDialog_Setup(GWEN_WIDGET *w) {
00182         CocoaWindow *newWindow;
00183         const char *s;
00184         uint32_t flags;
00185         
00186         flags=GWEN_Widget_GetFlags(w);
00187         s=GWEN_Widget_GetText(w, 0);
00188         
00189         newWindow=/*|NSClosableWindowMask*/[[CocoaWindow alloc] initWithContentRect:NSMakeRect(50.0, 50.0, 400.0, 200.0) styleMask:NSTitledWindowMask|NSResizableWindowMask backing:NSBackingStoreBuffered defer:YES];
00190         [newWindow setReleasedWhenClosed:NO];
00191         
00192         CocoaWindowContentView *newContentView = [[CocoaWindowContentView alloc] initWithFrame:[[newWindow contentView] frame]];
00193         [newContentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
00194         [newWindow setContentView:newContentView];
00195         [newContentView release];
00196         
00197         NSLog(@"getWindow Title");
00198         if (s && *s) {
00199                 //DBG_WARN(GWEN_LOGDOMAIN, "String s = (%s)",s );
00200                 NSString *stringValue = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
00201                 NSLog(@"Window Title = %@", stringValue);
00202                 [newWindow setTitle:stringValue];
00203                 [stringValue release];
00204         }
00205         
00206         GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) newWindow);
00207         GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) newWindow);
00208         
00209         GWEN_Widget_SetSetIntPropertyFn(w, CocoaGui_WDialog_SetIntProperty);
00210         GWEN_Widget_SetGetIntPropertyFn(w, CocoaGui_WDialog_GetIntProperty);
00211         GWEN_Widget_SetSetCharPropertyFn(w, CocoaGui_WDialog_SetCharProperty);
00212         GWEN_Widget_SetGetCharPropertyFn(w, CocoaGui_WDialog_GetCharProperty);
00213         GWEN_Widget_SetAddChildGuiWidgetFn(w, CocoaGui_WDialog_AddChildGuiWidget);
00214         
00215         return 0;
00216 }
00217 
00218