Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed to Consumed/NotConsumed in all files

  • Loading branch information...
commit d8e85d3acf5cf412a84c1c8dc92f67f17fbb8cc7 1 parent 0e2dfb8
@andreykruglyak andreykruglyak authored
View
17 COCOA.t
@@ -9,14 +9,12 @@ private
cocoaApplication :: Class App
cocoaApplication = class
activeWindows := []
- blockDefaultCocoaBehavior := False
-
+ modifiers := []
+
addWindow w = request
w.initWindow this
activeWindows := w:activeWindows
- modifiers := []
-
sendInputEvent (KeyEvent k) windowId = request
name = case k of
(KeyPressed n) -> n
@@ -28,17 +26,18 @@ cocoaApplication = class
Command -> updateList name
_ ->
sendInputToWindow (KeyEvent k) windowId
- result False -- Let keys pass through so that they appear in text fields etc.
+ {- Let key events pass through so that they appear in text fields etc. -}
+ result NotConsumed
sendInputEvent (MouseEvent m) windowId = request
sendInputToWindow (MouseEvent m) windowId
-
case m of
- (MouseWheelScroll _ _ _) -> result True -- Block scroll since we control it in Timber instead.
- _ -> result blockDefaultCocoaBehavior
+ {- Block scrolling events since we control them in Timber instead -}
+ (MouseWheelScroll _ _ _) -> result Consumed
+ _ -> result NotConsumed
sendInputEvent _ _ = request
- result blockDefaultCocoaBehavior
+ result NotConsumed
sendInputToWindow recvEvent windowId = do
forall window <- activeWindows do
View
8 CTContainer.t
@@ -30,7 +30,7 @@ mkCocoaContainer w = class
getAllChildren = request
cs <- forall c <- myComponents do
list <- c.getAllChildren
- result list ++ [c] -- order is important here (for reactions to mouse events)
+ result list ++ [c] -- order is important here for reactions to mouse events
result concat cs
setBackgroundColor c = request
@@ -113,11 +113,11 @@ basicHasResponders = class
getResponders = request
result responders
-- return true (block cocoa) if any of the installed responders say so
- returnVal := False
+ returnVal := NotConsumed
respondToInputEvent inputEvent modifiers = request
- returnVal := False
+ returnVal := NotConsumed
forall h <- responders do
- if returnVal == False then
+ if returnVal == NotConsumed then
returnVal := <- h.respondToInputEvent inputEvent modifiers
result returnVal
result DefaultEventResponder {..}
View
6 CTDropDown.t
@@ -100,7 +100,7 @@ data SizeState = Small | Expanded
defaultHandler dropdownUpdateMethod = class
sizeState := Small
respondToInputEvent (KeyEvent t) modifiers = request
- result False
+ result NotConsumed
respondToInputEvent (MouseEvent t) modifiers = request
case t of
MouseClicked pos ->
@@ -111,9 +111,9 @@ defaultHandler dropdownUpdateMethod = class
sizeState := Small
dropdownUpdateMethod
_ ->
- result True
+ result Consumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
--------------------------------------------------------------------------------------------------
View
4 CTTextArea.t
@@ -90,10 +90,10 @@ defaultTextScrollResponder textArea = class
MouseWheelScroll pos deltaX deltaY ->
scrollTo deltaX deltaY
_ ->
- result True
+ result Consumed
respondToInputEvent _ _ = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
10 CTWindow.t
@@ -18,7 +18,7 @@ mkCocoaWindow w = class
respondToInputEvent e m = request
respond e m
- result False -- do not block Cocoa from processing events
+ result NotConsumed -- do not block Cocoa from processing events
respond = new class
act e m = action
@@ -175,9 +175,9 @@ defaultInputResponder window rootContainer = class
window.setFocus rootContainer
-- first let the current focus target be able to consume the event
- consumed <- currentFocus.respondToInputEvent (KeyEvent keyEventType) modifiers
+ res <- currentFocus.respondToInputEvent (KeyEvent keyEventType) modifiers
- if (not consumed) then
+ if res == NotConsumed then
if tabPressed keyEventType then
-- the focused component did not consume the event AND it was a tab-event.
@@ -202,7 +202,7 @@ defaultInputResponder window rootContainer = class
window.setFocus (head listToScan)
-- TODO: Allow menu to consume key events
- result False
+ result NotConsumed
respondToInputEvent (MouseEvent me) modifiers = request
{- default implementation of mouse event dispatching, that "flattens out" the component-structure to a list where the first component is the component that was added last. the list is then traversed and each component that contains the point of the event inside its coordinates is given the possibility to consume it until one component has consumed it. -}
@@ -242,7 +242,7 @@ defaultInputResponder window rootContainer = class
isFocusable <- cmp.getIsFocusable
if (isMouseClick event && isFocusable) then
window.setFocus cmp
- result (<- cmp.respondToInputEvent (MouseEvent eventInLocalCoords) modifiers)
+ result isConsumed (<- cmp.respondToInputEvent (MouseEvent eventInLocalCoords) modifiers)
else
result False
View
24 CocoaDef.t
@@ -7,9 +7,11 @@ struct App < AppImpl where
addWindow :: CocoaWindow -> Request ()
struct AppImpl where
- sendInputEvent :: InputEvent -> WindowID -> Request Bool -- True: consumed (should not be handled by Cocoa), False: not consumed
+ {- a consumed event should not be handled by Cocoa -}
+ sendInputEvent :: InputEvent -> WindowID -> Request Consumed
sendWindowResize :: Size -> WindowID -> Request ()
- sendWindowCloseRequest :: WindowID -> Request Bool -- True: close window, False: ignore request
+ {- True: close window, False: ignore close request -}
+ sendWindowCloseRequest :: WindowID -> Request Bool
struct CocoaWindow < RespondsToWindowEvents, RespondsToInputEvents, HasSize, HasBackgroundColor,
ContainsComponents, HasTitle, HasResponders, HasWindowResponder, IsResizable where
@@ -66,16 +68,26 @@ struct HasResponders where
getResponders :: Request [RespondsToInputEvents]
struct RespondsToInputEvents where
- respondToInputEvent :: InputEvent -> Modifiers -> Request Bool
+ respondToInputEvent :: InputEvent -> Modifiers -> Request Consumed
data Consumed = Consumed | NotConsumed -- Consumed(1) = True(1)
+instance eqConsumed :: Eq Consumed where
+ (==) Consumed Consumed = True
+ (==) NotConsumed NotConsumed = True
+ (==) _ _ = False
+ (/=) a b = not (a == b)
+
+isConsumed Consumed = True
+isConsumed _ = False
+
struct HasWindowResponder where
- setWindowResponder :: RespondsToWindowEvents -> Bool -> Request ()
+ setWindowResponder :: RespondsToWindowEvents -> Bool -> Request ()
struct RespondsToWindowEvents where
onWindowResize :: Size -> Request ()
- onWindowCloseRequest :: Request Bool -- True: close window, False: ignore request
+ {- True: close window, False: ignore close request -}
+ onWindowCloseRequest :: Request Bool
struct DefaultEventResponder < HasResponders, RespondsToInputEvents
@@ -83,7 +95,7 @@ struct HasSelectionResponder where
setSelectionResponder :: RespondsToSelectionEvents -> Request ()
struct RespondsToSelectionEvents where
- selectionChanged :: String -> Action
+ selectionChanged :: String -> Action
struct Position where
x :: Int
View
4 Makefile
@@ -10,5 +10,9 @@ test:
timberc --make Tutorial4MultipleWindows
timberc --make Tutorial5ComponentCreation
+demo:
+ timberc --make Tetris
+ timberc --make Paint
+
clean:
./cleanFolder
View
4 Paint.t
@@ -38,10 +38,10 @@ paintHandler w1 label w = class
w1.removeComponent pixel
_ ->
- result False
+ result NotConsumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
4 TestButton.t
@@ -35,7 +35,7 @@ root w = class
buttonClickHandler otherButton = class
respondToInputEvent (MouseEvent (MouseClicked _)) _ = request
otherButton.setSize ({width=200;height=150})
- result True
+ result Consumed
respondToInputEvent _ _ = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
2  TestFocusHierarchy.t
@@ -1,7 +1,7 @@
module TestFocusHierarchy where
import POSIX
-import COCOAttt
+import COCOA
import CTButton
positions = [(200, 100), (140, 140), (80, 180), (80, 220), (140, 260),
View
8 Tetris.t
@@ -27,8 +27,7 @@ root w = class
case event of
(KeyEvent (KeyPressed theKey)) ->
case (theKey) of
- A ->
- gu.movePiece (-1) 0
+ A -> gu.movePiece (-1) 0
gameGrid.update
S -> gu.movePiece 0 1
gameGrid.update
@@ -38,7 +37,7 @@ root w = class
gameGrid.update
_ ->
_ ->
- result False
+ result NotConsumed
started := False
newGameResponder event modifiers = request
@@ -48,9 +47,8 @@ root w = class
started := True
send gameLoop env
send action gameWindow.addResponder ({respondToInputEvent=keyboardResponder})
-
_ ->
- result False
+ result NotConsumed
gameLoop env = action
if (not (<- gu.checkGameOver)) then
View
4 Tutorial1ComponentsAndHierarchies.t
@@ -64,7 +64,7 @@ eventHandler test write s = class
if (test e) then
clickCount := clickCount + 1
write (s ++ show clickCount ++ "\n")
- result True
+ result Consumed
else
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
6 Tutorial2Resizing.t
@@ -81,12 +81,12 @@ buttonHandler label env = class
MouseClicked pos ->
clickCount := clickCount + 1
label.setText ("Click #" ++ show clickCount)
- result True
+ result Consumed
_ ->
- result False
+ result NotConsumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
10 Tutorial3TabResponder.t
@@ -92,12 +92,12 @@ buttonHandler label = class
MouseClicked pos ->
clickCount := clickCount + 1
label.setText ("Click #" ++ show clickCount)
- result True
+ result Consumed
_ ->
- result False
+ result NotConsumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
@@ -134,9 +134,9 @@ myTabResponder label = class
if (key == Tab) then
tabCount := tabCount + 1
label.setText ("Tabs blocked #" ++ (show tabCount))
- result True
+ result Consumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
6 Tutorial4ColorPicker.t
@@ -20,15 +20,15 @@ colorPickerTile colorPickerX colorPickerY w = class
tileResponder tileColor setColor = class
respondToInputEvent (MouseEvent (MouseClicked _)) modifiers = request
setColor tileColor
- result False
+ result NotConsumed
respondToInputEvent (MouseEvent (MouseMoved _)) modifiers = request
if elem Shift modifiers then
setColor tileColor
- result False
+ result NotConsumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
15 Tutorial4MultipleWindows.t
@@ -129,12 +129,12 @@ buttonHandler label = class
MouseClicked pos ->
clickCount := clickCount + 1
label.setText ("Click #" ++ show clickCount)
- result True
+ result Consumed
_ ->
- result False
+ result NotConsumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
@@ -172,10 +172,10 @@ myTabResponder label = class
if (key == Tab) then
tabCount := tabCount + 1
label.setText ("Tabs blocked #" ++ (show tabCount))
- result True
+ result Consumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
@@ -185,12 +185,11 @@ colorPickerToggle this window env = class
respondToInputEvent (MouseEvent (MouseClicked pos)) modifiers = request
window.setVisible toggle
send action this.setTitle ((if (toggle) then "Open" else "Close") ++ " ColorPicker")
-
toggle := not toggle
- result False
+ result NotConsumed
respondToInputEvent _ _ = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
View
15 Tutorial5ComponentCreation.t
@@ -142,12 +142,12 @@ buttonHandler label = class
MouseClicked pos ->
clickCount := clickCount + 1
label.setText ("Click #" ++ show clickCount)
- result True
+ result Consumed
_ ->
- result False
+ result NotConsumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
@@ -183,10 +183,10 @@ myTabResponder label = class
if (key == Tab) then
tabCount := tabCount + 1
label.setText ("Tabs blocked #" ++ (show tabCount))
- result True
+ result Consumed
respondToInputEvent _ modifiers = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
@@ -196,12 +196,11 @@ colorPickerToggle this window env = class
respondToInputEvent (MouseEvent (MouseClicked pos)) modifiers = request
window.setVisible toggle
send action this.setTitle ((if (toggle) then "Open" else "Close") ++ " ColorPicker")
-
toggle := not toggle
- result False
+ result NotConsumed
respondToInputEvent _ _ = request
- result False
+ result NotConsumed
result RespondsToInputEvents {..}
Please sign in to comment.
Something went wrong with that request. Please try again.