~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/sdk/wxFlatNotebook/src/wxFlatNotebook/wxFlatNotebook.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////
 
2
// Name:                wxFlatNotebook.cpp
 
3
// Purpose:     generic implementation of flat style notebook class.
 
4
// Author:      Eran Ifrah <eranif@bezeqint.net>
 
5
// Modified by: Priyank Bolia <soft@priyank.in>
 
6
// Created:     30/12/2005
 
7
// Modified:    01/01/2006
 
8
// Copyright:   Eran Ifrah (c)
 
9
// Licence:     wxWindows license <http://www.wxwidgets.org/licence3.txt>
 
10
///////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
#include <wx/wxFlatNotebook/wxFlatNotebook.h>
 
13
#include <wx/wxFlatNotebook/renderer.h>
 
14
#include <wx/wxFlatNotebook/popup_dlg.h>
 
15
#include <wx/wxFlatNotebook/fnb_customize_dlg.h>
 
16
#include <algorithm>
 
17
#include <wx/tooltip.h>
 
18
#include <wx/tipwin.h>
 
19
#include <wx/arrimpl.cpp>
 
20
 
 
21
#ifdef DEVELOPMENT
 
22
# define FNB_LOG_MSG( msg ) { wxString logmsg; logmsg << msg; wxLogMessage( logmsg ); }
 
23
#else
 
24
# define FNB_LOG_MSG( msg ) { wxString logmsg; logmsg << msg; }
 
25
#endif
 
26
 
 
27
static bool InsideRect(const wxRect &rect, const wxPoint &pt)
 
28
{
 
29
#if wxCHECK_VERSION(2, 8, 0)
 
30
        return rect.Contains(pt);
 
31
#else
 
32
        return rect.Inside(pt);
 
33
#endif
 
34
}
 
35
 
 
36
#ifdef DEVELOPMENT
 
37
#include <map>
 
38
wxString WhereToString( int where )
 
39
{
 
40
        static std::map<int, wxString> whereMap;
 
41
        static bool first = true;
 
42
 
 
43
        if( first )
 
44
        {
 
45
                whereMap[wxFNB_TAB] = wxT("wxFNB_TAB");
 
46
                whereMap[wxFNB_X] = wxT("wxFNB_X");
 
47
                whereMap[wxFNB_TAB_X] = wxT("wxFNB_TAB_X");
 
48
                whereMap[wxFNB_LEFT_ARROW] = wxT("wxFNB_LEFT_ARROW");
 
49
                whereMap[wxFNB_RIGHT_ARROW] = wxT("wxFNB_RIGHT_ARROW");
 
50
                whereMap[wxFNB_DROP_DOWN_ARROW] = wxT("wxFNB_DROP_DOWN_ARROW");
 
51
                whereMap[wxFNB_NOWHERE] = wxT("wxFNB_NOWHERE");
 
52
                first = false;
 
53
        }
 
54
        return whereMap[where];
 
55
}
 
56
#endif
 
57
 
 
58
//-------------------------------------------------------------------
 
59
// Provide user with a nice feedback when tab is being dragged
 
60
//-------------------------------------------------------------------
 
61
bool wxFNBDropSource::GiveFeedback(wxDragResult effect)
 
62
{
 
63
        wxUnusedVar(effect);
 
64
        static_cast<wxPageContainer*>( m_win )->DrawDragHint();
 
65
        return false;
 
66
}
 
67
 
 
68
IMPLEMENT_DYNAMIC_CLASS(wxFlatNotebookEvent, wxNotifyEvent)
 
69
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGED)
 
70
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGING)
 
71
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSING)
 
72
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_CONTEXT_MENU)
 
73
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSED)
 
74
 
 
75
IMPLEMENT_DYNAMIC_CLASS(wxFlatNotebook, wxPanel)
 
76
 
 
77
WX_DEFINE_OBJARRAY(wxFlatNotebookImageList);
 
78
WX_DEFINE_OBJARRAY(wxPageInfoArray)
 
79
WX_DEFINE_OBJARRAY(wxWindowPtrArray)
 
80
 
 
81
BEGIN_EVENT_TABLE(wxFlatNotebook, wxPanel)
 
82
EVT_NAVIGATION_KEY(wxFlatNotebook::OnNavigationKey)
 
83
END_EVENT_TABLE()
 
84
 
 
85
wxFlatNotebook::wxFlatNotebook(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
 
86
{
 
87
        Init();
 
88
        Create(parent, id, pos, size, style, name);
 
89
}
 
90
 
 
91
void wxFlatNotebook::CleanUp ()
 
92
{
 
93
    wxFNBRendererMgrST::Free();
 
94
}
 
95
 
 
96
wxFlatNotebook::~wxFlatNotebook(void)
 
97
{
 
98
}
 
99
 
 
100
void wxFlatNotebook::Init()
 
101
{
 
102
    m_popupWin = NULL;
 
103
    m_sendPageChangeEvent = true;
 
104
        m_bForceSelection = false;
 
105
        m_nPadding = 6;
 
106
        m_nFrom = 0;
 
107
        m_pages = NULL;
 
108
        m_mainSizer = new wxBoxSizer(wxVERTICAL);
 
109
        SetSizer(m_mainSizer);
 
110
}
 
111
 
 
112
bool wxFlatNotebook::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
 
113
                             long style, const wxString& name)
 
114
{
 
115
        style |= wxTAB_TRAVERSAL;
 
116
        wxPanel::Create(parent, id, pos, size, style, name);
 
117
 
 
118
        m_pages = new wxPageContainer(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
 
119
        m_pages->m_colorBorder = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
 
120
 
 
121
        m_mainSizer = new wxBoxSizer(wxVERTICAL);
 
122
        SetSizer(m_mainSizer);
 
123
 
 
124
        SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
 
125
 
 
126
        // Set default page height
 
127
        wxMemoryDC memDc;
 
128
 
 
129
        wxBitmap bmp(10, 10);
 
130
        memDc.SelectObject(bmp);
 
131
 
 
132
        int width, height;
 
133
 
 
134
 
 
135
#ifdef __WXGTK__
 
136
        // For GTK it seems that we must do this steps in order
 
137
        // for the tabs will get the proper height on initialization
 
138
        // on MSW, preforming these steps yields wierd results
 
139
        wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
 
140
        wxFont boldFont = normalFont;
 
141
        boldFont.SetWeight(wxFONTWEIGHT_BOLD);
 
142
        memDc.SetFont( boldFont );
 
143
#endif
 
144
 
 
145
        wxString stam = wxT("Tp");      // Temp data to get the text height;
 
146
        memDc.GetTextExtent(stam, &width, &height);
 
147
 
 
148
        int tabHeight = height + wxFNB_HEIGHT_SPACER; // We use 8 pixels as padding
 
149
#ifdef __WXGTK__
 
150
        // On GTK the tabs are should be larger
 
151
        tabHeight += 6;
 
152
#endif
 
153
        m_pages->SetSizeHints(wxSize(-1, tabHeight));
 
154
 
 
155
        // Add the tab container to the sizer
 
156
        m_mainSizer->Insert(0, m_pages, 0, wxEXPAND);
 
157
        m_mainSizer->Layout();
 
158
 
 
159
        m_pages->m_nFrom = m_nFrom;
 
160
        m_pDropTarget = new wxFNBDropTarget<wxFlatNotebook>(this, &wxFlatNotebook::OnDropTarget);
 
161
        SetDropTarget(m_pDropTarget);
 
162
        return true;
 
163
}
 
164
 
 
165
void wxFlatNotebook::SetActiveTabTextColour(const wxColour& textColour)
 
166
{
 
167
        m_pages->m_activeTextColor = textColour;
 
168
}
 
169
 
 
170
wxDragResult wxFlatNotebook::OnDropTarget(wxCoord x, wxCoord y, int nTabPage, wxWindow * wnd_oldContainer)
 
171
{
 
172
        return m_pages->OnDropTarget(x, y, nTabPage, wnd_oldContainer);
 
173
}
 
174
 
 
175
int wxFlatNotebook::GetPreviousSelection() const
 
176
{
 
177
        return m_pages->GetPreviousSelection();
 
178
}
 
179
 
 
180
const wxArrayInt &wxFlatNotebook::GetBrowseHistory() const
 
181
{
 
182
        return m_pages->m_history;
 
183
}
 
184
 
 
185
bool wxFlatNotebook::AddPage(wxWindow* window, const wxString& caption, const bool selected, const int imgindex)
 
186
{
 
187
        return InsertPage(m_windows.GetCount(), window, caption, selected, imgindex);
 
188
}
 
189
 
 
190
void wxFlatNotebook::SetImageList(wxFlatNotebookImageList * imglist)
 
191
{
 
192
        m_pages->SetImageList(imglist);
 
193
}
 
194
 
 
195
wxFlatNotebookImageList * wxFlatNotebook::GetImageList()
 
196
{
 
197
        return m_pages->GetImageList();
 
198
}
 
199
 
 
200
bool wxFlatNotebook::InsertPage(size_t index, wxWindow* page, const wxString& text, bool select, const int imgindex)
 
201
{
 
202
        // sanity check
 
203
        if (!page)
 
204
                return false;
 
205
 
 
206
        // reparent the window to us
 
207
        page->Reparent(this);
 
208
 
 
209
        if( !m_pages->IsShown() )
 
210
                m_pages->Show();
 
211
 
 
212
        index = FNB_MIN((unsigned int)index, (unsigned int)m_windows.GetCount());
 
213
        // Insert tab
 
214
        bool bSelected = select || m_windows.empty();
 
215
        int curSel = m_pages->GetSelection();
 
216
 
 
217
        if(index <= m_windows.GetCount())
 
218
        {
 
219
                m_windows.Insert(page, index);
 
220
        }
 
221
        else
 
222
        {
 
223
                m_windows.Add(page);
 
224
        }
 
225
 
 
226
        if( !m_pages->InsertPage(index, page, text, bSelected, imgindex) )
 
227
                return false;
 
228
 
 
229
        if((int)index <= curSel) curSel++;
 
230
 
 
231
        Freeze();
 
232
 
 
233
        // Check if a new selection was made
 
234
        if(bSelected)
 
235
        {
 
236
                if(curSel >= 0)
 
237
                {
 
238
                        // Remove the window from the main sizer
 
239
                        m_mainSizer->Detach(m_windows[curSel]);
 
240
                        m_windows[curSel]->Hide();
 
241
                }
 
242
                m_pages->SetSelection(index);
 
243
        }
 
244
        else
 
245
        {
 
246
                // Hide the page
 
247
                page->Hide();
 
248
        }
 
249
        m_mainSizer->Layout();
 
250
        Thaw();
 
251
        Refresh();
 
252
 
 
253
        return true;
 
254
}
 
255
 
 
256
void wxFlatNotebook::SetSelection(size_t page)
 
257
{
 
258
        if(page >= m_windows.GetCount())
 
259
                return;
 
260
 
 
261
        // Support for disabed tabs
 
262
        if(!m_pages->GetEnabled(page) && m_windows.GetCount() > 1 && !m_bForceSelection)
 
263
                return;
 
264
 
 
265
        if( m_sendPageChangeEvent )
 
266
        {
 
267
                // Allow the user to veto the selection
 
268
                int oldSelection = GetSelection();
 
269
 
 
270
                wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGING, GetId());
 
271
                event.SetSelection( (int)page );
 
272
                event.SetOldSelection( oldSelection );
 
273
                event.SetEventObject( this );
 
274
                GetEventHandler()->ProcessEvent(event);
 
275
 
 
276
                if( !event.IsAllowed() )
 
277
                {
 
278
                        return;
 
279
                }
 
280
        }
 
281
 
 
282
        int curSel = m_pages->GetSelection();
 
283
 
 
284
        // program allows the page change
 
285
        Freeze();
 
286
        if(curSel >= 0)
 
287
        {
 
288
                // Remove the window from the main sizer
 
289
                m_mainSizer->Detach(m_windows[curSel]);
 
290
                m_windows[curSel]->Hide();
 
291
        }
 
292
 
 
293
        if(m_windowStyle & wxFNB_BOTTOM)
 
294
        {
 
295
                m_mainSizer->Insert(0, m_windows[page], 1, wxEXPAND);
 
296
        }
 
297
        else
 
298
        {
 
299
                // We leave a space of 1 pixel around the window
 
300
                m_mainSizer->Add(m_windows[page], 1, wxEXPAND);
 
301
        }
 
302
 
 
303
        m_windows[page]->Show();
 
304
        m_mainSizer->Layout();
 
305
        Thaw();
 
306
 
 
307
        if( page != (size_t)m_pages->m_iActivePage ){
 
308
                //keep the page history
 
309
                m_pages->PushPageHistory(m_pages->m_iActivePage);
 
310
        }
 
311
 
 
312
        m_pages->m_iActivePage = (int)page;
 
313
        m_pages->DoSetSelection(page);
 
314
 
 
315
        if( m_sendPageChangeEvent )
 
316
        {
 
317
                // Fire event 'Page Changed'
 
318
                wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGED, GetId());
 
319
                event.SetSelection( (int)page );
 
320
                event.SetEventObject( this );
 
321
                GetEventHandler()->ProcessEvent(event);
 
322
        }
 
323
}
 
324
 
 
325
void wxFlatNotebook::DeletePage(size_t page, bool notify)
 
326
{
 
327
        if(page >= m_windows.GetCount())
 
328
                return;
 
329
 
 
330
        // Fire a closing event
 
331
        if( notify )
 
332
        {
 
333
                wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSING, GetId());
 
334
                event.SetSelection((int)page);
 
335
                event.SetEventObject(this);
 
336
                GetEventHandler()->ProcessEvent(event);
 
337
 
 
338
 
 
339
                // The event handler allows it?
 
340
                if (!event.IsAllowed())
 
341
                        return;
 
342
        }
 
343
 
 
344
        Freeze();
 
345
 
 
346
        // Delete the requested page
 
347
        wxWindow *pageRemoved = m_windows[page];
 
348
 
 
349
        // If the page is the current window, remove it from the sizer
 
350
        // as well
 
351
        if((int)page == m_pages->GetSelection())
 
352
        {
 
353
                m_mainSizer->Detach(pageRemoved);
 
354
        }
 
355
 
 
356
        // Remove it from the array as well
 
357
        m_windows.RemoveAt(page);
 
358
 
 
359
        // Now we can destroy it; in wxWidgets use Destroy instead of delete
 
360
        pageRemoved->Destroy();
 
361
 
 
362
        Thaw();
 
363
 
 
364
        m_pages->DoDeletePage(page);
 
365
        Refresh();
 
366
 
 
367
        // Fire a closed event
 
368
        if( notify )
 
369
        {
 
370
                wxFlatNotebookEvent closedEvent(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSED, GetId());
 
371
                closedEvent.SetSelection((int)page);
 
372
                closedEvent.SetEventObject(this);
 
373
                GetEventHandler()->ProcessEvent(closedEvent);
 
374
        }
 
375
}
 
376
 
 
377
bool wxFlatNotebook::DeleteAllPages()
 
378
{
 
379
        if(m_windows.empty())
 
380
                return false;
 
381
 
 
382
        Freeze();
 
383
        int i = 0;
 
384
        for(; i<(int)m_windows.GetCount(); i++)
 
385
        {
 
386
                delete m_windows[i];
 
387
        }
 
388
 
 
389
        m_windows.Clear();
 
390
        Thaw();
 
391
 
 
392
        // Clear the container of the tabs as well
 
393
        m_pages->DeleteAllPages();
 
394
        return true;
 
395
}
 
396
 
 
397
wxWindow* wxFlatNotebook::GetCurrentPage() const
 
398
{
 
399
        int sel = m_pages->GetSelection();
 
400
        if(sel < 0)
 
401
                return NULL;
 
402
 
 
403
        return m_windows[sel];
 
404
}
 
405
 
 
406
wxWindow* wxFlatNotebook::GetPage(size_t page) const
 
407
{
 
408
        if(page >= m_windows.GetCount())
 
409
                return NULL;
 
410
 
 
411
        return m_windows[page];
 
412
}
 
413
 
 
414
int wxFlatNotebook::GetPageIndex(wxWindow* win) const
 
415
{
 
416
        for (size_t i = 0; i < m_windows.GetCount(); ++i)
 
417
        {
 
418
                if (m_windows[i] == win)
 
419
                        return (int)i;
 
420
        }
 
421
        return -1;
 
422
}
 
423
 
 
424
int wxFlatNotebook::GetSelection() const
 
425
{
 
426
        return m_pages->GetSelection();
 
427
}
 
428
 
 
429
void wxFlatNotebook::AdvanceSelection(bool bForward)
 
430
{
 
431
        m_pages->AdvanceSelection(bForward);
 
432
}
 
433
 
 
434
int wxFlatNotebook::GetPageCount() const
 
435
{
 
436
        return (int)m_pages->GetPageCount();
 
437
}
 
438
 
 
439
void wxFlatNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
 
440
{
 
441
        if ( event.IsWindowChange() )
 
442
        {
 
443
                if( HasFlag(wxFNB_SMART_TABS) )
 
444
                {
 
445
                        if( !m_popupWin && GetPageCount() > 0)
 
446
                        {
 
447
                                m_popupWin = new wxTabNavigatorWindow( this );
 
448
                                m_popupWin->ShowModal();
 
449
                                m_popupWin->Destroy();
 
450
                                SetSelection((size_t)GetSelection());
 
451
                                m_popupWin = NULL;
 
452
                        }
 
453
                        else if( m_popupWin )
 
454
                        {
 
455
                                // a dialog is already opened
 
456
                                m_popupWin->OnNavigationKey( event );
 
457
                                return;
 
458
                        }
 
459
                }
 
460
                else
 
461
                {
 
462
                        // change pages
 
463
                        AdvanceSelection(event.GetDirection());
 
464
                }
 
465
        }
 
466
        else
 
467
        {
 
468
                // pass to the parent
 
469
                if ( GetParent() )
 
470
                {
 
471
                        event.SetCurrentFocus(this);
 
472
                        GetParent()->ProcessEvent(event);
 
473
                }
 
474
        }
 
475
}
 
476
 
 
477
bool wxFlatNotebook::GetPageShapeAngle(int page_index, unsigned int * result)
 
478
{
 
479
        if(page_index < 0 || page_index >= (int)m_pages->m_pagesInfoVec.GetCount()) return false;
 
480
        *result = m_pages->m_pagesInfoVec[page_index].GetTabAngle();
 
481
        return true;
 
482
}
 
483
 
 
484
void wxFlatNotebook::SetPageShapeAngle(int page_index, unsigned int angle)
 
485
{
 
486
        if(page_index < 0 || page_index >= (int)m_pages->m_pagesInfoVec.GetCount()) return;
 
487
        if(angle > 15) return;
 
488
 
 
489
        m_pages->m_pagesInfoVec[page_index].SetTabAngle(angle);
 
490
}
 
491
 
 
492
void wxFlatNotebook::SetAllPagesShapeAngle(unsigned int angle)
 
493
{
 
494
        if(angle > 15) return;
 
495
        for(unsigned int i = 0; i < m_pages->m_pagesInfoVec.GetCount(); i++)
 
496
        {
 
497
                m_pages->m_pagesInfoVec[i].SetTabAngle(angle);
 
498
        }
 
499
        Refresh();
 
500
}
 
501
 
 
502
wxSize wxFlatNotebook::GetPageBestSize()
 
503
{
 
504
        return m_pages->GetClientSize();
 
505
}
 
506
 
 
507
bool wxFlatNotebook::SetPageText(size_t page, const wxString& text)
 
508
{
 
509
        bool bVal = m_pages->SetPageText(page, text);
 
510
        m_pages->Refresh();
 
511
        return bVal;
 
512
}
 
513
 
 
514
void wxFlatNotebook::SetPadding(const wxSize& padding)
 
515
{
 
516
        m_nPadding = padding.GetWidth();
 
517
}
 
518
 
 
519
void wxFlatNotebook::SetWindowStyleFlag(long style)
 
520
{
 
521
        wxPanel::SetWindowStyleFlag(style);
 
522
 
 
523
        if(m_pages)
 
524
        {
 
525
                // For changing the tab position (i.e. placing them top/bottom)
 
526
                // refreshing the tab container is not enough
 
527
                m_sendPageChangeEvent = false;
 
528
                SetSelection(m_pages->m_iActivePage);
 
529
                m_sendPageChangeEvent = true;
 
530
        }
 
531
}
 
532
 
 
533
bool wxFlatNotebook::RemovePage(size_t page, bool notify)
 
534
{
 
535
        if(page >= m_windows.GetCount())
 
536
                return false;
 
537
 
 
538
        // Fire a closing event
 
539
        if( notify )
 
540
        {
 
541
                wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSING, GetId());
 
542
                event.SetSelection((int)page);
 
543
                event.SetEventObject(this);
 
544
                GetEventHandler()->ProcessEvent(event);
 
545
 
 
546
                // The event handler allows it?
 
547
                if (!event.IsAllowed())
 
548
                        return false;
 
549
        }
 
550
 
 
551
        Freeze();
 
552
 
 
553
        // Remove the requested page
 
554
        wxWindow *pageRemoved = m_windows[page];
 
555
 
 
556
        // If the page is the current window, remove it from the sizer
 
557
        // as well
 
558
        if((int)page == m_pages->GetSelection())
 
559
        {
 
560
                m_mainSizer->Detach(pageRemoved);
 
561
        }
 
562
 
 
563
        // Remove it from the array as well
 
564
        m_windows.RemoveAt(page);
 
565
        Thaw();
 
566
 
 
567
        m_pages->DoDeletePage(page);
 
568
 
 
569
        // Fire a closed event
 
570
        if( notify )
 
571
        {
 
572
                wxFlatNotebookEvent closedEvent(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CLOSED, GetId());
 
573
                closedEvent.SetSelection((int)page);
 
574
                closedEvent.SetEventObject(this);
 
575
                GetEventHandler()->ProcessEvent(closedEvent);
 
576
        }
 
577
        return true;
 
578
}
 
579
 
 
580
void wxFlatNotebook::SetRightClickMenu(wxMenu* menu)
 
581
{
 
582
        m_pages->m_pRightClickMenu = menu;
 
583
}
 
584
 
 
585
wxString wxFlatNotebook::GetPageText(size_t page)
 
586
{
 
587
        return m_pages->GetPageText(page);
 
588
}
 
589
 
 
590
void wxFlatNotebook::SetGradientColors(const wxColour& from, const wxColour& to, const wxColour& border)
 
591
{
 
592
        m_pages->m_colorFrom = from;
 
593
        m_pages->m_colorTo   = to;
 
594
        m_pages->m_colorBorder = border;
 
595
}
 
596
 
 
597
void wxFlatNotebook::SetGradientColorFrom(const wxColour& from)
 
598
{
 
599
        m_pages->m_colorFrom = from;
 
600
}
 
601
 
 
602
void wxFlatNotebook::SetGradientColorTo(const wxColour& to)
 
603
{
 
604
        m_pages->m_colorTo   = to;
 
605
}
 
606
 
 
607
void wxFlatNotebook::SetGradientColorBorder(const wxColour& border)
 
608
{
 
609
        m_pages->m_colorBorder = border;
 
610
}
 
611
 
 
612
/// Gets first gradient colour
 
613
const wxColour& wxFlatNotebook::GetGradientColorFrom()
 
614
{
 
615
        return m_pages->m_colorFrom;
 
616
}
 
617
 
 
618
/// Gets second gradient colour
 
619
const wxColour& wxFlatNotebook::GetGradientColorTo()
 
620
{
 
621
        return m_pages->m_colorTo;
 
622
}
 
623
 
 
624
/// Gets the tab border colour
 
625
const wxColour& wxFlatNotebook::SetGradientColorBorder()
 
626
{
 
627
        return m_pages->m_colorBorder;
 
628
}
 
629
 
 
630
/// Get the active tab text
 
631
const wxColour& wxFlatNotebook::GetActiveTabTextColour()
 
632
{
 
633
        return m_pages->m_activeTextColor;
 
634
}
 
635
 
 
636
void wxFlatNotebook::SetPageImageIndex(size_t page, int imgindex)
 
637
{
 
638
        m_pages->SetPageImageIndex(page, imgindex);
 
639
}
 
640
 
 
641
int wxFlatNotebook::GetPageImageIndex(size_t page)
 
642
{
 
643
        return m_pages->GetPageImageIndex(page);
 
644
}
 
645
 
 
646
bool wxFlatNotebook::GetEnabled(size_t page)
 
647
{
 
648
        return m_pages->GetEnabled(page);
 
649
}
 
650
 
 
651
void wxFlatNotebook::Enable(size_t page, bool enabled)
 
652
{
 
653
        if(page >= m_windows.GetCount())
 
654
                return;
 
655
 
 
656
        m_windows[page]->Enable(enabled);
 
657
        m_pages->Enable(page, enabled);
 
658
}
 
659
 
 
660
const wxColour& wxFlatNotebook::GetNonActiveTabTextColour()
 
661
{
 
662
        return m_pages->m_nonActiveTextColor;
 
663
}
 
664
 
 
665
void wxFlatNotebook::SetNonActiveTabTextColour(const wxColour& color)
 
666
{
 
667
        m_pages->m_nonActiveTextColor = color;
 
668
}
 
669
 
 
670
void wxFlatNotebook::SetTabAreaColour(const wxColour& color)
 
671
{
 
672
        m_pages->m_tabAreaColor = color;
 
673
}
 
674
 
 
675
const wxColour& wxFlatNotebook::GetTabAreaColour()
 
676
{
 
677
        return m_pages->m_tabAreaColor;
 
678
}
 
679
 
 
680
void wxFlatNotebook::SetActiveTabColour(const wxColour& color)
 
681
{
 
682
        m_pages->m_activeTabColor = color;
 
683
}
 
684
 
 
685
const wxColour& wxFlatNotebook::GetActiveTabColour()
 
686
{
 
687
        return m_pages->m_activeTabColor;
 
688
}
 
689
 
 
690
long wxFlatNotebook::GetCustomizeOptions() const {
 
691
        return m_pages->GetCustomizeOptions();
 
692
}
 
693
 
 
694
void wxFlatNotebook::SetCustomizeOptions(long options) {
 
695
        m_pages->SetCustomizeOptions(options);
 
696
}
 
697
 
 
698
///////////////////////////////////////////////////////////////////////////////////////////
 
699
//
 
700
//      wxPageContainer
 
701
//
 
702
///////////////////////////////////////////////////////////////////////////////////////////
 
703
 
 
704
BEGIN_EVENT_TABLE(wxPageContainer, wxPanel)
 
705
        EVT_PAINT(wxPageContainer::OnPaint)
 
706
        EVT_SIZE(wxPageContainer::OnSize)
 
707
        EVT_LEFT_DOWN(wxPageContainer::OnLeftDown)
 
708
        EVT_LEFT_UP(wxPageContainer::OnLeftUp)
 
709
        EVT_RIGHT_DOWN(wxPageContainer::OnRightDown)
 
710
        EVT_MIDDLE_DOWN(wxPageContainer::OnMiddleDown)
 
711
        EVT_MOTION(wxPageContainer::OnMouseMove)
 
712
        EVT_ERASE_BACKGROUND(wxPageContainer::OnEraseBackground)
 
713
        EVT_LEAVE_WINDOW(wxPageContainer::OnMouseLeave)
 
714
        EVT_ENTER_WINDOW(wxPageContainer::OnMouseEnterWindow)
 
715
        EVT_LEFT_DCLICK(wxPageContainer::OnLeftDClick)
 
716
END_EVENT_TABLE()
 
717
 
 
718
wxPageContainer::wxPageContainer(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
 
719
: m_ImageList(NULL)
 
720
, m_iActivePage(-1)
 
721
, m_nFrom(0)
 
722
, m_pDropTarget(NULL)
 
723
, m_nLeftClickZone(wxFNB_NOWHERE)
 
724
, m_customizeOptions(wxFNB_CUSTOM_ALL)
 
725
{
 
726
        m_pRightClickMenu = NULL;
 
727
        m_nXButtonStatus = wxFNB_BTN_NONE;
 
728
        m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
 
729
        m_pParent = parent;
 
730
        m_nRightButtonStatus = wxFNB_BTN_NONE;
 
731
        m_nLeftButtonStatus = wxFNB_BTN_NONE;
 
732
        m_nTabXButtonStatus = wxFNB_BTN_NONE;
 
733
        m_customMenu = NULL;
 
734
 
 
735
        m_colorTo = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION));
 
736
        m_colorFrom   = wxColor(*wxWHITE);
 
737
        m_activeTabColor = wxColor(*wxWHITE);
 
738
        m_activeTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
 
739
        m_nonActiveTextColor = wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
 
740
        m_tabAreaColor = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
 
741
 
 
742
        // Set default page height, this is done according to the system font
 
743
        wxMemoryDC memDc;
 
744
        wxBitmap bmp(10, 10);
 
745
        memDc.SelectObject(bmp);
 
746
 
 
747
        int width, height;
 
748
 
 
749
#ifdef __WXGTK__
 
750
        wxFont normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
 
751
        wxFont boldFont = normalFont;
 
752
        boldFont.SetWeight(wxBOLD);
 
753
        memDc.SetFont( boldFont );
 
754
#endif
 
755
 
 
756
        memDc.GetTextExtent(wxT("Tp"), &width, &height);
 
757
        int tabHeight = height + wxFNB_HEIGHT_SPACER; // We use 10 pixels as padding
 
758
 
 
759
        wxWindow::Create(parent, id, pos, wxSize(size.x, tabHeight), style | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
 
760
 
 
761
        m_pDropTarget = new wxFNBDropTarget<wxPageContainer>(this, &wxPageContainer::OnDropTarget);
 
762
        SetDropTarget(m_pDropTarget);
 
763
}
 
764
 
 
765
wxPageContainer::~wxPageContainer(void)
 
766
{
 
767
        if(m_pRightClickMenu)
 
768
        {
 
769
                delete m_pRightClickMenu;
 
770
                m_pRightClickMenu = NULL;
 
771
        }
 
772
 
 
773
        if( m_customMenu )
 
774
        {
 
775
                delete m_customMenu;
 
776
                m_customMenu = NULL;
 
777
        }
 
778
}
 
779
 
 
780
void wxPageContainer::OnPaint(wxPaintEvent & event)
 
781
{
 
782
        wxBufferedPaintDC dc(this);
 
783
        wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
 
784
 
 
785
        render->DrawTabs(this, dc, event);
 
786
}
 
787
 
 
788
void wxPageContainer::PopPageHistory(int page)
 
789
{
 
790
        int tabIdx(wxNOT_FOUND);
 
791
        int where = m_history.Index(page);
 
792
        while(where != wxNOT_FOUND){
 
793
                tabIdx = m_history.Item(where);
 
794
                m_history.Remove(page);
 
795
                //remove all appearances of this page
 
796
                where = m_history.Index(page);
 
797
        }
 
798
 
 
799
        //update values
 
800
        if(tabIdx != wxNOT_FOUND){
 
801
                for(size_t i=0; i<m_history.size(); i++){
 
802
                        int &tt = m_history.Item(i);
 
803
                        if(tt > tabIdx){
 
804
                                tt--;
 
805
                        }
 
806
                }
 
807
        }
 
808
}
 
809
 
 
810
void wxPageContainer::PushPageHistory(int page)
 
811
{
 
812
        if(page == wxNOT_FOUND)
 
813
                return;
 
814
 
 
815
        int where = m_history.Index(page);
 
816
        if(where != wxNOT_FOUND){
 
817
                m_history.Remove(page);
 
818
        }
 
819
        m_history.Insert(page, 0);
 
820
}
 
821
 
 
822
bool wxPageContainer::AddPage(const wxString& caption, const bool selected, const int imgindex)
 
823
{
 
824
        if(selected)
 
825
        {
 
826
                PushPageHistory(m_iActivePage);
 
827
                m_iActivePage = (int)m_pagesInfoVec.GetCount();
 
828
        }
 
829
 
 
830
        /// Create page info and add it to the vector
 
831
        wxPageInfo pageInfo(caption, imgindex);
 
832
        m_pagesInfoVec.Add(pageInfo);
 
833
        Refresh();
 
834
        return true;
 
835
}
 
836
 
 
837
bool wxPageContainer::InsertPage(size_t index, wxWindow* /*page*/, const wxString& text, bool select, const int imgindex)
 
838
{
 
839
        if(select)
 
840
        {
 
841
                PushPageHistory(m_iActivePage);
 
842
                m_iActivePage = (int)index;
 
843
        }
 
844
        wxPageInfo pgInfo(text, imgindex);
 
845
        m_pagesInfoVec.Insert(pgInfo, index);
 
846
        Refresh();
 
847
        return true;
 
848
}
 
849
 
 
850
void wxPageContainer::OnSize(wxSizeEvent& WXUNUSED(event))
 
851
{
 
852
        // When resizing the control, try to fit to screen as many tabs as we we can
 
853
        long style = GetParent()->GetWindowStyleFlag();
 
854
        wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style);
 
855
        std::vector<wxRect> vTabInfo;
 
856
 
 
857
        int from = 0;
 
858
        int page = GetSelection();
 
859
        for(; from<m_nFrom; from++)
 
860
        {
 
861
                vTabInfo.clear();
 
862
                render->NumberTabsCanFit( this, vTabInfo, from );
 
863
                if(page - from >= static_cast<int>( vTabInfo.size() ))
 
864
                        continue;
 
865
                break;
 
866
        }
 
867
        m_nFrom = from;
 
868
        Refresh(); // Call on paint
 
869
}
 
870
 
 
871
void wxPageContainer::OnMiddleDown(wxMouseEvent& event)
 
872
{
 
873
        // Test if this style is enabled
 
874
        long style = GetParent()->GetWindowStyleFlag();
 
875
        if(!(style & wxFNB_MOUSE_MIDDLE_CLOSES_TABS))
 
876
                return;
 
877
 
 
878
        wxPageInfo pgInfo;
 
879
        int tabIdx;
 
880
        int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
 
881
        switch(where)
 
882
        {
 
883
        case wxFNB_TAB:
 
884
                {
 
885
                        DeletePage((size_t)tabIdx);
 
886
                        break;
 
887
                }
 
888
        default:
 
889
                break;
 
890
        }
 
891
 
 
892
        event.Skip();
 
893
}
 
894
 
 
895
void wxPageContainer::OnShowCustomizeDialog(wxCommandEvent &event)
 
896
{
 
897
        wxUnusedVar(event);
 
898
        wxFNBCustomizeDialog *dlg = new wxFNBCustomizeDialog(this, m_customizeOptions);
 
899
        dlg->ShowModal();
 
900
        dlg->Destroy();
 
901
}
 
902
 
 
903
void wxPageContainer::OnRightDown(wxMouseEvent& event)
 
904
{
 
905
        FNB_LOG_MSG(wxT("OnRightDown") << event.GetPosition().x << wxT(",") << event.GetPosition().y );
 
906
        wxPageInfo pgInfo;
 
907
        int tabIdx;
 
908
        int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
 
909
        switch(where)
 
910
        {
 
911
        case wxFNB_NOWHERE:
 
912
                {
 
913
                        // Incase user right clicked on 'anywhere' and style wxFNB_CUSTOM_DLG is set,
 
914
                        // popup the customize dialog
 
915
                        long style = GetParent()->GetWindowStyleFlag();
 
916
                        if( style & wxFNB_CUSTOM_DLG ){
 
917
                                if( !m_customMenu ){
 
918
                                        m_customMenu = new wxMenu();
 
919
                                        wxMenuItem *item = new wxMenuItem(m_customMenu, wxID_ANY, wxT("Properties..."));
 
920
                                        m_customMenu->Append(item);
 
921
                                        Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( wxPageContainer::OnShowCustomizeDialog ));
 
922
                                }
 
923
                                PopupMenu(m_customMenu);
 
924
                        }
 
925
                }
 
926
                break;
 
927
 
 
928
        case wxFNB_TAB:
 
929
        case wxFNB_TAB_X:
 
930
                {
 
931
                        if(!m_pagesInfoVec[tabIdx].GetEnabled())
 
932
                                break;
 
933
 
 
934
                        // Set the current tab to be active
 
935
                        // if needed
 
936
                        if(tabIdx != GetSelection())
 
937
                        {
 
938
                                SetSelection((size_t)tabIdx);
 
939
                        }
 
940
 
 
941
                        // If the owner has defined a context menu for the tabs,
 
942
                        // popup the right click menu
 
943
                if (m_pRightClickMenu)
 
944
                        PopupMenu(m_pRightClickMenu);
 
945
                else
 
946
                {
 
947
                        // send a message to popup a custom menu
 
948
                        wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_CONTEXT_MENU, GetParent()->GetId());
 
949
                        event.SetSelection((int)tabIdx);
 
950
                        event.SetOldSelection((int)m_iActivePage);
 
951
                        event.SetEventObject(GetParent());
 
952
                        GetParent()->GetEventHandler()->ProcessEvent(event);
 
953
                }
 
954
 
 
955
                }
 
956
                break;
 
957
 
 
958
        default:
 
959
                break;
 
960
        }
 
961
}
 
962
 
 
963
void wxPageContainer::OnLeftDown(wxMouseEvent& event)
 
964
{
 
965
        wxPageInfo pgInfo;
 
966
        int tabIdx;
 
967
 
 
968
        // Reset buttons status
 
969
        m_nXButtonStatus     = wxFNB_BTN_NONE;
 
970
        m_nLeftButtonStatus  = wxFNB_BTN_NONE;
 
971
        m_nRightButtonStatus = wxFNB_BTN_NONE;
 
972
        m_nTabXButtonStatus  = wxFNB_BTN_NONE;
 
973
        m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
 
974
 
 
975
        m_nLeftClickZone = HitTest(event.GetPosition(), pgInfo, tabIdx);
 
976
        switch(m_nLeftClickZone)
 
977
        {
 
978
        case wxFNB_DROP_DOWN_ARROW:
 
979
                m_nArrowDownButtonStatus = wxFNB_BTN_PRESSED;
 
980
                Refresh();
 
981
                break;
 
982
        case wxFNB_LEFT_ARROW:
 
983
                m_nLeftButtonStatus = wxFNB_BTN_PRESSED;
 
984
                Refresh();
 
985
                break;
 
986
        case wxFNB_RIGHT_ARROW:
 
987
                m_nRightButtonStatus = wxFNB_BTN_PRESSED;
 
988
                Refresh();
 
989
                break;
 
990
        case wxFNB_X:
 
991
                m_nXButtonStatus = wxFNB_BTN_PRESSED;
 
992
                Refresh();
 
993
                break;
 
994
        case wxFNB_TAB_X:
 
995
                m_nTabXButtonStatus = wxFNB_BTN_PRESSED;
 
996
                Refresh();
 
997
                break;
 
998
        case wxFNB_TAB:
 
999
                {
 
1000
                        if(m_iActivePage != tabIdx)
 
1001
                        {
 
1002
                                // Incase the tab is disabled, we dont allow to choose it
 
1003
                                if(!m_pagesInfoVec[tabIdx].GetEnabled())
 
1004
                                        break;
 
1005
 
 
1006
                                SetSelection(tabIdx);
 
1007
                        }
 
1008
                        break;
 
1009
                }
 
1010
        }
 
1011
}
 
1012
 
 
1013
void wxPageContainer::RotateLeft()
 
1014
{
 
1015
        if(m_nFrom == 0)
 
1016
                return;
 
1017
 
 
1018
        // Make sure that the button was pressed before
 
1019
        if(m_nLeftButtonStatus != wxFNB_BTN_PRESSED)
 
1020
                return;
 
1021
 
 
1022
        m_nLeftButtonStatus = wxFNB_BTN_HOVER;
 
1023
 
 
1024
        // We scroll left with bulks of 5
 
1025
        int scrollLeft = GetNumTabsCanScrollLeft();
 
1026
 
 
1027
        m_nFrom -= scrollLeft;
 
1028
        if(m_nFrom < 0)
 
1029
                m_nFrom = 0;
 
1030
 
 
1031
        Refresh();
 
1032
        return;
 
1033
}
 
1034
 
 
1035
void wxPageContainer::RotateRight()
 
1036
{
 
1037
        if(m_nFrom >= (int)m_pagesInfoVec.GetCount() - 1)
 
1038
                return;
 
1039
 
 
1040
        // Make sure that the button was pressed before
 
1041
        if(m_nRightButtonStatus != wxFNB_BTN_PRESSED)
 
1042
                return;
 
1043
 
 
1044
        m_nRightButtonStatus = wxFNB_BTN_HOVER;
 
1045
 
 
1046
        // Check if the right most tab is visible, if it is
 
1047
        // don't rotate right anymore
 
1048
        if(m_pagesInfoVec[m_pagesInfoVec.GetCount()-1].GetPosition() != wxPoint(-1, -1))
 
1049
                return;
 
1050
 
 
1051
        m_nFrom += 1;
 
1052
        Refresh();
 
1053
}
 
1054
 
 
1055
void wxPageContainer::OnLeftUp(wxMouseEvent& event)
 
1056
{
 
1057
        wxPageInfo pgInfo;
 
1058
        int tabIdx;
 
1059
 
 
1060
        // forget the zone that was initially clicked
 
1061
        m_nLeftClickZone = wxFNB_NOWHERE;
 
1062
 
 
1063
        int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
 
1064
        switch(where)
 
1065
        {
 
1066
        case wxFNB_LEFT_ARROW:
 
1067
                {
 
1068
                        RotateLeft();
 
1069
                        break;
 
1070
                }
 
1071
        case wxFNB_RIGHT_ARROW:
 
1072
                {
 
1073
                        RotateRight();
 
1074
                        break;
 
1075
                }
 
1076
        case wxFNB_X:
 
1077
                {
 
1078
                        // Make sure that the button was pressed before
 
1079
                        if(m_nXButtonStatus != wxFNB_BTN_PRESSED)
 
1080
                                break;
 
1081
 
 
1082
                        m_nXButtonStatus = wxFNB_BTN_HOVER;
 
1083
 
 
1084
                        DeletePage((size_t)m_iActivePage);
 
1085
                        break;
 
1086
                }
 
1087
        case wxFNB_TAB_X:
 
1088
                {
 
1089
                        // Make sure that the button was pressed before
 
1090
                        if(m_nTabXButtonStatus != wxFNB_BTN_PRESSED)
 
1091
                                break;
 
1092
 
 
1093
                        m_nTabXButtonStatus = wxFNB_BTN_HOVER;
 
1094
 
 
1095
                        DeletePage((size_t)m_iActivePage);
 
1096
                        break;
 
1097
                }
 
1098
        case wxFNB_DROP_DOWN_ARROW:
 
1099
                {
 
1100
                        // Make sure that the button was pressed before
 
1101
                        if(m_nArrowDownButtonStatus != wxFNB_BTN_PRESSED)
 
1102
                                break;
 
1103
 
 
1104
                        m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
 
1105
 
 
1106
                        // Refresh the button status
 
1107
                        wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
 
1108
                        wxClientDC dc(this);
 
1109
                        render->DrawDropDownArrow(this, dc);
 
1110
 
 
1111
                        PopupTabsMenu();
 
1112
                        break;
 
1113
                }
 
1114
        }
 
1115
        event.Skip();
 
1116
}
 
1117
 
 
1118
int wxPageContainer::HitTest(const wxPoint& pt, wxPageInfo& pageInfo, int &tabIdx)
 
1119
{
 
1120
        wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
 
1121
 
 
1122
        wxRect rect = GetClientRect();
 
1123
        int btnLeftPos = render->GetLeftButtonPos(this);
 
1124
        int btnRightPos = render->GetRightButtonPos(this);
 
1125
        int btnXPos =render->GetXPos(this);
 
1126
        long style = GetParent()->GetWindowStyleFlag();
 
1127
 
 
1128
        tabIdx = -1;
 
1129
        if(m_pagesInfoVec.IsEmpty())
 
1130
        {
 
1131
                return wxFNB_NOWHERE;
 
1132
        }
 
1133
 
 
1134
        rect = wxRect(btnXPos, 8, 16, 16);
 
1135
        if(InsideRect(rect, pt))
 
1136
        {
 
1137
                return (style & wxFNB_NO_X_BUTTON) ? wxFNB_NOWHERE : wxFNB_X;
 
1138
        }
 
1139
 
 
1140
        rect = wxRect(btnRightPos, 8, 16, 16);
 
1141
        if( style & wxFNB_DROPDOWN_TABS_LIST )
 
1142
        {
 
1143
                rect = wxRect(render->GetDropArrowButtonPos( this ), 8, 16, 16);
 
1144
                if(InsideRect(rect, pt))
 
1145
                        return wxFNB_DROP_DOWN_ARROW;
 
1146
        }
 
1147
 
 
1148
        if(InsideRect(rect, pt))
 
1149
        {
 
1150
                return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_RIGHT_ARROW;
 
1151
        }
 
1152
 
 
1153
 
 
1154
        rect = wxRect(btnLeftPos, 8, 16, 16);
 
1155
        if(InsideRect(rect, pt))
 
1156
        {
 
1157
                return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_LEFT_ARROW;
 
1158
        }
 
1159
 
 
1160
        // Test whether a left click was made on a tab
 
1161
        bool bFoundMatch = false;
 
1162
        for(size_t cur=m_nFrom; cur<m_pagesInfoVec.GetCount(); cur++)
 
1163
        {
 
1164
                wxPageInfo pgInfo = m_pagesInfoVec[cur];
 
1165
                if(pgInfo.GetPosition() == wxPoint(-1, -1))
 
1166
                        continue;
 
1167
 
 
1168
                // check for mouse over tab's x button
 
1169
                if(style & wxFNB_X_ON_TAB && (int)cur == GetSelection())
 
1170
                {
 
1171
                        // 'x' button exists on a tab
 
1172
                        if(InsideRect(m_pagesInfoVec[cur].GetXRect(), pt))
 
1173
                        {
 
1174
                                pageInfo = pgInfo;
 
1175
                                tabIdx = (int)cur;
 
1176
                                return wxFNB_TAB_X;
 
1177
                        }
 
1178
                }
 
1179
 
 
1180
                if(style & wxFNB_VC8)
 
1181
                {
 
1182
                        if(m_pagesInfoVec[cur].GetRegion().Contains(pt) == wxInRegion)
 
1183
                        {
 
1184
                                if(bFoundMatch || (int)cur == GetSelection())
 
1185
                                {
 
1186
                                        pageInfo = pgInfo;
 
1187
                                        tabIdx = (int)cur;
 
1188
                                        return wxFNB_TAB;
 
1189
                                }
 
1190
                                pageInfo = pgInfo;
 
1191
                                tabIdx = (int)cur;
 
1192
                                bFoundMatch = true;
 
1193
                        }
 
1194
                }
 
1195
                else
 
1196
                {
 
1197
 
 
1198
                        wxRect tabRect = wxRect(pgInfo.GetPosition().x, pgInfo.GetPosition().y,
 
1199
                                pgInfo.GetSize().x, pgInfo.GetSize().y);
 
1200
 
 
1201
                        if(InsideRect(tabRect, pt))
 
1202
                        {
 
1203
                                // We have a match
 
1204
                                pageInfo = pgInfo;
 
1205
                                tabIdx = (int)cur;
 
1206
                                return wxFNB_TAB;
 
1207
                        }
 
1208
                }
 
1209
        }
 
1210
 
 
1211
        if(bFoundMatch)
 
1212
                return wxFNB_TAB;
 
1213
 
 
1214
        // Default
 
1215
        return wxFNB_NOWHERE;
 
1216
}
 
1217
 
 
1218
void wxPageContainer::SetSelection(size_t page)
 
1219
{
 
1220
        wxFlatNotebook* book = (wxFlatNotebook*)GetParent();
 
1221
        book->SetSelection(page);
 
1222
        DoSetSelection(page);
 
1223
}
 
1224
 
 
1225
void wxPageContainer::DoSetSelection(size_t page)
 
1226
{
 
1227
        // Make sure that the selection is visible
 
1228
        if(page < m_pagesInfoVec.GetCount())
 
1229
        {
 
1230
                //! fix for tabfocus
 
1231
                wxWindow* da_page = ((wxFlatNotebook *)m_pParent)->GetPage(page);
 
1232
                if ( da_page!=NULL )
 
1233
                        da_page->SetFocus();
 
1234
        }
 
1235
 
 
1236
        if( !IsTabVisible(page) )
 
1237
        {
 
1238
                FNB_LOG_MSG( wxT("Tab ") << (int)page << wxT(" is not visible"));
 
1239
                FNB_LOG_MSG( wxT("m_nFrom=") << m_nFrom << wxT(", Selection=") << (int)page );
 
1240
 
 
1241
                // Try to remove one tab from start and try again
 
1242
                if( !CanFitToScreen(page) )
 
1243
                {
 
1244
                        if( m_nFrom > (int)page )
 
1245
                                m_nFrom = (int)page;
 
1246
                        else
 
1247
                        {
 
1248
                                while( m_nFrom < (int)page )
 
1249
                                {
 
1250
                                        m_nFrom++;
 
1251
                                        if( CanFitToScreen(page) )
 
1252
                                                break;
 
1253
                                }
 
1254
                        }
 
1255
                        FNB_LOG_MSG( wxT("Adjusting m_nFrom to=") << m_nFrom);
 
1256
                }
 
1257
        }
 
1258
        else
 
1259
        {
 
1260
                FNB_LOG_MSG( wxT("Tab ") << (int)page << wxT(" is visible"));
 
1261
        }
 
1262
        PushPageHistory((int)page);
 
1263
        Refresh();
 
1264
}
 
1265
 
 
1266
void wxPageContainer::DeletePage(size_t page)
 
1267
{
 
1268
        wxFlatNotebook* book = (wxFlatNotebook*)GetParent();
 
1269
        book->DeletePage(page);
 
1270
        book->Refresh();
 
1271
}
 
1272
 
 
1273
bool wxPageContainer::IsTabVisible(size_t page)
 
1274
{
 
1275
        int iPage = (int)page;
 
1276
        int iLastVisiblePage = GetLastVisibleTab();
 
1277
 
 
1278
        return iPage <= iLastVisiblePage && iPage >= m_nFrom;
 
1279
}
 
1280
 
 
1281
int wxPageContainer::GetPreviousSelection() const
 
1282
{
 
1283
        if(m_history.empty()){
 
1284
                return wxNOT_FOUND;
 
1285
        }
 
1286
        //return the top of the heap
 
1287
        return m_history.Item(0);
 
1288
}
 
1289
 
 
1290
void wxPageContainer::DoDeletePage(size_t page)
 
1291
{
 
1292
        // Remove the page from the vector
 
1293
        wxFlatNotebook* book = (wxFlatNotebook*)GetParent();
 
1294
 
 
1295
        PopPageHistory((int)page);
 
1296
 
 
1297
        // same thing with the active page
 
1298
        if (m_iActivePage > (int)page || (int)page >= (int)(m_pagesInfoVec.Count())){
 
1299
                m_iActivePage -= 1;
 
1300
        }else if (m_iActivePage == (int)page){
 
1301
                m_iActivePage = GetPreviousSelection();
 
1302
                //PopPageHistory(m_iActivePage);
 
1303
        }
 
1304
 
 
1305
        m_pagesInfoVec.RemoveAt(page);
 
1306
 
 
1307
        if(m_iActivePage == wxNOT_FOUND && m_pagesInfoVec.Count() > 0){
 
1308
                m_iActivePage = 0;
 
1309
        }
 
1310
 
 
1311
        // Refresh the tabs
 
1312
        book->SetForceSelection(true);
 
1313
        book->SetSelection(m_iActivePage);
 
1314
        book->SetForceSelection(false);
 
1315
 
 
1316
        if(m_pagesInfoVec.empty())
 
1317
        {
 
1318
                // Erase the page container drawings
 
1319
                wxClientDC dc(this);
 
1320
                dc.Clear();
 
1321
        }
 
1322
}
 
1323
 
 
1324
void wxPageContainer::DeleteAllPages()
 
1325
{
 
1326
        m_iActivePage = -1;
 
1327
        m_history.Clear();
 
1328
        m_nFrom = 0;
 
1329
        m_pagesInfoVec.Clear();
 
1330
 
 
1331
        // Erase the page container drawings
 
1332
        wxClientDC dc(this);
 
1333
        dc.Clear();
 
1334
}
 
1335
 
 
1336
void wxPageContainer::OnMouseMove(wxMouseEvent& event)
 
1337
{
 
1338
        if (!m_pagesInfoVec.empty() && IsShown())
 
1339
        {
 
1340
                const int xButtonStatus = m_nXButtonStatus;
 
1341
                const int xTabButtonStatus = m_nTabXButtonStatus;
 
1342
                const int rightButtonStatus = m_nRightButtonStatus;
 
1343
                const int leftButtonStatus = m_nLeftButtonStatus;
 
1344
                const int dropDownButtonStatus = m_nArrowDownButtonStatus;
 
1345
 
 
1346
                long style = GetParent()->GetWindowStyleFlag();
 
1347
 
 
1348
                m_nXButtonStatus = wxFNB_BTN_NONE;
 
1349
                m_nRightButtonStatus = wxFNB_BTN_NONE;
 
1350
                m_nLeftButtonStatus = wxFNB_BTN_NONE;
 
1351
                m_nTabXButtonStatus = wxFNB_BTN_NONE;
 
1352
                m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
 
1353
 
 
1354
                wxPageInfo pgInfo;
 
1355
                int tabIdx;
 
1356
 
 
1357
                int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
 
1358
                switch ( where )
 
1359
                {
 
1360
                case wxFNB_X:
 
1361
                        if (event.LeftIsDown())
 
1362
                        {
 
1363
                                m_nXButtonStatus = (m_nLeftClickZone==wxFNB_X) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
 
1364
                        }
 
1365
                        else
 
1366
                        {
 
1367
                                m_nXButtonStatus = wxFNB_BTN_HOVER;
 
1368
                        }
 
1369
                        break;
 
1370
                case wxFNB_DROP_DOWN_ARROW:
 
1371
                        if (event.LeftIsDown())
 
1372
                        {
 
1373
                                m_nArrowDownButtonStatus = (m_nLeftClickZone == wxFNB_DROP_DOWN_ARROW) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
 
1374
                        }
 
1375
                        else
 
1376
                        {
 
1377
                                m_nArrowDownButtonStatus = wxFNB_BTN_HOVER;
 
1378
                        }
 
1379
                        break;
 
1380
                case wxFNB_TAB_X:
 
1381
                        if (event.LeftIsDown())
 
1382
                        {
 
1383
                                m_nTabXButtonStatus = (m_nLeftClickZone==wxFNB_TAB_X) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
 
1384
                        }
 
1385
                        else
 
1386
                        {
 
1387
                                m_nTabXButtonStatus = wxFNB_BTN_HOVER;
 
1388
                        }
 
1389
                        break;
 
1390
                case wxFNB_RIGHT_ARROW:
 
1391
                        if (event.LeftIsDown())
 
1392
                        {
 
1393
                                m_nRightButtonStatus = (m_nLeftClickZone==wxFNB_RIGHT_ARROW) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
 
1394
                        }
 
1395
                        else
 
1396
                        {
 
1397
                                m_nRightButtonStatus = wxFNB_BTN_HOVER;
 
1398
                        }
 
1399
                        break;
 
1400
 
 
1401
                case wxFNB_LEFT_ARROW:
 
1402
                        if (event.LeftIsDown())
 
1403
                        {
 
1404
                                m_nLeftButtonStatus = (m_nLeftClickZone==wxFNB_LEFT_ARROW) ? wxFNB_BTN_PRESSED : wxFNB_BTN_NONE;
 
1405
                        }
 
1406
                        else
 
1407
                        {
 
1408
                                m_nLeftButtonStatus = wxFNB_BTN_HOVER;
 
1409
                        }
 
1410
                        break;
 
1411
 
 
1412
                case wxFNB_TAB:
 
1413
                        // Call virtual method for showing tooltip
 
1414
                        ShowTabTooltip(tabIdx);
 
1415
                        if(!GetEnabled((size_t)tabIdx))
 
1416
                        {
 
1417
                                // Set the cursor to be 'No-entry'
 
1418
                                ::wxSetCursor(wxCURSOR_NO_ENTRY);
 
1419
                        }
 
1420
 
 
1421
                        // Support for drag and drop
 
1422
                        if(event.Dragging() && !(style & wxFNB_NODRAG))
 
1423
                        {
 
1424
                                wxFNBDragInfo draginfo(this, tabIdx);
 
1425
                                wxFNBDragInfoDataObject dataobject(wxDataFormat(wxT("wxFNB")));
 
1426
                                dataobject.SetData(sizeof(wxFNBDragInfo), &draginfo);
 
1427
                                wxFNBDropSource dragSource(this);
 
1428
                                dragSource.SetData(dataobject);
 
1429
                                dragSource.DoDragDrop(wxDrag_DefaultMove);
 
1430
                        }
 
1431
                        break;
 
1432
                default:
 
1433
                        m_nTabXButtonStatus = wxFNB_BTN_NONE;
 
1434
                        break;
 
1435
                }
 
1436
 
 
1437
                const bool bRedrawX = m_nXButtonStatus != xButtonStatus;
 
1438
                const bool bRedrawDropArrow = m_nArrowDownButtonStatus != dropDownButtonStatus;
 
1439
                const bool bRedrawRight = m_nRightButtonStatus != rightButtonStatus;
 
1440
                const bool bRedrawLeft = m_nLeftButtonStatus != leftButtonStatus;
 
1441
                const bool bRedrawTabX = m_nTabXButtonStatus != xTabButtonStatus;
 
1442
 
 
1443
                wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
 
1444
 
 
1445
                if (bRedrawX || bRedrawRight || bRedrawLeft || bRedrawTabX || bRedrawDropArrow)
 
1446
                {
 
1447
                        wxClientDC dc(this);
 
1448
                        if (bRedrawX)
 
1449
                        {
 
1450
                                render->DrawX(this, dc);
 
1451
                        }
 
1452
                        if (bRedrawLeft)
 
1453
                        {
 
1454
                                render->DrawLeftArrow(this, dc);
 
1455
                        }
 
1456
                        if (bRedrawRight)
 
1457
                        {
 
1458
                                render->DrawRightArrow(this, dc);
 
1459
                        }
 
1460
                        if (bRedrawTabX)
 
1461
                        {
 
1462
                                render->DrawTabX(this, dc, pgInfo.GetXRect(), tabIdx, m_nTabXButtonStatus);
 
1463
                        }
 
1464
                        if (bRedrawDropArrow)
 
1465
                        {
 
1466
                                render->DrawDropDownArrow(this, dc);
 
1467
                        }
 
1468
                }
 
1469
        }
 
1470
        event.Skip();
 
1471
}
 
1472
 
 
1473
int wxPageContainer::GetLastVisibleTab()
 
1474
{
 
1475
        int i;
 
1476
        if( m_nFrom < 0)
 
1477
                return -1;
 
1478
 
 
1479
        for(i=m_nFrom; i<(int)m_pagesInfoVec.GetCount(); i++)
 
1480
        {
 
1481
                if(m_pagesInfoVec[i].GetPosition() == wxPoint(-1, -1))
 
1482
                        break;
 
1483
        }
 
1484
        return (i-1);
 
1485
}
 
1486
 
 
1487
int wxPageContainer::GetNumTabsCanScrollLeft()
 
1488
{
 
1489
        if( m_nFrom - 1 >= 0){
 
1490
                return 1;
 
1491
        } else {
 
1492
                return 0;
 
1493
        }
 
1494
}
 
1495
 
 
1496
bool wxPageContainer::IsDefaultTabs()
 
1497
{
 
1498
        long style = GetParent()->GetWindowStyleFlag();
 
1499
        bool res = (style & wxFNB_VC71) || (style & wxFNB_FANCY_TABS) || (style & wxFNB_VC8);
 
1500
        return !res;
 
1501
}
 
1502
 
 
1503
void wxPageContainer::AdvanceSelection(bool bForward)
 
1504
{
 
1505
        int nSel = GetSelection();
 
1506
 
 
1507
        if(nSel < 0)
 
1508
                return;
 
1509
 
 
1510
        int nMax = (int)GetPageCount() - 1;
 
1511
        if ( bForward )
 
1512
                SetSelection(nSel == nMax ? 0 : nSel + 1);
 
1513
        else
 
1514
                SetSelection(nSel == 0 ? nMax : nSel - 1);
 
1515
}
 
1516
 
 
1517
 
 
1518
void wxPageContainer::OnMouseLeave(wxMouseEvent& event)
 
1519
{
 
1520
        m_nLeftButtonStatus = wxFNB_BTN_NONE;
 
1521
        m_nXButtonStatus = wxFNB_BTN_NONE;
 
1522
        m_nRightButtonStatus = wxFNB_BTN_NONE;
 
1523
        m_nTabXButtonStatus = wxFNB_BTN_NONE;
 
1524
        m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
 
1525
 
 
1526
        long style = GetParent()->GetWindowStyleFlag();
 
1527
        wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style);
 
1528
 
 
1529
        wxClientDC dc(this);
 
1530
        render->DrawX(this, dc);
 
1531
        render->DrawLeftArrow(this, dc);
 
1532
        render->DrawRightArrow(this, dc);
 
1533
        if(GetSelection() != -1 && IsTabVisible((size_t)GetSelection()))
 
1534
        {
 
1535
                render->DrawTabX(this, dc, m_pagesInfoVec[GetSelection()].GetXRect(), GetSelection(), m_nTabXButtonStatus);
 
1536
        }
 
1537
 
 
1538
        event.Skip();
 
1539
}
 
1540
 
 
1541
void wxPageContainer::OnMouseEnterWindow(wxMouseEvent& event)
 
1542
{
 
1543
        m_nLeftButtonStatus = wxFNB_BTN_NONE;
 
1544
        m_nXButtonStatus = wxFNB_BTN_NONE;
 
1545
        m_nRightButtonStatus = wxFNB_BTN_NONE;
 
1546
        m_nLeftClickZone = wxFNB_BTN_NONE;
 
1547
        m_nArrowDownButtonStatus = wxFNB_BTN_NONE;
 
1548
 
 
1549
        event.Skip();
 
1550
}
 
1551
 
 
1552
void wxPageContainer::ShowTabTooltip(int tabIdx)
 
1553
{
 
1554
        wxWindow *pWindow = ((wxFlatNotebook *)m_pParent)->GetPage(tabIdx);
 
1555
        if( pWindow )
 
1556
        {
 
1557
                wxToolTip *pToolTip = pWindow->GetToolTip();
 
1558
                if(pToolTip && pToolTip->GetWindow() == pWindow)
 
1559
                        SetToolTip(pToolTip->GetTip());
 
1560
        }
 
1561
}
 
1562
 
 
1563
void wxPageContainer::SetPageImageIndex(size_t page, int imgindex)
 
1564
{
 
1565
        if(page < m_pagesInfoVec.GetCount())
 
1566
        {
 
1567
                m_pagesInfoVec[page].SetImageIndex(imgindex);
 
1568
                Refresh();
 
1569
        }
 
1570
}
 
1571
 
 
1572
int wxPageContainer::GetPageImageIndex(size_t page)
 
1573
{
 
1574
        if(page < m_pagesInfoVec.GetCount())
 
1575
        {
 
1576
                return m_pagesInfoVec[page].GetImageIndex();
 
1577
        }
 
1578
        return -1;
 
1579
}
 
1580
 
 
1581
wxDragResult wxPageContainer::OnDropTarget(wxCoord x, wxCoord y, int nTabPage, wxWindow * wnd_oldContainer)
 
1582
{
 
1583
        // Disable drag'n'drop for disabled tab
 
1584
        if(!((wxPageContainer *)wnd_oldContainer)->m_pagesInfoVec[nTabPage].GetEnabled())
 
1585
                return wxDragCancel;
 
1586
 
 
1587
        wxLogTrace(wxTraceMask(), _("Old Page Index = %i"), nTabPage);
 
1588
        wxPageContainer * oldContainer = (wxPageContainer *)wnd_oldContainer;
 
1589
        int nIndex = -1;
 
1590
        wxPageInfo pgInfo;
 
1591
        int where = HitTest(wxPoint(x, y), pgInfo, nIndex);
 
1592
        wxLogTrace(wxTraceMask(), _("OnDropTarget: index by HitTest = %i"), nIndex);
 
1593
        wxFlatNotebook * oldNotebook = (wxFlatNotebook *)oldContainer->GetParent();
 
1594
        wxFlatNotebook * newNotebook = (wxFlatNotebook *)GetParent();
 
1595
 
 
1596
        if(oldNotebook == newNotebook)
 
1597
        {
 
1598
                if(nTabPage >= 0)
 
1599
                {
 
1600
                        switch(where)
 
1601
                        {
 
1602
                        case wxFNB_TAB:
 
1603
                                MoveTabPage(nTabPage, nIndex);
 
1604
                                break;
 
1605
                        case wxFNB_NOWHERE:
 
1606
                                {
 
1607
                                }
 
1608
                                break;
 
1609
                        default:
 
1610
                                break;
 
1611
                        }
 
1612
                }
 
1613
        }
 
1614
        else if ( GetParent()->GetWindowStyleFlag() & wxFNB_ALLOW_FOREIGN_DND )
 
1615
        {
 
1616
#if defined(__WXMSW__) || defined(__WXGTK__)
 
1617
                if(nTabPage >= 0)
 
1618
                {
 
1619
                        wxWindow * window = oldNotebook->GetPage(nTabPage);
 
1620
                        if(window)
 
1621
                        {
 
1622
                                wxString caption = oldContainer->GetPageText(nTabPage);
 
1623
 
 
1624
                                // Pass the image to the new container
 
1625
                                // incase that the new container (this) does not have image list we dont pass the image
 
1626
                                // to the new notebook
 
1627
                                int newIndx( wxNOT_FOUND );
 
1628
 
 
1629
                                if( m_ImageList )
 
1630
                                {
 
1631
                                        int imageindex = oldContainer->GetPageImageIndex(nTabPage);
 
1632
                                        if( imageindex >= 0 )
 
1633
                                        {
 
1634
                                                wxBitmap bmp( (*oldContainer->GetImageList())[imageindex] );
 
1635
                                                m_ImageList->Add( bmp );
 
1636
                                                newIndx = static_cast<int>(m_ImageList->GetCount() - 1);
 
1637
                                        }
 
1638
                                }
 
1639
 
 
1640
                                oldNotebook->RemovePage( nTabPage );
 
1641
                                window->Reparent( newNotebook );
 
1642
                                newNotebook->InsertPage(nIndex, window, caption, true, newIndx);
 
1643
                        }
 
1644
                }
 
1645
#endif
 
1646
        }
 
1647
        return wxDragMove;
 
1648
}
 
1649
 
 
1650
void wxPageContainer::MoveTabPage(int nMove, int nMoveTo)
 
1651
{
 
1652
        if(nMove == nMoveTo)
 
1653
                return;
 
1654
 
 
1655
        else if(nMoveTo < (int)((wxFlatNotebook *)m_pParent)->GetWindows().GetCount())
 
1656
                nMoveTo++;
 
1657
 
 
1658
        m_pParent->Freeze();
 
1659
        // Remove the window from the main sizer
 
1660
        int nCurSel = ((wxFlatNotebook *)m_pParent)->GetPages()->GetSelection();
 
1661
        ((wxFlatNotebook *)m_pParent)->GetMainSizer()->Detach(((wxFlatNotebook *)m_pParent)->GetWindows().Item(nCurSel));
 
1662
        ((wxFlatNotebook *)m_pParent)->GetWindows().Item(nCurSel)->Hide();
 
1663
 
 
1664
        wxWindow *pWindow = ((wxFlatNotebook *)m_pParent)->GetWindows().Item(nMove);
 
1665
        ((wxFlatNotebook *)m_pParent)->GetWindows().RemoveAt(nMove);
 
1666
        ((wxFlatNotebook *)m_pParent)->GetWindows().Insert(pWindow, nMoveTo-1);
 
1667
 
 
1668
        wxPageInfo pgInfo = m_pagesInfoVec[nMove];
 
1669
 
 
1670
        m_pagesInfoVec.RemoveAt( nMove );
 
1671
        m_pagesInfoVec.Insert(pgInfo, nMoveTo - 1);
 
1672
 
 
1673
        // Add the page according to the style
 
1674
        wxBoxSizer* pSizer = ((wxFlatNotebook *)m_pParent)->GetMainSizer();
 
1675
        long style = GetParent()->GetWindowStyleFlag();
 
1676
 
 
1677
 
 
1678
        if(style & wxFNB_BOTTOM)
 
1679
        {
 
1680
                pSizer->Insert(0, pWindow, 1, wxEXPAND);
 
1681
        }
 
1682
        else
 
1683
        {
 
1684
                // We leave a space of 1 pixel around the window
 
1685
                pSizer->Add(pWindow, 1, wxEXPAND);
 
1686
        }
 
1687
        pWindow->Show();
 
1688
 
 
1689
        pSizer->Layout();
 
1690
        m_iActivePage = nMoveTo-1;
 
1691
        m_history.Clear();
 
1692
        DoSetSelection(m_iActivePage);
 
1693
        m_pParent->Thaw();
 
1694
}
 
1695
 
 
1696
bool wxPageContainer::CanFitToScreen(size_t page)
 
1697
{
 
1698
        // Incase the from is greater than page,
 
1699
        // we need to reset the m_nFrom, so in order
 
1700
        // to force the caller to do so, we return false
 
1701
        if(m_nFrom > (int)page)
 
1702
                return false;
 
1703
 
 
1704
        long style = GetParent()->GetWindowStyleFlag();
 
1705
        wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer(style);
 
1706
        std::vector<wxRect> vTabInfo;
 
1707
        render->NumberTabsCanFit( this, vTabInfo );
 
1708
 
 
1709
        if(static_cast<int>(page) - m_nFrom >= static_cast<int>( vTabInfo.size() ))
 
1710
                return false;
 
1711
        return true;
 
1712
}
 
1713
 
 
1714
int wxPageContainer::GetNumOfVisibleTabs()
 
1715
{
 
1716
        int i=m_nFrom;
 
1717
        int counter = 0;
 
1718
        for(; i<(int)m_pagesInfoVec.GetCount(); i++, ++counter)
 
1719
        {
 
1720
                if(m_pagesInfoVec[i].GetPosition() == wxPoint(-1, -1))
 
1721
                        break;
 
1722
        }
 
1723
        return counter;
 
1724
}
 
1725
 
 
1726
bool wxPageContainer::GetEnabled(size_t page)
 
1727
{
 
1728
        if(page >= m_pagesInfoVec.GetCount())
 
1729
                return true;    // Seems strange, but this is the default
 
1730
        return m_pagesInfoVec[page].GetEnabled();
 
1731
}
 
1732
 
 
1733
void wxPageContainer::Enable(size_t page, bool enabled)
 
1734
{
 
1735
        if(page >= m_pagesInfoVec.GetCount())
 
1736
                return ;
 
1737
    m_pagesInfoVec[page].Enable(enabled);
 
1738
    return;
 
1739
}
 
1740
 
 
1741
wxColor wxPageContainer::GetSingleLineBorderColor()
 
1742
{
 
1743
        if(HasFlag(wxFNB_FANCY_TABS))
 
1744
                return m_colorFrom;
 
1745
        return *wxWHITE;
 
1746
}
 
1747
 
 
1748
bool wxPageContainer::HasFlag(int flag)
 
1749
{
 
1750
        long style = GetParent()->GetWindowStyleFlag();
 
1751
        bool res = style & flag ? true : false;
 
1752
        return res;
 
1753
}
 
1754
 
 
1755
void wxPageContainer::ClearFlag(int flag)
 
1756
{
 
1757
        long style = GetParent()->GetWindowStyleFlag();
 
1758
        style &= ~( flag );
 
1759
        wxWindowBase::SetWindowStyleFlag(style);
 
1760
}
 
1761
 
 
1762
bool wxPageContainer::TabHasImage(int tabIdx)
 
1763
{
 
1764
        if(m_ImageList)
 
1765
                return m_pagesInfoVec[tabIdx].GetImageIndex() != -1;
 
1766
        return false;
 
1767
}
 
1768
 
 
1769
void wxPageContainer::OnLeftDClick(wxMouseEvent& event)
 
1770
{
 
1771
        wxPageInfo pgInfo;
 
1772
        int tabIdx;
 
1773
        int where = HitTest(event.GetPosition(), pgInfo, tabIdx);
 
1774
        switch(where)
 
1775
        {
 
1776
        case wxFNB_RIGHT_ARROW:
 
1777
                RotateRight();
 
1778
                break;
 
1779
        case wxFNB_LEFT_ARROW:
 
1780
                RotateLeft();
 
1781
                break;
 
1782
        case wxFNB_TAB:
 
1783
                if(HasFlag(wxFNB_DCLICK_CLOSES_TABS))
 
1784
                {
 
1785
                        DeletePage((size_t)tabIdx);
 
1786
                }
 
1787
                break;
 
1788
        case wxFNB_X:
 
1789
                {
 
1790
                        OnLeftDown(event);
 
1791
                }
 
1792
                break;
 
1793
        default:
 
1794
                event.Skip();
 
1795
                break;
 
1796
        }
 
1797
}
 
1798
 
 
1799
void wxPageContainer::PopupTabsMenu()
 
1800
{
 
1801
        wxMenu popupMenu;
 
1802
 
 
1803
        for(size_t i=0; i<m_pagesInfoVec.GetCount(); i++)
 
1804
        {
 
1805
                wxPageInfo pi = m_pagesInfoVec[i];
 
1806
                wxMenuItem *item = new wxMenuItem(&popupMenu, static_cast<int>(i), pi.GetCaption(), pi.GetCaption(), wxITEM_NORMAL);
 
1807
 
 
1808
                // This code is commented, since there is an alignment problem with wx2.6.3 & Menus
 
1809
//              if( TabHasImage(static_cast<int>(i)) )
 
1810
//                      item->SetBitmaps( (*m_ImageList)[pi.GetImageIndex()] );
 
1811
 
 
1812
                popupMenu.Append( item );
 
1813
        }
 
1814
 
 
1815
        // connect an event handler to our menu
 
1816
        popupMenu.Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxPageContainer::OnTabMenuSelection), NULL, this);
 
1817
        PopupMenu( &popupMenu );
 
1818
}
 
1819
 
 
1820
void wxPageContainer::OnTabMenuSelection(wxCommandEvent &event)
 
1821
{
 
1822
        int selection = event.GetId();
 
1823
        static_cast<wxFlatNotebook*>(m_pParent)->SetSelection( (size_t)selection );
 
1824
}
 
1825
 
 
1826
// Draw small arrow at the place that the tab will be placed
 
1827
void wxPageContainer::DrawDragHint()
 
1828
{
 
1829
        // get the index of tab that will be replaced with the dragged tab
 
1830
        wxPageInfo info;
 
1831
        int tabIdx;
 
1832
        wxPoint pt = ::wxGetMousePosition();
 
1833
    wxPoint client_pt = ScreenToClient(pt);
 
1834
        HitTest(client_pt, info, tabIdx);
 
1835
        wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() )->DrawDragHint(this, tabIdx);
 
1836
}
 
1837
 
 
1838
void wxPageContainer::SetCustomizeOptions(long options)
 
1839
{
 
1840
        m_customizeOptions = options;
 
1841
}
 
1842
 
 
1843
long wxPageContainer::GetCustomizeOptions() const
 
1844
{
 
1845
        return m_customizeOptions;
 
1846
}