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