Skip to content
Merged
14 changes: 8 additions & 6 deletions sakura_core/env/CShareData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,14 +1130,14 @@ int CShareData::GetMacroFilename( int idx, WCHAR *pszPath, int nBufLen )
if( pszPath == nullptr || nBufLen <= nLen ){
return -nLen;
}
wcscpy( pszPath, pszFile );
::wcscpy_s(pszPath, nBufLen, pszFile);
return nLen;
}
else { // フォルダー指定あり
// 相対パス→絶対パス
const auto nFolderSep = AddLastChar( m_pShareData->m_Common.m_sMacro.m_szMACROFOLDER, std::size(m_pShareData->m_Common.m_sMacro.m_szMACROFOLDER), L'\\' );
int nAllLen;
WCHAR *pszDir;
LPCWSTR pszDir = nullptr;
WCHAR szDir[_MAX_PATH + SFilePath::size()];

// 2003.06.24 Moca フォルダーも相対パスなら実行ファイルからのパス
Expand All @@ -1155,12 +1155,14 @@ int CShareData::GetMacroFilename( int idx, WCHAR *pszPath, int nBufLen )
return -nAllLen;
}

wcscpy( pszPath, pszDir );
WCHAR *ptr2 = pszPath + nDirLen;
::wcsncpy_s(pszPath, nBufLen, pszDir, nDirLen);

if( -1 == nFolderSep ){
*ptr2++ = L'\\';
::wcscat_s(pszPath, nBufLen, L"\\");
}
wcscpy( ptr2, pszFile );

::wcscat_s(pszPath, nBufLen, pszFile);

return nAllLen;
}
}
Expand Down
93 changes: 46 additions & 47 deletions sakura_core/window/CEditWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ void CEditWnd::UpdateCaption()
}

//!< ウィンドウ生成用の矩形を取得
void CEditWnd::_GetWindowRectForInit(CMyRect* rcResult, [[maybe_unused]] int nGroup, const STabGroupInfo& sTabGroupInfo) const
void CEditWnd::_GetWindowRectForInit(
CMyRect* rcResult,
int nGroup [[maybe_unused]],
const STabGroupInfo& sTabGroupInfo
) const
{
/* ウィンドウサイズ継承 */
int nWinCX, nWinCY;
Expand Down Expand Up @@ -384,7 +388,10 @@ HWND CEditWnd::_CreateMainWindow(int nGroup, const STabGroupInfo& sTabGroupInfo)
return hwndResult;
}

void CEditWnd::_GetTabGroupInfo(STabGroupInfo* pTabGroupInfo, int& nGroup) const
void CEditWnd::_GetTabGroupInfo(
STabGroupInfo* pTabGroupInfo,
int& nGroup
) const
{
HWND hwndTop = nullptr;
WINDOWPLACEMENT wpTop = {0};
Expand Down Expand Up @@ -798,20 +805,20 @@ void CEditWnd::LayoutMainMenu()
{
WCHAR szLabel[300];
WCHAR szKey[10];
CommonSetting_MainMenu* pcMenu = &m_pShareData->m_Common.m_sMainMenu;
CMainMenu* cMainMenu;

const auto pcMenu = &m_pShareData->m_Common.m_sMainMenu;

HWND hWnd = GetHwnd();
HMENU hMenu;
int i;
int j;
int nCount;
LPCWSTR pszName;

hMenu = ::CreateMenu();
for (i = 0; i < MAX_MAINMENU_TOP && pcMenu->m_nMenuTopIdx[i] >= 0; i++) {
const auto hMenu = ::CreateMenu();

for (int i = 0; i < MAX_MAINMENU_TOP && pcMenu->m_nMenuTopIdx[i] >= 0; i++) {
nCount = ( i >= MAX_MAINMENU_TOP || pcMenu->m_nMenuTopIdx[i+1] < 0 ? pcMenu->m_nMainMenuNum : pcMenu->m_nMenuTopIdx[i+1] )
- pcMenu->m_nMenuTopIdx[i]; // メニュー項目数
cMainMenu = &pcMenu->m_cMainMenuTbl[pcMenu->m_nMenuTopIdx[i]];
const auto cMainMenu = &pcMenu->m_cMainMenuTbl[pcMenu->m_nMenuTopIdx[i]];
switch (cMainMenu->m_nType) {
case T_NODE:
// ラベル未設定かつFunctionコードがありならストリングテーブルから取得 2012/10/18 syat 各国語対応
Expand Down Expand Up @@ -1007,8 +1014,7 @@ void CEditWnd::LayoutMiniMap( void )
void CEditWnd::EndLayoutBars( BOOL bAdjust/* = TRUE*/ )
{
int nCmdShow = m_pPrintPreview? SW_HIDE: SW_SHOW;
HWND hwndToolBar = (nullptr != m_cToolbar.GetRebarHwnd())? m_cToolbar.GetRebarHwnd(): m_cToolbar.GetToolbarHwnd();
if( nullptr != hwndToolBar )
if (const auto hwndToolBar = (nullptr != m_cToolbar.GetRebarHwnd()) ? m_cToolbar.GetRebarHwnd() : m_cToolbar.GetToolbarHwnd())
::ShowWindow( hwndToolBar, nCmdShow );
if( m_cStatusBar.GetStatusHwnd() )
::ShowWindow( m_cStatusBar.GetStatusHwnd(), nCmdShow );
Expand Down Expand Up @@ -1106,7 +1112,6 @@ LRESULT CEditWnd::DispatchEvent(
LPNMHDR pnmh;
int nPane;
EditInfo* pfi;
LPHELPINFO lphi;

UINT idCtl; /* コントロールのID */
LPDRAWITEMSTRUCT lpdis; /* 項目描画情報 */
Expand Down Expand Up @@ -1218,13 +1223,8 @@ LRESULT CEditWnd::DispatchEvent(
return GetActiveView().GetCommander().HandleCommand( F_COPY, true, 0, 0, 0, 0 );

case WM_HELP:
lphi = (LPHELPINFO) lParam;
switch( lphi->iContextType ){
case HELPINFO_MENUITEM:
if (const auto lphi = (LPHELPINFO) lParam; lphi && HELPINFO_MENUITEM == lphi->iContextType) {
MyWinHelp( hwnd, HELP_CONTEXT, FuncID_To_HelpContextID( (EFunctionCode)lphi->iCtrlId ) );
break;
default:
break;
}
return TRUE;

Expand Down Expand Up @@ -1261,9 +1261,8 @@ LRESULT CEditWnd::DispatchEvent(
// ・WM_SHOWWINDOWはすべての表示切替で呼ばれるわけではないのでWM_WINDOWPOSCHANGEDで処理
// (タブグループ解除などの設定変更時はWM_SHOWWINDOWは呼ばれない)
// ・即時切替だとタブ切替に干渉して元のタブに戻ってしまうことがあるので後で切り替える
WINDOWPOS* pwp;
pwp = (WINDOWPOS*)lParam;
if( pwp->flags & SWP_SHOWWINDOW )
if (const auto pwp = (WINDOWPOS*)lParam;
pwp->flags & SWP_SHOWWINDOW)
::PostMessage( hwnd, MYWM_SHOWOWNEDPOPUPS, TRUE, 0 );
else if( pwp->flags & SWP_HIDEWINDOW )
::PostMessage( hwnd, MYWM_SHOWOWNEDPOPUPS, FALSE, 0 );
Expand Down Expand Up @@ -1562,11 +1561,11 @@ LRESULT CEditWnd::DispatchEvent(
CJackManager::getInstance()->InvokePlugins( PP_EDITOR_END, &GetActiveView() );

// タブまとめ表示では閉じる動作はオプション指定に従う // 2006.02.13 ryoji
if( PM_CLOSE_EXIT != (PM_CLOSE_EXIT & wParam) ){ // 全終了要求でない場合
if (PM_CLOSE_EXIT != (PM_CLOSE_EXIT & wParam) && // 全終了要求でない場合
// タブまとめ表示で(無題)を残す指定の場合、残ウィンドウが1個なら新規エディタを起動して終了する
if( m_pShareData->m_Common.m_sTabBar.m_bDispTabWnd &&
!m_pShareData->m_Common.m_sTabBar.m_bDispTabWndMultiWin &&
m_pShareData->m_Common.m_sTabBar.m_bTab_RetainEmptyWin
m_pShareData->m_Common.m_sTabBar.m_bDispTabWnd &&
!m_pShareData->m_Common.m_sTabBar.m_bDispTabWndMultiWin &&
m_pShareData->m_Common.m_sTabBar.m_bTab_RetainEmptyWin
){
// 自グループ内の残ウィンドウ数を調べる // 2007.06.20 ryoji
int nGroup = CAppNodeManager::getInstance()->GetEditNode( GetHwnd() )->GetGroup();
Expand All @@ -1586,7 +1585,6 @@ LRESULT CEditWnd::DispatchEvent(
true
);
}
}
}
::DestroyWindow( hwnd );
}
Expand Down Expand Up @@ -2695,7 +2693,12 @@ void CEditWnd::SetMenuFuncSel( HMENU hMenu, EFunctionCode nFunc, const WCHAR* sK
m_cMenuDrawer.MyAppendMenu( hMenu, MF_BYPOSITION | MF_STRING, nFunc, sName, sKey );
}

STDMETHODIMP CEditWnd::DragEnter( LPDATAOBJECT pDataObject, DWORD dwKeyState, [[maybe_unused]] POINTL pt, LPDWORD pdwEffect) const
STDMETHODIMP CEditWnd::DragEnter(
LPDATAOBJECT pDataObject,
DWORD dwKeyState,
POINTL pt [[maybe_unused]],
LPDWORD pdwEffect
) const
{
if( pDataObject == nullptr || pdwEffect == nullptr ){
return E_INVALIDARG;
Expand All @@ -2717,7 +2720,11 @@ STDMETHODIMP CEditWnd::DragEnter( LPDATAOBJECT pDataObject, DWORD dwKeyState, [[
return S_OK;
}

STDMETHODIMP CEditWnd::DragOver([[maybe_unused]] DWORD dwKeyState, [[maybe_unused]] POINTL pt, LPDWORD pdwEffect) const
STDMETHODIMP CEditWnd::DragOver(
DWORD dwKeyState [[maybe_unused]],
POINTL pt [[maybe_unused]],
LPDWORD pdwEffect
) const
{
if( pdwEffect == nullptr )
return E_INVALIDARG;
Expand Down Expand Up @@ -3096,7 +3103,7 @@ LRESULT CEditWnd::OnSize2( WPARAM wParam, LPARAM lParam, bool bUpdateStatus )
int nBdrWidth = ::GetSystemMetrics(SM_CXSIZEFRAME) + ::GetSystemMetrics(SM_CXEDGE) * 2; // 境界の幅
SIZE sz;
HDC hdc;
int i;

// 2004-02-28 yasu
// 正確な幅を計算するために、表示フォントを取得してhdcに選択させる。
hdc = ::GetDC( m_cStatusBar.GetStatusHwnd() );
Expand All @@ -3109,7 +3116,7 @@ LRESULT CEditWnd::OnSize2( WPARAM wParam, LPARAM lParam, bool bUpdateStatus )
if( wParam != SIZE_MAXIMIZED ){
nStArr[nStArrNum - 1] -= nSbxWidth;
}
for( i = nStArrNum - 1; i > 0; i-- ){
for (int i = nStArrNum - 1; i > 0; --i) {
::GetTextExtentPoint32W(hdc, PSZ_ARGS(pszLabel[i]), &sz);
nStArr[i - 1] = nStArr[i] - ( sz.cx + nBdrWidth );
}
Expand Down Expand Up @@ -3751,8 +3758,8 @@ int CEditWnd::CreateFileDropDownMenu( HWND hwnd )
*/
void CEditWnd::SetWindowIcon(HICON hIcon, int flag) const
{
HICON hOld = (HICON)::SendMessage( GetHwnd(), WM_SETICON, flag, (LPARAM)hIcon );
if( hOld != nullptr ){
if (const auto hOld = (HICON)::SendMessageW(GetHwnd(), WM_SETICON, flag, LPARAM(hIcon));
hOld != nullptr ){
::DestroyIcon( hOld );
}
}
Expand Down Expand Up @@ -4392,10 +4399,9 @@ void CEditWnd::SetActivePane( int nIndex )
*/
bool CEditWnd::SetDrawSwitchOfAllViews( bool bDraw )
{
int i;
bool bDrawSwitchOld = GetActiveView().GetDrawSwitch();

for( i = 0; i < GetAllViewCount(); i++ ){
for (int i = 0; i < GetAllViewCount(); ++i) {
GetView(i).SetDrawSwitch( bDraw );
}
m_cMiniMapView.SetDrawSwitch( bDraw );
Expand All @@ -4412,11 +4418,8 @@ bool CEditWnd::SetDrawSwitchOfAllViews( bool bDraw )
*/
void CEditWnd::RedrawAllViews( CEditView* pcViewExclude )
{
int i;
CEditView* pcView;

for( i = 0; i < GetAllViewCount(); i++ ){
pcView = &GetView(i);
for (int i = 0; i < GetAllViewCount(); ++i) {
const auto pcView = &GetView(i);
if( pcView == pcViewExclude )
continue;
if( i == m_nActivePaneIndex ){
Expand Down Expand Up @@ -4584,8 +4587,7 @@ CLogicPointEx* CEditWnd::SavePhysPosOfAllView()

for( int i = 0; i < NUM_OF_VIEW; ++i ){
CLayoutPoint tmp = CLayoutPoint(CLayoutInt(0), GetView(i).m_pcTextArea->GetViewTopLine());
const CLayout* layoutLine = GetDocument()->m_cLayoutMgr.SearchLineByLayoutY(tmp.GetY2());
if( layoutLine ){
if (const auto layoutLine = GetDocument()->m_cLayoutMgr.SearchLineByLayoutY(tmp.GetY2())) {
CLogicInt nLineCenter = layoutLine->GetLogicOffset() + layoutLine->GetLengthWithoutEOL() / 2;
pptPosArray[i * NUM_OF_POS + 0].x = nLineCenter;
pptPosArray[i * NUM_OF_POS + 0].y = layoutLine->GetLogicLineNo();
Expand Down Expand Up @@ -4772,8 +4774,7 @@ const LOGFONT& CEditWnd::GetLogfont(bool bTempSetting)
if( bTempSetting && GetDocument()->m_blfCurTemp ){
return GetDocument()->m_lfCur;
}
bool bUseTypeFont = GetDocument()->m_cDocType.GetDocumentAttribute().m_bUseTypeFont;
if( bUseTypeFont ){
if (const auto bUseTypeFont = GetDocument()->m_cDocType.GetDocumentAttribute().m_bUseTypeFont) {
return GetDocument()->m_cDocType.GetDocumentAttribute().m_lf;
}
return m_pShareData->m_Common.m_sView.m_lf;
Expand All @@ -4784,8 +4785,7 @@ int CEditWnd::GetFontPointSize(bool bTempSetting)
if( bTempSetting && GetDocument()->m_blfCurTemp ){
return GetDocument()->m_nPointSizeCur;
}
bool bUseTypeFont = GetDocument()->m_cDocType.GetDocumentAttribute().m_bUseTypeFont;
if( bUseTypeFont ){
if (const auto bUseTypeFont = GetDocument()->m_cDocType.GetDocumentAttribute().m_bUseTypeFont) {
return GetDocument()->m_cDocType.GetDocumentAttribute().m_nPointSize;
}
return m_pShareData->m_Common.m_sView.m_nPointSize;
Expand All @@ -4795,8 +4795,7 @@ ECharWidthCacheMode CEditWnd::GetLogfontCacheMode()
if( GetDocument()->m_blfCurTemp ){
return CWM_CACHE_LOCAL;
}
bool bUseTypeFont = GetDocument()->m_cDocType.GetDocumentAttribute().m_bUseTypeFont;
if( bUseTypeFont ){
if (const auto bUseTypeFont = GetDocument()->m_cDocType.GetDocumentAttribute().m_bUseTypeFont) {
return CWM_CACHE_LOCAL;
}
return CWM_CACHE_SHARE;
Expand Down
4 changes: 2 additions & 2 deletions sakura_core/window/CEditWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ class CEditWnd
const CMyPoint& GetDragPosOrg() const{ return m_ptDragPosOrg; }

/* IDropTarget実装 */ // 2008.06.20 ryoji
STDMETHODIMP DragEnter(LPDATAOBJECT pDataObject, DWORD dwKeyState, POINTL pt, LPDWORD pdwEffect) const;
STDMETHODIMP DragOver(DWORD dwKeyState, POINTL pt, LPDWORD pdwEffect) const;
STDMETHODIMP DragEnter(LPDATAOBJECT pDataObject, DWORD dwKeyState, POINTL pt [[maybe_unused]], LPDWORD pdwEffect) const;
STDMETHODIMP DragOver(DWORD dwKeyState [[maybe_unused]], POINTL pt [[maybe_unused]], LPDWORD pdwEffect) const;
STDMETHODIMP DragLeave() const;
STDMETHODIMP Drop(LPDATAOBJECT pDataObject, DWORD dwKeyState, POINTL pt, LPDWORD pdwEffect);

Expand Down
23 changes: 22 additions & 1 deletion src/test/cpp/tests1/test-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,18 @@ class CExeIniTest : public ::testing::Test {
*/
std::filesystem::path exeIniPath;

/*
* profile1 配下のフォルダーのパス
*/
std::filesystem::path profileDirPath;

/*!
* テストが起動される直前に毎回呼ばれる関数
*/
void SetUp() override {
// マルチユーザー構成設定ファイルのパス
exeIniPath = GetExeFileName().concat(L".ini");
profileDirPath.clear();
}

/*!
Expand All @@ -358,8 +364,16 @@ class CExeIniTest : public ::testing::Test {
std::filesystem::remove(exeIniPath, ec);
}

// profile1 配下のフォルダーも削除する
if (!profileDirPath.empty()) {
std::filesystem::remove_all(profileDirPath, ec);
}

// 削除チェック
EXPECT_FALSE(fexist(exeIniPath));
if (!profileDirPath.empty()) {
EXPECT_FALSE(std::filesystem::exists(profileDirPath));
}
}
};

Expand All @@ -383,9 +397,12 @@ TEST_F(CExeIniTest, GetIniFileName_PrivateRoamingAppData)
// プロセスのインスタンスを用意する
CControlProcess dummy(nullptr, LR"(-PROF="profile1")");

const auto iniPath = GetIniFileName();
profileDirPath = iniPath.parent_path();

// 期待値を取得する
auto expected = ExpandEnvironmentStringsW(LR"(%USERPROFILE%\AppData\Roaming\sakura\profile1\)");
expected += GetIniFileName().filename();
expected += iniPath.filename();

// テスト実施
EXPECT_THAT(GetIniFileName(), StrEq(expected));
Expand Down Expand Up @@ -554,6 +571,10 @@ TEST(file, GetInidirOrExedir)
// 両方ないときはINI基準のパスが変える
GetInidirOrExedir(buf.data(), filename, true);
EXPECT_THAT(buf, StartsWith(iniBasePath.c_str()));

std::filesystem::remove(iniBasePath, ec);
std::filesystem::remove(exeBasePath, ec);
std::filesystem::remove_all(iniBasePath.parent_path(), ec);
}

/*!
Expand Down
Loading
Loading