scrollab.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:12k
- /*
- * scrollab.h
- *
- * Scrollable interactor classes.
- *
- * 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: scrollab.h,v $
- * Revision 1.20 1999/03/10 03:49:53 robertj
- * More documentation adjustments.
- *
- * Revision 1.19 1999/03/09 08:01:50 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.18 1999/02/16 08:08:46 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.17 1998/09/23 06:28:57 robertj
- * Added open source copyright license.
- *
- * Revision 1.16 1996/04/30 12:33:41 robertj
- * Changed "inPixels" boolean to enum for three coordinate systems.
- *
- * Revision 1.15 1995/06/17 11:13:16 robertj
- * Documentation update.
- *
- * Revision 1.14 1995/03/14 12:42:31 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.13 1995/01/21 05:16:25 robertj
- * Modified ShowAll so PScrollable does not change show state of scroll bars..
- *
- * Revision 1.12 1995/01/14 06:19:36 robertj
- * Documentation
- *
- * Revision 1.11 1994/10/30 11:47:04 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.10 1994/10/23 04:55:29 robertj
- * Major implementation.
- *
- * Revision 1.9 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.8 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.7 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.6 1994/04/20 12:17:44 robertj
- * Some implementation.
- *
- * Revision 1.5 1994/04/01 14:15:44 robertj
- * Added some PScrollable functionality.
- *
- * Revision 1.4 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.3 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.2 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #define _PSCROLLABLE
- #ifdef __GNUC__
- #pragma interface
- #endif
- class PHorizontalScrollBar;
- class PVerticalScrollBar;
- class PScrollable;
- /**An interactor that has support for scroll bars so that its logical contents
- may be larger than the drawable bounds. This works in conjunction with the
- Ref{PScrollable} class to produce a scrolling interactor.
- The bounds returned by a Ref{PCanvas} attached to an interactor normally
- indicate the size of the internal area of the window. With a scrollable
- interactor the PCanvas may return a larger dimension, as set by the
- Ref{PScrollable::SetScrollRange()} function.
- The canvas does not know (or care) what is visible and this interactor
- handles the necessary coordinate adjustments and and bitblt's for
- scrolling around a large drawable area.
-
- Note that the last child interactor that is a descendent of the
- Ref{PScrollable} class is the contents" that is scrolled by the scroller.
- */
- class PScroller : public PInteractor
- {
- PCLASSINFO(PScroller, PInteractor);
- public:
- /**Create an interactor that has scroll bars and will automatically scroll
- a Ref{PScrollable} interactor when scrolled by the user.
- */
- PScroller(
- PInteractor * parent /// Interactor into which the scroller is put.
- );
- /**@name New functions for class */
- /**Get the scrollable that the scroller scrolls. If no Ref{PScrollable}
- interactor has been created with this instance of PScroller as its
- parent, this function will assert.
- @return
- reference to contents of scroller interactor.
- */
- PScrollable & GetContents();
- /**Get the vertical scroll bar in the scroller. This will allow the user
- to customise the usage of the scroller, eg hide the scroll bar as only
- one dimension is scrollable.
-
- @return
- reference to vertical scroll bar.
- */
- PVerticalScrollBar & GetVerticalScrollBar() const;
- /**Get the horizontal scroll bar in the scroller. This will allow the user
- to customise the usage of the scroller, eg hide the scroll bar as only
- one dimension is scrollable.
-
- @return
- reference to horizontal scroll bar.
- */
- PHorizontalScrollBar & GetHorizontalScrollBar() const;
- protected:
- /**@name Overrides from class PInteractor */
- /**Show the interactor and all child and grandchild etc interactors.
- This enabled the interactor tree in post order, ie all children have
- their Ref{PInteractor::ShowAll()} function called and then the
- interactor itself is shown using the Ref{PInteractor::Show()}
- function.
- */
- virtual void ShowAll();
- /**Set the dimensions of the scroller interactor. This will automatically
- adjust the position and dimensions of the scroll bars and the contents
- interactor.
- When scaling is used (#coords == LocalCoords#), the
- coordinates used are 1/4 average font width and 1/8 the font height.
- */
- virtual void _SetDimensions(
- PDIMENSION width, /// New width for scroller.
- PDIMENSION height, /// New height for scroller.
- CoordinateSystem coords /// Coordinate system to use.
- );
- /**@name Member variables */
- /** Vertical scroll bar child interactors for scrollable window */
- PVerticalScrollBar * vScroll;
- /** Horizontal scroll bar child interactors for scrollable window */
- PHorizontalScrollBar * hScroll;
- private:
- PDECLARE_NOTIFIER(PScrollBar, PScroller, ScrollBarNotify);
- // Callback function for scoll bars
- friend class PScrollable;
- };
- /**An interactor that has its logical contents larger than the drawable
- bounds. This works in conjunction with the Ref{PScroller} class to produce
- a scrolling interactor.
- The bounds returned by a Ref{PCanvas} attached to an interactor normally
- indicate the size of the internal area of the window. With a scrollable
- interactor the PCanvas may return a larger dimension, as set by the
- Ref{SetScrollRange()} function.
- The canvas does not know (or care) what is visible and this interactor
- handles the necessary coordinate adjustments and and bitblt's for
- scrolling around a large drawable area.
- The scrolling mechanism can operate in minimum "quanta". This is smallest
- number of pixels that can be scrolled. This is set by the {it scale
- factor} of the scrollable interactor. For example, a text editor would
- only ever scroll in whole lines or character widths. So the scale factor
- is set to the number of pixels for the height of a line and width of a
- character.
-
- Note that the last child interactor that is a descendent of the
- Ref{PScrollable} class is the contents" that is scrolled by the
- Ref{PScroller}.
- */
- class PScrollable : public PInteractor
- {
- PCLASSINFO(PScrollable, PInteractor);
- public:
- /**Create a scrollable interactor that will be scrolled by the parent
- Ref{PScroller} class.
- */
- PScrollable(
- PScroller * parent /// Scroller class that scrolls the scrollable.
- );
- /**@name Overrides from class PInteractor */
- /**Get the drawing bounds for the scrollable interactor. This yields the
- size of the drawable area that the Ref{PInteractorCanvas} will use as
- its drawing bounds.
- When scaling is used (#coords == LocalCoords#), the
- coordinates used are 1/4 average font width and 1/8 the font height.
- @return
- drawing bounds rectangle for the interactor.
- */
- virtual PRect GetDrawingBounds(
- CoordinateSystem coords /// Coordinate system to use.
- ) const;
- /**@name New functions for class */
- /**Set the range in which the scrollable is scrolled. This gives the
- minimum and maximum scroll range in both vertical and horizontal
- directions.
- */
- void SetScrollRange(
- const PRect & rect /// Rectangle for the scrolling limits.
- );
- /**Get the range in which the scrollable is scrolled. This gives the
- minimum and maximum scroll range in both vertical and horizontal
- directions.
-
- @return
- rectangle for the scrolling limits.
- */
- PRect GetScrollRange() const;
- /**Set the scaling factor in pixels for the scroll range. This determines
- the minimum "quanta" for scrolling. Each scroll bar unit will scroll
- the contents by this many pixels in each direction.
- */
- void SetScaleFactor(
- PORDINATE x, /// Set horizontal scale factor.
- PORDINATE y /// Set vertical sccroll factor.
- );
- void SetScaleFactor(
- const PPoint & scale /// Set scale factor in both dimensions.
- );
- /**Get the scaling factor in pixels for the scroll range. This determines
- the minimum "quanta" for scrolling. Each scroll bar unit will scroll
- the contents by this many pixels in each direction.
- @return
- scale factor in each dimension.
- */
- PPoint GetScaleFactor() const;
- /**Get the current origin of the scrollable in the scrolling units. This
- must be multiplied by the scale factor to yield a number of pixels to
- scroll.
- @return
- the current origin for the scrollable area
- */
- PPoint GetOrigin() const;
- /**Scroll the scrollable contents to the new origin specified. The origin
- is in the scrolling units. This must be multiplied by the scale factor
- to yield a number of pixels.
- */
- void ScrollTo(
- PORDINATE x, /// Horizontal position to scroll to.
- PORDINATE y /// Vertical position to scroll to.
- );
- void ScrollTo(
- const PPoint & newOrg /// New position to scroll to.
- );
- /**Scroll the scrollable contents by the amount specified. The delta to
- scroll is in the scrolling units. This must be multiplied by the scale
- factor to yield a number of pixels.
- */
- void ScrollBy(
- PORDINATE dx, /// Amount to scroll horizontally.
- PORDINATE dy /// Amount to scroll vertically.
- );
- void ScrollBy(
- const PPoint & delta /// Amount to scroll.
- );
- /**@name System callback functions. */
- /**The system (via the PScroller class) calls this whenever the user has
- scrolled the window in one of the two dimensions. The origin variable
- will be already be updated to its new position. The old position can
- be calculated by subtracting the delta value to it.
-
- The default behaviour of this function is to do the bitblt of the
- interactors contents by the scrolled amount and invalidate the area
- "exposed" by the scrolling.
- */
- virtual void OnScroll(
- const PPoint & delta /// Amount the scrollable was scrolled.
- );
- protected:
- /**@name Member variables */
- /** The range in which the scrollable is scrolled. */
- PRect scrollRange;
- /** Scaling factor in pixels of the scrollBounds. */
- PPoint scaleFactor;
- /**Origin into the virtual bounds rectangle that the top left corner of
- the interactor is currently displaying.
- */
- PPoint origin;
- };
- // End of file ///////////////////////////////////////////////////////////////