📄 gtk.cpp
字号:
///////////////////////////////////////////////////////////////////////////////
// Name: src/univ/themes/gtk.cpp
// Purpose: wxUniversal theme implementing GTK-like LNF
// Author: Vadim Zeitlin
// Modified by:
// Created: 06.08.00
// RCS-ID: $Id: gtk.cpp,v 1.53 2006/07/03 19:02:48 ABX Exp $
// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ===========================================================================
// declarations
// ===========================================================================
// ---------------------------------------------------------------------------
// headers
// ---------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/dcmemory.h"
#include "wx/window.h"
#include "wx/menu.h"
#include "wx/bmpbuttn.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/listbox.h"
#include "wx/checklst.h"
#include "wx/combobox.h"
#include "wx/scrolbar.h"
#include "wx/slider.h"
#include "wx/textctrl.h"
#include "wx/toolbar.h"
#include "wx/statusbr.h"
#include "wx/settings.h"
#include "wx/toplevel.h"
#include "wx/image.h"
#endif // WX_PRECOMP
#include "wx/notebook.h"
#include "wx/spinbutt.h"
#include "wx/artprov.h"
#ifdef wxUSE_TOGGLEBTN
#include "wx/tglbtn.h"
#endif // wxUSE_TOGGLEBTN
#include "wx/univ/renderer.h"
#include "wx/univ/inphand.h"
#include "wx/univ/colschem.h"
#include "wx/univ/theme.h"
class WXDLLEXPORT wxGTKMenuGeometryInfo;
// ----------------------------------------------------------------------------
// constants (to be removed, for testing only)
// ----------------------------------------------------------------------------
static const size_t BORDER_THICKNESS = 1;
// ----------------------------------------------------------------------------
// wxGTKRenderer: draw the GUI elements in GTK style
// ----------------------------------------------------------------------------
class wxGTKRenderer : public wxRenderer
{
public:
wxGTKRenderer(const wxColourScheme *scheme);
// implement the base class pure virtuals
virtual void DrawBackground(wxDC& dc,
const wxColour& col,
const wxRect& rect,
int flags = 0,
wxWindow *window = NULL );
virtual void DrawLabel(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags = 0,
int alignment = wxALIGN_LEFT | wxALIGN_TOP,
int indexAccel = -1,
wxRect *rectBounds = NULL);
virtual void DrawButtonLabel(wxDC& dc,
const wxString& label,
const wxBitmap& image,
const wxRect& rect,
int flags = 0,
int alignment = wxALIGN_LEFT | wxALIGN_TOP,
int indexAccel = -1,
wxRect *rectBounds = NULL);
virtual void DrawBorder(wxDC& dc,
wxBorder border,
const wxRect& rect,
int flags = 0,
wxRect *rectIn = (wxRect *)NULL);
virtual void DrawHorizontalLine(wxDC& dc,
wxCoord y, wxCoord x1, wxCoord x2);
virtual void DrawVerticalLine(wxDC& dc,
wxCoord x, wxCoord y1, wxCoord y2);
virtual void DrawFrame(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags = 0,
int alignment = wxALIGN_LEFT,
int indexAccel = -1);
virtual void DrawTextBorder(wxDC& dc,
wxBorder border,
const wxRect& rect,
int flags = 0,
wxRect *rectIn = (wxRect *)NULL);
virtual void DrawButtonBorder(wxDC& dc,
const wxRect& rect,
int flags = 0,
wxRect *rectIn = (wxRect *)NULL);
virtual void DrawArrow(wxDC& dc,
wxDirection dir,
const wxRect& rect,
int flags = 0);
virtual void DrawScrollbarArrow(wxDC& dc,
wxDirection dir,
const wxRect& rect,
int flags = 0);
virtual void DrawScrollbarThumb(wxDC& dc,
wxOrientation orient,
const wxRect& rect,
int flags = 0);
virtual void DrawScrollbarShaft(wxDC& dc,
wxOrientation orient,
const wxRect& rect,
int flags = 0);
virtual void DrawScrollCorner(wxDC& dc,
const wxRect& rect);
virtual void DrawItem(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags = 0);
virtual void DrawCheckItem(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags = 0);
virtual void DrawCheckButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags = 0,
wxAlignment align = wxALIGN_LEFT,
int indexAccel = -1);
virtual void DrawRadioButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags = 0,
wxAlignment align = wxALIGN_LEFT,
int indexAccel = -1);
#if wxUSE_TOOLBAR
virtual void DrawToolBarButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags = 0,
long style = 0,
int tbarStyle = 0);
#endif // wxUSE_TOOLBAR
virtual void DrawTextLine(wxDC& dc,
const wxString& text,
const wxRect& rect,
int selStart = -1,
int selEnd = -1,
int flags = 0);
virtual void DrawLineWrapMark(wxDC& dc, const wxRect& rect);
virtual void DrawTab(wxDC& dc,
const wxRect& rect,
wxDirection dir,
const wxString& label,
const wxBitmap& bitmap = wxNullBitmap,
int flags = 0,
int indexAccel = -1);
#if wxUSE_SLIDER
virtual void DrawSliderShaft(wxDC& dc,
const wxRect& rect,
int lenThumb,
wxOrientation orient,
int flags = 0,
long style = 0,
wxRect *rectShaft = NULL);
virtual void DrawSliderThumb(wxDC& dc,
const wxRect& rect,
wxOrientation orient,
int flags = 0,
long style = 0);
virtual void DrawSliderTicks(wxDC& WXUNUSED(dc),
const wxRect& WXUNUSED(rect),
int WXUNUSED(lenThumb),
wxOrientation WXUNUSED(orient),
int WXUNUSED(start),
int WXUNUSED(end),
int WXUNUSED(step) = 1,
int WXUNUSED(flags) = 0,
long WXUNUSED(style) = 0)
{
// we don't have the ticks in GTK version
}
#endif // wxUSE_SLIDER
#if wxUSE_MENUS
virtual void DrawMenuBarItem(wxDC& dc,
const wxRect& rect,
const wxString& label,
int flags = 0,
int indexAccel = -1);
virtual void DrawMenuItem(wxDC& dc,
wxCoord y,
const wxMenuGeometryInfo& geometryInfo,
const wxString& label,
const wxString& accel,
const wxBitmap& bitmap = wxNullBitmap,
int flags = 0,
int indexAccel = -1);
virtual void DrawMenuSeparator(wxDC& dc,
wxCoord y,
const wxMenuGeometryInfo& geomInfo);
#endif // wxUSE_MENUS
#if wxUSE_STATUSBAR
virtual void DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
int flags = 0, int style = 0);
#endif // wxUSE_STATUSBAR
virtual void DrawFrameTitleBar(wxDC& dc,
const wxRect& rect,
const wxString& title,
const wxIcon& icon,
int flags,
int specialButton = 0,
int specialButtonFlag = 0);
virtual void DrawFrameBorder(wxDC& dc,
const wxRect& rect,
int flags);
virtual void DrawFrameBackground(wxDC& dc,
const wxRect& rect,
int flags);
virtual void DrawFrameTitle(wxDC& dc,
const wxRect& rect,
const wxString& title,
int flags);
virtual void DrawFrameIcon(wxDC& dc,
const wxRect& rect,
const wxIcon& icon,
int flags);
virtual void DrawFrameButton(wxDC& dc,
wxCoord x, wxCoord y,
int button,
int flags = 0);
// titlebars
virtual wxRect GetFrameClientArea(const wxRect& rect, int flags) const;
virtual wxSize GetFrameTotalSize(const wxSize& clientSize, int flags) const;
virtual wxSize GetFrameMinSize(int flags) const;
virtual wxSize GetFrameIconSize() const;
virtual int HitTestFrame(const wxRect& rect, const wxPoint& pt, int flags) const;
virtual void GetComboBitmaps(wxBitmap *bmpNormal,
wxBitmap *bmpFocus,
wxBitmap *bmpPressed,
wxBitmap *bmpDisabled);
virtual void AdjustSize(wxSize *size, const wxWindow *window);
virtual wxRect GetBorderDimensions(wxBorder border) const;
virtual bool AreScrollbarsInsideBorder() const;
// geometry and hit testing
virtual wxSize GetScrollbarArrowSize() const
{ return m_sizeScrollbarArrow; }
#if wxUSE_SCROLLBAR
virtual wxRect GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos = -1) const;
virtual wxCoord GetScrollbarSize(const wxScrollBar *scrollbar);
virtual wxHitTest HitTestScrollbar(const wxScrollBar *scrollbar,
const wxPoint& pt) const;
virtual wxCoord ScrollbarToPixel(const wxScrollBar *scrollbar,
int thumbPos = -1);
virtual int PixelToScrollbar(const wxScrollBar *scrollbar, wxCoord coord);
#endif // wxUSE_SCROLLBAR
virtual wxCoord GetListboxItemHeight(wxCoord fontHeight)
{ return fontHeight + 2; }
virtual wxSize GetCheckBitmapSize() const
{ return wxSize(10, 10); }
virtual wxSize GetRadioBitmapSize() const
{ return wxSize(11, 11); }
virtual wxCoord GetCheckItemMargin() const
{ return 2; }
virtual wxSize GetToolBarButtonSize(wxCoord *separator) const
{ if ( separator ) *separator = 5; return wxSize(16, 15); }
virtual wxSize GetToolBarMargin() const
{ return wxSize(6, 6); }
#if wxUSE_TEXTCTRL
virtual wxRect GetTextTotalArea(const wxTextCtrl *text,
const wxRect& rect) const;
virtual wxRect GetTextClientArea(const wxTextCtrl *text,
const wxRect& rect,
wxCoord *extraSpaceBeyond) const;
#endif // wxUSE_TEXTCTRL
virtual wxSize GetTabIndent() const { return wxSize(2, 2); }
virtual wxSize GetTabPadding() const { return wxSize(6, 6); }
#if wxUSE_SLIDER
virtual wxCoord GetSliderDim() const { return 15; }
virtual wxCoord GetSliderTickLen() const { return 0; }
virtual wxRect GetSliderShaftRect(const wxRect& rect,
int lenThumb,
wxOrientation orient,
long style = 0) const;
virtual wxSize GetSliderThumbSize(const wxRect& rect,
int lenThumb,
wxOrientation orient) const;
#endif // wxUSE_SLIDER
virtual wxSize GetProgressBarStep() const { return wxSize(16, 32); }
#if wxUSE_MENUS
virtual wxSize GetMenuBarItemSize(const wxSize& sizeText) const;
virtual wxMenuGeometryInfo *GetMenuGeometry(wxWindow *win,
const wxMenu& menu) const;
#endif // wxUSE_MENUS
#if wxUSE_STATUSBAR
virtual wxSize GetStatusBarBorders(wxCoord *borderBetweenFields) const;
#endif // wxUSE_STATUSBAR
// helpers for "wxBitmap wxColourScheme::Get()"
void DrawCheckBitmap(wxDC& dc, const wxRect& rect);
void DrawUncheckBitmap(wxDC& dc, const wxRect& rect, bool isPressed);
void DrawUndeterminedBitmap(wxDC& dc, const wxRect& rect, bool isPressed);
protected:
// DrawBackground() helpers
// get the colour to use for background
wxColour GetBackgroundColour(int flags) const
{
if ( flags & wxCONTROL_PRESSED )
return wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED);
else if ( flags & wxCONTROL_CURRENT )
return wxSCHEME_COLOUR(m_scheme, CONTROL_CURRENT);
else
return wxSCHEME_COLOUR(m_scheme, CONTROL);
}
// draw the background with any colour, not only the default one(s)
void DoDrawBackground(wxDC& dc,
const wxColour& col,
const wxRect& rect,
wxWindow *window = NULL);
// DrawBorder() helpers: all of them shift and clip the DC after drawing
// the border
// just draw a rectangle with the given pen
void DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen);
// draw the lower left part of rectangle
void DrawHalfRect(wxDC& dc, wxRect *rect, const wxPen& pen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -