Mercurial > dwindows
comparison gtk/dw.c @ 612:c5e5671dec8f
Modify Calendar widget
Amke Mac port actually compile and run
Add Clipboard support for GTK and Win
Add *from_data() contructors allowing icons, bitmaps to be created from embedded data.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 23 Mar 2008 04:54:30 +0000 |
parents | 2bff0dbae0e5 |
children | fb59f9eeeecd |
comparison
equal
deleted
inserted
replaced
611:bc800fc67343 | 612:c5e5671dec8f |
---|---|
66 { 0, 0xffff, 0x0000, 0xffff }, /* 13 bright magenta */ | 66 { 0, 0xffff, 0x0000, 0xffff }, /* 13 bright magenta */ |
67 { 0, 0x0000, 0xeeee, 0xeeee }, /* 14 bright cyan */ | 67 { 0, 0x0000, 0xeeee, 0xeeee }, /* 14 bright cyan */ |
68 { 0, 0xffff, 0xffff, 0xffff }, /* 15 bright white */ | 68 { 0, 0xffff, 0xffff, 0xffff }, /* 15 bright white */ |
69 }; | 69 }; |
70 | 70 |
71 #define NUM_EXTS 5 | |
72 char *image_exts[NUM_EXTS] = | |
73 { | |
74 ".xpm", | |
75 ".png", | |
76 ".bmp", | |
77 ".jpg", | |
78 ".ico", | |
79 }; | |
80 | |
71 #define DW_THREAD_LIMIT 50 | 81 #define DW_THREAD_LIMIT 50 |
72 | 82 |
73 #ifndef max | 83 #ifndef max |
74 # define max(a,b) (((a) > (b)) ? (a) : (b)) | 84 # define max(a,b) (((a) > (b)) ? (a) : (b)) |
75 #endif | 85 #endif |
80 | 90 |
81 DWTID _dw_thread_list[DW_THREAD_LIMIT]; | 91 DWTID _dw_thread_list[DW_THREAD_LIMIT]; |
82 GdkColor _foreground[DW_THREAD_LIMIT]; | 92 GdkColor _foreground[DW_THREAD_LIMIT]; |
83 GdkColor _background[DW_THREAD_LIMIT]; | 93 GdkColor _background[DW_THREAD_LIMIT]; |
84 int _transparent[DW_THREAD_LIMIT]; | 94 int _transparent[DW_THREAD_LIMIT]; |
95 GtkClipboard *_clipboard_object[DW_THREAD_LIMIT]; | |
96 gchar *_clipboard_contents[DW_THREAD_LIMIT]; | |
85 | 97 |
86 GtkWidget *last_window = NULL, *popup = NULL; | 98 GtkWidget *last_window = NULL, *popup = NULL; |
87 | 99 |
88 static int _dw_file_active = 0, _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0; | 100 static int _dw_file_active = 0, _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0; |
89 static pthread_t _dw_thread = (pthread_t)-1; | 101 static pthread_t _dw_thread = (pthread_t)-1; |
1856 _dw_thread_list[z] = tid; | 1868 _dw_thread_list[z] = tid; |
1857 _foreground[z].pixel = _foreground[z].red =_foreground[z].green = _foreground[z].blue = 0; | 1869 _foreground[z].pixel = _foreground[z].red =_foreground[z].green = _foreground[z].blue = 0; |
1858 _background[z].pixel = 1; | 1870 _background[z].pixel = 1; |
1859 _background[z].red = _background[z].green = _background[z].blue = 0; | 1871 _background[z].red = _background[z].green = _background[z].blue = 0; |
1860 _transparent[z] = 1; | 1872 _transparent[z] = 1; |
1873 _clipboard_contents[z] = NULL; | |
1874 _clipboard_object[z] = NULL; | |
1861 return; | 1875 return; |
1862 } | 1876 } |
1863 } | 1877 } |
1864 } | 1878 } |
1865 | 1879 |
1869 int z; | 1883 int z; |
1870 | 1884 |
1871 for(z=0;z<DW_THREAD_LIMIT;z++) | 1885 for(z=0;z<DW_THREAD_LIMIT;z++) |
1872 { | 1886 { |
1873 if(_dw_thread_list[z] == (DWTID)tid) | 1887 if(_dw_thread_list[z] == (DWTID)tid) |
1888 { | |
1874 _dw_thread_list[z] = (DWTID)-1; | 1889 _dw_thread_list[z] = (DWTID)-1; |
1890 if ( _clipboard_contents[z] != NULL ) | |
1891 { | |
1892 g_free( _clipboard_contents[z] ); | |
1893 _clipboard_contents[z] = NULL;; | |
1894 } | |
1895 _clipboard_object[z] = NULL;; | |
1896 } | |
1875 } | 1897 } |
1876 } | 1898 } |
1877 | 1899 |
1878 /* Try to load the mozilla embed shared libary */ | 1900 /* Try to load the mozilla embed shared libary */ |
1879 #ifdef USE_GTKMOZEMBED | 1901 #ifdef USE_GTKMOZEMBED |
3694 } | 3716 } |
3695 | 3717 |
3696 /* | 3718 /* |
3697 * Create a new bitmap button window (widget) to be packed from a file. | 3719 * Create a new bitmap button window (widget) to be packed from a file. |
3698 * Parameters: | 3720 * Parameters: |
3721 * label_text: Text to display on button. TBD when Windows works | |
3699 * text: Bubble help text to be displayed. | 3722 * text: Bubble help text to be displayed. |
3700 * id: An ID to be used with dw_window_from_id() or 0L. | 3723 * id: An ID to be used with dw_window_from_id() or 0L. |
3701 * filename: Name of the file, omit extention to have | 3724 * filename: Name of the file, omit extention to have |
3702 * DW pick the appropriate file extension. | 3725 * DW pick the appropriate file extension. |
3703 * (BMP on OS/2 or Windows, XPM on Unix) | 3726 * (BMP on OS/2 or Windows, XPM on Unix) |
3704 */ | 3727 */ |
3705 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) | 3728 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) |
3706 { | 3729 { |
3707 GtkWidget *tmp; | 3730 GtkWidget *bitmap; |
3708 GtkWidget *bitmap; | 3731 GtkWidget *box; |
3709 GtkTooltips *tooltips; | 3732 GtkWidget *label; |
3710 int _locked_by_me = FALSE; | 3733 GtkWidget *button; |
3711 | 3734 GtkTooltips *tooltips; |
3712 DW_MUTEX_LOCK; | 3735 char *label_text=NULL; |
3713 tmp = gtk_button_new(); | 3736 int _locked_by_me = FALSE; |
3714 bitmap = dw_bitmap_new(id); | 3737 |
3715 | 3738 DW_MUTEX_LOCK; |
3716 if(bitmap) | 3739 |
3717 { | 3740 /* Create box for image and label */ |
3718 dw_window_set_bitmap(bitmap, 0, filename); | 3741 box = gtk_hbox_new (FALSE, 0); |
3719 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 3742 gtk_container_set_border_width (GTK_CONTAINER (box), 2); |
3720 } | 3743 |
3721 gtk_widget_show(tmp); | 3744 /* Now on to the image stuff */ |
3722 if(text) | 3745 bitmap = dw_bitmap_new(id); |
3723 { | 3746 if ( bitmap ) |
3724 tooltips = gtk_tooltips_new(); | 3747 { |
3725 gtk_tooltips_set_tip(tooltips, tmp, text, NULL); | 3748 dw_window_set_bitmap( bitmap, 0, filename ); |
3726 gtk_object_set_data(GTK_OBJECT(tmp), "tooltip", (gpointer)tooltips); | 3749 /* Pack the image into the box */ |
3727 } | 3750 gtk_box_pack_start( GTK_BOX(box), bitmap, TRUE, FALSE, 3 ); |
3728 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", (gpointer)id); | 3751 gtk_widget_show( bitmap ); |
3729 DW_MUTEX_UNLOCK; | 3752 } |
3730 return tmp; | 3753 if ( label_text ) |
3754 { | |
3755 /* Create a label for the button */ | |
3756 label = gtk_label_new( label_text ); | |
3757 /* Pack the label into the box */ | |
3758 gtk_box_pack_start( GTK_BOX(box), label, TRUE, FALSE, 3 ); | |
3759 gtk_widget_show( label ); | |
3760 } | |
3761 /* Create a new button */ | |
3762 button = gtk_button_new(); | |
3763 | |
3764 /* Pack and show all our widgets */ | |
3765 gtk_widget_show( box ); | |
3766 gtk_container_add( GTK_CONTAINER(button), box ); | |
3767 gtk_widget_show( button ); | |
3768 if ( text ) | |
3769 { | |
3770 tooltips = gtk_tooltips_new(); | |
3771 gtk_tooltips_set_tip( tooltips, button, text, NULL ); | |
3772 gtk_object_set_data( GTK_OBJECT(button), "tooltip", (gpointer)tooltips ); | |
3773 } | |
3774 gtk_object_set_data( GTK_OBJECT(button), "_dw_id", (gpointer)id ); | |
3775 DW_MUTEX_UNLOCK; | |
3776 return button; | |
3777 } | |
3778 | |
3779 /* | |
3780 * Create a new bitmap button window (widget) to be packed from data. | |
3781 * Parameters: | |
3782 * text: Bubble help text to be displayed. | |
3783 * id: An ID to be used with dw_window_from_id() or 0L. | |
3784 * data: Raw data of image. | |
3785 * (BMP on OS/2 or Windows, XPM on Unix) | |
3786 * len: Length of raw data | |
3787 */ | |
3788 HWND dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len) | |
3789 { | |
3790 GtkWidget *tmp; | |
3791 GtkWidget *bitmap; | |
3792 GtkTooltips *tooltips; | |
3793 int _locked_by_me = FALSE; | |
3794 | |
3795 DW_MUTEX_LOCK; | |
3796 tmp = gtk_button_new(); | |
3797 bitmap = dw_bitmap_new(id); | |
3798 | |
3799 if ( bitmap ) | |
3800 { | |
3801 dw_window_set_bitmap_from_data(bitmap, 0, data, len); | |
3802 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | |
3803 } | |
3804 gtk_widget_show(tmp); | |
3805 if(text) | |
3806 { | |
3807 tooltips = gtk_tooltips_new(); | |
3808 gtk_tooltips_set_tip(tooltips, tmp, text, NULL); | |
3809 gtk_object_set_data(GTK_OBJECT(tmp), "tooltip", (gpointer)tooltips); | |
3810 } | |
3811 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", (gpointer)id); | |
3812 DW_MUTEX_UNLOCK; | |
3813 return tmp; | |
3731 } | 3814 } |
3732 | 3815 |
3733 /* | 3816 /* |
3734 * Create a new spinbutton window (widget) to be packed. | 3817 * Create a new spinbutton window (widget) to be packed. |
3735 * Parameters: | 3818 * Parameters: |
3931 * Windows and a pixmap on Unix, pass | 4014 * Windows and a pixmap on Unix, pass |
3932 * NULL if you use the id param) | 4015 * NULL if you use the id param) |
3933 */ | 4016 */ |
3934 void dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) | 4017 void dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) |
3935 { | 4018 { |
3936 GdkBitmap *bitmap = NULL; | 4019 GdkBitmap *bitmap = NULL; |
3937 GdkPixmap *tmp; | 4020 GdkPixmap *tmp; |
3938 int _locked_by_me = FALSE; | 4021 int found_ext = 0; |
3939 | 4022 int i; |
3940 if(!id && !filename) | 4023 int _locked_by_me = FALSE; |
3941 return; | 4024 |
3942 | 4025 if(!id && !filename) |
3943 DW_MUTEX_LOCK; | 4026 return; |
3944 if(id) | 4027 |
3945 tmp = _find_pixmap(&bitmap, id, handle, NULL, NULL); | 4028 DW_MUTEX_LOCK; |
3946 else | 4029 if(id) |
3947 { | 4030 tmp = _find_pixmap(&bitmap, id, handle, NULL, NULL); |
3948 char *file = alloca(strlen(filename) + 5); | 4031 else |
4032 { | |
4033 char *file = alloca(strlen(filename) + 5); | |
3949 #if GTK_MAJOR_VERSION > 1 | 4034 #if GTK_MAJOR_VERSION > 1 |
3950 GdkPixbuf *pixbuf; | 4035 GdkPixbuf *pixbuf; |
3951 #elif defined(USE_IMLIB) | 4036 #elif defined(USE_IMLIB) |
3952 GdkImlibImage *image; | 4037 GdkImlibImage *image; |
3953 #endif | 4038 #endif |
3954 | 4039 |
3955 if (!file) | 4040 if (!file) |
3956 { | 4041 { |
3957 DW_MUTEX_UNLOCK; | 4042 DW_MUTEX_UNLOCK; |
3958 return; | 4043 return; |
3959 } | 4044 } |
3960 | 4045 |
3961 strcpy(file, filename); | 4046 strcpy(file, filename); |
3962 | 4047 |
3963 /* check if we can read from this file (it exists and read permission) */ | 4048 /* check if we can read from this file (it exists and read permission) */ |
3964 if(access(file, 04) != 0) | 4049 if ( access(file, 04 ) != 0 ) |
3965 { | 4050 { |
3966 /* Try with .xpm extention */ | 4051 /* Try with .xpm extention */ |
3967 strcat(file, ".xpm"); | 4052 for ( i = 0; i < NUM_EXTS; i++ ) |
3968 if(access(file, 04) != 0) | 4053 { |
3969 { | 4054 strcpy( file, filename ); |
3970 DW_MUTEX_UNLOCK; | 4055 strcat( file, image_exts[i] ); |
3971 return; | 4056 if ( access( file, 04 ) == 0 ) |
3972 } | 4057 { |
3973 } | 4058 found_ext = 1; |
4059 break; | |
4060 } | |
4061 } | |
4062 if ( found_ext == 0 ) | |
4063 { | |
4064 DW_MUTEX_UNLOCK; | |
4065 return; | |
4066 } | |
4067 } | |
3974 #if GTK_MAJOR_VERSION > 1 | 4068 #if GTK_MAJOR_VERSION > 1 |
3975 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | 4069 pixbuf = gdk_pixbuf_new_from_file(file, NULL ); |
3976 | 4070 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &tmp, &bitmap, 1); |
3977 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &tmp, &bitmap, 1); | 4071 g_object_unref(pixbuf); |
3978 g_object_unref(pixbuf); | |
3979 #elif defined(USE_IMLIB) | 4072 #elif defined(USE_IMLIB) |
3980 image = gdk_imlib_load_image(file); | 4073 image = gdk_imlib_load_image(file); |
3981 | 4074 gdk_imlib_render(image, image->rgb_width, image->rgb_height); |
3982 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | 4075 tmp = gdk_imlib_copy_image(image); |
3983 tmp = gdk_imlib_copy_image(image); | 4076 bitmap = gdk_imlib_copy_mask(image); |
3984 bitmap = gdk_imlib_copy_mask(image); | 4077 gdk_imlib_destroy_image(image); |
3985 gdk_imlib_destroy_image(image); | |
3986 #else | 4078 #else |
3987 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); | 4079 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); |
3988 #endif | 4080 #endif |
3989 } | 4081 } |
3990 | 4082 |
3991 if(tmp) | 4083 if(tmp) |
4084 { | |
3992 #if GTK_MAJOR_VERSION > 1 | 4085 #if GTK_MAJOR_VERSION > 1 |
3993 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); | 4086 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); |
3994 #else | 4087 #else |
3995 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); | 4088 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); |
3996 #endif | 4089 #endif |
3997 DW_MUTEX_UNLOCK; | 4090 } |
4091 DW_MUTEX_UNLOCK; | |
4092 } | |
4093 | |
4094 /* | |
4095 * Sets the bitmap used for a given static window. | |
4096 * Parameters: | |
4097 * handle: Handle to the window. | |
4098 * id: An ID to be used to specify the icon, | |
4099 * (pass 0 if you use the filename param) | |
4100 * data: the image data | |
4101 * Bitmap on Windows and a pixmap on Unix, pass | |
4102 * NULL if you use the id param) | |
4103 * len: length of data | |
4104 */ | |
4105 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len) | |
4106 { | |
4107 GdkBitmap *bitmap = NULL; | |
4108 GdkPixmap *tmp; | |
4109 int _locked_by_me = FALSE; | |
4110 char *file; | |
4111 FILE *fp; | |
4112 | |
4113 if (!id && !data) | |
4114 return; | |
4115 | |
4116 DW_MUTEX_LOCK; | |
4117 if (id) | |
4118 tmp = _find_pixmap(&bitmap, id, handle, NULL, NULL); | |
4119 else | |
4120 { | |
4121 #if GTK_MAJOR_VERSION > 1 | |
4122 GdkPixbuf *pixbuf; | |
4123 #elif defined(USE_IMLIB) | |
4124 GdkImlibImage *image; | |
4125 #endif | |
4126 if (!data) | |
4127 { | |
4128 DW_MUTEX_UNLOCK; | |
4129 return; | |
4130 } | |
4131 /* | |
4132 * A real hack; create a temporary file and write the contents | |
4133 * of the data to the file | |
4134 */ | |
4135 file = tmpnam( NULL ); | |
4136 fp = fopen( file, "wb" ); | |
4137 if ( fp ) | |
4138 { | |
4139 fwrite( data, len, 1, fp ); | |
4140 fclose( fp ); | |
4141 } | |
4142 else | |
4143 { | |
4144 DW_MUTEX_UNLOCK; | |
4145 return; | |
4146 } | |
4147 #if GTK_MAJOR_VERSION > 1 | |
4148 pixbuf = gdk_pixbuf_new_from_file(file, NULL ); | |
4149 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &tmp, &bitmap, 1); | |
4150 g_object_unref(pixbuf); | |
4151 #elif defined(USE_IMLIB) | |
4152 image = gdk_imlib_load_image(file); | |
4153 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | |
4154 tmp = gdk_imlib_copy_image(image); | |
4155 bitmap = gdk_imlib_copy_mask(image); | |
4156 gdk_imlib_destroy_image(image); | |
4157 #else | |
4158 tmp = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], mydata); | |
4159 #endif | |
4160 /* remove our temporary file */ | |
4161 unlink (file ); | |
4162 } | |
4163 | |
4164 if(tmp) | |
4165 { | |
4166 #if GTK_MAJOR_VERSION > 1 | |
4167 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); | |
4168 #else | |
4169 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); | |
4170 #endif | |
4171 } | |
4172 DW_MUTEX_UNLOCK; | |
3998 } | 4173 } |
3999 | 4174 |
4000 /* | 4175 /* |
4001 * Sets the text used for a given window. | 4176 * Sets the text used for a given window. |
4002 * Parameters: | 4177 * Parameters: |
4003 * handle: Handle to the window. | 4178 * handle: Handle to the window. |
4004 * text: The text associsated with a given window. f | 4179 * text: The text associated with a given window. |
4005 */ | 4180 */ |
4006 void dw_window_set_text(HWND handle, char *text) | 4181 void dw_window_set_text(HWND handle, char *text) |
4007 { | 4182 { |
4008 int _locked_by_me = FALSE; | 4183 int _locked_by_me = FALSE; |
4009 GtkWidget *tmp; | 4184 GtkWidget *tmp; |
5845 * DW pick the appropriate file extension. | 6020 * DW pick the appropriate file extension. |
5846 * (ICO on OS/2 or Windows, XPM on Unix) | 6021 * (ICO on OS/2 or Windows, XPM on Unix) |
5847 */ | 6022 */ |
5848 unsigned long API dw_icon_load_from_file(char *filename) | 6023 unsigned long API dw_icon_load_from_file(char *filename) |
5849 { | 6024 { |
5850 int found = -1, _locked_by_me = FALSE; | 6025 int found = -1, _locked_by_me = FALSE; |
5851 #if GTK_MAJOR_VERSION > 1 | 6026 #if GTK_MAJOR_VERSION > 1 |
5852 GdkPixbuf *pixbuf; | 6027 GdkPixbuf *pixbuf; |
5853 #elif defined(USE_IMLIB) | 6028 #elif defined(USE_IMLIB) |
5854 GdkImlibImage *image; | 6029 GdkImlibImage *image; |
5855 #endif | 6030 #endif |
5856 char *file = alloca(strlen(filename) + 5); | 6031 char *file = alloca(strlen(filename) + 5); |
5857 unsigned long z, ret = 0; | 6032 unsigned long z, ret = 0; |
5858 | 6033 |
5859 if (!file) | 6034 if (!file) |
5860 return 0; | 6035 return 0; |
5861 | 6036 |
5862 strcpy(file, filename); | 6037 strcpy(file, filename); |
5863 | 6038 |
5864 /* check if we can read from this file (it exists and read permission) */ | 6039 /* check if we can read from this file (it exists and read permission) */ |
5865 if(access(file, 04) != 0) | 6040 if (access(file, 04) != 0) |
5866 { | 6041 { |
5867 /* Try with .xpm extention */ | 6042 /* Try with .xpm extention */ |
5868 strcat(file, ".xpm"); | 6043 strcat(file, ".xpm"); |
5869 if(access(file, 04) != 0) | 6044 if(access(file, 04) != 0) |
5870 return 0; | 6045 return 0; |
5871 } | 6046 } |
5872 | 6047 |
5873 DW_MUTEX_LOCK; | 6048 DW_MUTEX_LOCK; |
5874 /* Find a free entry in the array */ | 6049 /* Find a free entry in the array */ |
5875 for(z=0;z<_PixmapCount;z++) | 6050 for (z=0;z<_PixmapCount;z++) |
5876 { | 6051 { |
5877 if(!_PixmapArray[z].used) | 6052 if (!_PixmapArray[z].used) |
5878 { | 6053 { |
5879 ret = found = z; | 6054 ret = found = z; |
5880 break; | 6055 break; |
5881 } | 6056 } |
5882 } | 6057 } |
5883 | 6058 |
5884 /* If there are no free entries, expand the | 6059 /* If there are no free entries, expand the |
5885 * array. | 6060 * array. |
5886 */ | 6061 */ |
5887 if(found == -1) | 6062 if (found == -1) |
5888 { | 6063 { |
5889 DWPrivatePixmap *old = _PixmapArray; | 6064 DWPrivatePixmap *old = _PixmapArray; |
5890 | 6065 |
5891 ret = found = _PixmapCount; | 6066 ret = found = _PixmapCount; |
5892 _PixmapCount++; | 6067 _PixmapCount++; |
5893 | 6068 |
5894 _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount); | 6069 _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount); |
5895 | 6070 |
5896 if(found) | 6071 if (found) |
5897 memcpy(_PixmapArray, old, sizeof(DWPrivatePixmap) * found); | 6072 memcpy(_PixmapArray, old, sizeof(DWPrivatePixmap) * found); |
5898 if(old) | 6073 if (old) |
5899 free(old); | 6074 free(old); |
5900 _PixmapArray[found].used = 1; | 6075 _PixmapArray[found].used = 1; |
5901 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL; | 6076 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL; |
5902 } | 6077 } |
5903 | 6078 |
5904 #if GTK_MAJOR_VERSION > 1 | 6079 #if GTK_MAJOR_VERSION > 1 |
5905 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | 6080 pixbuf = gdk_pixbuf_new_from_file(file, NULL); |
5906 | 6081 if (pixbuf) |
5907 if(pixbuf) | 6082 { |
5908 { | 6083 _PixmapArray[found].pixbuf = pixbuf; |
5909 _PixmapArray[found].pixbuf = pixbuf; | 6084 _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf); |
5910 _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf); | 6085 _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf); |
5911 _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf); | 6086 |
5912 | 6087 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &_PixmapArray[found].pixmap, &_PixmapArray[found].mask, 1); |
5913 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &_PixmapArray[found].pixmap, &_PixmapArray[found].mask, 1); | 6088 } |
5914 } | |
5915 #elif defined(USE_IMLIB) | 6089 #elif defined(USE_IMLIB) |
5916 image = gdk_imlib_load_image(file); | 6090 image = gdk_imlib_load_image(file); |
5917 | 6091 if (image) |
5918 if(image) | 6092 { |
5919 { | 6093 _PixmapArray[found].width = image->rgb_width; |
5920 _PixmapArray[found].width = image->rgb_width; | 6094 _PixmapArray[found].height = image->rgb_height; |
5921 _PixmapArray[found].height = image->rgb_height; | 6095 |
5922 | 6096 gdk_imlib_render(image, image->rgb_width, image->rgb_height); |
5923 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | 6097 _PixmapArray[found].pixmap = gdk_imlib_copy_image(image); |
5924 _PixmapArray[found].pixmap = gdk_imlib_copy_image(image); | 6098 _PixmapArray[found].mask = gdk_imlib_copy_mask(image); |
5925 _PixmapArray[found].mask = gdk_imlib_copy_mask(image); | 6099 gdk_imlib_destroy_image(image); |
5926 gdk_imlib_destroy_image(image); | 6100 } |
5927 } | |
5928 #else | 6101 #else |
5929 if (last_window) | 6102 if (last_window) |
5930 _PixmapArray[found].pixmap = gdk_pixmap_create_from_xpm(last_window->window, &_PixmapArray[found].mask, &_colors[DW_CLR_PALEGRAY], file); | 6103 _PixmapArray[found].pixmap = gdk_pixmap_create_from_xpm(last_window->window, &_PixmapArray[found].mask, &_colors[DW_CLR_PALEGRAY], file); |
5931 #endif | 6104 #endif |
5932 DW_MUTEX_UNLOCK; | 6105 DW_MUTEX_UNLOCK; |
5933 if(!_PixmapArray[found].pixmap || !_PixmapArray[found].mask) | 6106 if (!_PixmapArray[found].pixmap || !_PixmapArray[found].mask) |
5934 { | 6107 { |
5935 _PixmapArray[found].used = 0; | 6108 _PixmapArray[found].used = 0; |
5936 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL; | 6109 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL; |
5937 return 0; | 6110 return 0; |
5938 } | 6111 } |
5939 return ret | (1 << 31); | 6112 return ret | (1 << 31); |
6113 } | |
6114 | |
6115 /* | |
6116 * Obtains an icon from data. | |
6117 * Parameters: | |
6118 * data: Source of data for image. | |
6119 * len: length of data | |
6120 */ | |
6121 unsigned long API dw_icon_load_from_data(char *data, int len) | |
6122 { | |
6123 int found = -1, _locked_by_me = FALSE; | |
6124 char *file; | |
6125 FILE *fp; | |
6126 #if GTK_MAJOR_VERSION > 1 | |
6127 GdkPixbuf *pixbuf; | |
6128 #elif defined(USE_IMLIB) | |
6129 GdkImlibImage *image; | |
6130 #endif | |
6131 unsigned long z, ret = 0; | |
6132 | |
6133 DW_MUTEX_LOCK; | |
6134 /* | |
6135 * A real hack; create a temporary file and write the contents | |
6136 * of the data to the file | |
6137 */ | |
6138 file = tmpnam( NULL ); | |
6139 fp = fopen( file, "wb" ); | |
6140 if ( fp ) | |
6141 { | |
6142 fwrite( data, len, 1, fp ); | |
6143 fclose( fp ); | |
6144 } | |
6145 else | |
6146 { | |
6147 DW_MUTEX_UNLOCK; | |
6148 return 0; | |
6149 } | |
6150 /* Find a free entry in the array */ | |
6151 for (z=0;z<_PixmapCount;z++) | |
6152 { | |
6153 if(!_PixmapArray[z].used) | |
6154 { | |
6155 ret = found = z; | |
6156 break; | |
6157 } | |
6158 } | |
6159 | |
6160 /* If there are no free entries, expand the | |
6161 * array. | |
6162 */ | |
6163 if (found == -1) | |
6164 { | |
6165 DWPrivatePixmap *old = _PixmapArray; | |
6166 | |
6167 ret = found = _PixmapCount; | |
6168 _PixmapCount++; | |
6169 | |
6170 _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount); | |
6171 | |
6172 if (found) | |
6173 memcpy(_PixmapArray, old, sizeof(DWPrivatePixmap) * found); | |
6174 if (old) | |
6175 free(old); | |
6176 _PixmapArray[found].used = 1; | |
6177 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL; | |
6178 } | |
6179 | |
6180 #if GTK_MAJOR_VERSION > 1 | |
6181 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | |
6182 if (pixbuf) | |
6183 { | |
6184 _PixmapArray[found].pixbuf = pixbuf; | |
6185 _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf); | |
6186 _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf); | |
6187 | |
6188 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &_PixmapArray[found].pixmap, &_PixmapArray[found].mask, 1); | |
6189 } | |
6190 #elif defined(USE_IMLIB) | |
6191 image = gdk_imlib_load_image(file); | |
6192 | |
6193 if (image) | |
6194 { | |
6195 _PixmapArray[found].width = image->rgb_width; | |
6196 _PixmapArray[found].height = image->rgb_height; | |
6197 | |
6198 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | |
6199 _PixmapArray[found].pixmap = gdk_imlib_copy_image(image); | |
6200 _PixmapArray[found].mask = gdk_imlib_copy_mask(image); | |
6201 gdk_imlib_destroy_image(image); | |
6202 } | |
6203 #else | |
6204 if (last_window) | |
6205 _PixmapArray[found].pixmap = gdk_pixmap_create_from_xpm_d(last_window->window, &_PixmapArray[found].mask, &_colors[DW_CLR_PALEGRAY], data); | |
6206 #endif | |
6207 /* remove our temporary file */ | |
6208 unlink (file ); | |
6209 DW_MUTEX_UNLOCK; | |
6210 if (!_PixmapArray[found].pixmap || !_PixmapArray[found].mask) | |
6211 { | |
6212 _PixmapArray[found].used = 0; | |
6213 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL; | |
6214 return 0; | |
6215 } | |
6216 return ret | (1 << 31); | |
5940 } | 6217 } |
5941 | 6218 |
5942 /* | 6219 /* |
5943 * Frees a loaded resource in OS/2 and Windows. | 6220 * Frees a loaded resource in OS/2 and Windows. |
5944 * Parameters: | 6221 * Parameters: |
7151 * Returns: | 7428 * Returns: |
7152 * A handle to a pixmap or NULL on failure. | 7429 * A handle to a pixmap or NULL on failure. |
7153 */ | 7430 */ |
7154 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename) | 7431 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename) |
7155 { | 7432 { |
7156 int _locked_by_me = FALSE; | 7433 int _locked_by_me = FALSE; |
7157 HPIXMAP pixmap; | 7434 HPIXMAP pixmap; |
7158 #ifndef USE_IMLIB | 7435 #ifndef USE_IMLIB |
7159 GdkBitmap *bitmap = NULL; | 7436 GdkBitmap *bitmap = NULL; |
7160 #endif | 7437 #endif |
7161 #if GTK_MAJOR_VERSION > 1 | 7438 #if GTK_MAJOR_VERSION > 1 |
7162 GdkPixbuf *pixbuf; | 7439 GdkPixbuf *pixbuf; |
7163 #elif defined(USE_IMLIB) | 7440 #elif defined(USE_IMLIB) |
7164 GdkImlibImage *image; | 7441 GdkImlibImage *image; |
7165 #endif | 7442 #endif |
7166 char *file = alloca(strlen(filename) + 5); | 7443 char *file = alloca(strlen(filename) + 5); |
7167 | 7444 |
7168 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 7445 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7169 return NULL; | 7446 return NULL; |
7170 | 7447 |
7171 strcpy(file, filename); | 7448 strcpy(file, filename); |
7172 | 7449 |
7173 /* check if we can read from this file (it exists and read permission) */ | 7450 /* check if we can read from this file (it exists and read permission) */ |
7174 if(access(file, 04) != 0) | 7451 if(access(file, 04) != 0) |
7175 { | 7452 { |
7176 /* Try with .xpm extention */ | 7453 /* Try with .xpm extention */ |
7177 strcat(file, ".xpm"); | 7454 strcat(file, ".xpm"); |
7178 if(access(file, 04) != 0) | 7455 if(access(file, 04) != 0) |
7179 { | 7456 { |
7180 free(pixmap); | 7457 free(pixmap); |
7181 return NULL; | 7458 return NULL; |
7182 } | 7459 } |
7183 } | 7460 } |
7184 | 7461 |
7185 DW_MUTEX_LOCK; | 7462 DW_MUTEX_LOCK; |
7186 #if GTK_MAJOR_VERSION > 1 | 7463 #if GTK_MAJOR_VERSION > 1 |
7187 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | 7464 pixbuf = gdk_pixbuf_new_from_file(file, NULL); |
7188 | 7465 pixmap->width = gdk_pixbuf_get_width(pixbuf); |
7189 pixmap->width = gdk_pixbuf_get_width(pixbuf); | 7466 pixmap->height = gdk_pixbuf_get_height(pixbuf); |
7190 pixmap->height = gdk_pixbuf_get_height(pixbuf); | 7467 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1); |
7191 | 7468 g_object_unref(pixbuf); |
7192 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1); | |
7193 g_object_unref(pixbuf); | |
7194 #elif defined(USE_IMLIB) | 7469 #elif defined(USE_IMLIB) |
7195 image = gdk_imlib_load_image(file); | 7470 image = gdk_imlib_load_image(file); |
7196 | 7471 |
7197 pixmap->width = image->rgb_width; | 7472 pixmap->width = image->rgb_width; |
7198 pixmap->height = image->rgb_height; | 7473 pixmap->height = image->rgb_height; |
7199 | 7474 |
7200 gdk_imlib_render(image, pixmap->width, pixmap->height); | 7475 gdk_imlib_render(image, pixmap->width, pixmap->height); |
7201 pixmap->pixmap = gdk_imlib_copy_image(image); | 7476 pixmap->pixmap = gdk_imlib_copy_image(image); |
7202 gdk_imlib_destroy_image(image); | 7477 gdk_imlib_destroy_image(image); |
7203 #else | 7478 #else |
7204 pixmap->pixmap = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); | 7479 pixmap->pixmap = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); |
7205 #endif | 7480 #endif |
7206 pixmap->handle = handle; | 7481 pixmap->handle = handle; |
7207 DW_MUTEX_UNLOCK; | 7482 DW_MUTEX_UNLOCK; |
7208 return pixmap; | 7483 return pixmap; |
7484 } | |
7485 | |
7486 /* | |
7487 * Creates a pixmap from data | |
7488 * Parameters: | |
7489 * handle: Window handle the pixmap is associated with. | |
7490 * data: Source of image data | |
7491 * DW pick the appropriate file extension. | |
7492 * (BMP on OS/2 or Windows, XPM on Unix) | |
7493 * Returns: | |
7494 * A handle to a pixmap or NULL on failure. | |
7495 */ | |
7496 HPIXMAP dw_pixmap_new_from_data(HWND handle, char *data, int len) | |
7497 { | |
7498 int _locked_by_me = FALSE; | |
7499 char *file; | |
7500 FILE *fp; | |
7501 HPIXMAP pixmap; | |
7502 #ifndef USE_IMLIB | |
7503 GdkBitmap *bitmap = NULL; | |
7504 #endif | |
7505 #if GTK_MAJOR_VERSION > 1 | |
7506 GdkPixbuf *pixbuf; | |
7507 #elif defined(USE_IMLIB) | |
7508 GdkImlibImage *image; | |
7509 #endif | |
7510 | |
7511 if (!data || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
7512 return NULL; | |
7513 | |
7514 DW_MUTEX_LOCK; | |
7515 /* | |
7516 * A real hack; create a temporary file and write the contents | |
7517 * of the data to the file | |
7518 */ | |
7519 file = tmpnam( NULL ); | |
7520 fp = fopen( file, "wb" ); | |
7521 if ( fp ) | |
7522 { | |
7523 fwrite( data, len, 1, fp ); | |
7524 fclose( fp ); | |
7525 } | |
7526 else | |
7527 { | |
7528 DW_MUTEX_UNLOCK; | |
7529 return 0; | |
7530 } | |
7531 #if GTK_MAJOR_VERSION > 1 | |
7532 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | |
7533 pixmap->width = gdk_pixbuf_get_width(pixbuf); | |
7534 pixmap->height = gdk_pixbuf_get_height(pixbuf); | |
7535 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1); | |
7536 g_object_unref(pixbuf); | |
7537 #elif defined(USE_IMLIB) | |
7538 image = gdk_imlib_load_image(file); | |
7539 | |
7540 pixmap->width = image->rgb_width; | |
7541 pixmap->height = image->rgb_height; | |
7542 | |
7543 gdk_imlib_render(image, pixmap->width, pixmap->height); | |
7544 pixmap->pixmap = gdk_imlib_copy_image(image); | |
7545 gdk_imlib_destroy_image(image); | |
7546 #else | |
7547 pixmap->pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], data); | |
7548 #endif | |
7549 /* remove our temporary file */ | |
7550 unlink (file ); | |
7551 pixmap->handle = handle; | |
7552 DW_MUTEX_UNLOCK; | |
7553 return pixmap; | |
7209 } | 7554 } |
7210 | 7555 |
7211 /* | 7556 /* |
7212 * Creates a pixmap from internal resource graphic specified by id. | 7557 * Creates a pixmap from internal resource graphic specified by id. |
7213 * Parameters: | 7558 * Parameters: |
8229 * width: New width in pixels. | 8574 * width: New width in pixels. |
8230 * height: New height in pixels. | 8575 * height: New height in pixels. |
8231 */ | 8576 */ |
8232 void dw_window_set_size(HWND handle, unsigned long width, unsigned long height) | 8577 void dw_window_set_size(HWND handle, unsigned long width, unsigned long height) |
8233 { | 8578 { |
8234 int _locked_by_me = FALSE; | 8579 int _locked_by_me = FALSE; |
8235 | 8580 long default_width = width - _dw_border_width; |
8236 if(!handle) | 8581 long default_height = height - _dw_border_height; |
8237 return; | 8582 |
8238 | 8583 if(!handle) |
8239 DW_MUTEX_LOCK; | 8584 return; |
8240 if(GTK_IS_WINDOW(handle)) | 8585 |
8241 { | 8586 DW_MUTEX_LOCK; |
8242 _size_allocate(GTK_WINDOW(handle)); | 8587 if(GTK_IS_WINDOW(handle)) |
8243 if(handle->window) | 8588 { |
8244 gdk_window_resize(handle->window, width - _dw_border_width, height - _dw_border_height); | 8589 if ( width == 0 ) |
8245 gtk_window_set_default_size(GTK_WINDOW(handle), width - _dw_border_width, height - _dw_border_height); | 8590 default_width = -1; |
8246 if(!gtk_object_get_data(GTK_OBJECT(handle), "_dw_size")) | 8591 if ( height == 0 ) |
8247 { | 8592 default_height = -1; |
8248 gtk_object_set_data(GTK_OBJECT(handle), "_dw_width", (gpointer)width - _dw_border_width); | 8593 _size_allocate(GTK_WINDOW(handle)); |
8249 gtk_object_set_data(GTK_OBJECT(handle), "_dw_height", (gpointer)height - _dw_border_height); | 8594 if(handle->window) |
8250 } | 8595 gdk_window_resize(handle->window, default_width , default_height ); |
8251 } | 8596 gtk_window_set_default_size(GTK_WINDOW(handle), default_width , default_height ); |
8252 else | 8597 if(!gtk_object_get_data(GTK_OBJECT(handle), "_dw_size")) |
8253 gtk_widget_set_usize(handle, width, height); | 8598 { |
8254 DW_MUTEX_UNLOCK; | 8599 gtk_object_set_data(GTK_OBJECT(handle), "_dw_width", (gpointer)default_width ); |
8600 gtk_object_set_data(GTK_OBJECT(handle), "_dw_height", (gpointer)default_height ); | |
8601 } | |
8602 } | |
8603 else | |
8604 gtk_widget_set_usize(handle, width, height); | |
8605 DW_MUTEX_UNLOCK; | |
8255 } | 8606 } |
8256 | 8607 |
8257 /* | 8608 /* |
8258 * Returns the width of the screen. | 8609 * Returns the width of the screen. |
8259 */ | 8610 */ |
8284 | 8635 |
8285 /* This should return the current color depth */ | 8636 /* This should return the current color depth */ |
8286 unsigned long dw_color_depth_get(void) | 8637 unsigned long dw_color_depth_get(void) |
8287 { | 8638 { |
8288 int retval; | 8639 int retval; |
8289 int _locked_by_me = FALSE; | 8640 GdkVisual *vis; |
8290 | 8641 int _locked_by_me = FALSE; |
8291 DW_MUTEX_UNLOCK; | 8642 |
8292 retval = gdk_visual_get_best_depth(); | 8643 DW_MUTEX_UNLOCK; |
8644 vis = gdk_visual_get_system(); | |
8645 retval = vis->depth; | |
8293 DW_MUTEX_UNLOCK; | 8646 DW_MUTEX_UNLOCK; |
8294 return retval; | 8647 return retval; |
8295 } | 8648 } |
8296 | 8649 |
8297 /* | 8650 /* |
8384 | 8737 |
8385 DW_MUTEX_LOCK; | 8738 DW_MUTEX_LOCK; |
8386 #if GTK_MAJOR_VERSION > 1 | 8739 #if GTK_MAJOR_VERSION > 1 |
8387 if((mdi = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_mdi")) && GTK_IS_MDI(mdi)) | 8740 if((mdi = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_mdi")) && GTK_IS_MDI(mdi)) |
8388 { | 8741 { |
8389 gint myx, myy; | 8742 gint myx=0, myy=0; |
8390 | 8743 |
8391 gtk_mdi_get_pos(GTK_MDI(mdi), handle, &myx, &myy); | 8744 gtk_mdi_get_pos(GTK_MDI(mdi), handle, &myx, &myy); |
8392 *x = myx; | 8745 *x = myx; |
8393 *y = myy; | 8746 *y = myy; |
8394 } | 8747 } |
9390 * Returns: | 9743 * Returns: |
9391 * A handle to a calendar window or NULL on failure. | 9744 * A handle to a calendar window or NULL on failure. |
9392 */ | 9745 */ |
9393 HWND dw_calendar_new(unsigned long id) | 9746 HWND dw_calendar_new(unsigned long id) |
9394 { | 9747 { |
9395 GtkCalendar *tmp; | 9748 GtkWidget *tmp; |
9396 int _locked_by_me = FALSE; | 9749 int _locked_by_me = FALSE; |
9397 GtkCalendarDisplayOptions flags; | 9750 GtkCalendarDisplayOptions flags; |
9751 time_t now; | |
9752 struct tm *tmdata; | |
9398 | 9753 |
9399 DW_MUTEX_LOCK; | 9754 DW_MUTEX_LOCK; |
9400 tmp = gtk_calendar_new(); | 9755 tmp = gtk_calendar_new(); |
9401 gtk_widget_show(tmp); | 9756 gtk_widget_show(tmp); |
9402 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", (gpointer)id); | 9757 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", (gpointer)id); |
9403 /* select today */ | 9758 /* select today */ |
9404 flags = GTK_CALENDAR_WEEK_START_MONDAY|GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES; | 9759 flags = GTK_CALENDAR_WEEK_START_MONDAY|GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES; |
9405 gtk_calendar_display_options(tmp,flags); | 9760 gtk_calendar_display_options( GTK_CALENDAR(tmp), flags ); |
9406 gtk_calendar_select_month(tmp,11,2005); | 9761 now = time( NULL ); |
9407 gtk_calendar_select_day(tmp, 12); | 9762 tmdata = localtime( & now ); |
9763 gtk_calendar_select_month( GTK_CALENDAR(tmp), tmdata->tm_mon, 1900+tmdata->tm_year ); | |
9764 gtk_calendar_select_day( GTK_CALENDAR(tmp), tmdata->tm_mday ); | |
9408 | 9765 |
9409 DW_MUTEX_UNLOCK; | 9766 DW_MUTEX_UNLOCK; |
9410 return tmp; | 9767 return tmp; |
9411 } | 9768 } |
9412 | 9769 |
9414 * Sets the current date of a calendar | 9771 * Sets the current date of a calendar |
9415 * Parameters: | 9772 * Parameters: |
9416 * handle: The handle to the calendar returned by dw_calendar_new(). | 9773 * handle: The handle to the calendar returned by dw_calendar_new(). |
9417 * year... | 9774 * year... |
9418 */ | 9775 */ |
9419 void dw_calendar_set_date(HWND handle, int year, int month, int day) | 9776 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) |
9420 { | 9777 { |
9421 int _locked_by_me = FALSE; | 9778 int _locked_by_me = FALSE; |
9422 | 9779 |
9423 DW_MUTEX_LOCK; | 9780 DW_MUTEX_LOCK; |
9424 if(GTK_IS_CALENDAR(handle)) | 9781 if(GTK_IS_CALENDAR(handle)) |
9433 /* | 9790 /* |
9434 * Gets the position of a splitbar (pecentage). | 9791 * Gets the position of a splitbar (pecentage). |
9435 * Parameters: | 9792 * Parameters: |
9436 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 9793 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
9437 */ | 9794 */ |
9438 void dw_calendar_get_date(HWND handle, int *year, int *month, int *day) | 9795 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) |
9439 { | 9796 { |
9440 int _locked_by_me = FALSE; | 9797 int _locked_by_me = FALSE; |
9441 | 9798 |
9442 DW_MUTEX_LOCK; | 9799 DW_MUTEX_LOCK; |
9443 if(GTK_IS_CALENDAR(handle)) | 9800 if(GTK_IS_CALENDAR(handle)) |
9444 { | 9801 { |
9445 gtk_calendar_get_date(GTK_CALENDAR(handle),year,month,day); | 9802 gtk_calendar_get_date(GTK_CALENDAR(handle),year,month,day); |
9803 *month = *month + 1; | |
9446 } | 9804 } |
9447 DW_MUTEX_UNLOCK; | 9805 DW_MUTEX_UNLOCK; |
9448 return; | 9806 return; |
9449 } | 9807 } |
9450 | 9808 |
10120 return dw_box_new(DW_HORZ, 0); | 10478 return dw_box_new(DW_HORZ, 0); |
10121 #endif | 10479 #endif |
10122 } | 10480 } |
10123 | 10481 |
10124 /* | 10482 /* |
10483 * Gets the contents of the default clipboard as text. | |
10484 * Parameters: | |
10485 * None. | |
10486 * Returns: | |
10487 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not | |
10488 * be converted to text. | |
10489 */ | |
10490 char *dw_clipboard_get_text() | |
10491 { | |
10492 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); | |
10493 | |
10494 DW_MUTEX_LOCK; | |
10495 if ( _clipboard_object[index] == NULL ) | |
10496 { | |
10497 _clipboard_object[index] = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); | |
10498 } | |
10499 if ( _clipboard_contents[index] != NULL ) | |
10500 { | |
10501 g_free( _clipboard_contents[index] ); | |
10502 } | |
10503 _clipboard_contents[index] = gtk_clipboard_wait_for_text( _clipboard_object[index] ); | |
10504 DW_MUTEX_UNLOCK; | |
10505 return (char *)_clipboard_contents[index]; | |
10506 } | |
10507 | |
10508 /* | |
10509 * Sets the contents of the default clipboard to the supplied text. | |
10510 * Parameters: | |
10511 * Text. | |
10512 */ | |
10513 void dw_clipboard_set_text( char *str, int len ) | |
10514 { | |
10515 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); | |
10516 | |
10517 DW_MUTEX_LOCK; | |
10518 if ( _clipboard_object[index] == NULL ) | |
10519 { | |
10520 _clipboard_object[index] = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); | |
10521 } | |
10522 gtk_clipboard_set_text( _clipboard_object[index], str, len ); | |
10523 DW_MUTEX_UNLOCK; | |
10524 } | |
10525 | |
10526 /* | |
10125 * Returns a pointer to a static buffer which containes the | 10527 * Returns a pointer to a static buffer which containes the |
10126 * current user directory. Or the root directory (C:\ on | 10528 * current user directory. Or the root directory (C:\ on |
10127 * OS/2 and Windows). | 10529 * OS/2 and Windows). |
10128 */ | 10530 */ |
10129 char *dw_user_dir(void) | 10531 char *dw_user_dir(void) |
10283 HWND thiswindow = window; | 10685 HWND thiswindow = window; |
10284 int sigid, _locked_by_me = FALSE; | 10686 int sigid, _locked_by_me = FALSE; |
10285 gint cid; | 10687 gint cid; |
10286 | 10688 |
10287 DW_MUTEX_LOCK; | 10689 DW_MUTEX_LOCK; |
10690 /* | |
10691 * If the window we are setting the signal on is a scrolled window we need to get | |
10692 * the "real" widget type. thiswindow is the "real" widget type | |
10693 */ | |
10288 if(GTK_IS_SCROLLED_WINDOW(thiswindow)) | 10694 if(GTK_IS_SCROLLED_WINDOW(thiswindow)) |
10289 { | 10695 { |
10290 thiswindow = (HWND)gtk_object_get_user_data(GTK_OBJECT(window)); | 10696 thiswindow = (HWND)gtk_object_get_user_data(GTK_OBJECT(window)); |
10291 } | 10697 } |
10292 | 10698 |
10302 } | 10708 } |
10303 #if GTK_MAJOR_VERSION > 1 | 10709 #if GTK_MAJOR_VERSION > 1 |
10304 else if(GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0) | 10710 else if(GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0) |
10305 { | 10711 { |
10306 thisfunc = _findsigfunc("tree-context"); | 10712 thisfunc = _findsigfunc("tree-context"); |
10713 | |
10307 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc); | 10714 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc); |
10308 cid = gtk_signal_connect(GTK_OBJECT(thiswindow), "button_press_event", GTK_SIGNAL_FUNC(thisfunc), (gpointer)sigid); | 10715 cid = gtk_signal_connect(GTK_OBJECT(thiswindow), "button_press_event", GTK_SIGNAL_FUNC(thisfunc), (gpointer)sigid); |
10309 _set_signal_handler_id(thiswindow, sigid, cid); | 10716 _set_signal_handler_id(thiswindow, sigid, cid); |
10717 | |
10718 #if 0 | |
10310 sigid = _set_signal_handler(window, window, sigfunc, data, thisfunc); | 10719 sigid = _set_signal_handler(window, window, sigfunc, data, thisfunc); |
10311 cid = gtk_signal_connect(GTK_OBJECT(window), "button_press_event", GTK_SIGNAL_FUNC(thisfunc), (gpointer)sigid); | 10720 cid = gtk_signal_connect(GTK_OBJECT(window), "button_press_event", GTK_SIGNAL_FUNC(thisfunc), (gpointer)sigid); |
10312 _set_signal_handler_id(window, sigid, cid); | 10721 _set_signal_handler_id(window, sigid, cid); |
10722 #endif | |
10723 | |
10313 DW_MUTEX_UNLOCK; | 10724 DW_MUTEX_UNLOCK; |
10314 return; | 10725 return; |
10315 } | 10726 } |
10316 else if(GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_SELECT) == 0) | 10727 else if(GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_SELECT) == 0) |
10317 { | 10728 { |