1*10ce8018SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*10ce8018SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*10ce8018SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*10ce8018SAndrew Rist * distributed with this work for additional information 6*10ce8018SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*10ce8018SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*10ce8018SAndrew Rist * "License"); you may not use this file except in compliance 9*10ce8018SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*10ce8018SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*10ce8018SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*10ce8018SAndrew Rist * software distributed under the License is distributed on an 15*10ce8018SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*10ce8018SAndrew Rist * KIND, either express or implied. See the License for the 17*10ce8018SAndrew Rist * specific language governing permissions and limitations 18*10ce8018SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*10ce8018SAndrew Rist *************************************************************/ 21*10ce8018SAndrew Rist 22*10ce8018SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _HELPPOPUPWINDOW_HXX_ 25cdf0e10cSrcweir #define _HELPPOPUPWINDOW_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir //------------------------------------------------------------------------ 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir //------------------------------------------------------------------------ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <sal/types.h> 32cdf0e10cSrcweir #include <rtl/ustring.hxx> 33cdf0e10cSrcweir #include <osl/mutex.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN 36cdf0e10cSrcweir #if defined _MSC_VER 37cdf0e10cSrcweir #pragma warning(push, 1) 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #include <windows.h> 40cdf0e10cSrcweir #if defined _MSC_VER 41cdf0e10cSrcweir #pragma warning(pop) 42cdf0e10cSrcweir #endif 43cdf0e10cSrcweir 44cdf0e10cSrcweir //--------------------------------------------- 45cdf0e10cSrcweir // declaration 46cdf0e10cSrcweir //--------------------------------------------- 47cdf0e10cSrcweir 48cdf0e10cSrcweir /* 49cdf0e10cSrcweir A simple popup window similary to the one the 50cdf0e10cSrcweir windows help (using WinHelp) creates when called 51cdf0e10cSrcweir with the option HELP_CONTEXTPOPUP. 52cdf0e10cSrcweir 53cdf0e10cSrcweir The interface is very simple but necessary for our 54cdf0e10cSrcweir needs. 55cdf0e10cSrcweir The window automaticaly calculates the necessary 56cdf0e10cSrcweir dimensions of the window and a appropriate show 57cdf0e10cSrcweir position based on the position the client provides. 58cdf0e10cSrcweir When the user click any mouse button or hits any key 59cdf0e10cSrcweir the window closes itself and disappears. 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir 62cdf0e10cSrcweir class CHelpPopupWindow 63cdf0e10cSrcweir { 64cdf0e10cSrcweir public: 65cdf0e10cSrcweir 66cdf0e10cSrcweir /* 67cdf0e10cSrcweir The client may set some parameter of the window. 68cdf0e10cSrcweir When the client omits to set one or more values 69cdf0e10cSrcweir a default value will be taken. 70cdf0e10cSrcweir The values are in pixel. 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir CHelpPopupWindow( 73cdf0e10cSrcweir HINSTANCE hInstance, 74cdf0e10cSrcweir HWND hwndParent ); 75cdf0e10cSrcweir 76cdf0e10cSrcweir /* 77cdf0e10cSrcweir dtor 78cdf0e10cSrcweir */ 79cdf0e10cSrcweir ~CHelpPopupWindow( ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir /* 82cdf0e10cSrcweir The client may set the text the window is showing 83cdf0e10cSrcweir on next activation. 84cdf0e10cSrcweir */ 85cdf0e10cSrcweir void SAL_CALL setText( const rtl::OUString& aHelpText ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir /* 88cdf0e10cSrcweir Shows the window with the text that was last set. 89cdf0e10cSrcweir The posistion is the prefered position. The window 90cdf0e10cSrcweir may itself show at a slightly different position 91cdf0e10cSrcweir if it fits not at the prefered position. 92cdf0e10cSrcweir */ 93cdf0e10cSrcweir void SAL_CALL show( sal_Int32 x, sal_Int32 y ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir HWND SAL_CALL setParent( HWND hwndNewParent ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir private: 98cdf0e10cSrcweir void SAL_CALL onPaint( HWND, HDC ); 99cdf0e10cSrcweir void SAL_CALL onNcDestroy(); 100cdf0e10cSrcweir void SAL_CALL onCreate( HWND ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir POINT SAL_CALL calcUpperLeftCorner( ); 103cdf0e10cSrcweir void SAL_CALL calcWindowRect( LPRECT lprect ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir void SAL_CALL adjustWindowSize( sal_Int32*, sal_Int32* ); 106cdf0e10cSrcweir void SAL_CALL adjustWindowPos( sal_Int32 x, sal_Int32 y, sal_Int32 cx, sal_Int32 cy ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir ATOM SAL_CALL RegisterWindowClass( ); 109cdf0e10cSrcweir void SAL_CALL UnregisterWindowClass( ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir private: 114cdf0e10cSrcweir sal_Int32 m_hMargins; 115cdf0e10cSrcweir sal_Int32 m_vMargins; 116cdf0e10cSrcweir sal_Int32 m_avCharWidth; 117cdf0e10cSrcweir sal_Int32 m_avCharHeight; 118cdf0e10cSrcweir HWND m_hwnd; 119cdf0e10cSrcweir HWND m_hwndParent; 120cdf0e10cSrcweir HINSTANCE m_hInstance; 121cdf0e10cSrcweir sal_Bool m_bWndClassRegistered; 122cdf0e10cSrcweir ::rtl::OUString m_HelpText; 123cdf0e10cSrcweir HBITMAP m_hBitmapShadow; 124cdf0e10cSrcweir HBRUSH m_hBrushShadow; 125cdf0e10cSrcweir 126cdf0e10cSrcweir // the window class has to be registered only 127cdf0e10cSrcweir // once per process, so multiple instance of this class 128cdf0e10cSrcweir // share the registered window class 129cdf0e10cSrcweir static ATOM s_ClassAtom; 130cdf0e10cSrcweir static osl::Mutex s_Mutex; 131cdf0e10cSrcweir static sal_Int32 s_RegisterWndClassCount; 132cdf0e10cSrcweir 133cdf0e10cSrcweir // prevent copy and assignment 134cdf0e10cSrcweir private: 135cdf0e10cSrcweir CHelpPopupWindow( const CHelpPopupWindow& ); 136cdf0e10cSrcweir CHelpPopupWindow& operator=( const CHelpPopupWindow& ); 137cdf0e10cSrcweir }; 138cdf0e10cSrcweir 139cdf0e10cSrcweir #endif 140