colgal.cpp

Go to the documentation of this file.
00001 // $Id: colgal.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 // colgal.cpp - Implementation of the ColourGallery class
00099 
00100 /*
00101 */
00102 
00103 
00104 #include "camtypes.h"
00105 
00106 
00107 
00108 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "ccolbar.h"
00110 #include "coldlog.h"
00111 #include "colgal.h"
00112 #include "colmsg.h"
00113 #include "colormgr.h"
00114 #include "colpick.h"
00115 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 //#include "galstr.h"
00118 //#include "jason.h"
00119 #include "lineattr.h"
00120 #include "oilfiles.h"
00121 //#include "markn.h"
00122 //#include "resource.h"
00123 #include "sginit.h"
00124 
00125 //#include "will2.h"
00126 
00127 // This is not compulsory, but you may as well put it in so that the correct version
00128 // of your file can be registered in the .exe
00129 DECLARE_SOURCE("$Revision: 1282 $");
00130 
00131 
00132 
00133 
00134 
00135 
00136 #if FALSE
00137 // The old Colour Gallery no longer exists. THIS FILE IS DEFUNCT
00138 
00139 
00140 CC_IMPLEMENT_DYNCREATE(ColourGallery, Gallery)
00141 CC_IMPLEMENT_DYNCREATE(OpDisplayColourGallery,Operation);
00142 
00143 // This will get Camelot to display the filename and linenumber of any memory allocations
00144 // that are not released at program exit
00145 #define new CAM_DEBUG_NEW
00146 
00147 
00148 
00149 
00150 
00151 // Static member variables
00152 ColourGallery *ColourGallery::TheColourGallery = NULL;
00153 
00154 static BOOL LockColourChange = FALSE;
00155 
00156 
00157 
00158 /********************************************************************************************
00159 
00160 >   ColourGallery::ColourGallery() : Gallery()
00161 
00162     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00163     Created:    18/7/94
00164     Purpose:    Colour Gallery constructor
00165 
00166 ********************************************************************************************/
00167 
00168 ColourGallery::ColourGallery() : Gallery()
00169 {
00170     TheColourGallery = this;                // Set up our static instance pointer
00171 
00172     // Just in case we arrive at the party late, ensure that the SelectedDoc
00173     // has a display cache - this is needed for the colour bar if it is to be able
00174     // to display a colour list
00175     if (Document::GetSelected() != NULL)
00176         CreateCachedDisplayList(Document::GetSelected());
00177 }
00178 
00179 
00180 
00181 /********************************************************************************************
00182 
00183 >   ColourGallery::~ColourGallery()
00184 
00185     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00186     Created:    1/8/94
00187     Purpose:    Colour Gallery destructor
00188 
00189 ********************************************************************************************/
00190 
00191 ColourGallery::~ColourGallery()
00192 {
00193     ERROR3IF(TheColourGallery != this,
00194         "There seem to have been several ColourGallery instantiations?!\n");
00195 
00196     TheColourGallery = NULL;
00197 }
00198 
00199 
00200 
00201 /********************************************************************************************
00202 
00203 >   virtual BOOL ColourGallery::PreCreate(void)
00204 
00205     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00206     Created:    18/7/94
00207     Returns:    TRUE if it is successful; FALSE to abort creation of the window
00208                 FALSE => ERROR1
00209 
00210     Purpose:    Colour Gallery PreCreate handler
00211 
00212     Notes:      This method is called whenever the gallery window is about to be
00213                 created.
00214                 At this point, the gallery should set up data structures - it is
00215                 *essential* that DisplayList is set up by the end of this method.
00216                 (As it is used in the creation of the window)
00217                 In the case of the colour gallery, the display list has already
00218                 been set up, so this function needs take no action. (However, if
00219                 the DisplayList is NULL, it refuses to allow the Gallery window
00220                 to be created)
00221 
00222                 Note that you cannot AddItemToDisplay etc in this method, as 
00223                 although the display list exists, the related window controls
00224                 do not yet exist, and ENSURE failures will result.
00225 
00226 ********************************************************************************************/
00227 
00228 BOOL ColourGallery::PreCreate(void)
00229 {
00230     SwitchTheDisplayList(NULL);         // Ensure there's a DisplayList for the GalleryDoc
00231     return(GetCurrentDisplayList() != NULL);
00232 }
00233 
00234 
00235 
00236 /********************************************************************************************
00237 
00238 >   virtual BOOL ColourGallery::PostCreate(void)
00239 
00240     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00241     Created:    18/7/94
00242     Returns:    TRUE if it is successful; FALSE to abort creation of the window
00243 
00244     Purpose:    Colour Gallery PostCreate handler
00245 
00246     Notes:      This method is called whenever the gallery window is created, AFTER
00247                 the window has been brought into existence.
00248                 At this point (and henceforth), the gallery can add items to]
00249                 the DisplayList, etc. as the display controls now exist.
00250 
00251 ********************************************************************************************/
00252 
00253 BOOL ColourGallery::PostCreate(void)
00254 {
00255     if (GetCurrentDisplayList() == NULL)
00256         return(FALSE);
00257 
00258     ReadNewColourList();
00259 
00260     return(TRUE);
00261 }
00262 
00263 
00264 
00265 /********************************************************************************************
00266 
00267 >   static void ColourGallery::ColourListHasChanged(ColourList *TheList)
00268 
00269     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00270     Created:    18/7/94
00271     Inputs:     TheList - The list which has been changed
00272 
00273     Purpose:    The ColourManager calls this function just prior to broadcasting a
00274                 LISTUPDATED ColourChangingMsg. This allows us to update our display list
00275                 so that entities (such as the colour bar), which interrogate us upon
00276                 recieving the message, get correct information (as if we sat on the
00277                 msg broadcast, we could not guarantee that we'd get it first)
00278 
00279     Notes:      This method is called whenever the gallery window is created, AFTER
00280                 the window has been brought into existence.
00281                 At this point (and henceforth), the gallery can add items to]
00282                 the DisplayList, etc. as the display controls now exist.
00283 
00284 ********************************************************************************************/
00285 
00286 void ColourGallery::ColourListHasChanged(ColourList *TheList)
00287 {
00288     if (TheColourGallery == NULL)
00289         return;
00290 
00291     TheColourGallery->UnshadeGallery();
00292     if (TheColourGallery->GetCurrentDisplayList() != NULL)
00293         TheColourGallery->ReadNewColourList();
00294 }
00295 
00296 
00297 
00298 /********************************************************************************************
00299 
00300 >   void ColourGallery::SetSelectionFromDocument(void)
00301 
00302     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00303     Created:    11/10/94
00304 
00305     Purpose:    Sets the colour gallery listbox selection state based upon the currently
00306                 selected object(s) in the document (to show the current fill/stroke colours)
00307 
00308     Scope:      private
00309 
00310 ********************************************************************************************/
00311 
00312 void ColourGallery::SetSelectionFromDocument(void)
00313 {
00314     DocColour *SelColour[2];
00315     BOOL AreCurrentAttrs =
00316             ColourManager::GetCurrentLineAndFillColours(&SelColour[0], &SelColour[1]);
00317 
00318     DeselectAllItems();                 // Clear the current selection
00319     if (!AreCurrentAttrs)
00320     {
00321         // The line/fill colours returned are those of the selection, not the current attrs
00322         IndexedColour *Parent;
00323         
00324         for (INT32 i = 0; i < 2; i++)       // For each colour (line, fill)
00325         {
00326             if (SelColour[i] != NULL)   // If there is a single selected colour
00327             {
00328                 Parent = SelColour[i]->FindParentIndexedColour();       // Find the named IxColour
00329                 if (Parent != NULL && Parent->IsNamed())                // (if any)
00330                 {
00331                     SequenceItem *SeqItem = FindSequenceItem(Parent);   // And select it
00332 
00333                     if (SeqItem != NULL)
00334                         SetDisplayItemSelState(SeqItem, TRUE);
00335                 }
00336             }
00337         }
00338     }
00339 }
00340 
00341 
00342 
00343 /********************************************************************************************
00344 
00345 >   MsgResult ColourGallery::Message(Msg* Message) 
00346 
00347     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00348     Created:    18/7/94
00349     Inputs:     Message- The message to handle
00350 
00351     Purpose:    Colour Gallery dialog message handler
00352 
00353     Notes:      This should generally only process GalleryMsg messages and things
00354                 like DocChagingMsg messages which might affect what list you want
00355                 your gallery to display. All unprocessed messages must be passed
00356                 down to the base class Gallery::Message method
00357 
00358 ********************************************************************************************/
00359 
00360 MsgResult ColourGallery::Message(Msg* Message) 
00361 {
00362     // Note that all Dialogue messages should have been handled by the base class
00363     // message handler. Unless we're being antisocial, all we should have to
00364     // process here are list changing messages such as Doc- or Colour-ChangingMsg
00365 
00366     if (MESSAGE_IS_A(Message, ColourChangingMsg))
00367     {
00368         ColourChangingMsg *Msg = (ColourChangingMsg *) Message;
00369 
00370         switch(Msg->State)
00371         {
00372             case ColourChangingMsg::LISTPAGED:
00373                 SwitchTheDisplayList(Msg->ScopeDoc);
00374                 if (GetCurrentDisplayList() != NULL &&  // cache exists, but not been filled in
00375                     GetCurrentDisplayList()->GetCount() < 1)
00376                     ReadNewColourList();
00377                 break;
00378 
00379             case ColourChangingMsg::COLOURUPDATED:
00380             case ColourChangingMsg::COLOURUPDATEDINVISIBLE:
00381                 // If we weren't responsible for the colour being updated, then we must
00382                 // re-read the colour list to ensure we've got it right.
00383                 // **** This could be optimised by just re-sorting the displaylist...
00384 //              if (!LockColourChange && GetCurrentDisplayList() != NULL)
00385 //                  ReadNewColourList();
00386                 ForceRedrawOfList();        // Cause list to be resorted & redisplayed
00387                 break;
00388 
00389 #if FALSE
00390 /*
00391     // We NO LONGER process this message: The Colour Manager calls our special
00392     // ColourGallery::ColourListHasChanged() function in order to do this, so that we
00393     // have updated our DisplayList before others (the colour bar) start making
00394     // requests on it in response to the LISTUPDAETD message.
00395             case ColourChangingMsg::LISTUPDATED:
00396                 UnshadeGallery();
00397                 if (GetCurrentDisplayList() != NULL)
00398                     ReadNewColourList();    // Re-create the display list from the new list
00399                 break;
00400 */
00401 #endif
00402 
00403             case ColourChangingMsg::LISTDESELECTED:
00404                 // Gallery should grey out - there is no current colour list
00405                 ShadeGallery();
00406                 break;
00407         }
00408         // Drop through so the Gallery base class gets to see this message too
00409     }
00410     else if (MESSAGE_IS_A(Message, SelChangingMsg))
00411     {
00412         SelChangingMsg *Msg = (SelChangingMsg *) Message;
00413         switch ( Msg->State )
00414         {
00415             case SelChangingMsg::SelectionState::COLOURATTCHANGED:
00416             case SelChangingMsg::SelectionState::SELECTIONCHANGED:
00417             case SelChangingMsg::SelectionState::NODECHANGED:
00418                 if (IsVisible() && !IsShaded)   // If we're open & active, set listbox selection
00419                     SetSelectionFromDocument();
00420                 break;
00421         }
00422         // Drop through so the Gallery base class gets to see this message too
00423     }
00424     else if (MESSAGE_IS_A(Message, DocChangingMsg))
00425     {
00426         DocChangingMsg *Msg = (DocChangingMsg *) Message;
00427 
00428         switch (Msg->State)
00429         {
00430             case DocChangingMsg::BORN:
00431                 if (Msg->pChangingDoc != NULL)
00432                     CreateCachedDisplayList(Msg->pChangingDoc);
00433                 break;
00434         }
00435         // Drop through so the Gallery base class gets to see this message too
00436     }
00437     
00438 
00439     return(Gallery::Message(Message));
00440 }    
00441 
00442 
00443 
00444 /***********************************************************************************************
00445 
00446 >   BOOL ColourGallery::DoRedrawAnItem(ListItem *Item, BOOL Large, UINT32 DisplayMode);
00447 
00448     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00449     Created:    12/7/94
00450     Inputs:     Item - The item to be redrawn
00451                 Large - TRUE for large mode, FALSE for small mode redraw
00452                 DisplayMode - derived gallery defined display mode index which
00453                 determines how the item is redrawn (icon only, name only, full info)
00454 
00455     Returns:    TRUE if it redraws successfully
00456     Purpose:    Redraws a display list item. MUST be overridden by derived class
00457                 (it would be pure virtual but for DYNCREATE)
00458 
00459 ***********************************************************************************************/
00460 
00461 BOOL ColourGallery::DoRedrawAnItem(ListItem *Item, BOOL Large, UINT32 DisplayMode)
00462 {
00463     PaintText(0, 0, ((IndexedColour *)Item)->GetName());
00464     return(TRUE);
00465 }
00466 
00467 
00468 
00469 /***********************************************************************************************
00470 
00471 >   BOOL ColourGallery::PrepareToDelete(void)
00472 
00473     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00474     Created:    18/7/94
00475     Purpose:    Scans the current Gallery selection. Possibly asks the user for
00476                 confirmation about the delete. Possibly adjusts the selection as
00477                 appropriate. Then returns a value to indicate whether the remaining
00478                 selection should be deleted.
00479     SeeAlso:    ColourGallery::DoDeleteSelection
00480 
00481 ***********************************************************************************************/
00482  
00483 BOOL ColourGallery::PrepareToDelete(void)
00484 {
00485     SequenceItem *Ptr = FindFirstSelected();
00486     DWORD ItemsInUse = 0;
00487     DWORD TotalItems = 0;
00488 
00489     // Determine how many items are selected, and how many of these are in use
00490     while (Ptr != NULL)
00491     {
00492         if ( ((IndexedColour *)FindRealItem(Ptr))->IsInUse() )
00493             ItemsInUse++;
00494         TotalItems++;
00495         Ptr = FindNextSelected(Ptr);
00496     }
00497 
00498     // If some are in use, determine if the user really wants to delete them
00499     INT32 ButtonPressed = 2;
00500     if (ItemsInUse != 0)
00501     {
00502         ButtonPressed = AskQuestion(_R(IDS_COLGAL_COLINUSE),
00503                                     _R(IDS_COLGAL_KILL), _R(IDS_COLGAL_NOKILL), _R(IDS_CANCEL), 0,
00504                                     2, 3);  // NOKILL=default, CANCEL=cancel
00505 
00506         if (ButtonPressed == 3)     // Delete was cancelled - return FALSE
00507             return(FALSE);
00508     }
00509 
00510     if (ButtonPressed == 1)     // Force-delete all items, so go ahead and delete
00511         return(TRUE);
00512 
00513     if (ButtonPressed == 2 && TotalItems - ItemsInUse <= 0)
00514         return(FALSE);          // No items left to delete (all in use) so abort
00515 
00516     // Remove all in-use items from the selection so we only delete 'free' colours
00517     Ptr = FindFirstSelected();
00518     while (Ptr != NULL)
00519     {
00520         if ( ((IndexedColour *) FindRealItem(Ptr))->IsInUse() )
00521             SetDisplayItemSelState(Ptr, FALSE); // Item won't be deleted- deselect it
00522         //else
00523         //  the item will be deleted - leave it selected
00524 
00525         Ptr = FindNextSelected(Ptr);
00526     }
00527 
00528     return(TRUE);
00529 }
00530 
00531 
00532 
00533 /***********************************************************************************************
00534 
00535 >   BOOL ColourGallery::DoDeleteSelection(void)
00536 
00537     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00538     Created:    18/7/94
00539     Returns:    FALSE if it couldn't delete the selection. (This should, if at all possible
00540                 leave the entire selection undeleted in this case)
00541 
00542     Purpose:    FORCIBLY deletes the current gallery selection. By the time this function
00543                 is called, PrepareToDelete has made sure that it is safe to continue.
00544                 This must simply invoke a forced delete upon the selection.
00545                 Deletion of colours occurs by hiding (with undo)
00546 
00547     SeeAlso:    ColourGallery::PrepareToDelete; ColourManager::HideColours
00548 
00549 ***********************************************************************************************/
00550  
00551 BOOL ColourGallery::DoDeleteSelection(void)
00552 {
00553     DWORD TotalItems = GetSelectedItemCount();
00554 
00555     IndexedColour **KillList = new IndexedColourPtr[TotalItems+1];
00556     if (KillList == NULL)
00557         return(FALSE);
00558     
00559     DWORD KillIndex = 0;
00560     SequenceItem *Ptr = FindFirstSelected();
00561     while (Ptr != NULL)
00562     {
00563         KillList[KillIndex++] = (IndexedColour *) FindRealItem(Ptr);
00564 
00565         Ptr = FindNextSelected(Ptr);
00566     }
00567     
00568     KillList[KillIndex] = NULL;     // NULL terminate the list
00569 
00570     // Delete (hide, with undo actually) the given colours
00571     ColourManager::HideColours(ColourManager::GetColourList(), KillList, TRUE);
00572 
00573     // HideColours has made a copy of this list for itself, so we are responsible
00574     // for deleting our original list
00575     delete [] KillList;
00576 
00577     return(TRUE);
00578 }
00579 
00580 
00581 
00582 /***********************************************************************************************
00583 
00584 >   ListItem *ColourGallery::DoCreateNewItem(ListItem *BasedOn)
00585 
00586     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00587     Created:    20/7/94
00588     Inputs:     BasedOn - This is the item in the gallery display on which the
00589                 new item should be based. If there is no Gallery selection, this parameter
00590                 will be NULL, in which case you should read the sttributes of the current
00591                 selection of object(s) in the document to determine what to base your
00592                 new item on. If this fails, then you should create a new item with some
00593                 kind of default settings.
00594 
00595     Returns:    NULL, or the newly created real item
00596     Purpose:    This function is meant to be overridden in derived classes
00597                 It creates a new item and adds it to the Gallery DisplayList
00598                 The item may be created by cloning/deriving/basing-on the
00599                 selected item, depending on the type of Gallery concerned.
00600 
00601     Notes:      Generally, a gallery should do the following:
00602                 If BasedOn != NULL, then the gallery is supplying you with an item which
00603                 should be copied to make the item.
00604                 If BasedOn == NULL, then you should try to find something useful to copy-
00605                 usually, this means something from the attributes of the selection or
00606                 whatever.
00607                 If all of this fails, then you should create an item from some default
00608                 template (e.g. the ColourGallery creates a mid-grey HSV colour)
00609 
00610                 The ColourGallery also has another set of options: The source colour can
00611                 either be copied, or (if it is an IndexedColour) used to create a tint
00612                 or linked colour. This is determined by asking the user if necessary.
00613 
00614 ***********************************************************************************************/
00615 
00616 ListItem *ColourGallery::DoCreateNewItem(ListItem *BasedOn)
00617 {
00618     ColourList *ColList = ColourManager::GetColourList();
00619 
00620     if (ColList == NULL)
00621         return(NULL);
00622 
00623     IndexedColour *NewCol;
00624     NewCol = ColourManager::GenerateNewNamedColour(ColList, (IndexedColour *) BasedOn);
00625 
00626     if (NewCol != NULL)
00627     {
00628         // Bring up the colour editor on the new colour
00629         DoSpecialClick(NewCol);
00630 
00631         // And make the new item the selected one in the list
00632         DeselectAllItems();
00633         SetDisplayItemSelState(FindSequenceItem(NewCol), TRUE);
00634         ForceRedrawOfList();
00635     }
00636 
00637     // Return NULL or the new item to let Gallery know what happened
00638     return(NewCol);
00639 }
00640 
00641 
00642 
00643 /***********************************************************************************************
00644 
00645 >   void ColourGallery::DoApplyItem(ListItem *ItemToApply)
00646 
00647     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00648     Created:    20/7/94
00649     Inputs:     ItemToApply - The item to apply
00650     Purpose:    This function is meant to be overridden in derived classes
00651                 It applies the selected item to the document in whatever way
00652                 is appropriate to its particular data item type. 
00653 
00654 ***********************************************************************************************/
00655 
00656 void ColourGallery::DoApplyItem(ListItem *ItemToApply)
00657 {
00658     if (ItemToApply == NULL)        // Check for stupidity just in case
00659         return;
00660 
00661     // Fill colour selected so create a fill colour attribute
00662     NodeAttribute *Attrib = new AttrColourChange;
00663     if (Attrib == NULL)
00664         return;
00665 
00666     DocColour Ref = *((AttrColourChange *)Attrib)->GetStartColour();
00667     Ref.MakeRefToIndexedColour((IndexedColour *) ItemToApply);
00668 
00669     ((AttrColourChange *)Attrib)->SetStartColour(&Ref);
00670 
00671     // AttributeSelected knows what to do with a selected attribute
00672     AttributeManager::AttributeSelected(NULL, Attrib);
00673 }
00674 
00675 
00676 
00677 /***********************************************************************************************
00678 
00679 >   BOOL ColourGallery::DoRedefineItem(ListItem *ItemToRedefine)
00680 
00681     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00682     Created:    20/7/94
00683 
00684     Inputs:     ItemToRedefine - The item which should be redefined
00685 
00686     Returns:    TRUE if the item was changed (or if you're not sure).
00687                 FALSE if the item definitely was not changed (to save us
00688                 re-sorting and drawing the displayed list)
00689 
00690     Purpose:    This function is meant to be overridden in derived classes
00691                 It allows the user to 'redefine' the item in some way; in the case
00692                 of the colour gallery, this redefines the colour from the selected
00693                 object on the page
00694 
00695 ***********************************************************************************************/
00696 
00697 BOOL ColourGallery::DoRedefineItem(ListItem *ItemToRedefine)
00698 {
00699     // Bring up the colour editor on the new colour
00700     if (ItemToRedefine != NULL)
00701         DoSpecialClick(ItemToRedefine);
00702 
00703     return(TRUE);
00704 
00705 #if FALSE
00706     ColourList *ColList = ColourManager::GetColourList();
00707     if (ColList == NULL)
00708         return(FALSE);
00709 
00710     DocColour *SourceColour = NULL;
00711     if (ColourManager::GetCurrentLineAndFillColours(NULL, &SourceColour))
00712         SourceColour = NULL;                // Sourcecolour returned was current attr - don't use
00713 
00714     if (SourceColour == NULL)
00715     {
00716         // Nothing to copy to redefine the colour. Report this to the user
00717         InformError(_R(IDE_COLGAL_NOSOURCE), _R(IDS_OK));
00718         return(FALSE);
00719     }
00720 
00721     // We have a colour to copy...
00722     INT32 Result;
00723     IndexedColour *ParentColour = SourceColour->FindParentIndexedColour();
00724     if (ParentColour == NULL)
00725     {
00726         Result = AskQuestion(_R(IDS_COLGAL_QREDEFINE), _R(IDS_COLGAL_YREDEFINE), _R(IDS_CANCEL));
00727 
00728         if (Result == 1)        // The user said to go ahead...
00729         {
00730             // Source is an immediate colour - generate an IndexedColour from its definition
00731             ColourGeneric Bob;
00732             SourceColour->GetSourceColour(&Bob);
00733             *((IndexedColour *)ItemToRedefine) = IndexedColour(SourceColour->GetColourModel(), &Bob);
00734             return(TRUE);
00735         }
00736 
00737         return(FALSE);          // The user cancelled
00738     }
00739 
00740     if (ParentColour == (IndexedColour *) ItemToRedefine)
00741     {
00742         InformError(_R(IDE_COLGAL_SAMEITEM));
00743         return(FALSE);
00744     }
00745 
00746     Result = 3;         // Default to making a copy of the colour
00747 
00748     {
00749         IndexedColour *NewCol = (IndexedColour *)ItemToRedefine;
00750         
00751         *NewCol = *ParentColour;
00752         if (ParentColour->IsNamed())
00753         {
00754             String_128 NewName;     // Accomodate overflow- SetName clips this to String_64
00755             NewName.MakeMsg(_R(IDS_COPYOFCOLOUR), (TCHAR *) (*ParentColour->GetName()));
00756             ((IndexedColour *)ItemToRedefine)->SetName(NewName);
00757 
00758             // If the parent was named, then remember it as the 'parent' colour, even
00759             // if it was not tint/linked. This will allow the colour editor to default
00760             // to linking to a useful colour if tint/link is turned on at a later date.
00761             NewCol->SetLinkedParent(ParentColour, NewCol->GetType());
00762         }
00763     }
00764 
00765     if (Result != 0)                // Finally, inform the world if this item has changed
00766         ColourManager::ColourHasChanged(GetGalleryDocument(),
00767                                         ColList, (IndexedColour *) ItemToRedefine);
00768 
00769     return(Result != 0);            // if Cancelled, return FALSE (no change), else TRUE
00770 
00771 #endif
00772 
00773 
00774 }
00775 
00776 
00777 
00778 /***********************************************************************************************
00779 
00780 >   void ColourGallery::DoSpecialClick(ListItem *ClickedItem)
00781 
00782     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00783     Created:    7/10/94
00784     Inputs:     ClickedItem - The item which has been special clicked
00785 
00786     Purpose:    This function is meant to be overridden in derived classes
00787                 It handles a special (alt-) click on a list item. This is generally used
00788                 as a short-cut to bring up an editor on the clicked item, but the exact
00789                 interpretation is left to the derived gallery to decide.
00790 
00791                 The ColourGallery pops up the colour editor on the given colour.
00792 
00793     Notes:      This is called internally to EDIT a colour. It is thus vital that you
00794                 do not change this function without also changing the calling code in this
00795                 file (see ColourGallery::DoCreateNewItem())
00796 
00797 ***********************************************************************************************/
00798 
00799 void ColourGallery::DoSpecialClick(ListItem *ClickedItem)
00800 {
00801     ColourList *ColList = ColourManager::GetColourList();
00802     if (ColList == NULL)
00803         return;
00804 
00805 LockColourChange = TRUE;
00806 
00807     ColourPicker ColPicker;
00808     ColPicker.EditColour(ColList, (IndexedColour *) ClickedItem);
00809 
00810 LockColourChange = FALSE;
00811 }
00812 
00813 
00814 
00815 /***********************************************************************************************
00816 
00817 >   virtual StringBase *ColourGallery::GetItemText(ListItem *TheItem)
00818 
00819     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00820     Created:    19/7/94
00821     Returns:    NULL, or a pointer to the item's text
00822 
00823     Purpose:    STAGE 1 - SIMPLE GALLERY IMPLEMENTATION
00824 
00825                 This method is overridden by derived galleries to provide text
00826                 for each displayed item. This will not be used once user-redraw
00827                 has been implemented, but is used for the time being.
00828 
00829 ***********************************************************************************************/
00830 
00831 StringBase *ColourGallery::GetItemText(ListItem *TheItem)
00832 {
00833     if (TheItem != NULL)
00834         return( ((IndexedColour *)TheItem)->GetName() );
00835 
00836     return(NULL);
00837 }
00838 
00839 
00840 
00841 /***********************************************************************************************
00842 
00843 >   virtual void ColourGallery::SortModeHasBeenChanged(BOOL SetDerivedSortsToo)
00844 
00845     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00846     Created:    29/7/94
00847     Inputs:     SetDerivedSortsToo - If FALSE, only the base gallery class' Display List
00848                 sort mode should be changed. If TRUE, then any other things that can
00849                 depend upon this sort mode should also be updated (e.g. ColourGallery
00850                 will update the colour bar sortmode if this is TRUE).
00851 
00852     Purpose:    Called when the GalleryDisplayDlg has chnaged the gallery DisplayList
00853                 SortMode array to a new sort. The gallery will cause a re-sort and
00854                 update of its list display.
00855 
00856     Notes:      The base class functionality MUST be provided in derived classes. Thus,
00857                 you should call the base class method from any derived version.
00858                 If SetDerivedSorts == FALSE, derived methods probably should do nothing.
00859                 Otherwise, you should copy the DisplayList->SortMode array into any other
00860                 SortModes you may have for external entities such as the colour bar, and
00861                 cause them to update themselves for the new sort too.
00862 
00863 ***********************************************************************************************/
00864  
00865 
00866 void ColourGallery::SortModeHasBeenChanged(BOOL SetDerivedSortsToo)
00867 {
00868     ENSURE(GetCurrentDisplayList() != NULL,
00869             "Inconceivably, the DisplayList is NULL");
00870 
00871     // We *MUST* call the base class version of this function
00872     Gallery::SortModeHasBeenChanged(SetDerivedSortsToo);
00873 
00874     // This function should probaby do nothing if SetDerivedSortsToo == FALSE
00875     // It is called to say that the DisplayList->SortMode (array of sort keys
00876     // defining the displayed order of items) has been changed, so if you
00877     // depend on this sort mode for anything (other than the basic DisplayList
00878     // dependency, which the base class handles) you should update it now.
00879 
00880 
00881     if (SetDerivedSortsToo)
00882     {
00883         // Set the sort mode for the colour bar as well as the gallery
00884         // First, copy the SortMode array...
00885 
00886         ColGalDisplayList *CurDisplayList = (ColGalDisplayList *) GetCurrentDisplayList();
00887 
00888         if (CurDisplayList != NULL)
00889         {
00890             SortKey *ColourBarSortMode = CurDisplayList->GetColourBarSortMode();
00891 
00892             for (INT32 i = 0; i < MaxSortKeys; i++)
00893             {
00894                 ColourBarSortMode[i].Info       = CurDisplayList->SortMode[i].Info;
00895                 ColourBarSortMode[i].Reversed   = CurDisplayList->SortMode[i].Reversed;
00896             }
00897         }
00898 
00899         // Now, tell the Colour Bar to re-sort its display sequence and redraw...
00900 //      CColourBar::SetSortMode(ColourBarSortFunction);
00901     }
00902 }
00903 
00904 
00905 
00906 /***********************************************************************************************
00907 
00908 >   BOOL ColourGallery::DoSetDisplayModes(GalleryDisplayDlg *TheDialogue)
00909 
00910     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00911     Created:    29/7/94
00912     Inputs:     TheDialogue - The Gallery Display dialogue to call
00913                 SetDisplayModeName for.
00914 
00915     Returns:    TRUE if the gallery has a choice of display modes, 
00916                 FALSE if not (in which case the combo box list is greyed)
00917 
00918     Purpose:    This derived function is called by the base class when the
00919                 GallerySortDlg is opened. It is a request from the gallery
00920                 for you to fill in the list of available display modes. e.g
00921                 you may provide icon-only, name-only, icon-and-name, full info
00922                 modes for displaying the gallery items.
00923 
00924                 For each mode you support, call SetDisplayModeName to add it to
00925                 the list. Return TRUE when you're done.
00926 
00927                 If you don't support anything other than one display mode, then you
00928                 should just return FALSE (the base class default does this for you)
00929 
00930     SeeAlso:    GalleryDisplayDlg::SetDisplayModeName; ColourGallery::DoDisplayModeChange
00931 
00932 ***********************************************************************************************/
00933 
00934 BOOL ColourGallery::DoSetDisplayModes(GalleryDisplayDlg *TheDialogue)
00935 {
00936     // Example:
00937     // String_64 Text(_R(IDS_DISPLAY_NAMES_ONLY));
00938     // TheDialogue->SetDisplayModeName(Text);
00939 
00940     // ****
00941 
00942     return(FALSE);      // By default, the gallery will have no choice of modes
00943 }
00944 
00945 
00946 
00947 /***********************************************************************************************
00948 
00949 >   void ColourGallery::DoDisplayModeChange(UINT32 NewDisplayMode)
00950 
00951     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00952     Created:    29/7/94
00953     Inputs:     NewDisplayMode - this number is an index [0..MaxDisplayModes] into
00954                 the list of display names you gave in DoSetDisplayModes
00955     Returns:    -
00956 
00957     Purpose:    This function probably won't be needed, but it is called if the
00958                 display mode is changed in the gallery display dialogue. You may
00959                 want to cache new values or something before the next time your
00960                 redraw code is called, in which case this is the place to do it.
00961 
00962     SeeAlso:    GalleryDisplayDlg::SetDisplayModeName; ColourGallery::DoSetDisplayModes
00963 
00964 ***********************************************************************************************/
00965 
00966 void ColourGallery::DoDisplayModeChange(UINT32 NewDisplayMode)
00967 {
00968     // By default, no action is taken for display mode changes
00969 }
00970 
00971 
00972 
00973 /***********************************************************************************************
00974 
00975 >   void ColourGallery::DoShowMenu(void)
00976 
00977     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00978     Created:    29/7/94
00979     Inputs:     -
00980     Returns:    -
00981 
00982     Purpose:    Creates and shows your gallery-specific menu.
00983                 This is in reaction to clicking the gallery menu button - you should
00984                 pop up a menu under the pointer. How to do this is a complete mystery
00985                 to me! I guess the menu items should be connected to actions via the
00986                 standard Op system, so this is the only call the Gallery provides
00987                 for you.
00988 
00989 ***********************************************************************************************/
00990 
00991 void ColourGallery::DoShowMenu(void)
00992 {
00993     // By default, no menu is shown
00994 }
00995 
00996 
00997 
00998 /***********************************************************************************************
00999 
01000 >   virtual BOOL ColourGallery::SetAlsoButton(String_64 *TextToPutIn)
01001 
01002     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01003     Created:    29/7/94
01004     Inputs:     -
01005     Outputs:    TextToPutIn - Fill this in with the text you want on the
01006                 'also' option button
01007     Returns:    TRUE if it wants an 'also' button, FALSE if not
01008 
01009     Purpose:    If your gallery sort mode can also be applied to other entities
01010                 (e.g. the Colour Gallery display mode can also be applied to the
01011                 colour bar) then return TRUE from this function after filling in
01012                 the text parameter with a string (e.g. "Also apply this sort to
01013                 the colour bar"
01014 
01015                 If you want more control than this, you'll need to override the
01016                 GalleryDisplayDlg class and get your hands dirty.
01017 
01018                 By default (if you don't override this method) there is no button
01019 
01020     SeeAlso:    ColourGallery::SortModeHasBeenChanged
01021 
01022 ***********************************************************************************************/
01023 
01024 BOOL ColourGallery::SetAlsoButton(String_64 *TextToPutIn)
01025 {
01026     TextToPutIn->MakeMsg(_R(IDS_COLGAL_ALSOCOLOURBAR));
01027     return(TRUE);
01028 }
01029 
01030 
01031 
01032 
01033 
01034 
01035 // ---------------------------------------------------------------------------------------------
01036 // ColourGallery specific methods
01037 
01038 
01039 /***********************************************************************************************
01040 
01041 >   static ColGalDisplayList *ColourGallery::FindColourDisplayList(void)
01042 
01043     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01044     Created:    2/8/94
01045 
01046     Returns:    The current colour gallery DisplayList pointer, or NULL
01047 
01048     Purpose:    To find the ColGalDisplayList list in which the Colour Gallery
01049                 stores its displayed IndexedColour items. (Used by the colour bar
01050                 to redraw itself with)
01051 
01052 ***********************************************************************************************/
01053  
01054 ColGalDisplayList *ColourGallery::FindColourDisplayList(void)
01055 {
01056     if (TheColourGallery == NULL)
01057         return(NULL);
01058 
01059     // This may be called by things like the colour bar on LISTUPDATED colour change messages
01060     // Unfortunately, they may be called before we are, so we have to assume that the
01061     // current display list could be invalid now, and search for the right one for the
01062     // selected doc. This may be slow, but the message system doesn't let us grab the
01063     // message first, so we have to bodge our way around it...
01064     TheColourGallery->SwitchTheDisplayList(NULL);
01065     if (TheColourGallery->GetCurrentDisplayList() != NULL &&    // cache exists, but not been filled in
01066         TheColourGallery->GetCurrentDisplayList()->GetCount() < 1)
01067         TheColourGallery->ReadNewColourList();
01068 
01069     return((ColGalDisplayList *) TheColourGallery->GetCurrentDisplayList());
01070 }
01071 
01072 
01073 
01074 /***********************************************************************************************
01075 
01076 >   static ColourGallery *ColourGallery::FindTheGallery(void)
01077 
01078     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01079     Created:    4/8/94
01080 
01081     Returns:    The current colour gallery (or NULL)
01082 
01083     Purpose:    To find the current Colour Gallery object
01084                 Used by the colour bar to use Gallery display list traversal routines
01085 
01086 ***********************************************************************************************/
01087  
01088 ColourGallery *ColourGallery::FindTheGallery(void)
01089 {
01090     return(TheColourGallery);
01091 }
01092 
01093 
01094 
01095 /***********************************************************************************************
01096 
01097 >   void ColourGallery::CreateCachedDisplayList(Document *ScopeDoc = NULL)
01098 
01099     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01100     Created:    3/8/94
01101     Inputs:     ScopeDoc - The document to cache a displaylist for.
01102     Purpose:    Creates (if necessary) a new DisplayList cache for the given Doc.
01103                 If this doc is the SelectedDoc, it also sets the current gallery
01104                 Display List to the (new) cached list for this doc
01105 
01106 ***********************************************************************************************/
01107  
01108 void ColourGallery::CreateCachedDisplayList(Document *ScopeDoc)
01109 {
01110     if (ScopeDoc != NULL)
01111     {
01112         OrderedList *NewDisplayList = FindDisplayListInDoc(ScopeDoc);
01113 
01114         if (NewDisplayList == NULL)     // Not previously cached a DList in this doc
01115         {
01116             NewDisplayList = new ColGalDisplayList;
01117 
01118             if (NewDisplayList != NULL)
01119             {
01120                 ((ColGalDisplayList *) NewDisplayList)->Init(ScopeDoc); // Init list
01121                 AddDisplayListToDoc(ScopeDoc, NewDisplayList);          // Cache it in the doc
01122 
01123                 if (ScopeDoc == Document::GetSelected())
01124                     SelectDisplayList(NewDisplayList);
01125             }
01126         }
01127     }
01128 }
01129 
01130 
01131 
01132 /***********************************************************************************************
01133 
01134 >   void ColourGallery::SwitchTheDisplayList(Document *ScopeDoc = NULL)
01135 
01136     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01137     Created:    2/8/94
01138 
01139     Inputs:     ScopeDoc - The document to switch to. NULL if you want to just use
01140                 the GalleryDocument (As we swap lists on ColourChangingMsgS, there
01141                 may be a brief discrepancy between GalleryDoc and SelectedDoc while
01142                 the message is being processed)
01143 
01144     Returns:    TRUE if the Display List pointer changed as a result of this call
01145 
01146     Purpose:    Switches the DisplayList to the appropriate list for the current 
01147                 GalleryDocument.
01148                 
01149     Notes:      If a cached list is not available in the document, a new list is
01150                 created and the gallery is redrawn.
01151 
01152                 If a cached list is available, the DisplayList is swapped to it,
01153                 and the gallery will be redrawn.
01154 
01155 ***********************************************************************************************/
01156 
01157 BOOL ColourGallery::SwitchTheDisplayList(Document *ScopeDoc)
01158 {
01159     if (ScopeDoc == NULL)
01160         ScopeDoc = GetGalleryDocument();
01161 
01162     OrderedList *OldDisplayList = GetCurrentDisplayList();
01163 
01164     OrderedList *NewDisplayList = NULL;
01165     if (ScopeDoc != NULL)
01166         NewDisplayList = FindDisplayListInDoc(ScopeDoc);
01167 
01168     if (NewDisplayList == NULL && ScopeDoc != NULL)     // No cached DisplayList for this doc
01169     {
01170         NewDisplayList = new ColGalDisplayList;
01171 
01172         if (NewDisplayList != NULL)
01173         {
01174             ((ColGalDisplayList *) NewDisplayList)->Init(ScopeDoc);
01175                                                             // Init lists sort modes etc
01176             SelectDisplayList(NewDisplayList);              // Swap to the new list
01177             AddDisplayListToDoc(ScopeDoc, NewDisplayList);  // Cache list in its doc
01178             ReadNewColourList();                            // Fill in the display colours
01179         }
01180     }
01181     else
01182     {
01183         if (OldDisplayList != NewDisplayList)   // If list changed, redraw the gallery
01184         {
01185             UnshadeGallery();
01186             SelectDisplayList(NewDisplayList);
01187             ForceRedrawOfList();
01188         }
01189     }           
01190 
01191     return(OldDisplayList != NewDisplayList);
01192 }
01193 
01194 
01195 
01196 /***********************************************************************************************
01197 
01198 >   void ColourGallery::ReadNewColourList(void)
01199 
01200     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01201     Created:    18/7/94
01202     Purpose:    Reads the (new) ColourList for the (new) Document, causing the 
01203                 gallery to display it. Called when the ColourList either changes
01204                 or is paged. (Inefficient in that it recalculates the entire
01205                 display list - this will be improved upon later, with a cached
01206                 DisplayList in each document)
01207 
01208 ***********************************************************************************************/
01209  
01210 void ColourGallery::ReadNewColourList(void)
01211 {
01212     ColourList *Colours = ColourManager::GetColourList();
01213 
01214     RemoveAllItemsFromDisplay();
01215 
01216     if (Colours == NULL)
01217     {
01218         ForceRedrawOfList();
01219         return;
01220     }
01221 
01222     IndexedColour *Ptr = (IndexedColour *) Colours->GetHead();
01223     while (Ptr != NULL)
01224     {
01225         if (!Ptr->IsDeleted())
01226             AddItemToDisplay(Ptr);
01227 
01228         Ptr = (IndexedColour *) Colours->GetNext(Ptr);
01229     }
01230 
01231     SetSelectionFromDocument();
01232     ForceRedrawOfList();
01233 }
01234 
01235 
01236 
01237 /********************************************************************************************
01238 
01239 >   static INT32 ColourGallery::ColourBarSortFunction(OrderedList *Parent,
01240                                                 ListItem *Item1, ListItem *Item2)
01241 
01242     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
01243     Created:    5/8/94 (Based on Gallery::SortFunction of 12/7/94)
01244     Inputs:     Parent - the OrderedList which the items are in
01245                 Item1, Item2 - The two items to be compared
01246     Outputs:    -
01247     Returns:    A Negative/Zero/Positive result to indicate the result of comparing
01248                 the two items.
01249     Purpose:    Special multi-key list comparator function.
01250                 This provides the sort mode which has been set by the ColourGallery
01251                 class for the ColourBar, using the ColourBarSortKeys held by the
01252                 ColourGallery
01253     Scope:      private
01254     SeeAlso:    OrderedList; keyword ListComparator; Gallery::SortFunction
01255 
01256 ********************************************************************************************/
01257 
01258 INT32 ColourGallery::ColourBarSortFunction(OrderedList *Parent,
01259                                             ListItem *Item1, ListItem *Item2)
01260 {
01261     ListComparator SortFn;
01262     INT32 result = 0;
01263     INT32 i = 0;
01264 
01265     ENSURE(Parent != NULL && Item1 != NULL && Item2 != NULL, 
01266             "NULL parameter(s) passed to Gallery SortFunction!");
01267 
01268     SortKey *ColourBarSortMode = ((ColGalDisplayList *)Parent)->GetColourBarSortMode();
01269 
01270     while (i < MaxSortKeys && result == 0)
01271     {
01272         if (ColourBarSortMode[i].Info != NULL)
01273         {
01274             SortFn = ColourBarSortMode[i].Info->GetSortFn();
01275 
01276             if (ColourBarSortMode[i].Reversed)
01277                 result = SortFn(Parent, Item2, Item1);
01278             else
01279                 result = SortFn(Parent, Item1, Item2);
01280         }
01281 
01282         i++;
01283     }
01284     return(result);
01285 }
01286 
01287 
01288 
01289 
01290 
01291 //-----------------------------------------------------------------------------------------------
01292 
01293 // OpDisplayColourGallery - the operation that is used to display the colours gallery
01294 
01295 /********************************************************************************************
01296 
01297 >   BOOL OpDisplayColourGallery::Init()
01298 
01299     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01300     Created:    12/8/94
01301     Inputs:     -
01302     Outputs:    -
01303     Returns:    TRUE if the operation could be successfully initialised 
01304                 FALSE if no more memory could be allocated 
01305                 
01306     Purpose:    OpDisplayColourGallery initialiser method
01307     Errors:     ERROR will be called if there was insufficient memory to allocate the 
01308                 operation.
01309     SeeAlso:    -
01310 
01311 ********************************************************************************************/
01312 
01313 BOOL OpDisplayColourGallery::Init()
01314 {
01315     return (RegisterOpDescriptor(
01316                                 0,
01317                                 _R(IDS_DISPLAY_COLOUR_GALLERY),
01318                                 CC_RUNTIME_CLASS(OpDisplayColourGallery),
01319                                 OPTOKEN_DISPLAYCOLOURGALLERY,
01320                                 OpDisplayColourGallery::GetState,
01321                                 0,                                  // Help ID
01322                                 _R(IDBBL_DISPLAY_COLOUR_GALLERY),   // bubble help
01323                                 0,                                  // bitmap ID        
01324                                 0,                                  // control ID
01325                                 SYSTEMBAR_ILLEGAL,                  // Bar ID
01326                                 TRUE,                               // Recieve system messages
01327                                 FALSE,                              // Smart duplicate operation
01328                                 TRUE,                               // Clean operation
01329                                 NULL,                               // No vertical counterpart
01330                                 0,                                  // String for one copy only error
01331                                 0,                                  // Auto state flags
01332                                 TRUE                                // Tickable
01333                                 ));
01334 }               
01335     
01336 /********************************************************************************************
01337 
01338 >   OpState OpDisplayColourGallery::GetState(String_256*, OpDescriptor*)
01339 
01340     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01341     Created:    12/8/94
01342     Inputs:     -
01343     Outputs:    -
01344     Returns:    The state of the OpDisplayColourGallery operation
01345     Purpose:    For finding the OpDisplayColourGallery's state. 
01346     Errors:     -
01347     SeeAlso:    -
01348 
01349 ********************************************************************************************/
01350 
01351 OpState OpDisplayColourGallery::GetState(String_256* UIDescription, OpDescriptor*)
01352 {
01353     OpState OpSt;  
01354 
01355     // If the gallery is currenty open, then the menu item should be ticked
01356     String_32 Name(_R(IDS_K_COLGAL_GALLNAME));
01357     DialogBarOp* pDialogBarOp = DialogBarOp::FindDialogBarOp(Name);
01358 
01359     if (pDialogBarOp != NULL)
01360     {
01361         if (pDialogBarOp->GetRuntimeClass() == CC_RUNTIME_CLASS(ColourSGallery))
01362             OpSt.Ticked = pDialogBarOp->IsVisible();
01363     }
01364 
01365     // If there are no open documents, you can't toggle the gallery
01366     OpSt.Greyed = (Document::GetSelected() == NULL);
01367 
01368     return(OpSt);   
01369 }
01370 
01371 
01372 
01373 /********************************************************************************************
01374 
01375 >   void OpDisplayColourGallery::Do(OpDescriptor*)
01376 
01377     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01378     Created:    12/8/94
01379     Inputs:     -
01380     Outputs:    -
01381     Returns:    -
01382     Purpose:    Displays the colours gallery
01383     Errors:     -
01384     SeeAlso:    -
01385 
01386 ********************************************************************************************/
01387 
01388 void OpDisplayColourGallery::Do(OpDescriptor*)
01389 {
01390     String_32 Name(_R(IDS_K_COLGAL_GALLNAME));
01391     DialogBarOp* pDialogBarOp = DialogBarOp::FindDialogBarOp(Name);
01392 
01393     if (pDialogBarOp != NULL)
01394     {
01395         if (pDialogBarOp->GetRuntimeClass() == CC_RUNTIME_CLASS(ColourSGallery))
01396         {
01397             // Toggle the visibility of the gallery window
01398             pDialogBarOp->SetVisibility( !pDialogBarOp->IsVisible() );
01399         }
01400 #if _DEBUG
01401         else
01402             ERROR3("The Colour Gallery isn't a ColourSGallery! Woss goin' on?");
01403 #endif
01404 
01405         SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYCOLOURGALLERY, pDialogBarOp->IsVisible());
01406     }
01407 
01408     ERROR3IF(pDialogBarOp == NULL,"Couldn't find the colour gallery bar");
01409 
01410     End();
01411 }
01412 
01413 #endif
01414 

Generated on Sat Nov 10 03:44:51 2007 for Camelot by  doxygen 1.4.4