Author Topic: How to use Custom control (derived from wxControl) with wxSmith ?  (Read 7741 times)

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
I'm writing specific own Gauge, derived from wxControl...
For the moment, I just try to see my control before continue. I use WxSmith into Code::Blocks with xrc.
For the moment, the code is (see at bottom).
I put a custom control into my GUI under wxSmith (under wxs), it appears with "????".
In class name, I put wxETKGauge
Style is 0, Xml Data is empty.
Running my app, my class is never created (adding breakpoints on constructors) and my control never appears...
How to add own specific control into wxSmith interface ?

My code is :

.h
Code
#ifndef WX_ETK_GAUGE_INCLUDE_H
#define WX_ETK_GAUGE_INCLUDE_H

#include <wx/control.h>
#include "wxETKTypes.h"

/**
 * Gauge.
 *
 * This class is used to display cusom gauge.
 *
 * @author Stéphane Château
 * @version Nom : wxETK<br>
 *          Révision : <b>1.0</b>
 */
class EXPORT_IMPORT wxETKGauge : public wxControl
{
private:
    /**
     * Actual value of the gauge.
     */
    unsigned long                       m_lValue;

    /**
     * Value max of the gauge.
     */
    unsigned long                       m_lRange;
public:
    /// @name Constructor / Destructor.
    //@{
     wxETKGauge();

    /**
     * Constructor.
     *
     * @param _pParent Parent window.
     * @param _wId Identifier.
     * @param _rPos Position.
     * @param _rSize Size.
     * @param _lStyle Style
     * @param _rValidator Validator.
     * @param _rName Name of the control.
     *
     */
     wxETKGauge(wxWindow *_pParent,wxWindowID _wId,const wxPoint& _rPos = wxDefaultPosition,const wxSize& _rSize = wxDefaultSize,
                long _lStyle = 0,const wxValidator& _rValidator = wxDefaultValidator,const wxString& _rName = wxControlNameStr);

    virtual ~wxETKGauge();
    //@}

    /**
     * Get the current value.
     *
     * By default, the value is initalized with 0.
     *
     * @return The current value.
     */
    unsigned long                       GetValue() const;

    /**
     * Set the current value.
     *
     * @param _lValue The current value to set.
     */
    void                                SetValue(unsigned long _lValue);

    /**
     * Get the current range value.
     *
     * The current range is the max value allowed for value.
     * By default, the range is initalized with 100.
     *
     * @return The current range.
     */
    unsigned long                       GetRange() const;

    /**
     * Set the current range value.
     *
     * The current range is the max value allowed for value.
     *
     * @param _lRange The new current range.
     */
     void                               SetRange(unsigned long _lRange);

    void                                OnPaint(wxPaintEvent& _rEvent);

private:
    DECLARE_EVENT_TABLE()
    DECLARE_DYNAMIC_CLASS(wxGauge)
};

#endif // WX_ETK_GAUGE_INCLUDE_H


.cpp :
Code
#include "wxETKGauge.h"

BEGIN_EVENT_TABLE(wxETKGauge, wxControl)
    EVT_PAINT(wxETKGauge::OnPaint)
END_EVENT_TABLE()

IMPLEMENT_DYNAMIC_CLASS(wxETKGauge, wxControl)

wxETKGauge::wxETKGauge()
{

}

wxETKGauge::wxETKGauge(wxWindow *_pParent,wxWindowID _wId,const wxPoint& _rPos,const wxSize& _rSize,
                long _lStyle,const wxValidator& _rValidator,const wxString& _rName)
    : wxControl(_pParent,_wId,_rPos,_rSize,_lStyle,_rValidator,_rName)
    , m_lValue(0)
    , m_lRange(100)
{
}

wxETKGauge::~wxETKGauge()
{
}

unsigned long wxETKGauge::GetValue() const
{
    return m_lValue;
}

void wxETKGauge::SetValue(unsigned long _lValue)
{
    m_lValue = _lValue;
}

unsigned long wxETKGauge::GetRange() const
{
    return m_lRange;
}

void wxETKGauge::SetRange(unsigned long _lRange)
{
    m_lRange = _lRange;
}

void wxETKGauge::OnPaint(wxPaintEvent& _rEvent)
{
    wxRect rect = GetClientRect();

    wxWindowDC dc(this);
    dc.SetBrush(*wxCYAN_BRUSH);
    dc.SetPen(*wxTRANSPARENT_PEN);
    dc.DrawRectangle(rect);
}

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: How to use Custom control (derived from wxControl) with wxSmith ?
« Reply #1 on: March 22, 2010, 06:02:38 pm »
The easiest way is to start from an example.  Download this file:

http://prdownload.berlios.de/ringowidgets/SpeedButton.zip

This is an example of how to create a new component (this is also from wxControl) and to make a plug-in for wxSmith.  Study it carefully, especially the code and the project under the "wxs" sub-directory.  If necessary, you can just copy the entire directory tree, and just substitute your code for the speed-button code.

Ringo

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: How to use Custom control (derived from wxControl) with wxSmith ?
« Reply #2 on: March 22, 2010, 08:03:07 pm »
Thanks for your reply...
I don't want to to create plug-in for wxSmith, just add a custom component that will be written in xrc (don't care if I see ??? in wxSmith GUI).
I thought that custom components in wxSmith was created in this way...
I want the xrc create an instance of my class and after I could use it. Another way is to forget wxSmith and Custom and create it by code, but so, custom component should be used to do what kind of things ?
Peharps, if I create another component and says it is this class it could be work ? I have created a panel like this, putting wxETKLogWindowPanel as class name. In this case my panel is correctly created.

What should I do ?

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: How to use Custom control (derived from wxControl) with wxSmith ?
« Reply #3 on: March 23, 2010, 01:56:30 pm »
I'm not sure I understand you correctly; if you just want to enter the class name in the properties panel of wxSmith designer, then the way you did it with the panel should work fine.  Just make sure that the constructor of your custom control takes the same arguments as a wxPanel, then put a wxPanel on your form.  On the properties list, change the class name to your custom component, and it will be created instead of a panel

Ringo

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to use Custom control (derived from wxControl) with wxSmith ?
« Reply #4 on: March 23, 2010, 04:25:49 pm »
There is a custom control in the wxSmith, add one to your panel/dialog and play with the options a bit.
It works very well and it is very powerful and configurable.
You can control the parameters that should be passed to the control's c-tor and so on...
It is pretty straight forward.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: How to use Custom control (derived from wxControl) with wxSmith ?
« Reply #5 on: March 25, 2010, 12:00:07 am »
No success with custom control, have no time to spend with this, I create the component by code :-(
I'll see again later...