1 // xap_Win32DialogBase.h
2 
3 /* AbiWord
4  * Copyright (C) 2003 AbiSource, Inc.
5  *           (C) 2003 Mike Nordell
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  */
22 
23 #ifndef XAP_Win32DialogBase_H
24 #define XAP_Win32DialogBase_H
25 
26 // MSVC++ warns about using 'this' in initializer list.
27 // and the DialogHelper uses 'this' typically for its contructor
28 #ifdef _MSC_VER
29 #pragma warning(disable: 4355)
30 #endif
31 
32 #include <windows.h>
33 #include <commctrl.h>
34 #include "ut_Win32LocaleString.h"
35 
36 #include "ut_types.h"
37 /*****************************************************************/
38 
39 
40 class XAP_Frame;
41 class XAP_StringSet;
42 
43 class ABI_EXPORT XAP_Win32DialogBase
44 {
45 public:
XAP_Win32DialogBase()46 	XAP_Win32DialogBase() : m_hDlg(0), m_tag(magic_tag), m_pDlg(0), m_pSS(0) {}
47 	// no need for user-defined destructor
48     // static functions
49 	static bool setWindowText (HWND hWnd, const char* uft8_str);
50 	static bool getDlgItemText(HWND hWnd, int nIDDlgItem, UT_Win32LocaleString& str);
51     static bool setDlgItemText(HWND hWnd, int nIDDlgItem, const char* uft8_str);
52 
53 protected:
54 	void createModal(XAP_Frame* pFrame, LPCWSTR dlgTemplate);
55     void createModal(XAP_Frame* pFrame);
56 	HWND createModeless(XAP_Frame* pFrame, LPCWSTR dlgTemplate);
57 
58     void notifyCloseFrame(XAP_Frame *pFrame);
59 	// Subclasses: override this and use it as your DLGPROC
60 	virtual BOOL _onDlgMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
_onInitDialog(HWND,WPARAM,LPARAM)61 	virtual BOOL _onInitDialog(HWND /*hWnd*/, WPARAM /*wParam*/, LPARAM /*lParam*/) {return FALSE;};
_onCommand(HWND,WPARAM,LPARAM)62 	virtual BOOL _onCommand(HWND /*hWnd*/, WPARAM /*wParam*/, LPARAM /*lParam*/) {return FALSE;};
_onDeltaPos(NM_UPDOWN *)63 	virtual BOOL _onDeltaPos(NM_UPDOWN * /*pnmud*/) {return FALSE;};
64 	virtual BOOL _callHelp();
65 
66 
67 	// Control Functionality
68 	void checkButton(UT_sint32 controlId, bool bChecked = true);
69 	void enableControl(UT_sint32 controlId, bool bEnabled = true);
70 	void destroyWindow();
71     void setDialogTitle(const char* uft8_str);
72 	void localizeDialogTitle(UT_uint32 stringId);
73 	int	 showWindow( int Mode );
74 	int	 showControl(UT_sint32 controlId, int Mode);
75 	int	 bringWindowToTop();
76     bool setDlgItemText(int nIDDlgItem, const char* uft8_str);
77 	bool getDlgItemText(int nIDDlgItem, UT_Win32LocaleString& str);
78 
79 	// Combo boxes.
80 
81 	int	 addItemToCombo(UT_sint32 controlId, LPCSTR p_str);
82 	void selectComboItem(UT_sint32 controlId, int index);
83 	int  setComboDataItem(UT_sint32 controlId, int nIndex, DWORD dwData);
84 	int  getComboDataItem(UT_sint32 controlId, int nIndex);
85 	int  getComboItemIndex(UT_sint32 controlId, LPCSTR p_str);
86 	int	 getComboSelectedIndex(UT_sint32 controlId) const;
87 	void resetComboContent(UT_sint32 controlId);
88     void getComboTextItem(UT_sint32 controlId, int index, UT_Win32LocaleString& str);
89 
90 	// List boxes
91 
92 	void resetContent(UT_sint32 controlId);
93 	int	 addItemToList(UT_sint32 controlId, LPCSTR p_str);
94 	int	 getListSelectedIndex(UT_sint32 controlId) const;
95 	int  setListDataItem(UT_sint32 controlId, int nIndex, DWORD dwData);
96 	int  getListDataItem(UT_sint32 controlId, int nIndex);
97 	void selectListItem(UT_sint32 controlId, int index);
98 	void getListText(UT_sint32 controlId, int index, char *p_str) const;
99 
100 	// Controls
101 	void setControlText(UT_sint32 controlId, LPCSTR p_str);
102 	void localizeControlText(UT_sint32 controlId, UT_uint32 stringId);
103 	void setControlInt(UT_sint32 controlId, int value);
104 	int	 getControlInt(UT_sint32 controlId) const;
105 
106 	void selectControlText(UT_sint32 controlId, UT_sint32 start, UT_sint32 end);
107 
108 	int  isChecked(UT_sint32 controlId) const;
109 	void getControlText(UT_sint32 controlId, LPSTR p_buffer, UT_sint32 Buffer_length) const;
110 
111 	bool isControlVisible(UT_sint32	controlId) const;
112 
113 	void centerDialog();
setHandle(HWND hWnd)114 	void setHandle(HWND hWnd) { m_hDlg = hWnd; };
setDialog(XAP_Dialog * pDlg)115 	void setDialog(XAP_Dialog * pDlg) { m_pDlg = pDlg; };
116 	bool isDialogValid() const;
117 
118 protected:
119 HWND m_hDlg;
120 
121 protected:
122 	static BOOL CALLBACK s_dlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
123 private:
124 
125 	// disallow copying and assignment
126 	XAP_Win32DialogBase(const XAP_Win32DialogBase&);	// no impl.
127 	void operator=(const XAP_Win32DialogBase&);			// no impl.
128 
129 	enum { // VC6 can't handle static int here, why an enum is the only way...
130 		magic_tag = 0x327211
131 	};
132 
133 	int m_tag;	// all for safety
134 	XAP_Dialog* m_pDlg;
135 	const XAP_StringSet* m_pSS;
136 };
137 
138 
139 #endif /* XAP_Win32DialogBase_H */
140