Mercurial > mplayer.hg
annotate gui/ui/widgets.c @ 34507:582ca9169495
Fix 32-bit png playback with current FFmpeg.
author | cehoyos |
---|---|
date | Tue, 24 Jan 2012 18:11:10 +0000 |
parents | 887c198b5b78 |
children | 04feb00f91be |
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> | |
21 | |
22 #include <sys/types.h> | |
23 #include <sys/stat.h> | |
24 #include <sys/wait.h> | |
25 #include <unistd.h> | |
26 #include <string.h> | |
27 #include <signal.h> | |
28 | |
29 #include <gdk/gdkprivate.h> | |
30 #include <gdk/gdkkeysyms.h> | |
31 #include <gdk/gdkx.h> | |
32 #include <gdk/gdk.h> | |
33 #include <gtk/gtk.h> | |
34 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
35 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
36 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "mp_msg.h" |
33542 | 38 #include "libavutil/intreadwrite.h" |
33465 | 39 #include "libvo/x11_common.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
40 |
23077 | 41 #include "widgets.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
42 #include "gui/app.h" |
33466 | 43 #include "gui/interface.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
44 #include "gui/wm/ws.h" |
23077 | 45 |
33556 | 46 #include "actions.h" |
33572 | 47 #include "gtk/fileselect.h" |
23077 | 48 |
33538 | 49 GtkWidget *PopUpMenu = NULL; |
23077 | 50 |
33538 | 51 GtkWidget *WarningPixmap; |
52 GtkWidget *ErrorPixmap; | |
23077 | 53 |
33538 | 54 int gtkPopupMenu = 0; |
23077 | 55 int gtkPopupMenuParam = 0; |
33538 | 56 int gtkInitialized = 0; |
23077 | 57 |
33572 | 58 #include "gtk/skinbrowser.h" |
59 #include "gtk/playlist.h" | |
60 #include "gtk/msgbox.h" | |
23077 | 61 #include "gtk/about.h" |
33572 | 62 #include "gtk/preferences.h" |
63 #include "gtk/menu.h" | |
64 #include "gtk/url.h" | |
65 #include "gtk/equalizer.h" | |
23077 | 66 |
34480 | 67 #define GUI_ICON_NAME "mplayer" |
23077 | 68 |
33542 | 69 #define THRESHOLD 128 // transparency values equal to or above this will become |
70 // opaque, all values below this will become transparent | |
71 | |
23077 | 72 // --- init & close gtk |
73 | |
33529 | 74 guiIcon_t guiIcon; |
23077 | 75 |
34480 | 76 static void gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
77 { | |
78 GdkPixbuf *pixbuf; | |
79 guchar *data; | |
80 int csize, i; | |
81 | |
82 pixbuf = gtk_icon_theme_load_icon(theme, GUI_ICON_NAME, size, 0, NULL); | |
83 | |
84 if (pixbuf) | |
85 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
86 | |
87 if (pixbuf && | |
88 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
89 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
90 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
91 csize = guiIcon.collection_size; | |
92 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
93 | |
94 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
95 | |
96 if (guiIcon.collection) { | |
97 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
98 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
99 | |
100 data = gdk_pixbuf_get_pixels(pixbuf); | |
101 | |
102 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
103 guiIcon.collection[i] = (data[3] << 24) | AV_RB24(data); // RGBA -> ARGB | |
104 } | |
105 | |
106 g_object_unref(pixbuf); | |
107 } else | |
34481 | 108 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, GUI_ICON_NAME, size); |
34480 | 109 |
110 // start up GTK which realizes the pixmaps | |
111 gtk_main_iteration_do(FALSE); | |
112 } | |
113 | |
33538 | 114 void gtkInit(void) |
23077 | 115 { |
34480 | 116 int argc = 0; |
33538 | 117 char *arg[3], **argv = arg; |
34480 | 118 GtkIconTheme *theme; |
33538 | 119 GdkPixmap *gdkIcon; |
120 GdkBitmap *gdkIconMask; | |
33465 | 121 |
33538 | 122 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 123 |
33538 | 124 arg[argc++] = GMPlayer; |
33465 | 125 |
33538 | 126 if (mDisplayName) { // MPlayer option '-display' was given |
127 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
128 arg[argc++] = mDisplayName; // to open the requested display for the GUI, too. | |
129 } | |
33465 | 130 |
27343 | 131 #ifdef CONFIG_GTK2 |
33538 | 132 gtk_disable_setlocale(); |
23077 | 133 #endif |
33528 | 134 |
33538 | 135 gtk_init(&argc, &argv); |
136 | |
34480 | 137 theme = gtk_icon_theme_get_default(); |
33542 | 138 |
34480 | 139 gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask); |
140 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); | |
141 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
33542 | 142 |
34480 | 143 gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask); |
33538 | 144 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
145 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
23077 | 146 |
34480 | 147 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
148 | |
33538 | 149 gtkInitialized = 1; |
150 } | |
23077 | 151 |
33538 | 152 void gtkAddIcon(GtkWidget *window) |
153 { | |
154 wsSetIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); | |
155 } | |
23077 | 156 |
33538 | 157 void gtkClearList(GtkWidget *list) |
158 { | |
159 gtk_clist_clear(GTK_CLIST(list)); | |
23077 | 160 } |
161 | |
33538 | 162 int gtkFindCList(GtkWidget *list, char *item) |
23077 | 163 { |
33538 | 164 gint j; |
165 gchar *tmpstr; | |
166 | |
167 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
168 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
169 | |
170 if (!strcmp(tmpstr, item)) | |
171 return j; | |
172 } | |
173 | |
174 return -1; | |
23077 | 175 } |
176 | |
33538 | 177 void gtkSetDefaultToCList(GtkWidget *list, char *item) |
23077 | 178 { |
33538 | 179 gint i; |
180 | |
181 if ((i = gtkFindCList(list, item)) > -1) | |
182 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
23077 | 183 } |
184 | |
33538 | 185 void gtkEventHandling(void) |
23077 | 186 { |
33538 | 187 int i; |
188 | |
189 for (i = 0; i < 25; i++) | |
190 gtk_main_iteration_do(0); | |
23077 | 191 } |
192 | |
193 // --- funcs | |
194 | |
33538 | 195 void gtkMessageBox(int type, const gchar *str) |
23077 | 196 { |
33538 | 197 if (!gtkInitialized) |
198 return; | |
199 | |
200 ShowMessageBox(str); | |
201 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
202 | |
203 /* enable linewrapping by alex */ | |
23077 | 204 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 205 if (strlen(str) > 80) |
206 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
207 else | |
208 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
209 | |
210 switch (type) { | |
23077 | 211 case GTK_MB_FATAL: |
33538 | 212 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
213 gtk_widget_hide(WarningPixmap); | |
214 gtk_widget_show(ErrorPixmap); | |
215 break; | |
216 | |
23077 | 217 case GTK_MB_ERROR: |
33538 | 218 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
219 gtk_widget_hide(WarningPixmap); | |
220 gtk_widget_show(ErrorPixmap); | |
221 break; | |
222 | |
23077 | 223 case GTK_MB_WARNING: |
33538 | 224 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
225 gtk_widget_show(WarningPixmap); | |
226 gtk_widget_hide(ErrorPixmap); | |
227 break; | |
228 } | |
229 | |
230 gtk_widget_show(MessageBox); | |
231 gtkSetLayer(MessageBox); | |
232 | |
233 if (type == GTK_MB_FATAL) | |
234 while (MessageBox) | |
235 gtk_main_iteration_do(0); | |
23077 | 236 } |
237 | |
33538 | 238 void gtkSetLayer(GtkWidget *wdg) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
239 { |
33555 | 240 wsSetLayer(gdk_display, GDK_WINDOW_XWINDOW(wdg->window), guiApp.subWindow.isFullScreen); |
33538 | 241 gtkActive(wdg); |
242 } | |
243 | |
244 void gtkActive(GtkWidget *wdg) | |
245 { | |
33990
3a93b9227b01
Cosmetic: Rename wsMoveTopWindow() wsRaiseWindowTop().
ib
parents:
33572
diff
changeset
|
246 wsRaiseWindowTop(gdk_display, GDK_WINDOW_XWINDOW(wdg->window)); |
23077 | 247 } |
248 | |
33538 | 249 void gtkShow(int type, char *param) |
23077 | 250 { |
33538 | 251 switch (type) { |
252 case evEqualizer: | |
253 ShowEqualizer(); | |
254 gtkSetLayer(Equalizer); | |
255 break; | |
256 | |
257 case evSkinBrowser: | |
258 ShowSkinBrowser(); | |
259 | |
23077 | 260 // gtkClearList( SkinList ); |
33538 | 261 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
262 gtkFillSkinList(sbMPlayerDirInHome)) { | |
263 gtkSetDefaultToCList(SkinList, param); | |
264 gtk_clist_sort(GTK_CLIST(SkinList)); | |
265 gtk_widget_show(SkinBrowser); | |
266 gtkSetLayer(SkinBrowser); | |
267 } else { | |
268 gtk_widget_destroy(SkinBrowser); | |
269 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
270 } | |
271 | |
23077 | 272 break; |
33538 | 273 |
274 case evPreferences: | |
23077 | 275 ShowPreferences(); |
276 break; | |
33538 | 277 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
278 case evPlaylist: |
23077 | 279 ShowPlayList(); |
33538 | 280 gtkSetLayer(PlayList); |
23077 | 281 break; |
33538 | 282 |
283 case evLoad: | |
284 ShowFileSelect(fsVideoSelector, 0); | |
285 gtkSetLayer(fsFileSelect); | |
23077 | 286 break; |
33538 | 287 |
288 case evLoadSubtitle: | |
289 ShowFileSelect(fsSubtitleSelector, 0); | |
290 gtkSetLayer(fsFileSelect); | |
23077 | 291 break; |
33538 | 292 |
293 case evLoadAudioFile: | |
294 ShowFileSelect(fsAudioSelector, 0); | |
295 gtkSetLayer(fsFileSelect); | |
296 break; | |
297 | |
298 case evAbout: | |
299 ShowAboutBox(); | |
300 gtkSetLayer(About); | |
23077 | 301 break; |
33538 | 302 |
34333 | 303 case ivShowPopUpMenu: |
33538 | 304 gtkPopupMenu = evNone; |
305 gtkPopupMenuParam = 0; | |
306 | |
307 if (PopUpMenu) { | |
308 gtk_widget_hide(PopUpMenu); | |
309 gtk_widget_destroy(PopUpMenu); | |
310 } | |
311 | |
312 PopUpMenu = create_PopUpMenu(); | |
313 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); | |
23077 | 314 break; |
33538 | 315 |
34333 | 316 case ivHidePopUpMenu: |
33538 | 317 |
318 if (PopUpMenu) { | |
319 gtk_widget_hide(PopUpMenu); | |
320 gtk_widget_destroy(PopUpMenu); | |
321 PopUpMenu = NULL; | |
322 } | |
323 | |
23077 | 324 break; |
33538 | 325 |
34329 | 326 case evLoadURL: |
33538 | 327 ShowURLDialogBox(); |
328 gtkSetLayer(URL); | |
329 break; | |
330 } | |
23077 | 331 } |