📄 resizedialog.h
字号:
/*------------------------------------------------------------------------------*
* File Name:ResizeDialog.h *
* Creation: CPY 6/12/2003 *
* Purpose: OriginC Header file for basic dialog functions *
* Copyright (c) Originlab Corp. 2003, 2004, 2005, 2006, *
* All Rights Reserved *
* *
* Modification Log: *
* DVT 8/1/03 TWO_GAPS_WHEN_BOTTOM_NULL *
* CPY 9/13/03 PLOT_SETUP_PANEL_RESIZE_FROM_INSIDE_GRID *
*------------------------------------------------------------------------------*/
#include <Tree_utils.h>
#ifndef _RESIZE_CONTROL_H_
#include "ResizeControl.h"
#endif //_RESIZE_CONTROL_H_
#define FACTOR_ORIG_TO_MIN 0.8
enum{ PANEL_ORIENT_NONE, PANEL_ORIENT_VERTICAL, PANEL_ORIENT_HORIZONTAL };
#define MAX_ALLOWED_PANELS 5
class ResizeDialog : public Dialog
{
public:
ResizeDialog(UINT nDlgID, LPCSTR lpcszDLL) : Dialog(nDlgID, lpcszDLL)
{
m_bRepaintWhenMove = true;
/// TD 8-26-03 RESIZING
m_bDoNotHandleOnSize = true;
m_nNumPanels = 0;
for(int ii = 0; ii < MAX_ALLOWED_PANELS; ii++)
{
m_parrPanels[ii] = NULL;
}
/// ----TD 8-26-03 RESIZING
}
void SetControlGap(int nEdge) {m_nEdge = nEdge;}
void AddPanel(ResizeControl* pPanel)
{
m_parrPanels[m_nNumPanels++] = pPanel;
}
virtual string GetRuntimeClass()
{
return "ResizeDialog";
}
protected:
//---- CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP
void SaveDlgHeight() { m_nDlgHight = GetDlgExtent();}
BOOL OnResize(int nType, int cx, int cy) // return TRUE only if OnSize is enabled
{
if(m_bDoNotHandleOnSize)
{
//m_nDlgHight = cy;
return FALSE;
}
resizePanelsOnDlgResize(cx, cy);
return TRUE;
}
//---- CPY 9/13/03 PLOT_SETUP_PANEL_RESIZE_FROM_INSIDE_GRID
// wParam = Panel index, 0 = wks List, 1 = col List, 3 = Plot List for example, this is the panel that we need to increase/decrease its height
// lParam = LPARAM_RESIZE_CONTROLS_INCREASE, LPARAM_RESIZE_CONTROLS_DECREASE
//
BOOL OnIncreaseDecreasePanelSize(uint wParam, uint lParam)
{
bool bIncrease = LPARAM_RESIZE_CONTROLS_INCREASE == lParam? true:false;
int nSizeDiff = 0;
if(wParam < getNumOfPanels())
{
ResizeControl *pKeyPanel = m_parrPanels[wParam];
if(!bIncrease || isDlgSmallerThenScreen(0, 0.9)) // simply decrease given panel
{
nSizeDiff = bIncrease? pKeyPanel->GetHeight() * (-0.75) : pKeyPanel->GetHeight() * 0.45;
pKeyPanel->SetHeight(pKeyPanel->GetHeight() - nSizeDiff);
return true;
}
// to increase, we will try not to increase the dialog since often there is no space to expand dialog
// so we will need to grab space from other panels. To do this, we ask each panel how much it can give up
// by comparing its current height and its GetMinHeight(true), so the extra is what we can add to the current (wParam) panel
int nDiffs[MAX_ALLOWED_PANELS];
int ii, ny, nTotal = 0;
for(ii = 0; ii < getNumOfPanels(); ii++)
{
nDiffs[ii] = 0;
if(wParam == ii)
continue;
if(m_parrPanels[ii]->IsVisible())
{
int ndiff = m_parrPanels[ii]->GetHeight() - m_parrPanels[ii]->GetMinHeight(true);
if(ndiff < 0)
ndiff = 0;
nTotal += ndiff;
nDiffs[ii] = ndiff;
}
}
ny = pKeyPanel->GetHeight();
int nn = pKeyPanel->GetMaxHeight(true);
if(ny > nn)
ny = nn;
nSizeDiff = nTotal;
if(0 == nSizeDiff || nSizeDiff > 0.4 * ny)
nSizeDiff = 0.4 * ny;
double factor = nSizeDiff / (double)nTotal;
for(ii = 0; ii < getNumOfPanels(); ii++)
{
if(wParam == ii)
continue;
if(nDiffs[ii] > 0)
m_parrPanels[ii]->SetHeight(m_parrPanels[ii]->GetHeight() - (0.5 + factor*nDiffs[ii]));
}
pKeyPanel->SetHeight(pKeyPanel->GetHeight() + nSizeDiff);
}
return TRUE;
}
//---- end PLOT_SETUP_PANEL_RESIZE_FROM_INSIDE_GRID
int GetTotalHeight(bool bMin = false) // by summing up each panels, assume vertical, need to modify if to support general
{
int nTotalHeight = 0;
bool bAnyVisible = false;
for(int ii = 0; ii < getNumOfPanels(); ii++)
{
if(m_parrPanels[ii]->IsVisible())
{
bAnyVisible = true;
nTotalHeight += m_parrPanels[ii]->GetPanelHeight(bMin) + GetControlGap();
}
}
if(bAnyVisible)
nTotalHeight -= GetControlGap();
return nTotalHeight;
}
int GetTotalWidth(bool bGetMin = false)
{
int mx, nx = 0;
for(int ii = 0; ii < getNumOfPanels(); ii++)
{
if(m_parrPanels[ii]->IsVisible())
{
mx = m_parrPanels[ii]->GetPanelWidth(true);
if(GetPanelsOrientation() == PANEL_ORIENT_VERTICAL && mx > nx)
nx = mx;
else if(GetPanelsOrientation() == PANEL_ORIENT_HORIZONTAL)
nx += mx; // + GetControlGap()
}
}
return nx;
}
//---- end CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP
bool SetMoveRepaint(bool bRepaint = true)
{
bool bOldVal = m_bRepaintWhenMove;
m_bRepaintWhenMove = bRepaint;
return bOldVal;
}
int GetDlgExtent(bool bVertial = true)
{
RECT r1;
m_wndDlg.GetClientRect(&r1);
return bVertial? r1.bottom : r1.right;
}
int GetControlGap() { return m_nEdge; }
HWND GetSafeHwnd()
{
return m_wndDlg.GetSafeHwnd();
}
void ShowControls(uint nButtonIDs[], bool bShow = true)
{
int ii = 0;
while(nButtonIDs[ii] > 0)
{
Control btn = GetItem(nButtonIDs[ii]);
if(btn)
btn.Visible = bShow;
ii++;
}
}
void EnableControls(uint nButtonIDs[], bool bEnable = true)
{
int ii = 0;
while(nButtonIDs[ii] > 0)
{
Control btn = GetItem(nButtonIDs[ii]);
if(btn)
btn.Enable = bEnable;
ii++;
}
}
void CheckButtons(uint nButtonIDs[], bool bCheck = true)
{
int ii = 0;
while(nButtonIDs[ii] > 0)
{
Button btn = GetItem(nButtonIDs[ii]);
if(btn)
btn.Check = bCheck;
ii++;
}
}
// use default gap if nGap < 0
// return the right most x position
int ArrangControlsTopDown(uint nButtonIDs[], int nx, int ny, int nGap = -1)
{
RECT rr, r1;
rr.left = nx;
rr.top = ny;
if(nGap < 0)
nGap = m_nEdge;
int ii = 0;
int nMaxWidth = 0;
while(nButtonIDs[ii] > 0)
{
Control btn = GetItem(nButtonIDs[ii]);
if(btn && btn.Visible)
{
btn.GetWindowRect(&r1);
rr.bottom = rr.top + RECT_HEIGHT(r1);
if(nMaxWidth < RECT_WIDTH(r1))
nMaxWidth = RECT_WIDTH(r1);
rr.right = rr.left + RECT_WIDTH(r1);
btn.MoveWindow(&rr, m_bRepaintWhenMove);
rr.top = rr.bottom + nGap;
}
ii++;
}
return nx + nMaxWidth;
}
// starting from nx, ny as the top-right position, move controls one after another to
// the left, nGap < 0 will use default gap between controls
// return the lowest y position
int ArrangeControlsRightLeft(uint nButtonIDs[], int nx, int ny, int nGap = -1)
{
RECT rr, r1;
if(nGap < 0)
nGap = m_nEdge;
rr.right = nx - nGap;
rr.top = ny;
int ii = 0;
int nMaxHeight = 0;
while(nButtonIDs[ii] > 0)
{
Control btn = GetItem(nButtonIDs[ii]);
if(btn && btn.Visible)
{
btn.GetWindowRect(&r1);
rr.left = rr.right - RECT_WIDTH(r1);
if(nMaxHeight < RECT_HEIGHT(r1))
nMaxHeight = RECT_HEIGHT(r1);
rr.bottom = rr.top + RECT_HEIGHT(r1);
btn.MoveWindow(&rr, m_bRepaintWhenMove);
rr.right = rr.left - nGap;
}
ii++;
}
return ny + nMaxHeight;
}
// position nMainID as top-left and move nIDsRight group of controls to the far right and nIDsBottom to the left bottom
//nIDsRight should be moved only horizontally, while nIDsBottom should be moved only vertically
//nMainID should be resize right-bottom, while keeping top-left
//cx is the right most x pixel
//cy is the bottom y pixel
bool ResizeMoveControlsRightBottom(int nMainID, uint nRightIDs[], uint nBottomIDs[], int cx, int cy)
{
int nRightGroupWidth = getControlGroupExtent(nRightIDs, true);
int nBottomGroupHeight = getControlGroupExtent(nBottomIDs, false);
int nRightGroupLeft = cx - m_nEdge - nRightGroupWidth;
int nBottomGroupTop = cy - m_nEdge - nBottomGroupHeight;
RECT r1;
r1.left = 0;
if(nRightIDs && !GetControlClientRect(nRightIDs[0], r1))
return false;
int nRightGroupOffset = nRightGroupLeft - r1.left;
r1.top = 0;
if(nBottomIDs && !GetControlClientRect(nBottomIDs[0], r1))
return false;
int nBottomGroupOffset = nBottomGroupTop - r1.top;
Control cMain;
if(!GetControlClientRect(nMainID, r1, &cMain))
return false;
r1.right = nRightGroupLeft - m_nEdge;
/// DVT 8/1/03 TWO_GAPS_WHEN_BOTTOM_NULL
//r1.bottom = nBottomGroupTop - m_nEdge;
r1.bottom = nBottomGroupTop;
if(nBottomIDs)
r1.bottom -= m_nEdge;
/// end TWO_GAPS_WHEN_BOTTOM_NULL
cMain.MoveWindow(&r1, m_bRepaintWhenMove);
if(nRightIDs)
MoveControls(nRightIDs, nRightGroupOffset, 0);
if(nBottomIDs)
MoveControls(nBottomIDs, 0, nBottomGroupOffset);
return true;
}
void MakeSameSize(uint nIDs[], bool bVert = true)
{
RECT r0;
Control btnRef = GetItem(nIDs[0]);
btnRef.GetWindowRect(&r0);
int ii = 1;
while(nIDs[ii] > 0)
{
RECT r1;
Control btn;
if(GetControlClientRect(nIDs[ii], r1, &btn))
{
if(bVert)
r1.bottom = r1.top + RECT_HEIGHT(r0);
else
r1.right = r1.left + RECT_WIDTH(r0);
btn.MoveWindow(&r1, m_bRepaintWhenMove);
}
ii++;
}
return;
}
bool GetControlClientRect(uint nID, RECT& r1, Control* pCntrl = NULL)
{
Control btn;
if(NULL == pCntrl)
pCntrl = &btn;
*pCntrl = GetItem(nID);
if(*pCntrl)
{
pCntrl->GetWindowRect(&r1);
m_wndDlg.ScreenToClient(&r1);
return true;
}
return false;
}
void MoveControls(uint nIDs[], int nDx, int nDy)
{
int ii = 0;
while(nIDs[ii] > 0)
{
RECT r1;
Control btn;
if(GetControlClientRect(nIDs[ii], r1, &btn))
{
OffsetRect(&r1, nDx, nDy);
btn.MoveWindow(&r1, m_bRepaintWhenMove);
}
ii++;
}
}
// return top if bTop = false, return bottom if bTop = true
int PositionControl(uint nID, int nx, int ny, bool bTop = true, bool bCheckVisible = true)
{
Control btn = GetItem(nID);
int nRet = ny;
if(btn && (!bCheckVisible || btn.Visible))
{
RECT rr, r1;
btn.GetWindowRect(&r1);
rr.left = nx;
if(bTop)
{
rr.top = ny, rr.bottom = ny + RECT_HEIGHT(r1);
nRet = rr.bottom;
}
else
{
rr.bottom = ny, rr.top = ny - RECT_HEIGHT(r1);
nRet = rr.top;
}
rr.right = nx + RECT_WIDTH(r1);
btn.MoveWindow(&rr, m_bRepaintWhenMove);
}
return nRet;
}
// return bottom of control
int StretchControlWide(uint nID, int nx, int ny, int cx, int nGap = -1)
{
Control btn = GetItem(nID);
if(nGap < 0)
nGap = m_nEdge;
if(btn && btn.Visible)
{
RECT rr, r1;
btn.GetWindowRect(&r1);
rr.left = nx;
rr.top = ny;
rr.right = cx - nGap;
rr.bottom = ny + RECT_HEIGHT(r1);
btn.MoveWindow(&rr, m_bRepaintWhenMove);
ny = rr.bottom;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -