-- GENERATED by C->Haskell Compiler, version 0.28.6 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "lib/UI/NCurses/Panel.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}

-- Copyright (C) 2010 John Millikin <jmillikin@gmail.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

module UI.NCurses.Panel
	( Panel
	, newPanel
	, deletePanel
	, refreshPanels
	, panelAbove
	, panelBelow
	, panelTop
	, panelBottom
	, showPanel
	, hidePanel
	, panelHidden
	, movePanel
	, raisePanel
	, lowerPanel
	, getPanelWindow
	, replacePanelWindow
	) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import           Control.Exception (throwIO)
import           Foreign
import           Foreign.C

import           UI.NCurses (render) -- for haddock
import           UI.NCurses.Types






{-# LINE 52 "lib/UI/NCurses/Panel.chs" #-}


{-# LINE 53 "lib/UI/NCurses/Panel.chs" #-}

newtype Panel = Panel { panelPtr :: Ptr Panel }

-- | Creates a new 'Panel', on top of the panel stack.
newPanel :: Window -> Curses Panel
newPanel :: Window -> Curses Panel
newPanel win :: Window
win = IO Panel -> Curses Panel
forall a. IO a -> Curses a
Curses (IO Panel -> Curses Panel) -> IO Panel -> Curses Panel
forall a b. (a -> b) -> a -> b
$ do
	Panel
p <- Window -> IO Panel
new_panel Window
win
	if Panel -> Ptr Panel
panelPtr Panel
p Ptr Panel -> Ptr Panel -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Panel
forall a. Ptr a
nullPtr
		then CursesException -> IO Panel
forall e a. Exception e => e -> IO a
throwIO (String -> CursesException
CursesException "newPanel: new_panel() returned NULL")
		else Panel -> IO Panel
forall (m :: * -> *) a. Monad m => a -> m a
return Panel
p

-- | Permanently removes the given panel from the panel stack.
deletePanel :: Panel -> Curses ()
deletePanel :: Panel -> Curses ()
deletePanel p :: Panel
p = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (Panel -> IO CInt
del_panel Panel
p IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> CInt -> IO ()
checkRC "deletePanel")

-- | Updates windows to account for the current panel stack order. The user
-- must call 'render' before changes are drawn to the screen.
refreshPanels :: Curses ()
refreshPanels :: Curses ()
refreshPanels = IO () -> Curses ()
forall a. IO a -> Curses a
Curses IO ()
update_panels
{-# LINE 71 "lib/UI/NCurses/Panel.chs" #-}


-- | @panelAbove p@ retrieve the panel above /p/.
panelAbove :: Panel -> Curses (Maybe Panel)
panelAbove :: Panel -> Curses (Maybe Panel)
panelAbove p :: Panel
p = IO (Maybe Panel) -> Curses (Maybe Panel)
forall a. IO a -> Curses a
Curses (IO (Maybe Panel) -> Curses (Maybe Panel))
-> IO (Maybe Panel) -> Curses (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ do
	Panel
ptr <- Panel -> IO Panel
panel_above Panel
p
	Maybe Panel -> IO (Maybe Panel)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Panel -> IO (Maybe Panel))
-> Maybe Panel -> IO (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ if Panel -> Ptr Panel
panelPtr Panel
ptr Ptr Panel -> Ptr Panel -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Panel
forall a. Ptr a
nullPtr
		then Maybe Panel
forall a. Maybe a
Nothing
		else Panel -> Maybe Panel
forall a. a -> Maybe a
Just Panel
ptr

-- | @panelAbove p@ retrieve the panel below /p/.
panelBelow :: Panel -> Curses (Maybe Panel)
panelBelow :: Panel -> Curses (Maybe Panel)
panelBelow p :: Panel
p = IO (Maybe Panel) -> Curses (Maybe Panel)
forall a. IO a -> Curses a
Curses (IO (Maybe Panel) -> Curses (Maybe Panel))
-> IO (Maybe Panel) -> Curses (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ do
	Panel
ptr <- Panel -> IO Panel
panel_below Panel
p
	Maybe Panel -> IO (Maybe Panel)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Panel -> IO (Maybe Panel))
-> Maybe Panel -> IO (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ if Panel -> Ptr Panel
panelPtr Panel
ptr Ptr Panel -> Ptr Panel -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Panel
forall a. Ptr a
nullPtr
		then Maybe Panel
forall a. Maybe a
Nothing
		else Panel -> Maybe Panel
forall a. a -> Maybe a
Just Panel
ptr

-- | Retrieve the top&#x2013;most panel in the stack.
panelTop :: Curses (Maybe Panel)
panelTop :: Curses (Maybe Panel)
panelTop = IO (Maybe Panel) -> Curses (Maybe Panel)
forall a. IO a -> Curses a
Curses (IO (Maybe Panel) -> Curses (Maybe Panel))
-> IO (Maybe Panel) -> Curses (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ do
	Panel
ptr <- Panel -> IO Panel
panel_below (Ptr Panel -> Panel
Panel Ptr Panel
forall a. Ptr a
nullPtr)
	Maybe Panel -> IO (Maybe Panel)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Panel -> IO (Maybe Panel))
-> Maybe Panel -> IO (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ if Panel -> Ptr Panel
panelPtr Panel
ptr Ptr Panel -> Ptr Panel -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Panel
forall a. Ptr a
nullPtr
		then Maybe Panel
forall a. Maybe a
Nothing
		else Panel -> Maybe Panel
forall a. a -> Maybe a
Just Panel
ptr

-- | Retrieve the bottom&#x2013;most panel in the stack.
panelBottom :: Curses (Maybe Panel)
panelBottom :: Curses (Maybe Panel)
panelBottom = IO (Maybe Panel) -> Curses (Maybe Panel)
forall a. IO a -> Curses a
Curses (IO (Maybe Panel) -> Curses (Maybe Panel))
-> IO (Maybe Panel) -> Curses (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ do
	Panel
ptr <- Panel -> IO Panel
panel_above (Ptr Panel -> Panel
Panel Ptr Panel
forall a. Ptr a
nullPtr)
	Maybe Panel -> IO (Maybe Panel)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Panel -> IO (Maybe Panel))
-> Maybe Panel -> IO (Maybe Panel)
forall a b. (a -> b) -> a -> b
$ if Panel -> Ptr Panel
panelPtr Panel
ptr Ptr Panel -> Ptr Panel -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Panel
forall a. Ptr a
nullPtr
		then Maybe Panel
forall a. Maybe a
Nothing
		else Panel -> Maybe Panel
forall a. a -> Maybe a
Just Panel
ptr

-- | Makes a hidden panel visible, and places it on the top of the stack.
showPanel :: Panel -> Curses ()
showPanel :: Panel -> Curses ()
showPanel p :: Panel
p = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (Panel -> IO CInt
show_panel Panel
p IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> CInt -> IO ()
checkRC "showPanel")

-- | Temporarily removes the given panel from the panel stack. Use
-- 'showPanel' to restore it.
hidePanel :: Panel -> Curses ()
hidePanel :: Panel -> Curses ()
hidePanel p :: Panel
p = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (Panel -> IO CInt
hide_panel Panel
p IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> CInt -> IO ()
checkRC "hidePanel")

-- | Checks if the given panel is currently visible.
panelHidden :: Panel -> Curses Bool
panelHidden :: Panel -> Curses Bool
panelHidden p :: Panel
p = IO Bool -> Curses Bool
forall a. IO a -> Curses a
Curses (CInt -> Bool
forall a. Integral a => a -> Bool
cToBool (CInt -> Bool) -> IO CInt -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Panel -> IO CInt
panel_hidden Panel
p)

-- | Move the panel so its upper&#x2013;left corner is at the new
-- coordinates.
movePanel :: Panel
          -> Integer -- ^ New upper&#x2013;left row
          -> Integer -- ^ New upper&#x2013;left column
          -> Curses ()
movePanel :: Panel -> Integer -> Integer -> Curses ()
movePanel p :: Panel
p row :: Integer
row col :: Integer
col = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (IO () -> Curses ()) -> IO () -> Curses ()
forall a b. (a -> b) -> a -> b
$
	String -> CInt -> IO ()
checkRC "movePanel" (CInt -> IO ()) -> IO CInt -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Panel -> CInt -> CInt -> IO CInt
move_panel Panel
p
		(Integer -> CInt
forall a. Num a => Integer -> a
fromInteger Integer
row)
		(Integer -> CInt
forall a. Num a => Integer -> a
fromInteger Integer
col)

-- | Raise a bottom to the top of the stack.
raisePanel :: Panel -> Curses ()
raisePanel :: Panel -> Curses ()
raisePanel p :: Panel
p = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (Panel -> IO CInt
top_panel Panel
p IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> CInt -> IO ()
checkRC "raisePanel")

-- | Lower a panel to the bottom of the stack.
lowerPanel :: Panel -> Curses ()
lowerPanel :: Panel -> Curses ()
lowerPanel p :: Panel
p = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (Panel -> IO CInt
bottom_panel Panel
p IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> CInt -> IO ()
checkRC "lowerPanel")

-- | Retrieves which window a panel is drawn to.
getPanelWindow :: Panel -> Curses Window
getPanelWindow :: Panel -> Curses Window
getPanelWindow p :: Panel
p = IO Window -> Curses Window
forall a. IO a -> Curses a
Curses (Panel -> IO Window
panel_window Panel
p)

-- | Replaces which window a panel is drawn to.
replacePanelWindow :: Panel -> Window -> Curses ()
replacePanelWindow :: Panel -> Window -> Curses ()
replacePanelWindow p :: Panel
p win :: Window
win = IO () -> Curses ()
forall a. IO a -> Curses a
Curses (IO () -> Curses ()) -> IO () -> Curses ()
forall a b. (a -> b) -> a -> b
$
	Panel -> Window -> IO CInt
replace_panel Panel
p Window
win IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> CInt -> IO ()
checkRC "replacePanelWindow"

foreign import ccall safe "UI/NCurses/Panel.chs.h new_panel"
  new_panel :: ((Window) -> (IO (Panel)))

foreign import ccall safe "UI/NCurses/Panel.chs.h del_panel"
  del_panel :: ((Panel) -> (IO C2HSImp.CInt))

foreign import ccall safe "UI/NCurses/Panel.chs.h update_panels"
  update_panels :: (IO ())

foreign import ccall safe "UI/NCurses/Panel.chs.h panel_above"
  panel_above :: ((Panel) -> (IO (Panel)))

foreign import ccall safe "UI/NCurses/Panel.chs.h panel_below"
  panel_below :: ((Panel) -> (IO (Panel)))

foreign import ccall safe "UI/NCurses/Panel.chs.h show_panel"
  show_panel :: ((Panel) -> (IO C2HSImp.CInt))

foreign import ccall safe "UI/NCurses/Panel.chs.h hide_panel"
  hide_panel :: ((Panel) -> (IO C2HSImp.CInt))

foreign import ccall safe "UI/NCurses/Panel.chs.h panel_hidden"
  panel_hidden :: ((Panel) -> (IO C2HSImp.CInt))

foreign import ccall safe "UI/NCurses/Panel.chs.h move_panel"
  move_panel :: ((Panel) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall safe "UI/NCurses/Panel.chs.h top_panel"
  top_panel :: ((Panel) -> (IO C2HSImp.CInt))

foreign import ccall safe "UI/NCurses/Panel.chs.h bottom_panel"
  bottom_panel :: ((Panel) -> (IO C2HSImp.CInt))

foreign import ccall safe "UI/NCurses/Panel.chs.h panel_window"
  panel_window :: ((Panel) -> (IO (Window)))

foreign import ccall safe "UI/NCurses/Panel.chs.h replace_panel"
  replace_panel :: ((Panel) -> ((Window) -> (IO C2HSImp.CInt)))