9.14 File Selections
The file selection widget is a quick and simple way to display a File dialog box. It comes complete with Ok, Cancel, and Help buttons, a great way to cut down on programming time.
To create a new file selection box use:
|
To set the filename, for example to bring up a specific directory, or give a default filename, use this function:
|
To grab the text that the user has entered or clicked on, use this function:
|
There are also pointers to the widgets contained within the file selection widget. These are:
dir_list
file_list
selection_entry
selection_text
main_vbox
ok_button
cancel_button
help_button
Most likely you will want to use the ok_button, cancel_button, and help_button pointers in signaling their use.
Included here is an example stolen from testgtk.c, modified to run on its own. As you will see, there is nothing much to creating a file selection widget. While in this example the Help button appears on the screen, it does nothing as there is not a signal attached to it.
|
10. Container Widgets
10.1 The EventBox
Some GTK widgets don't have associated X windows, so they just draw on their parents. Because of this, they cannot receive events and if they are incorrectly sized, they don't clip so you can get messy overwriting, etc. If you require more from these widgets, the EventBox is for you.
At first glance, the EventBox widget might appear to be totally useless. It draws nothing on the screen and responds to no events. However, it does serve a function - it provides an X window for its child widget. This is important as many GTK widgets do not have an associated X window. Not having an X window saves memory and improves performance, but also has some drawbacks. A widget without an X window cannot receive events, and does not perform any clipping on its contents. Although the name EventBox emphasizes the event-handling function, the widget can also be used for clipping. (and more, see the example below).
To create a new EventBox widget, use:
|
A child widget can then be added to this EventBox:
|
The following example demonstrates both uses of an EventBox - a label is created that is clipped to a small box, and set up so that a mouse-click on the label causes the program to exit. Resizing the window reveals varying amounts of the label.
|
推荐文章
精彩文章
|