SDK:Creating handler class for manual layout dialog: Difference between revisions
m (1 revision) |
(Gave more force to that statement :) .) |
||
Line 146: | Line 146: | ||
*Override [[VectorWorks:VWDialog::OnUpdateUI|VWDialog::OnUpdateUI]] function | *Override [[VectorWorks:VWDialog::OnUpdateUI|VWDialog::OnUpdateUI]] function | ||
:This function is called when the dialog should be updated. That happens when what ever control in the dialog layout is changed. | :This function is called when the dialog should be updated. That happens when what ever control in the dialog layout is changed. | ||
:This | :This funciton should ONLY be used to enable/disable and hide/show controls on the dialog. You should not use it for anything else!. | ||
*You should override [[VectorWorks:VWDialog::OnDDXInitialize|VWDialog::OnDDXInitialize]] function | *You should override [[VectorWorks:VWDialog::OnDDXInitialize|VWDialog::OnDDXInitialize]] function |
Revision as of 15:16, 10 July 2014
.SDK|SDK ..SDK:Types|SDK Types ..SDK:Using the SDK|Using the SDK ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference
Dialog handler
Manual dialogs are dialogs created by creating different controls and then manually adding them to the dialog. The first thing to do is create your own class for the dialog inheriting the VectorWorks:VWUI::VWDialog.
See SDK:Creating handler class for VectorScript layout dialog for normal VectorScript defined dialog. The difference is just the way the dialog is created. Actual event handing is the same.
Here is an example of what a dialog should look like:
/////////////////////////////////////////////// // The MyDialog.h file class CMyDialog : public VW::VWUI::VWDialog { public: CMyDialog(); virtual ~CMyDialog(); public: virtual bool CreateDialogLayout(); // events dispatcher map protected: DEFINE_EVENT_DISPATH_MAP; void EditIntegerChanged(long controlID, VWDialogEventArgs& eventArgs); virtual void OnSetUpEvent(); virtual void OnDDXInitialize(); virtual void OnUpdateUI(); // DDX variables protected: long fIntControlValue; // the controls private: VW::VWUI::VWStaticTextCtrl fStaticTextCtrl; VW::VWUI::VWEditIntegerCtrl fEditIntegerCtrl; };
//////////////////////////////////////////////// // The MyDialog.cpp file #include "MyDialog.h" #define kDialogID 128 #define kTextControlID 3 #define kEditIntegerControlID 4 using namespace VW::VWUI; EVENT_DISPATCH_MAP_BEGIN( CMyDialog ); ADD_DISPATCH_EVENT( kEditIntegerControlID, EditIntegerChanged ); EVENT_DISPATCH_MAP_END; CMyDialog::CMyDialog() : fStaticTextCtrl( kTextControlID ), fEditIntegerCtrl( kEditIntegerControlID ) { // TODO: Init DDX variables -- if any fIntControlValue = 5; } CMyDialog::~CMyDialog() { } bool CMyDialog::CreateDialogLayout() { // create the dialog if ( ! this->CreateDilaog( "Dlg title", "OK", "Cancel", true ) ) return false; // create the controls in the dialog if ( ! fStaticTextCtrl.CreateControl( this, "Enter a value:" ) ) return false; if ( ! fEditIntegerCtrl.CreateControl( this, 4, 5 ) ) return false; // add the controls to the dialog this->AddFirstGroupControl( & fStaticTextCtrl ); this->AddRightControl( & fStaticTextCtrl, & fEditIntegerCtrl ); return true; } void CMyDialog::OnSetUpEvent() { VWDialog::OnSetUpEvent(); // TODO: Add setup event handler } void CMyDialog::OnDDXInitialize() { // TODO: Attach DDX variables -- if any this->AddDDX_EditInteger( kEditIntegerControlID, & fIntControlValue ); } void CMyDialog::OnUpdateUI() { VWDialog::OnUpdateUI(); // TODO: Update user interface state } void CMyDialog::EditIntegerChanged(long controlID, VWDialogEventArgs& eventArgs) { // TODO: Handle the control event }
- Adding initialization for the controls of this dialog.
- This is done in the dialog class' constructor by calling each control constructor with appropriate ID. It's good idea to move the controls IDs as constants at the beginning of the file.
- You have to assign each control an unique ID for this dialog.
- Note The control ID 1 is reserved for the default button, and control ID 2 is reserved for the cancel button. So you should use IDs from 3 up.
- Override VWDialog::CreateDialogLayout function
- This is the function which actually creates the dialog. Any user of this dialog will create and instance of the class, and call this function to actually create the dialog and all controls inside. The function should return true if everything is ok with creation.
- Before creating any controls you should create the dialog itself. This is done by calling VWDialog::CreateDilaog function specifying title of the dialog and text for the default button, usually "OK" and text for the cancel button, usually "Cancel".
- Note You can pass empty string for the cancel button if you want your dialog to have only one button. Also note that this is the place for creating controls, you should not put any initialization code.
- Next thing to do is to create each one of the controls you have in the dialog. So call each control's create method with appropriate parameters different for each control.
- The last thing is to add the created controls into the dialog. This is done by calling VWDialog::AddFirstGroupControl, VWDialog::AddRightControl and VWDialog::AddBelowControl.
- First thing to do is assign First Group Control for the dialog and then add the rest of the controls relative to the first one, or relative to already added.
- Creating dispatch map
- By using DEFINE_EVENT_DISPATH_MAP macros in the class definition you add the message dispatching mechanism to your dialog. You also have to implement the map in your cpp file with the macros: EVENT_DISPATCH_MAP_BEGIN and EVENT_DISPATCH_MAP_END. Within these two you should add dispatcher entries, which message id which function should be called.
- Add dispatch event for the controls
- By using ADD_DISPATCH_EVENT macros you specify which function should be called, when event for specified control ID appears.
- In the example above a function is assigned to the event for the integer control, and that is the event when the controls was changed.
- Override OnSetUpEvent function
- This function is called when the dialog is already created but not shown. This is the place where you SHOULD initialize your control content, hide controls and so on.
- Override VWDialog::OnUpdateUI function
- This function is called when the dialog should be updated. That happens when what ever control in the dialog layout is changed.
- This funciton should ONLY be used to enable/disable and hide/show controls on the dialog. You should not use it for anything else!.
- You should override VWDialog::OnDDXInitialize function
- This function is part of the Dynamic Data Exchange (DDX) mechanism. This mechanism provides you a simple way of putting values into the controls and getting it out of there.
- This function is called before the dialog is show, and it should bind the concrete variables of the class with the controls in the dialog.
Running the dialog:
CMyDialog dlg; if ( dlg.RunDialogLayout() == VW::VWUI::kDialogButton_Ok ) { // TODO: Do something usefull }
See Also
SDK:Creating handler class for VectorScript layout dialog | SDK:Working with Dynamic Data Exchange (DDX) | Using Saved Settings |