~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/wx/treelistctrl/treelistctrl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        treelistctrl.cpp
 
3
// Purpose:     multi column tree control implementation
 
4
// Created:     01/02/97
 
5
// Author:      Robert Roebling
 
6
// Maintainer:  Ronan Chartois (pgriddev)
 
7
// Version:     $Id: treelistctrl.cpp 2693 2011-04-03 19:48:06Z pgriddev $
 
8
// Copyright:   (c) 2004-2011 Robert Roebling, Julian Smart, Alberto Griggio,
 
9
//              Vadim Zeitlin, Otto Wyss, Ronan Chartois
 
10
// Licence:     wxWindows
 
11
/////////////////////////////////////////////////////////////////////////////
 
12
 
 
13
// ===========================================================================
 
14
// declarations
 
15
// ===========================================================================
 
16
 
 
17
// ---------------------------------------------------------------------------
 
18
// headers
 
19
// ---------------------------------------------------------------------------
 
20
 
 
21
#if defined(__GNUG__) && !defined(__APPLE__)
 
22
  #pragma implementation "treelistctrl.h"
 
23
#endif
 
24
 
 
25
// For compilers that support precompilation, includes "wx.h".
 
26
#include "wx/wxprec.h"
 
27
 
 
28
#ifdef __BORLANDC__
 
29
    #pragma hdrstop
 
30
#endif
 
31
 
 
32
 
 
33
#include <wx/app.h>
 
34
#include <wx/treebase.h>
 
35
#include <wx/timer.h>
 
36
#include <wx/textctrl.h>
 
37
#include <wx/imaglist.h>
 
38
#include <wx/settings.h>
 
39
#include <wx/dcclient.h>
 
40
#include <wx/dcscreen.h>
 
41
#include <wx/scrolwin.h>
 
42
#include <wx/dcmemory.h>
 
43
#if wxCHECK_VERSION(2, 7, 0)
 
44
#include <wx/renderer.h>
 
45
#endif
 
46
#include <wx/apptrait.h>
 
47
#include <wx/dcbuffer.h>
 
48
#include <wx/tooltip.h>
 
49
#include <wx/hashmap.h>
 
50
 
 
51
#ifdef __WXMAC__
 
52
#include "wx/mac/private.h"
 
53
#endif
 
54
 
 
55
#include "treelistctrl.h"
 
56
 
 
57
#include <wx/log.h>  // only required for debugging purpose
 
58
#include <wx/msgdlg.h>  // only required for debugging purpose
 
59
 
 
60
// ---------------------------------------------------------------------------
 
61
// array types
 
62
// ---------------------------------------------------------------------------
 
63
 
 
64
class wxTreeListItem;
 
65
class wxTreeListItemCellAttr;
 
66
 
 
67
#if !wxCHECK_VERSION(2, 5, 0)
 
68
WX_DEFINE_ARRAY(wxTreeListItem *, wxArrayTreeListItems);
 
69
#else
 
70
WX_DEFINE_ARRAY_PTR(wxTreeListItem *, wxArrayTreeListItems);
 
71
#endif
 
72
 
 
73
#include <wx/dynarray.h>
 
74
WX_DECLARE_OBJARRAY(wxTreeListColumnInfo, wxArrayTreeListColumnInfo);
 
75
#include <wx/arrimpl.cpp>
 
76
WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo);
 
77
 
 
78
 
 
79
WX_DECLARE_HASH_MAP( int, wxTreeListItemCellAttr *, wxIntegerHash, wxIntegerEqual, wxTreeListItemCellAttrHash );
 
80
 
 
81
// --------------------------------------------------------------------------
 
82
// constants
 
83
// --------------------------------------------------------------------------
 
84
 
 
85
static const int NO_IMAGE = -1;
 
86
 
 
87
static const int LINEHEIGHT = 10;
 
88
static const int LINEATROOT = 5;
 
89
static const int MARGIN = 2;
 
90
static const int MININDENT = 16;
 
91
static const int BTNWIDTH = 9;
 
92
static const int BTNHEIGHT = 9;
 
93
static const int EXTRA_WIDTH = 4;
 
94
static const int EXTRA_HEIGHT = 4;
 
95
static const int HEADER_OFFSET_X = 0;  // changed from 1 to 0 on 2009.03.10 for Windows (other OS untested)
 
96
static const int HEADER_OFFSET_Y = 1;
 
97
 
 
98
static const int DRAG_TIMER_TICKS = 250; // minimum drag wait time in ms
 
99
static const int FIND_TIMER_TICKS = 500; // minimum find wait time in ms
 
100
static const int RENAME_TIMER_TICKS = 250; // minimum rename wait time in ms
 
101
 
 
102
const wxChar* wxTreeListCtrlNameStr = _T("treelistctrl");
 
103
 
 
104
static wxTreeListColumnInfo wxInvalidTreeListColumnInfo;
 
105
 
 
106
 
 
107
// ---------------------------------------------------------------------------
 
108
// private classes
 
109
// ---------------------------------------------------------------------------
 
110
 
 
111
class  wxTreeListHeaderWindow : public wxWindow
 
112
{
 
113
protected:
 
114
    wxTreeListMainWindow *m_owner;
 
115
    const wxCursor *m_currentCursor;
 
116
    const wxCursor *m_resizeCursor;
 
117
    bool m_isDragging;
 
118
 
 
119
    // column being resized
 
120
    int m_column;
 
121
 
 
122
    // divider line position in logical (unscrolled) coords
 
123
    int m_currentX;
 
124
 
 
125
    // minimal position beyond which the divider line can't be dragged in
 
126
    // logical coords
 
127
    int m_minX;
 
128
 
 
129
    wxArrayTreeListColumnInfo m_columns;
 
130
 
 
131
    // total width of the columns
 
132
    int m_total_col_width;
 
133
 
 
134
#if wxCHECK_VERSION_FULL(2, 7, 0, 1)
 
135
    // which col header is currently highlighted with mouse-over
 
136
    int m_hotTrackCol;
 
137
    int XToCol(int x);
 
138
    void RefreshColLabel(int col);
 
139
#endif
 
140
 
 
141
public:
 
142
    wxTreeListHeaderWindow();
 
143
 
 
144
    wxTreeListHeaderWindow( wxWindow *win,
 
145
                            wxWindowID id,
 
146
                            wxTreeListMainWindow *owner,
 
147
                            const wxPoint &pos = wxDefaultPosition,
 
148
                            const wxSize &size = wxDefaultSize,
 
149
                            long style = 0,
 
150
                            const wxString &name = _T("wxtreelistctrlcolumntitles") );
 
151
 
 
152
    virtual ~wxTreeListHeaderWindow();
 
153
 
 
154
    void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
 
155
    void DrawCurrent();
 
156
    void AdjustDC(wxDC& dc);
 
157
 
 
158
    void OnPaint( wxPaintEvent &event );
 
159
    void OnEraseBackground(wxEraseEvent& WXUNUSED(event)) { ;; } // reduce flicker
 
160
    void OnMouse( wxMouseEvent &event );
 
161
    void OnSetFocus( wxFocusEvent &event );
 
162
 
 
163
    // total width of all columns
 
164
    int GetWidth() const { return m_total_col_width; }
 
165
 
 
166
    // column manipulation
 
167
    int GetColumnCount() const { return (int)m_columns.GetCount(); }
 
168
 
 
169
    void AddColumn (const wxTreeListColumnInfo& colInfo);
 
170
 
 
171
    void InsertColumn (int before, const wxTreeListColumnInfo& colInfo);
 
172
 
 
173
    void RemoveColumn (int column);
 
174
 
 
175
    // column information manipulation
 
176
    const wxTreeListColumnInfo& GetColumn (int column) const{
 
177
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
178
                     wxInvalidTreeListColumnInfo, _T("Invalid column"));
 
179
        return m_columns[column];
 
180
    }
 
181
    wxTreeListColumnInfo& GetColumn (int column) {
 
182
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
183
                     wxInvalidTreeListColumnInfo, _T("Invalid column"));
 
184
        return m_columns[column];
 
185
    }
 
186
    void SetColumn (int column, const wxTreeListColumnInfo& info);
 
187
 
 
188
    wxString GetColumnText (int column) const {
 
189
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
190
                     wxEmptyString, _T("Invalid column"));
 
191
        return m_columns[column].GetText();
 
192
    }
 
193
    void SetColumnText (int column, const wxString& text) {
 
194
        wxCHECK_RET ((column >= 0) && (column < GetColumnCount()),
 
195
                     _T("Invalid column"));
 
196
        m_columns[column].SetText (text);
 
197
    }
 
198
 
 
199
    int GetColumnAlignment (int column) const {
 
200
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
201
                     wxALIGN_LEFT, _T("Invalid column"));
 
202
        return m_columns[column].GetAlignment();
 
203
    }
 
204
    void SetColumnAlignment (int column, int flag) {
 
205
        wxCHECK_RET ((column >= 0) && (column < GetColumnCount()),
 
206
                     _T("Invalid column"));
 
207
        m_columns[column].SetAlignment (flag);
 
208
    }
 
209
 
 
210
    int GetColumnWidth (int column) const {
 
211
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
212
                     -1, _T("Invalid column"));
 
213
        return m_columns[column].GetWidth();
 
214
    }
 
215
    void SetColumnWidth (int column, int width);
 
216
 
 
217
    bool IsColumnEditable (int column) const {
 
218
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
219
                     false, _T("Invalid column"));
 
220
        return m_columns[column].IsEditable();
 
221
    }
 
222
 
 
223
    bool IsColumnShown (int column) const {
 
224
        wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
 
225
                     true, _T("Invalid column"));
 
226
        return m_columns[column].IsShown();
 
227
    }
 
228
 
 
229
    // needs refresh
 
230
    bool m_dirty;
 
231
 
 
232
private:
 
233
    // common part of all ctors
 
234
    void Init();
 
235
 
 
236
    void SendListEvent(wxEventType type, wxPoint pos);
 
237
 
 
238
    DECLARE_DYNAMIC_CLASS(wxTreeListHeaderWindow)
 
239
    DECLARE_EVENT_TABLE()
 
240
};
 
241
 
 
242
 
 
243
//-----------------------------------------------------------------------------
 
244
 
 
245
class wxEditTextCtrl;
 
246
 
 
247
 
 
248
// this is the "true" control
 
249
class  wxTreeListMainWindow: public wxScrolledWindow
 
250
{
 
251
public:
 
252
    // creation
 
253
    // --------
 
254
    wxTreeListMainWindow() { Init(); }
 
255
 
 
256
    wxTreeListMainWindow (wxTreeListCtrl *parent, wxWindowID id = -1,
 
257
               const wxPoint& pos = wxDefaultPosition,
 
258
               const wxSize& size = wxDefaultSize,
 
259
               long style = wxTR_DEFAULT_STYLE,
 
260
               const wxValidator &validator = wxDefaultValidator,
 
261
               const wxString& name = _T("wxtreelistmainwindow"))
 
262
    {
 
263
        Init();
 
264
        Create (parent, id, pos, size, style, validator, name);
 
265
    }
 
266
 
 
267
    virtual ~wxTreeListMainWindow();
 
268
 
 
269
    bool Create(wxTreeListCtrl *parent, wxWindowID id = -1,
 
270
                const wxPoint& pos = wxDefaultPosition,
 
271
                const wxSize& size = wxDefaultSize,
 
272
                long style = wxTR_DEFAULT_STYLE,
 
273
                const wxValidator &validator = wxDefaultValidator,
 
274
                const wxString& name = _T("wxtreelistctrl"));
 
275
 
 
276
    // accessors
 
277
    // ---------
 
278
 
 
279
    // return true if this is a virtual list control
 
280
    bool IsVirtual() const { return HasFlag(wxTR_VIRTUAL); }
 
281
 
 
282
    // get the total number of items in the control
 
283
    size_t GetCount() const;
 
284
 
 
285
    // indent is the number of pixels the children are indented relative to
 
286
    // the parents position. SetIndent() also redraws the control
 
287
    // immediately.
 
288
    unsigned int GetIndent() const { return m_indent; }
 
289
    void SetIndent(unsigned int indent);
 
290
 
 
291
    // see wxTreeListCtrl for the meaning
 
292
    unsigned int GetLineSpacing() const { return m_linespacing; }
 
293
    void SetLineSpacing(unsigned int spacing);
 
294
 
 
295
    // image list: these functions allow to associate an image list with
 
296
    // the control and retrieve it. Note that when assigned with
 
297
    // SetImageList, the control does _not_ delete
 
298
    // the associated image list when it's deleted in order to allow image
 
299
    // lists to be shared between different controls. If you use
 
300
    // AssignImageList, the control _does_ delete the image list.
 
301
 
 
302
    // The normal image list is for the icons which correspond to the
 
303
    // normal tree item state (whether it is selected or not).
 
304
    // Additionally, the application might choose to show a state icon
 
305
    // which corresponds to an app-defined item state (for example,
 
306
    // checked/unchecked) which are taken from the state image list.
 
307
    wxImageList *GetImageList() const { return m_imageListNormal; }
 
308
    wxImageList *GetStateImageList() const { return m_imageListState; }
 
309
    wxImageList *GetButtonsImageList() const { return m_imageListButtons; }
 
310
 
 
311
    void SetImageList(wxImageList *imageList);
 
312
    void SetStateImageList(wxImageList *imageList);
 
313
    void SetButtonsImageList(wxImageList *imageList);
 
314
    void AssignImageList(wxImageList *imageList);
 
315
    void AssignStateImageList(wxImageList *imageList);
 
316
    void AssignButtonsImageList(wxImageList *imageList);
 
317
 
 
318
    void SetToolTip(const wxString& tip);
 
319
    void SetToolTip(wxToolTip *tip);
 
320
    void SetItemToolTip(const wxTreeItemId& item, const wxString &tip);
 
321
 
 
322
    // Functions to work with tree ctrl items.
 
323
 
 
324
 
 
325
 
 
326
    // accessors (most props have a default at row/item level *and* a default at cell level)
 
327
    // ---------
 
328
 
 
329
         std::list<wxTreeItemId> GetPublicChildren(const wxTreeItemId& item) const;
 
330
    wxString GetItemText (const wxTreeItemId& item, int column) const;
 
331
    wxString GetItemText (wxTreeItemData* item, int column) const;
 
332
 
 
333
    // ItemImage is special: main col has multiple images
 
334
    int GetItemImage (const wxTreeItemId& item,             wxTreeItemIcon which = wxTreeItemIcon_Normal) const  { return GetItemImage (item, GetMainColumn(), which); }
 
335
    int GetItemImage (const wxTreeItemId& item, int column, wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
 
336
 
 
337
    // ItemData is special, there is a separate default at row/item level
 
338
    wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
 
339
    wxTreeItemData *GetItemData(const wxTreeItemId& item, int column) const;
 
340
 
 
341
    bool GetItemBold(const wxTreeItemId& item)             const;
 
342
    bool GetItemBold(const wxTreeItemId& item, int column) const;
 
343
 
 
344
    wxColour GetItemTextColour(const wxTreeItemId& item)             const;
 
345
    wxColour GetItemTextColour(const wxTreeItemId& item, int column) const;
 
346
 
 
347
    wxColour GetItemBackgroundColour(const wxTreeItemId& item)             const;
 
348
    wxColour GetItemBackgroundColour(const wxTreeItemId& item, int column) const;
 
349
 
 
350
    wxFont GetItemFont(const wxTreeItemId& item) const;
 
351
    wxFont GetItemFont(const wxTreeItemId& item, int column) const;
 
352
 
 
353
 
 
354
 
 
355
    // modifiers (most properties have a default at row/item level *and* a default at cell level)
 
356
    // ---------
 
357
 
 
358
    // force appearance of [+] button near the item. This is useful to
 
359
    // allow the user to expand the items which don't have any children now
 
360
    // - but instead add them only when needed, thus minimizing memory
 
361
    // usage and loading time.
 
362
    void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
 
363
 
 
364
    // set item's label
 
365
    void SetItemText (const wxTreeItemId& item, int column, const wxString& text);
 
366
 
 
367
    // get one of the images associated with the item (normal by default)
 
368
    void SetItemImage (const wxTreeItemId& item,             int image, wxTreeItemIcon which = wxTreeItemIcon_Normal) { SetItemImage (item, GetMainColumn(), image, which); }
 
369
    void SetItemImage (const wxTreeItemId& item, int column, int image, wxTreeItemIcon which = wxTreeItemIcon_Normal);
 
370
 
 
371
    // associate some data with the item
 
372
    void SetItemData(const wxTreeItemId& item,             wxTreeItemData *data);
 
373
    void SetItemData(const wxTreeItemId& item, int column, wxTreeItemData *data);
 
374
 
 
375
    // the item will be shown in bold
 
376
    void SetItemBold(const wxTreeItemId& item,             bool bold = true);
 
377
    void SetItemBold(const wxTreeItemId& item, int column, bool bold = true);
 
378
 
 
379
    // set the item's text colour
 
380
    void SetItemTextColour(const wxTreeItemId& item,             const wxColour& colour);
 
381
    void SetItemTextColour(const wxTreeItemId& item, int column, const wxColour& colour);
 
382
 
 
383
    // set the item's background colour
 
384
    void SetItemBackgroundColour(const wxTreeItemId& item,             const wxColour& colour);
 
385
    void SetItemBackgroundColour(const wxTreeItemId& item, int column, const wxColour& colour);
 
386
 
 
387
    // set the item's font (should be of the same height for all items)
 
388
    void SetItemFont(const wxTreeItemId& item,             const wxFont& font);
 
389
    void SetItemFont(const wxTreeItemId& item, int column, const wxFont& font);
 
390
 
 
391
 
 
392
 
 
393
    // item status inquiries
 
394
    // ---------------------
 
395
 
 
396
    // is the item visible (it might be outside the view or not expanded)?
 
397
    bool IsVisible(const wxTreeItemId& item, bool fullRow, bool within = true) const;
 
398
    // does the item has any children?
 
399
    bool HasChildren(const wxTreeItemId& item) const;
 
400
    // is the item expanded (only makes sense if HasChildren())?
 
401
    bool IsExpanded(const wxTreeItemId& item) const;
 
402
    // is this item currently selected (the same as has focus)?
 
403
    bool IsSelected(const wxTreeItemId& item) const;
 
404
    // is item text in bold font?
 
405
    bool IsBold(const wxTreeItemId& item)             const;
 
406
    bool IsBold(const wxTreeItemId& item, int column) const;
 
407
 
 
408
 
 
409
 
 
410
    // set the window font
 
411
    virtual bool SetFont( const wxFont &font );
 
412
 
 
413
    // set the styles.  No need to specify a GetWindowStyle here since
 
414
    // the base wxWindow member function will do it for us
 
415
    void SetWindowStyle(const long styles);
 
416
 
 
417
    // number of children
 
418
    // ------------------
 
419
 
 
420
    // if 'recursively' is false, only immediate children count, otherwise
 
421
    // the returned number is the number of all items in this branch
 
422
    size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = true);
 
423
 
 
424
    // navigation
 
425
    // ----------
 
426
 
 
427
    // wxTreeItemId.IsOk() will return false if there is no such item
 
428
 
 
429
    // get the root tree item
 
430
    wxTreeItemId GetRootItem() const { return m_rootItem; }  // implict cast from wxTreeListItem *
 
431
 
 
432
    // get the item currently selected, only if a single item is selected
 
433
    wxTreeItemId GetSelection() const { return m_selectItem; }
 
434
 
 
435
    // get all the items currently selected, return count of items
 
436
    size_t GetSelections(wxArrayTreeItemIds&) const;
 
437
 
 
438
    // get the parent of this item (may return NULL if root)
 
439
    wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
 
440
 
 
441
    // for this enumeration function you must pass in a "cookie" parameter
 
442
    // which is opaque for the application but is necessary for the library
 
443
    // to make these functions reentrant (i.e. allow more than one
 
444
    // enumeration on one and the same object simultaneously). Of course,
 
445
    // the "cookie" passed to GetFirstChild() and GetNextChild() should be
 
446
    // the same!
 
447
 
 
448
    // get child of this item
 
449
#if !wxCHECK_VERSION(2, 5, 0)
 
450
    wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
 
451
    wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
 
452
    wxTreeItemId GetPrevChild(const wxTreeItemId& item, long& cookie) const;
 
453
    wxTreeItemId GetLastChild(const wxTreeItemId& item, long& cookie) const;
 
454
#else
 
455
    wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
 
456
    wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
 
457
    wxTreeItemId GetPrevChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
 
458
    wxTreeItemId GetLastChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
 
459
#endif
 
460
 
 
461
    // get sibling of this item
 
462
    wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
 
463
    wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
 
464
 
 
465
    // get item in the full tree (currently only for internal use)
 
466
    wxTreeItemId GetNext(const wxTreeItemId& item, bool fulltree = true) const;
 
467
    wxTreeItemId GetPrev(const wxTreeItemId& item, bool fulltree = true) const;
 
468
 
 
469
    // get expanded item, see IsExpanded()
 
470
    wxTreeItemId GetFirstExpandedItem() const;
 
471
    wxTreeItemId GetNextExpanded(const wxTreeItemId& item) const;
 
472
    wxTreeItemId GetPrevExpanded(const wxTreeItemId& item) const;
 
473
 
 
474
    // get visible item, see IsVisible()
 
475
    wxTreeItemId GetFirstVisible(                          bool fullRow, bool within) const;
 
476
    wxTreeItemId GetNextVisible (const wxTreeItemId& item, bool fullRow, bool within) const;
 
477
    wxTreeItemId GetPrevVisible (const wxTreeItemId& item, bool fullRow, bool within) const;
 
478
    wxTreeItemId GetLastVisible (                          bool fullRow, bool within) const;
 
479
 
 
480
    // operations
 
481
    // ----------
 
482
 
 
483
    // add the root node to the tree
 
484
    wxTreeItemId AddRoot (const wxString& text,
 
485
                          int image = -1, int selectedImage = -1,
 
486
                          wxTreeItemData *data = NULL);
 
487
 
 
488
    // insert a new item in as the first child of the parent
 
489
    wxTreeItemId PrependItem(const wxTreeItemId& parent,
 
490
                             const wxString& text,
 
491
                             int image = -1, int selectedImage = -1,
 
492
                             wxTreeItemData *data = NULL);
 
493
 
 
494
    // insert a new item after a given one
 
495
    wxTreeItemId InsertItem(const wxTreeItemId& parent,
 
496
                            const wxTreeItemId& idPrevious,
 
497
                            const wxString& text,
 
498
                            int image = -1, int selectedImage = -1,
 
499
                            wxTreeItemData *data = NULL);
 
500
 
 
501
    // insert a new item before the one with the given index
 
502
    wxTreeItemId InsertItem(const wxTreeItemId& parent,
 
503
                            size_t index,
 
504
                            const wxString& text,
 
505
                            int image = -1, int selectedImage = -1,
 
506
                            wxTreeItemData *data = NULL);
 
507
 
 
508
    // insert a new item in as the last child of the parent
 
509
    wxTreeItemId AppendItem(const wxTreeItemId& parent,
 
510
                            const wxString& text,
 
511
                            int image = -1, int selectedImage = -1,
 
512
                            wxTreeItemData *data = NULL);
 
513
 
 
514
    // delete this item and associated data if any
 
515
    void Delete(const wxTreeItemId& item);
 
516
    // delete all children (but don't delete the item itself)
 
517
    // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
 
518
    void DeleteChildren(const wxTreeItemId& item);
 
519
    // delete the root and all its children from the tree
 
520
    // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
 
521
    void DeleteRoot();
 
522
 
 
523
    // expand this item
 
524
    void Expand(const wxTreeItemId& item);
 
525
    // expand this item and all subitems recursively
 
526
    void ExpandAll(const wxTreeItemId& item);
 
527
    // collapse the item without removing its children
 
528
    void Collapse(const wxTreeItemId& item);
 
529
    // collapse the item and remove all children
 
530
    void CollapseAndReset(const wxTreeItemId& item);
 
531
    // toggles the current state
 
532
    void Toggle(const wxTreeItemId& item);
 
533
 
 
534
    // set cursor item (indicated by black rectangle)
 
535
    void SetCurrentItem(const wxTreeItemId& item);
 
536
 
 
537
    // remove the selection from currently selected item (if any)
 
538
    void Unselect();
 
539
    void UnselectAll();
 
540
    // select this item
 
541
    bool SelectItem(const wxTreeItemId& item, const wxTreeItemId& prev = (wxTreeItemId*)NULL,
 
542
                    bool unselect_others = true);
 
543
    void SelectAll();
 
544
    // make sure this item is visible (expanding the parent item and/or
 
545
    // scrolling to this item if necessary)
 
546
    void EnsureVisible(const wxTreeItemId& item);
 
547
    // scroll to this item (but don't expand its parent)
 
548
    void ScrollTo(const wxTreeItemId& item);
 
549
    void AdjustMyScrollbars();
 
550
 
 
551
    // The first function is more portable (because easier to implement
 
552
    // on other platforms), but the second one returns some extra info.
 
553
    wxTreeItemId HitTest (const wxPoint& point)
 
554
        { int flags; int column; return HitTest (point, flags, column); }
 
555
    wxTreeItemId HitTest (const wxPoint& point, int& flags)
 
556
        { int column; return HitTest (point, flags, column); }
 
557
    wxTreeItemId HitTest (const wxPoint& point, int& flags, int& column);
 
558
 
 
559
 
 
560
    // get the bounding rectangle of the item (or of its label only)
 
561
    bool GetBoundingRect(const wxTreeItemId& item,
 
562
                         wxRect& rect,
 
563
                         bool textOnly = false) const;
 
564
 
 
565
    // Start editing the item label: this (temporarily) replaces the item
 
566
    // with a one line edit control. The item will be selected if it hadn't
 
567
    // been before.
 
568
    void EditLabel (const wxTreeItemId& item, int column);
 
569
    void EndEdit(bool isCancelled);
 
570
 
 
571
    // sorting
 
572
    // this function is called to compare 2 items and should return -1, 0
 
573
    // or +1 if the first item is less than, equal to or greater than the
 
574
    // second one. The base class version performs alphabetic comparaison
 
575
    // of item labels (GetText)
 
576
    virtual int OnCompareItems(const wxTreeItemId& item1,
 
577
                               const wxTreeItemId& item2);
 
578
    // sort the children of this item using OnCompareItems
 
579
    //
 
580
    // NB: this function is not reentrant and not MT-safe (TODO)!
 
581
    void SortChildren(const wxTreeItemId& item, int column, bool reverseOrder);
 
582
 
 
583
    // searching
 
584
    wxTreeItemId FindItem (const wxTreeItemId& item, int column, const wxString& str, int mode = 0);
 
585
 
 
586
    // implementation only from now on
 
587
 
 
588
    // overridden base class virtuals
 
589
    virtual bool SetBackgroundColour(const wxColour& colour);
 
590
    virtual bool SetForegroundColour(const wxColour& colour);
 
591
 
 
592
    // drop over item
 
593
    void SetDragItem (const wxTreeItemId& item = (wxTreeItemId*)NULL);
 
594
 
 
595
    // callbacks
 
596
    void OnPaint( wxPaintEvent &event );
 
597
    void OnEraseBackground(wxEraseEvent& WXUNUSED(event)) { ;; } // to reduce flicker
 
598
    void OnSetFocus( wxFocusEvent &event );
 
599
    void OnKillFocus( wxFocusEvent &event );
 
600
    void OnChar( wxKeyEvent &event );
 
601
    void OnMouse( wxMouseEvent &event );
 
602
    void OnIdle( wxIdleEvent &event );
 
603
    void OnScroll(wxScrollWinEvent& event);
 
604
    void OnCaptureLost(wxMouseCaptureLostEvent & WXUNUSED(event)) { ;; }
 
605
 
 
606
    // implementation helpers
 
607
    int GetColumnCount() const
 
608
    { return m_owner->GetHeaderWindow()->GetColumnCount(); }
 
609
 
 
610
    void SetMainColumn (int column)
 
611
    { if ((column >= 0) && (column < GetColumnCount())) m_main_column = column; }
 
612
 
 
613
    int GetMainColumn() const { return m_main_column; }
 
614
    int GetCurrentColumn() const { return m_curColumn >= 0 ? m_curColumn : m_main_column; }
 
615
 
 
616
    int GetBestColumnWidth (int column, wxTreeItemId parent = wxTreeItemId());
 
617
    int GetItemWidth (int column, wxTreeListItem *item);
 
618
 
 
619
    void SetFocus();
 
620
 
 
621
protected:
 
622
    wxTreeListCtrl* m_owner;
 
623
 
 
624
    int m_main_column;
 
625
 
 
626
    friend class wxTreeListItem;
 
627
    friend class wxTreeListRenameTimer;
 
628
    friend class wxEditTextCtrl;
 
629
 
 
630
    wxFont               m_normalFont;
 
631
    wxFont               m_boldFont;
 
632
 
 
633
    wxTreeListItem       *m_rootItem; // root item
 
634
    wxTreeListItem       *m_curItem; // current item, either selected or marked
 
635
    wxTreeListItem       *m_shiftItem; // item, where the shift key was pressed
 
636
    wxTreeListItem       *m_selectItem; // current selected item, not with wxTR_MULTIPLE
 
637
 
 
638
    int                  m_curColumn;
 
639
    int                  m_sortColumn;
 
640
    bool                 m_ReverseSortOrder;
 
641
 
 
642
    int                  m_btnWidth, m_btnWidth2;
 
643
    int                  m_btnHeight, m_btnHeight2;
 
644
    int                  m_imgWidth, m_imgWidth2;
 
645
    int                  m_imgHeight, m_imgHeight2;
 
646
    unsigned short       m_indent;
 
647
    int                  m_lineHeight;
 
648
    unsigned short       m_linespacing;
 
649
    wxPen                m_dottedPen;
 
650
    wxBrush             *m_hilightBrush,
 
651
                        *m_hilightUnfocusedBrush;
 
652
    bool                 m_hasFocus;
 
653
public:
 
654
    bool                 m_dirty;
 
655
protected:
 
656
    bool                 m_ownsImageListNormal,
 
657
                         m_ownsImageListState,
 
658
                         m_ownsImageListButtons;
 
659
    bool                 m_lastOnSame;  // last click on the same item as prev
 
660
    bool                 m_left_down_selection;
 
661
 
 
662
    wxImageList         *m_imageListNormal,
 
663
                        *m_imageListState,
 
664
                        *m_imageListButtons;
 
665
 
 
666
    bool                 m_isDragStarted;  // set at the very beginning of dragging
 
667
    bool                 m_isDragging; // set once a drag begin event was fired
 
668
    wxPoint              m_dragStartPos;  // set whenever m_isDragStarted is set to true
 
669
    wxTreeListItem      *m_dragItem;
 
670
    int                  m_dragCol;
 
671
 
 
672
    wxTreeListItem       *m_editItem; // item, which is currently edited
 
673
    wxTimer             *m_editTimer;
 
674
    bool                 m_editAccept;  // currently unused, OnRenameAccept() argument makes it redundant
 
675
    wxString             m_editRes;
 
676
    int                  m_editCol;
 
677
    wxEditTextCtrl      *m_editControl;
 
678
 
 
679
    // char navigation
 
680
    wxTimer             *m_findTimer;
 
681
    wxString             m_findStr;
 
682
 
 
683
    bool                 m_isItemToolTip;  // true if individual item tooltips were set (disable global tooltip)
 
684
    wxString             m_toolTip;  // global tooltip
 
685
    wxTreeListItem      *m_toolTipItem;  // item whose tip is currently shown (NULL==global, -1==not displayed)
 
686
 
 
687
    // the common part of all ctors
 
688
    void Init();
 
689
 
 
690
    // misc helpers
 
691
    wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
 
692
                              size_t previous,
 
693
                              const wxString& text,
 
694
                              int image, int selectedImage,
 
695
                              wxTreeItemData *data);
 
696
    void DoDeleteItem (wxTreeListItem *item);
 
697
    void SetCurrentItem(wxTreeListItem *item);
 
698
    bool HasButtons(void) const
 
699
        { return (m_imageListButtons) || HasFlag (wxTR_TWIST_BUTTONS|wxTR_HAS_BUTTONS); }
 
700
 
 
701
    void CalculateLineHeight();
 
702
    int  GetLineHeight(wxTreeListItem *item) const;
 
703
    void PaintLevel( wxTreeListItem *item, wxDC& dc, int level, int &y,
 
704
                     int x_maincol);
 
705
    void PaintItem( wxTreeListItem *item, wxDC& dc);
 
706
 
 
707
    void CalculateLevel( wxTreeListItem *item, wxDC &dc, int level, int &y,
 
708
                         int x_maincol);
 
709
    void CalculatePositions();
 
710
    void CalculateSize( wxTreeListItem *item, wxDC &dc );
 
711
 
 
712
    void RefreshSubtree (wxTreeListItem *item);
 
713
    void RefreshLine (wxTreeListItem *item);
 
714
    // redraw all selected items
 
715
    void RefreshSelected();
 
716
    // RefreshSelected() recursive helper
 
717
    void RefreshSelectedUnder (wxTreeListItem *item);
 
718
 
 
719
    void OnRenameTimer();
 
720
    void OnRenameAccept(bool isCancelled);
 
721
 
 
722
    void FillArray(wxTreeListItem*, wxArrayTreeItemIds&) const;
 
723
    bool TagAllChildrenUntilLast (wxTreeListItem *crt_item, wxTreeListItem *last_item);
 
724
    bool TagNextChildren (wxTreeListItem *crt_item, wxTreeListItem *last_item);
 
725
    void UnselectAllChildren (wxTreeListItem *item );
 
726
    bool SendEvent(wxEventType event_type, wxTreeListItem *item = NULL, wxTreeEvent *event = NULL);  // returns true if processed
 
727
 
 
728
private:
 
729
    DECLARE_EVENT_TABLE()
 
730
    DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow)
 
731
};
 
732
 
 
733
 
 
734
//-----------------------------------------------------------------------------
 
735
 
 
736
// timer used for enabling in-place edit
 
737
class  wxTreeListRenameTimer: public wxTimer
 
738
{
 
739
public:
 
740
    wxTreeListRenameTimer( wxTreeListMainWindow *owner );
 
741
 
 
742
    void Notify();
 
743
 
 
744
private:
 
745
    wxTreeListMainWindow   *m_owner;
 
746
};
 
747
 
 
748
 
 
749
//-----------------------------------------------------------------------------
 
750
 
 
751
// control used for in-place edit
 
752
class  wxEditTextCtrl: public wxTextCtrl
 
753
{
 
754
public:
 
755
    wxEditTextCtrl (wxWindow *parent,
 
756
                    const wxWindowID id,
 
757
                    bool *accept,
 
758
                    wxString *res,
 
759
                    wxTreeListMainWindow *owner,
 
760
                    const wxString &value = wxEmptyString,
 
761
                    const wxPoint &pos = wxDefaultPosition,
 
762
                    const wxSize &size = wxDefaultSize,
 
763
                    int style = 0,
 
764
                    const wxValidator& validator = wxDefaultValidator,
 
765
                    const wxString &name = wxTextCtrlNameStr );
 
766
    ~wxEditTextCtrl();
 
767
 
 
768
    virtual bool Destroy();  // wxWindow override
 
769
    void EndEdit(bool isCancelled);
 
770
    void SetOwner(wxTreeListMainWindow *owner) { m_owner = owner; }
 
771
 
 
772
    void OnChar( wxKeyEvent &event );
 
773
    void OnKeyUp( wxKeyEvent &event );
 
774
    void OnKillFocus( wxFocusEvent &event );
 
775
 
 
776
 
 
777
private:
 
778
    wxTreeListMainWindow  *m_owner;
 
779
    bool               *m_accept;
 
780
    wxString           *m_res;
 
781
    wxString            m_startValue;
 
782
    bool                m_finished;  // true==deleting, don't process events anymore
 
783
 
 
784
    DECLARE_EVENT_TABLE()
 
785
};
 
786
 
 
787
 
 
788
//-----------------------------------------------------------------------------
 
789
 
 
790
// list of per-column attributes for an item (wxTreeListItem)
 
791
// since there can be very many of these, we save size by chosing
 
792
// the smallest representation for the elements and by ordering
 
793
// the members to avoid padding.
 
794
class  wxTreeListItemCellAttr
 
795
{
 
796
public:
 
797
    wxTreeListItemCellAttr() {
 
798
        m_attr = NULL;
 
799
        m_data = NULL;
 
800
        m_isBold = 0;
 
801
        m_isBoldSet = 0;
 
802
        m_ownsAttr = 0;
 
803
        m_image = NO_IMAGE;
 
804
    };
 
805
    ~wxTreeListItemCellAttr() {
 
806
        if (m_ownsAttr) delete m_attr;
 
807
    }
 
808
 
 
809
    // generic attribute from wxWidgets lib
 
810
    wxTreeItemAttr      *m_attr;
 
811
 
 
812
    // other attributes
 
813
    wxTreeItemData      *m_data;        // user-provided data
 
814
    short                m_image;       // images for the various columns (!= main)
 
815
    int                  m_isBold :1;   // render the label in bold font
 
816
    int                  m_isBoldSet :1;   // was 'm_isBold' set ?
 
817
    int                  m_ownsAttr :1; // delete attribute when done
 
818
};
 
819
 
 
820
 
 
821
//-----------------------------------------------------------------------------
 
822
 
 
823
// a tree item (NOTE: this class is storage only, does not generate events)
 
824
class  wxTreeListItem : public wxTreeListItemPublic
 
825
{
 
826
public:
 
827
    // ctors & dtor
 
828
    // ------------
 
829
    wxTreeListItem() { m_toolTip = NULL; }
 
830
    wxTreeListItem( wxTreeListMainWindow *owner,
 
831
                    wxTreeListItem *parent,
 
832
                    const wxArrayString& text,
 
833
                    int image,
 
834
                    int selImage,
 
835
                    wxTreeItemData *data );
 
836
 
 
837
    ~wxTreeListItem();
 
838
 
 
839
 
 
840
    // accessors (most properties have a default at row/item level)
 
841
    // ---------
 
842
        
 
843
        virtual  std::list<wxTreeItemId> GetPublicChildren() const
 
844
        {
 
845
                std::list<wxTreeItemId> ch;
 
846
                for (unsigned int i = 0; i < m_children.size(); i++) {
 
847
                        ch.push_back(m_children[i]);
 
848
                }
 
849
                return ch;
 
850
        }
 
851
 
 
852
        wxArrayTreeListItems& GetChildren() { return m_children; }
 
853
 
 
854
 
 
855
//    const wxString GetText (          ) const { return GetText(m_owner->GetMainColumn());  }
 
856
    const wxString GetText (int column) const
 
857
    {
 
858
        if ( IsVirtual() )   return m_owner->GetItemText( m_props_row.m_data, column );
 
859
        if (column < (signed)m_text.GetCount()) return m_text[column];
 
860
        return wxEmptyString;
 
861
    };
 
862
 
 
863
    int GetImage (            wxTreeItemIcon which = wxTreeItemIcon_Normal) const { return m_images[which]; };
 
864
    int GetImage (int column, wxTreeItemIcon which = wxTreeItemIcon_Normal) const
 
865
    {
 
866
        // main column is special, more images available
 
867
        if(column == m_owner->GetMainColumn()) return m_images[which];
 
868
 
 
869
        // other columns ignore the 'which' parameter
 
870
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
871
        if (entry == m_props_cell.end()) return NO_IMAGE;
 
872
        return entry->second->m_image;
 
873
    };
 
874
 
 
875
    // data is special: it has a default value at row/item level
 
876
    wxTreeItemData *GetData()           const { return m_props_row.m_data; };
 
877
    wxTreeItemData *GetData(int column) const {
 
878
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
879
        if (entry == m_props_cell.end()) return NULL;
 
880
        return entry->second->m_data;
 
881
    };
 
882
 
 
883
    const wxString * GetToolTip() const  {  return m_toolTip;  };
 
884
 
 
885
    // returns the current image for the item (depending on its
 
886
    // selected/expanded/whatever state)
 
887
    int GetCurrentImage() const;
 
888
 
 
889
 
 
890
    // modifiers (most properties have a default at row/item level)
 
891
    // ---------
 
892
    void SetHasPlus(bool has = true) { m_hasPlus = has; };
 
893
 
 
894
    void SetText (int column, const wxString& text)
 
895
    {
 
896
        if (column < (int)m_text.GetCount()) {
 
897
            m_text[column] = text;
 
898
        } else if (column < m_owner->GetColumnCount()) {
 
899
            int howmany = m_owner->GetColumnCount();
 
900
            for (int i = (int)m_text.GetCount(); i < howmany; ++i) m_text.Add (wxEmptyString);
 
901
            m_text[column] = text;
 
902
        }
 
903
    };
 
904
    void SetImage (            int image, wxTreeItemIcon which) { m_images[which] = image; };
 
905
    void SetImage (int column, int image, wxTreeItemIcon which)
 
906
    {
 
907
        // main column is special, more images available
 
908
        if (column == m_owner->GetMainColumn()) m_images[which] = image;
 
909
        // other columns ignore the 'which' parameter
 
910
        else {
 
911
            wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
912
            if (entry == m_props_cell.end()) {
 
913
                m_props_cell[column] = new wxTreeListItemCellAttr();
 
914
                m_props_cell[column]->m_image = image;
 
915
            } else {
 
916
                entry->second->m_image = image;
 
917
            }
 
918
        }
 
919
    };
 
920
 
 
921
    // data is special: it has a default value at row/item level
 
922
    void SetData(            wxTreeItemData *data) { m_props_row.m_data = data; };
 
923
    void SetData(int column, wxTreeItemData *data)
 
924
    {
 
925
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
926
        if (entry == m_props_cell.end()) {
 
927
            m_props_cell[column] = new wxTreeListItemCellAttr();
 
928
            m_props_cell[column]->m_data = data;
 
929
        } else {
 
930
            entry->second->m_data = data;
 
931
        }
 
932
    }
 
933
 
 
934
    void SetBold(            bool bold) { m_props_row.m_isBold = bold; }
 
935
    void SetBold(int column, bool bold)
 
936
    {
 
937
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
938
        if (entry == m_props_cell.end()) {
 
939
            m_props_cell[column] = new wxTreeListItemCellAttr();
 
940
            m_props_cell[column]->m_isBold = bold;
 
941
            m_props_cell[column]->m_isBoldSet = 1;
 
942
        } else {
 
943
            entry->second->m_isBold = bold;
 
944
            entry->second->m_isBoldSet = 1;
 
945
        }
 
946
    }
 
947
 
 
948
 
 
949
    void SetToolTip(const wxString &tip) {
 
950
        if (m_toolTip)  { delete m_toolTip; m_toolTip = NULL; }
 
951
        if (tip.length() > 0) { m_toolTip = new wxString(tip); }
 
952
    };
 
953
 
 
954
 
 
955
    // status inquiries
 
956
    // ----------------
 
957
    bool HasChildren() const        { return !m_children.IsEmpty(); }
 
958
    bool IsSelected()  const        { return m_hasHilight != 0; }
 
959
    bool IsExpanded()  const        { return !m_isCollapsed; }
 
960
    bool HasPlus()     const        { return m_hasPlus || HasChildren(); }
 
961
    bool IsBold()      const        { return m_props_row.m_isBold; }
 
962
    bool IsBold(int column) const
 
963
    {
 
964
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
965
        if (entry == m_props_cell.end() || ! entry->second->m_isBoldSet) return IsBold();
 
966
        return (entry->second->m_isBold != 0);
 
967
    }
 
968
    bool IsVirtual()   const        { return m_owner->IsVirtual(); }
 
969
 
 
970
 
 
971
 
 
972
    int GetX() const { return m_x; }
 
973
    int GetY() const { return m_y; }
 
974
 
 
975
    void SetX (int x) { m_x = x; }
 
976
    void SetY (int y) { m_y = y; }
 
977
 
 
978
    int  GetHeight() const { return m_height; }
 
979
    int  GetWidth()  const { return m_width; }
 
980
 
 
981
    void SetHeight (int height) { m_height = height; }
 
982
    void SetWidth (int width) { m_width = width; }
 
983
 
 
984
    int GetTextX() const { return m_text_x; }
 
985
    void SetTextX (int text_x) { m_text_x = text_x; }
 
986
 
 
987
    virtual wxTreeListItem *GetItemParent() const { return m_parent; }
 
988
 
 
989
    // get count of all children (and grand children if 'recursively')
 
990
    size_t GetChildrenCount(bool recursively = true) const;
 
991
 
 
992
    void GetSize( int &x, int &y, const wxTreeListMainWindow* );
 
993
 
 
994
    // return the item at given position (or NULL if no item), onButton is
 
995
    // true if the point belongs to the item's button, otherwise it lies
 
996
    // on the button's label
 
997
    wxTreeListItem *HitTest (const wxPoint& point,
 
998
                             const wxTreeListMainWindow *,
 
999
                             int &flags, int& column, int level);
 
1000
 
 
1001
 
 
1002
    // operations
 
1003
    // ----------
 
1004
    // deletes all children
 
1005
    void DeleteChildren();
 
1006
 
 
1007
    void Insert(wxTreeListItem *child, size_t index)
 
1008
    { m_children.Insert(child, index); }
 
1009
 
 
1010
    void Expand() { m_isCollapsed = false; }
 
1011
    void Collapse() { m_isCollapsed = true; }
 
1012
 
 
1013
    void SetHilight( bool set = true ) { m_hasHilight = set; }
 
1014
 
 
1015
 
 
1016
    // attributes
 
1017
    // ----------
 
1018
 
 
1019
    // get them - may be NULL (used to read attributes)
 
1020
    // NOTE: fall back on default at row/item level is not defined for cell
 
1021
    wxTreeItemAttr *GetAttributes(int column) const
 
1022
    {
 
1023
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
1024
        if (entry == m_props_cell.end()) return GetAttributes();
 
1025
        return entry->second->m_attr;
 
1026
    }
 
1027
    wxTreeItemAttr *GetAttributes() const { return m_props_row.m_attr; }
 
1028
 
 
1029
    // get them ensuring that the pointer is not NULL (used to write attributes)
 
1030
    wxTreeItemAttr& Attr(int column) {
 
1031
        wxTreeListItemCellAttrHash::const_iterator entry = m_props_cell.find( column );
 
1032
        if (entry == m_props_cell.end()) {
 
1033
            m_props_cell[column] = new wxTreeListItemCellAttr();
 
1034
            m_props_cell[column]->m_attr = new wxTreeItemAttr;
 
1035
            m_props_cell[column]->m_ownsAttr = 1;
 
1036
            return *(m_props_cell[column]->m_attr);
 
1037
        } else {
 
1038
            return *(entry->second->m_attr);
 
1039
        }
 
1040
    }
 
1041
    wxTreeItemAttr& Attr()
 
1042
    {
 
1043
        if ( !m_props_row.m_attr )
 
1044
        {
 
1045
            m_props_row.m_attr = new wxTreeItemAttr;
 
1046
            m_props_row.m_ownsAttr = 1;
 
1047
        }
 
1048
        return *m_props_row.m_attr;
 
1049
    }
 
1050
/* ----- unused -----
 
1051
    // set them
 
1052
    void SetAttributes(wxTreeItemAttr *attr)
 
1053
    {
 
1054
        if ( m_props_row.m_ownsAttr ) delete m_props_row.m_attr;
 
1055
        m_props_row.m_attr = attr;
 
1056
        m_props_row.m_ownsAttr = 0;
 
1057
    }
 
1058
    // set them and delete when done
 
1059
    void AssignAttributes(wxTreeItemAttr *attr)
 
1060
    {
 
1061
        SetAttributes(attr);
 
1062
        m_props_row.m_ownsAttr = 1;
 
1063
    }
 
1064
*/
 
1065
 
 
1066
private:
 
1067
    wxTreeListMainWindow       *m_owner;        // control the item belongs to
 
1068
 
 
1069
    wxArrayTreeListItems        m_children;     // list of children
 
1070
    wxTreeListItem             *m_parent;       // parent of this item
 
1071
 
 
1072
    // main column item positions
 
1073
    wxCoord                     m_x;            // (virtual) offset from left (vertical line)
 
1074
    wxCoord                     m_y;            // (virtual) offset from top
 
1075
    wxCoord                     m_text_x;       // item offset from left
 
1076
    short                       m_width;        // width of this item
 
1077
    unsigned char               m_height;       // height of this item
 
1078
 
 
1079
    // for the normal, selected, expanded and expanded+selected states
 
1080
    short                       m_images[wxTreeItemIcon_Max];
 
1081
    // currently there is no tooltip at cell level
 
1082
    wxString                   *m_toolTip;
 
1083
 
 
1084
    // use bitfields to save size
 
1085
    int                         m_isCollapsed :1;
 
1086
    int                         m_hasHilight  :1; // same as focused
 
1087
    int                         m_hasPlus     :1; // used for item which doesn't have
 
1088
                                                    // children but has a [+] button
 
1089
 
 
1090
    // here are all the properties which can be set per column
 
1091
    wxArrayString               m_text;        // labels to be rendered for item
 
1092
    wxTreeListItemCellAttr      m_props_row;   // default at row/item level for: data, attr
 
1093
    wxTreeListItemCellAttrHash  m_props_cell;
 
1094
};
 
1095
 
 
1096
 
 
1097
// ===========================================================================
 
1098
// implementation
 
1099
// ===========================================================================
 
1100
 
 
1101
// ---------------------------------------------------------------------------
 
1102
// wxTreeListRenameTimer (internal)
 
1103
// ---------------------------------------------------------------------------
 
1104
 
 
1105
wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow *owner )
 
1106
{
 
1107
    m_owner = owner;
 
1108
}
 
1109
 
 
1110
void wxTreeListRenameTimer::Notify()
 
1111
{
 
1112
    m_owner->OnRenameTimer();
 
1113
}
 
1114
 
 
1115
//-----------------------------------------------------------------------------
 
1116
// wxEditTextCtrl (internal)
 
1117
//-----------------------------------------------------------------------------
 
1118
 
 
1119
BEGIN_EVENT_TABLE (wxEditTextCtrl,wxTextCtrl)
 
1120
    EVT_KEY_DOWN           (wxEditTextCtrl::OnChar)
 
1121
    EVT_KEY_UP         (wxEditTextCtrl::OnKeyUp)
 
1122
    EVT_KILL_FOCUS     (wxEditTextCtrl::OnKillFocus)
 
1123
END_EVENT_TABLE()
 
1124
 
 
1125
wxEditTextCtrl::wxEditTextCtrl (wxWindow *parent,
 
1126
                                const wxWindowID id,
 
1127
                                bool *accept,
 
1128
                                wxString *res,
 
1129
                                wxTreeListMainWindow *owner,
 
1130
                                const wxString &value,
 
1131
                                const wxPoint &pos,
 
1132
                                const wxSize &size,
 
1133
                                int style,
 
1134
                                const wxValidator& validator,
 
1135
                                const wxString &name)
 
1136
    : wxTextCtrl (parent, id, value, pos, size, style | wxSIMPLE_BORDER, validator, name)
 
1137
{
 
1138
    m_res = res;
 
1139
    m_accept = accept;
 
1140
    m_owner = owner;
 
1141
    (*m_accept) = false;
 
1142
    (*m_res) = wxEmptyString;
 
1143
    m_startValue = value;
 
1144
    m_finished = false;
 
1145
}
 
1146
 
 
1147
wxEditTextCtrl::~wxEditTextCtrl() {
 
1148
    EndEdit(true); // cancelled
 
1149
}
 
1150
 
 
1151
void wxEditTextCtrl::EndEdit(bool isCancelled) {
 
1152
    if (m_finished) return;
 
1153
    m_finished = true;
 
1154
 
 
1155
    if (m_owner) {
 
1156
        (*m_accept) = ! isCancelled;
 
1157
        (*m_res) = isCancelled ? m_startValue : GetValue();
 
1158
        m_owner->OnRenameAccept(*m_res == m_startValue);
 
1159
        m_owner->m_editControl = NULL;
 
1160
        m_owner->m_editItem = NULL;
 
1161
        m_owner->SetFocus(); // This doesn't work. TODO.
 
1162
        m_owner = NULL;
 
1163
    }
 
1164
 
 
1165
    Destroy();
 
1166
}
 
1167
 
 
1168
bool wxEditTextCtrl::Destroy() {
 
1169
    Hide();
 
1170
    wxTheApp->GetTraits()->ScheduleForDestroy(this);
 
1171
    return true;
 
1172
}
 
1173
 
 
1174
void wxEditTextCtrl::OnChar( wxKeyEvent &event )
 
1175
{
 
1176
    if (m_finished)
 
1177
    {
 
1178
        event.Skip();
 
1179
        return;
 
1180
    }
 
1181
    if (event.GetKeyCode() == WXK_RETURN)
 
1182
    {
 
1183
        EndEdit(false);  // not cancelled
 
1184
        return;
 
1185
    }
 
1186
    if (event.GetKeyCode() == WXK_ESCAPE)
 
1187
    {
 
1188
        EndEdit(true);  // cancelled
 
1189
        return;
 
1190
    }
 
1191
    event.Skip();
 
1192
}
 
1193
 
 
1194
void wxEditTextCtrl::OnKeyUp( wxKeyEvent &event )
 
1195
{
 
1196
    if (m_finished)
 
1197
    {
 
1198
        event.Skip();
 
1199
        return;
 
1200
    }
 
1201
 
 
1202
    // auto-grow the textctrl:
 
1203
    wxSize parentSize = m_owner->GetSize();
 
1204
    wxPoint myPos = GetPosition();
 
1205
    wxSize mySize = GetSize();
 
1206
    int sx, sy;
 
1207
    GetTextExtent(GetValue() + _T("M"), &sx, &sy);
 
1208
    if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x;
 
1209
    if (mySize.x > sx) sx = mySize.x;
 
1210
    SetSize(sx, -1);
 
1211
 
 
1212
    event.Skip();
 
1213
}
 
1214
 
 
1215
void wxEditTextCtrl::OnKillFocus( wxFocusEvent &event )
 
1216
{
 
1217
    if (m_finished)
 
1218
    {
 
1219
        event.Skip();
 
1220
        return;
 
1221
    }
 
1222
 
 
1223
    EndEdit(false);  // not cancelled
 
1224
}
 
1225
 
 
1226
//-----------------------------------------------------------------------------
 
1227
//  wxTreeListHeaderWindow
 
1228
//-----------------------------------------------------------------------------
 
1229
 
 
1230
IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow,wxWindow);
 
1231
 
 
1232
BEGIN_EVENT_TABLE(wxTreeListHeaderWindow,wxWindow)
 
1233
    EVT_PAINT         (wxTreeListHeaderWindow::OnPaint)
 
1234
    EVT_ERASE_BACKGROUND(wxTreeListHeaderWindow::OnEraseBackground) // reduce flicker
 
1235
    EVT_MOUSE_EVENTS  (wxTreeListHeaderWindow::OnMouse)
 
1236
    EVT_SET_FOCUS     (wxTreeListHeaderWindow::OnSetFocus)
 
1237
END_EVENT_TABLE()
 
1238
 
 
1239
 
 
1240
void wxTreeListHeaderWindow::Init()
 
1241
{
 
1242
    m_currentCursor = (wxCursor *) NULL;
 
1243
    m_isDragging = false;
 
1244
    m_dirty = false;
 
1245
    m_total_col_width = 0;
 
1246
#if wxCHECK_VERSION_FULL(2, 7, 0, 1)
 
1247
    m_hotTrackCol = -1;
 
1248
#endif
 
1249
 
 
1250
    // prevent any background repaint in order to reducing flicker
 
1251
    SetBackgroundStyle(wxBG_STYLE_CUSTOM);
 
1252
}
 
1253
 
 
1254
wxTreeListHeaderWindow::wxTreeListHeaderWindow()
 
1255
{
 
1256
    Init();
 
1257
 
 
1258
    m_owner = (wxTreeListMainWindow *) NULL;
 
1259
    m_resizeCursor = (wxCursor *) NULL;
 
1260
}
 
1261
 
 
1262
wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow *win,
 
1263
                                                wxWindowID id,
 
1264
                                                wxTreeListMainWindow *owner,
 
1265
                                                const wxPoint& pos,
 
1266
                                                const wxSize& size,
 
1267
                                                long style,
 
1268
                                                const wxString &name )
 
1269
    : wxWindow( win, id, pos, size, style, name )
 
1270
{
 
1271
    Init();
 
1272
 
 
1273
    m_owner = owner;
 
1274
    m_resizeCursor = new wxCursor(wxCURSOR_SIZEWE);
 
1275
 
 
1276
#if !wxCHECK_VERSION(2, 5, 0)
 
1277
    SetBackgroundColour (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_BTNFACE));
 
1278
#else
 
1279
    SetBackgroundColour (wxSystemSettings::GetColour (wxSYS_COLOUR_BTNFACE));
 
1280
#endif
 
1281
}
 
1282
 
 
1283
wxTreeListHeaderWindow::~wxTreeListHeaderWindow()
 
1284
{
 
1285
    delete m_resizeCursor;
 
1286
}
 
1287
 
 
1288
void wxTreeListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
 
1289
{
 
1290
#if !wxCHECK_VERSION(2, 5, 0)
 
1291
    wxPen pen (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID);
 
1292
#else
 
1293
    wxPen pen (wxSystemSettings::GetColour (wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID);
 
1294
#endif
 
1295
 
 
1296
    const int m_corner = 1;
 
1297
 
 
1298
    dc->SetBrush( *wxTRANSPARENT_BRUSH );
 
1299
#if defined( __WXMAC__  )
 
1300
    dc->SetPen (pen);
 
1301
#else // !GTK, !Mac
 
1302
    dc->SetPen( *wxBLACK_PEN );
 
1303
#endif
 
1304
    dc->DrawLine( x+w-m_corner+1, y, x+w, y+h );  // right (outer)
 
1305
    dc->DrawRectangle( x, y+h, w+1, 1 );          // bottom (outer)
 
1306
 
 
1307
#if defined( __WXMAC__  )
 
1308
    pen = wxPen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
 
1309
#endif
 
1310
    dc->SetPen( pen );
 
1311
    dc->DrawLine( x+w-m_corner, y, x+w-1, y+h );  // right (inner)
 
1312
    dc->DrawRectangle( x+1, y+h-1, w-2, 1 );      // bottom (inner)
 
1313
 
 
1314
    dc->SetPen( *wxWHITE_PEN );
 
1315
    dc->DrawRectangle( x, y, w-m_corner+1, 1 );   // top (outer)
 
1316
    dc->DrawRectangle( x, y, 1, h );              // left (outer)
 
1317
    dc->DrawLine( x, y+h-1, x+1, y+h-1 );
 
1318
    dc->DrawLine( x+w-1, y, x+w-1, y+1 );
 
1319
}
 
1320
 
 
1321
// shift the DC origin to match the position of the main window horz
 
1322
// scrollbar: this allows us to always use logical coords
 
1323
void wxTreeListHeaderWindow::AdjustDC(wxDC& dc)
 
1324
{
 
1325
    int xpix;
 
1326
    m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
 
1327
    int x;
 
1328
    m_owner->GetViewStart( &x, NULL );
 
1329
 
 
1330
    // account for the horz scrollbar offset
 
1331
    dc.SetDeviceOrigin( -x * xpix, 0 );
 
1332
}
 
1333
 
 
1334
void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
1335
{
 
1336
    wxAutoBufferedPaintDC dc( this );
 
1337
    AdjustDC( dc );
 
1338
 
 
1339
    int x = HEADER_OFFSET_X;
 
1340
 
 
1341
    // width and height of the entire header window
 
1342
    int w, h;
 
1343
    GetClientSize( &w, &h );
 
1344
    m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
 
1345
    dc.SetBackgroundMode(wxTRANSPARENT);
 
1346
 
 
1347
#if wxCHECK_VERSION_FULL(2, 7, 0, 1)
 
1348
    int numColumns = GetColumnCount();
 
1349
    for ( int i = 0; i < numColumns && x < w; i++ )
 
1350
    {
 
1351
        if (!IsColumnShown (i)) continue; // do next column if not shown
 
1352
 
 
1353
        wxHeaderButtonParams params;
 
1354
 
 
1355
        // TODO: columnInfo should have label colours...
 
1356
        params.m_labelColour = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
 
1357
        params.m_labelFont = GetFont();
 
1358
 
 
1359
        wxTreeListColumnInfo& column = GetColumn(i);
 
1360
        int wCol = column.GetWidth();
 
1361
        int flags = 0;
 
1362
        wxRect rect(x, 0, wCol, h);
 
1363
        x += wCol;
 
1364
 
 
1365
        if ( i == m_hotTrackCol)
 
1366
            flags |= wxCONTROL_CURRENT;
 
1367
 
 
1368
        params.m_labelText = column.GetText();
 
1369
        params.m_labelAlignment = column.GetAlignment();
 
1370
 
 
1371
        int image = column.GetImage();
 
1372
        wxImageList* imageList = m_owner->GetImageList();
 
1373
        if ((image != -1) && imageList)
 
1374
            params.m_labelBitmap = imageList->GetBitmap(image);
 
1375
 
 
1376
        wxRendererNative::Get().DrawHeaderButton(this, dc, rect, flags, wxHDR_SORT_ICON_NONE, &params);
 
1377
    }
 
1378
 
 
1379
    if (x < w) {
 
1380
        wxRect rect(x, 0, w-x, h);
 
1381
        wxRendererNative::Get().DrawHeaderButton(this, dc, rect);
 
1382
    }
 
1383
 
 
1384
#else  // not 2.7.0.1+
 
1385
 
 
1386
    dc.SetFont( GetFont() );
 
1387
 
 
1388
    // do *not* use the listctrl colour for headers - one day we will have a
 
1389
    // function to set it separately
 
1390
    //dc.SetTextForeground( *wxBLACK );
 
1391
#if !wxCHECK_VERSION(2, 5, 0)
 
1392
    dc.SetTextForeground (wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT ));
 
1393
#else
 
1394
    dc.SetTextForeground (wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ));
 
1395
#endif
 
1396
 
 
1397
    int numColumns = GetColumnCount();
 
1398
    for ( int i = 0; i < numColumns && x < w; i++ )
 
1399
    {
 
1400
        if (!IsColumnShown (i)) continue; // do next column if not shown
 
1401
 
 
1402
        wxTreeListColumnInfo& column = GetColumn(i);
 
1403
        int wCol = column.GetWidth();
 
1404
 
 
1405
        // the width of the rect to draw: make it smaller to fit entirely
 
1406
        // inside the column rect
 
1407
        int cw = wCol - 2;
 
1408
 
 
1409
#if !wxCHECK_VERSION(2, 7, 0)
 
1410
        dc.SetPen( *wxWHITE_PEN );
 
1411
        DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
 
1412
#else
 
1413
        wxRect rect(x, HEADER_OFFSET_Y, cw, h-2);
 
1414
        wxRendererNative::GetDefault().DrawHeaderButton (this, dc, rect);
 
1415
#endif
 
1416
 
 
1417
        // if we have an image, draw it on the right of the label
 
1418
        int image = column.GetImage(); //item.m_image;
 
1419
        int ix = -2, iy = 0;
 
1420
        wxImageList* imageList = m_owner->GetImageList();
 
1421
        if ((image != -1) && imageList) {
 
1422
            imageList->GetSize (image, ix, iy);
 
1423
        }
 
1424
 
 
1425
        // extra margins around the text label
 
1426
        int text_width = 0;
 
1427
        int text_x = x;
 
1428
        int image_offset = cw - ix - 1;
 
1429
 
 
1430
        switch(column.GetAlignment()) {
 
1431
        case wxALIGN_LEFT:
 
1432
            text_x += EXTRA_WIDTH;
 
1433
            cw -= ix + 2;
 
1434
            break;
 
1435
        case wxALIGN_RIGHT:
 
1436
            dc.GetTextExtent (column.GetText(), &text_width, NULL);
 
1437
            text_x += cw - text_width - EXTRA_WIDTH - MARGIN;
 
1438
            image_offset = 0;
 
1439
            break;
 
1440
        case wxALIGN_CENTER:
 
1441
            dc.GetTextExtent(column.GetText(), &text_width, NULL);
 
1442
            text_x += (cw - text_width)/2 + ix + 2;
 
1443
            image_offset = (cw - text_width - ix - 2)/2 - MARGIN;
 
1444
            break;
 
1445
        }
 
1446
 
 
1447
        // draw the image
 
1448
        if ((image != -1) && imageList) {
 
1449
            imageList->Draw (image, dc, x + image_offset/*cw - ix - 1*/,
 
1450
                             HEADER_OFFSET_Y + (h - 4 - iy)/2,
 
1451
                             wxIMAGELIST_DRAW_TRANSPARENT);
 
1452
        }
 
1453
 
 
1454
        // draw the text clipping it so that it doesn't overwrite the column boundary
 
1455
        wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
 
1456
        dc.DrawText (column.GetText(), text_x, HEADER_OFFSET_Y + EXTRA_HEIGHT );
 
1457
 
 
1458
        // next column
 
1459
        x += wCol;
 
1460
    }
 
1461
 
 
1462
    int more_w = m_owner->GetSize().x - x - HEADER_OFFSET_X;
 
1463
    if (more_w > 0) {
 
1464
#if !wxCHECK_VERSION(2, 7, 0)
 
1465
        DoDrawRect (&dc, x, HEADER_OFFSET_Y, more_w, h-2 );
 
1466
#else
 
1467
        wxRect rect (x, HEADER_OFFSET_Y, more_w, h-2);
 
1468
        wxRendererNative::GetDefault().DrawHeaderButton (this, dc, rect);
 
1469
#endif
 
1470
    }
 
1471
 
 
1472
#endif // 2.7.0.1
 
1473
}
 
1474
 
 
1475
void wxTreeListHeaderWindow::DrawCurrent()
 
1476
{
 
1477
    int x1 = m_currentX;
 
1478
    int y1 = 0;
 
1479
    ClientToScreen (&x1, &y1);
 
1480
 
 
1481
    int x2 = m_currentX-1;
 
1482
#ifdef __WXMSW__
 
1483
    ++x2; // but why ????
 
1484
#endif
 
1485
    int y2 = 0;
 
1486
    m_owner->GetClientSize( NULL, &y2 );
 
1487
    m_owner->ClientToScreen( &x2, &y2 );
 
1488
 
 
1489
    wxScreenDC dc;
 
1490
    dc.SetLogicalFunction (wxINVERT);
 
1491
    dc.SetPen (wxPen (*wxBLACK, 2, wxSOLID));
 
1492
    dc.SetBrush (*wxTRANSPARENT_BRUSH);
 
1493
 
 
1494
    AdjustDC(dc);
 
1495
    dc.DrawLine (x1, y1, x2, y2);
 
1496
    dc.SetLogicalFunction (wxCOPY);
 
1497
    dc.SetPen (wxNullPen);
 
1498
    dc.SetBrush (wxNullBrush);
 
1499
}
 
1500
 
 
1501
#if wxCHECK_VERSION_FULL(2, 7, 0, 1)
 
1502
int wxTreeListHeaderWindow::XToCol(int x)
 
1503
{
 
1504
    int colLeft = 0;
 
1505
    int numColumns = GetColumnCount();
 
1506
    for ( int col = 0; col < numColumns; col++ )
 
1507
    {
 
1508
        if (!IsColumnShown(col)) continue;
 
1509
        wxTreeListColumnInfo& column = GetColumn(col);
 
1510
 
 
1511
        if ( x < (colLeft + column.GetWidth()) )
 
1512
             return col;
 
1513
 
 
1514
        colLeft += column.GetWidth();
 
1515
    }
 
1516
    return -1;
 
1517
}
 
1518
 
 
1519
void wxTreeListHeaderWindow::RefreshColLabel(int col)
 
1520
{
 
1521
    if ( col > GetColumnCount() )
 
1522
        return;
 
1523
 
 
1524
    int x = 0;
 
1525
    int width = 0;
 
1526
    int idx = 0;
 
1527
    do {
 
1528
        if (!IsColumnShown(idx)) continue;
 
1529
        wxTreeListColumnInfo& column = GetColumn(idx);
 
1530
        x += width;
 
1531
        width = column.GetWidth();
 
1532
    } while (++idx <= col);
 
1533
 
 
1534
    m_owner->CalcScrolledPosition(x, 0, &x, NULL);
 
1535
    RefreshRect(wxRect(x, 0, width, GetSize().GetHeight()));
 
1536
}
 
1537
#endif
 
1538
 
 
1539
void wxTreeListHeaderWindow::OnMouse (wxMouseEvent &event) {
 
1540
 
 
1541
    // we want to work with logical coords
 
1542
    int x;
 
1543
    m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
 
1544
 
 
1545
#if wxCHECK_VERSION_FULL(2, 7, 0, 1)
 
1546
    if ( event.Moving() )
 
1547
    {
 
1548
        int col = XToCol(x);
 
1549
        if ( col != m_hotTrackCol )
 
1550
        {
 
1551
            // Refresh the col header so it will be painted with hot tracking
 
1552
            // (if supported by the native renderer.)
 
1553
            RefreshColLabel(col);
 
1554
 
 
1555
            // Also refresh the old hot header
 
1556
            if ( m_hotTrackCol >= 0 )
 
1557
                RefreshColLabel(m_hotTrackCol);
 
1558
 
 
1559
            m_hotTrackCol = col;
 
1560
        }
 
1561
    }
 
1562
 
 
1563
    if ( event.Leaving() && m_hotTrackCol >= 0 )
 
1564
    {
 
1565
        // Leaving the window so clear any hot tracking indicator that may be present
 
1566
        RefreshColLabel(m_hotTrackCol);
 
1567
        m_hotTrackCol = -1;
 
1568
    }
 
1569
#endif
 
1570
 
 
1571
    if (m_isDragging) {
 
1572
 
 
1573
        SendListEvent (wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition());
 
1574
 
 
1575
        // we don't draw the line beyond our window, but we allow dragging it
 
1576
        // there
 
1577
        int w = 0;
 
1578
        GetClientSize( &w, NULL );
 
1579
        m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
 
1580
        w -= 6;
 
1581
 
 
1582
        // erase the line if it was drawn
 
1583
        if (m_currentX < w) DrawCurrent();
 
1584
 
 
1585
        if (event.ButtonUp()) {
 
1586
            m_isDragging = false;
 
1587
            if (HasCapture()) ReleaseMouse();
 
1588
            m_dirty = true;
 
1589
            SetColumnWidth (m_column, m_currentX - m_minX);
 
1590
            Refresh();
 
1591
            SendListEvent (wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition());
 
1592
        }else{
 
1593
            m_currentX = wxMax (m_minX + 7, x);
 
1594
 
 
1595
            // draw in the new location
 
1596
            if (m_currentX < w) DrawCurrent();
 
1597
        }
 
1598
 
 
1599
    }else{ // not dragging
 
1600
 
 
1601
        m_minX = 0;
 
1602
        bool hit_border = false;
 
1603
 
 
1604
        // end of the current column
 
1605
        int xpos = 0;
 
1606
 
 
1607
        // find the column where this event occured
 
1608
        int countCol = GetColumnCount();
 
1609
        for (int column = 0; column < countCol; column++) {
 
1610
            if (!IsColumnShown (column)) continue; // do next if not shown
 
1611
 
 
1612
            xpos += GetColumnWidth (column);
 
1613
            m_column = column;
 
1614
            if (abs (x-xpos) < 3) {
 
1615
                // near the column border
 
1616
                hit_border = true;
 
1617
                break;
 
1618
            }
 
1619
 
 
1620
            if (x < xpos) {
 
1621
                // inside the column
 
1622
                break;
 
1623
            }
 
1624
 
 
1625
            m_minX = xpos;
 
1626
        }
 
1627
 
 
1628
        if (event.LeftDown() || event.RightUp()) {
 
1629
            m_owner->EndEdit(true);  // cancelled
 
1630
 
 
1631
            if (hit_border && event.LeftDown()) {
 
1632
                m_isDragging = true;
 
1633
                CaptureMouse();
 
1634
                m_currentX = x;
 
1635
                DrawCurrent();
 
1636
                SendListEvent (wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, event.GetPosition());
 
1637
            }else{ // click on a column
 
1638
                wxEventType evt = event.LeftDown()? wxEVT_COMMAND_LIST_COL_CLICK:
 
1639
                                                    wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
 
1640
                SendListEvent (evt, event.GetPosition());
 
1641
            }
 
1642
        }else if (event.LeftDClick() && hit_border) {
 
1643
            SetColumnWidth (m_column, m_owner->GetBestColumnWidth (m_column));
 
1644
            Refresh();
 
1645
 
 
1646
        }else if (event.Moving()) {
 
1647
            bool setCursor;
 
1648
            if (hit_border) {
 
1649
                setCursor = m_currentCursor == wxSTANDARD_CURSOR;
 
1650
                m_currentCursor = m_resizeCursor;
 
1651
            }else{
 
1652
                setCursor = m_currentCursor != wxSTANDARD_CURSOR;
 
1653
                m_currentCursor = wxSTANDARD_CURSOR;
 
1654
            }
 
1655
            if (setCursor) SetCursor (*m_currentCursor);
 
1656
        }
 
1657
 
 
1658
    }
 
1659
}
 
1660
 
 
1661
void wxTreeListHeaderWindow::OnSetFocus (wxFocusEvent &WXUNUSED(event)) {
 
1662
    m_owner->SetFocus();
 
1663
}
 
1664
 
 
1665
void wxTreeListHeaderWindow::SendListEvent (wxEventType type, wxPoint pos) {
 
1666
    wxWindow *parent = GetParent();
 
1667
    wxListEvent le (type, parent->GetId());
 
1668
    le.SetEventObject (parent);
 
1669
    le.m_pointDrag = pos;
 
1670
 
 
1671
    // the position should be relative to the parent window, not
 
1672
    // this one for compatibility with MSW and common sense: the
 
1673
    // user code doesn't know anything at all about this header
 
1674
    // window, so why should it get positions relative to it?
 
1675
    le.m_pointDrag.y -= GetSize().y;
 
1676
    le.m_col = m_column;
 
1677
    parent->GetEventHandler()->ProcessEvent (le);
 
1678
}
 
1679
 
 
1680
void wxTreeListHeaderWindow::AddColumn (const wxTreeListColumnInfo& colInfo) {
 
1681
    m_columns.Add (colInfo);
 
1682
    m_total_col_width += colInfo.GetWidth();
 
1683
    m_owner->AdjustMyScrollbars();
 
1684
    m_owner->m_dirty = true;
 
1685
}
 
1686
 
 
1687
void wxTreeListHeaderWindow::SetColumnWidth (int column, int width) {
 
1688
    wxCHECK_RET ((column >= 0) && (column < GetColumnCount()), _T("Invalid column"));
 
1689
    m_total_col_width -= m_columns[column].GetWidth();
 
1690
    m_columns[column].SetWidth(width);
 
1691
    m_total_col_width += width;
 
1692
    m_owner->AdjustMyScrollbars();
 
1693
    m_owner->m_dirty = true;
 
1694
}
 
1695
 
 
1696
void wxTreeListHeaderWindow::InsertColumn (int before, const wxTreeListColumnInfo& colInfo) {
 
1697
    wxCHECK_RET ((before >= 0) && (before < GetColumnCount()), _T("Invalid column"));
 
1698
    m_columns.Insert (colInfo, before);
 
1699
    m_total_col_width += colInfo.GetWidth();
 
1700
    m_owner->AdjustMyScrollbars();
 
1701
    m_owner->m_dirty = true;
 
1702
}
 
1703
 
 
1704
void wxTreeListHeaderWindow::RemoveColumn (int column) {
 
1705
    wxCHECK_RET ((column >= 0) && (column < GetColumnCount()), _T("Invalid column"));
 
1706
    m_total_col_width -= m_columns[column].GetWidth();
 
1707
    m_columns.RemoveAt (column);
 
1708
    m_owner->AdjustMyScrollbars();
 
1709
    m_owner->m_dirty = true;
 
1710
}
 
1711
 
 
1712
void wxTreeListHeaderWindow::SetColumn (int column, const wxTreeListColumnInfo& info) {
 
1713
    wxCHECK_RET ((column >= 0) && (column < GetColumnCount()), _T("Invalid column"));
 
1714
    int w = m_columns[column].GetWidth();
 
1715
    m_columns[column] = info;
 
1716
    if (w != info.GetWidth()) {
 
1717
        m_total_col_width += info.GetWidth() - w;
 
1718
        m_owner->AdjustMyScrollbars();
 
1719
    }
 
1720
    m_owner->m_dirty = true;
 
1721
}
 
1722
 
 
1723
// ---------------------------------------------------------------------------
 
1724
// wxTreeListItem
 
1725
// ---------------------------------------------------------------------------
 
1726
 
 
1727
wxTreeListItem::wxTreeListItem (wxTreeListMainWindow *owner,
 
1728
                                wxTreeListItem *parent,
 
1729
                                const wxArrayString& text,
 
1730
                                int image, int selImage,
 
1731
                                wxTreeItemData *data)
 
1732
              : m_text (text) {
 
1733
 
 
1734
    m_images[wxTreeItemIcon_Normal] = image;
 
1735
    m_images[wxTreeItemIcon_Selected] = selImage;
 
1736
    m_images[wxTreeItemIcon_Expanded] = NO_IMAGE;
 
1737
    m_images[wxTreeItemIcon_SelectedExpanded] = NO_IMAGE;
 
1738
 
 
1739
    m_props_row.m_data = data;
 
1740
    m_toolTip = NULL;
 
1741
    m_x = 0;
 
1742
    m_y = 0;
 
1743
    m_text_x = 0;
 
1744
 
 
1745
    m_isCollapsed = true;
 
1746
    m_hasHilight = false;
 
1747
    m_hasPlus = false;
 
1748
 
 
1749
    m_owner = owner;
 
1750
    m_parent = parent;
 
1751
 
 
1752
    // We don't know the height here yet.
 
1753
    m_width = 0;
 
1754
    m_height = 0;
 
1755
}
 
1756
 
 
1757
wxTreeListItem::~wxTreeListItem() {
 
1758
    if (m_toolTip) delete m_toolTip;
 
1759
 
 
1760
    wxTreeListItemCellAttrHash::iterator entry = m_props_cell.begin();
 
1761
    while (entry != m_props_cell.end()) {
 
1762
        if (entry->second) delete entry->second;
 
1763
        entry++;
 
1764
    }
 
1765
 
 
1766
    wxASSERT_MSG( m_children.IsEmpty(), _T("please call DeleteChildren() before destructor"));
 
1767
}
 
1768
 
 
1769
void wxTreeListItem::DeleteChildren () {
 
1770
    m_children.Empty();
 
1771
}
 
1772
 
 
1773
size_t wxTreeListItem::GetChildrenCount (bool recursively) const {
 
1774
    size_t count = m_children.Count();
 
1775
    if (!recursively) return count;
 
1776
 
 
1777
    size_t total = count;
 
1778
    for (size_t n = 0; n < count; ++n) {
 
1779
        total += m_children[n]->GetChildrenCount();
 
1780
    }
 
1781
    return total;
 
1782
}
 
1783
 
 
1784
void wxTreeListItem::GetSize (int &x, int &y, const wxTreeListMainWindow *theButton) {
 
1785
    int bottomY = m_y + theButton->GetLineHeight (this);
 
1786
    if (y < bottomY) y = bottomY;
 
1787
    int width = m_x +  m_width;
 
1788
    if ( x < width ) x = width;
 
1789
 
 
1790
    if (IsExpanded()) {
 
1791
        size_t count = m_children.Count();
 
1792
        for (size_t n = 0; n < count; ++n ) {
 
1793
            m_children[n]->GetSize (x, y, theButton);
 
1794
        }
 
1795
    }
 
1796
}
 
1797
 
 
1798
wxTreeListItem *wxTreeListItem::HitTest (const wxPoint& point,
 
1799
                                         const wxTreeListMainWindow *theCtrl,
 
1800
                                         int &flags, int& column, int level) {
 
1801
 
 
1802
    // reset any previous hit infos
 
1803
    flags = 0;
 
1804
    column = -1;
 
1805
 
 
1806
    // for a hidden root node, don't evaluate it, but do evaluate children
 
1807
    if (!theCtrl->HasFlag(wxTR_HIDE_ROOT) || (level > 0)) {
 
1808
 
 
1809
        wxTreeListHeaderWindow* header_win = theCtrl->m_owner->GetHeaderWindow();
 
1810
 
 
1811
        // check for right of all columns (outside)
 
1812
        if (point.x > header_win->GetWidth()) return (wxTreeListItem*) NULL;
 
1813
        // else find column
 
1814
        for (int x = 0, j = 0; j < theCtrl->GetColumnCount(); ++j) {
 
1815
            if (!header_win->IsColumnShown(j)) continue;
 
1816
            int w = header_win->GetColumnWidth (j);
 
1817
            if (point.x >= x && point.x < x+w) {
 
1818
                column = j;
 
1819
                break;
 
1820
            }
 
1821
            x += w;
 
1822
        }
 
1823
 
 
1824
        // evaluate if y-pos is okay
 
1825
        int h = theCtrl->GetLineHeight (this);
 
1826
        if ((point.y >= m_y) && (point.y <= m_y + h)) {
 
1827
 
 
1828
            // check for above/below middle
 
1829
            int y_mid = m_y + h/2;
 
1830
            if (point.y < y_mid) {
 
1831
                flags |= wxTREE_HITTEST_ONITEMUPPERPART;
 
1832
            }else{
 
1833
                flags |= wxTREE_HITTEST_ONITEMLOWERPART;
 
1834
            }
 
1835
 
 
1836
            // check for button hit
 
1837
            if (HasPlus() && theCtrl->HasButtons()) {
 
1838
                int bntX = m_x - theCtrl->m_btnWidth2;
 
1839
                int bntY = y_mid - theCtrl->m_btnHeight2;
 
1840
                if ((point.x >= bntX) && (point.x <= (bntX + theCtrl->m_btnWidth)) &&
 
1841
                    (point.y >= bntY) && (point.y <= (bntY + theCtrl->m_btnHeight))) {
 
1842
                    flags |= wxTREE_HITTEST_ONITEMBUTTON;
 
1843
                    return this;
 
1844
                }
 
1845
            }
 
1846
 
 
1847
            // check for image hit
 
1848
            if (theCtrl->m_imgWidth > 0) {
 
1849
                int imgX = m_text_x - theCtrl->m_imgWidth - MARGIN;
 
1850
                int imgY = y_mid - theCtrl->m_imgHeight2;
 
1851
                if ((point.x >= imgX) && (point.x <= (imgX + theCtrl->m_imgWidth)) &&
 
1852
                    (point.y >= imgY) && (point.y <= (imgY + theCtrl->m_imgHeight))) {
 
1853
                    flags |= wxTREE_HITTEST_ONITEMICON;
 
1854
                    return this;
 
1855
                }
 
1856
            }
 
1857
 
 
1858
            // check for label hit
 
1859
            if ((point.x >= m_text_x) && (point.x <= (m_text_x + m_width))) {
 
1860
                flags |= wxTREE_HITTEST_ONITEMLABEL;
 
1861
                return this;
 
1862
            }
 
1863
 
 
1864
            // check for indent hit after button and image hit
 
1865
            if (point.x < m_x) {
 
1866
                flags |= wxTREE_HITTEST_ONITEMINDENT;
 
1867
// Ronan, 2008.07.17: removed, not consistent               column = -1; // considered not belonging to main column
 
1868
                return this;
 
1869
            }
 
1870
 
 
1871
            // check for right of label
 
1872
            int end = 0;
 
1873
            for (int i = 0; i <= theCtrl->GetMainColumn(); ++i) end += header_win->GetColumnWidth (i);
 
1874
            if ((point.x > (m_text_x + m_width)) && (point.x <= end)) {
 
1875
                flags |= wxTREE_HITTEST_ONITEMRIGHT;
 
1876
// Ronan, 2008.07.17: removed, not consistent                column = -1; // considered not belonging to main column
 
1877
                return this;
 
1878
            }
 
1879
 
 
1880
            // else check for each column except main
 
1881
            if (column >= 0 && column != theCtrl->GetMainColumn()) {
 
1882
                flags |= wxTREE_HITTEST_ONITEMCOLUMN;
 
1883
                return this;
 
1884
            }
 
1885
 
 
1886
            // no special flag or column found
 
1887
            return this;
 
1888
 
 
1889
        }
 
1890
 
 
1891
        // if children not expanded, return no item
 
1892
        if (!IsExpanded()) return (wxTreeListItem*) NULL;
 
1893
    }
 
1894
 
 
1895
    // in any case evaluate children
 
1896
    wxTreeListItem *child;
 
1897
    size_t count = m_children.Count();
 
1898
    for (size_t n = 0; n < count; n++) {
 
1899
        child = m_children[n]->HitTest (point, theCtrl, flags, column, level+1);
 
1900
        if (child) return child;
 
1901
    }
 
1902
 
 
1903
    // not found
 
1904
    return (wxTreeListItem*) NULL;
 
1905
}
 
1906
 
 
1907
int wxTreeListItem::GetCurrentImage() const {
 
1908
    int image = NO_IMAGE;
 
1909
    if (IsExpanded()) {
 
1910
        if (IsSelected()) {
 
1911
            image = GetImage (wxTreeItemIcon_SelectedExpanded);
 
1912
        }else{
 
1913
            image = GetImage (wxTreeItemIcon_Expanded);
 
1914
        }
 
1915
    }else{ // not expanded
 
1916
        if (IsSelected()) {
 
1917
            image = GetImage (wxTreeItemIcon_Selected);
 
1918
        }else{
 
1919
            image = GetImage (wxTreeItemIcon_Normal);
 
1920
        }
 
1921
    }
 
1922
 
 
1923
    // maybe it doesn't have the specific image, try the default one instead
 
1924
    if (image == NO_IMAGE) image = GetImage();
 
1925
 
 
1926
    return image;
 
1927
}
 
1928
 
 
1929
// ---------------------------------------------------------------------------
 
1930
// wxTreeListMainWindow implementation
 
1931
// ---------------------------------------------------------------------------
 
1932
 
 
1933
IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow, wxScrolledWindow)
 
1934
 
 
1935
BEGIN_EVENT_TABLE(wxTreeListMainWindow, wxScrolledWindow)
 
1936
    EVT_PAINT          (wxTreeListMainWindow::OnPaint)
 
1937
    EVT_ERASE_BACKGROUND(wxTreeListMainWindow::OnEraseBackground) // to reduce flicker
 
1938
    EVT_MOUSE_EVENTS   (wxTreeListMainWindow::OnMouse)
 
1939
    EVT_KEY_DOWN           (wxTreeListMainWindow::OnChar)
 
1940
    EVT_SET_FOCUS      (wxTreeListMainWindow::OnSetFocus)
 
1941
    EVT_KILL_FOCUS     (wxTreeListMainWindow::OnKillFocus)
 
1942
    EVT_IDLE           (wxTreeListMainWindow::OnIdle)
 
1943
    EVT_SCROLLWIN      (wxTreeListMainWindow::OnScroll)
 
1944
    EVT_MOUSE_CAPTURE_LOST(wxTreeListMainWindow::OnCaptureLost)
 
1945
END_EVENT_TABLE()
 
1946
 
 
1947
 
 
1948
// ---------------------------------------------------------------------------
 
1949
// construction/destruction
 
1950
// ---------------------------------------------------------------------------
 
1951
 
 
1952
 
 
1953
void wxTreeListMainWindow::Init() {
 
1954
 
 
1955
    m_rootItem = (wxTreeListItem*)NULL;
 
1956
    m_curItem = (wxTreeListItem*)NULL;
 
1957
    m_shiftItem = (wxTreeListItem*)NULL;
 
1958
    m_editItem = (wxTreeListItem*)NULL;
 
1959
    m_selectItem = (wxTreeListItem*)NULL;
 
1960
 
 
1961
    m_curColumn = -1; // no current column
 
1962
 
 
1963
    m_hasFocus = false;
 
1964
    m_dirty = false;
 
1965
 
 
1966
    m_lineHeight = LINEHEIGHT;
 
1967
    m_indent = MININDENT; // min. indent
 
1968
    m_linespacing = 4;
 
1969
 
 
1970
#if !wxCHECK_VERSION(2, 5, 0)
 
1971
    m_hilightBrush = new wxBrush (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_HIGHLIGHT), wxSOLID);
 
1972
    m_hilightUnfocusedBrush = new wxBrush (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_BTNSHADOW), wxSOLID);
 
1973
#else
 
1974
    m_hilightBrush = new wxBrush (wxSystemSettings::GetColour (wxSYS_COLOUR_HIGHLIGHT), wxSOLID);
 
1975
    m_hilightUnfocusedBrush = new wxBrush (wxSystemSettings::GetColour (wxSYS_COLOUR_BTNSHADOW), wxSOLID);
 
1976
#endif
 
1977
 
 
1978
    m_imageListNormal = (wxImageList *) NULL;
 
1979
    m_imageListButtons = (wxImageList *) NULL;
 
1980
    m_imageListState = (wxImageList *) NULL;
 
1981
    m_ownsImageListNormal = m_ownsImageListButtons =
 
1982
    m_ownsImageListState = false;
 
1983
 
 
1984
    m_imgWidth = 0, m_imgWidth2 = 0;
 
1985
    m_imgHeight = 0, m_imgHeight2 = 0;
 
1986
    m_btnWidth = 0, m_btnWidth2 = 0;
 
1987
    m_btnHeight = 0, m_btnHeight2 = 0;
 
1988
 
 
1989
    m_isDragStarted = m_isDragging = false;
 
1990
    m_dragItem = NULL;
 
1991
    m_dragCol = -1;
 
1992
 
 
1993
    m_editTimer = new wxTreeListRenameTimer (this);
 
1994
    m_editControl = NULL;
 
1995
 
 
1996
    m_lastOnSame = false;
 
1997
    m_left_down_selection = false;
 
1998
 
 
1999
    m_findTimer = new wxTimer (this, -1);
 
2000
 
 
2001
#if defined( __WXMAC__ ) && defined(__WXMAC_CARBON__)
 
2002
    m_normalFont.MacCreateThemeFont (kThemeViewsFont);
 
2003
#else
 
2004
    m_normalFont = wxSystemSettings::GetFont (wxSYS_DEFAULT_GUI_FONT);
 
2005
#endif
 
2006
    m_boldFont = wxFont( m_normalFont.GetPointSize(),
 
2007
                         m_normalFont.GetFamily(),
 
2008
                         m_normalFont.GetStyle(),
 
2009
                         wxBOLD,
 
2010
                         m_normalFont.GetUnderlined(),
 
2011
                         m_normalFont.GetFaceName(),
 
2012
                         m_normalFont.GetEncoding());
 
2013
 
 
2014
    m_toolTip.clear();
 
2015
    m_toolTipItem = (wxTreeListItem *)-1;  // no tooltip displayed
 
2016
    m_isItemToolTip = false;  // so far no item-specific tooltip
 
2017
}
 
2018
 
 
2019
bool wxTreeListMainWindow::Create (wxTreeListCtrl *parent,
 
2020
                                   wxWindowID id,
 
2021
                                   const wxPoint& pos,
 
2022
                                   const wxSize& size,
 
2023
                                   long style,
 
2024
                                   const wxValidator &validator,
 
2025
                                   const wxString& name) {
 
2026
 
 
2027
#ifdef __WXMAC__
 
2028
    //if (style & wxTR_HAS_BUTTONS) style |= wxTR_MAC_BUTTONS;
 
2029
    if (style & wxTR_HAS_BUTTONS) style &= ~wxTR_HAS_BUTTONS;
 
2030
    style &= ~wxTR_LINES_AT_ROOT;
 
2031
    style |= wxTR_NO_LINES;
 
2032
 
 
2033
    int major,minor;
 
2034
    wxGetOsVersion( &major, &minor );
 
2035
    if (major < 10) style |= wxTR_ROW_LINES;
 
2036
#endif
 
2037
 
 
2038
    wxScrolledWindow::Create (parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name);
 
2039
 
 
2040
#if wxUSE_VALIDATORS
 
2041
    SetValidator(validator);
 
2042
#endif
 
2043
 
 
2044
#if !wxCHECK_VERSION(2, 5, 0)
 
2045
    SetBackgroundColour (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_LISTBOX));
 
2046
#else
 
2047
    SetBackgroundColour (wxSystemSettings::GetColour (wxSYS_COLOUR_LISTBOX));
 
2048
#endif
 
2049
    // prevent any background repaint in order to reducing flicker
 
2050
    SetBackgroundStyle(wxBG_STYLE_CUSTOM);
 
2051
 
 
2052
#ifdef __WXMSW__
 
2053
    {
 
2054
        int i, j;
 
2055
        wxBitmap bmp(8, 8);
 
2056
        wxMemoryDC bdc;
 
2057
        bdc.SelectObject(bmp);
 
2058
        bdc.SetPen(*wxGREY_PEN);
 
2059
        bdc.DrawRectangle(-1, -1, 10, 10);
 
2060
        for (i = 0; i < 8; i++) {
 
2061
            for (j = 0; j < 8; j++) {
 
2062
                if (!((i + j) & 1)) {
 
2063
                    bdc.DrawPoint(i, j);
 
2064
                }
 
2065
            }
 
2066
        }
 
2067
 
 
2068
        m_dottedPen = wxPen(bmp, 1);
 
2069
    }
 
2070
#else
 
2071
//?    m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT );  // too slow under XFree86
 
2072
    m_dottedPen = wxPen( _T("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK!
 
2073
#endif
 
2074
 
 
2075
    m_owner = parent;
 
2076
    m_main_column = 0;
 
2077
 
 
2078
    return true;
 
2079
}
 
2080
 
 
2081
wxTreeListMainWindow::~wxTreeListMainWindow() {
 
2082
    delete m_hilightBrush;
 
2083
    delete m_hilightUnfocusedBrush;
 
2084
 
 
2085
    delete m_editTimer;
 
2086
    delete m_findTimer;
 
2087
    if (m_ownsImageListNormal) delete m_imageListNormal;
 
2088
    if (m_ownsImageListState) delete m_imageListState;
 
2089
    if (m_ownsImageListButtons) delete m_imageListButtons;
 
2090
 
 
2091
    if (m_editControl) {
 
2092
        m_editControl->SetOwner(NULL);    // prevent control from calling us during delete
 
2093
        delete m_editControl;
 
2094
    }
 
2095
 
 
2096
    DeleteRoot();
 
2097
}
 
2098
 
 
2099
 
 
2100
//-----------------------------------------------------------------------------
 
2101
// accessors
 
2102
//-----------------------------------------------------------------------------
 
2103
 
 
2104
size_t wxTreeListMainWindow::GetCount() const {
 
2105
    return m_rootItem == NULL? 0: m_rootItem->GetChildrenCount();
 
2106
}
 
2107
 
 
2108
void wxTreeListMainWindow::SetIndent (unsigned int indent) {
 
2109
    m_indent = wxMax ((unsigned)MININDENT, indent);
 
2110
    m_dirty = true;
 
2111
}
 
2112
 
 
2113
void wxTreeListMainWindow::SetLineSpacing (unsigned int spacing) {
 
2114
    m_linespacing = spacing;
 
2115
    m_dirty = true;
 
2116
    CalculateLineHeight();
 
2117
}
 
2118
 
 
2119
size_t wxTreeListMainWindow::GetChildrenCount (const wxTreeItemId& item,
 
2120
                                               bool recursively) {
 
2121
    wxCHECK_MSG (item.IsOk(), 0u, _T("invalid tree item"));
 
2122
    return ((wxTreeListItem*)item.m_pItem)->GetChildrenCount (recursively);
 
2123
}
 
2124
 
 
2125
void wxTreeListMainWindow::SetWindowStyle (const long styles) {
 
2126
    // change to selection mode, reset selection
 
2127
    if ((styles ^ m_windowStyle) & wxTR_MULTIPLE) { UnselectAll(); }
 
2128
    // right now, just sets the styles.  Eventually, we may
 
2129
    // want to update the inherited styles, but right now
 
2130
    // none of the parents has updatable styles
 
2131
    m_windowStyle = styles;
 
2132
    m_dirty = true;
 
2133
}
 
2134
 
 
2135
void wxTreeListMainWindow::SetToolTip(const wxString& tip) {
 
2136
    m_isItemToolTip = false;
 
2137
    m_toolTip = tip;
 
2138
    m_toolTipItem = (wxTreeListItem *)-1;  // no tooltip displayed (force refresh)
 
2139
}
 
2140
void wxTreeListMainWindow::SetToolTip(wxToolTip *tip) {
 
2141
    m_isItemToolTip = false;
 
2142
    m_toolTip = (tip == NULL) ? wxString() : tip->GetTip();
 
2143
    m_toolTipItem = (wxTreeListItem *)-1;  // no tooltip displayed (force refresh)
 
2144
}
 
2145
 
 
2146
void wxTreeListMainWindow::SetItemToolTip(const wxTreeItemId& item, const wxString &tip) {
 
2147
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2148
    m_isItemToolTip = true;
 
2149
    ((wxTreeListItem*) item.m_pItem)->SetToolTip(tip);
 
2150
    m_toolTipItem = (wxTreeListItem *)-1;  // no tooltip displayed (force refresh)
 
2151
}
 
2152
 
 
2153
 
 
2154
//-----------------------------------------------------------------------------
 
2155
// functions to work with tree items
 
2156
//-----------------------------------------------------------------------------
 
2157
 
 
2158
int wxTreeListMainWindow::GetItemImage (const wxTreeItemId& item, int column, wxTreeItemIcon which) const {
 
2159
    wxCHECK_MSG (item.IsOk(), -1, _T("invalid tree item"));
 
2160
    return ((wxTreeListItem*) item.m_pItem)->GetImage (column, which);
 
2161
}
 
2162
 
 
2163
wxTreeItemData *wxTreeListMainWindow::GetItemData (const wxTreeItemId& item) const {
 
2164
    wxCHECK_MSG (item.IsOk(), NULL, _T("invalid tree item"));
 
2165
    return ((wxTreeListItem*) item.m_pItem)->GetData();
 
2166
}
 
2167
wxTreeItemData *wxTreeListMainWindow::GetItemData (const wxTreeItemId& item, int column) const {
 
2168
    wxCHECK_MSG (item.IsOk(), NULL, _T("invalid tree item"));
 
2169
    return ((wxTreeListItem*) item.m_pItem)->GetData(column);
 
2170
}
 
2171
 
 
2172
bool wxTreeListMainWindow::GetItemBold (const wxTreeItemId& item) const {
 
2173
    wxCHECK_MSG(item.IsOk(), false, _T("invalid tree item"));
 
2174
    return ((wxTreeListItem *)item.m_pItem)->IsBold();
 
2175
}
 
2176
bool wxTreeListMainWindow::GetItemBold (const wxTreeItemId& item, int column) const {
 
2177
    wxCHECK_MSG(item.IsOk(), false, _T("invalid tree item"));
 
2178
    return ((wxTreeListItem *)item.m_pItem)->IsBold(column);
 
2179
}
 
2180
 
 
2181
wxColour wxTreeListMainWindow::GetItemTextColour (const wxTreeItemId& item) const {
 
2182
    wxCHECK_MSG (item.IsOk(), wxNullColour, _T("invalid tree item"));
 
2183
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2184
    wxTreeItemAttr *attr = pItem->GetAttributes();
 
2185
    if (attr && attr->HasTextColour()) {
 
2186
        return attr->GetTextColour();
 
2187
    } else {
 
2188
        return GetForegroundColour();
 
2189
    }
 
2190
}
 
2191
wxColour wxTreeListMainWindow::GetItemTextColour (const wxTreeItemId& item, int column) const {
 
2192
    wxCHECK_MSG (item.IsOk(), wxNullColour, _T("invalid tree item"));
 
2193
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2194
    wxTreeItemAttr *attr = pItem->GetAttributes(column);
 
2195
    if (attr && attr->HasTextColour()) {
 
2196
        return attr->GetTextColour();
 
2197
    } else {
 
2198
        return GetItemTextColour(item);
 
2199
    }
 
2200
}
 
2201
 
 
2202
wxColour wxTreeListMainWindow::GetItemBackgroundColour (const wxTreeItemId& item) const {
 
2203
    wxCHECK_MSG (item.IsOk(), wxNullColour, _T("invalid tree item"));
 
2204
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2205
    wxTreeItemAttr *attr = pItem->GetAttributes();
 
2206
    if (attr && attr->HasBackgroundColour()) {
 
2207
        return attr->GetBackgroundColour();
 
2208
    } else {
 
2209
        return GetBackgroundColour();
 
2210
    }
 
2211
}
 
2212
wxColour wxTreeListMainWindow::GetItemBackgroundColour (const wxTreeItemId& item, int column) const {
 
2213
    wxCHECK_MSG (item.IsOk(), wxNullColour, _T("invalid tree item"));
 
2214
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2215
    wxTreeItemAttr *attr = pItem->GetAttributes(column);
 
2216
    if (attr && attr->HasBackgroundColour()) {
 
2217
        return attr->GetBackgroundColour();
 
2218
    } else {
 
2219
        return GetItemBackgroundColour(item);
 
2220
    }
 
2221
}
 
2222
 
 
2223
wxFont wxTreeListMainWindow::GetItemFont (const wxTreeItemId& item) const {
 
2224
    wxCHECK_MSG (item.IsOk(), wxNullFont, _T("invalid tree item"));
 
2225
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2226
    wxTreeItemAttr *attr = pItem->GetAttributes();
 
2227
    if (attr && attr->HasFont()) {
 
2228
        return attr->GetFont();
 
2229
    }else if (pItem->IsBold()) {
 
2230
        return m_boldFont;
 
2231
    } else {
 
2232
        return m_normalFont;
 
2233
    }
 
2234
}
 
2235
wxFont wxTreeListMainWindow::GetItemFont (const wxTreeItemId& item, int column) const {
 
2236
    wxCHECK_MSG (item.IsOk(), wxNullFont, _T("invalid tree item"));
 
2237
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2238
    wxTreeItemAttr *attr_cell = pItem->GetAttributes(column);
 
2239
    wxTreeItemAttr *attr_row = pItem->GetAttributes();
 
2240
    if (attr_cell && attr_cell->HasFont()) {
 
2241
        return attr_cell->GetFont();
 
2242
    } else if (attr_row && attr_row->HasFont()) {
 
2243
        return attr_row->GetFont();
 
2244
    } else if (pItem->IsBold(column)) {
 
2245
        return m_boldFont;
 
2246
    } else {
 
2247
        return m_normalFont;
 
2248
    }
 
2249
}
 
2250
 
 
2251
void wxTreeListMainWindow::SetItemHasChildren (const wxTreeItemId& item, bool has) {
 
2252
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2253
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2254
    pItem->SetHasPlus (has);
 
2255
    RefreshLine (pItem);
 
2256
}
 
2257
 
 
2258
void wxTreeListMainWindow::SetItemImage (const wxTreeItemId& item, int column, int image, wxTreeItemIcon which) {
 
2259
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2260
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2261
    pItem->SetImage (column, image, which);
 
2262
    wxClientDC dc (this);
 
2263
    CalculateSize (pItem, dc);
 
2264
    RefreshLine (pItem);
 
2265
}
 
2266
 
 
2267
void wxTreeListMainWindow::SetItemData (const wxTreeItemId& item,             wxTreeItemData *data) {
 
2268
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2269
    ((wxTreeListItem*) item.m_pItem)->SetData(data);
 
2270
}
 
2271
void wxTreeListMainWindow::SetItemData (const wxTreeItemId& item, int column, wxTreeItemData *data) {
 
2272
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2273
    ((wxTreeListItem*) item.m_pItem)->SetData(column, data);
 
2274
}
 
2275
 
 
2276
void wxTreeListMainWindow::SetItemBold (const wxTreeItemId& item,             bool bold) {
 
2277
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2278
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2279
    if (pItem->IsBold() != bold) { // avoid redrawing if no real change
 
2280
        pItem->SetBold (bold);
 
2281
        RefreshLine (pItem);
 
2282
    }
 
2283
}
 
2284
void wxTreeListMainWindow::SetItemBold (const wxTreeItemId& item, int column, bool bold) {
 
2285
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2286
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2287
//    if (pItem->IsBold(column) != bold) { // avoid redrawing if no real change
 
2288
        pItem->SetBold (column, bold);
 
2289
        RefreshLine (pItem);
 
2290
//    }
 
2291
}
 
2292
 
 
2293
void wxTreeListMainWindow::SetItemTextColour (const wxTreeItemId& item,             const wxColour& colour) {
 
2294
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2295
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2296
    pItem->Attr().SetTextColour (colour);
 
2297
    RefreshLine (pItem);
 
2298
}
 
2299
void wxTreeListMainWindow::SetItemTextColour (const wxTreeItemId& item, int column, const wxColour& colour) {
 
2300
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2301
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2302
    pItem->Attr(column).SetTextColour (colour);
 
2303
    RefreshLine (pItem);
 
2304
}
 
2305
 
 
2306
void wxTreeListMainWindow::SetItemBackgroundColour (const wxTreeItemId& item,             const wxColour& colour) {
 
2307
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2308
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2309
    pItem->Attr().SetBackgroundColour (colour);
 
2310
    RefreshLine (pItem);
 
2311
}
 
2312
void wxTreeListMainWindow::SetItemBackgroundColour (const wxTreeItemId& item, int column, const wxColour& colour) {
 
2313
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2314
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2315
    pItem->Attr(column).SetBackgroundColour (colour);
 
2316
    RefreshLine (pItem);
 
2317
}
 
2318
 
 
2319
void wxTreeListMainWindow::SetItemFont (const wxTreeItemId& item,             const wxFont& font) {
 
2320
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2321
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2322
    pItem->Attr().SetFont (font);
 
2323
    RefreshLine (pItem);
 
2324
}
 
2325
void wxTreeListMainWindow::SetItemFont (const wxTreeItemId& item, int column, const wxFont& font) {
 
2326
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2327
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2328
    pItem->Attr(column).SetFont (font);
 
2329
    RefreshLine (pItem);
 
2330
}
 
2331
 
 
2332
 
 
2333
bool wxTreeListMainWindow::SetFont (const wxFont &font) {
 
2334
    wxScrolledWindow::SetFont (font);
 
2335
    m_normalFont = font;
 
2336
    m_boldFont = wxFont (m_normalFont.GetPointSize(),
 
2337
                         m_normalFont.GetFamily(),
 
2338
                         m_normalFont.GetStyle(),
 
2339
                         wxBOLD,
 
2340
                         m_normalFont.GetUnderlined(),
 
2341
                         m_normalFont.GetFaceName());
 
2342
    CalculateLineHeight();
 
2343
    return true;
 
2344
}
 
2345
 
 
2346
 
 
2347
// ----------------------------------------------------------------------------
 
2348
// item status inquiries
 
2349
// ----------------------------------------------------------------------------
 
2350
 
 
2351
bool wxTreeListMainWindow::IsVisible (const wxTreeItemId& item, bool fullRow, bool within) const {
 
2352
    wxCHECK_MSG (item.IsOk(), false, _T("invalid tree item"));
 
2353
 
 
2354
    // An item is only visible if it's not a descendant of a collapsed item
 
2355
    wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem;
 
2356
    wxTreeListItem* parent = pItem->GetItemParent();
 
2357
    while (parent) {
 
2358
        if (parent == m_rootItem && HasFlag(wxTR_HIDE_ROOT)) break;
 
2359
        if (!parent->IsExpanded()) return false;
 
2360
        parent = parent->GetItemParent();
 
2361
    }
 
2362
 
 
2363
    // and the item is only visible if it is currently (fully) within the view
 
2364
    if (within) {
 
2365
        wxSize clientSize = GetClientSize();
 
2366
        wxRect rect;
 
2367
        if ((!GetBoundingRect (item, rect)) ||
 
2368
            ((!fullRow && rect.GetWidth() == 0) || rect.GetHeight() == 0) ||
 
2369
            (rect.GetTop() < 0 || rect.GetBottom() >= clientSize.y) ||
 
2370
            (!fullRow && (rect.GetLeft() < 0 || rect.GetRight() >= clientSize.x))) return false;
 
2371
    }
 
2372
 
 
2373
    return true;
 
2374
}
 
2375
 
 
2376
bool wxTreeListMainWindow::HasChildren (const wxTreeItemId& item) const {
 
2377
    wxCHECK_MSG (item.IsOk(), false, _T("invalid tree item"));
 
2378
 
 
2379
    // consider that the item does have children if it has the "+" button: it
 
2380
    // might not have them (if it had never been expanded yet) but then it
 
2381
    // could have them as well and it's better to err on this side rather than
 
2382
    // disabling some operations which are restricted to the items with
 
2383
    // children for an item which does have them
 
2384
    return ((wxTreeListItem*) item.m_pItem)->HasPlus();
 
2385
}
 
2386
 
 
2387
bool wxTreeListMainWindow::IsExpanded (const wxTreeItemId& item) const {
 
2388
    wxCHECK_MSG (item.IsOk(), false, _T("invalid tree item"));
 
2389
    return ((wxTreeListItem*) item.m_pItem)->IsExpanded();
 
2390
}
 
2391
 
 
2392
bool wxTreeListMainWindow::IsSelected (const wxTreeItemId& item) const {
 
2393
    wxCHECK_MSG (item.IsOk(), false, _T("invalid tree item"));
 
2394
    return ((wxTreeListItem*) item.m_pItem)->IsSelected();
 
2395
}
 
2396
 
 
2397
bool wxTreeListMainWindow::IsBold (const wxTreeItemId& item, int column) const {
 
2398
    wxCHECK_MSG (item.IsOk(), false, _T("invalid tree item"));
 
2399
    return ((wxTreeListItem*) item.m_pItem)->IsBold(column);
 
2400
}
 
2401
 
 
2402
// ----------------------------------------------------------------------------
 
2403
// navigation
 
2404
// ----------------------------------------------------------------------------
 
2405
 
 
2406
wxTreeItemId wxTreeListMainWindow::GetItemParent (const wxTreeItemId& item) const {
 
2407
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2408
    return ((wxTreeListItem*) item.m_pItem)->GetItemParent();
 
2409
}
 
2410
 
 
2411
#if !wxCHECK_VERSION(2, 5, 0)
 
2412
wxTreeItemId wxTreeListMainWindow::GetFirstChild (const wxTreeItemId& item,
 
2413
                                                  long& cookie) const {
 
2414
#else
 
2415
wxTreeItemId wxTreeListMainWindow::GetFirstChild (const wxTreeItemId& item,
 
2416
                                                  wxTreeItemIdValue& cookie) const {
 
2417
#endif
 
2418
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2419
    wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren();
 
2420
    cookie = 0;
 
2421
    return (!children.IsEmpty())? wxTreeItemId(children.Item(0)): wxTreeItemId();
 
2422
}
 
2423
 
 
2424
#if !wxCHECK_VERSION(2, 5, 0)
 
2425
wxTreeItemId wxTreeListMainWindow::GetNextChild (const wxTreeItemId& item,
 
2426
                                                 long& cookie) const {
 
2427
#else
 
2428
wxTreeItemId wxTreeListMainWindow::GetNextChild (const wxTreeItemId& item,
 
2429
                                                 wxTreeItemIdValue& cookie) const {
 
2430
#endif
 
2431
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2432
    wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren();
 
2433
    // it's ok to cast cookie to long, we never have indices which overflow "void*"
 
2434
    long *pIndex = ((long*)&cookie);
 
2435
    return ((*pIndex)+1 < (long)children.Count())? wxTreeItemId(children.Item(++(*pIndex))): wxTreeItemId();
 
2436
}
 
2437
 
 
2438
#if !wxCHECK_VERSION(2, 5, 0)
 
2439
wxTreeItemId wxTreeListMainWindow::GetPrevChild (const wxTreeItemId& item,
 
2440
                                                 long& cookie) const {
 
2441
#else
 
2442
wxTreeItemId wxTreeListMainWindow::GetPrevChild (const wxTreeItemId& item,
 
2443
                                                 wxTreeItemIdValue& cookie) const {
 
2444
#endif
 
2445
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2446
    wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren();
 
2447
    // it's ok to cast cookie to long, we never have indices which overflow "void*"
 
2448
    long *pIndex = (long*)&cookie;
 
2449
    return ((*pIndex)-1 >= 0)? wxTreeItemId(children.Item(--(*pIndex))): wxTreeItemId();
 
2450
}
 
2451
 
 
2452
#if !wxCHECK_VERSION(2, 5, 0)
 
2453
wxTreeItemId wxTreeListMainWindow::GetLastChild (const wxTreeItemId& item,
 
2454
                                                 long& cookie) const {
 
2455
#else
 
2456
wxTreeItemId wxTreeListMainWindow::GetLastChild (const wxTreeItemId& item,
 
2457
                                                 wxTreeItemIdValue& cookie) const {
 
2458
#endif
 
2459
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2460
    wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren();
 
2461
    // it's ok to cast cookie to long, we never have indices which overflow "void*"
 
2462
    long *pIndex = ((long*)&cookie);
 
2463
    (*pIndex) = (long)children.Count();
 
2464
    return (!children.IsEmpty())? wxTreeItemId(children.Last()): wxTreeItemId();
 
2465
}
 
2466
 
 
2467
wxTreeItemId wxTreeListMainWindow::GetNextSibling (const wxTreeItemId& item) const {
 
2468
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2469
 
 
2470
    // get parent
 
2471
    wxTreeListItem *i = (wxTreeListItem*) item.m_pItem;
 
2472
    wxTreeListItem *parent = i->GetItemParent();
 
2473
    if (!parent) return wxTreeItemId(); // root item doesn't have any siblings
 
2474
 
 
2475
    // get index
 
2476
    wxArrayTreeListItems& siblings = parent->GetChildren();
 
2477
    size_t index = siblings.Index (i);
 
2478
    wxASSERT (index != (size_t)wxNOT_FOUND); // I'm not a child of my parent?
 
2479
    return (index < siblings.Count()-1)? wxTreeItemId(siblings[index+1]): wxTreeItemId();
 
2480
}
 
2481
 
 
2482
wxTreeItemId wxTreeListMainWindow::GetPrevSibling (const wxTreeItemId& item) const {
 
2483
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2484
 
 
2485
    // get parent
 
2486
    wxTreeListItem *i = (wxTreeListItem*) item.m_pItem;
 
2487
    wxTreeListItem *parent = i->GetItemParent();
 
2488
    if (!parent) return wxTreeItemId(); // root item doesn't have any siblings
 
2489
 
 
2490
    // get index
 
2491
    wxArrayTreeListItems& siblings = parent->GetChildren();
 
2492
    size_t index = siblings.Index(i);
 
2493
    wxASSERT (index != (size_t)wxNOT_FOUND); // I'm not a child of my parent?
 
2494
    return (index >= 1)? wxTreeItemId(siblings[index-1]): wxTreeItemId();
 
2495
}
 
2496
 
 
2497
// Only for internal use right now, but should probably be public
 
2498
wxTreeItemId wxTreeListMainWindow::GetNext (const wxTreeItemId& item, bool fulltree) const {
 
2499
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2500
 
 
2501
    // if there are any children, return first child
 
2502
    if (fulltree || ((wxTreeListItem*)item.m_pItem)->IsExpanded()) {
 
2503
        wxArrayTreeListItems& children = ((wxTreeListItem*)item.m_pItem)->GetChildren();
 
2504
        if (children.GetCount() > 0) return children.Item (0);
 
2505
    }
 
2506
 
 
2507
    // get sibling of this item or of the ancestors instead
 
2508
    wxTreeItemId next;
 
2509
    wxTreeItemId parent = item;
 
2510
    do {
 
2511
        next = GetNextSibling (parent);
 
2512
        parent = GetItemParent (parent);
 
2513
    } while (!next.IsOk() && parent.IsOk());
 
2514
    return next;
 
2515
}
 
2516
 
 
2517
// Only for internal use right now, but should probably be public
 
2518
wxTreeItemId wxTreeListMainWindow::GetPrev (const wxTreeItemId& item, bool fulltree) const {
 
2519
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2520
 
 
2521
    // if there are no previous sibling get parent
 
2522
    wxTreeItemId prev = GetPrevSibling (item);
 
2523
    if (! prev.IsOk()) return GetItemParent (item);
 
2524
 
 
2525
    // while previous sibling has children, return last
 
2526
    while (fulltree || ((wxTreeListItem*)prev.m_pItem)->IsExpanded()) {
 
2527
        wxArrayTreeListItems& children = ((wxTreeListItem*)prev.m_pItem)->GetChildren();
 
2528
        if (children.GetCount() == 0) break;
 
2529
        prev = children.Item (children.GetCount() - 1);
 
2530
    }
 
2531
 
 
2532
    return prev;
 
2533
}
 
2534
 
 
2535
wxTreeItemId wxTreeListMainWindow::GetFirstExpandedItem() const {
 
2536
    return GetNextExpanded (GetRootItem());
 
2537
}
 
2538
 
 
2539
wxTreeItemId wxTreeListMainWindow::GetNextExpanded (const wxTreeItemId& item) const {
 
2540
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2541
    return GetNext (item, false);
 
2542
}
 
2543
 
 
2544
wxTreeItemId wxTreeListMainWindow::GetPrevExpanded (const wxTreeItemId& item) const {
 
2545
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2546
    return GetPrev (item, false);
 
2547
}
 
2548
 
 
2549
wxTreeItemId wxTreeListMainWindow::GetFirstVisible(bool fullRow, bool within) const {
 
2550
    if (HasFlag(wxTR_HIDE_ROOT) || ! IsVisible(GetRootItem(), fullRow, within)) {
 
2551
        return GetNextVisible (GetRootItem(), fullRow, within);
 
2552
    } else {
 
2553
        return GetRootItem();
 
2554
    }
 
2555
}
 
2556
 
 
2557
wxTreeItemId wxTreeListMainWindow::GetNextVisible (const wxTreeItemId& item, bool fullRow, bool within) const {
 
2558
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2559
    wxTreeItemId id = GetNext (item, false);
 
2560
    while (id.IsOk()) {
 
2561
        if (IsVisible (id, fullRow, within)) return id;
 
2562
        id = GetNext (id, false);
 
2563
    }
 
2564
    return wxTreeItemId();
 
2565
}
 
2566
 
 
2567
wxTreeItemId wxTreeListMainWindow::GetLastVisible ( bool fullRow, bool within) const {
 
2568
    wxCHECK_MSG (GetRootItem().IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2569
    wxTreeItemId id = GetRootItem();
 
2570
    wxTreeItemId res = id;
 
2571
    while ((id = GetNext (id, false)).IsOk()) {
 
2572
        if (IsVisible (id, fullRow, within)) res = id;
 
2573
    }
 
2574
    return res;
 
2575
}
 
2576
 
 
2577
wxTreeItemId wxTreeListMainWindow::GetPrevVisible (const wxTreeItemId& item, bool fullRow, bool within) const {
 
2578
    wxCHECK_MSG (item.IsOk(), wxTreeItemId(), _T("invalid tree item"));
 
2579
    wxTreeItemId id = GetPrev (item, true);
 
2580
    while (id.IsOk()) {
 
2581
        if (IsVisible (id, fullRow, within)) return id;
 
2582
        id = GetPrev(id, true);
 
2583
    }
 
2584
    return wxTreeItemId();
 
2585
}
 
2586
 
 
2587
// ----------------------------------------------------------------------------
 
2588
// operations
 
2589
// ----------------------------------------------------------------------------
 
2590
 
 
2591
// ----------------------------  ADD OPERATION  -------------------------------
 
2592
 
 
2593
wxTreeItemId wxTreeListMainWindow::DoInsertItem (const wxTreeItemId& parentId,
 
2594
                                                 size_t previous,
 
2595
                                                 const wxString& text,
 
2596
                                                 int image, int selImage,
 
2597
                                                 wxTreeItemData *data) {
 
2598
    wxTreeListItem *parent = (wxTreeListItem*)parentId.m_pItem;
 
2599
    wxCHECK_MSG (parent, wxTreeItemId(), _T("item must have a parent, at least root!") );
 
2600
    m_dirty = true; // do this first so stuff below doesn't cause flicker
 
2601
 
 
2602
    wxArrayString arr;
 
2603
    arr.Alloc (GetColumnCount());
 
2604
    for (int i = 0; i < (int)GetColumnCount(); ++i) arr.Add (wxEmptyString);
 
2605
    arr[m_main_column] = text;
 
2606
    wxTreeListItem *item = new wxTreeListItem (this, parent, arr, image, selImage, data);
 
2607
    if (data != NULL) {
 
2608
#if !wxCHECK_VERSION(2, 5, 0)
 
2609
        data->SetId ((long)item);
 
2610
#else
 
2611
        data->SetId (item);
 
2612
#endif
 
2613
    }
 
2614
    parent->Insert (item, previous);
 
2615
 
 
2616
    return item;
 
2617
}
 
2618
 
 
2619
wxTreeItemId wxTreeListMainWindow::AddRoot (const wxString& text,
 
2620
                                            int image, int selImage,
 
2621
                                            wxTreeItemData *data) {
 
2622
    wxCHECK_MSG(!m_rootItem, wxTreeItemId(), _T("tree can have only one root"));
 
2623
    wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), _T("Add column(s) before adding the root item"));
 
2624
    m_dirty = true; // do this first so stuff below doesn't cause flicker
 
2625
 
 
2626
    wxArrayString arr;
 
2627
    arr.Alloc (GetColumnCount());
 
2628
    for (int i = 0; i < (int)GetColumnCount(); ++i) arr.Add (wxEmptyString);
 
2629
    arr[m_main_column] = text;
 
2630
    m_rootItem = new wxTreeListItem (this, (wxTreeListItem *)NULL, arr, image, selImage, data);
 
2631
    if (data != NULL) {
 
2632
#if !wxCHECK_VERSION(2, 5, 0)
 
2633
        data->SetId((long)m_rootItem);
 
2634
#else
 
2635
        data->SetId(m_rootItem);
 
2636
#endif
 
2637
    }
 
2638
    if (HasFlag(wxTR_HIDE_ROOT)) {
 
2639
        // if we will hide the root, make sure children are visible
 
2640
        m_rootItem->SetHasPlus();
 
2641
        m_rootItem->Expand();
 
2642
#if !wxCHECK_VERSION(2, 5, 0)
 
2643
        long cookie = 0;
 
2644
#else
 
2645
        wxTreeItemIdValue cookie = 0;
 
2646
#endif
 
2647
        SetCurrentItem(GetFirstChild(m_rootItem, cookie));
 
2648
    }
 
2649
    return m_rootItem;
 
2650
}
 
2651
 
 
2652
wxTreeItemId wxTreeListMainWindow::PrependItem (const wxTreeItemId& parent,
 
2653
                                                const wxString& text,
 
2654
                                                int image, int selImage,
 
2655
                                                wxTreeItemData *data) {
 
2656
    return DoInsertItem (parent, 0u, text, image, selImage, data);
 
2657
}
 
2658
 
 
2659
wxTreeItemId wxTreeListMainWindow::InsertItem (const wxTreeItemId& parentId,
 
2660
                                               const wxTreeItemId& idPrevious,
 
2661
                                               const wxString& text,
 
2662
                                               int image, int selImage,
 
2663
                                               wxTreeItemData *data) {
 
2664
    wxTreeListItem *parent = (wxTreeListItem*)parentId.m_pItem;
 
2665
    wxCHECK_MSG (parent, wxTreeItemId(), _T("item must have a parent, at least root!") );
 
2666
 
 
2667
    int index = parent->GetChildren().Index((wxTreeListItem*) idPrevious.m_pItem);
 
2668
    wxASSERT_MSG( index != wxNOT_FOUND,
 
2669
                  _T("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") );
 
2670
 
 
2671
    return DoInsertItem (parentId, ++index, text, image, selImage, data);
 
2672
}
 
2673
 
 
2674
wxTreeItemId wxTreeListMainWindow::InsertItem (const wxTreeItemId& parentId,
 
2675
                                               size_t before,
 
2676
                                               const wxString& text,
 
2677
                                               int image, int selImage,
 
2678
                                               wxTreeItemData *data) {
 
2679
    wxTreeListItem *parent = (wxTreeListItem*)parentId.m_pItem;
 
2680
    wxCHECK_MSG (parent, wxTreeItemId(), _T("item must have a parent, at least root!") );
 
2681
 
 
2682
    return DoInsertItem (parentId, before, text, image, selImage, data);
 
2683
}
 
2684
 
 
2685
wxTreeItemId wxTreeListMainWindow::AppendItem (const wxTreeItemId& parentId,
 
2686
                                               const wxString& text,
 
2687
                                               int image, int selImage,
 
2688
                                               wxTreeItemData *data) {
 
2689
    wxTreeListItem *parent = (wxTreeListItem*) parentId.m_pItem;
 
2690
    wxCHECK_MSG (parent, wxTreeItemId(), _T("item must have a parent, at least root!") );
 
2691
 
 
2692
    return DoInsertItem (parent, parent->GetChildren().Count(), text, image, selImage, data);
 
2693
}
 
2694
 
 
2695
 
 
2696
// --------------------------  DELETE OPERATION  ------------------------------
 
2697
 
 
2698
void wxTreeListMainWindow::Delete (const wxTreeItemId& itemId) {
 
2699
    if (! itemId.IsOk()) return;
 
2700
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
2701
    wxTreeListItem *parent = item->GetItemParent();
 
2702
    wxCHECK_RET (item != m_rootItem, _T("invalid item, root may not be deleted this way!"));
 
2703
 
 
2704
    // recursive delete
 
2705
    DoDeleteItem(item);
 
2706
 
 
2707
    // update parent --CAUTION: must come after delete itself, so that item's
 
2708
    //  siblings may be found
 
2709
    if (parent) {
 
2710
        parent->GetChildren().Remove (item);  // remove by value
 
2711
    }
 
2712
}
 
2713
 
 
2714
 
 
2715
void wxTreeListMainWindow::DeleteRoot() {
 
2716
    if (! m_rootItem) return;
 
2717
 
 
2718
    SetCurrentItem((wxTreeListItem*)NULL);
 
2719
    m_selectItem = (wxTreeListItem*)NULL;
 
2720
    m_shiftItem = (wxTreeListItem*)NULL;
 
2721
 
 
2722
    DeleteChildren (m_rootItem);
 
2723
    SendEvent(wxEVT_COMMAND_TREE_DELETE_ITEM, m_rootItem);
 
2724
    delete m_rootItem; m_rootItem = NULL;
 
2725
}
 
2726
 
 
2727
 
 
2728
void wxTreeListMainWindow::DeleteChildren (const wxTreeItemId& itemId) {
 
2729
    if (! itemId.IsOk()) return;
 
2730
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
2731
 
 
2732
    // recursive delete on all children, starting from the right to prevent
 
2733
    //  multiple selection changes (see m_curItem handling in DoDeleteItem() )
 
2734
    wxArrayTreeListItems& children = item->GetChildren();
 
2735
    for (size_t n = children.GetCount(); n>0; n--) {
 
2736
        DoDeleteItem(children[n-1]);
 
2737
        // immediately remove child from array, otherwise it might get selected
 
2738
        // as current item (see m_curItem handling in DoDeleteItem() )
 
2739
        children.RemoveAt(n-1);
 
2740
    }
 
2741
}
 
2742
 
 
2743
 
 
2744
void wxTreeListMainWindow::DoDeleteItem(wxTreeListItem *item) {
 
2745
    wxCHECK_RET (item, _T("invalid item for delete!"));
 
2746
 
 
2747
    m_dirty = true; // do this first so stuff below doesn't cause flicker
 
2748
 
 
2749
    // cancel any editing
 
2750
 
 
2751
    if (m_editControl) { m_editControl->EndEdit(true); }  // cancelled
 
2752
 
 
2753
    // cancel any dragging
 
2754
    if (item == m_dragItem) {
 
2755
        // stop dragging
 
2756
        m_isDragStarted = m_isDragging = false;
 
2757
        if (HasCapture()) ReleaseMouse();
 
2758
    }
 
2759
 
 
2760
    // don't stay with invalid m_curItem: take next sibling or reset to NULL
 
2761
    // NOTE: this might be slighty inefficient when deleting a whole tree
 
2762
    //  but has the advantage that all deletion side-effects are handled here
 
2763
    if (item == m_curItem) {
 
2764
        SetCurrentItem(item->GetItemParent());
 
2765
        if (m_curItem) {
 
2766
            wxArrayTreeListItems& siblings = m_curItem->GetChildren();
 
2767
            size_t index = siblings.Index (item);
 
2768
            wxASSERT (index != (size_t)wxNOT_FOUND); // I'm not a child of my parent?
 
2769
            SetCurrentItem(index < siblings.Count()-1 ? siblings[index+1]: (wxTreeListItem*)NULL);
 
2770
        }
 
2771
    }
 
2772
    // don't stay with invalid m_shiftItem: reset it to NULL
 
2773
    if (item == m_shiftItem) m_shiftItem = (wxTreeListItem*)NULL;
 
2774
    // don't stay with invalid m_selectItem: default to current item
 
2775
    if (item == m_selectItem) {
 
2776
        m_selectItem = m_curItem;
 
2777
        SelectItem(m_selectItem, (wxTreeItemId*)NULL, true);  // unselect others
 
2778
    }
 
2779
 
 
2780
    // recurse children, starting from the right to prevent multiple selection
 
2781
    //  changes (see m_curItem handling above)
 
2782
    wxArrayTreeListItems& children = item->GetChildren();
 
2783
    for (size_t n = children.GetCount(); n>0; n--) {
 
2784
        DoDeleteItem(children[n-1]);
 
2785
        // immediately remove child from array, otherwise it might get selected
 
2786
        // as current item (see m_curItem handling above)
 
2787
        children.RemoveAt(n-1);
 
2788
    }
 
2789
 
 
2790
    // delete item itself
 
2791
    SendEvent(wxEVT_COMMAND_TREE_DELETE_ITEM, item);
 
2792
    delete item;
 
2793
}
 
2794
 
 
2795
 
 
2796
// ----------------------------------------------------------------------------
 
2797
 
 
2798
void wxTreeListMainWindow::SetCurrentItem(const wxTreeItemId& itemId) {
 
2799
  SetCurrentItem((wxTreeListItem *)(itemId ? itemId.m_pItem : NULL));
 
2800
}
 
2801
void wxTreeListMainWindow::SetCurrentItem(wxTreeListItem *item) {
 
2802
wxTreeListItem *old_item;
 
2803
 
 
2804
    old_item = m_curItem; m_curItem = item;
 
2805
 
 
2806
    // change of item, redraw previous
 
2807
    if (old_item != NULL && old_item != item) {
 
2808
        RefreshLine(old_item);
 
2809
    }
 
2810
 
 
2811
}
 
2812
 
 
2813
// ----------------------------------------------------------------------------
 
2814
 
 
2815
void wxTreeListMainWindow::Expand (const wxTreeItemId& itemId) {
 
2816
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
2817
    wxCHECK_RET (item, _T("invalid item in wxTreeListMainWindow::Expand") );
 
2818
 
 
2819
    if (!item->HasPlus() || item->IsExpanded()) return;
 
2820
 
 
2821
    // send event to user code
 
2822
    wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, 0);
 
2823
    event.SetInt(m_curColumn);
 
2824
    if (SendEvent(0, item, &event) && !event.IsAllowed()) return; // expand canceled
 
2825
 
 
2826
    item->Expand();
 
2827
    m_dirty = true;
 
2828
 
 
2829
    // send event to user code
 
2830
    event.SetEventType (wxEVT_COMMAND_TREE_ITEM_EXPANDED);
 
2831
    SendEvent(0, NULL, &event);
 
2832
}
 
2833
 
 
2834
void wxTreeListMainWindow::ExpandAll (const wxTreeItemId& itemId) {
 
2835
    wxCHECK_RET (itemId.IsOk(), _T("invalid tree item"));
 
2836
 
 
2837
    Expand (itemId);
 
2838
    if (!IsExpanded (itemId)) return;
 
2839
#if !wxCHECK_VERSION(2, 5, 0)
 
2840
    long cookie;
 
2841
#else
 
2842
    wxTreeItemIdValue cookie;
 
2843
#endif
 
2844
    wxTreeItemId child = GetFirstChild (itemId, cookie);
 
2845
    while (child.IsOk()) {
 
2846
        ExpandAll (child);
 
2847
        child = GetNextChild (itemId, cookie);
 
2848
    }
 
2849
}
 
2850
 
 
2851
void wxTreeListMainWindow::Collapse (const wxTreeItemId& itemId) {
 
2852
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
2853
    wxCHECK_RET (item, _T("invalid item in wxTreeListMainWindow::Collapse") );
 
2854
 
 
2855
    if (!item->HasPlus() || !item->IsExpanded()) return;
 
2856
 
 
2857
    // send event to user code
 
2858
    wxTreeEvent event (wxEVT_COMMAND_TREE_ITEM_COLLAPSING, 0 );
 
2859
    event.SetInt(m_curColumn);
 
2860
    if (SendEvent(0, item, &event) && !event.IsAllowed()) return; // collapse canceled
 
2861
 
 
2862
    item->Collapse();
 
2863
    m_dirty = true;
 
2864
 
 
2865
    // send event to user code
 
2866
    event.SetEventType (wxEVT_COMMAND_TREE_ITEM_COLLAPSED);
 
2867
    SendEvent(0, NULL, &event);
 
2868
}
 
2869
 
 
2870
void wxTreeListMainWindow::CollapseAndReset (const wxTreeItemId& item) {
 
2871
    wxCHECK_RET (item.IsOk(), _T("invalid tree item"));
 
2872
 
 
2873
    Collapse (item);
 
2874
    DeleteChildren (item);
 
2875
}
 
2876
 
 
2877
void wxTreeListMainWindow::Toggle (const wxTreeItemId& itemId) {
 
2878
    wxCHECK_RET (itemId.IsOk(), _T("invalid tree item"));
 
2879
 
 
2880
    if (IsExpanded (itemId)) {
 
2881
        Collapse (itemId);
 
2882
    }else{
 
2883
        Expand (itemId);
 
2884
    }
 
2885
}
 
2886
 
 
2887
void wxTreeListMainWindow::Unselect() {
 
2888
    if (m_selectItem) {
 
2889
        m_selectItem->SetHilight (false);
 
2890
        RefreshLine (m_selectItem);
 
2891
        m_selectItem = (wxTreeListItem*)NULL;
 
2892
    }
 
2893
}
 
2894
 
 
2895
void wxTreeListMainWindow::UnselectAllChildren (wxTreeListItem *item) {
 
2896
    wxCHECK_RET (item, _T("invalid tree item"));
 
2897
 
 
2898
    if (item->IsSelected()) {
 
2899
        item->SetHilight (false);
 
2900
        RefreshLine (item);
 
2901
        if (item == m_selectItem) m_selectItem = (wxTreeListItem*)NULL;
 
2902
        if (item != m_curItem) m_lastOnSame = false;  // selection change, so reset edit marker
 
2903
    }
 
2904
    if (item->HasChildren()) {
 
2905
        wxArrayTreeListItems& children = item->GetChildren();
 
2906
        size_t count = children.Count();
 
2907
        for (size_t n = 0; n < count; ++n) {
 
2908
            UnselectAllChildren (children[n]);
 
2909
        }
 
2910
    }
 
2911
}
 
2912
 
 
2913
void wxTreeListMainWindow::UnselectAll() {
 
2914
    UnselectAllChildren ((wxTreeListItem*)GetRootItem().m_pItem);
 
2915
}
 
2916
 
 
2917
// Recursive function !
 
2918
// To stop we must have crt_item<last_item
 
2919
// Algorithm :
 
2920
// Tag all next children, when no more children,
 
2921
// Move to parent (not to tag)
 
2922
// Keep going... if we found last_item, we stop.
 
2923
bool wxTreeListMainWindow::TagNextChildren (wxTreeListItem *crt_item,
 
2924
                                            wxTreeListItem *last_item) {
 
2925
    wxTreeListItem *parent = crt_item->GetItemParent();
 
2926
 
 
2927
    if (!parent) {// This is root item
 
2928
        return TagAllChildrenUntilLast (crt_item, last_item);
 
2929
    }
 
2930
 
 
2931
    wxArrayTreeListItems& children = parent->GetChildren();
 
2932
    int index = children.Index(crt_item);
 
2933
    wxASSERT (index != wxNOT_FOUND); // I'm not a child of my parent?
 
2934
 
 
2935
    if ((parent->HasChildren() && parent->IsExpanded()) ||
 
2936
        ((parent == (wxTreeListItem*)GetRootItem().m_pItem) && HasFlag(wxTR_HIDE_ROOT))) {
 
2937
        size_t count = children.Count();
 
2938
        for (size_t n = (index+1); n < count; ++n) {
 
2939
            if (TagAllChildrenUntilLast (children[n], last_item)) return true;
 
2940
        }
 
2941
    }
 
2942
 
 
2943
    return TagNextChildren (parent, last_item);
 
2944
}
 
2945
 
 
2946
bool wxTreeListMainWindow::TagAllChildrenUntilLast (wxTreeListItem *crt_item,
 
2947
                                                    wxTreeListItem *last_item) {
 
2948
    crt_item->SetHilight (true);
 
2949
    RefreshLine(crt_item);
 
2950
 
 
2951
    if (crt_item==last_item) return true;
 
2952
 
 
2953
    if (crt_item->HasChildren() && crt_item->IsExpanded()) {
 
2954
        wxArrayTreeListItems& children = crt_item->GetChildren();
 
2955
        size_t count = children.Count();
 
2956
        for (size_t n = 0; n < count; ++n) {
 
2957
            if (TagAllChildrenUntilLast (children[n], last_item)) return true;
 
2958
        }
 
2959
    }
 
2960
 
 
2961
    return false;
 
2962
}
 
2963
 
 
2964
bool wxTreeListMainWindow::SelectItem (const wxTreeItemId& itemId,
 
2965
                                       const wxTreeItemId& lastId,
 
2966
                                       bool unselect_others) {
 
2967
 
 
2968
    wxTreeListItem *item = itemId.IsOk() ? (wxTreeListItem*) itemId.m_pItem : NULL;
 
2969
 
 
2970
    // send selecting event to the user code
 
2971
    wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, 0);
 
2972
    event.SetInt(m_curColumn);
 
2973
#if !wxCHECK_VERSION(2, 5, 0)
 
2974
    event.SetOldItem ((long)m_curItem);
 
2975
#else
 
2976
    event.SetOldItem (m_curItem);
 
2977
#endif
 
2978
    if (SendEvent(0, item, &event) && !event.IsAllowed()) return false;  // veto on selection change
 
2979
 
 
2980
    // unselect all if unselect other items
 
2981
    bool bUnselectedAll = false; // see that UnselectAll is done only once
 
2982
    if (unselect_others) {
 
2983
        if (HasFlag(wxTR_MULTIPLE)) {
 
2984
            UnselectAll(); bUnselectedAll = true;
 
2985
        }else{
 
2986
            Unselect(); // to speed up thing
 
2987
        }
 
2988
    }
 
2989
 
 
2990
    // select item range
 
2991
    if (lastId.IsOk() && itemId.IsOk() && (itemId != lastId)) {
 
2992
 
 
2993
        if (! bUnselectedAll) UnselectAll();
 
2994
        wxTreeListItem *last = (wxTreeListItem*) lastId.m_pItem;
 
2995
 
 
2996
        // ensure that the position of the item it calculated in any case
 
2997
        if (m_dirty) CalculatePositions();
 
2998
 
 
2999
        // select item range according Y-position
 
3000
        if (last->GetY() < item->GetY()) {
 
3001
            if (!TagAllChildrenUntilLast (last, item)) {
 
3002
                TagNextChildren (last, item);
 
3003
            }
 
3004
        }else{
 
3005
            if (!TagAllChildrenUntilLast (item, last)) {
 
3006
                TagNextChildren (item, last);
 
3007
            }
 
3008
        }
 
3009
 
 
3010
    // or select single item
 
3011
    }else if (itemId.IsOk()) {
 
3012
 
 
3013
        // select item according its old selection
 
3014
        item->SetHilight (!item->IsSelected());
 
3015
        RefreshLine (item);
 
3016
        if (unselect_others) {
 
3017
            m_selectItem = (item->IsSelected())? item: (wxTreeListItem*)NULL;
 
3018
        }
 
3019
 
 
3020
    // or select nothing
 
3021
    } else {
 
3022
        if (! bUnselectedAll) UnselectAll();
 
3023
    }
 
3024
 
 
3025
    // send event to user code
 
3026
    event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
 
3027
    SendEvent(0, NULL, &event);
 
3028
 
 
3029
    return true;
 
3030
}
 
3031
 
 
3032
void wxTreeListMainWindow::SelectAll() {
 
3033
    wxTreeItemId root = GetRootItem();
 
3034
    wxCHECK_RET (HasFlag(wxTR_MULTIPLE), _T("invalid tree style"));
 
3035
    wxCHECK_RET (root.IsOk(), _T("no tree"));
 
3036
 
 
3037
    // send event to user code
 
3038
    wxTreeEvent event (wxEVT_COMMAND_TREE_SEL_CHANGING, 0);
 
3039
#if !wxCHECK_VERSION(2, 5, 0)
 
3040
    event.SetOldItem ((long)m_curItem);
 
3041
#else
 
3042
    event.SetOldItem (m_curItem);
 
3043
#endif
 
3044
    event.SetInt (-1); // no colum clicked
 
3045
    if (SendEvent(0, m_rootItem, &event) && !event.IsAllowed()) return;  // selection change vetoed
 
3046
 
 
3047
#if !wxCHECK_VERSION(2, 5, 0)
 
3048
    long cookie = 0;
 
3049
#else
 
3050
    wxTreeItemIdValue cookie = 0;
 
3051
#endif
 
3052
    wxTreeListItem *first = (wxTreeListItem *)GetFirstChild (root, cookie).m_pItem;
 
3053
    wxTreeListItem *last = (wxTreeListItem *)GetLastChild (root, cookie).m_pItem;
 
3054
    if (!TagAllChildrenUntilLast (first, last)) {
 
3055
        TagNextChildren (first, last);
 
3056
    }
 
3057
 
 
3058
    // send event to user code
 
3059
    event.SetEventType (wxEVT_COMMAND_TREE_SEL_CHANGED);
 
3060
    SendEvent(0, NULL, &event);
 
3061
}
 
3062
 
 
3063
void wxTreeListMainWindow::FillArray (wxTreeListItem *item,
 
3064
                                      wxArrayTreeItemIds &array) const {
 
3065
    if (item->IsSelected()) array.Add (wxTreeItemId(item));
 
3066
 
 
3067
    if (item->HasChildren()) {
 
3068
        wxArrayTreeListItems& children = item->GetChildren();
 
3069
        size_t count = children.GetCount();
 
3070
        for (size_t n = 0; n < count; ++n) FillArray (children[n], array);
 
3071
    }
 
3072
}
 
3073
 
 
3074
size_t wxTreeListMainWindow::GetSelections (wxArrayTreeItemIds &array) const {
 
3075
    array.Empty();
 
3076
    wxTreeItemId idRoot = GetRootItem();
 
3077
    if (idRoot.IsOk()) FillArray ((wxTreeListItem*) idRoot.m_pItem, array);
 
3078
    return array.Count();
 
3079
}
 
3080
 
 
3081
void wxTreeListMainWindow::EnsureVisible (const wxTreeItemId& item) {
 
3082
    if (!item.IsOk()) return; // do nothing if no item
 
3083
 
 
3084
    // first expand all parent branches
 
3085
    wxTreeListItem *gitem = (wxTreeListItem*) item.m_pItem;
 
3086
    wxTreeListItem *parent = gitem->GetItemParent();
 
3087
    while (parent) {
 
3088
        Expand (parent);
 
3089
        parent = parent->GetItemParent();
 
3090
    }
 
3091
 
 
3092
    ScrollTo (item);
 
3093
    RefreshLine (gitem);
 
3094
}
 
3095
 
 
3096
void wxTreeListMainWindow::ScrollTo (const wxTreeItemId &item) {
 
3097
    if (!item.IsOk()) return; // do nothing if no item
 
3098
 
 
3099
    // ensure that the position of the item it calculated in any case
 
3100
    if (m_dirty) CalculatePositions();
 
3101
 
 
3102
    wxTreeListItem *gitem = (wxTreeListItem*) item.m_pItem;
 
3103
 
 
3104
    // now scroll to the item
 
3105
    int item_y = gitem->GetY();
 
3106
 
 
3107
    int xUnit, yUnit;
 
3108
    GetScrollPixelsPerUnit (&xUnit, &yUnit);
 
3109
    int start_x = 0;
 
3110
    int start_y = 0;
 
3111
    GetViewStart (&start_x, &start_y);
 
3112
    start_y *= yUnit;
 
3113
 
 
3114
    int client_h = 0;
 
3115
    int client_w = 0;
 
3116
    GetClientSize (&client_w, &client_h);
 
3117
 
 
3118
    int x = 0;
 
3119
    int y = 0;
 
3120
    m_rootItem->GetSize (x, y, this);
 
3121
    x = m_owner->GetHeaderWindow()->GetWidth();
 
3122
    y += yUnit + 2; // one more scrollbar unit + 2 pixels
 
3123
    int x_pos = GetScrollPos( wxHORIZONTAL );
 
3124
 
 
3125
    if (item_y < start_y+3) {
 
3126
        // going down, item should appear at top
 
3127
        SetScrollbars (xUnit, yUnit, xUnit ? x/xUnit : 0, yUnit ? y/yUnit : 0, x_pos, yUnit ? item_y/yUnit : 0);
 
3128
    }else if (item_y+GetLineHeight(gitem) > start_y+client_h) {
 
3129
        // going up, item should appear at bottom
 
3130
        item_y += yUnit + 2;
 
3131
        SetScrollbars (xUnit, yUnit, xUnit ? x/xUnit : 0, yUnit ? y/yUnit : 0, x_pos, yUnit ? (item_y+GetLineHeight(gitem)-client_h)/yUnit : 0 );
 
3132
    }
 
3133
}
 
3134
 
 
3135
// TODO: tree sorting functions are not reentrant and not MT-safe!
 
3136
static wxTreeListMainWindow *s_treeBeingSorted = NULL;
 
3137
 
 
3138
static int LINKAGEMODE tree_ctrl_compare_func(wxTreeListItem **item1, wxTreeListItem **item2)
 
3139
{
 
3140
    wxCHECK_MSG (s_treeBeingSorted, 0, _T("bug in wxTreeListMainWindow::SortChildren()") );
 
3141
    return s_treeBeingSorted->OnCompareItems(*item1, *item2);
 
3142
}
 
3143
 
 
3144
int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
 
3145
{
 
3146
    return (m_sortColumn == -1
 
3147
        ? m_owner->OnCompareItems (item1, item2)
 
3148
        : (m_ReverseSortOrder
 
3149
            ? m_owner->OnCompareItems (item2, item1, m_sortColumn)
 
3150
            : m_owner->OnCompareItems (item1, item2, m_sortColumn)
 
3151
        )
 
3152
    );
 
3153
}
 
3154
 
 
3155
void wxTreeListMainWindow::SortChildren (const wxTreeItemId& itemId, int column, bool reverseOrder) {
 
3156
    wxCHECK_RET (itemId.IsOk(), _T("invalid tree item"));
 
3157
 
 
3158
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
3159
 
 
3160
    wxCHECK_RET (!s_treeBeingSorted,
 
3161
                 _T("wxTreeListMainWindow::SortChildren is not reentrant") );
 
3162
 
 
3163
    wxArrayTreeListItems& children = item->GetChildren();
 
3164
    if ( children.Count() > 1 ) {
 
3165
        m_dirty = true;
 
3166
        s_treeBeingSorted = this;
 
3167
        m_sortColumn = column;  // -1 indicates legacy mode
 
3168
        m_ReverseSortOrder = reverseOrder;
 
3169
        children.Sort(tree_ctrl_compare_func);
 
3170
        s_treeBeingSorted = NULL;
 
3171
    }
 
3172
}
 
3173
 
 
3174
wxTreeItemId wxTreeListMainWindow::FindItem (const wxTreeItemId& item, int column, const wxString& str, int mode) {
 
3175
    wxString itemText;
 
3176
    // determine start item
 
3177
    wxTreeItemId next = item;
 
3178
    if (next.IsOk()) {
 
3179
        if (mode & wxTL_MODE_NAV_LEVEL) {
 
3180
            next = GetNextSibling (next);
 
3181
        }else if (mode & wxTL_MODE_NAV_VISIBLE) { //
 
3182
            next = GetNextVisible (next, false, true);
 
3183
        }else if (mode & wxTL_MODE_NAV_EXPANDED) {
 
3184
            next = GetNextExpanded (next);
 
3185
        }else{ // (mode & wxTL_MODE_NAV_FULLTREE) default
 
3186
            next = GetNext (next, true);
 
3187
        }
 
3188
    }
 
3189
 
 
3190
#if !wxCHECK_VERSION(2, 5, 0)
 
3191
    long cookie = 0;
 
3192
#else
 
3193
    wxTreeItemIdValue cookie = 0;
 
3194
#endif
 
3195
    if (!next.IsOk()) {
 
3196
        next = GetRootItem();
 
3197
        if (next.IsOk() && HasFlag(wxTR_HIDE_ROOT)) {
 
3198
            next = GetFirstChild (GetRootItem(), cookie);
 
3199
        }
 
3200
    }
 
3201
    if (!next.IsOk()) return (wxTreeItemId*)NULL;
 
3202
 
 
3203
    // start checking the next items
 
3204
    while (next.IsOk() && (next != item)) {
 
3205
        if (mode & wxTL_MODE_FIND_PARTIAL) {
 
3206
            itemText = GetItemText (next, column).Mid (0, str.Length());
 
3207
        }else{
 
3208
            itemText = GetItemText (next, column);
 
3209
        }
 
3210
        if (mode & wxTL_MODE_FIND_NOCASE) {
 
3211
            if (itemText.CmpNoCase (str) == 0) return next;
 
3212
        }else{
 
3213
            if (itemText.Cmp (str) == 0) return next;
 
3214
        }
 
3215
        if (mode & wxTL_MODE_NAV_LEVEL) {
 
3216
            next = GetNextSibling (next);
 
3217
        }else if (mode & wxTL_MODE_NAV_VISIBLE) { //
 
3218
            next = GetNextVisible (next, false, true);
 
3219
        }else if (mode & wxTL_MODE_NAV_EXPANDED) {
 
3220
            next = GetNextExpanded (next);
 
3221
        }else{ // (mode & wxTL_MODE_NAV_FULLTREE) default
 
3222
            next = GetNext (next, true);
 
3223
        }
 
3224
        if (!next.IsOk() && item.IsOk()) {
 
3225
            next = (wxTreeListItem*)GetRootItem().m_pItem;
 
3226
            if (HasFlag(wxTR_HIDE_ROOT)) {
 
3227
                next = (wxTreeListItem*)GetNextChild (GetRootItem().m_pItem, cookie).m_pItem;
 
3228
            }
 
3229
        }
 
3230
    }
 
3231
    return (wxTreeItemId*)NULL;
 
3232
}
 
3233
 
 
3234
void wxTreeListMainWindow::SetDragItem (const wxTreeItemId& item) {
 
3235
    wxTreeListItem *prevItem = m_dragItem;
 
3236
    m_dragItem = (wxTreeListItem*) item.m_pItem;
 
3237
    if (prevItem) RefreshLine (prevItem);
 
3238
    if (m_dragItem) RefreshLine (m_dragItem);
 
3239
}
 
3240
 
 
3241
void wxTreeListMainWindow::CalculateLineHeight() {
 
3242
    wxClientDC dc (this);
 
3243
    dc.SetFont (m_normalFont);
 
3244
    m_lineHeight = (int)(dc.GetCharHeight() + m_linespacing);
 
3245
 
 
3246
    if (m_imageListNormal) {
 
3247
        // Calculate a m_lineHeight value from the normal Image sizes.
 
3248
        // May be toggle off. Then wxTreeListMainWindow will spread when
 
3249
        // necessary (which might look ugly).
 
3250
        int n = m_imageListNormal->GetImageCount();
 
3251
        for (int i = 0; i < n ; i++) {
 
3252
            int width = 0, height = 0;
 
3253
            m_imageListNormal->GetSize(i, width, height);
 
3254
            if (height > m_lineHeight) m_lineHeight = height + m_linespacing;
 
3255
        }
 
3256
    }
 
3257
 
 
3258
    if (m_imageListButtons) {
 
3259
        // Calculate a m_lineHeight value from the Button image sizes.
 
3260
        // May be toggle off. Then wxTreeListMainWindow will spread when
 
3261
        // necessary (which might look ugly).
 
3262
        int n = m_imageListButtons->GetImageCount();
 
3263
        for (int i = 0; i < n ; i++) {
 
3264
            int width = 0, height = 0;
 
3265
            m_imageListButtons->GetSize(i, width, height);
 
3266
            if (height > m_lineHeight) m_lineHeight = height + m_linespacing;
 
3267
        }
 
3268
    }
 
3269
 
 
3270
    if (m_lineHeight < 30) { // add 10% space if greater than 30 pixels
 
3271
        m_lineHeight += 2; // minimal 2 pixel space
 
3272
    }else{
 
3273
        m_lineHeight += m_lineHeight / 10; // otherwise 10% space
 
3274
    }
 
3275
}
 
3276
 
 
3277
void wxTreeListMainWindow::SetImageList (wxImageList *imageList) {
 
3278
    if (m_ownsImageListNormal) delete m_imageListNormal;
 
3279
    m_imageListNormal = imageList;
 
3280
    m_ownsImageListNormal = false;
 
3281
    m_dirty = true;
 
3282
    CalculateLineHeight();
 
3283
}
 
3284
 
 
3285
void wxTreeListMainWindow::SetStateImageList (wxImageList *imageList) {
 
3286
    if (m_ownsImageListState) delete m_imageListState;
 
3287
    m_imageListState = imageList;
 
3288
    m_ownsImageListState = false;
 
3289
}
 
3290
 
 
3291
void wxTreeListMainWindow::SetButtonsImageList (wxImageList *imageList) {
 
3292
    if (m_ownsImageListButtons) delete m_imageListButtons;
 
3293
    m_imageListButtons = imageList;
 
3294
    m_ownsImageListButtons = false;
 
3295
    m_dirty = true;
 
3296
    CalculateLineHeight();
 
3297
}
 
3298
 
 
3299
void wxTreeListMainWindow::AssignImageList (wxImageList *imageList) {
 
3300
    SetImageList(imageList);
 
3301
    m_ownsImageListNormal = true;
 
3302
}
 
3303
 
 
3304
void wxTreeListMainWindow::AssignStateImageList (wxImageList *imageList) {
 
3305
    SetStateImageList(imageList);
 
3306
    m_ownsImageListState = true;
 
3307
}
 
3308
 
 
3309
void wxTreeListMainWindow::AssignButtonsImageList (wxImageList *imageList) {
 
3310
    SetButtonsImageList(imageList);
 
3311
    m_ownsImageListButtons = true;
 
3312
}
 
3313
 
 
3314
// ----------------------------------------------------------------------------
 
3315
// helpers
 
3316
// ----------------------------------------------------------------------------
 
3317
 
 
3318
void wxTreeListMainWindow::AdjustMyScrollbars() {
 
3319
    if (m_rootItem) {
 
3320
        int xUnit, yUnit;
 
3321
        GetScrollPixelsPerUnit (&xUnit, &yUnit);
 
3322
        if (xUnit == 0) xUnit = GetCharWidth();
 
3323
        if (yUnit == 0) yUnit = m_lineHeight;
 
3324
        int x = 0, y = 0;
 
3325
        m_rootItem->GetSize (x, y, this);
 
3326
        y += yUnit + 2; // one more scrollbar unit + 2 pixels
 
3327
        int x_pos = GetScrollPos (wxHORIZONTAL);
 
3328
        int y_pos = GetScrollPos (wxVERTICAL);
 
3329
        x = m_owner->GetHeaderWindow()->GetWidth() + 2;
 
3330
        if (x < GetClientSize().GetWidth()) x_pos = 0;
 
3331
        SetScrollbars (xUnit, yUnit, x/xUnit, y/yUnit, x_pos, y_pos);
 
3332
    }else{
 
3333
        SetScrollbars (0, 0, 0, 0);
 
3334
    }
 
3335
}
 
3336
 
 
3337
int wxTreeListMainWindow::GetLineHeight (wxTreeListItem *item) const {
 
3338
    if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT) {
 
3339
        return item->GetHeight();
 
3340
    }else{
 
3341
        return m_lineHeight;
 
3342
    }
 
3343
}
 
3344
 
 
3345
void wxTreeListMainWindow::PaintItem (wxTreeListItem *item, wxDC& dc) {
 
3346
 
 
3347
// read attributes constant for all item cells
 
3348
    wxColour colText = GetItemTextColour(item);
 
3349
    wxColour colBg = GetItemBackgroundColour(item);
 
3350
#if !wxCHECK_VERSION(2, 5, 0)
 
3351
    wxColour colTextHilight = wxSystemSettings::GetSystemColour (wxSYS_COLOUR_HIGHLIGHTTEXT);
 
3352
#else
 
3353
    wxColour colTextHilight = wxSystemSettings::GetColour (wxSYS_COLOUR_HIGHLIGHTTEXT);
 
3354
#endif
 
3355
    int total_w = m_owner->GetHeaderWindow()->GetWidth();
 
3356
    int total_h = GetLineHeight(item);
 
3357
    int off_h = HasFlag(wxTR_ROW_LINES) ? 1 : 0;
 
3358
    int off_w = HasFlag(wxTR_COLUMN_LINES) ? 1 : 0;
 
3359
    wxDCClipper clipper (dc, 0, item->GetY(), total_w, total_h); // only within line
 
3360
    // compute text height based on main col
 
3361
    int text_h = 0;
 
3362
    dc.GetTextExtent( item->GetText(GetMainColumn()).size() > 0
 
3363
            ? item->GetText(GetMainColumn())
 
3364
            : _T("M"),  // dummy text to avoid zero height and no highlight width
 
3365
        NULL, &text_h );
 
3366
 
 
3367
// determine background and show it
 
3368
// in wxTR_FULL_ROW_HIGHLIGHT mode, some drawing can be done already now
 
3369
    dc.SetBrush (wxBrush ( colBg, wxSOLID));
 
3370
    dc.SetPen (*wxTRANSPARENT_PEN);
 
3371
    if (HasFlag (wxTR_FULL_ROW_HIGHLIGHT)) {
 
3372
        if (item->IsSelected()) {
 
3373
            if (! m_isDragging && m_hasFocus) {
 
3374
                dc.SetBrush (*m_hilightBrush);
 
3375
#ifndef __WXMAC__ // don't draw rect outline if we already have the background color
 
3376
                dc.SetPen (*wxBLACK_PEN);
 
3377
#endif // !__WXMAC__
 
3378
            }else{
 
3379
                dc.SetBrush (*m_hilightUnfocusedBrush);
 
3380
#ifndef __WXMAC__ // don't draw rect outline if we already have the background color
 
3381
                dc.SetPen (*wxTRANSPARENT_PEN);
 
3382
#endif // !__WXMAC__
 
3383
            }
 
3384
            dc.SetTextForeground (colTextHilight);
 
3385
        }else {
 
3386
            dc.SetTextForeground (GetItemTextColour(item));
 
3387
            if (item == m_curItem) {
 
3388
                dc.SetPen (m_hasFocus? *wxBLACK_PEN: *wxTRANSPARENT_PEN);
 
3389
            }
 
3390
        }
 
3391
        dc.DrawRectangle (0, item->GetY() + off_h, total_w, total_h - off_h);
 
3392
    }
 
3393
 
 
3394
// iterate through all cells
 
3395
    int text_extraH = (total_h > text_h) ? (total_h - text_h)/2 : 0;
 
3396
    int img_extraH = (total_h > m_imgHeight)? (total_h-m_imgHeight)/2: 0;
 
3397
    int x_colstart = 0;
 
3398
    for (int i = 0; i < GetColumnCount(); ++i ) {
 
3399
        if (!m_owner->GetHeaderWindow()->IsColumnShown(i)) continue;
 
3400
        int col_w = m_owner->GetHeaderWindow()->GetColumnWidth(i);
 
3401
        if (col_w <= 0) continue;  // workaround for probable GTK2 bug [wxCode-Bugs-#3061215]
 
3402
        wxDCClipper clipper (dc, x_colstart, item->GetY(), col_w, total_h); // only within column
 
3403
 
 
3404
        // read variable attributes
 
3405
        dc.SetFont (GetItemFont (item, i));
 
3406
        colText = GetItemTextColour(item, i);
 
3407
        colBg = GetItemBackgroundColour(item, i);
 
3408
 
 
3409
        //
 
3410
        int x = 0;
 
3411
        int image = NO_IMAGE;
 
3412
        int image_w = 0;
 
3413
        if(i == GetMainColumn()) {
 
3414
            x = item->GetX() + MARGIN;
 
3415
            if (HasButtons()) {
 
3416
                x += (m_btnWidth-m_btnWidth2) + LINEATROOT;
 
3417
            }else{
 
3418
                x -= m_indent/2;
 
3419
            }
 
3420
            if (m_imageListNormal) image = item->GetCurrentImage();
 
3421
        }else{
 
3422
            x = x_colstart + MARGIN;
 
3423
            image = item->GetImage(i);
 
3424
        }
 
3425
        if (image != NO_IMAGE) image_w = m_imgWidth + MARGIN;
 
3426
 
 
3427
        // honor text alignment
 
3428
        int w = 0, text_w = 0;
 
3429
        wxString text = item->GetText(i);
 
3430
        dc.GetTextExtent (text, &text_w, NULL);
 
3431
        switch ( m_owner->GetHeaderWindow()->GetColumn(i).GetAlignment() ) {
 
3432
        case wxALIGN_LEFT:
 
3433
            // nothing to do, already left aligned
 
3434
            break;
 
3435
        case wxALIGN_RIGHT:
 
3436
            w = col_w - (image_w + text_w + off_w + MARGIN);
 
3437
            x += (w > 0)? w: 0;
 
3438
            break;
 
3439
        case wxALIGN_CENTER:
 
3440
            w = (col_w - (image_w + text_w + off_w + MARGIN))/2;
 
3441
            x += (w > 0)? w: 0;
 
3442
            break;
 
3443
        }
 
3444
        int text_x = x + image_w;
 
3445
        if (i == GetMainColumn()) item->SetTextX (text_x);
 
3446
 
 
3447
        // draw background (in non wxTR_FULL_ROW_HIGHLIGHT mode)
 
3448
        // cell-specific settings are used --excepted for selection:
 
3449
        if ( ! HasFlag (wxTR_FULL_ROW_HIGHLIGHT)) {
 
3450
            // cursor: indicate current cell
 
3451
            bool drawCursor = false;
 
3452
#ifndef __WXMAC__ // don't draw rect outline if we already have the background color
 
3453
            drawCursor = (item == m_curItem && i == m_curColumn && !m_isDragging && m_hasFocus);
 
3454
#endif // !__WXMAC__
 
3455
            // selection: main col only, overrides colors + separate draw
 
3456
            if (item->IsSelected() && i == GetMainColumn()) {
 
3457
                // draw normal background
 
3458
                dc.SetPen (*wxTRANSPARENT_PEN);
 
3459
                dc.SetBrush (wxBrush ( colBg, wxSOLID));
 
3460
                dc.DrawRectangle (x_colstart, item->GetY() + off_h, col_w, total_h - off_h);
 
3461
                // draw selection & optionally cursor
 
3462
                dc.SetPen (drawCursor ? *wxBLACK_PEN : *wxTRANSPARENT_PEN);
 
3463
                dc.SetBrush(!m_isDragging && m_hasFocus ? *m_hilightBrush : *m_hilightUnfocusedBrush);
 
3464
                dc.SetTextForeground (colTextHilight);
 
3465
                dc.DrawRectangle (text_x, item->GetY() + off_h, text_w, total_h - off_h);
 
3466
            // normal FG / BG from attributes
 
3467
            } else {
 
3468
                // draw normal background & optionally cursor
 
3469
                dc.SetPen (drawCursor && i != GetMainColumn() ? *wxBLACK_PEN : *wxTRANSPARENT_PEN);
 
3470
                dc.SetBrush (wxBrush ( colBg, wxSOLID));
 
3471
                dc.SetTextForeground (colText);
 
3472
                dc.DrawRectangle (x_colstart, item->GetY() + off_h, col_w, total_h - off_h);
 
3473
                // on main col draw a separate cursor
 
3474
                if (drawCursor && i == GetMainColumn()) {
 
3475
                    dc.SetPen (*wxBLACK_PEN);
 
3476
                    dc.SetBackgroundMode (wxTRANSPARENT);
 
3477
                    dc.DrawRectangle (text_x, item->GetY() + off_h, text_w, total_h - off_h);
 
3478
                }
 
3479
            }
 
3480
        }
 
3481
 
 
3482
        // draw vertical column lines
 
3483
        if (HasFlag(wxTR_COLUMN_LINES)) { // vertical lines between columns
 
3484
#if !wxCHECK_VERSION(2, 5, 0)
 
3485
            wxPen pen (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_3DLIGHT ), 1, wxSOLID);
 
3486
#else
 
3487
            wxPen pen (wxSystemSettings::GetColour (wxSYS_COLOUR_3DLIGHT ), 1, wxSOLID);
 
3488
#endif
 
3489
            dc.SetPen ((GetBackgroundColour() == *wxWHITE)? pen: *wxWHITE_PEN);
 
3490
            dc.DrawLine (x_colstart+col_w-1, item->GetY(), x_colstart+col_w-1, item->GetY()+total_h);
 
3491
        }
 
3492
 
 
3493
        dc.SetBackgroundMode (wxTRANSPARENT);
 
3494
 
 
3495
        // draw image
 
3496
        if (image != NO_IMAGE && m_imageListNormal && image < m_imageListNormal->GetImageCount()) {
 
3497
            int y = item->GetY() + img_extraH;
 
3498
            m_imageListNormal->Draw (image, dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
 
3499
        }
 
3500
 
 
3501
        // draw text
 
3502
        int text_y = item->GetY() + text_extraH;
 
3503
        dc.DrawText (text, (wxCoord)text_x, (wxCoord)text_y);
 
3504
 
 
3505
        x_colstart += col_w;
 
3506
    }
 
3507
 
 
3508
    // restore normal font
 
3509
    dc.SetFont( m_normalFont );
 
3510
}
 
3511
 
 
3512
// Now y stands for the top of the item, whereas it used to stand for middle !
 
3513
void wxTreeListMainWindow::PaintLevel (wxTreeListItem *item, wxDC &dc,
 
3514
                                       int level, int &y, int x_maincol) {
 
3515
 
 
3516
    // Handle hide root (only level 0)
 
3517
    if (HasFlag(wxTR_HIDE_ROOT) && (level == 0)) {
 
3518
        wxArrayTreeListItems& children = item->GetChildren();
 
3519
        for (size_t n = 0; n < children.Count(); n++) {
 
3520
            PaintLevel (children[n], dc, 1, y, x_maincol);
 
3521
        }
 
3522
        // end after expanding root
 
3523
        return;
 
3524
    }
 
3525
 
 
3526
    // calculate position of vertical lines
 
3527
    int x = x_maincol + MARGIN; // start of column
 
3528
    if (HasFlag(wxTR_LINES_AT_ROOT)) x += LINEATROOT; // space for lines at root
 
3529
    if (HasButtons()) {
 
3530
        x += (m_btnWidth-m_btnWidth2); // half button space
 
3531
    }else{
 
3532
        x += (m_indent-m_indent/2);
 
3533
    }
 
3534
    if (HasFlag(wxTR_HIDE_ROOT)) {
 
3535
        x += m_indent * (level-1); // indent but not level 1
 
3536
    }else{
 
3537
        x += m_indent * level; // indent according to level
 
3538
    }
 
3539
 
 
3540
    // set position of vertical line
 
3541
    item->SetX (x);
 
3542
    item->SetY (y);
 
3543
 
 
3544
    int h = GetLineHeight (item);
 
3545
    int y_top = y;
 
3546
    int y_mid = y_top + (h/2);
 
3547
    y += h;
 
3548
 
 
3549
    int exposed_x = dc.LogicalToDeviceX(0);
 
3550
    int exposed_y = dc.LogicalToDeviceY(y_top);
 
3551
 
 
3552
    if (IsExposed(exposed_x, exposed_y, 10000, h)) { // 10000 = very much
 
3553
 
 
3554
        if (HasFlag(wxTR_ROW_LINES)) { // horizontal lines between rows
 
3555
            //dc.DestroyClippingRegion();
 
3556
            int total_width = m_owner->GetHeaderWindow()->GetWidth();
 
3557
            // if the background colour is white, choose a
 
3558
            // contrasting color for the lines
 
3559
#if !wxCHECK_VERSION(2, 5, 0)
 
3560
            wxPen pen (wxSystemSettings::GetSystemColour (wxSYS_COLOUR_3DLIGHT ), 1, wxSOLID);
 
3561
#else
 
3562
            wxPen pen (wxSystemSettings::GetColour (wxSYS_COLOUR_3DLIGHT ), 1, wxSOLID);
 
3563
#endif
 
3564
            dc.SetPen ((GetBackgroundColour() == *wxWHITE)? pen: *wxWHITE_PEN);
 
3565
            dc.DrawLine (0, y_top, total_width, y_top);
 
3566
            dc.DrawLine (0, y_top+h, total_width, y_top+h);
 
3567
        }
 
3568
 
 
3569
        // draw item
 
3570
        PaintItem (item, dc);
 
3571
 
 
3572
        // restore DC objects
 
3573
        dc.SetBrush(*wxWHITE_BRUSH);
 
3574
        dc.SetPen(m_dottedPen);
 
3575
 
 
3576
        // clip to the column width
 
3577
        int clip_width = m_owner->GetHeaderWindow()->
 
3578
                            GetColumn(m_main_column).GetWidth();
 
3579
        wxDCClipper clipper(dc, x_maincol, y_top, clip_width, 10000);
 
3580
 
 
3581
        if (!HasFlag(wxTR_NO_LINES)) { // connection lines
 
3582
 
 
3583
            // draw the horizontal line here
 
3584
            dc.SetPen(m_dottedPen);
 
3585
            int x2 = x - m_indent;
 
3586
            if (x2 < (x_maincol + MARGIN)) x2 = x_maincol + MARGIN;
 
3587
            int x3 = x + (m_btnWidth-m_btnWidth2);
 
3588
            if (HasButtons()) {
 
3589
                if (item->HasPlus()) {
 
3590
                    dc.DrawLine (x2, y_mid, x - m_btnWidth2, y_mid);
 
3591
                    dc.DrawLine (x3, y_mid, x3 + LINEATROOT, y_mid);
 
3592
                }else{
 
3593
                    dc.DrawLine (x2, y_mid, x3 + LINEATROOT, y_mid);
 
3594
                }
 
3595
            }else{
 
3596
                dc.DrawLine (x2, y_mid, x - m_indent/2, y_mid);
 
3597
            }
 
3598
        }
 
3599
 
 
3600
        if (item->HasPlus() && HasButtons()) { // should the item show a button?
 
3601
 
 
3602
            if (m_imageListButtons) {
 
3603
 
 
3604
                // draw the image button here
 
3605
                int image = wxTreeItemIcon_Normal;
 
3606
                if (item->IsExpanded()) image = wxTreeItemIcon_Expanded;
 
3607
                if (item->IsSelected()) image += wxTreeItemIcon_Selected - wxTreeItemIcon_Normal;
 
3608
                int xx = x - m_btnWidth2 + MARGIN;
 
3609
                int yy = y_mid - m_btnHeight2;
 
3610
                dc.SetClippingRegion(xx, yy, m_btnWidth, m_btnHeight);
 
3611
                m_imageListButtons->Draw (image, dc, xx, yy, wxIMAGELIST_DRAW_TRANSPARENT);
 
3612
                dc.DestroyClippingRegion();
 
3613
 
 
3614
            }else if (HasFlag (wxTR_TWIST_BUTTONS)) {
 
3615
 
 
3616
                // draw the twisty button here
 
3617
                dc.SetPen(*wxBLACK_PEN);
 
3618
                dc.SetBrush(*m_hilightBrush);
 
3619
                wxPoint button[3];
 
3620
                if (item->IsExpanded()) {
 
3621
                    button[0].x = x - (m_btnWidth2+1);
 
3622
                    button[0].y = y_mid - (m_btnHeight/3);
 
3623
                    button[1].x = x + (m_btnWidth2+1);
 
3624
                    button[1].y = button[0].y;
 
3625
                    button[2].x = x;
 
3626
                    button[2].y = button[0].y + (m_btnHeight2+1);
 
3627
                }else{
 
3628
                    button[0].x = x - (m_btnWidth/3);
 
3629
                    button[0].y = y_mid - (m_btnHeight2+1);
 
3630
                    button[1].x = button[0].x;
 
3631
                    button[1].y = y_mid + (m_btnHeight2+1);
 
3632
                    button[2].x = button[0].x + (m_btnWidth2+1);
 
3633
                    button[2].y = y_mid;
 
3634
                }
 
3635
                dc.DrawPolygon(3, button);
 
3636
 
 
3637
            }else{ // if (HasFlag(wxTR_HAS_BUTTONS))
 
3638
 
 
3639
                // draw the plus sign here
 
3640
#if !wxCHECK_VERSION(2, 7, 0)
 
3641
                dc.SetPen(*wxGREY_PEN);
 
3642
                dc.SetBrush(*wxWHITE_BRUSH);
 
3643
                dc.DrawRectangle (x-m_btnWidth2, y_mid-m_btnHeight2, m_btnWidth, m_btnHeight);
 
3644
                dc.SetPen(*wxBLACK_PEN);
 
3645
                dc.DrawLine (x-(m_btnWidth2-2), y_mid, x+(m_btnWidth2-1), y_mid);
 
3646
                if (!item->IsExpanded()) { // change "-" to "+"
 
3647
                    dc.DrawLine (x, y_mid-(m_btnHeight2-2), x, y_mid+(m_btnHeight2-1));
 
3648
                }
 
3649
#else
 
3650
                wxRect rect (x-m_btnWidth2, y_mid-m_btnHeight2, m_btnWidth, m_btnHeight);
 
3651
                int flag = item->IsExpanded()? wxCONTROL_EXPANDED: 0;
 
3652
                wxRendererNative::GetDefault().DrawTreeItemButton (this, dc, rect, flag);
 
3653
#endif
 
3654
 
 
3655
            }
 
3656
 
 
3657
        }
 
3658
 
 
3659
    }
 
3660
 
 
3661
    // restore DC objects
 
3662
    dc.SetBrush(*wxWHITE_BRUSH);
 
3663
    dc.SetPen(m_dottedPen);
 
3664
    dc.SetTextForeground(*wxBLACK);
 
3665
 
 
3666
    if (item->IsExpanded())
 
3667
    {
 
3668
        wxArrayTreeListItems& children = item->GetChildren();
 
3669
 
 
3670
        // clip to the column width
 
3671
        int clip_width = m_owner->GetHeaderWindow()->
 
3672
                            GetColumn(m_main_column).GetWidth();
 
3673
 
 
3674
        // process lower levels
 
3675
        int oldY;
 
3676
        if (m_imgWidth > 0) {
 
3677
            oldY = y_mid + m_imgHeight2;
 
3678
        }else{
 
3679
            oldY = y_mid + h/2;
 
3680
        }
 
3681
        int y2;
 
3682
        for (size_t n = 0; n < children.Count(); ++n) {
 
3683
 
 
3684
            y2 = y + h/2;
 
3685
            PaintLevel (children[n], dc, level+1, y, x_maincol);
 
3686
 
 
3687
            // draw vertical line
 
3688
            wxDCClipper clipper(dc, x_maincol, y_top, clip_width, 10000);
 
3689
            if (!HasFlag (wxTR_NO_LINES)) {
 
3690
                x = item->GetX();
 
3691
                dc.DrawLine (x, oldY, x, y2);
 
3692
                oldY = y2;
 
3693
            }
 
3694
        }
 
3695
    }
 
3696
}
 
3697
 
 
3698
 
 
3699
// ----------------------------------------------------------------------------
 
3700
// wxWindows callbacks
 
3701
// ----------------------------------------------------------------------------
 
3702
 
 
3703
void wxTreeListMainWindow::OnPaint (wxPaintEvent &WXUNUSED(event)) {
 
3704
 
 
3705
    // init device context, clear background (BEFORE changing DC origin...)
 
3706
    wxAutoBufferedPaintDC dc (this);
 
3707
    wxBrush brush(GetBackgroundColour(), wxSOLID);
 
3708
    dc.SetBackground(brush);
 
3709
    dc.Clear();
 
3710
    DoPrepareDC (dc);
 
3711
 
 
3712
    if (!m_rootItem || (GetColumnCount() <= 0)) return;
 
3713
 
 
3714
    // calculate button size
 
3715
    if (m_imageListButtons) {
 
3716
        m_imageListButtons->GetSize (0, m_btnWidth, m_btnHeight);
 
3717
    }else if (HasButtons()) {
 
3718
        m_btnWidth = BTNWIDTH;
 
3719
        m_btnHeight = BTNHEIGHT;
 
3720
    }
 
3721
    m_btnWidth2 = m_btnWidth/2;
 
3722
    m_btnHeight2 = m_btnHeight/2;
 
3723
 
 
3724
    // calculate image size
 
3725
    if (m_imageListNormal) {
 
3726
        m_imageListNormal->GetSize (0, m_imgWidth, m_imgHeight);
 
3727
    }
 
3728
    m_imgWidth2 = m_imgWidth/2;
 
3729
    m_imgHeight2 = m_imgHeight/2;
 
3730
 
 
3731
    // calculate indent size
 
3732
    if (m_imageListButtons) {
 
3733
        m_indent = wxMax (MININDENT, m_btnWidth + MARGIN);
 
3734
    }else if (HasButtons()) {
 
3735
        m_indent = wxMax (MININDENT, m_btnWidth + LINEATROOT);
 
3736
    }
 
3737
 
 
3738
    // set default values
 
3739
    dc.SetFont( m_normalFont );
 
3740
    dc.SetPen( m_dottedPen );
 
3741
 
 
3742
    // calculate column start and paint
 
3743
    int x_maincol = 0;
 
3744
    int i = 0;
 
3745
    for (i = 0; i < (int)GetMainColumn(); ++i) {
 
3746
        if (!m_owner->GetHeaderWindow()->IsColumnShown(i)) continue;
 
3747
        x_maincol += m_owner->GetHeaderWindow()->GetColumnWidth (i);
 
3748
    }
 
3749
    int y = 0;
 
3750
    PaintLevel (m_rootItem, dc, 0, y, x_maincol);
 
3751
}
 
3752
 
 
3753
void wxTreeListMainWindow::OnSetFocus (wxFocusEvent &event) {
 
3754
    m_hasFocus = true;
 
3755
    RefreshSelected();
 
3756
    if (m_curItem) RefreshLine (m_curItem);
 
3757
    event.Skip();
 
3758
}
 
3759
 
 
3760
void wxTreeListMainWindow::OnKillFocus( wxFocusEvent &event )
 
3761
{
 
3762
    m_hasFocus = false;
 
3763
    RefreshSelected();
 
3764
    if (m_curItem) RefreshLine (m_curItem);
 
3765
    event.Skip();
 
3766
}
 
3767
 
 
3768
void wxTreeListMainWindow::OnChar (wxKeyEvent &event) {
 
3769
    // send event to user code
 
3770
    wxTreeEvent nevent (wxEVT_COMMAND_TREE_KEY_DOWN, 0 );
 
3771
    nevent.SetInt(m_curColumn);
 
3772
    nevent.SetKeyEvent (event);
 
3773
    if (SendEvent(0, NULL, &nevent)) return; // char event handled in user code
 
3774
 
 
3775
    // if no item current, select root
 
3776
    bool curItemSet = false;
 
3777
    if (!m_curItem) {
 
3778
        if (! GetRootItem().IsOk()) return;
 
3779
        SetCurrentItem((wxTreeListItem*)GetRootItem().m_pItem);
 
3780
        if (HasFlag(wxTR_HIDE_ROOT)) {
 
3781
#if !wxCHECK_VERSION(2, 5, 0)
 
3782
            long cookie = 0;
 
3783
#else
 
3784
            wxTreeItemIdValue cookie = 0;
 
3785
#endif
 
3786
            SetCurrentItem((wxTreeListItem*)GetFirstChild (m_curItem, cookie).m_pItem);
 
3787
        }
 
3788
        SelectItem(m_curItem, (wxTreeItemId*)NULL, true);  // unselect others
 
3789
        curItemSet = true;
 
3790
    }
 
3791
 
 
3792
    // remember item at shift down
 
3793
    if (HasFlag(wxTR_MULTIPLE) && event.ShiftDown()) {
 
3794
        if (!m_shiftItem) m_shiftItem = m_curItem;
 
3795
    }else{
 
3796
        m_shiftItem = (wxTreeListItem*)NULL;
 
3797
    }
 
3798
 
 
3799
    if (curItemSet) return;  // if no item was current until now, do nothing more
 
3800
 
 
3801
    // process all cases
 
3802
    wxTreeItemId newItem = (wxTreeItemId*)NULL;
 
3803
    switch (event.GetKeyCode()) {
 
3804
 
 
3805
        // '+': Expand subtree
 
3806
        case '+':
 
3807
        case WXK_ADD: {
 
3808
            if (m_curItem->HasPlus() && !IsExpanded (m_curItem)) Expand (m_curItem);
 
3809
        }break;
 
3810
 
 
3811
        // '-': collapse subtree
 
3812
        case '-':
 
3813
        case WXK_SUBTRACT: {
 
3814
            if (m_curItem->HasPlus() && IsExpanded (m_curItem)) Collapse (m_curItem);
 
3815
        }break;
 
3816
 
 
3817
        // '*': expand/collapse all subtrees // TODO: Mak it more useful
 
3818
        case '*':
 
3819
        case WXK_MULTIPLY: {
 
3820
            if (m_curItem->HasPlus() && !IsExpanded (m_curItem)) {
 
3821
                ExpandAll (m_curItem);
 
3822
            }else if (m_curItem->HasPlus()) {
 
3823
                Collapse (m_curItem); // TODO: CollapseAll
 
3824
            }
 
3825
        }break;
 
3826
 
 
3827
        // ' ': toggle current item
 
3828
        case ' ': {
 
3829
            SelectItem (m_curItem, (wxTreeListItem*)NULL, false);
 
3830
        }break;
 
3831
 
 
3832
        // <RETURN>: activate current item
 
3833
        case WXK_RETURN: {
 
3834
            if (! SendEvent(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, m_curItem)) {
 
3835
 
 
3836
                // if the user code didn't process the activate event,
 
3837
                // handle it ourselves by toggling the item when it is
 
3838
                // double clicked
 
3839
                if (m_curItem && m_curItem->HasPlus()) Toggle(m_curItem);
 
3840
            }
 
3841
        }break;
 
3842
 
 
3843
        // <BKSP>: go to the parent without collapsing
 
3844
        case WXK_BACK: {
 
3845
            newItem = GetItemParent (m_curItem);
 
3846
            if ((newItem == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) {
 
3847
                newItem = GetPrevSibling (m_curItem); // get sibling instead of root
 
3848
            }
 
3849
        }break;
 
3850
 
 
3851
        // <HOME>: go to first visible
 
3852
        case WXK_HOME: {
 
3853
            newItem = GetFirstVisible(false, false);
 
3854
        }break;
 
3855
 
 
3856
        // <PAGE-UP>: go to the top of the page, or if we already are then one page back
 
3857
        case WXK_PAGEUP: {
 
3858
        int flags = 0;
 
3859
        int col = 0;
 
3860
        wxPoint abs_p = CalcUnscrolledPosition (wxPoint(1,1));
 
3861
        // PAGE-UP: first go the the first visible row
 
3862
            newItem = m_rootItem->HitTest(abs_p, this, flags, col, 0);
 
3863
            newItem = GetFirstVisible(false, true);
 
3864
        // if we are already there then scroll back one page
 
3865
            if (newItem == m_curItem) {
 
3866
                abs_p.y -= GetClientSize().GetHeight() - m_curItem->GetHeight();
 
3867
                if (abs_p.y < 0) abs_p.y = 0;
 
3868
                newItem = m_rootItem->HitTest(abs_p, this, flags, col, 0);
 
3869
            }
 
3870
            // newItem should never be NULL
 
3871
        } break;
 
3872
 
 
3873
        // <UP>: go to the previous sibling or for the last of its children, to the parent
 
3874
        case WXK_UP: {
 
3875
            newItem = GetPrevSibling (m_curItem);
 
3876
            if (newItem) {
 
3877
#if !wxCHECK_VERSION(2, 5, 0)
 
3878
                long cookie = 0;
 
3879
#else
 
3880
                wxTreeItemIdValue cookie = 0;
 
3881
#endif
 
3882
                while (IsExpanded (newItem) && HasChildren (newItem)) {
 
3883
                    newItem = GetLastChild (newItem, cookie);
 
3884
                }
 
3885
            }else {
 
3886
                newItem = GetItemParent (m_curItem);
 
3887
                if ((newItem == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) {
 
3888
                    newItem = (wxTreeItemId*)NULL; // don't go to root if it is hidden
 
3889
                }
 
3890
            }
 
3891
        }break;
 
3892
 
 
3893
        // <LEFT>: if expanded collapse subtree, else go to the parent
 
3894
        case WXK_LEFT: {
 
3895
            if (IsExpanded (m_curItem)) {
 
3896
                Collapse (m_curItem);
 
3897
            }else{
 
3898
                newItem = GetItemParent (m_curItem);
 
3899
                if ((newItem == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) {
 
3900
                    newItem = GetPrevSibling (m_curItem); // go to sibling if it is hidden
 
3901
                }
 
3902
            }
 
3903
        }break;
 
3904
 
 
3905
        // <RIGHT>: if possible expand subtree, else go go to the first child
 
3906
        case WXK_RIGHT: {
 
3907
            if (m_curItem->HasPlus() && !IsExpanded (m_curItem)) {
 
3908
                Expand (m_curItem);
 
3909
            }else{
 
3910
                if (IsExpanded (m_curItem) && HasChildren (m_curItem)) {
 
3911
#if !wxCHECK_VERSION(2, 5, 0)
 
3912
                    long cookie = 0;
 
3913
#else
 
3914
                    wxTreeItemIdValue cookie = 0;
 
3915
#endif
 
3916
                    newItem = GetFirstChild (m_curItem, cookie);
 
3917
                }
 
3918
            }
 
3919
        }break;
 
3920
 
 
3921
        // <DOWN>: if expanded go to the first child, else to the next sibling, ect
 
3922
        case WXK_DOWN: {
 
3923
            if (IsExpanded (m_curItem) && HasChildren (m_curItem)) {
 
3924
#if !wxCHECK_VERSION(2, 5, 0)
 
3925
                long cookie = 0;
 
3926
#else
 
3927
                wxTreeItemIdValue cookie = 0;
 
3928
#endif
 
3929
                newItem = GetFirstChild( m_curItem, cookie );
 
3930
            }
 
3931
            if (!newItem) {
 
3932
                wxTreeItemId parent = m_curItem;
 
3933
                do {
 
3934
                    newItem = GetNextSibling (parent);
 
3935
                    parent = GetItemParent (parent);
 
3936
                } while (!newItem && parent);
 
3937
            }
 
3938
        }break;
 
3939
 
 
3940
        // <PAGE-DOWN>: go to the bottom of the page, or if we already are then one page further
 
3941
        case WXK_PAGEDOWN: {
 
3942
        int flags = 0;
 
3943
        int col = 0;
 
3944
        wxPoint abs_p = CalcUnscrolledPosition (wxPoint(1,GetClientSize().GetHeight() - m_curItem->GetHeight()));
 
3945
        // PAGE-UP: first go the the first visible row
 
3946
            newItem = m_rootItem->HitTest(abs_p, this, flags, col, 0);
 
3947
            newItem = GetLastVisible(false, true);
 
3948
        // if we are already there then scroll down one page
 
3949
            if (newItem == m_curItem) {
 
3950
                abs_p.y += GetClientSize().GetHeight() - m_curItem->GetHeight();
 
3951
//                if (abs_p.y >= GetVirtualSize().GetHeight()) abs_p.y = GetVirtualSize().GetHeight() - 1;
 
3952
                newItem = m_rootItem->HitTest(abs_p, this, flags, col, 0);
 
3953
            }
 
3954
        // if we reached the empty area below the rows, return last item instead
 
3955
            if (! newItem) newItem = GetLastVisible(false, false);
 
3956
        } break;
 
3957
 
 
3958
        // <END>: go to last item of the root
 
3959
        case WXK_END: {
 
3960
            newItem = GetLastVisible (false, false);
 
3961
        }break;
 
3962
 
 
3963
        // any char: go to the next matching string
 
3964
        default:
 
3965
            if (event.GetKeyCode() >= (int)' ') {
 
3966
                if (!m_findTimer->IsRunning()) m_findStr.Clear();
 
3967
                m_findStr.Append (event.GetKeyCode());
 
3968
                m_findTimer->Start (FIND_TIMER_TICKS, wxTIMER_ONE_SHOT);
 
3969
                wxTreeItemId prev = m_curItem? (wxTreeItemId*)m_curItem: (wxTreeItemId*)NULL;
 
3970
                while (true) {
 
3971
                    newItem = FindItem (prev, GetCurrentColumn(), m_findStr, wxTL_MODE_NAV_EXPANDED | wxTL_MODE_FIND_PARTIAL | wxTL_MODE_FIND_NOCASE);
 
3972
                    if (newItem || (m_findStr.Length() <= 1)) break;
 
3973
                    m_findStr.RemoveLast();
 
3974
                };
 
3975
            }
 
3976
            event.Skip();
 
3977
 
 
3978
    }
 
3979
 
 
3980
    // select and show the new item
 
3981
    if (newItem) {
 
3982
        if (!event.ControlDown()) {
 
3983
            bool unselect_others = !((event.ShiftDown() || event.ControlDown()) &&
 
3984
                                      HasFlag(wxTR_MULTIPLE));
 
3985
            SelectItem (newItem, m_shiftItem, unselect_others);
 
3986
        }
 
3987
        EnsureVisible (newItem);
 
3988
        wxTreeListItem *oldItem = m_curItem;
 
3989
        SetCurrentItem((wxTreeListItem*)newItem.m_pItem); // make the new item the current item
 
3990
        RefreshLine (oldItem);
 
3991
    }
 
3992
 
 
3993
}
 
3994
 
 
3995
wxTreeItemId wxTreeListMainWindow::HitTest (const wxPoint& point, int& flags, int& column) {
 
3996
 
 
3997
    int w, h;
 
3998
    GetSize(&w, &h);
 
3999
    flags=0;
 
4000
    column = -1;
 
4001
    if (point.x<0) flags |= wxTREE_HITTEST_TOLEFT;
 
4002
    if (point.x>w) flags |= wxTREE_HITTEST_TORIGHT;
 
4003
    if (point.y<0) flags |= wxTREE_HITTEST_ABOVE;
 
4004
    if (point.y>h) flags |= wxTREE_HITTEST_BELOW;
 
4005
    if (flags) return wxTreeItemId();
 
4006
 
 
4007
    if (!m_rootItem) {
 
4008
        flags = wxTREE_HITTEST_NOWHERE;
 
4009
        column = -1;
 
4010
        return wxTreeItemId();
 
4011
    }
 
4012
 
 
4013
    wxTreeListItem *hit = m_rootItem->HitTest (CalcUnscrolledPosition(point),
 
4014
                                               this, flags, column, 0);
 
4015
    if (!hit) {
 
4016
        flags = wxTREE_HITTEST_NOWHERE;
 
4017
        column = -1;
 
4018
        return wxTreeItemId();
 
4019
    }
 
4020
    return hit;
 
4021
}
 
4022
 
 
4023
// get the bounding rectangle of the item (or of its label only)
 
4024
bool wxTreeListMainWindow::GetBoundingRect (const wxTreeItemId& itemId, wxRect& rect,
 
4025
                                            bool WXUNUSED(textOnly)) const {
 
4026
    wxCHECK_MSG (itemId.IsOk(), false, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") );
 
4027
 
 
4028
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
4029
 
 
4030
    int xUnit, yUnit;
 
4031
    GetScrollPixelsPerUnit (&xUnit, &yUnit);
 
4032
    int startX, startY;
 
4033
    GetViewStart(& startX, & startY);
 
4034
 
 
4035
    rect.x = item->GetX() - startX * xUnit;
 
4036
    rect.y = item->GetY() - startY * yUnit;
 
4037
    rect.width = item->GetWidth();
 
4038
    rect.height = GetLineHeight (item);
 
4039
 
 
4040
    return true;
 
4041
}
 
4042
 
 
4043
/* **** */
 
4044
 
 
4045
void wxTreeListMainWindow::EditLabel (const wxTreeItemId& item, int column) {
 
4046
 
 
4047
// validate
 
4048
    if (!item.IsOk()) return;
 
4049
    if (!((column >= 0) && (column < GetColumnCount()))) return;
 
4050
 
 
4051
// cancel any editing
 
4052
    if (m_editControl) { m_editControl->EndEdit(true); }  // cancelled
 
4053
 
 
4054
// prepare edit (position)
 
4055
    m_editItem = (wxTreeListItem*) item.m_pItem;
 
4056
 
 
4057
    wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, 0 );
 
4058
    te.SetInt (column);
 
4059
    SendEvent(0, m_editItem, &te); if (!te.IsAllowed()) return;
 
4060
 
 
4061
    // ensure that the position of the item it calculated in any case
 
4062
    if (m_dirty) CalculatePositions();
 
4063
 
 
4064
    wxTreeListHeaderWindow* header_win = m_owner->GetHeaderWindow();
 
4065
 
 
4066
    // position & size are rather unpredictable (tsssk, tssssk) so were
 
4067
    //  set by trial & error (on Win 2003 pre-XP style)
 
4068
    int x = 0;
 
4069
    int w = +4;  // +4 is necessary, don't know why (simple border erronously counted somewhere ?)
 
4070
    int y = m_editItem->GetY() + 1;  // this is cell, not text
 
4071
    int h = m_editItem->GetHeight() - 1;  // consequence from above
 
4072
    long style = 0;
 
4073
    if (column == GetMainColumn()) {
 
4074
        x += m_editItem->GetTextX() - 2;  // wrong by 2, don't know why
 
4075
        w += m_editItem->GetWidth();
 
4076
    } else {
 
4077
        for (int i = 0; i < column; ++i) {
 
4078
            if ( header_win->IsColumnShown(i) ) {
 
4079
                x += header_win->GetColumnWidth (i); // start of column
 
4080
            }
 
4081
                }
 
4082
        w += header_win->GetColumnWidth (column);  // currently non-main column width not pre-computed
 
4083
    }
 
4084
    switch (header_win->GetColumnAlignment (column)) {
 
4085
        case wxALIGN_LEFT:   {style = wxTE_LEFT;   x -= 1; break;}
 
4086
        case wxALIGN_CENTER: {style = wxTE_CENTER; x -= 1; break;}
 
4087
        case wxALIGN_RIGHT:  {style = wxTE_RIGHT;  x += 0; break;}  // yes, strange but that's the way it is
 
4088
    }
 
4089
    // wxTextCtrl simple border style requires 2 extra pixels before and after
 
4090
    //  (measured by changing to style wxNO_BORDER in wxEditTextCtrl::wxEditTextCtrl() )
 
4091
    y -= 2; x -= 2;
 
4092
    w += 4; h += 4;
 
4093
 
 
4094
    wxClientDC dc (this);
 
4095
    PrepareDC (dc);
 
4096
    x = dc.LogicalToDeviceX (x);
 
4097
    y = dc.LogicalToDeviceY (y);
 
4098
 
 
4099
// now do edit (change state, show control)
 
4100
    m_editCol = column;  // only used in OnRenameAccept()
 
4101
    m_editControl = new wxEditTextCtrl (this, -1, &m_editAccept, &m_editRes,
 
4102
                                               this, m_editItem->GetText (column),
 
4103
                                               wxPoint (x, y), wxSize (w, h), style);
 
4104
    m_editControl->SetFocus();
 
4105
}
 
4106
 
 
4107
void wxTreeListMainWindow::OnRenameTimer() {
 
4108
    EditLabel (m_curItem, GetCurrentColumn());
 
4109
}
 
4110
 
 
4111
void wxTreeListMainWindow::OnRenameAccept(bool isCancelled) {
 
4112
 
 
4113
    // TODO if the validator fails this causes a crash
 
4114
    wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, 0 );
 
4115
    le.SetLabel( m_editRes );
 
4116
    le.SetEditCanceled(isCancelled);
 
4117
    le.SetInt(m_editCol);
 
4118
    SendEvent(0, m_editItem, &le); if (! isCancelled  && le.IsAllowed())
 
4119
    {
 
4120
        SetItemText (m_editItem, le.GetInt(), le.GetLabel());
 
4121
    }
 
4122
}
 
4123
 
 
4124
void wxTreeListMainWindow::EndEdit(bool /*isCancelled*/) {
 
4125
    if (m_editControl) { m_editControl->EndEdit(true); }
 
4126
}
 
4127
 
 
4128
void wxTreeListMainWindow::OnMouse (wxMouseEvent &event) {
 
4129
bool mayDrag = true;
 
4130
bool maySelect = true;  // may change selection
 
4131
bool mayClick = true;  // may process DOWN clicks to expand, send click events
 
4132
bool mayDoubleClick = true;  // implies mayClick
 
4133
bool bSkip = true;
 
4134
 
 
4135
    // send event to user code
 
4136
    if (m_owner->GetEventHandler()->ProcessEvent(event)) return; // handled (and not skipped) in user code
 
4137
    if (!m_rootItem) return;
 
4138
 
 
4139
 
 
4140
// ---------- DETERMINE EVENT ----------
 
4141
/*
 
4142
wxLogMessage("OnMouse: LMR down=<%d, %d, %d> up=<%d, %d, %d> LDblClick=<%d> dragging=<%d>",
 
4143
    event.LeftDown(), event.MiddleDown(), event.RightDown(),
 
4144
    event.LeftUp(), event.MiddleUp(), event.RightUp(),
 
4145
    event.LeftDClick(), event.Dragging());
 
4146
*/
 
4147
    wxPoint p = wxPoint (event.GetX(), event.GetY());
 
4148
    int flags = 0;
 
4149
    wxTreeListItem *item = m_rootItem->HitTest (CalcUnscrolledPosition (p),
 
4150
                                                this, flags, m_curColumn, 0);
 
4151
    bool bCrosshair = (item && item->HasPlus() && (flags & wxTREE_HITTEST_ONITEMBUTTON));
 
4152
    // we were dragging
 
4153
    if (m_isDragging) {
 
4154
        maySelect = mayDoubleClick = false;
 
4155
    }
 
4156
    // we are starting or continuing to drag
 
4157
    if (event.Dragging()) {
 
4158
        maySelect = mayDoubleClick = mayClick = false;
 
4159
    }
 
4160
    // crosshair area is special
 
4161
    if (bCrosshair) {
 
4162
        // left click does not select
 
4163
        if (event.LeftDown()) maySelect = false;
 
4164
        // double click is ignored
 
4165
        mayDoubleClick = false;
 
4166
    }
 
4167
    // double click only if simple click
 
4168
    if (mayDoubleClick) mayDoubleClick = mayClick;
 
4169
    // selection conditions --remember also that selection exludes editing
 
4170
    if (maySelect) maySelect = mayClick;  // yes, select/unselect requires a click
 
4171
    if (maySelect) {
 
4172
 
 
4173
        // multiple selection mode complicates things, sometimes we
 
4174
        //  select on button-up instead of down:
 
4175
        if (HasFlag(wxTR_MULTIPLE)) {
 
4176
 
 
4177
            // CONTROL/SHIFT key used, don't care about anything else, will
 
4178
            //  toggle on key down
 
4179
            if (event.ControlDown() || event.ShiftDown()) {
 
4180
                maySelect = maySelect && (event.LeftDown() || event.RightDown());
 
4181
                m_lastOnSame = false;  // prevent editing when keys are used
 
4182
 
 
4183
            // already selected item: to allow drag or contextual menu for multiple
 
4184
            //  items, we only select/unselect on click-up --and only on LEFT
 
4185
            // click, right is reserved for contextual menu
 
4186
            } else if ((item != NULL && item->IsSelected())) {
 
4187
                maySelect = maySelect && event.LeftUp();
 
4188
 
 
4189
            // non-selected items: select on click-down like simple select (so
 
4190
            //  that a right-click contextual menu may be chained)
 
4191
            } else {
 
4192
                maySelect = maySelect && (event.LeftDown() || event.RightDown());
 
4193
            }
 
4194
 
 
4195
        // single-select is simply on left or right click-down
 
4196
        } else {
 
4197
            maySelect = maySelect && (event.LeftDown() || event.RightDown());
 
4198
        }
 
4199
    }
 
4200
 
 
4201
 
 
4202
// ----------  GENERAL ACTIONS  ----------
 
4203
 
 
4204
    // set focus if window clicked
 
4205
    if (event.LeftDown() || event.MiddleDown() || event.RightDown()) SetFocus();
 
4206
 
 
4207
    // tooltip change ?
 
4208
    if (item != m_toolTipItem) {
 
4209
 
 
4210
        // not over an item, use global tip
 
4211
        if (item == NULL) {
 
4212
            m_toolTipItem = NULL;
 
4213
            wxScrolledWindow::SetToolTip(m_toolTip);
 
4214
 
 
4215
        // over an item
 
4216
        } else {
 
4217
            const wxString *tip = item->GetToolTip();
 
4218
 
 
4219
            // is there an item-specific tip ?
 
4220
            if (tip) {
 
4221
                m_toolTipItem = item;
 
4222
                wxScrolledWindow::SetToolTip(*tip);
 
4223
 
 
4224
            // no item tip, but we are in item-specific mode (SetItemToolTip()
 
4225
            //  was called after SetToolTip() )
 
4226
            } else if (m_isItemToolTip) {
 
4227
                m_toolTipItem = item;
 
4228
                wxScrolledWindow::SetToolTip(wxString());
 
4229
 
 
4230
            // no item tip, display global tip instead; item change ignored
 
4231
            } else if (m_toolTipItem != NULL) {
 
4232
                m_toolTipItem = NULL;
 
4233
                wxScrolledWindow::SetToolTip(m_toolTip);
 
4234
            }
 
4235
        }
 
4236
    }
 
4237
 
 
4238
 
 
4239
// ----------  HANDLE SIMPLE-CLICKS  (selection change, contextual menu) ----------
 
4240
    if (mayClick) {
 
4241
 
 
4242
        // 2nd left-click on an item might trigger edit
 
4243
        if (event.LeftDown()) m_lastOnSame = (item == m_curItem);
 
4244
 
 
4245
        // left-click on haircross is expand (and no select)
 
4246
        if (bCrosshair && event.LeftDown()) {
 
4247
 
 
4248
            bSkip = false;
 
4249
 
 
4250
            // note that we only toggle the item for a single click, double
 
4251
            // click on the button doesn't do anything
 
4252
            Toggle (item);
 
4253
        }
 
4254
 
 
4255
        if (maySelect) {
 
4256
            bSkip = false;
 
4257
 
 
4258
            // set / remember item at shift down before current item gets changed
 
4259
            if (event.LeftDown() && HasFlag(wxTR_MULTIPLE) && event.ShiftDown())  {
 
4260
                if (!m_shiftItem) m_shiftItem = m_curItem;
 
4261
            }else{
 
4262
                m_shiftItem = (wxTreeListItem*)NULL;
 
4263
            }
 
4264
 
 
4265
            // how is selection altered
 
4266
            // keep or discard already selected ?
 
4267
            bool unselect_others = ! (HasFlag(wxTR_MULTIPLE) && (
 
4268
                event.ShiftDown()
 
4269
             || event.ControlDown()
 
4270
            ));
 
4271
 
 
4272
            // check is selection change is not vetoed
 
4273
            if (SelectItem(item, m_shiftItem, unselect_others)) {
 
4274
                // make the new item the current item
 
4275
                EnsureVisible (item);
 
4276
                SetCurrentItem(item);
 
4277
            }
 
4278
        }
 
4279
 
 
4280
        // generate click & menu events
 
4281
        if (event.MiddleDown()) {
 
4282
            bSkip = false;
 
4283
            SendEvent(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, item);
 
4284
        }
 
4285
        if (event.RightDown()) {
 
4286
            bSkip = false;
 
4287
            SendEvent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, item);
 
4288
        }
 
4289
        if (event.RightUp()) {
 
4290
            wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_MENU, 0);
 
4291
            nevent.SetPoint(p);
 
4292
            nevent.SetInt(m_curColumn);
 
4293
            SendEvent(0, item, &nevent);
 
4294
        }
 
4295
 
 
4296
        // if 2nd left click finishes on same item, will edit it
 
4297
        if (m_lastOnSame && event.LeftUp()) {
 
4298
            if ((item == m_curItem) && (m_curColumn != -1) &&
 
4299
                (m_owner->GetHeaderWindow()->IsColumnEditable (m_curColumn)) &&
 
4300
                (flags & (wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMCOLUMN))
 
4301
            ){
 
4302
                m_editTimer->Start (RENAME_TIMER_TICKS, wxTIMER_ONE_SHOT);
 
4303
                bSkip = false;
 
4304
            }
 
4305
            m_lastOnSame = false;
 
4306
        }
 
4307
    }
 
4308
 
 
4309
 
 
4310
// ----------  HANDLE DOUBLE-CLICKS  ----------
 
4311
    if (mayDoubleClick && event.LeftDClick()) {
 
4312
 
 
4313
        bSkip = false;
 
4314
 
 
4315
        // double clicking should not start editing the item label
 
4316
        m_editTimer->Stop();
 
4317
        m_lastOnSame = false;
 
4318
 
 
4319
        // selection reset to that single item which was double-clicked
 
4320
        if (SelectItem(item, (wxTreeItemId*)NULL, true)) {  // unselect others --return false if vetoed
 
4321
 
 
4322
            // selection change not vetoed, send activate event
 
4323
            if (! SendEvent(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, item)) {
 
4324
 
 
4325
                // if the user code didn't process the activate event,
 
4326
                // handle it ourselves by toggling the item when it is
 
4327
                // double clicked
 
4328
                if (item && item->HasPlus()) Toggle(item);
 
4329
            }
 
4330
        }
 
4331
    }
 
4332
 
 
4333
 
 
4334
// ----------  HANDLE DRAGGING  ----------
 
4335
// NOTE: drag itself makes no change to selection
 
4336
    if (mayDrag) {  // actually this is always true
 
4337
 
 
4338
        // CASE 1: we were dragging => continue, end, abort
 
4339
        if (m_isDragging) {
 
4340
 
 
4341
            // CASE 1.1: click aborts drag:
 
4342
            if (event.LeftDown() || event.MiddleDown() || event.RightDown()) {
 
4343
 
 
4344
                bSkip = false;
 
4345
 
 
4346
                // stop dragging
 
4347
                m_isDragStarted = m_isDragging = false;
 
4348
                if (HasCapture()) ReleaseMouse();
 
4349
                RefreshSelected();
 
4350
 
 
4351
            // CASE 1.2: still dragging
 
4352
            } else if (event.Dragging()) {
 
4353
 
 
4354
                ;; // nothing to do
 
4355
 
 
4356
            // CASE 1.3: dragging now ends normally
 
4357
            } else {
 
4358
 
 
4359
                bSkip = false;
 
4360
 
 
4361
                // stop dragging
 
4362
                m_isDragStarted = m_isDragging = false;
 
4363
                if (HasCapture()) ReleaseMouse();
 
4364
                RefreshSelected();
 
4365
 
 
4366
                // send drag end event
 
4367
                wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, 0);
 
4368
                event.SetPoint(p);
 
4369
                event.SetInt(m_curColumn);
 
4370
                SendEvent(0, item, &event);
 
4371
            }
 
4372
 
 
4373
        // CASE 2: not were not dragging => continue, start
 
4374
        } else if (event.Dragging()) {
 
4375
 
 
4376
            // We will really start dragging if we've moved beyond a few pixels
 
4377
            if (m_isDragStarted) {
 
4378
                const int tolerance = 3;
 
4379
                int dx = abs(p.x - m_dragStartPos.x);
 
4380
                int dy = abs(p.y - m_dragStartPos.y);
 
4381
                if (dx <= tolerance && dy <= tolerance)
 
4382
                    return;
 
4383
            // determine drag start
 
4384
            } else {
 
4385
                m_dragStartPos = p;
 
4386
                m_dragCol = GetCurrentColumn();
 
4387
                m_dragItem = item;
 
4388
                m_isDragStarted = true;
 
4389
                return;
 
4390
            }
 
4391
 
 
4392
            bSkip = false;
 
4393
 
 
4394
            // we are now dragging
 
4395
            m_isDragging = true;
 
4396
            RefreshSelected();
 
4397
            CaptureMouse(); // TODO: usefulness unclear
 
4398
 
 
4399
            wxTreeEvent nevent(event.LeftIsDown()
 
4400
                                  ? wxEVT_COMMAND_TREE_BEGIN_DRAG
 
4401
                                  : wxEVT_COMMAND_TREE_BEGIN_RDRAG, 0);
 
4402
            nevent.SetPoint(p);
 
4403
            nevent.SetInt(m_dragCol);
 
4404
            nevent.Veto();
 
4405
            SendEvent(0, m_dragItem, &nevent);
 
4406
        }
 
4407
    }
 
4408
 
 
4409
 
 
4410
    if (bSkip) event.Skip();
 
4411
}
 
4412
 
 
4413
 
 
4414
void wxTreeListMainWindow::OnIdle (wxIdleEvent &WXUNUSED(event)) {
 
4415
    /* after all changes have been done to the tree control,
 
4416
     * we actually redraw the tree when everything is over */
 
4417
 
 
4418
    if (!m_dirty) return;
 
4419
 
 
4420
    m_dirty = false;
 
4421
 
 
4422
    CalculatePositions();
 
4423
    Refresh();
 
4424
    AdjustMyScrollbars();
 
4425
}
 
4426
 
 
4427
void wxTreeListMainWindow::OnScroll (wxScrollWinEvent& event) {
 
4428
 
 
4429
    // send event to wxTreeListCtrl (for user code)
 
4430
    if (m_owner->GetEventHandler()->ProcessEvent(event)) return; // handled (and not skipped) in user code
 
4431
 
 
4432
    // TODO
 
4433
#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
 
4434
    wxScrolledWindow::OnScroll(event);
 
4435
#else
 
4436
    HandleOnScroll( event );
 
4437
#endif
 
4438
 
 
4439
    if(event.GetOrientation() == wxHORIZONTAL) {
 
4440
        m_owner->GetHeaderWindow()->Refresh();
 
4441
        m_owner->GetHeaderWindow()->Update();
 
4442
    }
 
4443
}
 
4444
 
 
4445
void wxTreeListMainWindow::CalculateSize (wxTreeListItem *item, wxDC &dc) {
 
4446
    wxCoord text_w = 0;
 
4447
    wxCoord text_h = 0;
 
4448
 
 
4449
    dc.SetFont (GetItemFont (item));
 
4450
    dc.GetTextExtent (item->GetText(m_main_column).size() > 0
 
4451
            ? item->GetText (m_main_column)
 
4452
            : _T(" "),  // blank to avoid zero height and no highlight width
 
4453
        &text_w, &text_h);
 
4454
    // restore normal font
 
4455
    dc.SetFont (m_normalFont);
 
4456
 
 
4457
    int max_h = (m_imgHeight > text_h) ? m_imgHeight : text_h;
 
4458
    if (max_h < 30) { // add 10% space if greater than 30 pixels
 
4459
        max_h += 2; // minimal 2 pixel space
 
4460
    }else{
 
4461
        max_h += max_h / 10; // otherwise 10% space
 
4462
    }
 
4463
 
 
4464
    item->SetHeight (max_h);
 
4465
    if (max_h > m_lineHeight) m_lineHeight = max_h;
 
4466
    item->SetWidth(m_imgWidth + text_w+2);
 
4467
}
 
4468
 
 
4469
// -----------------------------------------------------------------------------
 
4470
void wxTreeListMainWindow::CalculateLevel (wxTreeListItem *item, wxDC &dc,
 
4471
                                           int level, int &y, int x_colstart) {
 
4472
 
 
4473
    // calculate position of vertical lines
 
4474
    int x = x_colstart + MARGIN; // start of column
 
4475
    if (HasFlag(wxTR_LINES_AT_ROOT)) x += LINEATROOT; // space for lines at root
 
4476
    if (HasButtons()) {
 
4477
        x += (m_btnWidth-m_btnWidth2); // half button space
 
4478
    }else{
 
4479
        x += (m_indent-m_indent/2);
 
4480
    }
 
4481
    if (HasFlag(wxTR_HIDE_ROOT)) {
 
4482
        x += m_indent * (level-1); // indent but not level 1
 
4483
    }else{
 
4484
        x += m_indent * level; // indent according to level
 
4485
    }
 
4486
 
 
4487
    // a hidden root is not evaluated, but its children are always
 
4488
    if (HasFlag(wxTR_HIDE_ROOT) && (level == 0)) goto Recurse;
 
4489
 
 
4490
    CalculateSize( item, dc );
 
4491
 
 
4492
    // set its position
 
4493
    item->SetX (x);
 
4494
    item->SetY (y);
 
4495
    y += GetLineHeight(item);
 
4496
 
 
4497
    // we don't need to calculate collapsed branches
 
4498
    if ( !item->IsExpanded() ) return;
 
4499
 
 
4500
Recurse:
 
4501
    wxArrayTreeListItems& children = item->GetChildren();
 
4502
    long n, count = (long)children.Count();
 
4503
    ++level;
 
4504
    for (n = 0; n < count; ++n) {
 
4505
        CalculateLevel( children[n], dc, level, y, x_colstart );  // recurse
 
4506
    }
 
4507
}
 
4508
 
 
4509
void wxTreeListMainWindow::CalculatePositions() {
 
4510
    if ( !m_rootItem ) return;
 
4511
 
 
4512
    wxClientDC dc(this);
 
4513
    PrepareDC( dc );
 
4514
 
 
4515
    dc.SetFont( m_normalFont );
 
4516
 
 
4517
    dc.SetPen( m_dottedPen );
 
4518
    //if(GetImageList() == NULL)
 
4519
    // m_lineHeight = (int)(dc.GetCharHeight() + 4);
 
4520
 
 
4521
    int y = 2;
 
4522
    int x_colstart = 0;
 
4523
    for (int i = 0; i < (int)GetMainColumn(); ++i) {
 
4524
        if (!m_owner->GetHeaderWindow()->IsColumnShown(i)) continue;
 
4525
        x_colstart += m_owner->GetHeaderWindow()->GetColumnWidth(i);
 
4526
    }
 
4527
    CalculateLevel( m_rootItem, dc, 0, y, x_colstart ); // start recursion
 
4528
}
 
4529
 
 
4530
void wxTreeListMainWindow::RefreshSubtree (wxTreeListItem *item) {
 
4531
    if (m_dirty) return;
 
4532
 
 
4533
    wxClientDC dc(this);
 
4534
    PrepareDC(dc);
 
4535
 
 
4536
    int cw = 0;
 
4537
    int ch = 0;
 
4538
    GetVirtualSize( &cw, &ch );
 
4539
 
 
4540
    wxRect rect;
 
4541
    rect.x = dc.LogicalToDeviceX( 0 );
 
4542
    rect.width = cw;
 
4543
    rect.y = dc.LogicalToDeviceY( item->GetY() - 2 );
 
4544
    rect.height = ch;
 
4545
 
 
4546
    Refresh (true, &rect );
 
4547
    AdjustMyScrollbars();
 
4548
}
 
4549
 
 
4550
void wxTreeListMainWindow::RefreshLine (wxTreeListItem *item) {
 
4551
    if (m_dirty) return;
 
4552
 
 
4553
    wxClientDC dc(this);
 
4554
    PrepareDC( dc );
 
4555
 
 
4556
    int cw = 0;
 
4557
    int ch = 0;
 
4558
    GetVirtualSize( &cw, &ch );
 
4559
 
 
4560
    wxRect rect;
 
4561
    rect.x = dc.LogicalToDeviceX( 0 );
 
4562
    rect.y = dc.LogicalToDeviceY( item->GetY() );
 
4563
    rect.width = cw;
 
4564
    rect.height = GetLineHeight(item); //dc.GetCharHeight() + 6;
 
4565
 
 
4566
    Refresh (true, &rect);
 
4567
}
 
4568
 
 
4569
void wxTreeListMainWindow::RefreshSelected() {
 
4570
    // TODO: this is awfully inefficient, we should keep the list of all
 
4571
    //       selected items internally, should be much faster
 
4572
    if (m_rootItem) {
 
4573
        RefreshSelectedUnder (m_rootItem);
 
4574
    }
 
4575
}
 
4576
 
 
4577
void wxTreeListMainWindow::RefreshSelectedUnder (wxTreeListItem *item) {
 
4578
    if (item->IsSelected()) {
 
4579
        RefreshLine (item);
 
4580
    }
 
4581
 
 
4582
    const wxArrayTreeListItems& children = item->GetChildren();
 
4583
    long count = (long)children.GetCount();
 
4584
    for (long n = 0; n < count; n++ ) {
 
4585
        RefreshSelectedUnder (children[n]);
 
4586
    }
 
4587
}
 
4588
 
 
4589
// ----------------------------------------------------------------------------
 
4590
// changing colours: we need to refresh the tree control
 
4591
// ----------------------------------------------------------------------------
 
4592
 
 
4593
bool wxTreeListMainWindow::SetBackgroundColour (const wxColour& colour) {
 
4594
    if (!wxWindow::SetBackgroundColour(colour)) return false;
 
4595
 
 
4596
    Refresh();
 
4597
    return true;
 
4598
}
 
4599
 
 
4600
bool wxTreeListMainWindow::SetForegroundColour (const wxColour& colour) {
 
4601
    if (!wxWindow::SetForegroundColour(colour)) return false;
 
4602
 
 
4603
    Refresh();
 
4604
    return true;
 
4605
}
 
4606
 
 
4607
void wxTreeListMainWindow::SetItemText (const wxTreeItemId& itemId, int column, const wxString& text) {
 
4608
    wxCHECK_RET (itemId.IsOk(), _T("invalid tree item"));
 
4609
 
 
4610
    wxClientDC dc (this);
 
4611
    wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
4612
    item->SetText (column, text);
 
4613
    CalculateSize (item, dc);
 
4614
    RefreshLine (item);
 
4615
}
 
4616
 
 
4617
std::list<wxTreeItemId> wxTreeListMainWindow::GetPublicChildren(const wxTreeItemId& itemId) const
 
4618
{
 
4619
        wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
 
4620
        return item->GetPublicChildren();
 
4621
}
 
4622
 
 
4623
wxString wxTreeListMainWindow::GetItemText (const wxTreeItemId& itemId, int column) const {
 
4624
    wxCHECK_MSG (itemId.IsOk(), _T(""), _T("invalid tree item") );
 
4625
 
 
4626
        if( IsVirtual() ) {
 
4627
                return m_owner->OnGetItemText(((wxTreeListItem*) itemId.m_pItem)->GetData(),column);
 
4628
        }
 
4629
        if (itemId.m_pItem != NULL) {
 
4630
                wxTreeListItem* item = (wxTreeListItem*) itemId.m_pItem;
 
4631
                if (!item->GetText(column).IsNull()) {
 
4632
                        return item->GetText(column);
 
4633
                }
 
4634
                else {
 
4635
                        return wxEmptyString;
 
4636
                }
 
4637
        }
 
4638
        else {
 
4639
                return wxEmptyString;
 
4640
        }
 
4641
}
 
4642
 
 
4643
wxString wxTreeListMainWindow::GetItemText (wxTreeItemData* item, int column) const {
 
4644
   wxASSERT_MSG( IsVirtual(), _T("can be used only with virtual control") );
 
4645
   return m_owner->OnGetItemText(item, column);
 
4646
}
 
4647
 
 
4648
void wxTreeListMainWindow::SetFocus() {
 
4649
    wxWindow::SetFocus();
 
4650
}
 
4651
 
 
4652
 
 
4653
int wxTreeListMainWindow::GetItemWidth (int column, wxTreeListItem *item) {
 
4654
    if (!item) return 0;
 
4655
 
 
4656
    // determine item width
 
4657
    int w = 0, h = 0;
 
4658
    wxFont font = GetItemFont (item);
 
4659
    GetTextExtent (item->GetText (column), &w, &h, NULL, NULL, font.Ok()? &font: NULL);
 
4660
    w += 2*MARGIN;
 
4661
 
 
4662
    // calculate width
 
4663
    int width = w + 2*MARGIN;
 
4664
    if (column == GetMainColumn()) {
 
4665
        width += MARGIN;
 
4666
        if (HasFlag(wxTR_LINES_AT_ROOT)) width += LINEATROOT;
 
4667
        if (HasButtons()) width += m_btnWidth + LINEATROOT;
 
4668
        if (item->GetCurrentImage() != NO_IMAGE) width += m_imgWidth;
 
4669
 
 
4670
        // count indent level
 
4671
        int level = 0;
 
4672
        wxTreeListItem *parent = item->GetItemParent();
 
4673
        wxTreeListItem *root = (wxTreeListItem*)GetRootItem().m_pItem;
 
4674
        while (parent && (!HasFlag(wxTR_HIDE_ROOT) || (parent != root))) {
 
4675
            level++;
 
4676
            parent = parent->GetItemParent();
 
4677
        }
 
4678
        if (level) width += level * GetIndent();
 
4679
    }
 
4680
 
 
4681
    return width;
 
4682
}
 
4683
 
 
4684
int wxTreeListMainWindow::GetBestColumnWidth (int column, wxTreeItemId parent) {
 
4685
    int maxWidth, h;
 
4686
    GetClientSize (&maxWidth, &h);
 
4687
    int width = 0;
 
4688
 
 
4689
    // get root if on item
 
4690
    if (!parent.IsOk()) parent = GetRootItem();
 
4691
 
 
4692
    // add root width
 
4693
    if (!HasFlag(wxTR_HIDE_ROOT)) {
 
4694
        int w = GetItemWidth (column, (wxTreeListItem*)parent.m_pItem);
 
4695
        if (width < w) width = w;
 
4696
        if (width > maxWidth) return maxWidth;
 
4697
    }
 
4698
 
 
4699
    wxTreeItemIdValue cookie = 0;
 
4700
    wxTreeItemId item = GetFirstChild (parent, cookie);
 
4701
    while (item.IsOk()) {
 
4702
        int w = GetItemWidth (column, (wxTreeListItem*)item.m_pItem);
 
4703
        if (width < w) width = w;
 
4704
        if (width > maxWidth) return maxWidth;
 
4705
 
 
4706
        // check the children of this item
 
4707
        if (((wxTreeListItem*)item.m_pItem)->IsExpanded()) {
 
4708
            int w = GetBestColumnWidth (column, item);
 
4709
            if (width < w) width = w;
 
4710
            if (width > maxWidth) return maxWidth;
 
4711
        }
 
4712
 
 
4713
        // next sibling
 
4714
        item = GetNextChild (parent, cookie);
 
4715
    }
 
4716
 
 
4717
    return width;
 
4718
}
 
4719
 
 
4720
 
 
4721
bool wxTreeListMainWindow::SendEvent(wxEventType event_type, wxTreeListItem *item, wxTreeEvent *event) {
 
4722
wxTreeEvent nevent (event_type, 0);
 
4723
 
 
4724
    if (event == NULL) {
 
4725
        event = &nevent;
 
4726
        event->SetInt (m_curColumn); // the mouse colum
 
4727
    }
 
4728
 
 
4729
    event->SetEventObject (m_owner);
 
4730
    event->SetId(m_owner->GetId());
 
4731
    if (item) {
 
4732
#if !wxCHECK_VERSION(2, 5, 0)
 
4733
        event->SetItem ((long)item);
 
4734
#else
 
4735
        event->SetItem (item);
 
4736
#endif
 
4737
    }
 
4738
 
 
4739
    return m_owner->GetEventHandler()->ProcessEvent (*event);
 
4740
}
 
4741
 
 
4742
 
 
4743
//-----------------------------------------------------------------------------
 
4744
//  wxTreeListCtrl
 
4745
//-----------------------------------------------------------------------------
 
4746
 
 
4747
IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl, wxControl);
 
4748
 
 
4749
BEGIN_EVENT_TABLE(wxTreeListCtrl, wxControl)
 
4750
    EVT_SIZE(wxTreeListCtrl::OnSize)
 
4751
END_EVENT_TABLE();
 
4752
 
 
4753
bool wxTreeListCtrl::Create(wxWindow *parent, wxWindowID id,
 
4754
                            const wxPoint& pos,
 
4755
                            const wxSize& size,
 
4756
                            long style, const wxValidator &validator,
 
4757
                            const wxString& name)
 
4758
{
 
4759
    long main_style = style & ~(wxSIMPLE_BORDER|wxSUNKEN_BORDER|wxDOUBLE_BORDER|
 
4760
                                wxRAISED_BORDER|wxSTATIC_BORDER);
 
4761
         main_style |= wxWANTS_CHARS ;
 
4762
    long ctrl_style = style & ~(wxVSCROLL|wxHSCROLL);
 
4763
 
 
4764
    if (!wxControl::Create(parent, id, pos, size, ctrl_style, validator, name)) {
 
4765
       return false;
 
4766
    }
 
4767
    m_main_win = new wxTreeListMainWindow (this, -1, wxPoint(0, 0), size,
 
4768
                                           main_style, validator);
 
4769
    m_header_win = new wxTreeListHeaderWindow (this, -1, m_main_win,
 
4770
                                               wxPoint(0, 0), wxDefaultSize,
 
4771
                                               wxTAB_TRAVERSAL);
 
4772
    CalculateAndSetHeaderHeight();
 
4773
    return true;
 
4774
}
 
4775
 
 
4776
void wxTreeListCtrl::CalculateAndSetHeaderHeight()
 
4777
{
 
4778
    if (m_header_win) {
 
4779
 
 
4780
        // we use 'g' to get the descent, too
 
4781
        int h;
 
4782
#if wxCHECK_VERSION_FULL(2, 7, 0, 1)
 
4783
#ifdef __WXMSW__
 
4784
        h = (int)(wxRendererNative::Get().GetHeaderButtonHeight(m_header_win) * 0.8) + 2;
 
4785
#else
 
4786
        h = wxRendererNative::Get().GetHeaderButtonHeight(m_header_win);
 
4787
#endif
 
4788
#else
 
4789
        int w, d;
 
4790
        m_header_win->GetTextExtent(_T("Hg"), &w, &h, &d);
 
4791
        h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
 
4792
#endif
 
4793
 
 
4794
        // only update if changed
 
4795
        if (h != m_headerHeight) {
 
4796
            m_headerHeight = h;
 
4797
            DoHeaderLayout();
 
4798
        }
 
4799
    }
 
4800
}
 
4801
 
 
4802
void wxTreeListCtrl::DoHeaderLayout()
 
4803
{
 
4804
    int w, h;
 
4805
    GetClientSize(&w, &h);
 
4806
    if (m_header_win) {
 
4807
        m_header_win->SetSize (0, 0, w, m_headerHeight);
 
4808
        m_header_win->Refresh();
 
4809
    }
 
4810
    if (m_main_win) {
 
4811
        m_main_win->SetSize (0, m_headerHeight, w, h - m_headerHeight);
 
4812
    }
 
4813
}
 
4814
 
 
4815
void wxTreeListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
 
4816
{
 
4817
    DoHeaderLayout();
 
4818
}
 
4819
 
 
4820
size_t wxTreeListCtrl::GetCount() const { return m_main_win->GetCount(); }
 
4821
 
 
4822
unsigned int wxTreeListCtrl::GetIndent() const
 
4823
{ return m_main_win->GetIndent(); }
 
4824
 
 
4825
void wxTreeListCtrl::SetIndent(unsigned int indent)
 
4826
{ m_main_win->SetIndent(indent); }
 
4827
 
 
4828
unsigned int wxTreeListCtrl::GetLineSpacing() const
 
4829
{ return m_main_win->GetLineSpacing(); }
 
4830
 
 
4831
void wxTreeListCtrl::SetLineSpacing(unsigned int spacing)
 
4832
{ m_main_win->SetLineSpacing(spacing); }
 
4833
 
 
4834
wxImageList* wxTreeListCtrl::GetImageList() const
 
4835
{ return m_main_win->GetImageList(); }
 
4836
 
 
4837
wxImageList* wxTreeListCtrl::GetStateImageList() const
 
4838
{ return m_main_win->GetStateImageList(); }
 
4839
 
 
4840
wxImageList* wxTreeListCtrl::GetButtonsImageList() const
 
4841
{ return m_main_win->GetButtonsImageList(); }
 
4842
 
 
4843
void wxTreeListCtrl::SetImageList(wxImageList* imageList)
 
4844
{ m_main_win->SetImageList(imageList); }
 
4845
 
 
4846
void wxTreeListCtrl::SetStateImageList(wxImageList* imageList)
 
4847
{ m_main_win->SetStateImageList(imageList); }
 
4848
 
 
4849
void wxTreeListCtrl::SetButtonsImageList(wxImageList* imageList)
 
4850
{ m_main_win->SetButtonsImageList(imageList); }
 
4851
 
 
4852
void wxTreeListCtrl::AssignImageList(wxImageList* imageList)
 
4853
{ m_main_win->AssignImageList(imageList); }
 
4854
 
 
4855
void wxTreeListCtrl::AssignStateImageList(wxImageList* imageList)
 
4856
{ m_main_win->AssignStateImageList(imageList); }
 
4857
 
 
4858
void wxTreeListCtrl::AssignButtonsImageList(wxImageList* imageList)
 
4859
{ m_main_win->AssignButtonsImageList(imageList); }
 
4860
 
 
4861
std::list<wxTreeItemId> wxTreeListCtrl::GetPublicChildren(const wxTreeItemId& item) const
 
4862
{
 
4863
        return m_main_win->GetPublicChildren(item);
 
4864
}
 
4865
 
 
4866
wxString wxTreeListCtrl::GetItemText(const wxTreeItemId& item, int column) const
 
4867
{ return m_main_win->GetItemText (item, column); }
 
4868
 
 
4869
int wxTreeListCtrl::GetItemImage(const wxTreeItemId& item, wxTreeItemIcon which) const
 
4870
{ return m_main_win->GetItemImage(item, which); }
 
4871
int wxTreeListCtrl::GetItemImage(const wxTreeItemId& item, int column) const
 
4872
{ return m_main_win->GetItemImage(item, column); }
 
4873
 
 
4874
wxTreeItemData* wxTreeListCtrl::GetItemData(const wxTreeItemId& item) const
 
4875
{ return m_main_win->GetItemData(item); }
 
4876
wxTreeItemData* wxTreeListCtrl::GetItemData(const wxTreeItemId& item, int column) const
 
4877
{ return m_main_win->GetItemData(item, column); }
 
4878
 
 
4879
bool wxTreeListCtrl::GetItemBold(const wxTreeItemId& item) const
 
4880
{ return m_main_win->GetItemBold(item); }
 
4881
bool wxTreeListCtrl::GetItemBold(const wxTreeItemId& item, int column) const
 
4882
{ return m_main_win->GetItemBold(item, column); }
 
4883
 
 
4884
wxColour wxTreeListCtrl::GetItemTextColour(const wxTreeItemId& item) const
 
4885
{ return m_main_win->GetItemTextColour(item); }
 
4886
wxColour wxTreeListCtrl::GetItemTextColour(const wxTreeItemId& item, int column) const
 
4887
{ return m_main_win->GetItemTextColour(item, column); }
 
4888
 
 
4889
wxColour wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId& item) const
 
4890
{ return m_main_win->GetItemBackgroundColour(item); }
 
4891
wxColour wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId& item, int column) const
 
4892
{ return m_main_win->GetItemBackgroundColour(item, column); }
 
4893
 
 
4894
wxFont wxTreeListCtrl::GetItemFont(const wxTreeItemId& item) const
 
4895
{ return m_main_win->GetItemFont(item); }
 
4896
wxFont wxTreeListCtrl::GetItemFont(const wxTreeItemId& item, int column) const
 
4897
{ return m_main_win->GetItemFont(item, column); }
 
4898
 
 
4899
 
 
4900
 
 
4901
void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has)
 
4902
{ m_main_win->SetItemHasChildren(item, has); }
 
4903
 
 
4904
void wxTreeListCtrl::SetItemText (const wxTreeItemId& itemId, const wxString& text) {
 
4905
        m_main_win->SetItemText (itemId, 0, text);
 
4906
}
 
4907
void wxTreeListCtrl::SetItemText(const wxTreeItemId& item, int column, const wxString& text)
 
4908
{ m_main_win->SetItemText (item, column, text); }
 
4909
 
 
4910
void wxTreeListCtrl::SetItemImage(const wxTreeItemId& item, int image, wxTreeItemIcon which)
 
4911
{ m_main_win->SetItemImage(item, image, which); }
 
4912
void wxTreeListCtrl::SetItemImage(const wxTreeItemId& item, int column, int image)
 
4913
{ m_main_win->SetItemImage(item, column, image); }
 
4914
 
 
4915
void wxTreeListCtrl::SetItemData(const wxTreeItemId& item,             wxTreeItemData* data)
 
4916
{ m_main_win->SetItemData(item, data); }
 
4917
void wxTreeListCtrl::SetItemData(const wxTreeItemId& item, int column, wxTreeItemData* data)
 
4918
{ m_main_win->SetItemData(item, column, data); }
 
4919
 
 
4920
void wxTreeListCtrl::SetItemBold(const wxTreeItemId& item,             bool bold)
 
4921
{ m_main_win->SetItemBold(item, bold); }
 
4922
void wxTreeListCtrl::SetItemBold(const wxTreeItemId& item, int column, bool bold)
 
4923
{ m_main_win->SetItemBold(item, column, bold); }
 
4924
 
 
4925
void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId& item,              const wxColour& colour)
 
4926
{ m_main_win->SetItemTextColour(item, colour); }
 
4927
void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId& item, int column, const wxColour& colour)
 
4928
{ m_main_win->SetItemTextColour(item, column, colour); }
 
4929
 
 
4930
void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId& item,             const wxColour& colour)
 
4931
{ m_main_win->SetItemBackgroundColour(item, colour); }
 
4932
void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId& item, int column, const wxColour& colour)
 
4933
{ m_main_win->SetItemBackgroundColour(item, column, colour); }
 
4934
 
 
4935
void wxTreeListCtrl::SetItemFont(const wxTreeItemId& item,             const wxFont& font)
 
4936
{ m_main_win->SetItemFont(item, font); }
 
4937
void wxTreeListCtrl::SetItemFont(const wxTreeItemId& item, int column, const wxFont& font)
 
4938
{ m_main_win->SetItemFont(item, column, font); }
 
4939
 
 
4940
 
 
4941
 
 
4942
bool wxTreeListCtrl::SetFont(const wxFont& font)
 
4943
{
 
4944
    if (m_header_win) {
 
4945
        m_header_win->SetFont(font);
 
4946
        CalculateAndSetHeaderHeight();
 
4947
        m_header_win->Refresh();
 
4948
    }
 
4949
    if (m_main_win) {
 
4950
        return m_main_win->SetFont(font);
 
4951
    }else{
 
4952
        return false;
 
4953
    }
 
4954
}
 
4955
 
 
4956
void wxTreeListCtrl::SetWindowStyle(const long style)
 
4957
{
 
4958
    if(m_main_win)
 
4959
        m_main_win->SetWindowStyle(style);
 
4960
    m_windowStyle = style;
 
4961
    // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win
 
4962
}
 
4963
 
 
4964
long wxTreeListCtrl::GetWindowStyle() const
 
4965
{
 
4966
    long style = m_windowStyle;
 
4967
    if(m_main_win)
 
4968
        style |= m_main_win->GetWindowStyle();
 
4969
    return style;
 
4970
}
 
4971
 
 
4972
bool wxTreeListCtrl::IsVisible(const wxTreeItemId& item, bool fullRow, bool within) const
 
4973
{ return m_main_win->IsVisible(item, fullRow, within); }
 
4974
 
 
4975
bool wxTreeListCtrl::HasChildren(const wxTreeItemId& item) const
 
4976
{ return m_main_win->HasChildren(item); }
 
4977
 
 
4978
bool wxTreeListCtrl::IsExpanded(const wxTreeItemId& item) const
 
4979
{ return m_main_win->IsExpanded(item); }
 
4980
 
 
4981
bool wxTreeListCtrl::IsSelected(const wxTreeItemId& item) const
 
4982
{ return m_main_win->IsSelected(item); }
 
4983
 
 
4984
size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId& item, bool rec)
 
4985
{ return m_main_win->GetChildrenCount(item, rec); }
 
4986
 
 
4987
wxTreeItemId wxTreeListCtrl::GetRootItem() const
 
4988
{ return m_main_win->GetRootItem(); }
 
4989
 
 
4990
wxTreeItemId wxTreeListCtrl::GetSelection() const
 
4991
{ return m_main_win->GetSelection(); }
 
4992
 
 
4993
size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds& arr) const
 
4994
{ return m_main_win->GetSelections(arr); }
 
4995
 
 
4996
wxTreeItemId wxTreeListCtrl::GetItemParent(const wxTreeItemId& item) const
 
4997
{ return m_main_win->GetItemParent(item); }
 
4998
 
 
4999
#if !wxCHECK_VERSION(2, 5, 0)
 
5000
wxTreeItemId wxTreeListCtrl::GetFirstChild (const wxTreeItemId& item,
 
5001
                                            long& cookie) const
 
5002
#else
 
5003
wxTreeItemId wxTreeListCtrl::GetFirstChild (const wxTreeItemId& item,
 
5004
                                            wxTreeItemIdValue& cookie) const
 
5005
#endif
 
5006
{ return m_main_win->GetFirstChild(item, cookie); }
 
5007
 
 
5008
#if !wxCHECK_VERSION(2, 5, 0)
 
5009
wxTreeItemId wxTreeListCtrl::GetNextChild (const wxTreeItemId& item,
 
5010
                                           long& cookie) const
 
5011
#else
 
5012
wxTreeItemId wxTreeListCtrl::GetNextChild (const wxTreeItemId& item,
 
5013
                                           wxTreeItemIdValue& cookie) const
 
5014
#endif
 
5015
{ return m_main_win->GetNextChild(item, cookie); }
 
5016
 
 
5017
#if !wxCHECK_VERSION(2, 5, 0)
 
5018
wxTreeItemId wxTreeListCtrl::GetPrevChild (const wxTreeItemId& item,
 
5019
                                           long& cookie) const
 
5020
#else
 
5021
wxTreeItemId wxTreeListCtrl::GetPrevChild (const wxTreeItemId& item,
 
5022
                                           wxTreeItemIdValue& cookie) const
 
5023
#endif
 
5024
{ return m_main_win->GetPrevChild(item, cookie); }
 
5025
 
 
5026
#if !wxCHECK_VERSION(2, 5, 0)
 
5027
wxTreeItemId wxTreeListCtrl::GetLastChild (const wxTreeItemId& item,
 
5028
                                           long& cookie) const
 
5029
#else
 
5030
wxTreeItemId wxTreeListCtrl::GetLastChild (const wxTreeItemId& item,
 
5031
                                           wxTreeItemIdValue& cookie) const
 
5032
#endif
 
5033
{ return m_main_win->GetLastChild(item, cookie); }
 
5034
 
 
5035
 
 
5036
wxTreeItemId wxTreeListCtrl::GetNextSibling(const wxTreeItemId& item) const
 
5037
{ return m_main_win->GetNextSibling(item); }
 
5038
 
 
5039
wxTreeItemId wxTreeListCtrl::GetPrevSibling(const wxTreeItemId& item) const
 
5040
{ return m_main_win->GetPrevSibling(item); }
 
5041
 
 
5042
wxTreeItemId wxTreeListCtrl::GetNext(const wxTreeItemId& item) const
 
5043
{ return m_main_win->GetNext(item, true); }
 
5044
 
 
5045
wxTreeItemId wxTreeListCtrl::GetPrev(const wxTreeItemId& item) const
 
5046
{ return m_main_win->GetPrev(item, true); }
 
5047
 
 
5048
wxTreeItemId wxTreeListCtrl::GetFirstExpandedItem() const
 
5049
{ return m_main_win->GetFirstExpandedItem(); }
 
5050
 
 
5051
wxTreeItemId wxTreeListCtrl::GetNextExpanded(const wxTreeItemId& item) const
 
5052
{ return m_main_win->GetNextExpanded(item); }
 
5053
 
 
5054
wxTreeItemId wxTreeListCtrl::GetPrevExpanded(const wxTreeItemId& item) const
 
5055
{ return m_main_win->GetPrevExpanded(item); }
 
5056
 
 
5057
wxTreeItemId wxTreeListCtrl::GetFirstVisibleItem(bool fullRow) const
 
5058
{ return GetFirstVisible(fullRow); }
 
5059
wxTreeItemId wxTreeListCtrl::GetFirstVisible(bool fullRow, bool within) const
 
5060
{ return m_main_win->GetFirstVisible(fullRow, within); }
 
5061
 
 
5062
wxTreeItemId wxTreeListCtrl::GetLastVisible(bool fullRow, bool within) const
 
5063
{ return m_main_win->GetLastVisible(fullRow, within); }
 
5064
 
 
5065
wxTreeItemId wxTreeListCtrl::GetNextVisible(const wxTreeItemId& item, bool fullRow, bool within) const
 
5066
{ return m_main_win->GetNextVisible(item, fullRow, within); }
 
5067
 
 
5068
wxTreeItemId wxTreeListCtrl::GetPrevVisible(const wxTreeItemId& item, bool fullRow, bool within) const
 
5069
{ return m_main_win->GetPrevVisible(item, fullRow, within); }
 
5070
 
 
5071
wxTreeItemId wxTreeListCtrl::AddRoot (const wxString& text, int image,
 
5072
                                      int selectedImage, wxTreeItemData* data)
 
5073
{ return m_main_win->AddRoot (text, image, selectedImage, data); }
 
5074
 
 
5075
wxTreeItemId wxTreeListCtrl::PrependItem(const wxTreeItemId& parent,
 
5076
                                         const wxString& text, int image,
 
5077
                                         int selectedImage,
 
5078
                                         wxTreeItemData* data)
 
5079
{ return m_main_win->PrependItem(parent, text, image, selectedImage, data); }
 
5080
 
 
5081
wxTreeItemId wxTreeListCtrl::InsertItem(const wxTreeItemId& parent,
 
5082
                                        const wxTreeItemId& previous,
 
5083
                                        const wxString& text, int image,
 
5084
                                        int selectedImage,
 
5085
                                        wxTreeItemData* data)
 
5086
{
 
5087
    return m_main_win->InsertItem(parent, previous, text, image,
 
5088
                                  selectedImage, data);
 
5089
}
 
5090
 
 
5091
wxTreeItemId wxTreeListCtrl::InsertItem(const wxTreeItemId& parent,
 
5092
                                        size_t index,
 
5093
                                        const wxString& text, int image,
 
5094
                                        int selectedImage,
 
5095
                                        wxTreeItemData* data)
 
5096
{
 
5097
    return m_main_win->InsertItem(parent, index, text, image,
 
5098
                                  selectedImage, data);
 
5099
}
 
5100
 
 
5101
wxTreeItemId wxTreeListCtrl::AppendItem(const wxTreeItemId& parent,
 
5102
                                        const wxString& text, int image,
 
5103
                                        int selectedImage,
 
5104
                                        wxTreeItemData* data)
 
5105
{ return m_main_win->AppendItem(parent, text, image, selectedImage, data); }
 
5106
 
 
5107
void wxTreeListCtrl::Delete(const wxTreeItemId& item)
 
5108
{ m_main_win->Delete(item); }
 
5109
 
 
5110
void wxTreeListCtrl::DeleteChildren(const wxTreeItemId& item)
 
5111
{ m_main_win->DeleteChildren(item); }
 
5112
 
 
5113
void wxTreeListCtrl::DeleteRoot()
 
5114
{ m_main_win->DeleteRoot(); }
 
5115
 
 
5116
void wxTreeListCtrl::Expand(const wxTreeItemId& item)
 
5117
{ m_main_win->Expand(item); }
 
5118
 
 
5119
void wxTreeListCtrl::ExpandAll(const wxTreeItemId& item)
 
5120
{ m_main_win->ExpandAll(item); }
 
5121
 
 
5122
void wxTreeListCtrl::Collapse(const wxTreeItemId& item)
 
5123
{ m_main_win->Collapse(item); }
 
5124
 
 
5125
void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId& item)
 
5126
{ m_main_win->CollapseAndReset(item); }
 
5127
 
 
5128
void wxTreeListCtrl::Toggle(const wxTreeItemId& item)
 
5129
{ m_main_win->Toggle(item); }
 
5130
 
 
5131
void wxTreeListCtrl::Unselect()
 
5132
{ m_main_win->Unselect(); }
 
5133
 
 
5134
void wxTreeListCtrl::UnselectAll()
 
5135
{ m_main_win->UnselectAll(); }
 
5136
 
 
5137
bool wxTreeListCtrl::SelectItem(const wxTreeItemId& item, const wxTreeItemId& last,
 
5138
                                bool unselect_others)
 
5139
{ return m_main_win->SelectItem (item, last, unselect_others); }
 
5140
 
 
5141
void wxTreeListCtrl::SelectAll()
 
5142
{ m_main_win->SelectAll(); }
 
5143
 
 
5144
void wxTreeListCtrl::EnsureVisible(const wxTreeItemId& item)
 
5145
{ m_main_win->EnsureVisible(item); }
 
5146
 
 
5147
void wxTreeListCtrl::ScrollTo(const wxTreeItemId& item)
 
5148
{ m_main_win->ScrollTo(item); }
 
5149
 
 
5150
wxTreeItemId wxTreeListCtrl::HitTest(const wxPoint& pos, int& flags, int& column)
 
5151
{
 
5152
    wxPoint p = m_main_win->ScreenToClient (ClientToScreen (pos));
 
5153
    return m_main_win->HitTest (p, flags, column);
 
5154
}
 
5155
 
 
5156
bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId& item, wxRect& rect,
 
5157
                                     bool textOnly) const
 
5158
{ return m_main_win->GetBoundingRect(item, rect, textOnly); }
 
5159
 
 
5160
void wxTreeListCtrl::EditLabel (const wxTreeItemId& item, int column)
 
5161
    { m_main_win->EditLabel (item, column); }
 
5162
void wxTreeListCtrl::EndEdit(bool isCancelled)
 
5163
    { m_main_win->EndEdit(isCancelled); }
 
5164
 
 
5165
int wxTreeListCtrl::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
 
5166
{
 
5167
    // do the comparison here and not in m_main_win in order to allow
 
5168
    // override in child class
 
5169
    return wxStrcmp(GetItemText(item1), GetItemText(item2));
 
5170
}
 
5171
int wxTreeListCtrl::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2, int column)
 
5172
{
 
5173
    // do the comparison here and not in m_main_win in order to allow
 
5174
    // override in child class
 
5175
    return wxStrcmp(GetItemText(item1, column), GetItemText(item2, column));
 
5176
}
 
5177
 
 
5178
void wxTreeListCtrl::SortChildren(const wxTreeItemId& item, int column, bool reverseOrder)
 
5179
{ m_main_win->SortChildren(item, column, reverseOrder); }
 
5180
 
 
5181
wxTreeItemId wxTreeListCtrl::FindItem (const wxTreeItemId& item, int column, const wxString& str, int mode)
 
5182
{ return m_main_win->FindItem (item, column, str, mode); }
 
5183
 
 
5184
void wxTreeListCtrl::SetDragItem (const wxTreeItemId& item)
 
5185
{ m_main_win->SetDragItem (item); }
 
5186
 
 
5187
bool wxTreeListCtrl::SetBackgroundColour(const wxColour& colour)
 
5188
{
 
5189
    if (!m_main_win) return false;
 
5190
    return m_main_win->SetBackgroundColour(colour);
 
5191
}
 
5192
 
 
5193
bool wxTreeListCtrl::SetForegroundColour(const wxColour& colour)
 
5194
{
 
5195
    if (!m_main_win) return false;
 
5196
    return m_main_win->SetForegroundColour(colour);
 
5197
}
 
5198
 
 
5199
int wxTreeListCtrl::GetColumnCount() const
 
5200
{ return m_main_win->GetColumnCount(); }
 
5201
 
 
5202
void wxTreeListCtrl::SetColumnWidth(int column, int width)
 
5203
{
 
5204
    m_header_win->SetColumnWidth (column, width);
 
5205
    m_header_win->Refresh();
 
5206
}
 
5207
 
 
5208
int wxTreeListCtrl::GetColumnWidth(int column) const
 
5209
{ return m_header_win->GetColumnWidth(column); }
 
5210
 
 
5211
void wxTreeListCtrl::SetMainColumn(int column)
 
5212
{ m_main_win->SetMainColumn(column); }
 
5213
 
 
5214
int wxTreeListCtrl::GetMainColumn() const
 
5215
{ return m_main_win->GetMainColumn(); }
 
5216
 
 
5217
void wxTreeListCtrl::SetColumnText(int column, const wxString& text)
 
5218
{
 
5219
    m_header_win->SetColumnText (column, text);
 
5220
    m_header_win->Refresh();
 
5221
}
 
5222
 
 
5223
wxString wxTreeListCtrl::GetColumnText(int column) const
 
5224
{ return m_header_win->GetColumnText(column); }
 
5225
 
 
5226
void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo& colInfo)
 
5227
{
 
5228
    m_header_win->AddColumn (colInfo);
 
5229
    DoHeaderLayout();
 
5230
}
 
5231
 
 
5232
void wxTreeListCtrl::InsertColumn(int before, const wxTreeListColumnInfo& colInfo)
 
5233
{
 
5234
    m_header_win->InsertColumn (before, colInfo);
 
5235
    m_header_win->Refresh();
 
5236
}
 
5237
 
 
5238
void wxTreeListCtrl::RemoveColumn(int column)
 
5239
{
 
5240
    m_header_win->RemoveColumn (column);
 
5241
    m_header_win->Refresh();
 
5242
}
 
5243
 
 
5244
void wxTreeListCtrl::SetColumn(int column, const wxTreeListColumnInfo& colInfo)
 
5245
{
 
5246
    m_header_win->SetColumn (column, colInfo);
 
5247
    m_header_win->Refresh();
 
5248
}
 
5249
 
 
5250
const wxTreeListColumnInfo& wxTreeListCtrl::GetColumn(int column) const
 
5251
{ return m_header_win->GetColumn(column); }
 
5252
 
 
5253
wxTreeListColumnInfo& wxTreeListCtrl::GetColumn(int column)
 
5254
{ return m_header_win->GetColumn(column); }
 
5255
 
 
5256
void wxTreeListCtrl::SetColumnImage(int column, int image)
 
5257
{
 
5258
    m_header_win->SetColumn (column, GetColumn(column).SetImage(image));
 
5259
    m_header_win->Refresh();
 
5260
}
 
5261
 
 
5262
int wxTreeListCtrl::GetColumnImage(int column) const
 
5263
{
 
5264
    return m_header_win->GetColumn(column).GetImage();
 
5265
}
 
5266
 
 
5267
void wxTreeListCtrl::SetColumnEditable(int column, bool shown)
 
5268
{
 
5269
    m_header_win->SetColumn (column, GetColumn(column).SetEditable(shown));
 
5270
}
 
5271
 
 
5272
void wxTreeListCtrl::SetColumnShown(int column, bool shown)
 
5273
{
 
5274
    wxASSERT_MSG (column != GetMainColumn(), _T("The main column may not be hidden") );
 
5275
    m_header_win->SetColumn (column, GetColumn(column).SetShown(GetMainColumn()==column? true: shown));
 
5276
    m_header_win->Refresh();
 
5277
}
 
5278
 
 
5279
bool wxTreeListCtrl::IsColumnEditable(int column) const
 
5280
{
 
5281
    return m_header_win->GetColumn(column).IsEditable();
 
5282
}
 
5283
 
 
5284
bool wxTreeListCtrl::IsColumnShown(int column) const
 
5285
{
 
5286
    return m_header_win->GetColumn(column).IsShown();
 
5287
}
 
5288
 
 
5289
void wxTreeListCtrl::SetColumnAlignment (int column, int flag)
 
5290
{
 
5291
    m_header_win->SetColumn(column, GetColumn(column).SetAlignment(flag));
 
5292
    m_header_win->Refresh();
 
5293
}
 
5294
 
 
5295
int wxTreeListCtrl::GetColumnAlignment(int column) const
 
5296
{
 
5297
    return m_header_win->GetColumn(column).GetAlignment();
 
5298
}
 
5299
 
 
5300
void wxTreeListCtrl::Refresh(bool erase, const wxRect* rect)
 
5301
{
 
5302
    m_main_win->Refresh (erase, rect);
 
5303
    m_header_win->Refresh (erase, rect);
 
5304
}
 
5305
 
 
5306
void wxTreeListCtrl::SetFocus()
 
5307
{ m_main_win->SetFocus(); }
 
5308
 
 
5309
wxSize wxTreeListCtrl::DoGetBestSize() const
 
5310
{
 
5311
    wxSize bestSizeHeader = m_header_win->GetBestSize();
 
5312
    wxSize bestSizeMain = m_main_win->GetBestSize();
 
5313
    return wxSize (bestSizeHeader.x > bestSizeMain.x ? bestSizeHeader.x : bestSizeMain.x, bestSizeHeader.y + bestSizeMain.y);
 
5314
}
 
5315
 
 
5316
wxString wxTreeListCtrl::OnGetItemText( wxTreeItemData* WXUNUSED(item), long WXUNUSED(column)) const
 
5317
{
 
5318
    return wxEmptyString;
 
5319
}
 
5320
 
 
5321
void wxTreeListCtrl::SetToolTip(const wxString& tip) {
 
5322
    m_header_win->SetToolTip(tip);
 
5323
    m_main_win->SetToolTip(tip);
 
5324
}
 
5325
void wxTreeListCtrl::SetToolTip(wxToolTip *tip) {
 
5326
    m_header_win->SetToolTip(tip);
 
5327
    m_main_win->SetToolTip(tip);
 
5328
}
 
5329
 
 
5330
void wxTreeListCtrl::SetItemToolTip(const wxTreeItemId& item, const wxString &tip) {
 
5331
    m_main_win->SetItemToolTip(item, tip);
 
5332
}
 
5333
 
 
5334
void wxTreeListCtrl::SetCurrentItem(const wxTreeItemId& itemId) {
 
5335
    m_main_win->SetCurrentItem(itemId);
 
5336
}