Ignore color arguments not starting with #
[xboard.git] / gtk / xboard.c
index 77e436b..4daec27 100644 (file)
@@ -172,6 +172,7 @@ extern char *getenv();
    // prevent pathname of positional file argument provided by OS X being be mistaken for option name
    // (price is that we won't recognize Windows option format anymore).
 #  define SLASH '-'
+#  define IMG ".png"
    // redefine some defaults
 #  undef ICS_LOGON
 #  undef DATADIR
@@ -179,10 +180,13 @@ extern char *getenv();
 #  define ICS_LOGON "Library/Preferences/XboardICS.conf"
 #  define DATADIR dataDir
 #  define SETTINGS_FILE masterSettings
+#  define SYNC_MENUBAR gtkosx_application_sync_menubar(theApp)
    char dataDir[MSG_SIZ]; // for expanding ~~
    char masterSettings[MSG_SIZ];
 #else
 #  define SLASH '/'
+#  define IMG ".svg"
+#  define SYNC_MENUBAR
 #endif
 
 #ifdef __EMX__
@@ -386,9 +390,10 @@ ParseFont (char *name, int number)
     //       defer processing it until we know if it matches our board size
     if(!strstr(name, "-*-") &&       // ignore X-fonts
        size >= 0 && size<MAX_SIZE) { // for now, fixed limit
-       fontTable[number][size] = name = strdup(strchr(name, ':')+1);
+       fontTable[number][size] = strdup(strchr(name, ':')+1);
        fontValid[number][size] = True;
-    } else return;
+    }
+    return;
   }
   switch(number) {
     case 0: // CLOCK_FONT
@@ -442,7 +447,7 @@ CreateFonts ()
 void
 ParseColor (int n, char *name)
 { // in XBoard, just copy the color-name string
-  if(colorVariable[n]) *(char**)colorVariable[n] = strdup(name);
+  if(colorVariable[n] && *name == '#') *(char**)colorVariable[n] = strdup(name);
 }
 
 char *
@@ -659,17 +664,23 @@ InitializeFonts (int clockFontPxlSize, int coordFontPxlSize, int fontPxlSize)
        appData.coordFont = fontTable[COORD_FONT][squareSize];
     if(!fontIsSet[CONSOLE_FONT] && fontValid[CONSOLE_FONT][squareSize])
        appData.icsFont = fontTable[CONSOLE_FONT][squareSize];
+    if(!fontIsSet[EDITTAGS_FONT] && fontValid[EDITTAGS_FONT][squareSize])
+       appData.tagsFont = fontTable[EDITTAGS_FONT][squareSize];
     if(!fontIsSet[COMMENT_FONT] && fontValid[COMMENT_FONT][squareSize])
        appData.commentFont = fontTable[COMMENT_FONT][squareSize];
+    if(!fontIsSet[MOVEHISTORY_FONT] && fontValid[MOVEHISTORY_FONT][squareSize])
+       appData.historyFont = fontTable[MOVEHISTORY_FONT][squareSize];
+    if(!fontIsSet[GAMELIST_FONT] && fontValid[GAMELIST_FONT][squareSize])
+       appData.gameListFont = fontTable[GAMELIST_FONT][squareSize];
 
-    appData.font = InsertPxlSize(appData.font, fontPxlSize);
+    appData.font = InsertPxlSize(appData.font, coordFontPxlSize);
     appData.clockFont = InsertPxlSize(appData.clockFont, clockFontPxlSize);
     appData.coordFont = InsertPxlSize(appData.coordFont, coordFontPxlSize);
-    appData.icsFont = InsertPxlSize(appData.icsFont, fontPxlSize);
-    appData.tagsFont = InsertPxlSize(appData.tagsFont, fontPxlSize);
-    appData.commentFont = InsertPxlSize(appData.commentFont, fontPxlSize);
-    appData.historyFont = InsertPxlSize(appData.historyFont, fontPxlSize);
-    appData.gameListFont = InsertPxlSize(appData.gameListFont, fontPxlSize);
+    appData.icsFont = InsertPxlSize(appData.icsFont, coordFontPxlSize);
+    appData.tagsFont = InsertPxlSize(appData.tagsFont, coordFontPxlSize);
+    appData.commentFont = InsertPxlSize(appData.commentFont, coordFontPxlSize);
+    appData.historyFont = InsertPxlSize(appData.historyFont, coordFontPxlSize);
+    appData.gameListFont = InsertPxlSize(appData.gameListFont, coordFontPxlSize);
 
 #ifdef TODO_GTK
     XrmValue vTo;
@@ -799,6 +810,15 @@ SlaveResize (Option *opt)
   gtk_window_resize(GTK_WINDOW(shells[DummyDlg]), slaveW + opt->max, slaveH + opt->value);
 }
 
+GdkPixbuf *
+LoadIconFile (gchar *svgFilename)
+{
+    char buf[MSG_SIZ];
+
+    snprintf(buf, MSG_SIZ, "%s/%s" IMG, svgDir, svgFilename);
+    return gdk_pixbuf_new_from_file(buf, NULL);
+}
+
 #ifdef __APPLE__
 static char clickedFile[MSG_SIZ];
 static int suppress;
@@ -815,6 +835,8 @@ StartNewXBoard(GtkosxApplication *app, gchar *path, gpointer user_data)
   }
   return TRUE;
 }
+
+GtkosxApplication *theApp;
 #endif
 
 int
@@ -845,10 +867,11 @@ main (int argc, char **argv)
     gtk_init (&argc, &argv);
 #ifdef __APPLE__
     {   // prepare to catch OX OpenFile signal, which will tell us the clicked file
-       GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
        char *path = gtkosx_application_get_bundle_path();
+       theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
        strncpy(dataDir, path, MSG_SIZ);
        snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path);
+       snprintf(svgDir, MSG_SIZ, "%s/Contents/Resources/share/xboard/themes/default", path);
        suppress = (argc == 1 || argc > 1 && argv[1][00] != '-'); // OSX sends signal even if name was already argv[1]!
        g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL);
        // we must call application ready before we can get the signal,
@@ -1116,10 +1139,9 @@ main (int argc, char **argv)
     /*
      * Create an icon. (Use two icons, to indicate whther it is white's or black's turn.)
      */
-    WhiteIcon  = gdk_pixbuf_new_from_file(SVGDIR "/icon_white.svg", NULL);
-    BlackIcon  = gdk_pixbuf_new_from_file(SVGDIR "/icon_black.svg", NULL);
-    mainwindowIcon = WhiteIcon;
-    gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
+    WhiteIcon  = LoadIconFile("icon_white");
+    BlackIcon  = LoadIconFile("icon_black");
+    SetClockIcon(0); // sets white icon
 
 
     /*
@@ -1446,11 +1468,23 @@ FindFont (char *pattern, int targetPxlSize)
 #endif
 
 void
+MarkMenuItem (char *menuRef, int state)
+{
+    MenuItem *item = MenuNameToItem(menuRef);
+
+    if(item && item->handle) {
+        ((GtkCheckMenuItem *) (item->handle))->active = state;
+    }
+    SYNC_MENUBAR;
+}
+
+void
 EnableNamedMenuItem (char *menuRef, int state)
 {
     MenuItem *item = MenuNameToItem(menuRef);
 
     if(item && item->handle) gtk_widget_set_sensitive(item->handle, state);
+    SYNC_MENUBAR;
 }
 
 void
@@ -2010,7 +2044,11 @@ SetClockIcon (int color)
     GdkPixbuf *pm = *clockIcons[color];
     if (mainwindowIcon != pm) {
         mainwindowIcon = pm;
-       gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
+#ifdef __APPLE__
+        gtkosx_application_set_dock_icon_pixbuf(theApp, mainwindowIcon);
+#else
+        gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
+#endif
     }
 }
 
@@ -2190,13 +2228,20 @@ static void
 LoadLogo (ChessProgramState *cps, int n, Boolean ics)
 {
     char buf[MSG_SIZ], *logoName = buf;
+    FILE *f;
     if(appData.logo[n][0]) {
        logoName = appData.logo[n];
     } else if(appData.autoLogo) {
        if(ics) { // [HGM] logo: in ICS mode second can be used for ICS
            sprintf(buf, "%s/%s.png", appData.logoDir, appData.icsHost);
-       } else if(appData.directory[n] && appData.directory[n][0]) {
-           sprintf(buf, "%s/%s.png", appData.logoDir, cps->tidy);
+       } else { // engine; look in engine-dir (if any) first
+           snprintf(buf, MSG_SIZ, "%s/logo.png", appData.directory[n]);
+           if(appData.directory[n] && appData.directory[n][0]
+              && strcmp(appData.directory[n], ".") && (f = fopen(buf, "r")) )
+               fclose(f);
+           else // no engine dir or no logo.png in it: look in logo dir
+           if(appData.logoDir && appData.logoDir[0])
+               sprintf(buf, "%s/%s.png", appData.logoDir, cps->tidy);
        }
     }
     if(logoName[0])