| 1 |
// xap_Win32DialogHelper.h |
| 2 |
|
| 3 |
/* AbiWord |
| 4 |
* Copyright (C) 1998 AbiSource, Inc. |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 |
* 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef XAP_Win32DialogHelper_H |
| 23 |
#define XAP_Win32DialogHelper_H |
| 24 |
|
| 25 |
// MSVC++ warns about using 'this' in initializer list. |
| 26 |
// and the DialogHelper uses 'this' typically for its contructor |
| 27 |
#ifdef _MSC_VER |
| 28 |
#pragma warning(disable: 4355) |
| 29 |
#endif |
| 30 |
|
| 31 |
#include <commctrl.h> |
| 32 |
|
| 33 |
// Compat stuff |
| 34 |
|
| 35 |
// newer MINGW32 seems to have that. Just prevent the redefine. |
| 36 |
#if defined(__MINGW32__) && !defined(ListView_GetSelectionMark) |
| 37 |
#define LVM_GETSELECTIONMARK (LVM_FIRST+66) |
| 38 |
#define ListView_GetSelectionMark(w) (INT)SNDMSG((w),LVM_GETSELECTIONMARK,0,0) |
| 39 |
#endif |
| 40 |
|
| 41 |
/*****************************************************************/ |
| 42 |
#include "xap_Frame.h" |
| 43 |
#include "xap_Win32FrameImpl.h" |
| 44 |
#include "ut_Xpm2Bmp.h" |
| 45 |
|
| 46 |
class ABI_EXPORT XAP_Win32Dialog |
| 47 |
{ |
| 48 |
public: |
| 49 |
virtual BOOL _onInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam) = 0; |
| 50 |
virtual BOOL _onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) = 0; |
| 51 |
virtual BOOL _onDeltaPos(NM_UPDOWN * pnmud) = 0; |
| 52 |
}; |
| 53 |
|
| 54 |
class ABI_EXPORT XAP_Win32DialogHelper |
| 55 |
{ |
| 56 |
public: |
| 57 |
XAP_Win32DialogHelper(XAP_Win32Dialog* p_dialog) |
| 58 |
: m_pDialog(p_dialog), |
| 59 |
m_hDlg(0) |
| 60 |
{ |
| 61 |
} |
| 62 |
|
| 63 |
// for plugin dialogs - they have their own runModal and s_dlgProc due to differing hInstance values |
| 64 |
// (DLL instead of Abi main executable) |
| 65 |
// Makes more sense to share this code rather than use bare WinAPI in plugins when possible |
| 66 |
XAP_Win32DialogHelper(HWND hDlg) |
| 67 |
: m_pDialog(0), |
| 68 |
m_hDlg(hDlg) |
| 69 |
{ |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
public: |
| 74 |
|
| 75 |
void runModal( XAP_Frame* pFrame, |
| 76 |
XAP_Dialog_Id dialog_id, |
| 77 |
UT_sint32 resource_id, |
| 78 |
XAP_Dialog* p_dialog); |
| 79 |
|
| 80 |
void runModeless( XAP_Frame* pFrame, |
| 81 |
XAP_Dialog_Id dialog_id, |
| 82 |
UT_sint32 resource_id, |
| 83 |
XAP_Dialog_Modeless* p_dialog); |
| 84 |
|
| 85 |
static BOOL CALLBACK s_dlgProc( HWND hWnd, |
| 86 |
UINT msg, |
| 87 |
WPARAM wParam, |
| 88 |
LPARAM lParam); |
| 89 |
|
| 90 |
void checkButton(UT_sint32 controlId, bool bChecked = true); |
| 91 |
void enableControl(UT_sint32 controlId, bool bEnabled = true); |
| 92 |
void destroyWindow(); |
| 93 |
void setDialogTitle(LPCSTR p_str); |
| 94 |
int showWindow( int Mode ); |
| 95 |
int showControl(UT_sint32 controlId, int Mode); |
| 96 |
int bringWindowToTop(); |
| 97 |
|
| 98 |
// Combo boxes. |
| 99 |
|
| 100 |
int addItemToCombo(UT_sint32 controlId, LPCSTR p_str); |
| 101 |
void selectComboItem(UT_sint32 controlId, int index); |
| 102 |
int setComboDataItem(UT_sint32 controlId, int nIndex, DWORD dwData); |
| 103 |
int getComboDataItem(UT_sint32 controlId, int nIndex); |
| 104 |
int getComboSelectedIndex(UT_sint32 controlId) const; |
| 105 |
void resetComboContent(UT_sint32 controlId); |
| 106 |
|
| 107 |
// List boxes |
| 108 |
|
| 109 |
void resetContent(UT_sint32 controlId); |
| 110 |
int addItemToList(UT_sint32 controlId, LPCSTR p_str); |
| 111 |
int getListSelectedIndex(UT_sint32 controlId) const; |
| 112 |
int setListDataItem(UT_sint32 controlId, int nIndex, DWORD dwData); |
| 113 |
int getListDataItem(UT_sint32 controlId, int nIndex); |
| 114 |
void selectListItem(UT_sint32 controlId, int index); |
| 115 |
void getListText(UT_sint32 controlId, int index, char *p_str) const; |
| 116 |
|
| 117 |
// Controls |
| 118 |
void setControlText(UT_sint32 controlId, LPCSTR p_str); |
| 119 |
void setControlInt(UT_sint32 controlId, int value); |
| 120 |
int getControlInt(UT_sint32 controlId) const; |
| 121 |
|
| 122 |
void selectControlText(UT_sint32 controlId, |
| 123 |
UT_sint32 start, |
| 124 |
UT_sint32 end); |
| 125 |
|
| 126 |
int isChecked(UT_sint32 controlId) const; |
| 127 |
void getControlText( UT_sint32 controlId, |
| 128 |
LPSTR p_buffer, |
| 129 |
UT_sint32 Buffer_length) const; |
| 130 |
|
| 131 |
bool isControlVisible(UT_sint32 controlId) const; |
| 132 |
|
| 133 |
bool isParentFrame(/*const*/ XAP_Frame& frame) const; |
| 134 |
void setParentFrame(const XAP_Frame* pFrame); |
| 135 |
XAP_Frame* getParentFrame(); |
| 136 |
void centerDialog(); |
| 137 |
static void s_centerDialog(HWND hWnd); |
| 138 |
static HBITMAP s_loadBitmap(HWND hWnd, UINT nId, |
| 139 |
const char* pName, |
| 140 |
int width, int height, |
| 141 |
const UT_RGBColor & Color); |
| 142 |
|
| 143 |
void setHandle(HWND hWnd){m_hDlg=hWnd;} |
| 144 |
|
| 145 |
private: |
| 146 |
XAP_Win32Dialog * m_pDialog; |
| 147 |
HWND m_hDlg; |
| 148 |
}; |
| 149 |
|
| 150 |
|
| 151 |
#endif /* XAP_Win32DialogHelper_H */ |