ordlist.h

Go to the documentation of this file.
00001 // $Id: ordlist.h 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 // ordlist.h -- the OrderedList class
00100 
00101 #if TRUE
00102 // OrderedList is no longer used by anything
00103 // If you think you might want to use an OrderedList, ask Jason about them first
00104 // and he'll try to make you see the error of your ways...
00105 
00106 #ifndef INC_ORDLIST
00107 #define INC_ORDLIST
00108 
00109 
00110 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "listitem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 
00113 
00114 
00115 /***********************************************************************************************
00116 
00117 <   ListComparator
00118 
00119     Comment:    typedef INT32 (*ListComparator)(OrderedList *ParentList,
00120                                                 ListItem *A, ListItem *B);
00121 
00122                 This defines a function type which is passed to and used
00123                 by OrderedList objects to sort OrderedList sequences for you.
00124 
00125                 The function should return negative, 0, or positive values to
00126                 indicate that A is considered less-than, equal-to, or greater-than B.
00127 
00128                 'ParentList' is a pointer to the OrderedList object which contains
00129                 the list on whose items you are operating. This is useful in some cases
00130                 (e.g. the ColourList can provide colour contexts for its sort functions
00131                 to use; these are used on a per-document basis and may change the
00132                 resulting sort order).
00133 
00134                 Note that you should be very careful only to use a ListComparator
00135                 function on OrderedLists made up of appropriate ListItem objects.
00136                 It would be best, if possible, to use runtime classing to check
00137                 this in an ENSURE for the debug build, to avoid accidental misuse.
00138 
00139     SeeAlso:    OrderedList::SelectOrder; OrderedList::Unsorted
00140     Documentation:  HowToUse\ordlist.doc
00141 
00142 ***********************************************************************************************/
00143 
00144 class OrderedList;
00145 typedef INT32 (*ListComparator)(OrderedList *, ListItem *, ListItem *);
00146 
00147 
00148 /***********************************************************************************************
00149 
00150 >   class ComparatorInfo : public ListItem
00151 
00152     Purpose:    This defines an object which is used to describe a sorting order.
00153 
00154                 A list of these objects is provided by all OrderdList objects, to
00155                 detail all of the sort orders which may be used on that type of
00156                 OrderedList. (The OrderedList base class provides only one sort order,
00157                 "Unsorted")
00158 
00159                 The idea behind this is to derive classes from the OrderedList
00160                 (see the ColourList class, collist.h, for an example that does this)
00161                 which provide a list of available sort modes that can be used on that
00162                 type of OrderedList. Thus, new sort modes can be added to the list class
00163                 and they can automatically appear as new sort-by modes in related dialogue
00164                 boxes etc.
00165 
00166                 Each ComparatorInfo contains a resource ID which references a name for
00167                 the sort type, e.g."Sort by Name", "Sort by Date", etc, plus a function
00168                 pointer to a ListComparator function which defines the sort order.
00169 
00170                 External entities (tool dlls etc) can call OrderedList::GetSortOrders
00171                 and List::AddTail to add their own sort orders to the available ones.
00172 
00173     SeeAlso:    OrderedList::GetSortOrders; keyword ListComparator; ColourList
00174     Documentation:  HowToUse\ordlist.doc
00175 
00176 ***********************************************************************************************/
00177 
00178 class CCAPI ComparatorInfo : public ListItem
00179 {
00180 
00181 CC_DECLARE_MEMDUMP(ComparatorInfo)
00182 
00183 public:
00184     ComparatorInfo();
00185     ComparatorInfo(const ComparatorInfo &other);
00186     ComparatorInfo(ListComparator Compare, UINT32 SortName, BOOL Reverse = TRUE);
00187     ComparatorInfo(ListComparator Compare, const String_32 &Name, BOOL Reverse = TRUE);
00188 
00189     inline const String_32 &GetSortName(void) const { return SortName; };
00190     inline ListComparator GetSortFn(void) const     { return SortFn; };
00191     inline BOOL CanBeReversed(void) const           { return CanReverse; };
00192 
00193 protected:
00194     String_32 SortName; 
00195     ListComparator SortFn;      // Comparator function that defines the sort order
00196     BOOL CanReverse;            // TRUE if this sort can be applied in reverse
00197 };
00198 
00199 
00200 
00201 
00202 /***********************************************************************************************
00203 
00204 <   SortKey; MaxColourSortKeys
00205 
00206     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00207     Created:    1/6/94
00208     Purpose:    Holds information describing a sort key - the ComparatorInfo
00209                 describing the sort, and a boolean determining if the sort is 
00210                 in reverse order.
00211 
00212                 For examples of use, see the ColourList, ColourBar, and ColourSortDlg,
00213                 which provide a 2-key sort mechanism using arrays of SortKeys.
00214                 These arrays are MaxColourSortKeys in length
00215     Documentation:  HowToUse\ordlist.doc
00216 
00217 ***********************************************************************************************/
00218 
00219 typedef struct
00220 {
00221     ComparatorInfo  *Info;
00222     BOOL            Reversed;
00223 } SortKey;
00224 
00225 
00226 const INT32 MaxSortKeys = 2;
00227 
00228 
00229 /***********************************************************************************************
00230 
00231 >   class SequenceItem : public ListItem
00232 
00233     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00234     Created:    16/5/94
00235     Friends:    OrderedList
00236     Purpose:    A list of SequenceItems is used to point to an OrderedList's
00237                 Master List Items in an arbitrary order. Each SequenceItem is 
00238                 thus made up solely of a Master-Item pointer.
00239     Scope:      Private (to OrderedList)
00240     SeeAlso:    OrderedList
00241     Documentation:  HowToUse\ordlist.doc
00242 
00243 ***********************************************************************************************/
00244 
00245 class CCAPI SequenceItem : public ListItem
00246 {
00247 friend class OrderedList;
00248 
00249 CC_DECLARE_MEMDUMP(SequenceItem)
00250 
00251 public:
00252     SequenceItem();
00253 
00254     inline ListItem *GetItem(void);
00255 
00256 protected:
00257     ListItem *MasterItem;           // Ptr to the actual Master List item
00258 };
00259 
00260 
00261 
00262 /***********************************************************************************************
00263 
00264 >   inline ListItem *SequenceItem::GetItem(void)
00265 
00266     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00267     Created:    16/5/94
00268     Friends:    
00269     Purpose:    Returns the actual ListItem referred to by a SequenceItem.
00270     SeeAlso:    OrderedList
00271 
00272 ***********************************************************************************************/
00273 
00274 ListItem *SequenceItem::GetItem(void)
00275 {
00276     return(MasterItem);
00277 }
00278 
00279 
00280 
00281 
00282 /***********************************************************************************************
00283 
00284 >   class OrderSequence : public ListItem
00285 
00286     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00287     Created:    16/5/94
00288     Friends:    OrderedList
00289     Purpose:    An OrderedList owns a set of OrderSequence objects. Each OrderSequence
00290                 is a list of SequenceItems which describe the Master List in a given
00291                 order.
00292     SeeAlso:    OrderedList; SequenceItem
00293     Documentation:  HowToUse\ordlist.doc
00294 
00295 ***********************************************************************************************/
00296 
00297 class CCAPI OrderSequence : public ListItem
00298 {
00299 friend class OrderedList;
00300 
00301 CC_DECLARE_MEMDUMP(OrderSequence)
00302 
00303 public:
00304     OrderSequence();
00305     OrderSequence(ListComparator Compare, BOOL Reverse = FALSE);
00306 
00307 protected:
00308     INT32               UsageCount;     // Number of clients who currently have this 'selected'
00309     BOOL            Cached;         // TRUE if this list has been sorted into correct order
00310     BOOL            Reversed;       // TRUE if this list is in reversed order
00311     ListComparator  Comparator;     // Sort-comparator which give the sort order; also used as ID
00312     List            Sequence;       // List of SequenceItems
00313 };
00314 
00315 
00316 
00317 /***********************************************************************************************
00318 
00319 >   class OrderedList : public CCObject
00320 
00321     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00322     Created:    16/5/94
00323     Purpose:    See docs... how\ordlist.doc
00324                 This class represents a linked list of ListItems, which can have more than
00325                 one oredering. (i.e. a set of items which are retained in several different
00326                 sequences).
00327 
00328                 This is achieved using a master list of all the list items stored in the list,
00329                 which is stored in order of creation. For each desired sort-order, an
00330                 OrderSequence is held, which is a list of SequenceItems - each SequenceItem is
00331                 a pointer to one item in the master list (there is a 1:1 relationship between
00332                 master ListItems and SequenceItems is a given Sequence).
00333 
00334                 Note that after Creating an OrderedList, you should call its Init() function.
00335 
00336     Notes:      You MUST remember to call OrderedList::Init() before using the list
00337 
00338                 OrderedLists are used in the following manner:
00339 
00340                     OrderSequence *Seq = MyOrderedList->SelectOrder(SortByName);
00341                     if (Seq != NULL)
00342                     {
00343                         SequenceItem *Item = Seq->GetFirst();
00344 
00345                         while(Item != NULL)
00346                         {
00347                             Item->GetItem()->DoSomething();
00348                             Item = Seq->GetNext(Item);
00349                         }
00350                     }
00351                     MyOrderedList->DeselectOrder(SortByName);                   
00352 
00353                 Special points of interest are:
00354                 Selection/Deselection.
00355                     These fuctions find the sequence of your choice, using the sort
00356                     comparator function (In this example 'SortByName') as a key.
00357                     When Selected for the first time, a new sequence will be created
00358                     and sorted using this function; this list is then cached for later
00359                     use. A count of the number of selections is kept in each list, so
00360                     that they can be deleted again when they are not in use.
00361 
00362                 GetItem()
00363                     As a SequenceItem is a list item containing a pointer to the master
00364                     list item, an extra level of indirection is needed to find the actual
00365                     list item.
00366 
00367                 Other than this, an OrderSequence is a normal list for traversal purposes.
00368 
00369                 It is MOST IMPORTANT that these lists be treated as read-only, and that all
00370                 write-operations on them are done through the OrderedList interface.
00371                 Although some functions seem to be missing (e.g. InsertAfter), these functions
00372                 are pointless on an OrderedList which will be sorted anyway!
00373 
00374                 You can, however, apply any operation to Master/Sequence list items, so long as
00375                 the result leaves all master items at the same memory addresses, and leaves all
00376                 lists containing the same set of items. (i.e. you can move an item to a new
00377                 position in the master list, but you cannot replace an item with a new item
00378                 unless you explicitly overwrite the data at that memory address)
00379 
00380     Documentation:  HowToUse\ordlist.doc
00381                 
00382 ***********************************************************************************************/
00383 
00384 class CCAPI OrderedList : public CCObject
00385 {
00386     CC_DECLARE_DYNAMIC( OrderedList )
00387 
00388 public:
00389     OrderedList();                                  // List constructor
00390     ~OrderedList();                                 // List destructor
00391 
00392     // Initialisation
00393     virtual BOOL Init(void);
00394 
00395     // List manipulation functions
00396     BOOL AddItem(ListItem *Item);
00397 
00398     ListItem *RemoveMasterItem(ListItem *TheItem);
00399     inline ListItem *RemoveItem(SequenceItem *TheItem);
00400 
00401     void DeleteAll(void);
00402 
00403     inline DWORD GetCount() const;
00404 
00405     void InvalidateCaches(void);
00406     inline void InvalidateSequenceCache(OrderSequence *TheSequence);    
00407 
00408     inline List *GetMasterList(void);
00409 
00410 
00411     // Functions for "connecting to" a particular ordering of the list
00412     List *SelectOrder(ListComparator Compare, BOOL Reverse = FALSE);
00413     void DeselectOrder(ListComparator Compare, BOOL Reverse = FALSE);
00414     void DestroyOrder(ListComparator Compare, BOOL Reverse = FALSE);
00415 
00416     void ReSortOrder(ListComparator Compare, BOOL Reverse = FALSE);
00417 
00418 
00419     // Access to the sort orders available from this class
00420     List *GetSortOrders(void);
00421     void AddSortOrder(const ComparatorInfo &CompInfo);
00422 
00423     inline void SetOwner(void *NewOwner);
00424     inline void *GetOwner(void) const;
00425 
00426 public:
00427     SortKey SortMode[MaxSortKeys];
00428         // The OrderedList contains a sort mode defined by several sort keys,
00429         // which can be used by any client if they so desire. For code that
00430         // does just this, see the kernel files gallery.h and gallery.cpp
00431         // This data is NOT used by the OrderedList, though it is initialised on
00432         // construction to contain {SortFn=NULL, Revered=FALSE} items.
00433 
00434 protected:
00435     List MasterList;            // Master list of actual stored ListItems
00436     List Sequences;             // List of the available ordering sequences
00437 
00438     List *SortOrders;           // List of available sorting functions
00439 
00440     void *Owner;                // Pointer to the object that 'owns' this list
00441 
00442     // Internal list management routines
00443     OrderSequence *FindSequence(ListComparator Compare, BOOL Reverse);
00444     OrderSequence *CreateSequence(ListComparator Compare, BOOL Reverse);
00445     BOOL SortSequence(OrderSequence *TheSeq);
00446 
00447     static INT32 Unsorted(OrderedList *, ListItem *, ListItem *);
00448 };
00449 
00450 
00451 
00452 /***********************************************************************************************
00453 
00454 >   inline void OrderedList::RemoveItem(SequenceItem *TheItem)
00455 
00456     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00457     Created:    18/5/94
00458     Returns:    -
00459     Purpose:    This function removes an item from the master list, given a SequenceItem
00460                 which references it. The item is really removed from the master list, and
00461                 ALL sequences are updated to no longer include this item.
00462 
00463 ***********************************************************************************************/
00464 
00465 ListItem *OrderedList::RemoveItem(SequenceItem *TheItem)
00466 {
00467     return(RemoveMasterItem(TheItem->GetItem()));
00468 }
00469 
00470 
00471 
00472 /***********************************************************************************************
00473 
00474 >   inline void OrderedList::InvalidateSequenceCache(Sequence *TheSequence)
00475 
00476     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00477     Created:    18/5/94
00478     Purpose:    Indicates to an OrderedList that a Sequence you are working on
00479                 is no longer guaranteed to be in the correct order (this will cause
00480                 the list to be re-sorted at the next call to SelectOrder). However,
00481                 generally you will probably need to use OrderedList::InvalidateCaches
00482                 if you change a list, in order to ensure that all sequences are
00483                 resorted.
00484     Scope:      Generally intended to be private
00485     SeeAlso:    OrderedList::InvalidateCaches
00486 
00487 ***********************************************************************************************/
00488 
00489 void OrderedList::InvalidateSequenceCache(OrderSequence *TheSequence)
00490 {
00491     TheSequence->Cached = FALSE;
00492 }
00493 
00494 
00495 /***********************************************************************************************
00496 
00497 >   inline List *OrderedList::GetMasterList(void)
00498 
00499     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00500     Created:    18/5/94
00501     Returns:    A pointer to the master list
00502     Purpose:    To find the Master list of ordinary ListItems on which the sequences of
00503                 this OrderedList are based. This is a normal List of the items, in no
00504                 particular order (in fact, this is guaranteed to be the creation order
00505                 of the OrderedList; Each new item is appended to the tail of the list)
00506 
00507     Notes:      IMPORTANT
00508     
00509                 This should be treated strictly as a READ ONLY list!
00510 
00511                 If you delete/insert items in this list, the OrderedList will fall flat
00512                 on its face, trash memory, and insult your mother recursively as it dies.
00513 
00514                 You must only party on items in this list via the main OrderedList interface
00515 
00516 ***********************************************************************************************/
00517 
00518 List *OrderedList::GetMasterList(void)
00519 {
00520     return(&MasterList);
00521 }
00522 
00523 
00524 
00525 /***********************************************************************************************
00526 
00527 >   inline DWORD GetCount() const
00528 
00529     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00530     Created:    23/5/94
00531     Returns:    The number of items in the list
00532     Purpose:    To find the number of items in the ordered list
00533 
00534 ***********************************************************************************************/
00535 
00536 DWORD OrderedList::GetCount() const
00537 {
00538     return(MasterList.GetCount());
00539 }
00540 
00541 
00542 
00543 /***********************************************************************************************
00544 
00545 >   inline void OrderedList::SetOwner(void *NewOwner)
00546 
00547     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00548     Created:    1/8/94
00549     Inputs:     NewOwner - A user-defined ID pointer to set as my 'owner'
00550     Purpose:    Sets the given pointer as the 'owner' of this list
00551                 (Used as an id system for the Gallery Subsystem)
00552     SeeAlso:    Gallery
00553 
00554 ***********************************************************************************************/
00555 
00556 void OrderedList::SetOwner(void *NewOwner)
00557 {
00558     Owner = NewOwner;
00559 }
00560 
00561 
00562 
00563 /***********************************************************************************************
00564 
00565 >   inline void *OrderedList::GetOwner(void) const
00566 
00567     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00568     Created:    1/8/94
00569     Returns:    The 'owner' pointer
00570     Purpose:    Gets the 'owner' pointer of this list
00571                 (Used as an id system for the Gallery Subsystem)
00572     SeeAlso:    Gallery
00573 
00574 ***********************************************************************************************/
00575 
00576 void *OrderedList::GetOwner(void) const
00577 {
00578     return(Owner);
00579 }
00580 
00581 #endif
00582 
00583 #endif
00584 

Generated on Sat Nov 10 03:46:22 2007 for Camelot by  doxygen 1.4.4