Applied patch [ 681893 ] Combobox in toolbar
This patch adds controls (i.e. combobox) to toolbars. It also changes the toolbar sample so the combobox is actually shown. Otto Wyss git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19243 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -203,7 +203,8 @@ public:
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int flags = 0) = 0;
|
int flags = 0,
|
||||||
|
long style = 0) = 0;
|
||||||
|
|
||||||
// draw a (part of) line in the text control
|
// draw a (part of) line in the text control
|
||||||
virtual void DrawTextLine(wxDC& dc,
|
virtual void DrawTextLine(wxDC& dc,
|
||||||
@@ -621,8 +622,9 @@ public:
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int flags = 0)
|
int flags = 0,
|
||||||
{ m_renderer->DrawToolBarButton(dc, label, bitmap, rect, flags); }
|
long style = 0)
|
||||||
|
{ m_renderer->DrawToolBarButton(dc, label, bitmap, rect, flags, style); }
|
||||||
virtual void DrawTextLine(wxDC& dc,
|
virtual void DrawTextLine(wxDC& dc,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
|
@@ -299,7 +299,7 @@ void MyFrame::RecreateToolbar()
|
|||||||
toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file"));
|
toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file"));
|
||||||
|
|
||||||
// neither the generic nor Motif native toolbars really support this
|
// neither the generic nor Motif native toolbars really support this
|
||||||
#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && !defined(__WXX11__)
|
#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && !defined(__WXX11__) || defined(__WXUNIVERSAL__)
|
||||||
// adding a combo to a vertical toolbar is not very smart
|
// adding a combo to a vertical toolbar is not very smart
|
||||||
if ( m_horzToolbar )
|
if ( m_horzToolbar )
|
||||||
{
|
{
|
||||||
|
@@ -165,7 +165,8 @@ public:
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int flags);
|
int flags = 0,
|
||||||
|
long style = 0);
|
||||||
|
|
||||||
virtual void DrawTextLine(wxDC& dc,
|
virtual void DrawTextLine(wxDC& dc,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
@@ -1632,7 +1633,8 @@ void wxGTKRenderer::DrawToolBarButton(wxDC& dc,
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxRect& rectOrig,
|
const wxRect& rectOrig,
|
||||||
int flags)
|
int flags,
|
||||||
|
long style)
|
||||||
{
|
{
|
||||||
// we don't draw the separators at all
|
// we don't draw the separators at all
|
||||||
if ( !label.empty() || bitmap.Ok() )
|
if ( !label.empty() || bitmap.Ok() )
|
||||||
|
@@ -239,7 +239,8 @@ public:
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int flags);
|
int flags = 0,
|
||||||
|
long style = 0);
|
||||||
virtual void DrawTextLine(wxDC& dc,
|
virtual void DrawTextLine(wxDC& dc,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
@@ -2407,9 +2408,10 @@ void wxWin32Renderer::DrawToolBarButton(wxDC& dc,
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxBitmap& bitmap,
|
const wxBitmap& bitmap,
|
||||||
const wxRect& rectOrig,
|
const wxRect& rectOrig,
|
||||||
int flags)
|
int flags,
|
||||||
|
long style)
|
||||||
{
|
{
|
||||||
if ( !label.empty() || bitmap.Ok() )
|
if (style == wxTOOL_STYLE_BUTTON)
|
||||||
{
|
{
|
||||||
wxRect rect = rectOrig;
|
wxRect rect = rectOrig;
|
||||||
rect.Deflate(BORDER_THICKNESS);
|
rect.Deflate(BORDER_THICKNESS);
|
||||||
@@ -2425,7 +2427,7 @@ void wxWin32Renderer::DrawToolBarButton(wxDC& dc,
|
|||||||
|
|
||||||
dc.DrawLabel(label, bitmap, rect, wxALIGN_CENTRE);
|
dc.DrawLabel(label, bitmap, rect, wxALIGN_CENTRE);
|
||||||
}
|
}
|
||||||
else // a separator
|
else if (style == wxTOOL_STYLE_SEPARATOR)
|
||||||
{
|
{
|
||||||
// leave a small gap aroudn the line, also account for the toolbar
|
// leave a small gap aroudn the line, also account for the toolbar
|
||||||
// border itself
|
// border itself
|
||||||
@@ -2433,6 +2435,7 @@ void wxWin32Renderer::DrawToolBarButton(wxDC& dc,
|
|||||||
rectOrig.y + 2*BORDER_THICKNESS,
|
rectOrig.y + 2*BORDER_THICKNESS,
|
||||||
rectOrig.GetBottom() - BORDER_THICKNESS);
|
rectOrig.GetBottom() - BORDER_THICKNESS);
|
||||||
}
|
}
|
||||||
|
// don't draw wxTOOL_STYLE_CONTROL
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -72,6 +72,24 @@ public:
|
|||||||
// no position yet
|
// no position yet
|
||||||
m_x =
|
m_x =
|
||||||
m_y = -1;
|
m_y = -1;
|
||||||
|
m_width =
|
||||||
|
m_height = 0;
|
||||||
|
|
||||||
|
// not pressed yet
|
||||||
|
m_isInverted = FALSE;
|
||||||
|
|
||||||
|
// mouse not here yet
|
||||||
|
m_underMouse = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxToolBarTool(wxToolBar *tbar, wxControl *control)
|
||||||
|
: wxToolBarToolBase(tbar, control)
|
||||||
|
{
|
||||||
|
// no position yet
|
||||||
|
m_x =
|
||||||
|
m_y = -1;
|
||||||
|
m_width =
|
||||||
|
m_height = 0;
|
||||||
|
|
||||||
// not pressed yet
|
// not pressed yet
|
||||||
m_isInverted = FALSE;
|
m_isInverted = FALSE;
|
||||||
@@ -96,9 +114,11 @@ public:
|
|||||||
bool IsUnderMouse() { return m_underMouse; }
|
bool IsUnderMouse() { return m_underMouse; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// the tool position (the size is known by the toolbar itself)
|
// the tool position (for controls)
|
||||||
int m_x,
|
wxCoord m_x;
|
||||||
m_y;
|
wxCoord m_y;
|
||||||
|
wxCoord m_width;
|
||||||
|
wxCoord m_height;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TRUE if the tool is pressed
|
// TRUE if the tool is pressed
|
||||||
@@ -330,9 +350,7 @@ wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
|||||||
|
|
||||||
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
|
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("Toolbar doesn't support controls yet (TODO)") );
|
return new wxToolBarTool(this, control);
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -357,15 +375,41 @@ wxRect wxToolBar::GetToolRect(wxToolBarToolBase *toolBase) const
|
|||||||
rect.y = tool->m_y - m_yMargin;
|
rect.y = tool->m_y - m_yMargin;
|
||||||
|
|
||||||
if ( IsVertical() )
|
if ( IsVertical() )
|
||||||
|
{
|
||||||
|
if (tool->IsButton())
|
||||||
{
|
{
|
||||||
rect.width = m_defaultWidth;
|
rect.width = m_defaultWidth;
|
||||||
rect.height = tool->IsSeparator() ? m_widthSeparator : m_defaultHeight;
|
rect.height = m_defaultHeight;
|
||||||
|
}
|
||||||
|
else if (tool->IsSeparator())
|
||||||
|
{
|
||||||
|
rect.width = m_defaultWidth;
|
||||||
|
rect.height = m_widthSeparator;
|
||||||
|
}
|
||||||
|
else // control
|
||||||
|
{
|
||||||
|
rect.width = tool->m_width;
|
||||||
|
rect.height = tool->m_height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // horizontal
|
else // horizontal
|
||||||
{
|
{
|
||||||
rect.width = tool->IsSeparator() ? m_widthSeparator : m_defaultWidth;
|
if (tool->IsButton())
|
||||||
|
{
|
||||||
|
rect.width = m_defaultWidth;
|
||||||
rect.height = m_defaultHeight;
|
rect.height = m_defaultHeight;
|
||||||
}
|
}
|
||||||
|
else if (tool->IsSeparator())
|
||||||
|
{
|
||||||
|
rect.width = m_widthSeparator;
|
||||||
|
rect.height = m_defaultHeight;
|
||||||
|
}
|
||||||
|
else // control
|
||||||
|
{
|
||||||
|
rect.width = tool->m_width;
|
||||||
|
rect.height = tool->m_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rect.width += 2*m_xMargin;
|
rect.width += 2*m_xMargin;
|
||||||
rect.height += 2*m_yMargin;
|
rect.height += 2*m_yMargin;
|
||||||
@@ -410,7 +454,25 @@ void wxToolBar::DoLayout()
|
|||||||
tool->m_y = y;
|
tool->m_y = y;
|
||||||
|
|
||||||
// TODO ugly number fiddling
|
// TODO ugly number fiddling
|
||||||
*pCur += ( tool->IsSeparator() ? m_widthSeparator : (widthTool+2) ) + margin;
|
if (tool->IsButton())
|
||||||
|
{
|
||||||
|
*pCur += widthTool;
|
||||||
|
}
|
||||||
|
else if (tool->IsSeparator())
|
||||||
|
{
|
||||||
|
*pCur += m_widthSeparator;
|
||||||
|
}
|
||||||
|
else if (!IsVertical()) // horizontal control
|
||||||
|
{
|
||||||
|
wxControl *control = tool->GetControl();
|
||||||
|
wxSize size = control->GetSize();
|
||||||
|
tool->m_y += (m_defaultHeight - size.y)/2;
|
||||||
|
tool->m_width = size.x;
|
||||||
|
tool->m_height = size.y;
|
||||||
|
|
||||||
|
*pCur += tool->m_width;
|
||||||
|
}
|
||||||
|
*pCur += margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate the total toolbar size
|
// calculate the total toolbar size
|
||||||
@@ -562,7 +624,15 @@ void wxToolBar::DoDraw(wxControlRenderer *renderer)
|
|||||||
}
|
}
|
||||||
//else: leave both the label and the bitmap invalid to draw a separator
|
//else: leave both the label and the bitmap invalid to draw a separator
|
||||||
|
|
||||||
rend->DrawToolBarButton(dc, label, bitmap, rectTool, flags);
|
if ( !tool->IsControl() )
|
||||||
|
{
|
||||||
|
rend->DrawToolBarButton(dc, label, bitmap, rectTool, flags, tool->GetStyle());
|
||||||
|
}
|
||||||
|
else // control
|
||||||
|
{
|
||||||
|
wxControl *control = tool->GetControl();
|
||||||
|
control->Move(tool->m_x, tool->m_y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user