1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.30 2003/06/17 18:13:18 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"
46 //---------------------------------------------------------------------------
48 //---------------------------------------------------------------------------
49 SkinWindow::SkinWindow( intf_thread_t *_p_intf, int x, int y, bool visible,
50 int transition, int normalalpha, int movealpha, bool dragdrop )
54 // Set position parameters
63 Transition = transition;
66 NormalAlpha = normalalpha;
67 MoveAlpha = movealpha;
79 OnStartThemeVisible = visible;
87 //---------------------------------------------------------------------------
88 SkinWindow::~SkinWindow()
94 // Destroy the controls
95 for( unsigned int i = 0; i < ControlList.size(); i++ )
96 delete ControlList[i];
98 //---------------------------------------------------------------------------
99 void SkinWindow::Open()
107 if( Transition && IS_WINNT )
109 SetTransparency( 0 );
110 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
111 Fade( NormalAlpha, Transition );
116 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
122 //---------------------------------------------------------------------------
123 void SkinWindow::Close()
128 if( Transition && IS_WINNT )
129 Fade( 0, Transition, WINDOW_HIDE );
132 OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 );
134 //---------------------------------------------------------------------------
135 void SkinWindow::Show()
141 //---------------------------------------------------------------------------
142 void SkinWindow::Hide()
150 OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 );
152 //---------------------------------------------------------------------------
153 void SkinWindow::Fade( int To, int Time, unsigned int evt )
155 // No fading effect on win9x
161 StartTime = OSAPI_GetTime();
162 EndTime = StartTime + Time;
165 OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
169 //---------------------------------------------------------------------------
170 bool SkinWindow::ProcessEvent( Event *evt )
173 unsigned int msg = evt->GetMessage();
174 unsigned int p1 = evt->GetParam1();
175 int p2 = evt->GetParam2();
177 // Send event to control if necessary
178 if( msg > VLC_CONTROL )
180 for( i = 0; i < ControlList.size(); i++ )
181 ControlList[i]->GenericProcessEvent( evt );
185 // Message processing
189 if( Lock == p2 && ChangeAlpha( OSAPI_GetTime() ) )
191 OSAPI_PostMessage( this, WINDOW_FADE, p1, p2 );
195 OSAPI_PostMessage( this, p1, 0, 0 );
200 WindowManualMoveInit();
203 Fade( MoveAlpha, 100 );
251 MouseMove( -1, -1, 0 );
259 // OS specific messages processing
260 return ProcessOSEvent( evt );
263 //---------------------------------------------------------------------------
264 bool SkinWindow::ChangeAlpha( int time )
269 if( time >= EndTime )
273 SetTransparency( EndAlpha );
279 int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
280 / (EndTime - StartTime);
281 if( NewAlpha != Alpha )
282 SetTransparency( NewAlpha );
283 if( NewAlpha == EndAlpha )
292 //---------------------------------------------------------------------------
293 void SkinWindow::RefreshImage( int x, int y, int w, int h )
297 // Create Bitmap Buffer
298 Graphics *Buffer = (Graphics *)new OSGraphics( p_intf, w, h, this );
299 // Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
301 // Draw every control
302 for( i = 0; i < ControlList.size(); i++ )
303 ControlList[i]->Draw( x, y, w, h, Buffer );
305 // Copy buffer in Image
306 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
311 //---------------------------------------------------------------------------
312 void SkinWindow::Refresh( int x, int y, int w, int h )
317 // Refresh buffer image
318 RefreshImage( x, y, w, h );
323 // And copy buffer to window
324 RefreshFromImage( x, y, w, h );
326 //---------------------------------------------------------------------------
327 void SkinWindow::RefreshAll()
329 Refresh( 0, 0, Width, Height );
331 //---------------------------------------------------------------------------
332 void SkinWindow::MouseDown( int x, int y, int button )
334 // Checking event in controls
335 for( int i = ControlList.size() - 1; i >= 0; i-- )
337 if( ControlList[i]->IsVisible() &&
338 ControlList[i]->MouseDown( x, y, button ) )
340 msg_Dbg( p_intf, "Mouse down (ID=%s)",
341 ControlList[i]->GetId().c_str() );
346 //---------------------------------------------------------------------------
347 void SkinWindow::MouseMove( int x, int y, int button )
351 // Move window if selected !
357 // Checking event in controls
358 for( i = ControlList.size() - 1; i >= 0; i-- )
360 if( ControlList[i]->IsVisible() &&
361 ControlList[i]->MouseMove( x, y, button ) )
367 // Checking help text
368 for( i = ControlList.size() - 1; i >= 0; i-- )
370 if( ControlList[i]->IsVisible() && ControlList[i]->MouseOver( x, y ) )
372 ControlList[i]->SendNewHelpText();
377 // If help text not found, change it to ""
380 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
381 ->PostTextMessage( " " );
384 // Checking for change in Tool Tip
385 for( i = ControlList.size() - 1; i >= 0; i-- )
387 if( ControlList[i]->IsVisible() &&
388 ControlList[i]->ToolTipTest( x, y ) )
394 // If no change, delete tooltip text
396 ChangeToolTipText( "none" );
398 //---------------------------------------------------------------------------
399 void SkinWindow::MouseUp( int x, int y, int button )
403 // Move window if selected !
407 Fade( NormalAlpha, 100 );
409 // Check for magnetism
410 p_intf->p_sys->p_theme->CheckAnchors();
412 WindowMoving = false;
415 // Checking event in controls
416 for( i = ControlList.size() - 1; i >= 0; i-- )
418 if( ControlList[i]->IsVisible() &&
419 ControlList[i]->MouseUp( x, y, button ) )
421 msg_Dbg( p_intf, "Mouse up (ID=%s)",
422 ControlList[i]->GetId().c_str() );
427 if( i < 0 && button == MOUSE_RIGHT )
429 p_intf->p_sys->p_dialogs->ShowPopup();
432 //---------------------------------------------------------------------------
433 void SkinWindow::MouseDblClick( int x, int y, int button )
437 // Checking event in controls
438 for( i = ControlList.size() - 1; i >= 0; i-- )
440 if( ControlList[i]->IsVisible() &&
441 ControlList[i]->MouseDblClick( x, y, button ) )
443 msg_Dbg( p_intf, "Double click (ID=%s)",
444 ControlList[i]->GetId().c_str() );
448 //---------------------------------------------------------------------------
449 void SkinWindow::MouseScroll( int x, int y, int direction )
451 // Checking event in controls
452 for( int i = ControlList.size() - 1; i >= 0; i-- )
454 if( ControlList[i]->IsVisible() &&
455 ControlList[i]->MouseScroll( x, y, direction ) )
461 // Checking for change in Tool Tip
462 for( int i = ControlList.size() - 1; i >= 0; i-- )
464 if( ControlList[i]->IsVisible() &&
465 ControlList[i]->ToolTipTest( x, y ) )
472 //---------------------------------------------------------------------------
473 void SkinWindow::Init()
475 // Get size of window
478 // Refresh Image buffer
479 RefreshImage( 0, 0, Width, Height );
481 // Move window as it hasn't been moved yet
484 //---------------------------------------------------------------------------
485 void SkinWindow::ReSize()
494 // Search size of window and negative values to move all
495 for( i = 0; i < ControlList.size(); i++ )
497 #define min(a,b) ((a)<(b))?(a):(b)
498 #define max(a,b) ((a)>(b))?(a):(b)
499 w = max( w, ControlList[i]->GetLeft() + ControlList[i]->GetWidth() );
500 h = max( h, ControlList[i]->GetTop() + ControlList[i]->GetHeight() );
501 MinX = min( MinX, ControlList[i]->GetLeft() );
502 MinY = min( MinY, ControlList[i]->GetTop() );
515 // Move window and controls !
516 if( MinX != 0 || MinY != 0 )
518 Move( Left + MinX, Top + MinY );
519 for( i = 0; i < ControlList.size(); i++ )
520 ControlList[i]->MoveRelative( -MinX, -MinY );
523 // Create buffer image for repainting if size has changed
524 if( w != Width || h != Height )
526 // Change image buffer
528 delete (OSGraphics *)Image;
529 Image = (Graphics *)new OSGraphics( p_intf, w, h, this );
535 //---------------------------------------------------------------------------
536 void SkinWindow::GetSize( int &w, int &h )
541 //---------------------------------------------------------------------------
542 void SkinWindow::GetPos( int &x, int &y )
547 //---------------------------------------------------------------------------