r870: Merge 2.1:
[cinelerra_cv.git] / guicast / bcresources.C
blob0fa2f9f04ff822ce31c0de50a14e9ee66cce51aa
1 #include "bcdisplayinfo.h"
2 #include "bcipc.h"
3 #include "bclistbox.inc"
4 #include "bcresources.h"
5 #include "bcsignals.h"
6 #include "bcsynchronous.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 #include "images/file_film_png.h"
30 #include "images/file_folder_png.h"
31 #include "images/file_sound_png.h"
32 #include "images/file_unknown_png.h"
33 #include "images/file_column_png.h"
34 VFrame* BC_Resources::type_to_icon[] = 
36         new VFrame(file_folder_png),
37         new VFrame(file_unknown_png),
38         new VFrame(file_film_png),
39         new VFrame(file_sound_png),
40         new VFrame(file_column_png)
43 char* BC_Resources::small_font = N_("-*-helvetica-medium-r-normal-*-10-*");
44 char* BC_Resources::small_font2 = N_("-*-helvetica-medium-r-normal-*-11-*");
45 char* BC_Resources::medium_font = N_("-*-helvetica-bold-r-normal-*-14-*");
46 char* BC_Resources::medium_font2 = N_("-*-helvetica-bold-r-normal-*-14-*");
47 char* BC_Resources::large_font = N_("-*-helvetica-bold-r-normal-*-18-*");
48 char* BC_Resources::large_font2 = N_("-*-helvetica-bold-r-normal-*-20-*");
50 char* BC_Resources::small_fontset = "6x12,*";
51 char* BC_Resources::medium_fontset = "7x14,*";
52 char* BC_Resources::large_fontset = "8x16,*";
54 char* BC_Resources::small_font_xft = N_("-*-luxi sans-*-r-*-*-12-*-*-*-*-*-*-*");
55 char* BC_Resources::small_font_xft2 = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
56 char* BC_Resources::medium_font_xft = N_("-*-luxi sans-*-r-*-*-16-*-*-*-*-*-*-*");
57 char* BC_Resources::medium_font_xft2 = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
58 char* BC_Resources::large_font_xft = N_("-*-luxi sans-bold-r-*-*-20-*-*-*-*-*-*-*");
59 char* BC_Resources::large_font_xft2 = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
61 suffix_to_type_t BC_Resources::suffix_to_type[] = 
63         { "m2v", ICON_FILM },
64         { "mov", ICON_FILM },
65         { "mp2", ICON_SOUND },
66         { "mp3", ICON_SOUND },
67         { "mpg", ICON_FILM },
68         { "vob", ICON_FILM },
69         { "wav", ICON_SOUND }
72 BC_Signals* BC_Resources::signal_handler = 0;
75 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
77 //      char string[1024];
78 //      XGetErrorText(event->display, event->error_code, string, 1024);
79 //      printf("BC_Resources::x_error_handler: error_code=%d opcode=%d,%d %s\n", 
80 //              event->error_code, 
81 //              event->request_code,
82 //              event->minor_code,
83 //              string);
86         BC_Resources::error = 1;
87 // This bug only happens in 32 bit mode.
88         if(sizeof(long) == 4)
89                 BC_WindowBase::get_resources()->use_xft = 0;
90         return 0;
95 BC_Resources::BC_Resources()
97         synchronous = 0;
98         display_info = new BC_DisplayInfo("", 0);
99         id_lock = new Mutex("BC_Resources::id_lock");
100         create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
101         id = 0;
103         for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
104                 filebox_history[i][0] = 0;
106 #ifdef HAVE_XFT
107         XftInitFtLibrary();
108 #endif
110         use_xvideo = 1;
113 #include "images/bar_png.h"
114         static VFrame* default_bar = new VFrame(bar_png);
115         bar_data = default_bar;
119 #include "images/cancel_up_png.h"
120 #include "images/cancel_hi_png.h"
121 #include "images/cancel_dn_png.h"
122         static VFrame* default_cancel_images[] = 
123         {
124                 new VFrame(cancel_up_png),
125                 new VFrame(cancel_hi_png),
126                 new VFrame(cancel_dn_png)
127         };
129 #include "images/ok_up_png.h"
130 #include "images/ok_hi_png.h"
131 #include "images/ok_dn_png.h"
132         static VFrame* default_ok_images[] = 
133         {
134                 new VFrame(ok_up_png),
135                 new VFrame(ok_hi_png),
136                 new VFrame(ok_dn_png)
137         };
139 #include "images/usethis_up_png.h"
140 #include "images/usethis_uphi_png.h"
141 #include "images/usethis_dn_png.h"
142         static VFrame* default_usethis_images[] = 
143         {
144                 new VFrame(usethis_up_png),
145                 new VFrame(usethis_uphi_png),
146                 new VFrame(usethis_dn_png)
147         };
150 #include "images/checkbox_checked_png.h"
151 #include "images/checkbox_dn_png.h"
152 #include "images/checkbox_checkedhi_png.h"
153 #include "images/checkbox_up_png.h"
154 #include "images/checkbox_hi_png.h"
155         static VFrame* default_checkbox_images[] =  
156         {
157                 new VFrame(checkbox_up_png),
158                 new VFrame(checkbox_hi_png),
159                 new VFrame(checkbox_checked_png),
160                 new VFrame(checkbox_dn_png),
161                 new VFrame(checkbox_checkedhi_png)
162         };
164 #include "images/radial_checked_png.h"
165 #include "images/radial_dn_png.h"
166 #include "images/radial_checkedhi_png.h"
167 #include "images/radial_up_png.h"
168 #include "images/radial_hi_png.h"
169         static VFrame* default_radial_images[] =  
170         {
171                 new VFrame(radial_up_png),
172                 new VFrame(radial_hi_png),
173                 new VFrame(radial_checked_png),
174                 new VFrame(radial_dn_png),
175                 new VFrame(radial_checkedhi_png)
176         };
178         static VFrame* default_label_images[] =  
179         {
180                 new VFrame(radial_up_png),
181                 new VFrame(radial_hi_png),
182                 new VFrame(radial_checked_png),
183                 new VFrame(radial_dn_png),
184                 new VFrame(radial_checkedhi_png)
185         };
188 #include "images/file_text_up_png.h"
189 #include "images/file_text_hi_png.h"
190 #include "images/file_text_dn_png.h"
191 #include "images/file_icons_up_png.h"
192 #include "images/file_icons_hi_png.h"
193 #include "images/file_icons_dn_png.h"
194 #include "images/file_newfolder_up_png.h"
195 #include "images/file_newfolder_hi_png.h"
196 #include "images/file_newfolder_dn_png.h"
197 #include "images/file_updir_up_png.h"
198 #include "images/file_updir_hi_png.h"
199 #include "images/file_updir_dn_png.h"
200 #include "images/file_delete_up_png.h"
201 #include "images/file_delete_hi_png.h"
202 #include "images/file_delete_dn_png.h"
203 #include "images/file_reload_up_png.h"
204 #include "images/file_reload_hi_png.h"
205 #include "images/file_reload_dn_png.h"
206         static VFrame* default_filebox_text_images[] = 
207         {
208                 new VFrame(file_text_up_png),
209                 new VFrame(file_text_hi_png),
210                 new VFrame(file_text_dn_png)
211         };
213         static VFrame* default_filebox_icons_images[] = 
214         {
215                 new VFrame(file_icons_up_png),
216                 new VFrame(file_icons_hi_png),
217                 new VFrame(file_icons_dn_png)
218         };
220         static VFrame* default_filebox_updir_images[] =  
221         {
222                 new VFrame(file_updir_up_png),
223                 new VFrame(file_updir_hi_png),
224                 new VFrame(file_updir_dn_png)
225         };
227         static VFrame* default_filebox_newfolder_images[] = 
228         {
229                 new VFrame(file_newfolder_up_png),
230                 new VFrame(file_newfolder_hi_png),
231                 new VFrame(file_newfolder_dn_png)
232         };
234         static VFrame* default_filebox_delete_images[] = 
235         {
236                 new VFrame(file_delete_up_png),
237                 new VFrame(file_delete_hi_png),
238                 new VFrame(file_delete_dn_png)
239         };
241         static VFrame* default_filebox_reload_images[] =
242         {
243                 new VFrame(file_reload_up_png),
244                 new VFrame(file_reload_hi_png),
245                 new VFrame(file_reload_dn_png)
246         };
248 #include "images/listbox_button_dn_png.h"
249 #include "images/listbox_button_hi_png.h"
250 #include "images/listbox_button_up_png.h"
251 #include "images/listbox_button_disabled_png.h"\r
252         static VFrame* default_listbox_button[] = 
253         {
254                 new VFrame(listbox_button_up_png),
255                 new VFrame(listbox_button_hi_png),
256                 new VFrame(listbox_button_dn_png),
257                 new VFrame(listbox_button_disabled_png)
258         };
259         listbox_button = default_listbox_button;
261 #include "images/list_bg_png.h"
262         static VFrame* default_listbox_bg = new VFrame(list_bg_png);
263         listbox_bg = default_listbox_bg;
265 #include "images/listbox_expandchecked_png.h"
266 #include "images/listbox_expandcheckedhi_png.h"
267 #include "images/listbox_expanddn_png.h"
268 #include "images/listbox_expandup_png.h"
269 #include "images/listbox_expanduphi_png.h"
270         static VFrame* default_listbox_expand[] = 
271         {
272                 new VFrame(listbox_expandup_png),
273                 new VFrame(listbox_expanduphi_png),
274                 new VFrame(listbox_expandchecked_png),
275                 new VFrame(listbox_expanddn_png),
276                 new VFrame(listbox_expandcheckedhi_png),
277         };
278         listbox_expand = default_listbox_expand;
280 #include "images/listbox_columnup_png.h"
281 #include "images/listbox_columnhi_png.h"
282 #include "images/listbox_columndn_png.h"
283         static VFrame* default_listbox_column[] = 
284         {
285                 new VFrame(listbox_columnup_png),
286                 new VFrame(listbox_columnhi_png),
287                 new VFrame(listbox_columndn_png)
288         };
289         listbox_column = default_listbox_column;
292 #include "images/listbox_up_png.h"
293 #include "images/listbox_dn_png.h"
294         listbox_up = new VFrame(listbox_up_png);
295         listbox_dn = new VFrame(listbox_dn_png);
296         listbox_title_margin = 0;
297         listbox_title_color = BLACK;
298         listbox_title_hotspot = 5;
299         
300         listbox_border1 = DKGREY;
301         listbox_border2_hi = RED;
302         listbox_border2 = BLACK;
303         listbox_border3_hi = RED;
304         listbox_border3 = MEGREY;
305         listbox_border4 = WHITE;
306         listbox_selected = BLUE;
307         listbox_highlighted = LTGREY;
308         listbox_inactive = WHITE;
309         listbox_text = BLACK;
311 #include "images/pot_hi_png.h"
312 #include "images/pot_up_png.h"
313 #include "images/pot_dn_png.h"
314         static VFrame *default_pot_images[] = 
315         {
316                 new VFrame(pot_up_png),
317                 new VFrame(pot_hi_png),
318                 new VFrame(pot_dn_png)
319         };
321 #include "images/progress_up_png.h"
322 #include "images/progress_hi_png.h"
323         static VFrame* default_progress_images[] = 
324         {
325                 new VFrame(progress_up_png),
326                 new VFrame(progress_hi_png)
327         };
329         pan_data = 0;
330         pan_text_color = YELLOW;
332 #include "images/7seg_small/0_png.h"
333 #include "images/7seg_small/1_png.h"
334 #include "images/7seg_small/2_png.h"
335 #include "images/7seg_small/3_png.h"
336 #include "images/7seg_small/4_png.h"
337 #include "images/7seg_small/5_png.h"
338 #include "images/7seg_small/6_png.h"
339 #include "images/7seg_small/7_png.h"
340 #include "images/7seg_small/8_png.h"
341 #include "images/7seg_small/9_png.h"
342 #include "images/7seg_small/colon_png.h"
343 #include "images/7seg_small/period_png.h"
344 #include "images/7seg_small/a_png.h"
345 #include "images/7seg_small/b_png.h"
346 #include "images/7seg_small/c_png.h"
347 #include "images/7seg_small/d_png.h"
348 #include "images/7seg_small/e_png.h"
349 #include "images/7seg_small/f_png.h"
350 #include "images/7seg_small/space_png.h"
351 #include "images/7seg_small/dash_png.h"
352         static VFrame* default_medium_7segment[] = 
353         {
354                 new VFrame(_0_png),
355                 new VFrame(_1_png),
356                 new VFrame(_2_png),
357                 new VFrame(_3_png),
358                 new VFrame(_4_png),
359                 new VFrame(_5_png),
360                 new VFrame(_6_png),
361                 new VFrame(_7_png),
362                 new VFrame(_8_png),
363                 new VFrame(_9_png),
364                 new VFrame(colon_png),
365                 new VFrame(period_png),
366                 new VFrame(a_png),
367                 new VFrame(b_png),
368                 new VFrame(c_png),
369                 new VFrame(d_png),
370                 new VFrame(e_png),
371                 new VFrame(f_png),
372                 new VFrame(space_png),
373                 new VFrame(dash_png)
374         };
376         generic_button_margin = 15;
377         draw_clock_background=1;
379         use_shm = -1;
381 // Initialize
382         bg_color = ORANGE;
383         bg_shadow1 = DKGREY;
384         bg_shadow2 = BLACK;
385         bg_light1 = WHITE;
386         bg_light2 = bg_color;
388         default_text_color = BLACK;
389         disabled_text_color = MEGREY;
391         button_light = WHITE;           // bright corner
392         button_highlighted = 0xffe000;  // face when highlighted
393         button_down = MDGREY;         // face when down
394         button_up = 0xffc000;           // face when up
395         button_shadow = DKGREY;       // dark corner
396         button_uphighlighted = RED;   // upper side when highlighted
398         tumble_data = 0;
399         tumble_duration = 150;
401         ok_images = default_ok_images;
402         cancel_images = default_cancel_images;
403         usethis_button_images = default_usethis_images;
404         filebox_descend_images = default_ok_images;
406         menu_light = LTCYAN;
407         menu_highlighted = LTBLUE;
408         menu_down = MDCYAN;
409         menu_up = MECYAN;
410         menu_shadow = DKCYAN;
411         menu_popup_bg = 0;
412         menu_title_bg = 0;
413         menu_item_bg = 0;
414         menu_bar_bg = 0;
415         menu_title_bg = 0;
416         popupmenu_images = 0;
417         popupmenu_margin = 10;
418         popupmenu_triangle_margin = 10;
420         min_menu_w = 0;
421         menu_title_text = BLACK;
422         popup_title_text = BLACK;
423         menu_item_text = BLACK;
424         menu_highlighted_fontcolor = BLACK;
425         progress_text = BLACK;
429         text_default = BLACK;
430         highlight_inverse = WHITE ^ BLUE;
431         text_background = WHITE;
432         text_background_hi = LTYELLOW;
433         text_background_noborder_hi = LTGREY;
434         text_background_noborder = -1;
435         text_border1 = DKGREY;
436         text_border2 = BLACK;
437         text_border2_hi = RED;
438         text_border3 = MEGREY;
439         text_border3_hi = LTPINK;
440         text_border4 = WHITE;
441         text_highlight = BLUE;
442         text_inactive_highlight = MEGREY;
444         toggle_highlight_bg = 0;
445         toggle_text_margin = 0;
447 // Delays must all be different for repeaters
448         double_click = 300;
449         blink_rate = 250;
450         scroll_repeat = 150;
451         tooltip_delay = 1000;
452         tooltip_bg_color = YELLOW;
453         tooltips_enabled = 1;
455         filebox_margin = 110;
456         dirbox_margin = 90;
457         filebox_mode = LISTBOX_TEXT;
458         sprintf(filebox_filter, "*");
459         filebox_w = 640;
460         filebox_h = 480;
461         filebox_columntype[0] = FILEBOX_NAME;
462         filebox_columntype[1] = FILEBOX_SIZE;
463         filebox_columntype[2] = FILEBOX_DATE;
464         filebox_columntype[3] = FILEBOX_EXTENSION;
465         filebox_columnwidth[0] = 200;
466         filebox_columnwidth[1] = 100;
467         filebox_columnwidth[2] = 100;
468         filebox_columnwidth[3] = 100;
469         dirbox_columntype[0] = FILEBOX_NAME;
470         dirbox_columntype[1] = FILEBOX_DATE;
471         dirbox_columnwidth[0] = 200;
472         dirbox_columnwidth[1] = 100;
474         filebox_text_images = default_filebox_text_images;
475         filebox_icons_images = default_filebox_icons_images;
476         filebox_updir_images = default_filebox_updir_images;
477         filebox_newfolder_images = default_filebox_newfolder_images;
478         filebox_delete_images = default_filebox_delete_images;
479         filebox_reload_images = default_filebox_reload_images;
480         directory_color = BLUE;
481         file_color = BLACK;
483         filebox_sortcolumn = 0;
484         filebox_sortorder = BC_ListBox::SORT_ASCENDING;
485         dirbox_sortcolumn = 0;
486         dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
489         pot_images = default_pot_images;
490         pot_offset = 2;
491         pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
492         pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
493         pot_r = pot_x1;
494         pot_needle_color = BLACK;
496         progress_images = default_progress_images;
498         xmeter_images = 0;
499         ymeter_images = 0;
500         meter_font = SMALLFONT_3D;
501         meter_font_color = RED;
502         meter_title_w = 20;
503         meter_3d = 1;
504         medium_7segment = default_medium_7segment;
506         audiovideo_color = RED;
508         use_fontset = 0;
510 // Xft has priority over font set
511 #ifdef HAVE_XFT
512 // But Xft dies in 32 bit mode after some amount of drawing.
513         use_xft = 1;
514 #else
515         use_xft = 0;
516 #endif
519         drag_radius = 10;
520         recursive_resizing = 1;
522         
525 BC_Resources::~BC_Resources()
529 int BC_Resources::initialize_display(BC_WindowBase *window)
531 // Set up IPC cleanup handlers
532 //      bc_init_ipc();
534 // Test for shm.  Must come before yuv test
535         init_shm(window);
536         return 0;
540 int BC_Resources::init_shm(BC_WindowBase *window)
542         use_shm = 1;
543         XSetErrorHandler(BC_Resources::x_error_handler);
545         if(!XShmQueryExtension(window->display)) use_shm = 0;
546         else
547         {
548                 XShmSegmentInfo test_shm;
549                 XImage *test_image;
550                 unsigned char *data;
551                 test_image = XShmCreateImage(window->display, window->vis, window->default_depth,
552                 ZPixmap, (char*)NULL, &test_shm, 5, 5);
554                 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0777 ));
555                 data = (unsigned char *)shmat(test_shm.shmid, NULL, 0);
556         shmctl(test_shm.shmid, IPC_RMID, 0);
557                 BC_Resources::error = 0;
558                 XShmAttach(window->display, &test_shm);
559         XSync(window->display, False);
560                 if(BC_Resources::error) use_shm = 0;
561                 XDestroyImage(test_image);
562                 shmdt(test_shm.shmaddr);
563         }
564 //      XSetErrorHandler(0);
565         return 0;
571 BC_Synchronous* BC_Resources::get_synchronous()
573         return synchronous;
576 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
578         this->synchronous = synchronous;
587 int BC_Resources::get_top_border()
589         return display_info->get_top_border();
592 int BC_Resources::get_left_border()
594         return display_info->get_left_border();
597 int BC_Resources::get_right_border()
599         return display_info->get_right_border();
602 int BC_Resources::get_bottom_border()
604         return display_info->get_bottom_border();
608 int BC_Resources::get_bg_color() { return bg_color; }
610 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
612 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
614 int BC_Resources::get_bg_light1() { return bg_light1; }
616 int BC_Resources::get_bg_light2() { return bg_light2; }
619 int BC_Resources::get_id()
621         id_lock->lock("BC_Resources::get_id");
622         int result = id++;
623         id_lock->unlock();
624         return result;
628 void BC_Resources::set_signals(BC_Signals *signal_handler)
630         BC_Resources::signal_handler = signal_handler;
633 BC_Signals* BC_Resources::get_signals()
635         return BC_Resources::signal_handler;