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

📄 preview.h

📁 一个多窗口的浏览器的程序benbrowse
💻 H
字号:
/////////////////////////////////////////////////////////////////////////////
// Preview.h: interface for the print preview classes.
//
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////

#ifndef __PREVIEW_H__
#define __PREVIEW_H__

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "FrameWndEx.h"
#include "ToolBarEx.h"

#include <afxpriv.h>

/////////////////////////////////////////////////////////////////////////////
// CPreviewToolBar

class CPreviewToolBar : public CToolBarEx
{
    DECLARE_DYNCREATE( CPreviewToolBar )

// Overrides
public:
    virtual void Init();
    virtual bool IsTextOptionAvailable( ETextOptions eTextOptions ) const;
    virtual bool IsIconOptionAvailable( EIconOptions eIconOptions ) const;

protected:
    virtual bool HasButtonText( UINT nID );
};

/////////////////////////////////////////////////////////////////////////////
// CPreviewViewEx

class CPreviewViewEx : public CPreviewView
{
	DECLARE_DYNCREATE( CPreviewViewEx )

// Constructors
public:
    CPreviewViewEx();

// Implementation
protected:
    class CViewFriend : public CView
    {
        friend CPreviewViewEx;
    };

// Implementation data
protected:
    CToolBarEx* m_pPreviewToolBar;

// Generated message map functions
protected:
    //{{AFX_MSG(CPreviewViewEx)
    afx_msg void OnPreviewClose();
    afx_msg void OnPreviewPrint();
    afx_msg void OnUpdateNumPageChange( CCmdUI* pCmdUI );
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
// CPreviewableView

template< class TBase >
class CPreviewableView : public TBase
{
// Constructors
public:
    CPreviewableView();
    ~CPreviewableView();

// Implementation
protected:
    bool DoPrintPreview( CView* pPrintView, CRuntimeClass* pPreviewToolBarClass,
        CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState );

    static BOOL CALLBACK PreviewCloseProc( CFrameWnd* pFrameWnd );

// Implementation
protected:
    class CViewFriend : public CView
    {
        friend CPreviewableView< TBase >;
    };

    class CPreviewViewExFriend : public CPreviewViewEx
    {
        friend CPreviewableView< TBase >;
    };

// Message map functions
protected:
    afx_msg void OnFilePrintPreview();
};

/////////////////////////////////////////////////////////////////////////////
// CPreviewableView out-of-line functions

template< class TBase >
CPreviewableView< TBase >::CPreviewableView()
{
}

template< class TBase >
CPreviewableView< TBase >::~CPreviewableView()
{
}

template< class TBase >
void CPreviewableView< TBase >::OnFilePrintPreview()
{
    CPrintPreviewState* pState = new CPrintPreviewState;
    pState->lpfnCloseProc = PreviewCloseProc;

    if ( !DoPrintPreview( this,
            RUNTIME_CLASS( CPreviewToolBar ),
            RUNTIME_CLASS( CPreviewViewEx ), pState ) )
    {
        AfxMessageBox( AFX_IDP_COMMAND_FAILURE );
        delete pState;      // preview failed to initialize, delete State now
    }
}

template< class TBase >
bool CPreviewableView< TBase >::DoPrintPreview( CView* pPrintView,
                                                CRuntimeClass* pPreviewToolBarClass,
                                                CRuntimeClass* pPreviewViewClass,
                                                CPrintPreviewState* pState )
{
    // This code is based on CView::DoPrintPreview().
    // See MFC source code for the original version.

    ASSERT_VALID( pPrintView );
    ASSERT( pState != 0 );

    CFrameWnd* pParent = STATIC_DOWNCAST( CFrameWnd, AfxGetMainWnd() );
    ASSERT_VALID( pParent );

    CCreateContext context;
    context.m_pCurrentFrame = pParent;
    context.m_pCurrentDoc   = CView::GetDocument();
    context.m_pLastView     = this;

    // Create the preview view object
    CPreviewViewExFriend* pView = ( CPreviewViewExFriend* )pPreviewViewClass->CreateObject();
    ASSERT( pView != 0 );
    ASSERT_KINDOF( CPreviewViewEx, pView );

    pView->m_pPreviewState = pState;    // save pointer
    pView->m_pToolBar      = 0;

    // Take over Frame Window
    pParent->OnSetPreviewMode( TRUE, pState );

    // Create print preview toolbar
    pView->m_pPreviewToolBar = ( CToolBarEx* )pPreviewToolBarClass->CreateObject();
    ASSERT( pView->m_pPreviewToolBar != 0 );
    ASSERT_KINDOF( CToolBarEx, pView->m_pPreviewToolBar );

    if ( !pView->m_pPreviewToolBar->Create( pParent,
            WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_FLYBY,
            AFX_IDW_PREVIEW_BAR) )
    {
        pParent->OnSetPreviewMode( FALSE, pState ); // restore Frame Window
        delete pView->m_pPreviewToolBar;            // not autodestruct yet
        pView->m_pPreviewToolBar = 0;
        pView->m_pPreviewState   = 0;               // do not delete state structure
        delete pView;
        return false;
    }

//    if ( pParent->IsKindOf( RUNTIME_CLASS( CFrameWndEx ) ) )
//    {
//        VERIFY( ( ( CFrameWndEx* )pParent )->m_wndReBar.AddBar( pView->m_pPreviewToolBar,
//            0, 0, /*RBBS_GRIPPERALWAYS |*/ RBBS_FIXEDBMP ) );
//    }
    if ( pParent->IsKindOf( RUNTIME_CLASS( CMDIFrameWndEx ) ) )
    {
        VERIFY( ( ( CMDIFrameWndEx* )pParent )->m_wndReBar.AddBar( pView->m_pPreviewToolBar,
            0, 0, /*RBBS_GRIPPERALWAYS |*/ RBBS_FIXEDBMP ) );
    }

    pView->m_pPreviewToolBar->m_bAutoDelete = TRUE;    // automatic cleanup
    pView->m_pPreviewToolBar->ModifyStyle( 0, CCS_ADJUSTABLE );
    pView->m_pPreviewToolBar->Init();

    // Create the preview view as a child of the App Main Window.  This
    // is a sibling of this view if this is an SDI app.  This is NOT a sibling
    // if this is an MDI app.
    if ( !pView->Create( 0, 0, AFX_WS_DEFAULT_VIEW,
            CRect( 0, 0, 0, 0 ), pParent, AFX_IDW_PANE_FIRST, &context ) )
    {
        pParent->OnSetPreviewMode( FALSE, pState ); // restore Frame Window
        pView->m_pPreviewState = 0;     // do not delete state structure
        delete pView;
        return false;
    }

    // Preview window shown now
    pState->pViewActiveOld = pParent->GetActiveView();
    CView* pActiveView = pParent->GetActiveFrame()->GetActiveView();
    if ( pActiveView != 0 )
    {
        ( ( CViewFriend* )pActiveView )->OnActivateView( FALSE, pActiveView, pActiveView );
    }

    if ( !pView->SetPrintView( pPrintView ) )
    {
        pView->OnPreviewClose();
        return true;            // signal that OnEndPrintPreview was called
    }

    pParent->SetActiveView( pView );    // set active view - even for MDI

    // Update toolbar and redraw everything
    pView->m_pPreviewToolBar->SendMessage( WM_IDLEUPDATECMDUI, ( WPARAM )TRUE );
    pParent->RecalcLayout();            // position and size everything
    pParent->UpdateWindow();

    return true;
}

template< class TBase >
BOOL CALLBACK CPreviewableView< TBase >::PreviewCloseProc( CFrameWnd* pFrameWnd )
{
    ASSERT_VALID( pFrameWnd );

    CPreviewViewExFriend* pView = ( CPreviewViewExFriend* )pFrameWnd->GetDlgItem( AFX_IDW_PANE_FIRST );
    ASSERT_KINDOF( CPreviewViewEx, pView );

    pView->OnPreviewClose();
    return FALSE;
}

/////////////////////////////////////////////////////////////////////////////
#endif  // !__PREVIEW_H__

⌨️ 快捷键说明

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