📄 layout.cpp
字号:
//******************************************************************
// layout.cpp
//
// This file contains the code that lays out the CTrapEventDialog.
// This is neccessary when the edit/view button changes the
// dialog form its small (main) view to the extended view.
//
// Author: Larry A. French
//
// History:
// 20-Febuary-96 Wrote it
//
//
// Copyright (C) 1996 Microsoft Corporation. All rights reserved.
//******************************************************************
#include "stdafx.h"
#include "layout.h"
#include "trapdlg.h"
#include "trapreg.h"
#include "globals.h"
#define CX_MARGIN 10
#define CY_MARGIN 10
#define CY_LEADING 3
#define CY_DIALOG_FONT 8
class CDlgMetrics
{
public:
CDlgMetrics(CEventTrapDlg* pdlg);
CSize m_sizeMargin;
CSize m_sizeAddButton;
CSize m_sizeRemoveButton;
CSize m_sizeFindButton;
CSize m_sizeOKButton;
int m_cyLeading;
CSize m_sizeLabel0;
CSize m_sizeLabel1;
CSize m_sizeLabel2;
CSize m_sizeConfigTypeBox;
CSize m_sizeConfigCustomButton;
CSize m_sizeConfigDefaultButton;
};
//*****************************************************************
// CDlgMetrics::CDlgMetrics
//
// Construct an object containing the metrics for the CEventTrapDlg
//
// Parameters:
// CEventTrapDlg* pdlg
// Pointer to an instance of the main event trap dialog.
// This pointer is used to access members, such as buttons
// and so on so that they can be measured.
//
// Returns:
// The members of this class are valid on return.
//
//*****************************************************************
CDlgMetrics::CDlgMetrics(CEventTrapDlg* pdlg)
{
m_sizeMargin.cx = CX_MARGIN;
m_sizeMargin.cy = CY_MARGIN;
m_cyLeading = CY_LEADING;
CRect rc;
pdlg->m_btnAdd.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeAddButton = rc.Size();
pdlg->m_btnFind.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeFindButton = rc.Size();
pdlg->m_btnRemove.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeRemoveButton = rc.Size();
pdlg->m_statLabel0.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeLabel0 = rc.Size();
pdlg->m_statLabel1.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeLabel1 = rc.Size();
pdlg->m_statLabel2.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeLabel2 = rc.Size();
pdlg->m_btnOK.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeOKButton = rc.Size();
if (g_reg.m_bShowConfigTypeBox) {
pdlg->m_btnConfigTypeBox.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeConfigTypeBox = rc.Size();
pdlg->m_btnConfigTypeCustom.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeConfigCustomButton = rc.Size();
pdlg->m_btnConfigTypeDefault.GetWindowRect(&rc);
pdlg->ScreenToClient(&rc);
m_sizeConfigDefaultButton = rc.Size();
}
else {
// If the "Configuration type box will not be shown, then the size of the
// box and the radio buttons in it are all zero.
pdlg->m_btnConfigTypeBox.GetWindowRect(&rc);
m_sizeConfigTypeBox.cx = 0;
m_sizeConfigTypeBox.cy = 0;
m_sizeConfigCustomButton.cx = 0;
m_sizeConfigCustomButton.cy = 0;
m_sizeConfigDefaultButton.cx = 0;
m_sizeConfigDefaultButton.cy = 0;
}
}
//////////////////////////////////////////////////////////////////////
// CLASS: CMainLayout
//
// This class computes the position of various items for the main (small)
// view of the dialog. The metrics for each of these items is made
// available through public data members.
/////////////////////////////////////////////////////////////////////
class CMainLayout
{
public:
void Create(CDlgMetrics& metrics, CRect& rc);
CRect m_rc;
CRect m_rcLabel0;
CRect m_rcOKButton;
CRect m_rcCancelButton;
CRect m_rcApplyButton;
CRect m_rcPropertiesButton;
CRect m_rcSettingsButton;
CRect m_rcExportButton;
CRect m_rcViewButton;
CRect m_rcListView;
CRect m_rcConfigTypeBox;
CRect m_rcConfigCustomButton;
CRect m_rcConfigDefaultButton;
};
//*****************************************************************
// CMainLayout::Create
//
// Construct the layout for the main part of the dialog. This is
// the part where the add event stuff is hidden.
//
// Note: The caller is responsible for making sure that the
// specified rectangle is large enough so that the display
// still looks good. For example, it doesn't make sense to shrink
// the listview to a zero size or even negative size.
//
// Parameters:
// CDlgMetrics& metrics
// The dialog metrics containing the size of the things
// that appear on the dialog and so on.
//
// CRect& rc
// The rectangle where the main part of the dialog will be
// drawn.
//
// Returns:
// The members of this class are valid on return.
//
//*****************************************************************
void CMainLayout::Create(CDlgMetrics& metrics, CRect& rc)
{
m_rc = rc;
// The rectangle for this layout may actually extend beyond the size
// of the dialog window. This can occur when the user shrinks the dialog
// to a size smaller than the minimum for this layout.
//
// Things that are drawn outside of the dialog are clipped.
//
// Set the rectangle for the "Configuration Type" groupbox
m_rcConfigTypeBox.left = rc.left + metrics.m_sizeMargin.cx;
m_rcConfigTypeBox.top = rc.top + metrics.m_sizeMargin.cy;
m_rcConfigTypeBox.right = rc.right - (metrics.m_sizeOKButton.cx + 2 * metrics.m_sizeMargin.cx);
m_rcConfigTypeBox.bottom = m_rcConfigTypeBox.top + metrics.m_sizeConfigTypeBox.cy;
// Set the rectangle for the "Custom" radio button within the "Configuration Type" groupbox
// We place it right in the middle between the top and the bottom of the groupbox.
m_rcConfigCustomButton.left = m_rcConfigTypeBox.left + metrics.m_sizeMargin.cx;
m_rcConfigCustomButton.top = m_rcConfigTypeBox.top +
(metrics.m_sizeConfigTypeBox.cy/2 - metrics.m_sizeConfigCustomButton.cy/2) + CY_DIALOG_FONT/2;
m_rcConfigCustomButton.right = m_rcConfigCustomButton.left + metrics.m_sizeConfigCustomButton.cx;
m_rcConfigCustomButton.bottom = m_rcConfigCustomButton.top + metrics.m_sizeConfigCustomButton.cy;
// Set the rectangle for the "Default" radio button within the "Configuration Type" groupbox
m_rcConfigDefaultButton.left = m_rcConfigCustomButton.right + metrics.m_sizeMargin.cx;
m_rcConfigDefaultButton.top = m_rcConfigCustomButton.top;
m_rcConfigDefaultButton.right = m_rcConfigDefaultButton.left + metrics.m_sizeConfigDefaultButton.cx;
m_rcConfigDefaultButton.bottom = m_rcConfigCustomButton.bottom;
m_rcLabel0.left = m_rcConfigTypeBox.left;
m_rcLabel0.top = m_rcConfigTypeBox.bottom;
if (metrics.m_sizeConfigTypeBox.cy != 0) {
// If the configuration type groupbox is present, then the event list
// should be placed one margin height below it.
m_rcLabel0.top += metrics.m_sizeMargin.cy;
}
m_rcLabel0.right = m_rcLabel0.left + metrics.m_sizeLabel0.cx;
m_rcLabel0.bottom = m_rcLabel0.top + metrics.m_sizeLabel0.cy;
// Set the position of the top events listview.
m_rcListView.left = m_rcConfigTypeBox.left;
m_rcListView.top = m_rcLabel0.bottom + metrics.m_sizeMargin.cy;
m_rcListView.right = m_rcConfigTypeBox.right;
m_rcListView.bottom = rc.bottom - metrics.m_sizeMargin.cy;
// Set the position of the OK button
m_rcOKButton.left = m_rcListView.right + metrics.m_sizeMargin.cx;
m_rcOKButton.top = m_rcConfigTypeBox.top;
if (metrics.m_sizeConfigTypeBox.cy != 0) {
// If the configuration type groupbox is present, then the OK button should be
// moved down by half the dialog font height so that it lines up with the
// top of the groupbox's rectangle instead of the top of the group box's title.
m_rcOKButton.top += CY_DIALOG_FONT / 2;
}
m_rcOKButton.right = m_rcOKButton.left + metrics.m_sizeOKButton.cx;
m_rcOKButton.bottom = m_rcOKButton.top + metrics.m_sizeOKButton.cy;
// Compute the vertical distance between buttons.
int cyDelta = m_rcOKButton.Height() + metrics.m_sizeMargin.cy / 2;
// Set the position of the Cancel button
m_rcCancelButton = m_rcOKButton;
m_rcCancelButton.OffsetRect(0, cyDelta);
// Set the position of the Apply button
m_rcApplyButton = m_rcCancelButton;
m_rcApplyButton.OffsetRect(0, cyDelta);
// Set the position of the settings button
m_rcSettingsButton = m_rcApplyButton;
m_rcSettingsButton.OffsetRect(0, cyDelta);
// Set the position of the properties button
m_rcPropertiesButton = m_rcSettingsButton;
m_rcPropertiesButton.OffsetRect(0, cyDelta);
// Set the position of the export button
m_rcExportButton = m_rcPropertiesButton;
m_rcExportButton.OffsetRect(0, cyDelta);
// Set the position of the view button
m_rcViewButton = m_rcExportButton;
m_rcViewButton.OffsetRect(0, cyDelta);
}
//////////////////////////////////////////////////////////////////////
// CLASS: CExtendedLayout
//
// This class computes the position of various items for the extended
// view of the dialog. The metrics for each of these items is made
// available through public data members.
/////////////////////////////////////////////////////////////////////
class CExtendedLayout
{
public:
void Create(CDlgMetrics& metrics, CRect& rc);
CRect m_rc;
CRect m_rcTreeView;
CRect m_rcListView;
CRect m_rcFindButton;
CRect m_rcAddButton;
CRect m_rcRemoveButton;
CRect m_rcLabel1;
CRect m_rcLabel2;
private:
};
//*****************************************************************
// CExtendedLayout::Create
//
// Construct the layout for the extended part of the dialog. This is
// the part where the add event stuff is shown.
//
// Note: The caller is responsible for making sure that the
// specified rectangle is large enough so that the display
// still looks good. For example, it doesn't make sense to shrink
// the listview to a zero size or even negative size.
//
// Parameters:
// CDlgMetrics& metrics
// The dialog metrics containing the size of the things
// that appear on the dialog and so on.
//
// CRect& rc
// The rectangle where the main part of the dialog will be
// drawn.
//
// Returns:
// The members of this class are valid on return.
//
//*****************************************************************
void CExtendedLayout::Create(CDlgMetrics& metrics, CRect& rc)
{
m_rc = rc;
CRect rcTemp;
// Calculate the combined width of the treeview and listview.
// We subtract 3 * CX_MARGIN because there is a margin on
// the left and right and another margin to separate the right
// side of the list view from the button.
int cxViews = rc.Width() - (2*metrics.m_sizeMargin.cx);
int cxTreeView = cxViews * 2 / 5;
int cxListView = cxViews - cxTreeView;
// Set the location of the add button. This should be aligned with
// the left side of the listview and one margin height below the
// top of the given rectangle.
m_rcAddButton.left = m_rc.left + metrics.m_sizeMargin.cx/2 + cxTreeView - metrics.m_sizeAddButton.cx;
m_rcAddButton.top = m_rc.top + metrics.m_cyLeading;
m_rcAddButton.right = m_rcAddButton.left + metrics.m_sizeAddButton.cx;
m_rcAddButton.bottom = m_rcAddButton.top + metrics.m_sizeAddButton.cy;
// Set the location of the remove button. This should be aligned with the
// top of the "Add" button and one margin size to the right of the add button.
m_rcRemoveButton.left = m_rcAddButton.right + metrics.m_sizeMargin.cx;
m_rcRemoveButton.top = m_rcAddButton.top;
m_rcRemoveButton.right = m_rcRemoveButton.left + metrics.m_sizeRemoveButton.cx;
m_rcRemoveButton.bottom = m_rcRemoveButton.top + metrics.m_sizeRemoveButton.cy;
// Set the location of label1. This is the label at the top-left
// of the tree control
m_rcLabel1.left = m_rc.left + metrics.m_sizeMargin.cx;
m_rcLabel1.top = m_rcRemoveButton.bottom + metrics.m_cyLeading + metrics.m_sizeMargin.cy;
m_rcLabel1.right = m_rcLabel1.left + metrics.m_sizeLabel1.cx;
m_rcLabel1.bottom = m_rcLabel1.top + metrics.m_sizeLabel1.cy;
// Set the location of label2. This is at the top-left of the list box.
m_rcLabel2.left = m_rcLabel1.left + cxTreeView;
m_rcLabel2.top = m_rcLabel1.top;
m_rcLabel2.right = m_rcLabel2.left + metrics.m_sizeLabel2.cx;
m_rcLabel2.bottom = m_rcLabel2.top + metrics.m_sizeLabel2.cy;
// Set the location of the tree view. This is one margin size from
// the left of m_rc and one margin size below the labels. The width
// has been calulated above. There is also a margin reserved on the
// bottom.
m_rcTreeView.left = m_rc.left + metrics.m_sizeMargin.cx;
m_rcTreeView.top = m_rcLabel2.bottom + 1; // + metrics.m_sizeMargin.cy;
m_rcTreeView.right = m_rcTreeView.left + cxTreeView;
m_rcTreeView.bottom = m_rc.bottom - metrics.m_sizeMargin.cy;
// Set the location of the list view. This is the same height as the
// tree view and aligned so that its left side is adjacent to the
// right side of the treeview. Its width has been calculated above.
m_rcListView.left = m_rcTreeView.right - 1;
m_rcListView.top = m_rcTreeView.top;
m_rcListView.right = m_rcListView.left + cxListView;
m_rcListView.bottom = m_rcTreeView.bottom;
// Set the location of the find button so that it is aligned with the top of the
// list view and so that its right side is one margin widh from m_rc.right.
m_rcFindButton.left = m_rc.right - metrics.m_sizeFindButton.cx - metrics.m_sizeMargin.cx;
m_rcFindButton.top = m_rcAddButton.top;
m_rcFindButton.right = m_rcFindButton.left + metrics.m_sizeFindButton.cx;
m_rcFindButton.bottom = m_rcFindButton.top + metrics.m_sizeFindButton.cy;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -