1
#include <wx/wxFlatNotebook/popup_dlg.h>
2
#include <wx/listctrl.h>
3
#include <wx/wxFlatNotebook/wxFlatNotebook.h>
4
#include <wx/wxFlatNotebook/renderer.h>
5
#include <wx/listbox.h>
7
//#include <wx/mstream.h>
8
#include <wx/wxFlatNotebook/fnb_resources.h>
10
wxBitmap wxTabNavigatorWindow::m_bmp;
12
wxTabNavigatorWindow::wxTabNavigatorWindow(wxWindow* parent)
18
GetSizer()->Fit(this);
19
GetSizer()->SetSizeHints(this);
24
wxTabNavigatorWindow::wxTabNavigatorWindow()
32
wxTabNavigatorWindow::~wxTabNavigatorWindow()
36
void wxTabNavigatorWindow::Create(wxWindow* parent)
39
if( !wxDialog::Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, style) )
42
wxBoxSizer *sz = new wxBoxSizer( wxVERTICAL );
45
long flags = wxLB_SINGLE | wxNO_BORDER ;
46
m_listBox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(200, 150), 0, NULL, flags);
48
static int panelHeight = 0;
49
if( panelHeight == 0 )
53
// bitmap must be set before it can be used for anything
55
mem_dc.SelectObject(bmp);
57
wxFont font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
58
font.SetWeight( wxBOLD );
61
mem_dc.GetTextExtent(wxT("Tp"), &w, &panelHeight);
62
panelHeight += 4; // Place a spacer of 2 pixels
64
// Out signpost bitmap is 24 pixels
65
if( panelHeight < 24 )
69
m_panel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxSize(200, panelHeight));
72
sz->Add( m_listBox, 1, wxEXPAND );
76
// Connect events to the list box
77
m_listBox->Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(wxTabNavigatorWindow::OnKeyUp), NULL, this);
78
//Connect(wxEVT_CHAR_HOOK, wxCharEventHandler(wxTabNavigatorWindow::OnKeyUp), NULL, this);
79
m_listBox->Connect(wxID_ANY, wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(wxTabNavigatorWindow::OnNavigationKey), NULL, this);
80
m_listBox->Connect(wxID_ANY, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler(wxTabNavigatorWindow::OnItemSelected), NULL, this);
82
// Connect paint event to the panel
83
m_panel->Connect(wxID_ANY, wxEVT_PAINT, wxPaintEventHandler(wxTabNavigatorWindow::OnPanelPaint), NULL, this);
84
m_panel->Connect(wxID_ANY, wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(wxTabNavigatorWindow::OnPanelEraseBg), NULL, this);
86
SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) );
87
m_listBox->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
88
PopulateListControl( static_cast<wxFlatNotebook*>( parent ) );
90
// Create the bitmap, only once
93
wxImage img(signpost_xpm);
94
img.SetAlpha((unsigned char*)signpost_alpha, true);
95
m_bmp = wxBitmap(img);
97
m_listBox->SetFocus();
100
void wxTabNavigatorWindow::OnKeyUp(wxKeyEvent &event)
102
if( event.GetKeyCode() == WXK_CONTROL )
108
void wxTabNavigatorWindow::OnNavigationKey(wxNavigationKeyEvent &event)
110
long selected = m_listBox->GetSelection();
111
wxFlatNotebook* bk = static_cast<wxFlatNotebook*>(GetParent());
112
long maxItems = bk->GetPageCount();
115
if( event.GetDirection() )
118
if (selected == maxItems - 1)
121
itemToSelect = selected + 1;
127
itemToSelect = maxItems - 1;
129
itemToSelect = selected - 1;
132
m_listBox->SetSelection( itemToSelect );
135
void wxTabNavigatorWindow::PopulateListControl(wxFlatNotebook *book)
137
int selection = book->GetSelection();
138
//int count = book->GetPageCount();
140
std::map<int, bool> temp;
141
m_listBox->Append( book->GetPageText(static_cast<int>(selection)) );
142
m_indexMap[0] = selection;
143
temp[selection] = true;
145
const wxArrayInt &arr = book->GetBrowseHistory();
146
for(size_t i=0; i<arr.GetCount(); i++)
148
if(temp.find(arr.Item(i)) == temp.end()){
149
m_listBox->Append( book->GetPageText(static_cast<int>(arr.Item(i))) );
150
m_indexMap[(int)m_listBox->GetCount()-1] = arr.Item(i);
151
temp[arr.Item(i)] = true;
155
// Select the next entry after the current selection
156
m_listBox->SetSelection( 0 );
157
wxNavigationKeyEvent dummy;
158
dummy.SetDirection(true);
159
OnNavigationKey(dummy);
162
void wxTabNavigatorWindow::OnItemSelected(wxCommandEvent & event )
164
wxUnusedVar( event );
168
void wxTabNavigatorWindow::CloseDialog()
170
wxFlatNotebook* bk = static_cast<wxFlatNotebook*>(GetParent());
171
m_selectedItem = m_listBox->GetSelection();
172
std::map<int, int>::iterator iter = m_indexMap.find(m_selectedItem);
173
bk->SetSelection( iter->second );
177
void wxTabNavigatorWindow::OnPanelPaint(wxPaintEvent &event)
180
wxPaintDC dc(m_panel);
181
wxRect rect = m_panel->GetClientRect();
183
static bool first = true;
184
static wxBitmap bmp( rect.width, rect.height );
190
mem_dc.SelectObject( bmp );
192
wxColour endColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW) );
193
wxColour startColour( wxFNBRenderer::LightColour(endColour, 50) );
194
wxFNBRenderer::PaintStraightGradientBox(mem_dc, rect, startColour, endColour);
196
// Draw the caption title and place the bitmap
200
// get the bitmap optimal position, and draw it
201
bmpPt.y = (rect.height - m_bmp.GetHeight()) / 2;
203
mem_dc.DrawBitmap( m_bmp, bmpPt, true );
205
// get the text position, and draw it
206
int fontHeight(0), w(0);
207
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
208
font.SetWeight( wxBOLD );
209
mem_dc.SetFont( font );
210
mem_dc.GetTextExtent( wxT("Tp"), &w, &fontHeight );
212
txtPt.x = bmpPt.x + m_bmp.GetWidth() + 4;
213
txtPt.y = (rect.height - fontHeight)/2;
214
mem_dc.SetTextForeground( *wxWHITE );
215
mem_dc.DrawText( wxT("Opened tabs:"), txtPt );
216
mem_dc.SelectObject( wxNullBitmap );
219
dc.DrawBitmap( bmp, 0, 0 );
222
void wxTabNavigatorWindow::OnPanelEraseBg(wxEraseEvent &event)