* window.cpp: Window class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
- * $Id: window.cpp,v 1.14 2003/04/16 19:22:53 karibu Exp $
+ * $Id: window.cpp,v 1.31 2003/06/22 00:00:28 asmax Exp $
*
* Authors: Olivier Teulière <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr>
+ * Cyril Deguet <asmax@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
//--- SKIN ------------------------------------------------------------------
#include "anchor.h"
-#include "generic.h"
+#include "../controls/generic.h"
#include "window.h"
#include "event.h"
-#include "os_api.h"
+#include "../os_api.h"
#include "graphics.h"
-#include "os_graphics.h"
+#include "../os_graphics.h"
#include "banks.h"
#include "theme.h"
#include "skin_common.h"
+#include "dialogs.h"
#include <stdio.h>
//---------------------------------------------------------------------------
// Skinable Window
//---------------------------------------------------------------------------
-Window::Window( intf_thread_t *_p_intf, int x, int y, bool visible,
+SkinWindow::SkinWindow( intf_thread_t *_p_intf, int x, int y, bool visible,
int transition, int normalalpha, int movealpha, bool dragdrop )
{
p_intf = _p_intf;
ToolTipText = "none";
}
//---------------------------------------------------------------------------
-Window::~Window()
+SkinWindow::~SkinWindow()
{
+ if( Image )
+ {
+ delete Image;
+ }
// Destroy the controls
for( unsigned int i = 0; i < ControlList.size(); i++ )
delete ControlList[i];
}
//---------------------------------------------------------------------------
-void Window::Open()
+void SkinWindow::Open()
{
if( !Hidden )
return;
Changing = true;
- if( Transition )
+#ifdef WIN32
+ if( Transition && IS_WINNT )
{
SetTransparency( 0 );
OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
}
else
{
+#endif
OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
+#ifdef WIN32
}
+#endif
+
}
//---------------------------------------------------------------------------
-void Window::Close()
+void SkinWindow::Close()
{
Changing = true;
- if( Transition )
+#ifdef WIN32
+ if( Transition && IS_WINNT )
Fade( 0, Transition, WINDOW_HIDE );
else
+#endif
OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 );
}
//---------------------------------------------------------------------------
-void Window::Show()
+void SkinWindow::Show()
{
Changing = false;
Hidden = false;
OSShow( true );
}
//---------------------------------------------------------------------------
-void Window::Hide()
+void SkinWindow::Hide()
{
if( Hidden )
return;
OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 );
}
//---------------------------------------------------------------------------
-void Window::Fade( int To, int Time, unsigned int evt )
+void SkinWindow::Fade( int To, int Time, unsigned int evt )
{
- StartAlpha = Alpha;
- EndAlpha = To;
- StartTime = OSAPI_GetTime();
- EndTime = StartTime + Time;
- Lock++;
+ // No fading effect on win9x
+#ifdef WIN32
+ if( IS_WINNT )
+ {
+ StartAlpha = Alpha;
+ EndAlpha = To;
+ StartTime = OSAPI_GetTime();
+ EndTime = StartTime + Time;
+ Lock++;
- OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
+ OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
+ }
+#endif
}
//---------------------------------------------------------------------------
-bool Window::ProcessEvent( Event *evt )
+bool SkinWindow::ProcessEvent( Event *evt )
{
unsigned int i;
unsigned int msg = evt->GetMessage();
}
}
//---------------------------------------------------------------------------
-bool Window::ChangeAlpha( int time )
+bool SkinWindow::ChangeAlpha( int time )
{
- if( time >= EndTime )
+#ifdef WIN32
+ if( IS_WINNT )
{
- if( Lock )
+ if( time >= EndTime )
{
- SetTransparency( EndAlpha );
- Lock = 0;
+ if( Lock )
+ {
+ SetTransparency( EndAlpha );
+ Lock = 0;
+ }
+ return false;
}
- return false;
- }
- int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
- / (EndTime - StartTime);
- if( NewAlpha != Alpha )
- SetTransparency( NewAlpha );
- if( NewAlpha == EndAlpha )
- {
- Lock = 0;
- return false;
+ int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
+ / (EndTime - StartTime);
+ if( NewAlpha != Alpha )
+ SetTransparency( NewAlpha );
+ if( NewAlpha == EndAlpha )
+ {
+ Lock = 0;
+ return false;
+ }
}
+#endif
return true;
}
//---------------------------------------------------------------------------
-void Window::RefreshImage( int x, int y, int w, int h )
+void SkinWindow::RefreshImage( int x, int y, int w, int h )
{
unsigned int i;
-fprintf(stderr, "refr %d %d %d %d\n", x,y,w,h);
// Create Bitmap Buffer
- Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
+ Graphics *Buffer = (Graphics *)new OSGraphics( p_intf, w, h, this );
+// Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
// Draw every control
- for( i = 0; i < ControlList.size(); i++ )
- ControlList[i]->Draw( x, y, w, h, Buffer );
+ for( i = 0; i < ControlList.size(); i++ )
+ ControlList[i]->Draw( x, y, w, h, Buffer );
// Copy buffer in Image
Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
delete Buffer;
}
//---------------------------------------------------------------------------
-void Window::Refresh( int x, int y, int w, int h )
+void SkinWindow::Refresh( int x, int y, int w, int h )
{
if( Image == NULL )
return;
if( Hidden )
return;
- fprintf( stderr, "Refresh: %i %i %i %i\n", x, y, w, h );
-
// And copy buffer to window
RefreshFromImage( x, y, w, h );
-
}
//---------------------------------------------------------------------------
-void Window::RefreshAll()
+void SkinWindow::RefreshAll()
{
Refresh( 0, 0, Width, Height );
}
//---------------------------------------------------------------------------
-void Window::MouseDown( int x, int y, int button )
+void SkinWindow::MouseDown( int x, int y, int button )
{
// Checking event in controls
- for( int i = ControlList.size() - 1; i >= 0 ; i-- )
+ for( int i = ControlList.size() - 1; i >= 0; i-- )
{
- if( ControlList[i]->MouseDown( x, y, button ) )
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->MouseDown( x, y, button ) )
{
- return;
+ msg_Dbg( p_intf, "Mouse down (ID=%s)",
+ ControlList[i]->GetId().c_str() );
+ break;
}
}
-
}
//---------------------------------------------------------------------------
-void Window::MouseMove( int x, int y, int button )
+void SkinWindow::MouseMove( int x, int y, int button )
{
int i;
}
// Checking event in controls
- for( i = ControlList.size() - 1; i >= 0 ; i-- )
+ for( i = ControlList.size() - 1; i >= 0; i-- )
{
- ControlList[i]->MouseMove( x, y, button );
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->MouseMove( x, y, button ) )
+ {
+ break;
+ }
}
// Checking help text
- for( i = ControlList.size() - 1; i >= 0 ; i-- )
+ for( i = ControlList.size() - 1; i >= 0; i-- )
{
- if( ControlList[i]->MouseOver( x, y ) )
+ if( ControlList[i]->IsVisible() && ControlList[i]->MouseOver( x, y ) )
{
- if( ControlList[i]->SendNewHelpText() )
- {
- break;
- }
+ ControlList[i]->SendNewHelpText();
+ break;
}
}
}
// Checking for change in Tool Tip
- for( i = ControlList.size() - 1; i >= 0 ; i-- )
+ for( i = ControlList.size() - 1; i >= 0; i-- )
{
- if( ControlList[i]->ToolTipTest( x, y ) )
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->ToolTipTest( x, y ) )
+ {
break;
+ }
}
// If no change, delete tooltip text
ChangeToolTipText( "none" );
}
//---------------------------------------------------------------------------
-void Window::MouseUp( int x, int y, int button )
+void SkinWindow::MouseUp( int x, int y, int button )
{
int i;
}
// Checking event in controls
- for( i = ControlList.size() - 1; i >= 0 ; i-- )
+ for( i = ControlList.size() - 1; i >= 0; i-- )
{
- fprintf( stderr, " -> Control\n" );
- if( ControlList[i]->MouseUp( x, y, button ) )
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->MouseUp( x, y, button ) )
{
- int x, y;
- //ControlList[i]->GetSize( x, y );
- fprintf( stderr, " x: %i\n y: %i\n",
- ControlList[i]->Left, ControlList[i]->Top );
-
- return;
+ msg_Dbg( p_intf, "Mouse up (ID=%s)",
+ ControlList[i]->GetId().c_str() );
+ break;
}
}
+
+ if( i < 0 && button == MOUSE_RIGHT )
+ {
+ p_intf->p_sys->p_dialogs->ShowPopup();
+ }
}
//---------------------------------------------------------------------------
-void Window::MouseDblClick( int x, int y, int button )
+void SkinWindow::MouseDblClick( int x, int y, int button )
{
int i;
// Checking event in controls
- for( i = ControlList.size() - 1; i >= 0 ; i-- )
+ for( i = ControlList.size() - 1; i >= 0; i-- )
{
- if( ControlList[i]->MouseDblClick( x, y, button ) )
- return;
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->MouseDblClick( x, y, button ) )
+ {
+ msg_Dbg( p_intf, "Double click (ID=%s)",
+ ControlList[i]->GetId().c_str() );
+ }
}
}
//---------------------------------------------------------------------------
-void Window::Init()
+void SkinWindow::MouseScroll( int x, int y, int direction )
+{
+ // Checking event in controls
+ for( int i = ControlList.size() - 1; i >= 0; i-- )
+ {
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->MouseScroll( x, y, direction ) )
+ {
+ break;
+ }
+ }
+
+ // Checking for change in Tool Tip
+ for( int i = ControlList.size() - 1; i >= 0; i-- )
+ {
+ if( ControlList[i]->IsVisible() &&
+ ControlList[i]->ToolTipTest( x, y ) )
+ {
+ break;
+ }
+ }
+
+}
+//---------------------------------------------------------------------------
+void SkinWindow::Init()
{
// Get size of window
ReSize();
Move( Left, Top );
}
//---------------------------------------------------------------------------
-void Window::ReSize()
+void SkinWindow::ReSize()
{
// Initialization
unsigned int i;
{
#define min(a,b) ((a)<(b))?(a):(b)
#define max(a,b) ((a)>(b))?(a):(b)
- w = max( w, ControlList[i]->Left + ControlList[i]->Width );
- h = max( h, ControlList[i]->Top + ControlList[i]->Height );
- MinX = min( MinX, ControlList[i]->Left );
- MinY = min( MinY, ControlList[i]->Top );
+ w = max( w, ControlList[i]->GetLeft() + ControlList[i]->GetWidth() );
+ h = max( h, ControlList[i]->GetTop() + ControlList[i]->GetHeight() );
+ MinX = min( MinX, ControlList[i]->GetLeft() );
+ MinY = min( MinY, ControlList[i]->GetTop() );
#undef max
#undef min
}
// Change image buffer
if( Image != NULL )
delete (OSGraphics *)Image;
- Image = (Graphics *)new OSGraphics( w, h, this );
-
+ Image = (Graphics *)new OSGraphics( p_intf, w, h, this );
Size( w, h );
}
}
//---------------------------------------------------------------------------
-void Window::GetSize( int &w, int &h )
+void SkinWindow::GetSize( int &w, int &h )
{
w = Width;
h = Height;
}
//---------------------------------------------------------------------------
-void Window::GetPos( int &x, int &y )
+void SkinWindow::GetPos( int &x, int &y )
{
x = Left;
y = Top;
}
-//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+// List of all the Skin Windows (singleton)
+//---------------------------------------------------------------------------
+SkinWindowList *SkinWindowList::_instance = NULL;
+//---------------------------------------------------------------------------
+SkinWindowList::SkinWindowList()
+{
+}
+//---------------------------------------------------------------------------
+SkinWindowList *SkinWindowList::Instance()
+{
+ if( _instance == NULL )
+ {
+ _instance = new SkinWindowList;
+ }
+ return _instance;
+}
+//---------------------------------------------------------------------------
+void SkinWindowList::Add( SkinWindow *win )
+{
+ _list.push_back( win );
+}
+//---------------------------------------------------------------------------
+SkinWindow *SkinWindowList::Back()
+{
+ return _list.back();
+}
+//---------------------------------------------------------------------------
+list<SkinWindow*>::const_iterator SkinWindowList::Begin()
+{
+ return _list.begin();
+}
+//---------------------------------------------------------------------------
+list<SkinWindow*>::const_iterator SkinWindowList::End()
+{
+ return _list.end();
+}
+//---------------------------------------------------------------------------