]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/richtext/richtextimagedlg.cpp | |
3 | // Purpose: | |
4 | // Author: Mingquan Yang | |
5 | // Modified by: | |
6 | // Created: Wed 02 Jun 2010 11:27:23 CST | |
7 | // RCS-ID: | |
8 | // Copyright: (c) Mingquan Yang | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | ||
20 | #if wxUSE_RICHTEXT | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/button.h" | |
24 | #include "wx/combobox.h" | |
25 | #include "wx/sizer.h" | |
26 | #include "wx/stattext.h" | |
27 | #include "wx/textctrl.h" | |
28 | #endif | |
29 | ||
30 | #include "wx/statline.h" | |
31 | ||
32 | #include "wx/richtext/richtextimagedlg.h" | |
33 | #include "wx/richtext/richtextctrl.h" | |
34 | ||
35 | ////@begin XPM images | |
36 | ////@end XPM images | |
37 | ||
38 | ||
39 | /*! | |
40 | * wxRichTextImageDialog type definition | |
41 | */ | |
42 | ||
43 | IMPLEMENT_DYNAMIC_CLASS( wxRichTextImageDialog, wxDialog ) | |
44 | ||
45 | ||
46 | /*! | |
47 | * wxRichTextImageDialog event table definition | |
48 | */ | |
49 | ||
50 | BEGIN_EVENT_TABLE( wxRichTextImageDialog, wxDialog ) | |
51 | ||
52 | ////@begin wxRichTextImageDialog event table entries | |
53 | EVT_BUTTON( ID_RICHTEXTIMAGEDIALOG_PARA_UP, wxRichTextImageDialog::OnRichtextimagedialogParaUpClick ) | |
54 | ||
55 | EVT_BUTTON( ID_RICHTEXTIMAGEDIALOG_DOWN, wxRichTextImageDialog::OnRichtextimagedialogDownClick ) | |
56 | ||
57 | ////@end wxRichTextImageDialog event table entries | |
58 | ||
59 | END_EVENT_TABLE() | |
60 | ||
61 | ||
62 | /*! | |
63 | * wxRichTextImageDialog constructors | |
64 | */ | |
65 | ||
66 | wxRichTextImageDialog::wxRichTextImageDialog() | |
67 | { | |
68 | Init(); | |
69 | } | |
70 | ||
71 | wxRichTextImageDialog::wxRichTextImageDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) | |
72 | { | |
73 | Init(); | |
74 | Create(parent, id, caption, pos, size, style); | |
75 | } | |
76 | ||
77 | ||
78 | /*! | |
79 | * wxRichTextImageDlg creator | |
80 | */ | |
81 | ||
82 | bool wxRichTextImageDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) | |
83 | { | |
84 | ////@begin wxRichTextImageDialog creation | |
85 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP); | |
86 | wxDialog::Create( parent, id, caption, pos, size, style ); | |
87 | ||
88 | CreateControls(); | |
89 | if (GetSizer()) | |
90 | { | |
91 | GetSizer()->SetSizeHints(this); | |
92 | } | |
93 | Centre(); | |
94 | ////@end wxRichTextImageDialog creation | |
95 | return true; | |
96 | } | |
97 | ||
98 | ||
99 | /*! | |
100 | * wxRichTextImageDialog destructor | |
101 | */ | |
102 | ||
103 | wxRichTextImageDialog::~wxRichTextImageDialog() | |
104 | { | |
105 | ////@begin wxRichTextImageDialog destruction | |
106 | ////@end wxRichTextImageDialog destruction | |
107 | } | |
108 | ||
109 | ||
110 | /*! | |
111 | * Member initialisation | |
112 | */ | |
113 | ||
114 | void wxRichTextImageDialog::Init() | |
115 | { | |
116 | ////@begin wxRichTextImageDialog member initialisation | |
117 | m_float = NULL; | |
118 | m_width = NULL; | |
119 | m_unitsW = NULL; | |
120 | m_height = NULL; | |
121 | m_unitsH = NULL; | |
122 | m_offset = NULL; | |
123 | m_unitsOffset = NULL; | |
124 | m_saveButton = NULL; | |
125 | m_cancelButton = NULL; | |
126 | ////@end wxRichTextImageDialog member initialisation | |
127 | } | |
128 | ||
129 | ||
130 | /*! | |
131 | * Control creation for wxRichTextImageDlg | |
132 | */ | |
133 | ||
134 | void wxRichTextImageDialog::CreateControls() | |
135 | { | |
136 | #ifdef __WXMAC__ | |
137 | SetWindowVariant(wxWINDOW_VARIANT_SMALL); | |
138 | #endif | |
139 | ||
140 | ////@begin wxRichTextImageDialog content construction | |
141 | wxRichTextImageDialog* itemDialog1 = this; | |
142 | ||
143 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
144 | itemDialog1->SetSizer(itemBoxSizer2); | |
145 | ||
146 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL); | |
147 | itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5); | |
148 | ||
149 | wxFlexGridSizer* itemFlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0); | |
150 | itemBoxSizer3->Add(itemFlexGridSizer4, 0, wxALIGN_TOP|wxRIGHT, 5); | |
151 | ||
152 | wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Floating mode:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
153 | itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
154 | ||
155 | wxArrayString m_floatStrings; | |
156 | m_floatStrings.Add(_("None")); | |
157 | m_floatStrings.Add(_("Left")); | |
158 | m_floatStrings.Add(_("Right")); | |
159 | m_float = new wxComboBox( itemDialog1, ID_RICHTEXTIMAGEDIALOG_FLOATING_MODE, _("None"), wxDefaultPosition, wxSize(80, -1), m_floatStrings, wxCB_READONLY ); | |
160 | m_float->SetStringSelection(_("None")); | |
161 | m_float->SetHelpText(_("How the image will float relative to the text.")); | |
162 | if (wxRichTextImageDialog::ShowToolTips()) | |
163 | m_float->SetToolTip(_("How the image will float relative to the text.")); | |
164 | itemFlexGridSizer4->Add(m_float, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
165 | ||
166 | wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Width:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
167 | itemFlexGridSizer4->Add(itemStaticText7, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
168 | ||
169 | wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxHORIZONTAL); | |
170 | itemFlexGridSizer4->Add(itemBoxSizer8, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
171 | ||
172 | m_width = new wxTextCtrl( itemDialog1, ID_RICHTEXTIMAGEDIALOG_WIDTH, wxEmptyString, wxDefaultPosition, wxSize(65, -1), 0 ); | |
173 | m_width->SetHelpText(_("The image width to be shown - does not change the source image width.")); | |
174 | if (wxRichTextImageDialog::ShowToolTips()) | |
175 | m_width->SetToolTip(_("The image width to be shown - does not change the source image width.")); | |
176 | itemBoxSizer8->Add(m_width, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
177 | ||
178 | wxArrayString m_unitsWStrings; | |
179 | m_unitsWStrings.Add(_("px")); | |
180 | m_unitsWStrings.Add(_("cm")); | |
181 | m_unitsW = new wxComboBox( itemDialog1, ID_RICHTEXTIMAGEDIALOG_UNITS_W, _("px"), wxDefaultPosition, wxSize(60, -1), m_unitsWStrings, wxCB_READONLY ); | |
182 | m_unitsW->SetStringSelection(_("px")); | |
183 | m_unitsW->SetHelpText(_("Units for the image width.")); | |
184 | if (wxRichTextImageDialog::ShowToolTips()) | |
185 | m_unitsW->SetToolTip(_("Units for the image width.")); | |
186 | itemBoxSizer8->Add(m_unitsW, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
187 | ||
188 | wxStaticText* itemStaticText11 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Height:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
189 | itemFlexGridSizer4->Add(itemStaticText11, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
190 | ||
191 | wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL); | |
192 | itemFlexGridSizer4->Add(itemBoxSizer12, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
193 | ||
194 | m_height = new wxTextCtrl( itemDialog1, ID_RICHTEXTIMAGEDIALOG_HEIGHT, wxEmptyString, wxDefaultPosition, wxSize(65, -1), 0 ); | |
195 | m_height->SetHelpText(_("The image height to be shown - does not change the source image height.")); | |
196 | if (wxRichTextImageDialog::ShowToolTips()) | |
197 | m_height->SetToolTip(_("The image height to be shown - does not change the source image height.")); | |
198 | itemBoxSizer12->Add(m_height, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
199 | ||
200 | wxArrayString m_unitsHStrings; | |
201 | m_unitsHStrings.Add(_("px")); | |
202 | m_unitsHStrings.Add(_("cm")); | |
203 | m_unitsH = new wxComboBox( itemDialog1, ID_RICHTEXTIMAGEDIALOG_UNITS_H, _("px"), wxDefaultPosition, wxSize(60, -1), m_unitsHStrings, wxCB_READONLY ); | |
204 | m_unitsH->SetStringSelection(_("px")); | |
205 | m_unitsH->SetHelpText(_("Units for the image height.")); | |
206 | if (wxRichTextImageDialog::ShowToolTips()) | |
207 | m_unitsH->SetToolTip(_("Units for the image height.")); | |
208 | itemBoxSizer12->Add(m_unitsH, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
209 | ||
210 | wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Image Vertical &Offset:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
211 | itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
212 | ||
213 | wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL); | |
214 | itemFlexGridSizer4->Add(itemBoxSizer16, 1, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
215 | ||
216 | m_offset = new wxTextCtrl( itemDialog1, ID_RICHTEXTIMAGEDIALOG_OFFSET, wxEmptyString, wxDefaultPosition, wxSize(65, -1), 0 ); | |
217 | m_offset->SetMaxLength(10); | |
218 | m_offset->SetHelpText(_("The vertical offset relative to the paragraph.")); | |
219 | if (wxRichTextImageDialog::ShowToolTips()) | |
220 | m_offset->SetToolTip(_("The vertical offset relative to the paragraph.")); | |
221 | itemBoxSizer16->Add(m_offset, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
222 | ||
223 | wxArrayString m_unitsOffsetStrings; | |
224 | m_unitsOffsetStrings.Add(_("px")); | |
225 | m_unitsOffsetStrings.Add(_("cm")); | |
226 | m_unitsOffset = new wxComboBox( itemDialog1, ID_RICHTEXTIMAGEDIALOG_OFFSET_UNITS, _("px"), wxDefaultPosition, wxSize(60, -1), m_unitsOffsetStrings, wxCB_READONLY ); | |
227 | m_unitsOffset->SetStringSelection(_("px")); | |
228 | m_unitsOffset->SetHelpText(_("Units for the image offset.")); | |
229 | if (wxRichTextImageDialog::ShowToolTips()) | |
230 | m_unitsOffset->SetToolTip(_("Units for the image offset.")); | |
231 | itemBoxSizer16->Add(m_unitsOffset, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
232 | ||
233 | wxStaticText* itemStaticText19 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Move the image to:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
234 | itemFlexGridSizer4->Add(itemStaticText19, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
235 | ||
236 | wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxHORIZONTAL); | |
237 | itemFlexGridSizer4->Add(itemBoxSizer20, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5); | |
238 | ||
239 | wxButton* itemButton21 = new wxButton( itemDialog1, ID_RICHTEXTIMAGEDIALOG_PARA_UP, _("&Previous Paragraph"), wxDefaultPosition, wxDefaultSize, 0 ); | |
240 | itemButton21->SetHelpText(_("Moves the image to the previous paragraph.")); | |
241 | if (wxRichTextImageDialog::ShowToolTips()) | |
242 | itemButton21->SetToolTip(_("Moves the image to the previous paragraph.")); | |
243 | itemBoxSizer20->Add(itemButton21, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
244 | ||
245 | wxButton* itemButton22 = new wxButton( itemDialog1, ID_RICHTEXTIMAGEDIALOG_DOWN, _("&Next Paragraph"), wxDefaultPosition, wxDefaultSize, 0 ); | |
246 | itemButton22->SetHelpText(_("Moves the image to the next paragraph.")); | |
247 | if (wxRichTextImageDialog::ShowToolTips()) | |
248 | itemButton22->SetToolTip(_("Moves the image to the next paragraph.")); | |
249 | itemBoxSizer20->Add(itemButton22, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP|wxBOTTOM, 5); | |
250 | ||
251 | wxStaticLine* itemStaticLine23 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); | |
252 | itemBoxSizer2->Add(itemStaticLine23, 0, wxGROW|wxALL, 5); | |
253 | ||
254 | wxStdDialogButtonSizer* itemStdDialogButtonSizer24 = new wxStdDialogButtonSizer; | |
255 | ||
256 | itemBoxSizer2->Add(itemStdDialogButtonSizer24, 0, wxGROW|wxALL, 5); | |
257 | m_saveButton = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 ); | |
258 | m_saveButton->SetHelpText(_("Click to confirm your changes.")); | |
259 | if (wxRichTextImageDialog::ShowToolTips()) | |
260 | m_saveButton->SetToolTip(_("Click to confirm your changes.")); | |
261 | itemStdDialogButtonSizer24->AddButton(m_saveButton); | |
262 | ||
263 | m_cancelButton = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); | |
264 | m_cancelButton->SetHelpText(_("Click to discard your changes.")); | |
265 | if (wxRichTextImageDialog::ShowToolTips()) | |
266 | m_cancelButton->SetToolTip(_("Click to discard your changes.")); | |
267 | itemStdDialogButtonSizer24->AddButton(m_cancelButton); | |
268 | ||
269 | itemStdDialogButtonSizer24->Realize(); | |
270 | ||
271 | ////@end wxRichTextImageDialog content construction | |
272 | } | |
273 | ||
274 | ||
275 | /*! | |
276 | * Should we show tooltips? | |
277 | */ | |
278 | ||
279 | bool wxRichTextImageDialog::ShowToolTips() | |
280 | { | |
281 | return true; | |
282 | } | |
283 | ||
284 | /*! | |
285 | * Get bitmap resources | |
286 | */ | |
287 | ||
288 | wxBitmap wxRichTextImageDialog::GetBitmapResource( const wxString& name ) | |
289 | { | |
290 | // Bitmap retrieval | |
291 | ////@begin wxRichTextImageDialog bitmap retrieval | |
292 | wxUnusedVar(name); | |
293 | return wxNullBitmap; | |
294 | ////@end wxRichTextImageDialog bitmap retrieval | |
295 | } | |
296 | ||
297 | /*! | |
298 | * Get icon resources | |
299 | */ | |
300 | ||
301 | wxIcon wxRichTextImageDialog::GetIconResource( const wxString& name ) | |
302 | { | |
303 | // Icon retrieval | |
304 | ////@begin wxRichTextImageDialog icon retrieval | |
305 | wxUnusedVar(name); | |
306 | return wxNullIcon; | |
307 | ////@end wxRichTextImageDialog icon retrieval | |
308 | } | |
309 | ||
310 | /*! | |
311 | * Set the image attribute | |
312 | */ | |
313 | void wxRichTextImageDialog::SetImageAttr(const wxRichTextAttr& textAttr) | |
314 | { | |
315 | m_textAttr = textAttr; | |
316 | ||
317 | TransferDataToWindow(); | |
318 | } | |
319 | ||
320 | /*! | |
321 | * Apply the new style | |
322 | */ | |
323 | wxRichTextImage* wxRichTextImageDialog::ApplyImageAttr() | |
324 | { | |
325 | wxRichTextImage* image = wxDynamicCast(m_image, wxRichTextImage); | |
326 | ||
327 | TransferDataFromWindow(); | |
328 | if (m_buffer->GetRichTextCtrl()) | |
329 | { | |
330 | m_buffer->GetRichTextCtrl()->SetImageStyle(image, m_textAttr); | |
331 | } | |
332 | return image; | |
333 | } | |
334 | ||
335 | void wxRichTextImageDialog::SetImageObject(wxRichTextImage* image, wxRichTextBuffer* buffer) | |
336 | { | |
337 | wxRichTextObject* parent = image->GetParent(); | |
338 | ||
339 | m_buffer = buffer; | |
340 | m_image = image; | |
341 | m_parent = parent; | |
342 | SetImageAttr(image->GetAttributes()); | |
343 | if (image->GetImageCache().IsOk()) | |
344 | { | |
345 | if (!m_textAttr.GetTextBoxAttr().GetWidth().IsPresent() || m_textAttr.GetTextBoxAttr().GetWidth().GetValue() <= 0) | |
346 | { | |
347 | m_textAttr.GetTextBoxAttr().GetWidth().SetValue(image->GetImageCache().GetWidth()); | |
348 | m_textAttr.GetTextBoxAttr().GetWidth().SetUnits(wxTEXT_ATTR_UNITS_PIXELS); | |
349 | } | |
350 | if (!m_textAttr.GetTextBoxAttr().GetHeight().IsPresent() || m_textAttr.GetTextBoxAttr().GetHeight().GetValue() <= 0) | |
351 | { | |
352 | m_textAttr.GetTextBoxAttr().GetHeight().SetValue(image->GetImageCache().GetHeight()); | |
353 | m_textAttr.GetTextBoxAttr().GetHeight().SetUnits(wxTEXT_ATTR_UNITS_PIXELS); | |
354 | } | |
355 | } | |
356 | } | |
357 | ||
358 | void wxRichTextImageDialog::SetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl) | |
359 | { | |
360 | int unitsIdx = 0; | |
361 | ||
362 | if (!dim.IsPresent()) | |
363 | { | |
364 | dim.SetValue(0); | |
365 | dim.SetUnits(wxTEXT_ATTR_UNITS_PIXELS); | |
366 | } | |
367 | ||
368 | if (dim.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM) | |
369 | { | |
370 | unitsIdx = 1; | |
371 | float value = float(dim.GetValue()) / 10.0; | |
372 | valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value)); | |
373 | } | |
374 | else | |
375 | { | |
376 | unitsIdx = 0; | |
377 | valueCtrl->SetValue(wxString::Format(wxT("%d"), (int) dim.GetValue())); | |
378 | } | |
379 | ||
380 | unitsCtrl->SetSelection(unitsIdx); | |
381 | } | |
382 | ||
383 | void wxRichTextImageDialog::GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl) | |
384 | { | |
385 | if (unitsCtrl->GetSelection() == 1) | |
386 | dim.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM); | |
387 | else | |
388 | dim.SetUnits(wxTEXT_ATTR_UNITS_PIXELS); | |
389 | ||
390 | int value = 0; | |
391 | if (ConvertFromString(valueCtrl->GetValue(), value, dim.GetUnits())) | |
392 | dim.SetValue(value); | |
393 | } | |
394 | ||
395 | bool wxRichTextImageDialog::TransferDataToWindow() | |
396 | { | |
397 | m_float->SetSelection(m_textAttr.GetTextBoxAttr().GetFloatMode()); | |
398 | ||
399 | SetDimensionValue(m_textAttr.GetTextBoxAttr().GetWidth(), m_width, m_unitsW); | |
400 | SetDimensionValue(m_textAttr.GetTextBoxAttr().GetHeight(), m_height, m_unitsH); | |
401 | SetDimensionValue(m_textAttr.GetTextBoxAttr().GetTop(), m_offset, m_unitsOffset); | |
402 | ||
403 | return true; | |
404 | } | |
405 | ||
406 | bool wxRichTextImageDialog::TransferDataFromWindow() | |
407 | { | |
408 | m_textAttr.GetTextBoxAttr().SetFloatMode(m_float->GetSelection()); | |
409 | ||
410 | GetDimensionValue(m_textAttr.GetTextBoxAttr().GetWidth(), m_width, m_unitsW); | |
411 | GetDimensionValue(m_textAttr.GetTextBoxAttr().GetHeight(), m_height, m_unitsH); | |
412 | GetDimensionValue(m_textAttr.GetTextBoxAttr().GetTop(), m_offset, m_unitsOffset); | |
413 | ||
414 | return true; | |
415 | } | |
416 | ||
417 | bool wxRichTextImageDialog::ConvertFromString(const wxString& string, int& ret, int scale) | |
418 | { | |
419 | const wxChar* chars = string.GetData(); | |
420 | int remain = 2; | |
421 | bool dot = false; | |
422 | ret = 0; | |
423 | ||
424 | for (unsigned int i = 0; i < string.Len() && remain; i++) | |
425 | { | |
426 | if (!(chars[i] >= '0' && chars[i] <= '9') && !(scale == wxTEXT_ATTR_UNITS_TENTHS_MM && chars[i] == '.')) | |
427 | return false; | |
428 | ||
429 | if (chars[i] == '.') | |
430 | { | |
431 | dot = true; | |
432 | continue; | |
433 | } | |
434 | ||
435 | if (dot) | |
436 | remain--; | |
437 | ||
438 | ret = ret * 10 + chars[i] - '0'; | |
439 | } | |
440 | ||
441 | while (remain-- > 0 && scale == wxTEXT_ATTR_UNITS_TENTHS_MM) | |
442 | ret *= 10; | |
443 | ||
444 | return true; | |
445 | } | |
446 | ||
447 | ||
448 | /*! | |
449 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_PARA_UP | |
450 | */ | |
451 | void wxRichTextImageDialog::OnRichtextimagedialogParaUpClick( wxCommandEvent& WXUNUSED(event)) | |
452 | { | |
453 | // Before editing this code, remove the block markers. | |
454 | wxRichTextRange range = m_image->GetRange(); | |
455 | wxRichTextObjectList::compatibility_iterator iter = m_buffer->GetChildren().GetFirst(); | |
456 | if (!iter) | |
457 | return; | |
458 | ||
459 | while (iter) | |
460 | { | |
461 | if (iter->GetData() == m_parent) | |
462 | break; | |
463 | iter = iter->GetNext(); | |
464 | } | |
465 | ||
466 | iter = iter->GetPrevious(); | |
467 | if (!iter) | |
468 | return; | |
469 | ||
470 | wxRichTextObject *obj = iter->GetData(); | |
471 | wxRichTextRange rg = obj->GetRange(); | |
472 | m_image = m_image->Clone(); | |
473 | ||
474 | m_buffer->DeleteRangeWithUndo(range, m_buffer->GetRichTextCtrl()); | |
475 | m_buffer->InsertObjectWithUndo(rg.GetEnd(), m_image, m_buffer->GetRichTextCtrl(), 0); | |
476 | m_parent = obj; | |
477 | m_image->SetRange(wxRichTextRange(rg.GetEnd(), rg.GetEnd())); | |
478 | } | |
479 | ||
480 | ||
481 | /*! | |
482 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_PARA_DOWN | |
483 | */ | |
484 | ||
485 | void wxRichTextImageDialog::OnRichtextimagedialogDownClick( wxCommandEvent& WXUNUSED(event)) | |
486 | { | |
487 | // Before editing this code, remove the block markers. | |
488 | wxRichTextRange range = m_image->GetRange(); | |
489 | wxRichTextObjectList::compatibility_iterator iter = m_buffer->GetChildren().GetFirst(); | |
490 | if (!iter) | |
491 | return; | |
492 | ||
493 | while (iter) | |
494 | { | |
495 | if (iter->GetData() == m_parent) | |
496 | break; | |
497 | iter = iter->GetNext(); | |
498 | } | |
499 | ||
500 | iter = iter->GetNext(); | |
501 | if (!iter) | |
502 | return; | |
503 | ||
504 | wxRichTextObject *obj = iter->GetData(); | |
505 | wxRichTextRange rg = obj->GetRange(); | |
506 | m_image = m_image->Clone(); | |
507 | ||
508 | m_buffer->DeleteRangeWithUndo(range, m_buffer->GetRichTextCtrl()); | |
509 | m_buffer->InsertObjectWithUndo(rg.GetEnd(), m_image, m_buffer->GetRichTextCtrl(), 0); | |
510 | m_parent = obj; | |
511 | m_image->SetRange(wxRichTextRange(rg.GetEnd(), rg.GetEnd())); | |
512 | } | |
513 | ||
514 | #endif |