From 616f3650033d974f59180dc553afd9b854876621 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 20 Mar 2018 09:31:59 +0900 Subject: [PATCH] show/hide toolbar --- READMEJP.txt | 1 + src/RisohEditor.cpp | 156 +++++++++++++++++++++++++----------------- src/RisohSettings.hpp | 1 + src/lang/en-US.rc | 1 + src/lang/ja-JP.rc | 1 + src/lang/zh-CN.rc | 1 + src/resource.h | 1 + 7 files changed, 101 insertions(+), 61 deletions(-) diff --git a/READMEJP.txt b/READMEJP.txt index 3a2bcd17..f4fa19e8 100644 --- a/READMEJP.txt +++ b/READMEJP.txt @@ -235,6 +235,7 @@ 「テキストファイルを開く」を修正。 「リソースIDの追加」の改良。 「言語の一覧」を追加。 + ツールバーを隠せるようになった。 ///////////////////////////////////////////////////// // 片山博文MZ (katahiromz) [A.N.T.] diff --git a/src/RisohEditor.cpp b/src/RisohEditor.cpp index 4f7b88d7..00d75325 100644 --- a/src/RisohEditor.cpp +++ b/src/RisohEditor.cpp @@ -669,34 +669,6 @@ TBBUTTON g_buttons5[] = { -1, ID_TEXTEDIT, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0, IDS_TEXTEDIT }, }; -void ToolBar_Update(HWND hwnd, INT iType) -{ - while (SendMessageW(hwnd, TB_DELETEBUTTON, 0, 0)) - ; - - switch (iType) - { - case 0: - SendMessageW(hwnd, TB_ADDBUTTONS, _countof(g_buttons0), (LPARAM)g_buttons0); - break; - case 1: - SendMessageW(hwnd, TB_ADDBUTTONS, _countof(g_buttons1), (LPARAM)g_buttons1); - break; - case 2: - SendMessageW(hwnd, TB_ADDBUTTONS, _countof(g_buttons2), (LPARAM)g_buttons2); - break; - case 3: - SendMessageW(hwnd, TB_ADDBUTTONS, _countof(g_buttons3), (LPARAM)g_buttons3); - break; - case 4: - SendMessageW(hwnd, TB_ADDBUTTONS, _countof(g_buttons4), (LPARAM)g_buttons4); - break; - case 5: - SendMessageW(hwnd, TB_ADDBUTTONS, _countof(g_buttons5), (LPARAM)g_buttons5); - break; - } -} - VOID ToolBar_StoreStrings(HWND hwnd, INT nCount, TBBUTTON *pButtons) { for (INT i = 0; i < nCount; ++i) @@ -711,29 +683,6 @@ VOID ToolBar_StoreStrings(HWND hwnd, INT nCount, TBBUTTON *pButtons) } } -HWND ToolBar_Create(HWND hwndParent) -{ - HWND hwndTB; - hwndTB = CreateWindowW(TOOLBARCLASSNAME, NULL, - WS_CHILD | WS_VISIBLE | CCS_TOP | TBSTYLE_WRAPABLE | TBSTYLE_LIST, - 0, 0, 0, 0, hwndParent, (HMENU)1, GetWindowInstance(hwndParent), NULL); - if (hwndTB == NULL) - return hwndTB; - - SendMessageW(hwndTB, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); - SendMessageW(hwndTB, TB_SETBITMAPSIZE, 0, MAKELPARAM(0, 0)); - - ToolBar_StoreStrings(hwndTB, _countof(g_buttons0), g_buttons0); - ToolBar_StoreStrings(hwndTB, _countof(g_buttons1), g_buttons1); - ToolBar_StoreStrings(hwndTB, _countof(g_buttons2), g_buttons2); - ToolBar_StoreStrings(hwndTB, _countof(g_buttons3), g_buttons3); - ToolBar_StoreStrings(hwndTB, _countof(g_buttons4), g_buttons4); - ToolBar_StoreStrings(hwndTB, _countof(g_buttons5), g_buttons5); - - ToolBar_Update(hwndTB, 3); - return hwndTB; -} - ////////////////////////////////////////////////////////////////////////////// void ReplaceFullWithHalf(LPWSTR pszText) @@ -1341,6 +1290,8 @@ class MMainWnd : public MWindowBase BOOL ReCompileOnSelChange(HWND hwnd, BOOL bReopen = FALSE); void SelectString(HWND hwnd); void SelectMessage(HWND hwnd); + BOOL CreateOurToolBar(HWND hwndParent); + void UpdateOurToolBar(INT iType); // ID list void OnIDList(HWND hwnd); @@ -1350,6 +1301,7 @@ class MMainWnd : public MWindowBase void OnSetPaths(HWND hwnd); void OnUseOldStyleLangStmt(HWND hwnd); void OnShowLangs(HWND hwnd); + void OnShowHideToolBar(HWND hwnd); // show/hide @@ -3122,6 +3074,11 @@ void MMainWnd::OnInitMenu(HWND hwnd, HMENU hMenu) else CheckMenuItem(hMenu, ID_USEOLDLANGSTMT, MF_BYCOMMAND | MF_UNCHECKED); + if (m_settings.bShowToolBar) + CheckMenuItem(hMenu, ID_SHOWHIDETOOLBAR, MF_BYCOMMAND | MF_CHECKED); + else + CheckMenuItem(hMenu, ID_SHOWHIDETOOLBAR, MF_BYCOMMAND | MF_UNCHECKED); + BOOL bCanEditLabel = TRUE; LPARAM lParam = TV_GetParam(m_hTreeView); if (HIWORD(lParam) == I_TYPE) @@ -3844,6 +3801,64 @@ BOOL MMainWnd::Preview(HWND hwnd, const ResEntry& entry) return bEditable; } +BOOL MMainWnd::CreateOurToolBar(HWND hwndParent) +{ + HWND hwndTB; + hwndTB = CreateWindowW(TOOLBARCLASSNAME, NULL, + WS_CHILD | WS_VISIBLE | CCS_TOP | TBSTYLE_WRAPABLE | TBSTYLE_LIST, + 0, 0, 0, 0, hwndParent, (HMENU)1, GetWindowInstance(hwndParent), NULL); + if (hwndTB == NULL) + return FALSE; + + SendMessageW(hwndTB, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); + SendMessageW(hwndTB, TB_SETBITMAPSIZE, 0, MAKELPARAM(0, 0)); + + ToolBar_StoreStrings(hwndTB, _countof(g_buttons0), g_buttons0); + ToolBar_StoreStrings(hwndTB, _countof(g_buttons1), g_buttons1); + ToolBar_StoreStrings(hwndTB, _countof(g_buttons2), g_buttons2); + ToolBar_StoreStrings(hwndTB, _countof(g_buttons3), g_buttons3); + ToolBar_StoreStrings(hwndTB, _countof(g_buttons4), g_buttons4); + ToolBar_StoreStrings(hwndTB, _countof(g_buttons5), g_buttons5); + + m_hToolBar = hwndTB; + UpdateOurToolBar(3); + + return TRUE; +} + +void MMainWnd::UpdateOurToolBar(INT iType) +{ + while (SendMessageW(m_hToolBar, TB_DELETEBUTTON, 0, 0)) + ; + + switch (iType) + { + case 0: + SendMessageW(m_hToolBar, TB_ADDBUTTONS, _countof(g_buttons0), (LPARAM)g_buttons0); + break; + case 1: + SendMessageW(m_hToolBar, TB_ADDBUTTONS, _countof(g_buttons1), (LPARAM)g_buttons1); + break; + case 2: + SendMessageW(m_hToolBar, TB_ADDBUTTONS, _countof(g_buttons2), (LPARAM)g_buttons2); + break; + case 3: + SendMessageW(m_hToolBar, TB_ADDBUTTONS, _countof(g_buttons3), (LPARAM)g_buttons3); + break; + case 4: + SendMessageW(m_hToolBar, TB_ADDBUTTONS, _countof(g_buttons4), (LPARAM)g_buttons4); + break; + case 5: + SendMessageW(m_hToolBar, TB_ADDBUTTONS, _countof(g_buttons5), (LPARAM)g_buttons5); + break; + } + + if (m_settings.bShowToolBar) + ShowWindow(m_hToolBar, SW_SHOWNOACTIVATE); + else + ShowWindow(m_hToolBar, SW_HIDE); +} + void MMainWnd::SelectTV(HWND hwnd, LPARAM lParam, BOOL DoubleClick) { HidePreview(hwnd); @@ -3854,7 +3869,7 @@ void MMainWnd::SelectTV(HWND hwnd, LPARAM lParam, BOOL DoubleClick) WORD i = LOWORD(lParam); if (m_entries.size() <= i) { - ToolBar_Update(m_hToolBar, 3); + UpdateOurToolBar(3); return; } @@ -3902,28 +3917,27 @@ void MMainWnd::SelectTV(HWND hwnd, LPARAM lParam, BOOL DoubleClick) if (Edit_GetModify(m_hSrcEdit)) { - ToolBar_Update(m_hToolBar, 2); + UpdateOurToolBar(2); } else if (Res_IsTestable(entry.type)) { - ToolBar_Update(m_hToolBar, 0); + UpdateOurToolBar(0); } else if (Res_CanGuiEdit(entry.type)) { - ToolBar_Update(m_hToolBar, 4); + UpdateOurToolBar(4); } else { - ToolBar_Update(m_hToolBar, 3); + UpdateOurToolBar(3); } } else { Edit_SetReadOnly(m_hSrcEdit, TRUE); - ToolBar_Update(m_hToolBar, 3); + UpdateOurToolBar(3); } - ShowWindow(m_hToolBar, SW_SHOWNOACTIVATE); PostMessageDx(WM_SIZE); } @@ -6828,6 +6842,18 @@ void MMainWnd::OnShowLangs(HWND hwnd) dialog.DialogBoxDx(hwnd); } +void MMainWnd::OnShowHideToolBar(HWND hwnd) +{ + m_settings.bShowToolBar = !m_settings.bShowToolBar; + + if (m_settings.bShowToolBar) + ShowWindow(m_hToolBar, SW_SHOWNOACTIVATE); + else + ShowWindow(m_hToolBar, SW_HIDE); + + PostMessageDx(WM_SIZE); +} + void MMainWnd::OnUseOldStyleLangStmt(HWND hwnd) { if (!CompileIfNecessary(hwnd, TRUE)) @@ -6893,7 +6919,7 @@ void MMainWnd::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) MWaitCursor wait; if (codeNotify == EN_CHANGE && m_hSrcEdit == hwndCtl) { - ToolBar_Update(m_hToolBar, 2); + UpdateOurToolBar(2); ChangeStatusText(IDS_READY); return; } @@ -7199,6 +7225,9 @@ void MMainWnd::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) case ID_SHOWLANGS: OnShowLangs(hwnd); break; + case ID_SHOWHIDETOOLBAR: + OnShowHideToolBar(hwnd); + break; default: bUpdateStatus = FALSE; break; @@ -8481,6 +8510,8 @@ void MMainWnd::SetDefaultSettings(HWND hwnd) m_settings.bSelectableByMacro = FALSE; m_settings.captions.clear(); + + m_settings.bShowToolBar = TRUE; } void MMainWnd::UpdatePrefixDB(HWND hwnd) @@ -8720,6 +8751,8 @@ BOOL MMainWnd::LoadSettings(HWND hwnd) } } + keyRisoh.QueryDword(TEXT("bShowToolBar"), (DWORD&)m_settings.bShowToolBar); + return TRUE; } @@ -8851,6 +8884,8 @@ BOOL MMainWnd::SaveSettings(HWND hwnd) keyRisoh.SetSz(szValueName, m_settings.captions[i].c_str()); } + keyRisoh.SetDword(TEXT("bShowToolBar"), m_settings.bShowToolBar); + return TRUE; } @@ -8888,8 +8923,7 @@ BOOL MMainWnd::OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct) ImageList_AddIcon(m_hImageList, m_hFileIcon); ImageList_AddIcon(m_hImageList, m_hFolderIcon); - m_hToolBar = ToolBar_Create(hwnd); - if (m_hToolBar == NULL) + if (!CreateOurToolBar(hwnd)) return FALSE; DWORD style, exstyle; diff --git a/src/RisohSettings.hpp b/src/RisohSettings.hpp index ea20f8ff..3bcb62a6 100644 --- a/src/RisohSettings.hpp +++ b/src/RisohSettings.hpp @@ -84,6 +84,7 @@ struct RisohSettings BOOL bStoreToResFolder; BOOL bSelectableByMacro; captions_type captions; + BOOL bShowToolBar; RisohSettings() { diff --git a/src/lang/en-US.rc b/src/lang/en-US.rc index 026527fd..2716a978 100644 --- a/src/lang/en-US.rc +++ b/src/lang/en-US.rc @@ -106,6 +106,7 @@ IDR_MAINMENU MENU POPUP "&View" { MENUITEM "&Status Bar", ID_STATUSBAR + MENUITEM "&Tool Bar", ID_SHOWHIDETOOLBAR MENUITEM "&Binary", ID_BINARYPANE MENUITEM SEPARATOR MENUITEM "List of &Resource IDs", ID_IDLIST diff --git a/src/lang/ja-JP.rc b/src/lang/ja-JP.rc index 38a584d3..c2d52ea2 100644 --- a/src/lang/ja-JP.rc +++ b/src/lang/ja-JP.rc @@ -106,6 +106,7 @@ IDR_MAINMENU MENU POPUP "表示(&V)" { MENUITEM "ステータス バー(&S)", ID_STATUSBAR + MENUITEM "ツール バー(&T)", ID_SHOWHIDETOOLBAR MENUITEM "バイナリー(&B)", ID_BINARYPANE MENUITEM SEPARATOR MENUITEM "リソースIDの一覧(&R)", ID_IDLIST diff --git a/src/lang/zh-CN.rc b/src/lang/zh-CN.rc index cc3a808a..4c4fa683 100644 --- a/src/lang/zh-CN.rc +++ b/src/lang/zh-CN.rc @@ -106,6 +106,7 @@ IDR_MAINMENU MENU POPUP "界面显示(&V)" { MENUITEM "状态栏(&S)", ID_STATUSBAR + MENUITEM "工具栏(&T)", ID_SHOWHIDETOOLBAR MENUITEM "二进制模式(&B)", ID_BINARYPANE MENUITEM SEPARATOR MENUITEM "资源ID列表(&R)", ID_IDLIST diff --git a/src/resource.h b/src/resource.h index 5f5b329c..a749f6ab 100644 --- a/src/resource.h +++ b/src/resource.h @@ -150,6 +150,7 @@ #define ID_IDJUMP08 229 #define ID_IDJUMP09 230 #define ID_SHOWLANGS 231 +#define ID_SHOWHIDETOOLBAR 232 #define IDD_REPLACERES 100 #define IDD_ADDICON 101