1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.20 2003/04/28 00:18:27 ipkiss Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
32 #include "../controls/generic.h"
35 #include "../os_api.h"
37 #include "../os_graphics.h"
40 #include "skin_common.h"
45 //---------------------------------------------------------------------------
47 //---------------------------------------------------------------------------
48 SkinWindow::SkinWindow( intf_thread_t *_p_intf, int x, int y, bool visible,
49 int transition, int normalalpha, int movealpha, bool dragdrop )
53 // Set position parameters
62 Transition = transition;
65 NormalAlpha = normalalpha;
66 MoveAlpha = movealpha;
78 OnStartThemeVisible = visible;
86 //---------------------------------------------------------------------------
87 SkinWindow::~SkinWindow()
89 // Destroy the controls
90 for( unsigned int i = 0; i < ControlList.size(); i++ )
91 delete ControlList[i];
93 //---------------------------------------------------------------------------
94 void SkinWindow::Open()
101 if( Transition && IS_WINNT )
103 SetTransparency( 0 );
104 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
105 Fade( NormalAlpha, Transition );
109 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
112 //---------------------------------------------------------------------------
113 void SkinWindow::Close()
117 if( Transition && IS_WINNT )
118 Fade( 0, Transition, WINDOW_HIDE );
120 OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 );
122 //---------------------------------------------------------------------------
123 void SkinWindow::Show()
129 //---------------------------------------------------------------------------
130 void SkinWindow::Hide()
138 OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 );
140 //---------------------------------------------------------------------------
141 void SkinWindow::Fade( int To, int Time, unsigned int evt )
143 // No fading effect on win9x
148 StartTime = OSAPI_GetTime();
149 EndTime = StartTime + Time;
152 OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
155 //---------------------------------------------------------------------------
156 bool SkinWindow::ProcessEvent( Event *evt )
159 unsigned int msg = evt->GetMessage();
160 unsigned int p1 = evt->GetParam1();
161 int p2 = evt->GetParam2();
163 // Send event to control if necessary
164 if( msg > VLC_CONTROL )
166 for( i = 0; i < ControlList.size(); i++ )
167 ControlList[i]->GenericProcessEvent( evt );
171 // Message processing
175 if( Lock == p2 && ChangeAlpha( OSAPI_GetTime() ) )
177 OSAPI_PostMessage( this, WINDOW_FADE, p1, p2 );
181 OSAPI_PostMessage( this, p1, 0, 0 );
186 WindowManualMoveInit();
189 Fade( MoveAlpha, 100 );
237 MouseMove( -1, -1, 0 );
245 // OS specific messages processing
246 return ProcessOSEvent( evt );
249 //---------------------------------------------------------------------------
250 bool SkinWindow::ChangeAlpha( int time )
254 if( time >= EndTime )
258 SetTransparency( EndAlpha );
264 int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
265 / (EndTime - StartTime);
266 if( NewAlpha != Alpha )
267 SetTransparency( NewAlpha );
268 if( NewAlpha == EndAlpha )
276 //---------------------------------------------------------------------------
277 void SkinWindow::RefreshImage( int x, int y, int w, int h )
281 // Create Bitmap Buffer
282 Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
284 // Draw every control
285 for( i = 0; i < ControlList.size(); i++ )
286 ControlList[i]->Draw( x, y, w, h, Buffer );
288 // Copy buffer in Image
289 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
294 //---------------------------------------------------------------------------
295 void SkinWindow::Refresh( int x, int y, int w, int h )
300 // Refresh buffer image
301 RefreshImage( x, y, w, h );
306 // And copy buffer to window
307 RefreshFromImage( x, y, w, h );
310 //---------------------------------------------------------------------------
311 void SkinWindow::RefreshAll()
313 Refresh( 0, 0, Width, Height );
315 //---------------------------------------------------------------------------
316 void SkinWindow::MouseDown( int x, int y, int button )
318 // Checking event in controls
319 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
321 if( ControlList[i]->MouseDown( x, y, button ) )
328 //---------------------------------------------------------------------------
329 void SkinWindow::MouseMove( int x, int y, int button )
333 // Move window if selected !
339 // Checking event in controls
340 for( i = ControlList.size() - 1; i >= 0 ; i-- )
342 ControlList[i]->MouseMove( x, y, button );
345 // Checking help text
346 for( i = ControlList.size() - 1; i >= 0 ; i-- )
348 if( ControlList[i]->MouseOver( x, y ) )
350 if( ControlList[i]->SendNewHelpText() )
357 // If help text not found, change it to ""
360 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
361 ->PostTextMessage( " " );
364 // Checking for change in Tool Tip
365 for( i = ControlList.size() - 1; i >= 0 ; i-- )
367 if( ControlList[i]->ToolTipTest( x, y ) )
371 // If no change, delete tooltip text
373 ChangeToolTipText( "none" );
375 //---------------------------------------------------------------------------
376 void SkinWindow::MouseUp( int x, int y, int button )
380 // Move window if selected !
384 Fade( NormalAlpha, 100 );
386 // Check for magnetism
387 p_intf->p_sys->p_theme->CheckAnchors();
389 WindowMoving = false;
392 // Checking event in controls
393 for( i = ControlList.size() - 1; i >= 0 ; i-- )
395 if( ControlList[i]->MouseUp( x, y, button ) )
401 //---------------------------------------------------------------------------
402 void SkinWindow::MouseDblClick( int x, int y, int button )
406 // Checking event in controls
407 for( i = ControlList.size() - 1; i >= 0 ; i-- )
409 if( ControlList[i]->MouseDblClick( x, y, button ) )
413 //---------------------------------------------------------------------------
414 void SkinWindow::MouseScroll( int x, int y, int direction )
416 // Checking event in controls
417 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
419 if( ControlList[i]->MouseScroll( x, y, direction ) )
425 //---------------------------------------------------------------------------
426 void SkinWindow::Init()
428 // Get size of window
431 // Refresh Image buffer
432 RefreshImage( 0, 0, Width, Height );
434 // Move window as it hasn't been moved yet
437 //---------------------------------------------------------------------------
438 void SkinWindow::ReSize()
447 // Search size of window and negative values to move all
448 for( i = 0; i < ControlList.size(); i++ )
450 #define min(a,b) ((a)<(b))?(a):(b)
451 #define max(a,b) ((a)>(b))?(a):(b)
452 w = max( w, ControlList[i]->Left + ControlList[i]->Width );
453 h = max( h, ControlList[i]->Top + ControlList[i]->Height );
454 MinX = min( MinX, ControlList[i]->Left );
455 MinY = min( MinY, ControlList[i]->Top );
468 // Move window and controls !
469 if( MinX != 0 || MinY != 0 )
471 Move( Left + MinX, Top + MinY );
472 for( i = 0; i < ControlList.size(); i++ )
473 ControlList[i]->MoveRelative( -MinX, -MinY );
476 // Create buffer image for repainting if size has changed
477 if( w != Width || h != Height )
479 // Change image buffer
481 delete (OSGraphics *)Image;
482 Image = (Graphics *)new OSGraphics( w, h, this );
489 //---------------------------------------------------------------------------
490 void SkinWindow::GetSize( int &w, int &h )
495 //---------------------------------------------------------------------------
496 void SkinWindow::GetPos( int &x, int &y )
501 //---------------------------------------------------------------------------