r854: Merge 2.1:
[cinelerra_cv/ct.git] / guicast / bcresources.C
blobea75c2086373fe25b21f70e302fa3688e3691a34
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_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
55 char* BC_Resources::medium_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
56 char* BC_Resources::large_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
58 suffix_to_type_t BC_Resources::suffix_to_type[] = 
60         { "m2v", ICON_FILM },
61         { "mov", ICON_FILM },
62         { "mp2", ICON_SOUND },
63         { "mp3", ICON_SOUND },
64         { "mpg", ICON_FILM },
65         { "vob", ICON_FILM },
66         { "wav", ICON_SOUND }
69 BC_Signals* BC_Resources::signal_handler = 0;
72 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
74         char string[1024];
75         XGetErrorText(event->display, event->error_code, string, 1024);
76 //      printf("BC_Resources::x_error_handler: %s\n", string);
77         BC_Resources::error = 1;
78         return 0;
83 BC_Resources::BC_Resources()
85         synchronous = 0;
86         display_info = new BC_DisplayInfo("", 0);
87         id_lock = new Mutex("BC_Resources::id_lock");
88         id = 0;
90         for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
91                 filebox_history[i][0] = 0;
93 #ifdef HAVE_XFT
94         XftInitFtLibrary();
95 #endif
97         use_xvideo = 1;
100 #include "images/bar_png.h"
101         static VFrame* default_bar = new VFrame(bar_png);
102         bar_data = default_bar;
106 #include "images/cancel_up_png.h"
107 #include "images/cancel_hi_png.h"
108 #include "images/cancel_dn_png.h"
109         static VFrame* default_cancel_images[] = 
110         {
111                 new VFrame(cancel_up_png),
112                 new VFrame(cancel_hi_png),
113                 new VFrame(cancel_dn_png)
114         };
116 #include "images/ok_up_png.h"
117 #include "images/ok_hi_png.h"
118 #include "images/ok_dn_png.h"
119         static VFrame* default_ok_images[] = 
120         {
121                 new VFrame(ok_up_png),
122                 new VFrame(ok_hi_png),
123                 new VFrame(ok_dn_png)
124         };
126 #include "images/usethis_up_png.h"
127 #include "images/usethis_uphi_png.h"
128 #include "images/usethis_dn_png.h"
129         static VFrame* default_usethis_images[] = 
130         {
131                 new VFrame(usethis_up_png),
132                 new VFrame(usethis_uphi_png),
133                 new VFrame(usethis_dn_png)
134         };
137 #include "images/checkbox_checked_png.h"
138 #include "images/checkbox_dn_png.h"
139 #include "images/checkbox_checkedhi_png.h"
140 #include "images/checkbox_up_png.h"
141 #include "images/checkbox_hi_png.h"
142         static VFrame* default_checkbox_images[] =  
143         {
144                 new VFrame(checkbox_up_png),
145                 new VFrame(checkbox_hi_png),
146                 new VFrame(checkbox_checked_png),
147                 new VFrame(checkbox_dn_png),
148                 new VFrame(checkbox_checkedhi_png)
149         };
151 #include "images/radial_checked_png.h"
152 #include "images/radial_dn_png.h"
153 #include "images/radial_checkedhi_png.h"
154 #include "images/radial_up_png.h"
155 #include "images/radial_hi_png.h"
156         static VFrame* default_radial_images[] =  
157         {
158                 new VFrame(radial_up_png),
159                 new VFrame(radial_hi_png),
160                 new VFrame(radial_checked_png),
161                 new VFrame(radial_dn_png),
162                 new VFrame(radial_checkedhi_png)
163         };
165         static VFrame* default_label_images[] =  
166         {
167                 new VFrame(radial_up_png),
168                 new VFrame(radial_hi_png),
169                 new VFrame(radial_checked_png),
170                 new VFrame(radial_dn_png),
171                 new VFrame(radial_checkedhi_png)
172         };
175 #include "images/file_text_up_png.h"
176 #include "images/file_text_hi_png.h"
177 #include "images/file_text_dn_png.h"
178 #include "images/file_icons_up_png.h"
179 #include "images/file_icons_hi_png.h"
180 #include "images/file_icons_dn_png.h"
181 #include "images/file_newfolder_up_png.h"
182 #include "images/file_newfolder_hi_png.h"
183 #include "images/file_newfolder_dn_png.h"
184 #include "images/file_updir_up_png.h"
185 #include "images/file_updir_hi_png.h"
186 #include "images/file_updir_dn_png.h"
187 #include "images/file_delete_up_png.h"
188 #include "images/file_delete_hi_png.h"
189 #include "images/file_delete_dn_png.h"
190 #include "images/file_reload_up_png.h"
191 #include "images/file_reload_hi_png.h"
192 #include "images/file_reload_dn_png.h"
193         static VFrame* default_filebox_text_images[] = 
194         {
195                 new VFrame(file_text_up_png),
196                 new VFrame(file_text_hi_png),
197                 new VFrame(file_text_dn_png)
198         };
200         static VFrame* default_filebox_icons_images[] = 
201         {
202                 new VFrame(file_icons_up_png),
203                 new VFrame(file_icons_hi_png),
204                 new VFrame(file_icons_dn_png)
205         };
207         static VFrame* default_filebox_updir_images[] =  
208         {
209                 new VFrame(file_updir_up_png),
210                 new VFrame(file_updir_hi_png),
211                 new VFrame(file_updir_dn_png)
212         };
214         static VFrame* default_filebox_newfolder_images[] = 
215         {
216                 new VFrame(file_newfolder_up_png),
217                 new VFrame(file_newfolder_hi_png),
218                 new VFrame(file_newfolder_dn_png)
219         };
221         static VFrame* default_filebox_delete_images[] = 
222         {
223                 new VFrame(file_delete_up_png),
224                 new VFrame(file_delete_hi_png),
225                 new VFrame(file_delete_dn_png)
226         };
228         static VFrame* default_filebox_reload_images[] =
229         {
230                 new VFrame(file_reload_up_png),
231                 new VFrame(file_reload_hi_png),
232                 new VFrame(file_reload_dn_png)
233         };
235 #include "images/listbox_button_dn_png.h"
236 #include "images/listbox_button_hi_png.h"
237 #include "images/listbox_button_up_png.h"
238 #include "images/listbox_button_disabled_png.h"\r
239         static VFrame* default_listbox_button[] = 
240         {
241                 new VFrame(listbox_button_up_png),
242                 new VFrame(listbox_button_hi_png),
243                 new VFrame(listbox_button_dn_png),
244                 new VFrame(listbox_button_disabled_png)
245         };
246         listbox_button = default_listbox_button;
248 #include "images/list_bg_png.h"
249         static VFrame* default_listbox_bg = new VFrame(list_bg_png);
250         listbox_bg = default_listbox_bg;
252 #include "images/listbox_expandchecked_png.h"
253 #include "images/listbox_expandcheckedhi_png.h"
254 #include "images/listbox_expanddn_png.h"
255 #include "images/listbox_expandup_png.h"
256 #include "images/listbox_expanduphi_png.h"
257         static VFrame* default_listbox_expand[] = 
258         {
259                 new VFrame(listbox_expandup_png),
260                 new VFrame(listbox_expanduphi_png),
261                 new VFrame(listbox_expandchecked_png),
262                 new VFrame(listbox_expanddn_png),
263                 new VFrame(listbox_expandcheckedhi_png),
264         };
265         listbox_expand = default_listbox_expand;
267 #include "images/listbox_columnup_png.h"
268 #include "images/listbox_columnhi_png.h"
269 #include "images/listbox_columndn_png.h"
270         static VFrame* default_listbox_column[] = 
271         {
272                 new VFrame(listbox_columnup_png),
273                 new VFrame(listbox_columnhi_png),
274                 new VFrame(listbox_columndn_png)
275         };
276         listbox_column = default_listbox_column;
279 #include "images/listbox_up_png.h"
280 #include "images/listbox_dn_png.h"
281         listbox_up = new VFrame(listbox_up_png);
282         listbox_dn = new VFrame(listbox_dn_png);
283         listbox_title_margin = 0;
284         listbox_title_color = BLACK;
285         listbox_title_hotspot = 5;
286         
287         listbox_border1 = DKGREY;
288         listbox_border2_hi = RED;
289         listbox_border2 = BLACK;
290         listbox_border3_hi = RED;
291         listbox_border3 = MEGREY;
292         listbox_border4 = WHITE;
293         listbox_selected = BLUE;
294         listbox_highlighted = LTGREY;
295         listbox_inactive = WHITE;
296         listbox_text = BLACK;
298 #include "images/pot_hi_png.h"
299 #include "images/pot_up_png.h"
300 #include "images/pot_dn_png.h"
301         static VFrame *default_pot_images[] = 
302         {
303                 new VFrame(pot_up_png),
304                 new VFrame(pot_hi_png),
305                 new VFrame(pot_dn_png)
306         };
308  #include "images/progress_up_png.h"
309  #include "images/progress_hi_png.h"
310         static VFrame* default_progress_images[] = 
311         {
312                 new VFrame(progress_up_png),
313                 new VFrame(progress_hi_png)
314         };
316         pan_data = 0;
317         pan_text_color = YELLOW;
319 #include "images/7seg_small/0_png.h"
320 #include "images/7seg_small/1_png.h"
321 #include "images/7seg_small/2_png.h"
322 #include "images/7seg_small/3_png.h"
323 #include "images/7seg_small/4_png.h"
324 #include "images/7seg_small/5_png.h"
325 #include "images/7seg_small/6_png.h"
326 #include "images/7seg_small/7_png.h"
327 #include "images/7seg_small/8_png.h"
328 #include "images/7seg_small/9_png.h"
329 #include "images/7seg_small/colon_png.h"
330 #include "images/7seg_small/period_png.h"
331 #include "images/7seg_small/a_png.h"
332 #include "images/7seg_small/b_png.h"
333 #include "images/7seg_small/c_png.h"
334 #include "images/7seg_small/d_png.h"
335 #include "images/7seg_small/e_png.h"
336 #include "images/7seg_small/f_png.h"
337 #include "images/7seg_small/space_png.h"
338 #include "images/7seg_small/dash_png.h"
339         static VFrame* default_medium_7segment[] = 
340         {
341                 new VFrame(_0_png),
342                 new VFrame(_1_png),
343                 new VFrame(_2_png),
344                 new VFrame(_3_png),
345                 new VFrame(_4_png),
346                 new VFrame(_5_png),
347                 new VFrame(_6_png),
348                 new VFrame(_7_png),
349                 new VFrame(_8_png),
350                 new VFrame(_9_png),
351                 new VFrame(colon_png),
352                 new VFrame(period_png),
353                 new VFrame(a_png),
354                 new VFrame(b_png),
355                 new VFrame(c_png),
356                 new VFrame(d_png),
357                 new VFrame(e_png),
358                 new VFrame(f_png),
359                 new VFrame(space_png),
360                 new VFrame(dash_png)
361         };
363         generic_button_margin = 15;
364         draw_clock_background=1;
366         use_shm = -1;
368 // Initialize
369         bg_color = ORANGE;
370         bg_shadow1 = DKGREY;
371         bg_shadow2 = BLACK;
372         bg_light1 = WHITE;
373         bg_light2 = bg_color;
375         default_text_color = BLACK;
376         disabled_text_color = MEGREY;
378         button_light = WHITE;           // bright corner
379         button_highlighted = 0xffe000;  // face when highlighted
380         button_down = MDGREY;         // face when down
381         button_up = 0xffc000;           // face when up
382         button_shadow = DKGREY;       // dark corner
383         button_uphighlighted = RED;   // upper side when highlighted
385         tumble_data = 0;
386         tumble_duration = 150;
388         ok_images = default_ok_images;
389         cancel_images = default_cancel_images;
390         usethis_button_images = default_usethis_images;
391         filebox_descend_images = default_ok_images;
393         menu_light = LTCYAN;
394         menu_highlighted = LTBLUE;
395         menu_down = MDCYAN;
396         menu_up = MECYAN;
397         menu_shadow = DKCYAN;
398         menu_popup_bg = 0;
399         menu_title_bg = 0;
400         menu_item_bg = 0;
401         menu_bar_bg = 0;
402         menu_title_bg = 0;
403         popupmenu_images = 0;
404         popupmenu_margin = 10;
405         popupmenu_triangle_margin = 10;
407         min_menu_w = 0;
408         menu_title_text = BLACK;
409         popup_title_text = BLACK;
410         menu_item_text = BLACK;
411         menu_highlighted_fontcolor = BLACK;
412         progress_text = BLACK;
416         text_default = BLACK;
417         highlight_inverse = WHITE ^ BLUE;
418         text_background = WHITE;
419         text_background_hi = LTYELLOW;
420         text_background_noborder_hi = LTGREY;
421         text_background_noborder = -1;
422         text_border1 = DKGREY;
423         text_border2 = BLACK;
424         text_border2_hi = RED;
425         text_border3 = MEGREY;
426         text_border3_hi = LTPINK;
427         text_border4 = WHITE;
428         text_highlight = BLUE;
429         text_inactive_highlight = MEGREY;
431         toggle_highlight_bg = 0;
432         toggle_text_margin = 0;
434 // Delays must all be different for repeaters
435         double_click = 300;
436         blink_rate = 250;
437         scroll_repeat = 150;
438         tooltip_delay = 1000;
439         tooltip_bg_color = YELLOW;
440         tooltips_enabled = 1;
442         filebox_margin = 110;
443         dirbox_margin = 90;
444         filebox_mode = LISTBOX_TEXT;
445         sprintf(filebox_filter, "*");
446         filebox_w = 640;
447         filebox_h = 480;
448         filebox_columntype[0] = FILEBOX_NAME;
449         filebox_columntype[1] = FILEBOX_SIZE;
450         filebox_columntype[2] = FILEBOX_DATE;
451         filebox_columntype[3] = FILEBOX_EXTENSION;
452         filebox_columnwidth[0] = 200;
453         filebox_columnwidth[1] = 100;
454         filebox_columnwidth[2] = 100;
455         filebox_columnwidth[3] = 100;
456         dirbox_columntype[0] = FILEBOX_NAME;
457         dirbox_columntype[1] = FILEBOX_DATE;
458         dirbox_columnwidth[0] = 200;
459         dirbox_columnwidth[1] = 100;
461         filebox_text_images = default_filebox_text_images;
462         filebox_icons_images = default_filebox_icons_images;
463         filebox_updir_images = default_filebox_updir_images;
464         filebox_newfolder_images = default_filebox_newfolder_images;
465         filebox_delete_images = default_filebox_delete_images;
466         filebox_reload_images = default_filebox_reload_images;
467         directory_color = BLUE;
468         file_color = BLACK;
470         filebox_sortcolumn = 0;
471         filebox_sortorder = BC_ListBox::SORT_ASCENDING;
472         dirbox_sortcolumn = 0;
473         dirbox_sortorder = BC_ListBox::SORT_ASCENDING;
475         pot_images = default_pot_images;
476         pot_offset = 2;
477         pot_x1 = pot_images[0]->get_w() / 2 - pot_offset;
478         pot_y1 = pot_images[0]->get_h() / 2 - pot_offset;
479         pot_r = pot_x1;
480         pot_needle_color = BLACK;
482         progress_images = default_progress_images;
484         xmeter_images = 0;
485         ymeter_images = 0;
486         meter_font = SMALLFONT_3D;
487         meter_font_color = RED;
488         meter_title_w = 20;
489         meter_3d = 1;
490         medium_7segment = default_medium_7segment;
492         audiovideo_color = RED;
494         use_fontset = 0;
496 // Xft has priority over font set
497 #ifdef HAVE_XFT
498         use_xft = 1;
499 #else
500         use_xft = 0;
501 #endif
504         drag_radius = 10;
505         recursive_resizing = 1;
507         
510 BC_Resources::~BC_Resources()
514 int BC_Resources::initialize_display(BC_WindowBase *window)
516 // Set up IPC cleanup handlers
517         bc_init_ipc();
519 // Test for shm.  Must come before yuv test
520         init_shm(window);
521         return 0;
525 int BC_Resources::init_shm(BC_WindowBase *window)
527         use_shm = 1;
528         XSetErrorHandler(BC_Resources::x_error_handler);
530         if(!XShmQueryExtension(window->display)) use_shm = 0;
531         else
532         {
533                 XShmSegmentInfo test_shm;
534                 XImage *test_image;
535                 unsigned char *data;
536                 test_image = XShmCreateImage(window->display, window->vis, window->default_depth,
537                 ZPixmap, (char*)NULL, &test_shm, 5, 5);
539                 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0777 ));
540                 data = (unsigned char *)shmat(test_shm.shmid, NULL, 0);
541         shmctl(test_shm.shmid, IPC_RMID, 0);
542                 BC_Resources::error = 0;
543                 XShmAttach(window->display, &test_shm);
544         XSync(window->display, False);
545                 if(BC_Resources::error) use_shm = 0;
546                 XDestroyImage(test_image);
547                 shmdt(test_shm.shmaddr);
548         }
549 //      XSetErrorHandler(0);
550         return 0;
556 BC_Synchronous* BC_Resources::get_synchronous()
558         return synchronous;
561 void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
563         this->synchronous = synchronous;
572 int BC_Resources::get_top_border()
574         return display_info->get_top_border();
577 int BC_Resources::get_left_border()
579         return display_info->get_left_border();
582 int BC_Resources::get_right_border()
584         return display_info->get_right_border();
587 int BC_Resources::get_bottom_border()
589         return display_info->get_bottom_border();
593 int BC_Resources::get_bg_color() { return bg_color; }
595 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
597 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
599 int BC_Resources::get_bg_light1() { return bg_light1; }
601 int BC_Resources::get_bg_light2() { return bg_light2; }
604 int BC_Resources::get_id()
606         id_lock->lock("BC_Resources::get_id");
607         int result = id++;
608         id_lock->unlock();
609         return result;