module Graphics.UI.FLTK.LowLevel.MenuButton
    (
     
     menuButtonNew,
     MenuButtonType(..)
     
     
     
     
     
     
    )
where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import C2HS hiding (cFromEnum, cFromBool, cToBool,cToEnum)
import Foreign.C.Types
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Utils
import Graphics.UI.FLTK.LowLevel.Dispatch
import Graphics.UI.FLTK.LowLevel.Hierarchy
data MenuButtonType = NormalMenuButton
                    | Popup1MenuButton
                    | Popup2MenuButton
                    | Popup12MenuButton
                    | Popup3MenuButton
                    | Popup13MenuButton
                    | Popup123MenuButton
  deriving (Show,Eq)
instance Enum MenuButtonType where
  succ NormalMenuButton = Popup1MenuButton
  succ Popup1MenuButton = Popup2MenuButton
  succ Popup2MenuButton = Popup12MenuButton
  succ Popup12MenuButton = Popup3MenuButton
  succ Popup3MenuButton = Popup13MenuButton
  succ Popup13MenuButton = Popup123MenuButton
  succ Popup123MenuButton = error "MenuButtonType.succ: Popup123MenuButton has no successor"
  pred Popup1MenuButton = NormalMenuButton
  pred Popup2MenuButton = Popup1MenuButton
  pred Popup12MenuButton = Popup2MenuButton
  pred Popup3MenuButton = Popup12MenuButton
  pred Popup13MenuButton = Popup3MenuButton
  pred Popup123MenuButton = Popup13MenuButton
  pred NormalMenuButton = error "MenuButtonType.pred: NormalMenuButton has no predecessor"
  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []
  enumFrom from = enumFromTo from Popup123MenuButton
  fromEnum NormalMenuButton = 0
  fromEnum Popup1MenuButton = 1
  fromEnum Popup2MenuButton = 2
  fromEnum Popup12MenuButton = 3
  fromEnum Popup3MenuButton = 4
  fromEnum Popup13MenuButton = 5
  fromEnum Popup123MenuButton = 7
  toEnum 0 = NormalMenuButton
  toEnum 1 = Popup1MenuButton
  toEnum 2 = Popup2MenuButton
  toEnum 3 = Popup12MenuButton
  toEnum 4 = Popup3MenuButton
  toEnum 5 = Popup13MenuButton
  toEnum 7 = Popup123MenuButton
  toEnum unmatched = error ("MenuButtonType.toEnum: Cannot match " ++ show unmatched)
menuButtonNew' :: (Int) -> (Int) -> (Int) -> (Int) -> IO ((Ptr ()))
menuButtonNew' a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  menuButtonNew''_ a1' a2' a3' a4' >>= \res ->
  let {res' = id res} in
  return (res')
menuButtonNewWithLabel' :: (Int) -> (Int) -> (Int) -> (Int) -> (String) -> IO ((Ptr ()))
menuButtonNewWithLabel' a1 a2 a3 a4 a5 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = unsafeToCString a5} in 
  menuButtonNewWithLabel''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = id res} in
  return (res')
menuButtonNew :: Rectangle -> Maybe String -> IO (Ref MenuButton)
menuButtonNew rectangle l'=
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in case l' of
        Nothing -> menuButtonNew' x_pos y_pos width height >>=
                             toRef
        Just l -> menuButtonNewWithLabel' x_pos y_pos width height l >>=
                               toRef
menuButtonDestroy' :: (Ptr ()) -> IO ((()))
menuButtonDestroy' a1 =
  let {a1' = id a1} in 
  menuButtonDestroy''_ a1' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')
instance (impl ~ ( IO ())) => Op (Destroy ()) MenuButton orig impl where
  runOp _ _ win = swapRef win $ \winPtr -> do
    menuButtonDestroy' winPtr
    return nullPtr
menuButtonHandle' :: (Ptr ()) -> (CInt) -> IO ((Int))
menuButtonHandle' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  menuButtonHandle''_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')
instance (impl ~ (Event -> IO Int)) => Op (Handle ()) MenuButton orig impl where
  runOp _ _ menu_bar event = withRef menu_bar (\p -> menuButtonHandle' p (fromIntegral . fromEnum $ event))
menuButtonPopup' :: (Ptr ()) -> IO ((Ptr ()))
menuButtonPopup' a1 =
  let {a1' = id a1} in 
  menuButtonPopup''_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
instance (impl ~ ( IO (Maybe (Ref MenuItem)))) => Op (Popup ()) MenuButton orig impl where
  runOp _ _ menu_bar = withRef menu_bar (\p -> menuButtonPopup' p >>= toMaybeRef)
foreign import ccall safe "Graphics/UI/FLTK/LowLevel/MenuButton.chs.h Fl_Menu_Button_New"
  menuButtonNew''_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))))
foreign import ccall safe "Graphics/UI/FLTK/LowLevel/MenuButton.chs.h Fl_Menu_Button_New_WithLabel"
  menuButtonNewWithLabel''_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))))))
foreign import ccall safe "Graphics/UI/FLTK/LowLevel/MenuButton.chs.h Fl_Menu_Button_Destroy"
  menuButtonDestroy''_ :: ((C2HSImp.Ptr ()) -> (IO ()))
foreign import ccall safe "Graphics/UI/FLTK/LowLevel/MenuButton.chs.h Fl_Menu_Button_handle"
  menuButtonHandle''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))
foreign import ccall safe "Graphics/UI/FLTK/LowLevel/MenuButton.chs.h Fl_Menu_Button_popup"
  menuButtonPopup''_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))