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

layout.cpp « windirstat - github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 682463036e1a5a18231a69e49279da8fc966e28b (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
// layout.cpp	- Implementation of CLayout
//
// WinDirStat - Directory Statistics
// Copyright (C) 2003 Bernhard Seifert
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Author: bseifert@users.sourceforge.net, bseifert@daccord.net

#include "stdafx.h"
#include "windirstat.h"
#include "options.h"
#include "layout.h"


CLayout::CLayout(CWnd *dialog, LPCTSTR name)
{
	ASSERT(dialog != NULL);
	m_dialog= dialog;
	m_name= name;

	// This is necessary because OnGetMinMaxInfo() will be called
	// before OnInitDialog!
	m_originalDialogSize.cx= 0;
	m_originalDialogSize.cy= 0;
}

void CLayout::AddControl(CWnd *control, double movex, double movey, double stretchx, double stretchy)
{
	SControlInfo info;
	
	info.control= control;
	info.movex= movex;
	info.movey= movey;
	info.stretchx= stretchx;
	info.stretchy= stretchy;
	
	m_control.Add(info);
}

void CLayout::AddControl(UINT id, double movex, double movey, double stretchx, double stretchy)
{
	AddControl(m_dialog->GetDlgItem(id), movex, movey, stretchx, stretchy);
}

void CLayout::OnInitDialog(bool centerWindow)
{
	m_dialog->SetIcon(GetApp()->LoadIcon(IDR_MAINFRAME), false);

	CRect rc;
	m_dialog->GetWindowRect(rc);
	m_originalDialogSize= rc.Size();

	for (int i=0; i < m_control.GetSize(); i++)
	{
		CRect rc;
		m_control[i].control->GetWindowRect(rc);
		m_dialog->ScreenToClient(rc);
		m_control[i].originalRectangle= rc;
	}

	CPersistence::GetDialogRectangle(m_name, rc);
	m_dialog->MoveWindow(rc);
	if (centerWindow)
		m_dialog->CenterWindow();
}

void CLayout::OnDestroy()
{
	CRect rc;
	m_dialog->GetWindowRect(rc);
	CPersistence::SetDialogRectangle(m_name, rc);
}

void CLayout::OnSize()
{
	CRect rc;
	m_dialog->GetWindowRect(rc);
	CSize newDialogSize= rc.Size();

	CSize diff= newDialogSize - m_originalDialogSize;

	for (int i=0; i < m_control.GetSize(); i++)
	{
		CRect rc= m_control[i].originalRectangle;

		CSize move(int(diff.cx * m_control[i].movex), int(diff.cy * m_control[i].movey));
		CRect stretch(0, 0, int(diff.cx * m_control[i].stretchx), int(diff.cy * m_control[i].stretchy));
		
		rc+= move;
		rc+= stretch;

		m_control[i].control->MoveWindow(rc);
	}
}

void CLayout::OnGetMinMaxInfo(MINMAXINFO *mmi)
{
	mmi->ptMinTrackSize.x= m_originalDialogSize.cx;
	mmi->ptMinTrackSize.y= m_originalDialogSize.cy;
}