gwenhywfar  4.6.0beta
w_checkbox.mm
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Aug 10 2010
3  copyright : (C) 2010 by Samuel Strupp
4 
5  ***************************************************************************
6  * Please see toplevel file COPYING for license details *
7  ***************************************************************************/
8 
9 
10 #import "CocoaCheckboxButton.h"
11 
12 
13 static GWENHYWFAR_CB
16  int index,
17  int value,
18  int doSignal) {
19  CocoaCheckboxButton *checkbox;
20 
22  assert(checkbox);
23 
24  switch(prop) {
26  [checkbox setEnabled:(value==0)?NO:YES];
27  return 0;
28 
30  if ([checkbox window]) {
31  [[checkbox window] makeFirstResponder:checkbox];
32  }
33  return 0;
34 
36  NSRect frame = [checkbox frame];
37  frame.size.width = value;
38  [checkbox setFrame:frame];
39  }
40  return 0;
41 
43  NSRect frame = [checkbox frame];
44  frame.size.height = value;
45  [checkbox setFrame:frame];
46  }
47  return 0;
48 
50  if (value==0) [checkbox setState:NSOffState];
51  else [checkbox setState:NSOnState];
52  }
53  return 0;
54 
55  default:
56  break;
57  }
58 
60  "Function is not appropriate for this type of widget (%s)",
62  return GWEN_ERROR_INVALID;
63 }
64 
65 
66 
67 
68 static GWENHYWFAR_CB
71  int index,
72  int defaultValue) {
73  CocoaCheckboxButton *checkbox;
74 
76  assert(checkbox);
77 
78  switch(prop) {
80  return ([checkbox isEnabled]==YES)?1:0;
81 
83  if ([checkbox window]) {
84  if ([[checkbox window] firstResponder] == checkbox) return 1;
85  }
86  return 0;
87 
89  return [checkbox frame].size.width;
90 
92  return [checkbox frame].size.height;
93 
95  return ([checkbox state]==NSOnState)?1:0;
96 
97  default:
98  break;
99  }
100 
102  "Function is not appropriate for this type of widget (%s)",
104  return defaultValue;
105 }
106 
107 
108 
109 static GWENHYWFAR_CB
112  int index,
113  const char *value,
114  int doSignal) {
115  CocoaCheckboxButton *checkbox;
116 
118  assert(checkbox);
119 
120  switch(prop) {
122  NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
123  [checkbox setTitle:stringValue];
124  [stringValue release];
125  }
126  return 0;
127  default:
128  break;
129  }
130 
132  "Function is not appropriate for this type of widget (%s)",
134  return GWEN_ERROR_INVALID;
135 }
136 
137 
138 
139 static GWENHYWFAR_CB
142  int index,
143  const char *defaultValue) {
144  CocoaCheckboxButton *checkbox;
145 
147  assert(checkbox);
148 
149  switch(prop) {
151  return [[checkbox stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
152  default:
153  break;
154  }
155 
157  "Function is not appropriate for this type of widget (%s)",
159  return defaultValue;
160 }
161 
162 
163 
164 static void CocoaGui_WCheckBox_Toggled_handler(NSButton *button, void* data) {
165  GWEN_WIDGET *w;
166  int rv;
167 
168  DBG_ERROR(0, "Toggled");
169  w=(GWEN_WIDGET*)data;
170  assert(w);
176  else if (rv==GWEN_DialogEvent_ResultReject)
178 }
179 
180 
181 
183  CocoaCheckboxButton *checkbox;
184  const char *s;
185  uint32_t flags;
186  GWEN_WIDGET *wParent;
187 
188  flags=GWEN_Widget_GetFlags(w);
189  wParent=GWEN_Widget_Tree_GetParent(w);
190  s=GWEN_Widget_GetText(w, 0);
191 
192  //Create Button
193  checkbox = [[[CocoaCheckboxButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
194  if (flags & GWEN_WIDGET_FLAGS_FILLX) checkbox.fillX = YES;
195  if (flags & GWEN_WIDGET_FLAGS_FILLY) checkbox.fillY = YES;
196  if (s && *s) {
197  NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
198  [checkbox setTitle:title];
199  [title release];
200  }
201 
204 
209 
211  [checkbox setC_ActionPtr:ptr Data:w];
212 
213  if (wParent)
214  GWEN_Widget_AddChildGuiWidget(wParent, w);
215 
216  return 0;
217 }
218 
219