forked from elha/CDex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDXGetFile.cpp
More file actions
211 lines (163 loc) · 4.82 KB
/
DDXGetFile.cpp
File metadata and controls
211 lines (163 loc) · 4.82 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
/*
** CDex - Open Source Digital Audio CD Extractor
**
** Copyright (C) 2006 - 2007 Georgy Berdyshev
** Copyright (C) 1999 Albert L. Faber
**
** http://cdexos.sourceforge.net/
** http://sourceforge.net/projects/cdexos
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
///////////////////////////////// Includes //////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "DDXGetFile.h"
#include "Util.h"
///////////////////////////////// defines /////////////////////////////////////
#define GETFOLDER_EDIT_ID 0x0C8F
BEGIN_MESSAGE_MAP(CFModifyButton, CButton)
//{{AFX_MSG_MAP(CFModifyButton)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CFModifyButton::CFModifyButton()
{
m_pBuddy = NULL;
m_bFirstCall = TRUE;
}
void CFModifyButton::SetBuddy(CGetFileControl* pBuddy)
{
m_pBuddy = pBuddy;
}
BOOL CFModifyButton::PreTranslateMessage(MSG* pMsg)
{
//create the tooltip
if (m_bFirstCall)
{
CUString strLang( g_language.GetString( IDS_DDX_GETFILE_SELECTFILE ) );
m_ToolTip.Create( this );
m_ToolTip.Activate( TRUE );
CUStringConvert strCnv;
m_ToolTip.AddTool( this, strCnv.ToT( strLang ) );
m_bFirstCall = FALSE;
}
//give the tooltip a chance to handle the message
m_ToolTip.RelayEvent(pMsg);
return CButton::PreTranslateMessage(pMsg);
}
void CFModifyButton::OnClicked()
{
if (m_pBuddy)
m_pBuddy->Edit();
else
TRACE0("CFModifyButton: No auto buddy defined\n");
}
BEGIN_MESSAGE_MAP(CGetFileControl, CStatic)
//{{AFX_MSG_MAP(CGetFileControl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CGetFileControl::CGetFileControl()
{
}
BOOL CGetFileControl::SubclassEdit(HWND hEdit)
{
// Test our inputs
ASSERT(this);
if (!IsWindow(hEdit))
{
ASSERT(FALSE);
TRACE0("CGetFileControl::SubclassEdit -- window handle is invalid!\n");
return FALSE;
}
// Subclass the control
if (SubclassWindow(hEdit))
{
//This control can only be used with a read only edit control
LONG lStyle = GetWindowLong(GetSafeHwnd(), GWL_STYLE);
if (!(lStyle & ES_READONLY))
{
TRACE0("CGetFileControl::SubclassEdit -- ES_READONLY style should be set for the edit control\n");
ASSERT(FALSE);
return FALSE;
}
return AddEditButton();
}
else
{
TRACE0("CGetFileControl::SubclassEdit -- Could not subclass edit control!\n");
ASSERT(FALSE);
return FALSE;
}
}
BOOL CGetFileControl::AddEditButton()
{
CRect Rect;
GetWindowRect(Rect);
GetParent()->ScreenToClient(Rect);
Rect.left = Rect.right;
Rect.right = Rect.left + (Rect.Height()*8/10); //width is 8/10 of height
// Dynamically create the edit button control
CUString sEditControlText;
sEditControlText = g_language.GetString(IDS_DDX_GFLDR_EDIT_TEXT);
CUStringConvert strCnv;
BOOL bSuccess = m_Edit.Create( strCnv.ToT( sEditControlText ), WS_VISIBLE | WS_CHILD | WS_GROUP, Rect, GetParent(), GETFOLDER_EDIT_ID);
// Tell the button to call this class when it is clicked
m_Edit.SetBuddy(this);
// Ensure it is using the same font as the parent
m_Edit.SetFont(GetParent()->GetFont());
return bSuccess;
}
void CGetFileControl::Edit()
{
CUStringConvert strCnv;
// Create file open dialog
CFileDialog dlg( TRUE, _T( "" ) , NULL, OFN_HIDEREADONLY, strCnv.ToT( m_strFilter ) );
if ( IDOK == dlg.DoModal() )
{
POSITION pos = dlg.GetStartPosition();
SetWindowText( dlg.GetNextPathName( pos ) );
UpdateData( FALSE );
}
}
void CGetFileControl::SetFlags(DWORD dwFlags, const CUString& strExt)
{
m_dwFlags = dwFlags;
m_strFilter = strExt;
}
void DDX_GetFileControl(CDataExchange* pDX, int nIDC, CGetFileControl& rCGetFileControl, DWORD dwFlags, const CUString& strExt)
{
HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
if (!pDX->m_bSaveAndValidate && rCGetFileControl.m_hWnd == NULL) // not subclassed yet
{
if (!rCGetFileControl.SubclassEdit(hWndCtrl))
{
ASSERT(FALSE); // possibly trying to subclass twice ?
AfxThrowNotSupportedException();
}
}
rCGetFileControl.SetFlags(dwFlags, strExt );
}
BOOL CGetFileControl::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN )
{
if ( VK_RETURN == pMsg->wParam )
{
m_Edit.OnClicked();
return TRUE;
}
}
return CStatic::PreTranslateMessage(pMsg);
}