A
download DimEdit.h
Language: C++
LOC: 102
Project Info
mcdcplusplus(mcdc)
Server: BerliOS (SVN)
Type: svn
...(SVN)\m\mcdc\trunk\windows\
   AboutDlg.h
   ADLSearchFrame.cpp
   ADLSearchFrame.h
   ADLSProperties.cpp
   ADLSProperties.h
   Advanced3Page.cpp
   Advanced3Page.h
   AdvancedPage.cpp
   AdvancedPage.h
   AGArrayTemplates.cpp
   AGArrayTemplates.h
   AGEmotionSetup.cpp
   AGEmotionSetup.h
   AppearancePage.cpp
   AppearancePage.h
   atlctrlxp.h
   BarShader.cpp
   BarShader.h
   BrowserFrame.cpp
   BrowserFrame.h
   Bumped.cpp
   Bumped.h
   ChatCtrl.cpp
   ChatCtrl.h
   CommandDlg.cpp
   CommandDlg.h
   DebugFrame.cpp
   DebugFrame.h
   DimEdit.h
   DirectoryListingFrm.cpp
   DirectoryListingFrm.h
   DownloadPage.cpp
   DownloadPage.h
   EmoticonsDlg.cpp
   EmoticonsDlg.h
   ExListViewCtrl.cpp
   ExListViewCtrl.h
   ExtendedTrace.cpp
   ExtendedTrace.h
   FavHubProperties.cpp
   FavHubProperties.h
   FavoriteDirsPage.cpp
   FavoriteDirsPage.h
   FavoritesFrm.cpp
   FavoritesFrm.h
   FilterPage.cpp
   FilterPage.h
   FilterPageDlg.h
   FinishedFrame.cpp
   FinishedFrame.h
   FinishedULFrame.cpp
   FinishedULFrame.h
   FlatTabCtrl.h
   FulComboBox.cpp
   FulComboBox.h
   FulTabsPage.cpp
   FulTabsPage.h
   GeneralPage.cpp
   GeneralPage.h
   HashProgressDlg.h
   HelpSystem.cpp
   HelpSystem.h
   HubFrame.cpp
   HubFrame.h
   IgnoreFrame.cpp
   IgnoreFrame.h
   ImageDataObject.cpp
   ImageDataObject.h
   iTunesCOMInterface.h
   iTunesCOMInterface_i.c
   LineDlg.cpp
   LineDlg.h
   ListViewArrows.h
   LogPage.cpp
   LogPage.h
   MagnetDlg.h
   main.cpp
   MainFrm.cpp
   MainFrm.h
   McAdvancedPage.cpp
   McAdvancedPage.h
   McDCPage.cpp
   McDCPage.h
   memdc.h
   NetworkPage.cpp
   NetworkPage.h
   NotepadFrame.cpp
   NotepadFrame.h
   NotepadFrame2.cpp
   NotepadFrame2.h
   OMenu.cpp
   OMenu.h
   OperaColorsPage.cpp
   OperaColorsPage.h
   picturewindow.h
   PopupDlg.h
   PopupManager.cpp
   PopupManager.h
   Popups.cpp
   Popups.h
   PreviewDlg.cpp
   PreviewDlg.h
   PreviewPage.cpp
   PreviewPage.h
   PrivateFrame.cpp
   PrivateFrame.h
   PropertiesDlg.cpp
   PropertiesDlg.h
   PropPage.cpp
   PropPage.h
   PropPageTextStyles.cpp
   PropPageTextStyles.h
   PublicHubsFrm.cpp
   PublicHubsFrm.h
   PublicHubsListDlg.h
   QueueFrame.cpp
   QueueFrame.h
   QueuePage.cpp
   QueuePage.h
   RecentsFrm.cpp
   RecentsFrm.h
   resource.h
   SearchFrm.cpp
   SearchFrm.h
   SecurityPage.cpp
   SecurityPage.h
   SingleInstance.h
   Sntp.cpp
   Sntp.h
   Sounds.cpp
   Sounds.h
   SpyFrame.cpp
   SpyFrame.h
   StaticFrm.h
   StatsFrame.cpp
   StatsFrame.h
   stdafx.cpp
   stdafx.h
   SystemFrame.cpp
   SystemFrame.h
   TextFrame.cpp
   TextFrame.h
   ThemesPage.cpp
   ThemesPage.h
   things.cpp
   things.h
   ToolbarPage.cpp
   ToolbarPage.h
   TransferView.cpp
   TransferView.h
   TreePropertySheet.cpp
   TreePropertySheet.h
   TypedListViewCtrl.h
   UCHandler.h
   UCPage.cpp
   UCPage.h
   UlcPage.cpp
   UlcPage.h
   UploadPage.cpp
   UploadPage.h
   UploadQueueFrame.cpp
   UploadQueueFrame.h
   UPnP.cpp
   UPnP.h
   UserInfo.cpp
   UserInfo.h
   UsersFrame.cpp
   UsersFrame.h
   Winamp.h
   WinampFrame.cpp
   WinampFrame.h
   WindowsPage.cpp
   WindowsPage.h
   WinUtil.cpp
   WinUtil.h

/*
  Name:

    DimEdit

  Author:

    Paul A. Howes

  Description:

    This object is a subclass of a normal edit control, which displays a
    "dimmed" string when the control is empty and does not have the
    keyboard focus.  When the control gains the focus, the user can type
    normally.  When the control loses the focus again, it determines
    whether or not the text of the control is empty or not, and if it is
    empty, replaces the "dimmed" string.

    The "dimmed" string and the color in which it is displayed can be
    specified by the user.

    One of the nice features of this Dim Edit control is that the window
    text is not modified by the control in any way.  This way, the
    GetWindowText and SetWindowText functions (and message handlers for
    WM_SETTEXT and WM_GETTEXT) do not need to be modified get the text
    "right" for the client.  All of the work is done in the WM_PAINT
    message handler.  The focus handlers are there only to keep the edit
    field in the right state.
*/

#ifndef DIMEDIT
#define DIMEDIT
#pragma once

#include <string>
#ifndef tstring
typedef std::basic_string< TCHAR > tstring;
#endif

#include <AtlCrack.h>

class CDimEdit : public CWindowImpl< CDimEdit, CEdit > {
public:

	// Constructors and destructors.

	//  Default constructor
	CDimEdit( )
		: CWindowImpl< CDimEdit, CEdit >( ),
		m_getDlgCodeHandled( false ),
		m_isDim( true ),
		m_dimText(_T("<Click here to enter value>")),
		m_dimColor( RGB( 128, 128, 128 ) ) {
  	}

	//  Constructor that initializes the dim text and the color.
	CDimEdit( const tstring& dimText,
		const COLORREF dimColor = RGB( 128, 128, 128 ) )
		: CWindowImpl< CDimEdit, CEdit >( ),
		m_getDlgCodeHandled( false ),
		m_isDim( true ),
		m_dimText( dimText ),
		m_dimColor( dimColor ) {
	}

	//  Another constructor that initializes the text and color.
	CDimEdit( const tstring&      dimText,
		const unsigned char red,
		const unsigned char green,
		const unsigned char blue )
		: CWindowImpl< CDimEdit, CEdit >( ),
		m_getDlgCodeHandled( false ),
		m_isDim( true ),
		m_dimText( dimText ),
		m_dimColor( RGB( red, green, blue ) ) {
	}

	//  Destructor
	virtual ~CDimEdit( ) {
	}

	// Actions.

	//  Subclass the control.
	BOOL SubclassWindow( HWND hWnd ) {
    		return( CWindowImpl< CDimEdit, CEdit >::SubclassWindow( hWnd ) );
	}

	//  Set the text to display when the control is empty (the "dim" text)
	CDimEdit& SetDimText( const tstring& dimText ) {
		m_dimText = dimText;
		return( *this );
	}

	//  Set the color to display the dim text in.
	CDimEdit& SetDimColor( const COLORREF dimColor ) {
		m_dimColor = dimColor;
		return( *this );
	}

	//  Another way to set the "dim" color.
	CDimEdit& SetDimColor( const unsigned char red,
		const unsigned char green,
		const unsigned char blue ) {
		m_dimColor = RGB( red, green, blue );
		return( *this );
	}

	// Message map and message handlers.

	BEGIN_MSG_MAP_EX( CDimEdit )
		MSG_WM_PAINT( OnPaint )
		MSG_WM_SETFOCUS( OnSetFocus )
		MSG_WM_KILLFOCUS( OnKillFocus )
	END_MSG_MAP( )

	//  WM_PAINT message handler.
	//  NOTE:  The device context passed in does not exist.  This is a WTL bug.
	void OnPaint( HDC ) {
		//  Start the painting operation.
		PAINTSTRUCT paint;

		//  CDCHandle is used, because this object is not responsible for
		//  releasing the device context.
		CDCHandle dc( BeginPaint( &paint ) );

		//  Same idea here -- It's a system brush, and doesn't need to be deleted.
		CBrushHandle brush;
		brush.CreateSysColorBrush( COLOR_WINDOW );

		//  Paint the background of the edit control's client area.
		dc.FillRect( &paint.rcPaint, brush );

		//  Use the system default font.
		dc.SelectFont( HFONT( GetStockObject( DEFAULT_GUI_FONT ) ) );

		//  If the control is in "dim" mode, display the text centered and dimmed.
		if( m_isDim == true ) {
			dc.SetTextColor( m_dimColor );
			dc.SetTextAlign( TA_CENTER );
			dc.TextOut( ( paint.rcPaint.right - paint.rcPaint.left ) / 2, 1, m_dimText.c_str( ) );
		} else { 	//  If the control is "normal", display the text on the left.
			dc.SetTextColor( GetSysColor( COLOR_BTNTEXT ) );
			dc.SetTextAlign( TA_LEFT );
			int length = GetWindowTextLength( ) + 1;
			TCHAR* text = new TCHAR[length];
			GetWindowText( text, length );
			dc.TextOut( 1, 1, text );
			delete[] text;
		}

		//  End the paint operation.  This releases the DC internally.
		EndPaint( &paint );
	}

	//  The edit control received the keyboard focus.
	void OnSetFocus( HWND /*hWnd*/ ) {
		//  Allow Windows to process everything normally.
		DefWindowProc( );

		//  If the text in the edit control is the dim text, then erase it.
		if( GetWindowTextLength( ) == 0 ) {
			m_isDim = false;
			Invalidate( );
		}
	}

	//  The edit control lost the keyboard focus.
	void OnKillFocus( HWND /*hWnd*/ ) {
		//  Allow Windows to process everything normally.
		DefWindowProc( );

		//  If the text length is zero, then the field is empty.  Put the dim text back.
		if( GetWindowTextLength( ) == 0 ) {
			m_isDim = true;
			Invalidate( );
		}
	}

private:
	//  A flag telling the code if WM_GETDLGCODE has already been handled.
	bool m_getDlgCodeHandled;

	//  A flag telling the paint code if the control is dim or active.
	bool m_isDim;

	//  The text to display when the edit control is empty.
	tstring m_dimText;

	//  The color to display it in.
	DWORD m_dimColor;
};

#endif // DIMEDIT

/**
 * @file
 * $Id: DimEdit.h 63 2005-12-12 17:02:22Z crakter $
 */

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us