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 _HELPPOPUPWINDOW_HXX_
25 #define _HELPPOPUPWINDOW_HXX_
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 
31 #include <sal/types.h>
32 #include <rtl/ustring.hxx>
33 #include <osl/mutex.hxx>
34 
35 #define WIN32_LEAN_AND_MEAN
36 #if defined _MSC_VER
37 #pragma warning(push, 1)
38 #endif
39 #include <windows.h>
40 #if defined _MSC_VER
41 #pragma warning(pop)
42 #endif
43 
44 //---------------------------------------------
45 // declaration
46 //---------------------------------------------
47 
48 /*
49     A simple popup window similary to the one the
50     windows help (using WinHelp) creates when called
51     with the option HELP_CONTEXTPOPUP.
52 
53     The interface is very simple but necessary for our
54     needs.
55     The window automaticaly calculates the necessary
56     dimensions of the window and a appropriate show
57     position based on the position the client provides.
58     When the user click any mouse button or hits any key
59     the window closes itself and disappears.
60 */
61 
62 class CHelpPopupWindow
63 {
64 public:
65 
66     /*
67         The client may set some parameter of the window.
68         When the client omits to set one or more values
69         a default value will be taken.
70         The values are in pixel.
71     */
72     CHelpPopupWindow(
73         HINSTANCE hInstance,
74         HWND hwndParent );
75 
76     /*
77         dtor
78     */
79     ~CHelpPopupWindow( );
80 
81     /*
82         The client may set the text the window is showing
83         on next activation.
84     */
85     void SAL_CALL setText( const rtl::OUString& aHelpText );
86 
87     /*
88         Shows the window with the text that was last set.
89         The posistion is the prefered position. The window
90         may itself show at a slightly different position
91         if it fits not at the prefered position.
92     */
93     void SAL_CALL show( sal_Int32 x, sal_Int32 y );
94 
95     HWND SAL_CALL setParent( HWND hwndNewParent );
96 
97 private:
98     void SAL_CALL onPaint( HWND, HDC );
99     void SAL_CALL onNcDestroy();
100     void SAL_CALL onCreate( HWND );
101 
102     POINT SAL_CALL calcUpperLeftCorner( );
103     void  SAL_CALL calcWindowRect( LPRECT lprect );
104 
105     void SAL_CALL adjustWindowSize( sal_Int32*, sal_Int32* );
106     void SAL_CALL adjustWindowPos( sal_Int32 x, sal_Int32 y, sal_Int32 cx, sal_Int32 cy );
107 
108     ATOM SAL_CALL RegisterWindowClass( );
109     void SAL_CALL UnregisterWindowClass( );
110 
111     static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
112 
113 private:
114     sal_Int32       m_hMargins;
115     sal_Int32       m_vMargins;
116     sal_Int32       m_avCharWidth;
117     sal_Int32       m_avCharHeight;
118     HWND		    m_hwnd;
119     HWND            m_hwndParent;
120 	HINSTANCE	    m_hInstance;
121     sal_Bool        m_bWndClassRegistered;
122     ::rtl::OUString m_HelpText;
123     HBITMAP         m_hBitmapShadow;
124     HBRUSH          m_hBrushShadow;
125 
126     // the window class has to be registered only
127     // once per process, so multiple instance of this class
128     // share the registered window class
129     static ATOM       s_ClassAtom;
130     static osl::Mutex s_Mutex;
131     static sal_Int32  s_RegisterWndClassCount;
132 
133 // prevent copy and assignment
134 private:
135     CHelpPopupWindow( const CHelpPopupWindow& );
136     CHelpPopupWindow& operator=( const CHelpPopupWindow& );
137 };
138 
139 #endif
140