vstate.cpp

Go to the documentation of this file.
00001 // $Id: vstate.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // The ViewState object - contains a platform-independent description of a view onto
00100 // a document.
00101 
00102 #include "camtypes.h"
00103 #include "vstate.h"
00104 //#include "oilcoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 
00107 // Declare smart memory handling in Debug builds
00108 #define new CAM_DEBUG_NEW
00109 
00110 // Construction and destruction.
00111 
00112 ViewState::ViewState()
00113 {
00114     // Set all the params to defaults
00115     pView = NULL;
00116 
00117     // Make all rects empty
00118     ScreenRect.MakeEmpty();
00119     ParentRect.MakeEmpty();
00120     ViewRect.MakeEmpty();
00121     WorkAreaExtent.MakeEmpty();
00122     IconPoint = Coord(0,0);
00123 
00124     ViewScale = 0;
00125     zPos = 0;
00126     
00127     IsNewView = TRUE;
00128     IsMinimised = FALSE;
00129     IsMaximised = FALSE;
00130     AlwaysOnTop = FALSE;
00131     RulersVisible = FALSE;
00132     ScrollersVisible = TRUE;
00133     ScrollPosition = WorkCoord(0,0);
00134 
00135     _GridShow = _GridSnap = _ObjectsSnap = _MagObjectsSnap = _PrintBorderShow = FALSE;
00136     _LogicalView = _GuidesSnap = _GuidesShow = FALSE;
00137 }
00138 
00139 
00140 
00141 ViewState::~ViewState()
00142 {
00143     // empty
00144 }
00145 
00146 
00147 
00148 
00149 /********************************************************************************************
00150 >   WorkCoord ViewState::SetScrollPos(WorkCoord sp, BOOL fPixelise = TRUE) 
00151 
00152     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00153     Created:    09/11/94
00154     Inputs:     New scroll position and whether to pixelise it.
00155     Outputs:    Pixelised scroll position.
00156     Returns:    None
00157     Purpose:    Set the scroll position in WorkCoords for use by DocView and CamView.
00158     Errors:     None
00159 
00160 ********************************************************************************************/
00161 
00162 WorkCoord ViewState::SetScrollPos(WorkCoord sp, BOOL fPixelise /* = TRUE */)
00163 {
00164     ERROR3IF(!fPixelise, "ViewState::SetScrollPos called with Pixelise = FALSE");
00165 
00166 //  TRACE( _T("VS::SetScrollPos(%d, %d)\n"), (INT32)(sp.x), (INT32)(sp.y));
00167 
00168     FIXED16 PixelWidth, PixelHeight;    
00169     ERROR2IF(pView == NULL, ScrollPosition, "No attached view in ViewState::SetScrollPos");
00170     pView->GetPixelSize(&PixelWidth, &PixelHeight);
00171 
00172     INT32 pw = PixelWidth.MakeLong();
00173     INT32 ph = PixelHeight.MakeLong();
00174 
00175     if (sp.x < 0) sp.x -= (pw - 1);         // Overcome the flooring of negative values
00176     if (sp.y < 0) sp.y -= (ph - 1);         // towards 0 by the upcoming divisions...
00177 
00178     ScrollPosition.x = (sp.x / pw) * pw;
00179     ScrollPosition.y = (sp.y / ph) * ph;
00180 
00181     return ScrollPosition;
00182 }
00183 
00184 
00185 
00186 
00187 /********************************************************************************************
00188 >   WorkCoord ViewState::GetScrollPos(BOOL Pixelise = TRUE) 
00189 
00190     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00191     Created:    09/11/94
00192     Inputs:     None
00193     Outputs:    None
00194     Returns:    Scroll position
00195     Purpose:    Set the scroll position in WorkCoords for use by DocView and CamView.
00196     Errors:     None
00197 
00198 ********************************************************************************************/
00199 /*
00200     Technical notes:
00201     This routine provides restricted access to the ScrollPosition member of ViewState.
00202     It ensures that the scroll position is aligned to a whole pixel boundary at all times by
00203     dividing and re-multiplying by the pixel size (YUK).
00204 
00205     Note that when a negative value is divided in C++ it is done so without regard for the
00206     sign of the value.
00207     E.g.
00208         21 / 4 = 5  Result has been truncated towards 0, moving Y coordinates down
00209         -21/ 4 = 5  Result has been truncated towards 0 again, moving Y coordinates UP!!!
00210     In other words when the values are coordinates the division truncates them in different
00211     directions depending which side of the origin they are on!
00212     This is obviously not required and so any negative values are adjusted before the division
00213     to ensure the end result is movement in the same direction as positive values.
00214 
00215 ********************************************************************************************/
00216 
00217 WorkCoord ViewState::GetScrollPos(BOOL Pixelise)
00218 {
00219     ERROR3IF(!Pixelise, "ViewState::GetScrollPos called with Pixelise = FALSE");
00220     return(ScrollPosition);
00221 
00222 #if FALSE
00223     WorkCoord temp = ScrollPosition;
00224 
00225     // If we have a NULL view, return quietly, cos this is probably in 
00226     // some rendering code.
00227     if (Pixelise)
00228     {
00229         FIXED16 PixelWidth, PixelHeight;    
00230         ERROR2IF(pView == NULL, temp, "No attached view in ViewState::GetScrollPos");
00231         pView->GetPixelSize(&PixelWidth, &PixelHeight);
00232     
00233         INT32 pw = PixelWidth.MakeLong();
00234         INT32 ph = PixelHeight.MakeLong();
00235 
00236         if (temp.x < 0) temp.x -= (pw - 1);         // Overcome the flooring of negative values
00237         if (temp.y < 0) temp.y -= (ph - 1);         // towards 0 by the upcoming divisions...
00238 
00239         temp.x = (temp.x / pw) * pw;
00240         temp.y = (temp.y / ph) * ph;
00241     }
00242     return temp;
00243 #endif
00244 }
00245 
00246 
00247 /*
00248 
00249 void ViewState::Serialize(CArchive& ar)
00250 {
00251     // Serialize the base class first.
00252     CObject::Serialize(ar);
00253 
00254     if (ar.IsStoring())
00255     {
00256         // Save the size of the screen.
00257         ar << ScreenRect.lo.x << ScreenRect.lo.y
00258            << ScreenRect.hi.x << ScreenRect.hi.y;
00259 
00260         // Save the size of the parent (MDI) frame window.
00261         ar << ParentRect.lo.x << ParentRect.lo.y
00262            << ParentRect.hi.x << ParentRect.hi.y;
00263 
00264         // Save the size of this view window.
00265         ar << ViewRect.lo.x << ViewRect.lo.y
00266            << ViewRect.hi.x << ViewRect.hi.y;
00267 
00268         // Save the position of this view when an icon.
00269         ar << IconPoint.x << IconPoint.y;
00270 
00271         // Save the scroller position.
00272         INT32 dwHigh;
00273         UINT32 dwLow;
00274         ScrollPosition.x.GetHighLow(&dwHigh, &dwLow);
00275         ar << dwHigh << dwLow;
00276         ScrollPosition.y.GetHighLow(&dwHigh, &dwLow);
00277         ar << dwHigh << dwLow;
00278 
00279         // Save the zoom scaling factor.  For now, this must be done by casting it
00280         // into a double, until Andy lets me change fixed16.h
00281         ar << ViewScale.MakeDouble();
00282 
00283         // Save the "state" of this view, ie. Is it an icon?  Is it top-most? etc.
00284         ar << INT32(IsMinimised) << INT32(IsMaximised) << INT32(HasFocus)
00285            << INT32(AlwaysOnTop);
00286     }
00287     else
00288     {
00289         // Load the previous size of the screen.
00290         ar >> ScreenRect.lo.x >> ScreenRect.lo.y
00291            >> ScreenRect.hi.x >> ScreenRect.hi.y;
00292 
00293         // Load the size of the parent (MDI) frame window.
00294         ar >> ParentRect.lo.x >> ParentRect.lo.y
00295            >> ParentRect.hi.x >> ParentRect.hi.y;
00296 
00297         // Load the size of this view window.
00298         ar >> ViewRect.lo.x >> ViewRect.lo.y
00299            >> ViewRect.hi.x >> ViewRect.hi.y;
00300 
00301         // Load the position of this view when an icon.
00302         ar >> IconPoint.x >> IconPoint.y;
00303 
00304         // Load the scroller position.
00305         INT32 dwHigh;
00306         UINT32 dwLow;
00307         ar >> dwHigh >> dwLow;
00308         ScrollPosition.x.SetHighLow(dwHigh, dwLow);
00309         ar >> dwHigh >> dwLow;
00310         ScrollPosition.y.SetHighLow(dwHigh, dwLow);
00311 
00312         // Load the scale factor, which was serialized as a double.
00313         double fp;
00314         ar >> fp;
00315         ViewScale = (FIXED16) fp;
00316 
00317         // Load the "state" of this view, ie. Is it an icon?  Is it top-most? etc
00318         INT32 a, b, c, d;
00319         ar >> a >> b >> c >> d;
00320         IsMinimised = (BOOL) a;
00321         IsMaximised = (BOOL) b;
00322         HasFocus    = (BOOL) c;
00323         AlwaysOnTop = (BOOL) d;
00324         
00325         // Finally, indicate that this is not a new view that has a default size etc
00326         // but an old one, so it should be set to match the data in the ViewState.
00327         IsNewView = FALSE;
00328     }
00329 }
00330 
00331 */
00332 
00333 
00334 #ifdef _DEBUG
00335 
00336 void ViewState::Dump() const
00337 {
00338     TCHAR              *pszTrue = wxT("TRUE"), *pszFalse = wxT("FALSE");
00339 
00340     TRACE( wxT("\nDUMP OF VIEWSTATE AT 0x%lX\n"), this );
00341 
00342     // Window attributes.
00343     TRACE( _T("\tScreenRect:\t\tlow = (%ld, %ld)\t\thigh = (%ld, %ld)\n"),
00344           ScreenRect.lo.x, ScreenRect.lo.y, ScreenRect.hi.x, ScreenRect.hi.y);
00345     TRACE( _T("\tParentRect:\t\tlow = (%ld, %ld)\t\thigh = (%ld, %ld)\n"),
00346           ParentRect.lo.x, ParentRect.lo.y, ParentRect.hi.x, ParentRect.hi.y);
00347     TRACE( _T("\tViewRect:\t\tlow = (%ld, %ld)\t\thigh = (%ld, %ld)\n"),
00348           ViewRect.lo.x, ViewRect.lo.y, ViewRect.hi.x, ViewRect.hi.y);
00349     TRACE( _T("\tIconPoint:\t\t(%ld, %ld)\n"), IconPoint.x, IconPoint.y);
00350     TRACE( _T("\tIsNewView:\t\t%s\n"), (IsNewView ? pszTrue : pszFalse));
00351     TRACE( _T("\tIsMinimised:\t%s\n"), (IsMinimised ? pszTrue : pszFalse));
00352     TRACE( _T("\tIsMaximised:\t%s\n"), (IsMaximised ? pszTrue : pszFalse));
00353     TRACE( _T("\tAlwaysOnTop:\t%s\n"), (AlwaysOnTop ? pszTrue : pszFalse));
00354 
00355     // Document view attributes.
00356     TRACE( _T("\tWork-Area Ext:\t(%ld, %ld)  -->  (%ld, %ld)\n"),
00357           INT32(WorkAreaExtent.lo.x), INT32(WorkAreaExtent.lo.y),
00358           INT32(WorkAreaExtent.hi.x), INT32(WorkAreaExtent.hi.y) );
00359     TRACE( _T("\tScroll Offset:\t(%ld, %ld)\n"),
00360           INT32(ScrollPosition.x), INT32(ScrollPosition.y) );
00361 //  TRACE( _T("\tPixel Width:\t%ld\n\tPixelHeight:\t%ld\n"), PixelWidth, PixelHeight);
00362 }
00363 
00364 #endif

Generated on Sat Nov 10 03:48:58 2007 for Camelot by  doxygen 1.4.4