OSDN Git Service

Allow NUL and \\.\NUL in paths specified as command line arguments (#2056)
[winmerge-jp/winmerge-jp.git] / Src / AboutDlg.cpp
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** 
3  * @file  AboutDlg.cpp
4  *
5  * @brief Implementation of the About-dialog.
6  *
7  */
8
9 #include "stdafx.h"
10 #include "AboutDlg.h"
11 #include "TrDialogs.h"
12 #include "Bitmap.h"
13 #include "resource.h" // IDD_ABOUTBOX
14
15  // https://www.gnu.org/graphics/gnu-ascii.html
16  // Copyright (c) 2001 Free Software Foundation, Inc.
17  // Converted with https://tomeko.net/online_tools/cpp_text_escape.php
18 static const char gnu_ascii[] =
19 "  ,           ,\n"
20 " /             \\\n"
21 "((__-^^-,-^^-__))\n"
22 " `-_---' `---_-'\n"
23 "  `--|o` 'o|--'\n"
24 "     \\  `  /\n"
25 "      ): :(\n"
26 "      :o_o:\n"
27 "       \"-\"";
28
29 /** 
30  * @brief About-dialog class.
31  * 
32  * Shows About-dialog bitmap and draws version number and other
33  * texts into it.
34  */
35 class CAboutDlg::Impl : public CTrDialog
36 {
37 public:
38         explicit Impl(CAboutDlg *p, CWnd* pParent = nullptr);
39
40 // Dialog Data
41         //{{AFX_DATA(CAboutDlg::Impl)
42         enum { IDD = IDD_ABOUTBOX };
43         //}}AFX_DATA
44
45         // ClassWizard generated virtual function overrides
46         //{{AFX_VIRTUAL(CAboutDlg::Impl)
47         protected:
48         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
49         //}}AFX_VIRTUAL
50
51 // Implementation
52 protected:
53         //{{AFX_MSG(CAboutDlg::Impl)
54         virtual BOOL OnInitDialog();
55         //}}AFX_MSG
56         DECLARE_MESSAGE_MAP()
57 public:
58         afx_msg void OnBnClickedOpenContributors();
59         afx_msg BOOL OnEraseBkgnd(CDC* pDC);
60         afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
61         afx_msg void OnBnClickedWWW(NMHDR *pNMHDR, LRESULT *pResult);
62
63 private:
64         CAboutDlg *const m_p;
65         ATL::CImage m_image;
66         CFont m_font;
67         CFont m_font_gnu_ascii;
68 };
69
70 BEGIN_MESSAGE_MAP(CAboutDlg::Impl, CTrDialog)
71         //{{AFX_MSG_MAP(CAboutDlg::Impl)
72         //}}AFX_MSG_MAP
73         ON_BN_CLICKED(IDC_OPEN_CONTRIBUTORS, OnBnClickedOpenContributors)
74         ON_WM_ERASEBKGND()
75         ON_WM_CTLCOLOR()
76         ON_NOTIFY(NM_CLICK, IDC_WWW, OnBnClickedWWW)
77 END_MESSAGE_MAP()
78
79 CAboutDlg::Impl::Impl(CAboutDlg *p, CWnd* pParent /*= nullptr*/)
80         : CTrDialog(CAboutDlg::Impl::IDD)
81         , m_p(p)
82 {
83         m_font.CreatePointFont(10 * 10, _T("Tahoma"));
84         LOGFONT lf = { 0 };
85         lf.lfHeight = 14 * 10;
86         lf.lfWeight = FW_BOLD;
87         _tcscpy_s(lf.lfFaceName, _T("Courier New"));
88         m_font_gnu_ascii.CreatePointFontIndirect(&lf);
89 }
90
91 void CAboutDlg::Impl::DoDataExchange(CDataExchange* pDX)
92 {
93         CTrDialog::DoDataExchange(pDX);
94         //{{AFX_DATA_MAP(CAboutDlg::Impl)
95         DDX_Text(pDX, IDC_COMPANY, m_p->m_info.copyright);
96         DDX_Text(pDX, IDC_VERSION, m_p->m_info.version);
97         //}}AFX_DATA_MAP
98 }
99
100 /** 
101  * @brief Read version info from resource to dialog.
102  */
103 BOOL CAboutDlg::Impl::OnInitDialog() 
104 {
105         CTrDialog::OnInitDialog();
106
107         if (!LoadImageFromResource(m_image, MAKEINTRESOURCE(IDR_SPLASH), _T("IMAGE")))
108         {
109                 // FIXME: LoadImageFromResource() seems to fail when running on Wine 5.0.
110         }
111
112         GetDlgItem(IDC_VERSION)->SetFont(&m_font);
113         GetDlgItem(IDC_GNU_ASCII)->SetFont(&m_font_gnu_ascii);
114         ::SetDlgItemTextA(m_hWnd, IDC_GNU_ASCII, gnu_ascii);
115
116         String link;
117         GetDlgItemText(IDC_WWW, link);
118         link = _T("<a href=\"") + m_p->m_info.website + _T("\">") + link + _T("</a>");
119         SetDlgItemText(IDC_WWW, link);  
120
121         UpdateData(FALSE);
122         
123         return TRUE;  // return TRUE unless you set the focus to a control
124                       // EXCEPTION: OCX Property Pages should return FALSE
125 }
126
127 HBRUSH CAboutDlg::Impl::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
128 {
129         if (nCtlColor == CTLCOLOR_STATIC)
130         {
131                 if (pWnd->GetDlgCtrlID() == IDC_GNU_ASCII)
132                         pDC->SetTextColor(RGB(128, 128, 128));
133                 pDC->SetBkMode(TRANSPARENT);
134                 return (HBRUSH)GetStockObject(NULL_BRUSH);
135         }
136         return CTrDialog::OnCtlColor(pDC, pWnd, nCtlColor);
137 }
138
139 BOOL CAboutDlg::Impl::OnEraseBkgnd(CDC* pDC)
140 {
141         if (!m_image)
142                 return FALSE;
143         CRect rc, rcCompany;
144         GetClientRect(&rc);
145         GetDlgItem(IDC_COMPANY)->GetWindowRect(&rcCompany);
146         ScreenToClient(&rcCompany);
147         rc.top = rcCompany.bottom;
148         pDC->FillSolidRect(&rc, GetSysColor(COLOR_BTNFACE));
149         rc.bottom = rc.top;
150         rc.top = 0;
151         m_image.Draw(pDC->m_hDC, rc, Gdiplus::InterpolationModeBicubic);
152         return TRUE;
153 }
154
155 /**
156  * @brief Show contributors list.
157  * Opens Contributors.txt into notepad.
158  */
159 void CAboutDlg::Impl::OnBnClickedOpenContributors()
160 {
161         int tmp = 0;
162         m_p->m_onclick_contributers.notify(m_p, tmp);
163 }
164
165 void CAboutDlg::Impl::OnBnClickedWWW(NMHDR *pNMHDR, LRESULT *pResult)
166 {
167         int tmp = 0;
168         m_p->m_onclick_url.notify(m_p, tmp);
169 }
170
171 CAboutDlg::CAboutDlg() : m_pimpl(new CAboutDlg::Impl(this)) {}
172 CAboutDlg::~CAboutDlg() = default;
173 int CAboutDlg::DoModal() { return static_cast<int>(m_pimpl->DoModal()); }