Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 37176:2208a16cc562
Remove GTK+ and GLib versions 1 relatedness from the GUI.
This isn't really a cut-back, because although it seemed
that compiling with GTK+ and GLib versions 1 were possible,
compiling actually hadn't been possible for quite some time.
author | ib |
---|---|
date | Mon, 08 Sep 2014 20:17:01 +0000 |
parents | b28b632efeef |
children |
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 | |
37065 | 62 * @param gdkIcon memory location to store a pointer to the created pixmap |
63 * @param gdkIconMask memory location to store a pointer to the created mask | |
35643 | 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 | |
36694 | 99 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_GUI_MSG_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 char *env; |
34480 | 117 GtkIconTheme *theme; |
33538 | 118 GdkPixmap *gdkIcon; |
119 GdkBitmap *gdkIconMask; | |
33465 | 120 |
33538 | 121 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 122 |
36054 | 123 arg[argc++] = gmplayer; |
33465 | 124 |
35703 | 125 if (display_name) { // MPlayer option '-display' was given |
126 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
35629 | 127 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 128 } |
33465 | 129 |
33538 | 130 gtk_disable_setlocale(); |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
131 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
132 env = getenv("G_FILENAME_ENCODING"); |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
133 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
134 if ((!env && getenv("G_BROKEN_FILENAMES")) || (gstrncmp(env, "@locale", 7) == 0)) |
36694 | 135 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_GUI_MSG_LocaleEncoding); |
33528 | 136 |
33538 | 137 gtk_init(&argc, &argv); |
35703 | 138 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 139 |
34480 | 140 theme = gtk_icon_theme_get_default(); |
33542 | 141 |
34780 | 142 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 143 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
144 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 145 } |
33542 | 146 |
34780 | 147 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 148 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
149 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 150 } |
23077 | 151 |
34480 | 152 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
153 | |
35493 | 154 gtkInitialized = True; |
33538 | 155 } |
23077 | 156 |
35643 | 157 /** |
158 * @brief Add the #guiIcon icons to a GTK window. | |
159 * | |
160 * @param window pointer to a GtkWindow widget | |
161 */ | |
33538 | 162 void gtkAddIcon(GtkWidget *window) |
163 { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
164 wsWindowIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); |
33538 | 165 } |
23077 | 166 |
36071 | 167 /** |
168 * @brief Process all pending events. | |
169 */ | |
36070 | 170 void gtkEvents(void) |
23077 | 171 { |
36071 | 172 while (gtk_events_pending()) |
173 gtk_main_iteration(); | |
23077 | 174 } |
175 | |
34684 | 176 /* funcs */ |
23077 | 177 |
33538 | 178 void gtkMessageBox(int type, const gchar *str) |
23077 | 179 { |
33538 | 180 if (!gtkInitialized) |
181 return; | |
182 | |
183 ShowMessageBox(str); | |
184 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
185 | |
186 /* enable linewrapping by alex */ | |
23077 | 187 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 188 if (strlen(str) > 80) |
189 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
190 else | |
191 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
192 | |
193 switch (type) { | |
36036 | 194 case MSGBOX_FATAL: |
36694 | 195 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_GUI_ErrorFatal); |
36680 | 196 gtk_widget_hide(InformationPixmap); |
33538 | 197 gtk_widget_hide(WarningPixmap); |
198 gtk_widget_show(ErrorPixmap); | |
199 break; | |
200 | |
36036 | 201 case MSGBOX_ERROR: |
36694 | 202 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_GUI_Error); |
36680 | 203 gtk_widget_hide(InformationPixmap); |
33538 | 204 gtk_widget_hide(WarningPixmap); |
205 gtk_widget_show(ErrorPixmap); | |
206 break; | |
207 | |
36036 | 208 case MSGBOX_WARNING: |
36694 | 209 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_GUI_Warning); |
36680 | 210 gtk_widget_hide(InformationPixmap); |
33538 | 211 gtk_widget_show(WarningPixmap); |
212 gtk_widget_hide(ErrorPixmap); | |
213 break; | |
36680 | 214 |
215 case MSGBOX_INFORMATION: | |
36694 | 216 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_GUI_Information); |
36680 | 217 gtk_widget_show(InformationPixmap); |
218 gtk_widget_hide(WarningPixmap); | |
219 gtk_widget_hide(ErrorPixmap); | |
220 break; | |
33538 | 221 } |
222 | |
223 gtk_widget_show(MessageBox); | |
224 gtkSetLayer(MessageBox); | |
225 | |
36036 | 226 if (type == MSGBOX_FATAL) |
33538 | 227 while (MessageBox) |
228 gtk_main_iteration_do(0); | |
23077 | 229 } |
230 | |
35643 | 231 /** |
232 * @brief Set the layer for a GTK window. | |
233 * | |
234 * @param window pointer to a GtkWindow widget | |
235 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
236 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
237 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
238 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
36019 | 239 gtkRaise(window); |
33538 | 240 } |
241 | |
35643 | 242 /** |
243 * @brief Activate a GTK window, i.e. raise it to the top. | |
244 * | |
245 * @param window pointer to a GtkWindow widget | |
246 */ | |
36019 | 247 void gtkRaise(GtkWidget *window) |
33538 | 248 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
249 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 250 } |
251 | |
36022 | 252 static void gtkSelectInCList(GtkWidget *list, char *item) |
253 { | |
254 gint i; | |
255 | |
36024 | 256 if ((i = gtkFindInCList(list, item)) > -1) |
36022 | 257 gtk_clist_select_row(GTK_CLIST(list), i, 0); |
258 } | |
259 | |
33538 | 260 void gtkShow(int type, char *param) |
23077 | 261 { |
33538 | 262 switch (type) { |
263 case evEqualizer: | |
264 ShowEqualizer(); | |
265 gtkSetLayer(Equalizer); | |
266 break; | |
267 | |
268 case evSkinBrowser: | |
269 ShowSkinBrowser(); | |
270 | |
36020 | 271 // gtk_clist_clear(GTK_CLIST(SkinList)); |
36044 | 272 if (FillSkinList(sbSkinDirInHome) && |
273 FillSkinList(sbSkinDirInData)) { | |
36021 | 274 gtkSelectInCList(SkinList, param); |
33538 | 275 gtk_clist_sort(GTK_CLIST(SkinList)); |
276 gtk_widget_show(SkinBrowser); | |
277 gtkSetLayer(SkinBrowser); | |
278 } else { | |
279 gtk_widget_destroy(SkinBrowser); | |
36036 | 280 gtkMessageBox(MSGBOX_ERROR, "Skin dirs not found ... Please install skins."); |
33538 | 281 } |
282 | |
23077 | 283 break; |
33538 | 284 |
285 case evPreferences: | |
23077 | 286 ShowPreferences(); |
287 break; | |
33538 | 288 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
289 case evPlaylist: |
35981 | 290 ShowPlaylist(); |
291 gtkSetLayer(Playlist); | |
23077 | 292 break; |
33538 | 293 |
294 case evLoad: | |
35976 | 295 ShowFileSelector(FILESELECT_VIDEO_AUDIO); |
35975 | 296 gtkSetLayer(FileSelector); |
23077 | 297 break; |
33538 | 298 |
299 case evLoadSubtitle: | |
35976 | 300 ShowFileSelector(FILESELECT_SUBTITLE); |
35975 | 301 gtkSetLayer(FileSelector); |
23077 | 302 break; |
33538 | 303 |
304 case evLoadAudioFile: | |
35976 | 305 ShowFileSelector(FILESELECT_AUDIO); |
35975 | 306 gtkSetLayer(FileSelector); |
33538 | 307 break; |
308 | |
309 case evAbout: | |
35977 | 310 ShowAbout(); |
33538 | 311 gtkSetLayer(About); |
23077 | 312 break; |
33538 | 313 |
34333 | 314 case ivShowPopUpMenu: |
33538 | 315 gtkPopupMenu = evNone; |
316 gtkPopupMenuParam = 0; | |
317 | |
318 if (PopUpMenu) { | |
319 gtk_widget_hide(PopUpMenu); | |
320 gtk_widget_destroy(PopUpMenu); | |
321 } | |
322 | |
35996 | 323 PopUpMenu = CreatePopUpMenu(); |
33538 | 324 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); |
23077 | 325 break; |
33538 | 326 |
34333 | 327 case ivHidePopUpMenu: |
33538 | 328 |
329 if (PopUpMenu) { | |
330 gtk_widget_hide(PopUpMenu); | |
331 gtk_widget_destroy(PopUpMenu); | |
332 PopUpMenu = NULL; | |
333 } | |
334 | |
23077 | 335 break; |
33538 | 336 |
34329 | 337 case evLoadURL: |
35978 | 338 ShowURLDialog(); |
339 gtkSetLayer(URLDialog); | |
33538 | 340 break; |
341 } | |
23077 | 342 } |