⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customizedialog.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////
// CustomizeDialog.cpp: implementation of the CCustomizeDialog class.
//
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2001 by Nikolay Denisov. All rights reserved.
//
// This code is free for personal and commercial use, providing this 
// notice remains intact in the source files and all eventual changes are
// clearly marked with comments.
//
// You must obtain the author's consent before you can include this code
// in a software library.
//
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Please email bug reports, bug fixes, enhancements, requests and
// comments to: nick@actor.ru
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CommonRes.h"
#include "CustomizeDialog.h"
#include "GlobalData.h"
#include "ToolBarEx.h"

#include "..\generaldata.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COptionsDialog dialog

COptionsDialog::COptionsDialog( ETextOptions eTextOptions,
                                EIconOptions eIconOptions )
{
    //{{AFX_DATA_INIT(COptionsDialog)
    //}}AFX_DATA_INIT

    m_eTextOptions = eTextOptions;
    m_eIconOptions = eIconOptions;
}


void COptionsDialog::DoDataExchange( CDataExchange* pDX )
{
    CDialog::DoDataExchange( pDX );
    //{{AFX_DATA_MAP(COptionsDialog)
    DDX_Control(pDX, IDC_CB_TEXTOPTIONS, m_cbTextOptions);
    DDX_Control(pDX, IDC_CB_ICONOPTIONS, m_cbIconOptions);
    //}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// Operations

bool COptionsDialog::SelectTextOption( ETextOptions eTextOptions )
{
    for ( int nIndex = 0; nIndex < m_cbTextOptions.GetCount(); nIndex++ )
    {
        if ( eTextOptions == ( ETextOptions )m_cbTextOptions.GetItemData( nIndex ) )
        {
            m_cbTextOptions.SetCurSel( nIndex );
            m_eTextOptions = eTextOptions;
            return true;
        }
    }

    return false;
}

bool COptionsDialog::SelectIconOption( EIconOptions eIconOptions )
{
    for ( int nIndex = 0; nIndex < m_cbIconOptions.GetCount(); nIndex++ )
    {
        if ( eIconOptions == ( EIconOptions )m_cbIconOptions.GetItemData( nIndex ) )
        {
            m_cbIconOptions.SetCurSel( nIndex );
            m_eIconOptions = eIconOptions;
            return true;
        }
    }

    return false;
}

/////////////////////////////////////////////////////////////////////////////
// Implementation

CCustomizeDialog* COptionsDialog::GetCustomizeDialog() const
{
    return STATIC_DOWNCAST( CCustomizeDialog, GetParent() );
}

/////////////////////////////////////////////////////////////////////////////
// COptionsDialog message handlers

BEGIN_MESSAGE_MAP(COptionsDialog, CDialog)
    //{{AFX_MSG_MAP(COptionsDialog)
    ON_CBN_SELENDOK(IDC_CB_TEXTOPTIONS, OnTextOptions)
    ON_CBN_SELENDOK(IDC_CB_ICONOPTIONS, OnIconOptions)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL COptionsDialog::OnInitDialog() 
{
    CDialog::OnInitDialog();

    CCustomizeDialog* pCustomizeDialog = GetCustomizeDialog();

    pCustomizeDialog->AddTextOption( m_cbTextOptions, toTextLabels,   IDS_TO_TEXTLABELS );
    pCustomizeDialog->AddTextOption( m_cbTextOptions, toTextOnRight,  IDS_TO_TEXTONRIGHT );
    pCustomizeDialog->AddTextOption( m_cbTextOptions, toNoTextLabels, IDS_TO_NOTEXTLABELS );
    VERIFY( SelectTextOption( m_eTextOptions ) );

    pCustomizeDialog->AddIconOption( m_cbIconOptions, ioSmallIcons, IDS_IO_SMALLICONS );
    pCustomizeDialog->AddIconOption( m_cbIconOptions, ioLargeIcons, IDS_IO_LARGEICONS );
    VERIFY( SelectIconOption( m_eIconOptions ) );
	SetLanguage();
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

void COptionsDialog::OnTextOptions()
{
    int nSel = m_cbTextOptions.GetCurSel();
    ASSERT( nSel != CB_ERR );
    m_eTextOptions = ( ETextOptions )m_cbTextOptions.GetItemData( nSel );
    GetCustomizeDialog()->SetTextOptions( m_eTextOptions, false );
}

void COptionsDialog::OnIconOptions()
{
    int nSel = m_cbIconOptions.GetCurSel();
    ASSERT( nSel != CB_ERR );
    m_eIconOptions = ( EIconOptions )m_cbIconOptions.GetItemData( nSel );
	GetCustomizeDialog()->SetIconOptions( m_eIconOptions, false );
}

/////////////////////////////////////////////////////////////////////////////
// CCustomizeDialog dialog

#define IDC_LB_AVAILABLE    0x00C9  // determined with Spy++
#define IDC_LB_CURRENT      0x00CB

static const int cxPadding = 3;
static const int cyPadding = 3;

IMPLEMENT_DYNAMIC( CCustomizeDialog, CWnd )

CCustomizeDialog::CCustomizeDialog( CToolBarEx* pToolBar )
    : m_dlgOptions( pToolBar->m_eTextOptions, pToolBar->m_eIconOptions )
{
    m_pToolBar = pToolBar;
}

/////////////////////////////////////////////////////////////////////////////
// Operations

void CCustomizeDialog::SetTextOptions( ETextOptions eTextOptions, bool bInDialog )
{
    if ( bInDialog )
    {
        VERIFY( m_dlgOptions.SelectTextOption( eTextOptions ) );
    }
    else
    {
        m_pToolBar->SetTextOptions( eTextOptions );
    }
}

void CCustomizeDialog::SetIconOptions( EIconOptions eIconOptions, bool bInDialog )
{
    if ( bInDialog )
    {
        VERIFY( m_dlgOptions.SelectIconOption( eIconOptions ) );
    }
    else
    {
        m_pToolBar->SetIconOptions( eIconOptions );
    }

    int nHeight = GetButtonSize().cy;

    CWnd* pWnd = GetDlgItem( IDC_LB_AVAILABLE );
    if ( pWnd != 0 )
    {
        pWnd->SendMessage( LB_SETITEMHEIGHT, 0, nHeight );
        pWnd->Invalidate();
    }

    pWnd = GetDlgItem( IDC_LB_CURRENT );
    if ( pWnd != 0 )
    {
        pWnd->SendMessage( LB_SETITEMHEIGHT, 0, nHeight );
        pWnd->Invalidate();
    }
}

/////////////////////////////////////////////////////////////////////////////
// Overrides

void CCustomizeDialog::PostNcDestroy()
{
    delete this;
}

/////////////////////////////////////////////////////////////////////////////
// Implementation

void CCustomizeDialog::AddTextOption( CComboBox& cbTextOptions, ETextOptions eTextOptions,
                                      UINT nStringID )
{
    if ( m_pToolBar->IsTextOptionAvailable( eTextOptions ) )
    {
        CString strText,strTextNew;
        VERIFY( strText.LoadString( nStringID ) );
		GetText(strText,strTextNew,global_item_text);
        int nItem = cbTextOptions.AddString( strTextNew );
        ASSERT( nItem >= 0 );
        cbTextOptions.SetItemData( nItem, ( DWORD )eTextOptions );
    }
}

void CCustomizeDialog::AddIconOption( CComboBox& cbIconOptions, EIconOptions eIconOptions,
                                      UINT nStringID )
{
    if ( m_pToolBar->IsIconOptionAvailable( eIconOptions ) )
    {
        CString strText,strTextNew;
        VERIFY( strText.LoadString( nStringID ) );
		GetText(strText,strTextNew,global_item_text);
        int nItem = cbIconOptions.AddString( strTextNew );
        ASSERT( nItem >= 0 );
        cbIconOptions.SetItemData( nItem, ( DWORD )eIconOptions );
    }
}

CSize CCustomizeDialog::GetButtonSize() const
{
    CSize szImage = ( m_pToolBar->GetIconOptions() == ioSmallIcons ) ?
        szImageSmall : szImageLarge;
    return szImage + CSize( cxPadding * 2, cyPadding * 2 );
}

/////////////////////////////////////////////////////////////////////////////
// CCustomizeDialog message handlers

BEGIN_MESSAGE_MAP(CCustomizeDialog, CWnd)
    //{{AFX_MSG_MAP(CCustomizeDialog)
    ON_WM_DRAWITEM()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -