xref: /AOO41X/main/fpicker/source/win32/filepicker/helppopupwindow.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _HELPPOPUPWINDOW_HXX_
29 #define _HELPPOPUPWINDOW_HXX_
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 
35 #include <sal/types.h>
36 #include <rtl/ustring.hxx>
37 #include <osl/mutex.hxx>
38 
39 #define WIN32_LEAN_AND_MEAN
40 #if defined _MSC_VER
41 #pragma warning(push, 1)
42 #endif
43 #include <windows.h>
44 #if defined _MSC_VER
45 #pragma warning(pop)
46 #endif
47 
48 //---------------------------------------------
49 // declaration
50 //---------------------------------------------
51 
52 /*
53     A simple popup window similary to the one the
54     windows help (using WinHelp) creates when called
55     with the option HELP_CONTEXTPOPUP.
56 
57     The interface is very simple but necessary for our
58     needs.
59     The window automaticaly calculates the necessary
60     dimensions of the window and a appropriate show
61     position based on the position the client provides.
62     When the user click any mouse button or hits any key
63     the window closes itself and disappears.
64 */
65 
66 class CHelpPopupWindow
67 {
68 public:
69 
70     /*
71         The client may set some parameter of the window.
72         When the client omits to set one or more values
73         a default value will be taken.
74         The values are in pixel.
75     */
76     CHelpPopupWindow(
77         HINSTANCE hInstance,
78         HWND hwndParent );
79 
80     /*
81         dtor
82     */
83     ~CHelpPopupWindow( );
84 
85     /*
86         The client may set the text the window is showing
87         on next activation.
88     */
89     void SAL_CALL setText( const rtl::OUString& aHelpText );
90 
91     /*
92         Shows the window with the text that was last set.
93         The posistion is the prefered position. The window
94         may itself show at a slightly different position
95         if it fits not at the prefered position.
96     */
97     void SAL_CALL show( sal_Int32 x, sal_Int32 y );
98 
99     HWND SAL_CALL setParent( HWND hwndNewParent );
100 
101 private:
102     void SAL_CALL onPaint( HWND, HDC );
103     void SAL_CALL onNcDestroy();
104     void SAL_CALL onCreate( HWND );
105 
106     POINT SAL_CALL calcUpperLeftCorner( );
107     void  SAL_CALL calcWindowRect( LPRECT lprect );
108 
109     void SAL_CALL adjustWindowSize( sal_Int32*, sal_Int32* );
110     void SAL_CALL adjustWindowPos( sal_Int32 x, sal_Int32 y, sal_Int32 cx, sal_Int32 cy );
111 
112     ATOM SAL_CALL RegisterWindowClass( );
113     void SAL_CALL UnregisterWindowClass( );
114 
115     static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
116 
117 private:
118     sal_Int32       m_hMargins;
119     sal_Int32       m_vMargins;
120     sal_Int32       m_avCharWidth;
121     sal_Int32       m_avCharHeight;
122     HWND		    m_hwnd;
123     HWND            m_hwndParent;
124 	HINSTANCE	    m_hInstance;
125     sal_Bool        m_bWndClassRegistered;
126     ::rtl::OUString m_HelpText;
127     HBITMAP         m_hBitmapShadow;
128     HBRUSH          m_hBrushShadow;
129 
130     // the window class has to be registered only
131     // once per process, so multiple instance of this class
132     // share the registered window class
133     static ATOM       s_ClassAtom;
134     static osl::Mutex s_Mutex;
135     static sal_Int32  s_RegisterWndClassCount;
136 
137 // prevent copy and assignment
138 private:
139     CHelpPopupWindow( const CHelpPopupWindow& );
140     CHelpPopupWindow& operator=( const CHelpPopupWindow& );
141 };
142 
143 #endif
144