00001 // $Id: overlist.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 // Imagemap class 00099 00100 #include "camtypes.h" 00101 #include "overlist.h" 00102 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 00104 00105 00106 CC_IMPLEMENT_DYNAMIC(OverrideList, List) 00107 00108 /******************************************************************************************** 00109 00110 OverrideList::OverrideList() 00111 00112 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00113 Created: 22/4/97 00114 Purpose: Default constructor 00115 00116 ********************************************************************************************/ 00117 00118 OverrideList::OverrideList() : List() 00119 { 00120 } 00121 00122 /******************************************************************************************** 00123 00124 virtual void OverrideList::AddHead( OverrideListItem* poliToAdd) 00125 00126 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00127 Created: 22/4/97 00128 Inputs: poliToAdd The item to add 00129 00130 Returns: - 00131 00132 Purpose: Compares this list item with all the items in the list, 00133 to find out whether they override this list item or 00134 whether this list item overrides them. 00135 00136 If this list item overrides any items already present 00137 in the list, the items in the list are deleted and this 00138 list item is added. 00139 00140 If any item in the list overrides this list item, 00141 this list item is not added to the list. 00142 00143 This function simply calls the InsertBefore function. 00144 00145 SeeAlso: OverrideList::InsertBefore() 00146 00147 ********************************************************************************************/ 00148 00149 void OverrideList::AddHead( OverrideListItem* poliToAdd) 00150 { 00151 if (poliToAdd==NULL) 00152 { 00153 ERROR2RAW("OverrideList::AddHead - NULL parameter"); 00154 return; 00155 } 00156 00157 //Get the first item in the list 00158 OverrideListItem* pliFirst=(OverrideListItem*) GetHead(); 00159 00160 //Was there anything in the list? 00161 if (pliFirst!=NULL) 00162 { 00163 //Yes. So call our InsertBefore function 00164 InsertBefore(pliFirst, poliToAdd); 00165 } 00166 else 00167 { 00168 //No. So we need do no special checking - simply insert 00169 //the list item 00170 List::AddHead(poliToAdd); 00171 } 00172 00173 } 00174 00175 /******************************************************************************************** 00176 00177 virtual void OverrideList::AddTail( OverrideListItem* poliToAdd) 00178 00179 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00180 Created: 22/4/97 00181 Inputs: poliToAdd The item to add 00182 00183 Returns: - 00184 00185 Purpose: Compares this list item with all the items in the list, 00186 to find out whether they override this list item or 00187 whether this list item overrides them. 00188 00189 If this list item overrides any items already present 00190 in the list, the items in the list are deleted and this 00191 list item is added. 00192 00193 If any item in the list overrides this list item, 00194 this list item is not added to the list. 00195 00196 This function simply calls the InsertAfter function. 00197 00198 SeeAlso: OverrideList::InsertAfter() 00199 00200 ********************************************************************************************/ 00201 00202 void OverrideList::AddTail( OverrideListItem* poliToAdd) 00203 { 00204 if (poliToAdd==NULL) 00205 { 00206 ERROR2RAW("OverrideList::AddTail - NULL parameter"); 00207 return; 00208 } 00209 00210 //Get the last item in the list 00211 OverrideListItem* pliLast=(OverrideListItem*) GetTail(); 00212 00213 //Was there anything in the list? 00214 if (pliLast!=NULL) 00215 { 00216 //Yes. So call our InsertAfter function 00217 InsertAfter(pliLast, poliToAdd); 00218 } 00219 else 00220 { 00221 //No. So we need do no special checking - simply insert 00222 //the list item 00223 List::AddTail(poliToAdd); 00224 } 00225 00226 //And add our item after it 00227 InsertAfter(pliLast, poliToAdd); 00228 00229 } 00230 00231 /******************************************************************************************** 00232 00233 virtual ListItem* OverrideList::InsertBefore(OverrideListItem* here, OverrideListItem* item); 00234 00235 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00236 Created: 22/4/97 00237 Inputs: poliToAdd The item to add 00238 00239 Returns: - 00240 00241 Purpose: Compares this list item with all the items in the list, 00242 to find out whether they override this list item or 00243 whether this list item overrides them. 00244 00245 It does this by calling the function 00246 OverrideListItem::OverrideFromBelow on all items 00247 below the insertion position, and MergeListItem::OverrideFromAbove 00248 on all items above the insertion position. 00249 00250 If this list item overrides any items already present 00251 in the list, the items in the list are deleted and this 00252 list item is added. 00253 00254 If any item in the list overrides this list item, 00255 this list item is not added to the list. 00256 00257 This function simply calls the InsertBefore function. 00258 00259 SeeAlso: OverrideList::InsertBefore() 00260 00261 ********************************************************************************************/ 00262 00263 ListItem* OverrideList::InsertBefore(OverrideListItem* pliInsertPoint, OverrideListItem* pliToInsert) 00264 { 00265 ERROR2IF(pliToInsert==NULL, NULL, "OverrideList::InsertBefore - NULL parameter"); 00266 00267 //This variable will tell us whether to insert pliToInsert 00268 //into the list 00269 BOOL fInsert=TRUE; 00270 00271 //First compare pliToInsert with everything below pliInsertPoint in the list 00272 fInsert=CompareWithItemsBelow(pliInsertPoint, pliToInsert); 00273 00274 //Now get the list item above pliInsertPoint 00275 OverrideListItem* pliTest=(OverrideListItem*) GetPrev(pliInsertPoint); 00276 00277 //If there is anything above pliInsertPoint 00278 if (fInsert && pliTest!=NULL) 00279 { 00280 //Then test everything above pliInsertPoint 00281 fInsert=CompareWithItemsAbove(pliInsertPoint, pliToInsert); 00282 } 00283 00284 //So, should we insert pliToInsert? 00285 if (fInsert) 00286 //Yes. So do it. 00287 return List::InsertBefore(pliInsertPoint, pliToInsert); 00288 else 00289 //No. So return an error value. 00290 return NULL; 00291 00292 } 00293 00294 /******************************************************************************************** 00295 00296 virtual ListItem* OverrideList::InsertBefore(OverrideListItem* here, OverrideListItem* item); 00297 00298 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00299 Created: 22/4/97 00300 Inputs: poliToAdd The item to add 00301 00302 Returns: - 00303 00304 Purpose: Compares this list item with all the items in the list, 00305 to find out whether they override this list item or 00306 whether this list item overrides them. 00307 00308 This function simply calls the other InsertBefore override. 00309 00310 SeeAlso: OverrideList::InsertBefore() 00311 00312 ********************************************************************************************/ 00313 00314 LISTPOS OverrideList::InsertBefore(LISTPOS here, OverrideListItem* item) 00315 { 00316 00317 ERROR2IF(item==NULL, NULL, "OverrideList::InsertBefore - NULL parameter"); 00318 00319 00320 //First find the list item at the position we have been given 00321 OverrideListItem* pliInsertionPoint=(OverrideListItem*) FindItem(here); 00322 00323 //If we have not found it, return -1 00324 if (pliInsertionPoint==NULL) 00325 return -1; 00326 00327 //Otherwise, call our other function to do the insertion 00328 OverrideListItem* pliResult=(OverrideListItem*) InsertBefore(pliInsertionPoint, item); 00329 00330 //If we have been returned NULL, then return an error value 00331 if (pliResult==NULL) 00332 return -1; 00333 00334 //Otherwise, find our newly returned list item in the list 00335 //and return it 00336 return FindPosition(pliResult); 00337 00338 } 00339 00340 /******************************************************************************************** 00341 00342 virtual ListItem* OverrideList::InsertAfter(OverrideListItem* here, OverrideListItem* item); 00343 00344 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00345 Created: 22/4/97 00346 Inputs: poliToAdd The item to add 00347 00348 Returns: - 00349 00350 Purpose: Compares this list item with all the items in the list, 00351 to find out whether they override this list item or 00352 whether this list item overrides them. 00353 00354 It does this by calling the function 00355 MergeListItem::OverrideFromBelow on all items 00356 below the insertion position, and MergeListItem::OverrideFromAbove 00357 on all items above the insertion position. 00358 00359 If this list item overrides any items already present 00360 in the list, the items in the list are deleted and this 00361 list item is added. 00362 00363 If any item in the list overrides this list item, 00364 this list item is not added to the list. 00365 00366 This function simply calls the InsertBefore function. 00367 00368 SeeAlso: OverrideList::InsertBefore() 00369 00370 ********************************************************************************************/ 00371 00372 ListItem* OverrideList::InsertAfter(OverrideListItem* pliInsertPoint, OverrideListItem* pliToInsert) 00373 { 00374 ERROR2IF(pliToInsert==NULL, NULL, "OverrideList::InsertAfter - NULL parameter"); 00375 00376 //This variable will tell us whether to insert pliToInsert 00377 //into the list 00378 BOOL fInsert=TRUE; 00379 00380 //First compare pliToInsert with everything above pliInsertPoint in the list 00381 fInsert=CompareWithItemsAbove(pliInsertPoint, pliToInsert); 00382 00383 //Now get the list item after pliInsertPoint 00384 OverrideListItem* pliTest=(OverrideListItem*) GetNext(pliInsertPoint); 00385 00386 //If there is anything before pliInsertPoint 00387 if (fInsert && pliTest!=NULL) 00388 { 00389 //Then test everything before pliInsertPoint 00390 fInsert=CompareWithItemsBelow(pliInsertPoint, pliToInsert); 00391 } 00392 00393 //So, should we insert pliToInsert? 00394 if (fInsert) 00395 //Yes. So do it. 00396 return List::InsertAfter(pliInsertPoint, pliToInsert); 00397 else 00398 //No. So return an error value. 00399 return NULL; 00400 00401 00402 00403 } 00404 00405 /******************************************************************************************** 00406 00407 virtual ListItem* OverrideList::InsertAfter(OverrideListItem* here, OverrideListItem* item); 00408 00409 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00410 Created: 22/4/97 00411 Inputs: poliToAdd The item to add 00412 00413 Returns: - 00414 00415 Purpose: Compares this list item with all the items in the list, 00416 to find out whether they override this list item or 00417 whether this list item overrides them. 00418 00419 This function simply calls the other InsertAfter override. 00420 00421 SeeAlso: OverrideList::InsertAfter() 00422 00423 ********************************************************************************************/ 00424 00425 LISTPOS OverrideList::InsertAfter(LISTPOS here, OverrideListItem* item) 00426 { 00427 ERROR2IF(item==NULL, 0, "OverrideList::InsertAfter - NULL parameter"); 00428 00429 //First find the list item at the position we have been given 00430 OverrideListItem* pliInsertionPoint=(OverrideListItem*) FindItem(here); 00431 00432 //If we have not found it, return -1 00433 if (pliInsertionPoint==NULL) 00434 return -1; 00435 00436 //Otherwise, call our other function to do the insertion 00437 OverrideListItem* pliResult=(OverrideListItem*) InsertAfter(pliInsertionPoint, item); 00438 00439 //If we have been returned NULL, then return an error value 00440 if (pliResult==NULL) 00441 return -1; 00442 00443 //Otherwise, find our newly returned list item in the list 00444 //and return it 00445 return FindPosition(pliResult); 00446 00447 } 00448 00449 /***************************************************** 00450 00451 Toolkit functions 00452 00453 ****************************************************/ 00454 00455 /******************************************************************************************** 00456 00457 virtual BOOL OverrideList::CompareWithItemsAbove(OverrideListItem* pliStartPos, OverrideListItem* pliToInsert); 00458 00459 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00460 Created: 22/4/97 00461 Inputs: pliStartPos The position to start searching from 00462 pliToAdd The list items to add 00463 00464 Returns: FALSE if pliToAdd was overridden by another 00465 item in the list 00466 00467 TRUE if pliToAdd was not overridden 00468 00469 Note that, if pliToAdd overrides another item in the list, 00470 this does not affect the result returned. 00471 00472 Purpose: Compares this list item with all the items 00473 above pliStartPos, inclusive. 00474 00475 SeeAlso: OverrideList::InsertBefore(), OverrideList::After() 00476 00477 ********************************************************************************************/ 00478 00479 BOOL OverrideList::CompareWithItemsAbove(OverrideListItem* pliStartPos, OverrideListItem* pliToInsert) 00480 { 00481 //This pointer will show the item we are looking at 00482 OverrideListItem* pliLook=pliStartPos; 00483 00484 //While we are still looking at a valid item 00485 while (pliLook!=NULL) 00486 { 00487 //This will be the next item we look at 00488 //It's important to do this now - because we may delete pliLook in a moment 00489 OverrideListItem* pliNext=(OverrideListItem*) GetPrev(pliLook); 00490 00491 //Does the item we are looking at override the item 00492 //we are about to insert? 00493 if (pliLook->OverrideFromAbove(pliToInsert)) 00494 { 00495 //Yes. So return to say that we're not going to insert the 00496 //item 00497 return FALSE; 00498 } 00499 00500 //Does the item we are about to insert override the item 00501 //we are looking at? 00502 if (pliToInsert->OverrideFromBelow(pliLook)) 00503 { 00504 //Yes. So delete the item we are looking at. 00505 RemoveItem(pliLook); 00506 delete pliLook; 00507 } 00508 00509 //And move on to the next item 00510 pliLook=pliNext; 00511 } 00512 00513 //ANd return to say that pliToInsert has not been overridden 00514 return TRUE; 00515 } 00516 00517 /******************************************************************************************** 00518 00519 virtual BOOL OverrideList::CompareWithItemsBelow(OverrideListItem* pliStartPos, OverrideListItem* pliToInsert) 00520 00521 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00522 Created: 22/4/97 00523 Inputs: pliStartPos The position to start searching from 00524 pliToAdd The list items to add 00525 00526 Returns: FALSE if pliToAdd was overridden by another 00527 item in the list 00528 00529 TRUE if pliToAdd was not overridden 00530 00531 Note that, if pliToAdd overrides another item in the list, 00532 this does not affect the result returned. 00533 00534 Purpose: Compares this list item with all the items 00535 below pliStartPos, inclusive. 00536 00537 SeeAlso: OverrideList::InsertBefore(), OverrideList::After() 00538 00539 ********************************************************************************************/ 00540 00541 BOOL OverrideList::CompareWithItemsBelow(OverrideListItem* pliStartPos, OverrideListItem* pliToInsert) 00542 { 00543 //This pointer will show the item we are looking at 00544 OverrideListItem* pliLook=pliStartPos; 00545 00546 //While we are still looking at a valid item 00547 while (pliLook!=NULL) 00548 { 00549 //This will be the next item we look at 00550 //It's important to do this now - because we may delete pliLook in a moment 00551 OverrideListItem* pliNext=(OverrideListItem*) GetNext(pliLook); 00552 00553 //Does the item we are looking at override the item 00554 //we are about to insert? 00555 if (pliLook->OverrideFromBelow(pliToInsert)) 00556 { 00557 //Yes. So return to say that we're not going to insert the 00558 //item 00559 return FALSE; 00560 } 00561 00562 //Does the item we are about to insert override the item 00563 //we are looking at? 00564 if (pliToInsert->OverrideFromAbove(pliLook)) 00565 { 00566 //Yes. So delete the item we are looking at. 00567 RemoveItem(pliLook); 00568 delete pliLook; 00569 } 00570 00571 //And move on to the next item 00572 pliLook=pliNext; 00573 } 00574 00575 //And return to say that pliToInsert has not been overridden 00576 return TRUE; 00577 } 00578 00579 00580 00581