1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_fpicker.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //------------------------------------------------------------------------ 32*cdf0e10cSrcweir // includes 33*cdf0e10cSrcweir //------------------------------------------------------------------------ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <tchar.h> 36*cdf0e10cSrcweir #include "dibpreview.hxx" 37*cdf0e10cSrcweir #include <osl/diagnose.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOG_FILEPREVIEWIMAGEFORMATS_HPP_ 40*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp> 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #ifndef _USTRING_HXX_ 44*cdf0e10cSrcweir #include <rtl/ustring.hxx> 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <stdexcept> 48*cdf0e10cSrcweir #include <string> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //------------------------------------------------------------------------ 51*cdf0e10cSrcweir // 52*cdf0e10cSrcweir //------------------------------------------------------------------------ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 55*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 56*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 57*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 58*cdf0e10cSrcweir using rtl::OUString; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //------------------------------------------------------------------------ 61*cdf0e10cSrcweir // 62*cdf0e10cSrcweir //------------------------------------------------------------------------ 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir namespace /* private */ 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir const LPTSTR CURRENT_INSTANCE = TEXT("CurrInst"); 67*cdf0e10cSrcweir }; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //------------------------------------------------------------------------ 70*cdf0e10cSrcweir // defines 71*cdf0e10cSrcweir //------------------------------------------------------------------------ 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir #define PREVIEWWND_CLASS_NAME TEXT("DIBPreviewWnd###") 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // means 3 pixel left and 3 pixel right 76*cdf0e10cSrcweir #define HORZ_BODER_SPACE 6 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // means 3 pixel top and 3 pixel bottom 79*cdf0e10cSrcweir #define VERT_BORDER_SPACE 6 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir //--------------------------------------------------- 82*cdf0e10cSrcweir // static member initialization 83*cdf0e10cSrcweir //--------------------------------------------------- 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir osl::Mutex CDIBPreview::s_Mutex; 86*cdf0e10cSrcweir ATOM CDIBPreview::s_ClassAtom = 0; 87*cdf0e10cSrcweir sal_Int32 CDIBPreview::s_RegisterDibPreviewWndCount = 0; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //--------------------------------------------------- 90*cdf0e10cSrcweir // 91*cdf0e10cSrcweir //--------------------------------------------------- 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir CDIBPreview::CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow) : 94*cdf0e10cSrcweir m_Instance(instance) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir RegisterDibPreviewWindowClass(); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir if (bShowWindow) 101*cdf0e10cSrcweir dwStyle |= WS_VISIBLE; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir m_Hwnd = CreateWindowEx( 104*cdf0e10cSrcweir WS_EX_CLIENTEDGE, 105*cdf0e10cSrcweir PREVIEWWND_CLASS_NAME, 106*cdf0e10cSrcweir TEXT(""), 107*cdf0e10cSrcweir dwStyle, 108*cdf0e10cSrcweir 0, 0, 0, 0, 109*cdf0e10cSrcweir parent, 110*cdf0e10cSrcweir (HMENU)0x0, // for child windows this will 111*cdf0e10cSrcweir // be used as child window identifier 112*cdf0e10cSrcweir m_Instance, 113*cdf0e10cSrcweir (LPVOID)this // pass a pointer to the current 114*cdf0e10cSrcweir // instance of this class 115*cdf0e10cSrcweir ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir bool bSuccess = IsWindow(m_Hwnd); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir OSL_POSTCOND(bSuccess,"Coud not create preview window"); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir if (!bSuccess) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir UnregisterDibPreviewWindowClass(); 124*cdf0e10cSrcweir throw std::runtime_error("Could not create preview window"); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //--------------------------------------------------- 129*cdf0e10cSrcweir // 130*cdf0e10cSrcweir //--------------------------------------------------- 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir CDIBPreview::~CDIBPreview( ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir // remember: we don't have to destroy the 135*cdf0e10cSrcweir // preview window because it will be destroyed 136*cdf0e10cSrcweir // by it's parent window (the FileOpen dialog) 137*cdf0e10cSrcweir // but we have to unregister the window class 138*cdf0e10cSrcweir //if ( m_bWndClassRegistered ) 139*cdf0e10cSrcweir UnregisterDibPreviewWindowClass(); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir //------------------------------- 143*cdf0e10cSrcweir // 144*cdf0e10cSrcweir //------------------------------- 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir sal_Int32 SAL_CALL CDIBPreview::getTargetColorDepth() throw (RuntimeException) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir HDC hdc = GetDC(m_Hwnd); 149*cdf0e10cSrcweir int clrRes = 0; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if (hdc) 152*cdf0e10cSrcweir clrRes = GetDeviceCaps(hdc, COLORRES); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir return clrRes; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir //------------------------------- 158*cdf0e10cSrcweir // 159*cdf0e10cSrcweir //------------------------------- 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir sal_Int32 SAL_CALL CDIBPreview::getAvailableWidth() throw (RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir RECT rect; 164*cdf0e10cSrcweir bool bRet = GetClientRect(m_Hwnd,&rect); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir sal_Int32 cx = 0; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir if ( bRet ) 169*cdf0e10cSrcweir cx = rect.right; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir return cx; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir //------------------------------- 175*cdf0e10cSrcweir // 176*cdf0e10cSrcweir //------------------------------- 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir sal_Int32 SAL_CALL CDIBPreview::getAvailableHeight() throw (RuntimeException) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir RECT rect; 181*cdf0e10cSrcweir bool bRet = GetClientRect(m_Hwnd,&rect); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir sal_Int32 cy = 0; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if ( bRet ) 186*cdf0e10cSrcweir cy = rect.bottom; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir return cy; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir //------------------------------- 192*cdf0e10cSrcweir // 193*cdf0e10cSrcweir //------------------------------- 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void SAL_CALL CDIBPreview::setImage(sal_Int16 aImageFormat, const Any& aImage) 196*cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir PreviewBase::setImage(aImageFormat,aImage); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // if the any has no value we have an 201*cdf0e10cSrcweir // empty Sequence which clears the 202*cdf0e10cSrcweir // preview window 203*cdf0e10cSrcweir osl::ClearableMutexGuard aGuard(m_PaintLock); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir m_Image.realloc(0); 206*cdf0e10cSrcweir m_ImageData >>= m_Image; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir aGuard.clear(); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir InvalidateRect(m_Hwnd,NULL,sal_False); 211*cdf0e10cSrcweir UpdateWindow(m_Hwnd); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir //------------------------------- 215*cdf0e10cSrcweir // 216*cdf0e10cSrcweir //------------------------------- 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir sal_Bool SAL_CALL CDIBPreview::setShowState(sal_Bool bShowState) throw (RuntimeException) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir PreviewBase::setShowState(bShowState); 221*cdf0e10cSrcweir ShowWindow(m_Hwnd, m_bShowState ? SW_SHOW : SW_HIDE); 222*cdf0e10cSrcweir return sal_True; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir //------------------------------- 226*cdf0e10cSrcweir // 227*cdf0e10cSrcweir //------------------------------- 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir sal_Bool SAL_CALL CDIBPreview::getShowState() throw (RuntimeException) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir return (sal_Bool)IsWindowVisible(m_Hwnd); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir //------------------------------- 235*cdf0e10cSrcweir // 236*cdf0e10cSrcweir //------------------------------- 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir HWND SAL_CALL CDIBPreview::getWindowHandle() const 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir return m_Hwnd; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //--------------------------------------------------- 244*cdf0e10cSrcweir // 245*cdf0e10cSrcweir //--------------------------------------------------- 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir void SAL_CALL CDIBPreview::onPaint(HWND hWnd, HDC hDC) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir BITMAPFILEHEADER* pbmfh; 250*cdf0e10cSrcweir BITMAPINFO * pbmi; 251*cdf0e10cSrcweir sal_uInt8 * pBits; 252*cdf0e10cSrcweir int cxDib; 253*cdf0e10cSrcweir int cyDib; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir osl::MutexGuard aGuard(m_PaintLock); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir try 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir pbmfh = reinterpret_cast<BITMAPFILEHEADER*>(m_Image.getArray()); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if ( !IsBadReadPtr( pbmfh, sizeof(BITMAPFILEHEADER)) && 262*cdf0e10cSrcweir (pbmfh->bfType == ('B' | ('M' << 8))) ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir pbmi = reinterpret_cast<BITMAPINFO*>((pbmfh + 1)); 265*cdf0e10cSrcweir pBits = reinterpret_cast<sal_uInt8*>(((DWORD)pbmfh) + pbmfh->bfOffBits); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir cxDib = pbmi->bmiHeader.biWidth; 268*cdf0e10cSrcweir cyDib = abs (pbmi->bmiHeader.biHeight); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir SetStretchBltMode(hDC, COLORONCOLOR); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir int nWidth = getAvailableWidth(); 273*cdf0e10cSrcweir int nHeight = getAvailableHeight(); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir int nX = abs(nWidth - cxDib) / 2; 276*cdf0e10cSrcweir int nY = abs(nHeight - cyDib) / 2; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir int GDIError = GDI_ERROR; 279*cdf0e10cSrcweir GDIError = StretchDIBits( 280*cdf0e10cSrcweir hDC, nX, nY, cxDib, cyDib, 281*cdf0e10cSrcweir 0, 0, cxDib, cyDib, pBits, pbmi, 282*cdf0e10cSrcweir DIB_RGB_COLORS, SRCCOPY); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir OSL_ASSERT(GDI_ERROR != GDIError); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // paint the border 287*cdf0e10cSrcweir RECT rc; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir if (nY > 0) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir // top 292*cdf0e10cSrcweir rc.left = 0; 293*cdf0e10cSrcweir rc.top = 0; 294*cdf0e10cSrcweir rc.right = nWidth; 295*cdf0e10cSrcweir rc.bottom = nY; 296*cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // bottom 299*cdf0e10cSrcweir rc.left = 0; 300*cdf0e10cSrcweir rc.top = nHeight - nY - 1; 301*cdf0e10cSrcweir rc.right = nWidth; 302*cdf0e10cSrcweir rc.bottom = nHeight; 303*cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir if (nX > 0) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir // left 309*cdf0e10cSrcweir rc.left = 0; 310*cdf0e10cSrcweir rc.top = nY; 311*cdf0e10cSrcweir rc.right = nX; 312*cdf0e10cSrcweir rc.bottom = nHeight - nY; 313*cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // right 316*cdf0e10cSrcweir rc.left = nWidth - nX - 1; 317*cdf0e10cSrcweir rc.top = nY; 318*cdf0e10cSrcweir rc.right = nWidth; 319*cdf0e10cSrcweir rc.bottom = nHeight - nY; 320*cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir else // clear background 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir RECT rc; 326*cdf0e10cSrcweir GetClientRect(hWnd,&rc); 327*cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir catch(...) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir OSL_ASSERT(sal_False); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir //--------------------------------------------------- 337*cdf0e10cSrcweir // 338*cdf0e10cSrcweir //--------------------------------------------------- 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir LRESULT CALLBACK CDIBPreview::WndProc( 341*cdf0e10cSrcweir HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir LRESULT lResult = 0; 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir switch(uMsg) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir // we connect a pointer to the current instance 349*cdf0e10cSrcweir // with a window instance via SetProp 350*cdf0e10cSrcweir case WM_CREATE: 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir LPCREATESTRUCT lpcs = 353*cdf0e10cSrcweir reinterpret_cast< LPCREATESTRUCT >(lParam); 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir OSL_ASSERT(lpcs->lpCreateParams); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir // connect the instance handle to the window 358*cdf0e10cSrcweir SetProp(hWnd, CURRENT_INSTANCE, lpcs->lpCreateParams); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir break; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir // we remove the window property which connects 363*cdf0e10cSrcweir // a class instance with a window class 364*cdf0e10cSrcweir case WM_NCDESTROY: 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir // RemoveProp returns the saved value on success 367*cdf0e10cSrcweir if (reinterpret_cast<CDIBPreview*>( 368*cdf0e10cSrcweir RemoveProp(hWnd, CURRENT_INSTANCE)) == NULL) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir OSL_ASSERT(false); 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir break; 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir case WM_PAINT: 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir CDIBPreview* pImpl = reinterpret_cast<CDIBPreview*>( 378*cdf0e10cSrcweir GetProp(hWnd, CURRENT_INSTANCE)); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir OSL_ASSERT(pImpl); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir HDC hDC; 383*cdf0e10cSrcweir PAINTSTRUCT ps; 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir hDC = BeginPaint(hWnd,&ps); 386*cdf0e10cSrcweir pImpl->onPaint(hWnd,hDC); 387*cdf0e10cSrcweir EndPaint(hWnd,&ps); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir break; 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir // ignore this message in order to 392*cdf0e10cSrcweir // avoid flickering during paint 393*cdf0e10cSrcweir case WM_ERASEBKGND: 394*cdf0e10cSrcweir lResult = 1; 395*cdf0e10cSrcweir break; 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir default: 398*cdf0e10cSrcweir return DefWindowProc(hWnd, uMsg, wParam, lParam); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir return lResult; 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir //--------------------------------------------------- 405*cdf0e10cSrcweir // 406*cdf0e10cSrcweir //--------------------------------------------------- 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass() 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir osl::MutexGuard aGuard( s_Mutex ); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir if (0 == s_ClassAtom) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir // register the preview window class 415*cdf0e10cSrcweir WNDCLASSEX wndClsEx; 416*cdf0e10cSrcweir ZeroMemory(&wndClsEx, sizeof(wndClsEx)); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir wndClsEx.cbSize = sizeof(wndClsEx); 419*cdf0e10cSrcweir wndClsEx.style = CS_HREDRAW | CS_VREDRAW; 420*cdf0e10cSrcweir wndClsEx.lpfnWndProc = CDIBPreview::WndProc; 421*cdf0e10cSrcweir wndClsEx.hInstance = m_Instance; 422*cdf0e10cSrcweir wndClsEx.hbrBackground = (HBRUSH)(COLOR_INACTIVEBORDER + 1); 423*cdf0e10cSrcweir wndClsEx.lpszClassName = PREVIEWWND_CLASS_NAME; 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir // register the preview window class 426*cdf0e10cSrcweir // !!! Win95 - the window class will be unregistered automaticly 427*cdf0e10cSrcweir // if the dll is unloaded 428*cdf0e10cSrcweir // Win2000 - the window class must be unregistered manually 429*cdf0e10cSrcweir // if the dll is unloaded 430*cdf0e10cSrcweir s_ClassAtom = RegisterClassEx(&wndClsEx); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir OSL_POSTCOND(s_ClassAtom,"Could not register preview window class"); 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if (0 == s_ClassAtom) 435*cdf0e10cSrcweir throw std::runtime_error("Preview window class could not be registered"); 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // increment the register class counter 439*cdf0e10cSrcweir // so that we keep track of the number 440*cdf0e10cSrcweir // of class registrations 441*cdf0e10cSrcweir //if ( 0 != s_ClassAtom ) 442*cdf0e10cSrcweir s_RegisterDibPreviewWndCount++; 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir return s_ClassAtom; 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir //--------------------------------------------------- 448*cdf0e10cSrcweir // 449*cdf0e10cSrcweir //--------------------------------------------------- 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass() 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir osl::MutexGuard aGuard( s_Mutex ); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir OSL_ASSERT( ( (0 != s_ClassAtom) && (s_RegisterDibPreviewWndCount > 0)) || 456*cdf0e10cSrcweir ( (0 == s_ClassAtom) && (0 == s_RegisterDibPreviewWndCount) ) ); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // update the register class counter 459*cdf0e10cSrcweir // and unregister the window class if 460*cdf0e10cSrcweir // counter drops to zero 461*cdf0e10cSrcweir if (0 != s_ClassAtom) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir s_RegisterDibPreviewWndCount--; 464*cdf0e10cSrcweir OSL_ASSERT(s_RegisterDibPreviewWndCount >= 0); 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir if (0 == s_RegisterDibPreviewWndCount) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir UnregisterClass((LPCTSTR)MAKELONG(s_ClassAtom,0),m_Instance); 470*cdf0e10cSrcweir s_ClassAtom = 0; 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir } 473