Mercurial > mplayer.hg
annotate gui/mplayer/pb.c @ 33107:eda3df3e4a9d
Prevent an out-of-bounds array access.
This out-of-bounds array access was of not much effect until r33190, because
the variables falsely changed (set to 1) were either almost always unused
(the last member of the mainItems array) or variable menuIsPresent which only
has effect if there is a menu present (in which case it is set anyway).
With r33190 the wItem (and thus the guiItems) structure size changed and now
variables were accessed whose changings have visible effect. After releasing
the moved main (or playbar) window, the IndexOfItems values got destroyed and
items disappeared.
author | ib |
---|---|
date | Sun, 03 Apr 2011 14:24:36 +0000 |
parents | 21e0de9c355f |
children | 5450a92ac4bd |
rev | line source |
---|---|
26458 | 1 /* |
2 * main window | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
23077 | 20 |
21 #include <stdlib.h> | |
22 #include <stdio.h> | |
23 #include <inttypes.h> | |
24 #include <sys/stat.h> | |
25 #include <unistd.h> | |
23305
22d3d12c6dfb
Include string.h for memcpy, fastmemcpy.h alone is not enough.
reimar
parents:
23077
diff
changeset
|
26 #include <string.h> |
23077 | 27 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
28 #include "config.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
29 #include "gui/app.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
30 #include "gui/skin/font.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
31 #include "gui/skin/skin.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
32 #include "gui/wm/ws.h" |
23077 | 33 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
34 #include "help_mp.h" |
33024 | 35 #include "mp_core.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
36 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "libvo/fastmemcpy.h" |
23077 | 38 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
39 #include "stream/stream.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
40 #include "mixer.h" |
32467 | 41 #include "sub/sub.h" |
23077 | 42 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
43 #include "libmpdemux/demuxer.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
44 #include "libmpdemux/stheader.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
45 #include "codec-cfg.h" |
23077 | 46 |
47 #include "gmplayer.h" | |
48 #include "play.h" | |
49 #include "widgets.h" | |
25603
01754b23193e
Rename common.[ch], there are too many files by that name.
diego
parents:
23457
diff
changeset
|
50 #include "gui_common.h" |
23077 | 51 |
28051 | 52 unsigned int GetTimerMS( void ); |
53 unsigned int GetTimer( void ); | |
23077 | 54 |
55 unsigned char * mplPBDrawBuffer = NULL; | |
56 int mplPBVisible = 0; | |
57 int mplPBLength = 0; | |
58 int mplPBFade = 0; | |
59 | |
30535
016e5fc1dead
GUI: Mark functions that are not used outside their files as static.
diego
parents:
29263
diff
changeset
|
60 static void mplPBDraw( void ) |
23077 | 61 { |
62 int x; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
63 |
23077 | 64 if ( !appMPlayer.subWindow.isFullScreen ) return; |
65 if ( !mplPBVisible || !appMPlayer.barIsPresent ) return; | |
66 | |
67 // appMPlayer.bar.x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ) / 2; | |
68 switch( appMPlayer.bar.x ) | |
69 { | |
70 case -1: x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ) / 2; break; | |
71 case -2: x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ); break; | |
72 default: x=appMPlayer.bar.x; | |
73 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
74 |
23077 | 75 switch ( mplPBFade ) |
76 { | |
77 case 1: // fade in | |
78 mplPBLength--; | |
79 if ( appMPlayer.subWindow.Height - appMPlayer.bar.height >= mplPBLength ) | |
80 { | |
81 mplPBLength=appMPlayer.subWindow.Height - appMPlayer.bar.height; | |
82 mplPBFade=0; | |
83 vo_mouse_autohide=0; | |
84 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
85 wsMoveWindow( &appMPlayer.barWindow,0,x,mplPBLength ); |
23077 | 86 break; |
87 case 2: // fade out | |
88 mplPBLength+=10; | |
89 if ( mplPBLength > appMPlayer.subWindow.Height ) | |
90 { | |
91 mplPBLength=appMPlayer.subWindow.Height; | |
92 mplPBFade=mplPBVisible=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
93 vo_mouse_autohide=1; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
94 wsVisibleWindow( &appMPlayer.barWindow,wsHideWindow ); |
23077 | 95 return; |
96 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
97 wsMoveWindow( &appMPlayer.barWindow,0,x,mplPBLength ); |
23077 | 98 break; |
99 } | |
100 | |
101 // --- render | |
102 if ( appMPlayer.barWindow.State == wsWindowExpose ) | |
103 { | |
104 btnModify( evSetMoviePosition,guiIntfStruct.Position ); | |
105 btnModify( evSetVolume,guiIntfStruct.Volume ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
106 |
23077 | 107 vo_mouse_autohide=0; |
108 | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23305
diff
changeset
|
109 fast_memcpy( mplPBDrawBuffer,appMPlayer.bar.Bitmap.Image,appMPlayer.bar.Bitmap.ImageSize ); |
32931
03b1051bed5c
Rename the 'NumberOf' members of the listItems structure.
ib
parents:
32919
diff
changeset
|
110 Render( &appMPlayer.barWindow,appMPlayer.barItems,appMPlayer.IndexOfBarItems,mplPBDrawBuffer,appMPlayer.bar.Bitmap.ImageSize ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
111 wsConvert( &appMPlayer.barWindow,mplPBDrawBuffer,appMPlayer.bar.Bitmap.ImageSize ); |
23077 | 112 } |
113 wsPutImage( &appMPlayer.barWindow ); | |
114 } | |
115 | |
30535
016e5fc1dead
GUI: Mark functions that are not used outside their files as static.
diego
parents:
29263
diff
changeset
|
116 static void mplPBMouseHandle( int Button, int X, int Y, int RX, int RY ) |
23077 | 117 { |
118 static int itemtype = 0; | |
119 int i; | |
120 wItem * item = NULL; | |
121 float value = 0.0f; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
122 |
23077 | 123 static int SelectedItem = -1; |
124 int currentselected = -1; | |
125 | |
32931
03b1051bed5c
Rename the 'NumberOf' members of the listItems structure.
ib
parents:
32919
diff
changeset
|
126 for ( i=0;i <= appMPlayer.IndexOfBarItems;i++ ) |
23077 | 127 if ( ( appMPlayer.barItems[i].pressed != btnDisabled )&& |
128 ( wgIsRect( X,Y,appMPlayer.barItems[i].x,appMPlayer.barItems[i].y,appMPlayer.barItems[i].x+appMPlayer.barItems[i].width,appMPlayer.barItems[i].y+appMPlayer.barItems[i].height ) ) ) | |
129 { currentselected=i; break; } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
130 |
23077 | 131 switch ( Button ) |
132 { | |
133 case wsPMMouseButton: | |
134 gtkShow( evHidePopUpMenu,NULL ); | |
135 mplShowMenu( RX,RY ); | |
136 break; | |
137 case wsRMMouseButton: | |
138 mplHideMenu( RX,RY,0 ); | |
139 break; | |
140 case wsRRMouseButton: | |
141 gtkShow( evShowPopUpMenu,NULL ); | |
142 break; | |
143 // --- | |
144 case wsPLMouseButton: | |
145 gtkShow( evHidePopUpMenu,NULL ); | |
146 SelectedItem=currentselected; | |
147 if ( SelectedItem == -1 ) break; // yeees, i'm move the fucking window | |
148 item=&appMPlayer.barItems[SelectedItem]; | |
149 itemtype=item->type; | |
150 item->pressed=btnPressed; | |
151 | |
152 switch( item->type ) | |
153 { | |
154 case itButton: | |
155 if ( ( SelectedItem > -1 ) && | |
32911 | 156 ( ( ( item->message == evPlaySwitchToPause && item->message == evPauseSwitchToPlay ) ) || |
157 ( ( item->message == evPauseSwitchToPlay && item->message == evPlaySwitchToPause ) ) ) ) | |
23077 | 158 { item->pressed=btnDisabled; } |
159 break; | |
160 } | |
161 | |
162 break; | |
163 case wsRLMouseButton: | |
33107 | 164 if ( SelectedItem != -1 ) // NOTE TO MYSELF: only if itButton, itHPotmeter or itVPotmeter |
165 { | |
23077 | 166 item=&appMPlayer.barItems[SelectedItem]; |
167 item->pressed=btnReleased; | |
33107 | 168 } |
23077 | 169 SelectedItem=-1; |
170 if ( currentselected == - 1 ) { itemtype=0; break; } | |
171 value=0; | |
172 | |
173 switch( itemtype ) | |
174 { | |
175 case itPotmeter: | |
176 case itHPotmeter: | |
32911 | 177 btnModify( item->message,(float)( X - item->x ) / item->width * 100.0f ); |
178 mplEventHandling( item->message,item->value ); | |
23077 | 179 value=item->value; |
180 break; | |
181 case itVPotmeter: | |
32911 | 182 btnModify( item->message, ( 1. - (float)( Y - item->y ) / item->height) * 100.0f ); |
183 mplEventHandling( item->message,item->value ); | |
23077 | 184 value=item->value; |
185 break; | |
186 } | |
32911 | 187 mplEventHandling( item->message,value ); |
23077 | 188 |
189 itemtype=0; | |
190 break; | |
191 // --- | |
192 case wsP5MouseButton: value=-2.5f; goto rollerhandled; | |
193 case wsP4MouseButton: value= 2.5f; | |
194 rollerhandled: | |
195 item=&appMPlayer.barItems[currentselected]; | |
196 if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) ) | |
197 { | |
198 item->value+=value; | |
32911 | 199 btnModify( item->message,item->value ); |
200 mplEventHandling( item->message,item->value ); | |
23077 | 201 } |
202 break; | |
203 // --- | |
204 case wsMoveMouse: | |
205 item=&appMPlayer.barItems[SelectedItem]; | |
206 switch ( itemtype ) | |
207 { | |
208 case itPRMButton: | |
209 mplMenuMouseHandle( X,Y,RX,RY ); | |
210 break; | |
211 case itPotmeter: | |
212 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
213 goto potihandled; | |
214 case itVPotmeter: | |
215 item->value=(1. - (float)( Y - item->y ) / item->height) * 100.0f; | |
216 goto potihandled; | |
217 case itHPotmeter: | |
218 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
219 potihandled: | |
220 if ( item->value > 100.0f ) item->value=100.0f; | |
221 if ( item->value < 0.0f ) item->value=0.0f; | |
32911 | 222 mplEventHandling( item->message,item->value ); |
23077 | 223 break; |
224 } | |
225 break; | |
226 } | |
227 } | |
228 | |
229 void mplPBShow( int x, int y ) | |
230 { | |
231 if ( !appMPlayer.barIsPresent || !gtkEnablePlayBar ) return; | |
232 if ( !appMPlayer.subWindow.isFullScreen ) return; | |
233 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
234 if ( y > appMPlayer.subWindow.Height - appMPlayer.bar.height ) |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
235 { |
23077 | 236 if ( !mplPBFade ) wsVisibleWindow( &appMPlayer.barWindow,wsShowWindow ); |
237 mplPBFade=1; mplPBVisible=1; wsPostRedisplay( &appMPlayer.barWindow ); | |
238 } | |
239 else if ( !mplPBFade ) mplPBFade=2; | |
240 } | |
241 | |
242 void mplPBInit( void ) | |
243 { | |
244 if ( !appMPlayer.barIsPresent ) return; | |
245 | |
246 gfree( (void**)&mplPBDrawBuffer ); | |
247 | |
248 if ( ( mplPBDrawBuffer = malloc( appMPlayer.bar.Bitmap.ImageSize ) ) == NULL ) | |
249 { | |
33024 | 250 gmp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_NEMDB ); |
251 exit_player( EXIT_ERROR ); | |
23077 | 252 } |
253 | |
254 appMPlayer.barWindow.Parent=appMPlayer.subWindow.WindowID; | |
255 wsCreateWindow( &appMPlayer.barWindow, | |
256 appMPlayer.bar.x,appMPlayer.bar.y,appMPlayer.bar.width,appMPlayer.bar.height, | |
257 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsHideFrame|wsHideWindow,"PlayBar" ); | |
258 | |
259 wsSetShape( &appMPlayer.barWindow,appMPlayer.bar.Mask.Image ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
260 |
23077 | 261 appMPlayer.barWindow.ReDraw=(void *)mplPBDraw; |
262 appMPlayer.barWindow.MouseHandler=mplPBMouseHandle; | |
263 appMPlayer.barWindow.KeyHandler=mplMainKeyHandle; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
264 |
23077 | 265 mplPBLength=appMPlayer.subWindow.Height; |
266 } |