Programming with gtkmm2

Murray Cumming

Bernhard Rieder

Chapter on "Timeouts".

Jason M'Sadoques

Chapter on "Drawing Area".

Ole Laursen

Parts of chapter on "Internationalization".

Gene Ruebsamen

Chapter on "Win32 Installation".

Cedric Gustin

Chapter on "Win32 Installation".

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. You may obtain a copy of the GNU Free Documentation License from the Free Software Foundation by visiting their Web site or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Abstract

Not all sections have been completed - some have not been started. Some chapters have been written, but not edited or proofread. Since they do contain helpful information, they have been included, and are marked "draft". We are working hard to make this helpful and accurate. We would very much appreciate any reports of inaccuracies or other errors in this document. Contributions are also most welcome. Post your suggestions, critiques or addenda to the gtkmm mailing list -- The gtkmm Development Team


Table of Contents

1. Introduction
This book
gtkmm
Why use gtkmm instead of GTK+?
gtkmm compared to QT
gtkmm is a wrapper
2. Installation
Dependencies
Unix and Linux
From Source
Prebuilt Packages
Microsoft Windows
3. Basics
Simple Example
Widgets
Signals
Glib::ustring
Intermediate types
Hello World in gtkmm
4. Buttons
Button
Constuctors
Example
Signals
ToggleButton
CheckButton
Example
RadioButton
Groups
Methods
Example
5. Range Widgets
Scrollbar Widgets
Scale Widgets
Useful methods
Update Policies
Example
6. Miscellaneous Widgets
Label
Example
Entry
Example
Combo
Example
SpinButton
Methods
Example
ProgressBar
Activity Mode
Example
Tooltips
7. Container Widgets
Single-item Containers
Frame
Paned
ScrolledWindow
AspectFrame
Alignment
Multiple-item widgets
Packing
An improved Hello World
STL-style APIs
Boxes
ButtonBoxes
Table
Notebook
8. The TreeView widget
The Model
ListStore, for rows
TreeStore, for a hierarchy
Model Columns
Adding Rows
Setting values
Getting values
"Hidden" Columns
The View
Using a Model
Adding View Columns
More than one Model Column per View Column
Specifying CellRenderer details
Editable Cells
Iterating over Model Rows
Row children
The Selection
Single or multiple selection
The selected rows
The "changed" signal
Preventing row selection
Changing the selection
Drag and Drop
Reorderable rows
Popup Context Menu
Handling button_press_event
Examples
ListStore
TreeStore
Editable Cells
Drag and Drop
Popup Context Menu
9. TextView
The Buffer
Iterators
Tags and Formatting
Marks
The View
Widgets and ChildAnchors
Examples
Simple Example
10. Menus and Toolbars
Menus
The MenuBar
Menus and Menu Items
Popup Menus
Examples
Toolbars
Example
11. Adjustments
Creating an Adjustment
Using Adjustments the Easy Way
Adjustment Internals
12. Widgets Without X-Windows
EventBox
Example
13. Dialogs
MessageDialog
Example
FileSelection
Example
ColorSelectionDialog
Example
FontSelectionDialog
Example
14. The Drawing Area Widget
Graphics Contexts
Drawing Pixels
Drawing Lines
Example
Drawing Rectangles and Polygons
Drawing Ellipses and Arcs
Drawing Text
Example
Draw Images
15. Drag and Drop
Sources and Destinations
Methods
Signals
Copy
Move
Link
DragContext
Example
16. The Clipboard
Targets
Copy
Paste
Discovering the available targets
Examples
Simple
Ideal
17. Timeouts, I/O and Idle Functions
Timeouts
Monitoring I/O
Idle Functions
18. Memory management
Widgets
Normal C++ memory management
Managed Widgets
Shared resources
19. Glade and libglademm
Loading the .glade file
Accessing widgets
Example
Using derived widgets
Example
20. Internationalization and Localization
English in the source code, translations in the .po files.
gettext
Expecting UTF8
Glib::ustring and std::iostreams
Pitfalls
Same strings, different semantics
Composition of strings
Assuming the displayed size of strings
Unusual words
Using non-ASCII characters in strings
Getting help with translations
21. Recommended Techniques
Application lifetime
Using a gtkmm widget
22. Contributing
A. The RefPtr smartpointer
Copying
Dereferencing
Casting
Checking for null
Constness
B. Signals
Connecting signal handlers
Writing signal handlers
Disconnecting signal handlers
Overriding default signal handlers
Binding extra arguments
X Event signals
C. Creating your own signals
D. Comparison with other signalling systems
E. gtkmm and Win32
The Dev-C++ IDE
Pre-Installation Issues
Dependencies
Installation
Compiling gtkmm Apps with Dev-C++
Command line tools
Building gtkmm on Win32

List of Figures

3.1. Hello World
4.1. buttons example
4.2. CheckButton
4.3. RadioButton
5.1. Range Widgets
6.1. Label
6.2. Entry
6.3. Combo
6.4. SpinButton
6.5. ProgressBar
7.1. Frame
7.2. Paned
7.3. ScrolledWindow
7.4. Alignment
7.5. Hello World 2
7.6. Box Packing 1
7.7. Box Packing 2
7.8. ButtonBox
7.9. Table
7.10. Notebook
8.1. TreeView - ListStore
8.2. TreeView - TreeStore
8.3. TreeView - ListStore
8.4. TreeView - TreeStore
8.5. TreeView - Editable Cells
8.6. TreeView - Drag And Drop
8.7. TreeView - Popup Context Menu
9.1. TextView
10.1. MenuBar
10.2. Menu
10.3. Main Menu
10.4. Popup Menu
10.5. Toolbar
12.1. EventBox
13.1. MessageDialog
13.2. FileSelection
13.3. ColorSelectionDialog
13.4. FontSelectionDialog
14.1. Drawing Area - Lines
14.2. Drawing Area - Text
15.1. Drag and Drop
16.1. Clipboard - Simple
16.2. Clipboard - Ideal
E.1. Dev-C++ Project Options