Connect CommentClick handler
[xboard.git] / xboard.c
index f1c5425..4a4cdad 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -149,38 +149,6 @@ extern char *getenv();
 #include <locale.h>
 #endif
 
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-#include <X11/Shell.h>
-#include <X11/cursorfont.h>
-#include <X11/Xatom.h>
-#include <X11/Xmu/Atoms.h>
-#if USE_XAW3D
-#include <X11/Xaw3d/Dialog.h>
-#include <X11/Xaw3d/Form.h>
-#include <X11/Xaw3d/List.h>
-#include <X11/Xaw3d/Label.h>
-#include <X11/Xaw3d/SimpleMenu.h>
-#include <X11/Xaw3d/SmeBSB.h>
-#include <X11/Xaw3d/SmeLine.h>
-#include <X11/Xaw3d/Box.h>
-#include <X11/Xaw3d/MenuButton.h>
-#include <X11/Xaw3d/Text.h>
-#include <X11/Xaw3d/AsciiText.h>
-#else
-#include <X11/Xaw/Dialog.h>
-#include <X11/Xaw/Form.h>
-#include <X11/Xaw/List.h>
-#include <X11/Xaw/Label.h>
-#include <X11/Xaw/SimpleMenu.h>
-#include <X11/Xaw/SmeBSB.h>
-#include <X11/Xaw/SmeLine.h>
-#include <X11/Xaw/Box.h>
-#include <X11/Xaw/MenuButton.h>
-#include <X11/Xaw/Text.h>
-#include <X11/Xaw/AsciiText.h>
-#endif
-
 // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
 #include "common.h"
 
@@ -221,15 +189,15 @@ int main P((int argc, char **argv));
 RETSIGTYPE CmailSigHandler P((int sig));
 RETSIGTYPE IntSigHandler P((int sig));
 RETSIGTYPE TermSizeSigHandler P((int sig));
-Widget CreateMenuBar P((Menu *mb, int boardWidth));
 #if ENABLE_NLS
 char *InsertPxlSize P((char *pattern, int targetPxlSize));
 XFontSet CreateFontSet P((char *base_fnt_lst));
 #else
 char *FindFont P((char *pattern, int targetPxlSize));
 #endif
-void EventProc P((Widget widget, caddr_t unused, XEvent *event));
 void DelayedDrag P((void));
+void ICSInputBoxPopUp P((void));
+#ifdef TODO_GTK
 static void MoveTypeInProc P((Widget widget, caddr_t unused, XEvent *event));
 void HandlePV P((Widget w, XEvent * event,
                     String * params, Cardinal * nParams));
@@ -237,7 +205,6 @@ void DrawPositionProc P((Widget w, XEvent *event,
                     String *prms, Cardinal *nprms));
 void CommentClick P((Widget w, XEvent * event,
                   String * params, Cardinal * nParams));
-void ICSInputBoxPopUp P((void));
 void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data));
 void KeyBindingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void QuitWrapper P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
@@ -246,20 +213,21 @@ static void UpKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)
 static void DownKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void TempBackwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void TempForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
-Boolean TempBackwardActive = False;
 void ManInner P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
+void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams));
+#endif
+Boolean TempBackwardActive = False;
 void DisplayMove P((int moveNumber));
 void ICSInitScript P((void));
-void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams));
 void update_ics_width P(());
 int CopyMemoProc P(());
 
+#ifdef TODO_GTK
 /*
 * XBoard depends on Xt R4 or higher
 */
 int xtVersion = XtSpecificationRelease;
 
-#ifdef TODO_GTK
 int xScreen;
 Display *xDisplay;
 Window xBoardWindow;
@@ -285,8 +253,6 @@ char *layoutName;
 
 char installDir[] = "."; // [HGM] UCI: needed for UCI; probably needs run-time initializtion
 
-Position commentX = -1, commentY = -1;
-Dimension commentW, commentH;
 typedef unsigned int BoardSize;
 BoardSize boardSize;
 Boolean chessProgram;
@@ -296,9 +262,11 @@ int smallLayout = 0, tinyLayout = 0,
   marginW, marginH, // [HGM] for run-time resizing
   fromX = -1, fromY = -1, toX, toY, commentUp = False,
   errorExitStatus = -1, defaultLineGap;
+#ifdef TODO_GTK
 Dimension textHeight;
 Pixel timerForegroundPixel, timerBackgroundPixel;
 Pixel buttonForegroundPixel, buttonBackgroundPixel;
+#endif
 char *chessDir, *programName, *programVersion;
 Boolean alwaysOnTop = False;
 char *icsTextMenuString;
@@ -1045,9 +1013,10 @@ main (int argc, char **argv)
 #ifdef TODO_GTK
     XSetWindowAttributes window_attributes;
     Arg args[16];
+    Dimension boardWidth, boardHeight, w, h;
 #else
 #endif
-    Dimension boardWidth, boardHeight, w, h;
+    int boardWidth, boardHeight, w, h;
     char *p;
     int forceMono = False;
     GError *gtkerror=NULL;
@@ -1273,14 +1242,6 @@ main (int argc, char **argv)
        appData.monoMode = True;
     }
 
-    if (appData.monoMode && appData.debugMode) {
-#ifdef TODO_GTK
-       fprintf(stderr, _("white pixel = 0x%lx, black pixel = 0x%lx\n"),
-               (unsigned long) XWhitePixel(xDisplay, xScreen),
-               (unsigned long) XBlackPixel(xDisplay, xScreen));
-#endif
-    }
-
     ParseIcsTextColors();
 
 #ifdef TODO_GTK
@@ -1325,7 +1286,6 @@ main (int argc, char **argv)
       XtGetValues(optList[W_PAUSE].handle, args, 2);
     }
 #endif
-    AppendEnginesToMenu(appData.recentEngineList);
 
 #ifdef TODO_GTK
     xBoardWindow = XtWindow(boardWidget);
@@ -1674,6 +1634,43 @@ SetMenuEnables (Enables *enab)
 }
 
 #ifdef TODO_GTK
+gboolean KeyPressProc(window, eventkey, data)
+     GtkWindow *window;
+     GdkEventKey  *eventkey;
+     gpointer data;
+{
+
+    MoveTypeInProc(eventkey); // pop up for typed in moves
+
+    // handle shift+<number> cases
+    if (eventkey->state & GDK_SHIFT_MASK) {
+        guint keyval;
+
+        gdk_keymap_translate_keyboard_state(NULL, eventkey->hardware_keycode,
+                                           0, eventkey->group,
+                                           &keyval, NULL, NULL, NULL);
+        switch(keyval) {
+            case GDK_1:
+                AskQuestionEvent("Direct command", "Send to chess program:", "", "1");
+                break;
+            case GDK_2:
+                AskQuestionEvent("Direct command", "Send to second chess program:", "", "2");
+                break;
+            default:
+                break;
+        }
+    }
+
+    /* check for other key values */
+    switch(eventkey->keyval) {
+        case GDK_question:
+         AboutGameEvent();
+         break;
+        default:
+         break;
+    }
+    return False;
+}
 void
 KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 {   // [HGM] new method of key binding: specify MenuItem(FlipView) in stead of FlipViewProc in translation string
@@ -1684,22 +1681,6 @@ KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 }
 #endif
 
-#ifdef TODO_GTK
-static void
-MenuEngineSelect (Widget w, caddr_t addr, caddr_t index)
-{
-    RecentEngineEvent((int) (intptr_t) addr);
-}
-#endif
-
-void
-AppendMenuItem (char *msg, int n)
-{
-#ifdef TODO_GTK
-    CreateMenuItem((Widget) optList[W_ENGIN].textValue, msg, (XtCallbackProc) MenuEngineSelect, n);
-#endif
-}
-
 void
 SetupDropMenu ()
 {
@@ -1736,10 +1717,7 @@ do_flash_delay (unsigned long msec)
 void
 FlashDelay (int flash_delay)
 {
-#ifdef TODO_GTK
-       XSync(xDisplay, False);
        if(flash_delay) do_flash_delay(flash_delay);
-#endif
 }
 
 double
@@ -1849,72 +1827,26 @@ DelayedDrag ()
 #endif
 }
 
+#ifdef TODO_GTK
 void
 EventProc (Widget widget, caddr_t unused, XEvent *event)
 {
-#ifdef TODO_GTK
     if(XtIsRealized(widget) && event->type == ConfigureNotify || appData.useStickyWindows)
        DelayedDrag(); // as long as events keep coming in faster than 50 msec, they destroy each other
-#endif
 }
+#endif
 
 /*
  * event handler for redrawing the board
  */
+#ifdef TODO_GTK
 void
 DrawPositionProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 {
     DrawPosition(True, NULL);
 }
-
-
-#ifdef TODO_GTK
-void
-HandlePV (Widget w, XEvent * event, String * params, Cardinal * nParams)
-{   // [HGM] pv: walk PV
-    MovePV(event->xmotion.x, event->xmotion.y, lineGap + BOARD_HEIGHT * (squareSize + lineGap));
-}
-#endif
-
-static int savedIndex;  /* gross that this is global */
-
-void
-CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams)
-{
-#ifdef TODO_GTK
-       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 */
@@ -1944,10 +1876,7 @@ ModeHighlight ()
     static int oldPausing = FALSE;
     static GameMode oldmode = (GameMode) -1;
     char *wname;
-#ifdef TODO_GTK
-    Arg args[16];
-
-    if (!boardWidget || !XtIsRealized(boardWidget)) return;
+    if (!boardWidget) return;
 
     if (pausing != oldPausing) {
        oldPausing = pausing;
@@ -1957,19 +1886,11 @@ ModeHighlight ()
          /* Always toggle, don't set.  Previous code messes up when
             invoked while the button is pressed, as releasing it
             toggles the state again. */
-         {
-           Pixel oldbg, oldfg;
-           XtSetArg(args[0], XtNbackground, &oldbg);
-           XtSetArg(args[1], XtNforeground, &oldfg);
-           XtGetValues(optList[W_PAUSE].handle,
-                       args, 2);
-           XtSetArg(args[0], XtNbackground, oldfg);
-           XtSetArg(args[1], XtNforeground, oldbg);
-         }
-         XtSetValues(optList[W_PAUSE].handle, args, 2);
+           GdkColor color;     
+            gdk_color_parse( pausing ? "#808080" : "#F0F0F0", &color );
+            gtk_widget_modify_bg ( GTK_WIDGET(optList[W_PAUSE].handle), GTK_STATE_NORMAL, &color );
        }
     }
-#endif
 
     wname = ModeToWidgetName(oldmode);
     if (wname != NULL) {
@@ -2168,11 +2089,13 @@ PasteGameProc ()
 }
 
 
+#ifdef TODO_GTK
 void
 QuitWrapper (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 {
     QuitProc();
 }
+#endif
 
 int
 ShiftKeys ()
@@ -2191,39 +2114,23 @@ ShiftKeys ()
     return k;
 }
 
-static void
-MoveTypeInProc (Widget widget, caddr_t unused, XEvent *event)
+void MoveTypeInProc(eventkey)
+    GdkEventKey  *eventkey;
 {
-#ifdef TODO_GTK
     char buf[10];
-    KeySym sym;
-    int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL);
-    if ( n == 1 && *buf >= 32 // printable
-        && !(ShiftKeys() & 0x3C) // no Alt, Ctrl
-       ) BoxAutoPopUp (buf);
-#endif
-}
-
-#ifdef TODO_GTK
-static void
-UpKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
-{   // [HGM] input: let up-arrow recall previous line from history
-    IcsKey(1);
-}
 
-static void
-DownKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
-{   // [HGM] input: let down-arrow recall next line from history
-    IcsKey(-1);
-}
+    // ingnore if ctrl or alt is pressed
+    if (eventkey->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) {
+        return;
+    }
 
-static void
-EnterKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
-{
-    IcsKey(0);
+    buf[0]=eventkey->keyval;
+    buf[1]='\0';
+    if (*buf >= 32)        
+       BoxAutoPopUp (buf);
 }
 
-
+#ifdef TODO_GTK
 void
 TempBackwardProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 {
@@ -2517,11 +2424,8 @@ FrameAlarm (int sig)
 void
 FrameDelay (int time)
 {
-#ifdef TODO_GTK
   struct itimerval delay;
 
-  XSync(xDisplay, False);
-
   if (time > 0) {
     frameWaiting = True;
     signal(SIGALRM, FrameAlarm);
@@ -2535,7 +2439,6 @@ FrameDelay (int time)
     delay.it_interval.tv_usec = delay.it_value.tv_usec = 0;
     setitimer(ITIMER_REAL, &delay, NULL);
   }
-#endif
 }
 
 #else
@@ -2546,6 +2449,8 @@ FrameDelay (int time)
 #ifdef TODO_GTK
   XSync(xDisplay, False);
 #endif
+//  gtk_main_iteration_do(False);
+
   if (time > 0)
     usleep(time * 1000);
 }