forked from DavidBuchanan314/iPodWizard-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPictureWnd.cpp
More file actions
235 lines (195 loc) · 4.87 KB
/
PictureWnd.cpp
File metadata and controls
235 lines (195 loc) · 4.87 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// PictureWnd.cpp : implementation file
//
#include "stdafx.h"
#include "iPodWizard.h"
#include "PictureWnd.h"
#define PICTUREWND_CLASSNAME _T("IpodPictureWnd") // Window class name
// CPictureWnd
IMPLEMENT_DYNAMIC(CPictureWnd, CWnd)
CPictureWnd::CPictureWnd()
{
m_pPicture = NULL;
m_Origin = CPoint(0, 0);
RegisterWindowClass();
}
CPictureWnd::~CPictureWnd()
{
}
BEGIN_MESSAGE_MAP(CPictureWnd, CWnd)
ON_WM_PAINT()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_CREATE()
ON_WM_DROPFILES()
END_MESSAGE_MAP()
BOOL CPictureWnd::RegisterWindowClass()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();
if (!(::GetClassInfo(hInst, PICTUREWND_CLASSNAME, &wndcls)))
{
// otherwise we need to register a new class
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = PICTUREWND_CLASSNAME;
if (!AfxRegisterClass(&wndcls))
{
AfxThrowResourceException();
return FALSE;
}
}
return TRUE;
}
// CPictureWnd message handlers
int CPictureWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
DragAcceptFiles(TRUE);
return 0;
}
void CPictureWnd::OnDropFiles(HDROP hDropInfo)
{
rjc::RDragDropFiles myFiles (hDropInfo);
CString buf;
int iL = 0;
int filesRead = 0;
while (myFiles ()) {
myFiles.sNextFile (buf);
iL++;
if (!(GetFileAttributes(buf.GetBuffer()) & FILE_ATTRIBUTE_DIRECTORY))
{
GetParent()->SendMessage(WM_APP, 11, (LPARAM)buf.GetBuffer());
filesRead++;
if (filesRead==1)
GetParent()->SendMessage(WM_APP, 10, (LPARAM)buf.Left(buf.ReverseFind('\\')).GetBuffer());
}
else
GetParent()->SendMessage(WM_APP, 10, (LPARAM)buf.GetBuffer());
}
}
void CPictureWnd::OnPaint()
{
if (theApp.m_LoadingFirmware==TRUE || theApp.m_SavingFirmware==TRUE)
return;
CPaintDC dc(this); // device context for painting
CRect clientRect;
GetClientRect(&clientRect);
if (m_pPicture != NULL)
{
m_pPicture->Draw(&dc, m_Origin);
}
// Do not call CWnd::OnPaint() for painting messages
}
void CPictureWnd::SetPicture(CPicture *pPicture)
{
CRect clientRect;
GetClientRect(&clientRect);
m_pPicture = pPicture;
if (m_pPicture != NULL)
{
m_Origin = CPoint(0, 0);
CSize size = m_pPicture->GetPictureSize();
if (size.cx > clientRect.Width())
{
EnableScrollBar(SB_HORZ, ESB_ENABLE_BOTH);
SetScrollRange(SB_HORZ, 0, size.cx - clientRect.Width());
SetScrollPos(SB_HORZ, 0);
}
else
EnableScrollBar(SB_HORZ, ESB_DISABLE_BOTH);
if (size.cy > clientRect.Height())
{
EnableScrollBar(SB_VERT, ESB_ENABLE_BOTH);
SetScrollRange(SB_VERT, 0, size.cy - clientRect.Height());
SetScrollPos(SB_VERT, 0);
}
else
EnableScrollBar(SB_VERT, ESB_DISABLE_BOTH);
}
Invalidate();
}
void CPictureWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CRect clientRect;
GetClientRect(&clientRect);
CSize size = m_pPicture->GetPictureSize();
LONG maxx = size.cx - clientRect.Width();
switch (nSBCode)
{
case SB_LEFT:
m_Origin.x = 0;
break;
case SB_ENDSCROLL:
break;
case SB_LINELEFT:
m_Origin.x++;
break;
case SB_LINERIGHT:
m_Origin.x--;
break;
case SB_PAGELEFT:
m_Origin.x += 10;
break;
case SB_PAGERIGHT:
m_Origin.x -= 10;
break;
case SB_RIGHT:
m_Origin.x = -maxx;
break;
case SB_THUMBPOSITION:
m_Origin.x = -(LONG)nPos;
break;
case SB_THUMBTRACK:
m_Origin.x = -(LONG)nPos;
break;
}
if (m_Origin.x > 0) m_Origin.x = 0;
if (m_Origin.x < -maxx) m_Origin.x = -maxx;
SetScrollPos(SB_HORZ, -m_Origin.x);
Invalidate();
}
void CPictureWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CRect clientRect;
GetClientRect(&clientRect);
CSize size = m_pPicture->GetPictureSize();
LONG maxy = size.cy - clientRect.Height();
switch (nSBCode)
{
case SB_LEFT:
m_Origin.y = 0;
break;
case SB_ENDSCROLL:
break;
case SB_LINELEFT:
m_Origin.y++;
break;
case SB_LINERIGHT:
m_Origin.y--;
break;
case SB_PAGELEFT:
m_Origin.y += 10;
break;
case SB_PAGERIGHT:
m_Origin.y -= 10;
break;
case SB_RIGHT:
m_Origin.y = -maxy;
break;
case SB_THUMBPOSITION:
m_Origin.y = -(LONG)nPos;
break;
case SB_THUMBTRACK:
m_Origin.y = -(LONG)nPos;
break;
}
if (m_Origin.y > 0) m_Origin.y = 0;
if (m_Origin.y < -maxy) m_Origin.y = -maxy;
SetScrollPos(SB_VERT, -m_Origin.y);
Invalidate();
}