We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2015-02-12 10:22 AM - last edited on 2023-08-01 01:39 PM by Doreena Deng
2015-02-23 01:40 PM
'GDLG' 32590 Modal | grow 300 300 387 350 "TabControl Dialog" { /* [ 1] */ Button 308 311 70 20 LargePlain "OK" /* [ 2] */ NormalTab 12 12 364 285 32591 NoIcon "TabPage1" } 'DLGH' 32590 DLG_32590_TabControl_Dialog { 1 "" Button_0 2 "" NormalTab_0 }As you see next to the 'OK' button here we have a NormalTab control and one TabPage
'GDLG' 32591 TabPage 0 0 256 121 "TabPage1" { /* [ 1] */ LeftText 6 10 100 18 LargePlain vCenter "Some text" /* [ 2] */ TextEdit 87 7 106 23 LargePlain 255 } 'DLGH' 32591 DLG_32591_TabPage1 { 1 "" LeftText_0 2 "" TextEdit_0 }I added a LeftText and a TextEdit to the corresponding TabPage in this example just to see
#ifndef (TABCONTROL_DIALOG_HPP) #define TABCONTROL_DIALOG_HPP #include "DG.h" #include "DGModule.hpp" #define TABCONTROL_DIALOG_RESID 32590 // --- TabControl Dialog ----------------------------------------------- class TabControlDialog: public DG::ModalDialog { friend class TabControlObserver; private: enum { OkButtonId = 1, TabControlId = 2, }; DG::NormalTab mTabControl; DG::Button mOkButton; public: TabControlDialog (GSResModule dialResModule, short resId); ~TabControlDialog (); }; // --- TabControlObserver ----------------------------------------------- class TabControlObserver: public DG::PanelObserver, public DG::NormalTabObserver, public DG::ButtonItemObserver, public DG::CompoundItemObserver { private: TabControlDialog* mDialog; protected: // DG::PanelObserver virtual void PanelOpened (const DG::PanelOpenEvent& ev) override; // DG::ButtonItemObserver virtual void ButtonClicked (const DG::ButtonClickEvent& ev) override; public: explicit TabControlObserver (TabControlDialog* testDialog); ~TabControlObserver (); }; #endif // TABCONTROL_DIALOG_HPP3. In the C++ source file you can find how the dialog is initialized.
#include "TabControlDialog.hpp" #include "DGMenu.hpp" #include "DGTabControl.hpp" //---------------------------- Class TabControlDialog ----------------------- TabControlDialog::TabControlDialog (GSResModule dialResModule, short resId): DG::ModalDialog (dialResModule, resId, dialResModule), mOkButton (GetReference (), OkButtonId), mTabControl (GetReference (), TabControlId) { } TabControlDialog::~TabControlDialog () { } //-------------------------- Class TabControlObserver ----------------------- TabControlObserver::TabControlObserver (TabControlDialog* testDialog): mDialog (testDialog) { mDialog->Attach (*this); AttachToAllItems (*mDialog); } TabControlObserver::~TabControlObserver () { mDialog->Detach (*this); DetachFromAllItems (*mDialog); } void TabControlObserver::PanelOpened (const DG::PanelOpenEvent& /*ev*/) { mDialog->SetClientSize (mDialog->GetOriginalClientWidth (), mDialog->GetOriginalClientHeight ()); } void TabControlObserver::ButtonClicked (const DG::ButtonClickEvent& ev) { // Close dialog with acceptance if (ev.GetSource () == &mDialog->mOkButton) { mDialog->PostCloseRequest (DG::ModalDialog::Accept); } }
2015-02-23 04:57 PM
2015-02-25 08:07 AM
Tamás wrote:Thanks but somewhere I have to call TabControlObserver class right ? oterwise TabControlObserver class doesn't run
Hi,
Here is an example how it can be implemented.
1. Let see how resource file looks like. Two things is needed
1.1 First you need to add a TabControl item (e.g. NormalTab or SingleTab) to the corresponding dialog:'GDLG' 32590 Modal | grow 300 300 387 350 "TabControl Dialog" { /* [ 1] */ Button 308 311 70 20 LargePlain "OK" /* [ 2] */ NormalTab 12 12 364 285 32591 NoIcon "TabPage1" } 'DLGH' 32590 DLG_32590_TabControl_Dialog { 1 "" Button_0 2 "" NormalTab_0 }As you see next to the 'OK' button here we have a NormalTab control and one TabPage
(it's important to add at least one TabPage to the TabControl otherwise resource file
won't compile).
1.2 After TabControl is added to the dialog, TabPages (you can define any of them) also should
be defined:'GDLG' 32591 TabPage 0 0 256 121 "TabPage1" { /* [ 1] */ LeftText 6 10 100 18 LargePlain vCenter "Some text" /* [ 2] */ TextEdit 87 7 106 23 LargePlain 255 } 'DLGH' 32591 DLG_32591_TabPage1 { 1 "" LeftText_0 2 "" TextEdit_0 }I added a LeftText and a TextEdit to the corresponding TabPage in this example just to see
something on the screen.
2. The C++ header contains a dialog and an observer class. You can overload any
virtual functions of NormalTabObserver to change the TabControl default behavior:
#ifndef (TABCONTROL_DIALOG_HPP) #define TABCONTROL_DIALOG_HPP #include "DG.h" #include "DGModule.hpp" #define TABCONTROL_DIALOG_RESID 32590 // --- TabControl Dialog ----------------------------------------------- class TabControlDialog: public DG::ModalDialog { friend class TabControlObserver; private: enum { OkButtonId = 1, TabControlId = 2, }; DG::NormalTab mTabControl; DG::Button mOkButton; public: TabControlDialog (GSResModule dialResModule, short resId); ~TabControlDialog (); }; // --- TabControlObserver ----------------------------------------------- class TabControlObserver: public DG::PanelObserver, public DG::NormalTabObserver, public DG::ButtonItemObserver, public DG::CompoundItemObserver { private: TabControlDialog* mDialog; protected: // DG::PanelObserver virtual void PanelOpened (const DG::PanelOpenEvent& ev) override; // DG::ButtonItemObserver virtual void ButtonClicked (const DG::ButtonClickEvent& ev) override; public: explicit TabControlObserver (TabControlDialog* testDialog); ~TabControlObserver (); }; #endif // TABCONTROL_DIALOG_HPP3. In the C++ source file you can find how the dialog is initialized.
#include "TabControlDialog.hpp" #include "DGMenu.hpp" #include "DGTabControl.hpp" //---------------------------- Class TabControlDialog ----------------------- TabControlDialog::TabControlDialog (GSResModule dialResModule, short resId): DG::ModalDialog (dialResModule, resId, dialResModule), mOkButton (GetReference (), OkButtonId), mTabControl (GetReference (), TabControlId) { } TabControlDialog::~TabControlDialog () { } //-------------------------- Class TabControlObserver ----------------------- TabControlObserver::TabControlObserver (TabControlDialog* testDialog): mDialog (testDialog) { mDialog->Attach (*this); AttachToAllItems (*mDialog); } TabControlObserver::~TabControlObserver () { mDialog->Detach (*this); DetachFromAllItems (*mDialog); } void TabControlObserver::PanelOpened (const DG::PanelOpenEvent& /*ev*/) { mDialog->SetClientSize (mDialog->GetOriginalClientWidth (), mDialog->GetOriginalClientHeight ()); } void TabControlObserver::ButtonClicked (const DG::ButtonClickEvent& ev) { // Close dialog with acceptance if (ev.GetSource () == &mDialog->mOkButton) { mDialog->PostCloseRequest (DG::ModalDialog::Accept); } }
After all of that you have a dialog with a TabControl.
Best Regards,
2015-02-25 01:38 PM
ggiloyan wrote:
Thanks but somewhere I have to call TabControlObserver class right ? oterwise TabControlObserver class doesn't run
static void Show_TabControlDialog (void) { TabControlDialog dialog (ACAPI_GetOwnResModule (), 32590); if (DBERROR (dialog.GetId () == 0)) { return; } TabControlObserver observer (&dialog); dialog.Invoke (); return; }
2015-02-26 04:22 PM
#include "DGTabPage.hpp" #include "DGEditControl.hpp" #include "APIEnvir.h" #include "ACAPinc.h" //---------------------------- Class MyTabPage ----------------------- class MyTabPage: public DG::TabPage { friend class MyTabPageObserver; private: enum { TextEditId = 2 }; DG::TextEdit mTextEdit; public: MyTabPage (const DG::TabControl& tabControl, short tabItem); ~MyTabPage (void); }; MyTabPage::MyTabPage (const DG::TabControl& tabControl, short tabItem): DG::TabPage (tabControl, tabItem, ACAPI_GetOwnResModule(), 32591, ACAPI_GetOwnResModule ()), mTextEdit (GetReference (), TextEditId) { } MyTabPage::~MyTabPage () { } //---------------------------- Class MyTabPageObserver ----------------------- class MyTabPageObserver: public DG::PanelObserver, public DG::CompoundItemObserver { private: MyTabPage* mTabPage; protected: // DG::PanelObserver virtual void PanelClosed (const DG::PanelCloseEvent& ev) override; public: explicit MyTabPageObserver (MyTabPage* tabPage); ~MyTabPageObserver (void); }; MyTabPageObserver::MyTabPageObserver (MyTabPage* tabPage): mTabPage (tabPage) { mTabPage->Attach (*this); AttachToAllItems (*mTabPage); } MyTabPageObserver::~MyTabPageObserver () { mTabPage->Detach (*this); DetachFromAllItems (*mTabPage); } void MyTabPageObserver::PanelClosed (const DG::PanelCloseEvent& ev) { if (ev.GetSource () == mTabPage) { DGAlert(DG_INFORMATION, "Information box", "Text changed in the text edit to:", mTabPage->mTextEdit.GetText(),"OK"); } }After you have these classes you need to use them inside your dialog class
class TabControlDialog: public DG::ModalDialog { friend class TabControlObserver; private: enum { OkButtonId = 1, TabControlId = 2, TabPageId = 3, }; DG::NormalTab mTabControl; DG::Button mOkButton; + MyTabPage* mTabPage; + MyTabPageObserver* mTabPageObserver; public: TabControlDialog (GSResModule dialResModule, short resId); ~TabControlDialog (); };In the constructor you can create the TabPage and link it with the Observer object:
TabControlDialog::TabControlDialog (GSResModule dialResModule, short resId): DG::ModalDialog (dialResModule, resId, dialResModule), mOkButton (GetReference (), OkButtonId), mTabControl (GetReference (), TabControlId), + mTabPage (new MyTabPage (mTabControl, 1)), + mTabPageObserver (new MyTabPageObserver (mTabPage)) { }Also take care of the dynamically allocated objects:
TabControlDialog::~TabControlDialog () { + delete mTabPageObserver; + delete mTabPage; }With these additional changes the new TabControl dialog will write out the text typed into the
2015-02-27 02:48 PM