Permalink
Browse files

Fix behaviour of textEntry and entry controls on OSX.

See #1 (comment)

It seems that using the wxTE_RICH attribute in textEntry and entry causes a multi-line text control style to be created by default on OS X. This is new behaviour on wxWidgets 2.9.x.

This patch makes the wxTE_RICH and wxTE_RICH2 attribute settings dependent on the host OS (only sets them on Windows)

This patch also fixes bugs associated with the use of textCtrlClear followed by textCtrlWriteText, reported in the same issue.

Note that this does not fix the problem that the textColor attribute is not respected.
  • Loading branch information...
1 parent 3a6d05e commit f225d0c3b4e014c91606a8af70ab47aca5534099 @jodonoghue committed Apr 20, 2012
@@ -77,6 +77,7 @@ import Graphics.UI.WX.Window
import Control.Monad (forM_)
import Data.Dynamic -- for "alignment"
+import System.Info (os)
defaultStyle
@@ -315,15 +316,27 @@ instance Able (TextCtrl a) where
= newAttr "enabled" textCtrlIsEditable textCtrlSetEditable
-}
+-- Workaround for Unexpected TextCtrl behaviour (https://github.com/jodonoghue/wxHaskell/issues/1#issuecomment-5202439)
+-- Problem arises from the fact that wxTE_RICH is needed only on Windows platforms, but is essential there. However, on
+-- wxMac > 2.9, wxTE_RICH seems not to be ignored as the documentation claims.
+getRichTE = if (os == "mingw32") || (os == "win32")
+ then wxTE_RICH
+ else 0
+
+getRichTE2 = if (os == "mingw32") || (os == "win32")
+ then wxTE_RICH2
+ else 0
+
-- | Create a single-line text entry control. Note: 'alignment' has to
-- be set at creation time (or the entry has default alignment (=left) ).
+-- This is an alias for textEntry
--
-- * Instances: 'Wrap', 'Aligned', 'Commanding' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
entry :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
entry parent props
- = textCtrlEx parent wxTE_RICH props
+ = textCtrlEx parent getRichTE props
-- | Create a single-line text entry control. Note: 'alignment' has to
-- be set at creation time (or the entry has default alignment (=left) ).
@@ -333,7 +346,7 @@ entry parent props
--
textEntry :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
textEntry parent props
- = textCtrlEx parent wxTE_RICH props
+ = textCtrlEx parent getRichTE props
-- | Create a multi-line text control. Note: the 'wrap' and 'alignment'
-- have to be set at creation time or the default to 'WrapNone' and 'AlignLeft' respectively.
@@ -343,7 +356,7 @@ textEntry parent props
--
textCtrl :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
textCtrl parent props
- = textCtrlEx parent (wxTE_MULTILINE .+. wxTE_RICH) props
+ = textCtrlEx parent (wxTE_MULTILINE .+. getRichTE) props
-- | Create a multi-line text rich-text control with a certain wrap mode
@@ -356,7 +369,7 @@ textCtrl parent props
--
textCtrlRich :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
textCtrlRich parent props
- = textCtrlEx parent (wxTE_MULTILINE .+. wxTE_RICH2) props
+ = textCtrlEx parent (wxTE_MULTILINE .+. getRichTE2) props
-- | Create a generic text control given a certain style.
--
@@ -367,9 +380,10 @@ textCtrlEx :: Window a -> Style -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
textCtrlEx parent stl props
= feed2 props stl $
initialWindow $ \id rect ->
+ initialText $ \txt ->
initialWrap $
initialAlignment $ \props flags ->
- do e <- textCtrlCreate parent id "" rect flags
+ do e <- textCtrlCreate parent id txt rect flags
set e props
return e
@@ -131,7 +131,7 @@ instance Textual (Window a) where
= ifInstanceOf w classComboBox
(\cb -> (comboBoxGetValue cb, \s -> do comboBoxClear cb; comboBoxAppend cb s)) $
ifInstanceOf w classTextCtrl
- (\tc -> (textCtrlGetValue tc, \s -> do textCtrlClear tc; textCtrlWriteText tc s)) $
+ (\tc -> (textCtrlGetValue tc, \s -> do textCtrlChangeValue tc s)) $
(windowGetLabel w,windowSetLabel w)
appendText w s
View
@@ -1,5 +1,5 @@
Name: wx
-Version: 0.90
+Version: 0.90.0.1
License: OtherLicense
License-file: license.txt
Homepage: http://haskell.org/haskellwiki/WxHaskell
@@ -19,6 +19,11 @@ EWXWEXPORT(void,wxTextCtrl_SetValue)(wxTextCtrl* self,wxString* value)
{
self->SetValue(*value);
}
+
+EWXWEXPORT(void,wxTextCtrl_ChangeValue)(wxTextCtrl* self, wxString* value)
+{
+ self->ChangeValue(*value);
+}
EWXWEXPORT(int,wxTextCtrl_GetLineLength)(wxTextCtrl* self,long lineNo)
{
@@ -4541,6 +4541,7 @@ TBool wxTextCtrl_CanCut( TSelf(wxTextCtrl) _obj );
TBool wxTextCtrl_CanCopy( TSelf(wxTextCtrl) _obj );
TBool wxTextCtrl_CanCut( TSelf(wxTextCtrl) _obj );
TBool wxTextCtrl_CanPaste( TSelf(wxTextCtrl) _obj );
+TBool wxTextCtrl_CanRedo( TSelf(wxTextCtrl) _obj );
TBool wxTextCtrl_CanUndo( TSelf(wxTextCtrl) _obj );
void wxTextCtrl_ChangeValue( TSelf(wxTextCtrl) _obj, TClass(wxString) text );
void wxTextCtrl_Clear( TSelf(wxTextCtrl) _obj );
View
@@ -1,5 +1,5 @@
name: wxc
-version: 0.90.0.2
+version: 0.90.0.3
license: OtherLicense
license-file: LICENSE
maintainer: wxhaskell-devel@lists.sourceforge.net

0 comments on commit f225d0c

Please sign in to comment.