[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A game
Hi
I've made this game in GTK+ well, actually its nor finished yet. I was
wondering if any of you would want to help me finish it. I'm willing to write
an article about writing games, simple games etc. Once I finish this one. Well,
its supposed to be a Stock Market simulation game... and it really doesn't have
much in it yet. It doesn't have any graphics stuff... so its gonna just do some
data manipulation... adding, dividing, multiplication... its really simple. So,
I was thinking of writing something about it when its finished, I mean, howto
create a game using vanilla gnu tools without using stuff like 3d and 2d
graphics, and also using the GTK+ widget for simple stuff. And it seems to me,
that this mailing-list is in need of some code or something to get things
started. so I'll attach the 2 programs that comprises the game, they have lots
of bugs, and are probably not a good example of excellent programming, but
we've got to start somewhere. the 1st program writes company files to be used
in the 2nd program, which is the game itself... the stock market simulator.
They both compile. the 1st program is more or less complete when it comes to
features, but the second one doesn't have much of an engine in place yet....
And haven't had the time to complete it because I was concentrating on school,
so I can graduate. but now that thats over.. I can devote more time. Thanks.
open.png
//This entire Package is under the GPL liscense.
//The principal Author is Glenn Bautista Jr.
//Thanks to clahey and Yosh at #gimp.. for a lot of tips and bug squishing.
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <time.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gdk_imlib.h>
//gcc -Wall -g main.c -o drtype `gtk-config --cflags` `gtk-config --libs` -lgdk_imlib
//gcc -Wall -g main.c -o freemarket `gtk-config --cflags` `gtk-config --libs` -lXext -ljpeg -lpng -ltiff -lgif -lz -lgdk_imlib
void quit ();
static void openfile ();
static void readfile ();
void readcompfiles();
static void savefilefunc ();
static void byeopen ();
static void byesave ();
static void newgame ();
static void byeconf ();
static void gameinitopen ();
static void init_clists();
static void init_notebooks();
static void init_clists_compname();
/* Function for Traversing the companies Glist */
void nblist(gchar np);
//static void set_initial_price_avail_stocks();
//Global Varialbles for the game engine itself
gchar *nameofplayer;
gchar *nameofcompany;
gint money_cash;
gint money_stocks;
gint money_debt;
gchar stocks_held;
gchar savefile;
/* Variables for the Saved game file. */
gchar *sav_comp_file_names[1000];
typedef struct _company_data
{
gchar category[45];
gchar comp_name[16];
gint max_start_stocks;
gint max_start_price;
gint current_price;
gint no_you_own;
gint prestige;
gint mass_appeal;
gint competition;
gchar good_news[5][500];
gchar very_good_news[5][500];
gchar bad_news[5][500];
gchar very_bad_news[5][500];
} company_data;
GList *companies_data_list;
company_data *temp_data_hold;
company_data *raw_data_from_file;
company_data *get_comp_data_pointer();
gint nocomps=0; /* Number of Companies */
//Other variables for the GUI etc.
GtkWidget *mainwin;
static GtkWidget *fileopen;
static GtkWidget *filesave;
static GtkWidget *mainnotebook;
static GtkWidget *marketnotebook;
static GtkWidget *openscreen;
static GdkImlibImage *gopen;
static GtkWidget *mainbox;
// Global Variables for the Clist.
static GtkWidget *techbox;
static GtkWidget *techlabel;
static GtkWidget *techlist;
static gchar *markettitles[4] = {"Name", "Price", "Available", "No. You Own"};
static GtkWidget *marketlabel;
static GtkWidget *finbox;
static GtkWidget *finlabel;
static GtkWidget *finlist;
static GtkWidget *autobox;
static GtkWidget *autolabel;
static GtkWidget *autolist;
static GtkWidget *gobox;
static GtkWidget *golabel;
static GtkWidget *golist;
static GtkWidget *fbtbox;
static GtkWidget *fbtlabel;
static GtkWidget *fbtlist;
static GtkWidget *mdtbox;
static GtkWidget *mdtlabel;
static GtkWidget *mdtlist;
static GtkWidget *holdbox;
static GtkWidget *holdlabel;
static GtkWidget *holdlist;
static GtkWidget *commbox;
static GtkWidget *commlabel;
static GtkWidget *commlist;
static GtkWidget *bankbox;
static GtkWidget *banklabel;
static GtkWidget *banklist;
static GtkWidget *pebox;
static GtkWidget *pelabel;
static GtkWidget *pelist;
static GtkWidget *constbox;
static GtkWidget *constlabel;
static GtkWidget *constlist;
static GtkWidget *hrbox;
static GtkWidget *hrlabel;
static GtkWidget *hrlist;
static GtkWidget *miningbox;
static GtkWidget *mininglabel;
static GtkWidget *mininglist;
static GtkWidget *prbox;
static GtkWidget *prlabel;
static GtkWidget *prlist;
static GtkWidget *companylabel;
static GtkWidget *companybox;
static GtkWidget *menubox;
static GtkWidget *confwin;
static GtkWidget *okbut;
static GtkWidget *cancbut;
static GtkWidget *holdconftab;
static GtkWidget *confnote;
static GtkWidget *mainconfbox;
static GtkWidget *conflabel;
static GtkWidget *namepconftext;
static GtkWidget *namecconftext;
gint h,w;
GtkWidget *new;
int main (int argc, char *argv[])
{
GtkWidget *holderbox;
GtkWidget *file;
GtkWidget *fileitem;
GtkWidget *options;
GtkWidget *optionsitem;
GtkWidget *help;
GtkWidget *helpitem;
GtkWidget *helpme;
GtkWidget *about;
GtkWidget *speed;
GtkWidget *save;
GtkWidget *saveas;
GtkWidget *open;
GtkWidget *menubar;
GtkWidget *exit;
gtk_init (&argc, &argv);
//Some GDk_imlib stuff.
gdk_imlib_init();
gtk_widget_push_visual(gdk_imlib_get_visual());
gtk_widget_push_colormap(gdk_imlib_get_colormap());
mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (mainwin), "Free Market!!!");
gtk_widget_set_usize(mainwin, 800, 600);
gtk_window_set_policy(GTK_WINDOW(mainwin), FALSE, FALSE, TRUE);
gtk_signal_connect (GTK_OBJECT(mainwin), "delete_event",
GTK_SIGNAL_FUNC (quit), NULL);
// Boxes for the Menu and the main display and the notebook.
holderbox = gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(mainwin), holderbox);
menubox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(holderbox), menubox);
mainbox = gtk_vbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(holderbox), mainbox);
gtk_widget_show(holderbox);
gtk_widget_show(mainbox);
gtk_widget_show(menubox);
// I'm creating the Menu
file = gtk_menu_new();
new = gtk_menu_item_new_with_label("New Game");
open = gtk_menu_item_new_with_label("Open File");
save = gtk_menu_item_new_with_label("Save Game");
saveas = gtk_menu_item_new_with_label("Save Game As...");
exit = gtk_menu_item_new_with_label("Exit Game");
options = gtk_menu_new();
speed = gtk_menu_item_new_with_label("Speed Options");
help = gtk_menu_new();
helpme = gtk_menu_item_new_with_label("Help Me!!!");
about = gtk_menu_item_new_with_label("About Free Market");
gtk_menu_append( GTK_MENU(file), new);
gtk_menu_append( GTK_MENU(file), open);
gtk_menu_append( GTK_MENU(file), save);
gtk_menu_append( GTK_MENU(file), saveas);
gtk_menu_append( GTK_MENU(file), exit);
gtk_menu_append( GTK_MENU(options), speed);
gtk_menu_append( GTK_MENU(help), helpme);
gtk_menu_append( GTK_MENU(help), about);
//Put callback functions.
gtk_signal_connect_object( GTK_OBJECT(new), "activate",
GTK_SIGNAL_FUNC(newgame), NULL);
gtk_signal_connect_object( GTK_OBJECT(open), "activate",
GTK_SIGNAL_FUNC(openfile), NULL);
gtk_signal_connect_object( GTK_OBJECT(saveas), "activate",
GTK_SIGNAL_FUNC(savefilefunc), NULL);
gtk_signal_connect_object( GTK_OBJECT(exit), "activate",
GTK_SIGNAL_FUNC(quit), NULL);
//Show menu items for File.
gtk_widget_show(new);
gtk_widget_show(open);
gtk_widget_show(save);
gtk_widget_show(saveas);
gtk_widget_show(exit);
gtk_widget_show(speed);
gtk_widget_show(helpme);
gtk_widget_show(about);
// Attach the file menu items to the menu bar, etc.
menubar = gtk_menu_bar_new ();
gtk_box_pack_start(GTK_BOX(menubox), menubar, FALSE, TRUE, 0);
fileitem = gtk_menu_item_new_with_label("File");
gtk_widget_show(fileitem);
optionsitem = gtk_menu_item_new_with_label("Options");
gtk_widget_show(optionsitem);
helpitem = gtk_menu_item_new_with_label("Help");
gtk_widget_show(helpitem);
gtk_menu_item_set_submenu( GTK_MENU_ITEM(fileitem), file );
gtk_menu_bar_append( GTK_MENU_BAR (menubar), fileitem );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(optionsitem), options);
gtk_menu_bar_append( GTK_MENU_BAR (menubar), optionsitem);
gtk_menu_item_set_submenu( GTK_MENU_ITEM(helpitem), help);
gtk_menu_item_right_justify( GTK_MENU_ITEM(helpitem));
gtk_menu_bar_append( GTK_MENU_BAR (menubar), helpitem);
//Create opening screen with drawingarea.
openscreen = gtk_drawing_area_new();
gtk_drawing_area_size (GTK_DRAWING_AREA (openscreen),790,570);
gtk_box_pack_start(GTK_BOX(mainbox), openscreen, FALSE, FALSE, 0);
gtk_widget_realize(GTK_WIDGET(openscreen));
gopen = gdk_imlib_load_image("open.png");
w=gopen->rgb_width;
h=gopen->rgb_height;
gdk_imlib_render(gopen,w,h);
gdk_window_set_back_pixmap(GTK_WIDGET(openscreen)->window,
gdk_imlib_move_image(gopen), FALSE);
gdk_window_shape_combine_mask(GTK_WIDGET(openscreen)->window,
gdk_imlib_move_image(gopen), 0, 0);
gdk_imlib_destroy_image(gopen);
gtk_widget_show (openscreen);
//Create notebook to organize data.
marketnotebook = gtk_notebook_new ();
gtk_notebook_set_tab_pos( GTK_NOTEBOOK(marketnotebook), GTK_POS_TOP);
mainnotebook = gtk_notebook_new ();
gtk_notebook_set_tab_pos( GTK_NOTEBOOK(mainnotebook),GTK_POS_TOP);
marketlabel = gtk_label_new("Markets");
//Create Company box for Company info.
companybox = gtk_vbox_new (FALSE,0);
//Show what's left
gtk_widget_show(menubar );
gtk_widget_show(mainwin);
gtk_main ();
return 0;
}
void quit ()
{
gtk_main_quit ();
}
void openfile ()
{
fileopen = gtk_file_selection_new("Open a Game File");
// savefile = gtk_file_selection_get_filename( GTK_FILE_SELECTION (fileopen) );
gtk_signal_connect (GTK_OBJECT (fileopen), "destroy",
(GtkSignalFunc) byeopen, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (fileopen)->cancel_button), "clicked",
(GtkSignalFunc) byeopen, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (fileopen)->ok_button), "clicked",
(GtkSignalFunc) readfile, NULL);
gtk_widget_show(fileopen);
}
void readfile()
{
// savefile = gtk_file_selection_get_filename( GTK_FILE_SELECTION (fileopen) );
gtk_widget_destroy(fileopen);
}
void savefilefunc ()
{
filesave = gtk_file_selection_new("Save a Game File");
gtk_signal_connect (GTK_OBJECT (filesave), "destroy",
(GtkSignalFunc) byesave, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesave)->cancel_button), "clicked",
(GtkSignalFunc) byesave, NULL);
gtk_widget_show(filesave);
}
void byeopen ()
{
gtk_widget_destroy(fileopen);
}
void byesave ()
{
gtk_widget_destroy(filesave);
}
void newgame ()
{
GtkWidget *button_box;
//New Dialog window, for configurations
confwin = gtk_window_new(GTK_WINDOW_DIALOG);
gtk_window_set_title (GTK_WINDOW (confwin), "Configure New Game");
gtk_widget_set_usize(confwin, 300, 180);
gtk_signal_connect (GTK_OBJECT(confwin), "delete_event",
GTK_SIGNAL_FUNC (byeconf), NULL);
holdconftab = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(confwin), holdconftab);
gtk_widget_show(holdconftab);
//Buttons.
button_box = gtk_hbutton_box_new ();
//gtk_button_box_set_spacing (GTK_BUTTON_BOX (button_box), 0);
//gtk_button_box_set_child_size (GTK_BUTTON_BOX (button_box), 0, 0);
//gtk_button_box_set_child_ipadding (GTK_BUTTON_BOX (button_box), 0, 0);
gtk_box_pack_end (GTK_BOX (holdconftab), button_box, TRUE, TRUE, 0);
gtk_widget_show (button_box);
okbut = gtk_button_new_with_label("Ok");
gtk_container_add (GTK_CONTAINER (button_box), okbut);
gtk_widget_show(okbut);
gtk_signal_connect (GTK_OBJECT(okbut), "clicked",
GTK_SIGNAL_FUNC (gameinitopen), NULL);
cancbut = gtk_button_new_with_label("Cancel");
gtk_container_add (GTK_CONTAINER (button_box), cancbut);
gtk_widget_show(cancbut);
gtk_signal_connect (GTK_OBJECT(cancbut), "clicked",
GTK_SIGNAL_FUNC (byeconf), NULL);
//Configuration Notebook.
confnote = gtk_notebook_new ();
conflabel = gtk_label_new("Game Settings");
gtk_notebook_set_tab_pos( GTK_NOTEBOOK(confnote),GTK_POS_TOP);
gtk_box_pack_start (GTK_BOX (holdconftab), confnote, TRUE, TRUE, 0);
//Box that holds the notebook which displays all the info
mainconfbox = gtk_vbox_new(FALSE,0);
//The stuff you enter info into.
namepconftext = gtk_entry_new_with_max_length(20);
namecconftext = gtk_entry_new_with_max_length(20);
gtk_entry_set_text( GTK_ENTRY (namepconftext),
"Mr. Linus Torvalds" );
gtk_entry_set_text( GTK_ENTRY (namecconftext),
"Linux International" );
nameofplayer = strdup(gtk_entry_get_text( GTK_ENTRY (namepconftext) ));
nameofcompany = strdup(gtk_entry_get_text( GTK_ENTRY (namecconftext) ));
gtk_box_pack_start (GTK_BOX (mainconfbox), namepconftext, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (mainconfbox), namecconftext, TRUE, TRUE, 0);
gtk_widget_show(namepconftext);
gtk_widget_show(namecconftext);
gtk_notebook_insert_page( (GtkNotebook*) confnote,
mainconfbox,
conflabel,
1 );
gtk_widget_show(mainconfbox);
gtk_widget_show(confnote);
gtk_widget_show(confwin);
gtk_widget_set_sensitive(mainwin,FALSE);
}
void byeconf ()
{
gtk_widget_destroy(confwin);
gtk_widget_set_sensitive(mainwin,TRUE);
}
void gameinitopen ()
{
gtk_widget_set_sensitive(new,FALSE);
nameofplayer = strdup(gtk_entry_get_text( GTK_ENTRY (namepconftext) ));
nameofcompany = strdup(gtk_entry_get_text( GTK_ENTRY (namecconftext) ));
gtk_widget_destroy(openscreen);
gtk_widget_destroy(confwin);
readcompfiles();
init_clists();
init_clists_compname();
init_notebooks();
gtk_widget_set_sensitive(mainwin,TRUE);
}
void readcompfiles()
{
DIR *compdir;
FILE *comp_file_pointer;
struct dirent *cmpn; //companyname2
gint entyno=0; //Entry number
gchar *tmpdir,*shortname,*cmps[1000];//Maximum of 1000 companies
company_data *comp_data_pointer;
companies_data_list = g_new(GList,1);
tmpdir = g_strconcat(g_get_home_dir (), "/.freemarket/companies/",NULL);
compdir = opendir (tmpdir);
g_free(tmpdir);
if (compdir != NULL)
{
while ((cmpn = readdir(compdir)))
{
if (entyno == 999)
break;
else
{
if ( strrchr( cmpn->d_name, '/' ) )
shortname = strrchr( cmpn->d_name, '/' ) + 1;
else
shortname = cmpn->d_name;
if ( strcmp( shortname, "." ) && strcmp( shortname, ".." ) )
{
cmps[entyno] = strdup(cmpn->d_name);
entyno++;
}
}
}
(void) closedir (compdir);
}
else
{
printf ("Free Market couldn't open that directory.\nAre you sure you have the directory ~/.freemarket/companies/ ? \n");
return;
}
nocomps = entyno;
while (entyno >0)
{
if((comp_file_pointer = fopen (cmps[entyno],"rb")) !=NULL)
{
fread(temp_data_hold,sizeof(company_data),1,comp_file_pointer);
sav_comp_file_names[entyno] = strdup(cmps[entyno]);
g_free(cmps[entyno]);
entyno--;
nocomps++;
comp_data_pointer = get_comp_data_pointer();
companies_data_list = g_list_append(companies_data_list,comp_data_pointer);
//g_free(raw_data_from_file);
g_free(temp_data_hold);
}
else
{
printf ("Free Market couldn't open that File. \nAre you sure you have the file %s ?\n",
cmps[entyno]);
return;
}
}
}
company_data* get_comp_data_pointer()
{
gint pn=0; //Paragraph Numbers +1
raw_data_from_file = g_new(company_data,1);
temp_data_hold = g_new(company_data,1);
strcpy(((gchar *)((company_data *)raw_data_from_file)->category),temp_data_hold->category);
strcpy(((gchar *)((company_data *)raw_data_from_file)->comp_name),temp_data_hold->comp_name);
((gint *)((company_data *)raw_data_from_file)->max_start_stocks) = temp_data_hold->max_start_stocks;
((gint *)((company_data *)raw_data_from_file)->max_start_price) = temp_data_hold->max_start_price;
((gint *)((company_data *)raw_data_from_file)->current_price) = temp_data_hold->current_price;
((gint *)((company_data *)raw_data_from_file)->no_you_own) = temp_data_hold->no_you_own;
((gint *)((company_data *)raw_data_from_file)->prestige) = temp_data_hold->prestige;
((gint *)((company_data *)raw_data_from_file)->mass_appeal) = temp_data_hold->mass_appeal;
((gint *)((company_data *)raw_data_from_file)->competition) = temp_data_hold->competition;
while(pn <=4)
{
strcpy(((gchar *)((company_data *)raw_data_from_file)->good_news[pn])
,temp_data_hold->good_news[pn]);
strcpy(((gchar *)((company_data *)raw_data_from_file)->very_good_news[pn])
,temp_data_hold->very_good_news[pn]);
strcpy(((gchar *)((company_data *)raw_data_from_file)->bad_news[pn])
,temp_data_hold->bad_news[pn]);
strcpy(((gchar *)((company_data *)raw_data_from_file)->very_bad_news[pn])
,temp_data_hold->very_bad_news[pn]);
pn++;
}
return ((company_data *)raw_data_from_file);
}
void init_clists()
{
//Create Clist for the Technology Market.
techbox = gtk_vbox_new (FALSE,0);
techlabel = gtk_label_new("Technology");
gtk_container_set_border_width (GTK_CONTAINER (techbox), 5);
techlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(techlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(techlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(techlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(techlist),
3,150);
gtk_box_pack_start(GTK_BOX(techbox), techlist, TRUE, TRUE, 3);
gtk_widget_show(techlist);
gtk_widget_show(techbox);
//Create Clist for the Financial Market
finbox = gtk_vbox_new (FALSE,0);
finlabel = gtk_label_new("Financial");
gtk_container_set_border_width (GTK_CONTAINER (finbox), 5);
finlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(finlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(finlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(finlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(finlist),
3,150);
gtk_box_pack_start(GTK_BOX(finbox), finlist, TRUE, TRUE, 3);
gtk_widget_show(finlist);
gtk_widget_show(finbox);
//Clist for the Automotive Market
autobox = gtk_vbox_new (FALSE,0);
autolabel = gtk_label_new("Automotive");
gtk_container_set_border_width (GTK_CONTAINER (autobox), 5);
autolist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(autolist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(autolist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(autolist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(autolist),
3,150);
gtk_box_pack_start(GTK_BOX(autobox), autolist, TRUE, TRUE, 3);
gtk_widget_show(autolist);
gtk_widget_show(autobox);
//Clist for the Gas & Oil Market
gobox = gtk_vbox_new (FALSE,0);
golabel = gtk_label_new("Gas & Oil");
gtk_container_set_border_width (GTK_CONTAINER (gobox), 5);
golist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(golist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(golist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(golist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(golist),
3,150);
gtk_box_pack_start(GTK_BOX(gobox), golist, TRUE, TRUE, 3);
gtk_widget_show(golist);
gtk_widget_show(gobox);
//Clist fot the Food, Beverage & Tobacco market
fbtbox = gtk_vbox_new (FALSE,0);
fbtlabel = gtk_label_new("Food, Beverage & Tobacco");
gtk_container_set_border_width (GTK_CONTAINER (fbtbox), 5);
fbtlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(fbtlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(fbtlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(fbtlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(fbtlist),
3,150);
gtk_box_pack_start(GTK_BOX(fbtbox), fbtlist, TRUE, TRUE, 3);
gtk_widget_show(fbtlist);
gtk_widget_show(fbtbox);
//Clist for the Manufacturing, Distribution & Trading market
mdtbox = gtk_vbox_new (FALSE,0);
mdtlabel = gtk_label_new("Manufacturing, Distribution & Trading");
gtk_container_set_border_width (GTK_CONTAINER (mdtbox), 5);
mdtlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(mdtlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(mdtlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(mdtlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(mdtlist),
3,150);
gtk_box_pack_start(GTK_BOX(mdtbox), mdtlist, TRUE, TRUE, 3);
gtk_widget_show(mdtlist);
gtk_widget_show(mdtbox);
//Clist fot the Holding Firms' market
holdbox = gtk_vbox_new (FALSE,0);
holdlabel = gtk_label_new("Holding Firms");
gtk_container_set_border_width (GTK_CONTAINER (holdbox), 5);
holdlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(holdlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(holdlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(holdlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(holdlist),
3,150);
gtk_box_pack_start(GTK_BOX(holdbox), holdlist, TRUE, TRUE, 3);
gtk_widget_show(holdlist);
gtk_widget_show(holdbox);
//Clist for the Communication market
commbox = gtk_vbox_new (FALSE,0);
commlabel = gtk_label_new("Communication");
gtk_container_set_border_width (GTK_CONTAINER (commbox), 5);
commlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(commlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(commlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(commlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(commlist),
3,150);
gtk_box_pack_start(GTK_BOX(commbox), commlist, TRUE, TRUE, 3);
gtk_widget_show(commlist);
gtk_widget_show(commbox);
//Clist for the Banks market
bankbox = gtk_vbox_new (FALSE,0);
banklabel = gtk_label_new("Banks");
gtk_container_set_border_width (GTK_CONTAINER (bankbox), 5);
banklist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(banklist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(banklist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(banklist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(banklist),
3,150);
gtk_box_pack_start(GTK_BOX(bankbox), banklist, TRUE, TRUE, 3);
gtk_widget_show(banklist);
gtk_widget_show(bankbox);
//Clist for the Power & Energy Market
pebox = gtk_vbox_new (FALSE,0);
pelabel = gtk_label_new("Power & Energy");
gtk_container_set_border_width (GTK_CONTAINER (pebox), 5);
pelist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(pelist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(pelist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(pelist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(pelist),
3,150);
gtk_box_pack_start(GTK_BOX(pebox), pelist, TRUE, TRUE, 3);
gtk_widget_show(pelist);
gtk_widget_show(pebox);
//Clist fot the Construction market
constbox = gtk_vbox_new (FALSE,0);
constlabel = gtk_label_new("Construction");
gtk_container_set_border_width (GTK_CONTAINER (constbox), 5);
constlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(constlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(constlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(constlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(constlist),
3,150);
gtk_box_pack_start(GTK_BOX(constbox), constlist, TRUE, TRUE, 3);
gtk_widget_show(constlist);
gtk_widget_show(constbox);
//Clist for the Hotel & Recreation market
hrbox = gtk_vbox_new (FALSE,0);
hrlabel = gtk_label_new("Hotel & Recreation");
gtk_container_set_border_width (GTK_CONTAINER (hrbox), 5);
hrlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(hrlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(hrlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(hrlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(hrlist),
3,150);
gtk_box_pack_start(GTK_BOX(hrbox), hrlist, TRUE, TRUE, 3);
gtk_widget_show(hrlist);
gtk_widget_show(hrbox);
//Clist for the Mining market
miningbox = gtk_vbox_new (FALSE,0);
mininglabel = gtk_label_new("Mining");
gtk_container_set_border_width (GTK_CONTAINER (miningbox), 5);
mininglist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(mininglist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(mininglist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(mininglist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(mininglist),
3,150);
gtk_box_pack_start(GTK_BOX(miningbox), mininglist, TRUE, TRUE, 3);
gtk_widget_show(mininglist);
gtk_widget_show(miningbox);
//Clist for the Property & Real Estate market
prbox = gtk_vbox_new (FALSE,0);
prlabel = gtk_label_new("Property & Real Estate");
gtk_container_set_border_width (GTK_CONTAINER (prbox), 5);
prlist = gtk_clist_new_with_titles(4,markettitles);
gtk_clist_set_column_width(GTK_CLIST(prlist),
0,300);
gtk_clist_set_column_width(GTK_CLIST(prlist),
1,150);
gtk_clist_set_column_width(GTK_CLIST(prlist),
2,150);
gtk_clist_set_column_width(GTK_CLIST(prlist),
3,150);
gtk_box_pack_start(GTK_BOX(prbox), prlist, TRUE, TRUE, 3);
gtk_widget_show(prlist);
gtk_widget_show(prbox);
}
void init_notebooks()
{
gtk_notebook_set_scrollable( (GtkNotebook*)marketnotebook,
TRUE);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
techbox,
techlabel,
1 );
gtk_widget_show(techlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
finbox,
finlabel,
2 );
gtk_widget_show(finlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
autobox,
autolabel,
3 );
gtk_widget_show(autolabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
gobox,
golabel,
4 );
gtk_widget_show(golabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
fbtbox,
fbtlabel,
5 );
gtk_widget_show(fbtlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
mdtbox,
mdtlabel,
6 );
gtk_widget_show(mdtlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
holdbox,
holdlabel,
7 );
gtk_widget_show(holdlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
commbox,
commlabel,
8 );
gtk_widget_show(commlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
bankbox,
banklabel,
9 );
gtk_widget_show(banklabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
pebox,
pelabel,
10 );
gtk_widget_show(pelabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
constbox,
constlabel,
11 );
gtk_widget_show(constlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
hrbox,
hrlabel,
12 );
gtk_widget_show(hrlabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
miningbox,
mininglabel,
13 );
gtk_widget_show(mininglabel);
gtk_notebook_insert_page( (GtkNotebook*) marketnotebook,
prbox,
prlabel,
14 );
gtk_widget_show(prlabel);
gtk_notebook_insert_page( (GtkNotebook*) mainnotebook,
marketnotebook,
marketlabel,
1 );
gtk_widget_show(marketlabel);
companylabel = gtk_label_new(nameofcompany);
gtk_notebook_insert_page( (GtkNotebook*) mainnotebook,
companybox,
companylabel,
2 );
gtk_widget_show (companylabel);
gtk_widget_show (companybox);
gtk_widget_destroy(mainbox);
gtk_box_pack_start(GTK_BOX(menubox),mainnotebook, TRUE, TRUE, 0);
gtk_widget_show(mainnotebook);
gtk_widget_show(marketnotebook);
}
void init_clists_compname()
{
gint nocomps_l;
gchar *clist_txt_buff[4];
gint start_price;
gint start_available;
gint max_start_price_buff;
gint max_start_stocks_buff;
nocomps_l = nocomps;
srand(time(NULL));
if (nocomps_l > 0)
{
max_start_price_buff = ((company_data *)companies_data_list->data)->max_start_price;
max_start_stocks_buff = ((company_data *)companies_data_list->data)->max_start_stocks;
start_price = 1+(int)(max_start_price_buff *rand()/(RAND_MAX+1.0));
start_available = 1+(int) (max_start_stocks_buff *rand()/(RAND_MAX+1.0));
clist_txt_buff[1] = g_strdup(((company_data *)companies_data_list->data)->comp_name);
clist_txt_buff[2] = g_strdup_printf( "%d", start_price);
clist_txt_buff[3] = g_strdup_printf( "%d", start_available);
clist_txt_buff[4] = g_strdup_printf( "%d", ((company_data*)companies_data_list->data)->no_you_own);
gtk_clist_append( GTK_CLIST (techlist), clist_txt_buff);
nocomps_l--;
nblist('n');
}
else
return;
}
void nblist(gchar np)
{
if (np == 'n')
companies_data_list = companies_data_list->next;
else
companies_data_list = companies_data_list->prev;
}
/* This Program is liscensed under the GNU/GPL and is owned by Glenn Bautista Jr. */
/* REMINDER!!!!!!!!!!!!!!!! .... To all of those who will use this, please dont */
/* write stuff more than 500 characters in the News text entries, it won't be saved */
#include <glib.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
void quit();
void openfile();
void savefile();
void printhelpme();
void printabout();
void filesavecanc();
void fileopencanc();
void filesavewrite();
void fileopenread();
typedef struct _company_data
{
gchar category[45];
gchar comp_name[16];
gint max_start_stocks;
gint max_start_price;
gint current_price;
gint no_you_own;
gint prestige;
gint mass_appeal;
gint competition;
gchar good_news[5][500];
gchar very_good_news[5][500];
gchar bad_news[5][500];
gchar very_bad_news[5][500];
} company_data;
/* The Global Variables for stuff thats gonna be saved */
gint mspint;
gint mnossint;
GtkWidget *compnametextent;
GtkWidget *catcomb;
GtkWidget *mspent;
GtkWidget *mnossent;
GtkWidget *gnewsent1; /* The Text Entry */
GtkWidget *gnewsent2;
GtkWidget *gnewsent3;
GtkWidget *gnewsent4;
GtkWidget *gnewsent5;
GtkWidget *vgnewsent1;
GtkWidget *vgnewsent2;
GtkWidget *vgnewsent3;
GtkWidget *vgnewsent4;
GtkWidget *vgnewsent5;
GtkWidget *bnewsent1;
GtkWidget *bnewsent2;
GtkWidget *bnewsent3;
GtkWidget *bnewsent4;
GtkWidget *bnewsent5;
GtkWidget *vbnewsent1;
GtkWidget *vbnewsent2;
GtkWidget *vbnewsent3;
GtkWidget *vbnewsent4;
GtkWidget *vbnewsent5;
/* The widgets that need to be Global */
GtkWidget *filesave;
GtkWidget *fileopen;
/* So that I can sensitize/unsensitize them menu thingies */
GtkWidget *save;
GtkWidget *openn;
void main (int argc, char *argv[])
{
/* The Boxes that contains most of everything */
GtkWidget *mainwin;
GtkWidget *holderbox;
GtkWidget *menubox;
GtkWidget *mainbox;
GtkWidget *mainscrollwin;
/* the vars for the menus */
GtkWidget *file;
GtkWidget *exit;
GtkWidget *help;
GtkWidget *helpme;
GtkWidget *about;
GtkWidget *fileitem;
GtkWidget *helpitem;
GtkWidget *menubar;
/* The variables for the graphical part of the data entry */
GtkWidget *compnamehbox;
GtkWidget *compnamelabel;
GtkWidget *cathbox;
GtkWidget *catlabel;
GList *catnames = NULL;
GtkWidget *gnewsframe;
GtkWidget *gnewsnote;
GtkWidget *gnewsnotelabel1; /* The Label for the Notebook */
GtkWidget *gnewsscrlentb1; /* The Box where the Scrollbar and the Text entry is put into */
GtkWidget *gnewsscrl1; /* The ScrollBar */
GtkWidget *gnewsnotelabel2;
GtkWidget *gnewsscrlentb2;
GtkWidget *gnewsscrl2;
GtkWidget *gnewsnotelabel3;
GtkWidget *gnewsscrlentb3;
GtkWidget *gnewsscrl3;
GtkWidget *gnewsnotelabel4;
GtkWidget *gnewsscrlentb4;
GtkWidget *gnewsscrl4;
GtkWidget *gnewsnotelabel5;
GtkWidget *gnewsscrlentb5;
GtkWidget *gnewsscrl5;
GtkWidget *vgnewsframe;
GtkWidget *vgnewsnote;
GtkWidget *vgnewsnotelabel1;
GtkWidget *vgnewsscrlentb1;
GtkWidget *vgnewsscrl1;
GtkWidget *vgnewsnotelabel2;
GtkWidget *vgnewsscrlentb2;
GtkWidget *vgnewsscrl2;
GtkWidget *vgnewsnotelabel3;
GtkWidget *vgnewsscrlentb3;
GtkWidget *vgnewsscrl3;
GtkWidget *vgnewsnotelabel4;
GtkWidget *vgnewsscrlentb4;
GtkWidget *vgnewsscrl4;
GtkWidget *vgnewsnotelabel5;
GtkWidget *vgnewsscrlentb5;
GtkWidget *vgnewsscrl5;
GtkWidget *bnewsframe;
GtkWidget *bnewsnote;
GtkWidget *bnewsnotelabel1;
GtkWidget *bnewsscrlentb1;
GtkWidget *bnewsscrl1;
GtkWidget *bnewsnotelabel2;
GtkWidget *bnewsscrlentb2;
GtkWidget *bnewsscrl2;
GtkWidget *bnewsnotelabel3;
GtkWidget *bnewsscrlentb3;
GtkWidget *bnewsscrl3;
GtkWidget *bnewsnotelabel4;
GtkWidget *bnewsscrlentb4;
GtkWidget *bnewsscrl4;
GtkWidget *bnewsnotelabel5;
GtkWidget *bnewsscrlentb5;
GtkWidget *bnewsscrl5;
GtkWidget *vbnewsframe;
GtkWidget *vbnewsnote;
GtkWidget *vbnewsnotelabel1;
GtkWidget *vbnewsscrlentb1;
GtkWidget *vbnewsscrl1;
GtkWidget *vbnewsnotelabel2;
GtkWidget *vbnewsscrlentb2;
GtkWidget *vbnewsscrl2;
GtkWidget *vbnewsnotelabel3;
GtkWidget *vbnewsscrlentb3;
GtkWidget *vbnewsscrl3;
GtkWidget *vbnewsnotelabel4;
GtkWidget *vbnewsscrlentb4;
GtkWidget *vbnewsscrl4;
GtkWidget *vbnewsnotelabel5;
GtkWidget *vbnewsscrlentb5;
GtkWidget *vbnewsscrl5;
GtkWidget *mspbox; /* Maximum Starting Price */
GtkWidget *msplabel;
GtkWidget *mnossbox; /* Maximum No. of Starting Stocks */
GtkWidget *mnosslabel;
/* The Program starts here */
gtk_init (&argc, &argv);
mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (mainwin), "Free Market!!!");
gtk_widget_set_usize(mainwin, 800, 600);
gtk_window_set_policy(GTK_WINDOW(mainwin), FALSE, FALSE, TRUE);
gtk_signal_connect (GTK_OBJECT (mainwin), "delete_event",
GTK_SIGNAL_FUNC (quit), NULL);
/* I'm Making the Boxes that will contain most of everything */
/* I'm also putting and making a Scrolled window here */
holderbox = gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(mainwin), holderbox);
menubox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(holderbox), menubox, FALSE, FALSE, 0);
mainscrollwin = gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mainscrollwin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
mainbox = gtk_vbox_new(FALSE,0);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (mainscrollwin),
mainbox);
gtk_box_pack_start(GTK_BOX(holderbox), mainscrollwin, TRUE, TRUE, 0);
gtk_widget_show(holderbox);
gtk_widget_show(mainscrollwin);
gtk_widget_show(mainbox);
gtk_widget_show(menubox);
/* I'm Making the Menus */
file = gtk_menu_new();
openn = gtk_menu_item_new_with_label("Open File");
save = gtk_menu_item_new_with_label("Save File");
exit = gtk_menu_item_new_with_label("Exit Company Editor");
help = gtk_menu_new();
helpme = gtk_menu_item_new_with_label("Help Me!!");
about = gtk_menu_item_new_with_label("About");
gtk_menu_append( GTK_MENU(file), openn);
gtk_menu_append( GTK_MENU(file), save);
gtk_menu_append( GTK_MENU(file), exit);
gtk_menu_append( GTK_MENU(help), helpme);
gtk_menu_append( GTK_MENU(help), about);
/* I'm putting the callback functions into their respective Menus */
gtk_signal_connect_object( GTK_OBJECT(openn), "activate",
GTK_SIGNAL_FUNC(openfile), NULL);
gtk_signal_connect_object( GTK_OBJECT(save), "activate",
GTK_SIGNAL_FUNC(savefile), NULL);
gtk_signal_connect_object( GTK_OBJECT(exit), "activate",
GTK_SIGNAL_FUNC(quit), NULL);
gtk_signal_connect_object( GTK_OBJECT(helpme), "activate",
GTK_SIGNAL_FUNC(printhelpme), NULL);
gtk_signal_connect_object( GTK_OBJECT(about), "activate",
GTK_SIGNAL_FUNC(printabout), NULL);
/* Show Menu Items for all*/
gtk_widget_show(openn);
gtk_widget_show(save);
gtk_widget_show(exit);
gtk_widget_show(helpme);
gtk_widget_show(about);
/* I'm attaching all the menu stuff together */
menubar = gtk_menu_bar_new ();
gtk_box_pack_start(GTK_BOX(menubox), menubar, FALSE, FALSE, 0);
fileitem = gtk_menu_item_new_with_label("File");
gtk_widget_show(fileitem);
helpitem = gtk_menu_item_new_with_label("Help");
gtk_widget_show(helpitem);
gtk_menu_item_set_submenu( GTK_MENU_ITEM(fileitem), file );
gtk_menu_bar_append( GTK_MENU_BAR (menubar), fileitem );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(helpitem), help);
gtk_menu_item_right_justify( GTK_MENU_ITEM(helpitem));
gtk_menu_bar_append( GTK_MENU_BAR (menubar), helpitem);
/* Ok, Here's where the action begins; Well, not really, */
/* its where the GUI action begins, The Data entry points */
/* Company Name Stuff */
compnamehbox = gtk_hbox_new (FALSE,5);
compnamelabel = gtk_label_new ("Company Name:");
compnametextent = gtk_entry_new_with_max_length(16);
gtk_entry_set_text(GTK_ENTRY(compnametextent),"My Company");
gtk_box_pack_start (GTK_BOX (compnamehbox), compnamelabel, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (compnamehbox), compnametextent, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (mainbox), compnamehbox, FALSE, FALSE, 5);
gtk_widget_show(compnametextent);
gtk_widget_show(compnamelabel);
gtk_widget_show(compnamehbox);
/* The Category Stuff */
cathbox = gtk_hbox_new(FALSE,5);
catlabel = gtk_label_new("Category:");
catnames = g_list_append(catnames,"Technology");
catnames = g_list_append(catnames,"Financial");
catnames = g_list_append(catnames,"Automotive");
catnames = g_list_append(catnames,"Gas & Oil");
catnames = g_list_append(catnames,"Food, Beverage & Tobacco");
catnames = g_list_append(catnames,"Manufacturing, Distribution & Trading");
catnames = g_list_append(catnames,"Holding Firms");
catnames = g_list_append(catnames,"Communication");
catnames = g_list_append(catnames,"Banks");
catnames = g_list_append(catnames,"Power & Energy");
catnames = g_list_append(catnames,"Construction");
catnames = g_list_append(catnames,"Hotel & Recreation");
catnames = g_list_append(catnames,"Mining");
catnames = g_list_append(catnames,"Property & Real Estate");
catcomb = gtk_combo_new();
gtk_combo_set_popdown_strings (GTK_COMBO (catcomb), catnames);
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(catcomb)->entry), FALSE);
gtk_box_pack_start (GTK_BOX (cathbox), catlabel, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (cathbox), catcomb, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (mainbox), cathbox, FALSE, FALSE, 5);
gtk_widget_show(catlabel);
gtk_widget_show(catcomb);
gtk_widget_show(cathbox);
/* Maximum Starting Price stuff */
mspbox = gtk_hbox_new(FALSE, 5);
msplabel = gtk_label_new("Maximum Starting Price");
mspent = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(mspent),"0.0");
gtk_box_pack_start (GTK_BOX (mspbox), msplabel, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (mspbox), mspent, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (mainbox), mspbox, FALSE, FALSE, 5);
gtk_widget_show(mspent);
gtk_widget_show(msplabel);
gtk_widget_show(mspbox);
/* Maximum no. of Starting Stocks */
mnossbox = gtk_hbox_new(FALSE, 5);
mnosslabel = gtk_label_new("Maximum No. of Starting Stocks");
mnossent = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(mnossent),"0.0");
gtk_box_pack_start (GTK_BOX (mnossbox), mnosslabel, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (mnossbox), mnossent, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (mainbox), mnossbox, FALSE, FALSE, 5);
gtk_widget_show(mnossent);
gtk_widget_show(mnosslabel);
gtk_widget_show(mnossbox);
/* Good News stuff */
gnewsframe = gtk_frame_new(NULL);
gtk_frame_set_label(GTK_FRAME(gnewsframe),"Good News");
gnewsnote = gtk_notebook_new();
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gnewsnote), GTK_POS_TOP);
gnewsscrlentb1 = gtk_hbox_new(FALSE,0);
gnewsent1 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(gnewsent1), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(gnewsent1), TRUE);
gnewsscrl1 = gtk_vscrollbar_new(GTK_TEXT(gnewsent1)->vadj);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb1), gnewsent1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb1), gnewsscrl1, FALSE, FALSE, 0);
gnewsnotelabel1 = gtk_label_new("Good News 1");
gtk_notebook_append_page(GTK_NOTEBOOK(gnewsnote), gnewsscrlentb1, gnewsnotelabel1);
gtk_widget_show(gnewsnotelabel1);
gtk_widget_show(gnewsscrl1);
gtk_widget_show(gnewsent1);
gtk_widget_show(gnewsscrlentb1);
gnewsscrlentb2 = gtk_hbox_new(FALSE,0);
gnewsent2 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(gnewsent2), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(gnewsent2), TRUE);
gnewsscrl2 = gtk_vscrollbar_new(GTK_TEXT(gnewsent2)->vadj);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb2), gnewsent2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb2), gnewsscrl2, FALSE, FALSE, 0);
gnewsnotelabel2 = gtk_label_new("Good News 2");
gtk_notebook_append_page(GTK_NOTEBOOK(gnewsnote), gnewsscrlentb2, gnewsnotelabel2);
gtk_widget_show(gnewsnotelabel2);
gtk_widget_show(gnewsscrl2);
gtk_widget_show(gnewsent2);
gtk_widget_show(gnewsscrlentb2);
gnewsscrlentb3 = gtk_hbox_new(FALSE,0);
gnewsent3 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(gnewsent3), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(gnewsent3), TRUE);
gnewsscrl3 = gtk_vscrollbar_new(GTK_TEXT(gnewsent3)->vadj);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb3), gnewsent3, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb3), gnewsscrl3, FALSE, FALSE, 0);
gnewsnotelabel3 = gtk_label_new("Good News 3");
gtk_notebook_append_page(GTK_NOTEBOOK(gnewsnote), gnewsscrlentb3, gnewsnotelabel3);
gtk_widget_show(gnewsnotelabel3);
gtk_widget_show(gnewsscrl3);
gtk_widget_show(gnewsent3);
gtk_widget_show(gnewsscrlentb3);
gnewsscrlentb4 = gtk_hbox_new(FALSE,0);
gnewsent4 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(gnewsent4), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(gnewsent4), TRUE);
gnewsscrl4 = gtk_vscrollbar_new(GTK_TEXT(gnewsent4)->vadj);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb4), gnewsent4, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb4), gnewsscrl4, FALSE, FALSE, 0);
gnewsnotelabel4 = gtk_label_new("Good News 4");
gtk_notebook_append_page(GTK_NOTEBOOK(gnewsnote), gnewsscrlentb4, gnewsnotelabel4);
gtk_widget_show(gnewsnotelabel4);
gtk_widget_show(gnewsscrl4);
gtk_widget_show(gnewsent4);
gtk_widget_show(gnewsscrlentb4);
gnewsscrlentb5 = gtk_hbox_new(FALSE,0);
gnewsent5 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(gnewsent5), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(gnewsent5), TRUE);
gnewsscrl5 = gtk_vscrollbar_new(GTK_TEXT(gnewsent5)->vadj);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb5), gnewsent5, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(gnewsscrlentb5), gnewsscrl5, FALSE, FALSE, 0);
gnewsnotelabel5 = gtk_label_new("Good News 5");
gtk_notebook_append_page(GTK_NOTEBOOK(gnewsnote), gnewsscrlentb5, gnewsnotelabel5);
gtk_widget_show(gnewsnotelabel5);
gtk_widget_show(gnewsscrl5);
gtk_widget_show(gnewsent5);
gtk_widget_show(gnewsscrlentb5);
gtk_container_add(GTK_CONTAINER(gnewsframe),gnewsnote);
gtk_box_pack_start(GTK_BOX(mainbox), gnewsframe, FALSE, FALSE, 15);
gtk_widget_show(gnewsnote);
gtk_widget_show(gnewsframe);
/* Very Good News stuff */
vgnewsframe = gtk_frame_new(NULL);
gtk_frame_set_label(GTK_FRAME(vgnewsframe),"Very Good News");
vgnewsnote = gtk_notebook_new();
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(vgnewsnote), GTK_POS_TOP);
vgnewsscrlentb1 = gtk_hbox_new(FALSE,0);
vgnewsent1 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vgnewsent1), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vgnewsent1), TRUE);
vgnewsscrl1 = gtk_vscrollbar_new(GTK_TEXT(vgnewsent1)->vadj);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb1), vgnewsent1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb1), vgnewsscrl1, FALSE, FALSE, 0);
vgnewsnotelabel1 = gtk_label_new("Very Good News 1");
gtk_notebook_append_page(GTK_NOTEBOOK(vgnewsnote), vgnewsscrlentb1, vgnewsnotelabel1);
gtk_widget_show(vgnewsnotelabel1);
gtk_widget_show(vgnewsscrl1);
gtk_widget_show(vgnewsent1);
gtk_widget_show(vgnewsscrlentb1);
vgnewsscrlentb2 = gtk_hbox_new(FALSE,0);
vgnewsent2 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vgnewsent2), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vgnewsent2), TRUE);
vgnewsscrl2 = gtk_vscrollbar_new(GTK_TEXT(vgnewsent2)->vadj);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb2), vgnewsent2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb2), vgnewsscrl2, FALSE, FALSE, 0);
vgnewsnotelabel2 = gtk_label_new("Very Good News 2");
gtk_notebook_append_page(GTK_NOTEBOOK(vgnewsnote), vgnewsscrlentb2, vgnewsnotelabel2);
gtk_widget_show(vgnewsnotelabel2);
gtk_widget_show(vgnewsscrl2);
gtk_widget_show(vgnewsent2);
gtk_widget_show(vgnewsscrlentb2);
vgnewsscrlentb3 = gtk_hbox_new(FALSE,0);
vgnewsent3 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vgnewsent3), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vgnewsent3), TRUE);
vgnewsscrl3 = gtk_vscrollbar_new(GTK_TEXT(vgnewsent3)->vadj);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb3), vgnewsent3, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb3), vgnewsscrl3, FALSE, FALSE, 0);
vgnewsnotelabel3 = gtk_label_new("Very Good News 3");
gtk_notebook_append_page(GTK_NOTEBOOK(vgnewsnote), vgnewsscrlentb3, vgnewsnotelabel3);
gtk_widget_show(vgnewsnotelabel3);
gtk_widget_show(vgnewsscrl3);
gtk_widget_show(vgnewsent3);
gtk_widget_show(vgnewsscrlentb3);
vgnewsscrlentb4 = gtk_hbox_new(FALSE,0);
vgnewsent4 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vgnewsent4), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vgnewsent4), TRUE);
vgnewsscrl4 = gtk_vscrollbar_new(GTK_TEXT(vgnewsent4)->vadj);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb4), vgnewsent4, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb4), vgnewsscrl4, FALSE, FALSE, 0);
vgnewsnotelabel4 = gtk_label_new("Very Good News 4");
gtk_notebook_append_page(GTK_NOTEBOOK(vgnewsnote), vgnewsscrlentb4, vgnewsnotelabel4);
gtk_widget_show(vgnewsnotelabel4);
gtk_widget_show(vgnewsscrl4);
gtk_widget_show(vgnewsent4);
gtk_widget_show(vgnewsscrlentb4);
vgnewsscrlentb5 = gtk_hbox_new(FALSE,0);
vgnewsent5 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vgnewsent5), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vgnewsent5), TRUE);
vgnewsscrl5 = gtk_vscrollbar_new(GTK_TEXT(vgnewsent5)->vadj);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb5), vgnewsent5, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vgnewsscrlentb5), vgnewsscrl5, FALSE, FALSE, 0);
vgnewsnotelabel5 = gtk_label_new("Very Good News 5");
gtk_notebook_append_page(GTK_NOTEBOOK(vgnewsnote), vgnewsscrlentb5, vgnewsnotelabel5);
gtk_widget_show(vgnewsnotelabel5);
gtk_widget_show(vgnewsscrl5);
gtk_widget_show(vgnewsent5);
gtk_widget_show(vgnewsscrlentb5);
gtk_container_add(GTK_CONTAINER(vgnewsframe),vgnewsnote);
gtk_box_pack_start(GTK_BOX(mainbox), vgnewsframe, FALSE, FALSE, 15);
gtk_widget_show(vgnewsnote);
gtk_widget_show(vgnewsframe);
/* Bad News stuff */
bnewsframe = gtk_frame_new(NULL);
gtk_frame_set_label(GTK_FRAME(bnewsframe),"Bad News");
bnewsnote = gtk_notebook_new();
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(bnewsnote), GTK_POS_TOP);
bnewsscrlentb1 = gtk_hbox_new(FALSE,0);
bnewsent1 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(bnewsent1), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(bnewsent1), TRUE);
bnewsscrl1 = gtk_vscrollbar_new(GTK_TEXT(bnewsent1)->vadj);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb1), bnewsent1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb1), bnewsscrl1, FALSE, FALSE, 0);
bnewsnotelabel1 = gtk_label_new("Bad News 1");
gtk_notebook_append_page(GTK_NOTEBOOK(bnewsnote), bnewsscrlentb1, bnewsnotelabel1);
gtk_widget_show(bnewsnotelabel1);
gtk_widget_show(bnewsscrl1);
gtk_widget_show(bnewsent1);
gtk_widget_show(bnewsscrlentb1);
bnewsscrlentb2 = gtk_hbox_new(FALSE,0);
bnewsent2 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(bnewsent2), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(bnewsent2), TRUE);
bnewsscrl2 = gtk_vscrollbar_new(GTK_TEXT(bnewsent2)->vadj);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb2), bnewsent2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb2), bnewsscrl2, FALSE, FALSE, 0);
bnewsnotelabel2 = gtk_label_new("Bad News 2");
gtk_notebook_append_page(GTK_NOTEBOOK(bnewsnote), bnewsscrlentb2, bnewsnotelabel2);
gtk_widget_show(bnewsnotelabel2);
gtk_widget_show(bnewsscrl2);
gtk_widget_show(bnewsent2);
gtk_widget_show(bnewsscrlentb2);
bnewsscrlentb3 = gtk_hbox_new(FALSE,0);
bnewsent3 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(bnewsent3), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(bnewsent3), TRUE);
bnewsscrl3 = gtk_vscrollbar_new(GTK_TEXT(bnewsent3)->vadj);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb3), bnewsent3, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb3), bnewsscrl3, FALSE, FALSE, 0);
bnewsnotelabel3 = gtk_label_new("Bad News 3");
gtk_notebook_append_page(GTK_NOTEBOOK(bnewsnote), bnewsscrlentb3, bnewsnotelabel3);
gtk_widget_show(bnewsnotelabel3);
gtk_widget_show(bnewsscrl3);
gtk_widget_show(bnewsent3);
gtk_widget_show(bnewsscrlentb3);
bnewsscrlentb4 = gtk_hbox_new(FALSE,0);
bnewsent4 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(bnewsent4), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(bnewsent4), TRUE);
bnewsscrl4 = gtk_vscrollbar_new(GTK_TEXT(bnewsent4)->vadj);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb4), bnewsent4, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb4), bnewsscrl4, FALSE, FALSE, 0);
bnewsnotelabel4 = gtk_label_new("Bad News 4");
gtk_notebook_append_page(GTK_NOTEBOOK(bnewsnote), bnewsscrlentb4, bnewsnotelabel4);
gtk_widget_show(bnewsnotelabel4);
gtk_widget_show(bnewsscrl4);
gtk_widget_show(bnewsent4);
gtk_widget_show(bnewsscrlentb4);
bnewsscrlentb5 = gtk_hbox_new(FALSE,0);
bnewsent5 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(bnewsent5), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(bnewsent5), TRUE);
bnewsscrl5 = gtk_vscrollbar_new(GTK_TEXT(bnewsent5)->vadj);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb5), bnewsent5, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(bnewsscrlentb5), bnewsscrl5, FALSE, FALSE, 0);
bnewsnotelabel5 = gtk_label_new("Bad News 5");
gtk_notebook_append_page(GTK_NOTEBOOK(bnewsnote), bnewsscrlentb5, bnewsnotelabel5);
gtk_widget_show(bnewsnotelabel5);
gtk_widget_show(bnewsscrl5);
gtk_widget_show(bnewsent5);
gtk_widget_show(bnewsscrlentb5);
gtk_container_add(GTK_CONTAINER(bnewsframe),bnewsnote);
gtk_box_pack_start(GTK_BOX(mainbox), bnewsframe, FALSE, FALSE, 15);
gtk_widget_show(bnewsnote);
gtk_widget_show(bnewsframe);
/* Very Bad News stuff */
vbnewsframe = gtk_frame_new(NULL);
gtk_frame_set_label(GTK_FRAME(vbnewsframe),"Very Bad News");
vbnewsnote = gtk_notebook_new();
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(vbnewsnote), GTK_POS_TOP);
vbnewsscrlentb1 = gtk_hbox_new(FALSE,0);
vbnewsent1 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vbnewsent1), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vbnewsent1), TRUE);
vbnewsscrl1 = gtk_vscrollbar_new(GTK_TEXT(vbnewsent1)->vadj);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb1), vbnewsent1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb1), vbnewsscrl1, FALSE, FALSE, 0);
vbnewsnotelabel1 = gtk_label_new("Very Bad News 1");
gtk_notebook_append_page(GTK_NOTEBOOK(vbnewsnote), vbnewsscrlentb1, vbnewsnotelabel1);
gtk_widget_show(vbnewsnotelabel1);
gtk_widget_show(vbnewsscrl1);
gtk_widget_show(vbnewsent1);
gtk_widget_show(vbnewsscrlentb1);
vbnewsscrlentb2 = gtk_hbox_new(FALSE,0);
vbnewsent2 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vbnewsent2), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vbnewsent2), TRUE);
vbnewsscrl2 = gtk_vscrollbar_new(GTK_TEXT(vbnewsent2)->vadj);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb2), vbnewsent2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb2), vbnewsscrl2, FALSE, FALSE, 0);
vbnewsnotelabel2 = gtk_label_new("Very Bad News 2");
gtk_notebook_append_page(GTK_NOTEBOOK(vbnewsnote), vbnewsscrlentb2, vbnewsnotelabel2);
gtk_widget_show(vbnewsnotelabel2);
gtk_widget_show(vbnewsscrl2);
gtk_widget_show(vbnewsent2);
gtk_widget_show(vbnewsscrlentb2);
vbnewsscrlentb3 = gtk_hbox_new(FALSE,0);
vbnewsent3 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vbnewsent3), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vbnewsent3), TRUE);
vbnewsscrl3 = gtk_vscrollbar_new(GTK_TEXT(vbnewsent3)->vadj);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb3), vbnewsent3, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb3), vbnewsscrl3, FALSE, FALSE, 0);
vbnewsnotelabel3 = gtk_label_new("Very Bad News 3");
gtk_notebook_append_page(GTK_NOTEBOOK(vbnewsnote), vbnewsscrlentb3, vbnewsnotelabel3);
gtk_widget_show(vbnewsnotelabel3);
gtk_widget_show(vbnewsscrl3);
gtk_widget_show(vbnewsent3);
gtk_widget_show(vbnewsscrlentb3);
vbnewsscrlentb4 = gtk_hbox_new(FALSE,0);
vbnewsent4 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vbnewsent4), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vbnewsent4), TRUE);
vbnewsscrl4 = gtk_vscrollbar_new(GTK_TEXT(vbnewsent4)->vadj);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb4), vbnewsent4, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb4), vbnewsscrl4, FALSE, FALSE, 0);
vbnewsnotelabel4 = gtk_label_new("Very Bad News 4");
gtk_notebook_append_page(GTK_NOTEBOOK(vbnewsnote), vbnewsscrlentb4, vbnewsnotelabel4);
gtk_widget_show(vbnewsnotelabel4);
gtk_widget_show(vbnewsscrl4);
gtk_widget_show(vbnewsent4);
gtk_widget_show(vbnewsscrlentb4);
vbnewsscrlentb5 = gtk_hbox_new(FALSE,0);
vbnewsent5 = gtk_text_new(NULL,NULL);
gtk_text_set_editable(GTK_TEXT(vbnewsent5), TRUE);
gtk_text_set_word_wrap(GTK_TEXT(vbnewsent5), TRUE);
vbnewsscrl5 = gtk_vscrollbar_new(GTK_TEXT(vbnewsent5)->vadj);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb5), vbnewsent5, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbnewsscrlentb5), vbnewsscrl5, FALSE, FALSE, 0);
vbnewsnotelabel5 = gtk_label_new("Very Bad News 5");
gtk_notebook_append_page(GTK_NOTEBOOK(vbnewsnote), vbnewsscrlentb5, vbnewsnotelabel5);
gtk_widget_show(vbnewsnotelabel5);
gtk_widget_show(vbnewsscrl5);
gtk_widget_show(vbnewsent5);
gtk_widget_show(vbnewsscrlentb5);
gtk_container_add(GTK_CONTAINER(vbnewsframe),vbnewsnote);
gtk_box_pack_start(GTK_BOX(mainbox), vbnewsframe, FALSE, FALSE, 15);
gtk_widget_show(vbnewsnote);
gtk_widget_show(vbnewsframe);
/* Show the mainwindow etc. tie up loose ends */
gtk_widget_show(menubar);
gtk_widget_show(mainwin);
gtk_main();
}
void quit ()
{
gtk_main_quit ();
}
void openfile()
{
fileopen = gtk_file_selection_new("Open Company File");
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fileopen),"My Company");
gtk_signal_connect (GTK_OBJECT (fileopen), "destroy",
(GtkSignalFunc) fileopencanc, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fileopen)->cancel_button), "clicked",
(GtkSignalFunc) fileopencanc, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fileopen)->ok_button), "clicked",
(GtkSignalFunc) fileopenread, NULL);
gtk_widget_show(fileopen);
gtk_widget_set_sensitive(save,FALSE);
gtk_widget_set_sensitive(openn,FALSE);
}
void savefile()
{
filesave = gtk_file_selection_new("Save Company Data");
gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesave),"My Company");
gtk_signal_connect (GTK_OBJECT (filesave), "destroy",
(GtkSignalFunc) filesavecanc, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(filesave)->cancel_button), "clicked",
(GtkSignalFunc) filesavecanc, NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(filesave)->ok_button), "clicked",
(GtkSignalFunc) filesavewrite, NULL);
gtk_widget_show(filesave);
gtk_widget_set_sensitive(save,FALSE);
gtk_widget_set_sensitive(openn,FALSE);
}
void printhelpme()
{
}
void printabout()
{
}
void filesavecanc()
{
gtk_widget_destroy(filesave);
gtk_widget_set_sensitive(save,TRUE);
gtk_widget_set_sensitive(openn,TRUE);
}
void fileopencanc()
{
gtk_widget_destroy(fileopen);
gtk_widget_set_sensitive(save,TRUE);
gtk_widget_set_sensitive(openn,TRUE);
}
void filesavewrite()
{
company_data *filecontent;
FILE *file_pointer;
gchar *buffnews[20];
gint buffno = 0;
gchar *filename=NULL;
filecontent = g_new(company_data,1);
filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesave)));
gtk_widget_destroy(filesave);
gtk_widget_set_sensitive(save,TRUE);
gtk_widget_set_sensitive(openn,TRUE);
/* Load everything into the data structure */
strcpy(filecontent->comp_name,gtk_entry_get_text(GTK_ENTRY (compnametextent)));
strcpy(filecontent->category,gtk_entry_get_text(GTK_ENTRY (GTK_COMBO (catcomb)->entry)));
mspint = atoi(gtk_entry_get_text(GTK_ENTRY(mspent)));
filecontent->max_start_price = mspint;
mnossint = atoi(gtk_entry_get_text(GTK_ENTRY(mnossent)));
filecontent->max_start_stocks = mnossint;
filecontent->current_price = 0;
filecontent->no_you_own = 0;
filecontent->prestige = 0;
filecontent->mass_appeal = 0;
filecontent->competition = 0;
strcpy(filecontent->good_news[1],(buffnews[1] =
gtk_editable_get_chars( GTK_EDITABLE(gnewsent1),0,-1)));
strcpy(filecontent->good_news[2],(buffnews[2] =
gtk_editable_get_chars( GTK_EDITABLE(gnewsent2),0,-1)));
strcpy(filecontent->good_news[3],(buffnews[3] =
gtk_editable_get_chars( GTK_EDITABLE(gnewsent3),0,-1)));
strcpy(filecontent->good_news[4],(buffnews[4] =
gtk_editable_get_chars( GTK_EDITABLE(gnewsent4),0,-1)));
strcpy(filecontent->good_news[5],(buffnews[5] =
gtk_editable_get_chars( GTK_EDITABLE(gnewsent5),0,-1)));
strcpy(filecontent->very_good_news[1],(buffnews[6] =
gtk_editable_get_chars( GTK_EDITABLE(vgnewsent1),0,-1)));
strcpy(filecontent->very_good_news[2],(buffnews[7] =
gtk_editable_get_chars( GTK_EDITABLE(vgnewsent2),0,-1)));
strcpy(filecontent->very_good_news[3],(buffnews[8] =
gtk_editable_get_chars( GTK_EDITABLE(vgnewsent3),0,-1)));
strcpy(filecontent->very_good_news[4],(buffnews[9] =
gtk_editable_get_chars( GTK_EDITABLE(vgnewsent4),0,-1)));
strcpy(filecontent->very_good_news[5],(buffnews[10] =
gtk_editable_get_chars( GTK_EDITABLE(vgnewsent5),0,-1)));
strcpy(filecontent->bad_news[1],(buffnews[11] =
gtk_editable_get_chars( GTK_EDITABLE(bnewsent1),0,-1)));
strcpy(filecontent->bad_news[2],(buffnews[12] =
gtk_editable_get_chars( GTK_EDITABLE(bnewsent2),0,-1)));
strcpy(filecontent->bad_news[3],(buffnews[13] =
gtk_editable_get_chars( GTK_EDITABLE(bnewsent3),0,-1)));
strcpy(filecontent->bad_news[4],(buffnews[14] =
gtk_editable_get_chars( GTK_EDITABLE(bnewsent4),0,-1)));
strcpy(filecontent->bad_news[5],(buffnews[15] =
gtk_editable_get_chars( GTK_EDITABLE(bnewsent5),0,-1)));
strcpy(filecontent->very_bad_news[1],(buffnews[16] =
gtk_editable_get_chars( GTK_EDITABLE(vbnewsent1),0,-1)));
strcpy(filecontent->very_bad_news[2],(buffnews[17] =
gtk_editable_get_chars( GTK_EDITABLE(vbnewsent2),0,-1)));
strcpy(filecontent->very_bad_news[3],(buffnews[18] =
gtk_editable_get_chars( GTK_EDITABLE(vbnewsent3),0,-1)));
strcpy(filecontent->very_bad_news[4],(buffnews[19] =
gtk_editable_get_chars( GTK_EDITABLE(vbnewsent4),0,-1)));
strcpy(filecontent->very_bad_news[5],(buffnews[20] =
gtk_editable_get_chars( GTK_EDITABLE(vbnewsent5),0,-1)));
/* Saving the File */
if((file_pointer = fopen(filename,"w+b")) != NULL)
{
fwrite(filecontent, sizeof(company_data),1,file_pointer);
}
else
{
g_print("Unable to save %s\n",filename);
}
fclose(file_pointer);
/* Free the memory you allocate */
while(buffno < 20)
{
buffno++;
g_free(buffnews[buffno]);
}
g_free(filename);
g_free(filecontent);
}
void fileopenread()
{
company_data *filecontent;
FILE *file_pointer;
gchar mnoss[1024];
gchar msp[1024];
gchar *filename=NULL;
filecontent = g_new(company_data,1);
filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fileopen)));
gtk_widget_destroy(fileopen);
gtk_widget_set_sensitive(save,TRUE);
gtk_widget_set_sensitive(openn,TRUE);
/* Open and read the data from the file */
if((file_pointer = fopen(filename,"rb")) != NULL)
{
fread(filecontent,sizeof(company_data),1,file_pointer);
}
else
{
g_print("Unable to Open/Read %s\n",filename);
}
fclose(file_pointer);
/* Maybe I should Automate this stuff, but hey, its done anyway */
gtk_entry_set_text( GTK_ENTRY (compnametextent),filecontent->comp_name);
gtk_entry_set_text( GTK_ENTRY (GTK_COMBO (catcomb)->entry),filecontent->category);
g_snprintf(msp,1024,"%d",filecontent->max_start_price);
gtk_entry_set_text( GTK_ENTRY (mspent),msp);
g_snprintf(mnoss,1024,"%d",filecontent->max_start_stocks);
gtk_entry_set_text( GTK_ENTRY (mnossent),mnoss);
gtk_text_freeze(GTK_TEXT( gnewsent1));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (gnewsent1)), 0, -1);
gtk_text_set_point( GTK_TEXT(gnewsent1), 0);
gtk_text_insert( GTK_TEXT(gnewsent1), NULL, NULL, NULL, filecontent->good_news[1], -1);
gtk_text_thaw(GTK_TEXT( gnewsent1));
gtk_text_freeze(GTK_TEXT( gnewsent2));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (gnewsent2)), 0, -1);
gtk_text_set_point( GTK_TEXT(gnewsent2), 0);
gtk_text_insert( GTK_TEXT(gnewsent2), NULL, NULL, NULL, filecontent->good_news[2], -1);
gtk_text_thaw(GTK_TEXT( gnewsent2));
gtk_text_freeze(GTK_TEXT( gnewsent3));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (gnewsent3)), 0, -1);
gtk_text_set_point( GTK_TEXT(gnewsent3), 0);
gtk_text_insert( GTK_TEXT(gnewsent3), NULL, NULL, NULL, filecontent->good_news[3], -1);
gtk_text_thaw(GTK_TEXT( gnewsent3));
gtk_text_freeze(GTK_TEXT( gnewsent4));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (gnewsent4)), 0, -1);
gtk_text_set_point( GTK_TEXT(gnewsent4), 0);
gtk_text_insert( GTK_TEXT(gnewsent4), NULL, NULL, NULL, filecontent->good_news[4], -1);
gtk_text_thaw(GTK_TEXT( gnewsent4));
gtk_text_freeze(GTK_TEXT( gnewsent5));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (gnewsent5)), 0, -1);
gtk_text_set_point( GTK_TEXT(gnewsent5), 0);
gtk_text_insert( GTK_TEXT(gnewsent5), NULL, NULL, NULL, filecontent->good_news[5], -1);
gtk_text_freeze(GTK_TEXT( gnewsent5));
gtk_text_freeze(GTK_TEXT( vgnewsent1));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vgnewsent1)), 0, -1);
gtk_text_set_point( GTK_TEXT(vgnewsent1), 0);
gtk_text_insert( GTK_TEXT(vgnewsent1), NULL, NULL, NULL, filecontent->very_good_news[1], -1);
gtk_text_thaw(GTK_TEXT( vgnewsent1));
gtk_text_freeze(GTK_TEXT( vgnewsent2));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vgnewsent2)), 0, -1);
gtk_text_set_point( GTK_TEXT(vgnewsent2), 0);
gtk_text_insert( GTK_TEXT(vgnewsent2), NULL, NULL, NULL, filecontent->very_good_news[2], -1);
gtk_text_thaw(GTK_TEXT( vgnewsent2));
gtk_text_freeze(GTK_TEXT( vgnewsent3));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vgnewsent3)), 0, -1);
gtk_text_set_point( GTK_TEXT(vgnewsent3), 0);
gtk_text_insert( GTK_TEXT(vgnewsent3), NULL, NULL, NULL, filecontent->very_good_news[3], -1);
gtk_text_thaw(GTK_TEXT( vgnewsent3));
gtk_text_freeze(GTK_TEXT( vgnewsent4));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vgnewsent4)), 0, -1);
gtk_text_set_point( GTK_TEXT(vgnewsent4), 0);
gtk_text_insert( GTK_TEXT(vgnewsent4), NULL, NULL, NULL, filecontent->very_good_news[4], -1);
gtk_text_thaw(GTK_TEXT( vgnewsent4));
gtk_text_freeze(GTK_TEXT( vgnewsent5));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vgnewsent5)), 0, -1);
gtk_text_set_point( GTK_TEXT(vgnewsent5), 0);
gtk_text_insert( GTK_TEXT(vgnewsent5), NULL, NULL, NULL, filecontent->very_good_news[5], -1);
gtk_text_freeze(GTK_TEXT( vgnewsent5));
gtk_text_freeze(GTK_TEXT( bnewsent1));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (bnewsent1)), 0, -1);
gtk_text_set_point( GTK_TEXT(bnewsent1), 0);
gtk_text_insert( GTK_TEXT(bnewsent1), NULL, NULL, NULL, filecontent->bad_news[1], -1);
gtk_text_thaw(GTK_TEXT( bnewsent1));
gtk_text_freeze(GTK_TEXT( bnewsent2));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (bnewsent2)), 0, -1);
gtk_text_set_point( GTK_TEXT(bnewsent2), 0);
gtk_text_insert( GTK_TEXT(bnewsent2), NULL, NULL, NULL, filecontent->bad_news[2], -1);
gtk_text_thaw(GTK_TEXT( bnewsent2));
gtk_text_freeze(GTK_TEXT( bnewsent3));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (bnewsent3)), 0, -1);
gtk_text_set_point( GTK_TEXT(bnewsent3), 0);
gtk_text_insert( GTK_TEXT(bnewsent3), NULL, NULL, NULL, filecontent->bad_news[3], -1);
gtk_text_thaw(GTK_TEXT( bnewsent3));
gtk_text_freeze(GTK_TEXT( bnewsent4));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (bnewsent4)), 0, -1);
gtk_text_set_point( GTK_TEXT(bnewsent4), 0);
gtk_text_insert( GTK_TEXT(bnewsent4), NULL, NULL, NULL, filecontent->bad_news[4], -1);
gtk_text_thaw(GTK_TEXT( bnewsent4));
gtk_text_freeze(GTK_TEXT( bnewsent5));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (bnewsent5)), 0, -1);
gtk_text_set_point( GTK_TEXT(bnewsent5), 0);
gtk_text_insert( GTK_TEXT(bnewsent5), NULL, NULL, NULL, filecontent->bad_news[5], -1);
gtk_text_freeze(GTK_TEXT( bnewsent5));
gtk_text_freeze(GTK_TEXT( vbnewsent1));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vbnewsent1)), 0, -1);
gtk_text_set_point( GTK_TEXT(vbnewsent1), 0);
gtk_text_insert( GTK_TEXT(vbnewsent1), NULL, NULL, NULL, filecontent->very_bad_news[1], -1);
gtk_text_thaw(GTK_TEXT( vbnewsent1));
gtk_text_freeze(GTK_TEXT( vbnewsent2));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vbnewsent2)), 0, -1);
gtk_text_set_point( GTK_TEXT(vbnewsent2), 0);
gtk_text_insert( GTK_TEXT(vbnewsent2), NULL, NULL, NULL, filecontent->very_bad_news[2], -1);
gtk_text_thaw(GTK_TEXT( vbnewsent2));
gtk_text_freeze(GTK_TEXT( vbnewsent3));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vbnewsent3)), 0, -1);
gtk_text_set_point( GTK_TEXT(vbnewsent3), 0);
gtk_text_insert( GTK_TEXT(vbnewsent3), NULL, NULL, NULL, filecontent->very_bad_news[3], -1);
gtk_text_thaw(GTK_TEXT( vbnewsent3));
gtk_text_freeze(GTK_TEXT( vbnewsent4));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vbnewsent4)), 0, -1);
gtk_text_set_point( GTK_TEXT(vbnewsent4), 0);
gtk_text_insert( GTK_TEXT(vbnewsent4), NULL, NULL, NULL, filecontent->very_bad_news[4], -1);
gtk_text_thaw(GTK_TEXT( vbnewsent4));
gtk_text_freeze(GTK_TEXT( vbnewsent5));
gtk_editable_delete_text(GTK_EDITABLE (GTK_TEXT (vbnewsent5)), 0, -1);
gtk_text_set_point( GTK_TEXT(vbnewsent5), 0);
gtk_text_insert( GTK_TEXT(vbnewsent5), NULL, NULL, NULL, filecontent->very_bad_news[5], -1);
gtk_text_freeze(GTK_TEXT( vbnewsent5));
/* Free the stuff you allocated */
g_free(filename);
g_free(filecontent);
}