Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

icontitle.cpp

Go to the documentation of this file.
00001 /* $Id: icontitle.cpp,v 1.8 2001/06/10 09:19:57 sandervl Exp $ */
00002 /*
00003  * Icontitle window class.
00004  *
00005  * Copyright 1997 Alex Korobka
00006  *
00007  * Copyright 1999 Christoph Bratschi
00008  */
00009 
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <os2win.h>
00013 #include <heapstring.h>
00014 #include "controls.h"
00015 #include "icontitle.h"
00016 
00017 #define DBG_LOCALLOG    DBG_icontitle
00018 #include "dbglocal.h"
00019 
00020 static  LPCSTR  emptyTitleText = "<...>";
00021 
00022         BOOL    bMultiLineTitle;
00023         HFONT   hIconTitleFont;
00024 
00025 /***********************************************************************
00026  *           ICONTITLE_Init
00027  */
00028 BOOL ICONTITLE_Init(void)
00029 {
00030     LOGFONTA logFont;
00031 
00032     SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
00033     SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 );
00034     hIconTitleFont = CreateFontIndirectA( &logFont );
00035     return (hIconTitleFont) ? TRUE : FALSE;
00036 }
00037 
00038 /***********************************************************************
00039  *           ICONTITLE_Create
00040  */
00041 HWND ICONTITLE_Create(Win32BaseWindow *parent)
00042 {
00043     HWND hWnd;
00044     Win32BaseWindow *win32wnd;
00045 
00046     if (parent->getStyle() & WS_CHILD)
00047         hWnd = CreateWindowExA( 0, ICONTITLECLASSNAME, NULL,
00048                                   WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 1, 1,
00049                                   parent->getWindowHandle(),0,parent->getInstance(), NULL );
00050     else
00051         hWnd = CreateWindowExA( 0, ICONTITLECLASSNAME, NULL,
00052                                   WS_CLIPSIBLINGS, 0, 0, 1, 1,
00053                                   parent->getWindowHandle(),0,parent->getInstance(), NULL );
00054 
00055     win32wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
00056     if (win32wnd)
00057     {
00058         win32wnd->setOwner(parent);     /* MDI depends on this */
00059         //No RELEASE_WNDOBJ necessary. Done in dtor of window
00060         win32wnd->setStyle(win32wnd->getStyle() & ~(WS_CAPTION | WS_BORDER));
00061         if (parent->getStyle() & WS_DISABLED ) win32wnd->setStyle(win32wnd->getStyle() | WS_DISABLED);
00062         return hWnd;
00063     }
00064     return 0;
00065 }
00066 
00067 /***********************************************************************
00068  *           ICONTITLE_GetTitlePos
00069  */
00070 static BOOL ICONTITLE_GetTitlePos(Win32BaseWindow *wnd,LPRECT lpRect)
00071 {
00072     LPSTR str;
00073     int length = wnd->getOwner()->GetWindowTextLengthA();
00074 
00075     if( length )
00076     {
00077         str = (LPSTR)HeapAlloc( GetProcessHeap(), 0, length + 1 );
00078         wnd->getOwner()->GetWindowTextA(str,length);
00079         while( str[length - 1] == ' ' ) /* remove trailing spaces */
00080         {
00081             str[--length] = '\0';
00082             if( !length )
00083             {
00084                 HeapFree( GetProcessHeap(), 0, str );
00085                 break;
00086             }
00087         }
00088     }
00089     if( !length )
00090     {
00091         str = (LPSTR)emptyTitleText;
00092         length = lstrlenA( str );
00093     }
00094 
00095     if( str )
00096     {
00097         HDC hDC = GetDC(wnd->getWindowHandle());
00098         if( hDC )
00099         {
00100             HFONT hPrevFont = SelectObject( hDC, hIconTitleFont );
00101 
00102             SetRect( lpRect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
00103                        GetSystemMetrics(SM_CXBORDER) * 2,
00104                        GetSystemMetrics(SM_CYBORDER) * 2 );
00105 
00106             DrawTextA( hDC, str, length, lpRect, DT_CALCRECT |
00107                          DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
00108                          (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );
00109 
00110             SelectObject( hDC, hPrevFont );
00111             ReleaseDC(wnd->getWindowHandle(),hDC);
00112 
00113             RECT rectWindow = *wnd->getOwner()->getWindowRect();
00114             lpRect->right += 4 * GetSystemMetrics(SM_CXBORDER) - lpRect->left;
00115             lpRect->left = rectWindow.left + GetSystemMetrics(SM_CXICON) / 2 -
00116                                       (lpRect->right - lpRect->left) / 2;
00117             lpRect->bottom -= lpRect->top;
00118             lpRect->top = rectWindow.top + GetSystemMetrics(SM_CYICON);
00119         }
00120         if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str );
00121         return ( hDC ) ? TRUE : FALSE;
00122     }
00123     return FALSE;
00124 }
00125 
00126 /***********************************************************************
00127  *           ICONTITLE_Paint
00128  */
00129 static BOOL ICONTITLE_Paint(Win32BaseWindow *wnd, HDC hDC, BOOL bActive )
00130 {
00131     HFONT hPrevFont;
00132     HBRUSH hBrush = 0;
00133     COLORREF textColor = 0;
00134 
00135     if( bActive )
00136     {
00137         hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
00138         textColor = GetSysColor(COLOR_CAPTIONTEXT);
00139     }
00140     else
00141     {
00142         if( wnd->getStyle() & WS_CHILD )
00143         {
00144             hBrush = (HBRUSH)wnd->getClass()->getClassLongA(GCL_HBRBACKGROUND);
00145             if( hBrush )
00146             {
00147                 INT level;
00148                 LOGBRUSH logBrush;
00149                 GetObjectA( hBrush, sizeof(logBrush), &logBrush );
00150                 level = GetRValue(logBrush.lbColor) +
00151                            GetGValue(logBrush.lbColor) +
00152                               GetBValue(logBrush.lbColor);
00153                 if( level < (0x7F * 3) )
00154                     textColor = RGB( 0xFF, 0xFF, 0xFF );
00155             }
00156             else
00157                 hBrush = GetStockObject( WHITE_BRUSH );
00158         }
00159         else
00160         {
00161             hBrush = GetStockObject( BLACK_BRUSH );
00162             textColor = RGB( 0xFF, 0xFF, 0xFF );
00163         }
00164     }
00165 
00166     //FillWindow16(wnd->getParent()->getWindowHandle(),hwnd,hDC,hBrush); //CB: todo
00167 
00168     hPrevFont = SelectObject( hDC, hIconTitleFont );
00169     if( hPrevFont )
00170     {
00171         RECT  rect,rectWindow = *wnd->getWindowRect();
00172         INT     length;
00173         char    buffer[80];
00174 
00175         rect.left = rect.top = 0;
00176         rect.right = rectWindow.right - rectWindow.left;
00177         rect.bottom = rectWindow.bottom - rectWindow.top;
00178 
00179         length = wnd->getOwner()->GetWindowTextA(buffer, 80 );
00180         SetTextColor( hDC, textColor );
00181         SetBkMode( hDC, TRANSPARENT );
00182 
00183         DrawTextA( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
00184                      DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );
00185 
00186         SelectObject( hDC, hPrevFont );
00187     }
00188     return ( hPrevFont ) ? TRUE : FALSE;
00189 }
00190 
00191 /***********************************************************************
00192  *           IconTitleWndProc
00193  */
00194 LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg,
00195                                  WPARAM wParam, LPARAM lParam )
00196 {
00197     LRESULT retvalue;
00198     Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
00199 
00200     switch( msg )
00201     {
00202         case WM_NCHITTEST:
00203              retvalue = HTCAPTION;
00204              goto END;
00205         case WM_NCMOUSEMOVE:
00206         case WM_NCLBUTTONDBLCLK:
00207              retvalue = SendMessageA( wnd->getOwner()->getWindowHandle(), msg, wParam, lParam );
00208              goto END;
00209         case WM_ACTIVATE:
00210              if( wParam ) SetActiveWindow( wnd->getOwner()->getWindowHandle() );
00211              /* fall through */
00212 
00213         case WM_CLOSE:
00214              retvalue = 0;
00215              goto END;
00216         case WM_SHOWWINDOW:
00217              if( wnd && wParam )
00218              {
00219                  RECT titleRect;
00220 
00221                  ICONTITLE_GetTitlePos( wnd, &titleRect );
00222                  if( wnd->getOwner()->getNextChild() != wnd )  /* keep icon title behind the owner */
00223                      SetWindowPos( hWnd, wnd->getOwner()->getWindowHandle(),
00224                                      titleRect.left, titleRect.top,
00225                                      titleRect.right, titleRect.bottom, SWP_NOACTIVATE );
00226                  else
00227                      SetWindowPos( hWnd, 0, titleRect.left, titleRect.top,
00228                                      titleRect.right, titleRect.bottom,
00229                                      SWP_NOACTIVATE | SWP_NOZORDER );
00230              }
00231              retvalue = 0;
00232              goto END;
00233         case WM_ERASEBKGND:
00234              if( wnd )
00235              {
00236                  Win32BaseWindow* iconWnd = wnd->getOwner();
00237 
00238                  if( iconWnd->getStyle() & WS_CHILD )
00239                      lParam = SendMessageA( iconWnd->getWindowHandle(), WM_ISACTIVEICON, 0, 0 );
00240                  else
00241                      lParam = (iconWnd->getWindowHandle() == GetActiveWindow());
00242 
00243                  if( ICONTITLE_Paint( wnd, (HDC)wParam, (BOOL)lParam ) )
00244                      ValidateRect( hWnd, NULL );
00245                  retvalue = 1;
00246                  goto END;
00247              }
00248     }
00249     retvalue = DefWindowProcA( hWnd, msg, wParam, lParam );
00250 END:
00251     if(wnd) RELEASE_WNDOBJ(wnd);
00252     return retvalue;
00253 }
00254 
00255 BOOL ICONTITLE_Register()
00256 {
00257     WNDCLASSA wndClass;
00258 
00259 //SvL: Don't check this now
00260 //    if (GlobalFindAtomA(ICONTITLECLASSNAME)) return FALSE;
00261 
00262     ZeroMemory(&wndClass,sizeof(WNDCLASSA));
00263     wndClass.style         = CS_GLOBALCLASS;
00264     wndClass.lpfnWndProc   = (WNDPROC)IconTitleWndProc;
00265     wndClass.cbClsExtra    = 0;
00266     wndClass.cbWndExtra    = 0;
00267     wndClass.hCursor       = LoadCursorA(0,IDC_ARROWA);
00268     wndClass.hbrBackground = (HBRUSH)0;
00269     wndClass.lpszClassName = ICONTITLECLASSNAME;
00270 
00271     return RegisterClassA(&wndClass);
00272 }
00273 //******************************************************************************
00274 //******************************************************************************
00275 BOOL ICONTITLE_Unregister()
00276 {
00277     if (GlobalFindAtomA(ICONTITLECLASSNAME))
00278         return UnregisterClassA(ICONTITLECLASSNAME,(HINSTANCE)NULL);
00279     else return FALSE;
00280 }
00281 //******************************************************************************
00282 //******************************************************************************

Generated on Wed Jan 23 23:17:32 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001