|[Home] [Credit Search] [Category Browser] [Staff Roll Call]||The LINUX.COM Article Archive|
|Originally Published: Wednesday, 25 July 2001||Author: Subhasish Ghosh|
|Published to: develop_articles/Development Articles||Page: 3/3 - [Printable]|
GNOME Programming in Linux using GTK+
Ever wonder how those little garden Gnomes move around and stuff at night? It's because they are programmed, of course! In this article Linux.com asked Subhasish Ghosh to show us how to start programming our own Gnome applications using the GTK+ toolkit.
|More Widgets||<< Page 3 of 3|
List boxes and Combo boxesList boxes and Combo boxes play the same role as they play on the Microsoft platform. List box widgets hold a list of strings that allow users to select one or more entries. Combo boxes are entry widgets with an added pull down menu that allows users to select options.
Menus & ToolbarsThe various widgets that we have come across until now are simple widgets that don't provide extra-ordinary functionality. We now look at some specific GNOME programming libraries that offer complicated widgets with rich functionality.
Just hang on for a second, someone may ask: "Hey, we were doing pretty well with ordinary code and all the stuff that you discussed earlier. What's the use of this so-called "specific GNOME programming libraries"? Are they indeed useful? Or are you just including them here for making your article a bit longer?"
Well, here's the reason for considering specific GNOME programming libraries. With plain GTK+ code, though nearly everything can be done that we would usually do using non-specific GNOME programming libraries, using simple and plain GTK+ code often leads to much code-repetition, in-efficient code-blocks and such other things, finally making the whole program a bloated one. Now, to prevent this from happening, we use specific GNOME programming libraries that provide a great deal of extra functionality with much lower programming overheads.
So, let's talk about "Menus" and "Toolbars" in this section.
GNOME let's us create menus and toolbars for our GnomeApp widgets
that can be docked and undocked from the window. The arrays need to
be filled with necessary information, and then call
The menus and toolbar items each have properties. The arrays (we earlier talked about) are a list of structures that define these properties. A few such properties include type, string, callback pointer etc. For the majority of the time menu entries are pretty simple, and we can just use one of a set of macros provided by GNOME to create the structure for us. So, let's check out a few most used top-level macros.
Please note: These top-level macros are the ones that create
top-level menus when passed an array that can contain any or all of
Menu Macro File GNOMEUIINFO_MENU_FILE_TREE(tree) Edit GNOMEUIINFO_MENU_EDIT_TREE(tree) View GNOMEUIINFO_MENU_VIEW_TREE(tree) Settings GNOMEUIINFO_MENU_SETTINGS_TREE(tree) Windows GNOMEUIINFO_MENU_WINDOWS_TREE(tree) Help GNOMEUIINFO_MENU_HELP_TREE(tree) Game GNOMEUIINFO_MENU_GAME_TREE(tree)
Within the top-level menu there exists over thirty macros for
creating common menu items. The macros associate small images
(pixmaps) and accelerator keys with each menu item. A
Let's look at some of these common menu items and their respective macros.
Just as with menu bars, toolbars require an array using the
Let's look at this example and see how the arrays and macros work in reality.
When executed this program will create a small window with an embedded menu and toolbar. It can be clicked, docked, undocked and dragged around the screen.
Dialog BoxesLet's now look at the widget that displays textual information to the user in the GNOME environment. Yes, we are referring to the Dialog box. When we need to create dialog boxes, we call the
Let's look at this code extract from a program that creates a simple question dialog box, adds three buttons and responds to the user's code.
Conclusion & Links for Further studyThis sums up our journey of the exciting world of GNOME Programming in Linux using GTK+ Toolkit. Please note: GNOME Programming using GTK+ Toolkits is not at all difficult, it's a matter of just a little understanding that makes it real easy to grasp. Though this article just barely manages to scratch the surface of this topic, GNOME Programming by itself is a huge topic, but if worked diligently, can definitely be mastered.
For more information and detailed coverage of this topic, check out the following links that I am sure would provide rich information on Gnome programming using GTK+ toolkit and more:
About the Author: My name is Subhasish Ghosh. I am 20, currently a computer-systems engineering student in India. I am a Microsoft Certified Professional (MCP), MCP certified on NT 4.0, recently completed Red Hat Linux Certified Engineer (RHCE) Training. I have been working with Linux for a long time now, have had programmed using C, C++, VC++, COM, MFC, DCOM, ATL 3.0, Perl, Python and Linux programming using GTK+. Currently busy learning the Linux Kernel Architecture in detail, writing articles for Linux.com and most importantly practicing non-geek talk with my girlfriend, Hanna. E-mail: firstname.lastname@example.org
|More Widgets||<< Page 3 of 3|