various close-button styles implemented in wxAuiNotebook
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42942 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -45,8 +45,8 @@ enum wxAuiNotebookOption
|
|||||||
wxAUI_NB_DEFAULT_STYLE = wxAUI_NB_TOP |
|
wxAUI_NB_DEFAULT_STYLE = wxAUI_NB_TOP |
|
||||||
wxAUI_NB_TAB_SPLIT |
|
wxAUI_NB_TAB_SPLIT |
|
||||||
wxAUI_NB_TAB_MOVE |
|
wxAUI_NB_TAB_MOVE |
|
||||||
wxAUI_NB_SCROLL_BUTTONS// |
|
wxAUI_NB_SCROLL_BUTTONS |
|
||||||
//wxAUI_NB_CLOSE_ON_ALL_TABS
|
wxAUI_NB_CLOSE_ON_ACTIVE_TAB
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -74,8 +74,9 @@ public:
|
|||||||
const wxRect& in_rect,
|
const wxRect& in_rect,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
bool active,
|
bool active,
|
||||||
bool with_close_button,
|
int close_button_state,
|
||||||
wxRect* out_rect,
|
wxRect* out_tab_rect,
|
||||||
|
wxRect* out_button_rect,
|
||||||
int* x_extent) = 0;
|
int* x_extent) = 0;
|
||||||
|
|
||||||
virtual void DrawButton(
|
virtual void DrawButton(
|
||||||
@@ -91,7 +92,7 @@ public:
|
|||||||
wxDC* dc,
|
wxDC* dc,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
bool active,
|
bool active,
|
||||||
bool with_close_button,
|
int close_button_state,
|
||||||
int* x_extent) = 0;
|
int* x_extent) = 0;
|
||||||
|
|
||||||
virtual int GetBestTabCtrlSize(wxWindow* wnd) = 0;
|
virtual int GetBestTabCtrlSize(wxWindow* wnd) = 0;
|
||||||
@@ -118,8 +119,9 @@ public:
|
|||||||
const wxRect& in_rect,
|
const wxRect& in_rect,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
bool active,
|
bool active,
|
||||||
bool with_close_button,
|
int close_button_state,
|
||||||
wxRect* out_rect,
|
wxRect* out_tab_rect,
|
||||||
|
wxRect* out_button_rect,
|
||||||
int* x_extent);
|
int* x_extent);
|
||||||
|
|
||||||
void DrawButton(
|
void DrawButton(
|
||||||
@@ -135,7 +137,7 @@ public:
|
|||||||
wxDC* dc,
|
wxDC* dc,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
bool active,
|
bool active,
|
||||||
bool with_close_button,
|
int close_button_state,
|
||||||
int* x_extent);
|
int* x_extent);
|
||||||
|
|
||||||
int GetBestTabCtrlSize(wxWindow* wnd);
|
int GetBestTabCtrlSize(wxWindow* wnd);
|
||||||
@@ -211,9 +213,10 @@ public:
|
|||||||
class WXDLLIMPEXP_AUI wxAuiTabContainerButton
|
class WXDLLIMPEXP_AUI wxAuiTabContainerButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int id; // button's id
|
int id; // button's id
|
||||||
int cur_state; // current state (normal, hover, pressed, etc.)
|
int cur_state; // current state (normal, hover, pressed, etc.)
|
||||||
int location; // buttons location (wxLEFT or wxRIGHT)
|
int location; // buttons location (wxLEFT, wxRIGHT, or wxCENTER)
|
||||||
wxBitmap bitmap; // button's hover bitmap
|
wxBitmap bitmap; // button's hover bitmap
|
||||||
wxBitmap dis_bitmap; // button's disabled bitmap
|
wxBitmap dis_bitmap; // button's disabled bitmap
|
||||||
wxRect rect; // button's hit rectangle
|
wxRect rect; // button's hit rectangle
|
||||||
@@ -259,6 +262,8 @@ public:
|
|||||||
void SetMeasuringFont(const wxFont& measuring_font);
|
void SetMeasuringFont(const wxFont& measuring_font);
|
||||||
void DoShowHide();
|
void DoShowHide();
|
||||||
void SetRect(const wxRect& rect);
|
void SetRect(const wxRect& rect);
|
||||||
|
|
||||||
|
void RemoveButton(int id);
|
||||||
void AddButton(int id,
|
void AddButton(int id,
|
||||||
int location,
|
int location,
|
||||||
const wxBitmap& normal_bitmap = wxNullBitmap,
|
const wxBitmap& normal_bitmap = wxNullBitmap,
|
||||||
@@ -276,6 +281,7 @@ private:
|
|||||||
wxAuiTabArt* m_art;
|
wxAuiTabArt* m_art;
|
||||||
wxAuiNotebookPageArray m_pages;
|
wxAuiNotebookPageArray m_pages;
|
||||||
wxAuiTabContainerButtonArray m_buttons;
|
wxAuiTabContainerButtonArray m_buttons;
|
||||||
|
wxAuiTabContainerButtonArray m_tab_close_buttons;
|
||||||
wxRect m_rect;
|
wxRect m_rect;
|
||||||
size_t m_tab_offset;
|
size_t m_tab_offset;
|
||||||
unsigned int m_flags;
|
unsigned int m_flags;
|
||||||
|
@@ -193,8 +193,9 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
|
|||||||
const wxRect& in_rect,
|
const wxRect& in_rect,
|
||||||
const wxString& caption_text,
|
const wxString& caption_text,
|
||||||
bool active,
|
bool active,
|
||||||
bool with_close_button,
|
int close_button_state,
|
||||||
wxRect* out_rect,
|
wxRect* out_tab_rect,
|
||||||
|
wxRect* out_button_rect,
|
||||||
int* x_extent)
|
int* x_extent)
|
||||||
{
|
{
|
||||||
wxCoord normal_textx, normal_texty;
|
wxCoord normal_textx, normal_texty;
|
||||||
@@ -213,7 +214,7 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
|
|||||||
dc->GetTextExtent(caption, &normal_textx, &normal_texty);
|
dc->GetTextExtent(caption, &normal_textx, &normal_texty);
|
||||||
|
|
||||||
// figure out the size of the tab
|
// figure out the size of the tab
|
||||||
wxSize tab_size = GetTabSize(dc, caption, active, with_close_button, x_extent);
|
wxSize tab_size = GetTabSize(dc, caption, active, close_button_state, x_extent);
|
||||||
|
|
||||||
wxCoord tab_height = tab_size.y;
|
wxCoord tab_height = tab_size.y;
|
||||||
wxCoord tab_width = tab_size.x;
|
wxCoord tab_width = tab_size.x;
|
||||||
@@ -269,7 +270,7 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
|
|||||||
int text_offset;
|
int text_offset;
|
||||||
|
|
||||||
int close_button_width = 0;
|
int close_button_width = 0;
|
||||||
if (with_close_button)
|
if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
|
||||||
{
|
{
|
||||||
close_button_width = m_active_close_bmp.GetWidth();
|
close_button_width = m_active_close_bmp.GetWidth();
|
||||||
text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2);
|
text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2);
|
||||||
@@ -287,7 +288,7 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
|
|||||||
|
|
||||||
|
|
||||||
// draw close button if necessary
|
// draw close button if necessary
|
||||||
if (with_close_button)
|
if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
|
||||||
{
|
{
|
||||||
wxBitmap bmp;
|
wxBitmap bmp;
|
||||||
if (active)
|
if (active)
|
||||||
@@ -297,18 +298,20 @@ void wxAuiDefaultTabArt::DrawTab(wxDC* dc,
|
|||||||
|
|
||||||
wxRect rect(tab_x + tab_width - close_button_width - 1, tab_y + 1,
|
wxRect rect(tab_x + tab_width - close_button_width - 1, tab_y + 1,
|
||||||
close_button_width, tab_height - 1);
|
close_button_width, tab_height - 1);
|
||||||
DrawButtonS(*dc, rect, bmp, *wxWHITE, wxAUI_BUTTON_STATE_NORMAL);
|
DrawButtonS(*dc, rect, bmp, *wxWHITE, close_button_state);
|
||||||
|
|
||||||
|
*out_button_rect = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*out_rect = wxRect(tab_x, tab_y, tab_width, tab_height);
|
*out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxSize wxAuiDefaultTabArt::GetTabSize(wxDC* dc,
|
wxSize wxAuiDefaultTabArt::GetTabSize(wxDC* dc,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
bool WXUNUSED(active),
|
bool WXUNUSED(active),
|
||||||
bool with_close_button,
|
int close_button_state,
|
||||||
int* x_extent)
|
int* x_extent)
|
||||||
{
|
{
|
||||||
wxCoord measured_textx, measured_texty;
|
wxCoord measured_textx, measured_texty;
|
||||||
@@ -319,7 +322,7 @@ wxSize wxAuiDefaultTabArt::GetTabSize(wxDC* dc,
|
|||||||
wxCoord tab_height = measured_texty + 4;
|
wxCoord tab_height = measured_texty + 4;
|
||||||
wxCoord tab_width = measured_textx + tab_height + 5;
|
wxCoord tab_width = measured_textx + tab_height + 5;
|
||||||
|
|
||||||
if (with_close_button)
|
if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
|
||||||
tab_width += m_active_close_bmp.GetWidth();
|
tab_width += m_active_close_bmp.GetWidth();
|
||||||
|
|
||||||
*x_extent = tab_width - (tab_height/2) - 1;
|
*x_extent = tab_width - (tab_height/2) - 1;
|
||||||
@@ -401,7 +404,7 @@ int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd)
|
|||||||
wxClientDC dc(wnd);
|
wxClientDC dc(wnd);
|
||||||
dc.SetFont(m_measuring_font);
|
dc.SetFont(m_measuring_font);
|
||||||
int x_ext = 0;
|
int x_ext = 0;
|
||||||
wxSize s = GetTabSize(&dc, wxT("ABCDEFGHIj"), true, false, &x_ext);
|
wxSize s = GetTabSize(&dc, wxT("ABCDEFGHIj"), true, wxAUI_BUTTON_STATE_HIDDEN, &x_ext);
|
||||||
return s.y+3;
|
return s.y+3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,6 +471,13 @@ wxAuiTabArt* wxAuiTabContainer::GetArtProvider()
|
|||||||
void wxAuiTabContainer::SetFlags(unsigned int flags)
|
void wxAuiTabContainer::SetFlags(unsigned int flags)
|
||||||
{
|
{
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
|
|
||||||
|
// check for new close button settings
|
||||||
|
RemoveButton(wxAUI_BUTTON_CLOSE);
|
||||||
|
if (flags & wxAUI_NB_CLOSE_BUTTON)
|
||||||
|
{
|
||||||
|
AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int wxAuiTabContainer::GetFlags() const
|
unsigned int wxAuiTabContainer::GetFlags() const
|
||||||
@@ -664,6 +674,22 @@ void wxAuiTabContainer::AddButton(int id,
|
|||||||
m_buttons.Add(button);
|
m_buttons.Add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxAuiTabContainer::RemoveButton(int id)
|
||||||
|
{
|
||||||
|
size_t i, button_count = m_buttons.GetCount();
|
||||||
|
|
||||||
|
for (i = 0; i < button_count; ++i)
|
||||||
|
{
|
||||||
|
if (m_buttons.Item(i).id == id)
|
||||||
|
{
|
||||||
|
m_buttons.RemoveAt(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t wxAuiTabContainer::GetTabOffset() const
|
size_t wxAuiTabContainer::GetTabOffset() const
|
||||||
{
|
{
|
||||||
return m_tab_offset;
|
return m_tab_offset;
|
||||||
@@ -708,7 +734,13 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
|
|
||||||
|
|
||||||
int x_extent = 0;
|
int x_extent = 0;
|
||||||
wxSize size = m_art->GetTabSize(&dc, page.caption, page.active, close_button, &x_extent);
|
wxSize size = m_art->GetTabSize(&dc,
|
||||||
|
page.caption,
|
||||||
|
page.active,
|
||||||
|
close_button ?
|
||||||
|
wxAUI_BUTTON_STATE_NORMAL :
|
||||||
|
wxAUI_BUTTON_STATE_HIDDEN,
|
||||||
|
&x_extent);
|
||||||
|
|
||||||
if (i+1 < page_count)
|
if (i+1 < page_count)
|
||||||
total_width += x_extent;
|
total_width += x_extent;
|
||||||
@@ -846,6 +878,23 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
m_rect.GetHeight());
|
m_rect.GetHeight());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// prepare the tab-close-button array
|
||||||
|
while (m_tab_close_buttons.GetCount() < page_count)
|
||||||
|
{
|
||||||
|
wxAuiTabContainerButton tempbtn;
|
||||||
|
tempbtn.id = wxAUI_BUTTON_CLOSE;
|
||||||
|
tempbtn.location = wxCENTER;
|
||||||
|
tempbtn.cur_state = wxAUI_BUTTON_STATE_HIDDEN;
|
||||||
|
m_tab_close_buttons.Add(tempbtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < m_tab_offset; ++i)
|
||||||
|
{
|
||||||
|
// buttons before the tab offset must be set to hidden
|
||||||
|
m_tab_close_buttons.Item(i).cur_state = wxAUI_BUTTON_STATE_HIDDEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// draw the tabs
|
// draw the tabs
|
||||||
|
|
||||||
@@ -861,6 +910,7 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
for (i = m_tab_offset; i < page_count; ++i)
|
for (i = m_tab_offset; i < page_count; ++i)
|
||||||
{
|
{
|
||||||
wxAuiNotebookPage& page = m_pages.Item(i);
|
wxAuiNotebookPage& page = m_pages.Item(i);
|
||||||
|
wxAuiTabContainerButton& tab_button = m_tab_close_buttons.Item(i);
|
||||||
|
|
||||||
// determine if a close button is on this tab
|
// determine if a close button is on this tab
|
||||||
bool close_button = false;
|
bool close_button = false;
|
||||||
@@ -868,6 +918,16 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active))
|
((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active))
|
||||||
{
|
{
|
||||||
close_button = true;
|
close_button = true;
|
||||||
|
if (tab_button.cur_state == wxAUI_BUTTON_STATE_HIDDEN)
|
||||||
|
{
|
||||||
|
tab_button.id = wxAUI_BUTTON_CLOSE;
|
||||||
|
tab_button.cur_state = wxAUI_BUTTON_STATE_NORMAL;
|
||||||
|
tab_button.location = wxCENTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tab_button.cur_state = wxAUI_BUTTON_STATE_HIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.x = offset;
|
rect.x = offset;
|
||||||
@@ -876,8 +936,9 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
rect,
|
rect,
|
||||||
page.caption,
|
page.caption,
|
||||||
page.active,
|
page.active,
|
||||||
close_button,
|
tab_button.cur_state,
|
||||||
&page.rect,
|
&page.rect,
|
||||||
|
&tab_button.rect,
|
||||||
&x_extent);
|
&x_extent);
|
||||||
|
|
||||||
if (page.active)
|
if (page.active)
|
||||||
@@ -885,7 +946,7 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
active = i;
|
active = i;
|
||||||
active_offset = offset;
|
active_offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += x_extent;
|
offset += x_extent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -894,6 +955,8 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
{
|
{
|
||||||
wxAuiNotebookPage& page = m_pages.Item(active);
|
wxAuiNotebookPage& page = m_pages.Item(active);
|
||||||
|
|
||||||
|
wxAuiTabContainerButton& tab_button = m_tab_close_buttons.Item(active);
|
||||||
|
|
||||||
// determine if a close button is on this tab
|
// determine if a close button is on this tab
|
||||||
bool close_button = false;
|
bool close_button = false;
|
||||||
if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 ||
|
if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 ||
|
||||||
@@ -907,8 +970,9 @@ void wxAuiTabContainer::Render(wxDC* raw_dc)
|
|||||||
rect,
|
rect,
|
||||||
page.caption,
|
page.caption,
|
||||||
page.active,
|
page.active,
|
||||||
close_button,
|
tab_button.cur_state,
|
||||||
&page.rect,
|
&page.rect,
|
||||||
|
&tab_button.rect,
|
||||||
&x_extent);
|
&x_extent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,8 +992,12 @@ bool wxAuiTabContainer::TabHitTest(int x, int y, wxWindow** hit) const
|
|||||||
if (!m_rect.Contains(x,y))
|
if (!m_rect.Contains(x,y))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (ButtonHitTest(x, y, NULL))
|
wxAuiTabContainerButton* btn = NULL;
|
||||||
return false;
|
if (ButtonHitTest(x, y, &btn))
|
||||||
|
{
|
||||||
|
if (m_buttons.Index(*btn) != wxNOT_FOUND)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
size_t i, page_count = m_pages.GetCount();
|
size_t i, page_count = m_pages.GetCount();
|
||||||
|
|
||||||
@@ -955,8 +1023,10 @@ bool wxAuiTabContainer::ButtonHitTest(int x, int y,
|
|||||||
if (!m_rect.Contains(x,y))
|
if (!m_rect.Contains(x,y))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t i, button_count = m_buttons.GetCount();
|
size_t i, button_count;
|
||||||
|
|
||||||
|
|
||||||
|
button_count = m_buttons.GetCount();
|
||||||
for (i = 0; i < button_count; ++i)
|
for (i = 0; i < button_count; ++i)
|
||||||
{
|
{
|
||||||
wxAuiTabContainerButton& button = m_buttons.Item(i);
|
wxAuiTabContainerButton& button = m_buttons.Item(i);
|
||||||
@@ -967,7 +1037,19 @@ bool wxAuiTabContainer::ButtonHitTest(int x, int y,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button_count = m_tab_close_buttons.GetCount();
|
||||||
|
for (i = 0; i < button_count; ++i)
|
||||||
|
{
|
||||||
|
wxAuiTabContainerButton& button = m_tab_close_buttons.Item(i);
|
||||||
|
if (button.rect.Contains(x,y))
|
||||||
|
{
|
||||||
|
if (hit)
|
||||||
|
*hit = &button;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user