r419: various fixes, memory allocations, etc.
[cinelerra_cv/mob.git] / guicast / bcresources.C
blob59957c2c6d36c4b7207e8a15cbfc7dce19dd1f0b
1 #include "bcdisplayinfo.h"
2 #include "bcipc.h"
3 #include "bclistbox.inc"
4 #include "bcresources.h"
5 #include "bcsignals.h"
6 #include "bctheme.h"
7 #include "bcwindowbase.h"
8 #include "colors.h"
9 #include "colormodels.h"
10 #include "fonts.h"
11 #include "language.h"
12 #include "vframe.h"
14 #include <string.h>
15 #include <sys/ipc.h>
16 #include <sys/shm.h>
17 #include <X11/extensions/XShm.h>
18 #include <unistd.h>
24 int BC_Resources::error = 0;
26 VFrame* BC_Resources::bg_image = 0;
27 VFrame* BC_Resources::menu_bg = 0;
29 char* BC_Resources::small_font = N_("-*-helvetica-medium-r-normal-*-10-*");
30 char* BC_Resources::small_font2 = N_("-*-helvetica-medium-r-normal-*-11-*");
31 char* BC_Resources::medium_font = N_("-*-helvetica-bold-r-normal-*-14-*");
32 char* BC_Resources::medium_font2 = N_("-*-helvetica-bold-r-normal-*-14-*");
33 char* BC_Resources::large_font = N_("-*-helvetica-bold-r-normal-*-18-*");
34 char* BC_Resources::large_font2 = N_("-*-helvetica-bold-r-normal-*-20-*");
36 char* BC_Resources::small_fontset = "6x12,*";
37 char* BC_Resources::medium_fontset = "7x14,*";
38 char* BC_Resources::large_fontset = "8x16,*";
40 char* BC_Resources::small_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
41 char* BC_Resources::medium_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
42 char* BC_Resources::large_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
44 suffix_to_type_t BC_Resources::suffix_to_type[] = 
46         { "m2v", ICON_FILM },
47         { "mov", ICON_FILM },
48         { "mp2", ICON_SOUND },
49         { "mp3", ICON_SOUND },
50         { "mpg", ICON_FILM },
51         { "vob", ICON_FILM },
52         { "wav", ICON_SOUND }
55 BC_Signals* BC_Resources::signal_handler = 0;
57 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
59         char string[1024];
60         XGetErrorText(event->display, event->error_code, string, 1024);
61 //      printf("BC_Resources::x_error_handler: %s\n", string);
62         BC_Resources::error = 1;
63         return 0;
68 BC_Resources::BC_Resources()
70         display_info = new BC_DisplayInfo("", 0);
72 #ifdef HAVE_XFT
73         XftInitFtLibrary();
74 #endif
76         use_xvideo = 1;
78 static VFrame* type_to_icon = 0;
80 #include "images/cancel_up_png.h"
81 #include "images/cancel_hi_png.h"
82 #include "images/cancel_dn_png.h"
83         static VFrame* default_cancel_images[] = 
84         {
85                 new VFrame(cancel_up_png),
86                 new VFrame(cancel_hi_png),
87                 new VFrame(cancel_dn_png)
88         };
90 #include "images/ok_up_png.h"
91 #include "images/ok_hi_png.h"
92 #include "images/ok_dn_png.h"
93         static VFrame* default_ok_images[] = 
94         {
95                 new VFrame(ok_up_png),
96                 new VFrame(ok_hi_png),
97                 new VFrame(ok_dn_png)
98         };
100 #include "images/usethis_up_png.h"
101 #include "images/usethis_uphi_png.h"
102 #include "images/usethis_dn_png.h"
103         static VFrame* default_usethis_images[] = 
104         {
105                 new VFrame(usethis_up_png),
106                 new VFrame(usethis_uphi_png),
107                 new VFrame(usethis_dn_png)
108         };
110         static VFrame* default_checkbox_images = 0;
111         static VFrame* default_radial_images = 0;
112         static VFrame* default_label_images =  0;
114         listbox_button = 0;
115         listbox_bg = 0;
117         static VFrame* default_filebox_text_images = 0; 
118         static VFrame* default_filebox_icons_images = 0;
119         static VFrame* default_filebox_updir_images = 0;
120         static VFrame* default_filebox_newfolder_images = 0; 
122         listbox_expand = 0;
123         listbox_column = 0;
124         listbox_up =0;
125         listbox_dn = 0;
127         horizontal_slider_data = 0;
128         vertical_slider_data = 0;
131 #include "images/pot_hi_png.h"
132 #include "images/pot_up_png.h"
133 #include "images/pot_dn_png.h"
134         static VFrame *default_pot_images[] = 
135         {
136                 new VFrame(pot_up_png),
137                 new VFrame(pot_hi_png),
138                 new VFrame(pot_dn_png)
139         };
141  #include "images/progress_up_png.h"
142  #include "images/progress_hi_png.h"
143         static VFrame* default_progress_images[] = 
144         {
145                 new VFrame(progress_up_png),
146                 new VFrame(progress_hi_png)
147         };
149         pan_data = 0;
150         pan_text_color = YELLOW;
152 #include "images/7seg_small/0_png.h"
153 #include "images/7seg_small/1_png.h"
154 #include "images/7seg_small/2_png.h"
155 #include "images/7seg_small/3_png.h"
156 #include "images/7seg_small/4_png.h"
157 #include "images/7seg_small/5_png.h"
158 #include "images/7seg_small/6_png.h"
159 #include "images/7seg_small/7_png.h"
160 #include "images/7seg_small/8_png.h"
161 #include "images/7seg_small/9_png.h"
162 #include "images/7seg_small/colon_png.h"
163 #include "images/7seg_small/period_png.h"
164 #include "images/7seg_small/a_png.h"
165 #include "images/7seg_small/b_png.h"
166 #include "images/7seg_small/c_png.h"
167 #include "images/7seg_small/d_png.h"
168 #include "images/7seg_small/e_png.h"
169 #include "images/7seg_small/f_png.h"
170 #include "images/7seg_small/space_png.h"
171 #include "images/7seg_small/dash_png.h"
172         static VFrame* default_medium_7segment[] = 
173         {
174                 new VFrame(_0_png),
175                 new VFrame(_1_png),
176                 new VFrame(_2_png),
177                 new VFrame(_3_png),
178                 new VFrame(_4_png),
179                 new VFrame(_5_png),
180                 new VFrame(_6_png),
181                 new VFrame(_7_png),
182                 new VFrame(_8_png),
183                 new VFrame(_9_png),
184                 new VFrame(colon_png),
185                 new VFrame(period_png),
186                 new VFrame(a_png),
187                 new VFrame(b_png),
188                 new VFrame(c_png),
189                 new VFrame(d_png),
190                 new VFrame(e_png),
191                 new VFrame(f_png),
192                 new VFrame(space_png),
193                 new VFrame(dash_png)
194         };
196         draw_clock_background=1;
198         use_shm = -1;
200 // Initialize
201         bg_color = ORANGE;
202         bg_shadow1 = DKGREY;
203         bg_shadow2 = BLACK;
204         bg_light1 = WHITE;
205         bg_light2 = bg_color;
207         default_text_color = BLACK;
208         disabled_text_color = MEGREY;
210         button_light = WHITE;           // bright corner
211         button_highlighted = 0xffe000;  // face when highlighted
212         button_down = MDGREY;         // face when down
213         button_up = 0xffc000;           // face when up
214         button_shadow = DKGREY;       // dark corner
215         button_uphighlighted = RED;   // upper side when highlighted
217         tumble_data = 0;
218         tumble_duration = 150;
220         ok_images = default_ok_images;
221         cancel_images = default_cancel_images;
222         usethis_button_images = default_usethis_images;
224         menu_light = LTCYAN;
225         menu_highlighted = LTBLUE;
226         menu_down = MDCYAN;
227         menu_up = MECYAN;
228         menu_shadow = DKCYAN;
230         popup_title_text = BLACK;
231         menu_item_text = BLACK;
232         menu_highlighted_fontcolor = BLACK;
233         progress_text = BLACK;
235         text_default = BLACK;
236         text_background = WHITE;
237         highlight_inverse = WHITE ^ BLUE;
238         text_highlight = BLUE;
240 // Delays must all be different for repeaters
241         double_click = 300;
242         blink_rate = 250;
243         scroll_repeat = 150;
244         tooltip_delay = 1000;
245         tooltip_bg_color = YELLOW;
246         tooltips_enabled = 1;
248         filebox_mode = LISTBOX_TEXT;
249         sprintf(filebox_filter, "*");
250         filebox_w = 640;
251         filebox_h = 480;
252         filebox_columntype[0] = FILEBOX_NAME;
253         filebox_columntype[1] = FILEBOX_SIZE;
254         filebox_columntype[2] = FILEBOX_DATE;
255         filebox_columnwidth[0] = 200;
256         filebox_columnwidth[1] = 100;
257         filebox_columnwidth[2] = 100;
259         filebox_text_images = 0;
260         filebox_icons_images = 0;
261         filebox_updir_images = 0;
262         filebox_newfolder_images = 0;
264         filebox_sortcolumn = 0;
265         filebox_sortorder = BC_ListBox::SORT_ASCENDING;
267         pot_images = default_pot_images;
268         pot_x1 = pot_images[0]->get_w() / 2 - 2;
269         pot_y1 = pot_images[0]->get_h() / 2 - 2;;
270         pot_r = pot_x1;
271         pot_needle_color = BLACK;
273         progress_images = default_progress_images;
275         xmeter_images = 0;
276         ymeter_images = 0;
277         meter_font = SMALLFONT_3D;
278         meter_font_color = RED;
279         meter_title_w = 20;
280         meter_3d = 1;
281         medium_7segment = default_medium_7segment;
283         listboxitemselected_color = BLUE;
285         audiovideo_color = RED;
287         use_fontset = 0;
289 // Xft has priority over font set
290 #ifdef HAVE_XFT
291         use_xft = 1;
292 #else
293         use_xft = 0;
294 #endif
297         drag_radius = 10;
298         recursive_resizing = 1;
300         
303 BC_Resources::~BC_Resources()
307 int BC_Resources::initialize_display(BC_WindowBase *window)
309 // Set up IPC cleanup handlers
310         bc_init_ipc();
312 // Test for shm.  Must come before yuv test
313         init_shm(window);
314         return 0;
318 int BC_Resources::init_shm(BC_WindowBase *window)
320         use_shm = 1;
321         XSetErrorHandler(BC_Resources::x_error_handler);
323         if(!XShmQueryExtension(window->display)) use_shm = 0;
324         else
325         {
326                 XShmSegmentInfo test_shm;
327                 XImage *test_image;
328                 unsigned char *data;
329                 test_image = XShmCreateImage(window->display, window->vis, window->default_depth,
330                 ZPixmap, (char*)NULL, &test_shm, 5, 5);
332                 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0777 ));
333                 data = (unsigned char *)shmat(test_shm.shmid, NULL, 0);
334         shmctl(test_shm.shmid, IPC_RMID, 0);
335                 BC_Resources::error = 0;
336                 XShmAttach(window->display, &test_shm);
337         XSync(window->display, False);
338                 if(BC_Resources::error) use_shm = 0;
339                 XDestroyImage(test_image);
340                 shmdt(test_shm.shmaddr);
341         }
342 //      XSetErrorHandler(0);
343         return 0;
346 int BC_Resources::get_top_border()
348         return display_info->get_top_border();
351 int BC_Resources::get_left_border()
353         return display_info->get_left_border();
356 int BC_Resources::get_right_border()
358         return display_info->get_right_border();
361 int BC_Resources::get_bottom_border()
363         return display_info->get_bottom_border();
367 int BC_Resources::get_bg_color() { return bg_color; }
369 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
371 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
373 int BC_Resources::get_bg_light1() { return bg_light1; }
375 int BC_Resources::get_bg_light2() { return bg_light2; }