[gtkmm] Gtk::entry set_position() problem and workaround



I'm working on a date-validation routine for an entry field and am having trouble using the set_position() method.

I have read all the posts I could find regarding 'set_position' and many of them deal with this same problem, but I have not found any posts that provide an explaination, answer, or even a workaround.

Design Summary:

The date validation routine is called every time a key is pressed and the entry text is updated accordingly. The entry field displays the 'mask' of the date field to guide the user in typing the date. For example, the mask will look something like this before the user starts typing:

##-##-####
^
|__ Insertion cursor is positioned before the first character of the month.


If the user types a '9' for the month (American date format of mm-dd-yyyy), then then entry will be updated to look like this:

09-##-####
  ^
  |__ Insertion cursor is positioned before the first character of the day.


The problem:

Our first approach was to call 'widget->set_position(3);' inside the signal_changed callback routine, but the only time the set_position method worked was when you pressed the DELETE key. We determined that either the set_position method was broken, or maybe something else was changing the cursor position after we set it. Since it clearly worked when you pressed certain keys (like the delete key) we assumed that something else must be changing the position.


A similar problem that was solved:

We experienced a similar type of behavior when trying to use the grab_focus method and found a solution that connected the entry's grab_focus method to Glib::signal_idle. For example:

void winPatient::grab_focus (Gtk::Entry * w)
{
   Glib::signal_idle ().
connect (SigC::bind_return (SigC::slot (*w, &Gtk::Entry::grab_focus), false));
}


Our workaround:

So, we hacked together a test and now we are able to set the position from inside the signal_changed callback. I believe that this essentially causes OUR set_position to be called AFTER the mystery set_position is occurring:

void Cinque::Validate::set_position (Gtk::Entry * w, int n)
{
   g_w = w;
   g_n = n;
   Glib::signal_idle().connect (SigC::slot (&Cinque::Validate::sp));
}

bool Cinque::Validate::sp ()
{
   g_w->set_position(g_n);
   return false;
}


The problem:

Is it possible to connect the entry widget's set_position method directly to Glib::signal_idle().connect?

We cannot figure out how to fassion a 'Glib::signal_idle().connect' statement where we can pass the entry widget, the set_position method and the position parameter so we don't have to use global variables and our helper 'sp' function. I would love to improve our workaround.


Summary:

Thanks for any help that you can provide! I know that 'entry validation' is very subjective, but my customer insists that fixed format fields like dates, times and social security numbers provide 'real-time' feedback to the user while they type it in. Our beta-testing with actual users also showed that some users (i.e. they never used a computer before) were confused about what to type in when they first came to the date field. If any one is interested in our solution, I would be happy to post an example, or provide one for the gtkmm documentation.

Regards,

Jeff Gavin






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