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
|
// vim: set et ts=4 sw=4:
//
// Trivial libyui example.
//
// Compile with:
//
// g++ -I/usr/include/yui -lyui test.cpp -o test
//
#include "YUI.h"
#include "YApplication.h"
#include "YWidgetFactory.h"
#include "YDialog.h"
#include "YPushButton.h"
#include "YLayoutBox.h"
#include "YReplacePoint.h"
#include "YEvent.h"
#include "YFrame.h"
#include <vector>
int main( int argc, char **argv )
{
YUI::app()->setApplicationTitle("Test module");
YUI::app()->setApplicationIcon("/usr/share/icons/mageia.png");
YDialog * dialog = YUI::widgetFactory()->createPopupDialog();
YFrame* frame = YUI::widgetFactory()->createFrame(dialog, "Test frame");
YLayoutBox * hbox = YUI::widgetFactory()->createHBox(frame);
YFrame* lframe = YUI::widgetFactory()->createFrame(hbox, "Left frame");
YFrame* rframe = YUI::widgetFactory()->createFrame(hbox, "Right frame");
// here we change the widget
YReplacePoint* replacePoint = YUI::widgetFactory()->createReplacePoint(rframe);
YLayoutBox * vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint );
YLayoutBox * vbox = YUI::widgetFactory()->createVBox( lframe );
// vbox->setSize( 1000, 1000 );
lframe->setWeight(YD_HORIZ, 25);
rframe->setWeight(YD_HORIZ, 75);
YUI::widgetFactory()->createLabel ( vbox, "Hello, World!" );
YPushButton* addButton = YUI::widgetFactory()->createPushButton( vbox, "Add Button" );
YPushButton* removeButton = YUI::widgetFactory()->createPushButton( vbox, "Remove Button" );
YPushButton* exitButton = YUI::widgetFactory()->createPushButton( vbox, "&Exit" );
YUI::widgetFactory()->createSpacing( vbox, YD_VERT, true, 1.0 );
//YPushButton* testButton = YUI::widgetFactory()->createPushButton( vbox, "&Cannot be added" );
//testButton->hide(); <-- Angelo, I could not see this call in the api
int bnum = 0;
std::vector<YPushButton*>buttons;
for (;;)
{
YEvent* event = dialog->waitForEvent();
// Check for window close
if (event->eventType() == YEvent::CancelEvent)
{
break;
}
// Check for Exit button push
if(event->widget() == (YWidget*)exitButton ) {
break;
};
if(event->widget() == (YWidget*)addButton ) {
if(bnum < 6) {
dialog->startMultipleChanges();
replacePoint->deleteChildren();
vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint );
bnum++;
buttons.clear();
for (int i=0; i < bnum; ++i) {
YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" );
buttons.push_back(tmpB);
}
replacePoint->showChild();
dialog->recalcLayout();
dialog->doneMultipleChanges();
}
else if (bnum == 6) {
dialog->startMultipleChanges();
replacePoint->deleteChildren();
vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint );
buttons.clear();
for (int i=0; i < bnum; ++i) {
YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" );
buttons.push_back(tmpB);
}
YUI::widgetFactory()->createSpacing( vbox_rframe, YD_VERT, false, 1.0 );
replacePoint->showChild();
dialog->recalcLayout();
dialog->doneMultipleChanges();
}
}
if(event->widget() == (YWidget*)removeButton ) {
if (bnum > 0) {
dialog->startMultipleChanges();
replacePoint->deleteChildren();
vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint );
bnum--;
buttons.clear();
for (int i=0; i < bnum; ++i) {
YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" );
buttons.push_back(tmpB);
}
replacePoint->showChild();
dialog->recalcLayout();
dialog->doneMultipleChanges();
}
}
for(int i = 0; i < bnum; ++i) {
if (event->widget() == (YWidget*)buttons[i]) {
dialog->startMultipleChanges();
replacePoint->deleteChildren();
vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint );
bnum--;
buttons.clear();
for (int i=0; i < bnum; ++i) {
YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" );
buttons.push_back(tmpB);
}
replacePoint->showChild();
dialog->recalcLayout();
dialog->doneMultipleChanges();
break;
}
}
}
dialog->destroy();
}
|