Mercurial > mplayer.hg
annotate gui/ui/actions.c @ 35432:a545e4994460
Check return value to avoid segmentation fault.
author | ib |
---|---|
date | Fri, 30 Nov 2012 12:22:45 +0000 |
parents | 20c90da2ba0d |
children | 208bfdd26819 |
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 <string.h> | |
21 | |
33556 | 22 #include "actions.h" |
32881 | 23 #include "gmplayer.h" |
24 #include "gui/app.h" | |
35429 | 25 #include "gui/gui.h" |
32881 | 26 #include "gui/interface.h" |
27 #include "gui/skin/font.h" | |
28 #include "gui/skin/skin.h" | |
33742
e1539e14d60f
Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents:
33740
diff
changeset
|
29 #include "gui/util/list.h" |
33739 | 30 #include "gui/util/mem.h" |
33737 | 31 #include "gui/util/string.h" |
32881 | 32 #include "gui/wm/wsxdnd.h" |
33 #include "widgets.h" | |
23077 | 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" |
32881 | 37 #include "input/input.h" |
35431 | 38 #include "libmpdemux/demuxer.h" |
30653
3d23e24c5c60
Declare externally used variables from vd.c as extern in vd.h.
diego
parents:
29263
diff
changeset
|
39 #include "libmpcodecs/vd.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
40 #include "libvo/video_out.h" |
32881 | 41 #include "mp_core.h" |
23077 | 42 |
33555 | 43 void uiFullScreen(void) |
23077 | 44 { |
33960 | 45 if (!guiInfo.VideoWindow) |
32881 | 46 return; |
47 | |
34697 | 48 wsFullScreen(&guiApp.videoWindow); |
23077 | 49 |
34697 | 50 vo_fs = guiApp.videoWindow.isFullScreen; |
23077 | 51 |
34697 | 52 wsSetLayer(wsDisplay, guiApp.mainWindow.WindowID, guiApp.videoWindow.isFullScreen); |
32881 | 53 |
33555 | 54 if (guiApp.menuIsPresent) |
34697 | 55 wsSetLayer(wsDisplay, guiApp.menuWindow.WindowID, guiApp.videoWindow.isFullScreen); |
32881 | 56 |
33555 | 57 if (guiInfo.Playing) |
34697 | 58 wsSetBackgroundRGB(&guiApp.videoWindow, 0, 0, 0); |
32881 | 59 else |
34697 | 60 wsSetBackgroundRGB(&guiApp.videoWindow, guiApp.video.R, guiApp.video.G, guiApp.video.B); |
23077 | 61 } |
62 | |
33555 | 63 void uiPlay(void) |
23077 | 64 { |
34401
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
65 if (guiInfo.Playing == GUI_PLAY) |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
66 return; |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
67 |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
68 if (guiInfo.StreamType != STREAMTYPE_CDDA && |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
69 guiInfo.StreamType != STREAMTYPE_VCD && |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
70 guiInfo.StreamType != STREAMTYPE_DVD && |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
71 (!guiInfo.Filename || (guiInfo.Filename[0] == 0))) |
32881 | 72 return; |
23077 | 73 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
74 if (guiInfo.Playing == GUI_PAUSE) { |
33555 | 75 uiPause(); |
32881 | 76 return; |
77 } | |
78 | |
33731
81f71d910333
Cosmetic: Change prefix for symbolic constants from GMP to GUI.
ib
parents:
33725
diff
changeset
|
79 gui(GUI_SET_STATE, (void *)GUI_PLAY); |
34697 | 80 uiVideoRender = 0; |
81 wsSetBackgroundRGB(&guiApp.videoWindow, 0, 0, 0); | |
35357
80fe9ad7f318
Pass guiApp's wsTWindow parameters always by reference (if possible).
ib
parents:
34697
diff
changeset
|
82 wsClearWindow(&guiApp.videoWindow); |
23077 | 83 } |
84 | |
33555 | 85 void uiPause(void) |
23077 | 86 { |
33555 | 87 if (!guiInfo.Playing) |
32881 | 88 return; |
89 | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
90 if (guiInfo.Playing == GUI_PLAY) { |
32881 | 91 mp_cmd_t *cmd = calloc(1, sizeof(*cmd)); |
35432 | 92 if (cmd) { |
32881 | 93 cmd->id = MP_CMD_PAUSE; |
94 cmd->name = strdup("pause"); | |
95 mp_input_queue_cmd(cmd); | |
35432 | 96 } |
32881 | 97 } else |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
98 guiInfo.Playing = GUI_PLAY; |
23077 | 99 } |
100 | |
33555 | 101 void uiState(void) |
32881 | 102 { |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
103 if (guiInfo.Playing == GUI_STOP || guiInfo.Playing == GUI_PAUSE) { |
33978 | 104 btnSet(evPlaySwitchToPause, btnReleased); |
105 btnSet(evPauseSwitchToPlay, btnDisabled); | |
32881 | 106 } else { |
33978 | 107 btnSet(evPlaySwitchToPause, btnDisabled); |
108 btnSet(evPauseSwitchToPlay, btnReleased); | |
32881 | 109 } |
23077 | 110 } |
111 | |
33555 | 112 void uiRelSeek(float sec) |
32881 | 113 { |
32971 | 114 rel_seek_secs = sec; |
32881 | 115 abs_seek_pos = 0; |
116 } | |
117 | |
33555 | 118 void uiAbsSeek(float percent) |
32881 | 119 { |
32971 | 120 rel_seek_secs = percent / 100.0; |
35431 | 121 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR; |
23077 | 122 } |
123 | |
33555 | 124 void uiChangeSkin(char *name) |
23077 | 125 { |
32893 | 126 int prev, bprev; |
32881 | 127 |
33555 | 128 prev = guiApp.menuIsPresent; |
129 bprev = guiApp.playbarIsPresent; | |
32881 | 130 |
131 mainVisible = 0; | |
132 | |
32893 | 133 if (skinRead(name) != 0) { |
134 if (skinRead(skinName) != 0) { | |
32894 | 135 mainVisible = 1; |
136 return; | |
32893 | 137 } |
32881 | 138 } |
139 | |
34684 | 140 /* reload menu window */ |
23077 | 141 |
33555 | 142 if (prev && guiApp.menuIsPresent) { |
143 free(menuDrawBuffer); | |
144 menuDrawBuffer = calloc(1, guiApp.menu.Bitmap.ImageSize); | |
32881 | 145 |
33555 | 146 if (!menuDrawBuffer) { |
33530 | 147 gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_NEMDB); |
33768 | 148 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
32881 | 149 } |
23077 | 150 |
33555 | 151 wsResizeWindow(&guiApp.menuWindow, guiApp.menu.width, guiApp.menu.height); |
152 wsResizeImage(&guiApp.menuWindow, guiApp.menu.width, guiApp.menu.height); | |
153 wsSetShape(&guiApp.menuWindow, guiApp.menu.Mask.Image); | |
154 wsVisibleWindow(&guiApp.menuWindow, wsHideWindow); | |
32881 | 155 } else |
33555 | 156 uiMenuInit(); |
32881 | 157 |
34697 | 158 /* reload video window */ |
23077 | 159 |
34697 | 160 if (guiApp.video.Bitmap.Image) |
161 wsResizeImage(&guiApp.videoWindow, guiApp.video.Bitmap.Width, guiApp.video.Bitmap.Height); | |
32881 | 162 |
34697 | 163 if (!guiApp.videoWindow.isFullScreen && !guiInfo.Playing) { |
164 wsResizeWindow(&guiApp.videoWindow, guiApp.video.width, guiApp.video.height); | |
165 wsMoveWindow(&guiApp.videoWindow, False, guiApp.video.x, guiApp.video.y); | |
32881 | 166 } |
167 | |
34697 | 168 if (guiApp.video.Bitmap.Image) |
169 wsConvert(&guiApp.videoWindow, guiApp.video.Bitmap.Image); | |
23077 | 170 |
33555 | 171 if (!guiInfo.Playing) { |
34697 | 172 uiVideoRender = 1; |
173 wsSetBackgroundRGB(&guiApp.videoWindow, guiApp.video.R, guiApp.video.G, guiApp.video.B); | |
35357
80fe9ad7f318
Pass guiApp's wsTWindow parameters always by reference (if possible).
ib
parents:
34697
diff
changeset
|
174 wsClearWindow(&guiApp.videoWindow); |
34697 | 175 wsPostRedisplay(&guiApp.videoWindow); |
32881 | 176 } |
177 | |
34684 | 178 /* reload playbar */ |
32881 | 179 |
180 if (bprev) | |
33555 | 181 wsDestroyWindow(&guiApp.playbarWindow); |
32881 | 182 |
33555 | 183 uiPlaybarInit(); |
23077 | 184 |
34684 | 185 /* reload main window */ |
32881 | 186 |
33555 | 187 free(mainDrawBuffer); |
188 mainDrawBuffer = calloc(1, guiApp.main.Bitmap.ImageSize); | |
23077 | 189 |
33555 | 190 if (!mainDrawBuffer) { |
33530 | 191 gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_NEMDB); |
33768 | 192 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
32881 | 193 } |
23077 | 194 |
33555 | 195 wsDestroyWindow(&guiApp.mainWindow); |
32881 | 196 |
33555 | 197 wsCreateWindow(&guiApp.mainWindow, guiApp.main.x, guiApp.main.y, guiApp.main.width, guiApp.main.height, wsNoBorder, wsShowMouseCursor | wsHandleMouseButton | wsHandleMouseMove, wsShowFrame | wsMaxSize | wsHideWindow, "MPlayer"); |
198 wsCreateImage(&guiApp.mainWindow, guiApp.main.Bitmap.Width, guiApp.main.Bitmap.Height); | |
199 wsSetShape(&guiApp.mainWindow, guiApp.main.Mask.Image); | |
200 wsSetIcon(wsDisplay, guiApp.mainWindow.WindowID, &guiIcon); | |
23077 | 201 |
33555 | 202 guiApp.mainWindow.ReDraw = (void *)uiMainDraw; |
203 guiApp.mainWindow.MouseHandler = uiMainMouseHandle; | |
204 guiApp.mainWindow.KeyHandler = uiMainKeyHandle; | |
205 guiApp.mainWindow.DandDHandler = uiDandDHandler; | |
32881 | 206 |
33555 | 207 wsXDNDMakeAwareness(&guiApp.mainWindow); |
23077 | 208 |
33555 | 209 if (!guiApp.mainDecoration) |
210 wsWindowDecoration(&guiApp.mainWindow, 0); | |
32881 | 211 |
33555 | 212 wsVisibleWindow(&guiApp.mainWindow, wsShowWindow); |
32881 | 213 mainVisible = 1; |
214 | |
33555 | 215 btnModify(evSetVolume, guiInfo.Volume); |
216 btnModify(evSetBalance, guiInfo.Balance); | |
217 btnModify(evSetMoviePosition, guiInfo.Position); | |
34697 | 218 btnSet(evFullScreen, (guiApp.videoWindow.isFullScreen ? btnPressed : btnReleased)); |
23077 | 219 |
34697 | 220 wsSetLayer(wsDisplay, guiApp.mainWindow.WindowID, guiApp.videoWindow.isFullScreen); |
221 wsSetLayer(wsDisplay, guiApp.menuWindow.WindowID, guiApp.videoWindow.isFullScreen); | |
32881 | 222 } |
223 | |
33555 | 224 void uiSetFileName(char *dir, char *name, int type) |
32881 | 225 { |
226 if (!dir) | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
227 setdup(&guiInfo.Filename, name); |
32881 | 228 else |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
229 setddup(&guiInfo.Filename, dir, name); |
23077 | 230 |
34064 | 231 filename = guiInfo.Filename; |
34399
f2c03009068d
Don't explicitly set stream type if the type doesn't change.
ib
parents:
34387
diff
changeset
|
232 |
f2c03009068d
Don't explicitly set stream type if the type doesn't change.
ib
parents:
34387
diff
changeset
|
233 if (type != SAME_STREAMTYPE) |
34400 | 234 guiInfo.StreamType = type; |
34064 | 235 |
33897 | 236 nfree(guiInfo.AudioFilename); |
237 nfree(guiInfo.SubtitleFilename); | |
23077 | 238 } |
239 | |
33555 | 240 void uiCurr(void) |
23077 | 241 { |
32881 | 242 plItem *curr; |
23077 | 243 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
244 if (guiInfo.Playing == GUI_PAUSE) |
32881 | 245 return; |
23077 | 246 |
33555 | 247 switch (guiInfo.StreamType) { |
34387 | 248 case STREAMTYPE_CDDA: |
34077 | 249 case STREAMTYPE_VCD: |
250 case STREAMTYPE_DVD: | |
32881 | 251 break; |
252 | |
253 default: | |
254 | |
34663 | 255 curr = listMgr(PLAYLIST_ITEM_GET_CURR, 0); |
32881 | 256 |
257 if (curr) { | |
33555 | 258 uiSetFileName(curr->path, curr->name, STREAMTYPE_FILE); |
35430
2d55540614a9
Move uiProcessNextInPlaylist to the guiInfo structure.
ib
parents:
35429
diff
changeset
|
259 guiInfo.PlaylistNext = 0; |
32881 | 260 break; |
261 } | |
262 | |
263 return; | |
264 } | |
265 | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
266 if (guiInfo.Playing == GUI_PLAY) |
33555 | 267 uiEventHandling(evPlay, 0); |
23077 | 268 } |
269 | |
33555 | 270 void uiPrev(void) |
23077 | 271 { |
35426 | 272 int stop = 0; |
32881 | 273 plItem *prev; |
274 | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
275 if (guiInfo.Playing == GUI_PAUSE) |
32881 | 276 return; |
277 | |
33555 | 278 switch (guiInfo.StreamType) { |
34387 | 279 case STREAMTYPE_CDDA: |
35426 | 280 |
34387 | 281 if (--guiInfo.Track == 0) { |
282 guiInfo.Track = 1; | |
283 stop = 1; | |
284 } | |
35426 | 285 |
34387 | 286 break; |
287 | |
34077 | 288 case STREAMTYPE_VCD: |
35426 | 289 |
34077 | 290 if (--guiInfo.Track == 1) { |
291 guiInfo.Track = 2; | |
292 stop = 1; | |
293 } | |
35426 | 294 |
34077 | 295 break; |
296 | |
32881 | 297 case STREAMTYPE_DVD: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
298 |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
299 if (--guiInfo.Chapter == 0) { |
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
300 guiInfo.Chapter = 1; |
32881 | 301 |
35428 | 302 if (--guiInfo.Track == 0) { |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
303 guiInfo.Track = 1; |
32881 | 304 stop = 1; |
305 } | |
306 } | |
307 | |
308 break; | |
309 | |
310 default: | |
311 | |
34663 | 312 prev = listMgr(PLAYLIST_ITEM_GET_PREV, 0); |
32881 | 313 |
314 if (prev) { | |
33555 | 315 uiSetFileName(prev->path, prev->name, STREAMTYPE_FILE); |
35430
2d55540614a9
Move uiProcessNextInPlaylist to the guiInfo structure.
ib
parents:
35429
diff
changeset
|
316 guiInfo.PlaylistNext = (guiInfo.Playing ? 0 : 1); |
33898 | 317 guiInfo.Track--; |
32881 | 318 break; |
319 } | |
320 | |
321 return; | |
322 } | |
323 | |
324 if (stop) | |
33555 | 325 uiEventHandling(evStop, 0); |
32881 | 326 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
327 if (guiInfo.Playing == GUI_PLAY) |
33555 | 328 uiEventHandling(evPlay, 0); |
23077 | 329 } |
330 | |
33555 | 331 void uiNext(void) |
23077 | 332 { |
32881 | 333 int stop = 0; |
334 plItem *next; | |
23077 | 335 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
336 if (guiInfo.Playing == GUI_PAUSE) |
32881 | 337 return; |
338 | |
33555 | 339 switch (guiInfo.StreamType) { |
34387 | 340 case STREAMTYPE_CDDA: |
35425 | 341 case STREAMTYPE_VCD: |
34387 | 342 |
343 if (++guiInfo.Track > guiInfo.Tracks) { | |
344 guiInfo.Track = guiInfo.Tracks; | |
345 stop = 1; | |
346 } | |
347 | |
348 break; | |
349 | |
32881 | 350 case STREAMTYPE_DVD: |
351 | |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
352 if (guiInfo.Chapter++ == guiInfo.Chapters) { |
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
353 guiInfo.Chapter = 1; |
32881 | 354 |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
355 if (++guiInfo.Track > guiInfo.Tracks) { |
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
356 guiInfo.Track = guiInfo.Tracks; |
32881 | 357 stop = 1; |
358 } | |
359 } | |
360 | |
361 break; | |
362 | |
363 default: | |
364 | |
34663 | 365 next = listMgr(PLAYLIST_ITEM_GET_NEXT, 0); |
32881 | 366 |
367 if (next) { | |
33555 | 368 uiSetFileName(next->path, next->name, STREAMTYPE_FILE); |
35430
2d55540614a9
Move uiProcessNextInPlaylist to the guiInfo structure.
ib
parents:
35429
diff
changeset
|
369 guiInfo.PlaylistNext = (guiInfo.Playing ? 0 : 1); |
33898 | 370 guiInfo.Track++; |
32881 | 371 break; |
372 } | |
373 | |
374 return; | |
375 } | |
376 | |
377 if (stop) | |
33555 | 378 uiEventHandling(evStop, 0); |
32881 | 379 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
380 if (guiInfo.Playing == GUI_PLAY) |
33555 | 381 uiEventHandling(evPlay, 0); |
23077 | 382 } |