Make reference to board widgets symbolic
[xboard.git] / dialogs.c
index 5272657..df8750a 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1792,22 +1792,6 @@ DisplayTitle (char *text)
     SetWindowTitle(text, title, icon);
 }
 
-void
-DisplayWhiteClock (long timeRemaining, int highlight)
-{
-    if(appData.noGUI) return;
-    DisplayTimerLabel(11, _("White"), timeRemaining, highlight);
-    if(highlight) SetClockIcon(0);
-}
-
-void
-DisplayBlackClock (long timeRemaining, int highlight)
-{
-    if(appData.noGUI) return;
-    DisplayTimerLabel(12, _("Black"), timeRemaining, highlight);
-    if(highlight) SetClockIcon(1);
-}
-
 #define PAUSE_BUTTON "P"
 #define PIECE_MENU_SIZE 18
 static String pieceMenuStrings[2][PIECE_MENU_SIZE+1] = {
@@ -1900,9 +1884,9 @@ SizeKludge (int n)
 {   // callback called by GenericPopUp immediately after sizing the menu bar
     int width = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
     int w = width - 44 - mainOptions[n].min;
-    mainOptions[10].max = w; // width left behind menu bar
+    mainOptions[W_TITLE].max = w; // width left behind menu bar
     if(w < 0.4*width) // if no reasonable amount of space for title, force small layout
-       mainOptions[13].type = mainOptions[10].type, mainOptions[10].type = -1; 
+       mainOptions[W_SMALL].type = mainOptions[W_TITLE].type, mainOptions[W_TITLE].type = -1; 
 }
 
 void
@@ -1925,7 +1909,9 @@ Exp (int n, int x, int y)
        if(but3) MovePV(x, y, lineGap + BOARD_HEIGHT * (squareSize + lineGap));
        return NULL;
     }
-    shiftKey = (ShiftKeys() & 3) != 0;
+    shiftKey = ShiftKeys();
+    controlKey = (shiftKey & 0xC) != 0;
+    shiftKey = (shiftKey & 3) != 0;
     switch(n) {
        case  1: LeftClick(Press,   x, y), but1 = 1; break;
        case -1: LeftClick(Release, x, y), but1 = 0; break;
@@ -1935,18 +1921,13 @@ Exp (int n, int x, int y)
        case -3: menuNr = RightClick(Release, x, y, &pmFromX, &pmFromY), but3 = 0; break;
        case 10:
            DrawPosition(True, NULL);
-           if(twoBoards) { // [HGM] dual: draw other board in other orientation
-               flipView = !flipView; partnerUp = !partnerUp;
-               DrawPosition(True, NULL);
-               flipView = !flipView; partnerUp = !partnerUp;
-           }
        default:
            return NULL;
     }
 
     switch(menuNr) {
-      case 0: return &mainOptions[shiftKey ? 23: 24];
-      case 1: SetupDropMenu(); return &mainOptions[25];
+      case 0: return &mainOptions[shiftKey ? W_MENUW: W_MENUB];
+      case 1: SetupDropMenu(); return &mainOptions[W_DROP];
       case 2:
       case -1: ErrorPopDown();
       case -2:
@@ -1960,21 +1941,79 @@ BoardPopUp (int squareSize, int lineGap, void *clockFontThingy)
 {
     extern Option *dialogOptions[];
     int i, size = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
-    mainOptions[11].choice = (char**) clockFontThingy;
-    mainOptions[12].choice = (char**) clockFontThingy;
-    mainOptions[22].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap;
-    mainOptions[22].max = mainOptions[13].max = size; // board size
-    mainOptions[13].max = size - 2; // board title (subtract border!)
-    mainOptions[12].max = mainOptions[11].max = size/2-3; // clock width
-    mainOptions[14].max = appData.showButtonBar ? size-130 : size-2; // message
-    mainOptions[0].max = size-40; // menu bar
-    mainOptions[10].type = appData.titleInWindow ? Label : -1 ;
-    if(!appData.showButtonBar) for(i=15; i<22; i++) mainOptions[i].type = -1;
+    mainOptions[W_WHITE].choice = (char**) clockFontThingy;
+    mainOptions[W_BLACK].choice = (char**) clockFontThingy;
+    mainOptions[W_BOARD].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap;
+    mainOptions[W_BOARD].max = mainOptions[W_SMALL].max = size; // board size
+    mainOptions[W_SMALL].max = size - 2; // board title (subtract border!)
+    mainOptions[W_BLACK].max = mainOptions[W_WHITE].max = size/2-3; // clock width
+    mainOptions[W_MESSG].max = appData.showButtonBar ? size-130 : size-2; // message
+    mainOptions[W_MENU].max = size-40; // menu bar
+    mainOptions[W_TITLE].type = appData.titleInWindow ? Label : -1 ;
+    if(!appData.showButtonBar) for(i=W_BUTTON; i<W_BOARD; i++) mainOptions[i].type = -1;
     for(i=0; i<8; i++) mainOptions[i+1].choice = (char**) menuBar[i].mi;
     GenericPopUp(mainOptions, "XBoard", BoardWindow, BoardWindow, NONMODAL, 1);
     return mainOptions;
 }
 
+static Option *
+SlaveExp (int n, int x, int y)
+{
+    if(n == 10) { // expose event
+       flipView = !flipView; partnerUp = !partnerUp;
+       DrawPosition(True, NULL); // [HGM] dual: draw other board in other orientation
+       flipView = !flipView; partnerUp = !partnerUp;
+    }
+    return NULL;
+}
+
+Option dualOptions[] = { // auxiliary board window
+{ 0, L2L|T2T,              198, NULL, NULL, NULL, NULL, Label, "White" }, // white clock
+{ 0, R2R|T2T|SAME_ROW,     198, NULL, NULL, NULL, NULL, Label, "Black" }, // black clock
+{ 0, LR|T2T|BORDER,        401, NULL, NULL, NULL, NULL, Label, "message" }, // message field
+{ 401, LR|TT, 401, NULL, (char*) &SlaveExp, NULL, NULL, Graph, "shadow board" }, // board
+{ 0,  NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
+};
+
+void
+SlavePopUp ()
+{
+    // copy params from main board
+    dualOptions[0].choice = mainOptions[W_WHITE].choice;
+    dualOptions[1].choice = mainOptions[W_BLACK].choice;
+    dualOptions[3].value = mainOptions[W_BOARD].value;
+    dualOptions[3].max = dualOptions[2].max = mainOptions[W_BOARD].max; // board size
+    dualOptions[0].max = dualOptions[1].max = mainOptions[W_WHITE].max; // clock width
+    GenericPopUp(dualOptions, "XBoard", DummyDlg, BoardWindow, NONMODAL, 1);
+}
+
+void
+DisplayWhiteClock (long timeRemaining, int highlight)
+{
+    if(appData.noGUI) return;
+    if(twoBoards && partnerUp) {
+       DisplayTimerLabel(&dualOptions[0], _("White"), timeRemaining, highlight);
+       return;
+    }
+    DisplayTimerLabel(&mainOptions[W_WHITE], _("White"), timeRemaining, highlight);
+    if(highlight) SetClockIcon(0);
+}
+
+void
+DisplayBlackClock (long timeRemaining, int highlight)
+{
+    if(appData.noGUI) return;
+    if(twoBoards && partnerUp) {
+       DisplayTimerLabel(&dualOptions[1], _("Black"), timeRemaining, highlight);
+       return;
+    }
+    DisplayTimerLabel(&mainOptions[W_BLACK], _("Black"), timeRemaining, highlight);
+    if(highlight) SetClockIcon(1);
+}
+
+
+//---------------------------------------------
+
 void
 DisplayMessage (char *message, char *extMessage)
 {
@@ -2000,8 +2039,8 @@ DisplayMessage (char *message, char *extMessage)
   /* need to test if messageWidget already exists, since this function
      can also be called during the startup, if for example a Xresource
      is not set up correctly */
-  if(mainOptions[14].handle)
-    SetWidgetLabel(&mainOptions[14], message);
+  if(mainOptions[W_MESSG].handle)
+    SetWidgetLabel(&mainOptions[W_MESSG], message);
 
   return;
 }
@@ -2067,10 +2106,10 @@ Option browseOptions[] = {
 {   0,    LR|T2T,      500, NULL, NULL, NULL, NULL, Label, title },
 {   0,    L2L|T2T,     250, NULL, NULL, NULL, NULL, Label, N_("Directories:") },
 {   0,R2R|T2T|SAME_ROW,100, NULL, NULL, NULL, NULL, Label, N_("Files:") },
-{   0,R2R|T2T|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by name") },
-{   0,R2R|T2T|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by type") },
-{ 300,    L2L|T2T,     250, NULL, (void*) folderList, (char*) &DirSelProc, NULL, ListBox, "" },
-{ 300,R2R|T2T|SAME_ROW,250, NULL, (void*) fileList, (char*) &FileSelProc, NULL, ListBox, "" },
+{   0, R2R|TT|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by name") },
+{   0, R2R|TT|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by type") },
+{ 300,    L2L|TB,      250, NULL, (void*) folderList, (char*) &DirSelProc, NULL, ListBox, "" },
+{ 300, R2R|TB|SAME_ROW,250, NULL, (void*) fileList, (char*) &FileSelProc, NULL, ListBox, "" },
 {   0,       0,        350, NULL, (void*) &fileName, NULL, NULL, TextBox, N_("Filename:") },
 {   0, COMBO_CALLBACK, 150, NULL, (void*) &SetTypeFilter, NULL, FileTypes, ComboBox, N_("File type:") },
 {   0,    SAME_ROW,      0, NULL, (void*) &BrowseOK, "", NULL, EndMark , "" }