From: H.G. Muller Date: Thu, 18 Oct 2012 19:42:49 +0000 (+0200) Subject: Add game-list callbacks X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=55fdfba16e54a8c9e770124f4a468956b478e90c;p=xboard.git Add game-list callbacks The callbacks for listbox and filter text are treated by the same callback, which does both key presses and button double-clicks. Giving focus back to the listbox after filtering does not yet work! --- diff --git a/dialogs.c b/dialogs.c index 2312c06..6455f74 100644 --- a/dialogs.c +++ b/dialogs.c @@ -973,7 +973,7 @@ NewCommentPopup (char *title, char *text, int index) commentIndex = index; MarkMenu("View.Comments", CommentDlg); if(GenericPopUp(commentOptions, title, CommentDlg, BoardWindow, NONMODAL, 1)) - AddHandler(&commentOptions[0], 1); + AddHandler(&commentOptions[0], CommentDlg, 1); } void @@ -1180,7 +1180,7 @@ ICSInputBoxPopUp () { MarkMenu("View.ICSInputBox", InputBoxDlg); if(GenericPopUp(boxOptions, _("ICS input box"), InputBoxDlg, BoardWindow, NONMODAL, 0)) - AddHandler(&boxOptions[0], 3); + AddHandler(&boxOptions[0], InputBoxDlg, 3); } void @@ -1211,7 +1211,7 @@ PopUpMoveDialog (char firstchar) static char buf[2]; buf[0] = firstchar; ASSIGN(icsText, buf); if(GenericPopUp(typeOptions, _("Type a move"), TransientDlg, BoardWindow, MODAL, 0)) - AddHandler(&typeOptions[0], 2); + AddHandler(&typeOptions[0], TransientDlg, 2); } void @@ -1502,7 +1502,7 @@ AskQuestion (char *title, char *question, char *replyPrefix, ProcRef pr) ASSIGN(answer, ""); askOptions[0].name = question; if(GenericPopUp(askOptions, title, AskDlg, BoardWindow, MODAL, 0)) - AddHandler(&askOptions[1], 2); + AddHandler(&askOptions[1], AskDlg, 2); } //---------------------------- Promotion Popup -------------------------------------- @@ -1684,7 +1684,7 @@ void ChatProc () { if(GenericPopUp(chatOptions, _("Chat box"), ChatDlg, BoardWindow, NONMODAL, 0)) - AddHandler(&chatOptions[0], 2), AddHandler(&chatOptions[6], 2); // treats return as OK + AddHandler(&chatOptions[0], ChatDlg, 2), AddHandler(&chatOptions[6], ChatDlg, 2); // treats return as OK MarkMenu("View.OpenChatWindow", ChatDlg); } diff --git a/dialogs.h b/dialogs.h index 49df73d..d77708b 100644 --- a/dialogs.h +++ b/dialogs.h @@ -158,7 +158,7 @@ void UnCaret P((void)); void SetIconName P((DialogClass dlg, char *name)); int ReadScroll P((Option *opt, float *top, float *bottom)); void SetScroll P((Option *opt, float f)); -void AddHandler P((Option *opt, int nr)); +void AddHandler P((Option *opt, DialogClass dlg, int nr)); void SendText P((int n)); void DisplayLogos P((Option *left, Option *right)); void Browse P((DialogClass dlg, char *label, char *proposed, char *ext, diff --git a/nengineoutput.c b/nengineoutput.c index 7b013c0..774d63a 100644 --- a/nengineoutput.c +++ b/nengineoutput.c @@ -155,8 +155,8 @@ EngineOutputPopUp () if (GenericPopUp(engoutOptions, _(title), EngOutDlg, BoardWindow, NONMODAL, 1)) { if(engoutOptions[STRIDE-1].type != Break) DisplayFatalError(_("Mismatch of STRIDE in nengineoutput.c\nChange and recompile!"), 0, 2); - AddHandler(&engoutOptions[MEMO], 6); - AddHandler(&engoutOptions[MEMO+STRIDE], 6); + AddHandler(&engoutOptions[MEMO], EngOutDlg, 6); + AddHandler(&engoutOptions[MEMO+STRIDE], EngOutDlg, 6); if( needInit ) { InitEngineOutput(&engoutOptions[0], &engoutOptions[MEMO]); // make icon bitmaps needInit = FALSE; diff --git a/ngamelist.c b/ngamelist.c index 32fdf33..72529a4 100644 --- a/ngamelist.c +++ b/ngamelist.c @@ -82,7 +82,7 @@ static void GameListReplace P((int page)); static void GL_Button P((int n)); static Option gamesOptions[] = { -{ 200, LR|TB, 400, NULL, (void*) list, "", NULL, ListBox, "" }, +{ 200, LR|TB, 400, NULL, (void*) list, NULL, NULL, ListBox, "" }, { 0, 0, 100, NULL, (void*) &filterPtr, "", NULL, TextBox, "" }, { 4, SAME_ROW, 0, NULL, (void*) &GL_Button, NULL, NULL, Button, N_("find position") }, { 2, SAME_ROW, 0, NULL, (void*) &GL_Button, NULL, NULL, Button, N_("narrow") }, // buttons referred to by ID in value (=first) field! @@ -152,8 +152,8 @@ GameListCreate (char *name) { int new; if(new = GenericPopUp(gamesOptions, name, GameListDlg, BoardWindow, NONMODAL, 1)) - AddHandler(&gamesOptions[1], 4), - AddHandler(&gamesOptions[0], 5); + AddHandler(&gamesOptions[1], GameListDlg, 4), + AddHandler(&gamesOptions[0], GameListDlg, 5); FocusOnWidget(&gamesOptions[0], GameListDlg); return new; } diff --git a/nhistory.c b/nhistory.c index 9d6a073..59b4226 100644 --- a/nhistory.c +++ b/nhistory.c @@ -101,7 +101,7 @@ void HistoryPopUp () { if(GenericPopUp(historyOptions, _("Move list"), HistoryDlg, BoardWindow, NONMODAL, 1)) - AddHandler(&historyOptions[0], 0); + AddHandler(&historyOptions[0], HistoryDlg, 0); MarkMenu("View.MoveHistory", HistoryDlg); } diff --git a/xaw/xoptions.c b/xaw/xoptions.c index 77d7358..4770f53 100644 --- a/xaw/xoptions.c +++ b/xaw/xoptions.c @@ -413,7 +413,7 @@ char *translationTable[] = { // beware: order is essential! }; void -AddHandler (Option *opt, int nr) +AddHandler (Option *opt, DialogClass dlg, int nr) { XtOverrideTranslations(opt->handle, XtParseTranslationTable(translationTable[nr])); } diff --git a/xoptions.c b/xoptions.c index ae20ee1..928d28d 100644 --- a/xoptions.c +++ b/xoptions.c @@ -296,7 +296,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 +305,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 @@ -512,6 +518,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 +601,22 @@ 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 3: // input box + g_signal_connect(opt->handle, "key-press-event", G_CALLBACK (ICSKeyEvent), NULL); break; // Input Box + 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: + break; } -#ifdef TODO_GTK - XtOverrideTranslations(opt->handle, XtParseTranslationTable(translationTable[nr])); -#endif } //----------------------------Generic dialog -------------------------------------------- @@ -616,7 +655,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);