1 |
/******************************************************************************* |
= |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
|
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
|
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
|
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
|
7 |
* |
8 |
* Contributors: |
|
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
|
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
|
10 |
*******************************************************************************/ |
|
|
<> |
11 |
/******************************************************************************* |
|
|
|
12 |
* Additions/modifications to this source file by Oracle America, Inc. 2011 |
|
|
|
13 |
*******************************************************************************/ |
11 |
|
= |
14 |
|
12 |
#include "ugl_win32.h" |
|
15 |
#include "ugl_win32.h" |
13 |
#include "UGL_Win32_Widget.h" |
|
16 |
#include "UGL_Win32_Widget.h" |
14 |
#include "UGL_win32_display.h" |
|
17 |
#include "UGL_win32_display.h" |
15 |
#include "UGL_Win32_DC.h" |
|
18 |
#include "UGL_Win32_DC.h" |
16 |
|
|
19 |
|
17 |
#include "Widget.h" |
|
20 |
#include "Widget.h" |
18 |
#include "Control.h" |
|
21 |
#include "Control.h" |
19 |
#include "Image.h" |
|
22 |
#include "Image.h" |
20 |
#include "Label.h" |
|
23 |
#include "Label.h" |
21 |
#include "Graphics.h" |
|
24 |
#include "Graphics.h" |
22 |
|
|
25 |
|
23 |
//======================================================================================== |
|
26 |
//======================================================================================== |
24 |
static UGL_Int _Label_ExStyle(UGL_Int ugl_style); |
|
27 |
static UGL_Int _Label_ExStyle(UGL_Int ugl_style); |
25 |
static UGL_Int _Label_Style(UGL_Int ugl_style); |
|
28 |
static UGL_Int _Label_Style(UGL_Int ugl_style); |
26 |
LRESULT CALLBACK _Label_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
|
29 |
LRESULT CALLBACK _Label_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
27 |
static void _Label_GetMinimumSize(UGL_Int handle, int prefWidth, POINT *point, UGL_Error uglError); |
|
30 |
static void _Label_GetMinimumSize(UGL_Int handle, int prefWidth, POINT *point, UGL_Error uglError); |
28 |
static int _Label_ApplyAlignmentStyle(PUGL_Label label, int oldStyle); |
|
31 |
static int _Label_ApplyAlignmentStyle(PUGL_Label label, int oldStyle); |
29 |
void _Label_OwnerDraw(PUGL_Control handle, LPDRAWITEMSTRUCT draw_struct); |
|
32 |
void _Label_OwnerDraw(PUGL_Control handle, LPDRAWITEMSTRUCT draw_struct); |
30 |
void Label_DrawImage(PUGL_Control); |
|
33 |
void Label_DrawImage(PUGL_Control); |
31 |
//======================================================================================== |
|
34 |
//======================================================================================== |
32 |
|
|
35 |
|
33 |
#ifdef _WIN32_WCE |
|
36 |
#ifdef _WIN32_WCE |
34 |
/** |
|
37 |
/** |
35 |
* Filters and passes incomming messages to the real windowProc. |
|
38 |
* Filters and passes incomming messages to the real windowProc. |
36 |
*/ |
|
39 |
*/ |
37 |
LRESULT CALLBACK _Label_FilterProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
|
40 |
LRESULT CALLBACK _Label_FilterProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
38 |
#endif |
|
41 |
#endif |
39 |
|
|
42 |
|
40 |
UGL_Int Label_New(UGL_Int parentHandle, UGL_Int ugl_style, UGL_Error uglError) { |
|
43 |
UGL_Int Label_New(UGL_Int parentHandle, UGL_Int ugl_style, UGL_Error uglError) { |
41 |
int style = _Label_Style(ugl_style); |
|
44 |
int style = _Label_Style(ugl_style); |
42 |
int extended_style = _Label_ExStyle(ugl_style); |
|
45 |
int extended_style = _Label_ExStyle(ugl_style); |
43 |
|
|
46 |
|
44 |
PUGL_Control ugl_label = _Control_New(_T("STATIC"), sizeof(UGL_Label), _Label_Proc, |
|
47 |
PUGL_Control ugl_label = _Control_New(_T("STATIC"), sizeof(UGL_Label), _Label_Proc, |
45 |
parentHandle, ugl_style, style, extended_style, uglError); |
|
48 |
parentHandle, ugl_style, style, extended_style, uglError); |
46 |
|
|
49 |
|
47 |
ugl_label->inheritsBackground = TRUE; |
|
50 |
ugl_label->inheritsBackground = TRUE; |
48 |
|
|
51 |
|
49 |
#ifdef _WIN32_WCE |
|
52 |
#ifdef _WIN32_WCE |
50 |
((PUGL_Label)ugl_label)->realWidgetProc = ugl_label->widgetProc; |
|
53 |
((PUGL_Label)ugl_label)->realWidgetProc = ugl_label->widgetProc; |
51 |
ugl_label->widgetProc = _Label_FilterProc; |
|
54 |
ugl_label->widgetProc = _Label_FilterProc; |
52 |
#endif |
|
55 |
#endif |
53 |
|
|
56 |
|
54 |
return (UGL_Int)ugl_label; |
|
57 |
return (UGL_Int)ugl_label; |
55 |
} |
|
58 |
} |
56 |
|
|
59 |
|
57 |
#ifdef _WIN32_WCE |
|
60 |
#ifdef _WIN32_WCE |
58 |
/** |
|
61 |
/** |
59 |
* Filters and passes incomming messages to the real windowProc. |
|
62 |
* Filters and passes incomming messages to the real windowProc. |
60 |
*/ |
|
63 |
*/ |
61 |
LRESULT CALLBACK _Label_FilterProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
|
64 |
LRESULT CALLBACK _Label_FilterProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
62 |
// Filter certian messages from the native windowProc because the native window proc does |
|
65 |
// Filter certian messages from the native windowProc because the native window proc does |
63 |
// something that we don't want. |
|
66 |
// something that we don't want. |
64 |
switch (message) { |
|
67 |
switch (message) { |
65 |
case WM_LBUTTONUP: |
|
68 |
case WM_LBUTTONUP: |
66 |
case WM_MOUSEMOVE: { |
|
69 |
case WM_MOUSEMOVE: { |
67 |
// Filter mouse events from going to the native windowProc because |
|
70 |
// Filter mouse events from going to the native windowProc because |
68 |
// the default behavior is to pass the message along to the parent. |
|
71 |
// the default behavior is to pass the message along to the parent. |
69 |
// Passing the message to the parent results in multiple windows getting |
|
72 |
// Passing the message to the parent results in multiple windows getting |
70 |
// events for the same mouse messages. |
|
73 |
// events for the same mouse messages. |
71 |
return 0; |
|
74 |
return 0; |
72 |
} |
|
75 |
} |
73 |
|
|
76 |
|
74 |
|
|
77 |
|
75 |
} |
|
78 |
} |
76 |
|
|
79 |
|
77 |
{ |
|
80 |
{ |
78 |
UGL_Label* label = (UGL_Label*)GetWindowLong(hWnd, GWL_USERDATA); |
|
81 |
UGL_Label* label = (UGL_Label*)GetWindowLong(hWnd, GWL_USERDATA); |
79 |
return CallWindowProc(label->realWidgetProc, hWnd, message, wParam, lParam); |
|
82 |
return CallWindowProc(label->realWidgetProc, hWnd, message, wParam, lParam); |
80 |
} |
|
83 |
} |
81 |
} |
|
84 |
} |
82 |
#endif |
|
85 |
#endif |
83 |
|
|
86 |
|
84 |
|
|
87 |
|
85 |
//======================================================================================== |
|
88 |
//======================================================================================== |
86 |
LRESULT CALLBACK _Label_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
|
89 |
LRESULT CALLBACK _Label_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { |
87 |
|
|
90 |
|
88 |
// PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
|
91 |
// PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
89 |
// //FocusCallback(UGL_WIDGET(ugl_control)->callback_target, message); |
|
92 |
// //FocusCallback(UGL_WIDGET(ugl_control)->callback_target, message); |
90 |
switch (message) { |
|
93 |
switch (message) { |
91 |
case UI_GET_MINIMUM_SIZE: { |
|
94 |
case UI_GET_MINIMUM_SIZE: { |
92 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
|
95 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
93 |
UGL_Int handle = (UGL_Int)ugl_control; |
|
96 |
UGL_Int handle = (UGL_Int)ugl_control; |
94 |
POINT* point = (POINT*)wParam; |
|
97 |
POINT* point = (POINT*)wParam; |
95 |
_Label_GetMinimumSize(handle, -1, point, (UGL_Error)lParam); |
|
98 |
_Label_GetMinimumSize(handle, -1, point, (UGL_Error)lParam); |
96 |
return 0; |
|
99 |
return 0; |
97 |
} break; |
|
100 |
} break; |
|
|
<> |
101 |
|
|
|
|
102 |
case WM_LBUTTONDOWN: { |
|
|
|
103 |
// STATIC controls don't receive focus, so we need to fake it out |
|
|
|
104 |
// by attempting to retrieve focus whenever the left mouse |
|
|
|
105 |
// button is pressed |
|
|
|
106 |
int returnVal; |
|
|
|
107 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
|
|
|
108 |
|
|
|
|
109 |
returnVal = SendMessage(ugl_control->hWnd, UI_SET_FOCUS, (WPARAM)ugl_control->hWnd, (LPARAM)0); |
|
|
|
110 |
return returnVal != 0; |
|
|
|
111 |
} break; |
98 |
|
= |
112 |
|
99 |
case WM_SIZE: { |
|
113 |
case WM_SIZE: { |
100 |
LRESULT result = _Control_Proc(hWnd, message, wParam, lParam); |
|
114 |
LRESULT result = _Control_Proc(hWnd, message, wParam, lParam); |
101 |
BOOL needsRepaint = FALSE; |
|
115 |
BOOL needsRepaint = FALSE; |
102 |
|
|
116 |
|
103 |
// Windows does not always repaint the control correctly on resize. |
|
117 |
// Windows does not always repaint the control correctly on resize. |
104 |
// When an alignment other than SS_LEFTNOWORDWRAP is used it does not update |
|
118 |
// When an alignment other than SS_LEFTNOWORDWRAP is used it does not update |
105 |
// correctly |
|
119 |
// correctly |
106 |
LONG style = GetWindowLong(hWnd, GWL_STYLE); |
|
120 |
LONG style = GetWindowLong(hWnd, GWL_STYLE); |
107 |
if ((style | (SS_LEFT | SS_CENTER | SS_RIGHT)) != 0) { |
|
121 |
if ((style | (SS_LEFT | SS_CENTER | SS_RIGHT)) != 0) { |
108 |
needsRepaint = TRUE; |
|
122 |
needsRepaint = TRUE; |
109 |
} |
|
123 |
} |
110 |
|
|
124 |
|
111 |
if (needsRepaint) { |
|
125 |
if (needsRepaint) { |
112 |
InvalidateRect(hWnd, NULL, TRUE); |
|
126 |
InvalidateRect(hWnd, NULL, TRUE); |
113 |
} |
|
127 |
} |
114 |
return result; |
|
128 |
return result; |
115 |
} |
|
129 |
} |
116 |
|
|
130 |
|
117 |
case WM_SETFONT: { |
|
131 |
case WM_SETFONT: { |
118 |
// Windows will drop/forget about the font |
|
132 |
// Windows will drop/forget about the font |
119 |
// when an image is displayed, so caching the |
|
133 |
// when an image is displayed, so caching the |
120 |
// current font will allow us to restore it when |
|
134 |
// current font will allow us to restore it when |
121 |
// the image is removed |
|
135 |
// the image is removed |
122 |
PUGL_Label label = (PUGL_Label)GetWindowLong(hWnd, GWL_USERDATA); |
|
136 |
PUGL_Label label = (PUGL_Label)GetWindowLong(hWnd, GWL_USERDATA); |
123 |
label->font = (HFONT)wParam; |
|
137 |
label->font = (HFONT)wParam; |
124 |
break; |
|
138 |
break; |
125 |
} |
|
139 |
} |
126 |
|
|
140 |
|
127 |
case UI_DRAWITEM: { |
|
141 |
case UI_DRAWITEM: { |
128 |
|
|
142 |
|
129 |
|
|
143 |
|
130 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
|
144 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
131 |
LPDRAWITEMSTRUCT drawItemStruct = (LPDRAWITEMSTRUCT)lParam; |
|
145 |
LPDRAWITEMSTRUCT drawItemStruct = (LPDRAWITEMSTRUCT)lParam; |
132 |
_Label_OwnerDraw(ugl_control, drawItemStruct); |
|
146 |
_Label_OwnerDraw(ugl_control, drawItemStruct); |
133 |
return TRUE; |
|
147 |
return TRUE; |
134 |
|
|
148 |
|
135 |
|
|
149 |
|
136 |
} |
|
150 |
} |
137 |
|
|
151 |
|
138 |
#ifdef _WIN32_WCE |
|
152 |
#ifdef _WIN32_WCE |
139 |
|
|
153 |
|
140 |
|
|
154 |
|
141 |
// fix for Label.setAlignment, paint to image ourselves to adjust the position depending on the image size |
|
155 |
// fix for Label.setAlignment, paint to image ourselves to adjust the position depending on the image size |
142 |
case WM_PAINT: { |
|
156 |
case WM_PAINT: { |
143 |
|
|
157 |
|
144 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
|
158 |
PUGL_Control ugl_control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
145 |
LONG bits = GetWindowLong(hWnd, GWL_STYLE); |
|
159 |
LONG bits = GetWindowLong(hWnd, GWL_STYLE); |
146 |
_Control_Proc(hWnd, message, wParam, lParam); |
|
160 |
_Control_Proc(hWnd, message, wParam, lParam); |
147 |
if ((bits & SS_BITMAP) == SS_BITMAP) { |
|
161 |
if ((bits & SS_BITMAP) == SS_BITMAP) { |
148 |
Label_DrawImage(ugl_control); |
|
162 |
Label_DrawImage(ugl_control); |
149 |
} |
|
163 |
} |
150 |
|
|
164 |
|
151 |
return TRUE; |
|
165 |
return TRUE; |
152 |
} |
|
166 |
} |
153 |
|
|
167 |
|
154 |
case WM_ERASEBKGND: { |
|
168 |
case WM_ERASEBKGND: { |
155 |
LONG bits = GetWindowLong(hWnd, GWL_STYLE); |
|
169 |
LONG bits = GetWindowLong(hWnd, GWL_STYLE); |
156 |
|
|
170 |
|
157 |
if ((bits & SS_BITMAP) == SS_BITMAP) { |
|
171 |
if ((bits & SS_BITMAP) == SS_BITMAP) { |
158 |
/** |
|
172 |
/** |
159 |
* On PocketPC, the background of a label with the SS_BITMAP |
|
173 |
* On PocketPC, the background of a label with the SS_BITMAP |
160 |
* style flag set will not be cleared automaticly by the OS. |
|
174 |
* style flag set will not be cleared automaticly by the OS. |
161 |
*/ |
|
175 |
*/ |
162 |
HDC hdc = (HDC)wParam; |
|
176 |
HDC hdc = (HDC)wParam; |
163 |
|
|
177 |
|
164 |
HBRUSH newBrush; |
|
178 |
HBRUSH newBrush; |
165 |
HGDIOBJ oldBrush; |
|
179 |
HGDIOBJ oldBrush; |
166 |
RECT rect; |
|
180 |
RECT rect; |
167 |
|
|
181 |
|
168 |
int rop2 = 0; |
|
182 |
int rop2 = 0; |
169 |
int dwRop; |
|
183 |
int dwRop; |
170 |
|
|
184 |
|
171 |
PUGL_Control control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
|
185 |
PUGL_Control control = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA); |
172 |
PUGL_Label label_control = (PUGL_Label)control; |
|
186 |
PUGL_Label label_control = (PUGL_Label)control; |
173 |
|
|
187 |
|
174 |
if (control->background_color != NULL) { |
|
188 |
if (control->background_color != NULL) { |
175 |
newBrush = Color_GetBrush(control->background_color); |
|
189 |
newBrush = Color_GetBrush(control->background_color); |
176 |
} else{ |
|
190 |
} else{ |
177 |
newBrush = GetSysColorBrush(COLOR_STATIC); |
|
191 |
newBrush = GetSysColorBrush(COLOR_STATIC); |
178 |
} |
|
192 |
} |
179 |
oldBrush = SelectObject(hdc, newBrush); |
|
193 |
oldBrush = SelectObject(hdc, newBrush); |
180 |
rop2 = SetROP2(hdc, R2_COPYPEN); |
|
194 |
rop2 = SetROP2(hdc, R2_COPYPEN); |
181 |
SetROP2(hdc, rop2); |
|
195 |
SetROP2(hdc, rop2); |
182 |
dwRop = rop2 == R2_XORPEN ? PATINVERT : PATCOPY; |
|
196 |
dwRop = rop2 == R2_XORPEN ? PATINVERT : PATCOPY; |
183 |
|
|
197 |
|
184 |
GetClipBox(hdc, &rect); |
|
198 |
GetClipBox(hdc, &rect); |
185 |
PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop); |
|
199 |
PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop); |
186 |
SelectObject(hdc, oldBrush); |
|
200 |
SelectObject(hdc, oldBrush); |
187 |
|
|
201 |
|
188 |
return 1; |
|
202 |
return 1; |
189 |
} |
|
203 |
} |
190 |
break; |
|
204 |
break; |
191 |
} |
|
205 |
} |
192 |
#endif |
|
206 |
#endif |
193 |
|
|
207 |
|
194 |
} |
|
208 |
} |
195 |
|
|
209 |
|
196 |
|
|
210 |
|
197 |
|
|
211 |
|
198 |
return _Control_Proc(hWnd, message, wParam, lParam); |
|
212 |
return _Control_Proc(hWnd, message, wParam, lParam); |
199 |
} |
|
213 |
} |
200 |
//======================================================================================= |
|
214 |
//======================================================================================= |
201 |
|
|
215 |
|
202 |
void Label_SetImage(UGL_Int handle, UGL_Int imageHandle, UGL_Error uglError) { |
|
216 |
void Label_SetImage(UGL_Int handle, UGL_Int imageHandle, UGL_Error uglError) { |
203 |
|
|
217 |
|
204 |
PUGL_Control ugl_control = (PUGL_Control)handle; |
|
218 |
PUGL_Control ugl_control = (PUGL_Control)handle; |
205 |
PUGL_Image ugl_image = UGL_IMAGE(imageHandle); |
|
219 |
PUGL_Image ugl_image = UGL_IMAGE(imageHandle); |
206 |
PUGL_Label ugl_label = (PUGL_Label)ugl_control; |
|
220 |
PUGL_Label ugl_label = (PUGL_Label)ugl_control; |
207 |
int newBits; |
|
221 |
int newBits; |
208 |
int oldBits; |
|
222 |
int oldBits; |
209 |
int flags = SWP_NOZORDER | SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOMOVE; |
|
223 |
int flags = SWP_NOZORDER | SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOMOVE; |
210 |
RECT rect; |
|
224 |
RECT rect; |
211 |
HWND hWnd = ugl_control->hWnd; |
|
225 |
HWND hWnd = ugl_control->hWnd; |
212 |
|
|
226 |
|
213 |
GetWindowRect(hWnd, &rect); |
|
227 |
GetWindowRect(hWnd, &rect); |
214 |
|
|
228 |
|
215 |
newBits = GetWindowLong (hWnd, GWL_STYLE); |
|
229 |
newBits = GetWindowLong (hWnd, GWL_STYLE); |
216 |
oldBits = newBits; |
|
230 |
oldBits = newBits; |
217 |
newBits &= ~(SS_BITMAP | SS_ICON ); |
|
231 |
newBits &= ~(SS_BITMAP | SS_ICON ); |
218 |
if (ugl_image != NULL) { |
|
232 |
if (ugl_image != NULL) { |
219 |
#ifdef _WIN32_WCE |
|
233 |
#ifdef _WIN32_WCE |
220 |
newBits |= SS_BITMAP ; |
|
234 |
newBits |= SS_BITMAP ; |
221 |
#else |
|
235 |
#else |
222 |
newBits |= SS_OWNERDRAW; |
|
236 |
newBits |= SS_OWNERDRAW; |
223 |
#endif |
|
237 |
#endif |
224 |
} else { |
|
238 |
} else { |
225 |
// Because SS_BITMAP conflicts with the native |
|
239 |
// Because SS_BITMAP conflicts with the native |
226 |
// alignment styles when the image is set to NULL |
|
240 |
// alignment styles when the image is set to NULL |
227 |
// the alignment styles need to be restored |
|
241 |
// the alignment styles need to be restored |
228 |
newBits = _Label_ApplyAlignmentStyle(ugl_label, newBits); |
|
242 |
newBits = _Label_ApplyAlignmentStyle(ugl_label, newBits); |
229 |
} |
|
243 |
} |
230 |
|
|
244 |
|
231 |
if (newBits != oldBits) { |
|
245 |
if (newBits != oldBits) { |
232 |
SetWindowLong(hWnd, GWL_STYLE, newBits); |
|
246 |
SetWindowLong(hWnd, GWL_STYLE, newBits); |
233 |
} |
|
247 |
} |
234 |
|
|
248 |
|
235 |
/* |
|
249 |
/* |
236 |
* Feature in Windows. When STM_SETIMAGE is used to set the |
|
250 |
* Feature in Windows. When STM_SETIMAGE is used to set the |
237 |
* image for a static control, Windows either streches the image |
|
251 |
* image for a static control, Windows either streches the image |
238 |
* to fit the control or shrinks the control to fit the image. |
|
252 |
* to fit the control or shrinks the control to fit the image. |
239 |
* While not stricly wrong, neither of these is desirable. |
|
253 |
* While not stricly wrong, neither of these is desirable. |
240 |
* The fix is to stop Windows from stretching the image by |
|
254 |
* The fix is to stop Windows from stretching the image by |
241 |
* using SS_REALSIZEIMAGE and SS_CENTERIMAGE, allow Windows |
|
255 |
* using SS_REALSIZEIMAGE and SS_CENTERIMAGE, allow Windows |
242 |
* to shrink the control, and then restore the control to the |
|
256 |
* to shrink the control, and then restore the control to the |
243 |
* original size. |
|
257 |
* original size. |
244 |
*/ |
|
258 |
*/ |
245 |
|
|
259 |
|
246 |
|
|
260 |
|
247 |
if (imageHandle == 0) { |
|
261 |
if (imageHandle == 0) { |
248 |
// When an image is displayed in a label, the current font |
|
262 |
// When an image is displayed in a label, the current font |
249 |
// will be dropped. The fix is to save the font and to restore |
|
263 |
// will be dropped. The fix is to save the font and to restore |
250 |
// it when the image is removed. |
|
264 |
// it when the image is removed. |
251 |
SendMessage(hWnd, WM_SETFONT, (WPARAM)ugl_label->font, FALSE); |
|
265 |
SendMessage(hWnd, WM_SETFONT, (WPARAM)ugl_label->font, FALSE); |
252 |
} |
|
266 |
} |
253 |
|
|
267 |
|
254 |
ugl_label->ugl_image = ugl_image; |
|
268 |
ugl_label->ugl_image = ugl_image; |
255 |
|
|
269 |
|
256 |
// Always repaint the control to either display the new image, or |
|
270 |
// Always repaint the control to either display the new image, or |
257 |
// to restore the text |
|
271 |
// to restore the text |
258 |
InvalidateRect(hWnd, NULL, TRUE); |
|
272 |
InvalidateRect(hWnd, NULL, TRUE); |
259 |
|
|
273 |
|
260 |
} |
|
274 |
} |
261 |
//======================================================================================== |
|
275 |
//======================================================================================== |
262 |
|
|
276 |
|
263 |
void Label_SetText(UGL_Int handle, UGL_String string, UGL_Error uglError) { |
|
277 |
void Label_SetText(UGL_Int handle, UGL_String string, UGL_Error uglError) { |
264 |
|
|
278 |
|
265 |
PUGL_Control label = (PUGL_Control)handle; |
|
279 |
PUGL_Control label = (PUGL_Control)handle; |
266 |
|
|
280 |
|
267 |
/** |
|
281 |
/** |
268 |
* If the style of the Label contains the SS_BITMAP flag |
|
282 |
* If the style of the Label contains the SS_BITMAP flag |
269 |
* then the SetWindowText call will silently be ignored. |
|
283 |
* then the SetWindowText call will silently be ignored. |
270 |
* To avoid the problem, unsetting SS_BITMAP and restoring |
|
284 |
* To avoid the problem, unsetting SS_BITMAP and restoring |
271 |
* it afterwards does the trick. |
|
285 |
* it afterwards does the trick. |
272 |
*/ |
|
286 |
*/ |
273 |
LONG style = GetWindowLong(label->hWnd, GWL_STYLE); |
|
287 |
LONG style = GetWindowLong(label->hWnd, GWL_STYLE); |
274 |
|
|
288 |
|
275 |
if ((style & SS_BITMAP) == SS_BITMAP) { |
|
289 |
if ((style & SS_BITMAP) == SS_BITMAP) { |
276 |
SetWindowLong(label->hWnd, GWL_STYLE, style & ~SS_BITMAP); |
|
290 |
SetWindowLong(label->hWnd, GWL_STYLE, style & ~SS_BITMAP); |
277 |
} |
|
291 |
} |
278 |
SetWindowText(label->hWnd, string); |
|
292 |
SetWindowText(label->hWnd, string); |
279 |
|
|
293 |
|
280 |
if ((style & SS_BITMAP) == SS_BITMAP) { |
|
294 |
if ((style & SS_BITMAP) == SS_BITMAP) { |
281 |
SetWindowLong(label->hWnd, GWL_STYLE, style); |
|
295 |
SetWindowLong(label->hWnd, GWL_STYLE, style); |
282 |
} |
|
296 |
} |
283 |
} |
|
297 |
} |
284 |
//======================================================================================== |
|
298 |
//======================================================================================== |
285 |
|
|
299 |
|
286 |
/** |
|
300 |
/** |
287 |
* Returns the new native style with the native alignment updated |
|
301 |
* Returns the new native style with the native alignment updated |
288 |
*/ |
|
302 |
*/ |
289 |
int _Label_ApplyAlignmentStyle(PUGL_Label label, int oldStyle) { |
|
303 |
int _Label_ApplyAlignmentStyle(PUGL_Label label, int oldStyle) { |
290 |
|
|
304 |
|
291 |
int nativeAlignment; |
|
305 |
int nativeAlignment; |
292 |
int alignment = label->alignment; |
|
306 |
int alignment = label->alignment; |
293 |
|
|
307 |
|
294 |
if (IS_FLAG_SET(alignment, UGL_STYLE_LEAD)) { |
|
308 |
if (IS_FLAG_SET(alignment, UGL_STYLE_LEAD)) { |
295 |
if (IS_FLAG_SET(label->control.widget.ugl_style, UGL_STYLE_WRAP)) { |
|
309 |
if (IS_FLAG_SET(label->control.widget.ugl_style, UGL_STYLE_WRAP)) { |
296 |
nativeAlignment = SS_LEFT; |
|
310 |
nativeAlignment = SS_LEFT; |
297 |
} else { |
|
311 |
} else { |
298 |
nativeAlignment = SS_LEFTNOWORDWRAP; |
|
312 |
nativeAlignment = SS_LEFTNOWORDWRAP; |
299 |
} |
|
313 |
} |
300 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_TRAIL)) { |
|
314 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_TRAIL)) { |
301 |
nativeAlignment = SS_RIGHT; |
|
315 |
nativeAlignment = SS_RIGHT; |
302 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_CENTER)) { |
|
316 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_CENTER)) { |
303 |
nativeAlignment = SS_CENTER; |
|
317 |
nativeAlignment = SS_CENTER; |
304 |
} |
|
318 |
} |
305 |
|
|
319 |
|
306 |
if (IS_FLAG_SET(label->control.widget.ugl_style, UGL_STYLE_MIDDLE)) nativeAlignment |= SS_CENTERIMAGE; |
|
320 |
if (IS_FLAG_SET(label->control.widget.ugl_style, UGL_STYLE_MIDDLE)) nativeAlignment |= SS_CENTERIMAGE; |
307 |
|
|
321 |
|
308 |
oldStyle &= ~(SS_LEFT | SS_LEFTNOWORDWRAP | SS_CENTER | SS_RIGHT | SS_CENTERIMAGE); |
|
322 |
oldStyle &= ~(SS_LEFT | SS_LEFTNOWORDWRAP | SS_CENTER | SS_RIGHT | SS_CENTERIMAGE); |
309 |
return oldStyle | nativeAlignment; |
|
323 |
return oldStyle | nativeAlignment; |
310 |
} |
|
324 |
} |
311 |
|
|
325 |
|
312 |
//======================================================================================== |
|
326 |
//======================================================================================== |
313 |
|
|
327 |
|
314 |
void Label_SetAlignment(UGL_Int handle, UGL_Int alignment, UGL_Error uglError) { |
|
328 |
void Label_SetAlignment(UGL_Int handle, UGL_Int alignment, UGL_Error uglError) { |
315 |
|
|
329 |
|
316 |
PUGL_Label ugl_label = (PUGL_Label)handle; |
|
330 |
PUGL_Label ugl_label = (PUGL_Label)handle; |
317 |
|
|
331 |
|
318 |
int bits = GetWindowLong(ugl_label->control.hWnd, GWL_STYLE); |
|
332 |
int bits = GetWindowLong(ugl_label->control.hWnd, GWL_STYLE); |
319 |
int style = bits; |
|
333 |
int style = bits; |
320 |
|
|
334 |
|
321 |
ugl_label->alignment = alignment; |
|
335 |
ugl_label->alignment = alignment; |
322 |
|
|
336 |
|
323 |
/* |
|
337 |
/* |
324 |
* Feature in Windows. The windows label does not align |
|
338 |
* Feature in Windows. The windows label does not align |
325 |
* the bitmap or icon. Any attempt to set alignment bits |
|
339 |
* the bitmap or icon. Any attempt to set alignment bits |
326 |
* such as SS_CENTER cause the label to display text. The |
|
340 |
* such as SS_CENTER cause the label to display text. The |
327 |
* fix is to disallow alignment. |
|
341 |
* fix is to disallow alignment. |
328 |
* |
|
342 |
* |
329 |
* NOTE: SS_BITMAP and SS_ICON are not single bit |
|
343 |
* NOTE: SS_BITMAP and SS_ICON are not single bit |
330 |
* masks so it is necessary to test for all of the |
|
344 |
* masks so it is necessary to test for all of the |
331 |
* bits in these masks. |
|
345 |
* bits in these masks. |
332 |
*/ |
|
346 |
*/ |
333 |
if (IS_FLAG_SET(bits, SS_BITMAP)) return; |
|
347 |
if (IS_FLAG_SET(bits, SS_BITMAP)) return; |
334 |
if (IS_FLAG_SET(bits, SS_ICON)) return; |
|
348 |
if (IS_FLAG_SET(bits, SS_ICON)) return; |
335 |
style &= ~(SS_LEFT | SS_LEFTNOWORDWRAP | SS_CENTER | SS_RIGHT); |
|
349 |
style &= ~(SS_LEFT | SS_LEFTNOWORDWRAP | SS_CENTER | SS_RIGHT); |
336 |
style = _Label_ApplyAlignmentStyle(ugl_label, style); |
|
350 |
style = _Label_ApplyAlignmentStyle(ugl_label, style); |
337 |
|
|
351 |
|
338 |
if (style != bits) { |
|
352 |
if (style != bits) { |
339 |
SetWindowLong(ugl_label->control.hWnd, GWL_STYLE, style); |
|
353 |
SetWindowLong(ugl_label->control.hWnd, GWL_STYLE, style); |
340 |
_Control_Redraw(&(ugl_label->control)); |
|
354 |
_Control_Redraw(&(ugl_label->control)); |
341 |
} |
|
355 |
} |
342 |
} |
|
356 |
} |
343 |
|
|
357 |
|
344 |
/** |
|
358 |
/** |
345 |
* Computes the minimum size of the label based on the width passed in. This |
|
359 |
* Computes the minimum size of the label based on the width passed in. This |
346 |
* method is used for labels instead of Control_GetMinimumSize because the |
|
360 |
* method is used for labels instead of Control_GetMinimumSize because the |
347 |
* WRAP flag makes the width important when calculating the height. |
|
361 |
* WRAP flag makes the width important when calculating the height. |
348 |
* |
|
362 |
* |
349 |
* @param handle the label |
|
363 |
* @param handle the label |
350 |
* @param width the desired width, this value will be -1 if no |
|
364 |
* @param width the desired width, this value will be -1 if no |
351 |
* desired width is provided. |
|
365 |
* desired width is provided. |
352 |
*/ |
|
366 |
*/ |
353 |
void Label_GetMinimumSize(UGL_Int handle, UGL_Int width, UGL_Int* returnX, UGL_Int* returnY, UGL_Error uglError) { |
|
367 |
void Label_GetMinimumSize(UGL_Int handle, UGL_Int width, UGL_Int* returnX, UGL_Int* returnY, UGL_Error uglError) { |
354 |
|
|
368 |
|
355 |
POINT p; |
|
369 |
POINT p; |
356 |
|
|
370 |
|
357 |
_Label_GetMinimumSize(handle, width, &p, uglError); |
|
371 |
_Label_GetMinimumSize(handle, width, &p, uglError); |
358 |
*returnX = p.x; |
|
372 |
*returnX = p.x; |
359 |
*returnY = p.y; |
|
373 |
*returnY = p.y; |
360 |
} |
|
374 |
} |
361 |
|
|
375 |
|
362 |
|
|
376 |
|
363 |
//======================================================================================== |
|
377 |
//======================================================================================== |
364 |
|
|
378 |
|
365 |
void _Label_GetMinimumSize(UGL_Int handle, int prefWidth, POINT *point, UGL_Error error) { |
|
379 |
void _Label_GetMinimumSize(UGL_Int handle, int prefWidth, POINT *point, UGL_Error error) { |
366 |
|
|
380 |
|
367 |
PUGL_Control control = UGL_CONTROL(handle); |
|
381 |
PUGL_Control control = UGL_CONTROL(handle); |
368 |
PUGL_Label ugl_label = (PUGL_Label)control; |
|
382 |
PUGL_Label ugl_label = (PUGL_Label)control; |
369 |
HWND hWnd = control->hWnd; |
|
383 |
HWND hWnd = control->hWnd; |
370 |
|
|
384 |
|
371 |
/* |
|
385 |
/* |
372 |
* NOTE: SS_BITMAP and SS_ICON are not single bit |
|
386 |
* NOTE: SS_BITMAP and SS_ICON are not single bit |
373 |
* masks so it is necessary to test for all of the |
|
387 |
* masks so it is necessary to test for all of the |
374 |
* bits in these masks. |
|
388 |
* bits in these masks. |
375 |
*/ |
|
389 |
*/ |
376 |
int bits = GetWindowLong(hWnd, GWL_STYLE); |
|
390 |
int bits = GetWindowLong(hWnd, GWL_STYLE); |
377 |
BOOL isBitmap = FALSE; |
|
391 |
BOOL isBitmap = FALSE; |
378 |
BOOL isIcon = FALSE; |
|
392 |
BOOL isIcon = FALSE; |
379 |
|
|
393 |
|
380 |
|
|
394 |
|
381 |
int width = 0, height = 0, widthBuffer = 0; |
|
395 |
int width = 0, height = 0, widthBuffer = 0; |
382 |
|
|
396 |
|
383 |
int border = _Control_GetBorderWidth(hWnd); |
|
397 |
int border = _Control_GetBorderWidth(hWnd); |
384 |
|
|
398 |
|
385 |
#ifndef _WIN32_WCE |
|
399 |
#ifndef _WIN32_WCE |
386 |
isIcon = (bits & SS_OWNERDRAW) == SS_OWNERDRAW;//(bits & SS_ICON) == SS_ICON; |
|
400 |
isIcon = (bits & SS_OWNERDRAW) == SS_OWNERDRAW;//(bits & SS_ICON) == SS_ICON; |
387 |
#endif |
|
401 |
#endif |
388 |
isBitmap = (bits & SS_BITMAP) == SS_BITMAP; |
|
402 |
isBitmap = (bits & SS_BITMAP) == SS_BITMAP; |
389 |
if (isBitmap || isIcon) { |
|
403 |
if (isBitmap || isIcon) { |
390 |
if (ugl_label->ugl_image != NULL) { |
|
404 |
if (ugl_label->ugl_image != NULL) { |
391 |
int image_x, image_y, image_width, image_height; |
|
405 |
int image_x, image_y, image_width, image_height; |
392 |
|
|
406 |
|
393 |
Image_GetBounds((UGL_Int)ugl_label->ugl_image, &image_x, &image_y, &image_width, &image_height, error); |
|
407 |
Image_GetBounds((UGL_Int)ugl_label->ugl_image, &image_x, &image_y, &image_width, &image_height, error); |
394 |
width = image_width; |
|
408 |
width = image_width; |
395 |
height = image_height; |
|
409 |
height = image_height; |
396 |
} |
|
410 |
} |
397 |
} else { |
|
411 |
} else { |
398 |
HDC hDC = GetDC(hWnd); |
|
412 |
HDC hDC = GetDC(hWnd); |
399 |
HGDIOBJ newFont = (HGDIOBJ)SendMessage(hWnd, WM_GETFONT, 0, 0); |
|
413 |
HGDIOBJ newFont = (HGDIOBJ)SendMessage(hWnd, WM_GETFONT, 0, 0); |
400 |
HGDIOBJ oldFont = SelectObject(hDC, newFont); |
|
414 |
HGDIOBJ oldFont = SelectObject(hDC, newFont); |
401 |
RECT rect; |
|
415 |
RECT rect; |
402 |
int length; |
|
416 |
int length; |
403 |
|
|
417 |
|
404 |
length = GetWindowTextLength(hWnd); |
|
418 |
length = GetWindowTextLength(hWnd); |
405 |
if (length > 0) { |
|
419 |
if (length > 0) { |
406 |
LPTSTR window_text; |
|
420 |
LPTSTR window_text; |
407 |
|
|
421 |
|
408 |
int flags = DT_CALCRECT | DT_EXPANDTABS; |
|
422 |
int flags = DT_CALCRECT | DT_EXPANDTABS; |
409 |
|
|
423 |
|
410 |
#ifndef _WIN32_WCE |
|
424 |
#ifndef _WIN32_WCE |
411 |
flags |= DT_EDITCONTROL; |
|
425 |
flags |= DT_EDITCONTROL; |
412 |
#endif |
|
426 |
#endif |
413 |
|
|
427 |
|
414 |
SetRect(&rect, 0, 0, 1, 0); |
|
428 |
SetRect(&rect, 0, 0, 1, 0); |
415 |
|
|
429 |
|
416 |
if ((prefWidth != -1) && (!(IS_FLAG_SET(bits, SS_LEFTNOWORDWRAP)))) { |
|
430 |
if ((prefWidth != -1) && (!(IS_FLAG_SET(bits, SS_LEFTNOWORDWRAP)))) { |
417 |
rect.right = prefWidth; |
|
431 |
rect.right = prefWidth; |
418 |
flags |= DT_WORDBREAK; |
|
432 |
flags |= DT_WORDBREAK; |
419 |
} |
|
433 |
} |
420 |
|
|
434 |
|
421 |
window_text = (LPTSTR)calloc(sizeof(TCHAR), length + 2); |
|
435 |
window_text = (LPTSTR)calloc(sizeof(TCHAR), length + 2); |
422 |
GetWindowText(hWnd, window_text, length + 1); |
|
436 |
GetWindowText(hWnd, window_text, length + 1); |
423 |
DrawText(hDC, window_text, length, &rect, flags); |
|
437 |
DrawText(hDC, window_text, length, &rect, flags); |
424 |
free(window_text); |
|
438 |
free(window_text); |
425 |
|
|
439 |
|
426 |
width = rect.right - rect.left; |
|
440 |
width = rect.right - rect.left; |
427 |
height = rect.bottom - rect.top; |
|
441 |
height = rect.bottom - rect.top; |
428 |
} else { |
|
442 |
} else { |
429 |
TEXTMETRIC tm; |
|
443 |
TEXTMETRIC tm; |
430 |
GetTextMetrics(hDC, &tm); |
|
444 |
GetTextMetrics(hDC, &tm); |
431 |
height = tm.tmHeight; |
|
445 |
height = tm.tmHeight; |
432 |
} |
|
446 |
} |
433 |
if (newFont != 0) SelectObject(hDC, oldFont); |
|
447 |
if (newFont != 0) SelectObject(hDC, oldFont); |
434 |
ReleaseDC(hWnd, hDC); |
|
448 |
ReleaseDC(hWnd, hDC); |
435 |
} |
|
449 |
} |
436 |
width += border * 2; height += border * 2; |
|
450 |
width += border * 2; height += border * 2; |
437 |
width += widthBuffer; |
|
451 |
width += widthBuffer; |
438 |
|
|
452 |
|
439 |
#ifdef _WIN32_WCE |
|
453 |
#ifdef _WIN32_WCE |
440 |
/* |
|
454 |
/* |
441 |
* Feature in WinCE PPC. Text labels have a trim |
|
455 |
* Feature in WinCE PPC. Text labels have a trim |
442 |
* of one pixel wide on the right and left side. |
|
456 |
* of one pixel wide on the right and left side. |
443 |
* The fix is to increase the size. |
|
457 |
* The fix is to increase the size. |
444 |
*/ |
|
458 |
*/ |
445 |
if (!isBitmap && !isIcon) width += 2; |
|
459 |
if (!isBitmap && !isIcon) width += 2; |
446 |
#endif |
|
460 |
#endif |
447 |
|
|
461 |
|
448 |
point->x = width; |
|
462 |
point->x = width; |
449 |
point->y = height; |
|
463 |
point->y = height; |
450 |
} |
|
464 |
} |
451 |
//======================================================================================== |
|
465 |
//======================================================================================== |
452 |
|
|
466 |
|
453 |
UGL_Int _Label_Style(UGL_Int ugl_style) { |
|
467 |
UGL_Int _Label_Style(UGL_Int ugl_style) { |
454 |
|
|
468 |
|
455 |
int bits = _Control_Style(ugl_style) & (~WS_TABSTOP); |
<> |
469 |
//int bits = _Control_Style(ugl_style) & (~WS_TABSTOP); |
456 |
bits |= SS_NOTIFY; |
|
470 |
//bits |= SS_NOTIFY; |
|
|
|
471 |
int bits = _Control_Style(ugl_style); |
|
|
|
472 |
bits |= SS_NOTIFY | WS_TABSTOP; |
457 |
|
|
473 |
|
458 |
|
= |
474 |
|
459 |
if (IS_FLAG_SET(ugl_style, UGL_STYLE_WRAP)) bits |= SS_LEFT; |
|
475 |
if (IS_FLAG_SET(ugl_style, UGL_STYLE_WRAP)) bits |= SS_LEFT; |
460 |
else bits |= SS_LEFTNOWORDWRAP; |
|
476 |
else bits |= SS_LEFTNOWORDWRAP; |
461 |
|
|
477 |
|
462 |
if (IS_FLAG_SET(ugl_style, UGL_STYLE_MIDDLE)) bits |= SS_CENTERIMAGE; |
|
478 |
if (IS_FLAG_SET(ugl_style, UGL_STYLE_MIDDLE)) bits |= SS_CENTERIMAGE; |
463 |
return bits; |
|
479 |
return bits; |
464 |
} |
|
480 |
} |
465 |
//======================================================================================== |
|
481 |
//======================================================================================== |
466 |
|
|
482 |
|
467 |
UGL_Int _Label_ExStyle(UGL_Int ugl_style) { |
|
483 |
UGL_Int _Label_ExStyle(UGL_Int ugl_style) { |
468 |
|
|
484 |
|
469 |
int bits = 0; |
|
485 |
int bits = 0; |
470 |
|
|
486 |
|
471 |
#ifndef _WIN32_WCE |
|
487 |
#ifndef _WIN32_WCE |
472 |
bits |= WS_EX_NOINHERITLAYOUT; |
|
488 |
bits |= WS_EX_NOINHERITLAYOUT; |
473 |
#endif |
|
489 |
#endif |
474 |
|
|
490 |
|
475 |
bits &= ~WS_EX_CLIENTEDGE; |
|
491 |
bits &= ~WS_EX_CLIENTEDGE; |
476 |
|
|
492 |
|
477 |
if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) bits |= WS_EX_STATICEDGE; |
|
493 |
if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) bits |= WS_EX_STATICEDGE; |
478 |
|
|
494 |
|
479 |
return bits; |
|
495 |
return bits; |
480 |
} |
|
496 |
} |
481 |
//======================================================================================== |
|
497 |
//======================================================================================== |
482 |
|
|
498 |
|
483 |
// fix for Label.setAlignment, paint to image ourselves to adjust the position depending on the image size |
|
499 |
// fix for Label.setAlignment, paint to image ourselves to adjust the position depending on the image size |
484 |
void Label_DrawImage(PUGL_Control handle) { |
|
500 |
void Label_DrawImage(PUGL_Control handle) { |
485 |
|
|
501 |
|
486 |
#ifdef _WIN32_WCE |
|
502 |
#ifdef _WIN32_WCE |
487 |
|
|
503 |
|
488 |
PUGL_Control ugl_control = (PUGL_Control)handle; |
|
504 |
PUGL_Control ugl_control = (PUGL_Control)handle; |
489 |
PUGL_Label ugl_label = (PUGL_Label)ugl_control; |
|
505 |
PUGL_Label ugl_label = (PUGL_Label)ugl_control; |
490 |
PUGL_Image ugl_image = ugl_label->ugl_image; |
|
506 |
PUGL_Image ugl_image = ugl_label->ugl_image; |
491 |
HWND hWnd = ugl_control->hWnd; |
|
507 |
HWND hWnd = ugl_control->hWnd; |
492 |
HDC hdc = GetDC(hWnd); |
|
508 |
HDC hdc = GetDC(hWnd); |
493 |
HBRUSH newBrush; |
|
509 |
HBRUSH newBrush; |
494 |
BITMAP bitmap; |
|
510 |
BITMAP bitmap; |
495 |
int alignment; |
|
511 |
int alignment; |
496 |
HBRUSH backgroundBrush; |
|
512 |
HBRUSH backgroundBrush; |
497 |
|
|
513 |
|
498 |
|
|
514 |
|
499 |
|
|
515 |
|
500 |
|
|
516 |
|
501 |
if(ugl_image != NULL){ |
|
517 |
if(ugl_image != NULL){ |
502 |
HGDIOBJ oldBrush; |
|
518 |
HGDIOBJ oldBrush; |
503 |
RECT rect; |
|
519 |
RECT rect; |
504 |
PUGL_DC ugl_dc; |
|
520 |
PUGL_DC ugl_dc; |
505 |
int rop2 = 0; |
|
521 |
int rop2 = 0; |
506 |
int dwRop; |
|
522 |
int dwRop; |
507 |
newBrush = CreatePatternBrush(ugl_label->ugl_image->image_handle); |
|
523 |
newBrush = CreatePatternBrush(ugl_label->ugl_image->image_handle); |
508 |
oldBrush = SelectObject(hdc, newBrush); |
|
524 |
oldBrush = SelectObject(hdc, newBrush); |
509 |
rop2 = SetROP2(hdc, SRCCOPY); |
|
525 |
rop2 = SetROP2(hdc, SRCCOPY); |
510 |
SetROP2(hdc, rop2); |
|
526 |
SetROP2(hdc, rop2); |
511 |
dwRop = SRCCOPY; |
|
527 |
dwRop = SRCCOPY; |
512 |
GetClipBox(hdc, &rect); |
|
528 |
GetClipBox(hdc, &rect); |
513 |
|
|
529 |
|
514 |
// Paint the background for the label |
|
530 |
// Paint the background for the label |
515 |
if (ugl_control->background_color != NULL) { |
|
531 |
if (ugl_control->background_color != NULL) { |
516 |
backgroundBrush = Color_GetBrush(ugl_control->background_color); |
|
532 |
backgroundBrush = Color_GetBrush(ugl_control->background_color); |
517 |
} else { |
|
533 |
} else { |
518 |
backgroundBrush = GetSysColorBrush(COLOR_BTNFACE); |
|
534 |
backgroundBrush = GetSysColorBrush(COLOR_BTNFACE); |
519 |
} |
|
535 |
} |
520 |
FillRect(hdc, &rect, backgroundBrush); |
|
536 |
FillRect(hdc, &rect, backgroundBrush); |
521 |
|
|
537 |
|
522 |
GetObject(ugl_label->ugl_image->image_handle, sizeof(BITMAP), &bitmap); |
|
538 |
GetObject(ugl_label->ugl_image->image_handle, sizeof(BITMAP), &bitmap); |
523 |
ugl_dc = _internal_new_DC(hdc, NULL,&(rect), NULL); |
|
539 |
ugl_dc = _internal_new_DC(hdc, NULL,&(rect), NULL); |
524 |
|
|
540 |
|
525 |
// check alignment and paint the image in accordance to the alignment |
|
541 |
// check alignment and paint the image in accordance to the alignment |
526 |
alignment = ugl_label->alignment; |
|
542 |
alignment = ugl_label->alignment; |
527 |
|
|
543 |
|
528 |
// fix for bug 156893 the original bitblt draws from the top of the image even when the label containing the image is partly scrolled |
|
544 |
// fix for bug 156893 the original bitblt draws from the top of the image even when the label containing the image is partly scrolled |
529 |
// out of visible area. Using Graphics_DrawImage fixes this problem. |
|
545 |
// out of visible area. Using Graphics_DrawImage fixes this problem. |
530 |
if (IS_FLAG_SET(alignment, UGL_STYLE_LEAD)) { |
|
546 |
if (IS_FLAG_SET(alignment, UGL_STYLE_LEAD)) { |
531 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
|
547 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
532 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_TRAIL)) { |
|
548 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_TRAIL)) { |
533 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect.right-rect.left)-bitmap.bmWidth), 0, NULL); |
|
549 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect.right-rect.left)-bitmap.bmWidth), 0, NULL); |
534 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_CENTER)) { |
|
550 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_CENTER)) { |
535 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect.right-rect.left)-bitmap.bmWidth)/2, 0, NULL); |
|
551 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect.right-rect.left)-bitmap.bmWidth)/2, 0, NULL); |
536 |
} else { |
|
552 |
} else { |
537 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
|
553 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
538 |
} |
|
554 |
} |
539 |
SelectObject(hdc, oldBrush); |
|
555 |
SelectObject(hdc, oldBrush); |
540 |
DeleteObject(newBrush); |
|
556 |
DeleteObject(newBrush); |
541 |
} |
|
557 |
} |
542 |
|
|
558 |
|
543 |
ReleaseDC(hWnd, hdc); |
|
559 |
ReleaseDC(hWnd, hdc); |
544 |
#endif |
|
560 |
#endif |
545 |
} |
|
561 |
} |
546 |
|
|
562 |
|
547 |
//======================================================================================== |
|
563 |
//======================================================================================== |
548 |
|
|
564 |
|
549 |
void _Label_OwnerDraw(PUGL_Control handle, LPDRAWITEMSTRUCT draw_struct) { |
|
565 |
void _Label_OwnerDraw(PUGL_Control handle, LPDRAWITEMSTRUCT draw_struct) { |
550 |
|
|
566 |
|
551 |
int imageWidth; |
|
567 |
int imageWidth; |
552 |
BITMAP bitmap; |
|
568 |
BITMAP bitmap; |
553 |
LPRECT rect = &draw_struct->rcItem; |
|
569 |
LPRECT rect = &draw_struct->rcItem; |
554 |
int alignment; |
|
570 |
int alignment; |
555 |
PUGL_Label ugl_label = UGL_LABEL(handle); |
|
571 |
PUGL_Label ugl_label = UGL_LABEL(handle); |
556 |
PUGL_Control ugl_control = UGL_CONTROL(handle); |
|
572 |
PUGL_Control ugl_control = UGL_CONTROL(handle); |
557 |
PUGL_Image image = ugl_label->ugl_image; |
|
573 |
PUGL_Image image = ugl_label->ugl_image; |
558 |
HBRUSH backgroundBrush; |
|
574 |
HBRUSH backgroundBrush; |
559 |
HDC hdc = draw_struct->hDC; |
|
575 |
HDC hdc = draw_struct->hDC; |
560 |
|
|
576 |
|
561 |
if (image != NULL) { |
|
577 |
if (image != NULL) { |
562 |
|
|
578 |
|
563 |
HRGN clip = CreateRectRgn(0, 0, 0, 0); |
|
579 |
HRGN clip = CreateRectRgn(0, 0, 0, 0); |
564 |
PUGL_DC ugl_dc; |
|
580 |
PUGL_DC ugl_dc; |
565 |
RECT shiftedClip; |
|
581 |
RECT shiftedClip; |
566 |
|
|
582 |
|
567 |
int res = GetClipRgn(draw_struct->hDC, clip); |
|
583 |
int res = GetClipRgn(draw_struct->hDC, clip); |
568 |
|
|
584 |
|
569 |
// Update the background color of the button |
|
585 |
// Update the background color of the button |
570 |
if (ugl_control->background_color != NULL) { |
|
586 |
if (ugl_control->background_color != NULL) { |
571 |
backgroundBrush = Color_GetBrush(ugl_control->background_color); |
|
587 |
backgroundBrush = Color_GetBrush(ugl_control->background_color); |
572 |
} else { |
|
588 |
} else { |
573 |
backgroundBrush = GetSysColorBrush(COLOR_BTNFACE); |
|
589 |
backgroundBrush = GetSysColorBrush(COLOR_BTNFACE); |
574 |
} |
|
590 |
} |
575 |
FillRect(hdc, rect, backgroundBrush); |
|
591 |
FillRect(hdc, rect, backgroundBrush); |
576 |
|
|
592 |
|
577 |
|
|
593 |
|
578 |
GetObject(ugl_label->ugl_image->image_handle, sizeof(BITMAP), &bitmap); |
|
594 |
GetObject(ugl_label->ugl_image->image_handle, sizeof(BITMAP), &bitmap); |
579 |
imageWidth = bitmap.bmWidth; |
|
595 |
imageWidth = bitmap.bmWidth; |
580 |
alignment = ugl_label->alignment; |
|
596 |
alignment = ugl_label->alignment; |
581 |
ugl_dc = _internal_new_DC(draw_struct->hDC, NULL,&(shiftedClip), NULL); |
|
597 |
ugl_dc = _internal_new_DC(draw_struct->hDC, NULL,&(shiftedClip), NULL); |
582 |
|
|
598 |
|
583 |
/* |
|
599 |
/* |
584 |
* Bug in Windows. When a bitmap is included in the |
|
600 |
* Bug in Windows. When a bitmap is included in the |
585 |
* menu bar, the HDC seems to already include the left |
|
601 |
* menu bar, the HDC seems to already include the left |
586 |
* coordinate. The fix is to ignore this value when |
|
602 |
* coordinate. The fix is to ignore this value when |
587 |
* the item is in a menu bar. |
|
603 |
* the item is in a menu bar. |
588 |
*/ |
|
604 |
*/ |
589 |
|
|
605 |
|
590 |
if (IS_FLAG_SET(alignment, UGL_STYLE_LEAD)) { |
|
606 |
if (IS_FLAG_SET(alignment, UGL_STYLE_LEAD)) { |
591 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
|
607 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
592 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_TRAIL)) { |
|
608 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_TRAIL)) { |
593 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect->right-rect->left)-imageWidth), 0, NULL); |
|
609 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect->right-rect->left)-imageWidth), 0, NULL); |
594 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_CENTER)) { |
|
610 |
} else if (IS_FLAG_SET(alignment, UGL_STYLE_CENTER)) { |
595 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect->right-rect->left)-imageWidth)/2, 0, NULL); |
|
611 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, ((rect->right-rect->left)-imageWidth)/2, 0, NULL); |
596 |
} else { |
|
612 |
} else { |
597 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
|
613 |
Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_label->ugl_image, 0, 0, NULL); |
598 |
} |
|
614 |
} |
599 |
|
|
615 |
|
600 |
SelectClipRgn(draw_struct->hDC, res == 1 ? clip : NULL ); |
|
616 |
SelectClipRgn(draw_struct->hDC, res == 1 ? clip : NULL ); |
601 |
DeleteObject(clip); |
|
617 |
DeleteObject(clip); |
602 |
} |
|
618 |
} |
603 |
|
|
619 |
|
604 |
} |
|
620 |
} |
605 |
|
|
621 |
|
606 |
//============================================================================================================== |
|
622 |
//============================================================================================================== |