radiobutton.cpp

00001 #include <gui/MessageBox.h>
00002 #include <gui/MessageQueue.h>
00003 #include <gui/RadioButton.h>
00004 #include <gui/RadioButton.h>
00005 #include <gui/TopView.h>
00006 #include <gui/Exceptions.h>
00007 #include <gui/Window.h>
00008 #include <gui/StringView.h>
00009 #include <gui/ApplicationWindow.h>
00010 #include <gui/Application.h>
00011 #include <gui/Menu.h>
00012 #include <gui/StatusBar.h>
00013 #include <gui/RadioButton.h>
00014 #include <gui/GroupView.h>
00015 #include <iostream> 
00016 
00017 using namespace SkyGI;
00018 
00019 class MyRadioButton : public View
00020 {
00021 public:
00022         MyRadioButton(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags);
00023         void RadioActivated();
00024 
00025         GroupView *pGroup1;
00026         GroupView *pGroup2;
00027         GroupView *pGroup3;
00028 };
00029 
00030 void MyRadioButton::RadioActivated()
00031 {
00032         String s;
00033         Window *pChild;
00034         int i=0;
00035 
00036         i = 0;
00037         while( ( pChild = pGroup1->GetChild( i++ ) ) != NULL )
00038         {
00039                 RadioButton *pRadio = dynamic_cast < RadioButton * >( pChild);
00040 
00041                 if( pRadio != NULL )
00042                 {
00043                         if (pRadio->IsActive())
00044                                 s += pRadio->GetCaption() + " ";
00045                 }
00046         }
00047         i = 0;
00048         while( ( pChild = pGroup2->GetChild( i++ ) ) != NULL )
00049         {
00050                 RadioButton *pRadio = dynamic_cast < RadioButton * >( pChild);
00051 
00052                 if( pRadio != NULL )
00053                 {
00054                         if (pRadio->IsActive())
00055                                 s += pRadio->GetCaption() + " ";
00056                 }
00057         }       
00058         i = 0;
00059         while( ( pChild = pGroup3->GetChild( i++ ) ) != NULL )
00060         {
00061                 RadioButton *pRadio = dynamic_cast < RadioButton * >( pChild);
00062 
00063                 if( pRadio != NULL )
00064                 {
00065                         if (pRadio->IsActive())
00066                                 s += pRadio->GetCaption() + " ";
00067                 }
00068         }
00069         ((ApplicationWindow*)GetTop())->GetStatusBar()->SetText(s);
00070 }
00071 
00072 
00073 MyRadioButton::MyRadioButton(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags) : View(pParent, rFrame, nWindowLayoutFlags)
00074 {
00075         GroupView *pGroup;
00076         RadioButton *pButton;
00077         int iTop;
00078         int iLeft;
00079 
00080         pGroup = new GroupView(this, Rect(10, 10, Width() - 10, 110), "Group 1", WINDOW_LAYOUT_SAME_WIDTH );
00081         iTop  = pGroup->GetBorder()->GetMargin().top  + pGroup->GetMargin().top;
00082         iLeft = pGroup->GetBorder()->GetMargin().left + pGroup->GetMargin().left;
00083         
00084         pButton = new RadioButton(pGroup, Rect(0,0,0,0), "Radio Button 1", 0);
00085         pButton->SetRect(Rect(iLeft, iTop, + pButton->GetPreferredSize().x, iTop  + pButton->GetPreferredSize().y));
00086         pButton->Activated.Connect(this, &MyRadioButton::RadioActivated);
00087         iTop += pButton->GetPreferredSize().y + 3;
00088 
00089         pButton = new RadioButton(pGroup, Rect(0,0,0,0), "Radio Button 2", 0);
00090         pButton->SetRect(Rect(iLeft, iTop, + pButton->GetPreferredSize().x, iTop  + pButton->GetPreferredSize().y));
00091         pButton->Activated.Connect(this, &MyRadioButton::RadioActivated);
00092         iTop += pButton->GetPreferredSize().y + 3;
00093 
00094         pButton = new RadioButton(pGroup, Rect(0,0,0,0), "Radio Button 3", 0);
00095         pButton->SetRect(Rect(iLeft, iTop, + pButton->GetPreferredSize().x, iTop  + pButton->GetPreferredSize().y));
00096         pButton->Activated.Connect(this, &MyRadioButton::RadioActivated);
00097         iTop += pButton->GetPreferredSize().y + 3;
00098         pGroup1 = pGroup;
00099 
00100 
00101         pGroup = new GroupView(this, Rect(10, 120, Width() - 10, 220), "Group 2 (different border)", WINDOW_LAYOUT_SAME_WIDTH );
00102         iTop  = pGroup->GetBorder()->GetMargin().top  + pGroup->GetMargin().top;
00103         iLeft = pGroup->GetBorder()->GetMargin().left + pGroup->GetMargin().left;
00104         
00105         pButton = new RadioButton(pGroup, Rect(0,0,0,0), "Radio Button 1", 0);
00106         pButton->SetBorder((Border*)ThemeManager::ActiveTheme()->GetProperty(THEME_PROPERTY_GROUP_VIEW_BORDER));
00107         pButton->SetRect(Rect(iLeft, iTop, + pButton->GetPreferredSize().x, iTop  + pButton->GetPreferredSize().y));
00108         pButton->Activated.Connect(this, &MyRadioButton::RadioActivated);
00109         iTop += pButton->GetPreferredSize().y + 3;
00110 
00111         pButton = new RadioButton(pGroup, Rect(0,0,0,0), "Radio Button 2", 0);
00112         pButton->SetBorder((Border*)ThemeManager::ActiveTheme()->GetProperty(THEME_PROPERTY_GROUP_VIEW_BORDER));
00113         pButton->SetRect(Rect(iLeft, iTop, + pButton->GetPreferredSize().x, iTop  + pButton->GetPreferredSize().y));
00114         pButton->Activated.Connect(this, &MyRadioButton::RadioActivated);
00115         iTop += pButton->GetPreferredSize().y + 3;
00116         pGroup2 = pGroup;
00117 
00118 
00119         pGroup = new GroupView(this, Rect(10, 230, Width() - 10, 280), "Group 3 (single button)", WINDOW_LAYOUT_SAME_WIDTH );
00120         iTop  = pGroup->GetBorder()->GetMargin().top  + pGroup->GetMargin().top;
00121         iLeft = pGroup->GetBorder()->GetMargin().left + pGroup->GetMargin().left;
00122         
00123         pButton = new RadioButton(pGroup, Rect(0,0,0,0), "Radio Button 1", 0);
00124         pButton->SetRect(Rect(iLeft, iTop, + pButton->GetPreferredSize().x, iTop  + pButton->GetPreferredSize().y));
00125         pButton->Activated.Connect(this, &MyRadioButton::RadioActivated);
00126         iTop += pButton->GetPreferredSize().y + 3;
00127         pGroup3 = pGroup;
00128 }
00129 
00130 void RadioButtonTest()
00131 {
00132         Rect r(Point(100, 100), Point(400, 440));
00133 
00134         ApplicationWindow* pApplicationWindow = new ApplicationWindow(r, "RadioButton", WINDOW_LAYOUT_NOTHING, APPLICATION_WINDOW_NO_VIEW);
00135         
00136         pApplicationWindow->GetTitleWindow()->SetFlags( (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags() ));
00137         pApplicationWindow->AttachView(new MyRadioButton(pApplicationWindow, pApplicationWindow->GetClientRect(), WINDOW_LAYOUT_NOTHING));
00138         pApplicationWindow->AddStatusBar();
00139         pApplicationWindow->Show();
00140 }

Generated on Thu Dec 13 18:13:10 2007 for SkyGI by  doxygen 1.5.1-p1