gwenhywfar 5.14.1
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
18static 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
94static 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
154static 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
207static 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
251static 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);
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
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)
309
310 return 0;
311}
312
313
void(* gwenListBoxActionPtr)(NSTableView *listbox, void *data)
#define COCOA_DIALOG_WIDGET_REAL
void CocoaGui_Dialog_Leave(GWEN_DIALOG *dlg, int result)
#define COCOA_DIALOG_WIDGET_CONTENT
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
#define DBG_WARN(dbg_logger, format,...)
Definition debug.h:125
int GWEN_Dialog_EmitSignal(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition dialog.c:321
#define GWEN_WIDGET_FLAGS_FILLY
Definition dialog.h:62
@ GWEN_DialogSortDirection_None
Definition dialog.h:297
@ GWEN_DialogSortDirection_Up
Definition dialog.h:298
@ GWEN_DialogSortDirection_Down
Definition dialog.h:299
#define GWEN_WIDGET_FLAGS_FILLX
Definition dialog.h:61
GWEN_DIALOG_PROPERTY
Definition dialog.h:260
@ GWEN_DialogProperty_AddValue
Definition dialog.h:268
@ GWEN_DialogProperty_ColumnWidth
Definition dialog.h:271
@ GWEN_DialogProperty_Title
Definition dialog.h:263
@ GWEN_DialogProperty_Sort
Definition dialog.h:279
@ GWEN_DialogProperty_ClearValues
Definition dialog.h:269
@ GWEN_DialogProperty_SelectionMode
Definition dialog.h:274
@ GWEN_DialogProperty_SortDirection
Definition dialog.h:278
@ GWEN_DialogProperty_Enabled
Definition dialog.h:267
@ GWEN_DialogProperty_Value
Definition dialog.h:264
@ GWEN_DialogProperty_Focus
Definition dialog.h:276
@ GWEN_DialogEvent_TypeActivated
Definition dialog.h:102
@ GWEN_DialogEvent_ResultAccept
Definition dialog.h:122
@ GWEN_DialogEvent_ResultReject
Definition dialog.h:123
@ GWEN_Dialog_SelectionMode_None
Definition dialog.h:290
@ GWEN_Dialog_SelectionMode_Multi
Definition dialog.h:292
@ GWEN_Dialog_SelectionMode_Single
Definition dialog.h:291
#define GWEN_ERROR_INVALID
Definition error.h:67
#define GWENHYWFAR_CB
#define GWEN_LOGDOMAIN
Definition logger.h:32
static GWENHYWFAR_CB int CocoaGui_WListBox_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition w_listbox.mm:19
int CocoaGui_WListBox_Setup(GWEN_WIDGET *w)
Definition w_listbox.mm:269
static GWENHYWFAR_CB const char * CocoaGui_WListBox_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
Definition w_listbox.mm:208
static GWENHYWFAR_CB int CocoaGui_WListBox_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Definition w_listbox.mm:95
static void CocoaGui_WListBox_Changed_handler(NSTableView *tableView, void *data)
Definition w_listbox.mm:251
static GWENHYWFAR_CB int CocoaGui_WListBox_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition w_listbox.mm:155
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition widget.c:740
GWEN_DIALOG * GWEN_Widget_GetTopDialog(const GWEN_WIDGET *w)
Definition widget.c:102
const char * GWEN_Widget_GetName(const GWEN_WIDGET *w)
Definition widget.c:320
GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)
Definition widget.c:710
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition widget.c:836
void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
Definition widget.c:136
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition widget.c:122
GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
Definition widget.c:695
uint32_t GWEN_Widget_GetFlags(const GWEN_WIDGET *w)
Definition widget.c:149
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition widget.c:456
GWEN_DIALOG * GWEN_Widget_GetDialog(const GWEN_WIDGET *w)
Definition widget.c:92
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition widget.c:185
GWEN_WIDGET_SETCHARPROPERTY_FN GWEN_Widget_SetSetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETCHARPROPERTY_FN fn)
Definition widget.c:725
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34