Mercurial > mplayer.hg
annotate gui/ui/widgets.c @ 33556:520fb0f7544c
Rename GUI directory 'mplayer' and some files in it.
The directory 'mplayer' contains the files for the user interface and
has thus been renamed 'ui'.
Inside this directory the following files have been renamed to better
reflect their contents:
mw.c -> main.c
sw.c -> sub.c
pb.c -> playbar.c
gui_common.* -> render.*
play.* -> actions.*
author | ib |
---|---|
date | Sat, 18 Jun 2011 16:03:31 +0000 |
parents | gui/mplayer/widgets.c@c5a19bbeac2b |
children | d9b805602aa1 |
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" |
23077 | 47 #include "gtk/fs.h" |
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 |
58 #include "gtk/sb.h" | |
59 #include "gtk/pl.h" | |
60 #include "gtk/fs.h" | |
61 #include "gtk/mb.h" | |
62 #include "gtk/about.h" | |
63 #include "gtk/opts.h" | |
30531
704903d34069
Rename gui/mplayer/gtk/menu.[ch] --> gui/mplayer/gtk/gtkmenu.[ch].
diego
parents:
29263
diff
changeset
|
64 #include "gtk/gtk_menu.h" |
26137
02a08fffb1dc
Rename url.c/url.h to the less generic gtk_url.c/gtk_url.h.
diego
parents:
25962
diff
changeset
|
65 #include "gtk/gtk_url.h" |
23077 | 66 #include "gtk/eq.h" |
67 | |
33484
4f940d7917f0
Provide a desktop icon of reasonable size (48x48) and quality.
ib
parents:
33466
diff
changeset
|
68 #include "pixmaps/mplayer.xpm" |
23077 | 69 |
33542 | 70 #define THRESHOLD 128 // transparency values equal to or above this will become |
71 // opaque, all values below this will become transparent | |
72 | |
23077 | 73 // --- init & close gtk |
74 | |
33529 | 75 guiIcon_t guiIcon; |
23077 | 76 |
33538 | 77 void gtkInit(void) |
23077 | 78 { |
33542 | 79 int argc = 0, i; |
33538 | 80 char *arg[3], **argv = arg; |
33542 | 81 GdkPixbuf *pixbuf; |
33538 | 82 GdkPixmap *gdkIcon; |
83 GdkBitmap *gdkIconMask; | |
33542 | 84 guchar *data; |
33465 | 85 |
33538 | 86 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 87 |
33538 | 88 arg[argc++] = GMPlayer; |
33465 | 89 |
33538 | 90 if (mDisplayName) { // MPlayer option '-display' was given |
91 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
92 arg[argc++] = mDisplayName; // to open the requested display for the GUI, too. | |
93 } | |
33465 | 94 |
27343 | 95 #ifdef CONFIG_GTK2 |
33538 | 96 gtk_disable_setlocale(); |
23077 | 97 #endif |
33528 | 98 |
33538 | 99 gtk_init(&argc, &argv); |
100 | |
33542 | 101 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)mplayer_xpm); |
102 | |
103 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), &gdkIcon, &gdkIconMask, THRESHOLD); | |
104 | |
105 if (gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
106 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
107 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
108 guiIcon.collection_size = 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
109 | |
110 guiIcon.collection = malloc(guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
111 | |
112 if (guiIcon.collection) { | |
113 guiIcon.collection[0] = gdk_pixbuf_get_width(pixbuf); | |
114 guiIcon.collection[1] = gdk_pixbuf_get_height(pixbuf); | |
115 | |
116 data = gdk_pixbuf_get_pixels(pixbuf); | |
117 | |
118 for (i = 2; i < guiIcon.collection_size; data += 4, i++) | |
119 guiIcon.collection[i] = (data[3] << 24) | AV_RB24(data); // RGBA -> ARGB | |
120 } | |
33551
5d5f66b52c62
Add a warning message for unavailable or unusable icons.
ib
parents:
33542
diff
changeset
|
121 } else |
5d5f66b52c62
Add a warning message for unavailable or unusable icons.
ib
parents:
33542
diff
changeset
|
122 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, "mplayer"); |
23077 | 123 |
33538 | 124 // start up GTK which realizes the pixmaps |
125 gtk_main_iteration_do(FALSE); | |
126 | |
127 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); | |
128 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
23077 | 129 |
33538 | 130 gtkInitialized = 1; |
131 } | |
23077 | 132 |
33538 | 133 void gtkAddIcon(GtkWidget *window) |
134 { | |
135 wsSetIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); | |
136 } | |
23077 | 137 |
33538 | 138 void gtkClearList(GtkWidget *list) |
139 { | |
140 gtk_clist_clear(GTK_CLIST(list)); | |
23077 | 141 } |
142 | |
33538 | 143 int gtkFindCList(GtkWidget *list, char *item) |
23077 | 144 { |
33538 | 145 gint j; |
146 gchar *tmpstr; | |
147 | |
148 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
149 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
150 | |
151 if (!strcmp(tmpstr, item)) | |
152 return j; | |
153 } | |
154 | |
155 return -1; | |
23077 | 156 } |
157 | |
33538 | 158 void gtkSetDefaultToCList(GtkWidget *list, char *item) |
23077 | 159 { |
33538 | 160 gint i; |
161 | |
162 if ((i = gtkFindCList(list, item)) > -1) | |
163 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
23077 | 164 } |
165 | |
33538 | 166 void gtkEventHandling(void) |
23077 | 167 { |
33538 | 168 int i; |
169 | |
170 for (i = 0; i < 25; i++) | |
171 gtk_main_iteration_do(0); | |
23077 | 172 } |
173 | |
174 // --- funcs | |
175 | |
33538 | 176 void gtkMessageBox(int type, const gchar *str) |
23077 | 177 { |
33538 | 178 if (!gtkInitialized) |
179 return; | |
180 | |
181 ShowMessageBox(str); | |
182 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
183 | |
184 /* enable linewrapping by alex */ | |
23077 | 185 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 186 if (strlen(str) > 80) |
187 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
188 else | |
189 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
190 | |
191 switch (type) { | |
23077 | 192 case GTK_MB_FATAL: |
33538 | 193 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
194 gtk_widget_hide(WarningPixmap); | |
195 gtk_widget_show(ErrorPixmap); | |
196 break; | |
197 | |
23077 | 198 case GTK_MB_ERROR: |
33538 | 199 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
200 gtk_widget_hide(WarningPixmap); | |
201 gtk_widget_show(ErrorPixmap); | |
202 break; | |
203 | |
23077 | 204 case GTK_MB_WARNING: |
33538 | 205 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
206 gtk_widget_show(WarningPixmap); | |
207 gtk_widget_hide(ErrorPixmap); | |
208 break; | |
209 } | |
210 | |
211 gtk_widget_show(MessageBox); | |
212 gtkSetLayer(MessageBox); | |
213 | |
214 if (type == GTK_MB_FATAL) | |
215 while (MessageBox) | |
216 gtk_main_iteration_do(0); | |
23077 | 217 } |
218 | |
33538 | 219 void gtkSetLayer(GtkWidget *wdg) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
220 { |
33555 | 221 wsSetLayer(gdk_display, GDK_WINDOW_XWINDOW(wdg->window), guiApp.subWindow.isFullScreen); |
33538 | 222 gtkActive(wdg); |
223 } | |
224 | |
225 void gtkActive(GtkWidget *wdg) | |
226 { | |
227 wsMoveTopWindow(gdk_display, GDK_WINDOW_XWINDOW(wdg->window)); | |
23077 | 228 } |
229 | |
33538 | 230 void gtkShow(int type, char *param) |
23077 | 231 { |
33538 | 232 switch (type) { |
233 case evEqualizer: | |
234 ShowEqualizer(); | |
235 gtkSetLayer(Equalizer); | |
236 break; | |
237 | |
238 case evSkinBrowser: | |
239 ShowSkinBrowser(); | |
240 | |
23077 | 241 // gtkClearList( SkinList ); |
33538 | 242 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
243 gtkFillSkinList(sbMPlayerDirInHome)) { | |
244 gtkSetDefaultToCList(SkinList, param); | |
245 gtk_clist_sort(GTK_CLIST(SkinList)); | |
246 gtk_widget_show(SkinBrowser); | |
247 gtkSetLayer(SkinBrowser); | |
248 } else { | |
249 gtk_widget_destroy(SkinBrowser); | |
250 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
251 } | |
252 | |
23077 | 253 break; |
33538 | 254 |
255 case evPreferences: | |
23077 | 256 ShowPreferences(); |
257 break; | |
33538 | 258 |
259 case evPlayList: | |
23077 | 260 ShowPlayList(); |
33538 | 261 gtkSetLayer(PlayList); |
23077 | 262 break; |
33538 | 263 |
264 case evLoad: | |
265 ShowFileSelect(fsVideoSelector, 0); | |
266 gtkSetLayer(fsFileSelect); | |
23077 | 267 break; |
33538 | 268 |
269 case evFirstLoad: | |
270 ShowFileSelect(fsVideoSelector, 0); | |
271 gtkSetLayer(fsFileSelect); | |
23077 | 272 break; |
33538 | 273 |
274 case evLoadSubtitle: | |
275 ShowFileSelect(fsSubtitleSelector, 0); | |
276 gtkSetLayer(fsFileSelect); | |
23077 | 277 break; |
33538 | 278 |
279 case evLoadAudioFile: | |
280 ShowFileSelect(fsAudioSelector, 0); | |
281 gtkSetLayer(fsFileSelect); | |
282 break; | |
283 | |
284 case evAbout: | |
285 ShowAboutBox(); | |
286 gtkSetLayer(About); | |
23077 | 287 break; |
33538 | 288 |
289 case evShowPopUpMenu: | |
290 gtkPopupMenu = evNone; | |
291 gtkPopupMenuParam = 0; | |
292 | |
293 if (PopUpMenu) { | |
294 gtk_widget_hide(PopUpMenu); | |
295 gtk_widget_destroy(PopUpMenu); | |
296 } | |
297 | |
298 PopUpMenu = create_PopUpMenu(); | |
299 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); | |
23077 | 300 break; |
33538 | 301 |
302 case evHidePopUpMenu: | |
303 | |
304 if (PopUpMenu) { | |
305 gtk_widget_hide(PopUpMenu); | |
306 gtk_widget_destroy(PopUpMenu); | |
307 PopUpMenu = NULL; | |
308 } | |
309 | |
23077 | 310 break; |
33538 | 311 |
312 case evPlayNetwork: | |
313 ShowURLDialogBox(); | |
314 gtkSetLayer(URL); | |
315 break; | |
316 } | |
23077 | 317 } |