X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xoptions.c;h=583ab9dcdd5e9c523813f48eede4319638251594;hb=6004960398b36a83d05c068ee633591b855b2c0b;hp=ae20ee165bf18b02278050de8cdcfc9b005640db;hpb=39e397e27badd8e302e664d65ae74f09f5dda895;p=xboard.git diff --git a/xoptions.c b/xoptions.c index ae20ee1..583ab9d 100644 --- a/xoptions.c +++ b/xoptions.c @@ -232,21 +232,13 @@ SetWidgetText (Option *opt, char *buf, int n) void GetWidgetState (Option *opt, int *state) { -#ifdef TODO_GTK - Arg arg; - XtSetArg(arg, XtNstate, state); - XtGetValues(opt->handle, &arg, 1); -#endif + *state = gtk_toggle_button_get_active(opt->handle); } void SetWidgetState (Option *opt, int state) { -#ifdef TODO_GTK - Arg arg; - XtSetArg(arg, XtNstate, state); - XtSetValues(opt->handle, &arg, 1); -#endif + gtk_toggle_button_set_active(opt->handle, state); } void @@ -296,7 +288,7 @@ LoadListBox (Option *opt, char *emptyText, int n1, int n2) } void -HighlightListBoxItem (Option *opt, int index) +HighlightItem (Option *opt, int index, int scroll) { char *value, **data = (char **) (opt->target); GtkWidget *list = (GtkWidget *) (opt->handle); @@ -305,15 +297,21 @@ HighlightListBoxItem (Option *opt, int index) GtkListStore *store = GTK_LIST_STORE(model); GtkTreePath *path = gtk_tree_path_new_from_indices(index, -1); GtkTreeIter iter; - gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &iter, path); + gtk_tree_selection_select_path(selection, path); + if(scroll) gtk_tree_view_scroll_to_cell(list, path, NULL, 0, 0, 0); gtk_tree_path_free(path); - gtk_tree_selection_select_iter(selection, &iter); } void -HighlightWithScroll (Option *opt, int sel, int max) +HighlightListBoxItem (Option *opt, int index) +{ + HighlightItem (opt, index, FALSE); +} + +void +HighlightWithScroll (Option *opt, int index, int max) { - HighlightListBoxItem (opt, index); // just highlight, as GTK scrolls by itself + HighlightItem (opt, index, TRUE); // ignore max } int @@ -340,6 +338,7 @@ FocusOnWidget (Option *opt, DialogClass dlg) #ifdef TODO_GTK XtSetKeyboardFocus(shells[dlg], opt->handle); #endif + gtk_widget_grab_focus(opt->handle); } void @@ -448,9 +447,29 @@ char *translationTable[] = { // beware: order is essential! filterTranslations, gameListTranslations, memoTranslations }; +Option *typeIn; // kludge to distinguish type-in callback from input-box callback + +void +CursorAtEnd (Option *opt) +{ + gtk_editable_set_position(opt->handle, -1); +} + static gboolean -ICSKeyEvent(GtkWidget *widget, GdkEventKey *event) +ICSKeyEvent(GtkWidget *widget, GdkEventKey *event, gpointer g) { + Option *opt = (Option *) g; + if(opt == typeIn) { + if(event->keyval == GDK_Return) { + char *val; + GetWidgetText(opt, &val); + TypeInDoneEvent(val); + PopDown(TransientDlg); + return TRUE; + } + return FALSE; + } + switch(event->keyval) { case GDK_Return: IcsKey(0); return TRUE; case GDK_Up: IcsKey(1); return TRUE; @@ -512,6 +531,37 @@ ShiftKeys () } static gboolean +GameListEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata) +{ + int n = (int) gdata; + + if(n == 4) { + if(((GdkEventKey *) event)->keyval != GDK_Return) return FALSE; + SetFilter(); + return TRUE; + } + + if(event->type == GDK_KEY_PRESS) { + int ctrl = (((GdkEventKey *) event)->state & GDK_CONTROL_MASK) != 0; + switch(((GdkEventKey *) event)->keyval) { + case GDK_Up: GameListClicks(-1 - 2*ctrl); return TRUE; + case GDK_Left: GameListClicks(-1); return TRUE; + case GDK_Down: GameListClicks(1 + 2*ctrl); return TRUE; + case GDK_Right: GameListClicks(1); return TRUE; + case GDK_Prior: GameListClicks(-4); return TRUE; + case GDK_Next: GameListClicks(4); return TRUE; + case GDK_Home: GameListClicks(-2); return TRUE; + case GDK_End: GameListClicks(2); return TRUE; + case GDK_Return: GameListClicks(0); return TRUE; + default: return FALSE; + } + } + if(event->type != GDK_2BUTTON_PRESS || ((GdkEventButton *) event)->button != 1) return FALSE; + GameListClicks(0); + return TRUE; +} + +static gboolean MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata) { // handle mouse clicks on text widgets that need it int w, h; @@ -564,20 +614,25 @@ MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata) } void -AddHandler (Option *opt, int nr) +AddHandler (Option *opt, DialogClass dlg, int nr) { switch(nr) { - case 0: - case 1: - case 2: break; - case 3: g_signal_connect(opt->handle, "key-press-event", G_CALLBACK (ICSKeyEvent), NULL); break; // Input Box - case 4: - case 5: - case 6: break; + case 0: // history (now uses generic textview callback) + case 1: // comment (likewise) + break; + case 2: // move type-in + typeIn = opt; + case 3: // input box + g_signal_connect(opt->handle, "key-press-event", G_CALLBACK (ICSKeyEvent), (gpointer) opt); + break; + case 5: // game list + g_signal_connect(opt->handle, "button-press-event", G_CALLBACK (GameListEvent), (gpointer) 0 ); + case 4: // game-list filter + g_signal_connect(opt->handle, "key-press-event", G_CALLBACK (GameListEvent), (gpointer) nr ); + break; + case 6: // engine output (uses generic textview callback) + break; } -#ifdef TODO_GTK - XtOverrideTranslations(opt->handle, XtParseTranslationTable(translationTable[nr])); -#endif } //----------------------------Generic dialog -------------------------------------------- @@ -616,7 +671,9 @@ RaiseWindow (DialogClass dlg) xev.xclient.data.l[1] = CurrentTime; XSendEvent (xDisplay, - root, False, + root, False,static gboolean +MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata) + SubstructureRedirectMask | SubstructureNotifyMask, &xev);