File: PreView.cpp

package info (click to toggle)
paintlib 2.6.2-14
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,920 kB
  • ctags: 3,874
  • sloc: cpp: 25,209; sh: 10,605; ansic: 1,891; makefile: 120
file content (135 lines) | stat: -rw-r--r-- 3,685 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998 by Jorge Lodos
// All rights reserved
//
// Distribute and use freely, except:
// 1. Don't alter or remove this notice.
// 2. Mark the changes you made
//
// Send bug reports, bug fixes, enhancements, requests, etc. to:
//    lodos@cigb.edu.cu
/////////////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "resource.h"
#include "WinBmpEx.h"
#include "DibCtl.h"
#include "Preview.h"

#include <dlgs.h>

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

/////////////////////////////////////////////////////////////////////////////
// CPreviewFileDlg

IMPLEMENT_DYNAMIC(CPreviewFileDlg, CFileDialog)

CPreviewFileDlg::CPreviewFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
                                 DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
        CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
    m_ofn.Flags |= (OFN_EXPLORER | OFN_ENABLETEMPLATE);
    m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEOPENPREVIEW);

    m_bPreview = true;
}


BEGIN_MESSAGE_MAP(CPreviewFileDlg, CFileDialog)
    //{{AFX_MSG_MAP(CPreviewFileDlg)
    ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
    ON_WM_QUERYNEWPALETTE()
    ON_WM_PALETTECHANGED()
    ON_WM_SETFOCUS()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CPreviewFileDlg::OnInitDialog()
{
    CFileDialog::OnInitDialog();

    m_DIBStaticCtrl.SubclassDlgItem(IDC_IMAGE, this);
    GetDlgItem(IDC_PREVIEW)->SendMessage(BM_SETCHECK, (m_bPreview) ? 1 : 0);

    return true;  // return true unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return false
}


void CPreviewFileDlg::OnFileNameChange()
{
    CFileDialog::OnFileNameChange();
    if (m_bPreview)
        m_DIBStaticCtrl.LoadDib(GetPathName()); // the control will handle errors
}


void CPreviewFileDlg::OnPreview()
{
    m_bPreview = !m_bPreview;
    if (!m_bPreview)
        m_DIBStaticCtrl.RemoveDib(); // no preview
    else
        m_DIBStaticCtrl.LoadDib(GetPathName()); // the control will handle errors
}


BOOL CPreviewFileDlg::OnQueryNewPalette()
{
    m_DIBStaticCtrl.SendMessage(WM_QUERYNEWPALETTE);  // redo the palette if necessary
    return CFileDialog::OnQueryNewPalette();
}

void CPreviewFileDlg::OnPaletteChanged(CWnd* pFocusWnd)
{
    CFileDialog::OnPaletteChanged(pFocusWnd);
    m_DIBStaticCtrl.SendMessage(WM_PALETTECHANGED, (WPARAM)pFocusWnd->GetSafeHwnd());  // redo the palette if necessary
}


void CPreviewFileDlg::OnSetFocus(CWnd* pOldWnd)
{
    CFileDialog::OnSetFocus(pOldWnd);
    m_DIBStaticCtrl.SendMessage(WM_QUERYNEWPALETTE);  // redo the palette if necessary
}


#ifdef _DEBUG
void CPreviewFileDlg::Dump(CDumpContext& dc) const
{
    CFileDialog::Dump(dc);
    if (m_bPreview)
        dc << "preview is enabled\n";
    else
        dc << "preview is disabled\n";
}
#endif //_DEBUG
/*
/--------------------------------------------------------------------
|
|      $Log: PreView.cpp,v $
|      Revision 1.8  2001/10/06 15:31:10  uzadow
|      Fixed open file dialog bug.
|
|      Revision 1.7  2001/09/16 19:03:23  uzadow
|      Added global name prefix PL, changed most filenames.
|
|      Revision 1.6  2000/03/28 21:05:04  Ulrich von Zadow
|      Added zoom capability.
|
|      Revision 1.5  2000/01/10 23:53:02  Ulrich von Zadow
|      Changed formatting & removed tabs.
|
|      Revision 1.4  1999/12/02 17:07:36  Ulrich von Zadow
|      Changes by bdelmee.
|
|
--------------------------------------------------------------------
*/