1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     More control (widget) classes for wxPython
 
   9 // Copyright:   (c) 1998 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  17 #include <wx/listctrl.h>
 
  18 #include <wx/treectrl.h>
 
  21 //----------------------------------------------------------------------
 
  24 %include my_typemaps.i
 
  26 // Import some definitions of other classes, etc.
 
  34 %pragma(python) code = "import wx"
 
  36 //----------------------------------------------------------------------
 
  39 extern wxValidator wxPyDefaultValidator;
 
  42 //----------------------------------------------------------------------
 
  46     long            m_mask;     // Indicates what fields are valid
 
  47     long            m_itemId;   // The zero-based item position
 
  48     int             m_col;      // Zero-based column, if in report mode
 
  49     long            m_state;    // The state of the item
 
  50     long            m_stateMask; // Which flags of m_state are valid (uses same flags)
 
  51     wxString        m_text;     // The label/header text
 
  52     int             m_image;    // The zero-based index into an image list
 
  53     long            m_data;     // App-defined data
 
  54 //    wxColour       *m_colour;   // only wxGLC, not supported by Windows ;->
 
  57     int             m_format;   // left, right, centre
 
  58     int             m_width;    // width of column
 
  64 class wxListEvent: public wxCommandEvent {
 
  78 class wxListCtrl : public wxControl {
 
  80     wxListCtrl(wxWindow* parent, wxWindowID id,
 
  81                const wxPoint& pos = wxPyDefaultPosition,
 
  82                const wxSize& size = wxPyDefaultSize,
 
  83                long style = wxLC_ICON,
 
  84                const wxValidator& validator = wxPyDefaultValidator,
 
  85                char* name = "listCtrl");
 
  87     %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
 
  89     bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
 
  90     bool DeleteItem(long item);
 
  91     bool DeleteAllItems();
 
  92     bool DeleteColumn(int col);
 
  94     bool DeleteAllColumns(void);
 
  96     wxTextCtrl* EditLabel(long item);
 
  97     bool EndEditLabel(bool cancel);
 
  99     bool EnsureVisible(long item);
 
 100     long FindItem(long start, const wxString& str, bool partial = FALSE);
 
 101     %name(FindItemData)long FindItem(long start, long data);
 
 102     %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
 
 104     bool GetColumn(int col, wxListItem& item);
 
 105     int GetColumnWidth(int col);
 
 106     int GetCountPerPage();
 
 108     wxTextCtrl* GetEditControl();
 
 110     wxImageList* GetImageList(int which);
 
 111     long GetItemData(long item);
 
 114         %new wxListItem* GetItem() {
 
 115             wxListItem* info = new wxListItem;
 
 116             self->GetItem(*info);
 
 119         %new wxPoint* GetItemPosition(long item) {
 
 120             wxPoint* pos = new wxPoint;
 
 121             self->GetItemPosition(item, *pos);
 
 124         %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
 
 125             wxRect* rect= new wxRect;
 
 126             self->GetItemRect(item, *rect, code);
 
 131     int GetItemState(long item, long stateMask);
 
 133     int GetItemSpacing(bool isSmall);
 
 134     wxString GetItemText(long item);
 
 135     long GetNextItem(long item,
 
 136                      int geometry = wxLIST_NEXT_ALL,
 
 137                      int state = wxLIST_STATE_DONTCARE);
 
 138     int GetSelectedItemCount();
 
 140     wxColour GetTextColour();
 
 143     long HitTest(const wxPoint& point, int& OUTPUT);
 
 144     %name(InsertColumnWithInfo)long InsertColumn(long col, wxListItem& info);
 
 145     long InsertColumn(long col, const wxString& heading,
 
 146                       int format = wxLIST_FORMAT_LEFT,
 
 149     long InsertItem(wxListItem& info);
 
 150     %name(InsertStringItem)     long InsertItem(long index, const wxString& label);
 
 151     %name(InsertImageItem)      long InsertItem(long index, int imageIndex);
 
 152     %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
 
 155     bool ScrollList(int dx, int dy);
 
 156     void SetBackgroundColour(const wxColour& col);
 
 157     bool SetColumn(int col, wxListItem& item);
 
 158     bool SetColumnWidth(int col, int width);
 
 159     void SetImageList(wxImageList* imageList, int which);
 
 160     bool SetItem(wxListItem& info);
 
 161     %name(SetItemString)long SetItem(long index, int col, const wxString& label,
 
 163     bool SetItemData(long item, long data);
 
 164     bool SetItemImage(long item, int image, int selImage);
 
 165     bool SetItemPosition(long item, const wxPoint& pos);
 
 166     bool SetItemState(long item, long state, long stateMask);
 
 167     void SetItemText(long item, const wxString& text);
 
 168     void SetSingleStyle(long style, bool add = TRUE);
 
 170     void SetTextColour(const wxColour& col);
 
 172     void SetWindowStyleFlag(long style);
 
 173     // TODO:  bool SortItems(wxListCtrlCompare fn, long data);
 
 178 //----------------------------------------------------------------------
 
 185     bool IsOk() const { return m_itemId != 0; }
 
 188 //        long GetId() { return (long)(*self); }
 
 194 // ****  This isn't very useful yet.  This needs to be specialized to enable
 
 195 // derived Python classes...
 
 196 class wxTreeItemData {
 
 201     const wxTreeItemId& GetId();
 
 202     void SetId(const wxTreeItemId& id);
 
 208 class wxTreeEvent : public wxCommandEvent {
 
 210     wxTreeItemId GetItem();
 
 211     wxTreeItemId GetOldItem();
 
 218 // These are for the GetFirstChild/GetNextChild methods below
 
 219 %typemap(python, in)     long& INOUT = long* INOUT;
 
 220 %typemap(python, argout) long& INOUT = long* INOUT;
 
 223 class wxTreeCtrl : public wxControl {
 
 226     wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
 
 227                const wxPoint& pos = wxPyDefaultPosition,
 
 228                const wxSize& size = wxPyDefaultSize,
 
 229                long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
 
 230                const wxValidator& validator = wxPyDefaultValidator,
 
 231                char* name = "wxTreeCtrl");
 
 234     wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
 
 235                const wxPoint& pos = wxPyDefaultPosition,
 
 236                const wxSize& size = wxPyDefaultSize,
 
 237                long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
 
 238                //const wxValidator& validator = wxPyDefaultValidator,
 
 239                char* name = "wxTreeCtrl");
 
 241     %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
 
 244     unsigned int GetIndent();
 
 245     void SetIndent(unsigned int indent);
 
 246     wxImageList *GetImageList();
 
 247     wxImageList *GetStateImageList();
 
 248     void SetImageList(wxImageList *imageList);
 
 249     void SetStateImageList(wxImageList *imageList);
 
 251     wxString GetItemText(const wxTreeItemId& item);
 
 252     int GetItemImage(const wxTreeItemId& item);
 
 253     int GetItemSelectedImage(const wxTreeItemId& item);
 
 254     wxTreeItemData *GetItemData(const wxTreeItemId& item);
 
 256     void SetItemText(const wxTreeItemId& item, const wxString& text);
 
 257     void SetItemImage(const wxTreeItemId& item, int image);
 
 258     void SetItemSelectedImage(const wxTreeItemId& item, int image);
 
 259     void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
 
 261     bool IsVisible(const wxTreeItemId& item);
 
 262     bool ItemHasChildren(const wxTreeItemId& item);
 
 263     bool IsExpanded(const wxTreeItemId& item);
 
 264     bool IsSelected(const wxTreeItemId& item);
 
 266     wxTreeItemId GetRootItem();
 
 267     wxTreeItemId GetSelection();
 
 268     wxTreeItemId GetParent(const wxTreeItemId& item);
 
 270     wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
 
 271     wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
 
 272     wxTreeItemId GetNextSibling(const wxTreeItemId& item);
 
 273     wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
 
 274     wxTreeItemId GetFirstVisibleItem();
 
 275     wxTreeItemId GetNextVisible(const wxTreeItemId& item);
 
 276     wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
 
 279     wxTreeItemId AddRoot(const wxString& text,
 
 280                          int image = -1, int selectedImage = -1,
 
 281                          wxTreeItemData *data = NULL);
 
 282     wxTreeItemId PrependItem(const wxTreeItemId& parent,
 
 283                              const wxString& text,
 
 284                              int image = -1, int selectedImage = -1,
 
 285                              wxTreeItemData *data = NULL);
 
 286     wxTreeItemId InsertItem(const wxTreeItemId& parent,
 
 287                             const wxTreeItemId& idPrevious,
 
 288                             const wxString& text,
 
 289                             int image = -1, int selectedImage = -1,
 
 290                             wxTreeItemData *data = NULL);
 
 291     wxTreeItemId AppendItem(const wxTreeItemId& parent,
 
 292                             const wxString& text,
 
 293                             int image = -1, int selectedImage = -1,
 
 294                             wxTreeItemData *data = NULL);
 
 296     void Delete(const wxTreeItemId& item);
 
 297     void DeleteAllItems();
 
 299     void Expand(const wxTreeItemId& item);
 
 300     void Collapse(const wxTreeItemId& item);
 
 301     void CollapseAndReset(const wxTreeItemId& item);
 
 302     void Toggle(const wxTreeItemId& item);
 
 305     void SelectItem(const wxTreeItemId& item);
 
 306     void EnsureVisible(const wxTreeItemId& item);
 
 307     void ScrollTo(const wxTreeItemId& item);
 
 309     wxTextCtrl* EditLabel(const wxTreeItemId& item);
 
 310                           // **** figure out how to do this
 
 311                           // wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
 
 312     wxTextCtrl* GetEditControl();
 
 313     void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE);
 
 315 //    void SortChildren(const wxTreeItemId& item);
 
 317                       // wxTreeItemCmpFunc *cmpFunction = NULL);
 
 319     void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
 
 320     bool IsBold(const wxTreeItemId& item) const;
 
 321     wxTreeItemId HitTest(const wxPoint& point);
 
 325 //----------------------------------------------------------------------
 
 329 class wxTabEvent : public wxCommandEvent {
 
 335 class wxTabCtrl : public wxControl {
 
 337     wxTabCtrl(wxWindow* parent, wxWindowID id,
 
 338               const wxPoint& pos = wxPyDefaultPosition,
 
 339               const wxSize& size = wxPyDefaultSize,
 
 341               char* name = "tabCtrl");
 
 343     %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
 
 345     bool DeleteAllItems();
 
 346     bool DeleteItem(int item);
 
 347     wxImageList* GetImageList();
 
 349     // TODO: void* GetItemData();
 
 350     int GetItemImage(int item);
 
 353         %new wxRect* GetItemRect(int item) {
 
 354             wxRect* rect = new wxRect;
 
 355             self->GetItemRect(item, *rect);
 
 360     wxString GetItemText(int item);
 
 363     int HitTest(const wxPoint& pt, long& OUTPUT);
 
 364     void InsertItem(int item, const wxString& text,
 
 365                     int imageId = -1, void* clientData = NULL);
 
 366     // TODO: bool SetItemData(int item, void* data);
 
 367     bool SetItemImage(int item, int image);
 
 368     void SetImageList(wxImageList* imageList);
 
 369     void SetItemSize(const wxSize& size);
 
 370     bool SetItemText(int item, const wxString& text);
 
 371     void SetPadding(const wxSize& padding);
 
 372     int SetSelection(int item);
 
 379 //----------------------------------------------------------------------
 
 382 /////////////////////////////////////////////////////////////////////////////
 
 385 // Revision 1.11  1998/12/15 20:41:16  RD
 
 386 // Changed the import semantics from "from wxPython import *" to "from
 
 387 // wxPython.wx import *"  This is for people who are worried about
 
 388 // namespace pollution, they can use "from wxPython import wx" and then
 
 389 // prefix all the wxPython identifiers with "wx."
 
 391 // Added wxTaskbarIcon for wxMSW.
 
 393 // Made the events work for wxGrid.
 
 397 // Added wxMiniFrame for wxGTK, (untested.)
 
 399 // Changed many of the args and return values that were pointers to gdi
 
 400 // objects to references to reflect changes in the wxWindows API.
 
 402 // Other assorted fixes and additions.
 
 404 // Revision 1.10  1998/11/25 08:45:23  RD
 
 406 // Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
 
 407 // Added events for wxGrid
 
 408 // Other various fixes and additions
 
 410 // Revision 1.9  1998/11/16 00:00:54  RD
 
 411 // Generic treectrl for wxPython/GTK compiles...
 
 413 // Revision 1.8  1998/11/11 04:40:20  RD
 
 414 // wxTreeCtrl now works (sort of) for wxPython-GTK.  This is the new
 
 415 // TreeCtrl in src/gtk/treectrl.cpp not the old generic one.
 
 417 // Revision 1.7  1998/11/11 03:12:25  RD
 
 419 // Additions for wxTreeCtrl
 
 421 // Revision 1.6  1998/10/20 06:43:55  RD
 
 422 // New wxTreeCtrl wrappers (untested)
 
 423 // some changes in helpers
 
 426 // Revision 1.5  1998/10/07 07:34:33  RD
 
 427 // Version 0.4.1 for wxGTK
 
 429 // Revision 1.4  1998/10/02 06:40:36  RD
 
 431 // Version 0.4 of wxPython for MSW.
 
 433 // Revision 1.3  1998/08/18 19:48:15  RD
 
 434 // more wxGTK compatibility things.
 
 436 // It builds now but there are serious runtime problems...
 
 438 // Revision 1.2  1998/08/15 07:36:30  RD
 
 439 // - Moved the header in the .i files out of the code that gets put into
 
 440 // the .cpp files.  It caused CVS conflicts because of the RCS ID being
 
 441 // different each time.
 
 443 // - A few minor fixes.
 
 445 // Revision 1.1  1998/08/09 08:25:49  RD