From: H.G. Muller Date: Wed, 17 Oct 2012 18:01:37 +0000 (+0200) Subject: Connect CommentClick handler X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b766f10fe10fc786b5793a010d777bacc4349820;p=xboard.git Connect CommentClick handler This can make use of generic memo callback, so it could be entirely backend. Therefore it was moved to dialogs.h. As it shared a global with some other back-end popup routines to remember the current move, these could now be moved out of xboard.c too. (Well, not so for the X11 front-end, so it has now been put in a header. :-( ) --- diff --git a/dialogs.c b/dialogs.c index 42d3f98..18310cb 100644 --- a/dialogs.c +++ b/dialogs.c @@ -921,6 +921,9 @@ static char *commentText; static int commentIndex; static void ClearComment P((int n)); static void SaveChanges P((int n)); +int savedIndex; /* gross that this is global (and even across files...) */ + +static int CommentClick P((Option *opt, int n, int x, int y, char *val, int index)); static int NewComCallback (int n) @@ -930,12 +933,22 @@ NewComCallback (int n) } Option commentOptions[] = { -{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, "", NULL, TextBox, "" }, +{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, "", (MemoCallback *) &CommentClick, TextBox, "" }, { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, N_("clear") }, { 0, SAME_ROW, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, N_("save changes") }, { 0, SAME_ROW, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" } }; +static int +CommentClick (Option *opt, int n, int x, int y, char *val, int index) +{ + if(n != 3) return FALSE; // only button-3 press is of interest + ReplaceComment(savedIndex, val); + if(savedIndex != currentMove) ToNrEvent(savedIndex); + LoadVariation( index, val ); // [HGM] also does the actual moving to it, now + return TRUE; +} + static void SaveChanges (int n) { @@ -964,6 +977,28 @@ NewCommentPopup (char *title, char *text, int index) } void +EditCommentPopUp (int index, char *title, char *text) +{ + savedIndex = index; + if (text == NULL) text = ""; + NewCommentPopup(title, text, index); +} + +void +CommentPopUp (char *title, char *text) +{ + savedIndex = currentMove; // [HGM] vari + NewCommentPopup(title, text, currentMove); +} + +void +CommentPopDown () +{ + PopDown(CommentDlg); +} + + +void EditCommentProc () { if (PopDown(CommentDlg)) { // popdown succesful diff --git a/xaw/xboard.c b/xaw/xboard.c index 71416d4..5bf3b0c 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -1781,7 +1781,7 @@ HandlePV (Widget w, XEvent * event, String * params, Cardinal * nParams) MovePV(event->xmotion.x, event->xmotion.y, lineGap + BOARD_HEIGHT * (squareSize + lineGap)); } -static int savedIndex; /* gross that this is global */ +extern int savedIndex; /* gross that this is global */ void CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) @@ -1798,27 +1798,6 @@ CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) LoadVariation( index, val ); // [HGM] also does the actual moving to it, now } -void -EditCommentPopUp (int index, char *title, char *text) -{ - savedIndex = index; - if (text == NULL) text = ""; - NewCommentPopup(title, text, index); -} - -void -CommentPopUp (char *title, char *text) -{ - savedIndex = currentMove; // [HGM] vari - NewCommentPopup(title, text, currentMove); -} - -void -CommentPopDown () -{ - PopDown(CommentDlg); -} - /* Disable all user input other than deleting the window */ static int frozen = 0; diff --git a/xaw/xboard.h b/xaw/xboard.h index 5a6587e..3345c33 100644 --- a/xaw/xboard.h +++ b/xaw/xboard.h @@ -170,6 +170,7 @@ extern char ICSInputTranslations[]; extern char *selected_fen_position; extern GC coordGC; extern Dimension textHeight; // of message widget in board window +extern int savedIndex; #define TOPLEVEL 1 /* preference item; 1 = make popup windows toplevel */ diff --git a/xboard.c b/xboard.c index a86877f..4a4cdad 100644 --- a/xboard.c +++ b/xboard.c @@ -1848,46 +1848,6 @@ DrawPositionProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) #endif -static int savedIndex; /* gross that this is global */ - -#ifdef TODO_GTK -void -CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) -{ - String val; - XawTextPosition index, dummy; - Arg arg; - - XawTextGetSelectionPos(w, &index, &dummy); - XtSetArg(arg, XtNstring, &val); - XtGetValues(w, &arg, 1); - ReplaceComment(savedIndex, val); - if(savedIndex != currentMove) ToNrEvent(savedIndex); - LoadVariation( index, val ); // [HGM] also does the actual moving to it, now -} -#endif - -void -EditCommentPopUp (int index, char *title, char *text) -{ - savedIndex = index; - if (text == NULL) text = ""; - NewCommentPopup(title, text, index); -} - -void -CommentPopUp (char *title, char *text) -{ - savedIndex = currentMove; // [HGM] vari - NewCommentPopup(title, text, currentMove); -} - -void -CommentPopDown () -{ - PopDown(CommentDlg); -} - /* Disable all user input other than deleting the window */ static int frozen = 0;