00001 // $Id: units.h 1261 2006-06-06 11:58:26Z 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 // Definition of the units class 00099 00100 #ifndef INC_UNITS 00101 #define INC_UNITS 00102 00103 #include "list.h" 00104 #include "unittype.h" 00105 #include "pump.h" 00106 #include "ccfile.h" 00107 00108 /*--------------------------------------------------------------------------------- 00109 00110 The defines below were calculated using the following facts : 00111 00112 1 mile = 1.60934 kilometres 00113 1 mile = 1760 yards 00114 00115 They define the number of millipoints in each of the default unit types supported by Camelot. 00116 00117 (MarkN 8/3/94 & 28/6/94) 00118 */ 00119 00120 #define MM_MP_VAL 2834.652715 // Num millipoints in a millimetre 00121 #define CM_MP_VAL (MM_MP_VAL*10) // Num millipoints in a centimetre 00122 #define M_MP_VAL (CM_MP_VAL*100) // Num millipoints in a metre 00123 #define KM_MP_VAL ( M_MP_VAL*1000) // Num millipoints in a kilometre 00124 00125 #define MP_MP_VAL 1.0 // Num millipoints in a millipoint (well, it's consistant) 00126 #define PT_MP_VAL (MP_MP_VAL*1000) // Num millipoints in a computer point 00127 #define PI_MP_VAL (PT_MP_VAL*12) // Num millipoints in a pica 00128 #define IN_MP_VAL (PI_MP_VAL*6) // Num millipoints in an inch 00129 #define FT_MP_VAL (IN_MP_VAL*12) // Num millipoints in a foot 00130 #define YD_MP_VAL (FT_MP_VAL*3) // Num millipoints in a yard 00131 #define MI_MP_VAL (YD_MP_VAL*1760) // Num millipoints in a mile 00132 #define PX_MP_VAL 750.0 // Num millipoints in a pixel (1/96 inch) 00133 00134 // Unit flags type definition 00135 struct UnitFlagsType 00136 { 00137 BOOL Prefix : 1; // TRUE if unit ident string should prefix value 00138 // Example prefix unit : "$4.30" 00139 // Example suffix unit : "23.1km" 00140 BOOL DefaultUnit : 1; // TRUE if this unit is one of the default units in Camelot 00141 // Default units cannot be edited or deleted 00142 }; 00143 00144 typedef enum 00145 { 00146 UNITREASON_OK, 00147 UNITREASON_HASDESCENDENTS, 00148 UNITREASON_BEINGUSED 00149 } UnitReason; 00150 00151 /******************************************************************************************** 00152 00153 > class Unit: public ListItem 00154 00155 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00156 Created: 28/6/94 00157 Purpose: Encapsulates units within Camelot. 00158 All units (i.e. default and user-defined ones) are an instance of this class. 00159 Each document has its own list of units controlled by an instance of DocUnitList 00160 within the Document class. 00161 Therefore you should get hold of the DocUnitList within the current doc when you 00162 want to add/delete/edit/find a unit. 00163 SeeAlso: DocUnitList,Document 00164 00165 ********************************************************************************************/ 00166 00167 class Unit : public ListItem 00168 { 00169 CC_DECLARE_DYNAMIC(Unit) 00170 00171 public: 00172 Unit(); 00173 ~Unit(); 00174 00175 static BOOL Init(); 00176 static BOOL Deinit(); 00177 00178 BOOL IsDefault(); 00179 BOOL SetDefaultState(BOOL State); 00180 BOOL IsPrefix(); 00181 BOOL SetPrefixState(BOOL State); 00182 00183 UnitType GetUnitType(); 00184 BOOL SetUnitType(UnitType NewUnitType); 00185 00186 double GetMillipoints(); 00187 BOOL SetMillipoints(double NewMillipoints); 00188 00189 UnitType GetBaseUnitType(); 00190 BOOL SetBaseUnitType(UnitType NewBaseUnitType); 00191 double GetBaseNumerator(); 00192 BOOL SetBaseNumerator(double NewBaseNumerator); 00193 double GetBaseDenominator(); 00194 BOOL SetBaseDenominator(double NewBaseDenominator); 00195 00196 String_32 GetToken(); 00197 BOOL SetToken(const String_32& NewToken); 00198 String_32 GetSpecifier(); 00199 BOOL SetSpecifier(const String_32& NewSpecifier); 00200 00201 private: 00202 00203 // Each unit has a unit type. This allows standard units to be accessed 00204 // easily via the constants defined by enum UnitType 00205 UnitType ThisUnitType; 00206 00207 // Millipoints is the num millipoints in 1 of these units 00208 // I have used millipoints here because all object dimensions in Camelot 00209 // are defined in millipoints 00210 // E.g. "1 in" = 72000.0 millipoints 00211 double Millipoints; 00212 00213 // The flags of this unit 00214 UnitFlagsType Flags; 00215 00216 // BaseUnitType is the unit which this is based on 00217 // BaseNumerator and BaseDenominator define how many BaseUnitTypes make 00218 // one of these units 00219 // E.g. one furlong = 220 yards 00220 // so BaseUnitType == YARDS 00221 // BaseNumerator == 220 00222 // BaseDenominator == 1 00223 UnitType BaseUnitType; 00224 double BaseNumerator; 00225 double BaseDenominator; 00226 00227 // Set of strings used to identify the unit 00228 // "Token" is the string used in drop-down lists of units to identify it 00229 // "Specifier" is the string used in ed fields to specify a particular unit 00230 // E.g. Token == "Furlong" , Specifier == "fl" 00231 // Token == "Dollars" , Specifier == "$" 00232 String_32 Token; 00233 String_32 Specifier; 00234 }; 00235 00236 00237 /******************************************************************************************** 00238 00239 > class DocUnitList: public List 00240 00241 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00242 Created: 5/7/94 00243 Purpose: Encapsulates units within Camelot. 00244 All units (i.e. default and user-defined ones) are an instance of this class. 00245 Each document has its own list of units controlled by an instance of DocUnitList 00246 within the Document class. 00247 Therefore you should get hold of the DocUnitList within the current doc when you 00248 want to add/delete/edit/find a unit. 00249 SeeAlso: DocUnitList,Document 00250 00251 ********************************************************************************************/ 00252 00253 class DocUnitList : public List 00254 { 00255 CC_DECLARE_DYNAMIC(DocUnitList) 00256 00257 public: 00258 DocUnitList(); 00259 ~DocUnitList(); 00260 00261 static BOOL Init(); 00262 static BOOL Deinit(); 00263 00264 static DocUnitList* GetCurrentDocUnitList(); 00265 00266 // Useful routines for finding things given bits of info 00267 Unit* FindUnit(UnitType ThisUnit); 00268 Unit* FindUnit(INT32 Index); 00269 UnitType FindUnitType(const StringBase& Str); 00270 UnitType FindUnitTypeFromToken(const StringBase& Str); 00271 INT32 FindUnitIndex(UnitType ThisUnit); 00272 00273 Unit* FindUserUnit(INT32 Index); 00274 Unit* FindFirstUserUnit(); 00275 Unit* FindNextUserUnit(Unit* pThisUnit); 00276 00277 void UnitHasChanged(UnitType ChangedUnitType); 00278 BOOL MakeNewUnit(Unit** ppUnit,BOOL Initialise = TRUE); 00279 BOOL MakeDefaultUnits(); 00280 INT32 GetNumUnits(); 00281 UnitReason DeleteUnit(UnitType ThisUnitType); 00282 00283 BOOL HasDescendents(UnitType ThisUnitType); 00284 BOOL IsDescendent(Unit* pThisUnit,UnitType NewBaseUnitType); 00285 void RecalcUnit(Unit* pThisUnit); 00286 BOOL RecalcUnit(Unit* pThisUnit,UnitType ChangedUnitType); 00287 BOOL SetBaseUnitType(Unit* pThisUnit,UnitType NewBaseUnitType); 00288 00289 00290 // These are the default units used for displaying scaled details, 00291 // page details and font details. Getting and setting functions. 00292 UnitType GetScaleUnits(); 00293 void SetScaleUnits(UnitType NewUnits); 00294 UnitType GetPageUnits(); 00295 void SetPageUnits(UnitType NewUnits); 00296 UnitType GetFontUnits(); 00297 void SetFontUnits(UnitType NewUnits); 00298 00299 // From the UnitType get the token and the specifier 00300 String_32 GetToken(UnitType); 00301 String_32 GetSpecifier(UnitType); 00302 00303 private: 00304 BOOL MakeFactoryDefaultUnits(); 00305 00306 void OutputTrace(char* err,const TCHAR* TokenBuf); 00307 BOOL ReadLong(CCLexFile& file,void* pLong,char* err); 00308 BOOL ReadDouble(CCLexFile& file,double* pDouble,char* err); 00309 BOOL ReadString(CCLexFile& file,StringBase* pStr,char* err); 00310 00311 BOOL ReadUnitsFromFile(CCLexFile& file); 00312 BOOL ReadUnitsFromDisk(); 00313 BOOL ReadUnitsFromRes(); 00314 00315 static BOOL CheckUnitTypesValid(); 00316 00317 INT32 NumUnits; 00318 INT32 NextUnitNum; 00319 INT32 NextUnitType; 00320 00321 BOOL DefaultsMade; // TRUE if MakeDefaultUnits() has been called 00322 00323 UnitType ScaleUnits; 00324 UnitType PageUnits; 00325 UnitType FontUnits; 00326 UnitType LastEditedUnit; 00327 }; 00328 00329 /******************************************************************************************** 00330 00331 > class UnitMsg: public Msg 00332 00333 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00334 Created: 15/7/94 00335 Purpose: This message is sent whenever something happens to a unit 00336 SeeAlso: - 00337 00338 ********************************************************************************************/ 00339 00340 class UnitMsg: public Msg 00341 { 00342 CC_DECLARE_DYNAMIC(UnitMsg); 00343 public: 00344 00345 enum UnitMsgType 00346 { 00347 BEFOREDELETE, // The unit is about to be deleted from the document 00348 AFTERDELETE, // The unit has just been deleted from the document 00349 NEW, // A new unit has just been created 00350 CHANGED // An existing unit has changed definition 00351 }; 00352 00353 UnitMsgType MsgType; // The message type 00354 DocUnitList* pDocUnitList; // The doc unit list this unit belongs to 00355 UnitType ThisUnitType; // The unit this message refers to 00356 00357 UnitMsg(DocUnitList* pDocList, UnitType UType, UnitMsgType TypeMsg): 00358 MsgType(TypeMsg), pDocUnitList(pDocList), ThisUnitType(UType) { } 00359 }; 00360 00361 00362 #endif // INC_UNITS