Data binding in dialogs

  • runnig

    runnig - 2007-02-27

    Cannot locate how to do data binding in dialogs. Can someone show me the way?
    Nice library anyway.

    • andrew7

      andrew7 - 2007-02-28

      If you mean similar to MFC's DDX, as described here:

      then SmartWin++ has no direct replacement.  Of course you can query the widgets in the dialog yourself.

      There is also a class InDialog, as demonstrated in the sample iolib or the sample WidgetGraph, that can pass in variables, operate as a modal dialog, and then return the values back to the parent class.

      One nice feature is that dialog is generated from the list of variables passed to the class at runtime.  That is right, it generates the appropriate Widgets for the int, float, bool, string, COLORREF, directory, ChoiceString, etc,  passed into InDialog.

      One drawback is that Cancel does not revert all the values back to their original state.

      It looks like this:

      #include "io/InDialog.h"

          COLORREF itsAxisColor, itsPointColor;
          bool axisPresent;
          int itsPenWidth;
              int itsHistoSections;

      void chooseProperties( const SmartWin::MouseEventResult & mouse )
          SmartUtil::tstring title= _T("Graph parameters");
          InDialog myInDialog( this, title );
              .add( _T( "Axis present?" ), & axisPresent )
              .add( _T( "Point color ..." ), & itsPointColor )
              .add( _T( "Axis color ..." ), & itsAxisColor )
              .add( _T( "Graph width" ), & itsPenWidth );

          if ( 0 == itsY.size() )
              myInDialog.add( _T( "Histogram sections" ), & itsHistoSections );

          if ( IDCANCEL == myInDialog.createDialog() ) return;

              // The new values have appeared in the variables now.

      best regards, Andrew

      • runnig

        runnig - 2007-02-28

        Thank you for the answer. But what I'm asking for is slightly different, because I need data binding in dialog that was designed in Visual Studio dialog designer, not in run-time. MS DDX implementation uses ugly, non-c++ approach. I think something like data binding should be implemented by using aspects or smth like that. Am I wrong?

        • andrew7

          andrew7 - 2007-02-28

          Hmm, well if the controls were specified for the resource compiler, then you can turn them into SmartWin++ Widgets with the subclass functions.  And then you have the ability to set and get the values with Widget member functions.

          WidgetTextBox * itsHexTxt

          itsHexTxt = this->subclassTextBox( IDC_HEXEDIT );

          itsHexTxt->setText( label );

          itsParent->dataFromDialog( itsHexTxt->getText() );

          This might be sufficent.  If not, how should the widget map to a variable with string, int or double type ?

    • runnig

      runnig - 2007-02-28

      Can we easily insert "aspect" into dialog behaviour to change specified variable if control value has been changed by user?


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks