The above examples were easy enough, but what about using ORBit with gnome (afterall, that is what it is designed for). In this chapter we will look at using ORBit in gnome, starting with simple GUI to the calculator idl presented in the previous chapter
The GUI will be very simple minded and won't provide much of user friendlyness. But the goal of the example is to show you how to use the function calls. We will provide two text entry widgets and two buttons to add and subtract the two values.
Example 6-1. Calculator Client with GUI C Source
#include <orb/orbit.h> #include "calculator.h" void add_it(GtkWidget* o, CORBA_Environment* ev) { GtkWidget* e1; GtkWidget* e2; GtkWidget* res; CORBA_double d1; CORBA_double d2; CORBA_double d3; /* extract the values from the e1, e2 entry fields. convert the strings to double values and assign these values to d1, d2 respectivly */ res = Calculator_add(d1, d2, ev); /* convert res to a string and display it in the res widget */ } GtkWidget* create_gui(CORBA_Object server) { /* create the gui with all the elemts. e1 is the entry widget for the first value; e2 is the entry widget for the second value; res is the widget to display the result; b_add is the button to add the two values; b_sub is the button to subtract the two values; window is the top level window */ /* create all the widgets and place them in the window */ ...... gtk_object_add(b_add, "calc-server", server); gtk_object_add(b_add, "e1", e1); gtk_object_add(b_add, "e2", e2); gtk_object_add(b_add, "res", res); gtk_object_add(b_sub, "calc-server", server); gtk_object_add(b_sub, "e1", e1); gtk_object_add(b_sub, "e2", e2); gtk_object_add(b_sub, "res", res); gtk_signal_connect(b_add, "clicked", add_it, 0); gtk_signal_connect(b_sub, "clicked", subtract_it, 0); return hbox; } int main(int argc, char* argv[]) { CORAB_Environment env; CORBA_ORB orb; CORBA_Object server; CORBA_double res; GtkWidget* app; gchar* dummy_argv[2] gint dummy_argc; CORBA_exception_init(&ev); dummy_argc = 1; dummy_argv[0] = argv[0]; dummy_argv[1] = 0; orb = gnome_CORBA_init("simple-calculator", NULL, &dummy_argc, dummy_argv, 0, NULL, &ev); server = CORBA_ORB_string_to_object(orb, argv[1], &ev); app = create_gui(server); gtk_widget_show_all(app); gtk_main(); exit(0); };
Notice the usage of the dummy_argc and dummy_argv variable. If you pass the original argc, argv variables to gnome_CORBA_init, you have to provide an argp parser. We won't do this for out simple minded examples, but it is surely helpful to do this for real world applications.
The big difference is the GUI part. To activate the CORBA system, and initialize it so that it works with the event driven Gtk library, you must call gnome_CORBA_init() instead of CORBA_ORB_init(). That's it! No big deal.