~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/ogl/divided.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

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