Kludge repair of expose after startup resize
[xboard.git] / dialogs.c
index df53d8a..0c430dd 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1034,7 +1034,7 @@ SendString (char *p)
 }
 
 void
-IcsTextProc ()
+IcsTextPopUp ()
 {
    int i=0, j;
    char *p, *q, *r;
@@ -1066,6 +1066,13 @@ IcsTextProc ()
    GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL, appData.topLevel);
 }
 
+void
+IcsTextProc ()
+{
+    if(shellUp[TextMenuDlg]) PopDown(TextMenuDlg);
+    else IcsTextPopUp();
+}
+
 //---------------------------------------------------- Edit Comment -----------------------------------
 
 static char *commentText;
@@ -1164,6 +1171,8 @@ EditCommentProc ()
 static void changeTags P((int n));
 static char *tagsText, **resPtr;
 
+static int TagsClick P((Option *opt, int n, int x, int y, char *val, int index));
+
 static int
 NewTagsCallback (int n)
 {
@@ -1173,13 +1182,27 @@ NewTagsCallback (int n)
     return 1;
 }
 
+static void
+NewMove ()
+{
+    addToBookFlag = !addToBookFlag;
+}
+
 static Option tagsOptions[] = {
 {   0,   0,   0, NULL, NULL, NULL, NULL, Label,  NULL },
-{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" },
-{   0,   0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") },
+{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", (char **) &TagsClick, TextBox, "" },
+{   0,   0, 100, NULL, (void*) &NewMove,    NULL, NULL, Button, N_("add next move") },
+{ 0,SAME_ROW,100,NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") },
 { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" }
 };
 
+static int TagsClick (Option *opt, int n, int x, int y, char *val, int index)
+{
+    if(!bookUp || n != 3) return FALSE; // only button-3 press in Edit Book is of interest
+    PlayBookMove(val, index);
+    return TRUE;
+}
+
 static void
 changeTags (int n)
 {
@@ -1194,6 +1217,7 @@ NewTagsPopup (char *text, char *msg)
 {
     char *title = bookUp ? _("Edit book") : _("Tags");
 
+    tagsOptions[2].type = bookUp ? Button : Skip;
     if(DialogExists(TagsDlg)) { // if already exists, alter title and content
        SetWidgetText(&tagsOptions[1], text, TagsDlg);
        SetDialogTitle(TagsDlg, title);
@@ -1230,6 +1254,12 @@ EditTagsProc ()
   if (bookUp || !PopDown(TagsDlg)) EditTagsEvent();
 }
 
+void
+AddBookMove (char *text)
+{
+    AppendText(&tagsOptions[1], text);
+}
+
 //---------------------------------------------- ICS Input Box ----------------------------------
 
 char *icsText;
@@ -1786,7 +1816,7 @@ ContextMenu (Option *opt, int button, int x, int y, char *text, int index)
   if(wpTextMenu.x < 0) wpTextMenu.x = 0;
   if(wpTextMenu.y < 0) wpTextMenu.y = 0;
   wpTextMenu.width = wpTextMenu.height = -1;
-  IcsTextProc();
+  IcsTextPopUp();
   return TRUE;
 }
 
@@ -2008,7 +2038,7 @@ ConsoleWrite(char *message, int count)
 }
 
 void
-ChatProc ()
+ChatPopUp ()
 {
     if(GenericPopUp(chatOptions, _("ICS Interaction"), ChatDlg, BoardWindow, NONMODAL, appData.topLevel))
        AddHandler(&chatOptions[CHAT_PARTNER], ChatDlg, 2), AddHandler(&chatOptions[CHAT_IN], ChatDlg, 2); // treats return as OK
@@ -2019,6 +2049,13 @@ ChatProc ()
 }
 
 void
+ChatProc ()
+{
+    if(shellUp[ChatDlg]) PopDown(ChatDlg);
+    else ChatPopUp();
+}
+
+void
 ConsoleAutoPopUp (char *buf)
 {
        if(!appData.autoBox) return;
@@ -2030,7 +2067,7 @@ ConsoleAutoPopUp (char *buf)
                SetWidgetText(&chatOptions[CHAT_IN], newText, ChatDlg);
                if(shellUp[ChatDlg]) HardSetFocus (&chatOptions[CHAT_IN], ChatDlg); //why???
            } else { ASSIGN(line, buf); } // box did not exist: make sure it pops up with char in it
-           ChatProc();
+           ChatPopUp();
        } else PopUpMoveDialog(*buf);
 }
 
@@ -2468,6 +2505,7 @@ Exp (int n, int x, int y)
 {
     static int but1, but3, oldW, oldH;
     int menuNr = -3, sizing, f, r;
+    TimeMark now;
 
     if(n == 0) { // motion
        if(SeekGraphClick(Press, x, y, 1)) return NULL;
@@ -2481,6 +2519,7 @@ Exp (int n, int x, int y)
        return NULL;
     }
     if(n != 10 && PopDown(PromoDlg)) fromX = fromY = -1; // user starts fiddling with board when promotion dialog is up
+    else GetTimeMark(&now);
     shiftKey = ShiftKeys();
     controlKey = (shiftKey & 0xC) != 0;
     shiftKey = (shiftKey & 3) != 0;
@@ -2495,7 +2534,7 @@ Exp (int n, int x, int y)
            sizing = (oldW != x || oldH != y);
            oldW = x; oldH = y;
            InitDrawingHandle(mainOptions + W_BOARD);
-           if(sizing) return NULL; // don't redraw while sizing
+           if(sizing && SubtractTimeMarks(&now, &programStartTime) > 10000) return NULL; // don't redraw while sizing (except at startup)
            DrawPosition(True, NULL);
        default:
            return NULL;