summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/_Win/Palettes/Progress/ProgressView.cpp
blob: 8b7e796c1989373f29c19ee09749d769ed06ab7a (plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/****************************************************************************
**
** Copyright (C) 2002 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//==============================================================================
// Prefix
//==============================================================================
#include "stdafx.h"

//==============================================================================
// Includes
//==============================================================================
#include "ProgressView.h"
#include "WndControl.h"
#include "StudioApp.h"
#include "ProgressControl.h"

//==============================================================================
//	Message Maps, etc.
//==============================================================================
IMPLEMENT_DYNCREATE(CProgressView, CView)

BEGIN_MESSAGE_MAP(CProgressView, CView)
//{{AFX_MSG_MAP(CProgressView)
ON_WM_SIZE()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_STUDIO_INITIALIZE_PALETTES, OnInitializePalettes)
ON_MESSAGE(WM_STUDIO_LOADPROGRESS, OnUpdateProgress)
END_MESSAGE_MAP()

//=============================================================================
/**
 * Constructor: Protected because the view is always created dynamically.
 * You must call Initialize() before trying to use this class.
 */
CProgressView::CProgressView()
    : m_WndControl(nullptr)
    , m_ProgressControl(nullptr)
{
}

//=============================================================================
/**
 * Destructor
 */
CProgressView::~CProgressView()
{
    if (m_WndControl) {
        m_WndControl->DestroyWindow();
        m_WndControl = nullptr;

        SAFE_DELETE(m_ProgressControl);
    }
}

//==============================================================================
/**
 *	Handles the WM_INITIALUPDATE message.  Responsible for preparing the view
 *	before it is displayed for the first time.
 */
LRESULT CProgressView::OnInitializePalettes(WPARAM, LPARAM)
{
    if (!m_WndControl) {
        m_ProgressControl = new CProgressControl;
        m_WndControl = new CWndControl(m_ProgressControl);
        m_ProgressControl->SetName("Progress Control");

        if (!::IsWindow(m_WndControl->m_hWnd))
            m_WndControl->CreateEx(0, AfxRegisterWndClass(CS_DBLCLKS, LoadCursor(nullptr, IDC_WAIT),
                                                          (HBRUSH)GetStockObject(BLACK_BRUSH)),
                                   L"LoadView", WS_CHILD | WS_VISIBLE | WS_MAXIMIZE,
                                   CRect(0, 0, 200, 200), this, 100);
    }

    return 0;
}

//==============================================================================
/**
 *	Handles the WM_STUDIO_LOADPROGRESS message.  Changes text displayed on the
 *	load control, depending on what we are trying to update.
 *	@param inwParam Should be an EProgressMessage to indicate what we are updating
 *	@param inlParam Depends on inwParam.  If the message type is PROGRESSUPDATE_PERCENT,
 *	this parameter contains a long value indicating the percent.  If the message
 *	type is PROGRESSUPDATE_FILENAME, this parameter contains a pointer to an
 *	Q3DStudio::CString, which is the name of the file that we are loading.
 *	@return 0
 */
LRESULT CProgressView::OnUpdateProgress(WPARAM inwParam, LPARAM inlParam)
{
    EProgressMessage theMessageType = static_cast<EProgressMessage>(inwParam);

    switch (theMessageType) {
    // Update the percentage completed
    case PROGRESSUPDATE_PERCENT: {
        long thePercent = (long)inlParam;
        m_ProgressControl->SetProgress(thePercent);
    } break;

    // Update the name of the file being loaded
    case PROGRESSUPDATE_FILENAME: {
        Q3DStudio::CString *theName = reinterpret_cast<Q3DStudio::CString *>(inlParam);
        m_ProgressControl->SetFileName(*theName);
    } break;

    // Update the text above the file name (loading or saving)
    case PROGRESSUPDATE_ACTIONTEXT: {
        Q3DStudio::CString *theText = reinterpret_cast<Q3DStudio::CString *>(inlParam);
        m_ProgressControl->SetActionText(*theText);
    } break;

    // Nothing to do in the default case
    default:
        break;
    }

    return 0;
}

//=============================================================================
/**
 * Required by base class but does nothing since all drawing is handled by the
 * child control.
 */
void CProgressView::OnDraw(CDC *inDC)
{
    Q_UNUSED(inDC);
}

//=============================================================================
/**
 * Resizes the wnd control to fill the whole view.
 */
void CProgressView::OnSize(UINT inType, int inX, int inY)
{
    CView::OnSize(inType, inX, inY);
    if (::IsWindow(m_WndControl->GetSafeHwnd()))
        m_WndControl->MoveWindow(0, 0, inX, inY);
}

//==============================================================================
/**
 * Tells the view to erase before redrawing.  Overridden because erasing
 * before each draw produces a flashing effect.
 * @param inDC the DC to erase on.
 * @return FALSE.
 */
BOOL CProgressView::OnEraseBkgnd(CDC *inDC)
{
    Q_UNUSED(inDC);
    return FALSE;
}