Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / C

Designing Dialog-based Applications with Glade and GTK

Rate me:
Please Sign up or sign in to vote.
2.55/5 (4 votes)
24 Jan 2008CPOL6 min read 46.1K   245   21  
Designing cross-platform dialog-based applications using GTK and Glade
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>
#include <string.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"


void
on_buttonAdd_clicked                   (GtkButton       *button,
                                        gpointer         user_data)
{
const gchar     *textFirstName;
const gchar     *textLastName;
const gchar     *textTitle;
GtkTextBuffer   *textNameList;
PangoTabArray   *ptaNameList;
GtkWidget       *widgetFirstName;
GtkWidget       *widgetLastName;
GtkWidget       *widgetTitle;
GtkWidget       *widgetNameList;

    widgetFirstName = lookup_widget(GTK_WIDGET(button), "entryFirstName");
    widgetLastName = lookup_widget(GTK_WIDGET(button), "entryLastName");
    widgetTitle = lookup_widget(GTK_WIDGET(button), "comboTitle");
    widgetNameList = lookup_widget(GTK_WIDGET(button), "textviewNameList");

    ptaNameList = pango_tab_array_new_with_positions(2, TRUE, PANGO_TAB_LEFT, 100, PANGO_TAB_LEFT, 200); 
    gtk_text_view_set_tabs(GTK_TEXT_VIEW(widgetNameList), ptaNameList);
    textNameList = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widgetNameList));

    /* these functions return pointers to internal storage */
    textFirstName = gtk_entry_get_text(GTK_ENTRY(widgetFirstName));
    textLastName = gtk_entry_get_text(GTK_ENTRY(widgetLastName));
    textTitle = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widgetTitle));

    gtk_text_buffer_insert_at_cursor(textNameList, textTitle, -1);
    gtk_text_buffer_insert_at_cursor(textNameList, "\t", -1); 
    gtk_text_buffer_insert_at_cursor(textNameList, textFirstName, -1); 
    gtk_text_buffer_insert_at_cursor(textNameList, "\t", -1); 
    gtk_text_buffer_insert_at_cursor(textNameList, textLastName, -1); 
    gtk_text_buffer_insert_at_cursor(textNameList, "\n", -1); 

    gtk_entry_set_text(GTK_ENTRY(widgetFirstName),"");
    gtk_entry_set_text(GTK_ENTRY(widgetLastName),"");
    pango_tab_array_free(ptaNameList);
}


void
on_buttonOK_clicked                    (GtkButton       *button,
                                        gpointer         user_data)
{
    gtk_main_quit();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions