|
From: <kr_...@us...> - 2003-08-25 04:39:20
|
Update of /cvsroot/htoolkit/gio/src/Graphics/UI/GIO
In directory sc8-pr-cvs1:/tmp/cvs-serv6171/gio/src/Graphics/UI/GIO
Modified Files:
Controls.hs
Log Message:
Implementation for Notebook control
Index: Controls.hs
===================================================================
RCS file: /cvsroot/htoolkit/gio/src/Graphics/UI/GIO/Controls.hs,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** Controls.hs 23 Aug 2003 00:04:47 -0000 1.22
--- Controls.hs 24 Aug 2003 13:57:34 -0000 1.23
***************
*** 8,12 ****
Portability : portable
! Controls.
-}
-----------------------------------------------------------------------------------------
--- 8,16 ----
Portability : portable
! This module contains interface to all controls supported from GIO.
! A control is a child window an application uses in conjunction with
! another window to perform simple input and output tasks.
! The controls provides the user with the means to type text, choose options,
! and execute an actions.
-}
-----------------------------------------------------------------------------------------
***************
*** 68,72 ****
-- ** CompoundControl
! , CompoundControl, compoundControl
) where
--- 72,83 ----
-- ** CompoundControl
! , CompoundControl, compoundControl
!
! -- ** Notebook
! -- | A notebook control is analogous to the dividers in a real notebook.
! -- By using a notebook control, an application can define multiple pages for
! -- the same area of a window or dialog box.
! , Notebook, notebook, labelsPosition, selectedPage
! , NotebookPage, notebookPageAt, notebookPage
) where
***************
*** 647,651 ****
= writeAttr "layout" (\w c -> do
let lay = pack c
- autosize <- get w autosize
domain <- get w domain
needed <- getLayoutSize lay
--- 658,661 ----
***************
*** 662,663 ****
--- 672,766 ----
instance Control CompoundControl where
pack w = stdPack (ccparent w) (Port.getCompoundControlRequestSize (cchandle w)) (Port.moveResizeControl (cchandle w))
+
+
+ --------------------------------------------------------------------
+ -- Notebook
+ --------------------------------------------------------------------
+ -- | A notebook control.
+ data Notebook = Notebook
+ { nbhandle :: !WindowHandle
+ , nbparent :: !WindowHandle
+ , nbpages :: !(Var [NotebookPage])
+ }
+
+ -- | Create a notebook control.
+ notebook :: Container w => [Prop Notebook] -> w -> IO Notebook
+ notebook props w
+ = do nb <- do hbook <- Port.createNotebook (hwindow w)
+ refPages <- newVar []
+ return (Notebook hbook (hwindow w) refPages)
+ set nb props
+ return nb
+
+ instance Control Notebook where
+ pack w = stdPack (nbparent w) getNotebookRequestSize (Port.moveResizeControl (nbhandle w))
+ where
+ getNotebookRequestSize = do
+ outSize <- Port.getNotebookRequestSize (nbhandle w)
+ pages <- getVar (nbpages w)
+ pageSizes <- mapM (\page -> get page layoutSize) pages
+ let inSize = foldr maxSize (Size 10 10) pageSizes
+ return (addSize inSize outSize)
+
+ labelsPosition :: Attr Notebook PositionType
+ labelsPosition = newStdAttr nbhandle Port.getNotebookLabelsPosition Port.setNotebookLabelsPosition
+
+ instance SingleSelect Notebook where
+ selected = newStdAttr nbhandle Port.getNotebookSelection Port.setNotebookSelection
+
+ selectedPage :: Attr Notebook NotebookPage
+ selectedPage = newAttr getPage setPage
+ where
+ getPage w = do
+ index <- Port.getNotebookSelection (nbhandle w)
+ pages <- getVar (nbpages w)
+ return (pages !! index)
+
+ setPage w p = do
+ index <- Port.getNotebookPagePos (pghandle p)
+ Port.setNotebookSelection (nbhandle w)index
+
+ -- | A notebook page control.
+ data NotebookPage = NotebookPage
+ { pghandle :: !WindowHandle
+ , pgparent :: !WindowHandle
+ , pglayout :: !(Var Layout)
+ }
+
+ -- | Create a new page at specified position in the notebook.
+ notebookPageAt :: Maybe Int -> [Prop NotebookPage] -> Notebook -> IO NotebookPage
+ notebookPageAt mb_pos props (Notebook hNotebook _ refPages)
+ = do pg <- do hpage <- Port.insertNotebookPage hNotebook mb_pos
+ vlayout <- newVar empty
+ return (NotebookPage hpage hNotebook vlayout)
+ updateVar refPages ((:) pg)
+ set pg [on relayout =: relayoutNotebookPage pg]
+ set pg props
+ return pg
+
+ notebookPage :: [Prop NotebookPage] -> Notebook -> IO NotebookPage
+ notebookPage = notebookPageAt Nothing
+
+ relayoutNotebookPage :: NotebookPage -> IO ()
+ relayoutNotebookPage c
+ = do size <- Port.getNotebookPageSize (pghandle c)
+ lay <- getVar (pglayout c)
+ layoutInRect (rectOfSize size) lay
+ return ()
+
+ instance Container NotebookPage where
+ layout = writeAttr "layout" (\w c -> setVar (pglayout w) (pack c))
+ autosize = readAttr "autosize" (\c -> return True)
+ layoutSize = readAttr "layoutSize" (\c -> getVar (pglayout c) >>= getLayoutSize)
+ relayout = newStdEvent pghandle Port.getWindowReLayoutHandler Port.setWindowReLayoutHandler Port.setWindowReLayoutDefHandler
+ hwindow c = pghandle c
+
+ instance Titled NotebookPage where
+ title = newStdAttr pghandle Port.getNotebookPageTitle Port.setNotebookPageTitle
+
+ instance Positioned NotebookPage where
+ pos = readAttr "pos" (Port.getNotebookPagePos . pghandle)
+
+ instance Deadly NotebookPage where
+ destroyWidget w = Port.destroyNotebookPage (pghandle w)
+ destroy = newStdEvent pghandle Port.getWindowDestroyHandler Port.setWindowDestroyHandler Port.setWindowDestroyDefHandler
|