340dfdea9cdbee56a51f62b3934c2d3b7bbf6b57
max
  Mon Apr 30 14:50:12 2012 -0700
UI themes for hgc/hgGene and some fixes for hgTracks
diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index 8156ef0..bebf67d 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -1502,39 +1502,115 @@
 googleAnalytics();	/* can't do this in htmlEnd	*/
 #endif /* GBROWSE */
 htmlEnd();		/* because it is in a higher library */
 }
 
 void cartHtmlEnd()
 /* Write out HTML footer and get rid or error handler. */
 {
 if (inWeb)
     webEnd();	/*	this does googleAnalytics for a lot of CGIs	*/
 else
     cartFooter();
 popWarnHandler();
 }
 
+void setThemeFromCart(struct cart *cart) 
+/* If 'theme' variable is set in cart: overwrite background with the one from
+ * defined for this theme Also set the "styleTheme", with additional styles
+ * that can overwrite the main style settings */
+{
+// get theme from cart and use it to get background file from config
+char *cartTheme = cartOptionalString(cart, "theme");
+if (cartTheme==NULL)
+    return;
+
+char *themeKey = catTwoStrings("browser.theme.", cartTheme);
+char *themeDefLine = cfgOption(themeKey);
+freeMem(themeKey);
+if (themeDefLine == NULL)
+    return;
+
+char * background = cloneString(themeDefLine);
+chopSuffixAt(background, ',');
+htmlSetBackground(background);
+
+// set css style (optional, after ',' in hg.conf line)
+if (! stringIn(",", themeDefLine))
+    return;
+char * styleFile = cloneString(themeDefLine);
+styleFile = chopPrefixAt(styleFile, ',');
+
+char * link = webTimeStampedLinkToResourceOnFirstCall(styleFile,TRUE); // resource file link wrapped in html
+if (link)
+    {
+    htmlSetStyleTheme(link); // for htmshell.c, used by hgTracks
+    webSetStyle(link);       // for web.c, used by hgc
+    }
+}
+
+void cartHtmlShellWithHead(char *head, char *title, void (*doMiddle)(struct cart *cart),
+	char *cookieName, char **exclude, struct hash *oldVars)
+/* Load cart from cookie and session cgi variable.  Write web-page
+ * preamble including head and title, call doMiddle with cart, and write end of web-page.
+ * Exclude may be NULL.  If it exists it's a comma-separated list of
+ * variables that you don't want to save in the cart between
+ * invocations of the cgi-script. */
+{
+struct cart *cart;
+char *db, *org, *pos, *clade=NULL;
+char titlePlus[128];
+char extra[128];
+pushWarnHandler(cartEarlyWarningHandler);
+cart = cartAndCookie(cookieName, exclude, oldVars);
+getDbAndGenome(cart, &db, &org, oldVars);
+clade = hClade(org);
+pos = cartOptionalString(cart, positionCgiName);
+pos = addCommasToPos(db, stripCommas(pos));
+if(pos != NULL && oldVars != NULL)
+    {
+    struct hashEl *oldpos = hashLookup(oldVars, positionCgiName);
+    if(oldpos != NULL && differentString(pos,oldpos->val))
+        cartSetString(cart,"lastPosition",oldpos->val);
+    }
+*extra = 0;
+if (pos == NULL && org != NULL)
+    safef(titlePlus,sizeof(titlePlus), "%s%s - %s",org, extra, title );
+else if (pos != NULL && org == NULL)
+    safef(titlePlus,sizeof(titlePlus), "%s - %s",pos, title );
+else if (pos == NULL && org == NULL)
+    safef(titlePlus,sizeof(titlePlus), "%s", title );
+else
+    safef(titlePlus,sizeof(titlePlus), "%s%s %s - %s",org, extra,pos, title );
+popWarnHandler();
+setThemeFromCart(cart);
+htmStartWithHead(stdout, head, titlePlus);
+cartWarnCatcher(doMiddle, cart, htmlVaWarn);
+cartCheckout(&cart);
+cartFooter();
+}
+
 void cartEmptyShell(void (*doMiddle)(struct cart *cart), char *cookieName,
 	char **exclude, struct hash *oldVars)
 /* Get cart and cookies and set up error handling, but don't start writing any
  * html yet. The doMiddleFunction has to call cartHtmlStart(title), and
  * cartHtmlEnd(), as well as writing the body of the HTML.
  * oldVars - those in cart that are overlayed by cgi-vars are
  * put in optional hash oldVars. */
 {
 struct cart *cart = cartAndCookie(cookieName, exclude, oldVars);
+setThemeFromCart(cart);
 cartWarnCatcher(doMiddle, cart, cartEarlyWarningHandler);
 cartCheckout(&cart);
 }
 
 void cartHtmlShellPB(char *title, void (*doMiddle)(struct cart *cart),
         char *cookieName, char **exclude, struct hash *oldVars)
 /* For Proteome Browser, Load cart from cookie and session cgi variable.  Write web-page
  * preamble, call doMiddle with cart, and write end of web-page.
  * Exclude may be NULL.  If it exists it's a comma-separated list of
  * variables that you don't want to save in the cart between
  * invocations of the cgi-script. */
 {
 struct cart *cart;
 char *db, *org;
 char titlePlus[128];
@@ -1562,91 +1638,30 @@
 {
 struct cart *cart;
 char titlePlus[128];
 char *proteinID;
 pushWarnHandler(cartEarlyWarningHandler);
 cart = cartAndCookie(cookieName, exclude, oldVars);
 proteinID = cartOptionalString(cart, "proteinID");
 safef(titlePlus, sizeof(titlePlus), "Protein %s - %s", proteinID, title);
 popWarnHandler();
 htmStart(stdout, titlePlus);
 cartWarnCatcher(doMiddle, cart, htmlVaWarn);
 cartCheckout(&cart);
 cartFooter();
 }
 
-void setBackgroundFromCart(struct cart *cart) 
-/* if 'theme' set in cart: overwrite background with the one from defined for this theme */
-{
-printf("trying to reset background ");
-char *cartTheme = cartOptionalString(cart, "theme");
-if (cartTheme==NULL)
-    return;
-printf("found theme");
-char * themeKey = stringCopy
-char *themeDefLine = cfgOption(cartTheme);
-if (themeDefLine == NULL)
-    return;
-printf("found theme line ");
-char * background = cloneString(themeDefLine);
-chopSuffixAt(background, ',');
-printf("background set to %s", background);
-htmlSetBackground(background);
-freeMem(background);
-}
-
-void cartHtmlShellWithHead(char *head, char *title, void (*doMiddle)(struct cart *cart),
-	char *cookieName, char **exclude, struct hash *oldVars)
-/* Load cart from cookie and session cgi variable.  Write web-page
- * preamble including head and title, call doMiddle with cart, and write end of web-page.
- * Exclude may be NULL.  If it exists it's a comma-separated list of
- * variables that you don't want to save in the cart between
- * invocations of the cgi-script. */
-{
-struct cart *cart;
-char *db, *org, *pos, *clade=NULL;
-char titlePlus[128];
-char extra[128];
-pushWarnHandler(cartEarlyWarningHandler);
-cart = cartAndCookie(cookieName, exclude, oldVars);
-getDbAndGenome(cart, &db, &org, oldVars);
-clade = hClade(org);
-pos = cartOptionalString(cart, positionCgiName);
-pos = addCommasToPos(db, stripCommas(pos));
-if(pos != NULL && oldVars != NULL)
-    {
-    struct hashEl *oldpos = hashLookup(oldVars, positionCgiName);
-    if(oldpos != NULL && differentString(pos,oldpos->val))
-        cartSetString(cart,"lastPosition",oldpos->val);
-    }
-*extra = 0;
-if (pos == NULL && org != NULL)
-    safef(titlePlus,sizeof(titlePlus), "%s%s - %s",org, extra, title );
-else if (pos != NULL && org == NULL)
-    safef(titlePlus,sizeof(titlePlus), "%s - %s",pos, title );
-else if (pos == NULL && org == NULL)
-    safef(titlePlus,sizeof(titlePlus), "%s", title );
-else
-    safef(titlePlus,sizeof(titlePlus), "%s%s %s - %s",org, extra,pos, title );
-popWarnHandler();
-setBackgroundFromCart(cart);
-htmStartWithHead(stdout, head, titlePlus);
-cartWarnCatcher(doMiddle, cart, htmlVaWarn);
-cartCheckout(&cart);
-cartFooter();
-}
-
 void cartHtmlShell(char *title, void (*doMiddle)(struct cart *cart),
 	char *cookieName, char **exclude, struct hash *oldVars)
 /* Load cart from cookie and session cgi variable.  Write web-page
  * preamble, call doMiddle with cart, and write end of web-page.
  * Exclude may be NULL.  If it exists it's a comma-separated list of
  * variables that you don't want to save in the cart between
  * invocations of the cgi-script. */
 {
 cartHtmlShellWithHead("", title, doMiddle, cookieName, exclude, oldVars);
 }
 
 void cartSetDbConnector(DbConnector connector)
 /* Set the connector that will be used by the cart to connect to the
  * database. Default connector is hConnectCart */
 {