source: trunk/src/user32/icontitle.cpp@ 2469

Last change on this file since 2469 was 2469, checked in by sandervl, 26 years ago

* empty log message *

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