File: layout.cpp

package info (click to toggle)
wxformbuilder 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,908 kB
  • sloc: cpp: 37,318; xml: 6,611; javascript: 1,353; python: 94; sh: 62; makefile: 62
file content (691 lines) | stat: -rw-r--r-- 26,331 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
///////////////////////////////////////////////////////////////////////////////
//
// wxFormBuilder - A Visual Dialog Editor for wxWidgets.
// Copyright (C) 2005 José Antonio Hurtado
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// Written by
//   José Antonio Hurtado - joseantonio.hurtado@gmail.com
//   Juan Antonio Ortega  - jortegalalmolda@gmail.com
//
///////////////////////////////////////////////////////////////////////////////

#include <cstring>
#include <map>

#include <wx/gbsizer.h>
#include <wx/wrapsizer.h>

#include <common/xmlutils.h>
#include <plugin_interface/plugin.h>
#include <plugin_interface/xrcconv.h>


class SpacerComponent : public ComponentBase
{
public:
    // ImportFromXRC is handled in sizeritem components

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj, std::nullopt, "");
        filter.AddPropertyPair("width", "height", "size");
        return xrc;
    }
};

class GBSizerItemComponent : public ComponentBase
{
public:
    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj, "sizeritem", "");
        filter.AddProperty(XrcFilter::Type::BitList, "flag");
        filter.AddProperty(XrcFilter::Type::Integer, "border");
        filter.AddPropertyPair("row", "column", "cellpos");
        filter.AddPropertyPair("rowspan", "colspan", "cellspan");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc, "gbsizeritem", "");
        filter.AddProperty(XrcFilter::Type::BitList, "flag");
        filter.AddProperty(XrcFilter::Type::Integer, "border");
        filter.AddPropertyPair("cellpos", "row", "column");
        filter.AddPropertyPair("cellspan", "rowspan", "colspan");

        // XrcLoader::GetObject imports spacers as sizeritems, check if this is a spacer
        if (!xrc->FirstChildElement("object") && xrc->FirstChildElement("size")) {
            XrcToXfbFilter spacerFilter(xfb->InsertNewChildElement(""), GetLibrary(), xrc, "spacer", "");
            spacerFilter.AddPropertyPair("size", "width", "height");
        }

        return xfb;
    }
};

class SizerItemComponent : public ComponentBase
{
public:
    void OnCreated(wxObject* wxobject, wxWindow* /*wxparent*/) override
    {
        // Get parent sizer
        wxObject* parent = GetManager()->GetParent(wxobject);
        wxSizer* sizer = wxDynamicCast(parent, wxSizer);

        if (NULL == sizer) {
            wxLogError(
              wxT("The parent of a SizerItem is either missing or not a wxSizer - this should not be possible!"));
            return;
        }

        // Get child window
        wxObject* child = GetManager()->GetChild(wxobject, 0);
        if (NULL == child) {
            wxLogError(wxT("The SizerItem component has no child - this should not be possible!"));
            return;
        }

        // Get IObject for property access
        IObject* obj = GetManager()->GetIObject(wxobject);
        IObject* childObj = GetManager()->GetIObject(child);

        // Add the spacer
        if (_("spacer") == childObj->GetClassName()) {
            sizer->Add(
              childObj->GetPropertyAsInteger(_("width")), childObj->GetPropertyAsInteger(_("height")),
              obj->GetPropertyAsInteger(_("proportion")), obj->GetPropertyAsInteger(_("flag")),
              obj->GetPropertyAsInteger(_("border")));
            return;
        }

        // Add the child ( window or sizer ) to the sizer
        wxWindow* windowChild = wxDynamicCast(child, wxWindow);
        wxSizer* sizerChild = wxDynamicCast(child, wxSizer);

        if (windowChild != NULL) {
            sizer->Add(
              windowChild, obj->GetPropertyAsInteger(_("proportion")), obj->GetPropertyAsInteger(_("flag")),
              obj->GetPropertyAsInteger(_("border")));
        } else if (sizerChild != NULL) {
            sizer->Add(
              sizerChild, obj->GetPropertyAsInteger(_("proportion")), obj->GetPropertyAsInteger(_("flag")),
              obj->GetPropertyAsInteger(_("border")));
        } else {
            wxLogError(
              wxT("The SizerItem component's child is not a wxWindow or a wxSizer or a spacer - this should not be "
                  "possible!"));
        }
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj, std::nullopt, "");
        filter.AddProperty(XrcFilter::Type::BitList, "flag");
        filter.AddProperty(XrcFilter::Type::Integer, "border");
        filter.AddProperty(XrcFilter::Type::Integer, "proportion", "option");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc, std::nullopt, "");
        filter.AddProperty(XrcFilter::Type::BitList, "flag");
        filter.AddProperty(XrcFilter::Type::Integer, "border");
        filter.AddProperty(XrcFilter::Type::Integer, "option", "proportion");

        // XrcLoader::GetObject imports spacers as sizeritems, check if this is a spacer
        if (!xrc->FirstChildElement("object") && xrc->FirstChildElement("size")) {
            XrcToXfbFilter spacerFilter(xfb->InsertNewChildElement(""), GetLibrary(), xrc, "spacer", "");
            spacerFilter.AddPropertyPair("size", "width", "height");
        }

        return xfb;
    }
};

class BoxSizerComponent : public ComponentBase
{
public:
    wxObject* Create(IObject* obj, wxObject* /*parent*/) override
    {
        wxBoxSizer* sizer = new wxBoxSizer(obj->GetPropertyAsInteger(_("orient")));
        sizer->SetMinSize(obj->GetPropertyAsSize(_("minimum_size")));
        return sizer;
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);
        if (obj->GetPropertyAsSize("minimum_size") != wxDefaultSize) {
            filter.AddProperty(XrcFilter::Type::Size, "minimum_size", "minsize");
        }
        filter.AddProperty(XrcFilter::Type::Option, "orient");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);
        filter.AddProperty(XrcFilter::Type::Size, "minsize", "minimum_size");
        filter.AddProperty(XrcFilter::Type::Option, "orient");
        return xfb;
    }
};

class WrapSizerComponent : public ComponentBase
{
public:
    wxObject* Create(IObject* obj, wxObject* /*parent*/) override
    {
        const auto sizer =
          new wxWrapSizer(obj->GetPropertyAsInteger(_("orient")), obj->GetPropertyAsInteger(_("flags")));
        sizer->SetMinSize(obj->GetPropertyAsSize(_("minimum_size")));
        return sizer;
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);
        if (obj->GetPropertyAsSize("minimum_size") != wxDefaultSize) {
            filter.AddProperty(XrcFilter::Type::Size, "minimum_size", "minsize");
        }
        filter.AddProperty(XrcFilter::Type::Option, "orient");
        filter.AddProperty(XrcFilter::Type::BitList, "flags");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);
        filter.AddProperty(XrcFilter::Type::Size, "minsize", "minimum_size");
        filter.AddProperty(XrcFilter::Type::Option, "orient");
        filter.AddProperty(XrcFilter::Type::BitList, "flags");
        return xfb;
    }
};

class StaticBoxSizerComponent : public ComponentBase
{
public:
    int m_count;
    StaticBoxSizerComponent() { m_count = 0; }
    wxObject* Create(IObject* obj, wxObject* parent) override
    {
        m_count++;
        wxStaticBox* box = new wxStaticBox((wxWindow*)parent, wxID_ANY, obj->GetPropertyAsString(_("label")));

        wxStaticBoxSizer* sizer = new wxStaticBoxSizer(box, obj->GetPropertyAsInteger(_("orient")));

        sizer->SetMinSize(obj->GetPropertyAsSize(_("minimum_size")));

        return sizer;
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);
        if (obj->GetPropertyAsSize("minimum_size") != wxDefaultSize) {
            filter.AddProperty(XrcFilter::Type::Size, "minimum_size", "minsize");
        }
        filter.AddProperty(XrcFilter::Type::Option, "orient");
        filter.AddProperty(XrcFilter::Type::Text, "label");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);
        filter.AddProperty(XrcFilter::Type::Size, "minsize", "minimum_size");
        filter.AddProperty(XrcFilter::Type::Option, "orient");
        filter.AddProperty(XrcFilter::Type::Text, "label");
        return xfb;
    }
};

class GridSizerComponent : public ComponentBase
{
public:
    wxObject* Create(IObject* obj, wxObject* /*parent*/) override
    {
        wxGridSizer* sizer = new wxGridSizer(
          obj->GetPropertyAsInteger(_("rows")), obj->GetPropertyAsInteger(_("cols")),
          obj->GetPropertyAsInteger(_("vgap")), obj->GetPropertyAsInteger(_("hgap")));

        sizer->SetMinSize(obj->GetPropertyAsSize(_("minimum_size")));

        return sizer;
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);
        if (obj->GetPropertyAsSize("minimum_size") != wxDefaultSize) {
            filter.AddProperty(XrcFilter::Type::Size, "minimum_size", "minsize");
        }
        filter.AddProperty(XrcFilter::Type::Integer, "rows");
        filter.AddProperty(XrcFilter::Type::Integer, "cols");
        filter.AddProperty(XrcFilter::Type::Integer, "vgap");
        filter.AddProperty(XrcFilter::Type::Integer, "hgap");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);
        filter.AddProperty(XrcFilter::Type::Size, "minsize", "minimum_size");
        filter.AddProperty(XrcFilter::Type::Integer, "rows");
        filter.AddProperty(XrcFilter::Type::Integer, "cols");
        filter.AddProperty(XrcFilter::Type::Integer, "vgap");
        filter.AddProperty(XrcFilter::Type::Integer, "hgap");
        return xfb;
    }
};

class FlexGridSizerBase : public ComponentBase
{
public:
    void AddProperties(IObject* obj, wxFlexGridSizer* sizer)
    {
        for (const auto& col : obj->GetPropertyAsVectorIntPair(_("growablecols"))) {
            sizer->AddGrowableCol(col.first, col.second);
        }
        for (const auto& row : obj->GetPropertyAsVectorIntPair(_("growablerows"))) {
            sizer->AddGrowableRow(row.first, row.second);
        }
        sizer->SetMinSize(obj->GetPropertyAsSize(_("minimum_size")));
        sizer->SetFlexibleDirection(obj->GetPropertyAsInteger(_("flexible_direction")));
        sizer->SetNonFlexibleGrowMode((wxFlexSizerGrowMode)obj->GetPropertyAsInteger(_("non_flexible_grow_mode")));
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj, "", "");
        if (obj->GetPropertyAsSize("minimum_size") != wxDefaultSize) {
            filter.AddProperty(XrcFilter::Type::Size, "minimum_size", "minsize");
        }
        filter.AddProperty(XrcFilter::Type::Integer, "vgap");
        filter.AddProperty(XrcFilter::Type::Integer, "hgap");
        filter.AddProperty(XrcFilter::Type::String, "growablerows");
        filter.AddProperty(XrcFilter::Type::String, "growablecols");
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc, "", "");
        filter.AddProperty(XrcFilter::Type::Size, "minsize", "minimum_size");
        filter.AddProperty(XrcFilter::Type::Integer, "vgap");
        filter.AddProperty(XrcFilter::Type::Integer, "hgap");
        filter.AddProperty(XrcFilter::Type::String, "growablerows");
        filter.AddProperty(XrcFilter::Type::String, "growablecols");
        return xfb;
    }
};

class FlexGridSizerComponent : public FlexGridSizerBase
{
public:
    wxObject* Create(IObject* obj, wxObject* /*parent*/) override
    {
        wxFlexGridSizer* sizer = new wxFlexGridSizer(
          obj->GetPropertyAsInteger(_("rows")), obj->GetPropertyAsInteger(_("cols")),
          obj->GetPropertyAsInteger(_("vgap")), obj->GetPropertyAsInteger(_("hgap")));

        AddProperties(obj, sizer);

        return sizer;
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        FlexGridSizerBase::ExportToXrc(xrc, obj);

        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);
        filter.AddProperty(XrcFilter::Type::Integer, "rows");
        filter.AddProperty(XrcFilter::Type::Integer, "cols");

        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        FlexGridSizerBase::ImportFromXrc(xfb, xrc);

        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);
        filter.AddProperty(XrcFilter::Type::Integer, "rows");
        filter.AddProperty(XrcFilter::Type::Integer, "cols");

        return xfb;
    }
};

class GridBagSizerComponent : public FlexGridSizerBase
{
private:
    wxGBSizerItem* GetGBSizerItem(
      IObject* sizeritem, const wxGBPosition& position, const wxGBSpan& span, wxObject* child)
    {
        IObject* childObj = GetManager()->GetIObject(child);

        if (_("spacer") == childObj->GetClassName()) {
            return new wxGBSizerItem(
              childObj->GetPropertyAsInteger(_("width")), childObj->GetPropertyAsInteger(_("height")), position, span,
              sizeritem->GetPropertyAsInteger(_("flag")), sizeritem->GetPropertyAsInteger(_("border")), NULL);
        }

        // Add the child ( window or sizer ) to the sizer
        wxWindow* windowChild = wxDynamicCast(child, wxWindow);
        wxSizer* sizerChild = wxDynamicCast(child, wxSizer);

        if (windowChild != NULL) {
            return new wxGBSizerItem(
              windowChild, position, span, sizeritem->GetPropertyAsInteger(_("flag")),
              sizeritem->GetPropertyAsInteger(_("border")), NULL);
        } else if (sizerChild != NULL) {
            return new wxGBSizerItem(
              sizerChild, position, span, sizeritem->GetPropertyAsInteger(_("flag")),
              sizeritem->GetPropertyAsInteger(_("border")), NULL);
        } else {
            wxLogError(
              wxT("The GBSizerItem component's child is not a wxWindow or a wxSizer or a Spacer - this should not be "
                  "possible!"));
            return NULL;
        }
    }

public:
    wxObject* Create(IObject* obj, wxObject* /*parent*/) override
    {
        wxGridBagSizer* sizer =
          new wxGridBagSizer(obj->GetPropertyAsInteger(_("vgap")), obj->GetPropertyAsInteger(_("hgap")));

        if (!obj->IsPropertyNull(_("empty_cell_size"))) {
            sizer->SetEmptyCellSize(obj->GetPropertyAsSize(_("empty_cell_size")));
        }

        return sizer;
    }

    void OnCreated(wxObject* wxobject, wxWindow* /*wxparent*/) override
    {
        // For storing objects whose position needs to be determined
        std::vector<std::pair<wxObject*, wxGBSizerItem*> > newObjects;
        wxGBPosition lastPosition(0, 0);

        // Get sizer
        wxGridBagSizer* sizer = wxDynamicCast(wxobject, wxGridBagSizer);
        if (NULL == sizer) {
            wxLogError(wxT("This should be a wxGridBagSizer!"));
            return;
        }

        // Add the children
        IManager* manager = GetManager();
        size_t count = manager->GetChildCount(wxobject);
        if (0 == count) {
            // wxGridBagSizer gets upset sometimes without children
            sizer->Add(0, 0, wxGBPosition(0, 0));
            return;
        }
        for (size_t i = 0; i < count; ++i) {
            // Should be a GBSizerItem
            wxObject* wxsizerItem = manager->GetChild(wxobject, i);
            IObject* isizerItem = manager->GetIObject(wxsizerItem);

            // Get the location of the item
            wxGBSpan span(
              isizerItem->GetPropertyAsInteger(_("rowspan")), isizerItem->GetPropertyAsInteger(_("colspan")));

            int column = isizerItem->GetPropertyAsInteger(_("column"));
            if (column < 0) {
                // Needs to be auto positioned after the other children are added
                wxGBSizerItem* item = GetGBSizerItem(isizerItem, lastPosition, span, manager->GetChild(wxsizerItem, 0));
                if (item != NULL) {
                    newObjects.push_back(std::pair<wxObject*, wxGBSizerItem*>(wxsizerItem, item));
                }
                continue;
            }

            wxGBPosition position(isizerItem->GetPropertyAsInteger(_("row")), column);

            // Check for intersection
            if (sizer->CheckForIntersection(position, span)) {
                continue;
            }

            lastPosition = position;

            // Add the child to the sizer
            wxGBSizerItem* item = GetGBSizerItem(isizerItem, position, span, manager->GetChild(wxsizerItem, 0));
            if (item != NULL) {
                sizer->Add(item);
            }
        }

        std::vector<std::pair<wxObject*, wxGBSizerItem*> >::iterator it;
        for (it = newObjects.begin(); it != newObjects.end(); ++it) {
            wxGBPosition position = it->second->GetPos();
            wxGBSpan span = it->second->GetSpan();
            int column = position.GetCol();
            while (sizer->CheckForIntersection(position, span)) {
                column++;
                position.SetCol(column);
            }
            it->second->SetPos(position);
            sizer->Add(it->second);
            GetManager()->ModifyProperty(it->first, _("row"), wxString::Format(wxT("%i"), position.GetRow()), false);
            GetManager()->ModifyProperty(it->first, _("column"), wxString::Format(wxT("%i"), column), false);
        }

        AddProperties(manager->GetIObject(wxobject), sizer);
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        FlexGridSizerBase::ExportToXrc(xrc, obj);

        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);

        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        FlexGridSizerBase::ImportFromXrc(xfb, xrc);

        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);

        return xfb;
    }
};

class StdDialogButtonSizerComponent : public ComponentBase
{
private:
    tinyxml2::XMLElement* ExportButtonToXrc(tinyxml2::XMLElement* xrc, const wxString& buttonId)
    {
        auto* buttonElement = xrc->InsertNewChildElement("object");
        XMLUtils::SetAttribute(buttonElement, "class", "button");

        auto* wxButtonElement = buttonElement->InsertNewChildElement("object");
        XMLUtils::SetAttribute(wxButtonElement, "class", "wxButton");
        XMLUtils::SetAttribute(wxButtonElement, "name", buttonId);

        return xrc;
    }

public:
    wxObject* Create(IObject* obj, wxObject* parent) override
    {
        wxStdDialogButtonSizer* sizer = new wxStdDialogButtonSizer();

        sizer->SetMinSize(obj->GetPropertyAsSize(_("minimum_size")));

        if (obj->GetPropertyAsInteger(_("OK")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_OK));
        }
        if (obj->GetPropertyAsInteger(_("Yes")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_YES));
        }
        if (obj->GetPropertyAsInteger(_("Save")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_SAVE));
        }
        if (obj->GetPropertyAsInteger(_("Apply")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_APPLY));
        }
        if (obj->GetPropertyAsInteger(_("No")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_NO));
        }
        if (obj->GetPropertyAsInteger(_("Cancel")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_CANCEL));
        }
        if (obj->GetPropertyAsInteger(_("Help")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_HELP));
        }
        if (obj->GetPropertyAsInteger(_("ContextHelp")) != 0) {
            sizer->AddButton(new wxButton((wxWindow*)parent, wxID_CONTEXT_HELP));
        }

        sizer->Realize();
        return sizer;
    }

    tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) override
    {
        ObjectToXrcFilter filter(xrc, GetLibrary(), obj);
        if (obj->GetPropertyAsSize("minimum_size") != wxDefaultSize) {
            filter.AddProperty(XrcFilter::Type::Size, "minimum_size", "minsize");
        }
        if (obj->GetPropertyAsInteger("OK") != 0) {
            ExportButtonToXrc(xrc, "wxID_OK");
        }
        if (obj->GetPropertyAsInteger("Yes") != 0) {
            ExportButtonToXrc(xrc, "wxID_YES");
        }
        if (obj->GetPropertyAsInteger("Save") != 0) {
            ExportButtonToXrc(xrc, "wxID_SAVE");
        }
        if (obj->GetPropertyAsInteger("Apply") != 0) {
            ExportButtonToXrc(xrc, "wxID_APPLY");
        }
        // FIXME: Close currently missing in data model
        if (obj->GetPropertyAsInteger("No") != 0) {
            ExportButtonToXrc(xrc, "wxID_NO");
        }
        if (obj->GetPropertyAsInteger("Cancel") != 0) {
            ExportButtonToXrc(xrc, "wxID_CANCEL");
        }
        if (obj->GetPropertyAsInteger("Help") != 0) {
            ExportButtonToXrc(xrc, "wxID_HELP");
        }
        if (obj->GetPropertyAsInteger("ContextHelp") != 0) {
            ExportButtonToXrc(xrc, "wxID_CONTEXT_HELP");
        }
        return xrc;
    }

    tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) override
    {
        XrcToXfbFilter filter(xfb, GetLibrary(), xrc);
        filter.AddProperty(XrcFilter::Type::Size, "minsize", "minimum_size");

        std::map<wxString, std::pair<wxString, wxString>> buttons = {
            {"wxID_OK", {"OK", "0"}},
            {"wxID_YES", {"Yes", "0"}},
            {"wxID_SAVE", {"Save", "0"}},
            {"wxID_APPLY", {"Apply", "0"}},
            // FIXME: Close currently missing in data model
            {"wxID_NO", {"No", "0"}},
            {"wxID_CANCEL", {"Cancel", "0"}},
            {"wxID_HELP", {"Help", "0"}},
            {"wxID_CONTEXT_HELP", {"ContextHelp", "0"}},
        };
        for (const auto* button = xrc->FirstChildElement("object"); button; button = button->NextSiblingElement("object")) {
            if (XMLUtils::StringAttribute(button, "class") != "button") {
                continue;
            }

            const auto* wxButton = button->FirstChildElement("object");
            if (XMLUtils::StringAttribute(wxButton, "class") != "wxButton") {
                continue;
            }
            auto buttonEntry = buttons.find(XMLUtils::StringAttribute(wxButton, "name"));
            if (buttonEntry != buttons.end()) {
                buttonEntry->second.second = "1";
            }
        }
        for (const auto& [id, property] : buttons) {
            filter.AddPropertyValue(property.first, property.second);
        }

        return xfb;
    }
};

///////////////////////////////////////////////////////////////////////////////

BEGIN_LIBRARY()

ABSTRACT_COMPONENT("spacer", SpacerComponent)
ABSTRACT_COMPONENT("sizeritem", SizerItemComponent)
ABSTRACT_COMPONENT("gbsizeritem", GBSizerItemComponent)

SIZER_COMPONENT("wxBoxSizer", BoxSizerComponent)
SIZER_COMPONENT("wxWrapSizer", WrapSizerComponent)
SIZER_COMPONENT("wxStaticBoxSizer", StaticBoxSizerComponent)
SIZER_COMPONENT("wxGridSizer", GridSizerComponent)
SIZER_COMPONENT("wxFlexGridSizer", FlexGridSizerComponent)
SIZER_COMPONENT("wxGridBagSizer", GridBagSizerComponent)
SIZER_COMPONENT("wxStdDialogButtonSizer", StdDialogButtonSizerComponent)

// wxBoxSizer
MACRO(wxHORIZONTAL)
MACRO(wxVERTICAL)

// wxWrapSizer
MACRO(wxEXTEND_LAST_ON_EACH_LINE)
MACRO(wxREMOVE_LEADING_SPACES)
MACRO(wxWRAPSIZER_DEFAULT_FLAGS)

// wxFlexGridSizer
MACRO(wxBOTH)
MACRO(wxFLEX_GROWMODE_NONE)
MACRO(wxFLEX_GROWMODE_SPECIFIED)
MACRO(wxFLEX_GROWMODE_ALL)

// Add
MACRO(wxALL)
MACRO(wxLEFT)
MACRO(wxRIGHT)
MACRO(wxTOP)
MACRO(wxBOTTOM)
MACRO(wxEXPAND)
MACRO(wxALIGN_BOTTOM)
MACRO(wxALIGN_CENTER)
MACRO(wxALIGN_CENTER_HORIZONTAL)
MACRO(wxALIGN_CENTER_VERTICAL)
MACRO(wxSHAPED)
MACRO(wxFIXED_MINSIZE)
MACRO(wxRESERVE_SPACE_EVEN_IF_HIDDEN)

SYNONYMOUS(wxGROW, wxEXPAND)
SYNONYMOUS(wxALIGN_CENTRE, wxALIGN_CENTER)
SYNONYMOUS(wxALIGN_CENTRE_HORIZONTAL, wxALIGN_CENTER_HORIZONTAL)
SYNONYMOUS(wxALIGN_CENTRE_VERTICAL, wxALIGN_CENTER_VERTICAL)

END_LIBRARY()