Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

win32_window.cpp

00001 /*****************************************************************************
00002  * win32_window.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: win32_window.cpp 11786 2005-07-18 23:57:41Z asmax $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #ifdef WIN32_SKINS
00026 
00027 #include "../src/generic_window.hpp"
00028 #include "../src/vlcproc.hpp"
00029 #include "win32_window.hpp"
00030 #include "win32_dragdrop.hpp"
00031 #include "win32_factory.hpp"
00032 
00033 
00035 #ifndef LWA_COLORKEY
00036 #   define LWA_COLORKEY  0x00000001
00037 #   define LWA_ALPHA     0x00000002
00038 #endif
00039 
00040 
00041 // XXX layered windows are supposed to work only with at least win2k
00042 #ifndef WS_EX_LAYERED
00043 #   define WS_EX_LAYERED 0x00080000
00044 #endif
00045 
00046 Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
00047                           HINSTANCE hInst, HWND hParentWindow,
00048                           bool dragDrop, bool playOnDrop,
00049                           Win32Window *pParentWindow ):
00050     OSWindow( pIntf ), m_dragDrop( dragDrop ), m_isLayered( false ),
00051     m_pParent( pParentWindow )
00052 {
00053     // Create the window
00054     if( pParentWindow )
00055     {
00056         // Child window (for vout)
00057         HWND hParent = pParentWindow->getHandle();
00058         m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
00059             "default name", WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT,
00060             CW_USEDEFAULT, CW_USEDEFAULT, hParent, 0, hInst, NULL );
00061     }
00062     else
00063     {
00064         // Normal window
00065         m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
00066             "default name", WS_POPUP | WS_CLIPCHILDREN,
00067             CW_USEDEFAULT, CW_USEDEFAULT,
00068             CW_USEDEFAULT, CW_USEDEFAULT, hParentWindow, 0, hInst, NULL );
00069     }
00070 
00071     if( !m_hWnd )
00072     {
00073         msg_Err( getIntf(), "CreateWindow failed" );
00074         return;
00075     }
00076 
00077     // Store a pointer to the GenericWindow in a map
00078     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
00079     pFactory->m_windowMap[m_hWnd] = &rWindow;
00080 
00081     // Drag & drop
00082     if( m_dragDrop )
00083     {
00084         m_pDropTarget = (LPDROPTARGET) new Win32DragDrop( getIntf(),
00085                                                           playOnDrop );
00086         // Register the window as a drop target
00087         RegisterDragDrop( m_hWnd, m_pDropTarget );
00088     }
00089 
00090     // Set this window as a vout
00091     if( m_pParent )
00092     {
00093         VlcProc::instance( getIntf() )->registerVoutWindow( (void*)m_hWnd );
00094     }
00095 }
00096 
00097 
00098 Win32Window::~Win32Window()
00099 {
00100     if( m_pParent )
00101     {
00102         VlcProc::instance( getIntf() )->unregisterVoutWindow( (void*)m_hWnd );
00103     }
00104 
00105     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
00106     pFactory->m_windowMap[m_hWnd] = NULL;
00107 
00108     if( m_hWnd )
00109     {
00110         if( m_dragDrop )
00111         {
00112             // Remove the window from the list of drop targets
00113             RevokeDragDrop( m_hWnd );
00114             m_pDropTarget->Release();
00115         }
00116 
00117         DestroyWindow( m_hWnd );
00118     }
00119 }
00120 
00121 
00122 void Win32Window::show( int left, int top ) const
00123 {
00124     ShowWindow( m_hWnd, SW_SHOW );
00125 }
00126 
00127 
00128 void Win32Window::hide() const
00129 {
00130     ShowWindow( m_hWnd, SW_HIDE );
00131 }
00132 
00133 
00134 void Win32Window::moveResize( int left, int top, int width, int height ) const
00135 {
00136     MoveWindow( m_hWnd, left, top, width, height, true );
00137 }
00138 
00139 
00140 void Win32Window::raise() const
00141 {
00142 //     SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
00143     SetForegroundWindow( m_hWnd );
00144 }
00145 
00146 
00147 void Win32Window::setOpacity( uint8_t value ) const
00148 {
00149     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
00150 
00151     if( value == 255 )
00152     {
00153         // If the window is opaque, we remove the WS_EX_LAYERED attribute
00154         // which slows down resizing for nothing
00155         if( m_isLayered )
00156         {
00157             SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
00158                 GetWindowLong( m_hWnd, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
00159 
00160             // Redraw the window, otherwise we may end up with a grey rectangle
00161             // for some strange reason
00162             RedrawWindow(m_hWnd, NULL, NULL,
00163                 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
00164 
00165             m_isLayered = false;
00166         }
00167     }
00168     else
00169     {
00170         if( pFactory->SetLayeredWindowAttributes )
00171         {
00172             if( ! m_isLayered )
00173             {
00174                 // (Re)Add the WS_EX_LAYERED attribute.
00175                 // Resizing will be very slow, now :)
00176                 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
00177                     GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
00178 
00179                 // Redraw the window, otherwise we may end up with a grey
00180                 // rectangle for some strange reason
00181                 RedrawWindow(m_hWnd, NULL, NULL,
00182                     RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
00183 
00184                 m_isLayered = true;
00185             }
00186 
00187             // Change the opacity
00188             pFactory->SetLayeredWindowAttributes(
00189                 m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
00190         }
00191     }
00192 }
00193 
00194 
00195 void Win32Window::toggleOnTop( bool onTop ) const
00196 {
00197     if( onTop )
00198     {
00199         // Set the window on top
00200         SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
00201                       SWP_NOSIZE | SWP_NOMOVE );
00202     }
00203     else
00204     {
00205         // Set the window not on top
00206         SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
00207                       SWP_NOSIZE | SWP_NOMOVE );
00208     }
00209 }
00210 
00211 
00212 #endif

Generated on Tue Dec 20 10:14:44 2005 for vlc-0.8.4a by  doxygen 1.4.2