From: Axel S. <as...@us...> - 2004-10-24 17:19:35
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/layout In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28086/gtk/layout Added Files: Alignment.chspp Expander.chspp Notebook.chspp Removed Files: Alignment.chs Expander.chs Notebook.chs Log Message: New build system. --- NEW FILE: Notebook.chspp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget Notebook -- -- Author : Axel Simon -- -- Created: 15 May 2001 -- -- Version $Revision: 1.1 $ from $Date: 2004/10/24 17:19:22 $ -- -- Copyright (c) 1999..2002 Axel Simon -- -- This file 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 2 of the License, or -- (at your option) any later version. -- -- This file 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. -- -- | -- -- This widget can display several pages of widgets. Each page can be selected -- by a tab at the top of the widget. It is useful in dialogs where a lot of -- information has to be displayed. -- -- TODO -- -- * The signals focus-tab and select-page are not bound because it is unclear -- what they mean. As far as I can see they are not emitted anywhere. -- module Notebook( Notebook, NotebookClass, castToNotebook, notebookNew, notebookAppendPage, notebookAppendPageMenu, notebookPrependPage, notebookPrependPageMenu, notebookInsertPage, notebookInsertPageMenu, notebookRemovePage, notebookPageNum, notebookSetCurrentPage, notebookNextPage, notebookPrevPage, notebookReorderChild, PositionType(..), notebookSetTabPos, notebookGetTabPos, notebookSetShowTabs, notebookGetShowTabs, notebookSetShowBorder, notebookSetScrollable, notebookGetScrollable, #ifndef DISABLE_DEPRECATED notebookSetTabBorder, notebookSetTabHBorder, notebookSetTabVBorder, #endif notebookSetPopup, notebookGetCurrentPage, notebookSetMenuLabel, notebookGetMenuLabel, notebookSetMenuLabelText, notebookGetMenuLabelText, notebookGetNthPage, #if GTK_CHECK_VERSION(2,2,0) notebookGetNPages, #endif notebookGetTabLabel, notebookGetTabLabelText, Packing(..), PackType(..), notebookQueryTabLabelPacking, notebookSetTabLabelPacking, #ifndef DISABLE_DEPRECATED notebookSetHomogeneousTabs, #endif notebookSetTabLabel, notebookSetTabLabelText, onSwitchPage, afterSwitchPage ) where import Monad (liftM) import Maybe (maybe) import FFI import Object (makeNewObject) {#import Hierarchy#} {#import Signal#} import Label (labelNew) import Enums (Packing(..), PackType(..), PositionType(..)) {# context lib="gtk" prefix="gtk" #} -- methods -- | Create a new notebook. -- notebookNew :: IO Notebook notebookNew = makeNewObject mkNotebook $ liftM castPtr {#call unsafe notebook_new#} #if GTK_CHECK_VERSION(2,4,0) -- | Insert a new tab to the right of the existing tabs. -- -- * The given label will be used for the label widget of the new tab. In case -- the context menu is enabled, this name will also appear in the popup menu. If -- you want to specify something else to go in the tab, use -- 'notebookAppendPageMenu'. -- -- * Returns index (starting from 0) of the appended page in the notebook, or -1 -- if the function fails. -- -- * This function returned @()@ in Gtk version 2.2.X and earlier -- notebookAppendPage :: (NotebookClass nb, WidgetClass child) => nb -> child -- ^ Widget to use as the contents of the page -> String -- ^ Label for the page. -> IO Int notebookAppendPage nb child tabLabel = do tab <- labelNew (Just tabLabel) liftM fromIntegral $ {#call notebook_append_page#} (toNotebook nb) (toWidget child) (toWidget tab) #else -- | Insert a new tab to the right of the existing tabs. -- -- * The given label will be used for the label widget of the new tab. In case -- the context popup menu is enabled, this name will also appear in the menu. If -- you want to specify something else to go in the tab, use -- 'notebookAppendPageMenu'. -- -- * This function returns @Int@ in Gtk version 2.4.0 and later. -- notebookAppendPage :: (NotebookClass nb, WidgetClass child) => nb -> child -- ^ Widget to use as the contents of the page -> String -- ^ Label for the page. -> IO () notebookAppendPage nb child tabLabel = do tab <- labelNew (Just tabLabel) {#call notebook_append_page#} (toNotebook nb) (toWidget child) (toWidget tab) #endif #if GTK_CHECK_VERSION(2,4,0) -- | Insert a new tab to the right of the existing tabs. -- -- Like 'notebookAppendPage' but allows any widget to be used for the label of -- the new tab and then entry in the page-switch popup menu. -- -- * Returns the index (starting from 0) of the appended page in the notebook, -- or -1 if the function fails. -- -- * This function returned @()@ in Gtk version 2.2.X and earlier -- notebookAppendPageMenu :: (NotebookClass nb, WidgetClass child, WidgetClass tab, WidgetClass menu) => nb -> child -- ^ Widget to use as the contents of the page -> tab -- ^ Tab label widget for the page. -> menu -- ^ Menu entry for this tab (usually a 'Label' widget). -> IO Int notebookAppendPageMenu nb child tabWidget menuWidget = liftM fromIntegral $ {#call notebook_append_page_menu#} (toNotebook nb) (toWidget child) (toWidget tabWidget) (toWidget menuWidget) #else -- | Insert a new tab to the right of the existing tabs. -- -- Like 'notebookAppendPage' but allows any widget to be used for the label of -- the new tab and then entry in the page-switch popup menu. -- -- * This function returns @Int@ in Gtk version 2.4.0 and later -- notebookAppendPageMenu :: (NotebookClass nb, WidgetClass child, WidgetClass tab, WidgetClass menu) => nb -> child -- ^ Widget to use as the contents of the page -> tab -- ^ Tab label widget for the page. -> menu -- ^ Menu entry for this tab (usually a 'Label' widget). -> IO () notebookAppendPageMenu nb child tabWidget menuWidget = {#call notebook_append_page_menu#} (toNotebook nb) (toWidget child) (toWidget tabWidget) (toWidget menuWidget) #endif #if GTK_CHECK_VERSION(2,4,0) -- | Insert a new tab to the left of the existing tabs. -- -- * The given label will be used for the label widget of the new tab. In case -- the context menu is enabled, this name will also appear in the popup menu. If -- you want to specify something else to go in the tab, use -- 'notebookPrependPageMenu'. -- -- * Returns index (starting from 0) of the prepended page in the notebook, or -1 -- if the function fails. -- -- * This function returned @()@ in Gtk version 2.2.X and earlier -- notebookPrependPage :: (NotebookClass nb, WidgetClass child) => nb -> child -- ^ Widget to use as the contents of the page -> String -- ^ Label for the page. -> IO Int notebookPrependPage nb child tabLabel = do tab <- labelNew (Just tabLabel) liftM fromIntegral $ {#call notebook_prepend_page#} (toNotebook nb) (toWidget child) (toWidget tab) #else -- | Insert a new tab to the left of the existing tabs. -- -- * The given label will be used for the label widget of the new tab. In case -- the context popup menu is enabled, this name will also appear in the menu. If -- you want to specify something else to go in the tab, use -- 'notebookPrependPageMenu'. -- -- * This function returns @Int@ in Gtk version 2.4.0 and later. -- notebookPrependPage :: (NotebookClass nb, WidgetClass child) => nb -> child -- ^ Widget to use as the contents of the page -> String -- ^ Label for the page. -> IO () notebookPrependPage nb child tabLabel = do tab <- labelNew (Just tabLabel) {#call notebook_prepend_page#} (toNotebook nb) (toWidget child) (toWidget tab) #endif #if GTK_CHECK_VERSION(2,4,0) -- | Insert a new tab to the left of the existing tabs. -- -- Like 'notebookPrependPage' but allows any widget to be used for the label of -- the new tab and then entry in the page-switch popup menu. -- -- * Returns the index (starting from 0) of the prepended page in the notebook, -- or -1 if the function fails. -- -- * This function returned @()@ in Gtk version 2.2.X and earlier -- notebookPrependPageMenu :: (NotebookClass nb, WidgetClass child, WidgetClass tab, WidgetClass menu) => nb -> child -- ^ Widget to use as the contents of the page -> tab -- ^ Tab label widget for the page. -> menu -- ^ Menu entry for this tab (usually a 'Label' widget). -> IO Int notebookPrependPageMenu nb child tabWidget menuWidget = liftM fromIntegral $ {#call notebook_prepend_page_menu#} (toNotebook nb) (toWidget child) (toWidget tabWidget) (toWidget menuWidget) #else -- | Insert a new tab to the left of the existing tabs. -- -- Like 'notebookPrependPage' but allows any widget to be used for the label of -- the new tab and then entry in the page-switch popup menu. -- -- * This function returns @Int@ in Gtk version 2.4.0 and later -- notebookPrependPageMenu :: (NotebookClass nb, WidgetClass child, WidgetClass tab, WidgetClass menu) => nb -> child -- ^ Widget to use as the contents of the page -> tab -- ^ Tab label widget for the page. -> menu -- ^ Menu entry for this tab (usually a 'Label' widget). -> IO () notebookPrependPageMenu nb child tabWidget menuWidget = {#call notebook_prepend_page_menu#} (toNotebook nb) (toWidget child) (toWidget tabWidget) (toWidget menuWidget) #endif #if GTK_CHECK_VERSION(2,4,0) -- | Insert a new tab at the specified position. That is between @pos@ and -- @pos@+1, or -1 to append the page after all other pages. -- -- * The given label will be used for the label widget of the new tab. In case -- the context menu is enabled, this name will also appear in the popup menu. If -- you want to specify something else to go in the tab, use -- 'notebookInsertPageMenu'. -- -- * Returns index (starting from 0) of the inserted page in the notebook, or -1 -- if the function fails. -- -- * This function returned @()@ in Gtk version 2.2.X and earlier -- notebookInsertPage :: (NotebookClass nb, WidgetClass child) => nb -> child -- ^ Widget to use as the contents of the page -> String -- ^ Label for the page. -> Int -- ^ Position for the new page. -> IO Int notebookInsertPage nb child tabLabel pos = do tab <- labelNew (Just tabLabel) liftM fromIntegral $ {#call notebook_insert_page#} (toNotebook nb) (toWidget child) (toWidget tab) (fromIntegral pos) #else -- | Insert a new tab at the specified position. That is between @pos@ and -- @pos@+1, or -1 to append the page after all other pages. -- -- * The given label will be used for the label widget of the new tab. In case -- the context menu is enabled, this name will also appear in the popup menu. If -- you want to specify something else to go in the tab, use -- 'notebookInsertPageMenu'. -- -- * This function returns @Int@ in Gtk version 2.4.0 and later. -- notebookInsertPage :: (NotebookClass nb, WidgetClass child) => nb -> child -- ^ Widget to use as the contents of the page -> String -- ^ Label for the page. -> Int -- ^ Position for the new page. -> IO () notebookInsertPage nb child tabLabel pos = do tab <- labelNew (Just tabLabel) {#call notebook_insert_page#} (toNotebook nb) (toWidget child) (toWidget tab) (fromIntegral pos) #endif #if GTK_CHECK_VERSION(2,4,0) -- | Insert a new tab at the specified position. That is between @pos@ and -- @pos@+1, or -1 to append the page after all other pages. -- -- Like 'notebookInsertPage' but allows any widget to be used for the label of -- the new tab and then entry in the page-switch popup menu. -- -- * Returns the index (starting from 0) of the inserted page in the notebook, -- or -1 if the function fails. -- -- * This function returned @()@ in Gtk version 2.2.X and earlier -- notebookInsertPageMenu ::(NotebookClass nb, WidgetClass child, WidgetClass tab, WidgetClass menu) => nb -> child -- ^ Widget to use as the contents of the page -> tab -- ^ Tab label widget for the page. -> menu -- ^ Menu entry for this tab (usually a 'Label' widget). -> Int -- ^ Position for the new page. -> IO Int notebookInsertPageMenu nb child tabWidget menuWidget pos = liftM fromIntegral $ {#call notebook_insert_page_menu#} (toNotebook nb) (toWidget child) (toWidget tabWidget) (toWidget menuWidget) (fromIntegral pos) #else -- | Insert a new tab at the specified position. That is between @pos@ and -- @pos@+1, or -1 to append the page after all other pages. -- -- Like 'notebookInsertPage' but allows any widget to be used for the label of -- the new tab and then entry in the page-switch popup menu. -- -- * This function returns @Int@ in Gtk version 2.4.0 and later -- notebookInsertPageMenu ::(NotebookClass nb, WidgetClass child, WidgetClass tab, WidgetClass menu) => nb -> child -- ^ Widget to use as the contents of the page -> tab -- ^ Tab label widget for the page. -> menu -- ^ Menu entry for this tab (usually a 'Label' widget). -> Int -- ^ Position for the new page. -> IO () notebookInsertPageMenu nb child tabWidget menuWidget pos = {#call notebook_insert_page_menu#} (toNotebook nb) (toWidget child) (toWidget tabWidget) (toWidget menuWidget) (fromIntegral pos) #endif -- | Remove a specific page from the notebook, counting from 0. -- notebookRemovePage :: NotebookClass nb => nb -> Int -> IO () notebookRemovePage nb pos = {#call notebook_remove_page#} (toNotebook nb) (fromIntegral pos) -- | Query the page the child widget is contained in. -- -- * The function returns the page number if the child was found, Nothing -- otherwise. -- notebookPageNum :: (NotebookClass nb, WidgetClass w) => nb -> w -> IO (Maybe Int) notebookPageNum nb child = liftM (\page -> if page==(-1) then Nothing else Just (fromIntegral page)) $ {#call unsafe notebook_page_num#} (toNotebook nb) (toWidget child) -- | Move to the specified page of the notebook. -- -- * If the position is out of range (e.g. negative) select the last page. -- notebookSetCurrentPage :: NotebookClass nb => nb -> Int -> IO () notebookSetCurrentPage nb pos = {#call notebook_set_current_page#} (toNotebook nb) (fromIntegral pos) -- | Move to the right neighbour of the current page. -- -- * Nothing happens if there is no such page. -- notebookNextPage :: NotebookClass nb => nb -> IO () notebookNextPage nb = {#call notebook_next_page#} (toNotebook nb) -- | Move to the left neighbour of the current page. -- -- * Nothing happens if there is no such page. -- notebookPrevPage :: NotebookClass nb => nb -> IO () notebookPrevPage nb = {#call notebook_prev_page#} (toNotebook nb) -- | Move a page withing the notebook. -- notebookReorderChild :: (NotebookClass nb, WidgetClass w) => nb -> w -> Int -> IO () notebookReorderChild nb child pos = {#call notebook_reorder_child#} (toNotebook nb) (toWidget child) (fromIntegral pos) -- | Specify at which border the tabs should be drawn. -- notebookSetTabPos :: NotebookClass nb => nb -> PositionType -> IO () notebookSetTabPos nb pt = {#call notebook_set_tab_pos#} (toNotebook nb) ((fromIntegral.fromEnum) pt) -- | Gets the edge at which the tabs for switching pages in the notebook are -- drawn. -- notebookGetTabPos :: NotebookClass nb => nb -> IO PositionType notebookGetTabPos nb = liftM (toEnum.fromIntegral) $ {#call unsafe notebook_get_tab_pos#} (toNotebook nb) -- | Show or hide the tabs of a notebook. -- notebookSetShowTabs :: NotebookClass nb => nb -> Bool -> IO () notebookSetShowTabs nb showTabs = {#call notebook_set_show_tabs#} (toNotebook nb) (fromBool showTabs) -- | Returns whether the tabs of the notebook are shown. -- notebookGetShowTabs :: NotebookClass nb => nb -> IO Bool notebookGetShowTabs nb = liftM toBool $ {#call unsafe notebook_get_show_tabs#} (toNotebook nb) -- | In case the tabs are not shown, specify whether to draw a border around -- the notebook. -- notebookSetShowBorder :: NotebookClass nb => nb -> Bool -> IO () notebookSetShowBorder nb showBorder = {#call notebook_set_show_border#} (toNotebook nb) (fromBool showBorder) -- | Returns whether a bevel will be drawn around the notebook pages. -- notebookGetShowBorder :: NotebookClass nb => nb -> IO Bool notebookGetShowBorder nb = liftM toBool $ {#call unsafe notebook_get_show_border#} (toNotebook nb) -- | Set whether scroll bars will be added in case the notebook has too many -- tabs to fit the widget size. -- notebookSetScrollable :: NotebookClass nb => nb -> Bool -> IO () notebookSetScrollable nb scrollable = {#call unsafe notebook_set_scrollable#} (toNotebook nb) (fromBool scrollable) -- | Returns whether the tab label area has arrows for scrolling. -- notebookGetScrollable :: NotebookClass nb => nb -> IO Bool notebookGetScrollable nb = liftM toBool $ {#call unsafe notebook_get_scrollable#} (toNotebook nb) #ifndef DISABLE_DEPRECATED -- | Set the width of the borders of the tab labels. -- -- * Sets both vertical and horizontal widths. -- notebookSetTabBorder :: NotebookClass nb => nb -> Int -> IO () notebookSetTabBorder nb width = {#call notebook_set_tab_border#} (toNotebook nb) (fromIntegral width) -- | Set the width of the borders of the tab labels. -- -- * Sets horizontal widths. -- notebookSetTabHBorder :: NotebookClass nb => nb -> Int -> IO () notebookSetTabHBorder nb width = {#call notebook_set_tab_hborder#} (toNotebook nb) (fromIntegral width) -- | Set the width of the borders of the tab labels. -- -- * Sets vertical widths. -- notebookSetTabVBorder :: NotebookClass nb => nb -> Int -> IO () notebookSetTabVBorder nb width = {#call notebook_set_tab_vborder#} (toNotebook nb) (fromIntegral width) #endif -- | Enable or disable context menus with all tabs in it. -- notebookSetPopup :: NotebookClass nb => nb -> Bool -> IO () notebookSetPopup nb enable = (if enable then {#call notebook_popup_enable#} else {#call notebook_popup_disable#}) (toNotebook nb) -- | Query the currently selected page. -- -- * Returns -1 if notebook has no pages. -- notebookGetCurrentPage :: NotebookClass nb => nb -> IO Int notebookGetCurrentPage nb = liftM fromIntegral $ {#call unsafe notebook_get_current_page#} (toNotebook nb) -- | Changes the menu label for the page containing the given child widget. -- notebookSetMenuLabel :: (NotebookClass nb, WidgetClass ch, WidgetClass label) => nb -> ch -> Maybe label -> IO () notebookSetMenuLabel nb child label = {#call notebook_set_menu_label#} (toNotebook nb) (toWidget child) (maybe (Widget nullForeignPtr) toWidget label) -- | Extract the menu label from the given @child@. -- -- * Returns Nothing if @child@ was not found. -- notebookGetMenuLabel :: (NotebookClass nb, WidgetClass w) => nb -> w -> IO (Maybe Label) notebookGetMenuLabel nb child = do wPtr <- {#call unsafe notebook_get_menu_label#} (toNotebook nb) (toWidget child) if wPtr==nullPtr then return Nothing else liftM Just $ makeNewObject mkLabel $ return $ castPtr wPtr -- | Creates a new label and sets it as the menu label of the given child -- widget. -- notebookSetMenuLabelText :: (NotebookClass nb, WidgetClass ch) => nb -> ch -> String -> IO () notebookSetMenuLabelText nb child label = withUTFString label $ \labelPtr -> {#call notebook_set_menu_label_text#} (toNotebook nb) (toWidget child) labelPtr -- | Retrieves the text of the menu label for the page containing the given -- child widget. -- notebookGetMenuLabelText :: (NotebookClass nb, WidgetClass ch) => nb -> ch -> IO (Maybe String) notebookGetMenuLabelText nb child = do labelPtr <- {#call unsafe notebook_get_menu_label_text#} (toNotebook nb) (toWidget child) maybePeek peekUTFString labelPtr -- | Retrieve the child widget at the given position (starting from 0). -- -- * Returns Nothing if the index is out of bounds. -- notebookGetNthPage :: NotebookClass nb => nb -> Int -> IO (Maybe Widget) notebookGetNthPage nb pos = do wPtr <- {#call unsafe notebook_get_nth_page#} (toNotebook nb) (fromIntegral pos) if wPtr==nullPtr then return Nothing else liftM Just $ makeNewObject mkWidget $ return wPtr #if GTK_CHECK_VERSION(2,2,0) -- | Get the number of pages in a notebook. -- -- * Only available in Gtk 2.2 and higher. -- notebookGetNPages :: NotebookClass nb => nb -> IO Int notebookGetNPages nb = liftM fromIntegral $ {#call unsafe notebook_get_n_pages#} (toNotebook nb) #endif -- | Extract the tab label from the given @child@. -- -- * Nothing is returned if no tab label has specifically been set for the -- child. -- notebookGetTabLabel :: (NotebookClass nb, WidgetClass w) => nb -> w -> IO (Maybe Widget) notebookGetTabLabel nb child = do wPtr <- {#call unsafe notebook_get_tab_label#} (toNotebook nb) (toWidget child) if wPtr==nullPtr then return Nothing else liftM Just $ makeNewObject mkWidget $ return wPtr -- | Retrieves the text of the tab label for the page containing the given child -- widget. -- notebookGetTabLabelText :: (NotebookClass nb, WidgetClass w) => nb -> w -> IO (Maybe String) notebookGetTabLabelText nb child = do labelPtr <- {#call unsafe notebook_get_tab_label_text#} (toNotebook nb) (toWidget child) maybePeek peekUTFString labelPtr -- | Query the packing attributes of the given child. -- notebookQueryTabLabelPacking :: (NotebookClass nb, WidgetClass w) => nb -> w -> IO (Packing,PackType) notebookQueryTabLabelPacking nb child = alloca $ \expPtr -> alloca $ \fillPtr -> alloca $ \packPtr -> do {#call unsafe notebook_query_tab_label_packing#} (toNotebook nb) (toWidget child) expPtr fillPtr packPtr expand <- liftM toBool $ peek expPtr fill <- liftM toBool $ peek fillPtr pt <- liftM (toEnum.fromIntegral) $ peek packPtr return (if fill then PackGrow else (if expand then PackRepel else PackNatural), pt) -- | Set the packing attributes of the given child. -- notebookSetTabLabelPacking :: (NotebookClass nb, WidgetClass w) => nb -> w -> Packing -> PackType -> IO () notebookSetTabLabelPacking nb child pack pt = {#call notebook_set_tab_label_packing#} (toNotebook nb) (toWidget child) (fromBool $ pack/=PackNatural) (fromBool $ pack==PackGrow) ((fromIntegral.fromEnum) pt) #ifndef DISABLE_DEPRECATED -- | Sets whether the tabs must have all the same size or not. -- notebookSetHomogeneousTabs :: NotebookClass nb => nb -> Bool -> IO () notebookSetHomogeneousTabs nb hom = {#call notebook_set_homogeneous_tabs#} (toNotebook nb) (fromBool hom) #endif -- | Set a new tab label for a given page. -- notebookSetTabLabel :: (NotebookClass nb, WidgetClass ch, WidgetClass tab) => nb -> ch -> tab -> IO () notebookSetTabLabel nb child tab = {#call notebook_set_tab_label#} (toNotebook nb) (toWidget child) (toWidget tab) -- | Creates a new label and sets it as the tab label for the given page. -- notebookSetTabLabelText :: (NotebookClass nb, WidgetClass ch) => nb -> ch -> String -> IO () notebookSetTabLabelText nb child label = withUTFString label $ \labelPtr -> {#call notebook_set_tab_label_text#} (toNotebook nb) (toWidget child) labelPtr -- signals -- | This signal is emitted when a new page is -- selected. -- onSwitchPage, afterSwitchPage :: NotebookClass nb => nb -> (Int -> IO ()) -> IO (ConnectId nb) onSwitchPage nb fun = connect_BOXED_WORD__NONE "switch-page" (const $ return ()) False nb (\_ page -> fun (fromIntegral page)) afterSwitchPage nb fun = connect_BOXED_WORD__NONE "switch-page" (const $ return ()) True nb (\_ page -> fun (fromIntegral page)) --- Alignment.chs DELETED --- --- Expander.chs DELETED --- --- Notebook.chs DELETED --- --- NEW FILE: Expander.chspp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget Expander -- -- Author : Duncan Coutts -- Created: 24 April 2004 -- -- Copyright (c) 2004 Duncan Coutts -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 of the License, or (at your option) any later version. -- -- This library 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 -- Library General Public License for more details. -- -- | -- -- An Expander allows the user to hide or show its child by clicking on an -- expander triangle similar to the triangles used in a TreeView. -- -- Normally you use an expander as you would use any other descendant of GtkBin -- you create the child widget and use containerAdd to add it to the expander. -- When the expander is toggled, it will take care of showing and hiding the -- child automatically. -- -- * Added in GTK+ 2.4 -- module Expander ( #if GTK_CHECK_VERSION(2,4,0) Expander, ExpanderClass, expanderNew, expanderNewWithMnemonic, expanderSetExpanded, expanderGetExpanded, expanderSetSpacing, expanderGetSpacing, expanderSetLabel, expanderGetLabel, expanderSetUseUnderline, expanderGetUseUnderline, expanderSetUseMarkup, expanderGetUseMarkup, expanderSetLabelWidget, expanderGetLabelWidget, onActivate, afterActivate #endif ) where #if GTK_CHECK_VERSION(2,4,0) import Monad (liftM) import FFI import Object {#import Hierarchy#} import Signal {# context lib="gtk" prefix ="gtk" #} expanderNew :: String -> IO Expander expanderNew label = makeNewObject mkExpander $ liftM castPtr $ withUTFString label $ \strPtr -> {# call gtk_expander_new #} strPtr expanderNewWithMnemonic :: String -> IO Expander expanderNewWithMnemonic label = makeNewObject mkExpander $ liftM castPtr $ withUTFString label $ \strPtr -> {# call gtk_expander_new_with_mnemonic #} strPtr expanderSetExpanded :: Expander -> Bool -> IO () expanderSetExpanded expander expanded = {# call gtk_expander_set_expanded #} expander (fromBool expanded) expanderGetExpanded :: Expander -> IO Bool expanderGetExpanded expander = liftM toBool $ {# call gtk_expander_get_expanded #} expander expanderSetSpacing :: Expander -> Int -> IO () expanderSetSpacing expander spacing = {# call gtk_expander_set_spacing #} expander (fromIntegral spacing) expanderGetSpacing :: Expander -> IO Int expanderGetSpacing expander = liftM fromIntegral $ {# call gtk_expander_get_spacing #} expander expanderSetLabel :: Expander -> String -> IO () expanderSetLabel expander label = withUTFString label $ \strPtr -> {# call gtk_expander_set_label #} expander strPtr expanderGetLabel :: Expander -> IO String expanderGetLabel expander = do strPtr <- {# call gtk_expander_get_label #} expander peekUTFString strPtr expanderSetUseUnderline :: Expander -> Bool -> IO () expanderSetUseUnderline expander useUnderline = {# call gtk_expander_set_use_underline #} expander (fromBool useUnderline) expanderGetUseUnderline :: Expander -> IO Bool expanderGetUseUnderline expander = liftM toBool $ {# call gtk_expander_get_use_underline #} expander expanderSetUseMarkup :: Expander -> Bool -> IO () expanderSetUseMarkup expander useMarkup = {# call gtk_expander_set_use_markup #} expander (fromBool useMarkup) expanderGetUseMarkup :: Expander -> IO Bool expanderGetUseMarkup expander = liftM toBool $ {# call gtk_expander_get_use_markup #} expander expanderSetLabelWidget :: WidgetClass widget => Expander -> widget -> IO () expanderSetLabelWidget expander widget = {# call gtk_expander_set_label_widget #} expander (toWidget widget) expanderGetLabelWidget :: Expander -> IO Widget expanderGetLabelWidget expander = makeNewObject mkWidget $ {# call gtk_expander_get_label_widget #} expander onActivate :: Expander -> IO () -> IO (ConnectId Expander) afterActivate :: Expander -> IO () -> IO (ConnectId Expander) onActivate = connect_NONE__NONE "activate" False afterActivate = connect_NONE__NONE "activate" True #endif --- NEW FILE: Alignment.chspp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget Alignment -- -- Author : Axel Simon -- -- Created: 15 May 2001 -- -- Version $Revision: 1.1 $ from $Date: 2004/10/24 17:19:22 $ -- -- Copyright (c) 1999..2002 Axel Simon -- -- This file 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 2 of the License, or -- (at your option) any later version. -- -- This file 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. -- -- | -- module Alignment( Alignment, AlignmentClass, castToAlignment, alignmentNew, alignmentSet #if GTK_CHECK_VERSION(2,4,0) ,alignmentSetPadding, alignmentGetPadding #endif ) where import Monad (liftM) import FFI import Object (makeNewObject) {#import Hierarchy#} {#import Signal#} {# context lib="gtk" prefix="gtk" #} -- methods -- | Create an alignment widget. This widget tells -- its child widget how to use the given space. -- alignmentNew :: Float -> Float -> Float -> Float -> IO Alignment alignmentNew yscale xalign yalign xscale = makeNewObject mkAlignment $ liftM castPtr $ {#call unsafe alignment_new#} (realToFrac xalign) (realToFrac yalign) (realToFrac xscale) (realToFrac yscale) -- | Change the space use behaviour of an 'Alignment'. -- alignmentSet :: AlignmentClass al => al -> Float -> Float -> Float -> Float -> IO () alignmentSet al xalign yalign xscale yscale = {#call alignment_set#} (toAlignment al) (realToFrac xalign) (realToFrac yalign) (realToFrac xscale) (realToFrac yscale) #if GTK_CHECK_VERSION(2,4,0) -- | Sets the padding on the different sides of the widget. -- alignmentSetPadding :: AlignmentClass al => al -> Int -> Int -> Int -> Int -> IO () alignmentSetPadding al top bottom left right = {# call gtk_alignment_set_padding #} (toAlignment al) (fromIntegral top) (fromIntegral bottom) (fromIntegral left) (fromIntegral right) -- | Gets the padding on the different sides of the widget. -- alignmentGetPadding :: AlignmentClass al => al -> IO (Int, Int, Int, Int) alignmentGetPadding al = alloca $ \topPtr -> alloca $ \bottomPtr -> alloca $ \leftPtr -> alloca $ \rightPtr -> do {# call gtk_alignment_get_padding #} (toAlignment al) topPtr bottomPtr leftPtr rightPtr top <- peek topPtr bottom <- peek bottomPtr left <- peek leftPtr right <- peek rightPtr return (fromIntegral top, fromIntegral bottom ,fromIntegral left, fromIntegral right) #endif |