GTK+ 2.0 Tree View Tutorial using Ocaml

Tim-Philipp Muller

Ocaml adaptation: SooHyoung Oh

Abstract

This is a tutorial on how to use GTK+ 2.0 GtkTreeView widget in Ocaml language. Ocaml has a very nice Gtk+ interface called LablGtk in which GtkTreeView widget is implemented as GTree module.

The LablGtk version used here is LablGTK 2.4.0.

This tutorial is adapted from the original C language version written by Tim-Philipp Muller.

Please mail all comments and suggestions about Ocaml adaptation to

There is also a version in PDF format (for easier printing) and the raw docbook XML source document.

Some examples can be found in treeview_tutorial_examples.tar.gz tarball.

This tutorial is work-in-progress. The latest version can be found at http://compiler.kaist.ac.kr/~shoh/ocaml/lablgtk2/treeview-tutorial/index.html.

"Gtk+ 2.0 Tutorial using Ocaml" can be found at http://compiler.kaist.ac.kr/~shoh/ocaml/lablgtk2/lablgtk2-tutorial/index.html.

Last updated: 2004-09-18


Table of Contents

1. Lists and Trees: the GTree Module
Hello World
2. Components: Model, Renderer, Column, View
3. GTree.models for Data Storage: GTree.list_store and GTree.tree_store
How Data is Organised in a Store
Refering to Rows: Gtk.tree_iter, Gtk.tree_path, Gtk.row_reference, GTree.row_reference
Gtk.tree_path
Gtk.tree_iter
Gtk.row_reference, GTree.row_reference
Usage
Adding Rows to a Store
Adding Rows to a List Store
Adding Rows to a Tree Store
Speed Issues when Adding a Lot of Rows
Manipulating Row Data
Retrieving Row Data
Removing Rows
Removing Multiple Rows
4. Creating a Tree View
Connecting Tree View and Model
Tree View Look and Feel
5. Mapping Data to the Screen: GTree.view_column and GTree.cell_renderer_*
Cell Renderers
Attributes
Cell Data Functions
GTree.cell_renderer_text and Integer, Boolean and Float Types
GTree.cell_renderer_text, UTF8, and pango markup
A Working Example
How to Make a Whole Row Bold or Coloured
How to Pack Icons into the Tree View
6. Selections, Double-Clicks and Context Menus
Handling Selections
Selection Modes
Getting the Currently Selected Rows
Using Selection Functions
Checking Whether a Row is Selected
Selecting and Unselecting Rows
Double-Clicks on a Row
Context Menus on Right Click
7. Sorting
GTree.tree_sortable
Sorting and Tree View Column Headers
8. Editable Cells
Editable Text Cells
Setting the cursor to a specific cell
Editable Toggle and Radio Button Cells
9. Other Resources
10. Copyright, License, Credits, and Revision History
Copyright and License
Ocaml Adaptation
Original Document
Credits
Ocaml Adaptation
Original Document
Revision History
Ocaml Adaptation
Original Document

List of Figures

3.1. Tree Paths
5.1. Cell Renderer Properties
5.2. GtkTreeViewColumns and GtkCellRenderers
5.3. Persistent Cell Renderer Properties