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

Last change on this file since 2269 was 2269, checked in by cbratschi, 26 years ago

* empty log message *

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