1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _DIBPREVIEW_HXX_ 25 #define _DIBPREVIEW_HXX_ 26 27 //------------------------------------------------------------------------ 28 // includes 29 //------------------------------------------------------------------------ 30 31 #include "previewbase.hxx" 32 #include <osl/mutex.hxx> 33 34 #if defined _MSC_VER 35 #pragma warning(push, 1) 36 #endif 37 #include <windows.h> 38 #if defined _MSC_VER 39 #pragma warning(pop) 40 #endif 41 42 //--------------------------------------------- 43 // A very simple wrapper for a window that does 44 // display DIBs. 45 // Maybe it would be better and more extensible 46 // to create another class that is responsible 47 // for rendering a specific image format into 48 // the area of the window, but for our purpose 49 // it's enough to go the simple way - KISS. 50 //--------------------------------------------- 51 52 class CDIBPreview : public PreviewBase 53 { 54 public: 55 56 // ctor 57 CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow = sal_False); 58 59 // dtor 60 virtual ~CDIBPreview( ); 61 62 // preview interface implementation 63 64 virtual sal_Int32 SAL_CALL getTargetColorDepth() 65 throw (::com::sun::star::uno::RuntimeException); 66 67 virtual sal_Int32 SAL_CALL getAvailableWidth() 68 throw (::com::sun::star::uno::RuntimeException); 69 70 virtual sal_Int32 SAL_CALL getAvailableHeight() 71 throw (::com::sun::star::uno::RuntimeException); 72 73 virtual void SAL_CALL setImage(sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage) 74 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 75 76 virtual sal_Bool SAL_CALL setShowState(sal_Bool bShowState) 77 throw (::com::sun::star::uno::RuntimeException); 78 79 virtual sal_Bool SAL_CALL getShowState() 80 throw (::com::sun::star::uno::RuntimeException); 81 82 virtual HWND SAL_CALL getWindowHandle() const; 83 84 private: 85 virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC ); 86 87 ATOM SAL_CALL RegisterDibPreviewWindowClass( ); 88 void SAL_CALL UnregisterDibPreviewWindowClass( ); 89 90 static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 91 92 private: 93 HINSTANCE m_Instance; 94 HWND m_Hwnd; 95 com::sun::star::uno::Sequence<sal_Int8> m_Image; 96 osl::Mutex m_PaintLock; 97 98 // the preview window class has to be registered only 99 // once per process, so multiple instance of this class 100 // share the registered window class 101 static ATOM s_ClassAtom; 102 static osl::Mutex s_Mutex; 103 static sal_Int32 s_RegisterDibPreviewWndCount; 104 105 // prevent copy and assignment 106 private: 107 CDIBPreview(const CDIBPreview&); 108 CDIBPreview& operator=(const CDIBPreview&); 109 }; 110 111 112 #endif 113