From 26d1da7b02a1b4190877777183bd7be2087bc6d2 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 3 Sep 2003 20:14:38 +0000 Subject: [PATCH] Implement `default-colours' on Windows based loosely on Michael Wardle's patch. git-svn-id: svn://svn.tartarus.org/sgt/putty@3444 cda61777-01e9-0310-a592-d414129be87e --- doc/config.but | 14 +++++++++++++- putty.h | 1 + settings.c | 2 ++ wincfg.c | 4 ++++ window.c | 33 +++++++++++++++++++++++++++++++++ winhelp.h | 1 + 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/doc/config.but b/doc/config.but index 1dc0ad45..ddfad40e 100644 --- a/doc/config.but +++ b/doc/config.but @@ -1,4 +1,4 @@ -\versionid $Id: config.but,v 1.66 2003/06/25 15:52:29 jacob Exp $ +\versionid $Id: config.but,v 1.67 2003/09/03 20:14:38 jacob Exp $ \C{config} Configuring PuTTY @@ -1315,6 +1315,18 @@ If you are not getting the colours you ask for on an 8-bit display, you can try enabling this option. However, be warned that it's never worked very well. +\S{config-syscolour} \q{Use system colours} + +\cfg{winhelp-topic}{colours.system} + +Enabling this option will cause PuTTY to ignore the configured colours +for \q{Default Background/Foreground} and \q{Cursor Colour/Text} (see +\k{config-colourcfg}), instead going with the system-wide defaults. + +Note that non-bold and bold text will be the same colour if this +option is enabled. You might want to change to indicating bold text +by font changes (see \k{config-boldcolour}). + \S{config-colourcfg} Adjusting the colours in the terminal window \cfg{winhelp-topic}{colours.config} diff --git a/putty.h b/putty.h index 026448b7..60aed037 100644 --- a/putty.h +++ b/putty.h @@ -429,6 +429,7 @@ struct config_tag { char answerback[256]; char printer[128]; /* Colour options */ + int system_colour; int try_palette; int bold_colour; unsigned char colours[22][3]; diff --git a/settings.c b/settings.c index d5e0d265..470ccd24 100644 --- a/settings.c +++ b/settings.c @@ -280,6 +280,7 @@ void save_open_settings(void *sesskey, int do_host, Config *cfg) write_setting_i(sesskey, "TermHeight", cfg->height); write_setting_fontspec(sesskey, "Font", cfg->font); write_setting_i(sesskey, "FontVTMode", cfg->vtmode); + write_setting_i(sesskey, "UseSystemColours", cfg->system_colour); write_setting_i(sesskey, "TryPalette", cfg->try_palette); write_setting_i(sesskey, "BoldAsColour", cfg->bold_colour); for (i = 0; i < 22; i++) { @@ -534,6 +535,7 @@ void load_open_settings(void *sesskey, int do_host, Config *cfg) gppi(sesskey, "TermHeight", 24, &cfg->height); gppfont(sesskey, "Font", &cfg->font); gppi(sesskey, "FontVTMode", VT_UNICODE, (int *) &cfg->vtmode); + gppi(sesskey, "UseSystemColours", 0, &cfg->system_colour); gppi(sesskey, "TryPalette", 0, &cfg->try_palette); gppi(sesskey, "BoldAsColour", 1, &cfg->bold_colour); for (i = 0; i < 22; i++) { diff --git a/wincfg.c b/wincfg.c index c094eb77..992d5dbf 100644 --- a/wincfg.c +++ b/wincfg.c @@ -271,6 +271,10 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, ctrl_checkbox(s, "Attempt to use logical palettes", 'l', HELPCTX(colours_logpal), dlg_stdcheckbox_handler, I(offsetof(Config,try_palette))); + ctrl_checkbox(s, "Use system colours", 's', + HELPCTX(colours_system), + dlg_stdcheckbox_handler, I(offsetof(Config,system_colour))); + /* * Resize-by-changing-font is a Windows insanity. diff --git a/window.c b/window.c index ea0077d9..1e84972e 100644 --- a/window.c +++ b/window.c @@ -75,6 +75,7 @@ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, unsigned char *output); static void cfgtopalette(void); +static void systopalette(void); static void init_palette(void); static void init_fonts(int, int); static void another_font(int); @@ -1015,6 +1016,38 @@ static void cfgtopalette(void) defpal[i].rgbtGreen = cfg.colours[w][1]; defpal[i].rgbtBlue = cfg.colours[w][2]; } + + /* Override with system colours if appropriate */ + if (cfg.system_colour) + systopalette(); +} + +/* + * Override bit of defpal with colours from the system. + * (NB that this takes a copy the system colours at the time this is called, + * so subsequent colour scheme changes don't take effect. To fix that we'd + * probably want to be using GetSysColorBrush() and the like.) + */ +static void systopalette(void) +{ + int i; + static const struct { int nIndex; int norm; int bold; } or[] = + { + { COLOR_WINDOWTEXT, 16, 17 }, /* Default Foreground */ + { COLOR_WINDOW, 18, 19 }, /* Default Background */ + { COLOR_HIGHLIGHTTEXT, 20, 21 }, /* Cursor Text */ + { COLOR_HIGHLIGHT, 22, 23 }, /* Cursor Colour */ + }; + + for (i = 0; i < (sizeof(or)/sizeof(or[0])); i++) { + COLORREF colour = GetSysColor(or[i].nIndex); + defpal[or[i].norm].rgbtRed = + defpal[or[i].bold].rgbtRed = GetRValue(colour); + defpal[or[i].norm].rgbtGreen = + defpal[or[i].bold].rgbtGreen = GetGValue(colour); + defpal[or[i].norm].rgbtBlue = + defpal[or[i].bold].rgbtBlue = GetBValue(colour); + } } /* diff --git a/winhelp.h b/winhelp.h index e767aabc..8d69573f 100644 --- a/winhelp.h +++ b/winhelp.h @@ -92,6 +92,7 @@ #define WINHELP_CTX_selection_linedraw "selection.linedraw" #define WINHELP_CTX_selection_rtf "selection.rtf" #define WINHELP_CTX_colours_bold "colours.bold" +#define WINHELP_CTX_colours_system "colours.system" #define WINHELP_CTX_colours_logpal "colours.logpal" #define WINHELP_CTX_colours_config "colours.config" #define WINHELP_CTX_translation_codepage "translation.codepage" -- 2.11.0