File: notebook_ex.h

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (298 lines) | stat: -rw-r--r-- 10,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : custom_notebook.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef __Notebook__
#define __Notebook__
#include "cl_defs.h"

#if CL_USE_NATIVEBOOK
#    include "gtk_notebook_ex.h"
#else

#include <wx/wx.h>
#include <wx/aui/auibook.h>
#include <vector>
#include <set>
#include "codelite_exports.h"

enum {
    wxVB_LEFT                   = wxAUI_NB_LEFT,
    wxVB_RIGHT                  = wxAUI_NB_RIGHT,
    wxVB_TOP                    = wxAUI_NB_TOP,
    wxVB_BOTTOM                 = wxAUI_NB_BOTTOM,
    wxVB_FIXED_WIDTH            = wxAUI_NB_TAB_FIXED_WIDTH,
    wxVB_HAS_X                  = wxAUI_NB_CLOSE_ON_ACTIVE_TAB,
    wxVB_MOUSE_MIDDLE_CLOSE_TAB = 0x20000000
};

class NotebookNavDialog;
class wxMenu;

class WXDLLIMPEXP_SDK Notebook : public wxAuiNotebook
{
    NotebookNavDialog *m_popupWin;
    wxMenu*            m_contextMenu;
    wxArrayPtrVoid     m_history;
    long               m_style;
    size_t             m_leftDownTabIdx;
    bool               m_notify;
    wxPoint            m_leftDownPos;

public:
    static const size_t npos = static_cast<size_t>(-1);

protected:
    void      Initialize();
    void      PushPageHistory(wxWindow *page);
    void      PopPageHistory(wxWindow *page);
    wxWindow* GetPreviousSelection();
    bool      HasCloseButton() {
        return m_style & wxVB_HAS_X;
    }
    bool      HasCloseMiddle() {
        return m_style & wxVB_MOUSE_MIDDLE_CLOSE_TAB;
    }

public:
    Notebook(wxWindow *parent, wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0);
    virtual ~Notebook();

    /**
     * \brief set page at given index to be the selected page. this function does not trigger an event
     * \param page
     */
    void SetSelection(size_t page, bool notify = false);

    /**
     * \brief add page to the book
     * \param win window to add, the window will be reparented to the book
     * \param text page's caption
     * \param selected set the page as the selected page
     */
    bool AddPage(wxWindow *win, const wxString &text, bool selected = false, const wxBitmap &bmp = wxNullBitmap);
    bool InsertPage(size_t index, wxWindow *win, const wxString &text, bool selected = false, const wxBitmap &bmp = wxNullBitmap);

    /**
     * \brief return page at give position
     * \param page page's index
     * \return the page or NULL if index is out of bounds
     */
    wxWindow *GetPage(size_t page) const;

    /**
     * \brief return the page caption
     * \param page page index
     * \return text or wxEmptyString if page index is invalid
     */
    wxString GetPageText(size_t page) const;

    /**
     * \brief remove page from the book without destroying it
     * \param notify set this to true if you wish to receive wxEVT_COMMAND_BOOK_PAGE_CLOSING & wxEVT_COMMAND_BOOK_PAGE_CLOSED
     */
    bool RemovePage(size_t page, bool notify = true);

    /**
     * \brief delete page from the book and destroy it as well
     * \param notify set this to true if you wish to receive wxEVT_COMMAND_BOOK_PAGE_CLOSING & wxEVT_COMMAND_BOOK_PAGE_CLOSED
     */
    bool DeletePage(size_t page, bool notify = true);

    /**
     * \brief delete all the pages in the notebook
     */
    bool DeleteAllPages(bool notify = false);

    /**
     * \brief return the tabbing history for this notebook
     */
    const wxArrayPtrVoid& GetHistory() const;

    /**
     *\param menu - right click menu object
     */
    void SetRightClickMenu(wxMenu* menu);

    /**
     * \brief return the active page
     * \return active page or NULL if there are no pages in the book
     */
    wxWindow *GetCurrentPage() const;

    /**
     * \brief return page index by window pointer
     * \param page page to search
     * \return page index, or Notebook::npos if page does not exist in the notebook
     */
    size_t GetPageIndex(wxWindow *page) const;

    /**
     * \brief return page index by page text
     * \param text text to search for
     * \return page index, or Notebook::npos if page does not exist in the notebook
     */
    size_t GetPageIndex(const wxString &text) const;

    /**
     * \brief returns the index within its tabctrl of the selected editor
     * \return page index, or Notebook::npos if page does not exist in the notebook
     */
    size_t GetVisibleEditorIndex();

    /**
     * \brief set the text for page at a given index
     * \param index page's index
     * \param text new text
     */
    bool SetPageText(size_t index, const wxString &text);

    /**
     * \brief tries to get a list of displayed editors, in display order
     * \param vector in which to return the editors
     */
    void GetEditorsInOrder(std::vector<wxWindow*> &editors);
    
    /**
     * @brief return an array of pages text in order
     */
    wxArrayString GetPagesTextInOrder() const;

    
    /**
     * @brief return a set of the used wxAuiTabControl in the notebook
     */
    std::set<wxAuiTabCtrl*> GetAllTabControls();

protected:
    // Event handlers
    void OnNavigationKey      (wxNavigationKeyEvent &e);
    void OnKeyDown            (wxKeyEvent           &e);
    void OnTabRightDown       (wxAuiNotebookEvent   &e);
    void OnTabRightUp         (wxAuiNotebookEvent   &e);
    void OnTabMiddle          (wxAuiNotebookEvent   &e);
    void OnTabButton          (wxAuiNotebookEvent   &e);

    // wxAuiNotebook events
    void OnInternalPageChanged (wxAuiNotebookEvent &e);
    void OnInternalPageChanging(wxAuiNotebookEvent &e);
    void OnInternalPageClosing (wxAuiNotebookEvent &e);
    void OnInternalPageClosed  (wxAuiNotebookEvent &e);
    void OnBgDclick            (wxAuiNotebookEvent &e);
    void OnEndDrag             (wxAuiNotebookEvent &e);

    void OnInternalMenu        (wxCommandEvent  &e);

    // wxChoicebook events
    void OnFocus                (wxFocusEvent      &e);

protected:
    void DoPageChangedEvent   (wxAuiNotebookEvent &e);
    void DoPageChangingEvent  (wxAuiNotebookEvent &e);
    bool DoNavigate();

};

class WXDLLIMPEXP_SDK NotebookEvent : public wxNotifyEvent
{
    size_t sel, oldsel;

public:
    /**
     * \param commandType - event type
     * \param winid - window ID
     * \param nSel - current selection
     * \param nOldSel - old selection
     */
    NotebookEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, size_t nSel = (size_t)-1, size_t nOldSel = (size_t)-1)
        : wxNotifyEvent(commandType, winid), sel(nSel), oldsel(nOldSel) { }

    /**
     * \param s - index of currently selected page
     */
    void SetSelection(size_t s) {
        sel = s;
    }

    /**
     * \param s - index of previously selected page
     */
    void SetOldSelection(size_t s) {
        oldsel = s;
    }

    /// Returns the index of currently selected page
    size_t GetSelection() {
        return sel;
    }

    /// Returns the index of previously selected page
    size_t GetOldSelection() {
        return oldsel;
    }

    virtual wxEvent *Clone() const {
        return new NotebookEvent(*this);
    }
};

extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_PAGE_CHANGED;
extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_PAGE_CHANGING;
extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_PAGE_CLOSING;
extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_PAGE_CLOSED;
extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_PAGE_MIDDLE_CLICKED;
extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_PAGE_X_CLICKED;
extern WXDLLIMPEXP_SDK const wxEventType wxEVT_COMMAND_BOOK_BG_DCLICK;

typedef void (wxEvtHandler::*NotebookEventFunction)(NotebookEvent&);

#define NotebookEventHandler(func) \
    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(NotebookEventFunction, &func)

#define EVT_BOOK_PAGE_CHANGED(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_PAGE_CHANGED, winid, NotebookEventHandler(fn))

#define EVT_BOOK_PAGE_CHANGING(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_PAGE_CHANGING, winid, NotebookEventHandler(fn))

#define EVT_BOOK_PAGE_CLOSING(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_PAGE_CLOSING, winid, NotebookEventHandler(fn))

#define EVT_BOOK_PAGE_CLOSED(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_PAGE_CLOSED, winid, NotebookEventHandler(fn))

#define EVT_BOOK_PAGE_MIDDLE_CLICKED(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_PAGE_MIDDLE_CLICKED, winid, NotebookEventHandler(fn))

#define EVT_BOOK_PAGE_X_CLICKED(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_PAGE_X_CLICKED, winid, NotebookEventHandler(fn))

#define EVT_BOOK_SWAP_PAGES(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_SWAP_PAGES, winid, NotebookEventHandler(fn))

#define EVT_BOOK_BG_DCLICK(winid, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_BOOK_BG_DCLICK, winid, NotebookEventHandler(fn))

#endif // __WXGTK__

#endif // __Notebook__