Mercurial > mplayer.hg
annotate gui/ui/widgets.c @ 35138:f5f583024549
Save poor users from my configure hack (r35227).
author | cehoyos |
---|---|
date | Sat, 06 Oct 2012 04:48:58 +0000 |
parents | bdf54c7f4eb6 |
children | 3e8dcfa3ceef |
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 |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
67 static const char 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 | |
34684 | 72 /* init & close gtk */ |
23077 | 73 |
33529 | 74 guiIcon_t guiIcon; |
23077 | 75 |
34780 | 76 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
34480 | 77 { |
78 GdkPixbuf *pixbuf; | |
79 guchar *data; | |
80 int csize, i; | |
81 | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
82 pixbuf = gtk_icon_theme_load_icon(theme, gui_icon_name, size, 0, NULL); |
34480 | 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 | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
108 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, gui_icon_name, size); |
34480 | 109 |
34684 | 110 /* start up GTK which realizes the pixmaps */ |
34480 | 111 gtk_main_iteration_do(FALSE); |
34780 | 112 |
113 return (pixbuf != NULL); | |
34480 | 114 } |
115 | |
33538 | 116 void gtkInit(void) |
23077 | 117 { |
34480 | 118 int argc = 0; |
33538 | 119 char *arg[3], **argv = arg; |
34480 | 120 GtkIconTheme *theme; |
33538 | 121 GdkPixmap *gdkIcon; |
122 GdkBitmap *gdkIconMask; | |
33465 | 123 |
33538 | 124 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 125 |
33538 | 126 arg[argc++] = GMPlayer; |
33465 | 127 |
33538 | 128 if (mDisplayName) { // MPlayer option '-display' was given |
129 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
130 arg[argc++] = mDisplayName; // to open the requested display for the GUI, too. | |
131 } | |
33465 | 132 |
27343 | 133 #ifdef CONFIG_GTK2 |
33538 | 134 gtk_disable_setlocale(); |
23077 | 135 #endif |
33528 | 136 |
33538 | 137 gtk_init(&argc, &argv); |
138 | |
34480 | 139 theme = gtk_icon_theme_get_default(); |
33542 | 140 |
34780 | 141 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 142 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
143 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 144 } |
33542 | 145 |
34780 | 146 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 147 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
148 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 149 } |
23077 | 150 |
34480 | 151 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
152 | |
33538 | 153 gtkInitialized = 1; |
154 } | |
23077 | 155 |
33538 | 156 void gtkAddIcon(GtkWidget *window) |
157 { | |
158 wsSetIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); | |
159 } | |
23077 | 160 |
33538 | 161 void gtkClearList(GtkWidget *list) |
162 { | |
163 gtk_clist_clear(GTK_CLIST(list)); | |
23077 | 164 } |
165 | |
33538 | 166 int gtkFindCList(GtkWidget *list, char *item) |
23077 | 167 { |
33538 | 168 gint j; |
169 gchar *tmpstr; | |
170 | |
171 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
172 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
173 | |
174 if (!strcmp(tmpstr, item)) | |
175 return j; | |
176 } | |
177 | |
178 return -1; | |
23077 | 179 } |
180 | |
33538 | 181 void gtkSetDefaultToCList(GtkWidget *list, char *item) |
23077 | 182 { |
33538 | 183 gint i; |
184 | |
185 if ((i = gtkFindCList(list, item)) > -1) | |
186 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
23077 | 187 } |
188 | |
33538 | 189 void gtkEventHandling(void) |
23077 | 190 { |
33538 | 191 int i; |
192 | |
193 for (i = 0; i < 25; i++) | |
194 gtk_main_iteration_do(0); | |
23077 | 195 } |
196 | |
34684 | 197 /* funcs */ |
23077 | 198 |
33538 | 199 void gtkMessageBox(int type, const gchar *str) |
23077 | 200 { |
33538 | 201 if (!gtkInitialized) |
202 return; | |
203 | |
204 ShowMessageBox(str); | |
205 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
206 | |
207 /* enable linewrapping by alex */ | |
23077 | 208 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 209 if (strlen(str) > 80) |
210 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
211 else | |
212 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
213 | |
214 switch (type) { | |
23077 | 215 case GTK_MB_FATAL: |
33538 | 216 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
217 gtk_widget_hide(WarningPixmap); | |
218 gtk_widget_show(ErrorPixmap); | |
219 break; | |
220 | |
23077 | 221 case GTK_MB_ERROR: |
33538 | 222 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
223 gtk_widget_hide(WarningPixmap); | |
224 gtk_widget_show(ErrorPixmap); | |
225 break; | |
226 | |
23077 | 227 case GTK_MB_WARNING: |
33538 | 228 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
229 gtk_widget_show(WarningPixmap); | |
230 gtk_widget_hide(ErrorPixmap); | |
231 break; | |
232 } | |
233 | |
234 gtk_widget_show(MessageBox); | |
235 gtkSetLayer(MessageBox); | |
236 | |
237 if (type == GTK_MB_FATAL) | |
238 while (MessageBox) | |
239 gtk_main_iteration_do(0); | |
23077 | 240 } |
241 | |
33538 | 242 void gtkSetLayer(GtkWidget *wdg) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
243 { |
34697 | 244 wsSetLayer(gdk_display, GDK_WINDOW_XWINDOW(wdg->window), guiApp.videoWindow.isFullScreen); |
33538 | 245 gtkActive(wdg); |
246 } | |
247 | |
248 void gtkActive(GtkWidget *wdg) | |
249 { | |
33990
3a93b9227b01
Cosmetic: Rename wsMoveTopWindow() wsRaiseWindowTop().
ib
parents:
33572
diff
changeset
|
250 wsRaiseWindowTop(gdk_display, GDK_WINDOW_XWINDOW(wdg->window)); |
23077 | 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 | |
23077 | 264 // gtkClearList( SkinList ); |
33538 | 265 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
266 gtkFillSkinList(sbMPlayerDirInHome)) { | |
267 gtkSetDefaultToCList(SkinList, param); | |
268 gtk_clist_sort(GTK_CLIST(SkinList)); | |
269 gtk_widget_show(SkinBrowser); | |
270 gtkSetLayer(SkinBrowser); | |
271 } else { | |
272 gtk_widget_destroy(SkinBrowser); | |
273 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
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: |
23077 | 283 ShowPlayList(); |
33538 | 284 gtkSetLayer(PlayList); |
23077 | 285 break; |
33538 | 286 |
287 case evLoad: | |
288 ShowFileSelect(fsVideoSelector, 0); | |
289 gtkSetLayer(fsFileSelect); | |
23077 | 290 break; |
33538 | 291 |
292 case evLoadSubtitle: | |
293 ShowFileSelect(fsSubtitleSelector, 0); | |
294 gtkSetLayer(fsFileSelect); | |
23077 | 295 break; |
33538 | 296 |
297 case evLoadAudioFile: | |
298 ShowFileSelect(fsAudioSelector, 0); | |
299 gtkSetLayer(fsFileSelect); | |
300 break; | |
301 | |
302 case evAbout: | |
303 ShowAboutBox(); | |
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 | |
316 PopUpMenu = create_PopUpMenu(); | |
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: |
33538 | 331 ShowURLDialogBox(); |
332 gtkSetLayer(URL); | |
333 break; | |
334 } | |
23077 | 335 } |