1 /************************************************************************/
2 /* */
3 /* QUASI88 ��˥塼�� Tool Kit */
4 /* */
5 /* GTK+ �� API ���ƺ��ޤ�������䤳�������ơ��ɥ�����Ȥ� */
6 /* �ޤ���ġġġ� */
7 /* */
8 /************************************************************************/
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <ctype.h>
13
14 #include "quasi88.h"
15
16 #include "q8tk.h"
17 #include "q8tk-glib.h"
18
19 #include "menu-screen.h"
20
21 #include "file-op.h"
22 #include "wait.h"
23
24 #include "keyboard.h" /* mouse_x, mouse_y */
25 #include "event.h"
26 #include "menu.h"
27 #include "screen.h"
28
29
30 /*#define OLD_FOCUS_CHANGE*/
31
32
33 /* ������Хå��ؿ��ΰ��� (Q8tkWidget*, void*) ��̤���Ѥξ�硢
34 * ��˥��Ф�ݵƫ�����Τǡ� gcc �����ǵ����Ƥ�餦�� */
35 #if defined(__GNUC__)
36 #define UNUSED_WIDGET __attribute__((__unused__)) Q8tkWidget *dummy_0
37 #define UNUSED_PARM __attribute__((__unused__)) void *dummy_1
38 #else
39 #define UNUSED_WIDGET Q8tkWidget *dummy_0
40 #define UNUSED_PARM void *dummy_1
41 #endif
42
43
44
45 /************************************************************************/
46 /* �ǥХå������顼���� */
47 /************************************************************************/
48
49 #define Q8tkAssert(e,s) \
50 ((e) ? (void)0 : _Q8tkAssert(__FILE__, __LINE__, #e, s))
51
_Q8tkAssert(char * file,int line,char * exp,const char * s)52 static void _Q8tkAssert(char *file, int line, char *exp, const char *s)
53 {
54 fprintf(stderr, "Fatal Error | %s <%s:%d>\n", exp, file, line);
55 fprintf(stderr, "message = %s\n",(s)?s:"---");
56 quasi88_exit(-1);
57 }
58
debug_type(int type)59 static const char *debug_type(int type) {
60 switch (type) {
61 case Q8TK_TYPE_WINDOW: return "window :";
62 case Q8TK_TYPE_BUTTON: return "button :";
63 case Q8TK_TYPE_TOGGLE_BUTTON: return "t-button:";
64 case Q8TK_TYPE_CHECK_BUTTON: return "c-button:";
65 case Q8TK_TYPE_RADIO_BUTTON: return "r-button:";
66 case Q8TK_TYPE_FRAME: return "frame :";
67 case Q8TK_TYPE_LABEL: return "label :";
68 case Q8TK_TYPE_LOGO: return "logo :";
69 case Q8TK_TYPE_NOTEBOOK: return "notebook:";
70 case Q8TK_TYPE_NOTEPAGE: return "page :";
71 case Q8TK_TYPE_VBOX: return "vbox :";
72 case Q8TK_TYPE_HBOX: return "hbox :";
73 case Q8TK_TYPE_VSEPARATOR: return "vsep :";
74 case Q8TK_TYPE_HSEPARATOR: return "hsep :";
75 case Q8TK_TYPE_COMBO: return "combo :";
76 case Q8TK_TYPE_LISTBOX: return "listbox :";
77 case Q8TK_TYPE_LIST_ITEM: return "listitem:";
78 case Q8TK_TYPE_ADJUSTMENT: return "adjust :";
79 case Q8TK_TYPE_HSCALE: return "hscale :";
80 case Q8TK_TYPE_VSCALE: return "vscale :";
81 case Q8TK_TYPE_SCROLLED_WINDOW: return "scrolled:";
82 case Q8TK_TYPE_ENTRY: return "entry :";
83 case Q8TK_TYPE_DIALOG: return "dialog :";
84 case Q8TK_TYPE_FILE_SELECTION: return "f-select:";
85 }
86 return "UNDEF TYPE:";
87 }
88
89
90
91 /************************************************************************/
92 /* ��� */
93 /************************************************************************/
94
95 static int MAX_WIDGET;
96 static Q8tkWidget **widget_table;
97
98
99 static int MAX_LIST;
100 static Q8List **list_table;
101
102
103 #define MAX_WINDOW_LAYER (8)
104 static Q8tkWidget *window_layer[ MAX_WINDOW_LAYER ];
105 static int window_layer_level;
106 static Q8tkWidget *focus_widget[ MAX_WINDOW_LAYER ];
107 #define get_focus_widget() (focus_widget[ window_layer_level ])
108
109
110
111 static struct {
112 int x, y;
113 int x_old, y_old;
114 } mouse;
115
116
117 static int kanji_code = Q8TK_KANJI_ANK;
118 static int disp_cursor = FALSE;
119
120 static int now_shift_on;
121 static int now_mouse_on;
122
123 /*----------------------------------------------------------------------*/
124
125 static void widget_map(Q8tkWidget *widget);
126 static void widget_construct(void);
127 static void widget_signal_do(Q8tkWidget *widget, const char *name);
128
129
130
131 /************************************************************************/
132 /* ưŪ����γ��ݡ����� */
133 /************************************************************************/
134 /*--------------------------------------------------------------
135 * Widget
136 *--------------------------------------------------------------*/
malloc_widget(void)137 static Q8tkWidget *malloc_widget(void)
138 {
139 int i;
140 Q8tkWidget **t, *w;
141 int add;
142
143 t = NULL;
144 for (i=0; i<MAX_WIDGET; i++) {
145 if (widget_table[i] == NULL) {
146 t = &widget_table[i];
147 break;
148 }
149 }
150
151 if (t == NULL) {
152 add = 512;
153 if (MAX_WIDGET == 0) {
154 widget_table = malloc((MAX_WIDGET + add) * sizeof(Q8tkWidget*));
155 } else {
156 widget_table = realloc(widget_table,
157 (MAX_WIDGET + add) * sizeof(Q8tkWidget*));
158 }
159 if (widget_table) {
160 for (i=0; i<add; i++) {
161 widget_table[ MAX_WIDGET + i ] = NULL;
162 }
163 t = &widget_table[ MAX_WIDGET ];
164 MAX_WIDGET += add;
165 }
166 }
167
168 if (t) {
169 w = (Q8tkWidget *)calloc(1, sizeof(Q8tkWidget));
170 if (w) {
171 /* ����ͤ� �����ФȤ� 0 */
172 *t = w;
173 return w;
174 } else {
175 Q8tkAssert(FALSE, "memory exhoused");
176 }
177 }
178
179 Q8tkAssert(FALSE, "work 'widget' exhoused");
180 return NULL;
181 }
free_widget(Q8tkWidget * w)182 static void free_widget(Q8tkWidget *w)
183 {
184 int i;
185 for (i=0; i<MAX_WIDGET; i++) {
186 if (widget_table[i] == w) {
187 free(w);
188 widget_table[i] = NULL;
189 return;
190 }
191 }
192 Q8tkAssert(FALSE, "pointer is not malloced widget");
193 }
194 /*--------------------------------------------------------------
195 * List
196 *--------------------------------------------------------------*/
malloc_list(void)197 static Q8List *malloc_list(void)
198 {
199 int i;
200 Q8List **t, *l;
201 int add;
202
203 t = NULL;
204 for (i=0; i<MAX_LIST; i++) {
205 if (list_table[i] == NULL) {
206 t = &list_table[i];
207 break;
208 }
209 }
210
211 if (t == NULL) {
212 add = 512;
213 if (MAX_LIST == 0) {
214 list_table = malloc((MAX_LIST + add) * sizeof(Q8List*));
215 } else {
216 list_table = realloc(list_table,
217 (MAX_LIST + add) * sizeof(Q8List*));
218 }
219 if (list_table) {
220 for (i=0; i<add; i++) {
221 list_table[ MAX_LIST + i ] = NULL;
222 }
223 t = &list_table[ MAX_LIST ];
224 MAX_LIST += add;
225 }
226 }
227
228 if (t) {
229 l = (Q8List *)calloc(1, sizeof(Q8List));
230 if (l) {
231 *t = l;
232 return l;
233 } else {
234 Q8tkAssert(FALSE, "memory exhoused");
235 }
236 }
237
238 Q8tkAssert(FALSE, "work 'list' exhoused");
239 return NULL;
240 }
free_list(Q8List * l)241 static void free_list(Q8List *l)
242 {
243 int i;
244 for (i=0; i<MAX_LIST; i++) {
245 if (list_table[i] == l) {
246 free(l);
247 list_table[i] = NULL;
248 return;
249 }
250 }
251 Q8tkAssert(FALSE, "pointer is not malloced list");
252 }
253
254
255
256 #if 0
257 /************************************************************************/
258 /* Q8TK ���� ʸ������� */
259 /* q8_strncpy(s, ct, n) */
260 /* ʸ���� ct �� ʸ���� s �� ���ԡ����롣 */
261 /* s ��ʸ����ü�ϡ�ɬ�� '\0' �Ȥʤꡢs ��Ĺ���� n-1 ʸ�� */
262 /* �ʲ��˼��ޤ롣 */
263 /* q8_strncat(s, ct, n) */
264 /* ʸ���� ct �� ʸ���� s �� �ղä��롣 */
265 /* s ��ʸ����ü�ϡ�ɬ�� '\0' �Ȥʤꡢs ��Ĺ���� n-1 ʸ�� */
266 /* �ʲ��˼��ޤ롣 */
267 /************************************************************************/
268 static void q8_strncpy(char *s, const char *ct, size_t n)
269 {
270 strncpy(s, ct, n-1);
271 s[ n-1 ] = '\0';
272 }
273 static void q8_strncat(char *s, const char *ct, size_t n)
274 {
275 if (n > strlen(s) + 1)
276 strncat(s, ct, n - strlen(s) -1);
277 }
278 #endif
279
280
281 /************************************************************************/
282 /* �ꥹ�Ƚ��� */
283 /************************************************************************/
284 /*--------------------------------------------------------------
285 * �ꥹ�Ȥ������ˤ����餷�����Ǥ��ɲ� (�ޤ��ϥꥹ�Ȥ�����)
286 * ����ͤϡ��ꥹ�Ȥ���Ƭ
287 *--------------------------------------------------------------*/
q8_list_append(Q8List * list,void * data)288 Q8List *q8_list_append(Q8List *list, void *data)
289 {
290 Q8List *new_list;
291
292 new_list = malloc_list(); /* ������� */
293
294 if (list) { /* ��¸�Υꥹ�ȤˤĤʤ����� */
295 list = q8_list_last(list); /* �����ȥ���� */
296 list->next = new_list;
297 new_list->prev = list;
298 new_list->next = NULL;
299 }else{ /* �����Υꥹ�Ȥξ�� */
300 new_list->prev = NULL;
301 new_list->next = NULL;
302 }
303 new_list->data = data;
304
305 return q8_list_first(new_list); /* ������Υꥹ����Ƭ���֤� */
306 }
307 /*--------------------------------------------------------------
308 * �ꥹ�Ȥ�����ˤ����餷�����Ǥ��ɲ� (position==0����Ƭ)
309 * ����ͤϡ��ꥹ�Ȥ���Ƭ
310 *--------------------------------------------------------------*/
311 #if 0
312 Q8List *q8_list_insert(Q8List *list, void *data, int position)
313 {
314 /* ̤���� */
315 return NULL;
316 }
317 #endif
318 /*--------------------------------------------------------------
319 * �ꥹ�Ȥ����Ǥ�ҤȤĤ������
320 * ����ͤϡ��ꥹ�Ȥ���Ƭ
321 *--------------------------------------------------------------*/
q8_list_remove(Q8List * list,void * data)322 Q8List *q8_list_remove(Q8List *list, void *data)
323 {
324 list = q8_list_first(list);
325
326 while (list) { /* �ꥹ����Ƭ�����ˤ��ɤä� */
327 if (list->data == data) { /* data �ΰ��פ����Τ�õ�� */
328 list->prev->next = list->next; /* �ߤĤ���Х�� */
329 list->next->prev = list->prev; /* �Ĥʤ��Ѥ��� */
330 free_list(list); /* ���ȤϺ�� */
331 break;
332 }
333 list = list->next;
334 }
335
336 return q8_list_first(list); /* ������Υꥹ����Ƭ���֤� */
337 }
338 /*--------------------------------------------------------------
339 * �ꥹ�Ȥξõ�
340 *--------------------------------------------------------------*/
q8_list_free(Q8List * list)341 void q8_list_free(Q8List *list)
342 {
343 Q8List *l;
344
345 list = q8_list_first(list); /* �ꥹ�Ȥ���Ƭ���� */
346
347 while (list) { /* ���ɤ�ʤ������ */
348 l = list->next;
349 free_list(list);
350 list = l;
351 }
352 }
353 /*--------------------------------------------------------------
354 * �ꥹ����Ƭ��
355 *--------------------------------------------------------------*/
q8_list_first(Q8List * list)356 Q8List *q8_list_first(Q8List *list)
357 {
358 if (list) {
359 while (list->prev) { /* �ꥹ�Ȥ����ˤ��ɤ� */
360 list = list->prev;
361 } /* ���ɤ�ʤ��ʤä��� */
362 } /* ���줬��Ƭ */
363 return list;
364 }
365 /*--------------------------------------------------------------
366 * �ꥹ��������
367 *--------------------------------------------------------------*/
q8_list_last(Q8List * list)368 Q8List *q8_list_last(Q8List *list)
369 {
370 if (list) {
371 while (list->next) { /* �ꥹ�Ȥ��ˤ��ɤ� */
372 list = list->next;
373 } /* ���ɤ�ʤ��ʤä��� */
374 } /* ���줬���� */
375 return list;
376 }
377 /*--------------------------------------------------------------
378 * �ꥹ�ȸ���
379 *--------------------------------------------------------------*/
q8_list_find(Q8List * list,void * data)380 Q8List *q8_list_find(Q8List *list, void *data)
381 {
382 list = q8_list_first(list); /* �ꥹ�Ȥ���Ƭ���� */
383
384 while (list) { /* ���ɤ�ʤ��� */
385 if (list->data == data) break; /* ���פ����Τ�õ�� */
386 list = list->next;
387 }
388 return list;
389 }
390
391
392 /************************************************************************/
393 /* ���������� */
394 /************************************************************************/
q8tk_set_kanjicode(int code)395 int q8tk_set_kanjicode(int code)
396 {
397 int ret = kanji_code;
398
399 if (code != Q8TK_KANJI_ANK &&
400 code != Q8TK_KANJI_EUC &&
401 code != Q8TK_KANJI_SJIS &&
402 code != Q8TK_KANJI_UTF8) {
403
404 code = Q8TK_KANJI_ANK;
405 }
406
407 kanji_code = code;
408
409 return ret;
410 }
411 /************************************************************************/
412 /* ��������ɽ����̵ͭ */
413 /************************************************************************/
q8tk_set_cursor(int enable)414 void q8tk_set_cursor(int enable)
415 {
416 disp_cursor = (enable) ? TRUE : FALSE;
417 }
418
419
420
421
422
423 /************************************************************************/
424 /* ������Ƚ�λ */
425 /************************************************************************/
426
427 static int q8tk_disp_init_flag;
428 static int q8tk_main_loop_flag;
429 static int q8tk_construct_flag;
430
431 #define set_main_loop_flag(f) q8tk_main_loop_flag = (f)
432 #define get_main_loop_flag() q8tk_main_loop_flag
433 #define set_construct_flag(f) q8tk_construct_flag = (f)
434 #define get_construct_flag() q8tk_construct_flag
435
436
437 static Q8tkWidget *q8tk_drag_widget;
438 #define set_drag_widget(w) q8tk_drag_widget = (w)
439 #define get_drag_widget() q8tk_drag_widget
440
441
442
443 static void widget_focus_list_init(void);
444 static Q8tkWidget *widget_focus_list_get_next(Q8tkWidget *widget,
445 int back);
446
447
448
449 static void widget_scrollin_init(void);
450 static void widget_scrollin_register(Q8tkWidget *widget);
451 static void widget_scrollin_drawn(Q8tkWidget *widget);
452
453
454 static int delay_timer;
455 static Q8tkWidget *q8tk_delay_widget;
456 #define set_delay_widget(w, n) do { \
457 if (w == NULL) { \
458 delay_timer = 0; \
459 } else { \
460 delay_timer = n; \
461 } \
462 q8tk_delay_widget = w; \
463 } while (0)
464 #define get_delay_widget() q8tk_delay_widget
465
466
467
468
469 /*--------------------------------------------------------------
470 * �����
471 *--------------------------------------------------------------*/
q8tk_init(void)472 void q8tk_init(void)
473 {
474 int i;
475
476 MAX_WIDGET = 0;
477 widget_table = NULL;
478
479 MAX_LIST = 0;
480 list_table = NULL;
481
482 for (i=0; i<MAX_WINDOW_LAYER; i++) {
483 window_layer[i] = NULL;
484 focus_widget[i] = NULL;
485 }
486 window_layer_level = -1;
487
488 set_main_loop_flag(TRUE);
489 set_construct_flag(FALSE);
490
491 set_drag_widget(NULL);
492 widget_focus_list_init();
493 widget_scrollin_init();
494
495
496 q8gr_init();
497
498
499 mouse.x_old = mouse.x = mouse_x;
500 mouse.y_old = mouse.y = mouse_y;
501
502 now_shift_on = FALSE;
503 now_mouse_on = FALSE;
504
505 q8tk_disp_init_flag = TRUE;
506 }
507 /*--------------------------------------------------------------
508 * ��λ
509 *--------------------------------------------------------------*/
q8tk_term(void)510 static void q8tk_term(void)
511 {
512 int i;
513 for (i=0; i<MAX_WIDGET; i++) {
514 if (widget_table[i]) {
515 if (widget_table[i]->name) {
516 free(widget_table[i]->name);
517 }
518 free(widget_table[i]);
519 }
520 }
521 if (widget_table) {
522 free(widget_table);
523 }
524 widget_table = NULL;
525 MAX_WIDGET = 0;
526
527 for (i=0; i<MAX_LIST; i++) {
528 if (list_table[i]) {
529 free(list_table[i]);
530 }
531 }
532 if (list_table) {
533 free(list_table);
534 }
535 list_table = NULL;
536 MAX_LIST = 0;
537 }
538
539
540
541 /************************************************************************/
542 /* �⡼��������� */
543 /************************************************************************/
544 /*--------------------------------------------------------------
545 * �⡼��������
546 *--------------------------------------------------------------*/
q8tk_grab_add(Q8tkWidget * widget)547 void q8tk_grab_add(Q8tkWidget *widget)
548 {
549 int i;
550 Q8tkAssert(widget->type == Q8TK_TYPE_WINDOW, "grab add not window");
551
552 for (i=0; i<MAX_WINDOW_LAYER; i++) {
553 if (window_layer[i] == NULL) {
554 window_layer[i] = widget;
555 window_layer_level = i;
556 set_construct_flag(TRUE);
557 return;
558 }
559 }
560 Q8tkAssert(FALSE, "overflow window level");
561 }
562 /*--------------------------------------------------------------
563 * �⡼������
564 *--------------------------------------------------------------*/
q8tk_grab_remove(Q8tkWidget * widget)565 void q8tk_grab_remove(Q8tkWidget *widget)
566 {
567 int i;
568
569 for (i=0; i<MAX_WINDOW_LAYER; i++) {
570 if (window_layer[i] == widget) {
571 break;
572 }
573 }
574 Q8tkAssert(i < MAX_WINDOW_LAYER, "grab remove not widget");
575 for ( ; i<MAX_WINDOW_LAYER-1; i++) {
576 window_layer[i] = window_layer[i+1];
577 focus_widget[i] = focus_widget[i+1];
578 }
579 window_layer[i] = NULL;
580 focus_widget[i] = NULL;
581 window_layer_level --;
582 set_construct_flag(TRUE);
583 }
584
585
586
587 /********************************************************/
588 /* �������åȤκ��� */
589 /********************************************************/
590
591 /*---------------------------------------------------------------------------
592 * ������ɥ� (WINDOW)
593 *---------------------------------------------------------------------------
594 * �����ƤΥ������åȤκǤ����Ĥˤʤ륳��ƥʥ������åȡ�
595 * ���Ҥ��Ļ��Ƥ롣
596 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
597 * �����Υ������åȤ�ɽ������ˤϡ�q8tk_grab_add()�ˤ�����Ū��ɽ����ؼ����롣
598 * ��WINDOW �Ϻ��硢MAX_WINDOW_LAYER�ĺ����Ǥ��뤬�������ʥ������դ���Τϡ�
599 * �Ǹ�� q8tk_grab_add() ��ȯ�Ԥ���������ɥ��λ�¹�ΤߤǤ��롣
600 * ��Q8TK_WINDOW_TOPLEVEL �Υ�����ɥ���ɬ��ɬ�ס�
601 * �������ʥ�
602 * �ʤ�
603 * �����������ʥ� (�桼�������Բ�)
604 * "inactivate" �ݥåץ��åץ�����ɥ��ˤƥ�����ɥ�����å���ȯ��
605 * -------------------------------------------------------------------------
606 * Q8tkWidget *q8tk_window_new(int window_type)
607 * ������ɥ�������
608 * �����ˤ�ꡢ������ɥ��μ��ब��ޤ�
609 * Q8TK_WINDOW_TOPLEVEL �� ���ִ��äΥ�����ɥ��ǡ�ͣ��ĤΤ�
610 * ������ǽ��������ɥ��Ȥ�����ʤ�
611 * Q8TK_WINDOW_DIALOG �� �ФäѤä�������ɥ��Ȥ���
612 * Q8TK_WINDOW_POPUP �� ñ��ʥ�����ɥ��Ȥ���
613 * -------------------------------------------------------------------------
614 * ��WINDOW�ۢ��� [xxxx] ���ޤ��ޤʥ������åȤ�Ҥ˻��Ƥ�
615 *
616 *---------------------------------------------------------------------------*/
617 /* �ݥåץ��åץ�����ɥ����ϰϳ��ˤƥޥ�������å������顢�����ʥ�ȯ�� */
window_event_button_on(Q8tkWidget * widget)618 static void window_event_button_on(Q8tkWidget *widget)
619 {
620 widget_signal_do(widget, "inactivate");
621 }
622
623 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
624
q8tk_window_new(int window_type)625 Q8tkWidget *q8tk_window_new(int window_type)
626 {
627 Q8tkWidget *w;
628
629 w = malloc_widget();
630 w->type = Q8TK_TYPE_WINDOW;
631 w->attr = Q8TK_ATTR_CONTAINER;
632 w->sensitive = TRUE;
633
634 w->stat.window.type = window_type;
635
636 switch (window_type) {
637 case Q8TK_WINDOW_TOPLEVEL:
638 Q8tkAssert(window_layer[0] == NULL, "Redefine TOP window");
639 q8tk_grab_add(w);
640 w->stat.window.no_frame = TRUE;
641 break;
642
643 case Q8TK_WINDOW_DIALOG:
644 w->stat.window.no_frame = FALSE;
645 w->stat.window.shadow_type = Q8TK_SHADOW_OUT;
646 break;
647
648 case Q8TK_WINDOW_POPUP:
649 w->stat.window.no_frame = FALSE;
650 w->stat.window.shadow_type = Q8TK_SHADOW_ETCHED_OUT;
651 w->event_button_on = window_event_button_on;
652 break;
653 }
654
655 return w;
656 }
657
658
659
660
661 /*---------------------------------------------------------------------------
662 * �ܥ��� (BUTTON)
663 *---------------------------------------------------------------------------
664 * ���ޥ����ʤɤǥܥ�����Ƥ���֤ϰ��ù���ǡ��ޥ�����Υ������롣
665 * ���Ҥ��Ļ��Ƥ롣 (â������٥�ʳ��λҤ���ä�����ư���̤�ݾ�)
666 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
667 * �������ʥ�
668 * "clicked" �ܥ������줿����ȯ��
669 * -------------------------------------------------------------------------
670 * Q8tkWidget *q8tk_button_new(void)
671 * �ܥ����������
672 *
673 * Q8tkWidget *q8tk_button_new_with_label(const char *label)
674 * ʸ���� label �������줿�ܥ����������
675 * ����Ū�ˤϡ��ܥ���ȥ�٥���ꡢ�ƻҤˤ��롣
676 * -------------------------------------------------------------------------
677 * ��BUTTON�ۢ��� [LABEL] ��٥��Ҥ˻���
678 *
679 *---------------------------------------------------------------------------*/
680 /* ������ڡ��������顢�����ʥ�ȯ�� */
button_event_key_on(Q8tkWidget * widget,int key)681 static void button_event_key_on(Q8tkWidget *widget, int key)
682 {
683 if (key == Q8TK_KEY_RET || key == Q8TK_KEY_SPACE) {
684
685 #if 0 /* ���Τޤޤ��ȡ���������֤����褹��ˤ��ʤ� */
686 widget_signal_do(widget, "clicked");
687
688 #else /* ��������֤����褵�������Τǡ����٥�Ȥ��٤餻�� */
689 widget->stat.button.active = Q8TK_BUTTON_ON;
690 set_construct_flag(TRUE);
691 set_delay_widget(widget, 3); /* 3 �ե졼��ʬ�ٱ� */
692 #endif
693 }
694 }
695
696 /* �ܥ����ޥ�������å������顢�ܥ������ޤ��ơ��ɥ�å����ϤȤ��� */
button_event_button_on(Q8tkWidget * widget)697 static void button_event_button_on(Q8tkWidget *widget)
698 {
699 set_drag_widget(widget);
700
701 widget->stat.button.active = Q8TK_BUTTON_ON;
702 set_construct_flag(TRUE);
703 }
704
705 /* �ɥ�å���ϡ��ޥ����ΰ��֤˱����ơ��ܥ�����̱������� */
button_event_dragging(Q8tkWidget * widget)706 static void button_event_dragging(Q8tkWidget *widget)
707 {
708 if (q8gr_get_focus_screen(mouse.x/8, mouse.y/16) == widget) {
709 if (widget->stat.button.active == Q8TK_BUTTON_OFF) {
710 widget->stat.button.active = Q8TK_BUTTON_ON;
711 set_construct_flag(TRUE);
712 }
713 } else {
714 if (widget->stat.button.active == Q8TK_BUTTON_ON) {
715 widget->stat.button.active = Q8TK_BUTTON_OFF;
716 set_construct_flag(TRUE);
717 }
718 }
719 }
720
721 /* �ɥ�å���λ�ǡ��ܥ�����Ǥ��顢�����ʥ�ȯ�� */
button_event_drag_off(Q8tkWidget * widget)722 static void button_event_drag_off(Q8tkWidget *widget)
723 {
724 if (widget->stat.button.active == Q8TK_BUTTON_ON) {
725
726 #if 0 /* �ޥ���Ϣ�ǤǤΡ����̤�Ϣ³ɽ��������äȸ��줷�� */
727 widget->stat.button.active = Q8TK_BUTTON_OFF;
728 widget_signal_do(widget, "clicked");
729 set_construct_flag(TRUE);
730
731 #else /* ���٥�Ȥ��٤餻�뤳�Ȥǡ�Ϣ³ɽ�����ʤ��褦�ˤ��� */
732 widget->stat.button.active = Q8TK_BUTTON_OFF;
733 set_delay_widget(widget, 3); /* 3 �ե졼��ʬ�ٱ� */
734 set_construct_flag(TRUE);
735 #endif
736 }
737 }
738
739 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
740
q8tk_button_new(void)741 Q8tkWidget *q8tk_button_new(void)
742 {
743 Q8tkWidget *w;
744
745 w = malloc_widget();
746 w->type = Q8TK_TYPE_BUTTON;
747 w->attr = Q8TK_ATTR_CONTAINER;
748 w->sensitive = TRUE;
749
750 w->event_button_on = button_event_button_on;
751 w->event_key_on = button_event_key_on;
752 w->event_dragging = button_event_dragging;
753 w->event_drag_off = button_event_drag_off;
754
755 return w;
756 }
757
q8tk_button_new_with_label(const char * label)758 Q8tkWidget *q8tk_button_new_with_label(const char *label)
759 {
760 Q8tkWidget *b = q8tk_button_new();
761 Q8tkWidget *l = q8tk_label_new(label);
762
763 q8tk_widget_show(l);
764 q8tk_container_add(b, l);
765
766 b->with_label = TRUE;
767
768 return b;
769 }
770
771
772
773
774 /*---------------------------------------------------------------------------
775 * �ȥ���ܥ��� (TOGGLE BUTTON)
776 *---------------------------------------------------------------------------
777 * ���ޥ����ʤɤǥܥ�����Ȱ��ù��ࡣ�⤦���٥ܥ��������롣
778 * ���Ҥ��Ļ��Ƥ롣 (â������٥�ʳ��λҤ���ä�����ư���̤�ݾ�)
779 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
780 * �������ʥ�
781 * "clicked" �ܥ�����ư��ù��������ȯ��
782 * "toggled" �ܥ���ξ��֤��Ѳ���������ȯ��
783 * -------------------------------------------------------------------------
784 * Q8tkWidget *q8tk_toggle_button_new(void)
785 * �ȥ���ܥ����������
786 *
787 * Q8tkWidget *q8tk_toggle_button_new_with_label(const char *label)
788 * ʸ���� label �������줿����ܥ����������
789 * ����Ū�ˤϡ��ȥ���ܥ���ȥ�٥���ꡢ�ƻҤˤ��롣
790 *
791 * void q8tk_toggle_button_set_state(Q8tkWidget *widget, int status)
792 * �ܥ���ξ��֤��ѹ����롣
793 * status �����ʤ�ܥ���������֤ˤ��� (�����ʥ뤬ȯ������)��
794 * status �����ʤ�ʤˤ⤷�ʤ���
795 * -------------------------------------------------------------------------
796 * ��TOGGLE BUTTON�ۢ��� [LABEL] ��٥��Ҥ˻���
797 *
798 *---------------------------------------------------------------------------*/
799 /* �ܥ����ޥ�������å������顢�����ʥ�ȯ�� */
toggle_button_event_button_on(Q8tkWidget * widget)800 static void toggle_button_event_button_on(Q8tkWidget *widget)
801 {
802 if (widget->stat.button.active == Q8TK_BUTTON_ON) {
803 widget->stat.button.active = Q8TK_BUTTON_OFF;
804 widget_signal_do(widget, "toggled");
805 } else {
806 widget->stat.button.active = Q8TK_BUTTON_ON;
807 widget_signal_do(widget, "clicked");
808 widget_signal_do(widget, "toggled");
809 }
810 set_construct_flag(TRUE);
811 }
812
813 /* ������ڡ��������顢�ޥ�������å���Ʊ�������� */
toggle_button_event_key_on(Q8tkWidget * widget,int key)814 static void toggle_button_event_key_on(Q8tkWidget *widget, int key)
815 {
816 if (key == Q8TK_KEY_RET || key == Q8TK_KEY_SPACE) {
817 toggle_button_event_button_on(widget);
818 }
819 }
820
821 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
822
q8tk_toggle_button_new(void)823 Q8tkWidget *q8tk_toggle_button_new(void)
824 {
825 Q8tkWidget *w;
826
827 w = malloc_widget();
828 w->type = Q8TK_TYPE_TOGGLE_BUTTON;
829 w->attr = Q8TK_ATTR_CONTAINER;
830 w->sensitive = TRUE;
831
832 w->event_button_on = toggle_button_event_button_on;
833 w->event_key_on = toggle_button_event_key_on;
834
835 return w;
836 }
837
q8tk_toggle_button_new_with_label(const char * label)838 Q8tkWidget *q8tk_toggle_button_new_with_label(const char *label)
839 {
840 Q8tkWidget *b = q8tk_toggle_button_new();
841 Q8tkWidget *l = q8tk_label_new(label);
842
843 q8tk_widget_show(l);
844 q8tk_container_add(b, l);
845
846 b->with_label = TRUE;
847
848 return b;
849 }
850
q8tk_toggle_button_set_state(Q8tkWidget * widget,int status)851 void q8tk_toggle_button_set_state(Q8tkWidget *widget, int status)
852 {
853 if (status) {
854 if (widget->event_key_on) {
855 (*widget->event_key_on)(widget, Q8TK_KEY_SPACE);
856 }
857 } else {
858 widget->stat.button.active = Q8TK_BUTTON_OFF;
859 set_construct_flag(TRUE);
860 }
861 }
862
863
864
865
866 /*---------------------------------------------------------------------------
867 * �����å��ܥ��� (CHECK BUTTON)
868 *---------------------------------------------------------------------------
869 * ���ܥ�����ȡ������å��ܥå������ɤ�Ĥ֤���롣
870 * �⤦���٥ܥ��������롣
871 * ���Ҥ��Ļ��Ƥ롣 (â������٥�ʳ��λҤ���ä�����ư���̤�ݾ�)
872 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
873 * �������ʥ�
874 * "clicked" �ܥ������줿����ȯ��
875 * "toggled" �ܥ���ξ��֤��Ѳ���������ȯ��
876 * ����OFF���֤ξ��ϡ� "toggled" ��ȯ��
877 * ���� ON���֤ξ��ϡ� "clicked" �� "toggled" �ν��ȯ��
878 * -------------------------------------------------------------------------
879 * Q8tkWidget *q8tk_check_button_new(void)
880 * �����å��ܥ����������
881 *
882 * Q8tkWidget *q8tk_check_button_new_with_label(const char *label)
883 * ʸ���� label �������줿�����å��ܥ����������
884 * ����Ū�ˤϡ������å��ܥ���ȥ�٥���ꡢ�ƻҤˤ��롣
885 * -------------------------------------------------------------------------
886 * �����ܤϰ㤦������ǽŪ�ˤϥȥ���ܥ����Ʊ���Ǥ��롣
887 * �ȥ���ܥ����Ʊ�͡�q8tk_toggle_button_set_state() �ˤ�ꡢ
888 * �ܥ���������֤ˤ��뤳�Ȥ��Ǥ��� (�����ʥ뤬ȯ������)��
889 * -------------------------------------------------------------------------
890 * ��CHECK BUTTON�ۢ��� [LABEL] ��٥��Ҥ˻���
891 *
892 *---------------------------------------------------------------------------*/
check_button_event_do(Q8tkWidget * widget)893 static void check_button_event_do(Q8tkWidget *widget)
894 {
895 if (widget->stat.button.active == Q8TK_BUTTON_ON) {
896 widget->stat.button.active = Q8TK_BUTTON_OFF;
897 widget_signal_do(widget, "toggled");
898 } else {
899 widget->stat.button.active = Q8TK_BUTTON_ON;
900 widget_signal_do(widget, "clicked");
901 widget_signal_do(widget, "toggled");
902 }
903 set_construct_flag(TRUE);
904 }
905
906 /* ������ڡ��������顢�����ʥ�ȯ�� */
check_button_event_key_on(Q8tkWidget * widget,int key)907 static void check_button_event_key_on(Q8tkWidget *widget, int key)
908 {
909 if (key == Q8TK_KEY_RET || key == Q8TK_KEY_SPACE) {
910 check_button_event_do(widget);
911 }
912 }
913
914 /* �ܥ����ޥ�������å������顢�ɥ�å����ϤȤ��� */
check_button_event_button_on(Q8tkWidget * widget)915 static void check_button_event_button_on(Q8tkWidget *widget)
916 {
917 set_drag_widget(widget);
918 set_construct_flag(TRUE);
919 }
920
921 /* �ɥ�å���λ�ǡ������ʥ�ȯ�� (�ɥ�å���ϡ��ʤˤ⤷�ʤ�) */
check_button_event_drag_off(Q8tkWidget * widget)922 static void check_button_event_drag_off(Q8tkWidget *widget)
923 {
924 if (q8gr_get_focus_screen(mouse.x/8, mouse.y/16) == widget) {
925 check_button_event_do(widget);
926 }
927 }
928
929 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
930
q8tk_check_button_new(void)931 Q8tkWidget *q8tk_check_button_new(void)
932 {
933 Q8tkWidget *w;
934
935 w = malloc_widget();
936 w->type = Q8TK_TYPE_CHECK_BUTTON;
937 w->attr = Q8TK_ATTR_CONTAINER;
938 w->sensitive = TRUE;
939
940 w->event_button_on = check_button_event_button_on;
941 w->event_key_on = check_button_event_key_on;
942 w->event_drag_off = check_button_event_drag_off;
943
944 return w;
945 }
946
q8tk_check_button_new_with_label(const char * label)947 Q8tkWidget *q8tk_check_button_new_with_label(const char *label)
948 {
949 Q8tkWidget *b = q8tk_check_button_new();
950 Q8tkWidget *l = q8tk_label_new(label);
951
952 q8tk_widget_show(l);
953 q8tk_container_add(b, l);
954
955 b->with_label = TRUE;
956
957 return b;
958 }
959
960
961
962
963 /*---------------------------------------------------------------------------
964 * �饸���ܥ��� (RADIO BUTTON)
965 *---------------------------------------------------------------------------
966 * �������Ĥ��Υ饸���ܥ���Ʊ�Τǥ��롼�ԥǤ��롣
967 * ���ܥ�����ȥ����å�����뤬��Ʊ�����롼�ԥ��줿
968 * ¾�Υ饸���ܥ���ϡ������å�������롣
969 * ���Ҥ��Ļ��Ƥ롣 (â������٥�ʳ��λҤ���ä�����ư���̤�ݾ�)
970 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
971 * �������ʥ�
972 * "clicked" �ܥ������줿����ȯ��
973 * "toggled" �ܥ���ξ��֤��Ѳ���������ȯ��
974 * -------------------------------------------------------------------------
975 * Q8tkWidget *q8tk_radio_button_new(Q8tkWidget *group)
976 * �饸���ܥ����������
977 * Ʊ�����롼�פȤ���饸���ܥ���������Ϳ���롣(�ǽ�Υܥ���ʤ� NULL)
978 * �ǽ�Υܥ������å�����롣���ʹߤΥܥ���ϥ����å�������롣
979 * �ʲ��ϡ�3�ĤΥ饸���ܥ��������������
980 * button[0] = q8tk_radio_button_new(NULL);
981 * button[1] = q8tk_radio_button_new(button[0]);
982 * button[2] = q8tk_radio_button_new(button[1]);
983 *
984 * Q8tkWidget *q8tk_radio_button_new_with_label(Q8List *list,
985 * const char *label)
986 * ʸ���� label �������줿�饸���ܥ����������
987 * ����Ū�ˤϡ��饸���ܥ���ȥ�٥���ꡢ�ƻҤˤ��롣
988 * -------------------------------------------------------------------------
989 * ���롼�ԥ���Ƥ��뤬����ǽŪ�ˤϥȥ���ܥ����Ʊ���Ǥ��롣
990 * �ȥ���ܥ����Ʊ�͡�q8tk_toggle_button_set_state() �ˤ�ꡢ
991 * �ܥ���������֤ˤ��뤳�Ȥ��Ǥ��롣�ʤ������λ����롼�ԥ��줿
992 * ���٤ƤΥ饸���ܥ���� "toggled" �����ʥ뤬ȯ�����롣
993 * -------------------------------------------------------------------------
994 * ��RADIO BUTTON�ۢ��� [LABEL] ��٥��Ҥ˻���
995 * �� LIST ��Ƭ���������ݻ�
996 * ���������������������� LIST
997 * ����
998 * ��RADIO BUTTON�ۢ��� [LABEL] �á�
999 * �� �â�
1000 * ���������������������� LIST
1001 *
1002 * �ƥ饸���ܥ������Ω�����������åȤǤ��뤬���ꥹ�Ⱦ���ˤ�ꥰ�롼�פ�
1003 * �ʤ��Ƥ��롣�ƥ饸���ܥ���ϡ����Υꥹ�Ȥ���Ƭ���������ݻ����Ƥ��롣
1004 * �ܥ�����ȥ��롼�פ��������Ƥ������������åȤ˥����ʥ뤬ȯ�����롣
1005 *
1006 *---------------------------------------------------------------------------*/
radio_button_event_do(Q8tkWidget * widget)1007 static void radio_button_event_do(Q8tkWidget *widget)
1008 {
1009 Q8List *list;
1010
1011 /* ��ʬ���Ȥ� clicked �����ʥ��ȯ�� */
1012 widget_signal_do(widget, "clicked");
1013 if (widget->stat.button.active == Q8TK_BUTTON_ON) return;
1014
1015 /* �ꥹ�ȤɤäƼ�ʬ�ʳ��Υܥ��� */
1016 list = widget->stat.button.list; /* �դˤ��� toggled �����ʥ�ȯ�� */
1017 while (list) {
1018 if (list->data != widget) {
1019 ((Q8tkWidget *)(list->data))->stat.button.active = Q8TK_BUTTON_OFF;
1020 widget_signal_do((Q8tkWidget *)(list->data), "toggled");
1021 }
1022 list = list->next;
1023 }
1024 /* ���Ȥ�ܥ�������Ѳ��ʤ� */
1025 /* toggled �����ʥ�ȯ�� */
1026 widget->stat.button.active = Q8TK_BUTTON_ON;
1027
1028 widget_signal_do(widget, "toggled");
1029
1030 set_construct_flag(TRUE);
1031 }
1032
1033 /* ������ڡ��������顢�����ʥ�ȯ�� */
1034 /* ����/�������������顢��/��Υ饸���ܥ���ˡ��ե���������ư */
radio_button_event_key_on(Q8tkWidget * widget,int key)1035 static void radio_button_event_key_on(Q8tkWidget *widget, int key)
1036 {
1037 if (key == Q8TK_KEY_RET || key == Q8TK_KEY_SPACE) {
1038 radio_button_event_do(widget);
1039 }
1040
1041 #ifdef OLD_FOCUS_CHANGE
1042 /* DO NOTHING */
1043 #else /* �����ʥե���������ư���� */
1044 if (key == Q8TK_KEY_LEFT ||
1045 key == Q8TK_KEY_UP ||
1046 key == Q8TK_KEY_RIGHT ||
1047 key == Q8TK_KEY_DOWN) {
1048
1049 #if 0 /* OFF���֤ǥե�����������ξ�硢�������륭���ǥܥ����Ȥߤʤ� */
1050 if (widget->stat.button.active == FALSE) {
1051 radio_button_event_do(widget);
1052 }
1053 else
1054 #endif
1055 {
1056 Q8List *list = q8_list_find(widget->stat.button.list, widget);
1057
1058 if (list) {
1059 if (key == Q8TK_KEY_LEFT ||
1060 key == Q8TK_KEY_UP) {
1061 if (list->prev == NULL) list = q8_list_last(list);
1062 else list = list->prev;
1063 } else {
1064 if (list->next == NULL) list = q8_list_first(list);
1065 else list = list->next;
1066 }
1067 if (list) {
1068 q8tk_widget_set_focus((Q8tkWidget *)(list->data));
1069 #if 0 /* ����/�������������顢��/��Υ饸���ܥ�����Ȥߤʤ� */
1070 radio_button_event_do((Q8tkWidget *)(list->data));
1071 #endif
1072 }
1073 }
1074 }
1075 }
1076 #endif
1077 }
1078
1079 /* �ܥ����ޥ�������å������顢�ɥ�å����ϤȤ��� */
radio_button_event_button_on(Q8tkWidget * widget)1080 static void radio_button_event_button_on(Q8tkWidget *widget)
1081 {
1082 set_drag_widget(widget);
1083 set_construct_flag(TRUE);
1084 }
1085
1086 /* �ɥ�å���λ�ǡ������ʥ�ȯ�� (�ɥ�å���ϡ��ʤˤ⤷�ʤ�) */
radio_button_event_drag_off(Q8tkWidget * widget)1087 static void radio_button_event_drag_off(Q8tkWidget *widget)
1088 {
1089 if (q8gr_get_focus_screen(mouse.x/8, mouse.y/16) == widget) {
1090 radio_button_event_do(widget);
1091 }
1092 }
1093
1094 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1095
q8tk_radio_button_new(Q8tkWidget * group)1096 Q8tkWidget *q8tk_radio_button_new(Q8tkWidget *group)
1097 {
1098 Q8tkWidget *w;
1099 Q8List *list;
1100
1101 w = malloc_widget();
1102 w->type = Q8TK_TYPE_RADIO_BUTTON;
1103 w->attr = Q8TK_ATTR_CONTAINER;
1104 w->sensitive = TRUE;
1105
1106 w->key_up_used = TRUE;
1107 w->key_down_used = TRUE;
1108 w->key_left_used = TRUE;
1109 w->key_right_used = TRUE;
1110
1111 w->event_button_on = radio_button_event_button_on;
1112 w->event_key_on = radio_button_event_key_on;
1113 w->event_drag_off = radio_button_event_drag_off;
1114
1115 if (group == NULL) { /* �ǽ��1���� */
1116 list = NULL;
1117 w->stat.button.active = TRUE;
1118 } else { /* 2���ܰʹ� */
1119 list = group->stat.button.list;
1120 w->stat.button.active = FALSE;
1121 }
1122 w->stat.button.list = q8_list_append(list, w);
1123
1124 return w;
1125 }
1126
q8tk_radio_button_new_with_label(Q8tkWidget * group,const char * label)1127 Q8tkWidget *q8tk_radio_button_new_with_label(Q8tkWidget *group,
1128 const char *label)
1129 {
1130 Q8tkWidget *b = q8tk_radio_button_new(group);
1131 Q8tkWidget *l = q8tk_label_new(label);
1132
1133 q8tk_widget_show(l);
1134 q8tk_container_add(b, l);
1135
1136 b->with_label = TRUE;
1137
1138 return b;
1139 }
1140
q8tk_radio_button_get_list(Q8tkWidget * group)1141 Q8List *q8tk_radio_button_get_list(Q8tkWidget *group)
1142 {
1143 return group->stat.button.list;
1144 }
1145
1146
1147
1148
1149 /*---------------------------------------------------------------------------
1150 * ����ܥܥå��� (COMBO BOX)
1151 *---------------------------------------------------------------------------
1152 * ������ȥ��ΰ����ġ�
1153 * ���Ҥϻ��Ƥʤ���
1154 * ��q8tk_combo_append_popdown_strings() �ˤ�ꡢ����ʸ������٥�˻��ä�
1155 * �ꥹ�ȥ����ƥ���������������롣����ϰ�������Υݥåץ��åץ�����ɥ�
1156 * �ˤ�ɽ������롣
1157 * �������ʥ�
1158 * "activate" �ꥹ�ȥ����ƥब���줿���Ȥˤ�ꡢ
1159 * ����ȥ��ΰ��ʸ������ѹ������ä�����ȯ��
1160 * �ʤ���������ȥ����ˤƥ�������Ϥ����ä�����ȯ��
1161 * "changed" ����ȥ����ˤ�ʸ�����ϡ�ʸ����������ä�����ȯ��
1162 * -------------------------------------------------------------------------
1163 * Q8tkWidget *q8tk_combo_new(void)
1164 * ����ܥܥå������������������ϡ����Ϥ��ԲĤˤʤäƤ��롣
1165 *
1166 * void q8tk_combo_append_popdown_strings(Q8tkWidget *combo,
1167 * const char *entry_str,
1168 * const char *disp_str)
1169 * ����������Υݥåץ��åץ�����ɥ��������뤿��Ρ��ꥹ�ȥ����ƥ��
1170 * �������롣���Υꥹ�ȥ����ƥ�ϡ� disp_str ��ʸ������٥�˻��ġ�
1171 * ����������Υݥåץ��åץ�����ɥ��ˤƤ��Υꥹ�ȥ����ƥब����
1172 * ���줿��硢 ����ܥܥå����Υ���ȥ��ΰ�� entry_str �����å�
1173 * ����롣("activate"�����ʥ뤬ȯ������)
1174 * disp_str == NULL �ξ��ϡ� disp_str �� entry_str ��Ʊ���ˤʤ롣
1175 *
1176 * const char *q8tk_combo_get_text(Q8tkWidget *combo)
1177 * ����ȥ��ΰ�����Ϥ���Ƥ���ʸ������֤�
1178 *
1179 * void q8tk_combo_set_text(Q8tkWidget *combo, const char *text)
1180 * ʸ�����ȥ��ΰ�����ꤹ�� (�����ʥ��ȯ�����ʤ�)��
1181 *
1182 * void q8tk_combo_set_editable(Q8tkWidget *combo, int editable)
1183 * ����ȥ��ΰ�����ϲġ��ԲĤ����ꤹ�롣 editable �� ���ʤ����ϲġ�
1184 *
1185 * void q8tk_misc_set_size(Q8tkWidget *widget, int width, int height)
1186 * ����ܥܥå�����ɽ�������� width ����ꤹ�롣 height ��̵����
1187 * -------------------------------------------------------------------------
1188 * ��COMBO BOX��
1189 * ��
1190 * ��������ENTRY��
1191 *
1192 * q8tk_combo_append_popdown_strings �ˤ� LIST ITEM �� LABEL ���������롣
1193 *
1194 * ��COMBO BOX��
1195 * �� ��
1196 * �� ��������ENTRY��
1197 * ��
1198 * ���������� LIST ����LIST ITEM�ۢ�����LABEL��
1199 * ����
1200 * LIST ����LIST ITEM�ۢ�����LABEL��
1201 * ����
1202 * LIST ����LIST ITEM�ۢ�����LABEL��
1203 * ����
1204 *
1205 * ����ܥܥå������ޥ����ǥ���å������ȡ��ʲ��Τ褦�ʥ�����ɥ�
1206 * (Q8TK_WINDOW_POPUP) ��ưŪ�������������Υ�����ɥ��� q8tk_grab_add()
1207 * ����롣�Ĥޤꡢ���Υ�����ɥ��ؤ����ʳ��ϡ�����ʤ��ʤ롣
1208 *
1209 * ��WINDOW�ۢ�����LIST BOX�ۢ�����LIST ITEM�ۢ�����LABEL��
1210 * �� ����
1211 * �� �� ��LIST ITEM�ۢ�����LABEL��
1212 * �� ����
1213 * �� �� ��LIST ITEM�ۢ�����LABEL��
1214 * �� ����
1215 * ��
1216 * ������ACCEL GROUP�ۢ�����ACCEL KEY�� �� ��BUTTON(���ߡ�)��
1217 *
1218 * ���� LIST ITEM �� LABEL �� q8tk_combo_append_popdown_strings() �ˤ�
1219 * ��ư�������줿�ꥹ�ȥ����ƥ� (�ȥ�٥�) �Ǥ��롣
1220 *
1221 * �ꥹ�ȥ����ƥ�Τ����줫��Ĥ������ȡ������Ǽ�ư��������
1222 * �������å�(�ꥹ�ȥ����ƥ�Ͻ���)�����ƺ�����졢��Ȥ�ɽ������롣
1223 * ���λ��������ꥹ�ȥ����ƥ�λ���ʸ��������ȥ��ΰ��
1224 * ���åȤ��졢Ʊ���˥����ʥ뤬ȯ�����롣
1225 *
1226 * ESC�����������줿���⡢����ɽ������롣(���ξ������������ʥ�ʤ�)
1227 * �����¸����뤿��˥�������졼�����������Ѥ��Ƥ��뤬����������졼��
1228 * �����ϡ��������åȤ˥����ʥ�����뤳�Ȥ�������ʤ��Τǡ����ߡ��Υܥ���
1229 * (��ɽ��) ���������ơ����Υܥ���˥����ʥ������褦�ˤ��Ƥ��롣
1230 * ���Υܥ���ϥ����ʥ�ȼ�����ȡ����ƤΥ������åȤ������롣
1231 *
1232 * �ꥹ�Ȥ�Ĺ���ʤä���硢�ꥹ�ȥܥå�����ɽ�������̤˼��ޤ�ʤ����Ȥ�
1233 * ����Τǡ����ξ��� WINDOW �� LIST BOX �δ֤˥�������ɥ�����ɥ�
1234 * ���������롣(���̤˼��ޤ뤫�ɤ�����Ƚ�ǤϷ빽�����ø�)
1235 *
1236 *---------------------------------------------------------------------------*/
1237
1238 /* �ݥåץ��åץ�����ɥ��ǡ�LIST ITEM ���� or ESC�������� or ������ɥ�����
1239 �ޥ�������å��������Υ�����Хå��ؿ����ݥåץ��åץ�����ɥ��������� */
combo_fake_callback(UNUSED_WIDGET,Q8tkWidget * parent)1240 static void combo_fake_callback(UNUSED_WIDGET, Q8tkWidget *parent)
1241 {
1242 Q8List *l;
1243
1244 l = parent->stat.combo.list; /* l->data �� LIST ITEM */
1245 while (l) {
1246 q8tk_signal_handlers_destroy((Q8tkWidget *)(l->data));
1247 l = l->next;
1248 }
1249
1250 q8tk_grab_remove(parent->stat.combo.popup_window);
1251
1252 if (parent->stat.combo.popup_scrolled_window)
1253 q8tk_widget_destroy(parent->stat.combo.popup_scrolled_window);
1254
1255 /* LIST BOX �Ϻ�����뤬�� LIST ITEM �Ϻ�������˻Ĥ� */
1256 q8tk_widget_destroy(parent->stat.combo.popup_list);
1257 q8tk_widget_destroy(parent->stat.combo.popup_window);
1258 q8tk_widget_destroy(parent->stat.combo.popup_fake);
1259 q8tk_widget_destroy(parent->stat.combo.popup_accel_group);
1260 }
1261
1262 /* �ݥåץ��åץ�����ɥ��� LIST ITEM ��ޥ�������å��������Υ�����Хå� */
combo_event_list_callback(Q8tkWidget * list_item,Q8tkWidget * parent)1263 static void combo_event_list_callback(Q8tkWidget *list_item,
1264 Q8tkWidget *parent)
1265 {
1266 if (strcmp(parent->stat.combo.entry->name, list_item->child->name) == 0) {
1267 /* ���ߤ����Ϥȡ������ꥹ�Ȥ�ʸ����Ʊ���ʤΤǡ������ʥ��̵�� */
1268 } else {
1269 /* ���ߤ����Ϥȡ������ꥹ�Ȥ�ʸ����Ʊ���ʤΤǡ������ʥ��̵�� */
1270 q8tk_entry_set_text(parent->stat.combo.entry,
1271 list_item->child->name);
1272 widget_signal_do(parent, "activate");
1273 }
1274
1275 combo_fake_callback(NULL, parent);
1276 }
1277
1278 /* ����ܤΰ���ɽ���ܥ����ޥ�������å������顢�ݥåץ��åץ�����ɥ����� */
combo_event_button_on(Q8tkWidget * widget)1279 static void combo_event_button_on(Q8tkWidget *widget)
1280 {
1281 int selected = FALSE;
1282 Q8List *l;
1283 int scrolled = FALSE;
1284 int y_pos = widget->y + 1; /* �ݥåץ��åץ�����ɥ�ɽ������ */
1285
1286 widget->stat.combo.popup_window = q8tk_window_new(Q8TK_WINDOW_POPUP);
1287 widget->stat.combo.popup_scrolled_window = NULL;
1288 widget->stat.combo.popup_list = q8tk_listbox_new();
1289
1290 l = widget->stat.combo.list; /* l->data �� LIST ITEM */
1291 while (l) {
1292 q8tk_container_add(widget->stat.combo.popup_list,
1293 (Q8tkWidget *)(l->data));
1294
1295 /* ����ȥ��ʸ����ΰ��פ���ꥹ�ȥ����ƥ��������֤Ȥ��롣 */
1296 /* q8tk_listbox_select_child()�ϥ����ʥ�ȯ������Τǥ����ʥ���Ͽ���˽��� */
1297 if (selected == FALSE) { /* l->data->child �� LABEL */
1298 if (strcmp(widget->stat.combo.entry->name,
1299 ((Q8tkWidget*)(l->data))->child->name) == 0) {
1300 q8tk_listbox_select_child(widget->stat.combo.popup_list,
1301 (Q8tkWidget*)(l->data));
1302 selected = TRUE;
1303 }
1304 }
1305
1306 q8tk_signal_connect((Q8tkWidget *)(l->data), "select",
1307 combo_event_list_callback, widget);
1308 l = l->next;
1309 }
1310
1311
1312 q8tk_widget_show(widget->stat.combo.popup_list);
1313
1314
1315 #if 1
1316 if (widget->y + widget->stat.combo.nr_items + 2 <= (24+1)) {
1317 /* ������ɽ�����Ƥ⡢���̤���Ϥ߽Ф��ʤ� (�̾�� WINDOW ����)*/
1318
1319 scrolled = FALSE;
1320 y_pos = widget->y + 1;
1321
1322 } else if (widget->y - widget->stat.combo.nr_items - 2 >= (0-1)) {
1323 /* ������ɽ������С����̤���Ϥ߽Ф��ʤ� (�̾�� WINDOW ����)*/
1324
1325 scrolled = FALSE;
1326 y_pos = widget->y - widget->stat.combo.nr_items - 2;
1327
1328 } else {
1329 /* �ɤä���ɽ�����Ƥ⡢���̤���Ϥ߽Ф� (SCROLLED WINDOW ����)*/
1330
1331 if (widget->y <= 25/2) { /* �����Τۤ��������Τǡ�������ɽ�� */
1332 scrolled = TRUE;
1333 y_pos = widget->y + 1;
1334 } else { /* �����Τۤ��������Τǡ�������ɽ�� */
1335 scrolled = TRUE;
1336 y_pos = 0-1;
1337 }
1338 }
1339
1340 if (scrolled) { /* SCROLLED WINDOW �� */
1341 int height;
1342
1343 if (y_pos > widget->y) height = (24+1) - 2 - widget->y; /* ���� */
1344 else height = widget->y - 2 +1; /* ���� */
1345 if (height < 3) height = 3; /* ���ꤨ�ʤ�����ǰ�ΰ� */
1346
1347 widget->stat.combo.popup_scrolled_window =
1348 q8tk_scrolled_window_new(NULL, NULL);
1349 q8tk_container_add(widget->stat.combo.popup_scrolled_window,
1350 widget->stat.combo.popup_list);
1351
1352 /* �岼�ǡ������ƥ��֤�ITEM��ɽ�����֤��Ѥ��Ƥ⤤�����⡣�������� */
1353 q8tk_listbox_set_placement(widget->stat.combo.popup_list, +1, +1);
1354
1355 q8tk_scrolled_window_set_policy(
1356 widget->stat.combo.popup_scrolled_window,
1357 Q8TK_POLICY_AUTOMATIC, Q8TK_POLICY_ALWAYS);
1358
1359 if (widget->stat.combo.width) {
1360 q8tk_misc_set_size(widget->stat.combo.popup_scrolled_window,
1361 widget->stat.combo.width +3, height);
1362 } else {
1363 q8tk_misc_set_size(widget->stat.combo.popup_scrolled_window,
1364 widget->stat.combo.length +3, height);
1365 }
1366
1367 q8tk_widget_show(widget->stat.combo.popup_scrolled_window);
1368 q8tk_container_add(widget->stat.combo.popup_window,
1369 widget->stat.combo.popup_scrolled_window);
1370
1371 } else { /* �Ρ��ޥ� WINDOW �ξ�� */
1372
1373 q8tk_container_add(widget->stat.combo.popup_window,
1374 widget->stat.combo.popup_list);
1375
1376 }
1377
1378 #else
1379 /* ���̤���Ϥ߽Ф����ʻ��ϡ�SCROLLED WINDOW ������ */
1380 if (widget->y + widget->stat.combo.nr_items + 2 > (24+1)) {
1381
1382 int height = (24+1) - 2 - widget->y;
1383 if (height < 3) height = 3;
1384
1385 widget->stat.combo.popup_scrolled_window =
1386 q8tk_scrolled_window_new(NULL, NULL);
1387 q8tk_container_add(widget->stat.combo.popup_scrolled_window,
1388 widget->stat.combo.popup_list);
1389
1390 q8tk_scrolled_window_set_policy(
1391 widget->stat.combo.popup_scrolled_window,
1392 Q8TK_POLICY_AUTOMATIC, Q8TK_POLICY_ALWAYS);
1393
1394 if (widget->stat.combo.width) {
1395 q8tk_misc_set_size(widget->stat.combo.popup_scrolled_window,
1396 widget->stat.combo.width +3, height);
1397 } else {
1398 q8tk_misc_set_size(widget->stat.combo.popup_scrolled_window,
1399 widget->stat.combo.length +3, height);
1400 }
1401
1402 q8tk_widget_show(widget->stat.combo.popup_scrolled_window);
1403 q8tk_container_add(widget->stat.combo.popup_window,
1404 widget->stat.combo.popup_scrolled_window);
1405
1406 } else { /* �̾�ϥ���ץ�� WINDOW ������ */
1407
1408 q8tk_container_add(widget->stat.combo.popup_window,
1409 widget->stat.combo.popup_list);
1410
1411 }
1412 #endif
1413
1414 q8tk_widget_show(widget->stat.combo.popup_window);
1415 q8tk_grab_add(widget->stat.combo.popup_window);
1416 q8tk_widget_set_focus(widget->stat.combo.popup_list);
1417
1418 if (widget->stat.combo.width) {
1419 q8tk_misc_set_size(widget->stat.combo.popup_list,
1420 widget->stat.combo.width, 0);
1421 }
1422
1423 widget->stat.combo.popup_window->stat.window.set_position = TRUE;
1424 widget->stat.combo.popup_window->stat.window.x =
1425 widget->x -1 -((widget->stat.combo.popup_scrolled_window)?1:0);
1426 widget->stat.combo.popup_window->stat.window.y =
1427 y_pos;
1428
1429 q8tk_signal_connect(widget->stat.combo.popup_window,
1430 "inactivate", combo_fake_callback,widget);
1431
1432
1433 /* ESC �����������ꥹ�Ȥ�õ�뤿��Ρ����ߡ������� */
1434
1435 widget->stat.combo.popup_fake = q8tk_button_new();
1436 q8tk_signal_connect(widget->stat.combo.popup_fake, "clicked",
1437 combo_fake_callback, widget);
1438
1439 widget->stat.combo.popup_accel_group = q8tk_accel_group_new();
1440 q8tk_accel_group_attach(widget->stat.combo.popup_accel_group,
1441 widget->stat.combo.popup_window);
1442 q8tk_accel_group_add(widget->stat.combo.popup_accel_group, Q8TK_KEY_ESC,
1443 widget->stat.combo.popup_fake, "clicked");
1444 }
1445
1446 /* ������ڡ��������顢����ɽ���ܥ���ޥ�������å���Ʊ��������*/
1447 /* ����������������Ʊ�� */
combo_event_key_on(Q8tkWidget * widget,int key)1448 static void combo_event_key_on(Q8tkWidget *widget, int key)
1449 {
1450 if (key == Q8TK_KEY_RET || key == Q8TK_KEY_SPACE) {
1451 combo_event_button_on(widget);
1452 }
1453
1454 #ifdef OLD_FOCUS_CHANGE
1455 /* DO NOTHING */
1456 #else /* �����ʥե���������ư���� */
1457 if (key == Q8TK_KEY_UP || key == Q8TK_KEY_DOWN) {
1458 combo_event_button_on(widget);
1459 }
1460 #endif
1461 }
1462
1463 /* ����ȥ��������Ϥ����ä��Ȥ��������ʥ�ȯ�� */
combo_event_entry_activate(UNUSED_WIDGET,Q8tkWidget * parent)1464 static void combo_event_entry_activate(UNUSED_WIDGET, Q8tkWidget *parent)
1465 {
1466 widget_signal_do(parent, "activate");
1467 }
combo_event_entry_changed(UNUSED_WIDGET,Q8tkWidget * parent)1468 static void combo_event_entry_changed(UNUSED_WIDGET, Q8tkWidget *parent)
1469 {
1470 widget_signal_do(parent, "changed");
1471 }
1472
1473
q8tk_combo_new(void)1474 Q8tkWidget *q8tk_combo_new(void)
1475 {
1476 Q8tkWidget *w;
1477
1478 w = malloc_widget();
1479 w->type = Q8TK_TYPE_COMBO;
1480 w->sensitive = TRUE;
1481
1482 w->key_up_used = TRUE;
1483 w->key_down_used = TRUE;
1484
1485 w->stat.combo.entry = q8tk_entry_new();
1486 w->stat.combo.list = NULL;
1487 w->stat.combo.width = 0;
1488 w->stat.combo.length = 0;
1489
1490 w->stat.combo.entry->stat.entry.combo = w;
1491
1492 q8tk_combo_set_editable(w, FALSE);
1493 q8tk_widget_show(w->stat.combo.entry);
1494 q8tk_signal_connect(w->stat.combo.entry, "activate",
1495 combo_event_entry_activate, w);
1496 q8tk_signal_connect(w->stat.combo.entry, "changed",
1497 combo_event_entry_changed, w);
1498
1499 w->event_button_on = combo_event_button_on;
1500 w->event_key_on = combo_event_key_on;
1501
1502 return w;
1503 }
q8tk_combo_append_popdown_strings(Q8tkWidget * combo,const char * entry_str,const char * disp_str)1504 void q8tk_combo_append_popdown_strings(Q8tkWidget *combo,
1505 const char *entry_str,
1506 const char *disp_str)
1507 {
1508 int l0, l1, l2;
1509 Q8tkWidget *list_item;
1510
1511 if (combo->stat.combo.list == NULL) { /* ǰ�Τ������� */
1512 combo->stat.combo.length = 0;
1513 combo->stat.combo.nr_items = 0;
1514 }
1515
1516 /* ʸ����Ĺ������å� */
1517
1518 if (entry_str == NULL) entry_str = "";
1519 if (disp_str == NULL) disp_str = entry_str;
1520
1521 l0 = combo->stat.combo.length;
1522 l1 = (disp_str) ? q8gr_strlen(kanji_code, disp_str) : 0;
1523 l2 = q8gr_strlen(kanji_code, entry_str)
1524 + ((combo->stat.combo.entry->stat.entry.editable) ? +1 : 0);
1525
1526 combo->stat.combo.length = Q8TKMAX(Q8TKMAX(l0, l1), l2);
1527
1528
1529 /* ��٥��դ� LIST ITEM �������������Υݥ���ꥹ�Ȥ��ݻ� */
1530
1531 list_item = q8tk_list_item_new_with_label(disp_str);
1532 q8tk_widget_show(list_item);
1533 q8tk_list_item_set_string(list_item, entry_str);
1534
1535 combo->stat.combo.list = q8_list_append(combo->stat.combo.list, list_item);
1536 combo->stat.combo.nr_items ++;
1537
1538
1539 /* ����ܤ��������ˡ�����ʸ����å� */
1540
1541 q8tk_entry_set_text(combo->stat.combo.entry, entry_str);
1542
1543 if (combo->stat.combo.width) {
1544 q8tk_misc_set_size(combo->stat.combo.entry,
1545 combo->stat.combo.width, 0);
1546 } else {
1547 q8tk_misc_set_size(combo->stat.combo.entry,
1548 combo->stat.combo.length, 0);
1549 }
1550 }
1551
1552 #if 0
1553 void q8tk_combo_clear_popdown_strings(Q8tkWidget *combo,
1554 int start, int end)
1555 {
1556 /* ̤���� */
1557 }
1558 #endif
1559
q8tk_combo_get_text(Q8tkWidget * combo)1560 const char *q8tk_combo_get_text(Q8tkWidget *combo)
1561 {
1562 return combo->stat.combo.entry->name;
1563 }
1564
q8tk_combo_set_text(Q8tkWidget * combo,const char * text)1565 void q8tk_combo_set_text(Q8tkWidget *combo, const char *text)
1566 {
1567 q8tk_entry_set_text(combo->stat.combo.entry, text);
1568 }
1569
q8tk_combo_set_editable(Q8tkWidget * combo,int editable)1570 void q8tk_combo_set_editable(Q8tkWidget *combo, int editable)
1571 {
1572 q8tk_entry_set_editable(combo->stat.combo.entry, editable);
1573 }
1574
1575
1576
1577
1578 /*---------------------------------------------------------------------------
1579 * �ꥹ�ȥܥå��� (LIST BOX)
1580 *---------------------------------------------------------------------------
1581 * ����ľ�ܥå����Τ褦�ʥ������åȡ�
1582 * ��ʣ���λҤ��Ƥ롣 â�����ꥹ�ȥ����ƥ�ʳ��λҤ���äƤϤ����ʤ���
1583 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
1584 * �Ҥϡ�q8tk_container_add() ��ƤӽФ������֤˲��ز��ؤ��¤�Ǥ�����
1585 * ���ꥹ�ȥ����ƥ�Τ����줫��Ĥ�������֤ˤ��뤳�Ȥ��Ǥ��롣
1586 * (����ʤ��ˤ��뤳�Ȥ�Ǥ��뤬��ʣ����������֤ˤ��뤳�ȤϤǤ��ʤ�)
1587 * �������ʥ�
1588 * "selection_change" �ꥹ�ȥ����ƥ��ޥ�������å���������
1589 * ����������֤ȤʤäƤ���ꥹ�ȥ����ƥब
1590 * �Ѳ�������ȯ�����롣
1591 * -------------------------------------------------------------------------
1592 * Q8tkWidget *q8tk_listbox_new(void)
1593 * �ꥹ�ȥܥå�����������
1594 *
1595 * void q8tk_listbox_clear_items(Q8tkWidget *wlist, int start, int end)
1596 * �ҤΥꥹ�ȥ����ƥ�������롣
1597 * �ꥹ�ȥ����ƥ�ϡ�q8tk_container_add()��ƤӽФ������ 0 ������ֹ椬
1598 * ������Τǡ������ֹ�ǡ��������ꥹ�ȥ����ƥ����ꤹ�롣
1599 * end �� start ���⾮�������ϡ����ƤΥꥹ�ȥ����ƥब�������롣
1600 * ��������ꥹ�ȥ����ƥ�Ͼ��Ǥ���ΤǸ夫������Ѥ��뤳�ȤϤǤ��ʤ���
1601 * ������Ѥ��������ϤҤȤĤ��� q8tk_container_remove() �ˤƺ�����٤���
1602 *
1603 * void q8tk_listbox_select_item(Q8tkWidget *wlist, int item)
1604 * item ���ֹ�Υꥹ�ȥ����ƥ��������֤ˤ��� (�����ʥ뤬ȯ������)��
1605 *
1606 * void q8tk_listbox_select_child(Q8tkWidget *wlist, Q8tkWidget *child)
1607 * child �Υꥹ�ȥ����ƥ��������֤ˤ��� (�����ʥ뤬ȯ������)��
1608 *
1609 * void q8tk_misc_set_size(Q8tkWidget *widget, int width, int height)
1610 * �ꥹ�ȥܥå�����ɽ�������� width ����ꤹ�롣 height ��̵����
1611 *
1612 * void q8tk_listbox_set_placement(Q8tkWidget *widget,
1613 * int top_pos, int left_pos)
1614 * �ꥹ�ȥܥå�������������ɥ�����ɥ��λҤǤ����硢�ꥹ�ȥܥå�����
1615 * �ҤΥꥹ�ȥ����ƥ�Τ����������ƥ��֤ʤ�Τ��������륤��褦��
1616 * ɽ�����֤�Ĵ������뤬������Ĵ�����֤���ꤹ�롣
1617 * top_pos �����ξ��ϡ������ƥ��֤ʤ�Τ�������ɥ������ˡ�
1618 * ��ξ��ϡ������ƥ��֤ʤ�Τ�������ɥ������ˡ�ɽ�������
1619 * �褦��Ĵ������롣�ͤ������ͤ��礭���ʤ�ۤɡ�������ɥ����
1620 * ����ɽ������롣
1621 * left_pos �����ξ��ϡ��ꥹ�ȥ����ƥ����Ƭ������ξ��ϡ�
1622 * �ꥹ�ȥ����ƥ��������ɽ�������褦��Ĵ������롣�ͤ������ͤ�
1623 * �ط��ʤ���
1624 * �ͤ� 0 �ξ�� (�ǥե����) �ϡ� -1 �Ȥߤʤ���롣(�Ĥޤꡢ
1625 * ������ɥ������˥����ƥ��������ɽ�������褦��Ĵ�������)
1626 * -------------------------------------------------------------------------
1627 * ��LIST BOX�ۢ��� [LIST ITEM] ���� [LABEL] �ꥹ�ȥ����ƥ� (�ȡ�
1628 * �� ���� ��٥�) ��Ҥ˻���
1629 * �� �� [LIST ITEM] ���� [LABEL]
1630 * �� ����
1631 * ����-> �� [LIST ITEM] ���� [LABEL]
1632 * �������� ����
1633 * �ˤ� �� [LIST ITEM] ���� [LABEL]
1634 * �����줫�� ����
1635 * ������֤�
1636 * ����
1637 * �ġġ� �� ���줿 LIST ITEM �� �ޥ�������å����줿���Ȥˤʤ�
1638 *
1639 *
1640 * �ꥹ�ȥܥå�������������ɥ�����ɥ��λҤǤ����硢��������
1641 * ������ɥ��˥ե�������������ľ���˥ꥹ�ȥܥå����˥ե���������
1642 * �ܤ롣����ˤ�ꡢ�ꥹ�ȥܥå����ϥ������Ϥ�����Ĥ���褦�ˤʤ롣
1643 *
1644 * �������Ϥˤơ�����ꥹ�ȥ����ƥ��������硢
1645 * ���Υꥹ�ȥ����ƥब�ޥ����ǥ���å����줿�Τ�Ʊ��ư��롣
1646 *
1647 * q8tk_listbox_select_item() ��q8tk_listbox_select_child() ��
1648 * �ꥹ�ȥ����ƥ���������Ȥ�ư��㤦������
1649 *
1650 *---------------------------------------------------------------------------*/
1651
1652 static void list_scroll_adjust(Q8tkWidget *widget);
1653
1654 /* ʸ�����������顢����ʸ������Ƭ�ˤ�ĥꥹ�ȥ����ƥब�����ƥ��֤ˤ��� */
1655 /* �������������顢�岼�Υꥹ�ȥ����ƥ���ƥ��֤ˤ��� */
1656 /* ���ڡ��������������顢���Υꥹ�ȥ����ƥ������ (�����ʥ�ȯ��) */
list_event_key_on(Q8tkWidget * widget,int key)1657 static void list_event_key_on(Q8tkWidget *widget, int key)
1658 {
1659 Q8tkWidget *w = widget->stat.listbox.active;
1660
1661 if (w) {
1662 if (key <= 0xff &&
1663 isgraph(key)) { /* ���ڡ����ʳ���ʸ�������Ϥ��줿��� */
1664
1665 Q8tkWidget *active = w;
1666 for (;;) { /* �����ƥ��֤ʥꥹ�ȥ����ƥ����� */
1667 w = w->next; /* �Υꥹ�ȥ����ƥ�Ρ���(��٥�)�� */
1668 if (w == NULL) { /* ��Ƭʸ���ȥ������ϤΤ����פ����� */
1669 w = widget->child; /* ��缡õ���Ƥ������ꥹ�ȥ����ƥ�� */
1670 } /* �����μ�����Ƭ����ꡢ���٤Ƥ�õ�� */
1671
1672 if (w == active || w == NULL) break; /* �ʤ���Ф������� */
1673
1674 if (w->child) {
1675 if ((w->name && w->name[0] == key) ||
1676 (w->child->name && w->child->name[0] == key)) {
1677 /* ���Ĥ��ä��� */
1678 widget->stat.listbox.active = w;/* ������ƥ��֤�*/
1679
1680 list_scroll_adjust(widget); /* ɽ�����֤�Ĵ�� */
1681 break;
1682 }
1683 }
1684 }
1685
1686 } else { /* ���ڡ���������ʸ�������Ϥ��줿��� */
1687 switch (key) {
1688
1689 case Q8TK_KEY_RET:
1690 case Q8TK_KEY_SPACE:
1691 (*w->event_button_on)(w);
1692 break;
1693
1694 case Q8TK_KEY_UP:
1695 if (w->prev) {
1696 widget->stat.listbox.active = w->prev;
1697 /* 1�������ƥ��� */
1698 list_scroll_adjust(widget); /* ɽ�����֤�Ĵ�� */
1699 }
1700 break;
1701 case Q8TK_KEY_DOWN:
1702 if (w->next) {
1703 widget->stat.listbox.active = w->next;
1704 /* 1�ĸ���ƥ��� */
1705 list_scroll_adjust(widget); /* ɽ�����֤�Ĵ�� */
1706 }
1707 break;
1708
1709 case Q8TK_KEY_PAGE_UP:
1710 if (widget->parent &&
1711 widget->parent->type == Q8TK_TYPE_SCROLLED_WINDOW &&
1712 widget->parent->stat.scrolled.vscrollbar) {
1713
1714 int h = widget->parent->stat.scrolled.height -1;
1715 if (widget->stat.scrolled.hscrollbar) h -= 3;
1716 else h -= 2;
1717 for ( ; h>0; h--) {
1718 if (w->prev == NULL) break;
1719 w = w->prev;
1720 }
1721 widget->stat.listbox.active = w;
1722 /* 1�������ƥ��� */
1723 list_scroll_adjust(widget); /* ɽ�����֤�Ĵ�� */
1724 }
1725 break;
1726 case Q8TK_KEY_PAGE_DOWN:
1727 if (widget->parent &&
1728 widget->parent->type == Q8TK_TYPE_SCROLLED_WINDOW &&
1729 widget->parent->stat.scrolled.vscrollbar) {
1730
1731 int h = widget->parent->stat.scrolled.height -1;
1732 if (widget->stat.scrolled.hscrollbar) h -= 3;
1733 else h -= 2;
1734 for ( ; h>0; h--) {
1735 if (w->next == NULL) break;
1736 w = w->next;
1737 }
1738 widget->stat.listbox.active = w;
1739 /* 1�Ǹ���ƥ��� */
1740 list_scroll_adjust(widget); /* ɽ�����֤�Ĵ�� */
1741 }
1742 break;
1743 }
1744 }
1745 }
1746 }
1747
1748
1749
list_scroll_adjust(Q8tkWidget * widget)1750 static void list_scroll_adjust(Q8tkWidget *widget)
1751 {
1752 int i;
1753 Q8tkWidget *c;
1754
1755 if (widget->parent &&
1756 widget->parent->type == Q8TK_TYPE_SCROLLED_WINDOW) {
1757
1758 c = widget->child;
1759 for (i=0; c ;i++) {
1760 if (c == widget->stat.listbox.active) break;
1761 c = c->next;
1762 }
1763
1764 if (i < widget->parent->stat.scrolled.child_y0) {
1765 Q8TK_ADJUSTMENT(widget->parent->stat.scrolled.vadj)->value = i;
1766 }
1767 else if (i >= widget->parent->stat.scrolled.child_y0
1768 + widget->parent->stat.scrolled.child_sy) {
1769 Q8TK_ADJUSTMENT(widget->parent->stat.scrolled.vadj)->value
1770 = i -widget->parent->stat.scrolled.child_sy +1;
1771 }
1772 }
1773 set_construct_flag(TRUE);
1774 }
1775
1776
1777
1778
1779
q8tk_listbox_new(void)1780 Q8tkWidget *q8tk_listbox_new(void)
1781 {
1782 Q8tkWidget *w;
1783
1784 w = malloc_widget();
1785 w->type = Q8TK_TYPE_LISTBOX;
1786 w->attr = Q8TK_ATTR_CONTAINER;
1787 w->sensitive = TRUE;
1788
1789 w->key_up_used = TRUE;
1790 w->key_down_used = TRUE;
1791
1792 w->event_key_on = list_event_key_on;
1793
1794 w->stat.listbox.selected = NULL;
1795 w->stat.listbox.active = NULL;
1796
1797 return w;
1798 }
1799
q8tk_listbox_clear_items(Q8tkWidget * wlist,int start,int end)1800 void q8tk_listbox_clear_items(Q8tkWidget *wlist, int start, int end)
1801 {
1802 int i, count;
1803 Q8tkWidget *wk, *c = wlist->child;
1804
1805 if (c == NULL) return;
1806 if (start < 0) return;
1807
1808 if (end < start) count = -1;
1809 else count = end - start +1;
1810
1811 for (i=0; i<start; i++) { /* �Ҥ� LIST ITEM �� start�� */
1812 if ((c = c->next) == NULL) return; /* �ܤޤǽ�ˤ��ɤ� */
1813 }
1814 while (count) { /* �������� end���ܤޤǤ� */
1815 wk = c->next; /* �ڤ�Υ�� */
1816 q8tk_container_remove(wlist, c); /* LIST ITEM �� LABEL*/
1817 q8tk_widget_destroy(c); /* ��쵤�˺������ */
1818 if ((c = wk) == NULL) break;
1819 if (count > 0) count --;
1820 }
1821
1822 set_construct_flag(TRUE);
1823 }
1824
1825 static /* LIST BOX �˷Ҥ��ä� LIST �Ρ� name �� s �˰��פ����Τ�õ�� */
q8tk_listbox_search_items(Q8tkWidget * wlist,const char * s)1826 Q8tkWidget *q8tk_listbox_search_items(Q8tkWidget *wlist, const char *s)
1827 {
1828 Q8tkWidget *c = wlist->child;
1829
1830 for (;;) {
1831 if (c == NULL) return NULL;
1832
1833 if (c->name &&
1834 strcmp(c->name, s) == 0) return c;
1835
1836 c = c->next;
1837 }
1838 }
1839
q8tk_listbox_select_item(Q8tkWidget * wlist,int item)1840 void q8tk_listbox_select_item(Q8tkWidget *wlist, int item)
1841 {
1842 int i;
1843 Q8tkWidget *c = wlist->child;
1844
1845 if (c == NULL) return;
1846
1847 if (item < 0) c = NULL;
1848 else {
1849 for (i=0; i<item; i++) {
1850 if ((c = c->next) == NULL) break;
1851 }
1852 }
1853
1854 q8tk_listbox_select_child(wlist, c);
1855 }
1856
q8tk_listbox_select_child(Q8tkWidget * wlist,Q8tkWidget * child)1857 void q8tk_listbox_select_child(Q8tkWidget *wlist, Q8tkWidget *child)
1858 {
1859 if (wlist->stat.listbox.selected != child) {
1860 wlist->stat.listbox.selected = child;
1861 wlist->stat.listbox.active = child;
1862 widget_signal_do(wlist, "selection_changed");
1863 set_construct_flag(TRUE);
1864 }
1865 if (child) {
1866 widget_signal_do(child, "select");
1867 widget_scrollin_register(child);
1868 }
1869 }
1870
q8tk_listbox_set_placement(Q8tkWidget * widget,int top_pos,int left_pos)1871 void q8tk_listbox_set_placement(Q8tkWidget *widget,
1872 int top_pos, int left_pos)
1873 {
1874 widget->stat.listbox.scrollin_top = top_pos;
1875 widget->stat.listbox.scrollin_left = left_pos;
1876 }
1877
1878
1879 /*
1880 * ����Ϥ���ä��ü������
1881 * LIST BOX �� SCROLLED WINDOW �λҤξ��ǡ�SCROLLED WINDOW �Υ�������
1882 * �С�(������) ��ư�����줿�Ȥ������δؿ����ƤФ�롣
1883 * �����Ǥϡ�SCROLLED WINDOW ��ɽ���ϰϤ˱����ơ�LIST BOX �� active
1884 * �������åȤ��ѹ����Ƥ��롣
1885 */
list_event_window_scrolled(Q8tkWidget * swin,int sy)1886 static void list_event_window_scrolled(Q8tkWidget *swin, int sy)
1887 {
1888 Q8tkWidget *widget = swin->child; /* == LISTBOX */
1889
1890 Q8tkWidget *c = widget->child;
1891 int nth = 0;
1892
1893 if (c == NULL) return;
1894
1895 while (c) {
1896 if (c == widget->stat.listbox.active) break;
1897 nth ++;
1898 c = c->next;
1899 }
1900 nth = nth - swin->stat.scrolled.vadj->stat.adj.value;
1901
1902 if (0 <= nth && nth < sy) {
1903 /* Ok, No Adjust */
1904 } else {
1905
1906 if (nth < 0) nth = swin->stat.scrolled.vadj->stat.adj.value;
1907 else nth = swin->stat.scrolled.vadj->stat.adj.value + sy -1;
1908
1909 c = widget->child;
1910 while (nth--) {
1911 if ((c = c->next) == NULL) return;
1912 }
1913 widget->stat.listbox.active = c;
1914 set_construct_flag(TRUE);
1915
1916 }
1917 }
1918
1919
1920
1921
1922 /*---------------------------------------------------------------------------
1923 * �ꥹ�ȥ����ƥ� (LIST ITEM)
1924 *---------------------------------------------------------------------------
1925 * ���ꥹ�ȥܥå����λҤˤʤ�롣
1926 * ���Ҥ��Ļ��Ƥ롣 (â������٥�ʳ��λҤ���ä�����ư���̤�ݾ�)
1927 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
1928 * ��������ʸ������ݻ��Ǥ��롣
1929 * �������ʥ�
1930 * "select" ����å������� (���Ǥ����줿���֤Ǥ�ȯ��)
1931 * �ƤΥꥹ�ȥܥå�����������֤Ȥ��Ƥ���Τ����Ȥ�̵��
1932 * ��硢��˿Ƥ� "selection_changed" ���٥�Ȥ�ȯ��������
1933 * -------------------------------------------------------------------------
1934 * Q8tkWidget *q8tk_list_item_new(void)
1935 * �ꥹ�ȥ����ƥ��������
1936 *
1937 * Q8tkWidget *q8tk_list_item_new_with_label(const char *label)
1938 * ʸ���� label �������줿�ꥹ�ȥ����ƥ��������
1939 * ����Ū�ˤϡ��ꥹ�ȥ����ƥ�ȥ�٥���ꡢ�ƻҤˤ��롣
1940 *
1941 * void q8tk_list_item_set_string(Q8tkWidget *w, const char *str)
1942 * ������ʸ���� str ���ݻ����롣
1943 * -------------------------------------------------------------------------
1944 * [LIST BOX] ���� ��LIST ITEM�ۢ��� [LABEL] ��٥��Ҥ˻���
1945 * �Ƥϡ��ꥹ�ȥܥå���
1946 * �� ��
1947 * �� ��
1948 * "selection_change" ��
1949 * �� "select"
1950 * ���ġġġġġ� ��
1951 * ��˿Ƥ� ��
1952 * ���Ť��� �ܥ��������
1953 *
1954 *---------------------------------------------------------------------------*/
1955 /* �ꥹ�ȥ����ƥ��ޥ�������å������顢�����ʥ�ȯ�� */
list_item_event_button_on(Q8tkWidget * widget)1956 static void list_item_event_button_on(Q8tkWidget *widget)
1957 {
1958 if (widget->parent) {
1959 q8tk_widget_set_focus(widget->parent);
1960
1961 if (widget->parent->stat.listbox.selected != widget) {
1962 widget->parent->stat.listbox.selected = widget;
1963 widget->parent->stat.listbox.active = widget;
1964
1965 #if 0 /* ���Τޤޤ��ȡ��������֤����褹��ˤ��ʤ� */
1966 widget_signal_do(widget->parent, "selection_changed");
1967
1968 #else /* �������֤����褵�������Τǡ����٥�Ȥ��٤餻�� */
1969 set_delay_widget(widget, 6); /* 6 �ե졼��ʬ�ٱ� */
1970 return;
1971 #endif
1972 }
1973 }
1974 widget_signal_do(widget, "select");
1975 set_construct_flag(TRUE);
1976 }
1977
q8tk_list_item_new(void)1978 Q8tkWidget *q8tk_list_item_new(void)
1979 {
1980 Q8tkWidget *w;
1981
1982 w = malloc_widget();
1983 w->type = Q8TK_TYPE_LIST_ITEM;
1984 w->attr = Q8TK_ATTR_CONTAINER | Q8TK_ATTR_LABEL_CONTAINER;
1985 w->sensitive = TRUE;
1986
1987 w->event_button_on = list_item_event_button_on;
1988
1989 return w;
1990 }
1991
q8tk_list_item_new_with_label(const char * label)1992 Q8tkWidget *q8tk_list_item_new_with_label(const char *label)
1993 {
1994 Q8tkWidget *i = q8tk_list_item_new();
1995 Q8tkWidget *l = q8tk_label_new(label);
1996
1997 q8tk_widget_show(l);
1998 q8tk_container_add(i, l);
1999
2000 i->with_label = TRUE;
2001
2002 return i;
2003 }
2004
q8tk_list_item_set_string(Q8tkWidget * w,const char * str)2005 void q8tk_list_item_set_string(Q8tkWidget *w, const char *str)
2006 {
2007 if (w->name) free(w->name);
2008 w->name = (char *)malloc(strlen(str)+1);
2009
2010 Q8tkAssert(w->name, "memory exhoused");
2011
2012 strcpy(w->name, str);
2013 w->code = kanji_code;
2014 }
2015
2016
2017
2018
2019 /*---------------------------------------------------------------------------
2020 * ��٥� (LABEL)
2021 *---------------------------------------------------------------------------
2022 * ��(ɽ���Ѥ�)ʸ������ݻ��Ǥ���
2023 * �����ޤ��ޤʥ���ƥʤλҤˤʤ롣
2024 * �������ʥ� �� ̵��
2025 * -------------------------------------------------------------------------
2026 * Q8tkWidget *q8tk_label_new(const char *label)
2027 * ʸ���� label ���ĥ�٥��������
2028 *
2029 * void q8tk_label_set(Q8tkWidget *w, const char *label)
2030 * ��٥��ʸ����� label ���ѹ����롣
2031 *
2032 * void q8tk_label_set_reverse(Q8tkWidget *w, int reverse)
2033 * ��٥��ʸ�����ȿžɽ�������ꤹ�롣 reverse �����ʤ�ȿž���롣
2034 *
2035 * void q8tk_label_set_color(Q8tkWidget *w, int foreground)
2036 * ��٥��ʸ����ο������ꤹ�롣���� foreground �����ꤹ�롣�ͤ�
2037 * Q8GR_PALETTE_xxxx �ǻ��ꤹ�롣�����ͤ���ʤ顢�ǥե���Ȥο����᤹��
2038 * -------------------------------------------------------------------------
2039 * ��LABEL�� �Ҥϻ��Ƥʤ�
2040 *
2041 *---------------------------------------------------------------------------*/
q8tk_label_new(const char * label)2042 Q8tkWidget *q8tk_label_new(const char *label)
2043 {
2044 Q8tkWidget *w;
2045
2046 if (label == NULL) label = "";
2047
2048 w = malloc_widget();
2049 w->type = Q8TK_TYPE_LABEL;
2050 w->name = (char *)malloc(strlen(label) + 1);
2051 w->sensitive = TRUE;
2052
2053 Q8tkAssert(w->name, "memory exhoused");
2054
2055 strcpy(w->name, label);
2056 w->code = kanji_code;
2057
2058 w->stat.label.foreground = Q8GR_PALETTE_FOREGROUND;
2059 w->stat.label.background = Q8GR_PALETTE_BACKGROUND;
2060 w->stat.label.reverse = FALSE;
2061
2062 return w;
2063 }
q8tk_label_set(Q8tkWidget * w,const char * label)2064 void q8tk_label_set(Q8tkWidget *w, const char *label)
2065 {
2066 if (label == NULL) label = "";
2067
2068 if (w->name) free(w->name);
2069 w->name = (char *)malloc(strlen(label) + 1);
2070
2071 Q8tkAssert(w->name, "memory exhoused");
2072
2073 strcpy(w->name, label);
2074 w->code = kanji_code;
2075
2076 set_construct_flag(TRUE);
2077 }
q8tk_label_set_reverse(Q8tkWidget * w,int reverse)2078 void q8tk_label_set_reverse(Q8tkWidget *w, int reverse)
2079 {
2080 if (w->stat.label.reverse != reverse) {
2081 w->stat.label.reverse = reverse;
2082 set_construct_flag(TRUE);
2083 }
2084 }
q8tk_label_set_color(Q8tkWidget * w,int foreground)2085 void q8tk_label_set_color(Q8tkWidget *w, int foreground)
2086 {
2087 if (foreground < 0) foreground = Q8GR_PALETTE_FOREGROUND;
2088
2089 if (w->stat.label.foreground != foreground) {
2090 w->stat.label.foreground = foreground;
2091 set_construct_flag(TRUE);
2092 }
2093 }
2094
2095
2096 /*---------------------------------------------------------------------------
2097 * �� (LOGO)
2098 *---------------------------------------------------------------------------
2099 * �������ȥ����ɽ���Ǥ���(����,�������ϸ���)
2100 * �����ޤ��ޤʥ���ƥʤλҤˤʤ롣
2101 * �������ʥ� �� ̵��
2102 * -------------------------------------------------------------------------
2103 * Q8tkWidget *q8tk_logo_new(void)
2104 * ����������
2105 *
2106 * -------------------------------------------------------------------------
2107 * ��LOGO�� �Ҥϻ��Ƥʤ�
2108 *
2109 *---------------------------------------------------------------------------*/
q8tk_logo_new(void)2110 Q8tkWidget *q8tk_logo_new(void)
2111 {
2112 Q8tkWidget *w;
2113
2114 w = malloc_widget();
2115 w->type = Q8TK_TYPE_LOGO;
2116 w->sensitive = TRUE;
2117
2118 return w;
2119 }
2120
2121
2122 /*---------------------------------------------------------------------------
2123 * �ե졼�� (FRAME)
2124 *---------------------------------------------------------------------------
2125 * ���Ҥ�ҤȤĤ�Ƥ롣
2126 * ���Ҥ���Ĥˤϡ�q8tk_container_add() ����Ѥ��롣
2127 * ��(���Ф���)ʸ������ݻ��Ǥ��롣
2128 * �������ʥ� �� ̵��
2129 * -------------------------------------------------------------------------
2130 * Q8tkWidget *q8tk_frame_new(const char *label)
2131 * ʸ���� label �Ф��ˤ�ĥե졼���������
2132 * void q8tk_frame_set_shadow_type(Q8tkWidget *frame, int shadow_type)
2133 * �ե졼��μ��������Ǥ��롣
2134 * Q8TK_SHADOW_NONE �����Τʤ��ե졼��
2135 * Q8TK_SHADOW_IN ���Τ��ؤ�����ե졼��
2136 * Q8TK_SHADOW_OUT ���Τ�����夬�ä��ե졼��
2137 * Q8TK_SHADOW_ETCHED_IN �Ȥ��ؤ�����ե졼��
2138 * Q8TK_SHADOW_ETCHED_OUT �Ȥ�����夬�ä��ե졼��
2139 * -------------------------------------------------------------------------
2140 * ��FRAME�� ���� [xxxx] �����ʻҤ����Ƥ�
2141 *
2142 *---------------------------------------------------------------------------*/
q8tk_frame_new(const char * label)2143 Q8tkWidget *q8tk_frame_new(const char *label)
2144 {
2145 Q8tkWidget *w;
2146
2147 w = malloc_widget();
2148 w->type = Q8TK_TYPE_FRAME;
2149 w->attr = Q8TK_ATTR_CONTAINER;
2150 w->sensitive = TRUE;
2151
2152 w->stat.frame.shadow_type = Q8TK_SHADOW_OUT;
2153
2154 w->name = (char *)malloc(strlen(label) + 1);
2155
2156 Q8tkAssert(w->name, "memory exhoused");
2157
2158 strcpy(w->name, label);
2159 w->code = kanji_code;
2160
2161 return w;
2162 }
2163
q8tk_frame_set_shadow_type(Q8tkWidget * frame,int shadow_type)2164 void q8tk_frame_set_shadow_type(Q8tkWidget *frame, int shadow_type)
2165 {
2166 frame->stat.frame.shadow_type = shadow_type;
2167 }
2168
2169
2170
2171
2172 /*---------------------------------------------------------------------------
2173 * ��ʿ�ܥå��� (HBOX)
2174 *---------------------------------------------------------------------------
2175 * ��ʣ���λҤ��Ƥ롣
2176 * ���Ҥ���Ĥˤϡ�q8tk_box_pack_start() / _end ()����Ѥ��롣
2177 * �������ʥ� �� ̵��
2178 * -------------------------------------------------------------------------
2179 * Q8tkWidget *q8tk_hbox_new(void)
2180 * ��ʿ�ܥå�����������
2181 * -------------------------------------------------------------------------
2182 * ��HBOX�ۢ��� [xxxx] �����ʻҤ����Ƥ�
2183 * ����
2184 * �� [xxxx]
2185 * ����
2186 * �� [xxxx]
2187 * ����
2188 *
2189 *---------------------------------------------------------------------------*/
q8tk_hbox_new(void)2190 Q8tkWidget *q8tk_hbox_new(void)
2191 {
2192 Q8tkWidget *w;
2193
2194 w = malloc_widget();
2195 w->type = Q8TK_TYPE_HBOX;
2196 w->attr = Q8TK_ATTR_CONTAINER;
2197 w->sensitive = TRUE;
2198
2199 return w;
2200 }
2201
2202
2203
2204
2205 /*---------------------------------------------------------------------------
2206 * ��ľ�ܥå��� (VBOX)
2207 *---------------------------------------------------------------------------
2208 * ��ʣ���λҤ��Ƥ롣
2209 * ���Ҥ���Ĥˤϡ�q8tk_box_pack_start() / _end ()����Ѥ��롣
2210 * �������ʥ� �� ̵��
2211 * -------------------------------------------------------------------------
2212 * Q8tkWidget *q8tk_vbox_new(void)
2213 * ��ľ�ܥå�����������
2214 * -------------------------------------------------------------------------
2215 * ��VBOX�ۢ��� [xxxx] �����ʻҤ����Ƥ�
2216 * ����
2217 * �� [xxxx]
2218 * ����
2219 * �� [xxxx]
2220 * ����
2221 *
2222 *---------------------------------------------------------------------------*/
q8tk_vbox_new(void)2223 Q8tkWidget *q8tk_vbox_new(void)
2224 {
2225 Q8tkWidget *w;
2226
2227 w = malloc_widget();
2228 w->type = Q8TK_TYPE_VBOX;
2229 w->attr = Q8TK_ATTR_CONTAINER;
2230 w->sensitive = TRUE;
2231
2232 return w;
2233 }
2234
2235
2236
2237
2238 /*---------------------------------------------------------------------------
2239 * �Ρ��ȥ֥å� (NOTE BOOK / NOTE PAGE)
2240 *---------------------------------------------------------------------------
2241 * ��ʣ���ΥΡ��ȥڡ������Ƥ롣
2242 * ���ƥΡ��ȥڡ����ϥ���ƥʤǤ��ꡢ�Ҥ��Ļ��Ƥ롣
2243 * ��q8tk_notebook_append() �ǻҤ���Ĥ��������٤������ǥΡ��ȥڡ�����������
2244 * ���줬�Ҥ���Ĥ��Ȥˤʤ롣
2245 * ��NOTE PAGE �ϡ�(���Ф���)ʸ������ݻ��Ǥ��롣
2246 * �������ʥ�
2247 * "switch_page" �̤Υڡ������ڤ��ؤ�ä�����ȯ��
2248 * -------------------------------------------------------------------------
2249 * Q8tkWidget *q8tk_notebook_new(void)
2250 * �Ρ��ȥܥå�������
2251 *
2252 * void q8tk_notebook_append(Q8tkWidget *notebook,
2253 * Q8tkWidget *widget, const char *label)
2254 * �Ρ��ȥ֥å� noteboot �˿����ʥڡ�����������롣
2255 * ���Υڡ����� widget ���ɲä��롣���Ф���ʸ����� label��
2256 * ����Ū�ˤϡ��Ρ��ȥڡ������ꡢ�ƻҤˤ��������Ǥ���ˡ�
2257 * �Ρ��ȥڡ����� wiget ��ƻҤˤ��롢
2258 *
2259 * int q8tk_notebook_current_page(Q8tkWidget *notebook)
2260 * ���ߤΥڡ����ֹ��������롣
2261 * �ʤ����Ρ��ȥ֥å��˥ڡ������ɲä�����ˡ�0 ������ֹ椬�����롣
2262 * �����ڡ������ɲä��Ƥ��ʤ����� -1 ��
2263 *
2264 * void q8tk_notebook_set_page(Q8tkWidget *notebook, int page_num)
2265 * �Ρ��ȥ֥å��Υڡ�������ꤹ��(�����ʥ뤬ȯ������)��
2266 *
2267 * void q8tk_notebook_next_page(Q8tkWidget *notebook)
2268 * �Ρ��ȥ֥å��Υڡ������Ǥˤ���(�����ʥ뤬ȯ������)��
2269 *
2270 * void q8tk_notebook_prev_page(Q8tkWidget *notebook)
2271 * �Ρ��ȥ֥å��Υڡ��������Ǥˤ���(�����ʥ뤬ȯ������)��
2272 * -------------------------------------------------------------------------
2273 * ��NOTE BOOK�ۢ�����NOTE PAGE�ۢ��� [xxxx] �Ρ��ȥڡ�����Ҥ˻���
2274 * ���� ����˥Ρ��ȥڡ�����
2275 * �� ��NOTE PAGE�ۢ��� [xxxx] �����ʻҤ����Ƥ�
2276 * ����
2277 * �� ��NOTE PAGE�ۢ��� [xxxx]
2278 * ����
2279 *
2280 *---------------------------------------------------------------------------*/
q8tk_notebook_new(void)2281 Q8tkWidget *q8tk_notebook_new(void)
2282 {
2283 Q8tkWidget *w;
2284
2285 w = malloc_widget();
2286 w->type = Q8TK_TYPE_NOTEBOOK;
2287 w->attr = Q8TK_ATTR_CONTAINER;
2288 w->sensitive = TRUE;
2289
2290 w->stat.notebook.page = NULL;
2291
2292 return w;
2293 }
2294
2295 /* �Ρ��ȥڡ����Υ�����ޥ�������å������顢�����ʥ�ȯ�� */
notepage_event_button_on(Q8tkWidget * widget)2296 static void notepage_event_button_on(Q8tkWidget *widget)
2297 {
2298 if ((widget->parent)->stat.notebook.page != widget) {
2299 (widget->parent)->stat.notebook.page = widget;
2300 widget_signal_do(widget->parent, "switch_page");
2301
2302 /* �Ρ��ȥڡ�������ľ��ϡ��ե�������(��������饤��)ɽ�����ʤ� */
2303 /* �������ʤ�Ȥʤ���ɽ�������å�������������Τǡ����� */
2304 if ((widget->parent)->stat.notebook.lost_focus) {
2305 q8tk_widget_set_focus(NULL);
2306 }
2307
2308 set_construct_flag(TRUE);
2309 }
2310 }
2311
2312 /* ������ڡ��������顢�ޥ�������å���Ʊ�������� */
2313 /* �������������顢����Υڡ����ǤΡ��ޥ�������å���Ʊ�������� */
notepage_event_key_on(Q8tkWidget * widget,int key)2314 static void notepage_event_key_on(Q8tkWidget *widget, int key)
2315 {
2316 if (key == Q8TK_KEY_RET || key == Q8TK_KEY_SPACE) {
2317 notepage_event_button_on(widget);
2318 }
2319
2320 #ifdef OLD_FOCUS_CHANGE
2321 /* DO NOTHING */
2322 #else /* �����ʥե���������ư���� */
2323 {
2324 Q8tkWidget *w = NULL;
2325
2326 if (key == Q8TK_KEY_LEFT) {
2327 if (widget->prev == NULL) {
2328 w = widget->next;
2329 if (w) {
2330 while (w->next) {
2331 w = w->next;
2332 }
2333 }
2334 } else {
2335 w = widget->prev;
2336 }
2337 }
2338 if (key == Q8TK_KEY_RIGHT) {
2339 if (widget->next == NULL) {
2340 w = widget->prev;
2341 if (w) {
2342 while (w->prev) {
2343 w = w->prev;
2344 }
2345 }
2346 } else {
2347 w = widget->next;
2348 }
2349 }
2350
2351 if (w) {
2352 q8tk_widget_set_focus(w);
2353 notepage_event_button_on(w);
2354 }
2355 }
2356 #endif
2357 }
2358
q8tk_notebook_append(Q8tkWidget * notebook,Q8tkWidget * widget,const char * label)2359 void q8tk_notebook_append(Q8tkWidget *notebook,
2360 Q8tkWidget *widget, const char *label)
2361 {
2362 Q8tkWidget *w;
2363
2364 Q8tkAssert(notebook->type == Q8TK_TYPE_NOTEBOOK, NULL);
2365
2366 w = malloc_widget();
2367 w->type = Q8TK_TYPE_NOTEPAGE;
2368 w->attr = Q8TK_ATTR_CONTAINER;
2369 w->sensitive = TRUE;
2370
2371 w->key_left_used = TRUE;
2372 w->key_right_used = TRUE;
2373
2374 w->name = (char *)malloc(strlen(label) + 1);
2375
2376 Q8tkAssert(w->name, "memory exhoused");
2377
2378 strcpy(w->name, label);
2379 w->code = kanji_code;
2380
2381 if (notebook->child == NULL) { /* �ǽ�� NOTE PAGE �ξ���*/
2382 notebook->stat.notebook.page = w; /* ����� ������֤ˤ��� */
2383 }
2384 q8tk_box_pack_start(notebook, w); /* ����ƥʽ����� BOX��Ʊ�� */
2385
2386 q8tk_container_add(w, widget);
2387 q8tk_widget_show(w);
2388
2389 w->event_button_on = notepage_event_button_on;
2390 w->event_key_on = notepage_event_key_on;
2391 }
2392
q8tk_notebook_current_page(Q8tkWidget * notebook)2393 int q8tk_notebook_current_page(Q8tkWidget *notebook)
2394 {
2395 Q8tkWidget *child = notebook->child;
2396 int i = 0;
2397
2398 while (child) {
2399 if (child == notebook->stat.notebook.page) {
2400 return i;
2401 }
2402 child = child->next;
2403 i++;
2404 }
2405 return -1;
2406 }
2407
q8tk_notebook_set_page(Q8tkWidget * notebook,int page_num)2408 void q8tk_notebook_set_page(Q8tkWidget *notebook, int page_num)
2409 {
2410 Q8tkWidget *child = notebook->child;
2411 int i = 0;
2412
2413 while (child) {
2414 if (i == page_num) {
2415 if (notebook->stat.notebook.page != child) {
2416 q8tk_widget_set_focus(child);
2417 notepage_event_button_on(child);
2418 }
2419 break;
2420 } else {
2421 child = child->next;
2422 i++;
2423 }
2424 }
2425 }
2426
q8tk_notebook_next_page(Q8tkWidget * notebook)2427 void q8tk_notebook_next_page(Q8tkWidget *notebook)
2428 {
2429 if (notebook->child) {
2430 Q8tkWidget *page = notebook->stat.notebook.page;
2431 if (page && page->next) {
2432 q8tk_widget_set_focus(page->next);
2433 notepage_event_button_on(page->next);
2434 }
2435 }
2436 }
2437
q8tk_notebook_prev_page(Q8tkWidget * notebook)2438 void q8tk_notebook_prev_page(Q8tkWidget *notebook)
2439 {
2440 if (notebook->child) {
2441 Q8tkWidget *page = notebook->stat.notebook.page;
2442 if (page && page->prev) {
2443 q8tk_widget_set_focus(page->prev);
2444 notepage_event_button_on(page->prev);
2445 }
2446 }
2447 }
2448
q8tk_notebook_hook_focus_lost(Q8tkWidget * notebook,int focus_lost)2449 void q8tk_notebook_hook_focus_lost(Q8tkWidget *notebook,
2450 int focus_lost)
2451 {
2452 notebook->stat.notebook.lost_focus = focus_lost;
2453 }
2454
2455
2456
2457 /*---------------------------------------------------------------------------
2458 * ��ľ���ѥ졼�� (VSEPARATOR)
2459 *---------------------------------------------------------------------------
2460 * ���Ҥϻ��Ƥʤ���
2461 * ��Ĺ�������ƥ������åȤ��礭���ˤ�ꡢưŪ���Ѥ�롣
2462 * �������ʥ� �� �ʤ�
2463 * -------------------------------------------------------------------------
2464 * Q8tkWidget *q8tk_vseparator_new(void)
2465 * ��ľ���ѥ졼��������
2466 * -------------------------------------------------------------------------
2467 * ��VSEPARATOR�� �Ҥϻ��Ƥʤ�
2468 *
2469 *---------------------------------------------------------------------------*/
q8tk_vseparator_new(void)2470 Q8tkWidget *q8tk_vseparator_new(void)
2471 {
2472 Q8tkWidget *w;
2473
2474 w = malloc_widget();
2475 w->type = Q8TK_TYPE_VSEPARATOR;
2476 w->sensitive = TRUE;
2477
2478 return w;
2479 }
2480
2481
2482
2483
2484 /*---------------------------------------------------------------------------
2485 * ��ʿ���ѥ졼�� (HSEPARATOR)
2486 *---------------------------------------------------------------------------
2487 * ���Ҥϻ��Ƥʤ���
2488 * ��Ĺ�������ƥ������åȤ��礭���ˤ�ꡢưŪ���Ѥ�롣
2489 * �������ʥ� �� �ʤ�
2490 * -------------------------------------------------------------------------
2491 * Q8tkWidget *q8tk_hseparator_new(void)
2492 * ��ʿ���ѥ졼��������
2493 * -------------------------------------------------------------------------
2494 * ��VSEPARATOR�� �Ҥϻ��Ƥʤ�
2495 *
2496 *---------------------------------------------------------------------------*/
q8tk_hseparator_new(void)2497 Q8tkWidget *q8tk_hseparator_new(void)
2498 {
2499 Q8tkWidget *w;
2500
2501 w = malloc_widget();
2502 w->type = Q8TK_TYPE_HSEPARATOR;
2503 w->sensitive = TRUE;
2504
2505 return w;
2506 }
2507
2508
2509
2510
2511 /*---------------------------------------------------------------------------
2512 * �����㥹�ȥ��� (ADJUSTMENT)
2513 *---------------------------------------------------------------------------
2514 * ��ɽ���Ǥ��ʤ�
2515 * ���Ҥϻ��Ƥʤ����Ҥˤʤ뤳�Ȥ�Ǥ��ʤ���
2516 * ����������䥹������ɥ�����ɥ�����������ݤˡ�ɬ�פȤʤ롣
2517 * ñ�ȤǤϻ��Ѥ��뤳�ȤϤʤ���
2518 * �����(�ͤ��ϰ�)����ʬ(��������ʬ���礭����ʬ��2����) ����Ĥ���
2519 * ������������˸¤롣
2520 * ���������������������ϡ�����äƥ����㥹�ȥ��Ȥ��������Ƥ����Τ�
2521 * �����Τ�����Ū��
2522 * ����������ɥ�����ɥ�������������ϡ����λ��˥����㥹�ȥ��Ȥ�ư
2523 * ����������Τ�����Ū��
2524 * �������ʥ�
2525 * "value_changed" �ͤ��Ѥ�ä�����ȯ��
2526 * -------------------------------------------------------------------------
2527 * Q8tkWidget *q8tk_adjustment_new(int value, int lower, int upper,
2528 * int step_increment, int page_increment)
2529 * �����㥹�ȥ��Ȥ�������
2530 * �ͤ��ϰϤ� lower �� upper �������ͤ� value ��
2531 * �礭����ʬ�� step_increment ����������ʬ�� page_increment ��
2532 *
2533 * void q8tk_adjustment_set_value(Q8tkWidget *adj, int value)
2534 * �����㥹�ȥ��Ȥθ����ͤ����ꤹ�롣�����ʥ��ȯ�����ʤ���
2535 *
2536 * void q8tk_adjustment_clamp_page(Q8tkWidget *adj, int lower, int upper)
2537 * �ͤ��ϰϤ� lower �� upper �����ꤷ�ʤ��������λ��������ͤ��ϰϳ��ξ��
2538 * �����ͤʤ����Ǿ��ͤ����ꤵ��롣�����ʥ��ȯ�����ʤ���
2539 *
2540 * void q8tk_adjustment_set_increment(Q8tkWidget *adj,
2541 * int step_increment, int page_increment)
2542 * �礭����ʬ�ȡ���������ʬ�����ꤷ�ʤ�����
2543 *
2544 * void q8tk_adjustment_set_arrow(Q8tkWidget *adj, int arrow)
2545 * arrow �����ξ�硢�����ɽ�����롣
2546 * �ʤ������������å����줿���� �� step_increment ʬ���������롣
2547 * �ط���ʬ������å����줿���� �� page_increment ʬ���������롣
2548 *
2549 * void q8tk_adjustment_set_length(Q8tkWidget *adj, int length)
2550 *
2551 * ------------------------------------------------------------------------
2552 * ��ADJUSTMENT�� �Ҥϻ��Ƥʤ������Ҥˤ�ʤ�ʤ�
2553 *
2554 *---------------------------------------------------------------------------*/
2555 /* �����㥹�ȥ��Ȥ�Ĵ��
2556 �����㥹�ȥ��Ȥ�ޥ�������å����ɥ�å������ݤ˸ƤӽФ���� */
2557 enum {
2558 ADJ_STEP_DEC,
2559 ADJ_STEP_INC,
2560 ADJ_PAGE_DEC,
2561 ADJ_PAGE_INC,
2562 ADJ_SLIDER_DRAG
2563 };
adjustment_do(Q8tkWidget * widget,int mode)2564 static void adjustment_do(Q8tkWidget *widget, int mode)
2565 {
2566 Q8Adjust *adj = &widget->stat.adj;
2567 int value_old = adj->value;
2568 int repeat = TRUE;
2569 static int old = -1; /* �ޥ����ܥ����äѤʤ��ˤ������ˡ�
2570 ���饤�������Ԥä����褿�ꤹ��Τ��ɤ� */
2571
2572 if (now_mouse_on == FALSE) old = -1;
2573
2574 switch (mode) {
2575 case ADJ_STEP_DEC:
2576 adj->value -= adj->step_increment;
2577 if (adj->value < adj->lower) {
2578 adj->value = adj->lower;
2579 repeat = FALSE;
2580 }
2581 break;
2582 case ADJ_STEP_INC:
2583 adj->value += adj->step_increment;
2584 if (adj->value > adj->upper) {
2585 adj->value = adj->upper;
2586 repeat = FALSE;
2587 }
2588 break;
2589 case ADJ_PAGE_DEC:
2590 if (old == ADJ_PAGE_INC) {
2591 mode = -1;
2592 repeat = FALSE;
2593 break;
2594 }
2595 adj->value -= adj->page_increment;
2596 if (adj->value < adj->lower) {
2597 adj->value = adj->lower;
2598 repeat = FALSE;
2599 }
2600 break;
2601 case ADJ_PAGE_INC:
2602 if (old == ADJ_PAGE_DEC) {
2603 mode = -1;
2604 repeat = FALSE;
2605 break;
2606 }
2607 adj->value += adj->page_increment;
2608 if (adj->value > adj->upper) {
2609 adj->value = adj->upper;
2610 repeat = FALSE;
2611 }
2612 break;
2613 case ADJ_SLIDER_DRAG:
2614 set_drag_widget(widget);
2615 return;
2616 }
2617
2618 if (value_old != adj->value) {
2619 widget_signal_do(widget, "value_changed");
2620 /* �����㥹�������ǡ�LISTBOX�����줿�����㳰�����ե饰ON */
2621 adj->listbox_changed = TRUE;
2622 }
2623 set_construct_flag(TRUE);
2624
2625 if (repeat) now_mouse_on = TRUE;
2626 else now_mouse_on = FALSE;
2627
2628 old = mode;
2629 }
2630
2631 /* �����㥹�ȥ��Ȥξ�ˤƥޥ�������å������顢��Ĵ���������ʥ�ȯ�� */
adjustment_event_button_on(Q8tkWidget * widget)2632 static void adjustment_event_button_on(Q8tkWidget *widget)
2633 {
2634 Q8Adjust *adj = &widget->stat.adj;
2635 int slider_x, slider_y;
2636 int arrow_lower_x, arrow_lower_y;
2637 int arrow_upper_x, arrow_upper_y;
2638 int m_x = mouse.x / 8;
2639 int m_y = mouse.y / 16;
2640
2641 if (adj->horizontal) { /* HORIZONTAL ADJUSTMENT */
2642
2643 slider_x = adj->x + adj->pos;
2644 slider_y = adj->y;
2645
2646 if (m_y == slider_y) {
2647
2648 if (adj->arrow) {
2649 arrow_lower_x = adj->x; slider_x ++;
2650 arrow_upper_x = adj->x + adj->length +1;
2651
2652 if (m_x == arrow_lower_x) {
2653 adjustment_do(widget, ADJ_STEP_DEC); return;
2654 } else if (m_x == arrow_upper_x) {
2655 adjustment_do(widget, ADJ_STEP_INC); return;
2656 }
2657 }
2658
2659 if (m_x == slider_x) {
2660 adjustment_do(widget, ADJ_SLIDER_DRAG); return;
2661 } else if (m_x < slider_x) {
2662 adjustment_do(widget, ADJ_PAGE_DEC); return;
2663 } else {
2664 adjustment_do(widget, ADJ_PAGE_INC); return;
2665 }
2666
2667 } else {
2668 return;
2669 }
2670
2671 } else { /* VIRTICAL ADJUSTMENT */
2672
2673 slider_x = adj->x;
2674 slider_y = adj->y + adj->pos;
2675
2676 if (m_x == slider_x) {
2677
2678 if (adj->arrow) {
2679 arrow_lower_y = adj->y; slider_y ++;
2680 arrow_upper_y = adj->y + adj->length +1;
2681 if (m_y == arrow_lower_y) {
2682 adjustment_do(widget, ADJ_STEP_DEC); return;
2683 } else if (m_y == arrow_upper_y) {
2684 adjustment_do(widget, ADJ_STEP_INC); return;
2685 }
2686 }
2687
2688 if (m_y == slider_y) {
2689 adjustment_do(widget, ADJ_SLIDER_DRAG); return;
2690 } else if (m_y < slider_y) {
2691 adjustment_do(widget, ADJ_PAGE_DEC); return;
2692 } else {
2693 adjustment_do(widget, ADJ_PAGE_INC); return;
2694 }
2695
2696 } else {
2697 return;
2698 }
2699
2700 }
2701 }
2702
2703 /* �����㥹�ȥ��ȤΥ��饤������ɥ�å������顢��Ĵ���������ʥ�ȯ�� */
adjustment_event_dragging(Q8tkWidget * widget)2704 static void adjustment_event_dragging(Q8tkWidget *widget)
2705 {
2706 Q8Adjust *adj = &widget->stat.adj;
2707 int m_x = mouse.x / 8;
2708 int m_y = mouse.y / 16;
2709 int adj_x = adj->x;
2710 int adj_y = adj->y;
2711 int slider = -1;
2712
2713 if (adj->upper <= adj->lower) return;
2714
2715 if (adj->horizontal) {
2716 if (adj->arrow) adj_x ++;
2717 if (adj_x <= m_x && m_x < adj_x+adj->length) {
2718 slider = m_x - adj_x;
2719 }
2720 }else{
2721 if (adj->arrow) adj_y ++;
2722 if (adj_y <= m_y && m_y < adj_y+adj->length) {
2723 slider = m_y - adj_y;
2724 }
2725 }
2726
2727 if (slider >= 0) {
2728 float val0 = (slider -1) * adj->scale + adj->lower;
2729 float val1 = (slider ) * adj->scale + adj->lower;
2730 int val;
2731
2732 if (slider <= 0) val = adj->lower;
2733 else if (slider >= adj->length-1) val = adj->upper;
2734 else {
2735 float base = (float)(adj->upper-adj->lower) / (adj->length-1);
2736 int val2 = (int) ((int)(val1 / base) * base);
2737 if (val0 < val2 && val2 <= val1) val = val2;
2738 else val = (int) ((val0 + val1) / 2);
2739 }
2740
2741 if (adj->value != val) {
2742 adj->value = val;
2743 widget_signal_do(widget, "value_changed");
2744 /* �����㥹�������ǡ�LISTBOX�����줿�����㳰�����ե饰ON */
2745 adj->listbox_changed = TRUE;
2746 }
2747 set_construct_flag(TRUE);
2748 }
2749 }
2750
2751 /* �������륭���ʤɤ����顢�ޥ�������å���Ʊ�������� */
adjustment_event_key_on(Q8tkWidget * widget,int key)2752 static void adjustment_event_key_on(Q8tkWidget *widget, int key)
2753 {
2754 Q8Adjust *adj = &widget->stat.adj;
2755
2756 if (adj->horizontal) { /* HORIZONTAL ADJUSTMENT */
2757 if (key == Q8TK_KEY_LEFT) adjustment_do(widget, ADJ_STEP_DEC);
2758 else if (key == Q8TK_KEY_RIGHT) adjustment_do(widget, ADJ_STEP_INC);
2759 } else { /* VIRTICAL ADJUSTMENT */
2760 if (key == Q8TK_KEY_UP) adjustment_do(widget, ADJ_STEP_DEC);
2761 else if (key == Q8TK_KEY_DOWN) adjustment_do(widget, ADJ_STEP_INC);
2762 else if (key == Q8TK_KEY_PAGE_UP) adjustment_do(widget, ADJ_PAGE_DEC);
2763 else if (key == Q8TK_KEY_PAGE_DOWN)adjustment_do(widget, ADJ_PAGE_INC);
2764 }
2765
2766 /* �������륭�����äѤʤ��ˤ���ȡ�
2767 �ޥ����ܥ���β����äѤʤ����ν��������ܤ��Ƥ��ޤ��Τǡ�������ɤ� */
2768 now_mouse_on = FALSE;
2769 }
2770
q8tk_adjustment_new(int value,int lower,int upper,int step_increment,int page_increment)2771 Q8tkWidget *q8tk_adjustment_new(int value, int lower, int upper,
2772 int step_increment, int page_increment)
2773 {
2774 Q8tkWidget *w;
2775
2776 w = malloc_widget();
2777 w->type = Q8TK_TYPE_ADJUSTMENT;
2778 w->sensitive = TRUE;
2779
2780 w->event_button_on = adjustment_event_button_on;
2781 w->event_dragging = adjustment_event_dragging;
2782 w->event_key_on = adjustment_event_key_on;
2783
2784 w->stat.adj.value = value;
2785 w->stat.adj.lower = lower;
2786 w->stat.adj.upper = upper;
2787 w->stat.adj.step_increment = step_increment;
2788 w->stat.adj.page_increment = page_increment;
2789
2790 return w;
2791 }
2792
q8tk_adjustment_set_value(Q8tkWidget * adj,int value)2793 void q8tk_adjustment_set_value(Q8tkWidget *adj, int value)
2794 {
2795 if (value < adj->stat.adj.lower) value = adj->stat.adj.lower;
2796 if (value > adj->stat.adj.upper) value = adj->stat.adj.upper;
2797
2798 if (adj->stat.adj.value != value) {
2799 adj->stat.adj.value = value;
2800 /* ���Υ����㥹�������ǡ�LISTBOX�����뤳�Ȥ�̵���ϥ�
2801 adj->stat.adj.listbox_changed = TRUE;
2802 */
2803
2804 /* �����ʥ��ȯ�������ʤ� */
2805 /*
2806 widget_signal_do(adj, "value_changed");
2807 */
2808
2809 set_construct_flag(TRUE);
2810 }
2811 }
2812
q8tk_adjustment_clamp_page(Q8tkWidget * adj,int lower,int upper)2813 void q8tk_adjustment_clamp_page(Q8tkWidget *adj,
2814 int lower, int upper)
2815 {
2816 if (upper < lower) upper = lower;
2817
2818 adj->stat.adj.lower = lower;
2819 adj->stat.adj.upper = upper;
2820 if (adj->stat.adj.value < adj->stat.adj.lower)
2821 adj->stat.adj.value = adj->stat.adj.lower;
2822 if (adj->stat.adj.value > adj->stat.adj.upper)
2823 adj->stat.adj.value = adj->stat.adj.upper;
2824
2825 /* �����ʥ��ȯ�������ʤ� */
2826
2827 set_construct_flag(TRUE);
2828 }
2829
q8tk_adjustment_set_arrow(Q8tkWidget * adj,int arrow)2830 void q8tk_adjustment_set_arrow(Q8tkWidget *adj, int arrow)
2831 {
2832 if (adj->stat.adj.arrow != arrow) {
2833 adj->stat.adj.arrow = arrow;
2834 set_construct_flag(TRUE);
2835 }
2836 }
2837
q8tk_adjustment_set_length(Q8tkWidget * adj,int length)2838 void q8tk_adjustment_set_length(Q8tkWidget *adj, int length)
2839 {
2840 if (adj->stat.adj.max_length != length) {
2841 adj->stat.adj.max_length = length;
2842 set_construct_flag(TRUE);
2843 }
2844 }
2845
q8tk_adjustment_set_increment(Q8tkWidget * adj,int step_increment,int page_increment)2846 void q8tk_adjustment_set_increment(Q8tkWidget *adj,
2847 int step_increment,
2848 int page_increment)
2849 {
2850 adj->stat.adj.step_increment = step_increment;
2851 adj->stat.adj.page_increment = page_increment;
2852 }
2853
2854
2855
2856 /*---------------------------------------------------------------------------
2857 * ��ʿ�������� (HSCALE)
2858 *---------------------------------------------------------------------------
2859 * ��new()���ˡ������ǥ����㥹�ȥ��Ȥ���ꤹ�롣
2860 * ��������Υ��(�ϰ�)����ʬ�ϡ����Υ����㥹�ȥ��Ȥ˰�¸���롣
2861 * ��new()���ΰ����� NULL �ξ��ϡ���ưŪ�˥����㥹�ȥ��Ȥ���������뤬��
2862 * ���λ��Υ�� 0��10 ����ʬ�� 1 �� 2 �˸���Ǥ��롣(�ѹ���ǽ)
2863 * ���Ҥϻ��Ƥʤ�
2864 * �������ʥ� �� �ʤ���
2865 * �������������㥹�ȥ��Ȥϥ����ʥ������롣
2866 * �����㥹�ȥ��Ȥ�ư����������硢�ɤ���äƥ����ʥ�åȤ��롩
2867 * -------------------------------------------------------------------------
2868 * Q8tkWidget *q8tk_hscale_new(Q8tkWidget *adjustment)
2869 * ��ʿ���������������
2870 * ͽ������ѤߤΥ����㥹�ȥ��� adjustment ����ꤹ�롣
2871 * NULL �ʤ������Ǽ�ư��������롣
2872 *
2873 * void q8tk_scale_set_draw_value(Q8tkWidget *scale, int draw_value)
2874 * draw_value �����ʤ顢�����ͤ饤�����β���ɽ�����롣
2875 *
2876 * void q8tk_scale_set_value_pos(Q8tkWidget *scale, int pos)
2877 * �����ͤ�ɽ��������֤���롣
2878 * Q8TK_POS_LEFT ���饤�����κ���ɽ��
2879 * Q8TK_POS_RIGHT ���饤�����α���ɽ��
2880 * Q8TK_POS_TOP ���饤�����ξ��ɽ��
2881 * Q8TK_POS_BOTTOM ���饤�����β���ɽ��
2882 * -------------------------------------------------------------------------
2883 * ��HSCALE�� �Ҥϻ��Ƥʤ�
2884 * ���������� ��ADJUSTMENT��
2885 *
2886 *---------------------------------------------------------------------------*/
q8tk_hscale_new(Q8tkWidget * adjustment)2887 Q8tkWidget *q8tk_hscale_new(Q8tkWidget *adjustment)
2888 {
2889 Q8tkWidget *w;
2890
2891 w = malloc_widget();
2892 w->type = Q8TK_TYPE_HSCALE;
2893 w->sensitive = TRUE;
2894
2895 if (adjustment) {
2896 w->stat.scale.adj = adjustment;
2897 } else {
2898 w->stat.scale.adj = q8tk_adjustment_new(0, 0, 10, 1, 2);
2899 }
2900
2901 w->stat.scale.adj->stat.adj.horizontal = TRUE;
2902 w->stat.scale.adj->parent = w;
2903
2904 w->stat.scale.adj->key_up_used = FALSE;
2905 w->stat.scale.adj->key_down_used = FALSE;
2906 w->stat.scale.adj->key_left_used = TRUE;
2907 w->stat.scale.adj->key_right_used = TRUE;
2908
2909 return w;
2910 }
2911
2912
2913
2914
2915 /*---------------------------------------------------------------------------
2916 * ��ľ�������� (HSCALE)
2917 *---------------------------------------------------------------------------
2918 * ��new()���ˡ������ǥ����㥹�ȥ��Ȥ���ꤹ�롣
2919 * ��������Υ��(�ϰ�)����ʬ�ϡ����Υ����㥹�ȥ��Ȥ˰�¸���롣
2920 * ��new()���ΰ����� NULL �ξ��ϡ���ưŪ�˥����㥹�ȥ��Ȥ���������뤬��
2921 * ���λ��Υ�� 0��10 ����ʬ�� 1 �� 2 �˸���Ǥ��롣(�ѹ���ǽ)
2922 * ���Ҥϻ��Ƥʤ�
2923 * �������ʥ� �� �ʤ���
2924 * �������������㥹�ȥ��Ȥϥ����ʥ������롣
2925 * -------------------------------------------------------------------------
2926 * Q8tkWidget *q8tk_hscale_new(Q8tkWidget *adjustment)
2927 * ��ľ���������������
2928 * ͽ������ѤߤΥ����㥹�ȥ��� adjustment ����ꤹ�롣
2929 * NULL �ʤ������Ǽ�ư��������롣
2930 *
2931 * void q8tk_scale_set_draw_value(Q8tkWidget *scale, int draw_value)
2932 * ��ʿ���������Ʊ����
2933 *
2934 * void q8tk_scale_set_value_pos(Q8tkWidget *scale, int pos)
2935 * ��ʿ���������Ʊ����
2936 * -------------------------------------------------------------------------
2937 * ��VSCALE�� �Ҥϻ��Ƥʤ�
2938 * ���������� ��ADJUSTMENT��
2939 *
2940 *---------------------------------------------------------------------------*/
q8tk_vscale_new(Q8tkWidget * adjustment)2941 Q8tkWidget *q8tk_vscale_new(Q8tkWidget *adjustment)
2942 {
2943 Q8tkWidget *w;
2944
2945 w = malloc_widget();
2946 w->type = Q8TK_TYPE_VSCALE;
2947 w->sensitive = TRUE;
2948
2949 w->key_up_used = TRUE;
2950 w->key_down_used = TRUE;
2951
2952 if (adjustment) {
2953 w->stat.scale.adj = adjustment;
2954 } else {
2955 w->stat.scale.adj = q8tk_adjustment_new(0, 0, 10, 1, 2);
2956 }
2957
2958 w->stat.scale.adj->stat.adj.horizontal = FALSE;
2959 w->stat.scale.adj->parent = w;
2960
2961 w->stat.scale.adj->key_up_used = TRUE;
2962 w->stat.scale.adj->key_down_used = TRUE;
2963 w->stat.scale.adj->key_left_used = FALSE;
2964 w->stat.scale.adj->key_right_used = FALSE;
2965
2966 return w;
2967 }
2968
q8tk_scale_set_value_pos(Q8tkWidget * scale,int pos)2969 void q8tk_scale_set_value_pos(Q8tkWidget *scale, int pos)
2970 {
2971 scale->stat.scale.value_pos = pos;
2972 set_construct_flag(TRUE);
2973 }
2974
q8tk_scale_set_draw_value(Q8tkWidget * scale,int draw_value)2975 void q8tk_scale_set_draw_value(Q8tkWidget *scale, int draw_value)
2976 {
2977 scale->stat.scale.draw_value = draw_value;
2978 set_construct_flag(TRUE);
2979 }
2980
2981
2982
2983 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2984 * ɽ�����Υ������� (widget_size()�⤫��ƤФ��)
2985 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
adjustment_size(Q8Adjust * adj,int * sx,int * sy)2986 static void adjustment_size(Q8Adjust *adj, int *sx, int *sy)
2987 {
2988 int i, limit;
2989 int range = (adj->upper - adj->lower + 1);
2990
2991 if (adj->horizontal) limit = (int) (Q8GR_SCREEN_X * 0.8);
2992 else limit = (int) (Q8GR_SCREEN_Y * 0.8);
2993
2994 if (adj->max_length <= 2) {
2995 for (i=1; ; i++) if (range / i < limit) break;
2996 adj->length = range / i;
2997 } else {
2998 adj->length = adj->max_length;
2999 }
3000 adj->scale = (float)(range - 1) / (adj->length - 2);
3001 if (adj->value == adj->lower) adj->pos = 0;
3002 else if (adj->value == adj->upper) adj->pos = adj->length-1;
3003 else {
3004 adj->pos = (int) ((adj->value - adj->lower) / adj->scale) + 1;
3005 if (adj->pos >= adj->length-1) adj->pos = adj->length-2;
3006 }
3007
3008 if (adj->horizontal) {
3009 *sx = adj->length + ((adj->arrow) ? +2 : 0);
3010 *sy = 1;
3011 }else{
3012 *sx = 1;
3013 *sy = adj->length + ((adj->arrow) ? +2 : 0);
3014 }
3015 }
3016
3017
3018
3019
3020 /*---------------------------------------------------------------------------
3021 * ��������ɥ�����ɥ� (SCROLLED WINDOW)
3022 *---------------------------------------------------------------------------
3023 * ��new()���ˡ������ǥ����㥹�ȥ��Ȥ���ꤹ�뤬����������Υ��(�ϰ�)��
3024 * ���Υ�������ɥ�����ɥ��λҤ��礭���ˤ�äơ�ưŪ���Ѳ����롣
3025 * (��ʬ�ϰ����Ѥ����)
3026 * ��new()���ΰ����� NULL �ξ��ϡ���ưŪ�˥����㥹�ȥ��Ȥ���������롣
3027 * ���λ�����ʬ�� 1 �� 10 �Ǥ��롣
3028 * �ä���ͳ���ʤ���С�NULL �ˤ�뼫ư������������ñ�������Ǥ��롣
3029 * �ʤ������������������� NULL �ˤ���ȥХ��ꤽ����ͽ�������롣
3030 * �ʤΤǡ����� NULL �ޤ��� ���˥����㥹�ȥ��Ȥ����ꡢ�Ȥ��뤳�ȡ�
3031 * ���Ҥ��Ļ��Ƥ롣
3032 * (â�����Ҥ�¹���������륦����ɥ�����Ĥ褦�ʾ���ư���̤�ݾ�)
3033 * �������ʥ� �� �ʤ�
3034 * -------------------------------------------------------------------------
3035 * Q8tkWidget *q8tk_scrolled_window_new(Q8tkWidget *hadjustment,
3036 * Q8tkWidget *vadjustment)
3037 * ��������ɥ�����ɥ���������
3038 * ͽ������ѤߤΥ����㥹�ȥ��� adjustment ����ꤹ�롣
3039 * NULL �ʤ������Ǽ�ư��������롣
3040 *
3041 * void q8tk_scrolled_window_set_policy(Q8tkWidget *scrolledw,
3042 * int hscrollbar_policy,
3043 * int vscrollbar_policy)
3044 * ��������С���ɽ����ˡ��ġ������̤����ꤹ�롣
3045 * Q8TK_POLICY_ALWAYS ���ɽ������
3046 * Q8TK_POLICY_AUTOMATIC ɽ�����������礭�����Τ�ɽ������
3047 * Q8TK_POLICY_NEVER ɽ�����ʤ�
3048 *
3049 * void q8tk_misc_set_size(Q8tkWidget *widget, int width, int height)
3050 * ������ɥ��Υ����� width �� height ����ꤹ�롣
3051 * -------------------------------------------------------------------------
3052 * ��SCROLLED WINDOW�ۢ��� [xxxx] �����ʻҤ����Ƥ�
3053 * �á�
3054 * ��� ��ADJUSTMENT��
3055 * ������ ��ADJUSTMENT��
3056 *
3057 *
3058 *
3059 * ��SCROLLED WINDOW�ۢ��� [LISTBOX]
3060 *
3061 * ��������ɥ�����ɥ��λҤ��ꥹ�ȥܥå����λ���
3062 * ��������ɥ�����ɥ���å�����ȡ��ꥹ�ȥܥå�����
3063 * �ե������������ꤵ��롣�Ĥޤꡢ�������Ϥ����ƥꥹ�ȥܥå���������롣
3064 *
3065 *---------------------------------------------------------------------------*/
3066 /* ������ɥ����ޥ�������å�������
3067 ľ���λҤ��ꥹ�ȥܥå����ξ��˸¤äơ��ꥹ�ȥܥå������ƥ��֤ˤ��� */
scrolled_window_event_button_on(Q8tkWidget * widget)3068 static void scrolled_window_event_button_on(Q8tkWidget *widget)
3069 {
3070 if (widget->child && widget->child->type == Q8TK_TYPE_LISTBOX) {
3071 q8tk_widget_set_focus(widget->child);
3072 }
3073 }
q8tk_scrolled_window_new(Q8tkWidget * hadjustment,Q8tkWidget * vadjustment)3074 Q8tkWidget *q8tk_scrolled_window_new(Q8tkWidget *hadjustment,
3075 Q8tkWidget *vadjustment)
3076 {
3077 Q8tkWidget *w;
3078
3079 w = malloc_widget();
3080 w->type = Q8TK_TYPE_SCROLLED_WINDOW;
3081 w->attr = Q8TK_ATTR_CONTAINER;
3082 w->sensitive = TRUE;
3083
3084 w->stat.scrolled.width = 10;
3085 w->stat.scrolled.height = 10;
3086 w->stat.scrolled.hpolicy = Q8TK_POLICY_ALWAYS;
3087 w->stat.scrolled.vpolicy = Q8TK_POLICY_ALWAYS;
3088 w->stat.scrolled.hscrollbar = TRUE;
3089 w->stat.scrolled.vscrollbar = TRUE;
3090
3091 if (hadjustment)
3092 w->stat.scrolled.hadj = hadjustment;
3093 else {
3094 w->stat.scrolled.hadj = q8tk_adjustment_new(0, 0, 7, 1, 10);
3095 w->with_label = TRUE;
3096 }
3097 q8tk_adjustment_set_arrow(w->stat.scrolled.hadj, TRUE);
3098 q8tk_adjustment_set_length(w->stat.scrolled.hadj, 7);
3099 w->stat.scrolled.hadj->stat.adj.horizontal = TRUE;
3100 w->stat.scrolled.hadj->parent = w;
3101 w->stat.scrolled.hadj->key_up_used = FALSE;
3102 w->stat.scrolled.hadj->key_down_used = FALSE;
3103 w->stat.scrolled.hadj->key_left_used = TRUE;
3104 w->stat.scrolled.hadj->key_right_used = TRUE;
3105
3106 if (vadjustment)
3107 w->stat.scrolled.vadj = vadjustment;
3108 else {
3109 w->stat.scrolled.vadj = q8tk_adjustment_new(0, 0, 7, 1, 10);
3110 w->with_label = TRUE;
3111 }
3112 q8tk_adjustment_set_arrow(w->stat.scrolled.vadj, TRUE);
3113 q8tk_adjustment_set_length(w->stat.scrolled.vadj, 7);
3114 w->stat.scrolled.vadj->stat.adj.horizontal = FALSE;
3115 w->stat.scrolled.vadj->parent = w;
3116 w->stat.scrolled.vadj->key_up_used = TRUE;
3117 w->stat.scrolled.vadj->key_down_used = TRUE;
3118 w->stat.scrolled.vadj->key_left_used = FALSE;
3119 w->stat.scrolled.vadj->key_right_used = FALSE;
3120
3121 w->event_button_on = scrolled_window_event_button_on;
3122
3123 return w;
3124 }
q8tk_scrolled_window_set_policy(Q8tkWidget * scrolledw,int hscrollbar_policy,int vscrollbar_policy)3125 void q8tk_scrolled_window_set_policy(Q8tkWidget *scrolledw,
3126 int hscrollbar_policy,
3127 int vscrollbar_policy)
3128 {
3129 scrolledw->stat.scrolled.hpolicy = hscrollbar_policy;
3130 scrolledw->stat.scrolled.vpolicy = vscrollbar_policy;
3131
3132 if (scrolledw->stat.scrolled.hpolicy == Q8TK_POLICY_ALWAYS) {
3133 scrolledw->stat.scrolled.hscrollbar = TRUE;
3134 } else if (scrolledw->stat.scrolled.hpolicy == Q8TK_POLICY_NEVER) {
3135 scrolledw->stat.scrolled.hscrollbar = FALSE;
3136 }
3137
3138 if (scrolledw->stat.scrolled.vpolicy == Q8TK_POLICY_ALWAYS) {
3139 scrolledw->stat.scrolled.vscrollbar = TRUE;
3140 } else if (scrolledw->stat.scrolled.vpolicy == Q8TK_POLICY_NEVER) {
3141 scrolledw->stat.scrolled.vscrollbar = FALSE;
3142 }
3143
3144 set_construct_flag(TRUE);
3145 }
3146 #if 0
3147 void q8tk_scrolled_window_set_width_height(Q8tkWidget *w,
3148 int width, int height)
3149 {
3150 w->stat.scrolled.width = width;
3151 w->stat.scrolled.height = height;
3152
3153 set_construct_flag(TRUE);
3154 }
3155 #endif
3156
3157
3158
3159
3160
3161
3162 /*---------------------------------------------------------------------------
3163 * ����ȥ (ENTRY)
3164 *---------------------------------------------------------------------------
3165 * ��ʸ�������Ϥ���ǽ��â����ʸ���� ASCII�Τߡ�ɽ��������ϴ������
3166 * ���Ҥϻ��Ƥʤ���
3167 * �������ʥ�
3168 * "activate" ��������Ϥ����ä�����ȯ��
3169 * "changed" ʸ�����ϡ�ʸ����������ä�����ȯ��
3170 * ------------------------------------------------------------------------
3171 * Q8tkWidget *q8tk_entry_new(void)
3172 * ����ȥ�����������ϲ�ǽ��ʸ������̵���¡�
3173 *
3174 * Q8tkWidget *q8tk_entry_new_with_max_length(int max)
3175 * ����ȥ�������� ���ϲ�ǽ��ʸ�����ϡ�max ʸ���ޤǡ�(max==0��̵����)
3176 *
3177 * void q8tk_entry_set_text(Q8tkWidget *entry, const char *text)
3178 * ����ȥ�ˡ�ʸ���� text �����ꤹ�롣�����ʥ��ȯ�����ʤ���
3179 * �����������ɽ���Ȥʤꡢɽ�����֤�ʸ������Ƭ�Ȥʤ롣
3180 * ���������������åȤ������ƥ��֤����Խ���ǽ�ʾ�硢���������ʸ������ü
3181 * �˰�ư�����������뤬ɽ�������褦��ɽ�����֤��Ѳ����롣
3182 *
3183 * void q8tk_entry_set_position(Q8tkWidget *entry, int position)
3184 * ����ȥ�������ʸ����Υ���������֤� position �����ꤹ�롣
3185 * position == -1 �ξ��ϡ����������ɽ������ʤ���
3186 * position ��ʸ�������������ξ�硢���������ʸ����������ɽ������롣
3187 * ��������ɽ�������硢�������뤬ɽ�������褦��ɽ�����֤��Ѳ����롣
3188 *
3189 * void q8tk_entry_set_max_length(Q8tkWidget *entry, int max)
3190 * ����ȥ�����ϲ�ǽ��ʸ������ max ���ѹ����롣(max==0��̵����)
3191 *
3192 * void q8tk_entry_set_editable(Q8tkWidget *entry, int editable)
3193 * ����ȥ��ΰ�����ϲġ��ԲĤ����ꤹ�롣 editable �� ���ʤ����ϲġ�
3194 *
3195 * void q8tk_misc_set_size(Q8tkWidget *widget, int width, int height)
3196 * ����ȥ��ɽ�������� width ����ꤹ�롣 height ��̵����
3197 * ��������ɽ�������硢�������뤬ɽ�������褦��ɽ�����֤��Ѳ����롣
3198 * -------------------------------------------------------------------------
3199 * ��ENTRY�� �Ҥϻ��Ƥʤ�
3200 *
3201 *---------------------------------------------------------------------------*/
3202 /*
3203 * strlen()�η�̤� strsize �Ǥ���褦��ʸ����åȲ�ǽ�ʥ�������
3204 */
q8tk_entry_malloc(Q8tkWidget * entry,int strsize)3205 static void q8tk_entry_malloc(Q8tkWidget *entry, int strsize)
3206 {
3207 #if 0
3208 /* strsize ��� 1�Х���;ʬ�˳��� ('\0' ��ʬ��;ʬ��) */
3209 int malloc_size = strsize + 1;
3210 #else
3211 /* 1�Х���ñ�̤Ǥʤ���512�Х���ñ�̤dz��ݤ���褦�ˤ��Ƥߤ褦 */
3212 int malloc_size = (((strsize + 1)/512) +1) * 512;
3213 #endif
3214
3215 if (entry->name == NULL ||
3216 entry->stat.entry.malloc_length < malloc_size) {
3217 if (entry->name == NULL) {
3218 entry->name = (char *)malloc(malloc_size);
3219 } else {
3220 entry->name = (char *)realloc(entry->name, malloc_size);
3221 }
3222
3223 Q8tkAssert(entry->name, "memory exhoused");
3224
3225 entry->stat.entry.malloc_length = malloc_size;
3226 }
3227 }
3228
3229 /* ����ȥ��ޥ�������å������顢���������ư (�Խ���ǽ���Τ�) */
entry_event_button_on(Q8tkWidget * widget)3230 static void entry_event_button_on(Q8tkWidget *widget)
3231 {
3232 int m_x = mouse.x / 8;
3233
3234 if (widget->stat.entry.editable == FALSE) return;
3235
3236 if (widget->stat.entry.cursor_pos < 0) { /* ����������ɽ���ʤ� */
3237 /* ʸ���������˥��������ư */
3238 q8tk_entry_set_position(widget,
3239 q8gr_strlen(widget->code, widget->name));
3240
3241 } else /* ��������ɽ������ʤ� */
3242 { /* �ޥ������֤˥��������ư */
3243 q8tk_entry_set_position(widget,
3244 m_x - widget->x + widget->stat.entry.disp_pos);
3245 }
3246 set_construct_flag(TRUE);
3247 }
3248
3249 /* �����������������顢���������ư (�Խ���ǽ���Τ�) */
3250 /* ʸ�����������顢ʸ�����Խ����������ʥ�ȯ�� (�Խ���ǽ���Τ�) */
3251 /* ���������顢�����ʥ�ȯ�� (�Խ���ǽ���Τ�) */
entry_event_key_on(Q8tkWidget * widget,int key)3252 static void entry_event_key_on(Q8tkWidget *widget, int key)
3253 {
3254 if (widget->stat.entry.editable == FALSE) return;
3255 if (widget->stat.entry.cursor_pos < 0) return;
3256
3257 switch (key) {
3258 case Q8TK_KEY_LEFT:
3259 if (widget->stat.entry.cursor_pos) {
3260 q8tk_entry_set_position(widget, widget->stat.entry.cursor_pos - 1);
3261 }
3262 break;
3263
3264 case Q8TK_KEY_RIGHT:
3265 {
3266 int w = 1;
3267 if (q8gr_strchk(widget->code, widget->name,
3268 widget->stat.entry.cursor_pos) == 1) { w = 2; }
3269 q8tk_entry_set_position(widget, widget->stat.entry.cursor_pos + w);
3270 }
3271 break;
3272
3273 case Q8TK_KEY_UP:
3274 case Q8TK_KEY_DOWN:
3275 #ifdef OLD_FOCUS_CHANGE
3276 /* DO NOTHING */
3277 #else /* �����ʥե���������ư���� */
3278 if (widget->stat.entry.combo) {
3279 Q8List *l = widget->stat.entry.combo->stat.combo.list;
3280 /* ����ܤ��۲��ˤ����硢�����ǥ���ܤΥꥹ�Ȥ�귫�� */
3281 while (l) {
3282 if (strcmp(widget->name,
3283 ((Q8tkWidget*)(l->data))->child->name) == 0) {
3284 if (key == Q8TK_KEY_UP) l = l->prev;
3285 else l = l->next;
3286 if (l) {
3287 q8tk_entry_set_text(widget,
3288 ((Q8tkWidget*)(l->data))->child->name);
3289 widget_signal_do(widget, "activate");
3290 return;
3291 } else {
3292 break;
3293 }
3294 }
3295 l = l->next;
3296 }
3297 /* �귫���оݤ��ʤ���С��ꥹ�Ȥ���Ƭ(����)�å� */
3298 l = widget->stat.entry.combo->stat.combo.list;
3299 if (l) {
3300 if (key == Q8TK_KEY_UP) l = q8_list_first(l);
3301 else l = q8_list_last(l);
3302 if (l) {
3303 q8tk_entry_set_text(widget,
3304 ((Q8tkWidget*)(l->data))->child->name);
3305 widget_signal_do(widget, "activate");
3306 return;
3307 }
3308 }
3309 }
3310 #endif
3311 if (key == Q8TK_KEY_UP)
3312 q8tk_entry_set_position(widget, 0);
3313 else
3314 q8tk_entry_set_position(widget,
3315 q8gr_strlen(widget->code, widget->name));
3316 break;
3317
3318 case Q8TK_KEY_PAGE_UP:
3319 q8tk_entry_set_position(widget, 0);
3320 break;
3321
3322 case Q8TK_KEY_PAGE_DOWN:
3323 q8tk_entry_set_position(widget,
3324 q8gr_strlen(widget->code, widget->name));
3325 break;
3326
3327 case Q8TK_KEY_RET:
3328 widget_signal_do(widget, "activate");
3329 break;
3330
3331 case Q8TK_KEY_BS:
3332 if (widget->stat.entry.cursor_pos > 0) {
3333 int w = q8gr_strdel(widget->code, widget->name,
3334 widget->stat.entry.cursor_pos - 1);
3335 /* ���������1ʸ��ʬ�����˰�ư */
3336 q8tk_entry_set_position(widget, widget->stat.entry.cursor_pos - w);
3337 widget_signal_do(widget, "changed");
3338 }
3339 break;
3340
3341 case Q8TK_KEY_DEL:
3342 if (widget->stat.entry.cursor_pos < (int)q8gr_strlen(widget->code,
3343 widget->name)) {
3344 q8gr_strdel(widget->code, widget->name,
3345 widget->stat.entry.cursor_pos);
3346 /* ��������ΰ�ư������ */
3347 set_construct_flag(TRUE);
3348 widget_signal_do(widget, "changed");
3349 }
3350 break;
3351
3352 default:
3353 if (key <= 0xff && isprint(key)) {
3354 int len = (int)strlen(widget->name) + 1; /* 1�Х���ʸ�����ɲ� */
3355 if (widget->stat.entry.max_length && /* ʸ�����¥����� */
3356 widget->stat.entry.max_length < len) { /* ��Ķ������̵�� */
3357 ;
3358 } else {
3359 q8tk_entry_malloc(widget, len); /* ���꤬��ʤ��ʤ���� */
3360
3361 if (q8gr_stradd(widget->code, widget->name,
3362 widget->stat.entry.cursor_pos, key)) {
3363 /* ���������1ʸ��ʬ�����˰�ư */
3364 q8tk_entry_set_position(widget,
3365 widget->stat.entry.cursor_pos + 1);
3366 widget_signal_do(widget, "changed");
3367 }
3368 }
3369 }
3370 break;
3371 }
3372 }
3373
q8tk_entry_new(void)3374 Q8tkWidget *q8tk_entry_new(void)
3375 {
3376 return q8tk_entry_new_with_max_length(0);
3377 }
3378
q8tk_entry_new_with_max_length(int max)3379 Q8tkWidget *q8tk_entry_new_with_max_length(int max)
3380 {
3381 Q8tkWidget *w;
3382
3383 w = malloc_widget();
3384 w->type = Q8TK_TYPE_ENTRY;
3385 w->sensitive = TRUE;
3386
3387 w->key_up_used = TRUE;
3388 w->key_down_used = TRUE;
3389 w->key_left_used = TRUE;
3390 w->key_right_used = TRUE;
3391
3392 q8tk_entry_malloc(w, max);
3393
3394 w->name[0] = '\0';
3395 w->code = kanji_code;
3396
3397 w->stat.entry.max_length = max;
3398 /* w->stat.entry.malloc_length = q8tk_entry_malloc()�ˤ�����Ѥ� */
3399 w->stat.entry.disp_pos = 0;
3400 w->stat.entry.cursor_pos = 0;
3401 w->stat.entry.width = 8;
3402 w->stat.entry.editable = TRUE;
3403 w->stat.entry.combo = NULL;
3404
3405 w->event_button_on = entry_event_button_on;
3406 w->event_key_on = entry_event_key_on;
3407
3408 return w;
3409 }
3410
q8tk_entry_get_text(Q8tkWidget * entry)3411 const char *q8tk_entry_get_text(Q8tkWidget *entry)
3412 {
3413 return entry->name;
3414 }
3415
q8tk_entry_set_text(Q8tkWidget * entry,const char * text)3416 void q8tk_entry_set_text(Q8tkWidget *entry, const char *text)
3417 {
3418 int len = strlen(text);
3419
3420 if (entry->stat.entry.max_length == 0) { /* ��¤ʤ� */
3421
3422 q8tk_entry_malloc(entry, len); /* ���꤬��ʤ��ʤ顢���� */
3423 strcpy(entry->name, text);
3424
3425 } else { /* ��¤��� */
3426
3427 q8gr_strncpy(entry->code,
3428 entry->name, text, entry->stat.entry.max_length - 1);
3429 entry->name[ entry->stat.entry.max_length - 1 ] = '\0';
3430
3431 }
3432
3433 entry->stat.entry.disp_pos = 0; /* ʸ������Ƭ����ɽ�� */
3434 q8tk_entry_set_position(entry, -1); /* ����������ɽ�� */
3435 }
3436
q8tk_entry_set_position(Q8tkWidget * entry,int position)3437 void q8tk_entry_set_position(Q8tkWidget *entry, int position)
3438 {
3439 int disp_pos;
3440 int tail = q8gr_strlen(entry->code, entry->name);
3441
3442 if (position < 0) {
3443 entry->stat.entry.cursor_pos = -1;
3444 set_construct_flag(TRUE);
3445 return;
3446 }
3447
3448 if (tail < position) position = tail;
3449 if (q8gr_strchk(entry->code, entry->name, position) == 2) {
3450 position -= 1;
3451 }
3452
3453 /* ɽ���ϰϤ�����˥������륻�å� */
3454 if (position < entry->stat.entry.disp_pos) {
3455
3456 entry->stat.entry.disp_pos = position;
3457 entry->stat.entry.cursor_pos = position;
3458
3459 } /* ɽ���ϰϤ����˥������륻�å� */
3460 else if (entry->stat.entry.disp_pos + entry->stat.entry.width <= position){
3461
3462 disp_pos = position - entry->stat.entry.width + 1;
3463 if (q8gr_strchk(entry->code, entry->name, disp_pos) == 2) {
3464 disp_pos += 1;
3465 }
3466 entry->stat.entry.disp_pos = disp_pos;
3467 entry->stat.entry.cursor_pos = position;
3468
3469 } /* ɽ���ϰϤ����� (����ʸ����2�Х�����)�˥������륻�å� */
3470 else if ((entry->stat.entry.disp_pos + entry->stat.entry.width - 1
3471 == position) &&
3472 q8gr_strchk(entry->code, entry->name, position) == 1) {
3473
3474 disp_pos = entry->stat.entry.disp_pos +1;
3475 if (q8gr_strchk(entry->code, entry->name, disp_pos) == 2) {
3476 disp_pos += 1;
3477 }
3478 entry->stat.entry.disp_pos = disp_pos;
3479 entry->stat.entry.cursor_pos = position;
3480
3481 } /* ����ʳ� (ɽ���ϰ���˥������륻�å�) */
3482 else {
3483
3484 entry->stat.entry.cursor_pos = position;
3485
3486 }
3487 q8gr_set_cursor_blink();
3488 set_construct_flag(TRUE);
3489 }
3490
q8tk_entry_set_max_length(Q8tkWidget * entry,int max)3491 void q8tk_entry_set_max_length(Q8tkWidget *entry, int max)
3492 {
3493 q8tk_entry_malloc(entry, max); /* ���꤬��ʤ��ʤ顢���� */
3494
3495 entry->stat.entry.max_length = max;
3496 }
3497
q8tk_entry_set_editable(Q8tkWidget * entry,int editable)3498 void q8tk_entry_set_editable(Q8tkWidget *entry, int editable)
3499 {
3500 if (entry->stat.entry.editable != editable) {
3501 entry->stat.entry.editable = editable;
3502 set_construct_flag(TRUE);
3503 }
3504 }
3505
3506
3507
3508
3509
3510 /*---------------------------------------------------------------------------
3511 * ��������졼�����롼�� (ACCEL GROUP)
3512 * ��������졼�������� (ACCEL KEY)
3513 *---------------------------------------------------------------------------
3514 * ���Ҥϻ��Ƥʤ�����ɽ����Ǥ��ʤ���
3515 * ������Ū�ˤϡ���������졼�����롼�פ��ơ���������졼���������Ҥ�
3516 * ���֤�Ȥ�
3517 * ����������졼�����롼�פ���ɥ��˴�Ϣ�Ť��뤳�Ȥǡ���������졼��
3518 * �����Υ�����ɥ��ˤ�ͭ���ˤ��뤳�Ȥ��Ǥ��롣
3519 * -------------------------------------------------------------------------
3520 * Q8tkWidget *q8tk_accel_group_new(void)
3521 * ��������졼�����롼�פ�������
3522 *
3523 * void q8tk_accel_group_attach(Q8tkWidget *accel_group,
3524 * Q8tkWidget *window)
3525 * ��������졼�����롼�פ�����ɥ� window �˴�Ϣ�Ť��롣
3526 *
3527 * void q8tk_accel_group_detach(Q8tkWidget *accel_group,
3528 * Q8tkWidget *window)
3529 * ������ɥ� window �˴�Ϣ�Ť�����������졼�����롼�פ��ڤ�Υ����
3530 *
3531 * void q8tk_accel_group_add(Q8tkWidget *accel_group, int accel_key,
3532 * Q8tkWidget *widget, const char *signal)
3533 * ��������졼�����������ꤹ�롣
3534 * ��������졼�����롼�� accel_group �ˡ����� accel_key �����ꤹ�롣
3535 * ���Υ������������줿�顢 �������å� widget �� �����ʥ� signal �����롣
3536 * -------------------------------------------------------------------------
3537 * [WINDOW]
3538 * ��
3539 * ��������ACCEL GROUP�ۢ�����ACCEL KEY��
3540 * ����
3541 * �� ��ACCEL KEY��
3542 * ����
3543 * �� ��ACCEL KEY��
3544 * ����
3545 *
3546 *---------------------------------------------------------------------------*/
q8tk_accel_group_new(void)3547 Q8tkWidget *q8tk_accel_group_new(void)
3548 {
3549 Q8tkWidget *w;
3550
3551 w = malloc_widget();
3552 w->type = Q8TK_TYPE_ACCEL_GROUP;
3553 w->sensitive = TRUE;
3554
3555 return w;
3556 }
3557
q8tk_accel_group_attach(Q8tkWidget * accel_group,Q8tkWidget * window)3558 void q8tk_accel_group_attach(Q8tkWidget *accel_group,
3559 Q8tkWidget *window)
3560 {
3561 Q8tkAssert(window->type == Q8TK_TYPE_WINDOW, NULL);
3562 window->stat.window.accel = accel_group;
3563 }
3564
q8tk_accel_group_detach(Q8tkWidget * accel_group,Q8tkWidget * window)3565 void q8tk_accel_group_detach(Q8tkWidget *accel_group,
3566 Q8tkWidget *window)
3567 {
3568 Q8tkAssert(window->type == Q8TK_TYPE_WINDOW, NULL);
3569
3570 if (window->stat.window.accel == accel_group) {
3571 window->stat.window.accel = NULL;
3572 }
3573 }
3574
q8tk_accel_group_add(Q8tkWidget * accel_group,int accel_key,Q8tkWidget * widget,const char * signal)3575 void q8tk_accel_group_add(Q8tkWidget *accel_group, int accel_key,
3576 Q8tkWidget *widget, const char *signal)
3577 {
3578 Q8tkWidget *w;
3579 w = malloc_widget();
3580
3581 if (accel_group->child) {
3582 Q8tkWidget *c = accel_group->child;
3583 while (c->next) {
3584 c = c->next;
3585 }
3586 c->next = w;
3587 w->prev = c;
3588 w->next = NULL;
3589 } else {
3590 accel_group->child = w;
3591 w->prev = NULL;
3592 w->next = NULL;
3593 }
3594 w->parent = accel_group;
3595
3596 w->type = Q8TK_TYPE_ACCEL_KEY;
3597 w->sensitive = TRUE;
3598 w->name = (char *)malloc(strlen(signal) + 1);
3599
3600 Q8tkAssert(w->name, "memory exhoused");
3601
3602 strcpy(w->name, signal);
3603 w->code = Q8TK_KANJI_ANK;
3604
3605 w->stat.accel.key = accel_key;
3606 w->stat.accel.widget = widget;
3607 }
3608
3609
3610
3611
3612 /*---------------------------------------------------------------------------
3613 * �������� (DIALOG)
3614 *---------------------------------------------------------------------------
3615 * ����������������ɥ�����
3616 * +-------------------+
3617 * | WARING ! |��
3618 * | Quit, really? |������ʬ�ϡ�vbox (��ľ�ܥå���)
3619 * | press button. |��
3620 * | +------+ +------+ |
3621 * | | OK | |CANCEL| |
3622 * | +------+ +------+ |
3623 * +-------------------+
3624 * �� ������ʬ�� ��
3625 * action_area (��ʿ�ܥå���)
3626 * ����������������������ϡ� vbox �� action_area ��Ǥ�դΥ������åȤ�
3627 * ����Ǥ��롣q8tk_box_pack_start() / end() �ˤ����ꤹ�롣
3628 * �����Υ�����ɥ��ϥ⡼���쥹�ʤΤ���ա�
3629 * -------------------------------------------------------------------------
3630 * Q8tkWidget *q8tk_dialog_new(void)
3631 * ����������������
3632 *
3633 * ������������������������ vbox �˥������åȤ��ɲä�������㡣
3634 * d = q8tk_dialog_new();
3635 * q8tk_box_pack_start(Q8TK_DIALOGE(d)->vbox, label);
3636 *
3637 * ������������������������ action_area �˥������åȤ��ɲä�������㡣
3638 * d = q8tk_dialog_new();
3639 * q8tk_box_pack_start(Q8TK_DIALOGE(d)->action_area, button);
3640 * -------------------------------------------------------------------------
3641 * ���ġĢ���DIALOG��
3642 * ��
3643 * ��WINDOW�ۢ�����FRAME�ۢ�����VBOX�ۢ�����VBOX(vbox)��
3644 * ����
3645 * �� ��HBOX(action_area)��
3646 *
3647 * q8tk_dialog_new()���֤��ͤ� ��WINDOW�� �Υ������åȤǤ��롣
3648 * �⡼����ˤ�����ϡ����Υ������åȤ� q8tk_grab_add() ���롣
3649 *
3650 * vbox��action_area �ϥ桼����Ǥ�դ˥������åȤ��ɲäǤ��롣
3651 *
3652 * q8tk_widget_destroy() �κݤϡ��������ƤΥ������åȤ��������뤬��
3653 * �桼���� vbox��action_area ���ɲä����������åȤϺ������ʤ���
3654 *
3655 *---------------------------------------------------------------------------*/
q8tk_dialog_new(void)3656 Q8tkWidget *q8tk_dialog_new(void)
3657 {
3658 Q8tkWidget *dialog, *window, *vbox, *frame;
3659
3660 dialog = malloc_widget();
3661 dialog->type = Q8TK_TYPE_DIALOG;
3662 dialog->sensitive = TRUE;
3663
3664 window = q8tk_window_new(Q8TK_WINDOW_DIALOG);
3665 window->stat.window.work = dialog;
3666
3667 frame = q8tk_frame_new("");
3668 q8tk_container_add(window, frame);
3669 q8tk_widget_show(frame);
3670 q8tk_frame_set_shadow_type(frame, Q8TK_SHADOW_NONE);
3671
3672 vbox = q8tk_vbox_new();
3673 q8tk_container_add(frame, vbox);
3674 q8tk_widget_show(vbox);
3675
3676 dialog->stat.dialog.vbox = q8tk_vbox_new();
3677 q8tk_box_pack_start(vbox, dialog->stat.dialog.vbox);
3678 q8tk_widget_show(dialog->stat.dialog.vbox);
3679
3680 dialog->stat.dialog.action_area = q8tk_hbox_new();
3681 q8tk_box_pack_start(vbox, dialog->stat.dialog.action_area);
3682 q8tk_widget_show(dialog->stat.dialog.action_area);
3683
3684 return window;
3685 }
3686
3687
3688
3689
3690 /*---------------------------------------------------------------------------
3691 * FILE SELECTION
3692 *---------------------------------------------------------------------------
3693 * ���������åȤ��Ȥ߹�碌�ơ��ե����륻�쥯��������Ф���
3694 * ��������ե�����̾��Ĺ���ϡ��ѥ���ޤ�ƺ����
3695 * Q8TK_MAX_FILENAME �ޤǤǤ��롣(ʸ����ü��\0��ޤ�)
3696 * ���ե�����̾�ΰ����ϡ������ƥ��¸�ؿ��ˤƽ������롣
3697 * -------------------------------------------------------------------------
3698 * Q8tkWidget *q8tk_file_selection_new(const char *title, int select_ro)
3699 * �ե����륻�쥯������������
3700 * ���Ф�ɽ���Ѥ�ʸ���� title ����ꤹ�롣
3701 * select_ro �� 1 �ʤ顢��Read Only�ץ����å��ܥ���ɽ�����졢�����å�
3702 * ����롣0 �ʤ顢��Read Only�ץ����å��ܥ���ɽ������뤬�������å���
3703 * ����ʤ���-1 �ʤ顢��Read Only�ץ����å��ܥ����ɽ������ʤ���
3704 * (�����å����줿���ɤ����ϡ� q8tk_file_selection_get_readonly �ˤ�
3705 * �����Ǥ���Τǡ��ƤӽФ����ǥ�ɥ����dz������ɤ�������ꤹ��)
3706 *
3707 * const char *q8tk_file_selection_get_filename(Q8tkWidget *fselect)
3708 * ����(����)����Ƥ���ե�����̾��������롣
3709 *
3710 * void q8tk_file_selection_set_filename(Q8tkWidget *fselect,
3711 * const char *filename)
3712 * �ե�����̾ (�ǥ��쥯�ȥ�̾�Ǥ��) ����ꤹ�롣
3713 *
3714 * int q8tk_file_selection_get_readonly(Q8tkWidget *fselect)
3715 * �� �ʤ顢�֥�ɥ����dz����פ������å�����Ƥ��롣
3716 * -------------------------------------------------------------------------
3717 * ���ġĢ���FILE SELECTION��
3718 * ��
3719 * ��WINDOW�ۢ���
3720 * ��������������
3721 * ������VBOX�ۢ�����LABEL�� q8tk_file_selection_new()�ΰ���
3722 * ����
3723 * �� ��HSEPARATOR��
3724 * ����
3725 * �� ��LABEL�� �ǥ��쥯�ȥ�̾
3726 * ����
3727 * �� ��HBOX�ۢ�����LABEL�� (������)
3728 * ���� ����
3729 * �á� �� ��SCROLLED WINDOW�ۢ�����LIST BOX�ۢ���(A)
3730 * �á� ���� �á�
3731 * �á� �á� �è��� ��ADJUSTMENT��
3732 * �á� �á� ������ ��ADJUSTMENT��
3733 * �á� �â�
3734 * �á� �� ��LABEL�� (������)
3735 * �á� ����
3736 * �á� �� ��VBOX�ۢ�����LABEL�� (������)
3737 * �á� ����
3738 * �á� �� ��LABEL�� �ե������
3739 * �á� ����
3740 * �á� �� ��LABEL�� (�����ޡ�4)
3741 * �á� ����
3742 * �á� �� ��BUTTON�ۢ�����LABEL��
3743 * �á� ���� (view_button)
3744 * �á� �â�
3745 * �á� �� ��LABEL�� (�����ޡ�2)
3746 * �á� ����
3747 * �á� �� ��CHECK BUTTON�ۢ�����LABEL��
3748 * �á� ���� Read only
3749 * �á� �â�
3750 * �á� �� ��BUTTON�ۢ�����LABEL��
3751 * �á� ���� (ok_button)
3752 * �á� �â�
3753 * �á� �� ��BUTTON�ۢ�����LABEL��
3754 * �á� (cancel_button)
3755 * �â�
3756 * �� ��LABEL�� (����)
3757 * ����
3758 * �� ��HBOX�ۢ�����LABEL�� Filename(���Ф�)
3759 * ����
3760 * �� ��ENTRY�� �ե�����̾����
3761 *
3762 * q8tk_file_selection_new() ���֤��ͤ� ��WINDOW�� �Υ������åȤǤ��롣
3763 * �⡼����ˤ�����ϡ����Υ������åȤ� q8tk_grab_add() ���롣
3764 *
3765 * cancel_button��ok_button �ϥ桼����Ǥ�դ˥����ʥ������Ǥ��롣
3766 *
3767 * fsel = q8tk_file_selection_new();
3768 * q8tk_widget_show(fsel);
3769 * q8tk_grab_add(fsel);
3770 * q8tk_signal_connect(Q8TK_FILE_SELECTION(fsel)->ok_button,
3771 * "clicked", �桼���ؿ����桼������);
3772 * q8tk_signal_connect(Q8TK_FILE_SELECTION(fsel)->cancel_button,
3773 * "clicked", �桼���ؿ����桼������);
3774 *
3775 * ---------------------------------------------------------------------
3776 * (A) ������LIST ITEM�ۢ�����LABEL��
3777 * ����
3778 * �� ��LIST ITEM�ۢ�����LABEL��
3779 * ����
3780 * �� ��LIST ITEM�ۢ�����LABEL��
3781 * ����
3782 *
3783 * q8tk_file_selection_set_filename() �ˤƥǥ��쥯�ȥ�̾�åȤ���ȡ�
3784 * ���Υǥ��쥯�ȥ�Υե�����������������(���ν����ϥ����ƥ��¸)��
3785 * ���ƤΥե�����̾��ꥹ�ȥ����ƥ�ˤ��ơ��ꥹ�ȥܥå����˾褻�롣
3786 * �ե�����̾�åȤ������⡢��������ǥ��쥯�ȥ�̾���ڤ�Ф���
3787 * (�����ν����⥷���ƥ��¸)��Ʊ�ͤ˥ǥ��쥯�ȥ�Υե��������������
3788 * ���롣���ξ�硢����ȥ�ˤ�ե�����̾�åȤ��롣
3789 *
3790 * ---------------------------------------------------------------------
3791 * �ʲ��ξ�硢ok_button �� "clicked" �����ʥ뤬ȯ�����롣
3792 * ��OK �Υܥ����å��������
3793 * ���ե�����̾�����Υꥹ�ȥ����ƥ�Ρ������ƥ��֤ʤΤ�å���
3794 * ���줬�ǥ��쥯�ȥ�Ǥʤ��ä���硣
3795 * ������ȥ�ˤ����Ϥ��ƥ����������
3796 * ���줬�ǥ��쥯�ȥ�Ǥʤ��ä���硣
3797 *
3798 * �Ĥޤꡢok_button �� "clicked" �����ʥ�����ꤷ�Ƥ����С�
3799 * ����Ū�����ˤ��ե���������(����)���ΤǤ��롣
3800 *
3801 * ---------------------------------------------------------------------
3802 * q8tk_widget_destroy() �κݤϡ����٤ƤΥ������åȤ��˲����롣
3803 * (������� LIST ITEM �������åȤ�ޤ�)
3804 *
3805 *---------------------------------------------------------------------------*/
3806 /*---------------------------------------------------------------------------
3807 * �ʲ��δؿ��ΰ��� fselect �� q8tk_file_selection_new() ������ͤΡ�
3808 * ������ɥ��������åȤǤ��롣�ե����륻�쥯��������åȤ��ѿ�
3809 * (fselect->stat.fselect.�ѿ�̾) �˥�����������ˤϡ��ʲ��Τ褦�ˤ��롣
3810 * Q8TK_FILE_SELECTION((Q8tkWidget*)fselect)->�ѿ�̾
3811 *---------------------------------------------------------------------------*/
3812
3813 /* �ե����륻�쥯�����Υꥹ�ȥܥå�����Υꥹ�ȥ����ƥब����å����줿���
3814
3815 ��ľ�������Ƥ����ꥹ�ȥܥå����Ȱ㤦�Τ�����å����줿���
3816 fsel_list_selection_changed() ("selection_changed"���٥�Ȥˤ��)
3817 fsel_item_selected() ("select" ���٥�Ȥˤ��)
3818 �ν�˸ƤӽФ���롣
3819
3820 ��ľ�������Ƥ����ꥹ�ȥܥå�����Ʊ���Τ�����å����줿���
3821 fsel_item_selected() ("select" ���٥�Ȥˤ��)
3822 �������ƤӽФ���롣 ("selection_changed" ���٥�Ȥ�ȯ�����ʤ��Τ�) */
3823
3824
3825 static void fsel_update(Q8tkWidget *fselect, const char *filename, int type);
3826 static int fsel_opendir(Q8tkWidget *fselect, const char *filename, int type);
3827
3828
3829 /* �ե�����̾���� LIST BOX �ˤơ�������Υե����뤬�Ѥ�ä����Υ�����Хå� */
fsel_selection_changed_callback(UNUSED_WIDGET,void * fselect)3830 static void fsel_selection_changed_callback(UNUSED_WIDGET, void *fselect)
3831 {
3832 Q8TK_FILE_SELECTION((Q8tkWidget*)fselect)->selection_changed = TRUE;
3833 }
3834
3835
3836 /* �ե�����̾�� LIST ITEM �ˤơ� ����å��������Υ�����Хå� */
fsel_selected_callback(Q8tkWidget * item,void * fselect)3837 static void fsel_selected_callback(Q8tkWidget *item, void *fselect)
3838 {
3839 const char *name;
3840 if (item->name) name = item->name;
3841 else if (item->child && item->child->name) name = item->child->name;
3842 else name = "";
3843
3844
3845 if (Q8TK_FILE_SELECTION((Q8tkWidget*)fselect)->selection_changed) {
3846
3847 /* ľ���� fsel_selection_changed_callback() ���ƤӽФ���Ƥ����硢
3848 �Ĥޤ�����Ȥϰ㤦�٥ꥹ�ȥ����ƥब����å����줿���ϡ�
3849 ���Υꥹ�ȥ����ƥ���ݻ�����ե�����̾����ȥ�˥��åȤ��� */
3850
3851 Q8TK_FILE_SELECTION((Q8tkWidget*)fselect)->selection_changed = FALSE;
3852
3853 q8tk_entry_set_text(Q8TK_FILE_SELECTION((Q8tkWidget*)fselect)
3854 ->selection_entry, name);
3855
3856 } else {
3857
3858 /* ���� fsel_selected_callback() �������ƤӽФ��줿��硢
3859 �Ĥޤ������Ʊ���٥ꥹ�ȥ����ƥब����å����줿���ϡ�
3860 ���Υꥹ�ȥ����ƥ���ݻ�����ե�����̾�ǡ��ե������������ */
3861
3862 fsel_update((Q8tkWidget*)fselect, name, item->stat.any.data[0]);
3863 }
3864 }
3865
3866
3867 /* �ե�����̾���Ϥ� ENTRY �ˤơ�������������Υ�����Хå� */
fsel_activate_callback(Q8tkWidget * entry,void * fselect)3868 static void fsel_activate_callback(Q8tkWidget *entry, void *fselect)
3869 {
3870 const char *input_filename = q8tk_entry_get_text(entry);
3871 int type = -1; /* �ǥ��쥯�ȥ꤫�ɤ��������� */
3872
3873 /* ���Ϥ����ե�����̾�����ꥹ�Ȥ� name �˰��פ���С�
3874 �ե����륿���פ���ꤹ�뤳�Ȥ��Ǥ��롣
3875 (�����Ƴ��ꤵ����ɬ�פϤʤ��Τǡ�Ŭ���˰��ץ����å�����) */
3876
3877 Q8tkWidget *match_list;
3878 match_list = q8tk_listbox_search_items(
3879 Q8TK_FILE_SELECTION((Q8tkWidget*)fselect)->file_list,
3880 input_filename);
3881
3882 if (match_list) type = match_list->stat.any.data[0];
3883
3884
3885 /* ���Ϥ����ե�����̾�ǡ��ե������������ */
3886 fsel_update((Q8tkWidget*)fselect, input_filename, type);
3887 }
3888
3889
3890 /* �ե�������� LIST BOX �����롣 �ǥ��쥯�ȥ�̾�ʤ�ɽ��������
3891 �ե�����̾�����ꤷ�����ϡ�OK �ܥ���������Ȥˤ��� */
fsel_update(Q8tkWidget * fselect,const char * filename,int type)3892 static void fsel_update(Q8tkWidget *fselect, const char *filename, int type)
3893 {
3894 char wk[ Q8TK_MAX_FILENAME ];
3895
3896 if (osd_path_join(Q8TK_FILE_SELECTION(fselect)->pathname, filename,
3897 wk, Q8TK_MAX_FILENAME) == FALSE) {
3898 strcpy(wk, "");
3899 }
3900
3901 if (fsel_opendir(fselect, wk, type) != FILE_STAT_DIR) {
3902 widget_signal_do(Q8TK_FILE_SELECTION(fselect)->ok_button, "clicked");
3903 }
3904 }
3905
3906
3907 /* ���ꤵ�줿�ѥ�̾�ǥ��쥯�ȥ�̾�ȥե�����̾��ʬ���� �ǥ��쥯�ȥ����
3908 �ꥹ�Ȥ˥ե���������åȡ� �ե�����̾��ȥ�˥��åȤ��� */
3909 static int fsel_opendir_sub(Q8tkWidget *fselect, const char *dirname);
fsel_opendir(Q8tkWidget * fselect,const char * filename,int type)3910 static int fsel_opendir(Q8tkWidget *fselect, const char *filename, int type)
3911 {
3912 int save_code = q8tk_set_kanjicode(osd_kanji_code());
3913
3914 char path[ Q8TK_MAX_FILENAME ];
3915 char dir [ Q8TK_MAX_FILENAME ];
3916 char file[ Q8TK_MAX_FILENAME ];
3917
3918
3919 if (filename == NULL || filename[0] == '\0') { /* filename��̵���ʾ��� */
3920 filename = osd_dir_cwd(); /* �����ȥǥ��쥯�ȥ�� */
3921 type = FILE_STAT_DIR; /* ����˻Ȥ����Ȥˤ��� */
3922 }
3923
3924 if (osd_path_normalize(filename, path, Q8TK_MAX_FILENAME) /* ������ */
3925 == FALSE) {
3926 strcpy(path, "");
3927 type = FILE_STAT_DIR;
3928 }
3929
3930
3931 /* filename ��ǥ��쥯�ȥ�̾�ȥե�����̾��ʬΥ���� */
3932
3933 if (type < 0) { /* �ǥ��쥯�ȥ꤫�ɤ������� */
3934 type = osd_file_stat(path); /* �ʤ顢�ޤ���°������� */
3935 }
3936
3937 if (type == FILE_STAT_DIR) { /* filename �ϥǥ��쥯�ȥ� */
3938 strcpy(dir, path);
3939 strcpy(file, ""); /* �ե�����̾�϶� */
3940
3941 } else { /* filename �ϥե�����餷�� */
3942 /* �ǥ��쥯�ȥ�̾��ʬΥ���� */
3943 if (osd_path_split(path, dir, file, Q8TK_MAX_FILENAME) == FALSE) {
3944 strcpy(dir, ""); /* ���Ԥ����� */
3945 strcpy(file, path); /* Ŭ���ˤ��ޤ��� */
3946 }
3947 }
3948
3949 /* �ǥ��쥯�ȥ�̾�ǥǥ��쥯�ȥ�� */
3950
3951 if (fsel_opendir_sub(fselect, dir) >= 0) { /* �������������� */
3952
3953 Q8TK_FILE_SELECTION(fselect)->pathname[0] = '\0';
3954 strncat(Q8TK_FILE_SELECTION(fselect)->pathname, dir,
3955 Q8TK_MAX_FILENAME-1);
3956
3957 q8tk_entry_set_text(Q8TK_FILE_SELECTION(fselect)->selection_entry,
3958 file);
3959 } else { /* �����ʤ��ä��ġ� */
3960
3961 q8tk_entry_set_text(Q8TK_FILE_SELECTION(fselect)->selection_entry,
3962 path);
3963 }
3964
3965
3966 q8tk_set_kanjicode(save_code);
3967
3968 /* ���ꤵ�줿�ѥ�̾���ǥ��쥯�ȥ���ä����ɤ������֤� */
3969 return type;
3970 }
3971
3972
fsel_opendir_sub(Q8tkWidget * fselect,const char * dirname)3973 static int fsel_opendir_sub(Q8tkWidget *fselect, const char *dirname)
3974 {
3975 T_DIR_INFO *dirp;
3976 T_DIR_ENTRY *dirent;
3977 char wk[ Q8TK_MAX_FILENAME ];
3978 int nr, i, width;
3979 char old_path[ Q8TK_MAX_FILENAME ];
3980 char *old_dirname = NULL;
3981
3982 /* ��¸�� LIST ITEM ��� */
3983
3984 if (Q8TK_FILE_SELECTION(fselect)->file_list->child) {
3985 q8tk_listbox_clear_items(Q8TK_FILE_SELECTION(fselect)->file_list,0,-1);
3986 }
3987 q8tk_adjustment_set_value(Q8TK_FILE_SELECTION(fselect)->scrolled_window
3988 ->stat.scrolled.hadj, 0);
3989 q8tk_adjustment_set_value(Q8TK_FILE_SELECTION(fselect)->scrolled_window
3990 ->stat.scrolled.vadj, 0);
3991
3992
3993 /* �ǥ��쥯�ȥ��Ĵ�١��ե�����̾�� LIST ITEM �Ȥ�����Ͽ */
3994 /* ����������ǽ�ʥե�����̾��ʻ���� LIST ITEM ���ݻ����Ƥ��� */
3995 /* �Ĥ��ǤʤΤǡ��ե�����Υ����פ� LIST ITEM ���ݻ����Ƥ��� */
3996
3997 if (dirname[0] != '\0' &&
3998 (dirp = osd_opendir(dirname))) {
3999
4000 /* ��ѥ�̾���̥ѥ��ȥǥ��쥯�ȥ�̾��ʬΥ���롣
4001 ���ξ�̥ѥ�̾�ȡ������Υѥ�̾�����פ���С�
4002 ����ʬΥ�����ǥ��쥯�ȥ�̾��Ф��Ƥ��� */
4003 if (Q8TK_FILE_SELECTION(fselect)->pathname[0] != '\0' &&
4004 osd_path_split(Q8TK_FILE_SELECTION(fselect)->pathname,
4005 wk,
4006 old_path,
4007 Q8TK_MAX_FILENAME)) {
4008 if (strcmp(wk, dirname) == 0) {
4009 old_dirname = old_path;
4010 }
4011 }
4012
4013 nr = 0;
4014 while ((dirent = osd_readdir(dirp))) {
4015 Q8tkWidget *item;
4016
4017 wk[0] = '\0';
4018 strncat(wk, dirent->str, Q8TK_MAX_FILENAME-1);
4019
4020 item = q8tk_list_item_new_with_label(wk);
4021 q8tk_list_item_set_string(item, dirent->name);
4022 item->stat.any.data[0] = dirent->type;
4023 q8tk_container_add(Q8TK_FILE_SELECTION(fselect)->file_list, item);
4024 q8tk_widget_show(item);
4025
4026 /* �Ф����ǥ��쥯�ȥ�̾�˰��פ��륢���ƥब����С������ƥ��֤� */
4027 if (old_dirname && (strcmp(old_dirname, dirent->name) == 0)) {
4028 q8tk_listbox_select_child(
4029 Q8TK_FILE_SELECTION(fselect)->file_list, item);
4030 old_dirname = NULL;
4031 }
4032
4033 q8tk_signal_connect(item, "select",
4034 fsel_selected_callback, fselect);
4035 nr ++;
4036 }
4037 osd_closedir(dirp);
4038
4039
4040 i = strlen(dirname);
4041 width = Q8TK_FILE_SELECTION(fselect)->width;
4042 if (i + 6 > width) { /* 6 == sizeof("DIR = ") */
4043 i = i - (width - 6 -3); /* 3 == sizeof("...") */
4044 if (q8gr_strchk(Q8TK_FILE_SELECTION(fselect)->dir_name->code,
4045 dirname, i) == 2) { i ++; } /* �������������*/
4046 } else {
4047 i = 0;
4048 }
4049 wk[0] = '\0';
4050 strncat(wk, "DIR = ", Q8TK_MAX_FILENAME-1);
4051 if (i) {
4052 strncat(wk, "...", Q8TK_MAX_FILENAME-1 -strlen(wk));
4053 }
4054 strncat(wk, &dirname[i], Q8TK_MAX_FILENAME-1 -strlen(wk));
4055
4056
4057 } else {
4058
4059 nr = -1;
4060
4061 wk[0] = '\0';
4062 strncat(wk, "DIR = non existant", Q8TK_MAX_FILENAME-1);
4063
4064 }
4065
4066 q8tk_label_set(Q8TK_FILE_SELECTION(fselect)->dir_name, wk);
4067
4068 sprintf(wk, "%4d file(s)", (nr < 0) ? 0 : nr);
4069 q8tk_label_set(Q8TK_FILE_SELECTION(fselect)->nr_files, wk);
4070
4071
4072 return nr;
4073 }
4074
4075
4076
4077
fsel_selection_view_callback(UNUSED_WIDGET,void * fselect)4078 static void fsel_selection_view_callback(UNUSED_WIDGET, void *fselect)
4079 {
4080 q8tk_utility_view(q8tk_file_selection_get_filename(fselect));
4081 }
4082
4083
4084
4085 #if 0 /* ver 0.5.x �ޤǤ�ɽ������ */
4086
4087 Q8tkWidget *q8tk_file_selection_new(const char *title, int select_ro)
4088 {
4089 Q8tkWidget *fselect, *window, *vbox, *wk;
4090 int save_code;
4091
4092 fselect = malloc_widget();
4093 fselect->type = Q8TK_TYPE_FILE_SELECTION;
4094 fselect->sensitive = TRUE;
4095
4096 fselect->stat.fselect.pathname = (char *)calloc(Q8TK_MAX_FILENAME, 1);
4097 fselect->stat.fselect.filename = (char *)calloc(Q8TK_MAX_FILENAME, 1);
4098 Q8tkAssert(fselect->stat.fselect.pathname, "memory exhoused");
4099 Q8tkAssert(fselect->stat.fselect.filename, "memory exhoused");
4100
4101 window = q8tk_window_new(Q8TK_WINDOW_DIALOG); /* ������ɥ����� */
4102 window->stat.window.work = fselect;
4103
4104 vbox = q8tk_vbox_new(); /* �ʲ� ��ľ�˵ͤ�� */
4105 q8tk_container_add(window, vbox);
4106 q8tk_widget_show(vbox);
4107
4108 wk = q8tk_label_new(title); /* ����(�������) */
4109 q8tk_box_pack_start(vbox, wk);
4110 q8tk_widget_show(wk);
4111 q8tk_misc_set_placement(wk, Q8TK_PLACEMENT_X_CENTER, Q8TK_PLACEMENT_Y_TOP);
4112 fselect->stat.fselect.width = MAX(q8gr_strlen(wk->code, wk->name),
4113 Q8GR_SCREEN_X * 0.5);
4114
4115 wk = q8tk_hseparator_new(); /* ---------------- */
4116 q8tk_box_pack_start(vbox, wk);
4117 q8tk_widget_show(wk);
4118 /* DIR = /... */
4119 fselect->stat.fselect.dir_name = q8tk_label_new("DIR =");
4120 q8tk_box_pack_start(vbox, fselect->stat.fselect.dir_name);
4121 q8tk_widget_show(fselect->stat.fselect.dir_name);
4122 q8tk_misc_set_placement(fselect->stat.fselect.dir_name,
4123 Q8TK_PLACEMENT_X_LEFT, Q8TK_PLACEMENT_Y_TOP);
4124
4125 /* 99 file(s) */
4126 fselect->stat.fselect.nr_files = q8tk_label_new("0 file(s)");
4127 q8tk_box_pack_start(vbox, fselect->stat.fselect.nr_files);
4128 q8tk_widget_show(fselect->stat.fselect.nr_files);
4129 q8tk_misc_set_placement(fselect->stat.fselect.nr_files,
4130 Q8TK_PLACEMENT_X_CENTER, Q8TK_PLACEMENT_Y_TOP);
4131
4132 /* [�ꥹ�ȥܥå���] */
4133 fselect->stat.fselect.scrolled_window=q8tk_scrolled_window_new(NULL, NULL);
4134 q8tk_box_pack_start(vbox, fselect->stat.fselect.scrolled_window);
4135 q8tk_widget_show(fselect->stat.fselect.scrolled_window);
4136
4137 fselect->stat.fselect.file_list = q8tk_listbox_new();
4138 q8tk_container_add(fselect->stat.fselect.scrolled_window,
4139 fselect->stat.fselect.file_list);
4140 q8tk_widget_show(fselect->stat.fselect.file_list);
4141 q8tk_signal_connect(fselect->stat.fselect.file_list, "selection_changed",
4142 fsel_selection_changed_callback, window);
4143
4144 q8tk_misc_set_placement(fselect->stat.fselect.scrolled_window,
4145 Q8TK_PLACEMENT_X_CENTER, Q8TK_PLACEMENT_Y_CENTER);
4146 q8tk_scrolled_window_set_policy(fselect->stat.fselect.scrolled_window,
4147 Q8TK_POLICY_AUTOMATIC, Q8TK_POLICY_ALWAYS);
4148 q8tk_misc_set_size(fselect->stat.fselect.scrolled_window, 40, 14);
4149 q8tk_misc_set_size(fselect->stat.fselect.file_list, 40-3, 0);
4150 q8tk_listbox_set_placement(fselect->stat.fselect.file_list, -2, +1);
4151
4152 /* File name: */
4153 wk = q8tk_label_new("File name:");
4154 q8tk_box_pack_start(vbox, wk);
4155 q8tk_widget_show(wk);
4156 q8tk_misc_set_placement(wk, Q8TK_PLACEMENT_X_LEFT, Q8TK_PLACEMENT_Y_TOP);
4157
4158 /* [����ȥ���] */
4159 save_code = q8tk_set_kanjicode(osd_kanji_code());
4160 fselect->stat.fselect.selection_entry = q8tk_entry_new();
4161 q8tk_box_pack_start(vbox, fselect->stat.fselect.selection_entry);
4162 q8tk_widget_show(fselect->stat.fselect.selection_entry);
4163 q8tk_misc_set_size(fselect->stat.fselect.selection_entry,
4164 fselect->stat.fselect.width, 0);
4165 q8tk_signal_connect(fselect->stat.fselect.selection_entry, "activate",
4166 fsel_activate_callback, window);
4167 q8tk_set_kanjicode(save_code);
4168
4169 wk = q8tk_hbox_new(); /* [OK][CANCEL] */
4170 q8tk_box_pack_start(vbox, wk);
4171 q8tk_widget_show(wk);
4172 q8tk_misc_set_placement(wk, Q8TK_PLACEMENT_X_RIGHT, Q8TK_PLACEMENT_Y_TOP);
4173
4174 fselect->stat.fselect.ro_button =
4175 q8tk_check_button_new_with_label("Read only");
4176 q8tk_box_pack_start(wk, fselect->stat.fselect.ro_button);
4177 if (select_ro >= 0) {
4178 if (select_ro > 0) {
4179 q8tk_toggle_button_set_state(fselect->stat.fselect.ro_button,TRUE);
4180 }
4181 q8tk_widget_show(fselect->stat.fselect.ro_button);
4182 }
4183 q8tk_misc_set_placement(fselect->stat.fselect.ro_button,
4184 Q8TK_PLACEMENT_X_CENTER, Q8TK_PLACEMENT_Y_CENTER);
4185
4186 fselect->stat.fselect.ok_button = q8tk_button_new_with_label(" OK ");
4187 q8tk_box_pack_start(wk, fselect->stat.fselect.ok_button);
4188 q8tk_widget_show(fselect->stat.fselect.ok_button);
4189
4190 fselect->stat.fselect.cancel_button = q8tk_button_new_with_label("CANCEL");
4191 q8tk_box_pack_start(wk, fselect->stat.fselect.cancel_button);
4192 q8tk_widget_show(fselect->stat.fselect.cancel_button);
4193
4194 /* q8tk_file_selection_set_filename(window, Q8TK_FILE_SELECTION(fselect)->pathname);*/
4195
4196 return window;
4197 }
4198
4199 #else /* ver 0.6.0 �ʹߤ�ɽ������ */
4200
q8tk_file_selection_new(const char * title,int select_ro)4201 Q8tkWidget *q8tk_file_selection_new(const char *title, int select_ro)
4202 {
4203 Q8tkWidget *fselect, *window, *vbox, *hbox, *vv, *wk;
4204 int i, save_code;
4205
4206 fselect = malloc_widget();
4207 fselect->type = Q8TK_TYPE_FILE_SELECTION;
4208 fselect->sensitive = TRUE;
4209
4210 fselect->stat.fselect.pathname = (char *)calloc(Q8TK_MAX_FILENAME, 1);
4211 fselect->stat.fselect.filename = (char *)calloc(Q8TK_MAX_FILENAME, 1);
4212 Q8tkAssert(fselect->stat.fselect.pathname, "memory exhoused");
4213 Q8tkAssert(fselect->stat.fselect.filename, "memory exhoused");
4214
4215 window = q8tk_window_new(Q8TK_WINDOW_DIALOG); /* ������ɥ����� */
4216 window->stat.window.work = fselect;
4217
4218 vbox = q8tk_vbox_new(); /* �ʲ� ��ľ�˵ͤ�� */
4219 q8tk_container_add(window, vbox);
4220 q8tk_widget_show(vbox);
4221
4222 wk = q8tk_label_new(title); /* ����(�������) */
4223 q8tk_box_pack_start(vbox, wk);
4224 q8tk_widget_show(wk);
4225 q8tk_misc_set_placement(wk, Q8TK_PLACEMENT_X_CENTER, Q8TK_PLACEMENT_Y_TOP);
4226 fselect->stat.fselect.width = MAX(q8gr_strlen(wk->code, wk->name), 60);
4227
4228 wk = q8tk_hseparator_new(); /* ---------------- */
4229 q8tk_box_pack_start(vbox, wk);
4230 q8tk_widget_show(wk);
4231 /* DIR = /... */
4232 fselect->stat.fselect.dir_name = q8tk_label_new("DIR =");
4233 q8tk_box_pack_start(vbox, fselect->stat.fselect.dir_name);
4234 q8tk_widget_show(fselect->stat.fselect.dir_name);
4235 q8tk_misc_set_placement(fselect->stat.fselect.dir_name,
4236 Q8TK_PLACEMENT_X_LEFT, Q8TK_PLACEMENT_Y_TOP);
4237
4238 hbox = q8tk_hbox_new();
4239 q8tk_box_pack_start(vbox, hbox);
4240 q8tk_widget_show(hbox);
4241 {
4242 wk = q8tk_label_new(" "); /* ������ */
4243 q8tk_box_pack_start(hbox, wk);
4244 q8tk_widget_show(wk);
4245
4246 /* [�ꥹ��] */
4247 fselect->stat.fselect.scrolled_window
4248 = q8tk_scrolled_window_new(NULL, NULL);
4249 q8tk_box_pack_start(hbox, fselect->stat.fselect.scrolled_window);
4250 q8tk_widget_show(fselect->stat.fselect.scrolled_window);
4251
4252 fselect->stat.fselect.file_list = q8tk_listbox_new();
4253 q8tk_container_add(fselect->stat.fselect.scrolled_window,
4254 fselect->stat.fselect.file_list);
4255 q8tk_widget_show(fselect->stat.fselect.file_list);
4256 q8tk_signal_connect(fselect->stat.fselect.file_list,
4257 "selection_changed",
4258 fsel_selection_changed_callback, window);
4259
4260 q8tk_misc_set_placement(fselect->stat.fselect.scrolled_window,
4261 Q8TK_PLACEMENT_X_CENTER,
4262 Q8TK_PLACEMENT_Y_CENTER);
4263 q8tk_scrolled_window_set_policy(fselect->stat.fselect.scrolled_window,
4264 Q8TK_POLICY_AUTOMATIC,
4265 Q8TK_POLICY_ALWAYS);
4266 q8tk_misc_set_size(fselect->stat.fselect.scrolled_window, 40, 18);
4267 q8tk_misc_set_size(fselect->stat.fselect.file_list, 40-3, 0);
4268 q8tk_listbox_set_placement(fselect->stat.fselect.file_list, -2, +1);
4269
4270
4271 wk = q8tk_label_new(" "); /* ������ */
4272 q8tk_box_pack_start(hbox, wk);
4273 q8tk_widget_show(wk);
4274
4275
4276 vv = q8tk_vbox_new();
4277 q8tk_box_pack_start(hbox, vv);
4278 q8tk_widget_show(vv);
4279 {
4280
4281 wk = q8tk_label_new(""); /* ���� */
4282 q8tk_box_pack_start(vv, wk);
4283 q8tk_widget_show(wk);
4284
4285 /* n file(s) */
4286 fselect->stat.fselect.nr_files = q8tk_label_new("0000 file(s)");
4287 q8tk_box_pack_start(vv, fselect->stat.fselect.nr_files);
4288 q8tk_widget_show(fselect->stat.fselect.nr_files);
4289 q8tk_misc_set_placement(fselect->stat.fselect.nr_files,
4290 Q8TK_PLACEMENT_X_CENTER,
4291 Q8TK_PLACEMENT_Y_CENTER);
4292 #if 0
4293 for (i=0; i<9; i++) { /* ���� */
4294 wk = q8tk_label_new("");
4295 q8tk_box_pack_start(vv, wk);
4296 q8tk_widget_show(wk);
4297 }
4298 #else
4299 for (i=0; i<4; i++) { /* ���� */
4300 wk = q8tk_label_new("");
4301 q8tk_box_pack_start(vv, wk);
4302 q8tk_widget_show(wk);
4303 }
4304 /* [VIEW] */
4305 fselect->stat.fselect.view_button =
4306 q8tk_button_new_with_label(" VIEW ");
4307 q8tk_box_pack_start(vv, fselect->stat.fselect.view_button);
4308 q8tk_widget_show(fselect->stat.fselect.view_button);
4309 q8tk_misc_set_placement(fselect->stat.fselect.view_button,
4310 Q8TK_PLACEMENT_X_CENTER,
4311 Q8TK_PLACEMENT_Y_CENTER);
4312 q8tk_signal_connect(fselect->stat.fselect.view_button, "clicked",
4313 fsel_selection_view_callback, window);
4314
4315 for (i=0; i<2; i++) { /* ���� */
4316 wk = q8tk_label_new("");
4317 q8tk_box_pack_start(vv, wk);
4318 q8tk_widget_show(wk);
4319 }
4320 #endif
4321
4322 /* Read only */
4323 fselect->stat.fselect.ro_button =
4324 q8tk_check_button_new_with_label("Read only");
4325 q8tk_box_pack_start(vv, fselect->stat.fselect.ro_button);
4326 q8tk_misc_set_placement(fselect->stat.fselect.ro_button,
4327 Q8TK_PLACEMENT_X_CENTER,
4328 Q8TK_PLACEMENT_Y_CENTER);
4329 if (select_ro >= 0) {
4330 if (select_ro > 0) {
4331 q8tk_toggle_button_set_state(
4332 fselect->stat.fselect.ro_button, TRUE);
4333 }
4334 q8tk_widget_show(fselect->stat.fselect.ro_button);
4335 }
4336
4337 /* [OK] */
4338 fselect->stat.fselect.ok_button =
4339 q8tk_button_new_with_label(" OK ");
4340 q8tk_box_pack_start(vv, fselect->stat.fselect.ok_button);
4341 q8tk_widget_show(fselect->stat.fselect.ok_button);
4342 q8tk_misc_set_placement(fselect->stat.fselect.ok_button,
4343 Q8TK_PLACEMENT_X_CENTER,
4344 Q8TK_PLACEMENT_Y_CENTER);
4345
4346 /* [CANCEL] */
4347 fselect->stat.fselect.cancel_button =
4348 q8tk_button_new_with_label("CANCEL");
4349 q8tk_box_pack_start(vv, fselect->stat.fselect.cancel_button);
4350 q8tk_widget_show(fselect->stat.fselect.cancel_button);
4351 q8tk_misc_set_placement(fselect->stat.fselect.cancel_button,
4352 Q8TK_PLACEMENT_X_CENTER,
4353 Q8TK_PLACEMENT_Y_CENTER);
4354 }
4355
4356 #if 0
4357 wk = q8tk_label_new(" "); /* ������ */
4358 q8tk_box_pack_start(hbox, wk);
4359 q8tk_widget_show(wk);
4360 #endif
4361 }
4362
4363
4364 wk = q8tk_label_new(""); /* ���� */
4365 q8tk_box_pack_start(vbox, wk);
4366 q8tk_widget_show(wk);
4367
4368 hbox = q8tk_hbox_new();
4369 q8tk_box_pack_start(vbox, hbox);
4370 q8tk_widget_show(hbox);
4371 {
4372 /* File name: */
4373 wk = q8tk_label_new("Filename ");
4374 q8tk_box_pack_start(hbox, wk);
4375 q8tk_widget_show(wk);
4376
4377 /* [����ȥ���] */
4378 save_code = q8tk_set_kanjicode(osd_kanji_code());
4379 fselect->stat.fselect.selection_entry = q8tk_entry_new();
4380 q8tk_box_pack_start(hbox, fselect->stat.fselect.selection_entry);
4381 q8tk_widget_show(fselect->stat.fselect.selection_entry);
4382 q8tk_misc_set_size(fselect->stat.fselect.selection_entry, 50, 0);
4383 q8tk_signal_connect(fselect->stat.fselect.selection_entry, "activate",
4384 fsel_activate_callback, window);
4385 q8tk_set_kanjicode(save_code);
4386 }
4387
4388 /* q8tk_file_selection_set_filename(window, Q8TK_FILE_SELECTION(fselect)->pathname);*/
4389
4390 return window;
4391 }
4392
4393 #endif
4394
q8tk_file_selection_get_filename(Q8tkWidget * fselect)4395 const char *q8tk_file_selection_get_filename(Q8tkWidget *fselect)
4396 {
4397 if (osd_path_join(Q8TK_FILE_SELECTION(fselect)->pathname,
4398 q8tk_entry_get_text(Q8TK_FILE_SELECTION(fselect)
4399 ->selection_entry),
4400 Q8TK_FILE_SELECTION(fselect)->filename,
4401 Q8TK_MAX_FILENAME)
4402 == FALSE) {
4403 return "";
4404 }
4405
4406 return Q8TK_FILE_SELECTION(fselect)->filename;
4407 }
4408
q8tk_file_selection_set_filename(Q8tkWidget * fselect,const char * filename)4409 void q8tk_file_selection_set_filename(Q8tkWidget *fselect,
4410 const char *filename)
4411 {
4412 fsel_opendir(fselect, filename, -1);
4413 }
4414
q8tk_file_selection_get_readonly(Q8tkWidget * fselect)4415 int q8tk_file_selection_get_readonly(Q8tkWidget *fselect)
4416 {
4417 return Q8TK_TOGGLE_BUTTON(Q8TK_FILE_SELECTION(fselect)->ro_button)->active;
4418 }
4419
4420
4421
4422
4423 /*---------------------------------------------------------------------------
4424 * FILE VIEWER
4425 *---------------------------------------------------------------------------
4426 * �����������Ǻ�ä����ե���������äȤ����ߤ�桼�ƥ���ƥ�
4427 * ���ƥ����ȥե������Ƚ�Ǥϡ���ĥ�ҤΤ�
4428 * SJIS �� EUC �� UTF8 ����ۣ���Ƚ��
4429 * �����Τ����ˤ����Ȥ�����Τ���Ȥ��褦�ġġ�
4430 * �Ȥ����������褬�褯�ʤ뵤�ۤ��ʤ���оä����ġġ�
4431 * �����ʤߤ˥������åȤǤϤʤ��������ʤ�ե�����ɽ�����롣
4432 *---------------------------------------------------------------------------*/
4433 #define VIEW_MAX_LINE (1000) /* 1000�Ԥ���ɽ�� */
4434 #define VIEW_MAX_COLUMN (80) /* 80��ʹߤ���ɽ�� */
4435 static Q8tkWidget *view_widget_win;
4436 static Q8tkWidget *view_widget_vbox;
4437 static Q8tkWidget *view_widget_swin;
4438 static Q8tkWidget *view_widget_board;
4439 static Q8tkWidget *view_widget_quit;
4440 static Q8tkWidget *view_widget_accel;
4441 static Q8tkWidget *view_string[ VIEW_MAX_LINE ];
4442 static int view_string_cnt;
4443
4444 static void q8tk_utility_view_end(UNUSED_WIDGET, UNUSED_PARM);
q8tk_utility_view(const char * filename)4445 int q8tk_utility_view(const char *filename)
4446 {
4447 int save_code, file_code, file_text;
4448 OSD_FILE *fp;
4449 Q8tkWidget *w, *swin, *x, *b, *z;
4450
4451 if (filename == NULL || *filename == '\0' ||
4452 osd_file_stat(filename) != FILE_STAT_FILE) {
4453 return 0;
4454 }
4455
4456 fp = osd_fopen(FTYPE_READ, filename, "rb");
4457
4458 if (fp == NULL) {
4459 return 0;
4460 }
4461
4462 {
4463 int l = strlen(filename);
4464 if (l >= 4 && ((filename[l-4] == '.') &&
4465 (filename[l-3] == 'T' || filename[l-3] == 't') &&
4466 (filename[l-2] == 'X' || filename[l-2] == 'x') &&
4467 (filename[l-1] == 'T' || filename[l-1] == 't'))) {
4468 file_text = TRUE;
4469 } else {
4470 file_text = FALSE;
4471 }
4472 }
4473
4474 if (file_text == FALSE) { /* �Х��ʥ�ե����� */
4475
4476 file_code = Q8TK_KANJI_ANK;
4477
4478 } else { /* �ƥ����ȥե����� */
4479 /* �ե�������Ƭ 1KB ��Ŭ���˸��� */
4480 int sz; /* ���������ɤ�Ƚ�ꡣ�ۤ�Ȥ�Ŭ�� */
4481 char buf[1024];
4482
4483 sz = (int)osd_fread(buf, sizeof(char), sizeof(buf), fp);
4484 if (osd_fseek(fp, 0, SEEK_SET) == -1) {
4485 osd_fclose(fp);
4486 return 0;
4487 }
4488 file_code = q8gr_strcode(buf, sz);
4489 }
4490
4491
4492
4493 { /* �ᥤ��Ȥʤ륦����ɥ� */
4494 w = q8tk_window_new(Q8TK_WINDOW_DIALOG);
4495 view_widget_accel = q8tk_accel_group_new();
4496 q8tk_accel_group_attach(view_widget_accel, w);
4497 }
4498 { /* ����˥ܥå�����褻�� */
4499 x = q8tk_vbox_new();
4500 q8tk_container_add(w, x);
4501 q8tk_widget_show(x);
4502 /* �ܥå����ˤ� */
4503 { /* SCRL������ɥ��� */
4504 swin = q8tk_scrolled_window_new(NULL, NULL);
4505 q8tk_widget_show(swin);
4506 q8tk_scrolled_window_set_policy(swin, Q8TK_POLICY_AUTOMATIC,
4507 Q8TK_POLICY_AUTOMATIC);
4508 q8tk_misc_set_size(swin, 78, 20);
4509 q8tk_box_pack_start(x, swin);
4510 }
4511 { /* ��λ�ܥ�������� */
4512 b = q8tk_button_new_with_label(" O K ");
4513 q8tk_box_pack_start(x, b);
4514 q8tk_widget_show(b);
4515
4516 q8tk_misc_set_placement(b, Q8TK_PLACEMENT_X_CENTER,
4517 Q8TK_PLACEMENT_Y_CENTER);
4518 q8tk_signal_connect(b, "clicked", q8tk_utility_view_end, NULL);
4519
4520 q8tk_accel_group_add(view_widget_accel, Q8TK_KEY_ESC,
4521 b, "clicked");
4522 }
4523 }
4524
4525 { /* SCRL������ɥ��� */
4526 z = q8tk_vbox_new(); /* VBOX���ä� */
4527 q8tk_container_add(swin, z);
4528 q8tk_widget_show(z);
4529
4530 save_code = q8tk_set_kanjicode(file_code); /* �ե��������Ƥ� */
4531 /* ��٥�Ȥ������� */
4532 {
4533 int c1, c2;
4534 int column, line;
4535 int end_of_line, end_of_file;
4536 char src[ VIEW_MAX_COLUMN + 1 ];
4537
4538 c2 = osd_fgetc(fp);
4539
4540 line = 0;
4541 end_of_file = FALSE;
4542 memset(src, 0, sizeof(src));
4543
4544 while (end_of_file == FALSE) {
4545
4546 if (file_text) { /* �ƥ����ȥե����� */
4547 column = 0;
4548 end_of_line = FALSE;
4549 memset(src, 0, sizeof(src));
4550
4551 while (end_of_line == FALSE) {
4552
4553 c1 = c2;
4554 c2 = osd_fgetc(fp);
4555 if (c1 == '\r' && c2 == '\n') c2 = osd_fgetc(fp);
4556
4557 if (c1 == EOF) {
4558 c1 = '\0';
4559 end_of_line = TRUE;
4560 end_of_file = TRUE;
4561 }
4562 else if ((c1 == '\r') || (c1 == '\n')) {
4563 c1 = '\0';
4564 end_of_line = TRUE;
4565 }
4566
4567
4568 if (c1 == '\t') { /* �����ִ� */
4569 int len = q8gr_strlen(file_code, src);
4570 int pad = ((len + 8) / 8) * 8 - len;
4571 int i;
4572 for (i=0; i<pad; i++) {
4573 if (column < (int)sizeof(src)-1) {
4574 src[ column ] = ' ';
4575 column ++;
4576 }
4577 }
4578 }
4579 else if (column < (int)sizeof(src)-1) { /* ���ְʳ� */
4580 src[ column ] = c1;
4581 column ++;
4582 }
4583 }
4584
4585 } else { /* �Х��ʥ�ե����� */
4586 int c[16];
4587 char fmt[128];
4588
4589 if (c2 == EOF) {
4590 strcpy(src, "[EOF]");
4591 end_of_file = TRUE;
4592 } else {
4593 for (column = 0; column < 16 && c2 != EOF; column ++) {
4594 c[column] = c2;
4595 c2 = osd_fgetc(fp);
4596 }
4597
4598 strcpy(fmt, "%04X : ");
4599 while (column--) { strcat(fmt, "%02X "); }
4600
4601 sprintf(src, fmt, line * 0x10,
4602 c[ 0], c[ 1], c[ 2], c[ 3],
4603 c[ 4], c[ 5], c[ 6], c[ 7],
4604 c[ 8], c[ 9], c[10], c[11],
4605 c[12], c[13], c[14], c[15]);
4606 }
4607 }
4608
4609
4610 if (line == COUNTOF(view_string)-1)
4611 strcpy(src, "........To be continued.");
4612
4613 view_string[ line ] = q8tk_label_new(src);
4614 q8tk_widget_show(view_string[ line ]);
4615 q8tk_box_pack_start(z, view_string[ line ]);
4616
4617 line ++;
4618 if (line >= COUNTOF(view_string)) break;
4619 }
4620
4621 view_string_cnt = line;
4622 }
4623 q8tk_set_kanjicode(save_code);
4624 }
4625
4626 osd_fclose(fp);
4627
4628
4629 q8tk_widget_show(w);
4630 q8tk_grab_add(w);
4631
4632 q8tk_widget_set_focus(b);
4633
4634
4635 view_widget_win = w; /* �����������Ĥ����Ȥ��������� */
4636 view_widget_vbox = x; /* �������åȤ�Ф��Ƥ����ޤ� */
4637 view_widget_swin = swin;
4638 view_widget_board = z;
4639 view_widget_quit = b;
4640
4641 return 1;
4642 }
4643
q8tk_utility_view_end(UNUSED_WIDGET,UNUSED_PARM)4644 static void q8tk_utility_view_end(UNUSED_WIDGET, UNUSED_PARM)
4645 {
4646 int i;
4647 for (i=0; i<view_string_cnt; i++)
4648 q8tk_widget_destroy(view_string[ i ]);
4649
4650 q8tk_widget_destroy(view_widget_quit);
4651 q8tk_widget_destroy(view_widget_board);
4652 q8tk_widget_destroy(view_widget_swin);
4653 q8tk_widget_destroy(view_widget_vbox);
4654
4655 q8tk_grab_remove(view_widget_win);
4656 q8tk_widget_destroy(view_widget_win);
4657 q8tk_widget_destroy(view_widget_accel);
4658 }
4659
4660
4661
4662
4663 /************************************************************************/
4664 /* ��¿�ʽ��� */
4665 /************************************************************************/
4666
4667 /*---------------------------------------------------------------------------
4668 * ɽ�����֤��ѹ�
4669 *---------------------------------------------------------------------------
4670 * ��HBOX��VBOXľ���λҤΥ������åȤΤ�ͭ����¾��̵�� (̵��)
4671 * -------------------------------------------------------------------------
4672 * void q8tk_misc_set_placement(Q8tkWidget *widget,
4673 * int placement_x, int placement_y)
4674 *---------------------------------------------------------------------------*/
q8tk_misc_set_placement(Q8tkWidget * widget,int placement_x,int placement_y)4675 void q8tk_misc_set_placement(Q8tkWidget *widget,
4676 int placement_x, int placement_y)
4677 {
4678 widget->placement_x = placement_x;
4679 widget->placement_y = placement_y;
4680 }
4681
4682 /*---------------------------------------------------------------------------
4683 * ɽ�����������ѹ�
4684 *---------------------------------------------------------------------------
4685 * ���ʲ��Υ������åȤΤ�ͭ����¾��̵�� (̵��)
4686 * COMBO �� ʸ������ʬ��ɽ����
4687 * LIST �� ʸ�����ɽ����
4688 * SCROLLED WINDOW �� ������ɥ��������⤵
4689 * ENTRY �� ʸ�����ɽ����
4690 * -------------------------------------------------------------------------
4691 * void q8tk_misc_set_size(Q8tkWidget *widget, int width, int height)
4692 *---------------------------------------------------------------------------*/
q8tk_misc_set_size(Q8tkWidget * widget,int width,int height)4693 void q8tk_misc_set_size(Q8tkWidget *widget, int width, int height)
4694 {
4695 switch (widget->type) {
4696
4697 case Q8TK_TYPE_COMBO:
4698 if (width > 0) {
4699 widget->stat.combo.width = width;
4700 q8tk_misc_set_size(widget->stat.combo.entry,
4701 widget->stat.combo.width, 0);
4702 } else {
4703 widget->stat.combo.width = 0;
4704 q8tk_misc_set_size(widget->stat.combo.entry,
4705 widget->stat.combo.length, 0);
4706 }
4707 break;
4708
4709 case Q8TK_TYPE_LISTBOX:
4710 if (width > 0) widget->stat.listbox.width = width;
4711 else widget->stat.listbox.width = 0;
4712 break;
4713
4714 case Q8TK_TYPE_SCROLLED_WINDOW:
4715 widget->stat.scrolled.width = width;
4716 widget->stat.scrolled.height = height;
4717
4718 if (widget->with_label) {
4719 q8tk_adjustment_set_increment(widget->stat.scrolled.hadj,
4720 1, MAX(10, width - 3));
4721 q8tk_adjustment_set_increment(widget->stat.scrolled.vadj,
4722 1, MAX(10, height - 3));
4723 }
4724 break;
4725
4726 case Q8TK_TYPE_ENTRY:
4727 widget->stat.entry.width = width;
4728 q8tk_entry_set_position(widget, widget->stat.entry.cursor_pos);
4729 break;
4730
4731 default:
4732 fprintf(stderr, "Cant resize widget=%s\n", debug_type(widget->type));
4733 Q8tkAssert(FALSE, NULL);
4734 return;
4735 }
4736 set_construct_flag(TRUE);
4737 }
4738
4739
4740
4741
4742 /************************************************************************/
4743 /* ����ƥʴط� */
4744 /************************************************************************/
4745 /*---------------------------------------------------------------------------
4746 * ����ƥ����
4747 *---------------------------------------------------------------------------
4748 * ������ƥʥ������åȤȥ������åȤ�ƻҤˤ���
4749 * -------------------------------------------------------------------------
4750 * void q8tk_container_add(Q8tkWidget *container, Q8tkWidget *widget)
4751 * ����ƥʥ������å� container �� �������å� widget ��ƻҤˤ��롣
4752 *
4753 * void q8tk_box_pack_start(Q8tkWidget *box, Q8tkWidget *widget)
4754 * ��ʿ����ľ�ܥå��� box �θ����ˡ��������å� widget ��ͤ�롣
4755 *
4756 * void q8tk_box_pack_end(Q8tkWidget *box, Q8tkWidget *widget)
4757 * ��ʿ����ľ�ܥå��� box �������ˡ��������å� widget ��ͤ�롣
4758 *
4759 * void q8tk_container_remove(Q8tkWidget *container, Q8tkWidget *widget)
4760 * ����ƥʥ������å� container ���� �������å� widget ���ڤ�Υ����
4761 *---------------------------------------------------------------------------*/
q8tk_container_add(Q8tkWidget * container,Q8tkWidget * widget)4762 void q8tk_container_add(Q8tkWidget *container, Q8tkWidget *widget)
4763 {
4764 Q8tkAssert(container->attr & Q8TK_ATTR_CONTAINER, NULL);
4765 if (container->attr & Q8TK_ATTR_LABEL_CONTAINER) {
4766 Q8tkAssert(widget->type == Q8TK_TYPE_LABEL, NULL);
4767 }
4768
4769 switch (container->type) {
4770 case Q8TK_TYPE_LISTBOX: /* LIST BOX �㳰���� */
4771 if (container->child == NULL) { /* �ǽ�� LIST ITEM */
4772 container->stat.listbox.selected = widget; /* �ξ��ϡ������ */
4773 container->stat.listbox.active = widget; /* ������֤ˤ��� */
4774 }
4775 q8tk_box_pack_start(container, widget); /* ������VBOX��Ʊ�� */
4776 return;
4777
4778 default: /* �̾�ν��� */
4779 container->child = widget;
4780 widget->parent = container;
4781 widget->prev = NULL;
4782 widget->next = NULL;
4783 break;
4784 }
4785
4786 if (widget->visible) {
4787 widget_map(widget);
4788 }
4789 }
4790
q8tk_box_pack_start(Q8tkWidget * box,Q8tkWidget * widget)4791 void q8tk_box_pack_start(Q8tkWidget *box, Q8tkWidget *widget)
4792 {
4793 Q8tkAssert(box->attr & Q8TK_ATTR_CONTAINER, NULL);
4794
4795 if (box->child == NULL) {
4796 box->child = widget;
4797 widget->prev = NULL;
4798 widget->next = NULL;
4799 } else {
4800 Q8tkWidget *c = box->child;
4801 while (c->next) {
4802 c = c->next;
4803 }
4804 c->next = widget;
4805 widget->prev = c;
4806 widget->next = NULL;
4807 }
4808 widget->parent = box;
4809
4810 if (widget->visible) {
4811 widget_map(widget);
4812 }
4813 }
4814
q8tk_box_pack_end(Q8tkWidget * box,Q8tkWidget * widget)4815 void q8tk_box_pack_end(Q8tkWidget *box, Q8tkWidget *widget)
4816 {
4817 Q8tkAssert(box->attr & Q8TK_ATTR_CONTAINER, NULL);
4818
4819 if (box->child == NULL) {
4820 widget->prev = NULL;
4821 widget->next = NULL;
4822 } else {
4823 Q8tkWidget *c = box->child;
4824 Q8tkAssert(c->prev == NULL, NULL);
4825 c->prev = widget;
4826 widget->next = c;
4827 widget->prev = NULL;
4828 }
4829 box->child = widget;
4830 widget->parent = box;
4831
4832 if (widget->visible) {
4833 widget_map(widget);
4834 }
4835 }
4836
q8tk_container_remove(Q8tkWidget * container,Q8tkWidget * widget)4837 void q8tk_container_remove(Q8tkWidget *container, Q8tkWidget *widget)
4838 {
4839 Q8tkAssert(container->attr & Q8TK_ATTR_CONTAINER, NULL);
4840 Q8tkAssert(widget->parent == container, NULL);
4841
4842 if (widget->prev == NULL) { /* ��ʬ���Ƥ�ľ���λ� */
4843 Q8tkWidget *n = widget->next;
4844 if (n) n->prev = NULL;
4845 container->child = n;
4846
4847 } else { /* ��������ʤ��� */
4848 Q8tkWidget *p = widget->prev;
4849 Q8tkWidget *n = widget->next;
4850 if (n) n->prev = p;
4851 p->next = n;
4852 }
4853
4854 widget->parent = NULL;
4855 widget->prev = NULL;
4856 widget->next = NULL;
4857
4858 switch (container->type) {
4859
4860 case Q8TK_TYPE_LISTBOX: /* LIST BOX �㳰���� */
4861 if (container->stat.listbox.selected == widget) {
4862 container->stat.listbox.selected = NULL;
4863 container->stat.listbox.active = NULL;
4864 }
4865 break;
4866
4867 }
4868
4869
4870 if (container->visible) {
4871 widget_map(container);
4872 }
4873 }
4874
4875
4876 /************************************************************************/
4877 /* ɽ���ط� */
4878 /************************************************************************/
4879 /*---------------------------------------------------------------------------
4880 * �Ļ벽���ԲĻ벽
4881 *---------------------------------------------------------------------------
4882 * ���������åȤ�ɽ������ɽ��
4883 * -------------------------------------------------------------------------
4884 * void q8tk_widget_show(Q8tkWidget *widget)
4885 * �������åȤ�ɽ�����롣
4886 *
4887 * void q8tk_widget_hide(Q8tkWidget *widget)
4888 * �������åȤ���ɽ���ˤ��롣�Ҥ�������ɽ���ˤʤ롣
4889 *---------------------------------------------------------------------------*/
q8tk_widget_show(Q8tkWidget * widget)4890 void q8tk_widget_show(Q8tkWidget *widget)
4891 {
4892 widget->visible = TRUE;
4893 widget_map(widget);
4894 }
q8tk_widget_hide(Q8tkWidget * widget)4895 void q8tk_widget_hide(Q8tkWidget *widget)
4896 {
4897 widget->visible = FALSE;
4898 widget_map(widget);
4899 }
4900
4901
4902 /*---------------------------------------------------------------------------
4903 * ������
4904 *---------------------------------------------------------------------------
4905 * ���������åȤ�������
4906 * -------------------------------------------------------------------------
4907 * void q8tk_widget_set_sensitive(Q8tkWidget *widget, int sensitive)
4908 * �������åȤ�����ǽ�������ǽ�ˤ��롣
4909 * ---------------------------------------------------------------------
4910 * �����ݤϡ��Ҥ�����롣
4911 * �����ǽ�ʥ������åȤϡ��̾�Ȥϰ㤦��(��Ϥο�)��ɽ���Ȥʤ롣
4912 * ��Ȥ�����Ǥ��ʤ��������å�(��٥�ʤ�)���Ф��Ƥ⡢����Ǥ��롣
4913 * ---------------------------------------------------------------------
4914 * LOGO / VSEPARATOR / HSEPARATOR �ϡ������ǽ�ˤ��Ƥ���Ѳ����ʤ���
4915 * (�Ѳ��������ۤ�����������?)
4916 *
4917 * NOTEPAGE �ϡ������ǥ���ƥ�(NOTEPAGE)��ư����������ȤߤʤΤǡ�
4918 * �����ݤ�����Ǥ��ʤ��� (̵����ꤵ��������С�
4919 * q8tk_widget_set_sensitive(widget->parent, FALSE) �ǤǤ��뤬��)
4920 *
4921 * ADJUSTMENT �������ݤ�����Ǥ��뤬����������ʤɤΤۤ������ꤹ��
4922 * �������顢ľ�ܻ��ꤹ�뤳�ȤϤʤ�������
4923 *---------------------------------------------------------------------------*/
q8tk_widget_set_sensitive(Q8tkWidget * widget,int sensitive)4924 void q8tk_widget_set_sensitive(Q8tkWidget *widget, int sensitive)
4925 {
4926 widget->sensitive = sensitive;
4927 widget_map(widget);
4928 }
4929
4930
4931 /************************************************************************/
4932 /* �������åȤξõ� */
4933 /************************************************************************/
4934 /*---------------------------------------------------------------------------
4935 * �������åȾõ�
4936 *---------------------------------------------------------------------------
4937 * ���������åȤ�õ��
4938 * �������� ��q8tk_dialog_new �ˤ����������������å����ƾõ
4939 * vbox �� action_area �˺ܤ����������åȤϾõ�
4940 * ���ʤ��Τơ��ƤӽФ����Ǿõ�롣
4941 *
4942 * �ե����륻�쥯����� �� �����������������ƤΥ������åȤ�õ
4943 * �ե�����������������������������åȤ����ƾõ�
4944 *
4945 * ����¾ �� �����Ǽ�ư���������������åȤ⤢�碌�ƾõ
4946 * q8tk_xxx_new_with_label ������������٥�䡢
4947 * q8tk_scrolled_window_new �Ǽ�ư��������
4948 * �����㥹�ȥ��Ȥʤ�
4949 * -------------------------------------------------------------------------
4950 * void q8tk_widget_destroy(Q8tkWidget *widget)
4951 * �������åȤξõ�ʹߡ������� widget �ϻ��Ѷػ�
4952 *
4953 *---------------------------------------------------------------------------*/
4954 static void widget_destroy_all(Q8tkWidget *widget);
4955
q8tk_widget_destroy(Q8tkWidget * widget)4956 void q8tk_widget_destroy(Q8tkWidget *widget)
4957 {
4958 Q8tkWidget *work;
4959
4960 if (widget->type == Q8TK_TYPE_WINDOW && /* DIALOG �� FILE SELECTION */
4961 (work = widget->stat.window.work)) { /* ���㳰���� */
4962
4963 switch (work->type) {
4964 case Q8TK_TYPE_DIALOG:
4965 Q8tkAssert(widget->child->type == Q8TK_TYPE_FRAME, NULL);
4966 Q8tkAssert(widget->child->child->type == Q8TK_TYPE_VBOX, NULL);
4967 q8tk_widget_destroy(Q8TK_DIALOG(widget)->action_area);
4968 q8tk_widget_destroy(Q8TK_DIALOG(widget)->vbox);
4969 q8tk_widget_destroy(widget->child->child);
4970 q8tk_widget_destroy(widget->child);
4971 q8tk_widget_destroy(work);
4972 break;
4973
4974 case Q8TK_TYPE_FILE_SELECTION:
4975 {
4976 q8tk_widget_destroy(
4977 (Q8TK_FILE_SELECTION(widget)->scrolled_window)
4978 ->stat.scrolled.hadj);
4979 q8tk_widget_destroy(
4980 (Q8TK_FILE_SELECTION(widget)->scrolled_window)
4981 ->stat.scrolled.vadj);
4982
4983 free(Q8TK_FILE_SELECTION(widget)->pathname);
4984 free(Q8TK_FILE_SELECTION(widget)->filename);
4985
4986 /* �ط����Ϥä��ꤷ�Ƥ���Τǡ�����̵�Ѥ����Ƥ�õ� */
4987 widget_destroy_all(widget->child);
4988 }
4989 q8tk_widget_destroy(work);
4990 break;
4991 }
4992 }
4993
4994 if (widget->type == Q8TK_TYPE_COMBO) { /* COMBO ���㳰���� */
4995 Q8List *l = widget->stat.combo.list;
4996 while (l) {
4997 q8tk_widget_destroy((Q8tkWidget *)(widget->stat.combo.list->data));
4998 l = l->next;
4999 }
5000 q8_list_free(widget->stat.combo.list);
5001 q8tk_widget_destroy(widget->stat.combo.entry);
5002 }
5003
5004 if (widget->type == Q8TK_TYPE_ACCEL_GROUP && /* ACCEL �λҤ����ƾõ� */
5005 widget->child) {
5006 /* �ط����Ϥä��ꤷ�Ƥ���Τǡ�����̵�Ѥ����Ƥ�õ� */
5007 widget_destroy_all(widget->child);
5008 }
5009
5010
5011 if (widget->with_label && /* XXX_new_with_label()�� */
5012 widget->child && /* �������줿 LABEL�ν��� */
5013 widget->child->type == Q8TK_TYPE_LABEL) {
5014 q8tk_widget_destroy(widget->child);
5015 }
5016 if (widget->with_label && /* ���� NULL ���������줿*/
5017 widget->type == Q8TK_TYPE_SCROLLED_WINDOW) {/* SCROLLED WINDOW ���*/
5018 q8tk_widget_destroy(widget->stat.scrolled.hadj);
5019 q8tk_widget_destroy(widget->stat.scrolled.vadj);
5020 }
5021
5022 if (widget->name) {
5023 free(widget->name);
5024 widget->name = NULL;
5025 }
5026 free_widget(widget);
5027 }
5028
5029
5030 /* ���Ȥȡ��Ҥȡ���֤����ƺ����
5031 ���Ȱʲ��Υ������åȤκ���ˤ��㳰������̵�����Ȥ��狼�äƤ�����Τ߲� */
5032
widget_destroy_all(Q8tkWidget * widget)5033 static void widget_destroy_all(Q8tkWidget *widget)
5034 {
5035 if (widget->next) widget_destroy_all(widget->next);
5036 if (widget->child) widget_destroy_all(widget->child);
5037
5038 if (widget->name) {
5039 free(widget->name);
5040 widget->name = NULL;
5041 }
5042 free_widget(widget);
5043 }
5044
5045
5046
5047
5048 /************************************************************************/
5049 /* ����Υ������åȤ˥ե������������Ƥ롣 */
5050 /* �̾� �ե��������ϡ�ľ���˥ܥ���䥭�����Ϥ��ʤ��줿�������å� */
5051 /* �ˤʤꡢTAB �ˤ�����ؤ���ǽ���������δؿ�������Υ������å� */
5052 /* �˥ե������������ꤹ�뤳�Ȥ��Ǥ��롣 */
5053 /* �����������Υ������åȤΰ������Ĥ� WINDOW ����q8tk_grab_add()�� */
5054 /* ������ʤ��줿���ȤǤʤ����̵���Ǥ��롣 */
5055 /************************************************************************/
q8tk_widget_set_focus(Q8tkWidget * widget)5056 void q8tk_widget_set_focus(Q8tkWidget *widget)
5057 {
5058 focus_widget[ window_layer_level ] = widget;
5059 set_construct_flag(TRUE);
5060 }
5061
5062
5063 /************************************************************************/
5064 /* �����ʥ�ط� */
5065 /************************************************************************/
5066 /*
5067 * Ǥ�դΥ������åȤˡ�Ǥ�դΥ����ʥ������
5068 */
widget_signal_do(Q8tkWidget * widget,const char * name)5069 static void widget_signal_do(Q8tkWidget *widget, const char *name)
5070 {
5071 switch (widget->type) {
5072 case Q8TK_TYPE_WINDOW: /* ������ɥ� */
5073 if (strcmp(name, "inactivate") == 0) {
5074 if (widget->user_event_0) {
5075 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5076 }
5077 return;
5078 }
5079 break;
5080 case Q8TK_TYPE_BUTTON: /* �ܥ��� */
5081 if (strcmp(name, "clicked") == 0) {
5082 if (widget->user_event_0) {
5083 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5084 }
5085 return;
5086 }
5087 break;
5088 case Q8TK_TYPE_TOGGLE_BUTTON: /* �ȥ���ܥ��� */
5089 case Q8TK_TYPE_CHECK_BUTTON: /* �����å��ܥ��� */
5090 case Q8TK_TYPE_RADIO_BUTTON: /* �饸���ܥ��� */
5091 if (strcmp(name, "clicked") == 0) {
5092 if (widget->user_event_0) {
5093 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5094 }
5095 return;
5096 } else if (strcmp(name, "toggled") == 0) {
5097 if (widget->user_event_1) {
5098 (*widget->user_event_1)(widget, widget->user_event_1_parm);
5099 }
5100 return;
5101 }
5102 break;
5103
5104 case Q8TK_TYPE_NOTEBOOK: /* �Ρ��ȥ֥å� */
5105 if (strcmp(name, "switch_page") == 0) {
5106 if (widget->user_event_0) {
5107 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5108 }
5109 return;
5110 }
5111 break;
5112
5113 case Q8TK_TYPE_COMBO: /* ����ܥܥå��� */
5114 if (strcmp(name, "activate") == 0) {
5115 if (widget->user_event_0) {
5116 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5117 }
5118 return;
5119 } else if (strcmp(name, "changed") == 0) {
5120 if (widget->user_event_1) {
5121 (*widget->user_event_1)(widget, widget->user_event_1_parm);
5122 }
5123 return;
5124 }
5125 break;
5126
5127 case Q8TK_TYPE_LISTBOX: /* �ꥹ�ȥܥå��� */
5128 if (strcmp(name, "selection_changed") == 0) {
5129 if (widget->user_event_0) {
5130 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5131 }
5132 return;
5133 }
5134 break;
5135
5136 case Q8TK_TYPE_LIST_ITEM: /* �ꥹ�ȥ����ƥ� */
5137 if (strcmp(name, "select") == 0) {
5138 if (widget->user_event_0) {
5139 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5140 }
5141 return;
5142 }
5143 break;
5144
5145 case Q8TK_TYPE_ADJUSTMENT: /* �����㥹�ȥ��� */
5146 if (strcmp(name, "value_changed") == 0) {
5147 if (widget->user_event_0) {
5148 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5149 }
5150 return;
5151 }
5152 break;
5153
5154 case Q8TK_TYPE_ENTRY: /* ����ȥ */
5155 if (strcmp(name, "activate") == 0) {
5156 if (widget->user_event_0) {
5157 (*widget->user_event_0)(widget, widget->user_event_0_parm);
5158 }
5159 return;
5160 } else if (strcmp(name, "changed") == 0) {
5161 if (widget->user_event_1) {
5162 (*widget->user_event_1)(widget, widget->user_event_1_parm);
5163 }
5164 return;
5165 }
5166 break;
5167
5168 }
5169
5170 fprintf(stderr, "BAD signal %s '%s'\n", debug_type(widget->type), name);
5171 Q8tkAssert(FALSE, NULL);
5172 return;
5173 }
5174
5175
5176 /*---------------------------------------------------------------------------
5177 * �����ʥ�����ꡦ���
5178 *---------------------------------------------------------------------------
5179 * ���������åȤΥ����ʥ�ˡ�������Хå��ؿ������ꤹ�롣
5180 * �ƥ������åȤ��Ȥ�ȯ�����륷���ʥ뤬��ޤäƤ���Τǡ����Υ����ʥ뤬
5181 * ȯ���������˸ƤӽФ����ؿ������ꤹ�롣
5182 * �����������ꤹ��ؿ������Ǽ�ʬ���ȤΥ������åȤ�������褦�ʤ��Ȥ�
5183 * ���ƤϤ����ʤ��������Ǹ�ư����ǽ�������롣
5184 * (���������ܥ������åȤ˸¤ꡢ��ǽ�Ȥ��롣�ʤΤǡ�����������
5185 * �ե����륻�쥯�����Υܥ���ˤơ����Ȥ�������Τ�����פʤϤ�)
5186 *
5187 * -------------------------------------------------------------------------
5188 * int q8tk_signal_connect(Q8tkWidget *widget, const char *name,
5189 * Q8tkSignalFunc func, void *func_data)
5190 * widget �� name �Ǽ�����륷���ʥ���Ф��륳����Хå��ؿ� func ��
5191 * ���ꤹ�롣�����ʥ�ȯ�����ˤϡ��ؿ� func �� ���� widget, func_data ��
5192 * ȼ�äƸƤӽФ���롣
5193 * �ʤ�������ͤϾ�� 0 �ˤʤ롣
5194 *
5195 * void q8tk_signal_handlers_destroy(Q8tkWidget *widget)
5196 * widget �����ꤵ�줿���ƤΥ����ʥ�Υ�����Хå��ؿ���̵���ˤ��롣
5197 *
5198 *---------------------------------------------------------------------------*/
q8tk_signal_handlers_destroy(Q8tkWidget * widget)5199 void q8tk_signal_handlers_destroy(Q8tkWidget *widget)
5200 {
5201 widget->user_event_0 = NULL;
5202 widget->user_event_1 = NULL;
5203 }
5204
q8tk_signal_connect(Q8tkWidget * widget,const char * name,Q8tkSignalFunc func,void * func_data)5205 int q8tk_signal_connect(Q8tkWidget *widget, const char *name,
5206 Q8tkSignalFunc func, void *func_data)
5207 {
5208 switch (widget->type) {
5209 case Q8TK_TYPE_WINDOW: /* ������ɥ� */
5210 if (strcmp(name, "inactivate") == 0) {
5211 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5212 widget->user_event_0_parm = func_data;
5213 return 0;
5214 }
5215 break;
5216 case Q8TK_TYPE_BUTTON: /* �ܥ��� */
5217 if (strcmp(name, "clicked") == 0) {
5218 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5219 widget->user_event_0_parm = func_data;
5220 return 0;
5221 }
5222 break;
5223 case Q8TK_TYPE_TOGGLE_BUTTON: /* �ȥ���ܥ��� */
5224 case Q8TK_TYPE_CHECK_BUTTON: /* �����å��ܥ��� */
5225 case Q8TK_TYPE_RADIO_BUTTON: /* �饸���ܥ��� */
5226 if (strcmp(name, "clicked") == 0) {
5227 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5228 widget->user_event_0_parm = func_data;
5229 return 0;
5230 } else if (strcmp(name, "toggled") == 0) {
5231 widget->user_event_1 = (void (*)(Q8tkWidget*,void*))func;
5232 widget->user_event_1_parm = func_data;
5233 return 0;
5234 }
5235 break;
5236
5237 case Q8TK_TYPE_NOTEBOOK: /* �Ρ��ȥ֥å� */
5238 if (strcmp(name, "switch_page") == 0) {
5239 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5240 widget->user_event_0_parm = func_data;
5241 return 0;
5242 }
5243 break;
5244
5245 case Q8TK_TYPE_COMBO: /* ����ܥܥå��� */
5246 if (strcmp(name, "activate") == 0) {
5247 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5248 widget->user_event_0_parm = func_data;
5249 return 0;
5250 } else if (strcmp(name, "changed") == 0) {
5251 widget->user_event_1 = (void (*)(Q8tkWidget*,void*))func;
5252 widget->user_event_1_parm = func_data;
5253 return 0;
5254 }
5255 break;
5256
5257 case Q8TK_TYPE_LISTBOX: /* �ꥹ�ȥܥå��� */
5258 if (strcmp(name, "selection_changed") == 0) {
5259 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5260 widget->user_event_0_parm = func_data;
5261 return 0;
5262 }
5263 break;
5264
5265 case Q8TK_TYPE_LIST_ITEM: /* �ꥹ�ȥ����ƥ� */
5266 if (strcmp(name, "select") == 0) {
5267 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5268 widget->user_event_0_parm = func_data;
5269 return 0;
5270 }
5271 break;
5272
5273 case Q8TK_TYPE_ADJUSTMENT: /* �����㥹�ȥ��� */
5274 if (strcmp(name, "value_changed") == 0) {
5275 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5276 widget->user_event_0_parm = func_data;
5277 return 0;
5278 }
5279 break;
5280
5281 case Q8TK_TYPE_ENTRY: /* ����ȥ� */
5282 if (strcmp(name, "activate") == 0) {
5283 widget->user_event_0 = (void (*)(Q8tkWidget*,void*))func;
5284 widget->user_event_0_parm = func_data;
5285 return 0;
5286 } else if (strcmp(name, "changed") == 0) {
5287 widget->user_event_1 = (void (*)(Q8tkWidget*,void*))func;
5288 widget->user_event_1_parm = func_data;
5289 return 0;
5290 }
5291 break;
5292
5293 }
5294
5295 fprintf(stderr,
5296 "Undefined signal %s '%s'\n", debug_type(widget->type),name);
5297 Q8tkAssert(FALSE, NULL);
5298 return 0;
5299 }
5300
5301
5302
5303 /************************************************************************/
5304 /* ���٥�ȤΥ����å� */
5305 /************************************************************************/
5306 /*
5307 * DRAGGING
5308 */
widget_dragging(Q8tkWidget * focus)5309 static void widget_dragging(Q8tkWidget *focus)
5310 {
5311 if (focus && focus->event_dragging) {
5312 (*focus->event_dragging)(focus);
5313 }
5314 }
5315 /*
5316 * DRAG OFF
5317 */
widget_drag_off(Q8tkWidget * focus)5318 static void widget_drag_off(Q8tkWidget *focus)
5319 {
5320 if (focus && focus->event_drag_off) {
5321 (*focus->event_drag_off)(focus);
5322 }
5323 }
5324
5325 /*
5326 * MOUSE BUTTON ON
5327 */
widget_button_on(Q8tkWidget * focus)5328 static void widget_button_on(Q8tkWidget *focus)
5329 {
5330 if (focus == NULL) {
5331 /* �������åȰʳ���å������顢���οƥ�����ɥ��˥��٥������ */
5332 focus = window_layer[ window_layer_level ];
5333 }
5334 if (focus && focus->event_button_on) {
5335 (*focus->event_button_on)(focus);
5336 }
5337 }
5338 /*
5339 * KEY ON
5340 */
widget_key_on(Q8tkWidget * focus,int key)5341 static void widget_key_on(Q8tkWidget *focus, int key)
5342 {
5343 if (focus && focus->event_key_on) {
5344 (*focus->event_key_on)(focus, key);
5345 }
5346 }
5347
5348
5349
5350 /************************************************************************/
5351 /* �ᥤ�� */
5352 /************************************************************************/
5353 /*--------------------------------------------------------------
5354 *
5355 *--------------------------------------------------------------*/
q8tk_event_key_on(int code)5356 void q8tk_event_key_on(int code)
5357 {
5358 Q8tkWidget *w;
5359 int change = FALSE;
5360 int back = FALSE;
5361
5362 now_mouse_on = FALSE;
5363
5364 if (code == Q8TK_KEY_SHIFT) now_shift_on = TRUE;
5365
5366 if (! get_drag_widget()) { /* �ɥ�å��椸��ʤ� */
5367
5368 w = get_focus_widget();
5369
5370 switch (code) {
5371 case Q8TK_KEY_TAB:
5372 change = TRUE;
5373 if (now_shift_on) back = TRUE;
5374 else back = FALSE;
5375 break;
5376
5377 #ifdef OLD_FOCUS_CHANGE
5378 /* DO NOTHING */
5379 #else /* �����ʥե���������ư���� */
5380 case Q8TK_KEY_UP:
5381 if (w->key_up_used == FALSE) {
5382 change = TRUE;
5383 back = TRUE;
5384 }
5385 break;
5386 case Q8TK_KEY_DOWN:
5387 if (w->key_down_used == FALSE) {
5388 change = TRUE;
5389 back = FALSE;
5390 }
5391 break;
5392 case Q8TK_KEY_LEFT:
5393 if (w->key_left_used == FALSE) {
5394 change = TRUE;
5395 back = TRUE;
5396 }
5397 break;
5398 case Q8TK_KEY_RIGHT:
5399 if (w->key_right_used == FALSE) {
5400 change = TRUE;
5401 back = FALSE;
5402 }
5403 break;
5404 #endif
5405 }
5406
5407 /* [TAB][��][��][��][��] �ǡ�����Υ������åȤ˥ե���������ܤ� */
5408 if (change) {
5409
5410 w = widget_focus_list_get_next(w, back);
5411 q8tk_widget_set_focus(w);
5412
5413 /* �ե����������ư�����������åȤ���
5414 ��������ɥ�����ɥ���Ǥ��ġ��������륢�����ΰ�ʤ顢
5415 ����Ū�˥������륤�������Τǡ�������������ͽ�� */
5416 if (w && w->type != Q8TK_TYPE_ADJUSTMENT
5417 && w->type != Q8TK_TYPE_LISTBOX
5418 && w->type != Q8TK_TYPE_DIALOG
5419 && w->type != Q8TK_TYPE_FILE_SELECTION) {
5420 widget_scrollin_register(w);
5421 }
5422 } else { /* ¾�Υ��� */
5423
5424 /* ��������졼���������������ꤵ��Ƥ���н������� */
5425 if (window_layer_level >= 0) {
5426 w = window_layer[ window_layer_level ];
5427 Q8tkAssert(w->type == Q8TK_TYPE_WINDOW, NULL);
5428
5429 if (w->stat.window.accel) {
5430 w = (w->stat.window.accel)->child;
5431 while (w) {
5432 if (w->stat.accel.key == code) {
5433 widget_signal_do(w->stat.accel.widget, w->name);
5434 break;
5435 }
5436 w = w->next;
5437 }
5438 }
5439 }
5440
5441 /* ��������졼����������ͭ���ʤ顢ɸ��ν����Ϥ��ʤ��ۤ�������? */
5442 widget_key_on(get_focus_widget(), code);
5443 }
5444 }
5445 }
5446
q8tk_event_key_off(int code)5447 void q8tk_event_key_off(int code)
5448 {
5449 now_mouse_on = FALSE;
5450
5451 if (code == Q8TK_KEY_SHIFT) now_shift_on = FALSE;
5452 }
5453
q8tk_event_mouse_on(int code)5454 void q8tk_event_mouse_on(int code)
5455 {
5456 if (get_construct_flag()) return; /* ������ɥ��˴�ľ��Υ���å����� */
5457
5458 if (code == Q8TK_BUTTON_L) { /* ���ܥ��� ON */
5459 if (! get_drag_widget()) { /* �ɥ�å��椸��ʤ� */
5460 void *focus = q8gr_get_focus_screen(mouse.x/8, mouse.y/16);
5461 if (focus == Q8GR_WIDGET_NONE) {
5462 widget_button_on(NULL);
5463 } else if (focus == Q8GR_WIDGET_WINDOW) {
5464 /* DO NOTHING */ ;
5465 } else {
5466 q8tk_widget_set_focus((Q8tkWidget *)focus);
5467 widget_button_on((Q8tkWidget *)focus);
5468 }
5469 }
5470 } else if (code == Q8TK_BUTTON_U) { /* �ۥ����� UP */
5471
5472 widget_key_on(get_focus_widget(), Q8TK_KEY_PAGE_UP);
5473
5474 } else if (code == Q8TK_BUTTON_D) { /* �ۥ����� DOWN */
5475
5476 widget_key_on(get_focus_widget(), Q8TK_KEY_PAGE_DOWN);
5477 }
5478 }
5479
q8tk_event_mouse_off(int code)5480 void q8tk_event_mouse_off(int code)
5481 {
5482 now_mouse_on = FALSE;
5483
5484 if (code == Q8TK_BUTTON_L) { /* ���ܥ��� OFF */
5485 if (get_drag_widget()) { /* ���� �ɥ�å��� */
5486 widget_drag_off(get_drag_widget());
5487 set_drag_widget(NULL);
5488 }
5489 }
5490 }
5491
q8tk_event_mouse_moved(int x,int y)5492 void q8tk_event_mouse_moved(int x, int y)
5493 {
5494 int block_moved;
5495
5496 mouse.x_old = mouse.x;
5497 mouse.y_old = mouse.y;
5498 mouse.x = x;
5499 mouse.y = y;
5500
5501 if (mouse.x/8 != mouse.x_old/8 || /* �ޥ��� 8dot�ʾ� ��ư */
5502 mouse.y/16 != mouse.y_old/16) {
5503 block_moved = TRUE;
5504 now_mouse_on = FALSE;
5505
5506 if (disp_cursor) {
5507 set_construct_flag(TRUE);
5508 }
5509 } else {
5510 block_moved = FALSE;
5511 }
5512
5513 if (get_drag_widget()) { /* ���� �ɥ�å��� ���� */
5514 if (block_moved) { /* �ޥ��� 8dot�ʾ� ��ư */
5515 widget_dragging(get_drag_widget());
5516 }
5517 }
5518 }
5519
q8tk_event_quit(void)5520 void q8tk_event_quit(void)
5521 {
5522 q8tk_main_quit();
5523 }
5524
5525 /*--------------------------------------------------------------
5526 *
5527 *--------------------------------------------------------------*/
5528 static int cursor_exist = 0;
5529 static int cursor_timer = 0;
5530
5531 #define Q8GR_CURSOR_BLINK (30)
5532 #define Q8GR_CURSOR_CYCLE (60)
5533
5534 #define Q8GR_MOUSE_AUTO_REPEAT (6)
5535
5536
q8gr_set_cursor_exist(int exist_flag)5537 void q8gr_set_cursor_exist(int exist_flag)
5538 {
5539 cursor_exist = exist_flag;
5540 }
q8gr_get_cursor_exist(void)5541 int q8gr_get_cursor_exist(void)
5542 {
5543 return cursor_exist;
5544 }
q8gr_get_cursor_blink(void)5545 int q8gr_get_cursor_blink(void)
5546 {
5547 return (cursor_timer < Q8GR_CURSOR_BLINK) ? TRUE : FALSE;
5548 }
q8gr_set_cursor_blink(void)5549 void q8gr_set_cursor_blink(void)
5550 {
5551 cursor_timer = 0;
5552 }
5553
5554 /*--------------------------------------------------------------
5555 * q8tk_main_loop
5556 * ����ͤ������ʤ顢�������ȸ�˲��٤Ǥ�ƤӽФ�
5557 * ���ʤ顢��λ
5558 *--------------------------------------------------------------*/
5559
q8tk_main_loop(void)5560 int q8tk_main_loop(void)
5561 {
5562 static int mouse_frame = 0;
5563
5564 if (get_main_loop_flag()) {
5565
5566 if (get_delay_widget() == NULL) {
5567
5568 if (cursor_exist) { /* ��������ɽ����ʤ����ǥ������� */
5569 cursor_timer ++;
5570 if (cursor_timer > Q8GR_CURSOR_CYCLE) {
5571 cursor_timer = 0;
5572 }
5573 } else {
5574 cursor_timer = 0;
5575 }
5576
5577 event_update(); /* ���٥�Ȥ�������� */
5578 /* (ɬ�פ˱����ơ������Dz��̹���) */
5579 /* (��λ���Υե饰�������ǥ��å�) */
5580
5581 if (now_mouse_on) { /* �ޥ����ܥ����ȥ�ԡ��Ƚ��� */
5582 ++ mouse_frame;
5583 if (mouse_frame >= Q8GR_MOUSE_AUTO_REPEAT) {
5584 q8tk_event_mouse_on(Q8TK_BUTTON_L);
5585 mouse_frame = 0;
5586 }
5587 } else {
5588 mouse_frame = 0;
5589 }
5590
5591 if (cursor_exist) { /* �������������ڤ��ؤ��� */
5592 if (cursor_timer == 0 || /* �����ߥ�����å� */
5593 cursor_timer == Q8GR_CURSOR_BLINK) {
5594 set_construct_flag(TRUE);
5595 }
5596 }
5597
5598 } else {
5599
5600 /* ���٥�Ȥ��ٱ䤵���뤿��Ρ������ޡ����� (���ʤ궯��) */
5601 /* (���ΤȤ����ܥ���ȥꥹ�ȥ����ƥ�Τ�) */
5602 if (-- delay_timer < 0) {
5603 Q8tkWidget *widget = get_delay_widget();
5604
5605 if (widget->type == Q8TK_TYPE_BUTTON) {
5606 widget->stat.button.active = Q8TK_BUTTON_OFF;
5607 widget_signal_do(widget, "clicked");
5608 }
5609 else if (widget->type == Q8TK_TYPE_LIST_ITEM) {
5610 widget_signal_do(widget->parent, "selection_changed");
5611 widget_signal_do(widget, "select");
5612 }
5613 set_construct_flag(TRUE);
5614
5615 set_delay_widget(NULL, 0);
5616 }
5617 }
5618
5619
5620
5621 if (get_construct_flag()) { /* ���̹����ѹ����ϡ����� */
5622
5623 widget_construct();
5624 set_construct_flag(FALSE);
5625
5626 if (q8tk_disp_init_flag) {
5627 screen_set_dirty_palette();
5628 q8tk_disp_init_flag = FALSE;
5629 }
5630 screen_set_dirty_flag(0);
5631
5632 #ifdef RESET_EVENT /* ������Ϥ�� */
5633 event_switch();
5634 #endif
5635 }
5636
5637 }
5638
5639 /* ���̤����������äơ�Q8TK ����λ���Ƥ��ʤ���С������֤� */
5640 /* ���¦�ϡ����衦�������ȸ�ˤ��δؿ�����ٸƤӽФ����� */
5641 /* */
5642 /* ���̤����������äơ�Q8TK ����λ���Ƥ���С������֤� */
5643 /* ���¦�ϡ����ν��������ܤ��뤳�� */
5644 /* ���衦�������ȸ�����ܤ��Ƥ��ʤ� */
5645 /* �ְ�äƺ��ٸƤӽФ�����硢�ʤˤ���������˵����֤� */
5646
5647 if (get_main_loop_flag()) {
5648
5649 return TRUE;
5650
5651 } else {
5652
5653 q8tk_term();
5654 return FALSE;
5655 }
5656 }
5657
5658 /*--------------------------------------------------------------
5659 *
5660 *--------------------------------------------------------------*/
q8tk_main_quit(void)5661 void q8tk_main_quit(void)
5662 {
5663 set_main_loop_flag(FALSE);
5664 }
5665
5666
5667
5668
5669
5670
5671
5672 /************************************************************************/
5673 /* */
5674 /* */
5675 /* */
5676 /* */
5677 /* */
5678 /* */
5679 /************************************************************************/
5680
5681 /*------------------------------------------------------*/
5682 /* �������åȤ�ɽ������
5683 �ƥ������åȤ�Ĥ��Ĥ������å�����
5684 �����Ƥοƥ������åȤ��Ļ����
5685 �����ĥ������åȤ� WINDOW
5686 �ξ�硢���� WINDOW �ʲ���Ʒ�����ɽ������
5687 �褦�ˡ��ե饰�Ƥ롣
5688 �ºݤκƷ���ɽ���ϡ�q8tk_main() �ǹԤʤ��� */
5689 /*------------------------------------------------------*/
widget_map(Q8tkWidget * widget)5690 static void widget_map(Q8tkWidget *widget)
5691 {
5692 Q8tkWidget *ancestor, *parent;
5693 int size_calc = TRUE;
5694
5695 if (widget->visible) {
5696 ancestor = widget;
5697 parent = widget->parent;
5698 while (parent) {
5699 if (parent->visible) {
5700 ancestor = parent;
5701 parent = parent->parent;
5702 } else {
5703 size_calc = FALSE;
5704 break;
5705 }
5706 }
5707 if (size_calc && ancestor->type == Q8TK_TYPE_WINDOW) {
5708 set_construct_flag(TRUE);
5709 }
5710 }
5711 }
5712
5713
5714 /*------------------------------------------------------*/
5715 /* �ҥ������åȤΥ������ˡ���ʬ���ȤΥ�����������롣
5716 �Ƶ�Ū�ˡ����Ƥλҥ��������åȤ�Ʊ���˷����롣
5717
5718 *widget �� ���ֿƤΥ������å�
5719 *max_sx �� ���Ƥλҥ������åȤΤʤ��Ǻ��祵���� x
5720 *max_sy �� ���Ƥλҥ������åȤΤʤ��Ǻ��祵���� y
5721 *sum_sx �� �Ҥ���֥������åȤΥ��������� x
5722 *sum_sy �� �Ҥ���֥������åȤΥ��������� y */
5723 /*------------------------------------------------------*/
5724 static void widget_resize(Q8tkWidget *widget, int max_sx, int max_sy);
widget_size(Q8tkWidget * widget,int * max_sx,int * max_sy,int * sum_sx,int * sum_sy)5725 static void widget_size(Q8tkWidget *widget, int *max_sx, int *max_sy,
5726 int *sum_sx, int *sum_sy)
5727 {
5728 int n_msx, n_msy, n_ssx, n_ssy;
5729
5730 /* printf("%d \n", widget->type); fflush(stdout);*/
5731
5732
5733 /* ��ʬ���Ȥ���� (next) ��¸�ߤ���С��Ƶ�Ū�˷� */
5734
5735 if (widget->next) {
5736 widget_size(widget->next, &n_msx, &n_msy, &n_ssx, &n_ssy);
5737 } else {
5738 n_msx = n_msy = n_ssx = n_ssy = 0;
5739 }
5740
5741
5742 if (widget->visible) {
5743
5744 int c_msx, c_msy, c_ssx, c_ssy;
5745
5746 /* �ҥ������åȤΥ�������(�Ƶ�) */
5747
5748 if (widget->child) {
5749 widget_size(widget->child, &c_msx, &c_msy, &c_ssx, &c_ssy);
5750 } else {
5751 c_msx = c_msy = c_ssx = c_ssy = 0;
5752 }
5753
5754 /* �ҥ������åȤˡ����ȤΥ������� */
5755
5756 switch (widget->type) {
5757
5758 case Q8TK_TYPE_WINDOW: /* ������ɥ� */
5759 if (widget->stat.window.no_frame) {
5760 widget->sx = c_msx;
5761 widget->sy = c_msy;
5762 } else {
5763 widget->sx = c_msx +2;
5764 widget->sy = c_msy +2;
5765 }
5766 break;
5767
5768 case Q8TK_TYPE_BUTTON: /* �ܥ��� */
5769 case Q8TK_TYPE_TOGGLE_BUTTON: /* �ȥ���ܥ��� */
5770 widget->sx = c_msx +2;
5771 widget->sy = c_msy +2;
5772 break;
5773
5774 case Q8TK_TYPE_CHECK_BUTTON: /* �����å��ܥ��� */
5775 case Q8TK_TYPE_RADIO_BUTTON: /* �饸���ܥ��� */
5776 widget->sx = c_msx +3;
5777 widget->sy = Q8TKMAX(c_msy, 1);
5778 break;
5779
5780 case Q8TK_TYPE_FRAME: /* �ե졼�� */
5781 if (widget->name) {
5782 widget->sx = Q8TKMAX(c_msx,
5783 q8gr_strlen(widget->code, widget->name))
5784 + 2;
5785 } else {
5786 widget->sx = c_msx + 2;
5787 }
5788 widget->sy = c_msy +2;
5789 break;
5790
5791 case Q8TK_TYPE_LABEL: /* ��٥� */
5792 if (widget->name) {
5793 widget->sx = q8gr_strlen(widget->code, widget->name);
5794 } else {
5795 widget->sx = 0;
5796 }
5797 widget->sy = 1;
5798 break;
5799
5800 case Q8TK_TYPE_LOGO: /* �� */
5801 widget->sx = Q8GR_LOGO_W;
5802 widget->sy = Q8GR_LOGO_H;
5803 break;
5804
5805 case Q8TK_TYPE_NOTEBOOK: /* �Ρ��ȥ֥å� */
5806 {
5807 int len = 0;
5808 Q8tkWidget *n = widget->child;
5809 while (n) {
5810 if (n ->name) {
5811 len += q8gr_strlen(n->code, n->name);
5812 }
5813 len += 1;
5814 n = n->next;
5815 }
5816 len += 1;
5817 widget->sx = Q8TKMAX(c_msx +2, len);
5818 }
5819 widget->sy = c_msy + 4;
5820 break;
5821
5822 case Q8TK_TYPE_NOTEPAGE: /* �Ρ��ȥ֥å��Υڡ��� */
5823 widget->sx = c_msx;
5824 widget->sy = c_msy;
5825 break;
5826
5827 case Q8TK_TYPE_VBOX: /* ��ľ�ܥå��� */
5828 widget->sx = c_msx;
5829 widget->sy = c_ssy;
5830 break;
5831 case Q8TK_TYPE_HBOX: /* ��ʿ�ܥå��� */
5832 widget->sx = c_ssx;
5833 widget->sy = c_msy;
5834 break;
5835
5836 case Q8TK_TYPE_VSEPARATOR: /* ��ľ���ڤ��� */
5837 widget->sx = 1;
5838 widget->sy = 1;
5839 break;
5840 case Q8TK_TYPE_HSEPARATOR: /* ��ʿ���ڤ��� */
5841 widget->sx = 1;
5842 widget->sy = 1;
5843 break;
5844
5845 case Q8TK_TYPE_COMBO: /* ����ܥܥå��� */
5846 if (widget->stat.combo.width) {
5847 widget->sx = widget->stat.combo.width;
5848 } else {
5849 if (widget->stat.combo.length) {
5850 widget->sx = widget->stat.combo.length;
5851 } else {
5852 widget->sx = 8;
5853 }
5854 }
5855 widget->sx += 3;
5856 widget->sy = 1;
5857 break;
5858
5859 case Q8TK_TYPE_LISTBOX: /* �ꥹ�ȥܥå��� */
5860 widget->sx = Q8TKMAX(c_msx, widget->stat.listbox.width);
5861 widget->sy = c_ssy;
5862 break;
5863
5864 case Q8TK_TYPE_LIST_ITEM: /* �ꥹ�ȥ����ƥ� */
5865 widget->sx = c_msx;
5866 widget->sy = c_msy;
5867 break;
5868
5869 case Q8TK_TYPE_ADJUSTMENT: /* �����㥹�ȥ��� */
5870 Q8tkAssert(FALSE, NULL);
5871 break;
5872
5873 case Q8TK_TYPE_HSCALE: /* ��ʿ�������� */
5874 case Q8TK_TYPE_VSCALE: /* ��ľ�������� */
5875 if (widget->stat.scale.adj) {
5876 int sx, sy;
5877 adjustment_size(&widget->stat.scale.adj->stat.adj, &sx, &sy);
5878
5879 if (widget->stat.scale.draw_value) {
5880 if (widget->stat.scale.value_pos == Q8TK_POS_LEFT ||
5881 widget->stat.scale.value_pos == Q8TK_POS_RIGHT) {
5882 widget->sx = sx + 4;
5883 widget->sy = Q8TKMAX(sy, 1);
5884 } else { /* Q8TK_POS_UP||Q8TK_POS_BOTTOM*/
5885 widget->sx = Q8TKMAX(sx, 3);
5886 widget->sy = sy + 1;
5887 }
5888 } else {
5889 widget->sx = sx;
5890 widget->sy = sy;
5891 }
5892 } else {
5893 widget->sx = 0;
5894 widget->sy = 0;
5895 }
5896 break;
5897
5898 case Q8TK_TYPE_SCROLLED_WINDOW: /* ��������ɥ�����ɥ� */
5899 if (widget->child) {
5900
5901 /* �IJ���������С���ɽ�����뤫�ɤ����ϡ�
5902 child ��������scrolled ��������scrolled �� policy��
5903 ���Ȥ߹�碌�ˤ�ꡢ�ʲ��� 9 �ѥ������ʬ����롣
5904
5905 0) 1) 2)
5906 c_msx < w-2 c_msx = w-2 c_msx > w-2
5907 (NEVER) (ALLWAYS)
5908 0)
5909 c_msy < h-2
5910 (NEVER) ---
5911 1)
5912 c_msy = h-2 |
5913 --+
5914 2)
5915 c_msy > h-2 | | |
5916 (ALLWAYS) --+ --+
5917
5918 */
5919
5920 int w, h, tmp;
5921
5922 switch (widget->stat.scrolled.hpolicy) {
5923 case Q8TK_POLICY_NEVER: w = 0; break;
5924 case Q8TK_POLICY_ALWAYS: w = 2; break;
5925 default: /* AUTOMATIC */
5926 if (c_msx < widget->stat.scrolled.width - 2) w = 0;
5927 else if (c_msx == widget->stat.scrolled.width - 2) w = 1;
5928 else w = 2;
5929 }
5930
5931 switch (widget->stat.scrolled.vpolicy) {
5932 case Q8TK_POLICY_NEVER: h = 0; break;
5933 case Q8TK_POLICY_ALWAYS: h = 2; break;
5934 default: /* AUTOMATIC */
5935 if (c_msy < widget->stat.scrolled.height - 2) h = 0;
5936 else if (c_msy == widget->stat.scrolled.height - 2) h = 1;
5937 else h = 2;
5938 }
5939
5940 if ((w == 0 || w == 1) && (h == 0 || h == 1)) {
5941 widget->stat.scrolled.hscrollbar = FALSE;
5942 widget->stat.scrolled.vscrollbar = FALSE;
5943 } else if ((w == 2) && (h == 0)) {
5944 widget->stat.scrolled.hscrollbar = TRUE;
5945 widget->stat.scrolled.vscrollbar = FALSE;
5946 } else if ((w == 0) && (h == 2)) {
5947 widget->stat.scrolled.hscrollbar = FALSE;
5948 widget->stat.scrolled.vscrollbar = TRUE;
5949 } else {
5950 widget->stat.scrolled.hscrollbar = TRUE;
5951 widget->stat.scrolled.vscrollbar = TRUE;
5952 }
5953
5954 w = (widget->stat.scrolled.vscrollbar)
5955 ? widget->stat.scrolled.width - 3
5956 : widget->stat.scrolled.width - 2;
5957 h = (widget->stat.scrolled.hscrollbar)
5958 ? widget->stat.scrolled.height - 3
5959 : widget->stat.scrolled.height - 2;
5960
5961 q8tk_adjustment_set_length(widget->stat.scrolled.hadj, w);
5962 q8tk_adjustment_clamp_page(widget->stat.scrolled.hadj,
5963 0, c_msx - w);
5964 adjustment_size(&widget->stat.scrolled.hadj->stat.adj,
5965 &tmp, &tmp);
5966
5967 q8tk_adjustment_set_length(widget->stat.scrolled.vadj, h);
5968 q8tk_adjustment_clamp_page(widget->stat.scrolled.vadj,
5969 0, c_msy - h);
5970 adjustment_size(&widget->stat.scrolled.vadj->stat.adj,
5971 &tmp, &tmp);
5972
5973 if (widget->child->type == Q8TK_TYPE_LISTBOX &&
5974 (widget->stat.scrolled.vadj->stat.adj.listbox_changed) &&
5975 (widget->stat.scrolled.vadj_value
5976 != widget->stat.scrolled.vadj->stat.adj.value)) {
5977 list_event_window_scrolled(widget, h);
5978 }
5979 }
5980 widget->stat.scrolled.vadj_value
5981 = widget->stat.scrolled.vadj->stat.adj.value;
5982 widget->stat.scrolled.vadj->stat.adj.listbox_changed = FALSE;
5983 widget->sx = widget->stat.scrolled.width;
5984 widget->sy = widget->stat.scrolled.height;
5985 break;
5986
5987 case Q8TK_TYPE_ENTRY: /* ����ȥ� */
5988 widget->sx = widget->stat.entry.width;
5989 widget->sy = 1;
5990 break;
5991
5992
5993 case Q8TK_TYPE_DIALOG: /* �������� */
5994 Q8tkAssert(FALSE, NULL);
5995 break;
5996 case Q8TK_TYPE_FILE_SELECTION: /* �ե����륻�쥯����� */
5997 Q8tkAssert(FALSE, NULL);
5998 break;
5999
6000 default:
6001 Q8tkAssert(FALSE, "Undefined type");
6002 }
6003
6004 } else {
6005 widget->sx = 0;
6006 widget->sy = 0;
6007 }
6008
6009
6010 /* ���������� */
6011
6012 *max_sx = Q8TKMAX(widget->sx, n_msx);
6013 *max_sy = Q8TKMAX(widget->sy, n_msy);
6014 *sum_sx = widget->sx + n_ssx;
6015 *sum_sy = widget->sy + n_ssy;
6016
6017
6018 /* �ҥ������åȤ˥��ѥ졼�����ޤޤ����ϡ�������Ĵ�� */
6019
6020 widget_resize(widget, widget->sx, widget->sy);
6021
6022
6023 /* �ꥹ�ȥܥå����ʤɤξ�硢�ҥ������åȤΥ�������Ĵ�� */
6024
6025
6026 if (widget->type == Q8TK_TYPE_LISTBOX) {
6027 Q8tkWidget *child = widget->child;
6028 while (child) {
6029 Q8tkAssert(child->type == Q8TK_TYPE_LIST_ITEM, NULL);
6030 child->sx = widget->sx;
6031 if (child->next) child = child->next;
6032 else break;
6033 }
6034 }
6035
6036
6037 /*printf("%s (%02d,%02d) max{ %02d,%02d } sum{ %02d,%02d }\n",debug_type(widget->type),widget->sx,widget->sy,*max_sx,*max_sy,*sum_sx,*sum_sy);fflush(stdout);*/
6038 }
6039
6040
6041 /*
6042 * ���ѥ졼���ʤɡ��Ƥ��礭���˰�¸���륦�����åȤΥ�������Ʒ�����
6043 */
widget_resize(Q8tkWidget * widget,int max_sx,int max_sy)6044 static void widget_resize(Q8tkWidget *widget, int max_sx, int max_sy)
6045 {
6046 if (widget->type == Q8TK_TYPE_WINDOW ||
6047 widget->type == Q8TK_TYPE_NOTEPAGE ||
6048 widget->type == Q8TK_TYPE_VBOX ||
6049 widget->type == Q8TK_TYPE_HBOX) {
6050
6051 Q8tkWidget *child = widget->child;
6052
6053 if (widget->type == Q8TK_TYPE_WINDOW &&
6054 ! widget->stat.window.no_frame) {
6055 max_sx -= 2;
6056 max_sy -= 2;
6057 }
6058 if (child) widget_resize(child, max_sx, max_sy);
6059
6060 while (child) {
6061 switch (child->type) {
6062
6063 case Q8TK_TYPE_HSEPARATOR:
6064 if (widget->type != Q8TK_TYPE_HBOX) {
6065 if (child->sx < max_sx) child->sx = max_sx;
6066 }
6067 break;
6068
6069 case Q8TK_TYPE_VSEPARATOR:
6070 if (widget->type != Q8TK_TYPE_VBOX) {
6071 if (child->sy < max_sy) child->sy = max_sy;
6072 }
6073 break;
6074
6075 case Q8TK_TYPE_VBOX:
6076 if (widget->type == Q8TK_TYPE_VBOX) {
6077 if (child->sx < max_sx) child->sx = max_sx;
6078 }
6079 break;
6080
6081 case Q8TK_TYPE_HBOX:
6082 if (widget->type == Q8TK_TYPE_HBOX) {
6083 if (child->sy < max_sy) child->sy = max_sy;
6084 }
6085 break;
6086 }
6087
6088 if (child->next) child = child->next;
6089 else break;
6090 }
6091 }
6092 }
6093
6094
6095
6096 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
6097
6098 /*------------------------------------------------------
6099 �������åȤ�����������ɥ�����ɥ��˴ޤޤ���硢
6100 ����������֤ˤ�äƤϡ�ɽ������ʤ����Ȥ����롣
6101
6102 ͽ�ᡢ���Υ������åȤ�ʲ��δؿ�����Ͽ���Ƥ����С�
6103
6104 widget_scrollin_register(this_widget);
6105
6106 ����ɽ���κݤˡ����Υ������åȤ�ɽ�������褦�ˡ���������
6107 ���֤�Ĵ������褦�ˤ��롣
6108
6109 ��������ɥ�����ɥ��ˤ��륦�����åȤ�ɽ�����줿���ɤ����ϡ�
6110 �ºݤ�ɽ������ޤǤ狼��ʤ��Τǡ��ºݤ�ɽ�����ʤ�������
6111 ���ꤷ����������Ƽ���ǡ���ɽ���Ȥ������Ȥˤʤ롣
6112
6113 �Ĥޤꡢ�ʲ��Τ褦�ʴ����ˤʤ롣
6114
6115 widget_scrollin_adjust_reset(); �� ��������
6116 widget_draw(); �� ����
6117
6118 if (widget_scrollin_adjust()) { �� Ĵ�������鿿
6119 widget_draw(); �� Ĵ�������Τǡ�������
6120 }
6121
6122 �ʤ���������Ԥʤ��Τϡ��ǽ�˸��Ĥ��ä� �Ƥ� SCROLLED WINDOW �Τ�
6123 ���Ф��Ƥ����ʤΤǡ�SCROLLED WINDOW ������Ҥξ��Ϥɤ��ʤ뤫
6124 �狼��ʤ���
6125 ------------------------------------------------------*/
6126
6127 /* Ĵ����ǽ�ʥ������åȤο�������������������פ��� */
6128 #define MAX_WIDGET_SCROLLIN (8)
6129 static struct {
6130 int drawn;
6131 Q8tkWidget *widget;
6132 } widget_scrollin[ MAX_WIDGET_SCROLLIN ];
6133
6134 /* ������ν���� (���٤����Ԥ�) */
widget_scrollin_init(void)6135 static void widget_scrollin_init(void)
6136 {
6137 int i;
6138 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6139 widget_scrollin[i].drawn = FALSE;
6140 widget_scrollin[i].widget = NULL;
6141 }
6142 }
6143 /* �������åȤ���Ͽ */
widget_scrollin_register(Q8tkWidget * w)6144 static void widget_scrollin_register(Q8tkWidget *w)
6145 {
6146 int i;
6147 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6148 if (widget_scrollin[i].widget == w) return;
6149 }
6150 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6151 if (widget_scrollin[i].widget == NULL) {
6152 widget_scrollin[i].drawn = FALSE;
6153 widget_scrollin[i].widget = w;
6154 return;
6155 }
6156 }
6157 }
6158 /* ��������������åȤ��������˸ƤӽФ� */
widget_scrollin_adjust_reset(void)6159 static void widget_scrollin_adjust_reset(void)
6160 {
6161 int i;
6162 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6163 widget_scrollin[i].drawn = FALSE;
6164 }
6165 }
6166 /* ���ꡧ�ƥ������åȤ�������˸ƤӽФ� */
widget_scrollin_drawn(Q8tkWidget * w)6167 static void widget_scrollin_drawn(Q8tkWidget *w)
6168 {
6169 int i;
6170 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6171 if (widget_scrollin[i].widget == w) {
6172 widget_scrollin[i].drawn = TRUE;
6173 return;
6174 }
6175 }
6176 }
6177 /* Ĵ�������������åȤ������˸ƤӽФ� */
widget_scrollin_adjust(void)6178 static int widget_scrollin_adjust(void)
6179 {
6180 int i, result = 0;
6181
6182 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6183
6184 /*printf("%d %d %s\n",i,widget_scrollin[i].drawn,(widget_scrollin[i].widget)?debug_type(widget_scrollin[i].widget->type):"NULL");*/
6185
6186 if (widget_scrollin[i].widget) {
6187
6188 if (widget_scrollin[i].drawn) {
6189
6190 Q8tkWidget *widget = widget_scrollin[i].widget;
6191 Q8tkWidget *p = widget->parent;
6192 /*int x1 = widget->x;*/
6193 int x1 = widget->x + widget->sx -1;
6194 int y1 = widget->y + widget->sy -1;
6195
6196 /*
6197 SCROLLED WINDOW ��˾褻�륦�����å����Τ�������Ȥ�����
6198 ����� real_y
6199
6200 y1 = widget->y + widget->sy -1;
6201 p->y + 1 - p->stat.scrolled.child_y0 + [ real_y ] = y1;
6202 */
6203
6204 while (p) {
6205 if (p->type == Q8TK_TYPE_SCROLLED_WINDOW) {
6206
6207 int d, topleft;
6208
6209 /* d > 0 �ʤ顢��üɽ�� */
6210 /* d < 0 �ʤ顢��üɽ�� */
6211 if (widget->type == Q8TK_TYPE_LIST_ITEM &&
6212 widget->parent->type == Q8TK_TYPE_LISTBOX) {
6213 d = widget->parent->stat.listbox.scrollin_left;
6214 } else {
6215 d = 0;
6216 }
6217 /* d == 0 �ϡ��ǥե���� (-1 �Ȥ���) */
6218 if (d == 0) { d = -1; }
6219
6220 if (d > 0) { topleft = TRUE; d -= 1; }
6221 else { topleft = FALSE; d += 1; }
6222
6223 if (topleft) { /* ��ü��ɽ�������褦�˰������� */
6224 /* d = 0, 1, 2, 3... */
6225 /* �������ʤ���к�ü��ɽ�������Τǡ����Τޤ� */
6226
6227 } else { /* ��ü��ɽ�������褦�˰������� */
6228 /* d = 0, -1, -2, -3... */
6229 if (p->x +1 <= x1 &&
6230 x1 < p->x +1 + p->stat.scrolled.child_sx) {
6231 /* Ok, Expose */
6232 } else {
6233 Q8TK_ADJUSTMENT(p->stat.scrolled.hadj)->value
6234 = x1 - (p->x+1 - p->stat.scrolled.child_x0)
6235 - p->stat.scrolled.child_sx + 1;
6236 result = 1;
6237 }
6238 }
6239 /* �� d ���ͤˤ�ä������̤��Ѥ����������ޤ����٤� */
6240
6241
6242 /* d > 0 �ʤ顢��üɽ����+1�����١�����1ʸ������ɽ�� */
6243 /* d < 0 �ʤ顢��üɽ����-1�����١�����1ʸ�����ɽ�� */
6244 if (widget->type == Q8TK_TYPE_LIST_ITEM &&
6245 widget->parent->type == Q8TK_TYPE_LISTBOX) {
6246 d = widget->parent->stat.listbox.scrollin_top;
6247 } else {
6248 d = 0;
6249 }
6250 /* d == 0 �ϡ��ǥե���� (-1 �Ȥ���) */
6251 if (d == 0) { d = -1; }
6252
6253 if (d > 0) { topleft = TRUE; d -= 1; }
6254 else { topleft = FALSE; d += 1; }
6255
6256 if (topleft) { /* ��ü��ɽ�������褦�˰������� */
6257 /* d = 0, 1, 2, 3... */
6258 if (p->y +1 == (y1-d)) {
6259 /* Ok */
6260 } else {
6261 Q8TK_ADJUSTMENT(p->stat.scrolled.vadj)->value =
6262 (y1-d) - (p->y+1 - p->stat.scrolled.child_y0);
6263 result = 1;
6264 }
6265
6266 } else { /* ��ü��ɽ�������褦�˰������� */
6267 /* d = 0, -1, -2, -3... */
6268 if (p->y +1 <= (y1-d) &&
6269 (y1-d) < p->y +1 + p->stat.scrolled.child_sy) {
6270 /* Ok, Expose */
6271 } else {
6272 Q8TK_ADJUSTMENT(p->stat.scrolled.vadj)->value =
6273 (y1-d) - (p->y+1 - p->stat.scrolled.child_y0)
6274 - p->stat.scrolled.child_sy + 1;
6275 result = 1;
6276 }
6277 }
6278
6279 /*
6280 printf(" %s %d %d %d %d %d %d %d %d\n",debug_type(p->type),
6281 p->x, p->y, p->sx, p->sy,
6282 p->stat.scrolled.child_x0, p->stat.scrolled.child_y0,
6283 p->stat.scrolled.child_sx, p->stat.scrolled.child_sy);
6284 printf(" %s %d %d %d %d\n",debug_type(widget->type),
6285 widget->x, widget->y, widget->sx, widget->sy);
6286 printf(" %d\n",y1);
6287 if (result) printf("ADJ %d,%d\n",
6288 Q8TK_ADJUSTMENT(p->stat.scrolled.vadj)->value,
6289 Q8TK_ADJUSTMENT(p->stat.scrolled.hadj)->value);
6290 */
6291
6292
6293 break;
6294 }
6295 p = p->parent;
6296 }
6297 widget_scrollin[i].drawn = FALSE;
6298 widget_scrollin[i].widget = NULL;
6299 }
6300 }
6301 }
6302
6303 return result;
6304 }
6305
6306
6307 /*------------------------------------------------------
6308 �������åȤΥե���������ư�Υꥹ�Ⱥ���
6309
6310 TAB�����䡢�������륭���ˤ�롢�ե��������ΰ�ư��¸����뤿��ˡ�
6311 �оݤȤʤ륦�����åȤΥꥹ�Ȥ��������롣
6312
6313 widget_focus_list_reset() �� �ꥹ�Ȥν����
6314 widget_draw() �� ���衣�����ǥꥹ�Ȥ���������
6315
6316 widget_draw() �������Ǥϡ��ե���������ư���оݤȤ������������åȤ�
6317 ����κݤˡ���widget_focus_list_append()�� �ؿ���Ƥ֡�
6318
6319 TAB�����ʤɤ��줿�Ȥ��ˡ����˥ե��������ΰܤ륦�����åȤ��������ˤ�
6320 ��widget_focus_list_get_next()�ٴؿ���Ƥ֡�
6321 ------------------------------------------------------*/
6322 /* BACKTAB �б� thanks! floi */
6323
6324 static Q8List *widget_focus_list;
6325
6326 /* ������ν���� (���٤����Ԥ�) */
widget_focus_list_init(void)6327 static void widget_focus_list_init(void)
6328 {
6329 widget_focus_list = NULL;
6330 }
6331 /* ��������������åȤ��������˸ƤӽФ� */
widget_focus_list_reset(void)6332 static void widget_focus_list_reset(void)
6333 {
6334 q8_list_free(widget_focus_list);
6335 widget_focus_list = NULL;
6336 }
6337 /* ���ꡧ�ե��������ꥹ�Ȥ���Ͽ���륦�����åȤʤ顢�ƤӽФ� */
widget_focus_list_append(Q8tkWidget * widget)6338 static void widget_focus_list_append(Q8tkWidget *widget)
6339 {
6340 if (widget) {
6341 widget_focus_list = q8_list_append(widget_focus_list, widget);
6342 }
6343 }
6344 /* �������ե��������ꥹ�Ȥ���Ƭ�������åȤ���� */
widget_focus_list_get_top(void)6345 static Q8tkWidget *widget_focus_list_get_top(void)
6346 {
6347 if (widget_focus_list) {
6348 return (Q8tkWidget *)(widget_focus_list->data);
6349 } else {
6350 return NULL;
6351 }
6352 }
6353 /* �������ե��������ꥹ�Ȥμ�(��)�Υ������åȤ���� */
widget_focus_list_get_next(Q8tkWidget * widget,int back)6354 static Q8tkWidget *widget_focus_list_get_next(Q8tkWidget *widget, int back)
6355 {
6356 Q8List *list;
6357
6358 if (widget == NULL) {
6359 return widget_focus_list_get_top();
6360 }
6361
6362 #if defined(OLD_FOCUS_CHANGE)
6363 list = q8_list_find(widget_focus_list, widget);
6364
6365 #else /* �����ʥե���������ư���� */
6366 switch (widget->type) {
6367 case Q8TK_TYPE_RADIO_BUTTON:
6368 {
6369 /* ����� RADIO BUTTON ��õ���ơ���������� */
6370 Q8List *l = widget->stat.button.list;
6371 while (l) {
6372 widget = (Q8tkWidget *)(l->data);
6373 if (widget->stat.button.active == Q8TK_BUTTON_ON) break;
6374 l = l->next;
6375 }
6376 }
6377 list = q8_list_find(widget_focus_list, widget);
6378 break;
6379
6380 case Q8TK_TYPE_NOTEPAGE:
6381 /* ���ΤȤ����ե��������Τ���NOTEPAGE�Ͼ��������֤�
6382 �ʤ�Τǡ����TAB�դ�����롣�Ĥޤꡢ�����ˤϤ��ʤ��� */
6383 widget = (widget->parent)->stat.notebook.page;
6384 list = q8_list_find(widget_focus_list, widget);
6385 break;
6386
6387 case Q8TK_TYPE_COMBO:
6388 if (widget->stat.combo.entry->stat.entry.editable == FALSE) {
6389 /* ENTRY ���Խ��ԲĤξ��ϡ�COMBO ���Ȥ������ */
6390 list = q8_list_find(widget_focus_list, widget);
6391 } else {
6392 /* ENTRY ���Խ��Ĥξ��� */
6393 if (back == FALSE) {
6394 /* COMBO �μ��ϡ�ENTRY �μ���Ʊ�� */
6395 list = q8_list_find(widget_focus_list,
6396 widget->stat.combo.entry);
6397 } else {
6398 /* COMBO �����ϡ�ENTRY ���Τ�Τˤ��Ƥ��ޤ��� */
6399 return widget->stat.combo.entry;
6400 }
6401 }
6402 break;
6403
6404 default:
6405 list = q8_list_find(widget_focus_list, widget);
6406 break;
6407 }
6408 #endif
6409
6410 if (list) {
6411 if (back == FALSE) {
6412 if (list->next) return (Q8tkWidget*)((list->next)->data);
6413 else return (Q8tkWidget*)((q8_list_first(list))->data);
6414 } else {
6415 if (list->prev) return (Q8tkWidget*)((list->prev)->data);
6416 else return (Q8tkWidget*)((q8_list_last(list))->data);
6417 }
6418 }
6419 return NULL;
6420 }
6421
6422
6423
6424
6425 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
6426
6427 /*------------------------------------------------------*/
6428 /* ��ʬ���Ȥ�ɽ�����֤��Ȥˡ����褷��
6429 �Ƶ�Ū�ˡ����Ƥλҥ��������åȤ����褹�롣 */
6430 /*------------------------------------------------------*/
6431
widget_draw(Q8tkWidget * widget,int parent_focus,int parent_sensitive)6432 static void widget_draw(Q8tkWidget *widget,
6433 int parent_focus, int parent_sensitive)
6434 {
6435 int x = widget->x;
6436 int y = widget->y;
6437 Q8tkWidget *child = widget->child;
6438 int focus, sensitive;
6439 int next_focus;
6440 Q8tkWidget *sense_widget;
6441
6442 /* �Ƥ��ե����������꤫�����Ȥ��ե�����������ǡ��ե�������������֤Ȥ���*/
6443 focus = (parent_focus || (widget == get_focus_widget())) ? TRUE : FALSE;
6444
6445 /* �Ƥ�����ǽ�ǡ����Ȥ�����ǽ�ʤ顢����ǽ�Ȥ��� */
6446 sensitive = (parent_sensitive && widget->sensitive) ? TRUE : FALSE;
6447 sense_widget = (sensitive) ? widget : NULL;
6448
6449 /* ��֤˥ե����������������硢�����̾�������ʤ� */
6450 next_focus = FALSE;
6451
6452
6453
6454 widget_scrollin_drawn(widget);
6455
6456
6457 /* HBOX��VBOX �λҤξ��˸¤ꡢ*/
6458 /* ���֤�㴳�ѹ��Ǥ��롣 */
6459 /* FRAME ��Ĥ��Ǥ˥襷�Ȥ��褦 */
6460
6461 if (widget->parent) {
6462 switch ((widget->parent)->type) {
6463 case Q8TK_TYPE_FRAME:
6464 if (widget->placement_x == Q8TK_PLACEMENT_X_CENTER) {
6465 x += ((widget->parent)->sx -2 - widget->sx) / 2;
6466 } else if (widget->placement_x == Q8TK_PLACEMENT_X_RIGHT) {
6467 x += ((widget->parent)->sx -2 - widget->sx);
6468 }
6469 widget->x = x;
6470 break;
6471 case Q8TK_TYPE_VBOX:
6472 if (widget->placement_x == Q8TK_PLACEMENT_X_CENTER) {
6473 x += ((widget->parent)->sx - widget->sx) / 2;
6474 } else if (widget->placement_x == Q8TK_PLACEMENT_X_RIGHT) {
6475 x += ((widget->parent)->sx - widget->sx);
6476 }
6477 widget->x = x;
6478 break;
6479 case Q8TK_TYPE_HBOX:
6480 if (widget->placement_y == Q8TK_PLACEMENT_Y_CENTER) {
6481 y += ((widget->parent)->sy - widget->sy) / 2;
6482 } else if (widget->placement_y == Q8TK_PLACEMENT_Y_BOTTOM) {
6483 y += ((widget->parent)->sy - widget->sy);
6484 }
6485 widget->y = y;
6486 break;
6487 }
6488 }
6489
6490
6491 /* ��ʬ���Ȥ� type���Ȥ��Ȥʤɤ��*/
6492 /* �Ҥ�����С�x,y ���롣 */
6493 /* �Ҥ����(next)�Ρ�x,y ����롣 */
6494 /* ľ���λҤ��Ф��ƤΤߺƵ�Ū�˽����� */
6495
6496 /*printf("%s (%d,%d) %d %d\n",debug_type(widget->type),widget->sx,widget->sy,widget->x,widget->y);fflush(stdout);*/
6497
6498 if (widget->visible) {
6499
6500 switch (widget->type) {
6501
6502 case Q8TK_TYPE_WINDOW: /* ������ɥ� */
6503 if (widget->stat.window.no_frame) {
6504 /* no frame */
6505 } else {
6506 q8gr_draw_window(x, y, widget->sx, widget->sy,
6507 widget->stat.window.shadow_type,
6508 (widget->stat.window.type
6509 == Q8TK_WINDOW_POPUP)
6510 ? Q8GR_WIDGET_WINDOW : NULL);
6511 }
6512 if (child) {
6513 child->x = x + (widget->stat.window.no_frame ? 0 : 1);
6514 child->y = y + (widget->stat.window.no_frame ? 0 : 1);
6515 widget_draw(child, FALSE, sensitive);
6516 }
6517 break;
6518
6519 case Q8TK_TYPE_BUTTON: /* �ܥ��� */
6520 case Q8TK_TYPE_TOGGLE_BUTTON: /* �ȥ���ܥ��� */
6521 widget_focus_list_append(sense_widget);
6522 q8gr_draw_button(x, y, widget->sx, widget->sy,
6523 widget->stat.button.active, sense_widget);
6524 if (child) {
6525 child->x = x + 1;
6526 child->y = y + 1;
6527 widget_draw(child, focus, sensitive);
6528 }
6529 break;
6530
6531 case Q8TK_TYPE_CHECK_BUTTON: /* �����å��ܥ��� */
6532 widget_focus_list_append(sense_widget);
6533 q8gr_draw_check_button(x, y, widget->stat.button.active,
6534 sense_widget);
6535 if (child) {
6536 child->x = x + 3;
6537 child->y = y;
6538 widget_draw(child, focus, sensitive);
6539 }
6540 break;
6541
6542 case Q8TK_TYPE_RADIO_BUTTON: /* �饸���ܥ��� */
6543 #if defined(OLD_FOCUS_CHANGE)
6544 widget_focus_list_append(sense_widget);
6545 #else /* �����ʥե���������ư���� */
6546 if (widget->stat.button.active == Q8TK_BUTTON_ON) {
6547 widget_focus_list_append(sense_widget);
6548 }
6549 #endif
6550 q8gr_draw_radio_button(x, y, widget->stat.button.active,
6551 sense_widget);
6552 if (child) {
6553 child->x = x + 3;
6554 child->y = y;
6555 widget_draw(child, focus, sensitive);
6556 }
6557 break;
6558
6559 case Q8TK_TYPE_FRAME: /* �ե졼�� */
6560 q8gr_draw_frame(x, y, widget->sx, widget->sy,
6561 widget->stat.frame.shadow_type,
6562 widget->code, widget->name,
6563 sense_widget);
6564 if (child) {
6565 child->x = x + 1;
6566 child->y = y + 1;
6567 widget_draw(child, FALSE, sensitive);
6568 }
6569 break;
6570
6571 case Q8TK_TYPE_LABEL: /* ��٥� */
6572 q8gr_draw_label(x, y,
6573 widget->stat.label.foreground,
6574 widget->stat.label.background,
6575 widget->stat.label.reverse,
6576 focus,
6577 (widget->name) ? (widget->code) : Q8TK_KANJI_ANK,
6578 (widget->name) ? (widget->name) : "",
6579 sense_widget);
6580 break;
6581
6582 case Q8TK_TYPE_LOGO: /* �� */
6583 q8gr_draw_logo(x, y);
6584 break;
6585
6586 case Q8TK_TYPE_NOTEBOOK: /* �Ρ��ȥ֥å� */
6587 q8gr_draw_notebook(x, y, widget->sx, widget->sy,
6588 widget, sense_widget);
6589 if (child) {
6590 child->x = x;
6591 child->y = y;
6592 widget_draw(child, FALSE, sensitive);
6593 }
6594 break;
6595 case Q8TK_TYPE_NOTEPAGE: /* �Ρ��ȥڡ��� */
6596 {
6597 int select_flag =
6598 (widget == (widget->parent)->stat.notebook.page);
6599
6600 q8gr_draw_notepage((widget->name) ? widget->code
6601 : Q8TK_KANJI_ANK,
6602 (widget->name) ? widget->name : "",
6603 select_flag,
6604 /*(select_flag) ? FALSE :*/ focus,
6605 widget->parent,
6606 sense_widget);
6607 if (child && select_flag) {
6608 child->x = ((widget->parent)->x) + 1;
6609 child->y = ((widget->parent)->y) + 3;
6610 widget_focus_list_append(widget);
6611 widget_draw(child, FALSE, sensitive);
6612 }
6613 #if defined(OLD_FOCUS_CHANGE)
6614 else {
6615 widget_focus_list_append(sense_widget);
6616 }
6617 #endif
6618 }
6619 break;
6620
6621 case Q8TK_TYPE_VBOX: /* ��ľ�ܥå��� */
6622 if (child) {
6623 child->x = x; x += 0;
6624 child->y = y; y += child->sy;
6625 while (child->next) {
6626 child = child->next;
6627 child->x = x; x += 0;
6628 child->y = y; y += child->sy;
6629 }
6630 child = widget->child;
6631 widget_draw(child, FALSE, sensitive);
6632 }
6633 break;
6634 case Q8TK_TYPE_HBOX: /* ��ʿ�ܥå��� */
6635 if (child) {
6636 child->x = x; x += child->sx;
6637 child->y = y; y += 0;
6638 while (child->next) {
6639 child = child->next;
6640 child->x = x; x += child->sx;
6641 child->y = y; y += 0;
6642 }
6643 child = widget->child;
6644 widget_draw(child, FALSE, sensitive);
6645 }
6646 break;
6647
6648 case Q8TK_TYPE_VSEPARATOR: /* ��ľ���ڤ��� */
6649 q8gr_draw_vseparator(x, y, widget->sy);
6650 break;
6651 case Q8TK_TYPE_HSEPARATOR: /* ��ʿ���ڤ��� */
6652 q8gr_draw_hseparator(x, y, widget->sx);
6653 break;
6654
6655 case Q8TK_TYPE_COMBO: /* ����ܥܥå��� */
6656 widget->stat.combo.entry->x = x;
6657 widget->stat.combo.entry->y = y;
6658 widget->stat.combo.entry->sx = widget->sx -3;
6659 widget_draw(widget->stat.combo.entry, FALSE, sensitive);
6660
6661 #if defined(OLD_FOCUS_CHANGE)
6662 widget_focus_list_append(sense_widget);
6663 #else /* �����ʥե���������ư���� */
6664 if (widget->stat.combo.entry->stat.entry.editable == FALSE) {
6665 widget_focus_list_append(sense_widget);
6666 }
6667 #endif
6668 q8gr_draw_combo(x, y, widget->sx -3, focus, sense_widget);
6669 break;
6670
6671 case Q8TK_TYPE_LISTBOX: /* �ꥹ�ȥܥå��� */
6672 widget_focus_list_append(sense_widget);
6673 if (child) {
6674 child->x = x; x += 0;
6675 child->y = y; y += child->sy;
6676 while (child->next) {
6677 child = child->next;
6678 child->x = x; x += 0;
6679 child->y = y; y += child->sy;
6680 }
6681 child = widget->child;
6682 widget_draw(child, focus, sensitive);
6683 }
6684 break;
6685
6686 case Q8TK_TYPE_LIST_ITEM: /* �ꥹ�ȥ����ƥ� */
6687 if (child) {
6688 int rev = (widget->parent->stat.listbox.selected == widget)
6689 ? TRUE : FALSE;
6690 int under = (widget->parent->stat.listbox.active == widget)
6691 ? TRUE : FALSE;
6692 if (rev && under) under = FALSE;
6693
6694 q8gr_draw_list_item(x, y, widget->sx, focus, rev,
6695 under, child->code, child->name,
6696 sense_widget);
6697 }
6698 next_focus = focus;
6699 break;
6700
6701 case Q8TK_TYPE_ADJUSTMENT: /* �����㥹�ȥ��� */
6702 Q8tkAssert(FALSE, NULL);
6703 break;
6704
6705 case Q8TK_TYPE_HSCALE: /* ��ʿ�������� */
6706 if (widget->stat.scale.adj) {
6707 int a_focus = (focus ||
6708 (widget->stat.scale.adj == get_focus_widget()))
6709 ? TRUE : FALSE;
6710 Q8tkWidget *a_widget = ((sensitive) ? widget->stat.scale.adj
6711 : NULL);
6712 widget_focus_list_append(a_widget);
6713 widget->stat.scale.adj->x = x;
6714 widget->stat.scale.adj->y = y;
6715 q8gr_draw_hscale(x, y,
6716 &(widget->stat.scale.adj->stat.adj),
6717 a_focus,
6718 widget->stat.scale.draw_value,
6719 widget->stat.scale.value_pos,
6720 a_widget);
6721 }
6722 break;
6723 case Q8TK_TYPE_VSCALE: /* ��ľ�������� */
6724 if (widget->stat.scale.adj) {
6725 int a_focus = (focus ||
6726 (widget->stat.scale.adj == get_focus_widget()))
6727 ? TRUE : FALSE;
6728 Q8tkWidget *a_widget = ((sensitive) ? widget->stat.scale.adj
6729 : NULL);
6730 widget_focus_list_append(a_widget);
6731 widget->stat.scale.adj->x = x;
6732 widget->stat.scale.adj->y = y;
6733 q8gr_draw_vscale(x, y,
6734 &(widget->stat.scale.adj->stat.adj),
6735 a_focus,
6736 widget->stat.scale.draw_value,
6737 widget->stat.scale.value_pos,
6738 a_widget);
6739 }
6740 break;
6741
6742 case Q8TK_TYPE_SCROLLED_WINDOW: /* ��������ɥ�����ɥ� */
6743 if (child) {
6744 int a_focus;
6745 Q8tkWidget *a_widget;
6746
6747 int sx = widget->sx;
6748 int sy = widget->sy;
6749
6750 if (widget->stat.scrolled.vscrollbar) { sx --; }
6751 if (widget->stat.scrolled.hscrollbar) { sy --; }
6752
6753 q8gr_draw_scrolled_window(x, y, sx, sy,
6754 Q8TK_SHADOW_ETCHED_OUT,
6755 sense_widget);
6756 q8gr_set_screen_mask(x+1, y+1, sx-2, sy-2);
6757 widget->stat.scrolled.child_x0
6758 = widget->stat.scrolled.hadj->stat.adj.value;
6759 widget->stat.scrolled.child_y0
6760 = widget->stat.scrolled.vadj->stat.adj.value;
6761 widget->stat.scrolled.child_sx = sx -2;
6762 widget->stat.scrolled.child_sy = sy -2;
6763
6764 child->x = x - widget->stat.scrolled.child_x0 +1;
6765 child->y = y - widget->stat.scrolled.child_y0 +1;
6766
6767 widget_draw(child, FALSE, sensitive);
6768 q8gr_reset_screen_mask();
6769
6770 if (widget->stat.scrolled.vscrollbar) {
6771 a_focus = (focus ||
6772 (widget->stat.scrolled.vadj == get_focus_widget()))
6773 ? TRUE : FALSE;
6774 a_widget = ((sensitive) ? widget->stat.scrolled.vadj
6775 : NULL);
6776 /* �ե��������ꥹ�Ȥˤ�����ʤ��ۤ��������ΤǤϡ� */
6777 widget_focus_list_append(a_widget);
6778 q8gr_draw_vscale(x + sx, y,
6779 &(widget->stat.scrolled.vadj->stat.adj),
6780 a_focus,
6781 FALSE, 0,
6782 a_widget);
6783 }
6784 if (widget->stat.scrolled.hscrollbar) {
6785 a_focus = (focus ||
6786 (widget->stat.scrolled.hadj == get_focus_widget()))
6787 ? TRUE : FALSE;
6788 a_widget = ((sensitive) ? widget->stat.scrolled.hadj
6789 : NULL);
6790 /* �ե��������ꥹ�Ȥˤ�����ʤ��ۤ��������ΤǤϡ� */
6791 widget_focus_list_append(a_widget);
6792 q8gr_draw_hscale(x, y + sy,
6793 &(widget->stat.scrolled.hadj->stat.adj),
6794 a_focus,
6795 FALSE, 0,
6796 a_widget);
6797 }
6798 } else {
6799 q8gr_draw_window(x, y, widget->sx, widget->sy,
6800 Q8TK_SHADOW_ETCHED_OUT,
6801 NULL);
6802 }
6803 break;
6804
6805 case Q8TK_TYPE_ENTRY: /* ����ȥ� */
6806 if (widget->stat.entry.editable) {
6807 widget_focus_list_append(sense_widget);
6808 }
6809 if (focus &&
6810 widget->stat.entry.editable &&
6811 widget->stat.entry.cursor_pos < 0) {
6812 q8tk_entry_set_position(widget,
6813 q8gr_strlen(widget->code, widget->name));
6814 }
6815
6816 q8gr_draw_entry(x, y, widget->sx, widget->code, widget->name,
6817 widget->stat.entry.disp_pos,
6818 ((focus && widget->stat.entry.editable)
6819 ? widget->stat.entry.cursor_pos: -1),
6820 sense_widget);
6821 break;
6822
6823 case Q8TK_TYPE_DIALOG: /* �������� */
6824 Q8tkAssert(FALSE, NULL);
6825 break;
6826 case Q8TK_TYPE_FILE_SELECTION: /* �ե����륻�쥯����� */
6827 Q8tkAssert(FALSE, NULL);
6828 break;
6829
6830 default:
6831 Q8tkAssert(FALSE, "Undefined type");
6832 }
6833 }
6834
6835
6836 /* ��ʬ���Ȥ���� (next) ��¸�ߤ���С��Ƶ�Ū�˽��� */
6837
6838 if (widget->next) {
6839 widget = widget->next;
6840 widget_draw(widget, next_focus, parent_sensitive);
6841 }
6842 }
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857 /*------------------------------------------------------*/
6858 /* ���������̤������
6859 q8tk_grab_add() �����ꤵ�줿 WINDOW ��ȥåפȤ��ơ�
6860 ���Ƥλҥ��������åȤ��礭�������֤������
6861 menu_screen[][]�ˡ�ɽ�����Ƥ����ꤹ�롣
6862 Ʊ���ˡ�TAB �������줿���Ρ��ե����������ѹ���
6863 ������Ƥ����� */
6864 /*------------------------------------------------------*/
6865
widget_construct(void)6866 static void widget_construct(void)
6867 {
6868 int i, j, tmp;
6869 Q8tkWidget *widget;
6870
6871 q8gr_clear_screen();
6872
6873 for (i=0; i<MAX_WINDOW_LAYER; i++) {
6874
6875 widget = window_layer[i];
6876
6877 if (widget) {
6878 Q8tkAssert(widget->type == Q8TK_TYPE_WINDOW, NULL);
6879
6880 for (j=0; j<2; j++) {
6881
6882 q8gr_clear_focus_screen();
6883
6884 widget_size(widget, &tmp, &tmp, &tmp, &tmp);
6885
6886 if (widget->stat.window.set_position == FALSE) {
6887 widget->x = (Q8GR_SCREEN_X - widget->sx) / 2;
6888 widget->y = (Q8GR_SCREEN_Y - widget->sy) / 2;
6889 } else {
6890 widget->x = widget->stat.window.x;
6891 widget->y = widget->stat.window.y;
6892 }
6893
6894 widget_scrollin_adjust_reset();
6895
6896 widget_focus_list_reset();
6897 widget_draw(widget, FALSE, widget->sensitive);
6898
6899 if (widget_scrollin_adjust()) {
6900 /* Redraw! */
6901 } else {
6902 break;
6903 }
6904
6905 }
6906
6907 } else {
6908 break;
6909 }
6910 }
6911
6912
6913 if (get_focus_widget() == NULL) {
6914 q8tk_widget_set_focus(widget_focus_list_get_top());
6915 }
6916
6917 #if 0
6918 if (get_drag_widget()) {
6919 /* none */
6920 } else {
6921 Q8tkWidget *w;
6922 int exist;
6923
6924 w = q8tk_tab_top_widget;
6925
6926 if (w) {
6927
6928 do { /* TAB TOP �� NOTEPAGE �ʳ������� */
6929 if (w->type != Q8TK_TYPE_NOTEPAGE) break;
6930 w = w->tab_next;
6931 } while (w != q8tk_tab_top_widget);
6932 q8tk_tab_top_widget = w;
6933
6934 exist = FALSE; /* event_widget ���ºߤ��뤫�����å� */
6935 do {
6936 if (w == get_event_widget()) {
6937 exist = TRUE;
6938 break;
6939 }
6940 w = w->tab_next;
6941 } while (w != q8tk_tab_top_widget);
6942 if (! exist) { /* �ºߤ��ʤ���� NULL �ˤ��Ƥ��� */
6943 set_event_widget(NULL);
6944 }
6945 }
6946 }
6947 #endif
6948
6949 if (disp_cursor) {
6950 q8gr_draw_mouse(mouse.x/8, mouse.y/16);
6951 }
6952
6953
6954 #if 0
6955 {
6956 int i, j; const char *c; void *w;
6957 for (j=0; j<Q8GR_SCREEN_Y; j++) {
6958 for (i=0; i<Q8GR_SCREEN_X; i++) {
6959 w = q8gr_get_focus_screen(i, j);
6960 if (w == Q8GR_WIDGET_NONE) c = " ";
6961 else if (w == Q8GR_WIDGET_WINDOW) c = "*";
6962 else c = debug_type(((Q8tkWidget *)w)->type);
6963 printf("%c", *c);
6964 }
6965 printf("\n");
6966 }
6967 printf("\n");
6968 fflush(0);
6969 }
6970 #endif
6971
6972 #if 0
6973 {
6974 int i;
6975 for (i=0; i<MAX_WIDGET_SCROLLIN; i++) {
6976 Q8tkWidget *w = widget_scrollin[i].widget;
6977 printf("%d [%s] %p\n",widget_scrollin[i].drawn,(w)?debug_type(w->type):"",w);
6978 }
6979 printf("--\n");fflush(0);
6980 }
6981 #endif
6982
6983 #if 0
6984 for (tmp=0,i=0; i<MAX_WIDGET; i++) { if (widget_table[i]) tmp++; }
6985 printf("[TOTAL WIDGET] %d/%d : ",tmp,MAX_WIDGET);
6986 for (tmp=0,i=0; i<MAX_LIST; i++) { if (list_table[i]) tmp++; }
6987 printf("[TOTAL LIST] %d/%d\n",tmp,MAX_LIST);
6988 #endif
6989 }
6990