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

« back to all changes in this revision

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