Avoid duplicate wxEVT_SEARCHCTRL_CANCEL_BTN event under macOS

see https://github.com/wxWidgets/wxWidgets/pull/698 , along the idea by commit 1776f136f7d673c8e772c9ca6e1607089a071651, implemented a little bit more defensively
This commit is contained in:
Stefan Csomor
2018-01-30 17:17:47 +01:00
parent ae8bc4e263
commit 5f21280130

View File

@@ -30,6 +30,7 @@
@interface wxNSSearchField : NSSearchField
{
BOOL m_withinTextDidChange;
}
@end
@@ -48,10 +49,20 @@
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if ( self = [super initWithFrame:frame] )
{
m_withinTextDidChange = NO;
}
return self;
}
- (void)textDidChange:(NSNotification *)aNotification
{
m_withinTextDidChange = YES;
[super textDidChange:aNotification];
m_withinTextDidChange = NO;
}
- (void)controlTextDidChange:(NSNotification *)aNotification
{
wxUnusedVar(aNotification);
@@ -84,6 +95,11 @@
return matches;
}
- (BOOL) isWithinTextDidChange
{
return m_withinTextDidChange;
}
@end
// ============================================================================
@@ -157,7 +173,8 @@ public :
NSString *searchString = [m_searchField stringValue];
if ( searchString == nil || !searchString.length )
{
wxpeer->HandleSearchFieldCancelHit();
if ( ![m_searchField isWithinTextDidChange])
wxpeer->HandleSearchFieldCancelHit();
}
else
{