root/src/w32reg.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. w32_get_rdb_resource
  2. w32_get_string_resource_1
  3. w32_get_string_resource

     1 /* Emulate the X Resource Manager through the registry.
     2 
     3 Copyright (C) 1990, 1993-1994, 2001-2023 Free Software Foundation, Inc.
     4 
     5 Author: Kevin Gallo
     6 
     7 This file is part of GNU Emacs.
     8 
     9 GNU Emacs is free software: you can redistribute it and/or modify
    10 it under the terms of the GNU General Public License as published by
    11 the Free Software Foundation, either version 3 of the License, or (at
    12 your option) any later version.
    13 
    14 GNU Emacs is distributed in the hope that it will be useful,
    15 but WITHOUT ANY WARRANTY; without even the implied warranty of
    16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17 GNU General Public License for more details.
    18 
    19 You should have received a copy of the GNU General Public License
    20 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    21 
    22 #include <config.h>
    23 #include "lisp.h"
    24 #include "blockinput.h"
    25 #include "w32term.h"
    26 
    27 #include <stdio.h>
    28 
    29 #define REG_ROOT "SOFTWARE\\GNU\\Emacs"
    30 
    31 /* Default system colors from the Display Control Panel settings.  */
    32 #define SYSTEM_DEFAULT_RESOURCES                          \
    33   "emacs.foreground:SystemWindowText\0"                   \
    34   "emacs.background:SystemWindow\0"                       \
    35   "emacs.tooltip.attributeForeground:SystemInfoText\0"    \
    36   "emacs.tooltip.attributeBackground:SystemInfoWindow\0"  \
    37   "emacs.tool-bar.attributeForeground:SystemButtonText\0" \
    38   "emacs.tool-bar.attributeBackground:SystemButtonFace\0" \
    39   "emacs.tab-bar.attributeForeground:SystemButtonText\0" \
    40   "emacs.tab-bar.attributeBackground:SystemButtonFace\0" \
    41   "emacs.menu.attributeForeground:SystemMenuText\0"       \
    42   "emacs.menu.attributeBackground:SystemMenu\0"           \
    43   "emacs.scroll-bar.attributeForeground:SystemScrollbar\0"
    44 
    45 /* Other possibilities for default faces:
    46 
    47   region: Could use SystemHilight, but interferes with our ability to
    48   see most syntax highlighting through the region face.
    49 
    50   modeline: Could use System(In)ActiveTitle, gradient versions (not
    51   supported on 95 and NT), but modeline is more like a status bar
    52   really (which don't appear to be configurable in Windows).
    53 
    54   highlight: Could use SystemHotTrackingColor, but it is not supported
    55   on Windows 95 or NT, and other apps only seem to use it for menus
    56   anyway.
    57 
    58 */
    59 
    60 static char *
    61 w32_get_rdb_resource (const char *rdb, const char *resource)
    62 {
    63   char *value = (char *)rdb;
    64   int len = strlen (resource);
    65 
    66   while (*value)
    67     {
    68       /* Comparison is case-insensitive because registry searches are too.  */
    69       if ((strnicmp (value, resource, len) == 0) && (value[len] == ':'))
    70         return xstrdup (&value[len + 1]);
    71 
    72       value = strchr (value, '\0') + 1;
    73     }
    74 
    75   return NULL;
    76 }
    77 
    78 static const char *
    79 w32_get_string_resource_1 (const char *name, const char *class, DWORD dwexptype)
    80 {
    81   LPBYTE lpvalue = NULL;
    82   HKEY hrootkey = NULL;
    83   DWORD dwType;
    84   DWORD cbData;
    85   BOOL ok = FALSE;
    86   HKEY hive = HKEY_CURRENT_USER;
    87 
    88  trykey:
    89 
    90   block_input ();
    91 
    92   /* Check both the current user and the local machine to see if we have
    93      any resources */
    94 
    95   if (RegOpenKeyEx (hive, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
    96     {
    97       const char *keyname;
    98 
    99       if (RegQueryValueEx (hrootkey, name, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
   100           && dwType == dwexptype)
   101         {
   102           keyname = name;
   103         }
   104       else if (RegQueryValueEx (hrootkey, class, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
   105                && dwType == dwexptype)
   106         {
   107           keyname = class;
   108         }
   109       else
   110         {
   111           keyname = NULL;
   112         }
   113 
   114       ok = (keyname
   115             && (lpvalue = xmalloc (cbData)) != NULL
   116             && RegQueryValueEx (hrootkey, keyname, NULL, NULL, lpvalue, &cbData) == ERROR_SUCCESS);
   117 
   118       RegCloseKey (hrootkey);
   119     }
   120 
   121   unblock_input ();
   122 
   123   if (!ok)
   124     {
   125       if (lpvalue)
   126         {
   127           xfree (lpvalue);
   128           lpvalue = NULL;
   129         }
   130       if (hive == HKEY_CURRENT_USER)
   131         {
   132           hive = HKEY_LOCAL_MACHINE;
   133           goto trykey;
   134         }
   135 
   136       /* Check if there are Windows specific defaults defined.  */
   137       return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES, name);
   138     }
   139   return (const char *)lpvalue;
   140 }
   141 
   142 /* Retrieve the string resource specified by NAME with CLASS from
   143    database RDB. */
   144 
   145 const char *
   146 w32_get_string_resource (void *v_rdb, const char *name, const char *class)
   147 {
   148   const char *rdb = *(char **) v_rdb;
   149 
   150   if (rdb)
   151     {
   152       char *resource;
   153 
   154       if ((resource = w32_get_rdb_resource (rdb, name)))
   155         return resource;
   156       if ((resource = w32_get_rdb_resource (rdb, class)))
   157         return resource;
   158     }
   159 
   160   if (inhibit_x_resources)
   161     /* --quick was passed, so this is a no-op.  */
   162     return NULL;
   163 
   164   return w32_get_string_resource_1 (name, class, REG_SZ);
   165 }

/* [<][>][^][v][top][bottom][index][help] */