Debian Codegraph @

src/af/xap/win/xap_Win32Dlg_Image.cpp

raw
1 /* AbiWord
2 * Copyright (C) 2000 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
29 #include "xap_Strings.h"
30 #include "xap_Dialog_Id.h"
31 #include "xap_Dlg_Image.h"
32 #include "xap_Win32Dlg_Image.h"
33
34 #include "xap_Win32Resources.rc2"
35 #include "ap_Win32App.h"
36
37 #define BUFSIZE 1024
38 /*****************************************************************/
39
40 XAP_Dialog * XAP_Win32Dialog_Image::static_constructor(XAP_DialogFactory * pFactory,
41 XAP_Dialog_Id id)
42 {
43 XAP_Win32Dialog_Image * p = new XAP_Win32Dialog_Image(pFactory,id);
44 return p;
45 }
46
47 #ifdef _MSC_VER // MSVC++ warns about using 'this' in initializer list.
48 #pragma warning(disable: 4355)
49 #endif
50
51 XAP_Win32Dialog_Image::XAP_Win32Dialog_Image(XAP_DialogFactory * pDlgFactory,
52 XAP_Dialog_Id id)
53 : XAP_Dialog_Image(pDlgFactory,id)
54 {
55 }
56
57 XAP_Win32Dialog_Image::~XAP_Win32Dialog_Image(void)
58 {
59 }
60
61 void XAP_Win32Dialog_Image::runModal(XAP_Frame * pFrame)
62 {
63 UT_ASSERT(pFrame);
64 UT_ASSERT(m_id == XAP_DIALOG_ID_IMAGE);
65
66 setDialog(this);
67 createModal(pFrame, MAKEINTRESOURCEW(XAP_RID_DIALOG_IMAGE));
68 }
69
70 #define _DS(c,s) setDlgItemText(XAP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s))
71 #define _DSX(c,s) setDlgItemText(XAP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s))
72
73 BOOL XAP_Win32Dialog_Image::_onInitDialog(HWND hWnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
74 {
75 const XAP_StringSet* pSS = m_pApp->getStringSet();
76
77 // Update the caption
78 setDialogTitle(pSS->getValue(XAP_STRING_ID_DLG_Image_Title));
79
80 /* Localise controls*/
81 _DSX(IMAGE_BTN_OK, DLG_OK);
82 _DSX(IMAGE_BTN_CANCEL, DLG_Cancel);
83 _DS(IMAGE_LBL_HEIGHT, DLG_Image_Height);
84 _DS(IMAGE_LBL_WIDTH, DLG_Image_Width);
85 _DS(IMAGE_CHK_ASPECT, DLG_Image_Aspect);
86 _DS(IMAGE_LBL_TITLE, DLG_Image_LblTitle);
87 _DS(IMAGE_LBL_DESCRIPTION, DLG_Image_LblDescription);
88 _DS(IMAGE_LBL_SIZE, DLG_Image_ImageSize);
89 _DS(IMAGE_LBL_NAME, DLG_Image_ImageDesc);
90 _DS(IMAGE_LBL_WRAPPING, DLG_Image_TextWrapping);
91 _DS(IMAGE_LBL_PLACEMENT, DLG_Image_Placement);
92 _DS(IMAGE_RADIO_INLINE, DLG_Image_InLine);
93 _DS(IMAGE_RADIO_FLOAT, DLG_Image_WrappedNone);
94 _DS(IMAGE_RADIO_RIGHT, DLG_Image_WrappedRight);
95 _DS(IMAGE_RADIO_LEFT, DLG_Image_WrappedLeft);
96 _DS(IMAGE_RADIO_BOTHSIDES, DLG_Image_WrappedBoth);
97 _DS(IMAGE_RADIO_PARAGRAPH, DLG_Image_PlaceParagraph);
98 _DS(IMAGE_RADIO_COLUMN, DLG_Image_PlaceColumn);
99 _DS(IMAGE_RADIO_PAGE, DLG_Image_PlacePage);
100 _DS(IMAGE_LBL_TYPE, DLG_Image_WrapType);
101 _DS(IMAGE_RADIO_SQUARE, DLG_Image_SquareWrap);
102 _DS(IMAGE_RADIO_TIGHT, DLG_Image_TightWrap);
103
104 // Initialize controls
105 setControlText( XAP_RID_DIALOG_IMAGE_EBX_HEIGHT, getHeightString() );
106 setControlText( XAP_RID_DIALOG_IMAGE_EBX_WIDTH, getWidthString() );
107 setControlText(XAP_RID_DIALOG_IMAGE_EBX_TITLE, getTitle().utf8_str());
108 setControlText(XAP_RID_DIALOG_IMAGE_EBX_DESCRIPTION, getDescription().utf8_str());
109 checkButton( XAP_RID_DIALOG_IMAGE_CHK_ASPECT, getPreserveAspect());
110
111 // Initialize text wrapping radio buttons
112 if(getWrapping() == WRAP_INLINE)
113 {
114 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE, XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES,
115 XAP_RID_DIALOG_IMAGE_RADIO_INLINE);
116 }
117 else if(getWrapping() == WRAP_NONE)
118 {
119 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE, XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES,
120 XAP_RID_DIALOG_IMAGE_RADIO_FLOAT);
121 }
122 else if(getWrapping() == WRAP_TEXTRIGHT)
123 {
124 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE, XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES,
125 XAP_RID_DIALOG_IMAGE_RADIO_RIGHT);
126 }
127 else if(getWrapping() == WRAP_TEXTLEFT)
128 {
129 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE, XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES,
130 XAP_RID_DIALOG_IMAGE_RADIO_LEFT);
131 }
132 else if(getWrapping() == WRAP_TEXTBOTH)
133 {
134 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE, XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES,
135 XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES);
136 }
137
138 // Initialize image placement radio buttons
139 if(getPositionTo() == POSITION_TO_PARAGRAPH)
140 {
141 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH, XAP_RID_DIALOG_IMAGE_RADIO_PAGE,
142 XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH);
143 }
144 else if(getPositionTo() == POSITION_TO_COLUMN)
145 {
146 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH, XAP_RID_DIALOG_IMAGE_RADIO_PAGE,
147 XAP_RID_DIALOG_IMAGE_RADIO_COLUMN);
148 }
149 else if(getPositionTo() == POSITION_TO_PAGE)
150 {
151 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH, XAP_RID_DIALOG_IMAGE_RADIO_PAGE,
152 XAP_RID_DIALOG_IMAGE_RADIO_PAGE);
153 }
154
155 //Initialize type radio buttons
156 if(isTightWrap())
157 {
158 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_SQUARE, XAP_RID_DIALOG_IMAGE_RADIO_TIGHT,
159 XAP_RID_DIALOG_IMAGE_RADIO_TIGHT);
160 }
161 else
162 {
163 CheckRadioButton(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_SQUARE, XAP_RID_DIALOG_IMAGE_RADIO_TIGHT,
164 XAP_RID_DIALOG_IMAGE_RADIO_SQUARE);
165 }
166
167 wrappingChanged();
168 return TRUE;
169 }
170
171 BOOL XAP_Win32Dialog_Image::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/)
172 {
173 WORD wNotifyCode = HIWORD(wParam);
174 WORD wId = LOWORD(wParam);
175
176 switch (wId)
177 {
178 case IDCANCEL: // also AP_RID_DIALOG_COLUMN_BTN_CANCEL
179 setAnswer( a_Cancel );
180 EndDialog(hWnd,0);
181 return 1;
182
183 case IDOK: // also AP_RID_DIALOG_COLUMN_BTN_OK
184 // change wrapping
185 if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE))
186 {
187 setWrapping(WRAP_INLINE);
188 }
189 else if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_FLOAT))
190 {
191 setWrapping(WRAP_NONE);
192 }
193 else if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_RIGHT))
194 {
195 setWrapping(WRAP_TEXTRIGHT);
196 }
197 else if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_LEFT))
198 {
199 setWrapping(WRAP_TEXTLEFT);
200 }
201 else if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES))
202 {
203 setWrapping(WRAP_TEXTBOTH);
204 }
205
206 if(!IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_INLINE))
207 {
208 // change placement if the inline option isn't selected
209 if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH))
210 {
211 setPositionTo(POSITION_TO_PARAGRAPH);
212 }
213 else if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_COLUMN))
214 {
215 setPositionTo(POSITION_TO_COLUMN);
216 }
217 else if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_PAGE))
218 {
219 setPositionTo(POSITION_TO_PAGE);
220 }
221
222 //change type if the inline option isn't selected
223 if(IsDlgButtonChecked(hWnd, XAP_RID_DIALOG_IMAGE_RADIO_SQUARE))
224 {
225 setTightWrap(false);
226 }
227 else
228 {
229 setTightWrap(true);
230 }
231 }
232
233 char buf[BUFSIZE];
234 getControlText(XAP_RID_DIALOG_IMAGE_EBX_TITLE,buf,BUFSIZE);
235 setTitle(buf);
236 getControlText(XAP_RID_DIALOG_IMAGE_EBX_DESCRIPTION,buf,BUFSIZE);
237 setDescription(buf);
238
239 setAnswer( a_OK );
240 EndDialog(hWnd,0);
241 return 1;
242
243 case XAP_RID_DIALOG_IMAGE_EBX_HEIGHT:
244 if( wNotifyCode == EN_KILLFOCUS )
245 {
246 //char bufHeight[BUFSIZE];
247 //GetDlgItemText( hWnd, wId, bufHeight, BUFSIZE );
248 UT_Win32LocaleString str, units;
249 getDlgItemText (wId, str);
250 units.fromASCII (UT_dimensionName(getPreferedUnits()));
251
252 //let the user manually change dimensions too
253 if(!wcsstr(str.c_str(), units.c_str()))
254 str.appendLocale (units.c_str());
255
256 setHeight( str.utf8_str().utf8_str() );
257 setControlText( XAP_RID_DIALOG_IMAGE_EBX_HEIGHT, getHeightString() );
258 setControlText( XAP_RID_DIALOG_IMAGE_EBX_WIDTH, getWidthString() );
259 }
260 return 1;
261
262 case XAP_RID_DIALOG_IMAGE_EBX_WIDTH:
263 if( wNotifyCode == EN_KILLFOCUS )
264 {
265 UT_Win32LocaleString str, units;
266 getDlgItemText (wId, str);
267
268 //let the user manually change dimensions too
269 if(!wcsstr(str.c_str(), units.c_str()))
270 str.appendLocale (units.c_str());
271
272 setWidth( str.utf8_str().utf8_str() );
273 setControlText( XAP_RID_DIALOG_IMAGE_EBX_HEIGHT, getHeightString() );
274 setControlText( XAP_RID_DIALOG_IMAGE_EBX_WIDTH, getWidthString() );
275 }
276 return 1;
277
278 case XAP_RID_DIALOG_IMAGE_CHK_ASPECT:
279 setPreserveAspect( isChecked(wId)!=0 );
280 return 1;
281
282 case XAP_RID_DIALOG_IMAGE_RADIO_INLINE: case XAP_RID_DIALOG_IMAGE_RADIO_FLOAT:
283 case XAP_RID_DIALOG_IMAGE_RADIO_RIGHT: case XAP_RID_DIALOG_IMAGE_RADIO_LEFT: case XAP_RID_DIALOG_IMAGE_RADIO_BOTHSIDES:
284 wrappingChanged();
285 return 1;
286
287 default: // we did not handle this notification
288 UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
289 return 0; // return zero to let windows take care of it.
290 }
291 }
292
293 BOOL XAP_Win32Dialog_Image::_onDeltaPos(NM_UPDOWN * pnmud)
294 {
295 switch( pnmud->hdr.idFrom )
296 {
297 case XAP_RID_DIALOG_IMAGE_SPN_WIDTH:
298 if( pnmud->iDelta < 0 )
299 {
300 incrementWidth( true );
301 }
302 else
303 {
304 incrementWidth( false );
305 }
306 setControlText( XAP_RID_DIALOG_IMAGE_EBX_HEIGHT, getHeightString() );
307 setControlText( XAP_RID_DIALOG_IMAGE_EBX_WIDTH, getWidthString() );
308 return 1;
309
310 case XAP_RID_DIALOG_IMAGE_SPN_HEIGHT:
311 if( pnmud->iDelta < 0 )
312 {
313 incrementHeight( true );
314 }
315 else
316 {
317 incrementHeight( false );
318 }
319 setControlText( XAP_RID_DIALOG_IMAGE_EBX_HEIGHT, getHeightString() );
320 setControlText( XAP_RID_DIALOG_IMAGE_EBX_WIDTH, getWidthString() );
321 return 1;
322
323 default:
324 return 0;
325 }
326 }
327
328 void XAP_Win32Dialog_Image::wrappingChanged(void)
329 {
330 if(isChecked(XAP_RID_DIALOG_IMAGE_RADIO_INLINE))
331 {
332 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH,FALSE);
333 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_COLUMN,FALSE);
334 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_PAGE,FALSE);
335 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_SQUARE,FALSE);
336 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_TIGHT,FALSE);
337 }
338 else
339 {
340 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_PARAGRAPH, TRUE);
341 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_COLUMN,TRUE);
342 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_PAGE,TRUE);
343 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_SQUARE,TRUE);
344 enableControl(XAP_RID_DIALOG_IMAGE_RADIO_TIGHT,TRUE);
345 }
346 }