Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions sakura_core/dlg/CDlgOpenFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
Copyright (C) 2004, genta
Copyright (C) 2005, novice, ryoji
Copyright (C) 2006, ryoji, Moca
Copyright (C) 2018-2022, Sakura Editor Organization
Copyright (C) 2018-2026, Sakura Editor Organization

This source code is designed for sakura editor.
Please contact the copyright holder to use this code for other purpose.
*/

#include "StdAfx.h"
#include "dlg/CDlgOpenFile.h"

#include "env/DLLSHAREDATA.h"

extern std::shared_ptr<IDlgOpenFile> New_CDlgOpenFile_CommonFileDialog();
Expand All @@ -45,15 +46,15 @@ void CDlgOpenFile::Create(
}

inline bool CDlgOpenFile::DoModal_GetOpenFileName(
WCHAR* pszPath,
std::span<WCHAR> szPath,
EFilter eAddFileter)
{
return m_pImpl->DoModal_GetOpenFileName(pszPath, eAddFileter);
return m_pImpl->DoModal_GetOpenFileName(szPath, eAddFileter);
}

inline bool CDlgOpenFile::DoModal_GetSaveFileName( WCHAR* pszPath )
inline bool CDlgOpenFile::DoModal_GetSaveFileName( std::span<WCHAR> szPath )
{
return m_pImpl->DoModal_GetSaveFileName(pszPath);
return m_pImpl->DoModal_GetSaveFileName(szPath);
}

inline bool CDlgOpenFile::DoModalOpenDlg(
Expand Down
16 changes: 9 additions & 7 deletions sakura_core/dlg/CDlgOpenFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Copyright (C) 2004, genta, MIK
Copyright (C) 2005, ryoji
Copyright (C) 2006, Moca, ryoji
Copyright (C) 2018-2022, Sakura Editor Organization
Copyright (C) 2018-2026, Sakura Editor Organization

This source code is designed for sakura editor.
Please contact the copyright holder to use this code for other purpose.
Expand Down Expand Up @@ -52,21 +52,21 @@ class IDlgOpenFile
// 操作

/*! 開くダイアログ モーダルダイアログの表示
@param[in,out] pszPath 初期ファイル名.選択されたファイル名の格納場所
@param[in,out] szPath 初期ファイル名.選択されたファイル名の格納場所
@param[in] eAddFiler フィルタ設定
@retval true ユーザーがファイル名を選択してOKした
@retval false ダイアログをユーザーがキャンセル等で閉じたかもしくは開くのに失敗したか
*/
virtual bool DoModal_GetOpenFileName(
WCHAR* pszPath,
std::span<WCHAR> szPath,
EFilter eAddFilter
) = 0;

/*! 保存ダイアログ モーダルダイアログの表示
@param pszPath [i/o] 初期ファイル名.選択されたファイル名の格納場所
@param szPath [i/o] 初期ファイル名.選択されたファイル名の格納場所
*/
virtual bool DoModal_GetSaveFileName(
WCHAR* pszPath
std::span<WCHAR> szPath
) = 0;

/* 開くダイアログ モーダルダイアログの表示 */
Expand Down Expand Up @@ -103,8 +103,8 @@ class CDlgOpenFile final : public IDlgOpenFile
) override;

//操作
bool DoModal_GetOpenFileName(WCHAR* pszPath, EFilter eAddFileter = EFITER_TEXT) override;
bool DoModal_GetSaveFileName(WCHAR* pszPath) override;
bool DoModal_GetOpenFileName(std::span<WCHAR> szPath, EFilter eAddFileter = EFITER_TEXT) override;
bool DoModal_GetSaveFileName(std::span<WCHAR> szPath) override;
bool DoModalOpenDlg(SLoadInfo* pLoadInfo,
std::vector<std::wstring>* pFilenames,
bool bOptions = true) override;
Expand All @@ -115,7 +115,9 @@ class CDlgOpenFile final : public IDlgOpenFile
bool resolvePath, EFilter eAddFilter = EFITER_TEXT);

DISALLOW_COPY_AND_ASSIGN(CDlgOpenFile);

private:
std::shared_ptr<IDlgOpenFile> m_pImpl;
};

#endif /* SAKURA_CDLGOPENFILE_8084B9DB_6463_4168_BA59_132EB2596AE7_H_ */
37 changes: 30 additions & 7 deletions sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Copyright (C) 2004, genta
Copyright (C) 2005, novice, ryoji
Copyright (C) 2006, ryoji, Moca
Copyright (C) 2018-2022, Sakura Editor Organization
Copyright (C) 2018-2026, Sakura Editor Organization

This source code is designed for sakura editor.
Please contact the copyright holder to use this code for other purpose.
Expand Down Expand Up @@ -71,8 +71,8 @@ struct CDlgOpenFile_CommonFileDialog final : public IDlgOpenFile
const std::vector<LPCWSTR>& vOPENFOLDER
) override;

bool DoModal_GetOpenFileName( WCHAR* pszPath, EFilter eAddFileter ) override;
bool DoModal_GetSaveFileName( WCHAR* pszPath ) override;
bool DoModal_GetOpenFileName(std::span<WCHAR> szPath, EFilter eAddFileter) override;
bool DoModal_GetSaveFileName(std::span<WCHAR> szPath) override;
bool DoModalOpenDlg( SLoadInfo* pLoadInfo, std::vector<std::wstring>*, bool bOptions ) override;
bool DoModalSaveDlg( SSaveInfo* pSaveInfo, bool bSimpleMode ) override;

Expand Down Expand Up @@ -699,8 +699,18 @@ void CDlgOpenFile_CommonFileDialog::Create(
拡張子フィルタの管理をCFileExtクラスで行う。
@date 2005.02.20 novice 拡張子を省略したら補完する
*/
bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFilter eAddFilter )
bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName(
std::span<WCHAR> szPath,
EFilter eAddFilter
)
{
const auto cchPath = std::size(szPath);

assert(_MAX_PATH <= cchPath);
assert(cchPath <= UINT_MAX);

auto pszPath = std::data(szPath);

//カレントディレクトリを保存。関数から抜けるときに自動でカレントディレクトリは復元される。
CCurrentDirectoryBackupPoint cCurDirBackup;

Expand Down Expand Up @@ -767,7 +777,9 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi
}
pData->m_ofn.lpstrFile = pszPath;
// To Here Jun. 23, 2002 genta
pData->m_ofn.nMaxFile = _MAX_PATH;

pData->m_ofn.nMaxFile = DWORD(cchPath);

pData->m_ofn.lpstrInitialDir = m_szInitialDir;
pData->m_ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
pData->m_ofn.lpstrDefExt = L""; // 2005/02/20 novice 拡張子を省略したら補完する
Expand All @@ -793,8 +805,17 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi
拡張子フィルタの管理をCFileExtクラスで行う。
@date 2005.02.20 novice 拡張子を省略したら補完する
*/
bool CDlgOpenFile_CommonFileDialog::DoModal_GetSaveFileName( WCHAR* pszPath )
bool CDlgOpenFile_CommonFileDialog::DoModal_GetSaveFileName(
std::span<WCHAR> szPath
)
{
const auto cchPath = std::size(szPath);

assert(_MAX_PATH <= cchPath);
assert(cchPath <= UINT_MAX);

auto pszPath = std::data(szPath);

//カレントディレクトリを保存。関数から抜けるときに自動でカレントディレクトリは復元される。
CCurrentDirectoryBackupPoint cCurDirBackup;

Expand Down Expand Up @@ -823,7 +844,9 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetSaveFileName( WCHAR* pszPath )
pData->m_ofn.hInstance = CSelectLang::getLangRsrcInstance();
pData->m_ofn.lpstrFilter = cFileExt.GetExtFilter();
pData->m_ofn.lpstrFile = pszPath; // 2005/02/20 novice デフォルトのファイル名は何も設定しない
pData->m_ofn.nMaxFile = _MAX_PATH;

pData->m_ofn.nMaxFile = DWORD(cchPath);

pData->m_ofn.lpstrInitialDir = m_szInitialDir;
pData->m_ofn.Flags = OFN_CREATEPROMPT | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

Expand Down
29 changes: 23 additions & 6 deletions sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Copyright (C) 2004, genta
Copyright (C) 2005, novice, ryoji
Copyright (C) 2006, ryoji, Moca
Copyright (C) 2018-2022, Sakura Editor Organization
Copyright (C) 2018-2026, Sakura Editor Organization

This source code is designed for sakura editor.
Please contact the copyright holder to use this code for other purpose.
Expand Down Expand Up @@ -50,8 +50,8 @@ struct CDlgOpenFile_CommonItemDialog final
const std::vector<LPCWSTR>& vOPENFOLDER
) override;

bool DoModal_GetOpenFileName( WCHAR* pszPath, EFilter eAddFileter ) override;
bool DoModal_GetSaveFileName( WCHAR* pszPath ) override;
bool DoModal_GetOpenFileName(std::span<WCHAR> szPath, EFilter eAddFileter) override;
bool DoModal_GetSaveFileName(std::span<WCHAR> szPath) override;
bool DoModalOpenDlg( SLoadInfo* pLoadInfo,
std::vector<std::wstring>* pFileNames,
bool bOptions ) override;
Expand Down Expand Up @@ -426,8 +426,17 @@ void CDlgOpenFile_CommonItemDialog::Create(
return;
}

bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFilter eAddFilter )
bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName(
std::span<WCHAR> szPath,
EFilter eAddFilter
)
{
const auto cchPath = std::size(szPath);

assert(_MAX_PATH <= cchPath);

auto pszPath = std::data(szPath);

// 2003.05.12 MIK
std::vector<COMDLG_FILTERSPEC> specs;
specs.reserve(7);
Expand Down Expand Up @@ -464,16 +473,24 @@ bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi
std::vector<std::wstring> fileNames;
bool ret = DoModalOpenDlgImpl0(false, &fileNames, L"", specs);
if (ret) {
wcscpy(pszPath, fileNames[0].c_str());
::wcscpy_s(pszPath, cchPath, fileNames[0].c_str());
}
return ret;
}

/*! 保存ダイアログ モーダルダイアログの表示
@param pszPath [i/o] 初期ファイル名.選択されたファイル名の格納場所
*/
bool CDlgOpenFile_CommonItemDialog::DoModal_GetSaveFileName( WCHAR* pszPath )
bool CDlgOpenFile_CommonItemDialog::DoModal_GetSaveFileName(
std::span<WCHAR> szPath
)
{
const auto cchPath = std::size(szPath);

assert(_MAX_PATH <= cchPath);

auto pszPath = std::data(szPath);

// 2010.08.28 カレントディレクトリを移動するのでパス解決する
if( pszPath[0] ){
WCHAR szFullPath[_MAX_PATH];
Expand Down
11 changes: 11 additions & 0 deletions sakura_core/util/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,17 @@ bool IsDlgItemEnabled(HWND hWndDlg, int nIDDlgItem)
return ret;
}

/*!
* @brief ダイアログボックス項目のテキストを設定する
*/
bool SetDlgItemTextW(HWND hWndDlg, int nIDDlgItem, std::wstring_view text)
{
// コントロールが存在しない場合は失敗とする
if (!::GetDlgItem(hWndDlg, nIDDlgItem)) return false;

return ::SetDlgItemTextW(hWndDlg, nIDDlgItem, std::data(text));
}

/*!
* @brief トラックバーの現在位置を変更する
*/
Expand Down
2 changes: 2 additions & 0 deletions sakura_core/util/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void SetUpDownPos(HWND hWndDlg, int nIDDlgItem, WORD pos);
SGetTextResult GetDlgItemTextW(HWND hWndDlg, int nIDDlgItem);
SGetTextResult GetDlgItemTextW(HWND hWndDlg, int nIDDlgItem, std::span<WCHAR> buffer);

bool SetDlgItemTextW(HWND hWndDlg, int nIDDlgItem, std::wstring_view text);

/*!
* @brief トラックバーのデータ範囲を変更する
*/
Expand Down
1 change: 1 addition & 0 deletions src/test/cpp/tests1/test-StdControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ TEST(ApiWrap, DlgItemTest001) {

// アイテムにテキストを設定しておく
ApiWrap::SetDlgItemTextW(hDlg, IDC_COMBO_TEXT, text);
apiwrap::SetDlgItemTextW(hDlg, IDC_COMBO_TEXT, text);

// バッファサイズ指定せずに取得。正常に取得できる
EXPECT_THAT(apiwrap::GetDlgItemTextW(hDlg, IDC_COMBO_TEXT), StrEq(text));
Expand Down
Loading
Loading