1 | /* $Id: icontitle.cpp,v 1.5 2000-02-16 14:34:20 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Icontitle window class.
|
---|
4 | *
|
---|
5 | * Copyright 1997 Alex Korobka
|
---|
6 | *
|
---|
7 | * Copyright 1999 Christoph Bratschi
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <string.h>
|
---|
12 | #include <os2win.h>
|
---|
13 | #include <heapstring.h>
|
---|
14 | #include "controls.h"
|
---|
15 | #include "icontitle.h"
|
---|
16 |
|
---|
17 | #define DBG_LOCALLOG DBG_icontitle
|
---|
18 | #include "dbglocal.h"
|
---|
19 |
|
---|
20 | static LPCSTR emptyTitleText = "<...>";
|
---|
21 |
|
---|
22 | BOOL bMultiLineTitle;
|
---|
23 | HFONT hIconTitleFont;
|
---|
24 |
|
---|
25 | /***********************************************************************
|
---|
26 | * ICONTITLE_Init
|
---|
27 | */
|
---|
28 | BOOL ICONTITLE_Init(void)
|
---|
29 | {
|
---|
30 | LOGFONTA logFont;
|
---|
31 |
|
---|
32 | SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
|
---|
33 | SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
|
---|
34 | hIconTitleFont = CreateFontIndirectA( &logFont );
|
---|
35 | return (hIconTitleFont) ? TRUE : FALSE;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /***********************************************************************
|
---|
39 | * ICONTITLE_Create
|
---|
40 | */
|
---|
41 | HWND ICONTITLE_Create(Win32BaseWindow *parent)
|
---|
42 | {
|
---|
43 | HWND hWnd;
|
---|
44 | Win32BaseWindow *win32wnd;
|
---|
45 |
|
---|
46 | if (parent->getStyle() & WS_CHILD)
|
---|
47 | hWnd = CreateWindowExA( 0, ICONTITLECLASSNAME, NULL,
|
---|
48 | WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 1, 1,
|
---|
49 | parent->getWindowHandle(),0,parent->getInstance(), NULL );
|
---|
50 | else
|
---|
51 | hWnd = CreateWindowExA( 0, ICONTITLECLASSNAME, NULL,
|
---|
52 | WS_CLIPSIBLINGS, 0, 0, 1, 1,
|
---|
53 | parent->getWindowHandle(),0,parent->getInstance(), NULL );
|
---|
54 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
|
---|
55 | if (win32wnd)
|
---|
56 | {
|
---|
57 | win32wnd->setOwner(parent); /* MDI depends on this */
|
---|
58 | win32wnd->setStyle(win32wnd->getStyle() & ~(WS_CAPTION | WS_BORDER));
|
---|
59 | if (parent->getStyle() & WS_DISABLED ) win32wnd->setStyle(win32wnd->getStyle() | WS_DISABLED);
|
---|
60 | return hWnd;
|
---|
61 | }
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /***********************************************************************
|
---|
66 | * ICONTITLE_GetTitlePos
|
---|
67 | */
|
---|
68 | static BOOL ICONTITLE_GetTitlePos(Win32BaseWindow *wnd,LPRECT lpRect)
|
---|
69 | {
|
---|
70 | LPSTR str;
|
---|
71 | int length = wnd->getOwner()->GetWindowTextLength();
|
---|
72 |
|
---|
73 | if( length )
|
---|
74 | {
|
---|
75 | str = (LPSTR)HeapAlloc( GetProcessHeap(), 0, length + 1 );
|
---|
76 | wnd->getOwner()->GetWindowTextA(str,length);
|
---|
77 | while( str[length - 1] == ' ' ) /* remove trailing spaces */
|
---|
78 | {
|
---|
79 | str[--length] = '\0';
|
---|
80 | if( !length )
|
---|
81 | {
|
---|
82 | HeapFree( GetProcessHeap(), 0, str );
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|
87 | if( !length )
|
---|
88 | {
|
---|
89 | str = (LPSTR)emptyTitleText;
|
---|
90 | length = lstrlenA( str );
|
---|
91 | }
|
---|
92 |
|
---|
93 | if( str )
|
---|
94 | {
|
---|
95 | HDC hDC = GetDC(wnd->getWindowHandle());
|
---|
96 | if( hDC )
|
---|
97 | {
|
---|
98 | HFONT hPrevFont = SelectObject( hDC, hIconTitleFont );
|
---|
99 |
|
---|
100 | SetRect( lpRect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
|
---|
101 | GetSystemMetrics(SM_CXBORDER) * 2,
|
---|
102 | GetSystemMetrics(SM_CYBORDER) * 2 );
|
---|
103 |
|
---|
104 | DrawTextA( hDC, str, length, lpRect, DT_CALCRECT |
|
---|
105 | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
|
---|
106 | (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
|
---|
107 |
|
---|
108 | SelectObject( hDC, hPrevFont );
|
---|
109 | ReleaseDC(wnd->getWindowHandle(),hDC);
|
---|
110 |
|
---|
111 | RECT rectWindow = *wnd->getOwner()->getWindowRect();
|
---|
112 | lpRect->right += 4 * GetSystemMetrics(SM_CXBORDER) - lpRect->left;
|
---|
113 | lpRect->left = rectWindow.left + GetSystemMetrics(SM_CXICON) / 2 -
|
---|
114 | (lpRect->right - lpRect->left) / 2;
|
---|
115 | lpRect->bottom -= lpRect->top;
|
---|
116 | lpRect->top = rectWindow.top + GetSystemMetrics(SM_CYICON);
|
---|
117 | }
|
---|
118 | if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str );
|
---|
119 | return ( hDC ) ? TRUE : FALSE;
|
---|
120 | }
|
---|
121 | return FALSE;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /***********************************************************************
|
---|
125 | * ICONTITLE_Paint
|
---|
126 | */
|
---|
127 | static BOOL ICONTITLE_Paint(Win32BaseWindow *wnd, HDC hDC, BOOL bActive )
|
---|
128 | {
|
---|
129 | HFONT hPrevFont;
|
---|
130 | HBRUSH hBrush = 0;
|
---|
131 | COLORREF textColor = 0;
|
---|
132 |
|
---|
133 | if( bActive )
|
---|
134 | {
|
---|
135 | hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
|
---|
136 | textColor = GetSysColor(COLOR_CAPTIONTEXT);
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | if( wnd->getStyle() & WS_CHILD )
|
---|
141 | {
|
---|
142 | hBrush = (HBRUSH)wnd->getClass()->getClassLongA(GCL_HBRBACKGROUND);
|
---|
143 | if( hBrush )
|
---|
144 | {
|
---|
145 | INT level;
|
---|
146 | LOGBRUSH logBrush;
|
---|
147 | GetObjectA( hBrush, sizeof(logBrush), &logBrush );
|
---|
148 | level = GetRValue(logBrush.lbColor) +
|
---|
149 | GetGValue(logBrush.lbColor) +
|
---|
150 | GetBValue(logBrush.lbColor);
|
---|
151 | if( level < (0x7F * 3) )
|
---|
152 | textColor = RGB( 0xFF, 0xFF, 0xFF );
|
---|
153 | }
|
---|
154 | else
|
---|
155 | hBrush = GetStockObject( WHITE_BRUSH );
|
---|
156 | }
|
---|
157 | else
|
---|
158 | {
|
---|
159 | hBrush = GetStockObject( BLACK_BRUSH );
|
---|
160 | textColor = RGB( 0xFF, 0xFF, 0xFF );
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | //FillWindow16(wnd->getParent()->getWindowHandle(),hwnd,hDC,hBrush); //CB: todo
|
---|
165 |
|
---|
166 | hPrevFont = SelectObject( hDC, hIconTitleFont );
|
---|
167 | if( hPrevFont )
|
---|
168 | {
|
---|
169 | RECT rect,rectWindow = *wnd->getWindowRect();
|
---|
170 | INT length;
|
---|
171 | char buffer[80];
|
---|
172 |
|
---|
173 | rect.left = rect.top = 0;
|
---|
174 | rect.right = rectWindow.right - rectWindow.left;
|
---|
175 | rect.bottom = rectWindow.bottom - rectWindow.top;
|
---|
176 |
|
---|
177 | length = wnd->getOwner()->GetWindowTextA(buffer, 80 );
|
---|
178 | SetTextColor( hDC, textColor );
|
---|
179 | SetBkMode( hDC, TRANSPARENT );
|
---|
180 |
|
---|
181 | DrawTextA( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
|
---|
182 | DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
|
---|
183 |
|
---|
184 | SelectObject( hDC, hPrevFont );
|
---|
185 | }
|
---|
186 | return ( hPrevFont ) ? TRUE : FALSE;
|
---|
187 | }
|
---|
188 |
|
---|
189 | /***********************************************************************
|
---|
190 | * IconTitleWndProc
|
---|
191 | */
|
---|
192 | LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
|
---|
193 | WPARAM wParam, LPARAM lParam )
|
---|
194 | {
|
---|
195 | LRESULT retvalue;
|
---|
196 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
|
---|
197 |
|
---|
198 | switch( msg )
|
---|
199 | {
|
---|
200 | case WM_NCHITTEST:
|
---|
201 | retvalue = HTCAPTION;
|
---|
202 | goto END;
|
---|
203 | case WM_NCMOUSEMOVE:
|
---|
204 | case WM_NCLBUTTONDBLCLK:
|
---|
205 | retvalue = SendMessageA( wnd->getOwner()->getWindowHandle(), msg, wParam, lParam );
|
---|
206 | goto END;
|
---|
207 | case WM_ACTIVATE:
|
---|
208 | if( wParam ) SetActiveWindow( wnd->getOwner()->getWindowHandle() );
|
---|
209 | /* fall through */
|
---|
210 |
|
---|
211 | case WM_CLOSE:
|
---|
212 | retvalue = 0;
|
---|
213 | goto END;
|
---|
214 | case WM_SHOWWINDOW:
|
---|
215 | if( wnd && wParam )
|
---|
216 | {
|
---|
217 | RECT titleRect;
|
---|
218 |
|
---|
219 | ICONTITLE_GetTitlePos( wnd, &titleRect );
|
---|
220 | if( wnd->getOwner()->getNextChild() != wnd ) /* keep icon title behind the owner */
|
---|
221 | SetWindowPos( hWnd, wnd->getOwner()->getWindowHandle(),
|
---|
222 | titleRect.left, titleRect.top,
|
---|
223 | titleRect.right, titleRect.bottom, SWP_NOACTIVATE );
|
---|
224 | else
|
---|
225 | SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
|
---|
226 | titleRect.right, titleRect.bottom,
|
---|
227 | SWP_NOACTIVATE | SWP_NOZORDER );
|
---|
228 | }
|
---|
229 | retvalue = 0;
|
---|
230 | goto END;
|
---|
231 | case WM_ERASEBKGND:
|
---|
232 | if( wnd )
|
---|
233 | {
|
---|
234 | Win32BaseWindow* iconWnd = wnd->getOwner();
|
---|
235 |
|
---|
236 | if( iconWnd->getStyle() & WS_CHILD )
|
---|
237 | lParam = SendMessageA( iconWnd->getWindowHandle(), WM_ISACTIVEICON, 0, 0 );
|
---|
238 | else
|
---|
239 | lParam = (iconWnd->getWindowHandle() == GetActiveWindow());
|
---|
240 |
|
---|
241 | if( ICONTITLE_Paint( wnd, (HDC)wParam, (BOOL)lParam ) )
|
---|
242 | ValidateRect( hWnd, NULL );
|
---|
243 | retvalue = 1;
|
---|
244 | goto END;
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | retvalue = DefWindowProcA( hWnd, msg, wParam, lParam );
|
---|
249 | END:
|
---|
250 | return retvalue;
|
---|
251 | }
|
---|
252 |
|
---|
253 | BOOL ICONTITLE_Register()
|
---|
254 | {
|
---|
255 | WNDCLASSA wndClass;
|
---|
256 |
|
---|
257 | //SvL: Don't check this now
|
---|
258 | // if (GlobalFindAtomA(ICONTITLECLASSNAME)) return FALSE;
|
---|
259 |
|
---|
260 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
261 | wndClass.style = CS_GLOBALCLASS;
|
---|
262 | wndClass.lpfnWndProc = (WNDPROC)IconTitleWndProc;
|
---|
263 | wndClass.cbClsExtra = 0;
|
---|
264 | wndClass.cbWndExtra = 0;
|
---|
265 | wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
|
---|
266 | wndClass.hbrBackground = (HBRUSH)0;
|
---|
267 | wndClass.lpszClassName = ICONTITLECLASSNAME;
|
---|
268 |
|
---|
269 | return RegisterClassA(&wndClass);
|
---|
270 | }
|
---|
271 | //******************************************************************************
|
---|
272 | //******************************************************************************
|
---|
273 | BOOL ICONTITLE_Unregister()
|
---|
274 | {
|
---|
275 | if (GlobalFindAtomA(ICONTITLECLASSNAME))
|
---|
276 | return UnregisterClassA(ICONTITLECLASSNAME,(HINSTANCE)NULL);
|
---|
277 | else return FALSE;
|
---|
278 | }
|
---|
279 | //******************************************************************************
|
---|
280 | //******************************************************************************
|
---|