summaryrefslogtreecommitdiff
path: root/fpicker/source/win32
diff options
context:
space:
mode:
authorTino Rachui <tra@openoffice.org>2001-07-09 11:57:23 +0000
committerTino Rachui <tra@openoffice.org>2001-07-09 11:57:23 +0000
commit099c4fe04c39af1ccecdeec0652fef05fbe16ea0 (patch)
tree9948b251a21b810d5ea64396dfda84625e2cd259 /fpicker/source/win32
parentb522a925fb15f5a01ec885fc7ae8f4e52681acf6 (diff)
now multi-instance able
Diffstat (limited to 'fpicker/source/win32')
-rw-r--r--fpicker/source/win32/filepicker/dibpreview.cxx177
-rw-r--r--fpicker/source/win32/filepicker/dibpreview.hxx20
2 files changed, 150 insertions, 47 deletions
diff --git a/fpicker/source/win32/filepicker/dibpreview.cxx b/fpicker/source/win32/filepicker/dibpreview.cxx
index 316340553265..e91a357c48b4 100644
--- a/fpicker/source/win32/filepicker/dibpreview.cxx
+++ b/fpicker/source/win32/filepicker/dibpreview.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: dibpreview.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: tra $ $Date: 2001-06-28 11:13:15 $
+ * last change: $Author: tra $ $Date: 2001-07-09 12:57:23 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -80,6 +80,17 @@
using ::com::sun::star::uno::Sequence;
//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+namespace /* private */
+{
+
+ const char* CURRENT_INSTANCE = "CurrInst";
+
+};
+
+//------------------------------------------------------------------------
// defines
//------------------------------------------------------------------------
@@ -95,7 +106,9 @@ using ::com::sun::star::uno::Sequence;
// static member initialization
//---------------------------------------------------
-CDIBPreview* CDIBPreview::s_DIBPreviewInst = NULL;
+osl::Mutex CDIBPreview::s_Mutex;
+ATOM CDIBPreview::s_ClassAtom = 0;
+sal_Int32 CDIBPreview::s_RegisterDibPreviewWndCount = 0;
//---------------------------------------------------
//
@@ -112,39 +125,25 @@ CDIBPreview::CDIBPreview(
m_hwnd( NULL ),
m_hInstance( hInstance )
{
- // register the preview window class
- WNDCLASSEXW wndClsEx;
- ZeroMemory( &wndClsEx, sizeof( WNDCLASSEXW ) );
-
- wndClsEx.cbSize = sizeof( WNDCLASSEXW );
- wndClsEx.style = CS_HREDRAW | CS_VREDRAW;
- wndClsEx.lpfnWndProc = CDIBPreview::WndProc;
- wndClsEx.hInstance = m_hInstance;
- wndClsEx.hbrBackground = (HBRUSH)( COLOR_INACTIVEBORDER + 1 );
- wndClsEx.lpszClassName = PREVIEWWND_CLASS_NAME;
-
- // register the preview window class
- // !!! Win95 - the window class will be unregistered automaticly
- // if the dll is unloaded
- // Win2000 - the window class must be unregistered manually
- // if the dll is unloaded
- m_ClassAtom = RegisterClassExW( &wndClsEx );
- if ( m_ClassAtom )
+ if ( RegisterDibPreviewWindowClass( ) )
{
// create the preview window in invisible state
sal_uInt32 dwStyle = bShow ? (WS_CHILD | WS_VISIBLE ) : (WS_CHILD );
m_hwnd = CreateWindowExW(
- WS_EX_CLIENTEDGE, PREVIEWWND_CLASS_NAME,
- L"", dwStyle, x, y, cx, cy, aParent,
+ WS_EX_CLIENTEDGE,
+ PREVIEWWND_CLASS_NAME,
+ L"", dwStyle,
+ x, y, cx, cy,
+ aParent,
(HMENU)0x0, // for child windows this will
- // be used as child window identifier
- m_hInstance, 0 );
+ // be used as child window identifier
+ m_hInstance,
+ (LPVOID)this // pass a pointer to the current
+ // instance of this class
+ );
OSL_ASSERT( IsWindow( m_hwnd ) );
}
-
- // set the static member
- s_DIBPreviewInst = this;
}
//---------------------------------------------------
@@ -153,8 +152,12 @@ CDIBPreview::CDIBPreview(
CDIBPreview::~CDIBPreview( )
{
- UnregisterClass(
- (LPCTSTR)MAKELONG( m_ClassAtom, 0 ), m_hInstance );
+ // remember: we don't have to destroy the
+ // preview window because it will be destroyed
+ // by it's parent window (the FileOpen dialog)
+ // but we have to unregister the window class
+
+ UnregisterDibPreviewWindowClass( );
}
//---------------------------------------------------
@@ -316,35 +319,123 @@ LRESULT CALLBACK CDIBPreview::WndProc(
switch( uMsg )
{
+
+ // we connect a pointer to the current instance
+ // with a window instance via SetProp
+ case WM_CREATE:
+ {
+ LPCREATESTRUCT lpcs =
+ reinterpret_cast< LPCREATESTRUCT >( lParam );
+
+ OSL_ASSERT( lpcs->lpCreateParams );
+
+ // connect the instance handle to the window
+ SetPropA( hWnd, CURRENT_INSTANCE, lpcs->lpCreateParams );
+ }
+ break;
+
+ // we remove the window property which connects
+ // a class instance with a window class
+ case WM_NCDESTROY:
+ {
+ // RemoveProp returns the saved value on success
+ CDIBPreview* pImpl = reinterpret_cast< CDIBPreview* >(
+ RemovePropA( hWnd, CURRENT_INSTANCE ) );
+
+ OSL_ASSERT( pImpl );
+ }
+ break;
+
case WM_PAINT:
{
- OSL_PRECOND( s_DIBPreviewInst, "Static member not initialized" );
+ CDIBPreview* pImpl = reinterpret_cast< CDIBPreview* >(
+ GetPropA( hWnd, CURRENT_INSTANCE ) );
+
+ OSL_ASSERT( pImpl );
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint( hWnd, &ps );
- s_DIBPreviewInst->onPaint( hWnd, hDC );
+ pImpl->onPaint( hWnd, hDC );
EndPaint( hWnd, &ps );
}
break;
- // under windows 95/98 the creation of the
- // hidden target request window fails if
- // we don't handle this message ourself
- // because the DefWindowProc returns 0 as
- // a result of handling WM_NCCREATE what
- // leads to a failure of CreateWindow[Ex]!!!
- case WM_NCCREATE:
- lResult = TRUE;
- break;
-
default:
- return DefWindowProc( hWnd, uMsg, wParam, lParam );
+#pragma message( "####################################" )
+#pragma message( " fix this" )
+#pragma message( "####################################" )
+
+ return DefWindowProcA( hWnd, uMsg, wParam, lParam );
}
return lResult;
}
+//---------------------------------------------------
+//
+//---------------------------------------------------
+
+ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass( )
+{
+ osl::MutexGuard aGuard( s_Mutex );
+
+ if ( 0 == s_ClassAtom )
+ {
+ // register the preview window class
+ WNDCLASSEXW wndClsEx;
+ ZeroMemory( &wndClsEx, sizeof( WNDCLASSEXW ) );
+
+ wndClsEx.cbSize = sizeof( WNDCLASSEXW );
+ wndClsEx.style = CS_HREDRAW | CS_VREDRAW;
+ wndClsEx.lpfnWndProc = CDIBPreview::WndProc;
+ wndClsEx.hInstance = m_hInstance;
+ wndClsEx.hbrBackground = (HBRUSH)( COLOR_INACTIVEBORDER + 1 );
+ wndClsEx.lpszClassName = PREVIEWWND_CLASS_NAME;
+
+ // register the preview window class
+ // !!! Win95 - the window class will be unregistered automaticly
+ // if the dll is unloaded
+ // Win2000 - the window class must be unregistered manually
+ // if the dll is unloaded
+ s_ClassAtom = RegisterClassExW( &wndClsEx );
+ OSL_ASSERT( s_ClassAtom );
+ }
+
+ // increment the register class counter
+ // so that we keep track of the number
+ // of class registrations
+ if ( 0 != s_ClassAtom )
+ s_RegisterDibPreviewWndCount++;
+
+ return s_ClassAtom;
+}
+
+//---------------------------------------------------
+//
+//---------------------------------------------------
+
+void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass( )
+{
+ osl::MutexGuard aGuard( s_Mutex );
+
+ OSL_ASSERT( 0 != s_ClassAtom );
+
+ // update the register class counter
+ // and unregister the window class if
+ // counter drops to zero
+ if ( 0 != s_ClassAtom )
+ {
+ s_RegisterDibPreviewWndCount--;
+ OSL_ASSERT( s_RegisterDibPreviewWndCount >= 0 );
+ }
+ if ( 0 == s_RegisterDibPreviewWndCount )
+ {
+ UnregisterClass(
+ (LPCTSTR)MAKELONG( s_ClassAtom, 0 ), m_hInstance );
+ s_ClassAtom = 0;
+ }
+} \ No newline at end of file
diff --git a/fpicker/source/win32/filepicker/dibpreview.hxx b/fpicker/source/win32/filepicker/dibpreview.hxx
index f710e00195d6..b108b33af20b 100644
--- a/fpicker/source/win32/filepicker/dibpreview.hxx
+++ b/fpicker/source/win32/filepicker/dibpreview.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: dibpreview.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: tra $ $Date: 2001-06-28 11:13:03 $
+ * last change: $Author: tra $ $Date: 2001-07-09 12:57:23 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -74,6 +74,10 @@
#include <com/sun/star/uno/Sequence.hxx>
#endif
+#ifndef _OSL_MUTEX_HXX_
+#include <osl/mutex.hxx>
+#endif
+
#include <windows.h>
//---------------------------------------------
@@ -130,17 +134,25 @@ public:
private:
virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC );
+
+ ATOM SAL_CALL RegisterDibPreviewWindowClass( );
+ void SAL_CALL UnregisterDibPreviewWindowClass( );
+
static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
private:
HWND m_hwnd;
- ATOM m_ClassAtom;
HINSTANCE m_hInstance;
::com::sun::star::uno::Sequence< sal_Int8 > m_ImageData;
sal_Int32 m_cx;
sal_Int32 m_cy;
- static CDIBPreview* s_DIBPreviewInst;
+ // the preview window class has to be registered only
+ // once per process, so multiple instance of this class
+ // share the registered window class
+ static ATOM s_ClassAtom;
+ static osl::Mutex s_Mutex;
+ static sal_Int32 s_RegisterDibPreviewWndCount;
// prevent copy and assignment
private: