📄 gtk_tut.txt
字号:
GTK v1.2 Tutorial Tony Gale <gale@gtk.org> Ian Main <imain@gtk.org>, February 21st, 1999 This is a tutorial on how to use GTK (the GIMP Toolkit) through its C interface. ______________________________________________________________________ Table of Contents 1. Introduction 2. Getting Started 2.1 Hello World in GTK 2.2 Compiling Hello World 2.3 Theory of Signals and Callbacks 2.4 Events 2.5 Stepping Through Hello World 3. Moving On 3.1 Data Types 3.2 More on Signal Handlers 3.3 An Upgraded Hello World 4. Packing Widgets 4.1 Theory of Packing Boxes 4.2 Details of Boxes 4.3 Packing Demonstration Program 4.4 Packing Using Tables 4.5 Table Packing Example 5. Widget Overview 5.1 Casting 5.2 Widget Hierarchy 5.3 Widgets Without Windows 6. The Button Widget 6.1 Normal Buttons 6.2 Toggle Buttons 6.3 Check Buttons 6.4 Radio Buttons 7. Adjustments 7.1 Creating an Adjustment 7.2 Using Adjustments the Easy Way 7.3 Adjustment Internals 8. Range Widgets 8.1 Scrollbar Widgets 8.2 Scale Widgets 8.2.1 Creating a Scale Widget 8.2.2 Functions and Signals (well, functions, at least) 8.3 Common Functions 8.3.1 Setting the Update Policy 8.3.2 Getting and Setting Adjustments 8.4 Key and Mouse bindings 8.4.1 Vertical Range Widgets 8.4.2 Horizontal Range Widgets 8.5 Example 9. Miscellaneous Widgets 9.1 Labels 9.2 Arrows 9.3 The Tooltips Widget 9.4 Progress Bars 9.5 Dialogs 9.6 Pixmaps 9.7 Rulers 9.8 Statusbars 9.9 Text Entries 9.10 Spin Buttons 9.11 Combo Box 9.12 Color Selection 9.13 File Selections 10. Container Widgets 10.1 The EventBox 10.2 The Alignment widget 10.3 Fixed Container 10.4 Layout Container 10.5 Frames 10.6 Aspect Frames 10.7 Paned Window Widgets 10.8 Viewports 10.9 Scrolled Windows 10.10 Button Boxes 10.11 Toolbar 10.12 Notebooks 11. CList Widget 11.1 Creating a GtkCList widget 11.2 Modes of operation 11.3 Working with titles 11.4 Manipulating the list itself 11.5 Adding rows to the list 11.6 Setting text and pixmaps in the cells 11.7 Storing data pointers 11.8 Working with selections 11.9 The signals that bring it together 11.10 A GtkCList example 12. Tree Widget 12.1 Creating a Tree 12.2 Adding a Subtree 12.3 Handling the Selection List 12.4 Tree Widget Internals 12.4.1 Signals 12.4.2 Functions and Macros 12.5 Tree Item Widget 12.5.1 Signals 12.5.2 Functions and Macros 12.6 Tree Example 13. Menu Widget 13.1 Manual Menu Creation 13.2 Manual Menu Example 13.3 Using GtkItemFactory 13.4 Item Factory Example 14. Text Widget 14.1 Creating and Configuring a Text box 14.2 Text Manipulation 14.3 Keyboard Shortcuts 14.3.1 Motion Shortcuts 14.3.2 Editing Shortcuts 14.3.3 Selection Shortcuts 14.4 A GtkText Example 15. Undocumented Widgets 15.1 Calendar 15.2 CTree 15.3 Curves 15.4 Drawing Area 15.5 Font Selection Dialog 15.6 Gamma Curve 15.7 Image 15.8 Packer 15.9 Plugs and Sockets 15.10 Preview 16. Setting Widget Attributes 17. Timeouts, IO and Idle Functions 17.1 Timeouts 17.2 Monitoring IO 17.3 Idle Functions 18. Advanced Event and Signal Handling 18.1 Signal Functions 18.1.1 Connecting and Disconnecting Signal Handlers 18.1.2 Blocking and Unblocking Signal Handlers 18.1.3 Emitting and Stopping Signals 18.2 Signal Emission and Propagation 19. Managing Selections 19.1 Overview 19.2 Retrieving the selection 19.3 Supplying the selection 20. glib 20.1 Definitions 20.2 Doubly Linked Lists 20.3 Singly Linked Lists 20.4 Memory Management 20.5 Timers 20.6 String Handling 20.7 Utility and Error Functions 21. GTK's rc Files 21.1 Functions For rc Files 21.2 GTK's rc File Format 21.3 Example rc file 22. Writing Your Own Widgets 22.1 Overview 22.2 The Anatomy Of A Widget 22.3 Creating a Composite widget 22.3.1 Introduction 22.3.2 Choosing a parent class 22.3.3 The header file 22.3.4 The 22.3.5 The 22.3.6 The 22.3.7 And the rest... 22.4 Creating a widget from scratch. 22.4.1 Introduction 22.4.2 Displaying a widget on the screen 22.4.3 The origins of the Dial Widget 22.4.4 The Basics 22.4.5 (TT 22.4.6 Size negotiation 22.4.7 (TT 22.4.8 Event handling 22.4.9 Possible Enhancements 22.5 Learning More 23. Scribble, A Simple Example Drawing Program 23.1 Overview 23.2 Event Handling 23.3 The DrawingArea Widget, And Drawing 23.4 Adding XInput support 23.4.1 Enabling extended device information 23.4.2 Using extended device information 23.4.3 Finding out more about a device 23.4.4 Further sophistications 24. Tips For Writing GTK Applications 25. Contributing 26. Credits 27. Tutorial Copyright and Permissions Notice 28. GTK Signals 28.1 GtkObject 28.2 GtkWidget 28.3 GtkData 28.4 GtkContainer 28.5 GtkCalendar 28.6 GtkEditable 28.7 GtkTipsQuery 28.8 GtkCList 28.9 GtkNotebook 28.10 GtkList 28.11 GtkMenuShell 28.12 GtkToolbar 28.13 GtkTree 28.14 GtkButton 28.15 GtkItem 28.16 GtkWindow 28.17 GtkHandleBox 28.18 GtkToggleButton 28.19 GtkMenuItem 28.20 GtkListItem 28.21 GtkTreeItem 28.22 GtkCheckMenuItem 28.23 GtkInputDialog 28.24 GtkColorSelection 28.25 GtkStatusBar 28.26 GtkCTree 28.27 GtkCurve 28.28 GtkAdjustment 29. GDK Event Types 30. Code Examples 30.1 Tictactoe 30.1.1 tictactoe.h 30.1.2 tictactoe.c 30.1.3 ttt_test.c 30.2 GtkDial 30.2.1 gtkdial.h 30.2.2 gtkdial.c 30.2.3 dial-test.c 30.3 Scribble 30.3.1 scribble-simple.c 30.3.2 scribble-xinput.c 31. List Widget 31.1 Signals 31.2 Functions 31.3 Example 31.4 List Item Widget 31.5 Signals 31.6 Functions 31.7 Example ______________________________________________________________________ 11.. IInnttrroodduuccttiioonn GTK (GIMP Toolkit) is a library for creating graphical user interfaces. It is licensed using the LGPL license, so you can develop open software, free software, or even commercial non-free software using GTK without having to spend anything for licenses or royalties. It's called the GIMP toolkit because it was originally written for developing the General Image Manipulation Program (GIMP), but GTK has now been used in a large number of software projects, including the GNU Network Object Model Environment (GNOME) project. GTK is built on top of GDK (GIMP Drawing Kit) which is basically a wrapper around the low-level functions for accessing the underlying windowing functions (Xlib in the case of X windows). The primary authors of GTK are: +o Peter Mattis petm@xcf.berkeley.edu +o Spencer Kimball spencer@xcf.berkeley.edu +o Josh MacDonald jmacd@xcf.berkeley.edu GTK is essentially an object oriented application programmers interface (API). Although written completely in C, it is implemented using the idea of classes and callback functions (pointers to functions). There is also a third component called glib which contains a few replacements for some standard calls, as well as some additional functions for handling linked lists etc. The replacement functions are used to increase GTK's portability, as some of the functions implemented here are not available or are nonstandard on other unixes such as g_strerror(). Some also contain enhancements to the libc versions, such as g_malloc that has enhanced debugging utilities. This tutorial describes the C interface to GTK. There are GTK bindings for many other languages including C++, Guile, Perl, Python, TOM, Ada95, Objective C, Free Pascal, and Eiffel. If you intend to use another language's bindings to GTK, look at that binding's documentation first. In some cases that documentation may describe some important conventions (which you should know first) and then refer you back to this tutorial. There are also some cross-platform APIs (such as wxWindows and V) which use GTK as one of their target platforms; again, consult their documentation first. If you're developing your GTK application in C++, a few extra notes are in order. There's a C++ binding to GTK called GTK--, which provides a more C++-like interface to GTK; you should probably look into this instead. If you don't like that approach for whatever reason, there are two alternatives for using GTK. First, you can use only the C subset of C++ when interfacing with GTK and then use the C interface as described in this tutorial. Second, you can use GTK and C++ together by declaring all callbacks as static functions in C++ classes, and again calling GTK using its C interface. If you choose this last approach, you can include as the callback's data value a pointer to the object to be manipulated (the so-called "this" value). Selecting between these options is simply a matter of preference, since in all three approaches you get C++ and GTK. None of these approaches requires the use of a specialized preprocessor, so no matter what you choose you can use standard C++ with GTK. This tutorial is an attempt to document as much as possible of GTK, but it is by no means complete. This tutorial assumes a good understanding of C, and how to create C programs. It would be a great benefit for the reader to have previous X programming experience, but it shouldn't be necessary. If you are learning GTK as your first widget set, please comment on how you found this tutorial, and what you had trouble with. Note that there is also a C++ API for GTK (GTK--) in the works, so if you prefer to use C++, you should look into this instead. There are also Objective C, ADA, Guile and other language bindings available, but I don't follow these. This document is a 'work in progress'. Please look for updates on http://www.gtk.org/ http://www.gtk.org/. I would very much like to hear of any problems you have learning GTK from this document, and would appreciate input as to how it may be improved. Please see the section on ``Contributing'' for further information. 22.. GGeettttiinngg SSttaarrtteedd The first thing to do of course, is download the GTK source and install it. You can always get the latest version from ftp.gtk.org in /pub/gtk. You can also view other sources of GTK information on http://www.gtk.org/ http://www.gtk.org/. GTK uses GNU autoconf for configuration. Once untar'd, type ./configure --help to see a list of options. Th GTK source distribution also contains the complete source to all of the examples used in this tutorial, along with Makefiles to aid compilation. To begin our introduction to GTK, we'll start with the simplest program possible. This program will create a 200x200 pixel window and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -