gwenhywfar  4.3.3
w_listbox.mm
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Aug 17 2010
3  copyright : (C) 2010 by Samuel Strupp
4 
5  ***************************************************************************
6  * Please see toplevel file COPYING for license details *
7  ***************************************************************************/
8 
9 
10 #import "CocoaScrollBox.h"
11 #import "CocoaListBox.h"
12 
13 
14 #define W_LISTBOX_MAX_TYPES 256
15 
16 
17 
18 static GWENHYWFAR_CB
21  int index,
22  int value,
23  int doSignal) {
24  CocoaListBox *listbox;
25  CocoaScrollBox *scrollView;
26 
28  assert(scrollView);
29 
30  listbox = [scrollView documentView];
31  assert(listbox);
32 
33  switch(prop) {
35  [listbox setEnabled:(value==0)?NO:YES];
36  return 0;
37 
39  if ([listbox window]) {
40  [[listbox window] makeFirstResponder:listbox];
41  }
42  }
43  return 0;
44 
46  switch(value) {
48  [listbox setAllowsEmptySelection:YES];
49  [listbox setAllowsMultipleSelection:NO];
50  [listbox deselectAll:listbox];
51  return 0;
53  [listbox setAllowsEmptySelection:NO];
54  [listbox setAllowsMultipleSelection:NO];
55  return 0;
57  [listbox setAllowsEmptySelection:NO];
58  [listbox setAllowsMultipleSelection:YES];
59  return 0;
60  }
61  DBG_ERROR(GWEN_LOGDOMAIN, "Unknown SelectionMode %d", value);
62  return GWEN_ERROR_INVALID;
63  }
64 
66 
67  if ([listbox setColumnWidthTo:value forColumn:index]) return 0;
68  return GWEN_ERROR_INVALID;
69  }
70 
72 
73  if ([listbox setSortOrderTo:(value == GWEN_DialogSortDirection_Up) ForColumnWithIndex:index]) return 0;
74  return GWEN_ERROR_INVALID;
75  }
76 
78  // NOOP, we use auto-sorting for now (TODO: figure out how to manually sort)
79  return 0;
80 
81  default:
82  break;
83  }
84 
86  "Function is not appropriate for this type of widget (%s)",
88  return GWEN_ERROR_INVALID;
89 }
90 
91 
92 
93 
94 static GWENHYWFAR_CB
97  int index,
98  int defaultValue) {
99  CocoaListBox *listbox;
100  CocoaScrollBox *scrollView;
101 
103  assert(scrollView);
104 
105  listbox = [scrollView documentView];
106  assert(listbox);
107 
108  switch(prop) {
110  return ([listbox isEnabled])?1:0;
111 
113  if ([listbox window]) {
114  if ([[listbox window] firstResponder] == listbox)
115  return 1;
116  }
117  return 0;
118 
120  return [listbox selectedRow];
121  return -1;
122  }
123 
125  return [listbox widthOfColumn:index];
126  }
127 
129 
130  NSInteger sortOrder = [listbox sortOrderForColumnAtIndex:index];
131  switch (sortOrder) {
132  case 1:
134  case 0:
136  default:
137  break;
138  }
140  }
141 
142  default:
143  break;
144  }
145 
147  "Function is not appropriate for this type of widget (%s)",
149  return defaultValue;
150 }
151 
152 
153 
154 static GWENHYWFAR_CB
157  int index,
158  const char *value,
159  int doSignal) {
160  CocoaListBox *listbox;
161  CocoaScrollBox *scrollView;
162 
164  assert(scrollView);
165 
166  listbox = [scrollView documentView];
167  assert(listbox);
168 
169  switch(prop) {
171 
172  if (value && *value) {
173  NSString *titleString = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
174  [listbox setTitelsAndCreateColumns:titleString];
175  [titleString release];
176  }
177  return 0;
178  }
179 
181  [listbox clearDataRows];
182  return 0;
183  }
184 
186 
187  if (value && *value) {
188  NSString *dataRowString = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
189  [listbox addDataRowString:dataRowString];
190  [dataRowString release];
191  }
192  return 0;
193  }
194 
195  default:
196  break;
197  }
198 
200  "Function is not appropriate for this type of widget (%s)",
202  return GWEN_ERROR_INVALID;
203 }
204 
205 
206 
207 static GWENHYWFAR_CB
210  int index,
211  const char *defaultValue) {
212  CocoaListBox *listbox;
213  CocoaScrollBox *scrollView;
214 
216  assert(scrollView);
217 
218  listbox = [scrollView documentView];
219  assert(listbox);
220 
221  switch(prop) {
223  NSString *titlesString = [listbox titlesString];
224  if (titlesString) {
225  return [titlesString cStringUsingEncoding:NSUTF8StringEncoding];
226  }
227  return defaultValue;
228  }
229 
231  NSString *dataRowString = [listbox dataRowStringForRow:index];
232  if (dataRowString) {
233  return [dataRowString cStringUsingEncoding:NSUTF8StringEncoding];
234  }
235  return defaultValue;
236  }
237 
238  default:
239  break;
240  }
241 
242 
244  "Function is not appropriate for this type of widget (%s)",
246  return defaultValue;
247 }
248 
249 
250 
251 static void CocoaGui_WListBox_Changed_handler(NSTableView *tableView, void* data) {
252  GWEN_WIDGET *w;
253  int rv;
254 
255  DBG_ERROR(0, "ListBox Changed");
256  w=data;
257  assert(w);
263  else if (rv==GWEN_DialogEvent_ResultReject)
265 }
266 
267 
268 
270  CocoaListBox *listBox;
271  uint32_t flags;
272  GWEN_WIDGET *wParent;
273  //gulong changed_handler_id;
274 
275  flags=GWEN_Widget_GetFlags(w);
276  wParent=GWEN_Widget_Tree_GetParent(w);
277 
278  CocoaScrollBox *scrollView = [[[CocoaScrollBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 100.0, 100.0)] autorelease];
279  [scrollView setHasVerticalScroller:YES];
280  [scrollView setHasHorizontalScroller:YES];
281  [scrollView setAutohidesScrollers:YES];
282  if (flags & GWEN_WIDGET_FLAGS_FILLX) scrollView.fillX = YES;
283  if (flags & GWEN_WIDGET_FLAGS_FILLY) scrollView.fillY = YES;
284 
285  listBox = [[[CocoaListBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 100.0, 100.0)] autorelease];
286  [listBox setFocusRingType:NSFocusRingTypeNone];
287  [scrollView setLayoutedDocumentView:listBox];
288 
289  GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) scrollView);
291 
296 
297 
298 #pragma mark NOCH MACHEN
299  /*changed_handler_id=g_signal_connect(g,
300  "cursor-changed",
301  G_CALLBACK (Gtk2Gui_WListBox_CursorChanged_handler),
302  w);*/
303 
305  [listBox setC_ActionPtr:ptr Data:w];
306 
307  if (wParent)
308  GWEN_Widget_AddChildGuiWidget(wParent, w);
309 
310  return 0;
311 }
312 
313