]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/ogl/divided.cpp
Source cleaning.
[wxWidgets.git] / contrib / src / ogl / divided.cpp
CommitLineData
1fc25a89
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: divided.cpp
3// Purpose: wxDividedShape class
4// Author: Julian Smart
5// Modified by:
6// Created: 12/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
2ba06d5a 9// Licence: wxWindows licence
1fc25a89
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "divided.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
92a19c2e 17#include "wx/wxprec.h"
1fc25a89
JS
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <wx/wx.h>
25#endif
26
5f331691 27#if wxUSE_PROLOGIO
7c9955d1 28#include <wx/deprecated/wxexpr.h>
fd657b8a 29#endif
1fc25a89 30
5f331691
RD
31#include "wx/ogl/ogl.h"
32
1fc25a89
JS
33
34class wxDividedShapeControlPoint: public wxControlPoint
35{
36 DECLARE_DYNAMIC_CLASS(wxDividedShapeControlPoint)
37 private:
38 int regionId;
39 public:
40 wxDividedShapeControlPoint() { regionId = 0; }
41 wxDividedShapeControlPoint(wxShapeCanvas *the_canvas, wxShape *object, int region,
42 double size, double the_xoffset, double the_yoffset, int the_type);
43 ~wxDividedShapeControlPoint();
44
45 void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
46 void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
47 void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
48};
49
50IMPLEMENT_DYNAMIC_CLASS(wxDividedShapeControlPoint, wxControlPoint)
51
52/*
53 * Divided object
54 *
55 */
56
57IMPLEMENT_DYNAMIC_CLASS(wxDividedShape, wxRectangleShape)
58
59wxDividedShape::wxDividedShape(double w, double h): wxRectangleShape(w, h)
60{
61 ClearRegions();
62}
63
64wxDividedShape::~wxDividedShape()
65{
66}
67
68void wxDividedShape::OnDraw(wxDC& dc)
69{
70 wxRectangleShape::OnDraw(dc);
71}
72
73void wxDividedShape::OnDrawContents(wxDC& dc)
74{
b9ac87bc 75 double defaultProportion = (double)(GetRegions().GetCount() > 0 ? (1.0/((double)(GetRegions().GetCount()))) : 0.0);
1fc25a89
JS
76 double currentY = (double)(m_ypos - (m_height / 2.0));
77 double maxY = (double)(m_ypos + (m_height / 2.0));
78
79 double leftX = (double)(m_xpos - (m_width / 2.0));
80 double rightX = (double)(m_xpos + (m_width / 2.0));
81
82 if (m_pen) dc.SetPen(* m_pen);
83
93210c68 84 dc.SetTextForeground(m_textColour);
1fc25a89
JS
85
86#ifdef __WXMSW__
87 // For efficiency, don't do this under X - doesn't make
88 // any visible difference for our purposes.
89 if (m_brush)
90 dc.SetTextBackground(m_brush->GetColour());
91#endif
92/*
93 if (!formatted)
94 {
95 FormatRegionText();
2ba06d5a 96 formatted = true;
1fc25a89
JS
97 }
98*/
99 if (GetDisableLabel()) return;
100
101 double xMargin = 2;
102 double yMargin = 2;
103 dc.SetBackgroundMode(wxTRANSPARENT);
104
5e0dbc8d 105 wxObjectList::compatibility_iterator node = GetRegions().GetFirst();
1fc25a89
JS
106 while (node)
107 {
b9ac87bc 108 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89 109 dc.SetFont(* region->GetFont());
93210c68 110 dc.SetTextForeground(region->GetActualColourObject());
1fc25a89
JS
111
112 double proportion =
113 region->m_regionProportionY < 0.0 ? defaultProportion : region->m_regionProportionY;
114
115 double y = currentY + m_height*proportion;
116 double actualY = maxY < y ? maxY : y;
117
118 double centreX = m_xpos;
119 double centreY = (double)(currentY + (actualY - currentY)/2.0);
120
121 oglDrawFormattedText(dc, &region->m_formattedText,
122 (double)(centreX), (double)(centreY), (double)(m_width-2*xMargin), (double)(actualY - currentY - 2*yMargin),
123 region->m_formatMode);
b9ac87bc 124 if ((y <= maxY) && (node->GetNext()))
1fc25a89
JS
125 {
126 wxPen *regionPen = region->GetActualPen();
127 if (regionPen)
128 {
129 dc.SetPen(* regionPen);
130 dc.DrawLine(WXROUND(leftX), WXROUND(y), WXROUND(rightX), WXROUND(y));
131 }
132 }
133
134 currentY = actualY;
135
b9ac87bc 136 node = node->GetNext();
1fc25a89
JS
137 }
138}
139
1484b5cc 140void wxDividedShape::SetSize(double w, double h, bool WXUNUSED(recursive))
1fc25a89
JS
141{
142 SetAttachmentSize(w, h);
143 m_width = w;
144 m_height = h;
145 SetRegionSizes();
146}
147
148void wxDividedShape::SetRegionSizes()
149{
b9ac87bc 150 if (GetRegions().GetCount() == 0)
1fc25a89
JS
151 return;
152
b9ac87bc 153 double defaultProportion = (double)(GetRegions().GetCount() > 0 ? (1.0/((double)(GetRegions().GetCount()))) : 0.0);
1fc25a89
JS
154 double currentY = (double)(m_ypos - (m_height / 2.0));
155 double maxY = (double)(m_ypos + (m_height / 2.0));
156
157// double leftX = (double)(m_xpos - (m_width / 2.0));
158// double rightX = (double)(m_xpos + (m_width / 2.0));
159
5e0dbc8d 160 wxObjectList::compatibility_iterator node = GetRegions().GetFirst();
1fc25a89
JS
161 while (node)
162 {
b9ac87bc 163 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
164 double proportion =
165 region->m_regionProportionY <= 0.0 ? defaultProportion : region->m_regionProportionY;
166
167 double sizeY = (double)proportion*m_height;
168 double y = currentY + sizeY;
169 double actualY = maxY < y ? maxY : y;
170
171 double centreY = (double)(currentY + (actualY - currentY)/2.0);
172
173 region->SetSize(m_width, sizeY);
174 region->SetPosition(0.0, (double)(centreY - m_ypos));
175 currentY = actualY;
b9ac87bc 176 node = node->GetNext();
1fc25a89
JS
177 }
178}
179
180// Attachment points correspond to regions in the divided box
181bool wxDividedShape::GetAttachmentPosition(int attachment, double *x, double *y, int nth, int no_arcs,
182 wxLineShape *line)
183{
b9ac87bc 184 int totalNumberAttachments = (GetRegions().GetCount() * 2) + 2;
1fc25a89
JS
185 if ((GetAttachmentMode() == ATTACHMENT_MODE_NONE) || (attachment >= totalNumberAttachments))
186 {
187 return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs);
188 }
189
b9ac87bc 190 int n = GetRegions().GetCount();
1fc25a89
JS
191 bool isEnd = (line && line->IsEnd(this));
192
193 double left = (double)(m_xpos - m_width/2.0);
194 double right = (double)(m_xpos + m_width/2.0);
195 double top = (double)(m_ypos - m_height/2.0);
196 double bottom = (double)(m_ypos + m_height/2.0);
197
198 // Zero is top, n+1 is bottom.
199 if (attachment == 0)
200 {
201 *y = top;
202 if (m_spaceAttachments)
203 {
204 if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
205 {
206 // Align line according to the next handle along
207 wxRealPoint *point = line->GetNextControlPoint(this);
208 if (point->x < left)
209 *x = left;
210 else if (point->x > right)
211 *x = right;
212 else
213 *x = point->x;
214 }
215 else
216 *x = left + (nth + 1)*m_width/(no_arcs + 1);
217 }
218 else
219 *x = m_xpos;
220 }
221 else if (attachment == (n+1))
222 {
223 *y = bottom;
224 if (m_spaceAttachments)
225 {
226 if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
227 {
228 // Align line according to the next handle along
229 wxRealPoint *point = line->GetNextControlPoint(this);
230 if (point->x < left)
231 *x = left;
232 else if (point->x > right)
233 *x = right;
234 else
235 *x = point->x;
236 }
237 else
238 *x = left + (nth + 1)*m_width/(no_arcs + 1);
239 }
240 else
241 *x = m_xpos;
242 }
243 // Left or right.
244 else
245 {
8552e6f0
MB
246 bool isLeft = !(attachment < (n+1));
247 int i = (isLeft) ? (totalNumberAttachments - attachment - 1) : (attachment-1);
5e0dbc8d 248 wxObjectList::compatibility_iterator node = GetRegions().Item(i);
1fc25a89
JS
249 if (node)
250 {
b9ac87bc 251 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
252
253 if (isLeft)
254 *x = left;
255 else
256 *x = right;
257
258 // Calculate top and bottom of region
259 top = (double)((m_ypos + region->m_y) - (region->m_height/2.0));
260 bottom = (double)((m_ypos + region->m_y) + (region->m_height/2.0));
261
262 // Assuming we can trust the absolute size and
263 // position of these regions...
264 if (m_spaceAttachments)
265 {
266 if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
267 {
268 // Align line according to the next handle along
269 wxRealPoint *point = line->GetNextControlPoint(this);
270 if (point->y < bottom)
271 *y = bottom;
272 else if (point->y > top)
273 *y = top;
274 else
275 *y = point->y;
276 }
277 else
278// *y = (double)(((m_ypos + region->m_y) - (region->m_height/2.0)) + (nth + 1)*region->m_height/(no_arcs+1));
279 *y = (double)(top + (nth + 1)*region->m_height/(no_arcs+1));
280 }
281 else
282 *y = (double)(m_ypos + region->m_y);
283 }
284 else
285 {
286 *x = m_xpos;
287 *y = m_ypos;
2ba06d5a 288 return false;
1fc25a89
JS
289 }
290 }
2ba06d5a 291 return true;
1fc25a89
JS
292}
293
294int wxDividedShape::GetNumberOfAttachments() const
295{
296 // There are two attachments for each region (left and right),
297 // plus one on the top and one on the bottom.
b9ac87bc 298 int n = (GetRegions().GetCount() * 2) + 2;
1fc25a89
JS
299
300 int maxN = n - 1;
5e0dbc8d 301 wxObjectList::compatibility_iterator node = m_attachmentPoints.GetFirst();
1fc25a89
JS
302 while (node)
303 {
b9ac87bc 304 wxAttachmentPoint *point = (wxAttachmentPoint *)node->GetData();
1fc25a89
JS
305 if (point->m_id > maxN)
306 maxN = point->m_id;
b9ac87bc 307 node = node->GetNext();
1fc25a89
JS
308 }
309 return maxN + 1;
310}
311
0a2c0398 312bool wxDividedShape::AttachmentIsValid(int attachment) const
1fc25a89 313{
b9ac87bc 314 int totalNumberAttachments = (GetRegions().GetCount() * 2) + 2;
1fc25a89
JS
315 if (attachment >= totalNumberAttachments)
316 {
317 return wxShape::AttachmentIsValid(attachment);
318 }
319 else if (attachment >= 0)
2ba06d5a 320 return true;
1fc25a89 321 else
2ba06d5a 322 return false;
1fc25a89
JS
323}
324
325void wxDividedShape::Copy(wxShape& copy)
326{
327 wxRectangleShape::Copy(copy);
328}
329
330// Region operations
331
332void wxDividedShape::MakeControlPoints()
333{
334 wxRectangleShape::MakeControlPoints();
335
336 MakeMandatoryControlPoints();
337}
338
339void wxDividedShape::MakeMandatoryControlPoints()
340{
341 double currentY = (double)(GetY() - (m_height / 2.0));
342 double maxY = (double)(GetY() + (m_height / 2.0));
343
5e0dbc8d 344 wxObjectList::compatibility_iterator node = GetRegions().GetFirst();
1fc25a89
JS
345 int i = 0;
346 while (node)
347 {
b9ac87bc 348 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
349
350 double proportion = region->m_regionProportionY;
351
352 double y = currentY + m_height*proportion;
353 double actualY = (double)(maxY < y ? maxY : y);
354
b9ac87bc 355 if (node->GetNext())
1fc25a89
JS
356 {
357 wxDividedShapeControlPoint *controlPoint =
358 new wxDividedShapeControlPoint(m_canvas, this, i, CONTROL_POINT_SIZE, 0.0, (double)(actualY - GetY()), 0);
359 m_canvas->AddShape(controlPoint);
360 m_controlPoints.Append(controlPoint);
361 }
362 currentY = actualY;
363 i ++;
b9ac87bc 364 node = node->GetNext();
1fc25a89
JS
365 }
366}
367
368void wxDividedShape::ResetControlPoints()
369{
370 // May only have the region handles, (n - 1) of them.
b9ac87bc 371 if (m_controlPoints.GetCount() > (GetRegions().GetCount() - 1))
1fc25a89
JS
372 wxRectangleShape::ResetControlPoints();
373
374 ResetMandatoryControlPoints();
375}
376
377void wxDividedShape::ResetMandatoryControlPoints()
378{
379 double currentY = (double)(GetY() - (m_height / 2.0));
380 double maxY = (double)(GetY() + (m_height / 2.0));
381
5e0dbc8d 382 wxObjectList::compatibility_iterator node = m_controlPoints.GetFirst();
1fc25a89
JS
383 int i = 0;
384 while (node)
385 {
b9ac87bc 386 wxControlPoint *controlPoint = (wxControlPoint *)node->GetData();
1fc25a89
JS
387 if (controlPoint->IsKindOf(CLASSINFO(wxDividedShapeControlPoint)))
388 {
5e0dbc8d 389 wxObjectList::compatibility_iterator node1 = GetRegions().Item(i);
b9ac87bc 390 wxShapeRegion *region = (wxShapeRegion *)node1->GetData();
1fc25a89
JS
391
392 double proportion = region->m_regionProportionY;
393
394 double y = currentY + m_height*proportion;
395 double actualY = (double)(maxY < y ? maxY : y);
396
397 controlPoint->m_xoffset = 0.0;
398 controlPoint->m_yoffset = (double)(actualY - GetY());
399 currentY = actualY;
400 i ++;
401 }
b9ac87bc 402 node = node->GetNext();
1fc25a89
JS
403 }
404}
405
2b5f62a0 406#if wxUSE_PROLOGIO
1fc25a89
JS
407void wxDividedShape::WriteAttributes(wxExpr *clause)
408{
409 wxRectangleShape::WriteAttributes(clause);
410}
411
412void wxDividedShape::ReadAttributes(wxExpr *clause)
413{
414 wxRectangleShape::ReadAttributes(clause);
415}
416#endif
417
418/*
419 * Edit the division colour/style
420 *
421 */
422
423void wxDividedShape::EditRegions()
424{
9e053640 425 wxMessageBox(wxT("EditRegions() is unimplemented."), wxT("OGL"), wxOK);
1fc25a89
JS
426
427 // TODO
428#if 0
b9ac87bc 429 if (GetRegions().GetCount() < 2)
1fc25a89
JS
430 return;
431
432 wxBeginBusyCursor();
433
434 GraphicsForm *form = new GraphicsForm("Divided nodes");
435 // Need an array to store all the style strings,
436 // since they need to be converted to integers
b9ac87bc
RD
437 char **styleStrings = new char *[GetRegions().GetCount()];
438 for (int j = 0; j < GetRegions().GetCount(); j++)
1fc25a89
JS
439 styleStrings[j] = NULL;
440
441 int i = 0;
b9ac87bc
RD
442 wxNode *node = GetRegions().GetFirst();
443 while (node && node->GetNext())
1fc25a89 444 {
b9ac87bc 445 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
446 char buf[50];
447 sprintf(buf, "Region %d", (i+1));
448 form->Add(wxMakeFormMessage(buf));
449 form->Add(wxMakeFormNewLine());
450
451 form->Add(wxMakeFormString("Colour", &region->penColour, wxFORM_CHOICE,
452 new wxList(wxMakeConstraintStrings(
453 "Invisible" ,
454 "BLACK" ,
455 "BLUE" ,
456 "BROWN" ,
457 "CORAL" ,
458 "CYAN" ,
459 "DARK GREY" ,
460 "DARK GREEN" ,
461 "DIM GREY" ,
462 "GREY" ,
463 "GREEN" ,
464 "LIGHT BLUE" ,
465 "LIGHT GREY" ,
466 "MAGENTA" ,
467 "MAROON" ,
468 "NAVY" ,
469 "ORANGE" ,
470 "PURPLE" ,
471 "RED" ,
472 "TURQUOISE" ,
473 "VIOLET" ,
474 "WHITE" ,
475 "YELLOW" ,
476 NULL),
477 NULL), NULL, wxVERTICAL, 150));
478
479 char *styleString = NULL;
480 switch (region->penStyle)
481 {
482 case wxSHORT_DASH:
483 styleString = "Short Dash";
484 break;
485 case wxLONG_DASH:
486 styleString = "Long Dash";
487 break;
488 case wxDOT:
489 styleString = "Dot";
490 break;
491 case wxDOT_DASH:
492 styleString = "Dot Dash";
493 break;
494 case wxSOLID:
495 default:
496 styleString = "Solid";
497 break;
498 }
499 styleStrings[i] = copystring(styleString);
500 form->Add(wxMakeFormString("Style", &(styleStrings[i]), wxFORM_CHOICE,
501 new wxList(wxMakeConstraintStrings(
502 "Solid" ,
503 "Short Dash" ,
504 "Long Dash" ,
505 "Dot" ,
506 "Dot Dash" ,
507 NULL),
508 NULL), NULL, wxVERTICAL, 100));
b9ac87bc 509 node = node->GetNext();
1fc25a89 510 i ++;
b9ac87bc 511 if (node && node->GetNext())
1fc25a89
JS
512 form->Add(wxMakeFormNewLine());
513 }
514 wxDialogBox *dialog = new wxDialogBox(m_canvas->GetParent(), "Divided object properties", 10, 10, 500, 500);
515 if (GraphicsLabelFont)
516 dialog->SetLabelFont(GraphicsLabelFont);
517 if (GraphicsButtonFont)
518 dialog->SetButtonFont(GraphicsButtonFont);
519 form->AssociatePanel(dialog);
520 form->dialog = dialog;
521
522 dialog->Fit();
523 dialog->Centre(wxBOTH);
524
525 wxEndBusyCursor();
526
2ba06d5a 527 dialog->Show(true);
1fc25a89 528
b9ac87bc 529 node = GetRegions().GetFirst();
1fc25a89
JS
530 i = 0;
531 while (node)
532 {
b9ac87bc 533 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
534
535 if (styleStrings[i])
536 {
537 if (strcmp(styleStrings[i], "Solid") == 0)
538 region->penStyle = wxSOLID;
539 else if (strcmp(styleStrings[i], "Dot") == 0)
540 region->penStyle = wxDOT;
541 else if (strcmp(styleStrings[i], "Short Dash") == 0)
542 region->penStyle = wxSHORT_DASH;
543 else if (strcmp(styleStrings[i], "Long Dash") == 0)
544 region->penStyle = wxLONG_DASH;
545 else if (strcmp(styleStrings[i], "Dot Dash") == 0)
546 region->penStyle = wxDOT_DASH;
547 delete[] styleStrings[i];
548 }
549 region->m_actualPenObject = NULL;
b9ac87bc 550 node = node->GetNext();
1fc25a89
JS
551 i ++;
552 }
553 delete[] styleStrings;
554 Draw(dc);
555#endif
556}
557
558void wxDividedShape::OnRightClick(double x, double y, int keys, int attachment)
559{
560 if (keys & KEY_CTRL)
561 {
562 EditRegions();
563 }
564 else
565 {
566 wxRectangleShape::OnRightClick(x, y, keys, attachment);
567 }
568}
569
570wxDividedShapeControlPoint::wxDividedShapeControlPoint(wxShapeCanvas *the_canvas, wxShape *object,
571 int region, double size, double the_m_xoffset, double the_m_yoffset, int the_type):
572 wxControlPoint(the_canvas, object, size, the_m_xoffset, the_m_yoffset, the_type)
573{
574 regionId = region;
575}
576
577wxDividedShapeControlPoint::~wxDividedShapeControlPoint()
578{
579}
580
581// Implement resizing of divided object division
1484b5cc 582void wxDividedShapeControlPoint::OnDragLeft(bool WXUNUSED(draw), double WXUNUSED(x), double y, int WXUNUSED(keys), int WXUNUSED(attachment))
1fc25a89
JS
583{
584 wxClientDC dc(GetCanvas());
585 GetCanvas()->PrepareDC(dc);
586
587 dc.SetLogicalFunction(OGLRBLF);
588 wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
589 dc.SetPen(dottedPen);
590 dc.SetBrush((* wxTRANSPARENT_BRUSH));
591
592 wxDividedShape *dividedObject = (wxDividedShape *)m_shape;
593 double x1 = (double)(dividedObject->GetX() - (dividedObject->GetWidth()/2.0));
594 double y1 = y;
595 double x2 = (double)(dividedObject->GetX() + (dividedObject->GetWidth()/2.0));
596 double y2 = y;
597 dc.DrawLine(WXROUND(x1), WXROUND(y1), WXROUND(x2), WXROUND(y2));
598}
599
1484b5cc 600void wxDividedShapeControlPoint::OnBeginDragLeft(double WXUNUSED(x), double y, int WXUNUSED(keys), int WXUNUSED(attachment))
1fc25a89
JS
601{
602 wxClientDC dc(GetCanvas());
603 GetCanvas()->PrepareDC(dc);
604
605 wxDividedShape *dividedObject = (wxDividedShape *)m_shape;
606 dc.SetLogicalFunction(OGLRBLF);
607 wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
608 dc.SetPen(dottedPen);
609 dc.SetBrush((* wxTRANSPARENT_BRUSH));
610
611 double x1 = (double)(dividedObject->GetX() - (dividedObject->GetWidth()/2.0));
612 double y1 = y;
613 double x2 = (double)(dividedObject->GetX() + (dividedObject->GetWidth()/2.0));
614 double y2 = y;
615 dc.DrawLine(WXROUND(x1), WXROUND(y1), WXROUND(x2), WXROUND(y2));
616 m_canvas->CaptureMouse();
617}
618
1484b5cc 619void wxDividedShapeControlPoint::OnEndDragLeft(double WXUNUSED(x), double y, int WXUNUSED(keys), int WXUNUSED(attachment))
1fc25a89
JS
620{
621 wxClientDC dc(GetCanvas());
622 GetCanvas()->PrepareDC(dc);
623
624 wxDividedShape *dividedObject = (wxDividedShape *)m_shape;
5e0dbc8d 625 wxObjectList::compatibility_iterator node = dividedObject->GetRegions().Item(regionId);
1fc25a89
JS
626 if (!node)
627 return;
628
b9ac87bc 629 wxShapeRegion *thisRegion = (wxShapeRegion *)node->GetData();
1fc25a89
JS
630 wxShapeRegion *nextRegion = NULL; // Region below this one
631
632 dc.SetLogicalFunction(wxCOPY);
633
634 m_canvas->ReleaseMouse();
635
636 // Find the old top and bottom of this region,
637 // and calculate the new proportion for this region
638 // if legal.
639
640 double currentY = (double)(dividedObject->GetY() - (dividedObject->GetHeight() / 2.0));
641 double maxY = (double)(dividedObject->GetY() + (dividedObject->GetHeight() / 2.0));
642
643 // Save values
644 double thisRegionTop = 0.0;
1fc25a89
JS
645 double nextRegionBottom = 0.0;
646
b9ac87bc 647 node = dividedObject->GetRegions().GetFirst();
1fc25a89
JS
648 while (node)
649 {
b9ac87bc 650 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
651
652 double proportion = region->m_regionProportionY;
653 double yy = currentY + (dividedObject->GetHeight()*proportion);
654 double actualY = (double)(maxY < yy ? maxY : yy);
655
656 if (region == thisRegion)
657 {
658 thisRegionTop = currentY;
b9ac87bc
RD
659 if (node->GetNext())
660 nextRegion = (wxShapeRegion *)node->GetNext()->GetData();
1fc25a89
JS
661 }
662 if (region == nextRegion)
663 {
664 nextRegionBottom = actualY;
665 }
666
667 currentY = actualY;
b9ac87bc 668 node = node->GetNext();
1fc25a89
JS
669 }
670 if (!nextRegion)
671 return;
672
673 // Check that we haven't gone above this region or below
674 // next region.
675 if ((y <= thisRegionTop) || (y >= nextRegionBottom))
676 return;
677
678 dividedObject->EraseLinks(dc);
679
680 // Now calculate the new proportions of this region and the next region.
681 double thisProportion = (double)((y - thisRegionTop)/dividedObject->GetHeight());
682 double nextProportion = (double)((nextRegionBottom - y)/dividedObject->GetHeight());
683 thisRegion->SetProportions(0.0, thisProportion);
684 nextRegion->SetProportions(0.0, nextProportion);
685 m_yoffset = (double)(y - dividedObject->GetY());
686
687 // Now reformat text
688 int i = 0;
b9ac87bc 689 node = dividedObject->GetRegions().GetFirst();
1fc25a89
JS
690 while (node)
691 {
b9ac87bc 692 wxShapeRegion *region = (wxShapeRegion *)node->GetData();
1fc25a89
JS
693 if (region->GetText())
694 {
17401ab1
JS
695 wxString s(region->GetText());
696 dividedObject->FormatText(dc, s.c_str(), i);
1fc25a89 697 }
b9ac87bc 698 node = node->GetNext();
1fc25a89
JS
699 i++;
700 }
701 dividedObject->SetRegionSizes();
702 dividedObject->Draw(dc);
703 dividedObject->GetEventHandler()->OnMoveLinks(dc);
704}
705