~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/sdk/cbauibook.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
4
 *
 
5
 * $Revision$
 
6
 * $Id$
 
7
 * $HeadURL$
 
8
 */
 
9
 
 
10
 
 
11
#include "prep.h"
 
12
#include "cbauibook.h"
 
13
//#include <wx/arrimpl.cpp>
 
14
 
 
15
//WX_DEFINE_OBJARRAY(cbAuiTabCtrlArray);
 
16
 
 
17
 
 
18
const int wxAuiBaseTabCtrlId = 5380;
 
19
 
 
20
 
 
21
BEGIN_EVENT_TABLE(cbAuiNotebook, wxAuiNotebook)
 
22
#if wxCHECK_VERSION(2, 9, 0)
 
23
    EVT_NAVIGATION_KEY(cbAuiNotebook::OnNavigationKeyNotebook)
 
24
#else
 
25
    EVT_NAVIGATION_KEY(cbAuiNotebook::OnNavigationKey)
 
26
#endif
 
27
END_EVENT_TABLE()
 
28
 
 
29
cbAuiNotebook::cbAuiNotebook(wxWindow* pParent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
 
30
        : wxAuiNotebook(pParent, id, pos, size, style)
 
31
{
 
32
    //ctor
 
33
#ifdef __WXGTK__
 
34
    m_mgr.SetFlags((m_mgr.GetFlags() | wxAUI_MGR_VENETIAN_BLINDS_HINT) & ~wxAUI_MGR_TRANSPARENT_HINT);
 
35
#endif  // #ifdef __WXGTK__
 
36
}
 
37
 
 
38
void cbAuiNotebook::UpdateTabControlsArray()
 
39
{
 
40
    m_TabCtrls.Clear();
 
41
    // first get all tab-controls
 
42
    const size_t tab_Count = GetPageCount();
 
43
    for (size_t i = 0; i < tab_Count; ++i)
 
44
    {
 
45
        wxAuiTabCtrl* tabCtrl = 0;
 
46
        int idx = -1;
 
47
        if (FindTab(GetPage(i), &tabCtrl, &idx))
 
48
        {
 
49
            if(m_TabCtrls.Index(tabCtrl) == wxNOT_FOUND)
 
50
            {
 
51
                m_TabCtrls.Add(tabCtrl);
 
52
            }
 
53
        }
 
54
        else
 
55
        {
 
56
            continue;
 
57
        }
 
58
    }
 
59
}
 
60
 
 
61
int cbAuiNotebook::GetTabPositionFromIndex(int index)
 
62
{
 
63
    if (GetPageCount() <= 1)
 
64
    {
 
65
        return wxNOT_FOUND;
 
66
    }
 
67
 
 
68
    UpdateTabControlsArray();
 
69
 
 
70
    wxAuiTabCtrl* tabCtrl = 0;
 
71
    int idx = -1;
 
72
 
 
73
    if (!FindTab(GetPage(index), &tabCtrl, &idx))
 
74
    {
 
75
        return wxNOT_FOUND;
 
76
    }
 
77
 
 
78
    if (!tabCtrl || idx < 0)
 
79
    {
 
80
        return wxNOT_FOUND;
 
81
    }
 
82
 
 
83
    int indexOffset = 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)
 
87
    {
 
88
        wxAuiPaneInfo& pane = all_panes.Item(i);
 
89
        if (pane.name == wxT("dummy"))
 
90
        {
 
91
            continue;
 
92
        }
 
93
 
 
94
        if(pane.window == GetTabFrameFromTabCtrl(tabCtrl))
 
95
        {
 
96
            break;
 
97
        }
 
98
        for (size_t j = 0; j < m_TabCtrls.GetCount(); ++j)
 
99
        {
 
100
            if(pane.window == GetTabFrameFromTabCtrl(m_TabCtrls.Item(j)))
 
101
            {
 
102
                indexOffset += m_TabCtrls.Item(j)->GetPageCount();
 
103
                break;
 
104
            }
 
105
        }
 
106
    }
 
107
    return idx + indexOffset;
 
108
}
 
109
 
 
110
void cbAuiNotebook::AdvanceSelection(bool forward)
 
111
{
 
112
    if (GetPageCount() <= 1)
 
113
    {
 
114
        return;
 
115
    }
 
116
 
 
117
    int currentSelection = GetSelection();
 
118
 
 
119
    wxAuiTabCtrl* tabCtrl = 0;
 
120
    int idx = -1;
 
121
 
 
122
    if (!FindTab(GetPage(currentSelection), &tabCtrl, &idx))
 
123
    {
 
124
        return;
 
125
    }
 
126
 
 
127
    if (!tabCtrl || idx < 0)
 
128
    {
 
129
        return;
 
130
    }
 
131
 
 
132
    wxWindow* page = 0;
 
133
    size_t maxPages = tabCtrl->GetPageCount();
 
134
 
 
135
    forward?idx++:idx--;
 
136
 
 
137
    if (idx < 0)
 
138
    {
 
139
        idx = maxPages - 1;
 
140
    }
 
141
 
 
142
    if ((size_t)idx < maxPages)
 
143
    {
 
144
        page = tabCtrl->GetPage(idx).window;
 
145
    }
 
146
 
 
147
    if (!page && maxPages > 0)
 
148
    {
 
149
        page = tabCtrl->GetPage(0).window;
 
150
    }
 
151
 
 
152
    if (page)
 
153
    {
 
154
        currentSelection = GetPageIndex(page);
 
155
        SetSelection(currentSelection);
 
156
    }
 
157
}
 
158
 
 
159
#if wxCHECK_VERSION(2, 9, 0)
 
160
void cbAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent& event)
 
161
#else
 
162
void cbAuiNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
 
163
#endif
 
164
{
 
165
    // if we change window, we call our own AdvanceSelection
 
166
    if ( event.IsWindowChange() )
 
167
    {
 
168
        AdvanceSelection(event.GetDirection());
 
169
    }
 
170
    else // otherwise we call the event-handler from the parent-class
 
171
    {
 
172
#if wxCHECK_VERSION(2, 9, 0)
 
173
        wxAuiNotebook::OnNavigationKeyNotebook(event);
 
174
#else
 
175
        wxAuiNotebook::OnNavigationKey(event);
 
176
#endif
 
177
    }
 
178
}
 
179
 
 
180
wxString cbAuiNotebook::SavePerspective()
 
181
{
 
182
    // Build list of panes/tabs
 
183
    wxString tabs;
 
184
 
 
185
    // first get all tab-controls
 
186
    UpdateTabControlsArray();
 
187
 
 
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)
 
191
    {
 
192
        wxAuiPaneInfo& pane = all_panes.Item(i);
 
193
        if (pane.name == wxT("dummy"))
 
194
        {
 
195
            continue;
 
196
        }
 
197
 
 
198
        wxAuiTabCtrl* tabCtrl = 0;
 
199
        for (size_t j = 0; j < m_TabCtrls.GetCount(); ++j)
 
200
        {
 
201
            if(pane.window == GetTabFrameFromTabCtrl(m_TabCtrls.Item(j)))
 
202
            {
 
203
                tabCtrl = m_TabCtrls.Item(j);
 
204
                break;
 
205
            }
 
206
        }
 
207
        if(tabCtrl)
 
208
        {
 
209
            if (!tabs.empty())
 
210
            {
 
211
                tabs += wxT("|");
 
212
            }
 
213
            tabs += pane.name;
 
214
            tabs += wxT("=");
 
215
 
 
216
            // add tab id's
 
217
            size_t page_count = tabCtrl->GetPageCount();
 
218
            for (size_t p = 0; p < page_count; ++p)
 
219
            {
 
220
                wxAuiNotebookPage& page = tabCtrl->GetPage(p);
 
221
                const size_t page_idx = m_tabs.GetIdxFromWindow(page.window);
 
222
 
 
223
                if (p)
 
224
                {
 
225
                    tabs += wxT(",");
 
226
                }
 
227
 
 
228
                if ((int)page_idx == m_curpage)
 
229
                {
 
230
                    tabs += wxT("*");
 
231
                }
 
232
                else if ((int)p == tabCtrl->GetActivePage())
 
233
                {
 
234
                    tabs += wxT("+");
 
235
                }
 
236
                tabs += wxString::Format(wxT("%u"), page_idx);
 
237
            }
 
238
        }
 
239
    }
 
240
    tabs += wxT("@");
 
241
 
 
242
    // Add frame perspective
 
243
    tabs += m_mgr.SavePerspective();
 
244
 
 
245
    return tabs;
 
246
}
 
247
 
 
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);
 
253
//
 
254
//      // find out which onscreen tab ctrl owns this tab
 
255
//      wxAuiTabCtrl* ctrl;
 
256
//      int ctrl_idx;
 
257
//      if (!FindTab(wnd, &ctrl, &ctrl_idx))
 
258
//         return false;
 
259
//
 
260
//      // remove the tab from ctrl
 
261
//      if (!ctrl->RemovePage(wnd))
 
262
//         return false;
 
263
//   }
 
264
//   RemoveEmptyTabFrames();
 
265
//
 
266
//   size_t sel_page = 0;
 
267
//
 
268
//   wxString tabs = layout.BeforeFirst(wxT('@'));
 
269
//   while (1)
 
270
//    {
 
271
//      const wxString tab_part = tabs.BeforeFirst(wxT('|'));
 
272
//
 
273
//      // if the string is empty, we're done parsing
 
274
//        if (tab_part.empty())
 
275
//            break;
 
276
//
 
277
//      // Get pane name
 
278
//      const wxString pane_name = tab_part.BeforeFirst(wxT('='));
 
279
//
 
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,
 
285
////                            wxDefaultSize,
 
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;
 
291
//
 
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);
 
296
//
 
297
//      // Get list of tab id's and move them to pane
 
298
//      wxString tab_list = tab_part.AfterFirst(wxT('='));
 
299
//      while(1) {
 
300
//         wxString tab = tab_list.BeforeFirst(wxT(','));
 
301
//         if (tab.empty()) break;
 
302
//         tab_list = tab_list.AfterFirst(wxT(','));
 
303
//
 
304
//         // Check if this page has an 'active' marker
 
305
//         const wxChar c = tab[0];
 
306
//         if (c == wxT('+') || c == wxT('*')) {
 
307
//            tab = tab.Mid(1);
 
308
//         }
 
309
//
 
310
//         const size_t tab_idx = wxAtoi(tab.c_str());
 
311
//         if (tab_idx >= GetPageCount()) continue;
 
312
//
 
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);
 
317
//
 
318
//         if (c == wxT('+')) dest_tabs->SetActivePage(newpage_idx);
 
319
//         else if ( c == wxT('*')) sel_page = tab_idx;
 
320
//      }
 
321
//      dest_tabs->DoShowHide();
 
322
//
 
323
//      tabs = tabs.AfterFirst(wxT('|'));
 
324
//   }
 
325
//
 
326
//   // Load the frame perspective
 
327
//   const wxString frames = layout.AfterFirst(wxT('@'));
 
328
//   m_mgr.LoadPerspective(frames);
 
329
//
 
330
//   // Force refresh of selection
 
331
//   m_curpage = -1;
 
332
//   SetSelection(sel_page);
 
333
//
 
334
//   return true;
 
335
//}