Ignore color arguments not starting with #
[xboard.git] / gtk / xboard.c
index e72a3aa..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__
@@ -443,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 *
@@ -669,7 +673,7 @@ InitializeFonts (int clockFontPxlSize, int coordFontPxlSize, int fontPxlSize)
     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, coordFontPxlSize);
@@ -806,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;
@@ -858,6 +871,7 @@ main (int argc, char **argv)
        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,
@@ -1125,8 +1139,8 @@ 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);
+    WhiteIcon  = LoadIconFile("icon_white");
+    BlackIcon  = LoadIconFile("icon_black");
     SetClockIcon(0); // sets white icon
 
 
@@ -1454,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
@@ -2018,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
     }
 }
 
@@ -2198,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])