| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
#include "ControlAdjuster.h" |
|---|
| 18 |
#include "RECTWrapper.h" |
|---|
| 19 |
|
|---|
| 20 |
void ControlAdjuster::AdjustControls (HWND dlg, |
|---|
| 21 |
const ControlInfo controlInfo[], |
|---|
| 22 |
int widthChange, int heightChange) |
|---|
| 23 |
{ |
|---|
| 24 |
const ControlInfo* ci = controlInfo; |
|---|
| 25 |
|
|---|
| 26 |
while (ci->control > 0) |
|---|
| 27 |
{ |
|---|
| 28 |
ci->adjust(dlg, widthChange,heightChange); |
|---|
| 29 |
ci++; |
|---|
| 30 |
} |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
void |
|---|
| 34 |
ControlAdjuster::ControlInfo::adjust(HWND dlg, int widthChange, int heightChange) const |
|---|
| 35 |
{ |
|---|
| 36 |
HWND ctl = GetDlgItem (dlg, control); |
|---|
| 37 |
if (ctl == 0) |
|---|
| 38 |
return; |
|---|
| 39 |
RECTWrapper ctlRect; |
|---|
| 40 |
GetWindowRect (ctl, &ctlRect); |
|---|
| 41 |
|
|---|
| 42 |
ScreenToClient (dlg, (LPPOINT)&ctlRect.left); |
|---|
| 43 |
ScreenToClient (dlg, (LPPOINT)&ctlRect.right); |
|---|
| 44 |
|
|---|
| 45 |
ControlDimension horizontal(ctlRect.left, ctlRect.right); |
|---|
| 46 |
ControlDimension vertical(ctlRect.top, ctlRect.bottom); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
adjust(horizontalPos, horizontal, widthChange); |
|---|
| 51 |
adjust(verticalPos, vertical, heightChange); |
|---|
| 52 |
|
|---|
| 53 |
SetWindowPos (ctl, 0, ctlRect.left, ctlRect.top, |
|---|
| 54 |
ctlRect.width (), ctlRect.height (), SWP_NOACTIVATE | SWP_NOZORDER); |
|---|
| 55 |
|
|---|
| 56 |
InvalidateRect (ctl, 0, false); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
void |
|---|
| 60 |
ControlAdjuster::ControlInfo::adjust (ControlPosition const &how, ControlDimension &where, int by) const |
|---|
| 61 |
{ |
|---|
| 62 |
switch (how) |
|---|
| 63 |
{ |
|---|
| 64 |
case CP_LEFT: |
|---|
| 65 |
break; |
|---|
| 66 |
case CP_CENTERED: |
|---|
| 67 |
where.left += by/2; |
|---|
| 68 |
where.right += by - by/2; |
|---|
| 69 |
break; |
|---|
| 70 |
case CP_RIGHT: |
|---|
| 71 |
where.left += by; |
|---|
| 72 |
where.right += by; |
|---|
| 73 |
break; |
|---|
| 74 |
case CP_STRETCH: |
|---|
| 75 |
where.right += by; |
|---|
| 76 |
break; |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
SizeProcessor::SizeProcessor () |
|---|
| 81 |
{ |
|---|
| 82 |
rectValid = false; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
void SizeProcessor::AddControlInfo ( |
|---|
| 86 |
const ControlAdjuster::ControlInfo* controlInfo) |
|---|
| 87 |
{ |
|---|
| 88 |
controlInfos.push_back (controlInfo); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
void SizeProcessor::UpdateSize (HWND dlg) |
|---|
| 92 |
{ |
|---|
| 93 |
RECTWrapper clientRect; |
|---|
| 94 |
::GetClientRect (dlg, &clientRect); |
|---|
| 95 |
|
|---|
| 96 |
if (rectValid) |
|---|
| 97 |
{ |
|---|
| 98 |
const int dX = clientRect.width () - lastRect.width (); |
|---|
| 99 |
const int dY = clientRect.height () - lastRect.height (); |
|---|
| 100 |
|
|---|
| 101 |
for (size_t i = 0; i < controlInfos.size (); i++) |
|---|
| 102 |
ControlAdjuster::AdjustControls (dlg, controlInfos[i], dX, dY); |
|---|
| 103 |
} |
|---|
| 104 |
else |
|---|
| 105 |
rectValid = true; |
|---|
| 106 |
|
|---|
| 107 |
lastRect = clientRect; |
|---|
| 108 |
} |
|---|