]> Pileus Git - ~andy/gtk/blob - gtk/gtkwin32.c
gtk: clean up the private horror
[~andy/gtk] / gtk / gtkwin32.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #include "config.h"
28
29 #include "gdk/gdk.h"
30
31 #include "gtkprivate.h"
32
33 #ifdef G_OS_WIN32
34 #define STRICT
35 #include <windows.h>
36 #undef STRICT
37 #endif
38
39 #ifdef G_OS_WIN32
40
41 static HMODULE gtk_dll;
42
43 BOOL WINAPI
44 DllMain (HINSTANCE hinstDLL,
45          DWORD     fdwReason,
46          LPVOID    lpvReserved)
47 {
48   switch (fdwReason)
49     {
50     case DLL_PROCESS_ATTACH:
51       gtk_dll = (HMODULE) hinstDLL;
52       break;
53     }
54
55   return TRUE;
56 }
57
58 const gchar *
59 _gtk_get_libdir (void)
60 {
61   static char *gtk_libdir = NULL;
62   if (gtk_libdir == NULL)
63     {
64       gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
65       gchar *slash = strrchr (root, '\\');
66       if (g_ascii_strcasecmp (slash + 1, ".libs") == 0)
67         gtk_libdir = GTK_LIBDIR;
68       else
69         gtk_libdir = g_build_filename (root, "lib", NULL);
70       g_free (root);
71     }
72
73   return gtk_libdir;
74 }
75
76 const gchar *
77 _gtk_get_localedir (void)
78 {
79   static char *gtk_localedir = NULL;
80   if (gtk_localedir == NULL)
81     {
82       const gchar *p;
83       gchar *root, *temp;
84
85       /* GTK_LOCALEDIR ends in either /lib/locale or
86        * /share/locale. Scan for that slash.
87        */
88       p = GTK_LOCALEDIR + strlen (GTK_LOCALEDIR);
89       while (*--p != '/')
90         ;
91       while (*--p != '/')
92         ;
93
94       root = g_win32_get_package_installation_directory_of_module (gtk_dll);
95       temp = g_build_filename (root, p, NULL);
96       g_free (root);
97
98       /* gtk_localedir is passed to bindtextdomain() which isn't
99        * UTF-8-aware.
100        */
101       gtk_localedir = g_win32_locale_filename_from_utf8 (temp);
102       g_free (temp);
103     }
104   return gtk_localedir;
105 }
106
107 const gchar *
108 _gtk_get_datadir (void)
109 {
110   static char *gtk_datadir = NULL;
111   if (gtk_datadir == NULL)
112     {
113       gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
114       gtk_datadir = g_build_filename (root, "share", NULL);
115       g_free (root);
116     }
117
118   return gtk_datadir;
119 }
120
121 const gchar *
122 _gtk_get_sysconfdir (void)
123 {
124   static char *gtk_sysconfdir = NULL;
125   if (gtk_sysconfdir == NULL)
126     {
127       gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
128       gtk_sysconfdir = g_build_filename (root, "etc", NULL);
129       g_free (root);
130     }
131
132   return gtk_sysconfdir;
133 }
134
135 const gchar *
136 _gtk_get_data_prefix (void)
137 {
138   static char *gtk_data_prefix = NULL;
139   if (gtk_data_prefix == NULL)
140     gtk_data_prefix = g_win32_get_package_installation_directory_of_module (gtk_dll);
141
142   return gtk_data_prefix;
143 }