diff options
Diffstat (limited to 'src/Gtk/Widgets.icl')
-rw-r--r-- | src/Gtk/Widgets.icl | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/Gtk/Widgets.icl b/src/Gtk/Widgets.icl index 0848122..4bf537b 100644 --- a/src/Gtk/Widgets.icl +++ b/src/Gtk/Widgets.icl @@ -8,14 +8,32 @@ import Data.Functor import Data.Tuple import System.FilePath import System._Pointer +from Text import class Text(split), instance Text String +import qualified Text import Gtk import Gtk.Internal +:: GtkActionBar :== Pointer + +instance gtkWidget GtkActionBar where gtkWidget ab = ab + +newActionBar :: GtkM GtkActionBar +newActionBar = toStateR gtk_action_bar_new >>= show + +packActionBar :: !GtkActionBar !GtkDirection !w -> GtkM w | gtkWidget w +packActionBar bar dir widget = + toState + (if dir=:StartToEnd gtk_action_bar_pack_start gtk_action_bar_pack_end + bar + (gtkWidget widget)) >>| + pure widget + :: GtkBox :== Pointer instance gtkWidget GtkBox where gtkWidget b = b instance gtkContainer GtkBox where gtkContainer b = b +instance gtkOrientable GtkBox where gtkOrientable b = b newBox :: !GtkOrientation !Int -> GtkM GtkBox newBox orientation spacing = @@ -28,6 +46,23 @@ packBox box direction expand widget = box (gtkWidget widget) expand=:Expand True 0) >>| pure widget +instance tune GtkBox GtkSpacing +where + tune (Spacing s) box = toState (gtk_box_set_spacing box s) >>| pure box + +:: GtkButton :== Pointer + +instance gtkWidget GtkButton where gtkWidget b = b +instance ptr GtkButton +where + toPtr b = b + fromPtr b = b + +newButtonFromIconName :: !String -> GtkM GtkButton +newButtonFromIconName icon = + toStateR (gtk_button_new_from_icon_name icon (toInt ButtonIconSize)) >>= + show + :: GtkContainer :== Pointer instance gtkWidget GtkContainer where gtkWidget c = c @@ -132,6 +167,11 @@ framed label widgetf = newListStore :: ![GType] -> GtkM GtkListStore newListStore types = toStateR (gtk_list_store_newv {toInt t \\ t <- types}) +clearListStore :: !GtkListStore -> GtkM GtkListStore +clearListStore store = + toState (gtk_list_store_clear store) >>| + pure store + appendToListStore :: ![GValue] !GtkListStore -> GtkM GtkListStore appendToListStore values store = set 0 values (gtk_list_store_append store) >>| @@ -148,6 +188,16 @@ where GValueString s -> toState (gtk_list_store_set_string store iter col s) set _ [] _ = pure () +swapItems :: !Int !Int !GtkListStore -> GtkM Bool +swapItems a b store = + let + (ok_a,iter_a) = gtk_tree_model_get_iter_from_string store (toString a) + (ok_b,iter_b) = gtk_tree_model_get_iter_from_string store (toString b) + in + if (ok_a && ok_b) + (toState (gtk_list_store_swap store iter_a iter_b) >>| pure True) + (pure False) + :: GtkMenu :== Pointer instance gtkWidget GtkMenu where gtkWidget m = m @@ -216,6 +266,14 @@ appendToMenuShell shell item = toState (gtk_menu_shell_append (gtkMenuShell shell) (gtkMenuItem item)) >>| pure item +:: GtkOrientable :== Pointer + +instance tune o GtkOrientation | gtkOrientable o +where + tune orientation orientable = + toState (gtk_orientable_set_orientation (gtkOrientable orientable) orientation=:Vertical) >>| + pure orientable + :: GtkPaned :== Pointer instance gtkWidget GtkPaned where gtkWidget p = p @@ -346,6 +404,36 @@ appendColumnToTreeView title col expand tree_view = toState (gtk_tree_view_append_column tree_view column) >>| pure tree_view +addSelectionChangedHandler :: !(GtkM ()) !GtkTreeView -> GtkM GtkTreeView +addSelectionChangedHandler handler tree = + let selection = gtk_tree_view_get_selection tree in + tune (ChangedHandler handler) selection >>| + pure tree + +getPathToSelection :: !GtkTreeView -> GtkM (Maybe [Int]) +getPathToSelection tree = + let selection = gtk_tree_view_get_selection tree in + toStateR (gtk_tree_selection_get_selected selection) >>= \(selected,iter) + | not selected -> + pure Nothing + | otherwise -> + let + model = gtk_tree_view_get_model tree + path = gtk_tree_model_get_string_from_iter model iter + in + pure (Just [toInt part \\ part <- split ":" path]) + +selectPath :: ![Int] !GtkTreeView -> GtkM Bool +selectPath path tree = + let + store = gtk_tree_view_get_model tree + selection = gtk_tree_view_get_selection tree + (ok,iter) = gtk_tree_model_get_iter_from_string store ('Text'.join ":" [toString i \\ i <- path]) + in + if ok + (toState (gtk_tree_selection_select_iter selection iter) >>| pure True) + (pure False) + :: GtkWidget :== Pointer instance gtkWidget GtkWidget where gtkWidget w = w @@ -384,6 +472,12 @@ setMargins {left,top,right,bottom} widget` = toState (gtk_widget_set_margin_bottom widget bottom) >>| pure widget` +instance tune w GtkSensitivity | gtkWidget w +where + tune sens widget = + toState (gtk_widget_set_sensitive (gtkWidget widget) sens=:Sensitive) >>| + pure widget + :: GtkWindow :== Pointer instance gtkWidget GtkWindow where gtkWidget w = w |