added wxRendererNative to be used by the generic controls for rendering platfomr-specific parts

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22151 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-07-20 17:52:26 +00:00
parent f509d00d20
commit 9c7f49f569
13 changed files with 1021 additions and 284 deletions

View File

@@ -68,13 +68,10 @@
IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxGenericListCtrl)
#endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
#if defined(__WXGTK__)
#include <gtk/gtk.h>
#include "wx/gtk/win_gtk.h"
#endif
#include "wx/selstore.h"
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// events
// ----------------------------------------------------------------------------
@@ -409,7 +406,6 @@ public:
virtual ~wxListHeaderWindow();
void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
void DrawCurrent();
void AdjustDC(wxDC& dc);
@@ -1657,66 +1653,6 @@ wxListHeaderWindow::~wxListHeaderWindow()
#include "wx/univ/theme.h"
#endif
void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
{
#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
GtkStateType state = m_parent->IsEnabled() ? GTK_STATE_NORMAL
: GTK_STATE_INSENSITIVE;
x = dc->XLOG2DEV( x );
gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window,
state, GTK_SHADOW_OUT,
(GdkRectangle*) NULL, m_wxwindow,
(char *)"button", // const_cast
x-1, y-1, w+2, h+2);
#elif defined(__WXUNIVERSAL__)
wxTheme *theme = wxTheme::Get();
wxRenderer *renderer = theme->GetRenderer();
renderer->DrawBorder( *dc, wxBORDER_RAISED, wxRect(x,y,w,h), 0 );
#elif defined(__WXMAC__)
const int m_corner = 1;
dc->SetBrush( *wxTRANSPARENT_BRUSH );
dc->SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
dc->SetPen( pen );
dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
dc->SetPen( *wxWHITE_PEN );
dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
dc->DrawRectangle( x, y, 1, h ); // left (outer)
dc->DrawLine( x, y+h-1, x+1, y+h-1 );
dc->DrawLine( x+w-1, y, x+w-1, y+1 );
#else // !GTK, !Mac
const int m_corner = 1;
dc->SetBrush( *wxTRANSPARENT_BRUSH );
dc->SetPen( *wxBLACK_PEN );
dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
dc->SetPen( pen );
dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
dc->SetPen( *wxWHITE_PEN );
dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
dc->DrawRectangle( x, y, 1, h ); // left (outer)
dc->DrawLine( x, y+h-1, x+1, y+h-1 );
dc->DrawLine( x+w-1, y, x+w-1, y+1 );
#endif
}
// shift the DC origin to match the position of the main window horz
// scrollbar: this allows us to always use logical coords
void wxListHeaderWindow::AdjustDC(wxDC& dc)
@@ -1733,11 +1669,7 @@ void wxListHeaderWindow::AdjustDC(wxDC& dc)
void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
#if defined(__WXGTK__)
wxClientDC dc( this );
#else
wxPaintDC dc( this );
#endif
PrepareDC( dc );
AdjustDC( dc );
@@ -1772,9 +1704,14 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
// inside the column rect
int cw = wCol - 2;
dc.SetPen( *wxWHITE_PEN );
DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
wxRendererNative::Get().DrawHeaderButton
(
this,
dc,
wxRect(x, HEADER_OFFSET_Y, cw, h - 2),
m_parent->IsEnabled() ? 0
: wxCONTROL_DISABLED
);
// see if we have enough space for the column label

136
src/generic/renderg.cpp Normal file
View File

@@ -0,0 +1,136 @@
///////////////////////////////////////////////////////////////////////////////
// Name: generic/renderg.cpp
// Purpose: generic implementation of wxRendererBase (for any platform)
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/string.h"
#endif //WX_PRECOMP
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererGeneric: our wxRendererBase implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererGeneric : public wxRendererBase
{
public:
// draw the header control button (used by wxListCtrl)
virtual void DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
// draw the expanded/collapsed icon for a tree control item
virtual void DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxRendererGeneric creation
// ----------------------------------------------------------------------------
/* static */
wxRendererNative *wxRendererGeneric::GetGeneric()
{
static wxRendererGeneric s_rendererGeneric;
return s_rendererGeneric;
}
// some platforms have their own renderers
#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
/* static */
wxRendererNative& wxRendererGeneric::Get()
{
return GetGeneric();
}
#endif // platforms using their own renderers
// ----------------------------------------------------------------------------
// wxRendererGeneric drawing functions
// ----------------------------------------------------------------------------
void
wxRendererGeneric::DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
const int m_corner = 1;
dc->SetBrush( *wxTRANSPARENT_BRUSH );
dc->SetPen( *wxBLACK_PEN );
dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
dc->SetPen( pen );
dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
dc->SetPen( *wxWHITE_PEN );
dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
dc->DrawRectangle( x, y, 1, h ); // left (outer)
dc->DrawLine( x, y+h-1, x+1, y+h-1 );
dc->DrawLine( x+w-1, y, x+w-1, y+1 );
}
// draw the plus or minus sign
void
wxRendererGeneric::DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
// white background
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(rect.Deflate(1, 2));
// black lines
const wxCoord xMiddle = rect.x + rect.width/2;
const wxCoord yMiddle = rect.y + rect.height/2;
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle);
if ( !item->IsExpanded() )
{
// turn "-" into "+"
dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3);
}
}

View File

@@ -38,9 +38,7 @@
#include "wx/settings.h"
#include "wx/dcclient.h"
#ifdef __WXMAC__
#include "wx/mac/private.h"
#endif
#include "wx/renderer.h"
// -----------------------------------------------------------------------------
// array types
@@ -58,54 +56,6 @@ static const int NO_IMAGE = -1;
static const int PIXELS_PER_UNIT = 10;
// ----------------------------------------------------------------------------
// Aqua arrows
// ----------------------------------------------------------------------------
/* XPM */
static const char *aqua_arrow_right[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" b ",
" ddb ",
" cccdb ",
" cccccd ",
" ccccccdb ",
" ccccccccd",
" ccccccdb ",
" cccccb ",
" cccdb ",
" ddb ",
" b "
};
/* XPM */
static const char *aqua_arrow_down[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" ",
" ",
" bdcccccccdb ",
" dcccccccd ",
" bcccccccb ",
" dcccccd ",
" bcccccb ",
" bcccd ",
" dcd ",
" bcb ",
" d "
};
// -----------------------------------------------------------------------------
// private classes
// -----------------------------------------------------------------------------
@@ -796,26 +746,11 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
int major,minor;
wxGetOsVersion( &major, &minor );
if (style & wxTR_HAS_BUTTONS) style |= wxTR_MAC_BUTTONS;
if (style & wxTR_HAS_BUTTONS) style &= ~wxTR_HAS_BUTTONS;
style &= ~wxTR_LINES_AT_ROOT;
style |= wxTR_NO_LINES;
if (major < 10)
style |= wxTR_ROW_LINES;
if (major >= 10)
style |= wxTR_AQUA_BUTTONS;
#endif
if (style & wxTR_AQUA_BUTTONS)
{
m_arrowRight = new wxBitmap( aqua_arrow_right );
m_arrowDown = new wxBitmap( aqua_arrow_down );
}
else
{
m_arrowRight = NULL;
m_arrowDown = NULL;
}
#endif // __WXMAC__
wxScrolledWindow::Create( parent, id, pos, size,
style|wxHSCROLL|wxVSCROLL, name );
@@ -847,9 +782,6 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl()
delete m_hilightBrush;
delete m_hilightUnfocusedBrush;
delete m_arrowRight;
delete m_arrowDown;
DeleteAllItems();
delete m_renameTimer;
@@ -2351,101 +2283,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
dc.SetPen(m_dottedPen);
dc.SetTextForeground(*wxBLACK);
if (item->HasPlus() && HasButtons()) // should the item show a button?
{
if (!HasFlag(wxTR_NO_LINES))
{
if (x > (signed)m_indent)
dc.DrawLine(x - m_indent, y_mid, x - 5, y_mid);
else if (HasFlag(wxTR_LINES_AT_ROOT))
dc.DrawLine(3, y_mid, x - 5, y_mid);
dc.DrawLine(x + 5, y_mid, x + m_spacing, y_mid);
}
if (m_imageListButtons != NULL)
{
// draw the image button here
int image_h = 0, image_w = 0, image = wxTreeItemIcon_Normal;
if (item->IsExpanded()) image = wxTreeItemIcon_Expanded;
if (item->IsSelected())
image += wxTreeItemIcon_Selected - wxTreeItemIcon_Normal;
m_imageListButtons->GetSize(image, image_w, image_h);
int xx = x - (image_w>>1);
int yy = y_mid - (image_h>>1);
dc.SetClippingRegion(xx, yy, image_w, image_h);
m_imageListButtons->Draw(image, dc, xx, yy,
wxIMAGELIST_DRAW_TRANSPARENT);
dc.DestroyClippingRegion();
}
else if (HasFlag(wxTR_TWIST_BUTTONS))
{
// draw the twisty button here
if (HasFlag(wxTR_AQUA_BUTTONS))
{
// This causes update problems, so disabling for now.
#if 0 // def __WXMAC__
wxMacPortSetter helper(&dc) ;
wxMacWindowClipper clipper(this) ;
wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
int loc_x = x - 5 ;
int loc_y = y_mid - 6 ;
MacWindowToRootWindow( & loc_x , & loc_y ) ;
Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
kThemeAdornmentNone };
DrawThemeButton( &bounds, kThemeDisclosureButton ,
&info , NULL , NULL , NULL , NULL ) ;
#else
if (item->IsExpanded())
dc.DrawBitmap( *m_arrowDown, x-5, y_mid-6, TRUE );
else
dc.DrawBitmap( *m_arrowRight, x-5, y_mid-6, TRUE );
#endif
}
else
{
dc.SetBrush(*m_hilightBrush);
dc.SetPen(*wxBLACK_PEN);
wxPoint button[3];
if (item->IsExpanded())
{
button[0].x = x-5;
button[0].y = y_mid-2;
button[1].x = x+5;
button[1].y = y_mid-2;
button[2].x = x;
button[2].y = y_mid+3;
}
else
{
button[0].y = y_mid-5;
button[0].x = x-2;
button[1].y = y_mid+5;
button[1].x = x-2;
button[2].y = y_mid;
button[2].x = x+3;
}
dc.DrawPolygon(3, button);
dc.SetPen(m_dottedPen);
}
}
else // if (HasFlag(wxTR_HAS_BUTTONS))
{
// draw the plus sign here
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(x-5, y_mid-4, 11, 9);
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(x-2, y_mid, x+3, y_mid);
if (!item->IsExpanded())
dc.DrawLine(x, y_mid-2, x, y_mid+3);
dc.SetPen(m_dottedPen);
}
}
else if (!HasFlag(wxTR_NO_LINES)) // no button; maybe a line?
if ( !HasFlag(wxTR_NO_LINES) )
{
// draw the horizontal line here
int x_start = x;
@@ -2455,6 +2293,46 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
x_start = 3;
dc.DrawLine(x_start, y_mid, x + m_spacing, y_mid);
}
// should the item show a button?
if ( item->HasPlus() && HasButtons() )
{
if ( m_imageListButtons )
{
// draw the image button here
int image_h = 0,
image_w = 0;
int image = item->IsExpanded() ? wxTreeItemIcon_Expanded
: wxTreeItemIcon_Normal;
if ( item->IsSelected() )
image += wxTreeItemIcon_Selected - wxTreeItemIcon_Normal;
m_imageListButtons->GetSize(image, image_w, image_h);
int xx = x - image_w/2;
int yy = y_mid - image_h/2;
wxDCClipper clip(dc, xx, yy, image_w, image_h);
m_imageListButtons->Draw(image, dc, xx, yy,
wxIMAGELIST_DRAW_TRANSPARENT);
}
else // no custom buttons
{
static const int wImage = 10;
static const int hImage = 12;
wxRendererNative::Get().DrawTreeItemButton
(
this,
dc,
wxRect(x - wImage/2,
y_mid - hImage/2,
wImage, hImage),
item->IsExpanded()
? wxCONTROL_EXPANDED
: 0
);
}
}
}
if (item->IsExpanded())

127
src/gtk/renderer.cpp Normal file
View File

@@ -0,0 +1,127 @@
///////////////////////////////////////////////////////////////////////////////
// Name: gtk/renderer.cpp
// Purpose: implementation of wxRendererBase for wxGTK
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif // WX_PRECOMP
#include <gtk/gtk.h>
#include "wx/gtk/win_gtk.h"
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererGTK: our wxRendererBase implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererBase
{
public:
// draw the header control button (used by wxListCtrl)
virtual void DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
#ifdef __WXGTK20__
// draw the expanded/collapsed icon for a tree control item
virtual void DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
#endif // GTK 2.0
};
// ============================================================================
// implementation
// ============================================================================
/* static */
wxRendererNative& wxRendererGTK::Get()
{
static wxRendererGTK s_rendererGTK;
return s_rendererGTK;
}
void
wxRendererGTK::DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
gtk_paint_box
(
win->m_wxwindow->style,
GTK_PIZZA(win->m_wxwindow)->bin_window,
flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
(GdkRectangle*) NULL, m_wxwindow,
(char *)"button", // const_cast
dc.XLOG2DEV(rect.x) - 1, rect.y - 1, rect.width + 2, rect.h + 2
);
}
#ifdef __WXGTK20__
// draw a ">" or "v" button
//
// TODO: isn't there a GTK function to draw it?
void
wxRendererGTK::DrawTreeItemButton(wxDC& dc, const wxRect& rect, int flags)
{
dc.SetBrush(*m_hilightBrush);
dc.SetPen(*wxBLACK_PEN);
wxPoint button[3];
const wxCoord xMiddle = rect.x + rect.width/2;
const wxCoord yMiddle = rect.y + rect.height/2;
if ( flags & wxCONTROL_EXPANDED )
{
button[0].x = rect.GetLeft();
button[0].y = yMiddle - 2;
button[1].x = rect.GetRight();
button[1].y = yMiddle - 2;
button[2].x = xMiddle;
button[2].y = yMiddle + 3;
}
else // collapsed
{
button[0].y = rect.GetBottom();
button[0].x = xMiddle - 2;
button[1].y = rect.GetTop();
button[1].x = xMiddle - 2;
button[2].y = yMiddle;
button[2].x = xMiddle + 3;
}
dc.DrawPolygon(3, button);
}
#endif // GTK 2.0

127
src/gtk1/renderer.cpp Normal file
View File

@@ -0,0 +1,127 @@
///////////////////////////////////////////////////////////////////////////////
// Name: gtk/renderer.cpp
// Purpose: implementation of wxRendererBase for wxGTK
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif // WX_PRECOMP
#include <gtk/gtk.h>
#include "wx/gtk/win_gtk.h"
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererGTK: our wxRendererBase implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererBase
{
public:
// draw the header control button (used by wxListCtrl)
virtual void DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
#ifdef __WXGTK20__
// draw the expanded/collapsed icon for a tree control item
virtual void DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
#endif // GTK 2.0
};
// ============================================================================
// implementation
// ============================================================================
/* static */
wxRendererNative& wxRendererGTK::Get()
{
static wxRendererGTK s_rendererGTK;
return s_rendererGTK;
}
void
wxRendererGTK::DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
gtk_paint_box
(
win->m_wxwindow->style,
GTK_PIZZA(win->m_wxwindow)->bin_window,
flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
(GdkRectangle*) NULL, m_wxwindow,
(char *)"button", // const_cast
dc.XLOG2DEV(rect.x) - 1, rect.y - 1, rect.width + 2, rect.h + 2
);
}
#ifdef __WXGTK20__
// draw a ">" or "v" button
//
// TODO: isn't there a GTK function to draw it?
void
wxRendererGTK::DrawTreeItemButton(wxDC& dc, const wxRect& rect, int flags)
{
dc.SetBrush(*m_hilightBrush);
dc.SetPen(*wxBLACK_PEN);
wxPoint button[3];
const wxCoord xMiddle = rect.x + rect.width/2;
const wxCoord yMiddle = rect.y + rect.height/2;
if ( flags & wxCONTROL_EXPANDED )
{
button[0].x = rect.GetLeft();
button[0].y = yMiddle - 2;
button[1].x = rect.GetRight();
button[1].y = yMiddle - 2;
button[2].x = xMiddle;
button[2].y = yMiddle + 3;
}
else // collapsed
{
button[0].y = rect.GetBottom();
button[0].x = xMiddle - 2;
button[1].y = rect.GetTop();
button[1].x = xMiddle - 2;
button[2].y = yMiddle;
button[2].x = xMiddle + 3;
}
dc.DrawPolygon(3, button);
}
#endif // GTK 2.0

187
src/mac/carbon/renderer.cpp Normal file
View File

@@ -0,0 +1,187 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/renderer.cpp
// Purpose: implementation of wxRendererBase for Mac
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/string.h"
#endif //WX_PRECOMP
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererMac: our wxRendererBase implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererMac : public wxRendererBase
{
public:
// draw the header control button (used by wxListCtrl)
virtual void DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
// draw the expanded/collapsed icon for a tree control item
virtual void DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
private:
// the tree buttons
wxBitmap m_bmpTreeExpanded,
m_bmpTreeCollapsed;
};
// ----------------------------------------------------------------------------
// Aqua arrows
// ----------------------------------------------------------------------------
/* XPM */
static const char *aqua_arrow_right_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" b ",
" ddb ",
" cccdb ",
" cccccd ",
" ccccccdb ",
" ccccccccd",
" ccccccdb ",
" cccccb ",
" cccdb ",
" ddb ",
" b "
};
/* XPM */
static const char *aqua_arrow_down_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" ",
" ",
" bdcccccccdb ",
" dcccccccd ",
" bcccccccb ",
" dcccccd ",
" bcccccb ",
" bcccd ",
" dcd ",
" bcb ",
" d "
};
// ============================================================================
// implementation
// ============================================================================
/* static */
wxRendererNative& wxRendererMac::Get()
{
static wxRendererMac s_rendererMac;
return s_rendererMac;
}
void
wxRendererMac::DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int WXUNUSED(flags))
{
const int CORNER = 1;
const wxCoord x = rect.x,
y = rect.y,
w = rect.width,
h = rect.height;
dc.SetBrush( *wxTRANSPARENT_BRUSH );
dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
dc.SetPen( pen );
dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
dc.SetPen( *wxWHITE_PEN );
dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
dc.DrawRectangle( x, y, 1, h ); // left (outer)
dc.DrawLine( x, y+h-1, x+1, y+h-1 );
dc.DrawLine( x+w-1, y, x+w-1, y+1 );
}
void
wxRendererMac::DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
// init the buttons on demand
if ( !m_bmpTreeExpanded.Ok() )
{
m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
}
// draw them
// VZ: this is the old code from treectlg.cpp which apparently doesn't work
// but I kept it here just in case it is needed -- if not, please
// remove it
#if 0 // def __WXMAC__
wxMacPortSetter helper(&dc) ;
wxMacWindowClipper clipper(this) ;
wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
int loc_x = x - 5 ;
int loc_y = y_mid - 6 ;
MacWindowToRootWindow( & loc_x , & loc_y ) ;
Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
kThemeAdornmentNone };
DrawThemeButton( &bounds, kThemeDisclosureButton ,
&info , NULL , NULL , NULL , NULL ) ;
#else // 1
dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
: m_bmpTreeCollapsed,
rect.x, rect.y, true /* use mask */);
#endif // 0/1
}

187
src/mac/renderer.cpp Normal file
View File

@@ -0,0 +1,187 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/renderer.cpp
// Purpose: implementation of wxRendererBase for Mac
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/string.h"
#endif //WX_PRECOMP
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererMac: our wxRendererBase implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererMac : public wxRendererBase
{
public:
// draw the header control button (used by wxListCtrl)
virtual void DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
// draw the expanded/collapsed icon for a tree control item
virtual void DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0);
private:
// the tree buttons
wxBitmap m_bmpTreeExpanded,
m_bmpTreeCollapsed;
};
// ----------------------------------------------------------------------------
// Aqua arrows
// ----------------------------------------------------------------------------
/* XPM */
static const char *aqua_arrow_right_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" b ",
" ddb ",
" cccdb ",
" cccccd ",
" ccccccdb ",
" ccccccccd",
" ccccccdb ",
" cccccb ",
" cccdb ",
" ddb ",
" b "
};
/* XPM */
static const char *aqua_arrow_down_xpm[] = {
/* columns rows colors chars-per-pixel */
"13 11 4 1",
" c None",
"b c #C0C0C0",
"c c #707070",
"d c #A0A0A0",
/* pixels */
" ",
" ",
" bdcccccccdb ",
" dcccccccd ",
" bcccccccb ",
" dcccccd ",
" bcccccb ",
" bcccd ",
" dcd ",
" bcb ",
" d "
};
// ============================================================================
// implementation
// ============================================================================
/* static */
wxRendererNative& wxRendererMac::Get()
{
static wxRendererMac s_rendererMac;
return s_rendererMac;
}
void
wxRendererMac::DrawHeaderButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int WXUNUSED(flags))
{
const int CORNER = 1;
const wxCoord x = rect.x,
y = rect.y,
w = rect.width,
h = rect.height;
dc.SetBrush( *wxTRANSPARENT_BRUSH );
dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
dc.SetPen( pen );
dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
dc.SetPen( *wxWHITE_PEN );
dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
dc.DrawRectangle( x, y, 1, h ); // left (outer)
dc.DrawLine( x, y+h-1, x+1, y+h-1 );
dc.DrawLine( x+w-1, y, x+w-1, y+1 );
}
void
wxRendererMac::DrawTreeItemButton(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
// init the buttons on demand
if ( !m_bmpTreeExpanded.Ok() )
{
m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
}
// draw them
// VZ: this is the old code from treectlg.cpp which apparently doesn't work
// but I kept it here just in case it is needed -- if not, please
// remove it
#if 0 // def __WXMAC__
wxMacPortSetter helper(&dc) ;
wxMacWindowClipper clipper(this) ;
wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
int loc_x = x - 5 ;
int loc_y = y_mid - 6 ;
MacWindowToRootWindow( & loc_x , & loc_y ) ;
Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
kThemeAdornmentNone };
DrawThemeButton( &bounds, kThemeDisclosureButton ,
&info , NULL , NULL , NULL , NULL ) ;
#else // 1
dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
: m_bmpTreeCollapsed,
rect.x, rect.y, true /* use mask */);
#endif // 0/1
}

52
src/msw/renderer.cpp Normal file
View File

@@ -0,0 +1,52 @@
///////////////////////////////////////////////////////////////////////////////
// Name: msw/renderer.cpp
// Purpose: implementation of wxRendererBase for Windows
// Author: Vadim Zeitlin
// Modified by:
// Created: 20.07.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/string.h"
#endif //WX_PRECOMP
#include "wx/renderer.h"
// ----------------------------------------------------------------------------
// wxRendererMSW: our wxRendererBase implementation
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererBase
{
};
// ============================================================================
// implementation
// ============================================================================
/* static */
wxRendererNative& wxRendererMSW::Get()
{
static wxRendererMSW s_rendererMSW;
return s_rendererMSW;
}