Skip to content

Commit

Permalink
Merge pull request #1246 from beru/SB_SETTEXT
Browse files Browse the repository at this point in the history
ステータスバーにテキストを設定する処理の調整
  • Loading branch information
beru authored Apr 26, 2020
2 parents 8339035 + c3a7434 commit 56f8950
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion sakura_core/view/CCaret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void CCaret::ShowCaretPosInfo()
}

auto& statusBar = m_pEditDoc->m_pcEditWnd->m_cStatusBar;

::SendMessage(statusBar.GetStatusHwnd(), WM_SETREDRAW, (WPARAM)FALSE, 0);
if( m_bClearStatus ){
statusBar.SetStatusText( 0, SBT_NOBORDERS, L"" );
}
Expand All @@ -846,6 +846,8 @@ void CCaret::ShowCaretPosInfo()
statusBar.SetStatusText( 4, 0, pszCodeName );
statusBar.SetStatusText( 5, SBT_OWNERDRAW, L"" );
statusBar.SetStatusText( 6, 0, szText_6 );
::SendMessage(statusBar.GetStatusHwnd(), WM_SETREDRAW, (WPARAM)TRUE, 0);
::RedrawWindow(statusBar.GetStatusHwnd(), NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
}

Expand Down
23 changes: 16 additions & 7 deletions sakura_core/window/CMainStatusBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void CMainStatusBar::DestroyStatusBar()
void CMainStatusBar::SendStatusMessage2( const WCHAR* msg )
{
if( NULL != m_hwndStatusBar ){
SetStatusText(0, SBT_NOBORDERS, msg);
SetStatusText(0, SBT_NOBORDERS, msg, SIZE_MAX, false);
}
}

Expand All @@ -107,15 +107,14 @@ void CMainStatusBar::SendStatusMessage2( const WCHAR* msg )
@param pszText [in] 表示テキスト
@param textLen [in] 表示テキストの文字数
*/
void CMainStatusBar::SetStatusText(int nIndex, int nOption, const WCHAR* pszText, size_t textLen /* = SIZE_MAX */)
void CMainStatusBar::SetStatusText(int nIndex, int nOption, const WCHAR* pszText, size_t textLen /* = SIZE_MAX */, bool bSendMessage /* = true */)
{
if( !m_hwndStatusBar ){
assert(m_hwndStatusBar != NULL);
return;
}
// StatusBar_SetText 関数を呼びだすかどうかを判定するラムダ式
// (StatusBar_SetText は SB_SETTEXT メッセージを SendMessage で送信する)
[&]() -> bool {
// SB_SETTEXT メッセージを発行するかどうかを判定するラムダ式
bool bNeedsToDraw = [&]() -> bool {
// オーナードローの場合は SB_SETTEXT メッセージを無条件に発行するように判定
// 本来表示に変化が無い場合には呼び出さない方が表示のちらつきが減るので好ましいが
// 判定が難しいので諦める
Expand Down Expand Up @@ -150,12 +149,22 @@ void CMainStatusBar::SetStatusText(int nIndex, int nOption, const WCHAR* pszText
return true;
}
if( prevTextLen > 0 ){
::StatusBar_GetText( m_hwndStatusBar, nIndex, prev );
StatusBar_GetText( m_hwndStatusBar, nIndex, prev );
// 設定済みの文字列と設定する文字列を比較して異なる場合は、SB_SETTEXT メッセージを発行
return (wcscmp(prev, pszText) != 0);
}
else{
return true;
}
}() ? StatusBar_SetText( m_hwndStatusBar, nIndex | nOption, pszText ) : 0;
}();
if (bNeedsToDraw) {
if (bSendMessage) {
::SendMessageW( m_hwndStatusBar, SB_SETTEXT, nIndex | nOption, (LPARAM)pszText );
}else {
std::unique_ptr<wchar_t[]> p(new wchar_t[textLen+1]);
std::copy(pszText, pszText+textLen+1, p.get());
::PostMessageW( m_hwndStatusBar, SB_SETTEXT, nIndex | nOption, (LPARAM)p.get() );
m_postponeBuffers[nIndex] = std::move(p);
}
};
}
5 changes: 4 additions & 1 deletion sakura_core/window/CMainStatusBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#pragma once

#include "doc/CDocListener.h"
#include <array>
#include <memory>

class CEditWnd;

Expand Down Expand Up @@ -52,9 +54,10 @@ class CMainStatusBar : public CDocListenerEx{
HWND GetProgressHwnd() const{ return m_hwndProgressBar; }

//設定
void SetStatusText(int nIndex, int nOption, const WCHAR* pszText, size_t textLen = SIZE_MAX);
void SetStatusText(int nIndex, int nOption, const WCHAR* pszText, size_t textLen = SIZE_MAX, bool bSendMessage = true);
private:
CEditWnd* m_pOwner;
HWND m_hwndStatusBar;
HWND m_hwndProgressBar;
std::array<std::unique_ptr<wchar_t[]>, 7> m_postponeBuffers;
};

0 comments on commit 56f8950

Please sign in to comment.