source: trunk/src/user32/icontitle.cpp

Last change on this file was 5950, checked in by sandervl, 24 years ago

bugfixes

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