Mercurial > dwindows
comparison gtk/dw.c @ 37:360bc6a5f1c9
Sync with latest Dynamic Windows code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 14 Oct 2001 23:27:37 +0000 |
parents | cddb02f847e1 |
children | 3aa9ef0b3996 |
comparison
equal
deleted
inserted
replaced
36:cddb02f847e1 | 37:360bc6a5f1c9 |
---|---|
51 GdkColor _background = { 0, 0xaaaa, 0xaaaa, 0xaaaa }; | 51 GdkColor _background = { 0, 0xaaaa, 0xaaaa, 0xaaaa }; |
52 | 52 |
53 int _dw_file_active = 0, _dw_ignore_click = 0; | 53 int _dw_file_active = 0, _dw_ignore_click = 0; |
54 pthread_t _dw_thread = (pthread_t)-1; | 54 pthread_t _dw_thread = (pthread_t)-1; |
55 int _dw_mutex_locked = FALSE; | 55 int _dw_mutex_locked = FALSE; |
56 /* Use default border size for the default enlightenment theme */ | |
57 int _dw_border_width = 12, _dw_border_height = 28; | |
56 | 58 |
57 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && _dw_mutex_locked == FALSE) { gdk_threads_enter(); _dw_mutex_locked = TRUE; _locked_by_me = TRUE; } } | 59 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && _dw_mutex_locked == FALSE) { gdk_threads_enter(); _dw_mutex_locked = TRUE; _locked_by_me = TRUE; } } |
58 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked = FALSE; _locked_by_me = FALSE; } } | 60 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked = FALSE; _locked_by_me = FALSE; } } |
59 | 61 |
60 /* Currently the non Imlib method does not work */ | 62 /* Currently the non Imlib method does not work */ |
81 void _container_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data); | 83 void _container_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data); |
82 void _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data); | 84 void _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data); |
83 void _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data); | 85 void _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data); |
84 void _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data); | 86 void _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data); |
85 void _tree_select_event(GtkTree *tree, GtkWidget *child, gpointer data); | 87 void _tree_select_event(GtkTree *tree, GtkWidget *child, gpointer data); |
88 | |
89 void msleep(long period); | |
86 | 90 |
87 typedef struct | 91 typedef struct |
88 { | 92 { |
89 void *func; | 93 void *func; |
90 char name[30]; | 94 char name[30]; |
467 * False if there is already a message loop running. | 471 * False if there is already a message loop running. |
468 */ | 472 */ |
469 int dw_int_init(DWResources *res, int newthread, int argc, char *argv[]) | 473 int dw_int_init(DWResources *res, int newthread, int argc, char *argv[]) |
470 { | 474 { |
471 int z; | 475 int z; |
476 char *tmp; | |
472 | 477 |
473 if(res) | 478 if(res) |
474 { | 479 { |
475 _resources.resource_max = res->resource_max; | 480 _resources.resource_max = res->resource_max; |
476 _resources.resource_id = res->resource_id; | 481 _resources.resource_id = res->resource_id; |
485 #endif | 490 #endif |
486 /* Add colors to the system colormap */ | 491 /* Add colors to the system colormap */ |
487 _dw_cmap = gdk_colormap_get_system(); | 492 _dw_cmap = gdk_colormap_get_system(); |
488 for(z=0;z<16;z++) | 493 for(z=0;z<16;z++) |
489 gdk_color_alloc(_dw_cmap, &_colors[z]); | 494 gdk_color_alloc(_dw_cmap, &_colors[z]); |
495 | |
496 tmp = getenv("DW_BORDER_WIDTH"); | |
497 if(tmp) | |
498 _dw_border_width = atoi(tmp); | |
499 tmp = getenv("DW_BORDER_HEIGHT"); | |
500 if(tmp) | |
501 _dw_border_height = atoi(tmp); | |
502 | |
490 return TRUE; | 503 return TRUE; |
491 } | 504 } |
492 | 505 |
493 /* | 506 /* |
494 * Runs a message loop for Dynamic Windows. | 507 * Runs a message loop for Dynamic Windows. |
501 { | 514 { |
502 _dw_thread = pthread_self(); | 515 _dw_thread = pthread_self(); |
503 gdk_threads_enter(); | 516 gdk_threads_enter(); |
504 gtk_main(); | 517 gtk_main(); |
505 gdk_threads_leave(); | 518 gdk_threads_leave(); |
519 } | |
520 | |
521 /* | |
522 * Runs a message loop for Dynamic Windows, for a period of seconds. | |
523 * Parameters: | |
524 * seconds: Number of seconds to run the loop for. | |
525 */ | |
526 void dw_main_sleep(int seconds) | |
527 { | |
528 time_t start = time(NULL); | |
529 | |
530 if(_dw_thread == (pthread_t)-1 || _dw_thread == pthread_self()) | |
531 { | |
532 while(time(NULL) - start <= seconds) | |
533 { | |
534 gdk_threads_enter(); | |
535 if(gtk_events_pending()) | |
536 gtk_main_iteration(); | |
537 else | |
538 msleep(1); | |
539 gdk_threads_leave(); | |
540 } | |
541 } | |
542 else | |
543 msleep(seconds * 1000); | |
506 } | 544 } |
507 | 545 |
508 /* | 546 /* |
509 * Free's memory allocated by dynamic windows. | 547 * Free's memory allocated by dynamic windows. |
510 * Parameters: | 548 * Parameters: |
996 void dw_window_capture(HWND handle) | 1034 void dw_window_capture(HWND handle) |
997 { | 1035 { |
998 int _locked_by_me = FALSE; | 1036 int _locked_by_me = FALSE; |
999 | 1037 |
1000 DW_MUTEX_LOCK; | 1038 DW_MUTEX_LOCK; |
1001 gdk_pointer_grab(handle->window, TRUE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, GDK_CURRENT_TIME); | 1039 gdk_pointer_grab(handle->window, TRUE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, NULL, GDK_CURRENT_TIME); |
1002 DW_MUTEX_UNLOCK; | 1040 DW_MUTEX_UNLOCK; |
1003 } | 1041 } |
1004 | 1042 |
1005 /* | 1043 /* |
1006 * Changes the appearance of the mouse pointer. | 1044 * Changes the appearance of the mouse pointer. |
1098 * pad: Number of pixels to pad around the box. | 1136 * pad: Number of pixels to pad around the box. |
1099 * title: Text to be displayined in the group outline. | 1137 * title: Text to be displayined in the group outline. |
1100 */ | 1138 */ |
1101 HWND dw_groupbox_new(int type, int pad, char *title) | 1139 HWND dw_groupbox_new(int type, int pad, char *title) |
1102 { | 1140 { |
1103 return dw_box_new(type, pad); | 1141 GtkWidget *tmp, *frame; |
1142 int _locked_by_me = FALSE; | |
1143 | |
1144 DW_MUTEX_LOCK; | |
1145 frame = gtk_frame_new(NULL); | |
1146 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); | |
1147 gtk_frame_set_label(GTK_FRAME(frame), title && *title ? title : NULL); | |
1148 tmp = gtk_table_new(1, 1, FALSE); | |
1149 gtk_object_set_data(GTK_OBJECT(tmp), "boxtype", (gpointer)type); | |
1150 gtk_object_set_data(GTK_OBJECT(tmp), "boxpad", (gpointer)pad); | |
1151 gtk_object_set_data(GTK_OBJECT(frame), "boxhandle", (gpointer)tmp); | |
1152 gtk_container_add(GTK_CONTAINER(frame), tmp); | |
1153 gtk_widget_show(tmp); | |
1154 gtk_widget_show(frame); | |
1155 DW_MUTEX_UNLOCK; | |
1156 return frame; | |
1104 } | 1157 } |
1105 | 1158 |
1106 /* | 1159 /* |
1107 * Create a new MDI Frame to be packed. | 1160 * Create a new MDI Frame to be packed. |
1108 * Parameters: | 1161 * Parameters: |
1533 | 1586 |
1534 /* Left and centered */ | 1587 /* Left and centered */ |
1535 gtk_misc_set_alignment(GTK_MISC(tmp), 0.0f, 0.5f); | 1588 gtk_misc_set_alignment(GTK_MISC(tmp), 0.0f, 0.5f); |
1536 gtk_widget_show(tmp); | 1589 gtk_widget_show(tmp); |
1537 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | 1590 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); |
1591 gtk_misc_set_alignment(GTK_MISC(tmp), DW_LEFT, DW_LEFT); | |
1538 DW_MUTEX_UNLOCK; | 1592 DW_MUTEX_UNLOCK; |
1539 return tmp; | 1593 return tmp; |
1540 } | 1594 } |
1541 | 1595 |
1542 /* | 1596 /* |
3610 * pad: Number of pixels of padding around the item. | 3664 * pad: Number of pixels of padding around the item. |
3611 */ | 3665 */ |
3612 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 3666 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
3613 { | 3667 { |
3614 int _locked_by_me = FALSE; | 3668 int _locked_by_me = FALSE; |
3669 GtkWidget *tmp; | |
3615 | 3670 |
3616 if(!box) | 3671 if(!box) |
3617 return; | 3672 return; |
3618 | 3673 |
3619 DW_MUTEX_LOCK; | 3674 DW_MUTEX_LOCK; |
3675 | |
3676 if((tmp = gtk_object_get_data(GTK_OBJECT(box), "boxhandle"))) | |
3677 box = tmp; | |
3620 | 3678 |
3621 if(!item) | 3679 if(!item) |
3622 { | 3680 { |
3623 item = gtk_label_new(""); | 3681 item = gtk_label_new(""); |
3624 gtk_widget_show(item); | 3682 gtk_widget_show(item); |
3769 if(handle && GTK_IS_WINDOW(handle)) | 3827 if(handle && GTK_IS_WINDOW(handle)) |
3770 { | 3828 { |
3771 _size_allocate(GTK_WINDOW(handle)); | 3829 _size_allocate(GTK_WINDOW(handle)); |
3772 | 3830 |
3773 gtk_widget_set_uposition(handle, x, y); | 3831 gtk_widget_set_uposition(handle, x, y); |
3774 gtk_window_set_default_size(GTK_WINDOW(handle), width, height); | 3832 gtk_window_set_default_size(GTK_WINDOW(handle), width - _dw_border_width, height - _dw_border_height); |
3775 } | 3833 } |
3776 else if(handle && handle->window) | 3834 else if(handle && handle->window) |
3777 { | 3835 { |
3778 gdk_window_resize(handle->window, width, height); | 3836 gdk_window_resize(handle->window, width, height); |
3779 gdk_window_move(handle->window, x, y); | 3837 gdk_window_move(handle->window, x, y); |
3803 gdk_window_get_root_origin(handle->window, &gx, &gy); | 3861 gdk_window_get_root_origin(handle->window, &gx, &gy); |
3804 if(x) | 3862 if(x) |
3805 *x = gx; | 3863 *x = gx; |
3806 if(y) | 3864 if(y) |
3807 *y = gy; | 3865 *y = gy; |
3808 if(width) | 3866 if(GTK_IS_WINDOW(handle)) |
3809 *width = gwidth; | 3867 { |
3810 if(height) | 3868 if(width) |
3811 *height = gheight; | 3869 *width = gwidth + _dw_border_width; |
3870 if(height) | |
3871 *height = gheight + _dw_border_height; | |
3872 } | |
3873 else | |
3874 { | |
3875 if(width) | |
3876 *width = gwidth; | |
3877 if(height) | |
3878 *height = gheight; | |
3879 } | |
3812 DW_MUTEX_UNLOCK; | 3880 DW_MUTEX_UNLOCK; |
3813 } | 3881 } |
3814 } | 3882 } |
3815 | 3883 |
3816 /* | 3884 /* |
3839 if(style & DW_CCS_SINGLESEL) | 3907 if(style & DW_CCS_SINGLESEL) |
3840 gtk_clist_set_selection_mode(GTK_CLIST(handle2), GTK_SELECTION_SINGLE); | 3908 gtk_clist_set_selection_mode(GTK_CLIST(handle2), GTK_SELECTION_SINGLE); |
3841 } | 3909 } |
3842 if(GTK_IS_LABEL(handle2)) | 3910 if(GTK_IS_LABEL(handle2)) |
3843 { | 3911 { |
3844 gfloat x, y; | 3912 if(style & DW_DT_CENTER || style & DW_DT_VCENTER) |
3845 | 3913 { |
3846 x = y = DW_LEFT; | 3914 gfloat x, y; |
3847 | 3915 |
3848 if(style & DW_DT_CENTER) | 3916 x = y = DW_LEFT; |
3849 x = DW_CENTER; | 3917 |
3850 | 3918 if(style & DW_DT_CENTER) |
3851 if(style & DW_DT_VCENTER) | 3919 x = DW_CENTER; |
3852 y = DW_CENTER; | 3920 |
3853 | 3921 if(style & DW_DT_VCENTER) |
3854 gtk_misc_set_alignment(GTK_MISC(handle2), x, y); | 3922 y = DW_CENTER; |
3923 | |
3924 gtk_misc_set_alignment(GTK_MISC(handle2), x, y); | |
3925 } | |
3926 if(style & DW_DT_WORDBREAK) | |
3927 gtk_label_set_line_wrap(GTK_LABEL(handle), TRUE); | |
3855 } | 3928 } |
3856 DW_MUTEX_UNLOCK; | 3929 DW_MUTEX_UNLOCK; |
3857 } | 3930 } |
3858 | 3931 |
3859 /* | 3932 /* |
4427 * pad: Number of pixels of padding around the item. | 4500 * pad: Number of pixels of padding around the item. |
4428 */ | 4501 */ |
4429 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 4502 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
4430 { | 4503 { |
4431 int _locked_by_me = FALSE; | 4504 int _locked_by_me = FALSE; |
4505 GtkWidget *tmp; | |
4432 | 4506 |
4433 if(!box) | 4507 if(!box) |
4434 return; | 4508 return; |
4435 | 4509 |
4436 DW_MUTEX_LOCK; | 4510 DW_MUTEX_LOCK; |
4511 | |
4512 if((tmp = gtk_object_get_data(GTK_OBJECT(box), "boxhandle"))) | |
4513 box = tmp; | |
4437 | 4514 |
4438 if(!item) | 4515 if(!item) |
4439 { | 4516 { |
4440 item = gtk_label_new(""); | 4517 item = gtk_label_new(""); |
4441 gtk_widget_show(item); | 4518 gtk_widget_show(item); |
4736 * function: Function pointer to be called. | 4813 * function: Function pointer to be called. |
4737 * data: Pointer to the data to be passed to the function. | 4814 * data: Pointer to the data to be passed to the function. |
4738 */ | 4815 */ |
4739 void dw_window_function(HWND handle, void *function, void *data) | 4816 void dw_window_function(HWND handle, void *function, void *data) |
4740 { | 4817 { |
4741 /* TODO */ | 4818 void (* windowfunc)(void *); |
4819 | |
4820 windowfunc = function; | |
4821 | |
4822 if(windowfunc) | |
4823 windowfunc(data); | |
4742 } | 4824 } |
4743 | 4825 |
4744 #ifndef NO_SIGNALS | 4826 #ifndef NO_SIGNALS |
4745 /* | 4827 /* |
4746 * Add a callback to a window event. | 4828 * Add a callback to a window event. |
4786 } | 4868 } |
4787 else if(GTK_IS_LIST(thiswindow) && strcmp(signame, "item-select") == 0) | 4869 else if(GTK_IS_LIST(thiswindow) && strcmp(signame, "item-select") == 0) |
4788 { | 4870 { |
4789 thisname = "select_child"; | 4871 thisname = "select_child"; |
4790 } | 4872 } |
4791 else if(GTK_IS_WINDOW(thiswindow) && strcmp(signame, "set-focus") == 0) | 4873 else if(strcmp(signame, "set-focus") == 0) |
4792 { | 4874 { |
4793 thisname = "focus-in-event"; | 4875 thisname = "focus-in-event"; |
4794 } | 4876 } |
4795 else if(GTK_IS_TREE(thiswindow) && strcmp(signame, "tree-select") == 0) | 4877 else if(GTK_IS_TREE(thiswindow) && strcmp(signame, "tree-select") == 0) |
4796 { | 4878 { |