Change wxRendererNative to use NSCell-based methods under Mac

Use wxOSX_USE_NSCELL_RENDERER to allow setting it to 0 to revert to the
old code.

Note that the new version is Objective C++, so the old .cpp file had to
be renamed to have .mm extension.

Closes #24053.

Co-Authored-By: Vadim Zeitlin <vadim@wxwidgets.org>
This commit is contained in:
Stefan Csomor 2023-11-12 09:51:59 +01:00 committed by Vadim Zeitlin
parent 1d7f2becd4
commit 21da0e128d
7 changed files with 8899 additions and 8583 deletions

View file

@ -5409,7 +5409,8 @@ COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS = \
monodll_taskbarcmn.o \
monodll_cocoa_activityindicator.o \
monodll_cocoa_statbmp.o \
monodll_core_display.o
monodll_core_display.o \
monodll_cocoa_renderer.o
@COND_TOOLKIT_OSX_COCOA@__GUI_SRC_OBJECTS = $(COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS)
COND_TOOLKIT_OSX_IPHONE___GUI_SRC_OBJECTS = \
$(__OSX_COMMON_SRC_OBJECTS) \
@ -7171,7 +7172,8 @@ COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS_1 = \
monolib_taskbarcmn.o \
monolib_cocoa_activityindicator.o \
monolib_cocoa_statbmp.o \
monolib_core_display.o
monolib_core_display.o \
monolib_cocoa_renderer.o
@COND_TOOLKIT_OSX_COCOA@__GUI_SRC_OBJECTS_1 = $(COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS_1)
COND_TOOLKIT_OSX_IPHONE___GUI_SRC_OBJECTS_1 = \
$(__OSX_COMMON_SRC_OBJECTS_0) \
@ -9085,7 +9087,8 @@ COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS_2 = \
coredll_taskbarcmn.o \
coredll_cocoa_activityindicator.o \
coredll_cocoa_statbmp.o \
coredll_core_display.o
coredll_core_display.o \
coredll_cocoa_renderer.o
@COND_TOOLKIT_OSX_COCOA@__GUI_SRC_OBJECTS_2 = $(COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS_2)
COND_TOOLKIT_OSX_IPHONE___GUI_SRC_OBJECTS_2 = \
$(__OSX_COMMON_SRC_OBJECTS_8) \
@ -10575,7 +10578,8 @@ COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS_3 = \
corelib_taskbarcmn.o \
corelib_cocoa_activityindicator.o \
corelib_cocoa_statbmp.o \
corelib_core_display.o
corelib_core_display.o \
corelib_cocoa_renderer.o
@COND_TOOLKIT_OSX_COCOA@__GUI_SRC_OBJECTS_3 = $(COND_TOOLKIT_OSX_COCOA___GUI_SRC_OBJECTS_3)
COND_TOOLKIT_OSX_IPHONE___GUI_SRC_OBJECTS_3 = \
$(__OSX_COMMON_SRC_OBJECTS_9) \
@ -12251,7 +12255,6 @@ COND_PLATFORM_MACOSX_1___OSX_COMMON_SRC_OBJECTS = \
monodll_carbon_mdi.o \
monodll_carbon_metafile.o \
monodll_carbon_popupwin.o \
monodll_carbon_renderer.o \
monodll_statbrma.o \
monodll_carbon_region.o \
monodll_utilscocoa.o \
@ -12385,7 +12388,6 @@ COND_PLATFORM_MACOSX_1___OSX_COMMON_SRC_OBJECTS_0 = \
monolib_carbon_mdi.o \
monolib_carbon_metafile.o \
monolib_carbon_popupwin.o \
monolib_carbon_renderer.o \
monolib_statbrma.o \
monolib_carbon_region.o \
monolib_utilscocoa.o \
@ -12518,7 +12520,6 @@ COND_PLATFORM_MACOSX_1___OSX_COMMON_SRC_OBJECTS_8 = \
coredll_carbon_mdi.o \
coredll_carbon_metafile.o \
coredll_carbon_popupwin.o \
coredll_carbon_renderer.o \
coredll_statbrma.o \
coredll_carbon_region.o \
coredll_utilscocoa.o \
@ -12651,7 +12652,6 @@ COND_PLATFORM_MACOSX_1___OSX_COMMON_SRC_OBJECTS_9 = \
corelib_carbon_mdi.o \
corelib_carbon_metafile.o \
corelib_carbon_popupwin.o \
corelib_carbon_renderer.o \
corelib_statbrma.o \
corelib_carbon_region.o \
corelib_utilscocoa.o \
@ -15487,6 +15487,9 @@ monodll_cocoa_statbmp.o: $(srcdir)/src/osx/cocoa/statbmp.mm $(MONODLL_ODEP)
monodll_core_display.o: $(srcdir)/src/osx/core/display.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/core/display.cpp
monodll_cocoa_renderer.o: $(srcdir)/src/osx/cocoa/renderer.mm $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/renderer.mm
monodll_regiong.o: $(srcdir)/src/generic/regiong.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/regiong.cpp
@ -18730,12 +18733,6 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monodll_carbon_popupwin.o: $(srcdir)/src/osx/carbon/popupwin.cpp $(MONODLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/carbon/popupwin.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@monodll_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(MONODLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monodll_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(MONODLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@monodll_statbrma.o: $(srcdir)/src/osx/carbon/statbrma.cpp $(MONODLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/osx/carbon/statbrma.cpp
@ -20233,6 +20230,9 @@ monolib_cocoa_statbmp.o: $(srcdir)/src/osx/cocoa/statbmp.mm $(MONOLIB_ODEP)
monolib_core_display.o: $(srcdir)/src/osx/core/display.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/core/display.cpp
monolib_cocoa_renderer.o: $(srcdir)/src/osx/cocoa/renderer.mm $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/renderer.mm
monolib_regiong.o: $(srcdir)/src/generic/regiong.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/regiong.cpp
@ -23476,12 +23476,6 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monolib_carbon_popupwin.o: $(srcdir)/src/osx/carbon/popupwin.cpp $(MONOLIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/carbon/popupwin.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@monolib_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(MONOLIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@monolib_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(MONOLIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@monolib_statbrma.o: $(srcdir)/src/osx/carbon/statbrma.cpp $(MONOLIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/osx/carbon/statbrma.cpp
@ -25657,6 +25651,9 @@ coredll_cocoa_statbmp.o: $(srcdir)/src/osx/cocoa/statbmp.mm $(COREDLL_ODEP)
coredll_core_display.o: $(srcdir)/src/osx/core/display.cpp $(COREDLL_ODEP)
$(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/core/display.cpp
coredll_cocoa_renderer.o: $(srcdir)/src/osx/cocoa/renderer.mm $(COREDLL_ODEP)
$(CXXC) -c -o $@ $(COREDLL_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/renderer.mm
coredll_regiong.o: $(srcdir)/src/generic/regiong.cpp $(COREDLL_ODEP)
$(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/regiong.cpp
@ -28318,12 +28315,6 @@ coredll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(COREDLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@coredll_carbon_popupwin.o: $(srcdir)/src/osx/carbon/popupwin.cpp $(COREDLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/carbon/popupwin.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@coredll_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(COREDLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@coredll_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(COREDLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@coredll_statbrma.o: $(srcdir)/src/osx/carbon/statbrma.cpp $(COREDLL_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/osx/carbon/statbrma.cpp
@ -29377,6 +29368,9 @@ corelib_cocoa_statbmp.o: $(srcdir)/src/osx/cocoa/statbmp.mm $(CORELIB_ODEP)
corelib_core_display.o: $(srcdir)/src/osx/core/display.cpp $(CORELIB_ODEP)
$(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/core/display.cpp
corelib_cocoa_renderer.o: $(srcdir)/src/osx/cocoa/renderer.mm $(CORELIB_ODEP)
$(CXXC) -c -o $@ $(CORELIB_OBJCXXFLAGS) $(srcdir)/src/osx/cocoa/renderer.mm
corelib_regiong.o: $(srcdir)/src/generic/regiong.cpp $(CORELIB_ODEP)
$(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/regiong.cpp
@ -32038,12 +32032,6 @@ corelib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(CORELIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@corelib_carbon_popupwin.o: $(srcdir)/src/osx/carbon/popupwin.cpp $(CORELIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/carbon/popupwin.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@corelib_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(CORELIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@corelib_carbon_renderer.o: $(srcdir)/src/osx/carbon/renderer.cpp $(CORELIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_IPHONE_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/carbon/renderer.cpp
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@corelib_statbrma.o: $(srcdir)/src/osx/carbon/statbrma.cpp $(CORELIB_ODEP)
@COND_PLATFORM_MACOSX_1_TOOLKIT_OSX_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/osx/carbon/statbrma.cpp

View file

@ -2157,7 +2157,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/osx/carbon/mdi.cpp
src/osx/carbon/metafile.cpp
src/osx/carbon/popupwin.cpp
src/osx/carbon/renderer.cpp
src/osx/carbon/statbrma.cpp
src/osx/carbon/region.cpp
<!-- cocoa bridge -->
@ -2338,6 +2337,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/osx/cocoa/activityindicator.mm
src/osx/cocoa/statbmp.mm
src/osx/core/display.cpp
src/osx/cocoa/renderer.mm
</set>
<set var="OSX_COCOA_HDR" hints="files">
wx/osx/cocoa/chkconf.h

View file

@ -2036,7 +2036,6 @@ set(OSX_COMMON_SRC
src/osx/carbon/mdi.cpp
src/osx/carbon/metafile.cpp
src/osx/carbon/popupwin.cpp
src/osx/carbon/renderer.cpp
src/osx/carbon/statbrma.cpp
src/osx/carbon/region.cpp
# cocoa bridge
@ -2212,6 +2211,7 @@ set(OSX_COCOA_SRC
src/osx/core/sound.cpp
src/osx/cocoa/statbmp.mm
src/osx/core/display.cpp
src/osx/cocoa/renderer.mm
)
set(OSX_COCOA_HDR

View file

@ -2022,7 +2022,6 @@ OSX_COMMON_SRC =
src/osx/carbon/mdi.cpp
src/osx/carbon/metafile.cpp
src/osx/carbon/popupwin.cpp
src/osx/carbon/renderer.cpp
src/osx/carbon/statbrma.cpp
src/osx/carbon/region.cpp
# cocoa bridge
@ -2173,6 +2172,7 @@ OSX_COCOA_SRC =
src/osx/cocoa/preferences.mm
src/osx/cocoa/printdlg.mm
src/osx/cocoa/radiobut.mm
src/osx/cocoa/renderer.mm
src/osx/cocoa/scrolbar.mm
src/osx/cocoa/settings.mm
src/osx/cocoa/slider.mm

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
// Name: src/osx/carbon/renderer.cpp
// Purpose: implementation of wxRendererNative for Mac
// Author: Vadim Zeitlin
// Name: src/osx/cocoa/renderer.mm
// Purpose: implementation of wxRendererNative for Cocoa
// Author: Vadim Zeitlin, Stefan Csomor
// Created: 20.07.2003
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
@ -36,6 +36,7 @@
#include "wx/mstream.h"
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
#define wxOSX_USE_NSCELL_RENDERER 1
// check if we're having a CGContext we can draw into
inline bool wxHasCGContext(wxWindow* WXUNUSED(win), wxDC& dc)
@ -55,6 +56,9 @@ inline bool wxHasCGContext(wxWindow* WXUNUSED(win), wxDC& dc)
class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
{
public:
wxRendererMac() = default;
virtual ~wxRendererMac();
// draw the header control button (used by wxListCtrl)
virtual int DrawHeaderButton( wxWindow *win,
wxDC& dc,
@ -144,10 +148,122 @@ private:
int flags,
int kind,
int adornment);
#if wxOSX_USE_NSCELL_RENDERER
void DrawMacCell(wxWindow *win,
wxDC& dc,
NSCell* cell,
const wxRect& rect,
int flags,
NSControlStateValue state);
void DrawMacHeaderCell(wxWindow *win,
wxDC& dc,
NSTableHeaderCell* cell,
const wxRect& rect,
int flags,
wxHeaderSortIconType ascending,
wxHeaderButtonParams* params);
#endif
void ApplyMacControlFlags(wxWindow* win, NSCell* cell, int flags);
// the tree buttons
wxBitmap m_bmpTreeExpanded;
wxBitmap m_bmpTreeCollapsed;
#if wxOSX_USE_NSCELL_RENDERER
NSButtonCell* GetPushButtonCell()
{
if ( !m_nsPushButtonCell )
{
m_nsPushButtonCell = [[NSButtonCell alloc] initTextCell:@""];
m_nsPushButtonCell.buttonType = NSButtonTypeMomentaryPushIn;
m_nsPushButtonCell.highlightsBy = NSPushInCellMask;
m_nsPushButtonCell.bezelStyle = NSBezelStyleShadowlessSquare;
}
return m_nsPushButtonCell;
}
NSButtonCell* GetCheckBoxCell()
{
if ( !m_nsCheckBoxCell )
{
m_nsCheckBoxCell = [[NSButtonCell alloc] initTextCell:@""];
m_nsCheckBoxCell.buttonType = NSButtonTypeSwitch;
m_nsCheckBoxCell.allowsMixedState = YES;
}
return m_nsCheckBoxCell;
}
NSButtonCell* GetRadioButtonCell()
{
if ( !m_nsRadioButtonCell )
{
m_nsRadioButtonCell = [[NSButtonCell alloc] initTextCell:@""];
m_nsRadioButtonCell.buttonType = NSButtonTypeRadio;
m_nsRadioButtonCell.allowsMixedState = YES;
}
return m_nsRadioButtonCell;
}
NSButtonCell* GetDisclosureButtonCell()
{
if ( !m_nsDisclosureButtonCell )
{
m_nsDisclosureButtonCell = [[NSButtonCell alloc] initTextCell:@""];
m_nsDisclosureButtonCell.bezelStyle = NSBezelStyleDisclosure;
m_nsDisclosureButtonCell.buttonType = NSButtonTypePushOnPushOff;
m_nsDisclosureButtonCell.highlightsBy = NSPushInCellMask;
}
return m_nsDisclosureButtonCell;
}
NSPopUpButtonCell* GetPopupbuttonCell()
{
if ( !m_nsPopupbuttonCell )
{
m_nsPopupbuttonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
}
return m_nsPopupbuttonCell;
}
NSComboBoxCell* GetComboBoxCell()
{
if ( !m_nsComboBoxCell )
{
m_nsComboBoxCell = [[NSComboBoxCell alloc] initTextCell:@""];
}
return m_nsComboBoxCell;
}
NSTableHeaderCell* GetTableHeaderCell()
{
if ( !m_nsTableHeaderCell )
{
m_nsTableHeaderCell = [[NSTableHeaderCell alloc] init];
m_nsTableHeaderCell.bezeled = NO;
m_nsTableHeaderCell.bezelStyle = NSTextFieldSquareBezel;
m_nsTableHeaderCell.bordered = NO;
}
return m_nsTableHeaderCell;
}
// These variables shouldn't be accessed directly as they're allocated on
// demand, use the getters above.
NSButtonCell* m_nsPushButtonCell = nil;
NSButtonCell* m_nsCheckBoxCell = nil;
NSButtonCell* m_nsRadioButtonCell = nil;
NSButtonCell* m_nsDisclosureButtonCell = nil;
NSPopUpButtonCell* m_nsPopupbuttonCell = nil;
NSComboBoxCell* m_nsComboBoxCell = nil;
NSTableHeaderCell* m_nsTableHeaderCell = nil;
#endif
};
// ============================================================================
@ -162,6 +278,19 @@ wxRendererNative& wxRendererNative::GetDefault()
return s_rendererMac;
}
wxRendererMac::~wxRendererMac()
{
#if wxOSX_USE_NSCELL_RENDERER
[m_nsPushButtonCell release];
[m_nsCheckBoxCell release];
[m_nsRadioButtonCell release];
[m_nsDisclosureButtonCell release];
[m_nsPopupbuttonCell release];
[m_nsComboBoxCell release];
[m_nsTableHeaderCell release];
#endif
}
int wxRendererMac::DrawHeaderButton( wxWindow *win,
wxDC& dc,
const wxRect& rect,
@ -169,6 +298,10 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win,
wxHeaderSortIconType sortArrow,
wxHeaderButtonParams* params )
{
#if wxOSX_USE_NSCELL_RENDERER
DrawMacHeaderCell(win, dc, GetTableHeaderCell(), rect, flags, sortArrow, params);
return GetTableHeaderCell().cellSize.width;
#else
if ( wxSystemSettings::GetAppearance().IsDark() )
return wxRendererNative::GetGeneric().DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
@ -234,11 +367,16 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win,
flags &= ~wxCONTROL_PRESSED;
return DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params);
#endif
}
int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win))
int wxRendererMac::GetHeaderButtonHeight(wxWindow* win)
{
#if wxOSX_USE_NSCELL_RENDERER
ApplyMacControlFlags( win, GetTableHeaderCell(), 0);
return GetTableHeaderCell().cellSize.height;
#else
SInt32 standardHeight;
OSStatus errStatus;
@ -248,6 +386,7 @@ int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win))
return standardHeight;
}
return -1;
#endif
}
int wxRendererMac::GetHeaderButtonMargin(wxWindow *WXUNUSED(win))
@ -260,21 +399,25 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win,
const wxRect& rect,
int flags )
{
// now the wxGCDC is using native transformations
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
wxDCBrushChanger setBrush(dc, *wxTRANSPARENT_BRUSH);
HIRect headerRect = CGRectMake( x, y, w, h );
if ( !wxHasCGContext(win, dc) )
{
win->RefreshRect(rect);
}
else
{
#if wxOSX_USE_NSCELL_RENDERER
NSControlStateValue stateValue = (flags & wxCONTROL_EXPANDED) ? NSControlStateValueOn : NSControlStateValueOff;
DrawMacCell(win, dc, GetDisclosureButtonCell(), rect, flags, stateValue);
#else
// now the wxGCDC is using native transformations
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
wxDCBrushChanger setBrush(dc, *wxTRANSPARENT_BRUSH);
HIRect headerRect = CGRectMake( x, y, w, h );
CGContextRef cgContext;
wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl();
@ -293,6 +436,7 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win,
drawInfo.adornment = kThemeAdornmentNone;
HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
#endif
}
}
@ -465,6 +609,159 @@ wxRendererMac::DrawMacThemeButton(wxWindow *win,
}
}
#if wxOSX_USE_NSCELL_RENDERER
void wxRendererMac::ApplyMacControlFlags(wxWindow* win, NSCell* cell, int flags)
{
NSControlSize size = NSRegularControlSize;
if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
size = NSSmallControlSize;
else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
size = NSMiniControlSize;
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_11_0
else if (win->GetWindowVariant() == wxWINDOW_VARIANT_LARGE|| (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_LARGE))
{
if (WX_IS_MACOS_AVAILABLE(11, 0))
size = NSControlSizeLarge;
else
size = NSControlSizeRegular;
}
#endif
else
size = NSRegularControlSize;
cell.controlSize = size;
cell.enabled = !(flags & wxCONTROL_DISABLED);
cell.highlighted = (flags & wxCONTROL_PRESSED);
cell.controlTint = (flags & wxCONTROL_FOCUSED) ? NSColor.currentControlTint : NSClearControlTint;
}
void wxRendererMac::DrawMacCell(wxWindow *win,
wxDC& dc,
NSCell* cell,
const wxRect& rect,
int flags,
NSControlStateValue state)
{
wxDCBrushChanger setBrush(dc, *wxTRANSPARENT_BRUSH);
if ( !wxHasCGContext(win, dc) )
{
win->RefreshRect(rect);
}
else
{
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
NSRect controlRect = NSMakeRect( x, y, w, h );
ApplyMacControlFlags(win, cell, flags);
cell.state = state;
wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl();
CGContextRef cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext();
CGContextSaveGState(cgContext);
NSGraphicsContext* formerContext = NSGraphicsContext.currentContext;
NSGraphicsContext.currentContext = [NSGraphicsContext graphicsContextWithCGContext:cgContext
flipped:YES];
[cell drawWithFrame:controlRect inView:(NSView*) win->GetHandle()];
if (flags & wxCONTROL_FOCUSED)
{
NSSetFocusRingStyle(NSFocusRingOnly);
// we must draw into a separate layer, otherwise every single subcell eg in a combobox
// will have its own focus rect drawn
CGContextBeginTransparencyLayerWithRect(cgContext, NSRectToCGRect(controlRect), 0);
[cell drawFocusRingMaskWithFrame:controlRect inView:(NSView*) win->GetHandle()];
CGContextEndTransparencyLayer(cgContext);
}
NSGraphicsContext.currentContext = formerContext;
CGContextRestoreGState(cgContext);
}
}
void wxRendererMac::DrawMacHeaderCell(wxWindow *win,
wxDC& dc,
NSTableHeaderCell* cell,
const wxRect& rect,
int flags,
wxHeaderSortIconType sortArrow,
wxHeaderButtonParams* params)
{
wxDCBrushChanger setBrush(dc, *wxTRANSPARENT_BRUSH);
if ( !wxHasCGContext(win, dc) )
{
win->RefreshRect(rect);
}
else
{
wxCoord x = rect.x;
wxCoord y = rect.y;
wxCoord w = rect.width;
wxCoord h = rect.height;
NSRect controlRect = NSMakeRect( x, y, w, h );
ApplyMacControlFlags(win, cell, flags);
NSString* title = @("");
NSTextAlignment alignment = NSTextAlignmentLeft;
if ( params )
{
title = wxCFStringRef(params->m_labelText).AsNSString();
switch( params->m_labelAlignment )
{
case wxALIGN_CENTER:
cell.alignment = NSTextAlignmentCenter;
break;
case wxALIGN_RIGHT:
cell.alignment = NSTextAlignmentRight;
break;
case wxALIGN_LEFT:
default:
cell.alignment = NSTextAlignmentLeft;
}
}
cell.title = title;
cell.alignment = alignment;
wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl();
CGContextRef cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext();
CGContextSaveGState(cgContext);
NSGraphicsContext* formerContext = NSGraphicsContext.currentContext;
NSGraphicsContext.currentContext = [NSGraphicsContext graphicsContextWithCGContext:cgContext
flipped:YES];
[cell drawWithFrame:controlRect inView:(NSView*) win->GetHandle()];
if ( sortArrow == wxHDR_SORT_ICON_UP || sortArrow == wxHDR_SORT_ICON_DOWN )
{
BOOL ascending = sortArrow == wxHDR_SORT_ICON_UP;
[cell drawSortIndicatorWithFrame:controlRect inView:(NSView*) win->GetHandle()
ascending:ascending priority:0];
}
NSGraphicsContext.currentContext = formerContext;
CGContextRestoreGState(cgContext);
}
}
#endif
void
wxRendererMac::DrawCheckBox(wxWindow *win,
wxDC& dc,
@ -473,7 +770,13 @@ wxRendererMac::DrawCheckBox(wxWindow *win,
{
if (flags & wxCONTROL_CHECKED)
flags |= wxCONTROL_PRESSED;
#if wxOSX_USE_NSCELL_RENDERER
NSControlStateValue stateValue = (flags & wxCONTROL_PRESSED) ? NSControlStateValueOn : NSControlStateValueOff;
if (flags & wxCONTROL_UNDETERMINED)
stateValue = NSControlStateValueMixed;
DrawMacCell(win, dc, GetCheckBoxCell(), rect, flags, stateValue);
#else
int kind;
if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
@ -488,15 +791,20 @@ wxRendererMac::DrawCheckBox(wxWindow *win,
DrawMacThemeButton(win, dc, rect, flags,
kind, kThemeAdornmentNone);
#endif
}
wxSize wxRendererMac::GetCheckBoxSize(wxWindow* win, int WXUNUSED(flags))
wxSize wxRendererMac::GetCheckBoxSize(wxWindow* win, int flags)
{
// Even though we don't use the window in this implementation, still check
// that it's valid to avoid surprises when running the same code under the
// other platforms.
wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );
#if wxOSX_USE_NSCELL_RENDERER
ApplyMacControlFlags( win, GetCheckBoxCell(), flags);
NSSize sz = GetCheckBoxCell().cellSize;
return wxSize(sz.width, sz.height);
#else
wxSize size;
SInt32 width, height;
OSStatus errStatus;
@ -514,6 +822,7 @@ wxSize wxRendererMac::GetCheckBoxSize(wxWindow* win, int WXUNUSED(flags))
}
return size;
#endif
}
void
@ -540,7 +849,11 @@ wxRendererMac::DrawPushButton(wxWindow *win,
const wxRect& rect,
int flags)
{
int kind;
#if wxOSX_USE_NSCELL_RENDERER
NSControlStateValue stateValue = (flags & wxCONTROL_PRESSED) ? NSControlStateValueOn : NSControlStateValueOff;
DrawMacCell(win, dc, GetPushButtonCell(), rect, flags, stateValue);
#else
int kind;
if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
kind = kThemeBevelButtonSmall;
// There is no kThemeBevelButtonMini, but in this case, use Small
@ -551,6 +864,7 @@ wxRendererMac::DrawPushButton(wxWindow *win,
DrawMacThemeButton(win, dc, rect, flags,
kind, kThemeAdornmentNone);
#endif
}
void wxRendererMac::DrawCollapseButton(wxWindow *win,
@ -619,6 +933,10 @@ wxRendererMac::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int fl
void wxRendererMac::DrawChoice(wxWindow* win, wxDC& dc,
const wxRect& rect, int flags)
{
#if wxOSX_USE_NSCELL_RENDERER
NSControlStateValue stateValue = (flags & wxCONTROL_PRESSED) ? NSControlStateValueOn : NSControlStateValueOff;
DrawMacCell(win, dc, GetPopupbuttonCell(), rect, flags, stateValue);
#else
int kind;
if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
@ -631,12 +949,17 @@ void wxRendererMac::DrawChoice(wxWindow* win, wxDC& dc,
kind = kThemePopupButton;
DrawMacThemeButton(win, dc, rect, flags, kind, kThemeAdornmentNone);
#endif
}
void wxRendererMac::DrawComboBox(wxWindow* win, wxDC& dc,
const wxRect& rect, int flags)
{
#if wxOSX_USE_NSCELL_RENDERER
NSControlStateValue stateValue = (flags & wxCONTROL_PRESSED) ? NSControlStateValueOn : NSControlStateValueOff;
DrawMacCell(win, dc, GetComboBoxCell(), rect, flags, stateValue);
#else
int kind;
if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
@ -649,11 +972,22 @@ void wxRendererMac::DrawComboBox(wxWindow* win, wxDC& dc,
kind = kThemeComboBox;
DrawMacThemeButton(win, dc, rect, flags, kind, kThemeAdornmentNone);
#endif
}
void wxRendererMac::DrawRadioBitmap(wxWindow* win, wxDC& dc,
const wxRect& rect, int flags)
{
if (flags & wxCONTROL_CHECKED)
flags |= wxCONTROL_PRESSED;
#if wxOSX_USE_NSCELL_RENDERER
NSControlStateValue stateValue = (flags & wxCONTROL_PRESSED) ? NSControlStateValueOn : NSControlStateValueOff;
if (flags & wxCONTROL_UNDETERMINED)
stateValue = NSControlStateValueMixed;
DrawMacCell(win, dc, GetRadioButtonCell(), rect, flags, stateValue);
#else
int kind;
if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
@ -665,11 +999,9 @@ void wxRendererMac::DrawRadioBitmap(wxWindow* win, wxDC& dc,
else
kind = kThemeRadioButton;
if (flags & wxCONTROL_CHECKED)
flags |= wxCONTROL_PRESSED;
DrawMacThemeButton(win, dc, rect, flags,
kind, kThemeAdornmentNone);
#endif
}
void wxRendererMac::DrawTextCtrl(wxWindow* win, wxDC& dc,