wined3d: Pass a wined3d_device_context to wined3d_cs_emit_set_index_buffer().
[wine.git] / dlls / gdi.exe16 / env.c
blobe9b8bc31dce8c748ccf85b28b9cd3eacd245fe47
1 /*
2 * Driver Environment functions
4 * Note: This has NOTHING to do with the task/process environment!
6 * Copyright 1997 Marcus Meissner
7 * Copyright 1998 Andreas Mohr
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library 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 GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "wine/wingdi16.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
36 typedef struct {
37 ATOM atom;
38 HGLOBAL16 handle;
39 } ENVTABLE;
41 static ENVTABLE EnvTable[20];
43 static ENVTABLE *SearchEnvTable(ATOM atom)
45 INT16 i;
47 for (i = 19; i >= 0; i--) {
48 if (EnvTable[i].atom == atom)
49 return &EnvTable[i];
51 return NULL;
54 static ATOM GDI_GetNullPortAtom(void)
56 static ATOM NullPortAtom = 0;
57 if (!NullPortAtom)
59 char NullPort[256];
61 GetProfileStringA( "windows", "nullport", "none",
62 NullPort, sizeof(NullPort) );
63 NullPortAtom = AddAtomA( NullPort );
65 return NullPortAtom;
68 static ATOM PortNameToAtom(LPCSTR lpPortName, BOOL16 add)
70 char buffer[256];
72 lstrcpynA( buffer, lpPortName, sizeof(buffer) );
74 if (buffer[0] && buffer[strlen(buffer)-1] == ':') buffer[strlen(buffer)-1] = 0;
76 if (add)
77 return AddAtomA(buffer);
78 else
79 return FindAtomA(buffer);
83 /***********************************************************************
84 * GetEnvironment (GDI.133)
86 INT16 WINAPI GetEnvironment16(LPCSTR lpPortName, LPDEVMODEA lpdev, UINT16 nMaxSize)
88 ATOM atom;
89 LPCSTR p;
90 ENVTABLE *env;
91 WORD size;
93 TRACE("('%s', %p, %d)\n", lpPortName, lpdev, nMaxSize);
95 if (!(atom = PortNameToAtom(lpPortName, FALSE)))
96 return 0;
97 if (atom == GDI_GetNullPortAtom())
98 if (!(atom = FindAtomA((LPCSTR)lpdev)))
99 return 0;
100 if (!(env = SearchEnvTable(atom)))
101 return 0;
102 size = GlobalSize16(env->handle);
103 if (!lpdev) return 0;
104 if (size < nMaxSize) nMaxSize = size;
105 if (!(p = GlobalLock16(env->handle))) return 0;
106 memcpy(lpdev, p, nMaxSize);
107 GlobalUnlock16(env->handle);
108 return nMaxSize;
112 /***********************************************************************
113 * SetEnvironment (GDI.132)
115 INT16 WINAPI SetEnvironment16(LPCSTR lpPortName, LPDEVMODEA lpdev, UINT16 nCount)
117 ATOM atom;
118 BOOL16 nullport = FALSE;
119 LPCSTR port_name;
120 LPSTR device_mode;
121 ENVTABLE *env;
122 HGLOBAL16 handle;
124 TRACE("('%s', %p, %d)\n", lpPortName, lpdev, nCount);
126 if ((atom = PortNameToAtom(lpPortName, FALSE))) {
127 if (atom == GDI_GetNullPortAtom()) {
128 nullport = TRUE;
129 atom = FindAtomA((LPCSTR)lpdev);
131 env = SearchEnvTable(atom);
132 GlobalFree16(env->handle);
133 env->atom = 0;
135 if (nCount) { /* store DEVMODE struct */
136 if (nullport)
137 port_name = (LPSTR)lpdev;
138 else
139 port_name = lpPortName;
141 if ((atom = PortNameToAtom(port_name, TRUE))
142 && (env = SearchEnvTable(0))
143 && (handle = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, nCount))) {
144 if (!(device_mode = GlobalLock16(handle))) {
145 GlobalFree16(handle);
146 return 0;
148 env->atom = atom;
149 env->handle = handle;
150 memcpy(device_mode, lpdev, nCount);
151 GlobalUnlock16(handle);
152 return handle;
154 else return 0;
156 else return -1;