Add support for toggle buttons to wxRibbonButtonBar.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66055 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -154,6 +154,7 @@ enum wxRibbonButtonKind
|
|||||||
wxRIBBON_BUTTON_NORMAL = 1 << 0,
|
wxRIBBON_BUTTON_NORMAL = 1 << 0,
|
||||||
wxRIBBON_BUTTON_DROPDOWN = 1 << 1,
|
wxRIBBON_BUTTON_DROPDOWN = 1 << 1,
|
||||||
wxRIBBON_BUTTON_HYBRID = wxRIBBON_BUTTON_NORMAL | wxRIBBON_BUTTON_DROPDOWN,
|
wxRIBBON_BUTTON_HYBRID = wxRIBBON_BUTTON_NORMAL | wxRIBBON_BUTTON_DROPDOWN,
|
||||||
|
wxRIBBON_BUTTON_TOGGLE = 1 << 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum wxRibbonButtonBarButtonState
|
enum wxRibbonButtonBarButtonState
|
||||||
@@ -170,7 +171,8 @@ enum wxRibbonButtonBarButtonState
|
|||||||
wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE = 1 << 6,
|
wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE = 1 << 6,
|
||||||
wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK = wxRIBBON_BUTTONBAR_BUTTON_NORMAL_ACTIVE | wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE,
|
wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK = wxRIBBON_BUTTONBAR_BUTTON_NORMAL_ACTIVE | wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE,
|
||||||
wxRIBBON_BUTTONBAR_BUTTON_DISABLED = 1 << 7,
|
wxRIBBON_BUTTONBAR_BUTTON_DISABLED = 1 << 7,
|
||||||
wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0xF8,
|
wxRIBBON_BUTTONBAR_BUTTON_TOGGLED = 1 << 8,
|
||||||
|
wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0x1F8,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum wxRibbonGalleryButtonState
|
enum wxRibbonGalleryButtonState
|
||||||
|
@@ -67,6 +67,12 @@ public:
|
|||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxString& help_string = wxEmptyString);
|
const wxString& help_string = wxEmptyString);
|
||||||
|
|
||||||
|
virtual wxRibbonButtonBarButtonBase* AddToggleButton(
|
||||||
|
int button_id,
|
||||||
|
const wxString& label,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxString& help_string = wxEmptyString);
|
||||||
|
|
||||||
virtual wxRibbonButtonBarButtonBase* AddButton(
|
virtual wxRibbonButtonBarButtonBase* AddButton(
|
||||||
int button_id,
|
int button_id,
|
||||||
const wxString& label,
|
const wxString& label,
|
||||||
@@ -82,6 +88,7 @@ public:
|
|||||||
virtual void ClearButtons();
|
virtual void ClearButtons();
|
||||||
virtual bool DeleteButton(int button_id);
|
virtual bool DeleteButton(int button_id);
|
||||||
virtual void EnableButton(int button_id, bool enable = true);
|
virtual void EnableButton(int button_id, bool enable = true);
|
||||||
|
virtual void ToggleButton(int button_id, bool checked);
|
||||||
|
|
||||||
virtual void SetArtProvider(wxRibbonArtProvider* art);
|
virtual void SetArtProvider(wxRibbonArtProvider* art);
|
||||||
virtual bool IsSizingContinuous() const;
|
virtual bool IsSizingContinuous() const;
|
||||||
|
@@ -174,6 +174,12 @@ enum wxRibbonButtonKind
|
|||||||
menu, and one which causes a generic action.
|
menu, and one which causes a generic action.
|
||||||
*/
|
*/
|
||||||
wxRIBBON_BUTTON_HYBRID = wxRIBBON_BUTTON_NORMAL | wxRIBBON_BUTTON_DROPDOWN,
|
wxRIBBON_BUTTON_HYBRID = wxRIBBON_BUTTON_NORMAL | wxRIBBON_BUTTON_DROPDOWN,
|
||||||
|
|
||||||
|
/**
|
||||||
|
Normal button or tool with a clickable area which toggles the button
|
||||||
|
between a pressed and unpressed state.
|
||||||
|
*/
|
||||||
|
wxRIBBON_BUTTON_TOGGLE = 1 << 2
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -78,10 +78,15 @@ enum wxRibbonButtonBarButtonState
|
|||||||
*/
|
*/
|
||||||
wxRIBBON_BUTTONBAR_BUTTON_DISABLED = 1 << 7,
|
wxRIBBON_BUTTONBAR_BUTTON_DISABLED = 1 << 7,
|
||||||
|
|
||||||
|
/**
|
||||||
|
The button is a toggle button which is currently in the toggled state.
|
||||||
|
*/
|
||||||
|
wxRIBBON_BUTTONBAR_BUTTON_TOGGLED = 1 << 8,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A mask to extract button state from a combination of flags.
|
A mask to extract button state from a combination of flags.
|
||||||
*/
|
*/
|
||||||
wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0xF8,
|
wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0x1F8,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,6 +195,17 @@ public:
|
|||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxString& help_string = wxEmptyString);
|
const wxString& help_string = wxEmptyString);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Add a toggle button to the button bar (simple version).
|
||||||
|
|
||||||
|
@see AddButton()
|
||||||
|
*/
|
||||||
|
virtual wxRibbonButtonBarButtonBase* AddToggleButton(
|
||||||
|
int button_id,
|
||||||
|
const wxString& label,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxString& help_string = wxEmptyString);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add a button to the button bar.
|
Add a button to the button bar.
|
||||||
|
|
||||||
@@ -223,6 +239,7 @@ public:
|
|||||||
|
|
||||||
@see AddDropdownButton()
|
@see AddDropdownButton()
|
||||||
@see AddHybridButton()
|
@see AddHybridButton()
|
||||||
|
@see AddToggleButton()
|
||||||
*/
|
*/
|
||||||
virtual wxRibbonButtonBarButtonBase* AddButton(
|
virtual wxRibbonButtonBarButtonBase* AddButton(
|
||||||
int button_id,
|
int button_id,
|
||||||
@@ -267,13 +284,25 @@ public:
|
|||||||
@true to enable the button, @false to disable it.
|
@true to enable the button, @false to disable it.
|
||||||
*/
|
*/
|
||||||
virtual void EnableButton(int button_id, bool enable = true);
|
virtual void EnableButton(int button_id, bool enable = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set a toggle button to the checked or unchecked state.
|
||||||
|
|
||||||
|
@param button_id
|
||||||
|
ID of the toggle button to manipulate.
|
||||||
|
@param checked
|
||||||
|
@true to set the button to the toggled/pressed/checked state,
|
||||||
|
@false to set it to the untoggled/unpressed/unchecked state.
|
||||||
|
*/
|
||||||
|
virtual void ToggleButton(int button_id, bool checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class wxRibbonButtonBarEvent
|
@class wxRibbonButtonBarEvent
|
||||||
|
|
||||||
Event used to indicate various actions relating to a button on a
|
Event used to indicate various actions relating to a button on a
|
||||||
wxRibbonButtonBar.
|
wxRibbonButtonBar. For toggle buttons, IsChecked() can be used to test
|
||||||
|
the state of the button.
|
||||||
|
|
||||||
See wxRibbonButtonBar for available event types.
|
See wxRibbonButtonBar for available event types.
|
||||||
|
|
||||||
|
@@ -959,6 +959,13 @@ void wxRibbonAUIArtProvider::DrawButtonBarButton(
|
|||||||
const wxBitmap& bitmap_large,
|
const wxBitmap& bitmap_large,
|
||||||
const wxBitmap& bitmap_small)
|
const wxBitmap& bitmap_small)
|
||||||
{
|
{
|
||||||
|
if(kind == wxRIBBON_BUTTON_TOGGLE)
|
||||||
|
{
|
||||||
|
kind = wxRIBBON_BUTTON_NORMAL;
|
||||||
|
if(state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED)
|
||||||
|
state ^= wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
|
if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
|
||||||
| wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
|
| wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
|
||||||
{
|
{
|
||||||
|
@@ -2021,6 +2021,13 @@ void wxRibbonMSWArtProvider::DrawButtonBarButton(
|
|||||||
const wxBitmap& bitmap_large,
|
const wxBitmap& bitmap_large,
|
||||||
const wxBitmap& bitmap_small)
|
const wxBitmap& bitmap_small)
|
||||||
{
|
{
|
||||||
|
if(kind == wxRIBBON_BUTTON_TOGGLE)
|
||||||
|
{
|
||||||
|
kind = wxRIBBON_BUTTON_NORMAL;
|
||||||
|
if(state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED)
|
||||||
|
state ^= wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK |
|
if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK |
|
||||||
wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
|
wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
|
||||||
{
|
{
|
||||||
@@ -2627,6 +2634,7 @@ bool wxRibbonMSWArtProvider::GetButtonBarButtonSize(
|
|||||||
switch(kind)
|
switch(kind)
|
||||||
{
|
{
|
||||||
case wxRIBBON_BUTTON_NORMAL:
|
case wxRIBBON_BUTTON_NORMAL:
|
||||||
|
case wxRIBBON_BUTTON_TOGGLE:
|
||||||
*normal_region = wxRect(*button_size);
|
*normal_region = wxRect(*button_size);
|
||||||
*dropdown_region = wxRect(0, 0, 0, 0);
|
*dropdown_region = wxRect(0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
@@ -2660,6 +2668,7 @@ bool wxRibbonMSWArtProvider::GetButtonBarButtonSize(
|
|||||||
dropdown_region->SetX(dropdown_region->GetX() + text_size);
|
dropdown_region->SetX(dropdown_region->GetX() + text_size);
|
||||||
// no break
|
// no break
|
||||||
case wxRIBBON_BUTTON_NORMAL:
|
case wxRIBBON_BUTTON_NORMAL:
|
||||||
|
case wxRIBBON_BUTTON_TOGGLE:
|
||||||
normal_region->SetWidth(normal_region->GetWidth() + text_size);
|
normal_region->SetWidth(normal_region->GetWidth() + text_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2674,7 +2683,7 @@ bool wxRibbonMSWArtProvider::GetButtonBarButtonSize(
|
|||||||
wxCoord best_width;
|
wxCoord best_width;
|
||||||
dc.GetTextExtent(label, &best_width, &label_height);
|
dc.GetTextExtent(label, &best_width, &label_height);
|
||||||
int last_line_extra_width = 0;
|
int last_line_extra_width = 0;
|
||||||
if(kind != wxRIBBON_BUTTON_NORMAL)
|
if(kind != wxRIBBON_BUTTON_NORMAL && kind != wxRIBBON_BUTTON_TOGGLE)
|
||||||
{
|
{
|
||||||
last_line_extra_width += 8;
|
last_line_extra_width += 8;
|
||||||
}
|
}
|
||||||
@@ -2711,6 +2720,7 @@ bool wxRibbonMSWArtProvider::GetButtonBarButtonSize(
|
|||||||
dropdown_region->height = icon_size.GetHeight() - normal_region->height;
|
dropdown_region->height = icon_size.GetHeight() - normal_region->height;
|
||||||
break;
|
break;
|
||||||
case wxRIBBON_BUTTON_NORMAL:
|
case wxRIBBON_BUTTON_NORMAL:
|
||||||
|
case wxRIBBON_BUTTON_TOGGLE:
|
||||||
*normal_region = wxRect(icon_size);
|
*normal_region = wxRect(icon_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -249,6 +249,16 @@ wxRibbonButtonBarButtonBase* wxRibbonButtonBar::AddDropdownButton(
|
|||||||
wxRIBBON_BUTTON_DROPDOWN);
|
wxRIBBON_BUTTON_DROPDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxRibbonButtonBarButtonBase* wxRibbonButtonBar::AddToggleButton(
|
||||||
|
int button_id,
|
||||||
|
const wxString& label,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
const wxString& help_string)
|
||||||
|
{
|
||||||
|
return AddButton(button_id, label, bitmap, help_string,
|
||||||
|
wxRIBBON_BUTTON_TOGGLE);
|
||||||
|
}
|
||||||
|
|
||||||
wxRibbonButtonBarButtonBase* wxRibbonButtonBar::AddHybridButton(
|
wxRibbonButtonBarButtonBase* wxRibbonButtonBar::AddHybridButton(
|
||||||
int button_id,
|
int button_id,
|
||||||
const wxString& label,
|
const wxString& label,
|
||||||
@@ -445,6 +455,36 @@ void wxRibbonButtonBar::EnableButton(int button_id, bool enable)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxRibbonButtonBar::ToggleButton(int button_id, bool checked)
|
||||||
|
{
|
||||||
|
size_t count = m_buttons.GetCount();
|
||||||
|
size_t i;
|
||||||
|
for(i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
wxRibbonButtonBarButtonBase* button = m_buttons.Item(i);
|
||||||
|
if(button->id == button_id)
|
||||||
|
{
|
||||||
|
if(checked)
|
||||||
|
{
|
||||||
|
if((button->state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED) == 0)
|
||||||
|
{
|
||||||
|
button->state |= wxRIBBON_BUTTONBAR_BUTTON_TOGGLED;
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(button->state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED)
|
||||||
|
{
|
||||||
|
button->state &= ~wxRIBBON_BUTTONBAR_BUTTON_TOGGLED;
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxRibbonButtonBar::SetArtProvider(wxRibbonArtProvider* art)
|
void wxRibbonButtonBar::SetArtProvider(wxRibbonArtProvider* art)
|
||||||
{
|
{
|
||||||
if(art == m_art)
|
if(art == m_art)
|
||||||
@@ -936,6 +976,13 @@ void wxRibbonButtonBar::OnMouseUp(wxMouseEvent& evt)
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
wxRibbonButtonBarEvent notification(event_type, id);
|
wxRibbonButtonBarEvent notification(event_type, id);
|
||||||
|
if(m_active_button->base->kind == wxRIBBON_BUTTON_TOGGLE)
|
||||||
|
{
|
||||||
|
m_active_button->base->state ^=
|
||||||
|
wxRIBBON_BUTTONBAR_BUTTON_TOGGLED;
|
||||||
|
notification.SetInt(m_active_button->base->state &
|
||||||
|
wxRIBBON_BUTTONBAR_BUTTON_TOGGLED);
|
||||||
|
}
|
||||||
notification.SetEventObject(this);
|
notification.SetEventObject(this);
|
||||||
notification.SetBar(this);
|
notification.SetBar(this);
|
||||||
m_lock_active_state = true;
|
m_lock_active_state = true;
|
||||||
|
Reference in New Issue
Block a user