4 * Splitter interactor class.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.9 1998/12/20 09:14:46 robertj
31 * Added pragma implementation for GNU compiler.
33 * Revision 1.8 1998/11/30 04:52:19 robertj
34 * New directory structure
36 * Revision 1.7 1998/09/23 06:29:58 robertj
37 * Added open source copyright license.
39 * Revision 1.6 1996/04/30 12:34:03 robertj
40 * Changed "inPixels" boolean to enum for three coordinate systems.
42 * Revision 1.5 1995/12/10 11:43:12 robertj
43 * Fixed automatic operator translation incompatibility amongst compilers.
45 * Revision 1.4 1995/07/02 01:21:00 robertj
46 * Removed OnDoubleClick() and added BOOL to OnMouseDown() for double click.
48 * Revision 1.3 1995/06/04 12:46:10 robertj
49 * Added function to set splitter split by percentage.
51 * Revision 1.2 1995/03/22 13:53:55 robertj
52 * Fixed integer overflow problem in 16 bit windows.
54 * Revision 1.1 1994/10/23 03:36:53 robertj
60 #pragma implementation "splitter.h"
64 #include <pwclib/splitter.h>
69 //////////////////////////////////////////////////////////////////////////////
72 PSplitter::PSplitter(PInteractor
* parent
)
73 : PInteractor(parent
),
74 splitBar(owner
->GetTitledBorderSize())
80 void PSplitter::OnMouseMove(PKeyCode
, const PPoint
& where
)
82 if (trackCanvas
!= NULL
) {
83 trackCanvas
->DrawRect(splitBar
);
85 trackCanvas
->DrawRect(splitBar
);
90 void PSplitter::OnMouseDown(PKeyCode
, const PPoint
&, BOOL
)
92 if (trackCanvas
!= NULL
) {
98 trackCanvas
= new PDrawCanvas(this, TRUE
, TRUE
);
99 trackCanvas
->SetPenMode(PCanvas::InvertDst
);
100 trackCanvas
->SetFillMode(PCanvas::InvertDst
);
101 trackCanvas
->DrawRect(splitBar
);
105 void PSplitter::OnMouseUp(PKeyCode button
, const PPoint
& where
)
107 if (trackCanvas
!= NULL
) {
108 OnMouseMove(button
, where
);
112 SetDimensions(GetDimensions(PixelCoords
), PixelCoords
);
117 void PSplitter::OnRedraw(PCanvas
& canvas
)
119 canvas
.SetMappingRect(canvas
.GetViewportRect());
120 canvas
.SetFillFgColour(GetBorderColour());
121 canvas
.DrawRect(splitBar
);
125 void PSplitter::AdjustChildInteractors(PDIMENSION width1
, PDIMENSION height1
,
126 PORDINATE x2
, PORDINATE y2
, PDIMENSION width2
, PDIMENSION height2
)
128 PINDEX num
= GetNumChildren();
131 PRect
rect(0, 0, width1
, height1
);
132 children
[num
-2].AutoAdjustBounds(rect
);
134 PRect
rect(x2
, y2
, width2
, height2
);
135 children
[num
-1].AutoAdjustBounds(rect
);
140 //////////////////////////////////////////////////////////////////////////////
143 PVerticalSplitter::PVerticalSplitter(PInteractor
* parent
)
146 SetCursor(PCursor(PSTD_ID_CURSOR_LEFTRIGHT
));
147 SetDimensions(parent
->GetDimensions(PixelCoords
), PixelCoords
);
151 void PVerticalSplitter::SetPercent(PDIMENSION percent
)
153 PAssert(percent
< 100, PInvalidParameter
);
154 PDim dim
= GetDimensions(PixelCoords
);
155 splitBar
.SetX(dim
.Width()*percent
/100);
156 AdjustChildInteractors(splitBar
.Left(), dim
.Height(),
158 dim
.Width()-splitBar
.Right(), dim
.Height());
162 void PVerticalSplitter::_SetDimensions(PDIMENSION width
, PDIMENSION height
,
163 CoordinateSystem coords
)
165 PDim oldDim
= GetDimensions(PixelCoords
);
166 PSplitter::_SetDimensions(width
, height
, coords
);
167 PDim newDim
= GetDimensions(PixelCoords
);
169 if (oldDim
.Width() > 0)
170 splitBar
.SetX((PORDINATE
)(splitBar
.X()*(long)newDim
.Width()/oldDim
.Width()));
172 splitBar
.SetX((newDim
.Width()-splitBar
.Width())/2);
173 splitBar
.SetHeight(newDim
.Height());
175 AdjustChildInteractors(splitBar
.Left(), newDim
.Height(),
177 newDim
.Width()-splitBar
.Right(), newDim
.Height());
181 void PVerticalSplitter::TrackSplitter(const PPoint
& where
)
183 PDIMENSION winWidth
= GetDimensions(PixelCoords
).Width();
184 PDIMENSION barWidth
= splitBar
.Width();
185 if (where
.X() + barWidth
> winWidth
)
186 splitBar
.SetX(winWidth
- barWidth
);
187 else if (where
.X() < 0)
190 splitBar
.SetX(where
.X());
194 //////////////////////////////////////////////////////////////////////////////
195 // PHorizontalSplitter
197 PHorizontalSplitter::PHorizontalSplitter(PInteractor
* parent
)
200 SetCursor(PCursor(PSTD_ID_CURSOR_UPDOWN
));
201 SetDimensions(parent
->GetDimensions(PixelCoords
), PixelCoords
);
205 void PHorizontalSplitter::SetPercent(PDIMENSION percent
)
207 PAssert(percent
< 100, PInvalidParameter
);
208 PDim dim
= GetDimensions(PixelCoords
);
209 splitBar
.SetY(dim
.Height()*percent
/100);
210 AdjustChildInteractors(dim
.Width(), splitBar
.Top(),
211 0, splitBar
.Bottom(),
212 dim
.Width(), dim
.Height()-splitBar
.Bottom());
216 void PHorizontalSplitter::_SetDimensions(PDIMENSION width
, PDIMENSION height
,
217 CoordinateSystem coords
)
219 PDim oldDim
= GetDimensions(PixelCoords
);
220 PSplitter::_SetDimensions(width
, height
, coords
);
221 PDim newDim
= GetDimensions(PixelCoords
);
223 if (oldDim
.Height() > 0)
224 splitBar
.SetY((PORDINATE
)(splitBar
.Y()*(long)newDim
.Height()/oldDim
.Height()));
226 splitBar
.SetY((newDim
.Height()-splitBar
.Height())/2);
227 splitBar
.SetWidth(newDim
.Width());
229 AdjustChildInteractors(splitBar
.Width(), splitBar
.Top(),
230 0, splitBar
.Bottom(),
231 splitBar
.Width(), newDim
.Height()-splitBar
.Bottom());
234 void PHorizontalSplitter::TrackSplitter(const PPoint
& where
)
236 PDIMENSION winHeight
= GetDimensions(PixelCoords
).Height();
237 PDIMENSION barHeight
= splitBar
.Height();
238 if (where
.Y() + barHeight
> winHeight
)
239 splitBar
.SetY(winHeight
- barHeight
);
240 else if (where
.Y() < 0)
243 splitBar
.SetY(where
.Y());
250 // End Of File ///////////////////////////////////////////////////////////////