gwenhywfar  4.8.0beta
w_pushbutton.mm
Go to the documentation of this file.
1 /***************************************************************************
2  begin : August 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 "CocoaButton.h"
11 
12 
13 static GWENHYWFAR_CB
16  int index,
17  int value,
18  int doSignal) {
19 
20  CocoaButton *button;
21 
23  assert(button);
24 
25  switch(prop) {
27  [button setEnabled:(value==0)?NO:YES];
28  return 0;
29 
31  if ([button window]) {
32  [[button window] makeFirstResponder:button];
33  }
34  return 0;
35 
37  NSRect frame = [button frame];
38  frame.size.width = value;
39  [button setFrame:frame];
40  }
41  return 0;
42 
44  NSRect frame = [button frame];
45  frame.size.height = value;
46  [button setFrame:frame];
47  }
48  return 0;
49 
50  default:
51  break;
52  }
53 
55  "Function is not appropriate for this type of widget (%s)",
57  return GWEN_ERROR_INVALID;
58 }
59 
60 
61 
62 
63 static GWENHYWFAR_CB
66  int index,
67  int defaultValue) {
68  CocoaButton *button;
69 
71  assert(button);
72 
73  switch(prop) {
75  return ([button isEnabled]==YES)?1:0;
76 
78  if ([button window]) {
79  if ([[button window] firstResponder] == button) return 1;
80  }
81  return 0;
82 
84  return [button frame].size.width;
85 
87  return [button frame].size.height;
88 
89  default:
90  break;
91  }
92 
94  "Function is not appropriate for this type of widget (%s)",
96  return defaultValue;
97 }
98 
99 
100 
101 static GWENHYWFAR_CB
104  int index,
105  const char *value,
106  int doSignal) {
107 
108  CocoaButton *button;
109 
111  assert(button);
112 
113  switch(prop) {
115  NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
116  [button setTitle:stringValue];
117  [stringValue release];
118  }
119  return 0;
120  default:
121  break;
122  }
123 
125  "Function is not appropriate for this type of widget (%s)",
127  return GWEN_ERROR_INVALID;
128 }
129 
130 
131 
132 static GWENHYWFAR_CB
135  int index,
136  const char *defaultValue) {
137  CocoaButton *button;
138 
140  assert(button);
141 
142  switch(prop) {
144  return [[button stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
145  default:
146  break;
147  }
148 
150  "Function is not appropriate for this type of widget (%s)",
152  return defaultValue;
153 }
154 
155 
156 
157 static void CocoaGui_WPushButton_Clicked_handler(NSButton *button, void* data) {
158  GWEN_WIDGET *w;
159  int rv;
160 
161  DBG_ERROR(0, "Clicked");
162  w=(GWEN_WIDGET*)data;
163  assert(w);
169  else if (rv==GWEN_DialogEvent_ResultReject)
171 }
172 
173 
174 
176 
177  CocoaButton *button;
178  const char *s;
179  uint32_t flags;
180  GWEN_WIDGET *wParent;
181 
182  flags=GWEN_Widget_GetFlags(w);
183  wParent=GWEN_Widget_Tree_GetParent(w);
184  s=GWEN_Widget_GetText(w, 0);
185 
186 
187  //Create Button
188  button = [[[CocoaButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
189  if (flags & GWEN_WIDGET_FLAGS_FILLX) button.fillX = YES;
190  if (flags & GWEN_WIDGET_FLAGS_FILLY) button.fillY = YES;
191  [button setBezelStyle:NSRoundedBezelStyle];
192  if (s && *s) {
193  NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
194  [button setTitle:title];
195  [title release];
196  }
197 
199  if (s && *s) {
200  GWEN_STRINGLIST *sl;
201 
203  if (sl) {
204  int rv;
205  GWEN_BUFFER *tbuf;
206 
207  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
208  rv=GWEN_Directory_FindFileInPaths(sl, s, tbuf);
209  if (rv<0) {
210  DBG_ERROR(GWEN_LOGDOMAIN, "Image file [%s] not found (%d)", s, rv);
211  // ignore result here, instead create GtkImage with "broken mage" later
212  }
213  else {
214  NSString *pathToIconFile = [[NSString alloc] initWithCString:GWEN_Buffer_GetStart(tbuf) encoding:NSUTF8StringEncoding];
215  if (pathToIconFile) {
216  NSImage *icon = [[NSImage alloc] initWithContentsOfFile:pathToIconFile];
217  CGFloat height = 15.0;
218  NSSize imageSize = [icon size];
219  imageSize.width = round(imageSize.width/(imageSize.height/height));
220  imageSize.height = 15.0;
221  [icon setSize:imageSize];
222  [pathToIconFile release];
223  if (icon) {
224  //[button setBezelStyle:NSRegularSquareBezelStyle];
225  [button setImage:icon];
226  [button setImagePosition:NSImageLeft];
227  //[[button cell] setImageScaling:NSImageScaleProportionallyUpOrDown];
228  [icon release];
229  }
230  }
231  }
232  GWEN_Buffer_free(tbuf);
233  }
234  }
235 
238 
243 
245  [button setC_ActionPtr:ptr Data:w];
246 
247  if (wParent)
248  GWEN_Widget_AddChildGuiWidget(wParent, w);
249 
250  return 0;
251 }
252 
253