-
Notifications
You must be signed in to change notification settings - Fork 200
/
Window.hs
64 lines (51 loc) · 2.46 KB
/
Window.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{-# LANGUAGE DeriveDataTypeable, TemplateHaskell, GeneralizedNewtypeDeriving #-}
--
-- Copyright (c) 2008 JP Bernardy
--
--
module Yi.Window where
import qualified Prelude
import Yi.Prelude
import Data.Binary
import Yi.Buffer.Basic (BufferRef, WindowRef)
import Yi.Region (Region,emptyRegion)
------------------------------------------------------------------------
-- | A window onto a buffer.
data Window = Window {
isMini :: !Bool -- ^ regular or mini window?
,bufkey :: !BufferRef -- ^ the buffer this window opens to
,bufAccessList :: ![BufferRef] -- ^ list of last accessed buffers (former bufKeys). Last accessed one is first element
,height :: Int -- ^ height of the window (in number of screen lines displayed)
,winRegion :: Region -- ^ view area.
-- note that the top point is also available as a buffer mark.
,wkey :: !WindowRef -- ^ identifier for the window (for UI sync)
-- This is required for accurate scrolling.
-- Scrolling depends on the actual number of buffer
-- lines displayed. Line wrapping changes that number
-- relative to the height so we can't use height for that
-- purpose.
,actualLines :: Int-- ^ The actual number of buffer lines displayed. Taking into account line wrapping
}
deriving (Typeable)
instance Binary Window where
put (Window mini bk bl _h _rgn key lns) = put mini >> put bk >> put bl >> put key >> put lns
get = Window <$> get <*> get <*> get
<*> return 0 <*> return emptyRegion
<*> get <*> get
-- | Get the identification of a window.
winkey :: Window -> (Bool, BufferRef)
winkey w = (isMini w, bufkey w)
instance Show Window where
show w = "Window to " ++ show (bufkey w)
-- ++ "{" ++ show (tospnt w) ++ "->" ++ show (bospnt w) ++ "}"
++ "(" ++ show (height w) ++ ")"
instance Eq Window where
(==) w1 w2 = wkey w1 == wkey w2
{-
-- | Is a given point within tospnt / bospnt?
pointInWindow :: Point -> Window -> Bool
pointInWindow point win = tospnt win <= point && point <= bospnt win
-}
-- | Return a "fake" window onto a buffer.
dummyWindow :: BufferRef -> Window
dummyWindow b = Window False b [] 0 emptyRegion initial 0