Map PrintDlg16 to PrintDlgA.
[wine] / controls / icontitle.c
1 /*
2  * Icontitle window class.
3  *
4  * Copyright 1997 Alex Korobka
5  */
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include "winuser.h"
11 #include "wine/winuser16.h"
12 #include "win.h"
13 #include "desktop.h"
14 #include "heap.h"
15
16 static  LPCSTR  emptyTitleText = "<...>";
17
18         BOOL    bMultiLineTitle;
19         HFONT   hIconTitleFont;
20
21 /***********************************************************************
22  *           ICONTITLE_Init
23  */
24 BOOL ICONTITLE_Init(void)
25 {
26     LOGFONTA logFont;
27
28     SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
29     SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
30     hIconTitleFont = CreateFontIndirectA( &logFont );
31     return (hIconTitleFont) ? TRUE : FALSE;
32 }
33
34 /***********************************************************************
35  *           ICONTITLE_Create
36  */
37 HWND ICONTITLE_Create( WND* wnd )
38 {
39     WND* wndPtr;
40     HWND hWnd;
41
42     if( wnd->dwStyle & WS_CHILD )
43         hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
44                                   WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 1, 1,
45                                   wnd->parent->hwndSelf, 0, wnd->hInstance, NULL );
46     else
47         hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_ATOM, NULL,
48                                   WS_CLIPSIBLINGS, 0, 0, 1, 1,
49                                   wnd->hwndSelf, 0, wnd->hInstance, NULL );
50     wndPtr = WIN_FindWndPtr( hWnd );
51     if( wndPtr )
52     {
53         wndPtr->owner = wnd;    /* MDI depends on this */
54         wndPtr->dwStyle &= ~(WS_CAPTION | WS_BORDER);
55         if( wnd->dwStyle & WS_DISABLED ) wndPtr->dwStyle |= WS_DISABLED;
56         WIN_ReleaseWndPtr(wndPtr);
57         return hWnd;
58     }
59     return 0;
60 }
61
62 /***********************************************************************
63  *           ICONTITLE_GetTitlePos
64  */
65 static BOOL ICONTITLE_GetTitlePos( WND* wnd, LPRECT lpRect )
66 {
67     LPSTR str;
68     int length = lstrlenA( wnd->owner->text );
69
70     if( length )
71     {
72         str = HeapAlloc( GetProcessHeap(), 0, length + 1 );
73         lstrcpyA( str, wnd->owner->text );
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->hwndSelf );
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->hwndSelf, hDC );
107
108             lpRect->right += 4 * GetSystemMetrics(SM_CXBORDER) - lpRect->left;
109             lpRect->left = wnd->owner->rectWindow.left + GetSystemMetrics(SM_CXICON) / 2 -
110                                       (lpRect->right - lpRect->left) / 2;
111             lpRect->bottom -= lpRect->top;
112             lpRect->top = wnd->owner->rectWindow.top + GetSystemMetrics(SM_CYICON);
113         }
114         if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str );
115         return ( hDC ) ? TRUE : FALSE;
116     }
117     return FALSE;
118 }
119
120 /***********************************************************************
121  *           ICONTITLE_Paint
122  */
123 static BOOL ICONTITLE_Paint( WND* wnd, HDC hDC, BOOL bActive )
124 {
125     HFONT hPrevFont;
126     HBRUSH hBrush = 0;
127     COLORREF textColor = 0;
128
129     if( bActive )
130     {
131         hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
132         textColor = GetSysColor(COLOR_CAPTIONTEXT);
133     }
134     else 
135     {
136         if( wnd->dwStyle & WS_CHILD ) 
137         { 
138             hBrush = (HBRUSH) GetClassLongA(wnd->hwndSelf, GCL_HBRBACKGROUND);
139             if( hBrush )
140             {
141                 INT level;
142                 LOGBRUSH logBrush;
143                 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
144                 level = GetRValue(logBrush.lbColor) +
145                            GetGValue(logBrush.lbColor) +
146                               GetBValue(logBrush.lbColor);
147                 if( level < (0x7F * 3) )
148                     textColor = RGB( 0xFF, 0xFF, 0xFF );
149             }
150             else
151                 hBrush = GetStockObject( WHITE_BRUSH );
152         }
153         else
154         {
155             hBrush = GetStockObject( BLACK_BRUSH );
156             textColor = RGB( 0xFF, 0xFF, 0xFF );    
157         }
158     }
159
160     FillWindow16( wnd->parent->hwndSelf, wnd->hwndSelf, hDC, hBrush );
161
162     hPrevFont = SelectObject( hDC, hIconTitleFont );
163     if( hPrevFont )
164     {
165         RECT  rect;
166         INT     length;
167         char    buffer[80];
168
169         rect.left = rect.top = 0;
170         rect.right = wnd->rectWindow.right - wnd->rectWindow.left;
171         rect.bottom = wnd->rectWindow.bottom - wnd->rectWindow.top;
172
173         length = GetWindowTextA( wnd->owner->hwndSelf, buffer, 80 );
174         SetTextColor( hDC, textColor );
175         SetBkMode( hDC, TRANSPARENT );
176         
177         DrawTextA( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
178                      DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) ); 
179
180         SelectObject( hDC, hPrevFont );
181     }
182     return ( hPrevFont ) ? TRUE : FALSE;
183 }
184
185 /***********************************************************************
186  *           IconTitleWndProc
187  */
188 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
189                                  WPARAM wParam, LPARAM lParam )
190 {
191     LRESULT retvalue;
192     WND *wnd = WIN_FindWndPtr( hWnd );
193
194     switch( msg )
195     {
196         case WM_NCHITTEST:
197              retvalue = HTCAPTION;
198              goto END;
199         case WM_NCMOUSEMOVE:
200         case WM_NCLBUTTONDBLCLK:
201              retvalue = SendMessageA( wnd->owner->hwndSelf, msg, wParam, lParam );      
202              goto END;
203         case WM_ACTIVATE:
204              if( wParam ) SetActiveWindow( wnd->owner->hwndSelf );
205              /* fall through */
206
207         case WM_CLOSE:
208              retvalue = 0;
209              goto END;
210         case WM_SHOWWINDOW:
211              if( wnd && wParam )
212              {
213                  RECT titleRect;
214
215                  ICONTITLE_GetTitlePos( wnd, &titleRect );
216                  if( wnd->owner->next != wnd )  /* keep icon title behind the owner */
217                      SetWindowPos( hWnd, wnd->owner->hwndSelf, 
218                                      titleRect.left, titleRect.top,
219                                      titleRect.right, titleRect.bottom, SWP_NOACTIVATE );
220                  else
221                      SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
222                                      titleRect.right, titleRect.bottom, 
223                                      SWP_NOACTIVATE | SWP_NOZORDER );
224              }
225              retvalue = 0;
226              goto END;
227         case WM_ERASEBKGND:
228              if( wnd )
229              {
230                  WND* iconWnd = WIN_LockWndPtr(wnd->owner);
231
232                  if( iconWnd->dwStyle & WS_CHILD )
233                      lParam = SendMessageA( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 );
234                  else
235                      lParam = (iconWnd->hwndSelf == GetActiveWindow16());
236
237                  WIN_ReleaseWndPtr(iconWnd);
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 );
246 END:
247     WIN_ReleaseWndPtr(wnd);
248     return retvalue;
249 }
250
251