2 * Copyright (c) 2003, Frank Richter <frichter@gmx.li>
3 * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * A copy of the GNU General Public License can be found at
13 * Written by Frank Richter.
17 #include "ControlAdjuster.h"
18 #include "RECTWrapper.h"
20 void ControlAdjuster::AdjustControls (HWND dlg
,
21 const ControlInfo controlInfo
[],
22 int widthChange
, int heightChange
)
24 const ControlInfo
* ci
= controlInfo
;
26 while (ci
->control
> 0)
28 ci
->adjust(dlg
, widthChange
,heightChange
);
34 ControlAdjuster::ControlInfo::adjust(HWND dlg
, int widthChange
, int heightChange
) const
36 HWND ctl
= GetDlgItem (dlg
, control
);
40 GetWindowRect (ctl
, &ctlRect
);
41 // We want client coords.
42 ScreenToClient (dlg
, (LPPOINT
)&ctlRect
.left
);
43 ScreenToClient (dlg
, (LPPOINT
)&ctlRect
.right
);
45 ControlDimension
horizontal(ctlRect
.left
, ctlRect
.right
);
46 ControlDimension
vertical(ctlRect
.top
, ctlRect
.bottom
);
48 Now adjust the rectangle coordinates.
50 adjust(horizontalPos
, horizontal
, widthChange
);
51 adjust(verticalPos
, vertical
, heightChange
);
52 /* update the windows window */
53 SetWindowPos (ctl
, 0, ctlRect
.left
, ctlRect
.top
,
54 ctlRect
.width (), ctlRect
.height (), SWP_NOACTIVATE
| SWP_NOZORDER
);
55 // If not done, weird visual glitches can occur.
56 InvalidateRect (ctl
, 0, false);
60 ControlAdjuster::ControlInfo::adjust (ControlPosition
const &how
, ControlDimension
&where
, int by
) const
68 where
.right
+= by
- by
/2;
77 case CP_STRETCH_LEFTHALF
:
80 case CP_STRETCH_RIGHTHALF
:
87 SizeProcessor::SizeProcessor ()
92 void SizeProcessor::AddControlInfo (
93 const ControlAdjuster::ControlInfo
* controlInfo
)
95 controlInfos
.push_back (controlInfo
);
98 void SizeProcessor::UpdateSize (HWND dlg
)
100 RECTWrapper clientRect
;
101 ::GetClientRect (dlg
, &clientRect
);
105 const int dX
= clientRect
.width () - lastRect
.width ();
106 const int dY
= clientRect
.height () - lastRect
.height ();
107 for (size_t i
= 0; i
< controlInfos
.size (); i
++)
108 ControlAdjuster::AdjustControls (dlg
, controlInfos
[i
], dX
, dY
);
113 lastRect
= clientRect
;