Revision: 7857 https://osdn.net/projects/ttssh2/scm/svn/commits/7857 Author: zmatsuo Date: 2019-07-18 00:37:28 +0900 (Thu, 18 Jul 2019) Log Message: ----------- ウィンドウサイズに合わせてlistboxのリストの横幅を調整するようにした - ウィンドウサイズに合わせてlistboxの横幅,ok,cancelボタンの位置を調整 - ウィンドウサイズはメッセージに合わせて調整される - listboxの横スクロールバーのサイズを調整した Modified Paths: -------------- trunk/teraterm/common/tmfc.cpp trunk/teraterm/ttpmacro/ListDlg.cpp trunk/teraterm/ttpmacro/ListDlg.h trunk/teraterm/ttpmacro/ttmdlg.cpp trunk/teraterm/ttpmacro/ttmdlg.h trunk/tests/gui_commands_test.ttl -------------- next part -------------- Modified: trunk/teraterm/common/tmfc.cpp =================================================================== --- trunk/teraterm/common/tmfc.cpp 2019-07-17 12:12:01 UTC (rev 7856) +++ trunk/teraterm/common/tmfc.cpp 2019-07-17 15:37:28 UTC (rev 7857) @@ -508,6 +508,8 @@ */ INT_PTR TTCDialog::DoModal(HINSTANCE hInstance, HWND hParent, int idd) { + m_hInst = hInstance; + m_hParentWnd = hParent; pseudoPtr = this; #if defined(REWRITE_TEMPLATE) INT_PTR result = Modified: trunk/teraterm/ttpmacro/ListDlg.cpp =================================================================== --- trunk/teraterm/ttpmacro/ListDlg.cpp 2019-07-17 12:12:01 UTC (rev 7856) +++ trunk/teraterm/ttpmacro/ListDlg.cpp 2019-07-17 15:37:28 UTC (rev 7857) @@ -43,7 +43,7 @@ // CListDlg \x83_\x83C\x83A\x83\x8D\x83O -CListDlg::CListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected, int x, int y) +CListDlg::CListDlg(const PCHAR Text, const PCHAR Caption, const CHAR **Lists, int Selected, int x, int y) { m_Text = Text; m_Caption = Caption; @@ -60,24 +60,14 @@ return TTCDialog::DoModal(hInst, hWndParent, IDD); } -BOOL CListDlg::OnInitDialog() +void CListDlg::InitList(HWND HList) { - static const DlgTextInfo TextInfos[] = { - { IDOK, "BTN_YES" }, - { IDCANCEL, "BTN_CANCEL" }, - }; - char **p; + const char **p; int ListMaxWidth = 0; int ListCount = 0; - HDC DC; - RECT R; - HWND HList, HOk; - - SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile); - - HList = ::GetDlgItem(m_hWnd, IDC_LISTBOX); - DC = ::GetDC(HList); // \x83\x8A\x83X\x83g\x83{\x83b\x83N\x83X\x82\xF0\x89\xA1\x83X\x83N\x83\x8D\x81[\x83\x8B\x82ł\xAB\x82\xE9\x82悤\x82ɍő啝\x82\xF0\x8E擾 - + HDC DC = ::GetDC(HList); + HFONT hFontList = (HFONT)::SendMessage(HList,WM_GETFONT,0,0); + HFONT hOldFont = (HFONT)SelectObject(DC,hFontList); p = m_Lists; while (*p) { SIZE size; @@ -93,6 +83,7 @@ } SendDlgItemMessage(IDC_LISTBOX, LB_SETHORIZONTALEXTENT, (ListMaxWidth + 5), 0); + SelectObject(DC,hOldFont); ::ReleaseDC(HList, DC); if (m_Selected < 0 || m_Selected >= ListCount) { @@ -99,7 +90,22 @@ m_Selected = 0; } SetCurSel(IDC_LISTBOX, m_Selected); +} +BOOL CListDlg::OnInitDialog() +{ + static const DlgTextInfo TextInfos[] = { + { IDOK, "BTN_YES" }, + { IDCANCEL, "BTN_CANCEL" }, + }; + RECT R; + HWND HList, HOk; + + SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile); + + HList = ::GetDlgItem(m_hWnd, IDC_LISTBOX); + InitList(HList); + // \x96{\x95\xB6\x82ƃ^\x83C\x83g\x83\x8B SetDlgItemText(IDC_LISTTEXT, m_Text); SetWindowText(m_Caption); @@ -138,8 +144,6 @@ return TTCDialog::OnCancel(); } -//int MessageBoxHaltScript(HWND hWnd); - BOOL CListDlg::OnClose() { int ret = MessageBoxHaltScript(m_hWnd); @@ -152,14 +156,18 @@ void CListDlg::Relocation(BOOL is_init, int new_WW) { RECT R; - HDC TmpDC; HWND HText, HOk, HCancel, HList; int CW, CH; + int NonClientAreaWidth; + int NonClientAreaHeight; ::GetClientRect(m_hWnd, &R); CW = R.right-R.left; CH = R.bottom-R.top; -#define CONTROL_GAP_W 14 + NonClientAreaWidth = WW - CW; + NonClientAreaHeight = WH - CH; + +#define CONTROL_GAP_W 14 // \x83E\x83B\x83\x93\x83h\x83E\x92[\x82ƃR\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x8AԂƂ̕\x9D // \x8F\x89\x89\xF1\x82̂\xDD if (is_init) { // \x83e\x83L\x83X\x83g\x83R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x83T\x83C\x83Y\x82\xF0\x95 @@ -167,8 +175,9 @@ TW = CW; } // \x83E\x83C\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82̌v\x8EZ - WW = TW + (WW - CW); - WH = TH + LH + (int)(BH*1.5) + (WH - CH); + WW = TW + NonClientAreaWidth; + CW = WW - NonClientAreaWidth; + WH = TH + LH + (int)(BH*1.5) + NonClientAreaHeight; // (\x83{\x83^\x83\x93\x82̍\x82\x82\xB3/2) \x82\xAA\x83E\x83B\x83\x93\x83h\x83E\x92[\x82ƃR\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x8AԂƂ̍\x82\x82\xB3 init_WW = WW; // \x83\x8A\x83X\x83g\x83{\x83b\x83N\x83X\x83T\x83C\x83Y\x82̌v\x8EZ if (LW < CW - BW - CONTROL_GAP_W * 3) { @@ -189,16 +198,17 @@ ::MoveWindow(HList,CONTROL_GAP_W,BH/2,LW,LH,TRUE); ::MoveWindow(HOk,CONTROL_GAP_W+CONTROL_GAP_W+LW,BH/2,BW,BH,TRUE); ::MoveWindow(HCancel,CONTROL_GAP_W+CONTROL_GAP_W+LW,BH*2,BW,BH,TRUE); + ::SetWindowPos(m_hWnd, HWND_TOP,0,0,WW,WH,SWP_NOMOVE); + // PosX\x82\xAA\x83E\x83B\x83\x93\x83h\x83E\x82̊O\x82\xC9-100\x88ȉ\xBA\x82̈ʒu\x82ɂ\xA0\x82\xE9\x8Fꍇ if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) { - ::GetWindowRect(m_hWnd, &R); - TmpDC = ::GetDC(GetSafeHwnd()); - PosX = (GetDeviceCaps(TmpDC,HORZRES)-R.right+R.left) / 2; - PosY = (GetDeviceCaps(TmpDC,VERTRES)-R.bottom+R.top) / 2; - ::ReleaseDC(GetSafeHwnd(),TmpDC); + // \x92\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9 + RECT rcWnd; + CenterWindow(m_hWnd, m_hParentWnd); + GetWindowRect(&rcWnd); + PosX = rcWnd.left; + PosY = rcWnd.top; } - ::SetWindowPos(m_hWnd, HWND_TOP,PosX,PosY,WW,WH,0); ::InvalidateRect(m_hWnd, NULL, TRUE); } - Modified: trunk/teraterm/ttpmacro/ListDlg.h =================================================================== --- trunk/teraterm/ttpmacro/ListDlg.h 2019-07-17 12:12:01 UTC (rev 7856) +++ trunk/teraterm/ttpmacro/ListDlg.h 2019-07-17 15:37:28 UTC (rev 7857) @@ -31,7 +31,7 @@ class CListDlg : public TTCDialog { public: - CListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected, int x, int y); + CListDlg(PCHAR Text, PCHAR Caption, const CHAR **Lists, int Selected, int x, int y); INT_PTR DoModal(); int m_SelectItem; @@ -39,12 +39,13 @@ enum { IDD = IDD_LISTDLG }; PCHAR m_Text; PCHAR m_Caption; - CHAR **m_Lists; + const CHAR **m_Lists; int m_Selected; int PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW, LW, LH; SIZE s; void Relocation(BOOL is_init, int WW); + void InitList(HWND HList); virtual BOOL OnInitDialog(); virtual BOOL OnOK(); Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp =================================================================== --- trunk/teraterm/ttpmacro/ttmdlg.cpp 2019-07-17 12:12:01 UTC (rev 7856) +++ trunk/teraterm/ttpmacro/ttmdlg.cpp 2019-07-17 15:37:28 UTC (rev 7857) @@ -278,7 +278,7 @@ * @retval -1 cancel\x83{\x83^\x83\x93 * @retval -2 close\x83{\x83^\x83\x93 */ -int OpenListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected) +int OpenListDlg(PCHAR Text, PCHAR Caption, const CHAR **Lists, int Selected) { CListDlg ListDlg(Text, Caption, Lists, Selected, DlgPosX, DlgPosY); INT_PTR r = ListDlg.DoModal(); Modified: trunk/teraterm/ttpmacro/ttmdlg.h =================================================================== --- trunk/teraterm/ttpmacro/ttmdlg.h 2019-07-17 12:12:01 UTC (rev 7856) +++ trunk/teraterm/ttpmacro/ttmdlg.h 2019-07-17 15:37:28 UTC (rev 7857) @@ -48,7 +48,7 @@ void CloseStatDlg(); void BringupStatDlg(); -int OpenListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected); +int OpenListDlg(const PCHAR Text, const PCHAR Caption, const CHAR **Lists, int Selected); extern char HomeDir[MAX_PATH]; extern char FileName[MAX_PATH]; Modified: trunk/tests/gui_commands_test.ttl =================================================================== --- trunk/tests/gui_commands_test.ttl 2019-07-17 12:12:01 UTC (rev 7856) +++ trunk/tests/gui_commands_test.ttl 2019-07-17 15:37:28 UTC (rev 7857) @@ -9,7 +9,10 @@ call test_passwordbox call test_statusbox call test_macrodialogbox +type = 1 call test_listbox +type = 2 +call test_listbox messagebox "finish all tests" "test" end @@ -200,9 +203,11 @@ ;;; messagebox :test_listbox N = 7 -intdim done N -strdim strs N -strdim srcs N +if type == 1 then + intdim done N + strdim strs N + strdim srcs N +endif for i 0 N-1 done[i] = 0 next @@ -234,6 +239,11 @@ else msg = "push `cancel`" endif + if type == 2 then + strconcat msg "===================================================================================================" + strconcat msg "\n=\n=\n" + strspecial msg + endif listbox msg "test listbox" strs prev if result < 0 then done_cancel = 1