📄 odcombo.cpp
字号:
butHeight -= btnBorder*2;
// Adjust button height
if ( m_btnHei < 0 )
butHeight += m_btnHei;
else if ( m_btnHei > 0 )
butHeight = m_btnHei;
// Use size of normal bitmap if...
// It is larger
// OR
// button width is set to default and blank button bg is not drawn
if ( m_bmpNormal.Ok() )
{
int bmpReqWidth = m_bmpNormal.GetWidth();
int bmpReqHeight = m_bmpNormal.GetHeight();
// If drawing blank button background, we need to add some margin.
if ( m_blankButtonBg )
{
bmpReqWidth += BMP_BUTTON_MARGIN*2;
bmpReqHeight += BMP_BUTTON_MARGIN*2;
}
if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
butWidth = bmpReqWidth;
if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
butHeight = bmpReqHeight;
// Need to fix height?
if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
{
int newY = butHeight+(customBorder*2);
SetClientSize(-1,newY);
sz.y = newY;
}
}
int butAreaWid = butWidth + (m_btnSpacingX*2);
m_btnSize.x = butWidth;
m_btnSize.y = butHeight;
m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
m_btnArea.y = btnBorder;
m_btnArea.width = butAreaWid;
m_btnArea.height = sz.y - (btnBorder*2);
if ( m_bmpNormal.Ok() || m_btnArea.width != butWidth || m_btnArea.height != butHeight )
m_iFlags |= wxPGCC_IFLAG_HAS_NONSTANDARD_BUTTON;
else
m_iFlags &= ~wxPGCC_IFLAG_HAS_NONSTANDARD_BUTTON;
m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder;
m_tcArea.y = customBorder;
m_tcArea.width = sz.x - butAreaWid - (customBorder*2);
m_tcArea.height = sz.y - (customBorder*2);
/*
if ( m_text )
{
::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
}
*/
}
void wxPGComboControlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
{
if ( !m_text )
return;
wxSize sz = GetClientSize();
int customBorder = m_widthCustomBorder;
if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
{
// Centre textctrl
int tcSizeY = m_text->GetBestSize().y;
int diff = sz.y - tcSizeY;
int y = textCtrlYAdjust + (diff/2);
if ( y < customBorder )
y = customBorder;
m_text->SetSize( m_tcArea.x + m_widthCustomPaint + m_absIndent + textCtrlXAdjust,
y,
m_tcArea.width - g_comboMargin -
(textCtrlXAdjust + m_widthCustomPaint + m_absIndent),
-1 );
// Make sure textctrl doesn't exceed the bottom custom border
wxSize tsz = m_text->GetSize();
diff = (y + tsz.y) - (sz.y - customBorder);
if ( diff >= 0 )
{
tsz.y = tsz.y - diff - 1;
m_text->SetSize(tsz);
}
}
else
{
m_text->SetSize( m_tcArea.x,
0,
sz.x - m_btnArea.x - m_widthCustomPaint - customBorder,
sz.y );
}
}
wxSize wxPGComboControlBase::DoGetBestSize() const
{
wxSize sizeText(150,0);
if ( m_text )
sizeText = m_text->GetBestSize();
// TODO: Better method to calculate close-to-native control height.
int fhei;
if ( m_font.Ok() )
fhei = (m_font.GetPointSize()*2) + 5;
else if ( wxNORMAL_FONT->Ok() )
fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
else
fhei = sizeText.y + 4;
// Need to force height to accomodate bitmap?
int btnSizeY = m_btnSize.y;
if ( m_bmpNormal.Ok() && fhei < btnSizeY )
fhei = btnSizeY;
// Control height doesn't depend on border
/*
// Add border
int border = m_windowStyle & wxBORDER_MASK;
if ( border == wxSIMPLE_BORDER )
fhei += 2;
else if ( border == wxNO_BORDER )
fhei += (m_widthCustomBorder*2);
else
// Sunken etc.
fhei += 4;
*/
// Final adjustments
#ifdef __WXGTK__
fhei += 1;
#endif
wxSize ret(sizeText.x + g_comboMargin + DEFAULT_DROPBUTTON_WIDTH,
fhei);
CacheBestSize(ret);
return ret;
}
void wxPGComboControlBase::DoMoveWindow(int x, int y, int width, int height)
{
// SetSize is called last in create, so it marks the end of creation
m_iFlags |= wxPGCC_IFLAG_CREATED;
wxControl::DoMoveWindow(x, y, width, height);
}
void wxPGComboControlBase::OnSizeEvent( wxSizeEvent& event )
{
if ( !IsCreated() )
return;
// defined by actual wxComboControls
OnResize();
event.Skip();
}
// ----------------------------------------------------------------------------
// standard operations
// ----------------------------------------------------------------------------
bool wxPGComboControlBase::Enable(bool enable)
{
if ( !wxControl::Enable(enable) )
return false;
if ( m_btn )
m_btn->Enable(enable);
if ( m_text )
m_text->Enable(enable);
return true;
}
bool wxPGComboControlBase::Show(bool show)
{
if ( !wxControl::Show(show) )
return false;
if (m_btn)
m_btn->Show(show);
if (m_text)
m_text->Show(show);
return true;
}
bool wxPGComboControlBase::SetFont ( const wxFont& font )
{
if ( !wxControl::SetFont(font) )
return false;
if (m_text)
m_text->SetFont(font);
return true;
}
#if wxUSE_TOOLTIPS
void wxPGComboControlBase::DoSetToolTip(wxToolTip *tooltip)
{
wxControl::DoSetToolTip(tooltip);
// Set tool tip for button and text box
if ( tooltip )
{
const wxString &tip = tooltip->GetTip();
if ( m_text ) m_text->SetToolTip(tip);
if ( m_btn ) m_btn->SetToolTip(tip);
}
else
{
if ( m_text ) m_text->SetToolTip( (wxToolTip*) NULL );
if ( m_btn ) m_btn->SetToolTip( (wxToolTip*) NULL );
}
}
#endif // wxUSE_TOOLTIPS
// ----------------------------------------------------------------------------
// painting
// ----------------------------------------------------------------------------
// draw focus background on area in a way typical on platform
void wxPGComboControlBase::DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags )
{
wxSize sz = GetClientSize();
bool isEnabled;
bool doDrawFocusRect; // also selected
// For smaller size control (and for disabled background) use less spacing
int focusSpacingX;
int focusSpacingY;
if ( !(flags & wxCONTROL_ISSUBMENU) )
{
// Drawing control
isEnabled = IsEnabled();
doDrawFocusRect = ShouldDrawFocus();
// Windows-style: for smaller size control (and for disabled background) use less spacing
//focusSpacingX = isEnabled ? 2 : 1;
focusSpacingX = 1;
focusSpacingY = sz.y > (GetCharHeight()+500) && isEnabled ? 2 : 1;
}
else
{
// Drawing a list item
isEnabled = true; // they are never disabled
doDrawFocusRect = flags & wxCONTROL_SELECTED ? true : false;
focusSpacingX = 0;
focusSpacingY = 0;
}
// Set the background sub-rectangle for selection, disabled etc
wxRect selRect(rect);
selRect.y += focusSpacingY;
selRect.height -= (focusSpacingY*2);
int wcp = 0;
if ( !(flags & wxCONTROL_ISSUBMENU) )
wcp += m_widthCustomPaint;
selRect.x += wcp + focusSpacingX;
selRect.width -= wcp + (focusSpacingX*2);
wxColour bgCol;
bool doDrawSelRect = true;
if ( isEnabled )
{
// If popup is hidden and this control is focused,
// then draw the focus-indicator (selbgcolor background etc.).
if ( doDrawFocusRect )
{
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
}
else
{
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
bgCol = GetBackgroundColour();
doDrawSelRect = false;
}
}
else
{
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) );
bgCol = GetBackgroundColour();
}
dc.SetBrush( bgCol );
if ( doDrawSelRect )
{
dc.SetPen( bgCol );
dc.DrawRectangle( selRect );
}
}
void wxPGComboControlBase::DrawButton( wxDC& dc, const wxRect& rect, int flags )
{
int drawState = m_btnState;
if ( (m_iFlags & wxPGCC_BUTTON_STAYS_DOWN) &&
IsPopupShown() )
drawState |= wxCONTROL_PRESSED;
wxRect drawRect(rect.x+m_btnSpacingX,
rect.y+((rect.height-m_btnSize.y)/2),
m_btnSize.x,
m_btnSize.y);
// Make sure area is not larger than the control
if ( drawRect.y < rect.y )
drawRect.y = rect.y;
if ( drawRect.height > rect.height )
drawRect.height = rect.height;
bool enabled = IsEnabled();
if ( !enabled )
drawState |= wxCONTROL_DISABLED;
if ( !m_bmpNormal.Ok() )
{
if ( flags & Button_BitmapOnly )
return;
// Need to clear button background even if m_btn is present
if ( flags & Button_PaintBackground )
{
wxColour bgCol;
if ( m_iFlags & wxPGCC_IFLAG_BUTTON_OUTSIDE )
bgCol = GetParent()->GetBackgroundColour();
else
bgCol = GetBackgroundColour();
dc.SetBrush(bgCol);
dc.SetPen(bgCol);
dc.DrawRectangle(rect);
}
// Draw standard button
wxRendererNative::Get().DrawComboBoxDropButton(this,
dc,
drawRect,
drawState);
}
else
{
// Draw bitmap
wxBitmap* pBmp;
if ( !enabled )
pBmp = &m_bmpDisabled;
else if ( m_btnState & wxCONTROL_PRESSED )
pBmp = &m_bmpPressed;
else if ( m_btnState & wxCONTROL_CURRENT )
pBmp = &m_bmpHover;
else
pBmp = &m_bmpNormal;
#if wxCHECK_VERSION(2, 7, 0)
if ( m_blankButtonBg )
{
// If using blank button background, we need to clear its background
// with button face colour instead of colour for rest of the control.
if ( flags & Button_PaintBackground )
{
wxColour bgCol = GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
//wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
dc.SetPen(bgCol);
dc.SetBrush(bgCol);
dc.DrawRectangle(rect);
}
if ( !(flags & Button_BitmapOnly) )
{
wxRendererNative::Get().DrawPushButton(this,
dc,
drawRect,
drawState);
}
}
else
#endif
{
// Need to clear button background even if m_btn is present
// (assume non-button background was cleared just before this call so brushes are good)
if ( flags & Button_PaintBackground )
dc.DrawRectangle(rect);
}
// Draw bitmap centered in drawRect
dc.DrawBitmap(*pBmp,
drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
true);
}
}
void wxPGComboControlBase::RecalcAndRefresh()
{
if ( IsCreated() )
{
wxSizeEvent evt(GetSize(),GetId());
GetEventHandler()->ProcessEvent(evt);
Refresh();
}
}
bool wxPGComboControlBase::OnDrawListItem( wxDC& WXUNUSED(dc),
const wxRect& WXUNUSED(rect),
int WXUNUSED(item),
int WXUNUSED(flags) )
{
return false; // signals caller to make default drawing
}
wxCoord wxPGComboControlBase::OnMeasureListItem( int WXUNUSED(item) )
{
return -1; // signals caller to use default
}
wxCoord wxPGComboControlBase::OnMeasureListItemWidth( int WXUNUSED(item) )
{
return -1; // signals caller to use default
}
// ----------------------------------------------------------------------------
// miscellaneous event handlers
// ----------------------------------------------------------------------------
void wxPGComboControlBase::OnTextCtrlEvent(wxCommandEvent& event)
{
// Change event id and relay it forward
event.SetId(GetId());
event.Skip();
}
// call if cursor is on button area or mouse is captured for the button
bool wxPGComboControlBase::HandleButtonMouseEvent( wxMouseEvent& event,
int flags )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -