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