1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.23 2003/05/13 19:25:59 asmax 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()
102 if( Transition && IS_WINNT )
104 SetTransparency( 0 );
105 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
106 Fade( NormalAlpha, Transition );
111 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
117 //---------------------------------------------------------------------------
118 void SkinWindow::Close()
123 if( Transition && IS_WINNT )
124 Fade( 0, Transition, WINDOW_HIDE );
127 OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 );
129 //---------------------------------------------------------------------------
130 void SkinWindow::Show()
136 //---------------------------------------------------------------------------
137 void SkinWindow::Hide()
145 OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 );
147 //---------------------------------------------------------------------------
148 void SkinWindow::Fade( int To, int Time, unsigned int evt )
150 // No fading effect on win9x
156 StartTime = OSAPI_GetTime();
157 EndTime = StartTime + Time;
160 OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
164 //---------------------------------------------------------------------------
165 bool SkinWindow::ProcessEvent( Event *evt )
168 unsigned int msg = evt->GetMessage();
169 unsigned int p1 = evt->GetParam1();
170 int p2 = evt->GetParam2();
172 // Send event to control if necessary
173 if( msg > VLC_CONTROL )
175 for( i = 0; i < ControlList.size(); i++ )
176 ControlList[i]->GenericProcessEvent( evt );
180 // Message processing
184 if( Lock == p2 && ChangeAlpha( OSAPI_GetTime() ) )
186 OSAPI_PostMessage( this, WINDOW_FADE, p1, p2 );
190 OSAPI_PostMessage( this, p1, 0, 0 );
195 WindowManualMoveInit();
198 Fade( MoveAlpha, 100 );
246 MouseMove( -1, -1, 0 );
254 // OS specific messages processing
255 return ProcessOSEvent( evt );
258 //---------------------------------------------------------------------------
259 bool SkinWindow::ChangeAlpha( int time )
264 if( time >= EndTime )
268 SetTransparency( EndAlpha );
274 int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
275 / (EndTime - StartTime);
276 if( NewAlpha != Alpha )
277 SetTransparency( NewAlpha );
278 if( NewAlpha == EndAlpha )
287 //---------------------------------------------------------------------------
288 void SkinWindow::RefreshImage( int x, int y, int w, int h )
292 // Create Bitmap Buffer
293 Graphics *Buffer = (Graphics *)new OSGraphics( p_intf, w, h, this );
294 // Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
296 // Draw every control
297 for( i = 0; i < ControlList.size(); i++ )
298 ControlList[i]->Draw( x, y, w, h, Buffer );
300 // Copy buffer in Image
301 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
306 //---------------------------------------------------------------------------
307 void SkinWindow::Refresh( int x, int y, int w, int h )
312 // Refresh buffer image
313 RefreshImage( x, y, w, h );
318 // And copy buffer to window
319 RefreshFromImage( x, y, w, h );
322 //---------------------------------------------------------------------------
323 void SkinWindow::RefreshAll()
325 Refresh( 0, 0, Width, Height );
327 //---------------------------------------------------------------------------
328 void SkinWindow::MouseDown( int x, int y, int button )
330 // Checking event in controls
331 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
333 if( ControlList[i]->MouseDown( x, y, button ) )
340 //---------------------------------------------------------------------------
341 void SkinWindow::MouseMove( int x, int y, int button )
345 // Move window if selected !
351 // Checking event in controls
352 for( i = ControlList.size() - 1; i >= 0 ; i-- )
354 ControlList[i]->MouseMove( x, y, button );
357 // Checking help text
358 for( i = ControlList.size() - 1; i >= 0 ; i-- )
360 if( ControlList[i]->MouseOver( x, y ) )
362 if( ControlList[i]->SendNewHelpText() )
369 // If help text not found, change it to ""
372 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
373 ->PostTextMessage( " " );
376 // Checking for change in Tool Tip
377 for( i = ControlList.size() - 1; i >= 0 ; i-- )
379 if( ControlList[i]->ToolTipTest( x, y ) )
383 // If no change, delete tooltip text
385 ChangeToolTipText( "none" );
387 //---------------------------------------------------------------------------
388 void SkinWindow::MouseUp( int x, int y, int button )
392 // Move window if selected !
396 Fade( NormalAlpha, 100 );
398 // Check for magnetism
399 p_intf->p_sys->p_theme->CheckAnchors();
401 WindowMoving = false;
404 // Checking event in controls
405 for( i = ControlList.size() - 1; i >= 0 ; i-- )
407 if( ControlList[i]->MouseUp( x, y, button ) )
413 //---------------------------------------------------------------------------
414 void SkinWindow::MouseDblClick( int x, int y, int button )
418 // Checking event in controls
419 for( i = ControlList.size() - 1; i >= 0 ; i-- )
421 if( ControlList[i]->MouseDblClick( x, y, button ) )
425 //---------------------------------------------------------------------------
426 void SkinWindow::MouseScroll( int x, int y, int direction )
428 // Checking event in controls
429 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
431 if( ControlList[i]->MouseScroll( x, y, direction ) )
437 //---------------------------------------------------------------------------
438 void SkinWindow::Init()
440 // Get size of window
443 // Refresh Image buffer
444 RefreshImage( 0, 0, Width, Height );
446 // Move window as it hasn't been moved yet
449 //---------------------------------------------------------------------------
450 void SkinWindow::ReSize()
459 // Search size of window and negative values to move all
460 for( i = 0; i < ControlList.size(); i++ )
462 #define min(a,b) ((a)<(b))?(a):(b)
463 #define max(a,b) ((a)>(b))?(a):(b)
464 w = max( w, ControlList[i]->Left + ControlList[i]->Width );
465 h = max( h, ControlList[i]->Top + ControlList[i]->Height );
466 MinX = min( MinX, ControlList[i]->Left );
467 MinY = min( MinY, ControlList[i]->Top );
480 // Move window and controls !
481 if( MinX != 0 || MinY != 0 )
483 Move( Left + MinX, Top + MinY );
484 for( i = 0; i < ControlList.size(); i++ )
485 ControlList[i]->MoveRelative( -MinX, -MinY );
488 // Create buffer image for repainting if size has changed
489 if( w != Width || h != Height )
491 // Change image buffer
493 delete (OSGraphics *)Image;
494 Image = (Graphics *)new OSGraphics( p_intf, w, h, this );
495 // Image = (Graphics *)new OSGraphics( w, h, this );
501 //---------------------------------------------------------------------------
502 void SkinWindow::GetSize( int &w, int &h )
507 //---------------------------------------------------------------------------
508 void SkinWindow::GetPos( int &x, int &y )
513 //---------------------------------------------------------------------------