WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray)
-wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, wxAuiToolBarEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, wxAuiToolBarEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, wxAuiToolBarEvent );
+wxDEFINE_EVENT( wxEVT_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEvent );
+wxDEFINE_EVENT( wxEVT_AUITOOLBAR_OVERFLOW_CLICK, wxAuiToolBarEvent );
+wxDEFINE_EVENT( wxEVT_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEvent );
+wxDEFINE_EVENT( wxEVT_AUITOOLBAR_MIDDLE_CLICK, wxAuiToolBarEvent );
+wxDEFINE_EVENT( wxEVT_AUITOOLBAR_BEGIN_DRAG, wxAuiToolBarEvent );
IMPLEMENT_CLASS(wxAuiToolBar, wxControl)
bool ProcessEvent(wxEvent& evt)
{
- if (evt.GetEventType() == wxEVT_COMMAND_MENU_SELECTED)
+ if (evt.GetEventType() == wxEVT_MENU)
{
m_lastId = evt.GetId();
return true;
dc.GradientFillLinear(rect, startColour, endColour, wxSOUTH);
}
+void wxAuiDefaultToolBarArt::DrawPlainBackground(wxDC& dc,
+ wxWindow* WXUNUSED(wnd),
+ const wxRect& _rect)
+{
+ wxRect rect = _rect;
+ rect.height++;
+
+ dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
+
+ dc.DrawRectangle(rect.GetX() - 1, rect.GetY() - 1,
+ rect.GetWidth() + 2, rect.GetHeight() + 1);
+}
+
void wxAuiDefaultToolBarArt::DrawLabel(
wxDC& dc,
wxWindow* WXUNUSED(wnd),
}
else if (item.GetState() & wxAUI_BUTTON_STATE_CHECKED)
{
- // it's important to put this code in an else statment after the
+ // it's important to put this code in an else statement after the
// hover, otherwise hovers won't draw properly for checked items
dc.SetPen(wxPen(m_highlightColour));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(170)));
}
void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC& dc,
- wxWindow* wnd,
+ wxWindow* /*wnd*/,
const wxRect& rect,
int state)
{
if (state & wxAUI_BUTTON_STATE_HOVER ||
state & wxAUI_BUTTON_STATE_PRESSED)
{
- wxRect cli_rect = wnd->GetClientRect();
wxColor light_gray_bg = m_highlightColour.ChangeLightness(170);
if (m_flags & wxAUI_TB_VERTICAL)
EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor)
END_EVENT_TABLE()
-
-wxAuiToolBar::wxAuiToolBar(wxWindow* parent,
- wxWindowID id,
- const wxPoint& position,
- const wxSize& size,
- long style)
- : wxControl(parent,
- id,
- position,
- size,
- style | wxBORDER_NONE)
+void wxAuiToolBar::Init()
{
m_sizer = new wxBoxSizer(wxHORIZONTAL);
m_buttonWidth = -1;
m_buttonHeight = -1;
m_sizerElementCount = 0;
- m_actionPos = wxPoint(-1,-1);
+ m_actionPos = wxDefaultPosition;
m_actionItem = NULL;
m_tipItem = NULL;
m_art = new wxAuiDefaultToolBarArt;
m_gripperSizerItem = NULL;
m_overflowSizerItem = NULL;
m_dragging = false;
+ m_gripperVisible = false;
+ m_overflowVisible = false;
+ m_overflowState = 0;
+ m_orientation = wxHORIZONTAL;
+}
+
+bool wxAuiToolBar::Create(wxWindow* parent,
+ wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style)
+{
+ style = style|wxBORDER_NONE;
+
+ if (!wxControl::Create(parent, id, pos, size, style))
+ return false;
+
+ m_windowStyle = style;
+
+ m_gripperVisible = (style & wxAUI_TB_GRIPPER) ? true : false;
+ m_overflowVisible = (style & wxAUI_TB_OVERFLOW) ? true : false;
+
m_orientation = GetOrientation(style);
if (m_orientation == wxBOTH)
{
m_orientation = wxHORIZONTAL;
}
- m_style = style | wxBORDER_NONE;
- m_gripperVisible = (m_style & wxAUI_TB_GRIPPER) ? true : false;
- m_overflowVisible = (m_style & wxAUI_TB_OVERFLOW) ? true : false;
- m_overflowState = 0;
+
SetMargins(5, 5, 2, 2);
SetFont(*wxNORMAL_FONT);
SetArtFlags();
if (style & wxAUI_TB_HORZ_LAYOUT)
SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT);
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
-}
+ return true;
+}
wxAuiToolBar::~wxAuiToolBar()
{
wxControl::SetWindowStyleFlag(style);
- m_style = style;
+ m_windowStyle = style;
if (m_art)
{
SetArtFlags();
}
- if (m_style & wxAUI_TB_GRIPPER)
+ if (m_windowStyle & wxAUI_TB_GRIPPER)
m_gripperVisible = true;
else
m_gripperVisible = false;
- if (m_style & wxAUI_TB_OVERFLOW)
+ if (m_windowStyle & wxAUI_TB_OVERFLOW)
m_overflowVisible = true;
else
m_overflowVisible = false;
SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM);
}
-long wxAuiToolBar::GetWindowStyleFlag() const
-{
- return m_style;
-}
-
void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt* art)
{
delete m_art;
if (!item)
return;
- item->m_dropDown = dropdown;
+ item->SetHasDropDown(dropdown);
}
bool wxAuiToolBar::GetToolDropDown(int tool_id) const
{
wxAuiToolBarItem* item = FindTool(tool_id);
if (!item)
- return 0;
+ return false;
- return item->m_dropDown;
+ return item->HasDropDown();
}
void wxAuiToolBar::SetToolSticky(int tool_id, bool sticky)
{
m_gripperVisible = visible;
if (visible)
- m_style |= wxAUI_TB_GRIPPER;
+ m_windowStyle |= wxAUI_TB_GRIPPER;
else
- m_style &= ~wxAUI_TB_GRIPPER;
+ m_windowStyle &= ~wxAUI_TB_GRIPPER;
Realize();
Refresh(false);
}
{
m_overflowVisible = visible;
if (visible)
- m_style |= wxAUI_TB_OVERFLOW;
+ m_windowStyle |= wxAUI_TB_OVERFLOW;
else
- m_style &= ~wxAUI_TB_OVERFLOW;
+ m_windowStyle &= ~wxAUI_TB_OVERFLOW;
Refresh(false);
}
void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem* pitem)
{
+ if (pitem && (pitem->m_state & wxAUI_BUTTON_STATE_DISABLED))
+ pitem = NULL;
+
wxAuiToolBarItem* former_hover = NULL;
size_t i, count;
case wxAUI_DOCK_LEFT:
return m_vertHintSize;
default:
- wxCHECK_MSG(false, wxDefaultSize, "invalid dock location value");
+ wxFAIL_MSG("invalid dock location value");
}
+ return wxDefaultSize;
}
bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo& pane) const
{
- return IsPaneValid(m_style, pane);
+ return IsPaneValid(m_windowStyle, pane);
}
bool wxAuiToolBar::IsPaneValid(long style, const wxAuiPaneInfo& pane)
void wxAuiToolBar::SetArtFlags() const
{
- unsigned int artflags = m_style & ~wxAUI_ORIENTATION_MASK;
+ unsigned int artflags = m_windowStyle & ~wxAUI_ORIENTATION_MASK;
if (m_orientation == wxVERTICAL)
{
artflags |= wxAUI_TB_VERTICAL;
vert_sizer->AddStretchSpacer(1);
ctrl_m_sizerItem = vert_sizer->Add(item.m_window, 0, wxEXPAND);
vert_sizer->AddStretchSpacer(1);
- if ( (m_style & wxAUI_TB_TEXT) &&
+ if ( (m_windowStyle & wxAUI_TB_TEXT) &&
m_toolTextOrientation == wxAUI_TBTOOL_TEXT_BOTTOM &&
!item.GetLabel().empty() )
{
// add drop down area
m_overflowSizerItem = NULL;
- if (m_style & wxAUI_TB_OVERFLOW)
+ if (m_windowStyle & wxAUI_TB_OVERFLOW)
{
int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
if (overflow_size > 0 && m_overflowVisible)
m_minWidth = size.x;
m_minHeight = size.y;
- if ((m_style & wxAUI_TB_NO_AUTORESIZE) == 0)
+ if ((m_windowStyle & wxAUI_TB_NO_AUTORESIZE) == 0)
{
wxSize curSize = GetClientSize();
wxSize new_size = GetMinSize();
{
bool is_enabled;
if (item.m_window)
- is_enabled = item.m_window->IsEnabled();
+ is_enabled = item.m_window->IsThisEnabled();
else
is_enabled = (item.m_state & wxAUI_BUTTON_STATE_DISABLED) ? false : true;
// pane state member is public, so it might have been changed
// without going through wxPaneInfo::SetFlag() check
bool ok = pane.IsOk();
- wxCHECK2_MSG(!ok || IsPaneValid(m_style, pane), ok = false,
+ wxCHECK2_MSG(!ok || IsPaneValid(m_windowStyle, pane), ok = false,
"window settings and pane settings are incompatible");
if (ok)
{
}
}
else if (pane.IsResizable() &&
- GetOrientation(m_style) == wxBOTH)
+ GetOrientation(m_windowStyle) == wxBOTH)
{
// changing orientation in OnSize causes havoc
int x, y;
}
}
}
-
- DoIdleUpdate();
evt.Skip();
}
+void wxAuiToolBar::UpdateWindowUI(long flags)
+{
+ if ( flags & wxUPDATE_UI_FROMIDLE )
+ {
+ DoIdleUpdate();
+ }
+
+ wxControl::UpdateWindowUI(flags);
+}
+
void wxAuiToolBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxAutoBufferedPaintDC dc(this);
bool horizontal = m_orientation == wxHORIZONTAL;
-
- m_art->DrawBackground(dc, this, cli_rect);
+ if (m_windowStyle & wxAUI_TB_PLAIN_BACKGROUND)
+ m_art->DrawPlainBackground(dc, this, cli_rect);
+ else
+ m_art->DrawBackground(dc, this, cli_rect);
int gripperSize = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE);
int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
break;
}
- if (item.m_kind == wxITEM_SEPARATOR)
- {
- // draw a separator
- m_art->DrawSeparator(dc, this, item_rect);
- }
- else if (item.m_kind == wxITEM_LABEL)
+ switch ( item.m_kind )
{
- // draw a text label only
- m_art->DrawLabel(dc, this, item, item_rect);
- }
- else if (item.m_kind == wxITEM_NORMAL)
- {
- // draw a regular button or dropdown button
- if (!item.m_dropDown)
- m_art->DrawButton(dc, this, item, item_rect);
- else
- m_art->DrawDropDownButton(dc, this, item, item_rect);
- }
- else if (item.m_kind == wxITEM_CHECK)
- {
- // draw either a regular or dropdown toggle button
- if (!item.m_dropDown)
+ case wxITEM_NORMAL:
+ // draw a regular or dropdown button
+ if (!item.m_dropDown)
+ m_art->DrawButton(dc, this, item, item_rect);
+ else
+ m_art->DrawDropDownButton(dc, this, item, item_rect);
+ break;
+
+ case wxITEM_CHECK:
+ case wxITEM_RADIO:
+ // draw a toggle button
m_art->DrawButton(dc, this, item, item_rect);
- else
- m_art->DrawDropDownButton(dc, this, item, item_rect);
- }
- else if (item.m_kind == wxITEM_RADIO)
- {
- // draw a toggle button
- m_art->DrawButton(dc, this, item, item_rect);
- }
- else if (item.m_kind == wxITEM_CONTROL)
- {
- // draw the control's label
- m_art->DrawControlLabel(dc, this, item, item_rect);
+ break;
+
+ case wxITEM_SEPARATOR:
+ // draw a separator
+ m_art->DrawSeparator(dc, this, item_rect);
+ break;
+
+ case wxITEM_LABEL:
+ // draw a text label only
+ m_art->DrawLabel(dc, this, item, item_rect);
+ break;
+
+ case wxITEM_CONTROL:
+ // draw the control's label
+ m_art->DrawControlLabel(dc, this, item, item_rect);
+ break;
}
// fire a signal to see if the item wants to be custom-rendered
m_overflowVisible &&
overflow_rect.Contains(evt.m_x, evt.m_y))
{
- wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, -1);
+ wxAuiToolBarEvent e(wxEVT_AUITOOLBAR_OVERFLOW_CLICK, -1);
e.SetEventObject(this);
e.SetToolId(-1);
e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY()));
Refresh(false);
if (res != -1)
{
- wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res);
- e.SetEventObject(this);
- GetParent()->GetEventHandler()->ProcessEvent(e);
+ wxCommandEvent event(wxEVT_MENU, res);
+ event.SetEventObject(this);
+ GetParent()->GetEventHandler()->ProcessEvent(event);
}
}
UnsetToolTip();
// fire the tool dropdown event
- wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, m_actionItem->m_toolId);
+ wxAuiToolBarEvent e(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, m_actionItem->m_toolId);
e.SetEventObject(this);
e.SetToolId(m_actionItem->m_toolId);
if(!GetEventHandler()->ProcessEvent(e) || e.GetSkipped())
CaptureMouse();
+ // Ensure hovered item is really ok, as mouse may have moved during
+ // event processing
+ wxPoint cursor_pos_after_evt = ScreenToClient(wxGetMousePosition());
+ SetHoverItem(FindToolByPosition(cursor_pos_after_evt.x, cursor_pos_after_evt.y));
+
DoIdleUpdate();
}
}
SetPressedItem(NULL);
- wxAuiToolBarItem* hitItem = FindToolByPosition(evt.GetX(), evt.GetY());
- if (hitItem && !(hitItem->m_state & wxAUI_BUTTON_STATE_DISABLED))
- {
- SetHoverItem(hitItem);
- }
+ wxAuiToolBarItem* hitItem;
+ hitItem = FindToolByPosition(evt.GetX(), evt.GetY());
+ SetHoverItem(hitItem);
if (m_dragging)
{
{
UnsetToolTip();
- wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_actionItem->m_toolId);
+ wxCommandEvent e(wxEVT_MENU, m_actionItem->m_toolId);
e.SetEventObject(this);
if (hitItem->m_kind == wxITEM_CHECK || hitItem->m_kind == wxITEM_RADIO)
ReleaseMouse();
GetEventHandler()->ProcessEvent(e);
+
+ // Ensure hovered item is really ok, as mouse may have moved during
+ // event processing
+ wxPoint cursor_pos_after_evt = ScreenToClient(wxGetMousePosition());
+ SetHoverItem(FindToolByPosition(cursor_pos_after_evt.x, cursor_pos_after_evt.y));
+
DoIdleUpdate();
}
else
return;
}
- if (m_overflowSizerItem)
+ if (m_overflowSizerItem && m_art)
{
int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
if (dropdown_size > 0 &&
evt.m_x > cli_rect.width - dropdown_size &&
evt.m_y >= 0 &&
- evt.m_y < cli_rect.height &&
- m_art)
+ evt.m_y < cli_rect.height)
{
return;
}
if (m_actionItem && hitItem == m_actionItem)
{
- wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, m_actionItem->m_toolId);
+ wxAuiToolBarEvent e(wxEVT_AUITOOLBAR_RIGHT_CLICK, m_actionItem->m_toolId);
e.SetEventObject(this);
e.SetToolId(m_actionItem->m_toolId);
e.SetClickPoint(m_actionPos);
else
{
// right-clicked on the invalid area of the toolbar
- wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, -1);
+ wxAuiToolBarEvent e(wxEVT_AUITOOLBAR_RIGHT_CLICK, -1);
e.SetEventObject(this);
e.SetToolId(-1);
e.SetClickPoint(m_actionPos);
return;
}
- if (m_overflowSizerItem)
+ if (m_overflowSizerItem && m_art)
{
int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
if (dropdown_size > 0 &&
evt.m_x > cli_rect.width - dropdown_size &&
evt.m_y >= 0 &&
- evt.m_y < cli_rect.height &&
- m_art)
+ evt.m_y < cli_rect.height)
{
return;
}
{
if (hitItem->m_kind == wxITEM_NORMAL)
{
- wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, m_actionItem->m_toolId);
+ wxAuiToolBarEvent e(wxEVT_AUITOOLBAR_MIDDLE_CLICK, m_actionItem->m_toolId);
e.SetEventObject(this);
e.SetToolId(m_actionItem->m_toolId);
e.SetClickPoint(m_actionPos);
{
// TODO: sending this event only makes sense if there is an 'END_DRAG'
// event sent sometime in the future (see OnLeftUp())
- wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId());
+ wxAuiToolBarEvent e(wxEVT_AUITOOLBAR_BEGIN_DRAG, GetId());
e.SetEventObject(this);
e.SetToolId(m_actionItem->m_toolId);
m_dragging = GetEventHandler()->ProcessEvent(e) && !e.GetSkipped();
}
else
{
- if (hitItem && (hitItem->m_state & wxAUI_BUTTON_STATE_DISABLED))
- SetHoverItem(NULL);
- else
- SetHoverItem(hitItem);
+ SetHoverItem(hitItem);
// tooltips handling
wxAuiToolBarItem* packingHitItem;