Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 35681:80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
wsXInit -> wsInit
wsXDone -> wsDone
wsEvents -> wsEvent
wsHandleEvents -> wsEvents
wsSetBackgroundRGB -> wsWindowBackground
wsClearWindow -> wsWindowClear
wsCreateWindow -> wsWindowCreate
wsDestroyWindow -> wsWindowDestroy
wsFullScreen -> wsWindowFullscreen
wsSetIcon -> wsWindowIcon
wsIconify -> wsWindowIconify
wsSetLayer -> wsWindowLayer
wsSearch -> wsWindowListSearch
wsMoveWindow -> wsWindowMove
wsMoveWindowWithin -> wsWindowMoveWithin
wsRaiseWindowTop -> wsWindowRaiseTop
wsPostRedisplay -> wsWindowRedraw
wsResizeWindow -> wsWindowResize
wsSetShape -> wsWindowShape
wsWindowPosition -> wsWindowUpdatePosition
wsUpdateXineramaInfo -> wsWindowUpdateXinerama
wsVisibleWindow -> wsWindowVisibility
wsConvert -> wsImageConvert
wsCreateImage -> wsImageCreate
wsDestroyImage -> wsImageDestroy
wsPutImage -> wsImageDraw
wsResizeImage -> wsImageResize
wsAutohideCursor -> wsMouseAutohide
wsVisibleMouse -> wsMouseVisibility
author | ib |
---|---|
date | Fri, 18 Jan 2013 00:35:38 +0000 |
parents | f8eb470c25ea |
children | c0d48e21b9fc |
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" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
46 #include "gui/wm/ws.h" |
23077 | 47 |
35529 | 48 #include "gui/ui/actions.h" |
49 #include "fileselect.h" | |
23077 | 50 |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
51 static GtkWidget *PopUpMenu; |
23077 | 52 |
33538 | 53 GtkWidget *WarningPixmap; |
54 GtkWidget *ErrorPixmap; | |
23077 | 55 |
35624 | 56 int gtkPopupMenu; |
57 int gtkPopupMenuParam; | |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
58 static int gtkInitialized; |
23077 | 59 |
35529 | 60 #include "skinbrowser.h" |
61 #include "playlist.h" | |
62 #include "msgbox.h" | |
63 #include "about.h" | |
64 #include "preferences.h" | |
65 #include "menu.h" | |
66 #include "url.h" | |
67 #include "equalizer.h" | |
23077 | 68 |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
69 static const char gui_icon_name[] = "mplayer"; |
23077 | 70 |
33542 | 71 #define THRESHOLD 128 // transparency values equal to or above this will become |
72 // opaque, all values below this will become transparent | |
73 | |
34684 | 74 /* init & close gtk */ |
23077 | 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++) | |
35361
3e8dcfa3ceef
Prevent unintended sign extension from int to long on 64-bit machines.
ib
parents:
34781
diff
changeset
|
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; |
34480 | 137 GtkIconTheme *theme; |
33538 | 138 GdkPixmap *gdkIcon; |
139 GdkBitmap *gdkIconMask; | |
33465 | 140 |
33538 | 141 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 142 |
33538 | 143 arg[argc++] = GMPlayer; |
33465 | 144 |
35629 | 145 if (display_name) { // MPlayer option '-display' was given |
33538 | 146 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, |
35629 | 147 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 148 } |
33465 | 149 |
27343 | 150 #ifdef CONFIG_GTK2 |
33538 | 151 gtk_disable_setlocale(); |
23077 | 152 #endif |
33528 | 153 |
33538 | 154 gtk_init(&argc, &argv); |
35636 | 155 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 156 |
34480 | 157 theme = gtk_icon_theme_get_default(); |
33542 | 158 |
34780 | 159 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 160 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
161 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 162 } |
33542 | 163 |
34780 | 164 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 165 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
166 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 167 } |
23077 | 168 |
34480 | 169 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
170 | |
35493 | 171 gtkInitialized = True; |
33538 | 172 } |
23077 | 173 |
35643 | 174 /** |
175 * @brief Add the #guiIcon icons to a GTK window. | |
176 * | |
177 * @param window pointer to a GtkWindow widget | |
178 */ | |
33538 | 179 void gtkAddIcon(GtkWidget *window) |
180 { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
181 wsWindowIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); |
33538 | 182 } |
23077 | 183 |
33538 | 184 void gtkClearList(GtkWidget *list) |
185 { | |
186 gtk_clist_clear(GTK_CLIST(list)); | |
23077 | 187 } |
188 | |
33538 | 189 int gtkFindCList(GtkWidget *list, char *item) |
23077 | 190 { |
33538 | 191 gint j; |
192 gchar *tmpstr; | |
193 | |
194 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
195 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
196 | |
197 if (!strcmp(tmpstr, item)) | |
198 return j; | |
199 } | |
200 | |
201 return -1; | |
23077 | 202 } |
203 | |
33538 | 204 void gtkSetDefaultToCList(GtkWidget *list, char *item) |
23077 | 205 { |
33538 | 206 gint i; |
207 | |
208 if ((i = gtkFindCList(list, item)) > -1) | |
209 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
23077 | 210 } |
211 | |
33538 | 212 void gtkEventHandling(void) |
23077 | 213 { |
33538 | 214 int i; |
215 | |
216 for (i = 0; i < 25; i++) | |
217 gtk_main_iteration_do(0); | |
23077 | 218 } |
219 | |
34684 | 220 /* funcs */ |
23077 | 221 |
33538 | 222 void gtkMessageBox(int type, const gchar *str) |
23077 | 223 { |
33538 | 224 if (!gtkInitialized) |
225 return; | |
226 | |
227 ShowMessageBox(str); | |
228 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
229 | |
230 /* enable linewrapping by alex */ | |
23077 | 231 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 232 if (strlen(str) > 80) |
233 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
234 else | |
235 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
236 | |
237 switch (type) { | |
23077 | 238 case GTK_MB_FATAL: |
33538 | 239 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
240 gtk_widget_hide(WarningPixmap); | |
241 gtk_widget_show(ErrorPixmap); | |
242 break; | |
243 | |
23077 | 244 case GTK_MB_ERROR: |
33538 | 245 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
246 gtk_widget_hide(WarningPixmap); | |
247 gtk_widget_show(ErrorPixmap); | |
248 break; | |
249 | |
23077 | 250 case GTK_MB_WARNING: |
33538 | 251 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
252 gtk_widget_show(WarningPixmap); | |
253 gtk_widget_hide(ErrorPixmap); | |
254 break; | |
255 } | |
256 | |
257 gtk_widget_show(MessageBox); | |
258 gtkSetLayer(MessageBox); | |
259 | |
260 if (type == GTK_MB_FATAL) | |
261 while (MessageBox) | |
262 gtk_main_iteration_do(0); | |
23077 | 263 } |
264 | |
35643 | 265 /** |
266 * @brief Set the layer for a GTK window. | |
267 * | |
268 * @param window pointer to a GtkWindow widget | |
269 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
270 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
271 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
272 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
273 gtkActive(window); |
33538 | 274 } |
275 | |
35643 | 276 /** |
277 * @brief Activate a GTK window, i.e. raise it to the top. | |
278 * | |
279 * @param window pointer to a GtkWindow widget | |
280 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
281 void gtkActive(GtkWidget *window) |
33538 | 282 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
283 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 284 } |
285 | |
33538 | 286 void gtkShow(int type, char *param) |
23077 | 287 { |
33538 | 288 switch (type) { |
289 case evEqualizer: | |
290 ShowEqualizer(); | |
291 gtkSetLayer(Equalizer); | |
292 break; | |
293 | |
294 case evSkinBrowser: | |
295 ShowSkinBrowser(); | |
296 | |
23077 | 297 // gtkClearList( SkinList ); |
33538 | 298 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
299 gtkFillSkinList(sbMPlayerDirInHome)) { | |
300 gtkSetDefaultToCList(SkinList, param); | |
301 gtk_clist_sort(GTK_CLIST(SkinList)); | |
302 gtk_widget_show(SkinBrowser); | |
303 gtkSetLayer(SkinBrowser); | |
304 } else { | |
305 gtk_widget_destroy(SkinBrowser); | |
306 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
307 } | |
308 | |
23077 | 309 break; |
33538 | 310 |
311 case evPreferences: | |
23077 | 312 ShowPreferences(); |
313 break; | |
33538 | 314 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
315 case evPlaylist: |
23077 | 316 ShowPlayList(); |
33538 | 317 gtkSetLayer(PlayList); |
23077 | 318 break; |
33538 | 319 |
320 case evLoad: | |
321 ShowFileSelect(fsVideoSelector, 0); | |
322 gtkSetLayer(fsFileSelect); | |
23077 | 323 break; |
33538 | 324 |
325 case evLoadSubtitle: | |
326 ShowFileSelect(fsSubtitleSelector, 0); | |
327 gtkSetLayer(fsFileSelect); | |
23077 | 328 break; |
33538 | 329 |
330 case evLoadAudioFile: | |
331 ShowFileSelect(fsAudioSelector, 0); | |
332 gtkSetLayer(fsFileSelect); | |
333 break; | |
334 | |
335 case evAbout: | |
336 ShowAboutBox(); | |
337 gtkSetLayer(About); | |
23077 | 338 break; |
33538 | 339 |
34333 | 340 case ivShowPopUpMenu: |
33538 | 341 gtkPopupMenu = evNone; |
342 gtkPopupMenuParam = 0; | |
343 | |
344 if (PopUpMenu) { | |
345 gtk_widget_hide(PopUpMenu); | |
346 gtk_widget_destroy(PopUpMenu); | |
347 } | |
348 | |
349 PopUpMenu = create_PopUpMenu(); | |
350 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); | |
23077 | 351 break; |
33538 | 352 |
34333 | 353 case ivHidePopUpMenu: |
33538 | 354 |
355 if (PopUpMenu) { | |
356 gtk_widget_hide(PopUpMenu); | |
357 gtk_widget_destroy(PopUpMenu); | |
358 PopUpMenu = NULL; | |
359 } | |
360 | |
23077 | 361 break; |
33538 | 362 |
34329 | 363 case evLoadURL: |
33538 | 364 ShowURLDialogBox(); |
365 gtkSetLayer(URL); | |
366 break; | |
367 } | |
23077 | 368 } |