2
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3
* http://www.gnu.org/licenses/lgpl-3.0.html
12
#include "cbauibook.h"
13
//#include <wx/arrimpl.cpp>
15
//WX_DEFINE_OBJARRAY(cbAuiTabCtrlArray);
18
const int wxAuiBaseTabCtrlId = 5380;
21
BEGIN_EVENT_TABLE(cbAuiNotebook, wxAuiNotebook)
22
#if wxCHECK_VERSION(2, 9, 0)
23
EVT_NAVIGATION_KEY(cbAuiNotebook::OnNavigationKeyNotebook)
25
EVT_NAVIGATION_KEY(cbAuiNotebook::OnNavigationKey)
29
cbAuiNotebook::cbAuiNotebook(wxWindow* pParent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
30
: wxAuiNotebook(pParent, id, pos, size, style)
34
m_mgr.SetFlags((m_mgr.GetFlags() | wxAUI_MGR_VENETIAN_BLINDS_HINT) & ~wxAUI_MGR_TRANSPARENT_HINT);
35
#endif // #ifdef __WXGTK__
38
void cbAuiNotebook::UpdateTabControlsArray()
41
// first get all tab-controls
42
const size_t tab_Count = GetPageCount();
43
for (size_t i = 0; i < tab_Count; ++i)
45
wxAuiTabCtrl* tabCtrl = 0;
47
if (FindTab(GetPage(i), &tabCtrl, &idx))
49
if(m_TabCtrls.Index(tabCtrl) == wxNOT_FOUND)
51
m_TabCtrls.Add(tabCtrl);
61
int cbAuiNotebook::GetTabPositionFromIndex(int index)
63
if (GetPageCount() <= 1)
68
UpdateTabControlsArray();
70
wxAuiTabCtrl* tabCtrl = 0;
73
if (!FindTab(GetPage(index), &tabCtrl, &idx))
78
if (!tabCtrl || idx < 0)
84
wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
85
const size_t pane_count = all_panes.GetCount();
86
for (size_t i = 0; i < pane_count; ++i)
88
wxAuiPaneInfo& pane = all_panes.Item(i);
89
if (pane.name == wxT("dummy"))
94
if(pane.window == GetTabFrameFromTabCtrl(tabCtrl))
98
for (size_t j = 0; j < m_TabCtrls.GetCount(); ++j)
100
if(pane.window == GetTabFrameFromTabCtrl(m_TabCtrls.Item(j)))
102
indexOffset += m_TabCtrls.Item(j)->GetPageCount();
107
return idx + indexOffset;
110
void cbAuiNotebook::AdvanceSelection(bool forward)
112
if (GetPageCount() <= 1)
117
int currentSelection = GetSelection();
119
wxAuiTabCtrl* tabCtrl = 0;
122
if (!FindTab(GetPage(currentSelection), &tabCtrl, &idx))
127
if (!tabCtrl || idx < 0)
133
size_t maxPages = tabCtrl->GetPageCount();
142
if ((size_t)idx < maxPages)
144
page = tabCtrl->GetPage(idx).window;
147
if (!page && maxPages > 0)
149
page = tabCtrl->GetPage(0).window;
154
currentSelection = GetPageIndex(page);
155
SetSelection(currentSelection);
159
#if wxCHECK_VERSION(2, 9, 0)
160
void cbAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent& event)
162
void cbAuiNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
165
// if we change window, we call our own AdvanceSelection
166
if ( event.IsWindowChange() )
168
AdvanceSelection(event.GetDirection());
170
else // otherwise we call the event-handler from the parent-class
172
#if wxCHECK_VERSION(2, 9, 0)
173
wxAuiNotebook::OnNavigationKeyNotebook(event);
175
wxAuiNotebook::OnNavigationKey(event);
180
wxString cbAuiNotebook::SavePerspective()
182
// Build list of panes/tabs
185
// first get all tab-controls
186
UpdateTabControlsArray();
188
wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
189
const size_t pane_count = all_panes.GetCount();
190
for (size_t i = 0; i < pane_count; ++i)
192
wxAuiPaneInfo& pane = all_panes.Item(i);
193
if (pane.name == wxT("dummy"))
198
wxAuiTabCtrl* tabCtrl = 0;
199
for (size_t j = 0; j < m_TabCtrls.GetCount(); ++j)
201
if(pane.window == GetTabFrameFromTabCtrl(m_TabCtrls.Item(j)))
203
tabCtrl = m_TabCtrls.Item(j);
217
size_t page_count = tabCtrl->GetPageCount();
218
for (size_t p = 0; p < page_count; ++p)
220
wxAuiNotebookPage& page = tabCtrl->GetPage(p);
221
const size_t page_idx = m_tabs.GetIdxFromWindow(page.window);
228
if ((int)page_idx == m_curpage)
232
else if ((int)p == tabCtrl->GetActivePage())
236
tabs += wxString::Format(wxT("%u"), page_idx);
242
// Add frame perspective
243
tabs += m_mgr.SavePerspective();
248
//bool cbAuiNotebook::LoadPerspective(const wxString& layout) {
249
// // Remove all tab ctrls (but still keep them in main index)
250
// const size_t tab_count = m_tabs.GetPageCount();
251
// for (size_t i = 0; i < tab_count; ++i) {
252
// wxWindow* wnd = m_tabs.GetWindowFromIdx(i);
254
// // find out which onscreen tab ctrl owns this tab
255
// wxAuiTabCtrl* ctrl;
257
// if (!FindTab(wnd, &ctrl, &ctrl_idx))
260
// // remove the tab from ctrl
261
// if (!ctrl->RemovePage(wnd))
264
// RemoveEmptyTabFrames();
266
// size_t sel_page = 0;
268
// wxString tabs = layout.BeforeFirst(wxT('@'));
271
// const wxString tab_part = tabs.BeforeFirst(wxT('|'));
273
// // if the string is empty, we're done parsing
274
// if (tab_part.empty())
278
// const wxString pane_name = tab_part.BeforeFirst(wxT('='));
280
// // create a new tab frame
281
// wxTabFrame* new_tabs = new wxTabFrame;
282
// new_tabs->m_tabs = new wxAuiTabCtrl(this,
283
// m_tab_id_counter++);
284
//// wxDefaultPosition,
286
//// wxNO_BORDER|wxWANTS_CHARS);
287
// new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone());
288
// new_tabs->SetTabCtrlHeight(m_tab_ctrl_height);
289
// new_tabs->m_tabs->SetFlags(m_flags);
290
// wxAuiTabCtrl *dest_tabs = new_tabs->m_tabs;
292
// // create a pane info structure with the information
293
// // about where the pane should be added
294
// wxAuiPaneInfo pane_info = wxAuiPaneInfo().Name(pane_name).Bottom().CaptionVisible(false);
295
// m_mgr.AddPane(new_tabs, pane_info);
297
// // Get list of tab id's and move them to pane
298
// wxString tab_list = tab_part.AfterFirst(wxT('='));
300
// wxString tab = tab_list.BeforeFirst(wxT(','));
301
// if (tab.empty()) break;
302
// tab_list = tab_list.AfterFirst(wxT(','));
304
// // Check if this page has an 'active' marker
305
// const wxChar c = tab[0];
306
// if (c == wxT('+') || c == wxT('*')) {
310
// const size_t tab_idx = wxAtoi(tab.c_str());
311
// if (tab_idx >= GetPageCount()) continue;
313
// // Move tab to pane
314
// wxAuiNotebookPage& page = m_tabs.GetPage(tab_idx);
315
// const size_t newpage_idx = dest_tabs->GetPageCount();
316
// dest_tabs->InsertPage(page.window, page, newpage_idx);
318
// if (c == wxT('+')) dest_tabs->SetActivePage(newpage_idx);
319
// else if ( c == wxT('*')) sel_page = tab_idx;
321
// dest_tabs->DoShowHide();
323
// tabs = tabs.AfterFirst(wxT('|'));
326
// // Load the frame perspective
327
// const wxString frames = layout.AfterFirst(wxT('@'));
328
// m_mgr.LoadPerspective(frames);
330
// // Force refresh of selection
332
// SetSelection(sel_page);