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 // Right margin for triangle not including text margin.
131 int popupmenu_triangle_margin;
132 // color for item text
134 // Override the menu item background if nonzero.
135 VFrame **menu_item_bg;
138 // color for progress text
142 int menu_highlighted_fontcolor;
144 // ms for double click
146 // ms for cursor flash
148 // ms for scroll repeats
152 int tooltip_bg_color;
153 int tooltips_enabled;
155 int audiovideo_color;
157 // default color of text
159 // background color of textboxes and list boxes
164 int text_background_hi;
165 int text_background_noborder_hi;
170 int text_inactive_highlight;
172 int text_background_noborder;
174 // Optional background for highlighted text in toggle
175 VFrame *toggle_highlight_bg;
176 int toggle_text_margin;
179 static VFrame *bg_image;
180 static VFrame *menu_bg;
184 VFrame **cancel_images;
185 VFrame **filebox_text_images;
186 VFrame **filebox_icons_images;
187 VFrame **filebox_updir_images;
188 VFrame **filebox_newfolder_images;
189 VFrame **filebox_rename_images;
190 VFrame **filebox_descend_images;
191 VFrame **filebox_delete_images;
192 VFrame **filebox_reload_images;
194 // Generic button images
195 VFrame **generic_button_images;
196 // Generic button text margin
197 int generic_button_margin;
198 VFrame **usethis_button_images;
201 VFrame **checkbox_images;
202 VFrame **radial_images;
203 VFrame **label_images;
207 VFrame **tumble_data;
215 VFrame **listbox_button;
216 VFrame **listbox_expand;
217 VFrame **listbox_column;
220 int listbox_title_overlap;
221 // Margin for titles in addition to listbox border
222 int listbox_title_margin;
223 int listbox_title_color;
224 int listbox_title_hotspot;
226 int listbox_border2_hi;
228 int listbox_border3_hi;
231 // Selected row color
232 int listbox_selected;
233 // Highlighted row color
234 int listbox_highlighted;
235 // Inactive row color
236 int listbox_inactive;
237 // Default text color
242 VFrame **horizontal_slider_data;
243 VFrame **vertical_slider_data;
244 VFrame **hscroll_data;
246 VFrame **vscroll_data;
247 // Minimum pixels in handle
248 int scroll_minhandle;
256 int pot_x1, pot_y1, pot_r;
257 // Amount of deflection of pot when down
259 int pot_needle_color;
262 VFrame **xmeter_images, **ymeter_images;
264 int meter_font_color;
269 VFrame **progress_images;
271 // Motion required to start a drag
275 static suffix_to_type_t suffix_to_type[TOTAL_SUFFIXES];
276 VFrame **type_to_icon;
277 // Display mode for fileboxes
279 // Filter currently used in filebox
280 char filebox_filter[BCTEXTLEN];
281 // History of submitted files
282 filebox_history_t filebox_history[FILEBOX_HISTORY_SIZE];
286 // Column types for filebox
287 int filebox_columntype[FILEBOX_COLUMNS];
288 int filebox_columnwidth[FILEBOX_COLUMNS];
289 int filebox_sortcolumn;
290 int filebox_sortorder;
291 // Column types for filebox in directory mode
292 int dirbox_columntype[FILEBOX_COLUMNS];
293 int dirbox_columnwidth[FILEBOX_COLUMNS];
294 int dirbox_sortcolumn;
295 int dirbox_sortorder;
296 // Bottom margin between list and window
301 double font_scale, icon_scale;
304 static const char *small_font;
305 static const char *medium_font;
306 static const char *large_font;
307 static const char *big_font;
308 // Backup of fonts in case the first choices don't exist
309 static const char *small_font2;
310 static const char *medium_font2;
311 static const char *large_font2;
312 static const char *big_font2;
314 static const char *small_fontset;
315 static const char *medium_fontset;
316 static const char *large_fontset;
317 static const char *big_fontset;
319 static const char *small_font_xft, *small_b_font_xft;
320 static const char *medium_font_xft, *medium_b_font_xft;
321 static const char *large_font_xft, *large_b_font_xft;
322 static const char *big_font_xft, *big_b_font_xft;
324 // Backup of fonts in case the first choices don't exist
325 static const char *small_font_xft2;
326 static const char *medium_font_xft2;
327 static const char *large_font_xft2;
328 static const char *big_font_xft2;
329 void init_font_defs(double scale);
331 VFrame **medium_7segment;
334 int draw_clock_background;
339 // Current locale uses utf8
340 static int locale_utf8;
341 // Byte order is little_endian
342 static int little_endian;
343 // Language and region
344 static char language[LEN_LANG];
345 static char region[LEN_LANG];
346 static char encoding[LEN_ENCOD];
347 static const char *wide_encoding;
348 static ArrayList<BC_FontEntry*> *fontlist;
349 static int init_fontconfig(const char *search_path);
350 static BC_FontEntry *find_fontentry(const char *displayname, int style,
351 int mask, int preferred_style = 0);
352 static void encode_to_utf8(char *buffer, int buflen);
353 static FcPattern* find_similar_font(FT_ULong char_code, FcPattern *oldfont);
354 static size_t encode(const char *from_enc, const char *to_enc,
355 char *input, int input_length, char *output, int output_length);
356 static int find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface);
357 static void dump_fonts(FILE *fp = stdout);
359 // Make VFrame use shm
361 int use_vframe_shm() { return use_shm && vframe_shm ? 1 : 0; }
363 static int get_machine_cpus();
364 static int machine_cpus;
365 // Available display extensions
369 // If the program uses recursive_resizing
370 int recursive_resizing;
371 // Work around X server bugs
373 // Seems to help if only 1 window is created at a time.
374 Mutex *create_window_lock;
377 // Test for availability of shared memory pixmaps
378 void init_shm(BC_WindowBase *window);
379 void init_sizes(BC_WindowBase *window);
380 static int x_error_handler(Display *display, XErrorEvent *event);
381 VFrame **list_pointers[100];
382 int list_lengths[100];
384 static const char *fc_properties[];
388 static Mutex fontconfig_lock;
390 // Pointer to signal handler class to run after ipc
391 static BC_Signals *signal_handler;
392 BC_Synchronous *synchronous;