Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 36049:31f6a88593b3
Cosmetic: Rename static variables.
Use a prefix that differs from prefixes used for global definitions
and that has a relation to the source it's used in.
author | ib |
---|---|
date | Thu, 04 Apr 2013 09:39:03 +0000 |
parents | e3e9b31b1088 |
children | 1562f350e8d2 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
23077 | 18 |
36040 | 19 #include <stdint.h> |
23077 | 20 #include <stdlib.h> |
36040 | 21 #include <string.h> |
22 #include <gdk/gdkx.h> | |
23077 | 23 |
36040 | 24 #include "dialog.h" |
25 #include "about.h" | |
26 #include "equalizer.h" | |
27 #include "fileselect.h" | |
28 #include "menu.h" | |
29 #include "msgbox.h" | |
30 #include "playlist.h" | |
31 #include "preferences.h" | |
32 #include "skinbrowser.h" | |
33 #include "tools.h" | |
34 #include "url.h" | |
35 #include "gui/interface.h" | |
36 #include "gui/app/app.h" | |
37 #include "gui/app/gui.h" | |
38 #include "gui/util/string.h" | |
39 #include "gui/wm/ws.h" | |
23077 | 40 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
42 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
43 #include "mp_msg.h" |
33542 | 44 #include "libavutil/intreadwrite.h" |
23077 | 45 |
33542 | 46 #define THRESHOLD 128 // transparency values equal to or above this will become |
47 // opaque, all values below this will become transparent | |
48 | |
33529 | 49 guiIcon_t guiIcon; |
23077 | 50 |
36049 | 51 static const char guiIconName[] = "mplayer"; |
36048 | 52 |
53 static GtkWidget *PopUpMenu; | |
54 | |
55 static int gtkInitialized; | |
56 | |
35643 | 57 /** |
58 * @brief Add an icon to the #guiIcon icon structure. | |
59 * | |
60 * @param theme theme to load the icon from | |
61 * @param size size of the icon to load | |
62 * @param gdkIcon location to store a pointer to the created pixmap | |
63 * @param gdkIconMask location to store a pointer to the created mask | |
64 * | |
65 * @return #True (ok) or #False (error) | |
66 */ | |
34780 | 67 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
34480 | 68 { |
69 GdkPixbuf *pixbuf; | |
70 guchar *data; | |
71 int csize, i; | |
72 | |
36049 | 73 pixbuf = gtk_icon_theme_load_icon(theme, guiIconName, size, 0, NULL); |
34480 | 74 |
75 if (pixbuf) | |
76 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
77 | |
78 if (pixbuf && | |
79 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
80 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
81 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
82 csize = guiIcon.collection_size; | |
83 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
84 | |
85 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
86 | |
87 if (guiIcon.collection) { | |
88 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
89 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
90 | |
91 data = gdk_pixbuf_get_pixels(pixbuf); | |
92 | |
93 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
35703 | 94 guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB |
34480 | 95 } |
96 | |
97 g_object_unref(pixbuf); | |
98 } else | |
36049 | 99 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, guiIconName, size); |
34480 | 100 |
34684 | 101 /* start up GTK which realizes the pixmaps */ |
34480 | 102 gtk_main_iteration_do(FALSE); |
34780 | 103 |
104 return (pixbuf != NULL); | |
34480 | 105 } |
106 | |
35643 | 107 /** |
108 * @brief Initialize the GTK user interface. | |
109 * | |
110 * @param display_name name of the X display to use or NULL (using the DISPLAY environment variable) | |
111 */ | |
35629 | 112 void gtkInit(char *display_name) |
23077 | 113 { |
34480 | 114 int argc = 0; |
33538 | 115 char *arg[3], **argv = arg; |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
116 #ifdef CONFIG_GTK2 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
117 char *env; |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
118 #endif |
34480 | 119 GtkIconTheme *theme; |
33538 | 120 GdkPixmap *gdkIcon; |
121 GdkBitmap *gdkIconMask; | |
33465 | 122 |
33538 | 123 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 124 |
33538 | 125 arg[argc++] = GMPlayer; |
33465 | 126 |
35703 | 127 if (display_name) { // MPlayer option '-display' was given |
128 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
35629 | 129 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 130 } |
33465 | 131 |
27343 | 132 #ifdef CONFIG_GTK2 |
33538 | 133 gtk_disable_setlocale(); |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
134 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
135 env = getenv("G_FILENAME_ENCODING"); |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
136 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
137 if ((!env && getenv("G_BROKEN_FILENAMES")) || (gstrncmp(env, "@locale", 7) == 0)) |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
138 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_LOCALE_ENCODING); |
23077 | 139 #endif |
33528 | 140 |
33538 | 141 gtk_init(&argc, &argv); |
35703 | 142 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 143 |
34480 | 144 theme = gtk_icon_theme_get_default(); |
33542 | 145 |
34780 | 146 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 147 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
148 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 149 } |
33542 | 150 |
34780 | 151 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 152 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
153 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 154 } |
23077 | 155 |
34480 | 156 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
157 | |
35493 | 158 gtkInitialized = True; |
33538 | 159 } |
23077 | 160 |
35643 | 161 /** |
162 * @brief Add the #guiIcon icons to a GTK window. | |
163 * | |
164 * @param window pointer to a GtkWindow widget | |
165 */ | |
33538 | 166 void gtkAddIcon(GtkWidget *window) |
167 { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
168 wsWindowIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); |
33538 | 169 } |
23077 | 170 |
33538 | 171 void gtkEventHandling(void) |
23077 | 172 { |
33538 | 173 int i; |
174 | |
175 for (i = 0; i < 25; i++) | |
176 gtk_main_iteration_do(0); | |
23077 | 177 } |
178 | |
34684 | 179 /* funcs */ |
23077 | 180 |
33538 | 181 void gtkMessageBox(int type, const gchar *str) |
23077 | 182 { |
33538 | 183 if (!gtkInitialized) |
184 return; | |
185 | |
186 ShowMessageBox(str); | |
187 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
188 | |
189 /* enable linewrapping by alex */ | |
23077 | 190 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 191 if (strlen(str) > 80) |
192 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
193 else | |
194 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
195 | |
196 switch (type) { | |
36036 | 197 case MSGBOX_FATAL: |
33538 | 198 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
199 gtk_widget_hide(WarningPixmap); | |
200 gtk_widget_show(ErrorPixmap); | |
201 break; | |
202 | |
36036 | 203 case MSGBOX_ERROR: |
33538 | 204 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
205 gtk_widget_hide(WarningPixmap); | |
206 gtk_widget_show(ErrorPixmap); | |
207 break; | |
208 | |
36036 | 209 case MSGBOX_WARNING: |
33538 | 210 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
211 gtk_widget_show(WarningPixmap); | |
212 gtk_widget_hide(ErrorPixmap); | |
213 break; | |
214 } | |
215 | |
216 gtk_widget_show(MessageBox); | |
217 gtkSetLayer(MessageBox); | |
218 | |
36036 | 219 if (type == MSGBOX_FATAL) |
33538 | 220 while (MessageBox) |
221 gtk_main_iteration_do(0); | |
23077 | 222 } |
223 | |
35643 | 224 /** |
225 * @brief Set the layer for a GTK window. | |
226 * | |
227 * @param window pointer to a GtkWindow widget | |
228 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
229 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
230 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
231 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
36019 | 232 gtkRaise(window); |
33538 | 233 } |
234 | |
35643 | 235 /** |
236 * @brief Activate a GTK window, i.e. raise it to the top. | |
237 * | |
238 * @param window pointer to a GtkWindow widget | |
239 */ | |
36019 | 240 void gtkRaise(GtkWidget *window) |
33538 | 241 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
242 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 243 } |
244 | |
36022 | 245 static void gtkSelectInCList(GtkWidget *list, char *item) |
246 { | |
247 gint i; | |
248 | |
36024 | 249 if ((i = gtkFindInCList(list, item)) > -1) |
36022 | 250 gtk_clist_select_row(GTK_CLIST(list), i, 0); |
251 } | |
252 | |
33538 | 253 void gtkShow(int type, char *param) |
23077 | 254 { |
33538 | 255 switch (type) { |
256 case evEqualizer: | |
257 ShowEqualizer(); | |
258 gtkSetLayer(Equalizer); | |
259 break; | |
260 | |
261 case evSkinBrowser: | |
262 ShowSkinBrowser(); | |
263 | |
36020 | 264 // gtk_clist_clear(GTK_CLIST(SkinList)); |
36044 | 265 if (FillSkinList(sbSkinDirInHome) && |
266 FillSkinList(sbSkinDirInData)) { | |
36021 | 267 gtkSelectInCList(SkinList, param); |
33538 | 268 gtk_clist_sort(GTK_CLIST(SkinList)); |
269 gtk_widget_show(SkinBrowser); | |
270 gtkSetLayer(SkinBrowser); | |
271 } else { | |
272 gtk_widget_destroy(SkinBrowser); | |
36036 | 273 gtkMessageBox(MSGBOX_ERROR, "Skin dirs not found ... Please install skins."); |
33538 | 274 } |
275 | |
23077 | 276 break; |
33538 | 277 |
278 case evPreferences: | |
23077 | 279 ShowPreferences(); |
280 break; | |
33538 | 281 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
282 case evPlaylist: |
35981 | 283 ShowPlaylist(); |
284 gtkSetLayer(Playlist); | |
23077 | 285 break; |
33538 | 286 |
287 case evLoad: | |
35976 | 288 ShowFileSelector(FILESELECT_VIDEO_AUDIO); |
35975 | 289 gtkSetLayer(FileSelector); |
23077 | 290 break; |
33538 | 291 |
292 case evLoadSubtitle: | |
35976 | 293 ShowFileSelector(FILESELECT_SUBTITLE); |
35975 | 294 gtkSetLayer(FileSelector); |
23077 | 295 break; |
33538 | 296 |
297 case evLoadAudioFile: | |
35976 | 298 ShowFileSelector(FILESELECT_AUDIO); |
35975 | 299 gtkSetLayer(FileSelector); |
33538 | 300 break; |
301 | |
302 case evAbout: | |
35977 | 303 ShowAbout(); |
33538 | 304 gtkSetLayer(About); |
23077 | 305 break; |
33538 | 306 |
34333 | 307 case ivShowPopUpMenu: |
33538 | 308 gtkPopupMenu = evNone; |
309 gtkPopupMenuParam = 0; | |
310 | |
311 if (PopUpMenu) { | |
312 gtk_widget_hide(PopUpMenu); | |
313 gtk_widget_destroy(PopUpMenu); | |
314 } | |
315 | |
35996 | 316 PopUpMenu = CreatePopUpMenu(); |
33538 | 317 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); |
23077 | 318 break; |
33538 | 319 |
34333 | 320 case ivHidePopUpMenu: |
33538 | 321 |
322 if (PopUpMenu) { | |
323 gtk_widget_hide(PopUpMenu); | |
324 gtk_widget_destroy(PopUpMenu); | |
325 PopUpMenu = NULL; | |
326 } | |
327 | |
23077 | 328 break; |
33538 | 329 |
34329 | 330 case evLoadURL: |
35978 | 331 ShowURLDialog(); |
332 gtkSetLayer(URLDialog); | |
33538 | 333 break; |
334 } | |
23077 | 335 } |