GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 30, 2014 5:30 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: 2 questions: gtk entry filter and modal dialog
PostPosted: Tue Dec 04, 2012 2:40 pm 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Hello!
I have 2 questions:
1) I have a dialog with a entry.
In this entry the operator should enter only digits (0-9)
Is it possible to set a filter over the entry? or should I use the "focus-out-event"?
I would rather just activate num keys.

2) I have another dialog, made by the function ts_get_user_entry. It is a modal dialog
When I call it with the commands
Code:
char newFolderName[50];
ts_get_user_entry("Name of the new folder", newFolderName);
if (strlen(newFolderName) > 0) ....

the next command "if (strlen(newFolderName) > 0) " is executed before the operator ckicked on the OK button of the dialog.
I thought that modal dialogs holds the execution until the operator close it.
Can you see my error in the next code? Isn't it a modal dialog?

Thanks a lot in advance for your help
MBoerner



Code:
/**
* instead of the deprecated gtk_input_dialog
* @param message message to show in the dialog
* @param text text that the user will enter
*
*/
void  ts_get_user_entry(const char *message, char *text)
{
   GtkWidget *inputDialog;
   GtkWidget *entry;
   GtkEntryBuffer *entryBuffer;

   GtkWidget *vbox;

   entryBuffer = gtk_entry_buffer_new (NULL, 0);
   entry = gtk_entry_new_with_buffer(GTK_ENTRY_BUFFER(entryBuffer));
   gtk_entry_set_text(GTK_ENTRY(entry),"new folder");

   inputDialog =  gtk_dialog_new_with_buttons(message, NULL, GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT , NULL);
   vbox = gtk_dialog_get_content_area (GTK_DIALOG(inputDialog));
   gtk_dialog_add_button( (GtkDialog*)inputDialog,
                                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL );
   gtk_dialog_add_button( (GtkDialog*)inputDialog,
                                   GTK_STOCK_OK, GTK_RESPONSE_OK );

    gtk_box_pack_end(GTK_BOX(vbox), entry, FALSE, TRUE, 10);

    gtk_dialog_set_default_response(GTK_DIALOG(inputDialog), GTK_RESPONSE_CANCEL);
    gtk_widget_show_all(GTK_WIDGET(inputDialog));
    gint result = gtk_dialog_run (GTK_DIALOG (inputDialog));
    switch (result)
    {
        case GTK_RESPONSE_OK:
          strcpy(text, gtk_entry_get_text(GTK_ENTRY(entry)));
          break;
        default:
           text = NULL;
           break;
    }
    gtk_widget_destroy (GTK_WIDGET(inputDialog));
}


Top
 Profile  
 
 Post subject: Re: 2 questions: gtk entry filter and modal dialog
PostPosted: Tue Dec 04, 2012 10:25 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
1. If you are after numerical input then don't use an entry, use a gtk_spin_button. It is much better geared towards numerical data.
2. I'm not sure exactly where the problem is. I would have though it much better (and more efficient) to check on whether the string was NULL then to make a check based on length. The way you handle strings can also be greatly improved by using glib string utility functions. I would prefer to declare as gchar* rather than an array of length 50. You can than use the g_str... functions which are more portable than stdio/strings, etc. (and also won't need to include them) and often handle potential buffer overflow issues better.
You are right about it being strange being a modal dialog; gtk_dialog_main holds up the queue in gtk_main. Maybe the compiler has rearranged things based on determining the result to be invariant of the dialog?


Top
 Profile  
 
 Post subject: Re: 2 questions: gtk entry filter and modal dialog
PostPosted: Wed Dec 05, 2012 6:36 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
ok, thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group