Debian Codegraph @

src/af/xap/win/xap_Win32Dlg_Zoom.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <windows.h>
21
22 #include "ut_string.h"
23 #include "ut_assert.h"
24 #include "ut_debugmsg.h"
25
26 #include "xap_App.h"
27 #include "xap_Win32App.h"
28 #include "xap_Win32FrameImpl.h"
29 #include "xav_View.h"
30
31 #include "xap_Strings.h"
32 #include "xap_Dialog_Id.h"
33 #include "xap_Dlg_Zoom.h"
34 #include "xap_Win32Dlg_Zoom.h"
35
36 #include "xap_Win32Resources.rc2"
37
38 /*****************************************************************/
39
40 XAP_Dialog * XAP_Win32Dialog_Zoom::static_constructor(XAP_DialogFactory * pFactory,
41 XAP_Dialog_Id id)
42 {
43 XAP_Win32Dialog_Zoom * p = new XAP_Win32Dialog_Zoom(pFactory,id);
44 return p;
45 }
46
47 XAP_Win32Dialog_Zoom::XAP_Win32Dialog_Zoom(XAP_DialogFactory * pDlgFactory,
48 XAP_Dialog_Id id)
49 : XAP_Dialog_Zoom(pDlgFactory,id)
50 {
51 m_bEditPctEnabled = false;
52 }
53
54 XAP_Win32Dialog_Zoom::~XAP_Win32Dialog_Zoom(void)
55 {
56
57 }
58
59 /*****************************************************************/
60
61 void XAP_Win32Dialog_Zoom::runModal(XAP_Frame * pFrame)
62 {
63 m_pFrame = pFrame;
64
65 /*
66 This dialog is non-persistent.
67
68 This dialog should do the following:
69
70 - Construct itself to represent the base-class zoomTypes
71 z_200, z_100, z_75, z_PageWidth, z_WholePage, and z_Percent.
72 The Unix one looks just like Microsoft Word 97, with the preview
73 and all (even though it's not hooked up yet).
74
75 - Set zoom type to match "m_zoomType" and value of radio button
76 to match "m_zoomPercent".
77
78 On "OK" (or during user-interaction) the dialog should:
79
80 - Save the zoom type to "m_zoomType".
81
82 - Save the value in the Percent spin button box to "m_zoomPercent".
83
84 - Just quit, the data items will be ignored by the caller.
85
86 */
87
88 // raise the dialog
89
90 UT_ASSERT(m_id == XAP_DIALOG_ID_ZOOM);
91
92 setDialog(this);
93 createModal(pFrame, MAKEINTRESOURCEW(XAP_RID_DIALOG_ZOOM));
94
95 }
96
97 BOOL XAP_Win32Dialog_Zoom::_onDlgMessage(HWND /*hWnd*/,UINT msg,WPARAM wParam,LPARAM /*lParam*/)
98 {
99 switch (msg)
100 {
101
102 case WM_VSCROLL:
103 _updatePreviewZoomPercent((UT_uint32)HIWORD(wParam));
104 return 1;
105
106 default:
107 return 0;
108 }
109 }
110
111 #define _DS(c,s) setDlgItemText(XAP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s))
112 #define _DSX(c,s) setDlgItemText(XAP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s))
113
114 BOOL XAP_Win32Dialog_Zoom::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
115 {
116 const XAP_StringSet* pSS = m_pApp->getStringSet();
117
118 // Update the caption
119 setDialogTitle(pSS->getValue(XAP_STRING_ID_DLG_Zoom_ZoomTitle));
120
121 // localize controls
122 _DSX(ZOOM_BTN_CLOSE, DLG_Close);
123 _DS(ZOOM_TEXT_ZOOMTO, DLG_Zoom_RadioFrameCaption);
124 _DS(ZOOM_RADIO_200, DLG_Zoom_200);
125 _DS(ZOOM_RADIO_100, DLG_Zoom_100);
126 _DS(ZOOM_RADIO_75, DLG_Zoom_75);
127 _DS(ZOOM_RADIO_WIDTH, DLG_Zoom_PageWidth);
128 _DS(ZOOM_RADIO_WHOLE, DLG_Zoom_WholePage);
129 _DS(ZOOM_RADIO_PCT, DLG_Zoom_Percent);
130
131 // set initial state
132 checkButton(XAP_RID_DIALOG_ZOOM_RADIO_200 + m_zoomType);
133 setControlInt(XAP_RID_DIALOG_ZOOM_EDIT_PCT, (UINT) m_zoomPercent);
134 m_bEditPctEnabled = ((XAP_RID_DIALOG_ZOOM_RADIO_200 + m_zoomType) == XAP_RID_DIALOG_ZOOM_RADIO_PCT);
135 enableControl(XAP_RID_DIALOG_ZOOM_EDIT_PCT ,m_bEditPctEnabled);
136
137 SendMessageW(GetDlgItem(hWnd,XAP_RID_DIALOG_ZOOM_SPIN_PCT),UDM_SETRANGE,
138 (WPARAM)0,(LPARAM)MAKELONG(XAP_DLG_ZOOM_MAXIMUM_ZOOM,XAP_DLG_ZOOM_MINIMUM_ZOOM));
139
140 _updatePreviewZoomPercent(getZoomPercent());
141
142 centerDialog();
143
144 return 1; // 1 == we did not call SetFocus()
145 }
146
147 BOOL XAP_Win32Dialog_Zoom::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
148 {
149 WORD wId = LOWORD(wParam);
150 UT_sint32 newValue;
151
152 m_bEditPctEnabled = (isChecked(XAP_RID_DIALOG_ZOOM_RADIO_PCT)==BST_CHECKED);
153 enableControl(XAP_RID_DIALOG_ZOOM_EDIT_PCT,m_bEditPctEnabled);
154
155 switch (wId)
156 {
157 case XAP_RID_DIALOG_ZOOM_RADIO_200:
158 m_zoomType = XAP_Frame::z_200;
159 m_pFrame->setZoomType(m_zoomType);
160 _updatePreviewZoomPercent(200);
161 return 1;
162
163 case XAP_RID_DIALOG_ZOOM_RADIO_100:
164 m_zoomType = XAP_Frame::z_100;
165 m_pFrame->setZoomType(m_zoomType);
166 _updatePreviewZoomPercent(100);
167 return 1;
168
169 case XAP_RID_DIALOG_ZOOM_RADIO_75:
170 m_zoomType = XAP_Frame::z_75;
171 m_pFrame->setZoomType(m_zoomType);
172 _updatePreviewZoomPercent(75);
173 return 1;
174
175 case XAP_RID_DIALOG_ZOOM_RADIO_WIDTH:
176 newValue = m_pFrame->getCurrentView()->calculateZoomPercentForPageWidth();
177 m_zoomType = XAP_Frame::z_PAGEWIDTH;
178 m_pFrame->setZoomType(m_zoomType);
179 _updatePreviewZoomPercent(newValue);
180 return 1;
181
182 case XAP_RID_DIALOG_ZOOM_RADIO_WHOLE:
183 newValue = m_pFrame->getCurrentView()->calculateZoomPercentForWholePage();
184 m_zoomType = XAP_Frame::z_WHOLEPAGE;
185 m_pFrame->setZoomType(m_zoomType);
186 _updatePreviewZoomPercent(newValue);
187 return 1;
188
189 case XAP_RID_DIALOG_ZOOM_RADIO_PCT:
190 if (m_bEditPctEnabled)
191 {
192 if (_getValueFromEditPct(&newValue))
193 {
194 m_zoomType = XAP_Frame::z_PERCENT;
195 m_pFrame->setZoomType(m_zoomType);
196 m_zoomPercent = newValue;
197 _updatePreviewZoomPercent(newValue);
198 }
199 }
200 return 1;
201
202 case XAP_RID_DIALOG_ZOOM_EDIT_PCT:
203 if (_getValueFromEditPct(&newValue))
204 {
205 m_zoomPercent = newValue;
206 _updatePreviewZoomPercent(newValue);
207 }
208 return 1;
209
210 case IDCANCEL: // Zoom is instant-apply, so treat cancel as OK
211 case IDOK: // also XAP_RID_DIALOG_ZOOM_BTN_CLOSE
212 m_answer = a_OK;
213 EndDialog(hWnd,0);
214 return 1;
215
216 default: // we did not handle this notification
217 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
218 return 0; // return zero to let windows take care of it.
219 }
220 }
221
222 BOOL XAP_Win32Dialog_Zoom::_onDeltaPos(NM_UPDOWN * pnmud)
223 {
224 // respond to WM_NOTIFY/UDN_DELTAPOS message
225 // return TRUE to prevent the change from happening
226 // return FALSE to allow it to occur
227 // we may alter the change by changing the fields in pnmud.
228
229 UT_ASSERT(pnmud->hdr.idFrom == XAP_RID_DIALOG_ZOOM_SPIN_PCT);
230 UT_DEBUGMSG(("onDeltaPos: [idFrom %d][iPos %d][iDelta %d]\n",
231 pnmud->hdr.idFrom,pnmud->iPos,pnmud->iDelta));
232 int iNew = pnmud->iPos + pnmud->iDelta;
233
234 if ((pnmud->iPos < XAP_DLG_ZOOM_MINIMUM_ZOOM) || (iNew < XAP_DLG_ZOOM_MINIMUM_ZOOM))
235 {
236 // bogus current position or bogus delta, force it back to minimum.
237 pnmud->iDelta = XAP_DLG_ZOOM_MINIMUM_ZOOM - pnmud->iPos;
238 return FALSE;
239 }
240
241 if ((pnmud->iPos > XAP_DLG_ZOOM_MAXIMUM_ZOOM) || (iNew > XAP_DLG_ZOOM_MAXIMUM_ZOOM))
242 {
243 // arbitrary upper limit (XAP_DLG_ZOOM_MAXIMUM_ZOOM)
244 // i did this because massive scaling of fonts
245 // causes problems for virtual memory (when they
246 // get rendered at huge sizes).
247 // MSWORD97 also applies this limit.
248
249 pnmud->iDelta = XAP_DLG_ZOOM_MAXIMUM_ZOOM - pnmud->iPos;
250 return FALSE;
251 }
252
253 return FALSE;
254 }
255
256 BOOL XAP_Win32Dialog_Zoom::_getValueFromEditPct(int * pNewValue)
257 {
258 int newValue = getControlInt(XAP_RID_DIALOG_ZOOM_EDIT_PCT);
259
260 // valid number, but out of range clip to MIN or MAX range;
261 if (newValue < XAP_DLG_ZOOM_MINIMUM_ZOOM) newValue = XAP_DLG_ZOOM_MINIMUM_ZOOM;
262 if (newValue > XAP_DLG_ZOOM_MAXIMUM_ZOOM) newValue = XAP_DLG_ZOOM_MAXIMUM_ZOOM;
263
264 *pNewValue = newValue;
265 return TRUE;
266 }
267