From 084009bff51af4c67c5a2600c60de15bdf4106bf Mon Sep 17 00:00:00 2001 From: Jouk Date: Fri, 16 Jun 2017 10:45:03 +0200 Subject: [PATCH 01/10] Update setup for OpenVMS --- setup.h_vms | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.h_vms b/setup.h_vms index 8768cf73c7..f327f42a5f 100644 --- a/setup.h_vms +++ b/setup.h_vms @@ -3,7 +3,7 @@ * Template for the set.h file for VMS * * Created from setup.h_in * * Author : J.Jansen (joukj@hrem.nano.tudelft.nl) * - * Date : 25 April 2017 * + * Date : 16 June 2017 * * * *****************************************************************************/ @@ -208,6 +208,8 @@ typedef pid_t GPid; #define wxUSE_UNSAFE_WXSTRING_CONV 1 +#define wxUSE_REPRODUCIBLE_BUILD 1 + #ifndef wxUSE_UNICODE #if defined( __WXX11__ ) #define wxUSE_UNICODE 0 From 74bde5690ce5df6a93dba9f7907300a51b0035a4 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sun, 18 Jun 2017 13:48:41 -0700 Subject: [PATCH 02/10] Use reported size for page source string Avoids a warning from Valgrind about reading uninitialized byte in strlen. The string does not seem to be nul-terminated. --- src/gtk/webview_webkit2.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gtk/webview_webkit2.cpp b/src/gtk/webview_webkit2.cpp index 6707cec719..f2e67d3202 100644 --- a/src/gtk/webview_webkit2.cpp +++ b/src/gtk/webview_webkit2.cpp @@ -827,8 +827,9 @@ wxString wxWebViewWebKit::GetPageSource() const g_main_context_iteration(main_context, TRUE); } + size_t length; guchar *source = webkit_web_resource_get_data_finish(resource, result, - NULL, NULL); + &length, NULL); if (result) { g_object_unref(result); @@ -836,7 +837,7 @@ wxString wxWebViewWebKit::GetPageSource() const if (source) { - wxString wxs = wxString(source, wxConvUTF8); + wxString wxs(source, wxConvUTF8, length); free(source); return wxs; } From 59acf5ac27b9d95dbe95b7e86695a3a81bbd2a7b Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sun, 18 Jun 2017 13:56:06 -0700 Subject: [PATCH 03/10] Use correct signature for callback --- src/gtk/webview_webkit2.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gtk/webview_webkit2.cpp b/src/gtk/webview_webkit2.cpp index f2e67d3202..958dcc39b9 100644 --- a/src/gtk/webview_webkit2.cpp +++ b/src/gtk/webview_webkit2.cpp @@ -801,11 +801,15 @@ wxString wxWebViewWebKit::GetCurrentTitle() const } -static void wxgtk_web_resource_get_data_cb(WebKitWebResource *, +extern "C" { +static void wxgtk_web_resource_get_data_cb(GObject*, GAsyncResult *res, - GAsyncResult **res_out) + void* user_data) { - *res_out = (GAsyncResult*)g_object_ref(res); + GAsyncResult** res_out = static_cast(user_data); + g_object_ref(res); + *res_out = res; +} } wxString wxWebViewWebKit::GetPageSource() const @@ -818,7 +822,7 @@ wxString wxWebViewWebKit::GetPageSource() const GAsyncResult *result = NULL; webkit_web_resource_get_data(resource, NULL, - (GAsyncReadyCallback)wxgtk_web_resource_get_data_cb, + wxgtk_web_resource_get_data_cb, &result); GMainContext *main_context = g_main_context_get_thread_default(); From a08812c499645fd3a3ebcabbae0e50caf6298520 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sun, 18 Jun 2017 22:47:15 -0700 Subject: [PATCH 04/10] Simplify overlapping regions check --- src/gtk/dc.cpp | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index d2d5f19cda..7eaab6fd7d 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -154,35 +154,9 @@ bool wxGTKCairoDCImpl::DoStretchBlit(int xdest, int ydest, int dstWidth, int dst if ( cr == cr_src ) { // Check if destination and source regions overlap. - bool regOverlap; -#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 10, 0) - if ( cairo_version() >= CAIRO_VERSION_ENCODE(1, 10, 0) ) - { - cairo_rectangle_int_t rdst; - rdst.x = xdest; - rdst.y = ydest; - rdst.width = dstWidth; - rdst.height = dstHeight; - cairo_region_t* regdst = cairo_region_create_rectangle(&rdst); - - cairo_rectangle_int_t rsrc; - rsrc.x = xsrc; - rsrc.y = ysrc; - rsrc.width = srcWidth; - rsrc.height = srcHeight; - cairo_region_overlap_t ov = cairo_region_contains_rectangle(regdst, &rsrc); - cairo_region_destroy(regdst); - regOverlap = (ov != CAIRO_REGION_OVERLAP_OUT); - } - else -#endif // Cairo 1.10 - { - wxRect rdst(xdest, ydest, dstWidth, dstHeight); - wxRect rsrc(xsrc, ysrc, srcWidth, srcHeight); - regOverlap = rdst.Intersects(rsrc); - } // If necessary, copy source surface to the temporary one. - if ( regOverlap ) + if (wxRect(xdest, ydest, dstWidth, dstHeight) + .Intersects(wxRect(xsrc, ysrc, srcWidth, srcHeight))) { const int w = cairo_image_surface_get_width(surfaceSrc); const int h = cairo_image_surface_get_height(surfaceSrc); From dd3c62660bfadd536baad503a04e12006213d023 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sun, 18 Jun 2017 23:14:43 -0700 Subject: [PATCH 05/10] Remove hard TABs and trailing spaces no real changes --- src/gtk/dc.cpp | 4 +- src/msw/statbox.cpp | 6 +- src/osx/carbon/renderer.cpp | 14 ++--- src/osx/cocoa/listbox.mm | 30 +++++----- src/osx/cocoa/mediactrl.mm | 114 ++++++++++++++++++------------------ src/osx/iphone/textctrl.mm | 55 +++++++++-------- src/osx/iphone/utils.mm | 2 +- src/osx/window_osx.cpp | 86 +++++++++++++-------------- 8 files changed, 155 insertions(+), 156 deletions(-) diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index 7eaab6fd7d..d14557097d 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -153,7 +153,7 @@ bool wxGTKCairoDCImpl::DoStretchBlit(int xdest, int ydest, int dstWidth, int dst // surface and use this copy in the drawing operations. if ( cr == cr_src ) { - // Check if destination and source regions overlap. + // Check if destination and source regions overlap. // If necessary, copy source surface to the temporary one. if (wxRect(xdest, ydest, dstWidth, dstHeight) .Intersects(wxRect(xsrc, ysrc, srcWidth, srcHeight))) @@ -221,7 +221,7 @@ bool wxGTKCairoDCImpl::DoStretchBlit(int xdest, int ydest, int dstWidth, int dst cairo_restore(cr); if ( surfaceTmp ) { - cairo_surface_destroy(surfaceTmp); + cairo_surface_destroy(surfaceTmp); } m_logicalFunction = rop_save; return true; diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 7261555233..5adc32ee65 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -510,10 +510,10 @@ void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event)) ::GetClientRect(GetHwnd(), &rc); wxPaintDC dc(this); - // No need to do anything if the client rectangle is empty and, worse, + // No need to do anything if the client rectangle is empty and, worse, // doing it would result in an assert when creating the bitmap below. - if ( !rc.right || !rc.bottom ) - return; + if ( !rc.right || !rc.bottom ) + return; // draw the entire box in a memory DC wxMemoryDC memdc(&dc); diff --git a/src/osx/carbon/renderer.cpp b/src/osx/carbon/renderer.cpp index 17cec77e49..f7cd333d38 100644 --- a/src/osx/carbon/renderer.cpp +++ b/src/osx/carbon/renderer.cpp @@ -44,7 +44,7 @@ inline bool wxHasCGContext(wxWindow* WXUNUSED(win), wxDC& dc) { wxGCDCImpl* gcdc = wxDynamicCast( dc.GetImpl() , wxGCDCImpl); - + if ( gcdc ) { if ( gcdc->GetGraphicsContext()->GetNativeContext() ) @@ -218,7 +218,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win, { drawInfo.value = kThemeButtonOn; } - + HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); } } @@ -730,22 +730,22 @@ void wxRendererMac::DrawTitleBarBitmap(wxWindow *win, drawCircle = false; glyphColor = wxColour(145, 147, 149); } - + if ( drawCircle ) { wxRect circleRect(rect); circleRect.Deflate(2); - + dc.DrawEllipse(circleRect); } - + dc.SetPen(wxPen(glyphColor, 1)); - + wxRect centerRect(rect); centerRect.Deflate(5); centerRect.height++; centerRect.width++; - + dc.DrawLine(centerRect.GetTopLeft(), centerRect.GetBottomRight()); dc.DrawLine(centerRect.GetTopRight(), centerRect.GetBottomLeft()); } diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index df6b080595..f7f85be8b0 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -145,7 +145,7 @@ public : virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender) wxOVERRIDE; - + protected : wxNSTableView* m_tableView ; @@ -293,9 +293,9 @@ protected: - (void) tableViewSelectionDidChange: (NSNotification *) notification { wxUnusedVar(notification); - + int row = [self selectedRow]; - + if (row == -1) { // no row selected @@ -305,14 +305,14 @@ protected: wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxListBox *list = static_cast ( impl->GetWXPeer()); wxCHECK_RET( list != NULL , wxT("Listbox expected")); - + if ((row < 0) || (row > (int) list->GetCount())) // OS X can select an item below the last item return; - + if ( !list->MacGetBlockEvents() ) list->HandleLineEvent( row, false ); } - + } - (void)setFont:(NSFont *)aFont @@ -388,11 +388,11 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertTextColumn( unsigned pos, const [col1 setWidth:1000]; } [col1 setResizingMask: NSTableColumnAutoresizingMask]; - + wxListBox *list = static_cast ( GetWXPeer()); if ( list != NULL ) [[col1 dataCell] setFont:list->GetFont().OSXGetNSFont()]; - + wxCocoaTableColumn* wxcol = new wxCocoaTableColumn( col1, editable ); [col1 setColumn:wxcol]; @@ -412,30 +412,30 @@ wxListWidgetColumn* wxListWidgetCocoaImpl::InsertCheckColumn( unsigned pos , con [checkbox setTitle:@""]; [checkbox setButtonType:NSSwitchButton]; [col1 setDataCell:checkbox] ; - + wxListBox *list = static_cast ( GetWXPeer()); if ( list != NULL ) { NSControlSize size = NSRegularControlSize; - + switch ( list->GetWindowVariant() ) { case wxWINDOW_VARIANT_NORMAL : size = NSRegularControlSize; break ; - + case wxWINDOW_VARIANT_SMALL : size = NSSmallControlSize; break ; - + case wxWINDOW_VARIANT_MINI : size = NSMiniControlSize; break ; - + case wxWINDOW_VARIANT_LARGE : size = NSRegularControlSize; break ; - + default: break ; } @@ -502,7 +502,7 @@ void wxListWidgetCocoaImpl::ListSetSelection( unsigned int n, bool select, bool // TODO if ( select ) [m_tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:n] - byExtendingSelection:multi]; + byExtendingSelection:multi]; else [m_tableView deselectRow: n]; diff --git a/src/osx/cocoa/mediactrl.mm b/src/osx/cocoa/mediactrl.mm index 4a1da75770..2e3df83874 100644 --- a/src/osx/cocoa/mediactrl.mm +++ b/src/osx/cocoa/mediactrl.mm @@ -60,7 +60,7 @@ static void *AVSPPlayerItemStatusContext = &AVSPPlayerItemStatusContext; static void *AVSPPlayerRateContext = &AVSPPlayerRateContext; @interface wxAVPlayer : AVPlayer { - + AVPlayerLayer *playerLayer; wxAVMediaBackend* m_backend; @@ -75,10 +75,10 @@ static void *AVSPPlayerRateContext = &AVSPPlayerRateContext; class WXDLLIMPEXP_MEDIA wxAVMediaBackend : public wxMediaBackendCommonBase { public: - + wxAVMediaBackend(); ~wxAVMediaBackend(); - + virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, wxWindowID id, const wxPoint& pos, @@ -86,41 +86,41 @@ public: long style, const wxValidator& validator, const wxString& name) wxOVERRIDE; - + virtual bool Play() wxOVERRIDE; virtual bool Pause() wxOVERRIDE; virtual bool Stop() wxOVERRIDE; - + virtual bool Load(const wxString& fileName) wxOVERRIDE; virtual bool Load(const wxURI& location) wxOVERRIDE; - + virtual wxMediaState GetState() wxOVERRIDE; - + virtual bool SetPosition(wxLongLong where) wxOVERRIDE; virtual wxLongLong GetPosition() wxOVERRIDE; virtual wxLongLong GetDuration() wxOVERRIDE; - + virtual void Move(int x, int y, int w, int h) wxOVERRIDE; wxSize GetVideoSize() const wxOVERRIDE; - + virtual double GetPlaybackRate() wxOVERRIDE; virtual bool SetPlaybackRate(double dRate) wxOVERRIDE; - + virtual double GetVolume() wxOVERRIDE; virtual bool SetVolume(double dVolume) wxOVERRIDE; - + void Cleanup(); void FinishLoad(); - + virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags) wxOVERRIDE; private: void DoShowPlayerControls(wxMediaCtrlPlayerControls flags); - + wxSize m_bestSize; //Original movie size wxAVPlayer* m_player; //AVPlayer handle/instance - + wxMediaCtrlPlayerControls m_interfaceflags; // Saved interface flags - + wxDECLARE_DYNAMIC_CLASS(wxAVMediaBackend); }; @@ -146,19 +146,19 @@ private: - (void)dealloc { - [playerLayer release]; + [playerLayer release]; [[NSNotificationCenter defaultCenter] removeObserver:self]; - + [self removeObserver:self forKeyPath:@"rate" context:AVSPPlayerRateContext]; - [self removeObserver:self forKeyPath:@"currentItem.status" context:AVSPPlayerItemStatusContext]; - - [super dealloc]; + [self removeObserver:self forKeyPath:@"currentItem.status" context:AVSPPlayerItemStatusContext]; + + [super dealloc]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (context == AVSPPlayerItemStatusContext) - { + if (context == AVSPPlayerItemStatusContext) + { id val = [change objectForKey:NSKeyValueChangeNewKey]; if ( val != [NSNull null ] ) { @@ -180,10 +180,10 @@ private: break; } } - } - else if (context == AVSPPlayerRateContext) - { - NSNumber* newRate = [change objectForKey:NSKeyValueChangeNewKey]; + } + else if (context == AVSPPlayerRateContext) + { + NSNumber* newRate = [change objectForKey:NSKeyValueChangeNewKey]; if ([newRate intValue] == 0) { m_backend->QueuePauseEvent(); @@ -192,11 +192,11 @@ private: { m_backend->QueuePlayEvent(); } - } - else - { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } + } + else + { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } } -(wxAVMediaBackend*) backend @@ -220,12 +220,12 @@ private: -(BOOL)isPlaying { - if ([self rate] == 0) - { - return NO; - } - - return YES; + if ([self rate] == 0) + { + return NO; + } + + return YES; } @end @@ -252,7 +252,7 @@ private: + (Class)layerClass { - return [AVPlayerLayer class]; + return [AVPlayerLayer class]; } - (id) initWithFrame:(CGRect)rect player:(wxAVPlayer*) player @@ -342,7 +342,7 @@ private: [playerlayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; [[self layer] addSublayer:playerlayer]; } - + return self; } @@ -377,9 +377,9 @@ bool wxAVMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent, const wxString& name) { wxMediaCtrl* mediactrl = (wxMediaCtrl*) inctrl; - + mediactrl->DontCreatePeer(); - + if ( !mediactrl->wxControl::Create( parent, wid, pos, size, wxWindow::MacRemoveBordersFromStyle(style), @@ -392,7 +392,7 @@ bool wxAVMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent, [m_player setBackend:this]; WXRect r = wxOSXGetFrameForControl( mediactrl, pos , size ) ; - + WXWidget view = NULL; #if wxOSX_USE_AVKIT if ( NSClassFromString(@"AVPlayerView") ) @@ -401,12 +401,12 @@ bool wxAVMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent, [(wxAVPlayerView*) view setControlsStyle:AVPlayerViewControlsStyleNone]; } #endif - + if ( view == NULL ) { view = [[wxAVView alloc] initWithFrame: r player:m_player]; } - + #if wxOSX_USE_IPHONE wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl(mediactrl,view); #else @@ -431,16 +431,16 @@ bool wxAVMediaBackend::Load(const wxURI& location) { wxCFStringRef uri(location.BuildURI()); NSURL *url = [NSURL URLWithString: uri.AsNSString()]; - + AVAsset* asset = [AVAsset assetWithURL:url]; if (! asset ) return false; - + if ( [asset isPlayable] ) { AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset]; [m_player replaceCurrentItemWithPlayerItem:playerItem]; - + return playerItem != nil; } return false; @@ -449,12 +449,12 @@ bool wxAVMediaBackend::Load(const wxURI& location) void wxAVMediaBackend::FinishLoad() { DoShowPlayerControls(m_interfaceflags); - + AVPlayerItem *playerItem = [m_player currentItem]; - + CGSize s = [playerItem presentationSize]; m_bestSize = wxSize(s.width, s.height); - + NotifyMovieLoaded(); } @@ -500,7 +500,7 @@ bool wxAVMediaBackend::SetPlaybackRate(double dRate) bool wxAVMediaBackend::SetPosition(wxLongLong where) { - [m_player seekToTime:CMTimeMakeWithSeconds(where.GetValue() / 1000.0, 1) + [m_player seekToTime:CMTimeMakeWithSeconds(where.GetValue() / 1000.0, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; return true; @@ -514,11 +514,11 @@ wxLongLong wxAVMediaBackend::GetPosition() wxLongLong wxAVMediaBackend::GetDuration() { AVPlayerItem *playerItem = [m_player currentItem]; - - if ([playerItem status] == AVPlayerItemStatusReadyToPlay) - return CMTimeGetSeconds([[playerItem asset] duration])*1000.0; - else - return 0.f; + + if ([playerItem status] == AVPlayerItemStatusReadyToPlay) + return CMTimeGetSeconds([[playerItem asset] duration])*1000.0; + else + return 0.f; } wxMediaState wxAVMediaBackend::GetState() @@ -555,7 +555,7 @@ bool wxAVMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags) { if ( m_interfaceflags != flags ) DoShowPlayerControls(flags); - + m_interfaceflags = flags; return true; } diff --git a/src/osx/iphone/textctrl.mm b/src/osx/iphone/textctrl.mm index b4e9a8fb0f..989a4d73d7 100644 --- a/src/osx/iphone/textctrl.mm +++ b/src/osx/iphone/textctrl.mm @@ -238,8 +238,7 @@ protected : - (BOOL)textFieldShouldReturn:(UITextField *)textField { wxUnusedVar(textField); - - + return NO; } @@ -317,7 +316,7 @@ wxUITextViewControl::wxUITextViewControl( wxTextCtrl *wxPeer, UITextView* v) : { m_textView = v; m_delegate= [[wxUITextViewDelegate alloc] init]; - + [m_textView setDelegate:m_delegate]; } @@ -423,7 +422,7 @@ void wxUITextViewControl::WriteText(const wxString& str) wxString st = str; wxMacConvertNewlines10To13( &st ); wxMacEditHelper helper(m_textView); - + wxCFStringRef insert( st , m_wxPeer->GetFont().GetEncoding() ); NSMutableString* subst = [NSMutableString stringWithString:[m_textView text]]; [subst replaceCharactersInRange:[m_textView selectedRange] withString:insert.AsNSString()]; @@ -466,10 +465,10 @@ bool wxUITextViewControl::GetStyle(long position, wxTextAttr& style) /* if (font) style.SetFont(wxFont(font)); - + if (bgcolor) style.SetBackgroundColour(wxColour(bgcolor)); - + if (fgcolor) style.SetTextColour(wxColour(fgcolor)); */ @@ -489,15 +488,15 @@ void wxUITextViewControl::SetStyle(long start, range = [m_textView selectedRange]; /* UITextStorage* storage = [m_textView textStorage]; - + wxFont font = style.GetFont(); if (style.HasFont() && font.IsOk()) [storage addAttribute:NSFontAttributeName value:font.OSXGetNSFont() range:range]; - + wxColour bgcolor = style.GetBackgroundColour(); if (style.HasBackgroundColour() && bgcolor.IsOk()) [storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range]; - + wxColour fgcolor = style.GetTextColour(); if (style.HasTextColour() && fgcolor.IsOk()) [storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range]; @@ -512,9 +511,9 @@ void wxUITextViewControl::CheckSpelling(bool check) wxSize wxUITextViewControl::GetBestSize() const { wxRect r; - + GetBestRect(&r); - + /* if (m_textView && [m_textView layoutManager]) { @@ -526,7 +525,7 @@ wxSize wxUITextViewControl::GetBestSize() const } return wxSize(0,0); */ - + wxSize sz = r.GetSize(); if ( sz.y < 31 ) sz.y = 31; @@ -571,7 +570,7 @@ void wxUITextFieldControl::SetStringValue( const wxString &str) wxSize wxUITextFieldControl::GetBestSize() const { wxRect r; - + GetBestRect(&r); wxSize sz = r.GetSize(); if ( sz.y < 31 ) @@ -605,7 +604,7 @@ void wxUITextFieldControl::SetEditable(bool editable) if ( !editable ) { [m_textField resignFirstResponder]; } - + [m_textField setEnabled: editable]; } } @@ -710,7 +709,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, UITextView * v = nil; v = [[UITextView alloc] initWithFrame:r]; tv = v; - + wxUITextViewControl* tc = new wxUITextViewControl( wxpeer, v ); c = tc; t = tc; @@ -721,39 +720,39 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, wxUITextField* v = [[wxUITextField alloc] initWithFrame:r]; tv = v; - v.textColor = [UIColor blackColor]; - v.font = [UIFont systemFontOfSize:17.0]; - v.backgroundColor = [UIColor whiteColor]; - - v.clearButtonMode = UITextFieldViewModeNever; - + v.textColor = [UIColor blackColor]; + v.font = [UIFont systemFontOfSize:17.0]; + v.backgroundColor = [UIColor whiteColor]; + + v.clearButtonMode = UITextFieldViewModeNever; + [v setBorderStyle:UITextBorderStyleBezel]; if ( style & wxNO_BORDER ) v.borderStyle = UITextBorderStyleNone; - + wxUITextFieldControl* tc = new wxUITextFieldControl( wxpeer, v ); c = tc; t = tc; } #endif - + if ( style & wxTE_PASSWORD ) [tv setSecureTextEntry:YES]; - + if ( style & wxTE_CAPITALIZE ) [tv setAutocapitalizationType:UITextAutocapitalizationTypeWords]; else [tv setAutocapitalizationType:UITextAutocapitalizationTypeSentences]; - + if ( !(style & wxTE_MULTILINE) ) { [tv setAutocorrectionType:UITextAutocorrectionTypeNo]; - [tv setReturnKeyType:UIReturnKeyDone]; + [tv setReturnKeyType:UIReturnKeyDone]; } [tv setKeyboardType:UIKeyboardTypeDefault]; - + t->SetStringValue(str); - + return c; } diff --git a/src/osx/iphone/utils.mm b/src/osx/iphone/utils.mm index b85cb437e0..1ac79e3ebf 100644 --- a/src/osx/iphone/utils.mm +++ b/src/osx/iphone/utils.mm @@ -68,7 +68,7 @@ } - (void)dealloc { - [super dealloc]; + [super dealloc]; } diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 1745608123..fa0587f493 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -221,7 +221,7 @@ void wxWindowMac::Init() wxWindowMac::~wxWindowMac() { SendDestroyEvent(); - + #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON for ( int i = s_hotkeys.size()-1; i>=0; -- i ) { @@ -310,10 +310,10 @@ void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl* wrapper) wxOSXWidgetImpl* inner = GetPeer(); wxASSERT_MSG( inner != NULL && inner->IsOk(), "missing or incomplete inner peer" ); wxASSERT_MSG( wrapper != NULL && wrapper->IsOk(), "missing or incomplete wrapper" ); - + if ( !(inner != NULL && inner->IsOk() && wrapper != NULL && wrapper->IsOk()) ) return; - + inner->RemoveFromParent(); wrapper->InstallEventHandler(); wrapper->Embed(inner); @@ -334,28 +334,28 @@ void wxWindowMac::SetPeer(wxOSXWidgetImpl* peer) if ( GetPeer() && !GetPeer()->IsRootControl()) { wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ; - + if (!GetParent()->GetChildren().Find((wxWindow*)this)) GetParent()->AddChild( this ); - + GetPeer()->InstallEventHandler(); GetPeer()->Embed(GetParent()->GetPeer()); - + GetParent()->MacChildAdded() ; - + // adjust font, controlsize etc GetPeer()->SetControlSize( m_windowVariant ); InheritAttributes(); // in case nothing has been set, use the variant default fonts if ( !m_hasFont ) DoSetWindowVariant( m_windowVariant ); - + GetPeer()->SetInitialLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; - + // for controls we want to use best size for wxDefaultSize params ) if ( !GetPeer()->IsUserPane() ) SetInitialSize(GetMinSize()); - + SetCursor( *wxSTANDARD_CURSOR ) ; } } @@ -859,16 +859,16 @@ void wxWindowMac::DoGetClientSize( int *x, int *y ) const // we shouldn't return invalid width if ( ww < 0 ) ww = 0; - + *x = ww; } - + if (y) { // we shouldn't return invalid height if ( hh < 0 ) hh = 0; - + *y = hh; } } @@ -1244,7 +1244,7 @@ bool wxWindowMac::Show(bool show) { if ( !show ) MacInvalidateBorders(); - + if ( !wxWindowBase::Show(show) ) return false; @@ -1375,7 +1375,7 @@ void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) if ( !IsShownOnScreen() ) return ; - + if ( IsFrozen() ) return; @@ -1999,7 +1999,7 @@ bool wxWindowMac::MacDoRedraw( long time ) wxNonOwnedWindow* top = MacGetTopLevelWindow(); if (top) top->WindowWasPainted() ; - + return handled; } @@ -2302,14 +2302,14 @@ long wxWindowMac::MacGetLeftBorderSize() const { // the wx borders are all symmetric in mac themes long border = MacGetWXBorderSize() ; - + if ( GetPeer() ) { int left, top, right, bottom; GetPeer()->GetLayoutInset( left, top, right, bottom ); border -= left; } - + return border; } @@ -2318,14 +2318,14 @@ long wxWindowMac::MacGetRightBorderSize() const { // the wx borders are all symmetric in mac themes long border = MacGetWXBorderSize() ; - + if ( GetPeer() ) { int left, top, right, bottom; GetPeer()->GetLayoutInset( left, top, right, bottom ); border -= right; } - + return border; } @@ -2333,14 +2333,14 @@ long wxWindowMac::MacGetTopBorderSize() const { // the wx borders are all symmetric in mac themes long border = MacGetWXBorderSize() ; - + if ( GetPeer() ) { int left, top, right, bottom; GetPeer()->GetLayoutInset( left, top, right, bottom ); border -= top; } - + return border; } @@ -2348,14 +2348,14 @@ long wxWindowMac::MacGetBottomBorderSize() const { // the wx borders are all symmetric in mac themes long border = MacGetWXBorderSize() ; - + if ( GetPeer() ) { int left, top, right, bottom; GetPeer()->GetLayoutInset( left, top, right, bottom ); border -= bottom; } - + return border; } @@ -2530,18 +2530,18 @@ wxHotKeyHandler(EventHandlerCallRef WXUNUSED(nextHandler), GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode ); GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers ); - + UInt32 keymessage = (keyCode << 8) + charCode; - + wxKeyEvent wxevent(wxEVT_HOTKEY); wxevent.SetId(hotKeyId.id); wxTheApp->MacCreateKeyEvent( wxevent, s_hotkeys[i].window , keymessage , modifiers , when , 0 ) ; - + s_hotkeys[i].window->HandleWindowEvent(wxevent); } } - + return noErr; } @@ -2552,11 +2552,11 @@ bool wxWindowMac::RegisterHotKey(int hotkeyId, int modifiers, int keycode) if ( s_hotkeys[i].keyId == hotkeyId ) { wxLogLastError(wxT("hotkeyId already registered")); - + return false; } } - + static bool installed = false; if ( !installed ) { @@ -2567,7 +2567,7 @@ bool wxWindowMac::RegisterHotKey(int hotkeyId, int modifiers, int keycode) InstallApplicationEventHandler(&wxHotKeyHandler, 1, &eventType, NULL, NULL); installed = true; } - + UInt32 mac_modifiers=0; if ( modifiers & wxMOD_ALT ) mac_modifiers |= optionKey; @@ -2577,18 +2577,18 @@ bool wxWindowMac::RegisterHotKey(int hotkeyId, int modifiers, int keycode) mac_modifiers |= controlKey; if ( modifiers & wxMOD_CONTROL ) mac_modifiers |= cmdKey; - + EventHotKeyRef hotKeyRef; EventHotKeyID hotKeyIDmac; - + hotKeyIDmac.signature = 'WXMC'; hotKeyIDmac.id = hotkeyId; - + if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode)keycode), mac_modifiers, hotKeyIDmac, GetApplicationEventTarget(), 0, &hotKeyRef) != noErr ) { wxLogLastError(wxT("RegisterHotKey")); - + return false; } else @@ -2597,10 +2597,10 @@ bool wxWindowMac::RegisterHotKey(int hotkeyId, int modifiers, int keycode) v.ref = hotKeyRef; v.keyId = hotkeyId; v.window = this; - + s_hotkeys.push_back(v); } - + return true; } @@ -2615,14 +2615,14 @@ bool wxWindowMac::UnregisterHotKey(int hotkeyId) if ( UnregisterEventHotKey(ref) != noErr ) { wxLogLastError(wxT("UnregisterHotKey")); - + return false; } else return true; } } - + return false; } @@ -2631,7 +2631,7 @@ bool wxWindowMac::UnregisterHotKey(int hotkeyId) bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) { bool handled = false; - + // moved the ordinary key event sending AFTER the accel evaluation #if wxUSE_ACCEL @@ -2665,7 +2665,7 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) } } #endif // wxUSE_ACCEL - + if ( !handled ) { handled = HandleWindowEvent( event ) ; @@ -2738,9 +2738,9 @@ void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl) void wxWidgetImpl::RemoveAssociation(WXWidget control) { - wxCHECK_RET( control != NULL, wxT("attempt to remove a NULL WXWidget from control map") ); + wxCHECK_RET( control != NULL, wxT("attempt to remove a NULL WXWidget from control map") ); - wxWinMacControlList.erase(control); + wxWinMacControlList.erase(control); } wxIMPLEMENT_ABSTRACT_CLASS(wxWidgetImpl, wxObject); From edb60cfcda0c3dce1510c012cb6def91829b1308 Mon Sep 17 00:00:00 2001 From: Jouk Date: Tue, 20 Jun 2017 08:31:16 +0200 Subject: [PATCH 06/10] Correct bitmap_in_button code for wxUniversal, wxMOTIF and wxGTK1 --- src/xrc/xh_tglbtn.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/xrc/xh_tglbtn.cpp b/src/xrc/xh_tglbtn.cpp index 2bac11a264..9b33a47471 100644 --- a/src/xrc/xh_tglbtn.cpp +++ b/src/xrc/xh_tglbtn.cpp @@ -16,6 +16,10 @@ #if wxUSE_XRC && wxUSE_TOGGLEBTN +# if !defined(__WXUNIVERSAL__) && !defined(__WXMOTIF__) && !(defined(__WXGTK__) && !defined(__WXGTK20__)) +# define wxHAVE_BITMAPS_IN_BUTTON 1 +# endif + #include "wx/xrc/xh_tglbtn.h" #include "wx/tglbtn.h" #include "wx/button.h" // solely for wxBU_EXACTFIT @@ -35,7 +39,7 @@ wxObject *wxToggleButtonXmlHandler::DoCreateResource() wxObject *control = m_instance; -#if !defined(__WXUNIVERSAL__) && !defined(__WXMOTIF__) && !(defined(__WXGTK__) && !defined(__WXGTK20__)) +#ifdef wxHAVE_BITMAPS_IN_BUTTON if (m_class == wxT("wxBitmapToggleButton")) { @@ -78,16 +82,18 @@ void wxToggleButtonXmlHandler::DoCreateToggleButton(wxObject *control) wxDefaultValidator, GetName()); +#ifdef wxHAVE_BITMAPS_IN_BUTTON if ( GetParamNode("bitmap") ) { button->SetBitmap(GetBitmap("bitmap", wxART_BUTTON), GetDirection("bitmapposition")); } - +#endi + button->SetValue(GetBool( wxT("checked"))); } -#if !defined(__WXUNIVERSAL__) && !defined(__WXMOTIF__) && !(defined(__WXGTK__) && !defined(__WXGTK20__)) +#ifdef wxHAVE_BITMAPS_IN_BUTTON void wxToggleButtonXmlHandler::DoCreateBitmapToggleButton(wxObject *control) { wxBitmapToggleButton *button = wxDynamicCast(control, wxBitmapToggleButton); From c03364149dc9d0a56677c9b2697d97317ee419e7 Mon Sep 17 00:00:00 2001 From: Jouk Date: Tue, 20 Jun 2017 10:18:22 +0200 Subject: [PATCH 07/10] correct typo in previous commit --- src/xrc/xh_tglbtn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xrc/xh_tglbtn.cpp b/src/xrc/xh_tglbtn.cpp index 9b33a47471..983b0f8f11 100644 --- a/src/xrc/xh_tglbtn.cpp +++ b/src/xrc/xh_tglbtn.cpp @@ -88,7 +88,7 @@ void wxToggleButtonXmlHandler::DoCreateToggleButton(wxObject *control) button->SetBitmap(GetBitmap("bitmap", wxART_BUTTON), GetDirection("bitmapposition")); } -#endi +#endif button->SetValue(GetBool( wxT("checked"))); } From a2af796156583987df5069b3aef9646b31db5800 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Jun 2017 14:06:13 +0200 Subject: [PATCH 08/10] Remove outdated comment about wxListCtrl checkboxes support They're implemented in the generic version too, so don't say that they're MSW-only. No real changes. --- include/wx/listbase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/listbase.h b/include/wx/listbase.h index 54f18888de..02f54a47c5 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -414,7 +414,7 @@ public: // Header attributes support: only implemented in wxMSW currently. virtual bool SetHeaderAttr(const wxItemAttr& WXUNUSED(attr)) { return false; } - // Checkboxes support: only implemented in wxMSW currently. + // Checkboxes support. virtual bool HasCheckBoxes() const { return false; } virtual bool EnableCheckBoxes(bool WXUNUSED(enable) = true) { return false; } virtual bool IsItemChecked(long WXUNUSED(item)) const { return false; } From e121e8addb22b0dd0f7e106ba89ae04c43850886 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 20 Jun 2017 15:32:00 +0200 Subject: [PATCH 09/10] Check for view presence in wxDocument::RemoveView() Return false and avoid calling OnChangedViewList() if the view wasn't present in the first place. This is not, strictly speaking, backwards compatible, but most of the existing code doesn't seem to check the return value of RemoveView() at all and it's hard to imagine that someone would rely on it returning true when removing a non-existent view, so in practice this changes seems to be safe. Closes #17888. --- interface/wx/docview.h | 8 ++++++-- src/common/docview.cpp | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/wx/docview.h b/interface/wx/docview.h index b4670d759d..ed74d5d320 100644 --- a/interface/wx/docview.h +++ b/interface/wx/docview.h @@ -1530,8 +1530,12 @@ public: virtual bool OnSaveModified(); /** - Removes the view from the document's list of views, and calls - OnChangedViewList(). + Removes the view from the document's list of views. + + If the view was really removed, also calls OnChangedViewList(). + + @return @true if the view was removed or @false if the document didn't + have this view in the first place. */ virtual bool RemoveView(wxView* view); diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 176c53444c..5be66f1190 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -570,7 +570,9 @@ bool wxDocument::AddView(wxView *view) bool wxDocument::RemoveView(wxView *view) { - (void)m_documentViews.DeleteObject(view); + if ( !m_documentViews.DeleteObject(view) ) + return false; + OnChangedViewList(); return true; } From 8b1381f2b1f1a7a0ed5dfd15482e70475351a18c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 20 Jun 2017 17:55:26 +0200 Subject: [PATCH 10/10] OSX use fontAttributes for better emulation of bold fonts (#501) * using fontAttributes dictionary allows for better emulation of bold typefaces, also switch to using color from context, this allows keeping the same dict throughout, as a side effect fix font caching * reverting in order to maintain crossplatform compatibility * applying review suggestions * applying review suggestions --- include/wx/defs.h | 1 + include/wx/osx/font.h | 1 + src/osx/carbon/font.cpp | 63 ++++++++++++++++++++++++++++++++++--- src/osx/carbon/graphics.cpp | 37 ++++++---------------- 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index f21937cd23..1f3b1724dc 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2943,6 +2943,7 @@ typedef const void * CFTypeRef; DECLARE_WXOSX_OPAQUE_CONST_CFREF( CFString ) typedef struct __CFString * CFMutableStringRef; +DECLARE_WXOSX_OPAQUE_CONST_CFREF( CFDictionary ) DECLARE_WXOSX_OPAQUE_CFREF( CFRunLoopSource ) DECLARE_WXOSX_OPAQUE_CONST_CFREF( CTFont ) diff --git a/include/wx/osx/font.h b/include/wx/osx/font.h index b82e948001..e32e7d7b63 100644 --- a/include/wx/osx/font.h +++ b/include/wx/osx/font.h @@ -144,6 +144,7 @@ public: #endif CTFontRef OSXGetCTFont() const; + CFDictionaryRef OSXGetCTFontAttributes() const; #if wxOSX_USE_COCOA WX_NSFont OSXGetNSFont() const; diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index fe0b259c46..5180ab66c9 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -158,6 +158,7 @@ protected: public: bool m_fontValid; wxCFRef m_ctFont; + wxCFRef m_ctFontAttributes; wxCFRef m_cgFont; #if wxOSX_USE_COCOA WX_NSFont m_nsFont; @@ -176,6 +177,7 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) : wxGDIRefData() m_info = data.m_info; m_fontValid = data.m_fontValid; m_ctFont = data.m_ctFont; + m_ctFontAttributes = data.m_ctFontAttributes; m_cgFont = data.m_cgFont; #if wxOSX_USE_COCOA m_nsFont = (NSFont*) wxMacCocoaRetain(data.m_nsFont); @@ -271,6 +273,11 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) break; } m_ctFont.reset(CTFontCreateUIFontForLanguage( uifont, (CGFloat) size, NULL )); + CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + m_ctFontAttributes.reset(dict); + CFDictionarySetValue(dict, kCTFontAttributeName, m_ctFont.get() ); + CFDictionarySetValue(dict, kCTForegroundColorFromContextAttributeName, kCFBooleanTrue); + wxCFRef descr; descr.reset( CTFontCopyFontDescriptor( m_ctFont ) ); m_info.Init(descr); @@ -288,6 +295,16 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) static const CGAffineTransform kSlantTransform = CGAffineTransformMake( 1, 0, tan(wxDegToRad(11)), 1, 0, 0 ); +namespace +{ + +struct CachedFontEntry { + wxCFRef< CTFontRef > font; + wxCFRef< CFDictionaryRef > fontAttributes; +} ; + +} // anonymous namespace + void wxFontRefData::MacFindFont() { if ( m_fontValid ) @@ -306,10 +323,19 @@ void wxFontRefData::MacFindFont() // use font caching wxString lookupnameWithSize = wxString::Format( "%s_%u_%d", m_info.m_faceName, traits, m_info.m_pointSize ); - static std::map< std::wstring , wxCFRef< CTFontRef > > fontcache ; - m_ctFont = fontcache[ std::wstring(lookupnameWithSize.wc_str()) ]; - if ( !m_ctFont ) + static std::map< wxString, CachedFontEntry > fontcache ; + + CachedFontEntry& entry = fontcache[ lookupnameWithSize ]; + m_ctFont = entry.font; + m_ctFontAttributes = entry.fontAttributes; + if ( m_ctFont ) { + // use cached version + } + else + { + CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + m_ctFontAttributes.reset(dict); wxStringToStringHashMap::const_iterator it = gs_FontFamilyToPSName.find(m_info.m_faceName); @@ -350,11 +376,23 @@ void wxFontRefData::MacFindFont() fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, remainingTransform, remainingTraits, remainingTraits ); if ( fontWithTraits == NULL ) { - // give in on the bold, try native oblique + // try native oblique, emulate bold later fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, NULL, kCTFontItalicTrait, kCTFontItalicTrait ); } + else + { + remainingTraits &= ~kCTFontBoldTrait; + } } } + + // we have to emulate bold + if ( remainingTraits & kCTFontBoldTrait ) + { + // 3 times as thick, negative value because we want effect on stroke and fill (not only stroke) + const float strokewidth = -3.0; + CFDictionarySetValue(dict, kCTStrokeWidthAttributeName, CFNumberCreate( NULL, kCFNumberFloatType, &strokewidth)); + } if ( fontWithTraits == NULL ) { @@ -366,6 +404,11 @@ void wxFontRefData::MacFindFont() m_ctFont.reset(fontWithTraits); } } + CFDictionarySetValue(dict, kCTFontAttributeName, m_ctFont.get() ); + CFDictionarySetValue(dict, kCTForegroundColorFromContextAttributeName, kCFBooleanTrue); + + entry.font = m_ctFont; + entry.fontAttributes = m_ctFontAttributes; } m_cgFont.reset(CTFontCopyGraphicsFont(m_ctFont, NULL)); @@ -378,7 +421,7 @@ void wxFontRefData::MacFindFont() #endif m_fontValid = true; } - + bool wxFontRefData::IsFixedWidth() const { CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(m_ctFont); @@ -659,6 +702,16 @@ CTFontRef wxFont::OSXGetCTFont() const return (CTFontRef)(M_FONTDATA->m_ctFont); } +CFDictionaryRef wxFont::OSXGetCTFontAttributes() const +{ + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); + + // cast away constness otherwise lazy font resolution is not possible + const_cast(this)->RealizeResource(); + + return (CFDictionaryRef)(M_FONTDATA->m_ctFontAttributes); +} + #if wxOSX_USE_COCOA_OR_CARBON CGFontRef wxFont::OSXGetCGFont() const diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 033d6ee6a1..5d2492554b 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -824,6 +824,7 @@ public: ~wxMacCoreGraphicsFontData(); CTFontRef OSXGetCTFont() const { return m_ctFont ; } + CFDictionaryRef OSXGetCTFontAttributes() const { return m_ctFontAttributes; } wxColour GetColour() const { return m_colour ; } bool GetUnderlined() const { return m_underlined ; } @@ -837,6 +838,7 @@ private : bool m_underlined, m_strikethrough; wxCFRef< CTFontRef > m_ctFont; + wxCFRef< CFDictionaryRef > m_ctFontAttributes; #if wxOSX_USE_IPHONE UIFont* m_uiFont; #endif @@ -849,6 +851,7 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere m_strikethrough = font.GetStrikethrough(); m_ctFont.reset( wxMacCreateCTFont( font ) ); + m_ctFontAttributes.reset( wxCFRetain( font.OSXGetCTFontAttributes() ) ); #if wxOSX_USE_IPHONE m_uiFont = CreateUIFont(font); wxMacCocoaRetain( m_uiFont ); @@ -2220,21 +2223,10 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); wxCFStringRef text(str, wxLocale::GetSystemEncoding() ); - CTFontRef font = fref->OSXGetCTFont(); CGColorRef col = wxMacCreateCGColor( fref->GetColour() ); -#if 0 - // right now there's no way to get continuous underlines, only words, so we emulate it - CTUnderlineStyle ustyle = fref->GetUnderlined() ? kCTUnderlineStyleSingle : kCTUnderlineStyleNone ; - wxCFRef underlined( CFNumberCreate(NULL, kCFNumberSInt32Type, &ustyle) ); - CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName, kCTUnderlineStyleAttributeName }; - CFTypeRef values[] = { font, col, underlined }; -#else - CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName }; - CFTypeRef values[] = { font, col }; -#endif - wxCFRef attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values, - WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) ); - wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) ); + CTFontRef font = fref->OSXGetCTFont(); + + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, fref->OSXGetCTFontAttributes()) ); wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); y += CTFontGetAscent(font); @@ -2246,6 +2238,7 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo CGContextScaleCTM(m_cgContext, 1, -1); CGContextSetTextMatrix(m_cgContext, CGAffineTransformIdentity); + CGContextSetFillColorWithColor( m_cgContext, col ); CTLineDraw( line, m_cgContext ); if ( fref->GetUnderlined() ) { @@ -2316,14 +2309,10 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid strToMeasure = wxS(" "); wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); - CTFontRef font = fref->OSXGetCTFont(); wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() ); - CFStringRef keys[] = { kCTFontAttributeName }; - CFTypeRef values[] = { font }; - wxCFRef attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values, - WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) ); - wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) ); + + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, fref->OSXGetCTFontAttributes() ) ); wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); CGFloat a, d, l, w; @@ -2336,7 +2325,6 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid if ( height ) *height = a+d+l; } - if ( descent ) *descent = d; if ( externalLeading ) @@ -2355,14 +2343,9 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr return; wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); - CTFontRef font = fref->OSXGetCTFont(); wxCFStringRef t(text, wxLocale::GetSystemEncoding() ); - CFStringRef keys[] = { kCTFontAttributeName }; - CFTypeRef values[] = { font }; - wxCFRef attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values, - WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) ); - wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, t, attributes) ); + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, t, fref->OSXGetCTFontAttributes()) ); wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); widths.reserve(text.length());