Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
Created a new class Updating with corresponding event "update". Provided
Browse files Browse the repository at this point in the history
instances for TextCtrl and ComboBox: update gets called when the text changes.
I might make additional instances if I see other appropriate applications.

Signed-off-by: Pamelloes <pamelloes@gmail.com>
  • Loading branch information
Pamelloes committed May 25, 2015
1 parent 02655ca commit 1c05768
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 15 additions & 8 deletions wx/src/Graphics/UI/WX/Controls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ getRichTE2 = if (os == "mingw32") || (os == "win32")
-- 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',
-- * Instances: 'Wrap', 'Aligned', 'Commanding', 'Updating' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
entry :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
Expand All @@ -356,7 +356,7 @@ entry parent props
-- | Create a single-line text entry control. Note: 'alignment' has to
-- be set at creation time (or the entry has default alignment (=left) ).
--
-- * Instances: 'Wrap', 'Aligned', 'Commanding' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- * Instances: 'Wrap', 'Aligned', 'Commanding', 'Updating' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
textEntry :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
Expand All @@ -366,7 +366,7 @@ textEntry parent 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.
--
-- * Instances: 'Wrap', 'Aligned', 'Commanding' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- * Instances: 'Wrap', 'Aligned', 'Commanding', 'Updating' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
textCtrl :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
Expand All @@ -379,7 +379,7 @@ textCtrl parent props
-- on other platforms. Note: the 'wrap' and 'alignment'
-- have to be set at creation time or the default to 'WrapNone' and 'AlignLeft' respectively.
--
-- * Instances: 'Wrap', 'Aligned', 'Commanding' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- * Instances: 'Wrap', 'Aligned', 'Commanding', 'Updating' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
textCtrlRich :: Window a -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
Expand All @@ -388,7 +388,7 @@ textCtrlRich parent props

-- | Create a generic text control given a certain style.
--
-- * Instances: 'Wrap', 'Aligned', 'Commanding' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- * Instances: 'Wrap', 'Aligned', 'Commanding', 'Updating' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
textCtrlEx :: Window a -> Style -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
Expand All @@ -405,7 +405,7 @@ textCtrlEx parent stl props
-- | Complete the construction of a text control instance which has been loaded
-- from a resource file.
--
-- * Instances: 'Wrap', 'Aligned', 'Commanding' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- * Instances: 'Wrap', 'Aligned', 'Commanding', 'Updating' -- 'Textual', 'Literate', 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
textCtrlRes :: Window a -> String -> [Prop (TextCtrl ())] -> IO (TextCtrl ())
Expand All @@ -414,6 +414,9 @@ textCtrlRes parent name props =
set t props
return t

instance Updating (TextCtrl a) where
update = newEvent "update" controlGetOnText controlOnText

instance Commanding (TextCtrl a) where
command = newEvent "command" textCtrlGetOnTextEnter textCtrlOnTextEnter

Expand Down Expand Up @@ -634,6 +637,10 @@ instance Commanding (ComboBox a) where
command
= newEvent "command" comboBoxGetOnTextEnter comboBoxOnTextEnter

instance Updating (ComboBox a) where
update
= newEvent "update" controlGetOnText controlOnText

instance Selecting (ComboBox a) where
select
= newEvent "select" comboBoxGetOnCommand comboBoxOnCommand
Expand Down Expand Up @@ -661,7 +668,7 @@ instance Items (ComboBox a) String where

-- | Create a new combo box.
--
-- * Instances: 'Selecting', 'Commanding','Selection','Items' -- 'Textual', 'Literate', 'Dimensions',
-- * Instances: 'Selecting', 'Commanding', 'Updating', 'Selection', 'Items' -- 'Textual', 'Literate', 'Dimensions',
-- 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
Expand All @@ -674,7 +681,7 @@ comboBox parent props

-- | Create a new combo box with a given set of flags.
--
-- * Instances: 'Selecting', 'Commanding','Selection','Items' -- 'Textual', 'Literate', 'Dimensions',
-- * Instances: 'Selecting', 'Commanding', 'Updating', 'Selection', 'Items' -- 'Textual', 'Literate', 'Dimensions',
-- 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled', 'Reactive', 'Paint'.
--
Expand Down
11 changes: 10 additions & 1 deletion wx/src/Graphics/UI/WX/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ module Graphics.UI.WX.Events
, Selecting, select
-- ** Commanding
, Commanding, command
-- ** Updating
, Updating, update
-- ** Reactive
, Reactive
, mouse, keyboard
Expand Down Expand Up @@ -152,6 +154,13 @@ class Commanding w where
-- | A commanding event, for example a button press.
command :: Event w (IO ())

-- | 'Updating' widgets fire an 'update' event.
class Updating w where
-- | An update event, for example when the text of a 'TextCtrl' changes.
-- An update event, unlike a 'command' event, is typically a passive state
-- change and doesn't require a response.
update :: Event w (IO ())

-- | 'Reactive' widgets are almost all visible widgets on the screen.
class Reactive w where
mouse :: Event w (EventMouse -> IO ())
Expand Down Expand Up @@ -369,4 +378,4 @@ auiNotebookOnPageChangedEvent = newAuiEvent "auiNotebookOnPageChanged" wxEVT_AUI
-- | Create a new event from a get and set function.
newEvent :: String -> (w -> IO a) -> (w -> a -> IO ()) -> Event w a
newEvent name getter setter
= Event (newAttr name getter setter)
= Event (newAttr name getter setter)

0 comments on commit 1c05768

Please sign in to comment.