diff --git a/lib/widget/dialog-switch.c b/lib/widget/dialog-switch.c
index 4a753842d..fe0de5873 100644
a
|
b
|
dialog_switch_list (void) |
237 | 237 | char *title; |
238 | 238 | |
239 | 239 | if (dlg->get_title != NULL) |
240 | | title = dlg->get_title (dlg, WIDGET (listbox->list)->cols - 2); |
| 240 | title = dlg->get_title (dlg, WIDGET (LISTBOX_(listbox)->list)->cols - 2); |
241 | 241 | else |
242 | 242 | title = g_strdup (""); |
243 | 243 | |
244 | | listbox_add_item (listbox->list, LISTBOX_APPEND_BEFORE, get_hotkey (i++), title, h, FALSE); |
| 244 | listbox_add_item (LISTBOX_(listbox)->list, LISTBOX_APPEND_BEFORE, get_hotkey (i++), title, h, FALSE); |
245 | 245 | |
246 | 246 | g_free (title); |
247 | 247 | } |
diff --git a/lib/widget/history.c b/lib/widget/history.c
index fc3caf3e2..bfeb5bf20 100644
a
|
b
|
history_create_item (history_descriptor_t * hd, void *data) |
158 | 158 | width = str_term_width1 (text); |
159 | 159 | hd->max_width = MAX (width, hd->max_width); |
160 | 160 | |
161 | | listbox_add_item (hd->listbox, LISTBOX_APPEND_AT_END, 0, text, NULL, TRUE); |
| 161 | listbox_add_item (LISTBOX(hd->listbox), LISTBOX_APPEND_AT_END, 0, text, NULL, TRUE); |
162 | 162 | } |
163 | 163 | |
164 | 164 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
history_show (history_descriptor_t * hd) |
217 | 217 | hd->create (hd, z->data); |
218 | 218 | /* after this, the order of history items is following: recent at begin, oldest at end */ |
219 | 219 | |
220 | | count = listbox_get_length (hd->listbox); |
| 220 | count = listbox_get_length (LISTBOX(hd->listbox)); |
221 | 221 | |
222 | 222 | hist_data.y = hd->y; |
223 | 223 | hist_data.x = hd->x; |
… |
… |
history_show (history_descriptor_t * hd) |
231 | 231 | |
232 | 232 | /* this call makes list stick to all sides of dialog, effectively make |
233 | 233 | it be resized with dialog */ |
234 | | group_add_widget_autopos (GROUP (query_dlg), hd->listbox, WPOS_KEEP_ALL, NULL); |
| 234 | group_add_widget_autopos (GROUP (query_dlg), LISTBOX(hd->listbox), WPOS_KEEP_ALL, NULL); |
235 | 235 | |
236 | 236 | /* to avoid diplicating of (calculating sizes in two places) |
237 | 237 | code, call history_dlg_callback function here, to set dialog and |
… |
… |
history_show (history_descriptor_t * hd) |
244 | 244 | { |
245 | 245 | /* history is above base widget -- revert order to place recent item at bottom */ |
246 | 246 | /* revert history direction */ |
247 | | g_queue_reverse (hd->listbox->list); |
| 247 | g_queue_reverse (LISTBOX_(hd->listbox)->list); |
248 | 248 | if (hd->current < 0 || (size_t) hd->current >= count) |
249 | | listbox_select_last (hd->listbox); |
| 249 | listbox_select_last (LISTBOX(hd->listbox)); |
250 | 250 | else |
251 | | listbox_select_entry (hd->listbox, count - 1 - (size_t) hd->current); |
| 251 | listbox_select_entry (LISTBOX(hd->listbox), count - 1 - (size_t) hd->current); |
252 | 252 | } |
253 | 253 | else |
254 | 254 | { |
255 | 255 | /* history is below base widget -- keep order to place recent item on top */ |
256 | 256 | if (hd->current > 0) |
257 | | listbox_select_entry (hd->listbox, hd->current); |
| 257 | listbox_select_entry (LISTBOX(hd->listbox), hd->current); |
258 | 258 | } |
259 | 259 | |
260 | 260 | dlg_ret = dlg_run (query_dlg); |
… |
… |
history_show (history_descriptor_t * hd) |
274 | 274 | hd->action = CK_Enter; |
275 | 275 | } |
276 | 276 | |
277 | | listbox_get_current (hd->listbox, &q, NULL); |
| 277 | listbox_get_current (LISTBOX(hd->listbox), &q, NULL); |
278 | 278 | hd->text = g_strdup (q); |
279 | 279 | } |
280 | 280 | |
281 | 281 | /* get modified history from dialog */ |
282 | 282 | z = NULL; |
283 | | for (hi = listbox_get_first_link (hd->listbox); hi != NULL; hi = g_list_next (hi)) |
| 283 | for (hi = listbox_get_first_link (LISTBOX(hd->listbox)); hi != NULL; hi = g_list_next (hi)) |
284 | 284 | /* history is being reverted here again */ |
285 | 285 | z = g_list_prepend (z, hd->release (hd, LENTRY (hi->data))); |
286 | 286 | |
diff --git a/lib/widget/listbox-window.c b/lib/widget/listbox-window.c
index d16dca9b0..c353b3d43 100644
a
|
b
|
run_listbox (Listbox * l) |
131 | 131 | int val = -1; |
132 | 132 | |
133 | 133 | if (dlg_run (l->dlg) != B_CANCEL) |
134 | | val = l->list->pos; |
| 134 | val = LISTBOX_(l->list)->pos; |
135 | 135 | widget_destroy (WIDGET (l->dlg)); |
136 | 136 | g_free (l); |
137 | 137 | return val; |
… |
… |
run_listbox_with_data (Listbox * l, const void *select) |
152 | 152 | void *val = NULL; |
153 | 153 | |
154 | 154 | if (select != NULL) |
155 | | listbox_select_entry (l->list, listbox_search_data (l->list, select)); |
| 155 | listbox_select_entry (LISTBOX_(l->list), listbox_search_data (LISTBOX_(l->list), select)); |
156 | 156 | |
157 | 157 | if (dlg_run (l->dlg) != B_CANCEL) |
158 | 158 | { |
159 | 159 | WLEntry *e; |
160 | | e = listbox_get_nth_item (l->list, l->list->pos); |
| 160 | e = listbox_get_nth_item (LISTBOX_(l->list), LISTBOX_(l->list)->pos); |
161 | 161 | if (e != NULL) |
162 | 162 | { |
163 | 163 | /* The assert guards against returning a soon-to-be deallocated |
diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
index 460dbee66..db6722839 100644
a
|
b
|
const global_keymap_t *listbox_map = NULL; |
51 | 51 | /*** file scope macro definitions ****************************************************************/ |
52 | 52 | |
53 | 53 | /* Gives the position of the last item. */ |
54 | | #define LISTBOX_LAST(l) (listbox_is_empty (l) ? 0 : (int) g_queue_get_length ((l)->list) - 1) |
| 54 | #define LISTBOX_LAST(l) (listbox_is_empty (l) ? 0 : (int) g_queue_get_length (LISTBOX_(l)->list) - 1) |
55 | 55 | |
56 | 56 | /*** file scope type declarations ****************************************************************/ |
57 | 57 | |
… |
… |
static void |
76 | 76 | listbox_entry_free (void *data) |
77 | 77 | { |
78 | 78 | WLEntry *e = data; |
79 | | |
| 79 | FILE *f=fopen("mc-.log","a+"); |
| 80 | fprintf(f,"1.FREE:%p, text:%s\n",data,e->text); |
| 81 | fclose(f); |
80 | 82 | g_free (e->text); |
81 | 83 | if (e->free_data) |
82 | 84 | g_free (e->data); |
… |
… |
listbox_entry_free (void *data) |
86 | 88 | /* --------------------------------------------------------------------------------------------- */ |
87 | 89 | |
88 | 90 | static void |
89 | | listbox_draw (WListbox * l, gboolean focused) |
| 91 | listbox_draw (WListbox_ * l, gboolean focused) |
90 | 92 | { |
91 | 93 | Widget *w = WIDGET (l); |
92 | 94 | const int *colors; |
… |
… |
listbox_draw (WListbox * l, gboolean focused) |
97 | 99 | int pos; |
98 | 100 | int i; |
99 | 101 | int sel_line = -1; |
100 | | |
101 | 102 | colors = widget_get_colors (w); |
102 | 103 | |
103 | 104 | disabled = widget_get_state (w, WST_DISABLED); |
104 | 105 | normalc = disabled ? DISABLED_COLOR : colors[DLG_COLOR_NORMAL]; |
105 | 106 | selc = disabled ? DISABLED_COLOR : colors[focused ? DLG_COLOR_HOT_FOCUS : DLG_COLOR_FOCUS]; |
106 | 107 | |
| 108 | FILE *f=fopen("mc-.log","a+"); |
| 109 | fprintf(f,"ptr:%p, first:%p, ->data--: %p, text:%p\n",l->list, |
| 110 | g_queue_peek_head_link(l->list), |
| 111 | LENTRY(g_queue_peek_head(l->list))? |
| 112 | LENTRY(g_queue_peek_head(l->list)):0, |
| 113 | g_queue_peek_head(l->list)); |
| 114 | fclose(f); |
| 115 | |
107 | 116 | if (l->list != NULL) |
108 | 117 | { |
109 | 118 | length = g_queue_get_length (l->list); |
… |
… |
listbox_draw (WListbox * l, gboolean focused) |
142 | 151 | |
143 | 152 | l->cursor_y = sel_line; |
144 | 153 | |
145 | | if (l->draw_scrollbar) |
| 154 | if (LISTBOX(WIDGET(l)->owner)->draw_scrollbar) |
146 | 155 | { |
147 | 156 | tty_setcolor (normalc); |
148 | | scrollbar_set_state (l->scrollbar, w->y - 1, w->x + w->cols, w->lines + 2, g_queue_get_length (l->list), w->lines, l->top); |
149 | | WIDGET (l->scrollbar)->callback (WIDGET (l->scrollbar), NULL, MSG_DRAW, 0, NULL); |
| 157 | /*scrollbar_set_state (SCROLLBAR_(l), w->y - 1, w->x + w->cols, w->lines + 2, g_queue_get_length (l->list), w->lines, l->top);*/ |
| 158 | /*WIDGET (SCROLLBAR_(l))->callback (WIDGET (SCROLLBAR_(l)), NULL, MSG_DRAW, 0, NULL);*/ |
150 | 159 | } |
151 | 160 | } |
152 | 161 | |
153 | 162 | /* --------------------------------------------------------------------------------------------- */ |
154 | 163 | |
155 | 164 | static int |
156 | | listbox_check_hotkey (WListbox * l, int key) |
| 165 | listbox_check_hotkey (WListbox_ * l, int key) |
157 | 166 | { |
158 | | if (!listbox_is_empty (l)) |
| 167 | if (!listbox_is_empty ((LISTBOX(WIDGET(l)->owner)))) |
159 | 168 | { |
160 | 169 | int i; |
161 | 170 | GList *le; |
… |
… |
listbox_check_hotkey (WListbox * l, int key) |
176 | 185 | |
177 | 186 | /* Calculates the item displayed at screen row 'y' (y==0 being the widget's 1st row). */ |
178 | 187 | static int |
179 | | listbox_y_pos (WListbox * l, int y) |
| 188 | listbox_y_pos (WListbox_ * l, int y) |
180 | 189 | { |
181 | | return MIN (l->top + y, LISTBOX_LAST (l)); |
| 190 | return MIN (l->top + y, LISTBOX_LAST (LISTBOX(WIDGET(l)->owner))); |
182 | 191 | } |
183 | 192 | |
184 | 193 | /* --------------------------------------------------------------------------------------------- */ |
185 | 194 | |
186 | 195 | static void |
187 | | listbox_fwd (WListbox * l, gboolean wrap) |
| 196 | listbox_fwd (WListbox_ * l, gboolean wrap) |
188 | 197 | { |
189 | | if (!listbox_is_empty (l)) |
| 198 | if (!listbox_is_empty ((LISTBOX(WIDGET(l)->owner)))) |
190 | 199 | { |
191 | 200 | if ((guint) l->pos + 1 < g_queue_get_length (l->list)) |
192 | | listbox_select_entry (l, l->pos + 1); |
| 201 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), l->pos + 1); |
193 | 202 | else if (wrap) |
194 | | listbox_select_first (l); |
| 203 | listbox_select_first (LISTBOX(WIDGET(l)->owner)); |
195 | 204 | } |
196 | 205 | } |
197 | 206 | |
198 | 207 | /* --------------------------------------------------------------------------------------------- */ |
199 | 208 | |
200 | 209 | static void |
201 | | listbox_fwd_n (WListbox * l, int n) |
| 210 | listbox_fwd_n (WListbox_ * l, int n) |
202 | 211 | { |
203 | | listbox_select_entry (l, MIN (l->pos + n, LISTBOX_LAST (l))); |
| 212 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), MIN (l->pos + n, LISTBOX_LAST (LISTBOX(WIDGET(l)->owner)))); |
204 | 213 | } |
205 | 214 | |
206 | 215 | /* --------------------------------------------------------------------------------------------- */ |
207 | 216 | |
208 | 217 | static void |
209 | | listbox_back (WListbox * l, gboolean wrap) |
| 218 | listbox_back (WListbox_ * l, gboolean wrap) |
210 | 219 | { |
211 | | if (!listbox_is_empty (l)) |
| 220 | if (!listbox_is_empty ((LISTBOX(WIDGET(l)->owner)))) |
212 | 221 | { |
213 | 222 | if (l->pos > 0) |
214 | | listbox_select_entry (l, l->pos - 1); |
| 223 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), l->pos - 1); |
215 | 224 | else if (wrap) |
216 | | listbox_select_last (l); |
| 225 | listbox_select_last (LISTBOX(WIDGET(l)->owner)); |
217 | 226 | } |
218 | 227 | } |
219 | 228 | |
220 | 229 | /* --------------------------------------------------------------------------------------------- */ |
221 | 230 | |
222 | 231 | static void |
223 | | listbox_back_n (WListbox * l, int n) |
| 232 | listbox_back_n (WListbox_ * l, int n) |
224 | 233 | { |
225 | | listbox_select_entry (l, MAX (l->pos - n, 0)); |
| 234 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), MAX (l->pos - n, 0)); |
226 | 235 | } |
227 | 236 | |
228 | 237 | /* --------------------------------------------------------------------------------------------- */ |
229 | 238 | |
230 | 239 | static cb_ret_t |
231 | | listbox_execute_cmd (WListbox * l, long command) |
| 240 | listbox_execute_cmd (WListbox_ * l, long command) |
232 | 241 | { |
233 | 242 | cb_ret_t ret = MSG_HANDLED; |
234 | 243 | Widget *w = WIDGET (l); |
… |
… |
listbox_execute_cmd (WListbox * l, long command) |
245 | 254 | listbox_fwd (l, TRUE); |
246 | 255 | break; |
247 | 256 | case CK_Top: |
248 | | listbox_select_first (l); |
| 257 | listbox_select_first (LISTBOX(WIDGET(l)->owner)); |
249 | 258 | break; |
250 | 259 | case CK_Bottom: |
251 | | listbox_select_last (l); |
| 260 | listbox_select_last (LISTBOX(WIDGET(l)->owner)); |
252 | 261 | break; |
253 | 262 | case CK_PageUp: |
254 | 263 | listbox_back_n (l, w->lines - 1); |
… |
… |
listbox_execute_cmd (WListbox * l, long command) |
267 | 276 | is_last = (l->pos + 1 >= length); |
268 | 277 | is_more = (l->top + w->lines >= length); |
269 | 278 | |
270 | | listbox_remove_current (l); |
| 279 | listbox_remove_current (LISTBOX(WIDGET(l)->owner)); |
271 | 280 | if ((l->top > 0) && (is_last || is_more)) |
272 | 281 | l->top--; |
273 | 282 | } |
… |
… |
listbox_execute_cmd (WListbox * l, long command) |
278 | 287 | && (query_dialog (Q_ ("DialogTitle|History cleanup"), |
279 | 288 | _("Do you want clean this history?"), |
280 | 289 | D_ERROR, 2, _("&Yes"), _("&No")) == 0)) |
281 | | listbox_remove_list (l); |
| 290 | listbox_remove_list (LISTBOX(WIDGET(l)->owner)); |
282 | 291 | break; |
283 | 292 | case CK_View: |
284 | 293 | case CK_Edit: |
… |
… |
listbox_execute_cmd (WListbox * l, long command) |
296 | 305 | |
297 | 306 | /* Return MSG_HANDLED if we want a redraw */ |
298 | 307 | static cb_ret_t |
299 | | listbox_key (WListbox * l, int key) |
| 308 | listbox_key (WListbox_ * l, int key) |
300 | 309 | { |
301 | 310 | long command; |
302 | 311 | |
… |
… |
listbox_key (WListbox * l, int key) |
306 | 315 | /* focus on listbox item N by '0'..'9' keys */ |
307 | 316 | if (key >= '0' && key <= '9') |
308 | 317 | { |
309 | | listbox_select_entry (l, key - '0'); |
| 318 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), key - '0'); |
310 | 319 | return MSG_HANDLED; |
311 | 320 | } |
312 | 321 | |
… |
… |
listbox_key (WListbox * l, int key) |
320 | 329 | |
321 | 330 | /* Listbox item adding function */ |
322 | 331 | static inline void |
323 | | listbox_append_item (WListbox * l, WLEntry * e, listbox_append_t pos) |
| 332 | listbox_append_item (WListbox_ * l, WLEntry * e, listbox_append_t pos) |
324 | 333 | { |
325 | 334 | if (l->list == NULL) |
326 | 335 | { |
… |
… |
listbox_append_item (WListbox * l, WLEntry * e, listbox_append_t pos) |
349 | 358 | default: |
350 | 359 | break; |
351 | 360 | } |
| 361 | |
| 362 | FILE *f=fopen("mc-.log","a+"); |
| 363 | fprintf(f,"Append ptr:%p, first:%p, ->dat: %p, text:%s\n",l->list, |
| 364 | g_queue_peek_head_link(l->list), |
| 365 | g_queue_peek_head (l->list), |
| 366 | LENTRY(g_queue_peek_tail(l->list))->text); |
| 367 | fclose(f); |
| 368 | |
352 | 369 | } |
353 | 370 | |
354 | 371 | /* --------------------------------------------------------------------------------------------- */ |
355 | 372 | |
356 | 373 | /* Call this whenever the user changes the selected item. */ |
357 | 374 | static void |
358 | | listbox_on_change (WListbox * l) |
| 375 | listbox_on_change (WListbox_ * l) |
359 | 376 | { |
360 | 377 | listbox_draw (l, TRUE); |
361 | 378 | send_message (WIDGET (l)->owner, l, MSG_NOTIFY, 0, NULL); |
… |
… |
listbox_on_change (WListbox * l) |
364 | 381 | /* --------------------------------------------------------------------------------------------- */ |
365 | 382 | |
366 | 383 | static void |
367 | | listbox_do_action (WListbox * l) |
| 384 | listbox_do_action (WListbox_ * l) |
368 | 385 | { |
369 | 386 | int action; |
370 | 387 | |
371 | | if (listbox_is_empty (l)) |
| 388 | if (listbox_is_empty ((LISTBOX(WIDGET(l)->owner)))) |
372 | 389 | return; |
373 | 390 | |
374 | 391 | if (l->callback != NULL) |
375 | | action = l->callback (l); |
| 392 | action = l->callback (LISTBOX(WIDGET(l)->owner)); |
376 | 393 | else |
377 | 394 | action = LISTBOX_DONE; |
378 | 395 | |
… |
… |
listbox_do_action (WListbox * l) |
388 | 405 | /* --------------------------------------------------------------------------------------------- */ |
389 | 406 | |
390 | 407 | static void |
391 | | listbox_run_hotkey (WListbox * l, int pos) |
| 408 | listbox_run_hotkey (WListbox_ * l, int pos) |
392 | 409 | { |
393 | | listbox_select_entry (l, pos); |
| 410 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), pos); |
394 | 411 | listbox_on_change (l); |
395 | 412 | listbox_do_action (l); |
396 | 413 | } |
… |
… |
listbox_run_hotkey (WListbox * l, int pos) |
398 | 415 | /* --------------------------------------------------------------------------------------------- */ |
399 | 416 | |
400 | 417 | static inline void |
401 | | listbox_destroy (WListbox * l) |
| 418 | listbox_destroy (WListbox_ * l) |
402 | 419 | { |
403 | | widget_destroy (WIDGET (l->scrollbar)); |
404 | | listbox_remove_list (l); |
| 420 | widget_destroy (WIDGET (SCROLLBAR_(l))); |
| 421 | listbox_remove_list (LISTBOX(WIDGET(l)->owner)); |
405 | 422 | } |
406 | 423 | |
407 | 424 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_destroy (WListbox * l) |
409 | 426 | static cb_ret_t |
410 | 427 | listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) |
411 | 428 | { |
412 | | WListbox *l = LISTBOX (w); |
| 429 | WListbox_ *l = LISTBOX__ (w); |
413 | 430 | |
414 | 431 | switch (msg) |
415 | 432 | { |
… |
… |
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void |
440 | 457 | return listbox_execute_cmd (l, parm); |
441 | 458 | |
442 | 459 | case MSG_CURSOR: |
443 | | widget_gotoyx (l, l->cursor_y, 0); |
| 460 | widget_gotoyx (w, l->cursor_y, 0); |
444 | 461 | return MSG_HANDLED; |
445 | 462 | |
446 | 463 | case MSG_DRAW: |
… |
… |
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void |
461 | 478 | static void |
462 | 479 | listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
463 | 480 | { |
464 | | WListbox *l = LISTBOX (w); |
| 481 | WListbox_ *l = LISTBOX__ (w); |
465 | 482 | int old_pos; |
466 | 483 | |
467 | 484 | old_pos = l->pos; |
… |
… |
listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
470 | 487 | { |
471 | 488 | case MSG_MOUSE_DOWN: |
472 | 489 | widget_select (w); |
473 | | listbox_select_entry (l, listbox_y_pos (l, event->y)); |
| 490 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), listbox_y_pos(l, event->y)); |
474 | 491 | break; |
475 | 492 | |
476 | 493 | case MSG_MOUSE_SCROLL_UP: |
477 | | listbox_back (l, FALSE); |
| 494 | listbox_back(l, FALSE); |
478 | 495 | break; |
479 | 496 | |
480 | 497 | case MSG_MOUSE_SCROLL_DOWN: |
… |
… |
listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
483 | 500 | |
484 | 501 | case MSG_MOUSE_DRAG: |
485 | 502 | event->result.repeat = TRUE; /* It'd be functional even without this. */ |
486 | | listbox_select_entry (l, listbox_y_pos (l, event->y)); |
| 503 | listbox_select_entry (LISTBOX(WIDGET(l)->owner), listbox_y_pos (l, event->y)); |
487 | 504 | break; |
488 | 505 | |
489 | 506 | case MSG_MOUSE_CLICK: |
… |
… |
listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
505 | 522 | /*** public functions ****************************************************************************/ |
506 | 523 | /* --------------------------------------------------------------------------------------------- */ |
507 | 524 | |
508 | | WListbox * |
509 | | listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback) |
| 525 | static WListbox_ * |
| 526 | listbox_new_inter (int y, int x, int height, int width, gboolean deletable, gboolean so, lcback_fn callback) |
510 | 527 | { |
511 | | WListbox *l; |
| 528 | WListbox_ *l; |
512 | 529 | Widget *w; |
513 | 530 | |
514 | 531 | if (height <= 0) |
515 | 532 | height = 1; |
516 | 533 | |
517 | | l = g_new (WListbox, 1); |
| 534 | l = g_new0 (WListbox_, 1); |
518 | 535 | w = WIDGET (l); |
519 | 536 | widget_init (w, y, x, height, width, listbox_callback, listbox_mouse_callback); |
520 | 537 | w->options |= WOP_SELECTABLE | WOP_WANT_HOTKEY; |
… |
… |
listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn |
525 | 542 | l->deletable = deletable; |
526 | 543 | l->callback = callback; |
527 | 544 | l->allow_duplicates = TRUE; |
528 | | l->draw_scrollbar = !mc_global.tty.slow_terminal; |
529 | | l->scrollbar = scrollbar_new (y, x + width - 1, height, TRUE); |
530 | 545 | |
531 | 546 | return l; |
532 | 547 | } |
533 | 548 | |
| 549 | |
| 550 | WListbox * |
| 551 | listbox_new (int y, int x, int height, int width, gboolean pruneable, lcback_fn callback) |
| 552 | { |
| 553 | WGroup *g; |
| 554 | Widget *w; |
| 555 | WListbox *l; |
| 556 | WListbox_ *w1; |
| 557 | WScrollbar *w2; |
| 558 | |
| 559 | if (height <= 0) |
| 560 | height = 1; |
| 561 | |
| 562 | l = g_new0 (WListbox, 1); |
| 563 | g = GROUP(l); |
| 564 | w = WIDGET(l); |
| 565 | group_init(g,y,x,height,width,NULL,NULL); |
| 566 | |
| 567 | w->options |= WOP_SELECTABLE | WOP_TOP_SELECT; |
| 568 | w->state |= WST_FOCUSED; |
| 569 | |
| 570 | w1 = listbox_new_inter(y,x,height,width,pruneable,TRUE,callback); |
| 571 | w2 = scrollbar_new (y, x + width - 1, height, TRUE); |
| 572 | l->draw_scrollbar = !mc_global.tty.slow_terminal; |
| 573 | group_add_widget_autopos(g,w2,0,0); |
| 574 | group_add_widget_autopos(g,w1,0,0); |
| 575 | return l; |
| 576 | } |
| 577 | |
534 | 578 | /* --------------------------------------------------------------------------------------------- */ |
535 | 579 | |
536 | 580 | /** |
… |
… |
listbox_search_text (WListbox * l, const char *text) |
544 | 588 | int i; |
545 | 589 | GList *le; |
546 | 590 | |
547 | | for (i = 0, le = g_queue_peek_head_link (l->list); le != NULL; i++, le = g_list_next (le)) |
| 591 | for (i = 0, le = g_queue_peek_head_link (LISTBOX_(l)->list); le != NULL; i++, le = g_list_next (le)) |
548 | 592 | { |
549 | 593 | WLEntry *e = LENTRY (le->data); |
550 | 594 | |
… |
… |
listbox_search_data (WListbox * l, const void *data) |
569 | 613 | int i; |
570 | 614 | GList *le; |
571 | 615 | |
572 | | for (i = 0, le = g_queue_peek_head_link (l->list); le != NULL; i++, le = g_list_next (le)) |
| 616 | for (i = 0, le = g_queue_peek_head_link (LISTBOX_(l)->list); le != NULL; i++, le = g_list_next (le)) |
573 | 617 | { |
574 | 618 | WLEntry *e = LENTRY (le->data); |
575 | 619 | |
… |
… |
listbox_search_data (WListbox * l, const void *data) |
587 | 631 | void |
588 | 632 | listbox_select_first (WListbox * l) |
589 | 633 | { |
590 | | l->pos = l->top = 0; |
| 634 | LISTBOX_(l)->pos = LISTBOX_(l)->top = 0; |
591 | 635 | } |
592 | 636 | |
593 | 637 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_select_last (WListbox * l) |
601 | 645 | |
602 | 646 | length = listbox_get_length (l); |
603 | 647 | |
604 | | l->pos = DOZ (length, 1); |
605 | | l->top = DOZ (length, lines); |
| 648 | LISTBOX_(l)->pos = DOZ (length, 1); |
| 649 | LISTBOX_(l)->top = DOZ (length, lines); |
606 | 650 | } |
607 | 651 | |
608 | 652 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_select_entry (WListbox * l, int dest) |
618 | 662 | return; |
619 | 663 | |
620 | 664 | /* Special case */ |
621 | | for (pos = 0, le = g_queue_peek_head_link (l->list); le != NULL; pos++, le = g_list_next (le)) |
| 665 | for (pos = 0, le = g_queue_peek_head_link (LISTBOX_(l)->list); le != NULL; pos++, le = g_list_next (le)) |
622 | 666 | { |
623 | | if (pos == l->top) |
| 667 | if (pos == LISTBOX_(l)->top) |
624 | 668 | top_seen = TRUE; |
625 | 669 | |
626 | 670 | if (pos == dest) |
627 | 671 | { |
628 | | l->pos = dest; |
| 672 | LISTBOX_(l)->pos = dest; |
629 | 673 | if (!top_seen) |
630 | | l->top = l->pos; |
| 674 | LISTBOX_(l)->top = LISTBOX_(l)->pos; |
631 | 675 | else |
632 | 676 | { |
633 | 677 | int lines = WIDGET (l)->lines; |
634 | 678 | |
635 | | if (l->pos - l->top >= lines) |
636 | | l->top = l->pos - lines + 1; |
| 679 | if (LISTBOX_(l)->pos - LISTBOX_(l)->top >= lines) |
| 680 | LISTBOX_(l)->top = LISTBOX_(l)->pos - lines + 1; |
637 | 681 | } |
638 | 682 | return; |
639 | 683 | } |
640 | 684 | } |
641 | 685 | |
642 | 686 | /* If we are unable to find it, set decent values */ |
643 | | l->pos = l->top = 0; |
| 687 | LISTBOX_(l)->pos = LISTBOX_(l)->top = 0; |
644 | 688 | } |
645 | 689 | |
646 | 690 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_select_entry (WListbox * l, int dest) |
648 | 692 | int |
649 | 693 | listbox_get_length (const WListbox * l) |
650 | 694 | { |
651 | | return listbox_is_empty (l) ? 0 : (int) g_queue_get_length (l->list); |
| 695 | return listbox_is_empty (l) ? 0 : (int) g_queue_get_length (LISTBOX_(l)->list); |
652 | 696 | } |
653 | 697 | |
654 | 698 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_get_current (WListbox * l, char **string, void **extra) |
661 | 705 | gboolean ok; |
662 | 706 | |
663 | 707 | if (l != NULL) |
664 | | e = listbox_get_nth_item (l, l->pos); |
| 708 | e = listbox_get_nth_item (l, LISTBOX_(l)->pos); |
665 | 709 | |
666 | 710 | ok = (e != NULL); |
667 | 711 | |
… |
… |
listbox_get_nth_item (const WListbox * l, int pos) |
681 | 725 | { |
682 | 726 | GList *item; |
683 | 727 | |
684 | | item = g_queue_peek_nth_link (l->list, (guint) pos); |
| 728 | item = g_queue_peek_nth_link (LISTBOX_(l)->list, (guint) pos); |
685 | 729 | if (item != NULL) |
686 | 730 | return LENTRY (item->data); |
687 | 731 | } |
… |
… |
listbox_get_nth_item (const WListbox * l, int pos) |
694 | 738 | GList * |
695 | 739 | listbox_get_first_link (const WListbox * l) |
696 | 740 | { |
697 | | return (l == NULL || l->list == NULL) ? NULL : g_queue_peek_head_link (l->list); |
| 741 | return (l == NULL || LISTBOX_(l)->list == NULL) ? NULL : g_queue_peek_head_link (LISTBOX_(l)->list); |
698 | 742 | } |
699 | 743 | |
700 | 744 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_remove_current (WListbox * l) |
707 | 751 | GList *current; |
708 | 752 | int length; |
709 | 753 | |
710 | | current = g_queue_peek_nth_link (l->list, (guint) l->pos); |
| 754 | current = g_queue_peek_nth_link (LISTBOX_(l)->list, (guint) LISTBOX_(l)->pos); |
711 | 755 | listbox_entry_free (current->data); |
712 | | g_queue_delete_link (l->list, current); |
| 756 | g_queue_delete_link (LISTBOX_(l)->list, current); |
713 | 757 | |
714 | | length = g_queue_get_length (l->list); |
| 758 | length = g_queue_get_length (LISTBOX_(l)->list); |
715 | 759 | |
716 | 760 | if (length == 0) |
717 | | l->top = l->pos = 0; |
718 | | else if (l->pos >= length) |
719 | | l->pos = length - 1; |
| 761 | LISTBOX_(l)->top = LISTBOX_(l)->pos = 0; |
| 762 | else if (LISTBOX_(l)->pos >= length) |
| 763 | LISTBOX_(l)->pos = length - 1; |
720 | 764 | } |
721 | 765 | } |
722 | 766 | |
… |
… |
listbox_remove_current (WListbox * l) |
725 | 769 | gboolean |
726 | 770 | listbox_is_empty (const WListbox * l) |
727 | 771 | { |
728 | | return (l == NULL || l->list == NULL || g_queue_is_empty (l->list)); |
| 772 | return (l == NULL || LISTBOX_(l)->list == NULL || g_queue_is_empty (LISTBOX_(l)->list)); |
729 | 773 | } |
730 | 774 | |
731 | 775 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_is_empty (const WListbox * l) |
733 | 777 | /** |
734 | 778 | * Set new listbox items list. |
735 | 779 | * |
736 | | * @param l WListbox object |
| 780 | * @param l WListbox_ object |
737 | 781 | * @param list list of WLEntry objects |
738 | 782 | */ |
739 | 783 | void |
… |
… |
listbox_set_list (WListbox * l, GQueue * list) |
742 | 786 | listbox_remove_list (l); |
743 | 787 | |
744 | 788 | if (l != NULL) |
745 | | l->list = list; |
| 789 | LISTBOX_(l)->list = list; |
746 | 790 | } |
747 | 791 | |
748 | 792 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
listbox_remove_list (WListbox * l) |
752 | 796 | { |
753 | 797 | if (l != NULL) |
754 | 798 | { |
755 | | if (l->list != NULL) |
| 799 | if (LISTBOX_(l)->list != NULL) |
756 | 800 | { |
757 | | g_queue_free_full (l->list, (GDestroyNotify) listbox_entry_free); |
758 | | l->list = NULL; |
| 801 | FILE *f=fopen("mc-.log","a+"); |
| 802 | fprintf(f,"1.release:%p, first:%p, entry: %p\n",LISTBOX_(l)->list, |
| 803 | g_queue_peek_head(LISTBOX_(l)->list), |
| 804 | 0); |
| 805 | fclose(f); g_queue_free_full (LISTBOX_(l)->list, (GDestroyNotify) listbox_entry_free); |
| 806 | LISTBOX_(l)->list = NULL; |
759 | 807 | } |
760 | 808 | |
761 | | l->pos = l->top = 0; |
| 809 | LISTBOX_(l)->pos = LISTBOX_(l)->top = 0; |
762 | 810 | } |
763 | 811 | } |
764 | 812 | |
… |
… |
listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *te |
773 | 821 | if (l == NULL) |
774 | 822 | return NULL; |
775 | 823 | |
776 | | if (!l->allow_duplicates && (listbox_search_text (l, text) >= 0)) |
| 824 | if (!LISTBOX_(l)->allow_duplicates && (listbox_search_text (l, text) >= 0)) |
777 | 825 | return NULL; |
778 | 826 | |
779 | 827 | entry = g_new (WLEntry, 1); |
… |
… |
listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *te |
781 | 829 | entry->data = data; |
782 | 830 | entry->free_data = free_data; |
783 | 831 | entry->hotkey = hotkey; |
784 | | |
785 | | listbox_append_item (l, entry, pos); |
| 832 | FILE *f=fopen("mc-.log","a+"); |
| 833 | fprintf(f,"1.Add-item ptr:%p, first:%p, entry: %p\n",LISTBOX_(l)->list, |
| 834 | g_queue_peek_head(LISTBOX_(l)->list), |
| 835 | entry); |
| 836 | fclose(f); |
| 837 | listbox_append_item (LISTBOX_ (l), entry, pos); |
786 | 838 | |
787 | 839 | return entry->text; |
788 | 840 | } |
diff --git a/lib/widget/listbox.h b/lib/widget/listbox.h
index 96dd4afc4..23dbb4817 100644
a
|
b
|
|
8 | 8 | |
9 | 9 | /*** typedefs(not structures) and defined constants **********************************************/ |
10 | 10 | |
11 | | #define LISTBOX(x) ((WListbox *)(x)) |
| 11 | #define SCROLLBAR_(x) ((WScrollbar *)(((GList *)GROUP((WListbox *)(x))->widgets)->data)) |
| 12 | #define LISTBOX(x) ((WListbox *)x) |
| 13 | #define LISTBOX__(x) ((WListbox_ *)x) |
| 14 | #define LISTBOX_(x) ((WListbox_ *)(g_list_next(GROUP((WListbox *)(x))->widgets)->data)) |
12 | 15 | #define LENTRY(x) ((WLEntry *)(x)) |
13 | 16 | |
14 | 17 | /*** enums ***************************************************************************************/ |
… |
… |
typedef enum |
30 | 33 | |
31 | 34 | /*** structures declarations (and typedefs of structures)*****************************************/ |
32 | 35 | |
33 | | struct WListbox; |
34 | | typedef lcback_ret_t (*lcback_fn) (struct WListbox * l); |
| 36 | typedef struct WListbox WListbox; |
| 37 | typedef struct WListbox_ WListbox_; |
| 38 | typedef lcback_ret_t (*lcback_fn) (WListbox * l); |
35 | 39 | |
36 | 40 | typedef struct WLEntry |
37 | 41 | { |
… |
… |
typedef struct WLEntry |
42 | 46 | } WLEntry; |
43 | 47 | |
44 | 48 | typedef struct WListbox |
| 49 | { |
| 50 | WGroup base; |
| 51 | gboolean draw_scrollbar; |
| 52 | } WListbox; |
| 53 | |
| 54 | typedef struct WListbox_ |
45 | 55 | { |
46 | 56 | Widget widget; |
47 | 57 | GQueue *list; /* Pointer to the list of WLEntry */ |
48 | 58 | int pos; /* The current element displayed */ |
49 | 59 | int top; /* The first element displayed */ |
50 | 60 | gboolean allow_duplicates; /* Do we allow duplicates on the list? */ |
51 | | gboolean draw_scrollbar; /* Draw a scrollbar? */ |
52 | | WScrollbar *scrollbar; /* Scrollbar widget */ |
53 | 61 | gboolean deletable; /* Can list entries be deleted? */ |
54 | 62 | lcback_fn callback; /* The callback function */ |
55 | 63 | int cursor_x, cursor_y; /* Cache the values */ |
56 | | } WListbox; |
| 64 | } WListbox_; |
57 | 65 | |
58 | 66 | /*** global variables defined in .c file *********************************************************/ |
59 | 67 | |
diff --git a/lib/widget/scrollbar.c b/lib/widget/scrollbar.c
index 8b68d0893..1599cd4a3 100644
a
|
b
|
scrollbar_new (int y, int x, int lines, gboolean has_subchars) |
132 | 132 | WScrollbar *scrollbar; |
133 | 133 | Widget *w; |
134 | 134 | |
135 | | scrollbar = g_new (WScrollbar, 1); |
| 135 | scrollbar = g_new0 (WScrollbar, 1); |
136 | 136 | w = WIDGET (scrollbar); |
137 | 137 | widget_init (w, y, x, lines, 1, scrollbar_callback, NULL); |
138 | 138 | |
diff --git a/po/be.po b/po/be.po
index 3bb003750..80db90018 100644
Binary files a/po/be.po and b/po/be.po differ
diff --git a/po/fr.po b/po/fr.po
index 2a7636f3f..f86c9ba8e 100644
Binary files a/po/fr.po and b/po/fr.po differ
diff --git a/po/hr.po b/po/hr.po
index 7d3fa992b..cbdf916bc 100644
Binary files a/po/hr.po and b/po/hr.po differ
diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c
index 202d10275..d1151961a 100644
a
|
b
|
user_group_button_cb (WButton * button, int action) |
582 | 582 | |
583 | 583 | listbox_select_entry (chl_list, fe); |
584 | 584 | |
585 | | b_pos = chl_list->pos; |
| 585 | b_pos = LISTBOX_(chl_list)->pos; |
586 | 586 | group_add_widget (GROUP (chl_dlg), chl_list); |
587 | 587 | |
588 | 588 | result = dlg_run (chl_dlg); |
589 | 589 | |
590 | 590 | if (result != B_CANCEL) |
591 | 591 | { |
592 | | if (b_pos != chl_list->pos) |
| 592 | if (b_pos != LISTBOX_(chl_list)->pos) |
593 | 593 | { |
594 | 594 | gboolean ok = FALSE; |
595 | 595 | char *text; |
diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c
index ec83e250a..75c36d634 100644
a
|
b
|
task_cb (WButton * button, int action) |
488 | 488 | |
489 | 489 | (void) button; |
490 | 490 | |
491 | | if (bg_list->list == NULL) |
| 491 | if (LISTBOX_(bg_list)->list == NULL) |
492 | 492 | return 0; |
493 | 493 | |
494 | 494 | /* Get this instance information */ |
diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c
index 9b66c4555..ad1118906 100644
a
|
b
|
add2hotlist (char *label, char *directory, enum HotListType type, listbox_append |
990 | 990 | } |
991 | 991 | else |
992 | 992 | listbox_add_item (l_hotlist, pos, 0, new->label, new, FALSE); |
993 | | listbox_select_entry (l_hotlist, l_hotlist->pos); |
| 993 | listbox_select_entry (l_hotlist, LISTBOX_(l_hotlist)->pos); |
994 | 994 | } |
995 | 995 | |
996 | 996 | return new; |
diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c
index 9edaff74c..d0f089f8e 100644
a
|
b
|
static struct panelize |
92 | 92 | static void |
93 | 93 | update_command (void) |
94 | 94 | { |
95 | | if (l_panelize->pos != last_listitem) |
| 95 | if (LISTBOX_(l_panelize)->pos != last_listitem) |
96 | 96 | { |
97 | 97 | struct panelize *data = NULL; |
98 | 98 | |
99 | | last_listitem = l_panelize->pos; |
| 99 | last_listitem = LISTBOX_(l_panelize)->pos; |
100 | 100 | listbox_get_current (l_panelize, NULL, (void **) &data); |
101 | 101 | input_assign_text (pname, data->command); |
102 | 102 | pname->point = 0; |