]> cygwin.com Git - cygwin-apps/setup.git/blame - ControlAdjuster.cc
2003-10-31 Igor Pechtchanski <pechtcha@cs.nyu.edu>
[cygwin-apps/setup.git] / ControlAdjuster.cc
CommitLineData
ee91d9be
RC
1/*
2 * Copyright (c) 2003, Frank Richter <frichter@gmx.li>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Frank Richter.
13 *
14 */
15
16#include "ControlAdjuster.h"
17#include "RECTWrapper.h"
18
19void ControlAdjuster::AdjustControls (HWND dlg,
20 const ControlInfo controlInfo[],
21 int widthChange, int heightChange)
22{
23 const ControlInfo* ci = controlInfo;
24
25 while (ci->control > 0)
26 {
27 HWND ctl = GetDlgItem (dlg, ci->control);
28 if (ctl != 0)
29 {
30 RECTWrapper ctlRect;
31 GetWindowRect (ctl, &ctlRect);
32 // We want client coords.
33 ScreenToClient (dlg, (LPPOINT)&ctlRect.left);
34 ScreenToClient (dlg, (LPPOINT)&ctlRect.right);
35
36 /*
37 Now adjust the rectangle.
ee91d9be 38 */
a8d753b6
RC
39 switch (ci->horizontalPos)
40 {
41 case CP_LEFT:
42 break;
43 case CP_MIDDLE:
44 ctlRect.left += widthChange/2;
45 ctlRect.right += widthChange - widthChange/2;
46 break;
47 case CP_RIGHT:
48 ctlRect.left += widthChange;
49 ctlRect.right += widthChange;
50 break;
51 case CP_STRETCH:
52 ctlRect.right += widthChange;
53 break;
54 }
55 switch (ci->verticalPos)
56 {
57 case CP_TOP:
58 break;
59 case CP_MIDDLE:
60 ctlRect.top += heightChange/2;
61 ctlRect.bottom += heightChange - heightChange/2;
62 break;
63 case CP_BOTTOM:
64 ctlRect.top += heightChange;
65 ctlRect.bottom += heightChange;
66 break;
67 case CP_STRETCH:
68 ctlRect.bottom += heightChange;
69 break;
70 }
71
ee91d9be
RC
72 SetWindowPos (ctl, 0, ctlRect.left, ctlRect.top,
73 ctlRect.width (), ctlRect.height (), SWP_NOACTIVATE | SWP_NOZORDER);
74 // If not done, weird visual glitches can occur.
75 InvalidateRect (ctl, 0, false);
76
77 }
78 ci++;
79 }
80}
81
82SizeProcessor::SizeProcessor ()
83{
84 rectValid = false;
85}
86
87void SizeProcessor::AddControlInfo (
88 const ControlAdjuster::ControlInfo* controlInfo)
89{
90 controlInfos.push_back (controlInfo);
91}
92
93void SizeProcessor::UpdateSize (HWND dlg)
94{
95 RECTWrapper clientRect;
96 ::GetClientRect (dlg, &clientRect);
97
98 if (rectValid)
99 {
100 const int dX = clientRect.width () - lastRect.width ();
101 const int dY = clientRect.height () - lastRect.height ();
102
103 for (size_t i = 0; i < controlInfos.size (); i++)
104 ControlAdjuster::AdjustControls (dlg, controlInfos[i], dX, dY);
105 }
106 else
107 rectValid = true;
108
109 lastRect = clientRect;
110}
This page took 0.07307 seconds and 5 git commands to generate.