wxRIBBON_BUTTON_NORMAL = 1 << 0,
wxRIBBON_BUTTON_DROPDOWN = 1 << 1,
wxRIBBON_BUTTON_HYBRID = wxRIBBON_BUTTON_NORMAL | wxRIBBON_BUTTON_DROPDOWN,
+ wxRIBBON_BUTTON_TOGGLE = 1 << 2
};
enum wxRibbonButtonBarButtonState
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_DISABLED = 1 << 7,
- wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0xF8,
+ wxRIBBON_BUTTONBAR_BUTTON_TOGGLED = 1 << 8,
+ wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0x1F8,
};
enum wxRibbonGalleryButtonState
const wxBitmap& bitmap,
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(
int button_id,
const wxString& label,
virtual void ClearButtons();
virtual bool DeleteButton(int button_id);
virtual void EnableButton(int button_id, bool enable = true);
+ virtual void ToggleButton(int button_id, bool checked);
virtual void SetArtProvider(wxRibbonArtProvider* art);
virtual bool IsSizingContinuous() const;
menu, and one which causes a generic action.
*/
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
};
/**
*/
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.
*/
- wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0xF8,
+ wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0x1F8,
};
/**
const wxBitmap& bitmap,
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.
@see AddDropdownButton()
@see AddHybridButton()
+ @see AddToggleButton()
*/
virtual wxRibbonButtonBarButtonBase* AddButton(
int button_id,
@true to enable the button, @false to disable it.
*/
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
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.
const wxBitmap& bitmap_large,
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
| wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
{
const wxBitmap& bitmap_large,
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 |
wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
{
switch(kind)
{
case wxRIBBON_BUTTON_NORMAL:
+ case wxRIBBON_BUTTON_TOGGLE:
*normal_region = wxRect(*button_size);
*dropdown_region = wxRect(0, 0, 0, 0);
break;
dropdown_region->SetX(dropdown_region->GetX() + text_size);
// no break
case wxRIBBON_BUTTON_NORMAL:
+ case wxRIBBON_BUTTON_TOGGLE:
normal_region->SetWidth(normal_region->GetWidth() + text_size);
break;
}
wxCoord best_width;
dc.GetTextExtent(label, &best_width, &label_height);
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;
}
dropdown_region->height = icon_size.GetHeight() - normal_region->height;
break;
case wxRIBBON_BUTTON_NORMAL:
+ case wxRIBBON_BUTTON_TOGGLE:
*normal_region = wxRect(icon_size);
break;
}
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(
int button_id,
const wxString& label,
}
}
+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)
{
if(art == m_art)
else
break;
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.SetBar(this);
m_lock_active_state = true;