Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 36024:a9e5f317d6e4
Move gtkFindCList() to tools.c.
Additionally, rename it gtkFindInCList().
author | ib |
---|---|
date | Sun, 31 Mar 2013 18:30:30 +0000 |
parents | bf5690e00dc6 |
children | 49be954ad61a |
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 |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
35361
3e8dcfa3ceef
Prevent unintended sign extension from int to long on 64-bit machines.
ib
parents:
34781
diff
changeset
|
21 #include <stdint.h> |
23077 | 22 |
23 #include <sys/types.h> | |
24 #include <sys/stat.h> | |
25 #include <sys/wait.h> | |
26 #include <unistd.h> | |
27 #include <string.h> | |
28 #include <signal.h> | |
29 | |
30 #include <gdk/gdkprivate.h> | |
31 #include <gdk/gdkkeysyms.h> | |
32 #include <gdk/gdkx.h> | |
33 #include <gdk/gdk.h> | |
34 #include <gtk/gtk.h> | |
35 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
36 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
38 #include "mp_msg.h" |
33542 | 39 #include "libavutil/intreadwrite.h" |
33465 | 40 #include "libvo/x11_common.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 |
35529 | 42 #include "dialog.h" |
35525 | 43 #include "gui/app/app.h" |
44 #include "gui/app/gui.h" | |
33466 | 45 #include "gui/interface.h" |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
46 #include "gui/util/string.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
47 #include "gui/wm/ws.h" |
23077 | 48 |
35529 | 49 #include "gui/ui/actions.h" |
50 #include "fileselect.h" | |
23077 | 51 |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
52 static GtkWidget *PopUpMenu; |
23077 | 53 |
33538 | 54 GtkWidget *WarningPixmap; |
55 GtkWidget *ErrorPixmap; | |
23077 | 56 |
35624 | 57 int gtkPopupMenu; |
58 int gtkPopupMenuParam; | |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
59 static int gtkInitialized; |
23077 | 60 |
35529 | 61 #include "skinbrowser.h" |
62 #include "playlist.h" | |
63 #include "msgbox.h" | |
64 #include "about.h" | |
65 #include "preferences.h" | |
66 #include "menu.h" | |
67 #include "url.h" | |
68 #include "equalizer.h" | |
36024 | 69 #include "tools.h" |
23077 | 70 |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
71 static const char gui_icon_name[] = "mplayer"; |
23077 | 72 |
33542 | 73 #define THRESHOLD 128 // transparency values equal to or above this will become |
74 // opaque, all values below this will become transparent | |
75 | |
33529 | 76 guiIcon_t guiIcon; |
23077 | 77 |
35643 | 78 /** |
79 * @brief Add an icon to the #guiIcon icon structure. | |
80 * | |
81 * @param theme theme to load the icon from | |
82 * @param size size of the icon to load | |
83 * @param gdkIcon location to store a pointer to the created pixmap | |
84 * @param gdkIconMask location to store a pointer to the created mask | |
85 * | |
86 * @return #True (ok) or #False (error) | |
87 */ | |
34780 | 88 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
34480 | 89 { |
90 GdkPixbuf *pixbuf; | |
91 guchar *data; | |
92 int csize, i; | |
93 | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
94 pixbuf = gtk_icon_theme_load_icon(theme, gui_icon_name, size, 0, NULL); |
34480 | 95 |
96 if (pixbuf) | |
97 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
98 | |
99 if (pixbuf && | |
100 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
101 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
102 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
103 csize = guiIcon.collection_size; | |
104 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
105 | |
106 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
107 | |
108 if (guiIcon.collection) { | |
109 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
110 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
111 | |
112 data = gdk_pixbuf_get_pixels(pixbuf); | |
113 | |
114 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
35703 | 115 guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB |
34480 | 116 } |
117 | |
118 g_object_unref(pixbuf); | |
119 } else | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
120 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, gui_icon_name, size); |
34480 | 121 |
34684 | 122 /* start up GTK which realizes the pixmaps */ |
34480 | 123 gtk_main_iteration_do(FALSE); |
34780 | 124 |
125 return (pixbuf != NULL); | |
34480 | 126 } |
127 | |
35643 | 128 /** |
129 * @brief Initialize the GTK user interface. | |
130 * | |
131 * @param display_name name of the X display to use or NULL (using the DISPLAY environment variable) | |
132 */ | |
35629 | 133 void gtkInit(char *display_name) |
23077 | 134 { |
34480 | 135 int argc = 0; |
33538 | 136 char *arg[3], **argv = arg; |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
137 #ifdef CONFIG_GTK2 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
138 char *env; |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
139 #endif |
34480 | 140 GtkIconTheme *theme; |
33538 | 141 GdkPixmap *gdkIcon; |
142 GdkBitmap *gdkIconMask; | |
33465 | 143 |
33538 | 144 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 145 |
33538 | 146 arg[argc++] = GMPlayer; |
33465 | 147 |
35703 | 148 if (display_name) { // MPlayer option '-display' was given |
149 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
35629 | 150 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 151 } |
33465 | 152 |
27343 | 153 #ifdef CONFIG_GTK2 |
33538 | 154 gtk_disable_setlocale(); |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
155 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
156 env = getenv("G_FILENAME_ENCODING"); |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
157 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
158 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
|
159 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_LOCALE_ENCODING); |
23077 | 160 #endif |
33528 | 161 |
33538 | 162 gtk_init(&argc, &argv); |
35703 | 163 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 164 |
34480 | 165 theme = gtk_icon_theme_get_default(); |
33542 | 166 |
34780 | 167 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 168 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
169 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 170 } |
33542 | 171 |
34780 | 172 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 173 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
174 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 175 } |
23077 | 176 |
34480 | 177 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
178 | |
35493 | 179 gtkInitialized = True; |
33538 | 180 } |
23077 | 181 |
35643 | 182 /** |
183 * @brief Add the #guiIcon icons to a GTK window. | |
184 * | |
185 * @param window pointer to a GtkWindow widget | |
186 */ | |
33538 | 187 void gtkAddIcon(GtkWidget *window) |
188 { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
189 wsWindowIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); |
33538 | 190 } |
23077 | 191 |
33538 | 192 void gtkEventHandling(void) |
23077 | 193 { |
33538 | 194 int i; |
195 | |
196 for (i = 0; i < 25; i++) | |
197 gtk_main_iteration_do(0); | |
23077 | 198 } |
199 | |
34684 | 200 /* funcs */ |
23077 | 201 |
33538 | 202 void gtkMessageBox(int type, const gchar *str) |
23077 | 203 { |
33538 | 204 if (!gtkInitialized) |
205 return; | |
206 | |
207 ShowMessageBox(str); | |
208 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
209 | |
210 /* enable linewrapping by alex */ | |
23077 | 211 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 212 if (strlen(str) > 80) |
213 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
214 else | |
215 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
216 | |
217 switch (type) { | |
23077 | 218 case GTK_MB_FATAL: |
33538 | 219 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
220 gtk_widget_hide(WarningPixmap); | |
221 gtk_widget_show(ErrorPixmap); | |
222 break; | |
223 | |
23077 | 224 case GTK_MB_ERROR: |
33538 | 225 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
226 gtk_widget_hide(WarningPixmap); | |
227 gtk_widget_show(ErrorPixmap); | |
228 break; | |
229 | |
23077 | 230 case GTK_MB_WARNING: |
33538 | 231 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
232 gtk_widget_show(WarningPixmap); | |
233 gtk_widget_hide(ErrorPixmap); | |
234 break; | |
235 } | |
236 | |
237 gtk_widget_show(MessageBox); | |
238 gtkSetLayer(MessageBox); | |
239 | |
240 if (type == GTK_MB_FATAL) | |
241 while (MessageBox) | |
242 gtk_main_iteration_do(0); | |
23077 | 243 } |
244 | |
35643 | 245 /** |
246 * @brief Set the layer for a GTK window. | |
247 * | |
248 * @param window pointer to a GtkWindow widget | |
249 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
250 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
251 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
252 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
36019 | 253 gtkRaise(window); |
33538 | 254 } |
255 | |
35643 | 256 /** |
257 * @brief Activate a GTK window, i.e. raise it to the top. | |
258 * | |
259 * @param window pointer to a GtkWindow widget | |
260 */ | |
36019 | 261 void gtkRaise(GtkWidget *window) |
33538 | 262 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
263 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 264 } |
265 | |
36022 | 266 static void gtkSelectInCList(GtkWidget *list, char *item) |
267 { | |
268 gint i; | |
269 | |
36024 | 270 if ((i = gtkFindInCList(list, item)) > -1) |
36022 | 271 gtk_clist_select_row(GTK_CLIST(list), i, 0); |
272 } | |
273 | |
33538 | 274 void gtkShow(int type, char *param) |
23077 | 275 { |
33538 | 276 switch (type) { |
277 case evEqualizer: | |
278 ShowEqualizer(); | |
279 gtkSetLayer(Equalizer); | |
280 break; | |
281 | |
282 case evSkinBrowser: | |
283 ShowSkinBrowser(); | |
284 | |
36020 | 285 // gtk_clist_clear(GTK_CLIST(SkinList)); |
33538 | 286 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
287 gtkFillSkinList(sbMPlayerDirInHome)) { | |
36021 | 288 gtkSelectInCList(SkinList, param); |
33538 | 289 gtk_clist_sort(GTK_CLIST(SkinList)); |
290 gtk_widget_show(SkinBrowser); | |
291 gtkSetLayer(SkinBrowser); | |
292 } else { | |
293 gtk_widget_destroy(SkinBrowser); | |
294 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
295 } | |
296 | |
23077 | 297 break; |
33538 | 298 |
299 case evPreferences: | |
23077 | 300 ShowPreferences(); |
301 break; | |
33538 | 302 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
303 case evPlaylist: |
35981 | 304 ShowPlaylist(); |
305 gtkSetLayer(Playlist); | |
23077 | 306 break; |
33538 | 307 |
308 case evLoad: | |
35976 | 309 ShowFileSelector(FILESELECT_VIDEO_AUDIO); |
35975 | 310 gtkSetLayer(FileSelector); |
23077 | 311 break; |
33538 | 312 |
313 case evLoadSubtitle: | |
35976 | 314 ShowFileSelector(FILESELECT_SUBTITLE); |
35975 | 315 gtkSetLayer(FileSelector); |
23077 | 316 break; |
33538 | 317 |
318 case evLoadAudioFile: | |
35976 | 319 ShowFileSelector(FILESELECT_AUDIO); |
35975 | 320 gtkSetLayer(FileSelector); |
33538 | 321 break; |
322 | |
323 case evAbout: | |
35977 | 324 ShowAbout(); |
33538 | 325 gtkSetLayer(About); |
23077 | 326 break; |
33538 | 327 |
34333 | 328 case ivShowPopUpMenu: |
33538 | 329 gtkPopupMenu = evNone; |
330 gtkPopupMenuParam = 0; | |
331 | |
332 if (PopUpMenu) { | |
333 gtk_widget_hide(PopUpMenu); | |
334 gtk_widget_destroy(PopUpMenu); | |
335 } | |
336 | |
35996 | 337 PopUpMenu = CreatePopUpMenu(); |
33538 | 338 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); |
23077 | 339 break; |
33538 | 340 |
34333 | 341 case ivHidePopUpMenu: |
33538 | 342 |
343 if (PopUpMenu) { | |
344 gtk_widget_hide(PopUpMenu); | |
345 gtk_widget_destroy(PopUpMenu); | |
346 PopUpMenu = NULL; | |
347 } | |
348 | |
23077 | 349 break; |
33538 | 350 |
34329 | 351 case evLoadURL: |
35978 | 352 ShowURLDialog(); |
353 gtkSetLayer(URLDialog); | |
33538 | 354 break; |
355 } | |
23077 | 356 } |