gwenhywfar  4.7.0beta
w_lineedit.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 "CocoaLineTextField.h"
11 
12 
13 static GWENHYWFAR_CB
16  int index,
17  int value,
18  int doSignal) {
19  CocoaLineTextField *textField;
20 
22  assert(textField);
23 
24  switch(prop) {
26  [textField setEnabled:(value==0)?NO:YES];
27  return 0;
28 
30  if ([textField window]) {
31  [[textField window] makeFirstResponder:textField];
32  }
33  return 0;
34 
36  NSRect frame = [textField frame];
37  frame.size.width = value;
38  [textField setFrame:frame];
39  }
40  return 0;
41 
43  NSRect frame = [textField frame];
44  frame.size.height = value;
45  [textField setFrame:frame];
46  }
47  return 0;
48 
49  default:
50  break;
51  }
52 
54  "Function is not appropriate for this type of widget (%s)",
56  return GWEN_ERROR_INVALID;
57 }
58 
59 
60 
61 
62 static GWENHYWFAR_CB
65  int index,
66  int defaultValue) {
67  CocoaLineTextField *textField;
68 
70  assert(textField);
71 
72  switch(prop) {
74  return ([textField isEnabled])?1:0;
75 
76 
78  if ([textField window]) {
79  if ([[textField window] firstResponder] == textField) return 1;
80  }
81  return 0;
82 
84  return [textField frame].size.width;
85 
87  return [textField 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  CocoaLineTextField *textField;
108 
110  assert(textField);
111 
112  switch(prop) {
114  NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
115  [textField setStringValue:stringValue];
116  [stringValue release];
117  }
118  default:
119  break;
120  }
121 
123  "Function is not appropriate for this type of widget (%s)",
125  return GWEN_ERROR_INVALID;
126 }
127 
128 
129 
130 static GWENHYWFAR_CB
133  int index,
134  const char *defaultValue) {
135  CocoaLineTextField *textField;
136 
138  assert(textField);
139 
140  switch(prop) {
142  return [[textField stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
143  default:
144  break;
145  }
146 
148  "Function is not appropriate for this type of widget (%s)",
150  return defaultValue;
151 }
152 
153 
154 
155 static void CocoaGui_WLineEdit_End_Editing_text_handler(NSTextField *textField, void* data) {
156  GWEN_WIDGET *w;
157  int rv;
158 
159  //NSLog(@"CocoaGui_WLineEdit_End_Editing_text_handler");
160 
161  w=data;
162  assert(w);
168  else if (rv==GWEN_DialogEvent_ResultReject)
170 }
171 
172 
173 
174 static void CocoaGui_WLineEdit_Changed_text_handler(NSTextField *textField, void* data) {
175  GWEN_WIDGET *w;
176  int rv;
177 
178  //NSLog(@"CocoaGui_WLineEdit_Changed_text_handler");
179 
180  w=data;
181  assert(w);
187  else if (rv==GWEN_DialogEvent_ResultReject)
189 }
190 
191 
192 
194  CocoaLineTextField *textField;
195  const char *s;
196  uint32_t flags;
197  GWEN_WIDGET *wParent;
198 
199  //gulong deleted_text_handler_id;
200  //gulong inserted_text_handler_id;
201 
202  flags=GWEN_Widget_GetFlags(w);
203  wParent=GWEN_Widget_Tree_GetParent(w);
204  s=GWEN_Widget_GetText(w, 0);
205 
206  /* create widget */
207  textField = [[[CocoaLineTextField alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 22.0)] autorelease];
208  if (flags & GWEN_WIDGET_FLAGS_FILLX) textField.fillX = YES;
209  if (flags & GWEN_WIDGET_FLAGS_FILLY) textField.fillY = YES;
210  if (flags & GWEN_WIDGET_FLAGS_PASSWORD) {
211  [textField setCell:[[[NSSecureTextFieldCell alloc] init] autorelease]];
212  [textField setDrawsBackground:YES];
213  [textField setBezeled:YES];
214  }
215  //[labelTextField setDrawsBackground:NO];
216  [[textField cell] setLineBreakMode:NSLineBreakByClipping];
217  //[[textField cell] setWraps:NO];
218  //[textField setBordered:YES];
219  [textField setEditable:YES];
220 
221 
222 
223  if (s && *s) {
224  NSString *stringValue = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
225  [textField setStringValue:stringValue];
226  [stringValue release];
227  }
228 
229  GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) textField);
231 
236 
238  [textField setC_ActionPtr:ptr Data:w];
239 
241  [textField setC_TextChanged_ActionPtr:changed_ptr Data:w];
242 
243 
244  if (wParent)
245  GWEN_Widget_AddChildGuiWidget(wParent, w);
246 
247  return 0;
248 }
249 
250