ui/motif/toolbar.c

changeset 34
0ec8a5f17782
parent 27
77b09bb52ca0
child 36
e4198fc2ead4
equal deleted inserted replaced
33:458831c574f4 34:0ec8a5f17782
46 46
47 void ui_toolitem(char *name, char *label, ui_callback f, void *userdata) { 47 void ui_toolitem(char *name, char *label, ui_callback f, void *userdata) {
48 UiToolItem *item = malloc(sizeof(UiToolItem)); 48 UiToolItem *item = malloc(sizeof(UiToolItem));
49 item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget; 49 item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget;
50 item->label = label; 50 item->label = label;
51 item->image = NULL;
51 item->callback = f; 52 item->callback = f;
52 item->userdata = userdata; 53 item->userdata = userdata;
53 item->groups = NULL; 54 item->groups = NULL;
55 item->isimportant = FALSE;
54 56
55 ucx_map_cstr_put(toolbar_items, name, item); 57 ucx_map_cstr_put(toolbar_items, name, item);
56 } 58 }
57 59
58 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) { 60 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) {
64 item->item.add_to = (ui_toolbar_add_f)add_toolitem_st_widget; 66 item->item.add_to = (ui_toolbar_add_f)add_toolitem_st_widget;
65 item->stockid = stockid; 67 item->stockid = stockid;
66 item->callback = f; 68 item->callback = f;
67 item->userdata = userdata; 69 item->userdata = userdata;
68 item->groups = NULL; 70 item->groups = NULL;
71 item->isimportant = FALSE;
69 72
70 // add groups 73 // add groups
71 va_list ap; 74 va_list ap;
72 va_start(ap, userdata); 75 va_start(ap, userdata);
76 int group;
77 while((group = va_arg(ap, int)) != -1) {
78 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group);
79 }
80 va_end(ap);
81
82 ucx_map_cstr_put(toolbar_items, name, item);
83 }
84
85 void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) {
86 // TODO
87
88 UiToolItem *item = malloc(sizeof(UiToolItem));
89 item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget;
90 item->label = label;
91 item->image = img;
92 item->callback = f;
93 item->userdata = udata;
94 item->groups = NULL;
95 item->isimportant = FALSE;
96
97 ucx_map_cstr_put(toolbar_items, name, item);
98 }
99
100
101 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) {
102 // TODO
103
104 UiStToolItem *item = malloc(sizeof(UiStToolItem));
105 item->item.add_to = (ui_toolbar_add_f)add_toolitem_st_toggle_widget;
106 item->stockid = stockid;
107 item->callback = f;
108 item->userdata = udata;
109 item->groups = NULL;
110 item->isimportant = FALSE;
111
112 // add groups
113 va_list ap;
114 va_start(ap, udata);
115 int group;
116 while((group = va_arg(ap, int)) != -1) {
117 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group);
118 }
119 va_end(ap);
120
121 ucx_map_cstr_put(toolbar_items, name, item);
122 }
123
124 void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...) {
125 // TODO
126
127 UiToolItem *item = malloc(sizeof(UiToolItem));
128 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget;
129 item->label = label;
130 item->image = img;
131 item->callback = f;
132 item->userdata = udata;
133 item->groups = NULL;
134 item->isimportant = FALSE;
135
136 // add groups
137 va_list ap;
138 va_start(ap, udata);
73 int group; 139 int group;
74 while((group = va_arg(ap, int)) != -1) { 140 while((group = va_arg(ap, int)) != -1) {
75 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); 141 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group);
76 } 142 }
77 va_end(ap); 143 va_end(ap);
156 UiStockItem *stock_item = ui_get_stock_item(item->stockid); 222 UiStockItem *stock_item = ui_get_stock_item(item->stockid);
157 223
158 XmString label = XmStringCreateLocalized(stock_item->label); 224 XmString label = XmStringCreateLocalized(stock_item->label);
159 XtSetArg(args[0], XmNlabelString, label); 225 XtSetArg(args[0], XmNlabelString, label);
160 XtSetArg(args[1], XmNshadowThickness, 1); 226 XtSetArg(args[1], XmNshadowThickness, 1);
227 //XtSetArg(args[2], XmNhighlightThickness, 0);
161 Widget button = XmCreatePushButton(parent, "toolbar_button", args, 2); 228 Widget button = XmCreatePushButton(parent, "toolbar_button", args, 2);
162 229
163 XmStringFree(label); 230 XmStringFree(label);
164 231
165 if(item->callback) { 232 if(item->callback) {
180 247
181 if(item->groups) { 248 if(item->groups) {
182 uic_add_group_widget(obj->ctx, button, item->groups); 249 uic_add_group_widget(obj->ctx, button, item->groups);
183 } 250 }
184 } 251 }
252
253 void add_toolitem_toggle_widget(Widget parent, UiToolItem *item, UiObject *obj) {
254 Arg args[8];
255
256 XmString label = XmStringCreateLocalized(item->label);
257 XtSetArg(args[0], XmNlabelString, label);
258 XtSetArg(args[1], XmNshadowThickness, 1);
259 XtSetArg(args[2], XmNindicatorOn, XmINDICATOR_NONE);
260 Widget button = XmCreateToggleButton(parent, "toolbar_toggle_button", args, 3);
261
262 XmStringFree(label);
263
264 if(item->callback) {
265 UiEventData *event = ucx_mempool_malloc(
266 obj->ctx->mempool,
267 sizeof(UiEventData));
268 event->obj = obj;
269 event->user_data = item->userdata;
270 event->callback = item->callback;
271 XtAddCallback(
272 button,
273 XmNvalueChangedCallback,
274 (XtCallbackProc)ui_toggle_button_callback,
275 event);
276 }
277
278 XtManageChild(button);
279
280 if(item->groups) {
281 uic_add_group_widget(obj->ctx, button, item->groups);
282 }
283 }
284
285 void add_toolitem_st_toggle_widget(Widget parent, UiStToolItem *item, UiObject *obj) {
286
287 }

mercurial