main :: IO ()
main = do
  FL.setOption FL.OptionArrowFocus True
  win' <- doubleWindowNew
           (Size (Width 922) (Height 382))
           Nothing
           (Just "Fl_Table Spreadsheet with Keyboard Navigation")
  (Width winWidth') <- getW win'
  (Height winHeight') <- getH win'
  let values' =
        map
          (\r' ->
            map
             (\c' -> (r'+2) * (c'+3))
             [0 .. (maxCols -1)]
          )
          [0.. (maxRows - 1)]
  props' <- newIORef $
              SpreadsheetProperties
                0
                0
                (TableCoordinate (Row 0) (Column 0))
                (TableCoordinate (Row 0) (Column 0))
                values'
  let tableWidth' = winWidth' - 80
      tableHeight' = winHeight' - 80
  intInput' <- inputNew
                (toRectangle
                 (
                  (truncate $ ((fromIntegral tableWidth' / 2) :: Double)),
                  (truncate $ ((fromIntegral tableHeight' / 2) :: Double)),
                  0,
                  0
                 )
                )
                Nothing
                (Just FlIntInput)
  hide intInput'
  setWhen intInput' [WhenEnterKeyAlways]
  setMaximumSize intInput' 5

  spreadsheet' <- tableCustom
                    (toRectangle (20,20,tableWidth', tableHeight'))
                    Nothing
                    Nothing
                    (drawCell props' intInput')
                    defaultCustomWidgetFuncs
                    defaultCustomTableFuncs
  whens' <- getWhen spreadsheet'
  setWhen spreadsheet' $ [WhenNotChanged] ++ whens'
  setSelection spreadsheet' (TableCoordinate (Row 0) (Column 0)) (TableCoordinate (Row 0) (Column 0))
  setCallback intInput' (setValueHide props' spreadsheet')
  setCallback spreadsheet' (eventCallback props' intInput')
  setTooltip spreadsheet' "Use keyboard to navigate cells:\n Arrow keys or Tab/Shift-Tab"
  -- Table rows
  setRowHeader spreadsheet' True
  setRowHeaderWidth spreadsheet' 70
  setRowResize spreadsheet' True
  setRows spreadsheet' (Rows 11)
  setRowHeightAll spreadsheet' 25
  -- Table cols
  setColHeader spreadsheet' True
  setColHeaderHeight spreadsheet' 25
  setColResize spreadsheet' True
  setCols spreadsheet' (Columns 11)
  setColWidthAll spreadsheet' 70

  begin win'
  -- Rows slider
  setRows' <- valueSliderNew (toRectangle (winWidth'-40,20,20,winHeight'-80)) Nothing
  setType setRows' VertNiceSliderType
  bounds setRows' 2 (fromIntegral maxRows)
  setStep setRows' 1
  (Rows numRows') <- getRows spreadsheet'
  _ <- setValue setRows' (fromIntegral $ numRows'-1)
  setCallback setRows' (setRowsCb spreadsheet')
  setWhen setRows' [WhenChanged]
  clearVisibleFocus setRows'
   -- Cols slider
  setCols' <- valueSliderNew (toRectangle (20,winHeight'-40,winWidth'-80,20)) Nothing
  setType setCols' HorNiceSliderType
  bounds setCols' 2 (fromIntegral maxCols)
  setStep setCols' 1
  (Columns numCols') <- getCols spreadsheet'
  _ <- setValue setCols' (fromIntegral $ numCols'-1)
  setCallback setCols' (setColsCb spreadsheet')
  setWhen setCols' [WhenChanged]
  clearVisibleFocus setCols'
  end win'
  setResizable win' (Just spreadsheet')
  showWidget win'
  _ <- FL.run
  return ()
main :: IO ()
main = do
  FL.setOption FL.OptionArrowFocus True
  win' <- doubleWindowNew
           (Size (Width 922) (Height 382))
           Nothing
           (Just "Fl_Table Spreadsheet with Keyboard Navigation")
  (Width winWidth') <- getW win'
  (Height winHeight') <- getH win'
  let values' =
        map
          (\r' ->
            map
             (\c' -> (r'+2) * (c'+3))
             [0 .. (maxCols -1)]
          )
          [0.. (maxRows - 1)]
  props' <- newIORef $
              SpreadsheetProperties
                0
                0
                (TableCoordinate (Row 0) (Column 0))
                (TableCoordinate (Row 0) (Column 0))
                values'
  let tableWidth' = winWidth' - 80
      tableHeight' = winHeight' - 80
  intInput' <- inputNew
                (toRectangle
                 (
                  (truncate $ ((fromIntegral tableWidth' / 2) :: Double)),
                  (truncate $ ((fromIntegral tableHeight' / 2) :: Double)),
                  0,
                  0
                 )
                )
                Nothing
                (Just FlIntInput)
  hide intInput'
  setWhen intInput' [WhenEnterKeyAlways]
  setMaximumSize intInput' 5

  spreadsheet' <- tableCustom
                    (toRectangle (20,20,tableWidth', tableHeight'))
                    Nothing
                    Nothing
                    (drawCell props' intInput')
                    defaultCustomWidgetFuncs
                    defaultCustomTableFuncs
  whens' <- getWhen spreadsheet'
  setWhen spreadsheet' $ [WhenNotChanged] ++ whens'
  setSelection spreadsheet' (TableCoordinate (Row 0) (Column 0)) (TableCoordinate (Row 0) (Column 0))
  setCallback intInput' (setValueHide props' spreadsheet')
  setCallback spreadsheet' (eventCallback props' intInput')
  setTooltip spreadsheet' "Use keyboard to navigate cells:\n Arrow keys or Tab/Shift-Tab"
  -- Table rows
  setRowHeader spreadsheet' True
  setRowHeaderWidth spreadsheet' 70
  setRowResize spreadsheet' True
  setRows spreadsheet' (Rows 11)
  setRowHeightAll spreadsheet' 25
  -- Table cols
  setColHeader spreadsheet' True
  setColHeaderHeight spreadsheet' 25
  setColResize spreadsheet' True
  setCols spreadsheet' (Columns 11)
  setColWidthAll spreadsheet' 70

  begin win'
  -- Rows slider
  setRows' <- valueSliderNew (toRectangle (winWidth'-40,20,20,winHeight'-80)) Nothing
  setType setRows' VertNiceSliderType
  bounds setRows' 2 (fromIntegral maxRows)
  setStep setRows' 1
  (Rows numRows') <- getRows spreadsheet'
  _ <- setValue setRows' (fromIntegral $ numRows'-1)
  setCallback setRows' (setRowsCb spreadsheet')
  setWhen setRows' [WhenChanged]
  clearVisibleFocus setRows'
   -- Cols slider
  setCols' <- valueSliderNew (toRectangle (20,winHeight'-40,winWidth'-80,20)) Nothing
  setType setCols' HorNiceSliderType
  bounds setCols' 2 (fromIntegral maxCols)
  setStep setCols' 1
  (Columns numCols') <- getCols spreadsheet'
  _ <- setValue setCols' (fromIntegral $ numCols'-1)
  setCallback setCols' (setColsCb spreadsheet')
  setWhen setCols' [WhenChanged]
  clearVisibleFocus setCols'
  end win'
  setResizable win' (Just spreadsheet')
  showWidget win'
  _ <- FL.run
  return ()
main = do
  FL.setOption FL.OptionArrowFocus True
  win' <- doubleWindowNew
           (Size (Width 922) (Height 382))
           Nothing
           (Just "Fl_Table Spreadsheet with Keyboard Navigation")
  (Width winWidth') <- getW win'
  (Height winHeight') <- getH win'
  let values' =
        map
          (\r' ->
            map
             (\c' -> (r'+2) * (c'+3))
             [0 .. (maxCols -1)]
          )
          [0.. (maxRows - 1)]
  props' <- newIORef $
              SpreadsheetProperties
                0
                0
                (TableCoordinate (Row 0) (Column 0))
                (TableCoordinate (Row 0) (Column 0))
                values'
  let tableWidth' = winWidth' - 80
      tableHeight' = winHeight' - 80
  intInput' <- inputNew
                (toRectangle
                 (
                  (truncate $ ((fromIntegral tableWidth' / 2) :: Double)),
                  (truncate $ ((fromIntegral tableHeight' / 2) :: Double)),
                  0,
                  0
                 )
                )
                Nothing
                (Just FlIntInput)
  hide intInput'
  setWhen intInput' [WhenEnterKeyAlways]
  setMaximumSize intInput' 5

  spreadsheet' <- tableCustom
                    (toRectangle (20,20,tableWidth', tableHeight'))
                    Nothing
                    Nothing
                    (drawCell props' intInput')
                    defaultCustomWidgetFuncs
                    defaultCustomTableFuncs
  whens' <- getWhen spreadsheet'
  setWhen spreadsheet' $ [WhenNotChanged] ++ whens'
  setSelection spreadsheet' (TableCoordinate (Row 0) (Column 0)) (TableCoordinate (Row 0) (Column 0))
  setCallback intInput' (setValueHide props' spreadsheet')
  setCallback spreadsheet' (eventCallback props' intInput')
  setTooltip spreadsheet' "Use keyboard to navigate cells:\n Arrow keys or Tab/Shift-Tab"
  -- Table rows
  setRowHeader spreadsheet' True
  setRowHeaderWidth spreadsheet' 70
  setRowResize spreadsheet' True
  setRows spreadsheet' (Rows 11)
  setRowHeightAll spreadsheet' 25
  -- Table cols
  setColHeader spreadsheet' True
  setColHeaderHeight spreadsheet' 25
  setColResize spreadsheet' True
  setCols spreadsheet' (Columns 11)
  setColWidthAll spreadsheet' 70

  begin win'
  -- Rows slider
  setRows' <- valueSliderNew (toRectangle (winWidth'-40,20,20,winHeight'-80)) Nothing
  setType setRows' VertNiceSliderType
  bounds setRows' 2 (fromIntegral maxRows)
  setStep setRows' 1
  (Rows numRows') <- getRows spreadsheet'
  _ <- setValue setRows' (fromIntegral $ numRows'-1)
  setCallback setRows' (setRowsCb spreadsheet')
  setWhen setRows' [WhenChanged]
  clearVisibleFocus setRows'
   -- Cols slider
  setCols' <- valueSliderNew (toRectangle (20,winHeight'-40,winWidth'-80,20)) Nothing
  setType setCols' HorNiceSliderType
  bounds setCols' 2 (fromIntegral maxCols)
  setStep setCols' 1
  (Columns numCols') <- getCols spreadsheet'
  _ <- setValue setCols' (fromIntegral $ numCols'-1)
  setCallback setCols' (setColsCb spreadsheet')
  setWhen setCols' [WhenChanged]
  clearVisibleFocus setCols'
  end win'
  setResizable win' (Just spreadsheet')
  showWidget win'
  _ <- FL.run
  return ()