Use GetMark if available

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32535 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2005-03-01 16:22:31 +00:00
parent ddc548ec77
commit b0f3dd44e4

View File

@@ -443,41 +443,45 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
wx.ComboBox.Append( self, choice ) wx.ComboBox.Append( self, choice )
def GetMark(self): # Not all wx platform implementations have .GetMark, so we make the following test,
""" # and fall back to our old hack if they don't...
This function is a hack to make up for the fact that wx.ComboBox has no #
method for returning the selected portion of its edit control. It if not hasattr(wx.ComboBox, 'GetMark'):
works, but has the nasty side effect of generating lots of intermediate def GetMark(self):
events. """
""" This function is a hack to make up for the fact that wx.ComboBox has no
## dbg(suspend=1) # turn off debugging around this function method for returning the selected portion of its edit control. It
## dbg('MaskedComboBox::GetMark', indent=1) works, but has the nasty side effect of generating lots of intermediate
if self.__readonly: events.
## dbg(indent=0) """
return 0, 0 # no selection possible for editing ## dbg(suspend=1) # turn off debugging around this function
## sel_start, sel_to = wxComboBox.GetMark(self) # what I'd *like* to have! ## dbg('MaskedComboBox::GetMark', indent=1)
sel_start = sel_to = self.GetInsertionPoint() if self.__readonly:
## dbg("current sel_start:", sel_start) ## dbg(indent=0)
value = self.GetValue() return 0, 0 # no selection possible for editing
## dbg('value: "%s"' % value) ## sel_start, sel_to = wxComboBox.GetMark(self) # what I'd *like* to have!
sel_start = sel_to = self.GetInsertionPoint()
## dbg("current sel_start:", sel_start)
value = self.GetValue()
## dbg('value: "%s"' % value)
self._ignoreChange = True # tell _OnTextChange() to ignore next event (if any) self._ignoreChange = True # tell _OnTextChange() to ignore next event (if any)
wx.ComboBox.Cut(self) wx.ComboBox.Cut(self)
newvalue = self.GetValue() newvalue = self.GetValue()
## dbg("value after Cut operation:", newvalue) ## dbg("value after Cut operation:", newvalue)
if newvalue != value: # something was selected; calculate extent if newvalue != value: # something was selected; calculate extent
## dbg("something selected") ## dbg("something selected")
sel_to = sel_start + len(value) - len(newvalue) sel_to = sel_start + len(value) - len(newvalue)
wx.ComboBox.SetValue(self, value) # restore original value and selection (still ignoring change) wx.ComboBox.SetValue(self, value) # restore original value and selection (still ignoring change)
wx.ComboBox.SetInsertionPoint(self, sel_start) wx.ComboBox.SetInsertionPoint(self, sel_start)
wx.ComboBox.SetMark(self, sel_start, sel_to) wx.ComboBox.SetMark(self, sel_start, sel_to)
self._ignoreChange = False # tell _OnTextChange() to pay attn again self._ignoreChange = False # tell _OnTextChange() to pay attn again
## dbg('computed selection:', sel_start, sel_to, indent=0, suspend=0) ## dbg('computed selection:', sel_start, sel_to, indent=0, suspend=0)
return sel_start, sel_to return sel_start, sel_to
def SetSelection(self, index): def SetSelection(self, index):
@@ -635,6 +639,11 @@ class PreMaskedComboBox( BaseMaskedComboBox, MaskedEditAccessorsMixin ):
__i = 0 __i = 0
## CHANGELOG: ## CHANGELOG:
## ==================== ## ====================
## Version 1.3
## 1. Made definition of "hack" GetMark conditional on base class not
## implementing it properly, to allow for migration in wx code base
## while taking advantage of improvements therein for some platforms.
##
## Version 1.2 ## Version 1.2
## 1. Converted docstrings to reST format, added doc for ePyDoc. ## 1. Converted docstrings to reST format, added doc for ePyDoc.
## 2. Renamed helper functions, vars etc. not intended to be visible in public ## 2. Renamed helper functions, vars etc. not intended to be visible in public