Mercurial > mplayer.hg
comparison gui/dialog/dialog.c @ 35529:8ad4d2fb46e8
Rebuild GUI directory structure.
Rename and move ui/widgets.* to dialog/dialog.*.
author | ib |
---|---|
date | Thu, 06 Dec 2012 15:16:38 +0000 |
parents | gui/ui/widgets.c@3c901704a27c |
children | 46b3d0bb76e0 |
comparison
equal
deleted
inserted
replaced
35528:ab07b17fddfb | 35529:8ad4d2fb46e8 |
---|---|
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 */ | |
18 | |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
21 #include <stdint.h> | |
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 | |
36 #include "config.h" | |
37 #include "help_mp.h" | |
38 #include "mp_msg.h" | |
39 #include "libavutil/intreadwrite.h" | |
40 #include "libvo/x11_common.h" | |
41 | |
42 #include "dialog.h" | |
43 #include "gui/app/app.h" | |
44 #include "gui/app/gui.h" | |
45 #include "gui/interface.h" | |
46 #include "gui/wm/ws.h" | |
47 | |
48 #include "gui/ui/actions.h" | |
49 #include "fileselect.h" | |
50 | |
51 GtkWidget *PopUpMenu = NULL; | |
52 | |
53 GtkWidget *WarningPixmap; | |
54 GtkWidget *ErrorPixmap; | |
55 | |
56 int gtkPopupMenu = 0; | |
57 int gtkPopupMenuParam = 0; | |
58 int gtkInitialized = False; | |
59 | |
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" | |
68 | |
69 static const char gui_icon_name[] = "mplayer"; | |
70 | |
71 #define THRESHOLD 128 // transparency values equal to or above this will become | |
72 // opaque, all values below this will become transparent | |
73 | |
74 /* init & close gtk */ | |
75 | |
76 guiIcon_t guiIcon; | |
77 | |
78 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) | |
79 { | |
80 GdkPixbuf *pixbuf; | |
81 guchar *data; | |
82 int csize, i; | |
83 | |
84 pixbuf = gtk_icon_theme_load_icon(theme, gui_icon_name, size, 0, NULL); | |
85 | |
86 if (pixbuf) | |
87 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
88 | |
89 if (pixbuf && | |
90 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
91 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
92 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
93 csize = guiIcon.collection_size; | |
94 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
95 | |
96 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
97 | |
98 if (guiIcon.collection) { | |
99 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
100 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
101 | |
102 data = gdk_pixbuf_get_pixels(pixbuf); | |
103 | |
104 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
105 guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB | |
106 } | |
107 | |
108 g_object_unref(pixbuf); | |
109 } else | |
110 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, gui_icon_name, size); | |
111 | |
112 /* start up GTK which realizes the pixmaps */ | |
113 gtk_main_iteration_do(FALSE); | |
114 | |
115 return (pixbuf != NULL); | |
116 } | |
117 | |
118 void gtkInit(void) | |
119 { | |
120 int argc = 0; | |
121 char *arg[3], **argv = arg; | |
122 GtkIconTheme *theme; | |
123 GdkPixmap *gdkIcon; | |
124 GdkBitmap *gdkIconMask; | |
125 | |
126 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); | |
127 | |
128 arg[argc++] = GMPlayer; | |
129 | |
130 if (mDisplayName) { // MPlayer option '-display' was given | |
131 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
132 arg[argc++] = mDisplayName; // to open the requested display for the GUI, too. | |
133 } | |
134 | |
135 #ifdef CONFIG_GTK2 | |
136 gtk_disable_setlocale(); | |
137 #endif | |
138 | |
139 gtk_init(&argc, &argv); | |
140 | |
141 theme = gtk_icon_theme_get_default(); | |
142 | |
143 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { | |
144 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); | |
145 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
146 } | |
147 | |
148 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { | |
149 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); | |
150 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
151 } | |
152 | |
153 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); | |
154 | |
155 gtkInitialized = True; | |
156 } | |
157 | |
158 void gtkAddIcon(GtkWidget *window) | |
159 { | |
160 wsSetIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); | |
161 } | |
162 | |
163 void gtkClearList(GtkWidget *list) | |
164 { | |
165 gtk_clist_clear(GTK_CLIST(list)); | |
166 } | |
167 | |
168 int gtkFindCList(GtkWidget *list, char *item) | |
169 { | |
170 gint j; | |
171 gchar *tmpstr; | |
172 | |
173 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
174 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
175 | |
176 if (!strcmp(tmpstr, item)) | |
177 return j; | |
178 } | |
179 | |
180 return -1; | |
181 } | |
182 | |
183 void gtkSetDefaultToCList(GtkWidget *list, char *item) | |
184 { | |
185 gint i; | |
186 | |
187 if ((i = gtkFindCList(list, item)) > -1) | |
188 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
189 } | |
190 | |
191 void gtkEventHandling(void) | |
192 { | |
193 int i; | |
194 | |
195 for (i = 0; i < 25; i++) | |
196 gtk_main_iteration_do(0); | |
197 } | |
198 | |
199 /* funcs */ | |
200 | |
201 void gtkMessageBox(int type, const gchar *str) | |
202 { | |
203 if (!gtkInitialized) | |
204 return; | |
205 | |
206 ShowMessageBox(str); | |
207 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
208 | |
209 /* enable linewrapping by alex */ | |
210 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; | |
211 if (strlen(str) > 80) | |
212 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
213 else | |
214 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
215 | |
216 switch (type) { | |
217 case GTK_MB_FATAL: | |
218 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); | |
219 gtk_widget_hide(WarningPixmap); | |
220 gtk_widget_show(ErrorPixmap); | |
221 break; | |
222 | |
223 case GTK_MB_ERROR: | |
224 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); | |
225 gtk_widget_hide(WarningPixmap); | |
226 gtk_widget_show(ErrorPixmap); | |
227 break; | |
228 | |
229 case GTK_MB_WARNING: | |
230 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); | |
231 gtk_widget_show(WarningPixmap); | |
232 gtk_widget_hide(ErrorPixmap); | |
233 break; | |
234 } | |
235 | |
236 gtk_widget_show(MessageBox); | |
237 gtkSetLayer(MessageBox); | |
238 | |
239 if (type == GTK_MB_FATAL) | |
240 while (MessageBox) | |
241 gtk_main_iteration_do(0); | |
242 } | |
243 | |
244 void gtkSetLayer(GtkWidget *wdg) | |
245 { | |
246 wsSetLayer(gdk_display, GDK_WINDOW_XWINDOW(wdg->window), guiApp.videoWindow.isFullScreen); | |
247 gtkActive(wdg); | |
248 } | |
249 | |
250 void gtkActive(GtkWidget *wdg) | |
251 { | |
252 wsRaiseWindowTop(gdk_display, GDK_WINDOW_XWINDOW(wdg->window)); | |
253 } | |
254 | |
255 void gtkShow(int type, char *param) | |
256 { | |
257 switch (type) { | |
258 case evEqualizer: | |
259 ShowEqualizer(); | |
260 gtkSetLayer(Equalizer); | |
261 break; | |
262 | |
263 case evSkinBrowser: | |
264 ShowSkinBrowser(); | |
265 | |
266 // gtkClearList( SkinList ); | |
267 if (gtkFillSkinList(sbMPlayerPrefixDir) && | |
268 gtkFillSkinList(sbMPlayerDirInHome)) { | |
269 gtkSetDefaultToCList(SkinList, param); | |
270 gtk_clist_sort(GTK_CLIST(SkinList)); | |
271 gtk_widget_show(SkinBrowser); | |
272 gtkSetLayer(SkinBrowser); | |
273 } else { | |
274 gtk_widget_destroy(SkinBrowser); | |
275 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
276 } | |
277 | |
278 break; | |
279 | |
280 case evPreferences: | |
281 ShowPreferences(); | |
282 break; | |
283 | |
284 case evPlaylist: | |
285 ShowPlayList(); | |
286 gtkSetLayer(PlayList); | |
287 break; | |
288 | |
289 case evLoad: | |
290 ShowFileSelect(fsVideoSelector, 0); | |
291 gtkSetLayer(fsFileSelect); | |
292 break; | |
293 | |
294 case evLoadSubtitle: | |
295 ShowFileSelect(fsSubtitleSelector, 0); | |
296 gtkSetLayer(fsFileSelect); | |
297 break; | |
298 | |
299 case evLoadAudioFile: | |
300 ShowFileSelect(fsAudioSelector, 0); | |
301 gtkSetLayer(fsFileSelect); | |
302 break; | |
303 | |
304 case evAbout: | |
305 ShowAboutBox(); | |
306 gtkSetLayer(About); | |
307 break; | |
308 | |
309 case ivShowPopUpMenu: | |
310 gtkPopupMenu = evNone; | |
311 gtkPopupMenuParam = 0; | |
312 | |
313 if (PopUpMenu) { | |
314 gtk_widget_hide(PopUpMenu); | |
315 gtk_widget_destroy(PopUpMenu); | |
316 } | |
317 | |
318 PopUpMenu = create_PopUpMenu(); | |
319 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); | |
320 break; | |
321 | |
322 case ivHidePopUpMenu: | |
323 | |
324 if (PopUpMenu) { | |
325 gtk_widget_hide(PopUpMenu); | |
326 gtk_widget_destroy(PopUpMenu); | |
327 PopUpMenu = NULL; | |
328 } | |
329 | |
330 break; | |
331 | |
332 case evLoadURL: | |
333 ShowURLDialogBox(); | |
334 gtkSetLayer(URL); | |
335 break; | |
336 } | |
337 } |