There would be a few ways of doing this. The first would be to use 4 spin buttons, but this would be a copout way and wouldn't look nice.
The second would be to just use one GtkEntry that restricts the input by using the "changed" signal of the GtkEditable implementation. You could even derive a new widget to do just this.
The last way, which I personally would do would be to create 4 entries that don't have borders. Place 3 GtkLabels between them. It would be done as such:
Code:
GtkWidget *entry1, *entry2, *entry3, *entry4, *label1, *label2, *label3, *hbox;
entry1 = gtk_entry_new_with_max_length (3);
entry2 = gtk_entry_new_with_max_length (3);
entry3 = gtk_entry_new_with_max_length (3);
entry4 = gtk_entry_new_with_max_length (3);
label1 = gtk_label_new (".");
label2 = gtk_label_new (".");
label3 = gtk_label_new (".");
gtk_entry_set_has_frame (GTK_ENTRY (entry1), FALSE);
gtk_entry_set_has_frame (GTK_ENTRY (entry2), FALSE);
gtk_entry_set_has_frame (GTK_ENTRY (entry3), FALSE);
gtk_entry_set_has_frame (GTK_ENTRY (entry4), FALSE);
hbox = gtk_hbox_new (FALSE, 1);
gtk_box_pack_start_defaults (GTK_BOX (hbox), entry1);
gtk_box_pack_start_defaults (GTK_BOX (hbox), label1);
gtk_box_pack_start_defaults (GTK_BOX (hbox), entry2);
gtk_box_pack_start_defaults (GTK_BOX (hbox), label2);
gtk_box_pack_start_defaults (GTK_BOX (hbox), entry3);
gtk_box_pack_start_defaults (GTK_BOX (hbox), label3);
gtk_box_pack_start_defaults (GTK_BOX (hbox), entry4);
Then use the
insert-at-cursor signal of the GtkEntry to restrict it to only digits. Of course, like I said before, making a custom widget would probably be the best thing to do, but that is your choice.
You could integrate it even better by setting the background color of every widget as the same color & then placing a black one pixel border around the hbox in a custom widget.
This is actually a really good idea for an example. I am currently working on a book on GTK+ programming that will be coming out in a few months. Would you give me permission to use this idea for an example in the book in the custom widgets chapter?