1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
2 // Copyright (C) 1999-2003 Forgotten
3 // Copyright (C) 2005 Forgotten and the VBA development team
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or(at your option)
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 // FileDlg.cpp: implementation of the FileDlg class.
28 #include "../System.h"
34 static char THIS_FILE
[] = __FILE__
;
37 static FileDlg
*instance
= NULL
;
39 static UINT_PTR CALLBACK
HookFunc(HWND hwnd
,
45 if(msg
== WM_NOTIFY
) {
46 OFNOTIFY
*notify
= (OFNOTIFY
*)lParam
;
48 if(notify
->hdr
.code
== CDN_TYPECHANGE
) {
49 instance
->OnTypeChange(hwnd
);
58 static UINT_PTR CALLBACK
HookFuncOldStyle(HWND hwnd
,
64 if(msg
== WM_COMMAND
) {
65 if(HIWORD(wParam
) == CBN_SELCHANGE
) {
66 if(LOWORD(wParam
) == cmb1
) {
67 // call method with combobox handle to keep
69 instance
->OnTypeChange((HWND
)lParam
);
78 /////////////////////////////////////////////////////////////////////////////
81 //////////////////////////////////////////////////////////////////////
82 // Construction/Destruction
83 //////////////////////////////////////////////////////////////////////
85 FileDlg::FileDlg(CWnd
*parent
, LPCTSTR file
, LPCTSTR filter
,
86 int filterIndex
, LPCTSTR ext
, LPCTSTR
*exts
, LPCTSTR initialDir
,
87 LPCTSTR title
, bool save
)
90 info
.dwOSVersionInfoSize
= sizeof(info
);
93 int size
= sizeof(OPENFILENAME
);
95 // avoid problems if OPENFILENAME is already defined with the extended fields
96 // needed for the enhanced open/save dialog
97 #if _WIN32_WINNT < 0x0500
98 if(info
.dwPlatformId
== VER_PLATFORM_WIN32_NT
) {
99 if(info
.dwMajorVersion
>= 5)
100 size
= sizeof(OPENFILENAMEEX
);
104 ZeroMemory(&m_ofn
, sizeof(m_ofn
));
105 m_ofn
.lpstrFile
= m_file
.GetBuffer(MAX_PATH
);
106 m_ofn
.nMaxFile
= MAX_PATH
;
107 m_ofn
.lStructSize
= size
;
108 m_ofn
.hwndOwner
= parent
? parent
->GetSafeHwnd() : NULL
;
109 m_ofn
.nFilterIndex
= filterIndex
;
110 m_ofn
.lpstrInitialDir
= initialDir
;
111 m_ofn
.lpstrTitle
= title
;
112 m_ofn
.lpstrDefExt
= ext
;
113 m_ofn
.lpfnHook
= HookFunc
;
114 m_ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_ENABLESIZING
| OFN_ENABLEHOOK
;
115 m_ofn
.Flags
|= OFN_EXPLORER
;
118 char *p
= m_filter
.GetBuffer(0);
120 while ((p
= strchr(p
, '|')) != NULL
)
122 m_ofn
.lpstrFilter
= m_filter
;
124 if(theApp
.videoOption
== VIDEO_320x240
) {
125 m_ofn
.lpTemplateName
= MAKEINTRESOURCE(IDD_OPENDLG
);
126 m_ofn
.lpfnHook
= HookFuncOldStyle
;
127 m_ofn
.Flags
|= OFN_ENABLETEMPLATE
;
128 m_ofn
.Flags
&= ~OFN_EXPLORER
;
142 void FileDlg::OnTypeChange(HWND hwnd
)
144 HWND parent
= GetParent(hwnd
);
146 HWND fileNameControl
= ::GetDlgItem(parent
, cmb13
);
148 if(fileNameControl
== NULL
)
149 fileNameControl
= ::GetDlgItem(parent
, edt1
);
151 if(fileNameControl
== NULL
)
155 GetWindowText(fileNameControl
, filename
.GetBuffer(MAX_PATH
), MAX_PATH
);
156 filename
.ReleaseBuffer();
158 HWND typeControl
= ::GetDlgItem(parent
, cmb1
);
160 ASSERT(typeControl
!= NULL
);
162 LRESULT sel
= ::SendMessage(typeControl
, CB_GETCURSEL
, 0, 0);
166 LPCTSTR typeName
= extensions
[sel
];
168 if(filename
.GetLength() == 0) {
169 if(strlen(typeName
) != 0)
170 filename
.Format("*%s", typeName
);
172 if(strlen(typeName
) != 0) {
173 int index
= filename
.Find('.');
175 filename
= filename
+ typeName
;
177 filename
= filename
.Left(index
) + typeName
;
181 SetWindowText(fileNameControl
, filename
);
184 int FileDlg::getFilterIndex()
186 return m_ofn
.nFilterIndex
;
189 int FileDlg::DoModal()
191 BOOL res
= isSave
? GetSaveFileName(&m_ofn
) :
192 GetOpenFileName(&m_ofn
);
194 return res
? IDOK
: IDCANCEL
;
197 LPCTSTR
FileDlg::GetPathName()
199 return (LPCTSTR
)m_file
;