📄 gtk.cpp
字号:
else if ( control == wxINP_HANDLER_CHECKLISTBOX )
handler = new wxStdCheckListboxInputHandler(GetDefaultInputHandler());
#endif // wxUSE_CHECKLISTBOX
#if wxUSE_TEXTCTRL
else if ( control == wxINP_HANDLER_TEXTCTRL )
handler = new wxGTKTextCtrlInputHandler(GetDefaultInputHandler());
#endif // wxUSE_TEXTCTRL
#if wxUSE_SLIDER
else if ( control == wxINP_HANDLER_SLIDER )
handler = new wxStdSliderButtonInputHandler(GetDefaultInputHandler());
#endif // wxUSE_SLIDER
#if wxUSE_SPINBTN
else if ( control == wxINP_HANDLER_SPINBTN )
handler = new wxStdSpinButtonInputHandler(GetDefaultInputHandler());
#endif // wxUSE_SPINBTN
#if wxUSE_NOTEBOOK
else if ( control == wxINP_HANDLER_NOTEBOOK )
handler = new wxStdNotebookInputHandler(GetDefaultInputHandler());
#endif // wxUSE_NOTEBOOK
#if wxUSE_TOOLBAR
else if ( control == wxINP_HANDLER_TOOLBAR )
handler = new wxStdToolbarInputHandler(GetDefaultInputHandler());
#endif // wxUSE_TOOLBAR
else if ( control == wxINP_HANDLER_TOPLEVEL )
handler = new wxStdFrameInputHandler(GetDefaultInputHandler());
if(!handler)
handler = GetDefaultInputHandler();
n = m_handlerNames.Add(control);
m_handlers.Insert(handler, n);
}
else // we already have it
{
handler = m_handlers[n];
}
return handler;
}
// ============================================================================
// wxGTKColourScheme
// ============================================================================
wxColour wxGTKColourScheme::GetBackground(wxWindow *win) const
{
wxColour col;
if ( win->UseBgCol() )
{
// use the user specified colour
col = win->GetBackgroundColour();
}
if ( !win->ShouldInheritColours() )
{
// doesn't depend on the state
if ( !col.Ok() )
{
col = Get(WINDOW);
}
}
else
{
int flags = win->GetStateFlags();
// the colour set by the user should be used for the normal state
// and for the states for which we don't have any specific colours
if ( !col.Ok() || (flags != 0) )
{
#if wxUSE_SCROLLBAR
if ( wxDynamicCast(win, wxScrollBar) )
col = Get(SCROLLBAR);
else
#endif //wxUSE_SCROLLBAR
if ( (flags & wxCONTROL_CURRENT) && win->CanBeHighlighted() )
col = Get(CONTROL_CURRENT);
else if ( flags & wxCONTROL_PRESSED )
col = Get(CONTROL_PRESSED);
else
col = Get(CONTROL);
}
}
return col;
}
wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col) const
{
switch ( col )
{
case WINDOW: return *wxWHITE;
case SHADOW_DARK: return *wxBLACK;
case SHADOW_HIGHLIGHT: return *wxWHITE;
case SHADOW_IN: return wxColour(0xd6d6d6);
case SHADOW_OUT: return wxColour(0x969696);
case CONTROL: return wxColour(0xd6d6d6);
case CONTROL_PRESSED: return wxColour(0xc3c3c3);
case CONTROL_CURRENT: return wxColour(0xeaeaea);
case CONTROL_TEXT: return *wxBLACK;
case CONTROL_TEXT_DISABLED:
return wxColour(0x757575);
case CONTROL_TEXT_DISABLED_SHADOW:
return *wxWHITE;
case SCROLLBAR:
case SCROLLBAR_PRESSED: return wxColour(0xc3c3c3);
case HIGHLIGHT: return wxColour(0x9c0000);
case HIGHLIGHT_TEXT: return wxColour(0xffffff);
case GAUGE: return Get(CONTROL_CURRENT);
case TITLEBAR: return wxColour(0xaeaaae);
case TITLEBAR_ACTIVE: return wxColour(0x820300);
case TITLEBAR_TEXT: return wxColour(0xc0c0c0);
case TITLEBAR_ACTIVE_TEXT:
return *wxWHITE;
case DESKTOP: return *wxBLACK;
case MAX:
default:
wxFAIL_MSG(_T("invalid standard colour"));
return *wxBLACK;
}
}
// ============================================================================
// wxGTKRenderer
// ============================================================================
// ----------------------------------------------------------------------------
// construction
// ----------------------------------------------------------------------------
wxGTKRenderer::wxGTKRenderer(const wxColourScheme *scheme)
{
// init data
m_scheme = scheme;
m_sizeScrollbarArrow = wxSize(15, 14);
// init pens
m_penBlack = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_DARK), 0, wxSOLID);
m_penDarkGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_OUT), 0, wxSOLID);
m_penGrey = wxPen(wxSCHEME_COLOUR(scheme, SCROLLBAR), 0, wxSOLID);
m_penLightGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_IN), 0, wxSOLID);
m_penHighlight = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_HIGHLIGHT), 0, wxSOLID);
}
// ----------------------------------------------------------------------------
// border stuff
// ----------------------------------------------------------------------------
void wxGTKRenderer::DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen)
{
// draw
dc.SetPen(pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(*rect);
// adjust the rect
rect->Inflate(-1);
}
void wxGTKRenderer::DrawHalfRect(wxDC& dc, wxRect *rect, const wxPen& pen)
{
// draw the bottom and right sides
dc.SetPen(pen);
dc.DrawLine(rect->GetLeft(), rect->GetBottom(),
rect->GetRight() + 1, rect->GetBottom());
dc.DrawLine(rect->GetRight(), rect->GetTop(),
rect->GetRight(), rect->GetBottom());
// adjust the rect
rect->width--;
rect->height--;
}
void wxGTKRenderer::DrawShadedRect(wxDC& dc, wxRect *rect,
const wxPen& pen1, const wxPen& pen2)
{
// draw the rectangle
dc.SetPen(pen1);
dc.DrawLine(rect->GetLeft(), rect->GetTop(),
rect->GetLeft(), rect->GetBottom());
dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(),
rect->GetRight(), rect->GetTop());
dc.SetPen(pen2);
dc.DrawLine(rect->GetRight(), rect->GetTop(),
rect->GetRight(), rect->GetBottom());
dc.DrawLine(rect->GetLeft(), rect->GetBottom(),
rect->GetRight() + 1, rect->GetBottom());
// adjust the rect
rect->Inflate(-1);
}
void wxGTKRenderer::DrawAntiShadedRectSide(wxDC& dc,
const wxRect& rect,
const wxPen& pen1,
const wxPen& pen2,
wxDirection dir)
{
dc.SetPen(dir == wxLEFT || dir == wxUP ? pen1 : pen2);
switch ( dir )
{
case wxLEFT:
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
rect.GetLeft(), rect.GetBottom() + 1);
break;
case wxUP:
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
rect.GetRight() + 1, rect.GetTop());
break;
case wxRIGHT:
dc.DrawLine(rect.GetRight(), rect.GetTop(),
rect.GetRight(), rect.GetBottom() + 1);
break;
case wxDOWN:
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
rect.GetRight() + 1, rect.GetBottom());
break;
default:
wxFAIL_MSG(_T("unknown rectangle side"));
}
}
void wxGTKRenderer::DrawAntiShadedRect(wxDC& dc, wxRect *rect,
const wxPen& pen1, const wxPen& pen2)
{
// draw the rectangle
dc.SetPen(pen1);
dc.DrawLine(rect->GetLeft(), rect->GetTop(),
rect->GetLeft(), rect->GetBottom() + 1);
dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(),
rect->GetRight() + 1, rect->GetTop());
dc.SetPen(pen2);
dc.DrawLine(rect->GetRight(), rect->GetTop() + 1,
rect->GetRight(), rect->GetBottom());
dc.DrawLine(rect->GetLeft() + 1, rect->GetBottom(),
rect->GetRight() + 1, rect->GetBottom());
// adjust the rect
rect->Inflate(-1);
}
void wxGTKRenderer::DrawRaisedBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penHighlight, m_penBlack);
DrawShadedRect(dc, rect, m_penLightGrey, m_penDarkGrey);
}
void wxGTKRenderer::DrawAntiRaisedBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penHighlight, m_penBlack);
DrawAntiShadedRect(dc, rect, m_penLightGrey, m_penDarkGrey);
}
void wxGTKRenderer::DrawBorder(wxDC& dc,
wxBorder border,
const wxRect& rectTotal,
int WXUNUSED(flags),
wxRect *rectIn)
{
size_t width;
wxRect rect = rectTotal;
switch ( border )
{
case wxBORDER_SUNKEN:
for ( width = 0; width < BORDER_THICKNESS; width++ )
{
DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
}
break;
case wxBORDER_STATIC:
for ( width = 0; width < BORDER_THICKNESS; width++ )
{
DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
}
break;
case wxBORDER_RAISED:
for ( width = 0; width < BORDER_THICKNESS; width++ )
{
DrawRaisedBorder(dc, &rect);
}
break;
case wxBORDER_DOUBLE:
for ( width = 0; width < BORDER_THICKNESS; width++ )
{
DrawShadedRect(dc, &rect, m_penLightGrey, m_penBlack);
DrawShadedRect(dc, &rect, m_penHighlight, m_penDarkGrey);
DrawRect(dc, &rect, m_penLightGrey);
}
break;
case wxBORDER_SIMPLE:
for ( width = 0; width < BORDER_THICKNESS; width++ )
{
DrawRect(dc, &rect, m_penBlack);
}
break;
default:
wxFAIL_MSG(_T("unknown border type"));
// fall through
case wxBORDER_DEFAULT:
case wxBORDER_NONE:
break;
}
if ( rectIn )
*rectIn = rect;
}
wxRect wxGTKRenderer::GetBorderDimensions(wxBorder border) const
{
wxCoord width;
switch ( border )
{
case wxBORDER_RAISED:
case wxBORDER_SUNKEN:
width = 2*BORDER_THICKNESS;
break;
case wxBORDER_SIMPLE:
case wxBORDER_STATIC:
width = BORDER_THICKNESS;
break;
case wxBORDER_DOUBLE:
width = 3*BORDER_THICKNESS;
break;
default:
wxFAIL_MSG(_T("unknown border type"));
// fall through
case wxBORDER_DEFAULT:
case wxBORDER_NONE:
width = 0;
break;
}
wxRect rect;
rect.x =
rect.y =
rect.width =
rect.height = width;
return rect;
}
bool wxGTKRenderer::AreScrollbarsInsideBorder() const
{
// no, the scrollbars are outside the border in GTK+
return false;
}
// ----------------------------------------------------------------------------
// special borders
// ----------------------------------------------------------------------------
void wxGTKRenderer::DrawTextBorder(wxDC& dc,
wxBorder border,
const wxRect& rectOrig,
int flags,
wxRect *rectIn)
{
wxRect rect = rectOrig;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -