1 /* WIN32Geometry - Implements coordinate transformations for MSWindows
2 
3    Copyright (C) 2002 Free Software Foundation, Inc.
4 
5    Written by: Fred Kiefer <FredKiefer@gmx.de>
6    Date: April 2002
7 
8    This file is part of the GNU Objective C User Interface Library.
9 
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14 
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
18    Lesser General Public License for more details.
19 
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; see the file COPYING.LIB.
22    If not, see <http://www.gnu.org/licenses/> or write to the
23    Free Software Foundation, 51 Franklin Street, Fifth Floor,
24    Boston, MA 02110-1301, USA.
25 */
26 
27 #ifndef _WIN32Geometry_h_INCLUDE
28 #define _WIN32Geometry_h_INCLUDE
29 
30 #include <Foundation/NSGeometry.h>
31 
32 #include <windows.h>
33 
34 @class WIN32Server;
35 
36 static inline NSPoint
MSWindowPointToGS(WIN32Server * svr,HWND hwnd,int x,int y)37 MSWindowPointToGS(WIN32Server *svr, HWND hwnd, int x, int y)
38 {
39   NSGraphicsContext *ctxt;
40   RECT rect;
41   float h, l, r, t, b;
42   NSPoint p1;
43   NSWindow *window;
44 
45   ctxt = GSCurrentContext();
46   window = GSWindowWithNumber((int)hwnd);
47   GetClientRect(hwnd, &rect);
48   h = rect.bottom - rect.top;
49   [svr styleoffsets: &l : &r : &t : &b : [window styleMask]];
50 
51   p1.x = x + l;
52   p1.y = h - y + b;
53   return p1;
54 }
55 
56 static inline NSRect
MSWindowRectToGS(WIN32Server * svr,HWND hwnd,RECT r0)57 MSWindowRectToGS(WIN32Server *svr, HWND hwnd, RECT r0)
58 {
59   NSGraphicsContext *ctxt;
60   RECT rect;
61   float h, l, r, t, b;
62   NSRect r1;
63   NSWindow *window;
64 
65   ctxt = GSCurrentContext();
66   window = GSWindowWithNumber((int)hwnd);
67   GetClientRect(hwnd, &rect);
68   h = rect.bottom - rect.top;
69   [svr styleoffsets: &l : &r : &t : &b : [window styleMask]];
70 
71   r1.origin.x = r0.left + l;
72   r1.origin.y = h - r0.bottom + b;
73   r1.size.width = r0.right - r0.left;
74   r1.size.height = r0.bottom - r0.top;
75   return r1;
76 }
77 
78 static inline RECT
GSWindowRectToMS(WIN32Server * svr,HWND hwnd,NSRect r0)79 GSWindowRectToMS(WIN32Server *svr, HWND hwnd, NSRect r0)
80 {
81   NSGraphicsContext *ctxt;
82   RECT rect;
83   float h, l, r, t, b;
84   RECT r1;
85   NSWindow *window;
86 
87   ctxt = GSCurrentContext();
88   window = GSWindowWithNumber((int)hwnd);
89   GetClientRect(hwnd, &rect);
90   h = rect.bottom - rect.top;
91   [svr styleoffsets: &l : &r : &t : &b : [window styleMask]];
92 
93   r1.left = r0.origin.x - l;
94   r1.bottom = h - r0.origin.y + b;
95   r1.right = r1.left + r0.size.width;
96   r1.top = r1.bottom - r0.size.height;
97   return r1;
98 }
99 
100 
101 static inline
MSWindowOriginToGS(HWND hwnd,int x,int y)102 NSPoint MSWindowOriginToGS(HWND hwnd, int x, int y)
103 {
104   NSPoint p1;
105   RECT rect;
106   int h;
107   int screen_height = GetSystemMetrics(SM_CYSCREEN);
108 
109   GetWindowRect(hwnd, &rect);
110   h = rect.bottom - rect.top;
111 
112   p1.x = x;
113   p1.y = screen_height - y - h;
114   return p1;
115 }
116 
117 static inline
GSWindowOriginToMS(HWND hwnd,NSPoint p)118 POINT GSWindowOriginToMS(HWND hwnd, NSPoint p)
119 {
120   POINT p1;
121   RECT rect;
122   int h;
123   int screen_height = GetSystemMetrics(SM_CYSCREEN);
124 
125   GetWindowRect(hwnd, &rect);
126   h = rect.bottom - rect.top;
127 
128   p1.x = p.x;
129   p1.y = screen_height - p.y - h;
130   return p1;
131 }
132 
133 static inline
MSScreenPointToGS(int x,int y)134 NSPoint MSScreenPointToGS(int x, int y)
135 {
136   NSPoint p1;
137   int screen_height = GetSystemMetrics(SM_CYSCREEN);
138 
139   p1.x = x;
140   p1.y = screen_height - y;
141   return p1;
142 }
143 
144 static inline
MSScreenRectToGS(RECT r)145 NSRect MSScreenRectToGS(RECT r)
146 {
147   NSRect r1;
148   int screen_height = GetSystemMetrics(SM_CYSCREEN);
149 
150   r1.origin.x = r.left;
151   r1.origin.y = screen_height - r.bottom;
152   r1.size.width = r.right - r.left;
153   r1.size.height = r.bottom - r.top;
154 
155   return r1;
156 }
157 
158 static inline
GSScreenPointToMS(NSPoint p)159 POINT GSScreenPointToMS(NSPoint p)
160 {
161   POINT p1;
162   int screen_height = GetSystemMetrics(SM_CYSCREEN);
163 
164   p1.x = p.x;
165   p1.y = screen_height - p.y;
166   return p1;
167 }
168 
169 static inline
GSScreenRectToMS(NSRect r)170 RECT GSScreenRectToMS(NSRect r)
171 {
172   RECT r1;
173   int screen_height = GetSystemMetrics(SM_CYSCREEN);
174 
175   r1.left = r.origin.x;
176   r1.bottom = screen_height - r.origin.y;
177   r1.right = r.origin.x + r.size.width;
178   r1.top = screen_height - r.origin.y - r.size.height;
179 
180   return r1;
181 }
182 
183 
184 #endif /* _WIN32Geometry_h_INCLUDE */
185