SDK:Creating handler class for VectorScript layout dialog

From Vectorworks Developer
Revision as of 15:14, 25 February 2015 by Pchang (talk | contribs) (→‎Dialog handler)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

.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

The first thing to do is to create a VectorScript that creates the desired dialog. The best way to do is to use Dialog Builder.

Then you should put the text of the script in DialogLayout section in your resource file (vwr file), and give it unique name for the resource file.

The only difference for this dialog from the manual layout dialogs is that you create the dialog not control by control, but telling Vectorworks to call the script which creates the dialog.

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 eventArg);

    virtual void  OnSetUpEvent();
    virtual void  OnDDXInitialize();
    virtual void  OnUpdateUI();

// DDX variables
protected:
    long          fIntControlValue;

// Inner data
private:

};
// The MyDialog.cpp file
#include "MyDialog.h"
  
#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()
{
     // TODO: Init DDX variables -- if any
}

CMyDialog::~CMyDialog()
{
}

bool CMyDialog::CreateDialogLayout()
{
    return this->CreateDialogLayoutFromVWR( "ResourceFile/DialogLayout/Layout.vs" ) )
}

void CMyDialog::OnSetUpEvent()
{
    VWDialog::OnSetUpEvent();
}

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 eventArg)
{
    // TODO: Handle the control event
}
Call VWDialog::CreateDilaogLayoutFromVWR 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.
Here you tell the VectorWorks to create the dialog from DialogLayout resource passing the name of the resource. In this example "ResourceFile/DialogLayout/Layout.vs" is the path of the VS resource containing the VectorScript creating the dialog.
  • 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 and 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.
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.
This function is called when the dialog should be updated. That happens when any control in the dialog layout is changed.
This is the place where normally you enable/disable, show/hide controls in the dialog layout.
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 manual layout dialog | SDK:Working with Dynamic Data Exchange (DDX) | Using Saved Settings |