heres my code so far:
/*
*File name: hexcon.c
*/
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <stdlib.h>
//global boolean says dec yes no
gboolean decimal=TRUE;
//global widgets
/*-- Declare the GTK Widgets used in the program --*/
GtkWidget *window;
GtkWidget *button;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *hbox;
/*-- This function allows the program to exit properly when the window is closed --*/
gint destroyapp (GtkWidget *widget, gpointer gdata)
{
gtk_main_quit();
return (FALSE);
}
//function responds to button click
void button_clicked(GtkWidget *widget, gpointer gdata)
{
if(decimal)
{
gtk_label_set_text( GTK_LABEL(label),"HEX." );
decimal=FALSE;
gchar* oldText=g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
gchar* newText=(gchar*)g_malloc(256);
guint64 value=g_ascii_strtoull(oldText,NULL,10);
//now convert to hexadecimal
//????????
gtk_entry_set_text(GTK_ENTRY(entry),newText);
}
else
{
gtk_label_set_text( GTK_LABEL(label),"DEC." );
decimal=TRUE;
gchar* oldText=g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
gchar* newText=(gchar*)g_malloc(256);
}
}
int main (int argc, char *argv[])
{
/*-- Initialize GTK --*/
gtk_init (&argc, &argv);
/*-- Create the new window --*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*-- Create the hbox --*/
hbox = gtk_hbox_new(FALSE, 0);
/*-- Connect the window to the destroyapp function --*/
gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL);
/*-- Create the first button with a label --*/
button = gtk_button_new_with_label ("CONVERT");
//connect button to button function
gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(button_clicked), NULL);
/*--create entry field --*/
entry=gtk_entry_new();
gtk_entry_set_text( GTK_ENTRY(entry),"0");
//create label
label=gtk_label_new("DEC.");
/*-- Pack all the radio buttons into the hbox --*/
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 2);
/*-- Add the hbox to the window --*/
gtk_container_add(GTK_CONTAINER(window), hbox);
/*-- Add a border to the window to give the button a little room --*/
gtk_container_border_width (GTK_CONTAINER (window), 15);
/*-- Display the widgets --*/
gtk_widget_show(entry);
gtk_widget_show(label);
gtk_widget_show(button);
gtk_widget_show(hbox);
gtk_widget_show(window);
/*-- Start the GTK event loop --*/
gtk_main();
/*-- Return 0 if exit is successful --*/
return 0;
}
|