-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseColorDialog.cpp
105 lines (85 loc) · 2.87 KB
/
BaseColorDialog.cpp
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
// BaseColorDialog.cpp : implementation file
//
#include "stdafx.h"
#include "SCIPicEditor.h"
#include "BaseColorDialog.h"
// CBaseColorDialog dialog
CBaseColorDialog::CBaseColorDialog(UINT nID, CWnd* pParent)
: CExtResizableDialog(nID, pParent)
{
_fUseTrack = FALSE;
RECT rc = { 0 };
m_wndDummyOwner.CreateEx(WS_EX_NOACTIVATE, TEXT("STATIC"), TEXT("SCI popup owner"), WS_POPUP, rc, NULL, 0);
m_wndDummyOwner.EnableWindow(FALSE); // Disable it, to trick MFC
// Trick MFC - use the desktop window as the owner, so it doesn't disable the app.
// (so we can click away, deactivate the dialog and close it)
this->m_pParentWnd = &m_wndDummyOwner;//CWnd::FromHandle(::GetDesktopWindow());
}
CBaseColorDialog::~CBaseColorDialog()
{
}
BEGIN_MESSAGE_MAP(CBaseColorDialog, CExtResizableDialog)
ON_WM_ACTIVATE()
END_MESSAGE_MAP()
// CBaseColorDialog message handlers
void CBaseColorDialog::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
{
// If we're being de-activated, and we haven't already been "ended", then end
// will cancel now. This makes us act like a popup.
if (!_fEnded && (nState == WA_INACTIVE))
{
// We'd better set this, otherwise we'll end up in an infinite loop. We'll continue
// to be make inactivate via EndDialog.
_fEnded = TRUE;
// Don't set IDCANCEL if someone already ended us.
EndDialog(IDCANCEL);
}
}
BOOL CBaseColorDialog::OnInitDialog()
{
_fEnded = FALSE;
BOOL bRet = __super::OnInitDialog();
ShowSizeGrip(FALSE);
_SetPosition();
return bRet;
}
void CBaseColorDialog::_SetPosition()
{
if (_fUseTrack)
{
// Calculate the most appropriate position for the left-top corner of control
// By default, at left and bottom of the caller
CPoint pt(_rcTrack.left, _rcTrack.bottom);
RECT rcCtrl;
GetClientRect(&rcCtrl);
// Alignment at right if necessary
if (pt.x + RECTWIDTH(rcCtrl) > ::GetSystemMetrics (SM_CXSCREEN))
{
pt.x = _rcTrack.right - RECTWIDTH(rcCtrl);
}
// Alignment at top if necessary
if (pt.y + RECTHEIGHT(rcCtrl) > ::GetSystemMetrics (SM_CYSCREEN))
{
pt.y = _rcTrack.top - RECTHEIGHT(rcCtrl);
}
// Adjustments to keep control into screen
if (pt.x + RECTWIDTH(rcCtrl) > ::GetSystemMetrics (SM_CXSCREEN))
{
pt.x = ::GetSystemMetrics (SM_CXSCREEN) - RECTWIDTH(rcCtrl);
}
if (pt.y + RECTHEIGHT(rcCtrl) > ::GetSystemMetrics (SM_CYSCREEN))
{
pt.y = ::GetSystemMetrics (SM_CYSCREEN)- RECTHEIGHT(rcCtrl);
}
if (pt.x < 0)
{
pt.x = 0;
}
if (pt.y < 0)
{
pt.y = 0;
}
RECT rcNew = { pt.x, pt.y, pt.x + RECTWIDTH(rcCtrl), pt.y + RECTHEIGHT(rcCtrl) };
MoveWindow(&rcNew);
}
}