+// aui notebook event class
+
+class WXDLLIMPEXP_AUI wxAuiNotebookEvent : public wxNotifyEvent
+{
+public:
+ wxAuiNotebookEvent(wxEventType command_type = wxEVT_NULL,
+ int win_id = 0)
+ : wxNotifyEvent(command_type, win_id)
+ {
+ old_selection = -1;
+ selection = -1;
+ drag_source = NULL;
+ }
+#ifndef SWIG
+ wxAuiNotebookEvent(const wxAuiNotebookEvent& c) : wxNotifyEvent(c)
+ {
+ old_selection = c.old_selection;
+ selection = c.selection;
+ drag_source = c.drag_source;
+ }
+#endif
+ wxEvent *Clone() const { return new wxAuiNotebookEvent(*this); }
+
+ void SetSelection(int s) { selection = s; m_commandInt = s; }
+ int GetSelection() const { return selection; }
+
+ void SetOldSelection(int s) { old_selection = s; }
+ int GetOldSelection() const { return old_selection; }
+
+ void SetDragSource(wxAuiNotebook* s) { drag_source = s; }
+ wxAuiNotebook* GetDragSource() const { return drag_source; }
+
+public:
+ int old_selection;
+ int selection;
+ wxAuiNotebook* drag_source;
+
+#ifndef SWIG
+private:
+ DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiNotebookEvent)
+#endif
+};
+
+
+class WXDLLIMPEXP_AUI wxAuiNotebookPage
+{
+public:
+ wxWindow* window; // page's associated window
+ wxString caption; // caption displayed on the tab
+ wxBitmap bitmap; // tab's bitmap
+ wxRect rect; // tab's hit rectangle
+ bool active; // true if the page is currently active
+};
+
+class WXDLLIMPEXP_AUI wxAuiTabContainerButton
+{
+public:
+
+ int id; // button's id
+ int cur_state; // current state (normal, hover, pressed, etc.)
+ int location; // buttons location (wxLEFT, wxRIGHT, or wxCENTER)
+ wxBitmap bitmap; // button's hover bitmap
+ wxBitmap dis_bitmap; // button's disabled bitmap
+ wxRect rect; // button's hit rectangle
+};
+
+
+#ifndef SWIG
+WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiNotebookPage, wxAuiNotebookPageArray, WXDLLIMPEXP_AUI);
+WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiTabContainerButton, wxAuiTabContainerButtonArray, WXDLLIMPEXP_AUI);
+#endif
+
+
// tab art class
class WXDLLIMPEXP_AUI wxAuiTabArt
wxWindow* wnd,
const wxRect& in_rect,
const wxString& caption,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
wxRect* out_tab_rect,
wxDC& dc,
wxWindow* wnd,
const wxString& caption,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
int* x_extent) = 0;
const wxArrayString& items,
int active_idx) = 0;
- virtual int GetBestTabCtrlSize(wxWindow* wnd) = 0;
+ virtual int GetBestTabCtrlSize(wxWindow* wnd,
+ wxAuiNotebookPageArray& pages) = 0;
};
-class WXDLLIMPEXP_AUI wxAuiSimpleTabArt : public wxAuiTabArt
+class WXDLLIMPEXP_AUI wxAuiDefaultTabArt : public wxAuiTabArt
{
public:
- wxAuiSimpleTabArt();
- virtual ~wxAuiSimpleTabArt();
+ wxAuiDefaultTabArt();
+ virtual ~wxAuiDefaultTabArt();
wxAuiTabArt* Clone();
void SetFlags(unsigned int flags);
-
void SetSizingInfo(const wxSize& tab_ctrl_size,
size_t tab_count);
wxDC& dc,
wxWindow* wnd,
const wxRect& rect);
-
+
void DrawTab(wxDC& dc,
wxWindow* wnd,
const wxRect& in_rect,
const wxString& caption,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
wxRect* out_tab_rect,
int orientation,
const wxBitmap& bitmap_override,
wxRect* out_rect);
-
- int GetIndentSize();
+ int GetIndentSize();
+
wxSize GetTabSize(
wxDC& dc,
wxWindow* wnd,
const wxString& caption,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
int* x_extent);
const wxArrayString& items,
int active_idx);
- int GetBestTabCtrlSize(wxWindow* wnd);
+ int GetBestTabCtrlSize(wxWindow* wnd,
+ wxAuiNotebookPageArray& pages);
protected:
wxBitmap m_disabled_windowlist_bmp;
int m_fixed_tab_width;
+ int m_tab_ctrl_height;
unsigned int m_flags;
};
-class WXDLLIMPEXP_AUI wxAuiDefaultTabArt : public wxAuiTabArt
+class WXDLLIMPEXP_AUI wxAuiSimpleTabArt : public wxAuiTabArt
{
public:
- wxAuiDefaultTabArt();
- virtual ~wxAuiDefaultTabArt();
+ wxAuiSimpleTabArt();
+ virtual ~wxAuiSimpleTabArt();
wxAuiTabArt* Clone();
void SetFlags(unsigned int flags);
+
void SetSizingInfo(const wxSize& tab_ctrl_size,
size_t tab_count);
wxDC& dc,
wxWindow* wnd,
const wxRect& rect);
-
+
void DrawTab(wxDC& dc,
wxWindow* wnd,
const wxRect& in_rect,
const wxString& caption,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
wxRect* out_tab_rect,
int orientation,
const wxBitmap& bitmap_override,
wxRect* out_rect);
-
+
int GetIndentSize();
-
+
wxSize GetTabSize(
wxDC& dc,
wxWindow* wnd,
const wxString& caption,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
int* x_extent);
const wxArrayString& items,
int active_idx);
- int GetBestTabCtrlSize(wxWindow* wnd);
+ int GetBestTabCtrlSize(wxWindow* wnd,
+ wxAuiNotebookPageArray& pages);
protected:
-// event declarations/classes
-
-class WXDLLIMPEXP_AUI wxAuiNotebookEvent : public wxNotifyEvent
-{
-public:
- wxAuiNotebookEvent(wxEventType command_type = wxEVT_NULL,
- int win_id = 0)
- : wxNotifyEvent(command_type, win_id)
- {
- old_selection = -1;
- selection = -1;
- drag_source = NULL;
- }
-#ifndef SWIG
- wxAuiNotebookEvent(const wxAuiNotebookEvent& c) : wxNotifyEvent(c)
- {
- old_selection = c.old_selection;
- selection = c.selection;
- drag_source = c.drag_source;
- }
-#endif
- wxEvent *Clone() const { return new wxAuiNotebookEvent(*this); }
-
- void SetSelection(int s) { selection = s; m_commandInt = s; }
- int GetSelection() const { return selection; }
-
- void SetOldSelection(int s) { old_selection = s; }
- int GetOldSelection() const { return old_selection; }
-
- void SetDragSource(wxAuiNotebook* s) { drag_source = s; }
- wxAuiNotebook* GetDragSource() const { return drag_source; }
-
-public:
- int old_selection;
- int selection;
- wxAuiNotebook* drag_source;
-
-#ifndef SWIG
-private:
- DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiNotebookEvent)
-#endif
-};
-
-
-
-
-
-class WXDLLIMPEXP_AUI wxAuiNotebookPage
-{
-public:
- wxWindow* window; // page's associated window
- wxString caption; // caption displayed on the tab
- wxBitmap bitmap; // tab's bitmap
- wxRect rect; // tab's hit rectangle
- bool active; // true if the page is currently active
-};
-
-class WXDLLIMPEXP_AUI wxAuiTabContainerButton
-{
-public:
- int id; // button's id
- int cur_state; // current state (normal, hover, pressed, etc.)
- int location; // buttons location (wxLEFT, wxRIGHT, or wxCENTER)
- wxBitmap bitmap; // button's hover bitmap
- wxBitmap dis_bitmap; // button's disabled bitmap
- wxRect rect; // button's hit rectangle
-};
-#ifndef SWIG
-WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiNotebookPage, wxAuiNotebookPageArray, WXDLLIMPEXP_AUI);
-WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiTabContainerButton, wxAuiTabContainerButtonArray, WXDLLIMPEXP_AUI);
-#endif
class WXDLLIMPEXP_AUI wxAuiTabContainer
size_t GetPageCount() const;
wxWindow* GetPage(size_t page_idx) const;
-
void SetArtProvider(wxAuiTabArt* art);
wxAuiTabArt* GetArtProvider();
protected:
+ // these can be overridden
+ virtual void SetTabCtrlHeight(int height);
+ virtual int CalculateTabCtrlHeight();
+
+protected:
+
+ void DoSizing();
+ void InitNotebook(long style);
wxAuiTabCtrl* GetTabCtrlFromPoint(const wxPoint& pt);
wxWindow* GetTabFrameFromTabCtrl(wxWindow* tab_ctrl);
wxAuiTabCtrl* GetActiveTabCtrl();
protected:
- void DoSizing();
- void InitNotebook(long style);
void OnChildFocus(wxChildFocusEvent& evt);
void OnRender(wxAuiManagerEvent& evt);
wxPoint(client_size.x, client_size.y),
wxSize(430,200),
m_notebook_style);
+
+ wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
- ctrl->AddPage(CreateHTMLCtrl(ctrl), wxT("Welcome to wxAUI"));
+ ctrl->AddPage(CreateHTMLCtrl(ctrl), wxT("Welcome to wxAUI") , false, page_bmp);
wxPanel *panel = new wxPanel( ctrl, wxID_ANY );
wxFlexGridSizer *flex = new wxFlexGridSizer( 2 );
wxSP_ARROW_KEYS, 5, 50, 5 ), 0, wxALL|wxALIGN_CENTRE, 5 );
flex->Add( 5,5 ); flex->Add( 5,5 );
panel->SetSizer( flex );
- ctrl->AddPage( panel, wxT("wxPanel") );
+ ctrl->AddPage( panel, wxT("wxPanel"), false, page_bmp );
ctrl->AddPage( new wxTextCtrl( ctrl, wxID_ANY, wxT("Some text"),
- wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER) , wxT("wxTextCtrl 1") );
+ wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER) , wxT("wxTextCtrl 1"), false, page_bmp );
ctrl->AddPage( new wxTextCtrl( ctrl, wxID_ANY, wxT("Some more text"),
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER) , wxT("wxTextCtrl 2") );
m_measuring_font = m_selected_font;
m_fixed_tab_width = 100;
+ m_tab_ctrl_height = 0;
wxColour base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
if (m_fixed_tab_width > 220)
m_fixed_tab_width = 220;
+
+ m_tab_ctrl_height = tab_ctrl_size.y;
}
wxWindow* wnd,
const wxRect& in_rect,
const wxString& caption_text,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
wxRect* out_tab_rect,
dc.GetTextExtent(caption, &normal_textx, &normal_texty);
// figure out the size of the tab
- wxSize tab_size = GetTabSize(dc, wnd, caption, active, close_button_state, x_extent);
-
- wxCoord tab_height = tab_size.y;
+ wxSize tab_size = GetTabSize(dc,
+ wnd,
+ caption,
+ bitmap,
+ active,
+ close_button_state,
+ x_extent);
+
+ wxCoord tab_height = m_tab_ctrl_height - 3;
wxCoord tab_width = tab_size.x;
wxCoord tab_x = in_rect.x;
wxCoord tab_y = in_rect.y + in_rect.height - tab_height;
points[5].x = tab_x + tab_width;
points[5].y = tab_y + tab_height - 4;
+ int drawn_tab_yoff = points[1].y;
+ int drawn_tab_height = points[0].y - points[1].y;
+
// draw gradient background
if (active)
dc.DrawLine(points[0].x, points[0].y, points[5].x+1, points[5].y);
}
- int text_offset;
+ int text_offset = tab_x + 8;
int close_button_width = 0;
-
if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
{
close_button_width = m_active_close_bmp.GetWidth();
}
- text_offset = tab_x + 8;
+ if (bitmap.IsOk())
+ {
+ int bitmap_offset = tab_x + 8;
+
+ // draw bitmap
+ dc.DrawBitmap(bitmap,
+ bitmap_offset,
+ drawn_tab_yoff + (drawn_tab_height/2) - (bitmap.GetHeight()/2) + 1,
+ true);
+
+ text_offset = bitmap_offset + bitmap.GetWidth();
+ text_offset += 3; // bitmap padding
+ }
+ else
+ {
+ text_offset = tab_x + 8;
+ }
+
wxString draw_text = ChopText(dc,
caption,
// draw tab text
dc.DrawText(draw_text,
text_offset,
- (tab_y + tab_height)/2 - (texty/2));
+ drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1);
wxSize wxAuiDefaultTabArt::GetTabSize(wxDC& dc,
wxWindow* WXUNUSED(wnd),
const wxString& caption,
+ const wxBitmap& bitmap,
bool WXUNUSED(active),
int close_button_state,
int* x_extent)
dc.GetTextExtent(wxT("ABCDEFXj"), &tmp, &measured_texty);
// add padding around the text
- wxCoord tab_width = measured_textx + 16;
- wxCoord tab_height = measured_texty + 10;
+ wxCoord tab_width = measured_textx;
+ wxCoord tab_height = measured_texty;
+ // if the close button is showing, add space for it
if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
tab_width += m_active_close_bmp.GetWidth() + 3;
+ // if there's a bitmap, add space for it
+ if (bitmap.IsOk())
+ {
+ tab_width += bitmap.GetWidth();
+ tab_width += 3; // right side bitmap padding
+ tab_height = wxMax(tab_height, bitmap.GetHeight());
+ }
+
+ // add padding
+ tab_width += 16;
+ tab_height += 10;
if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH)
{
return -1;
}
-int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd)
+int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd,
+ wxAuiNotebookPageArray& pages)
{
wxClientDC dc(wnd);
dc.SetFont(m_measuring_font);
- int x_ext = 0;
- wxSize s = GetTabSize(dc,
- wnd,
- wxT("ABCDEFGHIj"),
- true,
- wxAUI_BUTTON_STATE_HIDDEN,
- &x_ext);
- return s.y+3;
+
+ int max_y = 0;
+ size_t i, page_count = pages.GetCount();
+ for (i = 0; i < page_count; ++i)
+ {
+ wxAuiNotebookPage& page = pages.Item(i);
+
+ // we don't use the caption text because we don't
+ // want tab heights to be different in the case
+ // of a very short piece of text on one tab and a very
+ // tall piece of text on another tab
+ int x_ext = 0;
+ wxSize s = GetTabSize(dc,
+ wnd,
+ wxT("ABCDEFGHIj"),
+ page.bitmap,
+ true,
+ wxAUI_BUTTON_STATE_HIDDEN,
+ &x_ext);
+ max_y = wxMax(max_y, s.y);
+ }
+
+ return max_y+2;
}
void wxAuiDefaultTabArt::SetNormalFont(const wxFont& font)
wxWindow* wnd,
const wxRect& in_rect,
const wxString& caption_text,
+ const wxBitmap& bitmap,
bool active,
int close_button_state,
wxRect* out_tab_rect,
dc.GetTextExtent(caption, &normal_textx, &normal_texty);
// figure out the size of the tab
- wxSize tab_size = GetTabSize(dc, wnd, caption, active, close_button_state, x_extent);
+ wxSize tab_size = GetTabSize(dc,
+ wnd,
+ caption,
+ bitmap,
+ active,
+ close_button_state,
+ x_extent);
wxCoord tab_height = tab_size.y;
wxCoord tab_width = tab_size.x;
wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc,
wxWindow* WXUNUSED(wnd),
const wxString& caption,
+ const wxBitmap& WXUNUSED(bitmap),
bool WXUNUSED(active),
int close_button_state,
int* x_extent)
return -1;
}
-int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow* wnd)
+int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow* wnd,
+ wxAuiNotebookPageArray& WXUNUSED(pages))
{
wxClientDC dc(wnd);
dc.SetFont(m_measuring_font);
wxSize s = GetTabSize(dc,
wnd,
wxT("ABCDEFGHIj"),
+ wxNullBitmap,
true,
wxAUI_BUTTON_STATE_HIDDEN,
&x_ext);
wxSize size = m_art->GetTabSize(dc,
wnd,
page.caption,
+ page.bitmap,
page.active,
close_button ?
wxAUI_BUTTON_STATE_NORMAL :
wnd,
rect,
page.caption,
+ page.bitmap,
page.active,
tab_button.cur_state,
&page.rect,
wnd,
active_rect,
page.caption,
+ page.bitmap,
page.active,
tab_button.cur_state,
&page.rect,
{
m_tabs.SetArtProvider(art);
- // choose a default for the tab height
- m_tab_ctrl_height = art->GetBestTabCtrlSize(this);
-
- wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
- size_t i, pane_count = all_panes.GetCount();
- for (i = 0; i < pane_count; ++i)
+ SetTabCtrlHeight(CalculateTabCtrlHeight());
+}
+
+void wxAuiNotebook::SetTabCtrlHeight(int height)
+{
+ // if the tab control height needs to change, update
+ // all of our tab controls with the new height
+ if (m_tab_ctrl_height != height)
{
- wxAuiPaneInfo& pane = all_panes.Item(i);
- if (pane.name == wxT("dummy"))
- continue;
- wxTabFrame* tab_frame = (wxTabFrame*)pane.window;
- wxAuiTabCtrl* tabctrl = tab_frame->m_tabs;
- tab_frame->SetTabCtrlHeight(m_tab_ctrl_height);
- tabctrl->SetArtProvider(art->Clone());
- tab_frame->DoSizing();
+ wxAuiTabArt* art = m_tabs.GetArtProvider();
+
+ m_tab_ctrl_height = height;
+
+ wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
+ size_t i, pane_count = all_panes.GetCount();
+ for (i = 0; i < pane_count; ++i)
+ {
+ wxAuiPaneInfo& pane = all_panes.Item(i);
+ if (pane.name == wxT("dummy"))
+ continue;
+ wxTabFrame* tab_frame = (wxTabFrame*)pane.window;
+ wxAuiTabCtrl* tabctrl = tab_frame->m_tabs;
+ tab_frame->SetTabCtrlHeight(m_tab_ctrl_height);
+ tabctrl->SetArtProvider(art->Clone());
+ tab_frame->DoSizing();
+ }
}
-
}
+int wxAuiNotebook::CalculateTabCtrlHeight()
+{
+ // find out new best tab height
+ wxAuiTabArt* art = m_tabs.GetArtProvider();
+
+ return art->GetBestTabCtrlSize(this, m_tabs.GetPages());
+}
+
+
wxAuiTabArt* wxAuiNotebook::GetArtProvider()
{
return m_tabs.GetArtProvider();
else
active_tabctrl->InsertPage(page, info, page_idx);
+ SetTabCtrlHeight(CalculateTabCtrlHeight());
DoSizing();
active_tabctrl->DoShowHide();