Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PPageBase.cpp « mpc-hc « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 554221a586873017644b889a70c2c0f4c067f8a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * (C) 2003-2006 Gabest
 * (C) 2006-2014 see Authors.txt
 *
 * This file is part of MPC-HC.
 *
 * MPC-HC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * MPC-HC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "stdafx.h"
#include "MainFrm.h"
#include "mplayerc.h"
#include "PPageBase.h"
#include "SettingsDefines.h"

// CPPageBase dialog

IMPLEMENT_DYNAMIC(CPPageBase, CCmdUIPropertyPage)
CPPageBase::CPPageBase(UINT nIDTemplate, UINT nIDCaption)
    : CCmdUIPropertyPage(nIDTemplate, nIDCaption)
{
}

CPPageBase::~CPPageBase()
{
}

void CPPageBase::DoDataExchange(CDataExchange* pDX)
{
    __super::DoDataExchange(pDX);
}

bool CPPageBase::FillComboToolTip(CComboBox& comboBox, TOOLTIPTEXT* pTTT)
{
    bool bNeedTooltip = false;

    CDC* pDC = comboBox.GetDC();
    CFont* pFont = comboBox.GetFont();
    CFont* pOldFont = pDC->SelectObject(pFont);

    TEXTMETRIC tm;
    pDC->GetTextMetrics(&tm);

    CRect comboBoxRect;
    comboBox.GetWindowRect(comboBoxRect);
    comboBoxRect.right -= GetSystemMetrics(SM_CXVSCROLL) + 2 * GetSystemMetrics(SM_CXEDGE);

    int i = comboBox.GetCurSel();
    CString str;
    comboBox.GetLBText(i, str);
    CSize textSize;
    textSize = pDC->GetTextExtent(str);
    pDC->SelectObject(pOldFont);
    comboBox.ReleaseDC(pDC);
    textSize.cx += tm.tmAveCharWidth;

    if (textSize.cx > comboBoxRect.Width()) {
        bNeedTooltip = true;
        if (str.GetLength() > _countof(pTTT->szText) - 1) {
            str.Truncate(_countof(pTTT->szText) - 1);
        }
        _tcscpy_s(pTTT->szText, str);
        pTTT->hinst = nullptr;
    }

    return bNeedTooltip;
}

void CPPageBase::CreateToolTip()
{
    m_wndToolTip.Create(this, TTS_NOPREFIX);
    m_wndToolTip.Activate(TRUE);
    m_wndToolTip.SetMaxTipWidth(300);
    m_wndToolTip.SetDelayTime(TTDT_AUTOPOP, 10000);
    for (CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetWindow(GW_HWNDNEXT)) {
        CString strToolTip;
        if (strToolTip.LoadString(pChild->GetDlgCtrlID())) {
            m_wndToolTip.AddTool(pChild, strToolTip);
        }
    }
}

void CPPageBase::SetButtonIcon(UINT nIDButton, UINT nIDIcon)
{
    if (!m_buttonIcons.count(nIDIcon)) {
        CImage img;
        img.LoadFromResource(AfxGetInstanceHandle(), nIDIcon);
        CImageList& imageList = m_buttonIcons[nIDIcon];
        imageList.Create(img.GetWidth(), img.GetHeight(), ILC_COLOR32, 1, 0);
        imageList.Add(CBitmap::FromHandle(img), nullptr);
    }

    BUTTON_IMAGELIST buttonImageList;
    buttonImageList.himl = m_buttonIcons[nIDIcon];
    buttonImageList.margin = { 0, 0, 0, 0 };
    buttonImageList.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
    static_cast<CButton*>(GetDlgItem(nIDButton))->SetImageList(&buttonImageList);
}

BOOL CPPageBase::PreTranslateMessage(MSG* pMsg)
{
    if (IsWindow(m_wndToolTip))
        if (pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST) {
            MSG msg;
            memcpy(&msg, pMsg, sizeof(MSG));
            for (HWND hWndParent = ::GetParent(msg.hwnd);
                    hWndParent && hWndParent != m_hWnd;
                    hWndParent = ::GetParent(hWndParent)) {
                msg.hwnd = hWndParent;
            }

            if (msg.hwnd) {
                m_wndToolTip.RelayEvent(&msg);
            }
        }

    return __super::PreTranslateMessage(pMsg);
}

BEGIN_MESSAGE_MAP(CPPageBase, CCmdUIPropertyPage)
    ON_WM_DESTROY()
END_MESSAGE_MAP()


// CPPageBase message handlers

BOOL CPPageBase::OnSetActive()
{
    AfxGetAppSettings().nLastUsedPage = (UINT)m_pPSP->pszTemplate;
    return __super::OnSetActive();
}

BOOL CPPageBase::OnApply()
{
    // There is no main frame when the option dialog is displayed stand-alone
    if (CMainFrame* pMainFrame = AfxGetMainFrame()) {
        pMainFrame->PostMessage(WM_SAVESETTINGS);
    }
    return __super::OnApply();
}

void CPPageBase::OnDestroy()
{
    __super::OnDestroy();
    m_wndToolTip.DestroyWindow();
}