splitter.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:7k
- /*
- * splitter.cxx
- *
- * Splitter interactor class.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: splitter.cxx,v $
- * Revision 1.9 1998/12/20 09:14:46 robertj
- * Added pragma implementation for GNU compiler.
- *
- * Revision 1.8 1998/11/30 04:52:19 robertj
- * New directory structure
- *
- * Revision 1.7 1998/09/23 06:29:58 robertj
- * Added open source copyright license.
- *
- * Revision 1.6 1996/04/30 12:34:03 robertj
- * Changed "inPixels" boolean to enum for three coordinate systems.
- *
- * Revision 1.5 1995/12/10 11:43:12 robertj
- * Fixed automatic operator translation incompatibility amongst compilers.
- *
- * Revision 1.4 1995/07/02 01:21:00 robertj
- * Removed OnDoubleClick() and added BOOL to OnMouseDown() for double click.
- *
- * Revision 1.3 1995/06/04 12:46:10 robertj
- * Added function to set splitter split by percentage.
- *
- * Revision 1.2 1995/03/22 13:53:55 robertj
- * Fixed integer overflow problem in 16 bit windows.
- *
- * Revision 1.1 1994/10/23 03:36:53 robertj
- * Initial revision
- *
- */
- #ifdef __GNUC__
- #pragma implementation "splitter.h"
- #endif
- #include <pwlib.h>
- #include <pwclib/splitter.h>
- #define new PNEW
- //////////////////////////////////////////////////////////////////////////////
- // PSplitter
- PSplitter::PSplitter(PInteractor * parent)
- : PInteractor(parent),
- splitBar(owner->GetTitledBorderSize())
- {
- trackCanvas = NULL;
- }
- void PSplitter::OnMouseMove(PKeyCode, const PPoint & where)
- {
- if (trackCanvas != NULL) {
- trackCanvas->DrawRect(splitBar);
- TrackSplitter(where);
- trackCanvas->DrawRect(splitBar);
- }
- }
- void PSplitter::OnMouseDown(PKeyCode, const PPoint &, BOOL)
- {
- if (trackCanvas != NULL) {
- ReleaseMouse();
- delete trackCanvas;
- }
- GrabMouse();
- trackCanvas = new PDrawCanvas(this, TRUE, TRUE);
- trackCanvas->SetPenMode(PCanvas::InvertDst);
- trackCanvas->SetFillMode(PCanvas::InvertDst);
- trackCanvas->DrawRect(splitBar);
- }
- void PSplitter::OnMouseUp(PKeyCode button, const PPoint & where)
- {
- if (trackCanvas != NULL) {
- OnMouseMove(button, where);
- ReleaseMouse();
- delete trackCanvas;
- trackCanvas = NULL;
- SetDimensions(GetDimensions(PixelCoords), PixelCoords);
- }
- }
- void PSplitter::OnRedraw(PCanvas & canvas)
- {
- canvas.SetMappingRect(canvas.GetViewportRect());
- canvas.SetFillFgColour(GetBorderColour());
- canvas.DrawRect(splitBar);
- }
- void PSplitter::AdjustChildInteractors(PDIMENSION width1, PDIMENSION height1,
- PORDINATE x2, PORDINATE y2, PDIMENSION width2, PDIMENSION height2)
- {
- PINDEX num = GetNumChildren();
- if (num >= 1) {
- if (num >= 2) {
- PRect rect(0, 0, width1, height1);
- children[num-2].AutoAdjustBounds(rect);
- }
- PRect rect(x2, y2, width2, height2);
- children[num-1].AutoAdjustBounds(rect);
- }
- }
- //////////////////////////////////////////////////////////////////////////////
- // PVerticalSplitter
- PVerticalSplitter::PVerticalSplitter(PInteractor * parent)
- : PSplitter(parent)
- {
- SetCursor(PCursor(PSTD_ID_CURSOR_LEFTRIGHT));
- SetDimensions(parent->GetDimensions(PixelCoords), PixelCoords);
- }
- void PVerticalSplitter::SetPercent(PDIMENSION percent)
- {
- PAssert(percent < 100, PInvalidParameter);
- PDim dim = GetDimensions(PixelCoords);
- splitBar.SetX(dim.Width()*percent/100);
- AdjustChildInteractors(splitBar.Left(), dim.Height(),
- splitBar.Right(), 0,
- dim.Width()-splitBar.Right(), dim.Height());
- }
- void PVerticalSplitter::_SetDimensions(PDIMENSION width, PDIMENSION height,
- CoordinateSystem coords)
- {
- PDim oldDim = GetDimensions(PixelCoords);
- PSplitter::_SetDimensions(width, height, coords);
- PDim newDim = GetDimensions(PixelCoords);
- if (oldDim.Width() > 0)
- splitBar.SetX((PORDINATE)(splitBar.X()*(long)newDim.Width()/oldDim.Width()));
- else
- splitBar.SetX((newDim.Width()-splitBar.Width())/2);
- splitBar.SetHeight(newDim.Height());
- AdjustChildInteractors(splitBar.Left(), newDim.Height(),
- splitBar.Right(), 0,
- newDim.Width()-splitBar.Right(), newDim.Height());
- }
- void PVerticalSplitter::TrackSplitter(const PPoint & where)
- {
- PDIMENSION winWidth = GetDimensions(PixelCoords).Width();
- PDIMENSION barWidth = splitBar.Width();
- if (where.X() + barWidth > winWidth)
- splitBar.SetX(winWidth - barWidth);
- else if (where.X() < 0)
- splitBar.SetX(0);
- else
- splitBar.SetX(where.X());
- }
- //////////////////////////////////////////////////////////////////////////////
- // PHorizontalSplitter
- PHorizontalSplitter::PHorizontalSplitter(PInteractor * parent)
- : PSplitter(parent)
- {
- SetCursor(PCursor(PSTD_ID_CURSOR_UPDOWN));
- SetDimensions(parent->GetDimensions(PixelCoords), PixelCoords);
- }
- void PHorizontalSplitter::SetPercent(PDIMENSION percent)
- {
- PAssert(percent < 100, PInvalidParameter);
- PDim dim = GetDimensions(PixelCoords);
- splitBar.SetY(dim.Height()*percent/100);
- AdjustChildInteractors(dim.Width(), splitBar.Top(),
- 0, splitBar.Bottom(),
- dim.Width(), dim.Height()-splitBar.Bottom());
- }
- void PHorizontalSplitter::_SetDimensions(PDIMENSION width, PDIMENSION height,
- CoordinateSystem coords)
- {
- PDim oldDim = GetDimensions(PixelCoords);
- PSplitter::_SetDimensions(width, height, coords);
- PDim newDim = GetDimensions(PixelCoords);
- if (oldDim.Height() > 0)
- splitBar.SetY((PORDINATE)(splitBar.Y()*(long)newDim.Height()/oldDim.Height()));
- else
- splitBar.SetY((newDim.Height()-splitBar.Height())/2);
- splitBar.SetWidth(newDim.Width());
- AdjustChildInteractors(splitBar.Width(), splitBar.Top(),
- 0, splitBar.Bottom(),
- splitBar.Width(), newDim.Height()-splitBar.Bottom());
- }
- void PHorizontalSplitter::TrackSplitter(const PPoint & where)
- {
- PDIMENSION winHeight = GetDimensions(PixelCoords).Height();
- PDIMENSION barHeight = splitBar.Height();
- if (where.Y() + barHeight > winHeight)
- splitBar.SetY(winHeight - barHeight);
- else if (where.Y() < 0)
- splitBar.SetY(0);
- else
- splitBar.SetY(where.Y());
- }
- #undef new
- // End Of File ///////////////////////////////////////////////////////////////