However there are situations where you need to show some particular kind of data which is not suited to any existing control. In these cases rather than hacking an existing control for something it has not been coinceived for, it's better to write a new widget.
The first is to build it upon wxWidgets existing classes, thus deriving it from wxControl or wxWindow. In this way you'll get a generic widget. This method has the advantage that writing a single implementation works on all ports; the disadvantage is that it the widget will look the same on all platforms, and thus it may not integrate well with the native look and feel.
The second method is to build it directly upon the native toolkits of the platforms you want to support (e.g. GTK+, Carbon and GDI). In this way you'll get a native widget. This method in fact has the advantage of a native look and feel but requires different implementations and thus more work.
In both cases you'll want to better explore some hot topics like:
enum MySpecialWidgetStyles { SWS_LOOK_CRAZY = 1, SWS_LOOK_SERIOUS = 2, SWS_SHOW_BUTTON = 4, SWS_DEFAULT_STYLE = (SWS_SHOW_BUTTON|SWS_LOOK_SERIOUS) }; class MySpecialWidget : public wxControl { public: MySpecialWidget() { Init(); } MySpecialWidget(wxWindow *parent, wxWindowID winid, const wxString& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = SWS_DEFAULT_STYLE, const wxValidator& val = wxDefaultValidator, const wxString& name = "MySpecialWidget") { Init(); Create(parent, winid, label, pos, size, style, val, name); } bool Create(wxWindow *parent, wxWindowID winid, const wxString& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = SWS_DEFAULT_STYLE, const wxValidator& val = wxDefaultValidator, const wxString& name = wxCollapsiblePaneNameStr); // accessors... protected: void Init() { // init widget's internals... } virtual wxSize DoGetBestSize() const { // we need to calculate and return the best size of the widget... } void OnPaint(wxPaintEvent&) { // draw the widget on a wxDC... } private: DECLARE_DYNAMIC_CLASS(MySpecialWidget) DECLARE_EVENT_TABLE() };
The organization used by wxWidgets consists in:
"wx/button.h"
file.
"wx/gtk/button.h"
file.
"src/common/btncmn.cpp"
, "src/gtk/button.cpp"
and "src/msw/button.cpp"
files.
![]() |
[ top ] |