1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG interface defs for wxControl and other base classes
 
   7 // Created:     10-June-1998
 
   9 // Copyright:   (c) 2003 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  16 //---------------------------------------------------------------------------
 
  18 MAKE_CONST_WXSTRING(ControlNameStr);
 
  20 //---------------------------------------------------------------------------
 
  25 "This is the base class for a control or 'widget'.
 
  27 A control is generally a small window which processes user input
 
  28 and/or displays one or more item of data.", "");
 
  30 MustHaveApp(wxControl);
 
  32 class wxControl : public wxWindow
 
  35     %pythonAppend wxControl         "self._setOORInfo(self)"
 
  36     %pythonAppend wxControl()       ""
 
  37     %typemap(out) wxControl*;    // turn off this typemap
 
  40         wxControl(wxWindow *parent,
 
  42                   const wxPoint& pos=wxDefaultPosition,
 
  43                   const wxSize& size=wxDefaultSize,
 
  45                   const wxValidator& validator=wxDefaultValidator,
 
  46                   const wxString& name=wxPyControlNameStr),
 
  47         "Create a Control.  Normally you should only call this from a subclass'
 
  48 __init__ as a plain old wx.Control is not very useful.", "");
 
  52         "Precreate a Control control for 2-phase creation", "",
 
  55     // Turn it back on again
 
  56     %typemap(out) wxControl* { $result = wxPyMake_wxObject($1, $owner); }
 
  60         bool , Create(wxWindow *parent,
 
  62                       const wxPoint& pos=wxDefaultPosition,
 
  63                       const wxSize& size=wxDefaultSize,
 
  65                       const wxValidator& validator=wxDefaultValidator,
 
  66                       const wxString& name=wxPyControlNameStr),
 
  67         "Do the 2nd phase and create the GUI control.", "");
 
  71         int , GetAlignment() const,
 
  72         "Get the control alignment (left/right/centre, top/bottom/centre)", "");
 
  76         wxString , GetLabelText() const,
 
  77         "Get just the text of the label, without mnemonic characters ('&')", "");
 
  82         void , Command(wxCommandEvent& event),
 
  83         "Simulates the effect of the user issuing a command to the item.
 
  85 :see: `wx.CommandEvent`
 
  90 //         bool , GetAdjustMinSizeFlag(),
 
  91 //         "Returns whether the minsize should be adjusted for this control when
 
  92 // `SetLabel` or `SetFont` are called.", "");
 
  95 //         void , SetAdjustMinSizeFlag(bool adjust),
 
  96 //         "By default controls will readjust their size and minsize when
 
  97 // `SetLabel` or `SetFont` are called.  This flag will allow you to
 
  98 // control this behavior.", "
 
 100 // :see: `GetAdjustMinSizeFlag`
 
 105         static wxString , RemoveMnemonics(const wxString& str),
 
 106         "removes the mnemonics characters", "");
 
 111 //         static wxString , EscapeMnemonics(const wxString& str),
 
 112 //         "escapes the mnemonics characters ('&') by doubling them", "");
 
 115     static wxVisualAttributes
 
 116     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
 118     %property(Alignment, GetAlignment, doc="See `GetAlignment`");
 
 119     %property(LabelText, GetLabelText, doc="See `GetLabelText`");
 
 124 //---------------------------------------------------------------------------
 
 130 DocStr(wxItemContainer,
 
 131 "The wx.ItemContainer class defines an interface which is implemented
 
 132 by all controls which have string subitems, each of which may be
 
 133 selected, such as `wx.ListBox`, `wx.CheckListBox`, `wx.Choice` as well
 
 134 as `wx.ComboBox` which implements an extended interface deriving from
 
 137 It defines the methods for accessing the control's items and although
 
 138 each of the derived classes implements them differently, they still
 
 139 all conform to the same interface.
 
 141 The items in a wx.ItemContainer have (non empty) string labels and,
 
 142 optionally, client data associated with them.
 
 145 class wxItemContainer
 
 148     // wxItemContainer()  ** It's an ABC
 
 153                "Adds the item to the control, associating the given data with the item
 
 154 if not None.  The return value is the index of the newly added item
 
 155 which may be different from the last one if the control is sorted (e.g.
 
 156 has wx.LB_SORT or wx.CB_SORT style).", "");
 
 157         int Append(const wxString& item, PyObject* clientData=NULL) {
 
 159                 wxPyClientData* data = new wxPyClientData(clientData);
 
 160                 return self->Append(item, data);
 
 162                 return self->Append(item);
 
 167         void , Append(const wxArrayString& strings),
 
 168         "AppendItems(self, List strings)",
 
 169         "Apend several items at once to the control.  Notice that calling this
 
 170 method may be much faster than appending the items one by one if you
 
 171 need to add a lot of items.", "",
 
 177                "Insert an item into the control before the item at the ``pos`` index,
 
 178 optionally associating some data object with the item.", "");
 
 179         int Insert(const wxString& item, /*unsigned*/ int pos, PyObject* clientData=NULL) {
 
 181                 wxPyClientData* data = new wxPyClientData(clientData);
 
 182                 return self->Insert(item, pos, data);
 
 184                 return self->Insert(item, pos);
 
 190         virtual void , Clear(),
 
 191         "Removes all items from the control.", "");
 
 194         virtual void , Delete(/*unsigned*/ int n),
 
 195         "Deletes the item at the zero-based index 'n' from the control. Note
 
 196 that it is an error (signalled by a `wx.PyAssertionError` exception if
 
 197 enabled) to remove an item with the index negative or greater or equal
 
 198 than the number of items in the control.", "");
 
 204         DocStr(GetClientData,
 
 205                "Returns the client data associated with the given item, (if any.)", "");
 
 206         PyObject* GetClientData(/*unsigned*/ int n) {
 
 207             wxPyClientData* data = (wxPyClientData*)self->GetClientObject(n);
 
 209                 Py_INCREF(data->m_obj);
 
 217         DocStr(SetClientData,
 
 218                "Associate the given client data with the item at position n.", "");
 
 219         void SetClientData(/*unsigned*/ int n, PyObject* clientData) {
 
 220             wxPyClientData* data = new wxPyClientData(clientData);
 
 221             self->SetClientObject(n, data);
 
 228         virtual /*unsigned*/ int , GetCount() const,
 
 229         "Returns the number of items in the control.", "");
 
 232         bool , IsEmpty() const,
 
 233         "Returns True if the control is empty or False if it has some items.", "");
 
 236         virtual wxString , GetString(/*unsigned*/ int n) const,
 
 237         "Returns the label of the item with the given index.", "");
 
 240         wxArrayString , GetStrings() const,
 
 244         virtual void , SetString(/*unsigned*/ int n, const wxString& s),
 
 245         "Sets the label for the given item.", "");
 
 248         virtual int , FindString(const wxString& s) const,
 
 249         "Finds an item whose label matches the given string.  Returns the
 
 250 zero-based position of the item, or ``wx.NOT_FOUND`` if the string was not
 
 255         virtual void , SetSelection(int n),
 
 256         "Sets the item at index 'n' to be the selected item.", "");
 
 259         virtual int , GetSelection() const,
 
 260         "Returns the index of the selected item or ``wx.NOT_FOUND`` if no item
 
 264     bool SetStringSelection(const wxString& s);
 
 267         wxString , GetStringSelection() const,
 
 268         "Returns the label of the selected item or an empty string if no item
 
 273         void , Select(int n),
 
 274         "This is the same as `SetSelection` and exists only because it is
 
 275 slightly more natural for controls which support multiple selection.", "");
 
 280             """Return a list of the strings in the control"""
 
 281             return [self.GetString(i) for i in xrange(self.GetCount())]
 
 283         def SetItems(self, items):
 
 284             """Clear and set the strings in the control from a list"""
 
 290     %property(Count, GetCount, doc="See `GetCount`");
 
 291     %property(Items, GetItems, SetItems, doc="See `GetItems` and `SetItems`");
 
 292     %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
 
 293     %property(StringSelection, GetStringSelection, SetStringSelection, doc="See `GetStringSelection` and `SetStringSelection`");
 
 294     %property(Strings, GetStrings, doc="See `GetStrings`");
 
 299 //---------------------------------------------------------------------------
 
 302 DocStr(wxControlWithItems,
 
 303 "wx.ControlWithItems combines the ``wx.ItemContainer`` class with the
 
 304 wx.Control class, and is used for the base class of various controls
 
 305 that have items.", "");
 
 307 class wxControlWithItems : public wxControl, public wxItemContainer
 
 312 //---------------------------------------------------------------------------