]>
Commit | Line | Data |
---|---|---|
ee91d9be RC |
1 | /* |
2 | * Copyright (c) 2003, Frank Richter <frichter@gmx.li> | |
576a2b0b | 3 | * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com> |
ee91d9be RC |
4 | * |
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. | |
9 | * | |
10 | * A copy of the GNU General Public License can be found at | |
11 | * http://www.gnu.org/ | |
12 | * | |
13 | * Written by Frank Richter. | |
14 | * | |
15 | */ | |
16 | ||
17 | #include "ControlAdjuster.h" | |
18 | #include "RECTWrapper.h" | |
30718d6f CF |
19 | |
20 | void ControlAdjuster::AdjustControls (HWND dlg, | |
21 | const ControlInfo controlInfo[], | |
ee91d9be RC |
22 | int widthChange, int heightChange) |
23 | { | |
24 | const ControlInfo* ci = controlInfo; | |
30718d6f | 25 | |
ee91d9be RC |
26 | while (ci->control > 0) |
27 | { | |
576a2b0b | 28 | ci->adjust(dlg, widthChange,heightChange); |
ee91d9be RC |
29 | ci++; |
30 | } | |
31 | } | |
576a2b0b RC |
32 | |
33 | void | |
34 | ControlAdjuster::ControlInfo::adjust(HWND dlg, int widthChange, int heightChange) const | |
30718d6f CF |
35 | { |
36 | HWND ctl = GetDlgItem (dlg, control); | |
576a2b0b RC |
37 | if (ctl == 0) |
38 | return; | |
39 | RECTWrapper ctlRect; | |
40 | GetWindowRect (ctl, &ctlRect); | |
41 | // We want client coords. | |
42 | ScreenToClient (dlg, (LPPOINT)&ctlRect.left); | |
43 | ScreenToClient (dlg, (LPPOINT)&ctlRect.right); | |
30718d6f | 44 | |
576a2b0b RC |
45 | ControlDimension horizontal(ctlRect.left, ctlRect.right); |
46 | ControlDimension vertical(ctlRect.top, ctlRect.bottom); | |
47 | /* | |
48 | Now adjust the rectangle coordinates. | |
49 | */ | |
50 | adjust(horizontalPos, horizontal, widthChange); | |
51 | adjust(verticalPos, vertical, heightChange); | |
52 | /* update the windows window */ | |
30718d6f | 53 | SetWindowPos (ctl, 0, ctlRect.left, ctlRect.top, |
576a2b0b RC |
54 | ctlRect.width (), ctlRect.height (), SWP_NOACTIVATE | SWP_NOZORDER); |
55 | // If not done, weird visual glitches can occur. | |
56 | InvalidateRect (ctl, 0, false); | |
57 | } | |
30718d6f | 58 | |
576a2b0b RC |
59 | void |
60 | ControlAdjuster::ControlInfo::adjust (ControlPosition const &how, ControlDimension &where, int by) const | |
61 | { | |
62 | switch (how) | |
63 | { | |
64 | case CP_LEFT: | |
30718d6f | 65 | break; |
201741b7 | 66 | case CP_CENTERED: |
30718d6f CF |
67 | where.left += by/2; |
68 | where.right += by - by/2; | |
69 | break; | |
576a2b0b | 70 | case CP_RIGHT: |
30718d6f CF |
71 | where.left += by; |
72 | where.right += by; | |
73 | break; | |
576a2b0b | 74 | case CP_STRETCH: |
30718d6f CF |
75 | where.right += by; |
76 | break; | |
daab12c7 | 77 | case CP_STRETCH_LEFTHALF: |
30718d6f CF |
78 | where.right += by/2; |
79 | break; | |
daab12c7 | 80 | case CP_STRETCH_RIGHTHALF: |
30718d6f CF |
81 | where.left += by/2; |
82 | where.right += by; | |
83 | break; | |
576a2b0b RC |
84 | } |
85 | } | |
30718d6f | 86 | |
ee91d9be RC |
87 | SizeProcessor::SizeProcessor () |
88 | { | |
89 | rectValid = false; | |
90 | } | |
30718d6f | 91 | |
ee91d9be RC |
92 | void SizeProcessor::AddControlInfo ( |
93 | const ControlAdjuster::ControlInfo* controlInfo) | |
94 | { | |
95 | controlInfos.push_back (controlInfo); | |
96 | } | |
97 | ||
98 | void SizeProcessor::UpdateSize (HWND dlg) | |
99 | { | |
100 | RECTWrapper clientRect; | |
101 | ::GetClientRect (dlg, &clientRect); | |
102 | ||
103 | if (rectValid) | |
104 | { | |
105 | const int dX = clientRect.width () - lastRect.width (); | |
106 | const int dY = clientRect.height () - lastRect.height (); | |
ee91d9be RC |
107 | for (size_t i = 0; i < controlInfos.size (); i++) |
108 | ControlAdjuster::AdjustControls (dlg, controlInfos[i], dX, dY); | |
109 | } | |
110 | else | |
111 | rectValid = true; | |
30718d6f | 112 | |
ee91d9be RC |
113 | lastRect = clientRect; |
114 | } |