4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 // Global objects for the user interface
32 #include "bcdisplayinfo.inc"
33 #include "bcfilebox.h"
34 #include "bcfontentry.inc"
35 #include "bcresources.inc"
36 #include "bcsignals.inc"
37 #include "bcsynchronous.inc"
38 #include "bcwindowbase.inc"
58 BC_Resources(); // The window parameter is used to get the display information initially
61 friend class BC_WindowBase;
63 int initialize_display(BC_WindowBase *window);
67 // Get ID for filebox history. Persistent.
69 int get_bg_color(); // window backgrounds
70 int get_bg_shadow1(); // border for windows
74 // Get synchronous thread for OpenGL
75 BC_Synchronous* get_synchronous();
76 // Called by user after synchronous thread is created.
77 void set_synchronous(BC_Synchronous *synchronous);
79 static void set_signals(BC_Signals *signal_handler);
80 static BC_Signals* get_signals();
83 // These values should be changed before the first window is created.
85 int bg_color; // window backgrounds
91 int bg_shadow1; // border for windows
95 int default_text_color;
96 int disabled_text_color;
101 int button_highlighted;
105 int button_uphighlighted;
108 int highlight_inverse;
110 // 3D box colors for menus
112 int menu_highlighted;
116 // If these are nonzero, they override the menu backgrounds.
117 VFrame *menu_popup_bg;
118 VFrame **menu_title_bg;
120 VFrame **popupmenu_images;
122 // Minimum menu width
124 // Menu bar text color
126 // color of popup title
127 int popup_title_text;
128 // Right and left margin for text not including triangle space.
129 int popupmenu_margin;
130 // post popup on button release event
132 // Right margin for triangle not including text margin.
133 int popupmenu_triangle_margin;
134 // color for item text
136 // Override the menu item background if nonzero.
137 VFrame **menu_item_bg;
140 // color for progress text
142 // set focus on enter
143 int grab_input_focus;
145 int menu_highlighted_fontcolor;
147 // ms for double click
149 // ms for cursor flash
151 // ms for scroll repeats
155 int tooltip_bg_color;
156 int tooltips_enabled;
157 int textbox_focus_policy;
159 int audiovideo_color;
161 // default color of text
163 // background color of textboxes and list boxes
168 int text_background_disarmed;
169 int text_background_hi;
170 int text_background_noborder_hi;
175 int text_inactive_highlight;
176 int text_selected_highlight;
178 int text_background_noborder;
180 // Optional background for highlighted text in toggle
181 VFrame *toggle_highlight_bg;
182 int toggle_text_margin;
185 static VFrame *bg_image;
186 static VFrame *menu_bg;
190 VFrame **cancel_images;
191 VFrame **filebox_text_images;
192 VFrame **filebox_icons_images;
193 VFrame **filebox_updir_images;
194 VFrame **filebox_newfolder_images;
195 VFrame **filebox_rename_images;
196 VFrame **filebox_descend_images;
197 VFrame **filebox_delete_images;
198 VFrame **filebox_reload_images;
199 VFrame **filebox_szfmt_images;
201 // Generic button images
202 VFrame **generic_button_images;
203 // Generic button text margin
204 int generic_button_margin;
205 VFrame **usethis_button_images;
208 VFrame **checkbox_images;
209 VFrame **radial_images;
210 VFrame **label_images;
214 VFrame **tumble_data;
222 VFrame **listbox_button;
223 VFrame **listbox_expand;
224 VFrame **listbox_column;
227 int listbox_title_overlap;
228 // Margin for titles in addition to listbox border
229 int listbox_title_margin;
230 int listbox_title_color;
231 int listbox_title_hotspot;
233 int listbox_border2_hi;
235 int listbox_border3_hi;
238 // Selected row color
239 int listbox_selected;
240 // Highlighted row color
241 int listbox_highlighted;
242 // Inactive row color
243 int listbox_inactive;
244 // Default text color
249 VFrame **horizontal_slider_data;
250 VFrame **vertical_slider_data;
251 VFrame **hscroll_data;
253 VFrame **vscroll_data;
254 // Minimum pixels in handle
255 int scroll_minhandle;
263 int pot_x1, pot_y1, pot_r;
264 // Amount of deflection of pot when down
266 int pot_needle_color;
269 VFrame **xmeter_images, **ymeter_images;
271 int meter_font_color;
276 VFrame **progress_images;
278 // Motion required to start a drag
282 static suffix_to_type_t suffix_to_type[];
283 VFrame **type_to_icon;
284 // Display mode for fileboxes
286 // Filter currently used in filebox
287 char filebox_filter[BCTEXTLEN];
288 // History of submitted files
289 filebox_history_t filebox_history[FILEBOX_HISTORY_SIZE];
293 // Column types for filebox
294 int filebox_columntype[FILEBOX_COLUMNS];
295 int filebox_columnwidth[FILEBOX_COLUMNS];
296 int filebox_sortcolumn;
297 int filebox_sortorder;
298 // Column types for filebox in directory mode
299 int dirbox_columntype[FILEBOX_COLUMNS];
300 int dirbox_columnwidth[FILEBOX_COLUMNS];
301 int dirbox_sortcolumn;
302 int dirbox_sortorder;
303 // Bottom margin between list and window
308 double font_scale, icon_scale;
310 static const char *small_font, *small_font2;
311 static const char *medium_font, *medium_font2;
312 static const char *large_font, *large_font2;
313 static const char *big_font, *big_font2;
314 static const char *clock_font, *clock_font2;
316 static const char *small_fontset;
317 static const char *medium_fontset;
318 static const char *large_fontset;
319 static const char *big_fontset;
320 static const char *clock_fontset;
322 static const char *small_font_xft, *small_b_font_xft;
323 static const char *medium_font_xft, *medium_b_font_xft;
324 static const char *large_font_xft, *large_b_font_xft;
325 static const char *big_font_xft, *big_b_font_xft;
326 static const char *clock_font_xft, *clock_b_font_xft;
328 // Backup of fonts in case the first choices don't exist
329 static const char *small_font_xft2;
330 static const char *medium_font_xft2;
331 static const char *large_font_xft2;
332 static const char *big_font_xft2;
333 static const char *clock_font_xft2;
335 void init_font_defs(double scale);
336 void finit_font_defs();
338 VFrame **medium_7segment;
341 int draw_clock_background;
346 // Current locale uses utf8
347 static int locale_utf8;
348 // Byte order is little_endian
349 static int little_endian;
350 // Language and region
351 static char language[LEN_LANG];
352 static char region[LEN_LANG];
353 static char encoding[LEN_ENCOD];
354 static const char *wide_encoding;
355 static ArrayList<BC_FontEntry*> *fontlist;
356 static int init_fontconfig(const char *search_path);
357 static BC_FontEntry *find_fontentry(const char *displayname, int style,
358 int mask, int preferred_style = 0);
359 static void encode_to_utf8(char *buffer, int buflen);
360 static FcPattern* find_similar_font(FT_ULong char_code, FcPattern *oldfont);
361 static size_t encode(const char *from_enc, const char *to_enc,
362 char *input, int input_length, char *output, int output_length);
363 static int find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface);
364 static int font_debug;
365 static void dump_fonts(FILE *fp = stdout);
366 static void dump_font_entry(FILE *fp, const char *cp, BC_FontEntry *ep);
368 static void new_vframes(int n, VFrame *vframes[], ...);
369 static void del_vframes(VFrame *vframes[], int n);
371 static VFrame *default_type_to_icon[6];
372 static VFrame *default_bar;
373 static VFrame *default_cancel_images[3];
374 static VFrame *default_ok_images[3];
375 static VFrame *default_usethis_images[3];
377 static VFrame *default_checkbox_images[5];
378 static VFrame *default_radial_images[5];
379 static VFrame *default_label_images[5];
381 static VFrame *default_menuitem_data[3];
382 static VFrame *default_menubar_data[3];
383 static VFrame *default_menu_popup_bg;
384 static VFrame *default_menu_bar_bg;
385 static VFrame *default_check_image;
386 static VFrame *default_filebox_text_images[3];
387 static VFrame *default_filebox_icons_images[3];
388 static VFrame *default_filebox_updir_images[3];
389 static VFrame *default_filebox_newfolder_images[3];
390 static VFrame *default_filebox_rename_images[3];
391 static VFrame *default_filebox_delete_images[3];
392 static VFrame *default_filebox_reload_images[3];
393 static VFrame *default_filebox_szfmt_images[12];
394 static VFrame *default_listbox_button[4];
395 static VFrame *default_listbox_bg;
396 static VFrame *default_listbox_expand[5];
397 static VFrame *default_listbox_column[3];
398 static VFrame *default_listbox_up;
399 static VFrame *default_listbox_dn;
400 static VFrame *default_pot_images[3];
401 static VFrame *default_progress_images[2];
402 static VFrame *default_medium_7segment[20];
404 // Make VFrame use shm
406 int use_vframe_shm() { return use_shm && vframe_shm ? 1 : 0; }
408 static int get_machine_cpus();
409 static int machine_cpus;
410 // Available display extensions
414 // If the program uses recursive_resizing
415 int recursive_resizing;
416 // Work around X server bugs
418 // Seems to help if only 1 window is created at a time.
419 Mutex *create_window_lock;
420 // size raw, 1000, 1024, thou
421 int filebox_size_format;
423 // Test for availability of shared memory pixmaps
424 void init_shm(BC_WindowBase *window);
425 void init_sizes(BC_WindowBase *window);
426 static int x_error_handler(Display *display, XErrorEvent *event);
427 VFrame **list_pointers[100];
428 int list_lengths[100];
430 static const char *fc_properties[];
434 static Mutex fontconfig_lock;
436 // Pointer to signal handler class to run after ipc
437 static BC_Signals *signal_handler;
438 BC_Synchronous *synchronous;