(no subject)



Assignment operator for GtkWidgets?

Is there such a thing, can we do things like MyGtkWidget = SomeGtkWidget?

I get a segmentation fault when I try todo that!


What am I doing wrong?

class Data{
   public:
      std::string str;
      GtkWidget* obj;
   public:
      Data(){str = "";}
      void setStr(std::string ps){ str = ps;}
      void setObj(GtkWidget* o){obj = o;}
};

//Declare the objects
GtkWidget* MainMenueWin;
GtkWidget* VBx;
GtkWidget* Label;
GtkWidget* Separator;
GtkWidget* btnExit;
GtkWidget* btnCreateAccount;
GtkWidget* btn2;
GtkWidget* btn3;
GtkWidget* btn4;
GtkWidget* btn5;
Data* data;
std::string msg("Under Comstruction ... I am very sorry, but this \
                    feature has not been implemented yet. Please \
                    email me for any new updates on this program \
                    puchica hotmail com");

//Callbacks

void Quit(GtkButton* , gpointer);
   gboolean SystemQuit(GtkWidget*, GdkEvent*, gpointer);


void Quit(GtkButton* was_clicked, gpointer user_data){
   gtk_main_quit();
}
gboolean SystemQuit(GtkWidget* widget, GdkEvent* event, gpointer user_data){
     gtk_widget_destroy(widget);
     gtk_main_quit();
     return(TRUE);
     //return(FALSE);
}

int main(int argc, char *argv[]){
   // 1. Initialize the environment
   gtk_set_locale ();
   gtk_init(&argc, &argv);
   //-liconv -liconv
   // 2. Create Widgets
   MainMenueWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   //gtk_window_new(GTK_WINDOW_TOPLEVEL);
   VBx = gtk_vbox_new(FALSE,10);
   Label = gtk_label_new("Jaime");
   Separator = gtk_hseparator_new();
   btnCreateAccount = gtk_button_new_with_label("Create");
   btn2 = gtk_button_new_with_label("Unknown");
   btn3 = gtk_button_new_with_label("Unknown");
   btn4 = gtk_button_new_with_label("Unknown");
   btn5 = gtk_button_new_with_label("Unknown");
   btnExit = gtk_button_new_with_label("Exit");
   // Information for GeneralMessage


   data->setObj(MainMenueWin);
   data->setStr(msg);

   // 3. Set attributs
   gtk_window_set_title(GTK_WINDOW(MainMenueWin), "Jaime");
   gtk_window_set_policy(GTK_WINDOW(MainMenueWin), //which_window
                         FALSE,                    // allow_shrink
                         FALSE,                    // allow_grow
                         FALSE);                   // auto_shrink

   gtk_container_set_border_width(GTK_CONTAINER(MainMenueWin),15);
   gtk_widget_set_name(MainMenueWin,"Gtk++ One, dos");
   gtk_widget_set_name(VBx,"vertical box");
   gtk_widget_set_name(Label,"Label");
   gtk_widget_set_name(Separator, "Separator");

   // 4. Register CallBacks
   // These three callback fun' are only to exit the application
   g_signal_connect( GTK_OBJECT(btnExit), "clicked",
                     G_CALLBACK(Quit),    NULL);
   g_signal_connect( GTK_OBJECT(MainMenueWin), "delete-event",
                     GTK_SIGNAL_FUNC(SystemQuit), NULL);
   g_signal_connect(GTK_OBJECT(MainMenueWin), "destroy",
                    G_CALLBACK(SystemQuit), NULL);

   g_signal_connect(GTK_OBJECT(btnCreateAccount), "clicked",
                    G_CALLBACK(GeneralMsg),
reinterpret_cast<gpointer>(&data));

   g_signal_connect(GTK_OBJECT(btn2), "clicked",
                    G_CALLBACK(GeneralMsg),
reinterpret_cast<gpointer>(&data));
   g_signal_connect(GTK_OBJECT(btn3), "clicked",
                    G_CALLBACK(GeneralMsg),
reinterpret_cast<gpointer>(&data));
   g_signal_connect(GTK_OBJECT(btn4), "clicked",
                    G_CALLBACK(GeneralMsg),
reinterpret_cast<gpointer>(&data));
   g_signal_connect(GTK_OBJECT(btn5), "clicked",
                    G_CALLBACK(GeneralMsg),
reinterpret_cast<gpointer>(&data));

   // 5. Define instance hirarchy (pack the widgets)
   gtk_container_add(GTK_CONTAINER(MainMenueWin), VBx);
   gtk_box_pack_start_defaults(GTK_BOX(VBx), Label);
   gtk_box_pack_start(GTK_BOX(VBx), btnCreateAccount, FALSE, FALSE,1);
   gtk_box_pack_start(GTK_BOX(VBx), btn2, FALSE, FALSE,1);
   gtk_box_pack_start(GTK_BOX(VBx), btn3, FALSE, FALSE,1);
   gtk_box_pack_start(GTK_BOX(VBx), btn4, FALSE, FALSE,1);
   gtk_box_pack_start(GTK_BOX(VBx), btn5, FALSE, FALSE,1);

   gtk_box_pack_start(GTK_BOX(VBx), Separator, FALSE,FALSE, 1);
   gtk_box_pack_start_defaults(GTK_BOX(VBx), btnExit);


   // 6. Show the Widgets
   gtk_widget_show_all(MainMenueWin);

   // 7. Processing loop
   gtk_main();
   //if (data) { delete data; }
   std::cerr << "Assalam Alaykum" << std::endl;
   return 0;
}

void GeneralMsg(GtkButton* button, gpointer p) {
    Data* d;
	GtkWidget* label;
	GtkWidget* dialog;

	try {
		dialog = new GtkWidget;
		label = new GtkWidget;
		d = new Data();
	} catch(std::exception& e) { std::cout << e.what() << std::endl;}
    try{d = reinterpret_cast<Data*>(p);}
    catch(std::exception& e){std::cerr << e.what() << std::endl;}
	dialog = gtk_message_dialog_new(
               einterpret_cast<GtkWindow*>(d->obj),                  //Parent
	       static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL |
	                                 GTK_DIALOG_DESTROY_WITH_PARENT),        
 //Flags
	       reinterpret_cast<GtkMessageType>(GTK_MESSAGE_WARNING), // Message
type
	       reinterpret_cast<GtkButtonsType>(GTK_BUTTONS_OK),      //Button type
	       d->str.c_str());                              //Message format

	// Destroy the dialog when the user responds to it (e.g. clicks a button)


	gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (dialog);

        delete d;
	delete dialog;
	delete label;
}

-- 
* You cannot exercise your power to a point of humiliation.
                               - Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding  can
yield a crop of hate and death...

* If that document has fine printing anywhere, just chuck it in the garbage
                              - Jorge Escalante

Ma'assalama! Adiós!  bye!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]