coldrop.cpp

Go to the documentation of this file.
00001 // $Id: coldrop.cpp 1777 2007-07-04 10:37:58Z luke $
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 // coldrop.cpp - Colour drop-down list support
00100 
00101 /*
00102 */
00103 
00104 
00105 //-----------------------------------------------------------------------------------------
00106 // Include files
00107 
00108 #include "camtypes.h"
00109 
00110 #include "coldrop.h"
00111 #include "colormgr.h"
00112 #include "devcolor.h"
00113 #include "dlgmgr.h"
00114 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 #include "progress.h"
00117 
00118 
00119 //-----------------------------------------------------------------------------------------
00120 // Implementation of dynamic classes
00121 
00122 class SpecialEntry : public ListItem
00123 {
00124     CC_DECLARE_DYNCREATE(SpecialEntry);
00125 
00126 public:
00127     BOOL Init(StringBase *Text, DocColour *Colour);
00128 
00129 public:
00130     String_256  ItemText;
00131     BOOL        ItemHasColour;
00132     DocColour   ItemColour;
00133 };
00134 
00135 CC_IMPLEMENT_DYNCREATE(SpecialEntry, ListItem);
00136 CC_IMPLEMENT_DYNCREATE(ColourDropDown, ListItem);
00137 CC_IMPLEMENT_DYNAMIC(ColourDropMsgHandler, MessageHandler);
00138 
00139 
00140 
00141 //-----------------------------------------------------------------------------------------
00142 // This must be defined AFTER all CC_IMPLEMENT_DYNCREATE calls
00143 #define new CAM_DEBUG_NEW
00144 
00145 
00146 
00147 BOOL SpecialEntry::Init(StringBase *Text, DocColour *Colour)
00148 {
00149     ItemText = *Text;
00150     if (Colour == NULL)
00151         ItemHasColour = FALSE;
00152     else
00153     {
00154         ItemHasColour = TRUE;
00155         ItemColour = *Colour;
00156     }
00157 
00158     return(TRUE);
00159 }
00160 
00161 
00162 // --- Statics
00163 ColourDropMsgHandler *ColourDropDown::MessageHandler = NULL;        // One msg handler for all coldropdowns
00164 INT32 ColourDropDown::MsgHandlerCount = 0;
00165 
00166 
00167 
00168 
00169 /********************************************************************************************
00170 
00171 >   ColourDropDown(BOOL AutoUpdateOnColourListChange = TRUE)
00172 
00173     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00174     Date:       6/10/95
00175 
00176     Inouts:     AutoUpdateOnColourListChange - Cor! What a whopper! ;-)
00177                 er... where was I? Oh, yeah.
00178 
00179                 TRUE (default) if you want the colour list to automatically update
00180                 when the current colour list (selected document) changes. This includes
00181                 addition/removal/change of colours, as well as changing document, and
00182                 auto-shadin/unshading of the list gadget when there are no documents
00183                 or colours present.
00184 
00185                 FALSE if you want to poke the list yourself. (This should only really
00186                 be used by the Colour Editor, which already had lots of careful handling
00187                 code built in- everyone else should just use the default setting)
00188 
00189     Purpose:    ColourDropDown constructor
00190 
00191 ********************************************************************************************/
00192 
00193 ColourDropDown::ColourDropDown(BOOL AutoUpdateOnColourListChange)
00194 {
00195     AutoUpdateOnChange = AutoUpdateOnColourListChange;
00196 }
00197 
00198 
00199 
00200 /********************************************************************************************
00201 
00202 >   virtual ColourDropDown::~ColourDropDown()
00203 
00204     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00205     Date:       29/8/95
00206 
00207     Purpose:    ColourDropDown destructor
00208 
00209 ********************************************************************************************/
00210 
00211 ColourDropDown::~ColourDropDown()
00212 {
00213     ClearAllSpecialEntries();
00214 
00215     if (MessageHandler != NULL)
00216     {
00217         MsgHandlerCount--;
00218         if (MsgHandlerCount <= 0)
00219         {
00220             delete MessageHandler;      // Get rid of msghandler when not needed
00221             MessageHandler = NULL;
00222         }
00223     }
00224 }
00225 
00226 
00227 
00228 /********************************************************************************************
00229 
00230 >   virtual BOOL ColourDropDown::Init(CWindowID Window, CGadgetID Gadget)
00231 
00232     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00233     Date:       29/8/95
00234 
00235     Inputs:     Window - The Window in which your dropdown list gadget resides
00236                 Gadget - The GadgetID of the deropdown list gadget
00237 
00238     Returns:    TRUE if it succeeded in connecting itself to your gadget
00239                 FALSE if it failed
00240 
00241     Purpose:    DropDown initialiser
00242 
00243 ********************************************************************************************/
00244 
00245 BOOL ColourDropDown::Init(CWindowID Window, CGadgetID Gadget)
00246 {
00247     BOOL AlreadyInitialised = Initialised;  // Remember if this is the first time we've been init'd
00248 
00249     if (DropDown::Init(Window, Gadget))     // Call the base class
00250     {
00251         if (AlreadyInitialised)             // Only increment handler count on first initialisation
00252             return(TRUE);
00253 
00254         if (MessageHandler == NULL)         // And ensure we have a message handler
00255         {
00256             MessageHandler = new ColourDropMsgHandler;
00257             MsgHandlerCount = 0;
00258         }
00259 
00260         if (MessageHandler != NULL)         // And increment its usage count
00261         {
00262             MsgHandlerCount++;
00263             return(TRUE);
00264         }
00265     }
00266 
00267     return(FALSE);
00268 }
00269 
00270 
00271 
00272 
00273 
00274 
00275 /********************************************************************************************
00276 
00277 >   void ColourDropDown::ClearAllSpecialEntries(void)
00278 
00279     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00280     Date:       29/8/95
00281 
00282     Purpose:    Forgets about any special entries you may have added in the past
00283 
00284     SeeAlso:    ColourDropDown::AddSpecialEntry
00285 
00286 ********************************************************************************************/
00287 
00288 void ColourDropDown::ClearAllSpecialEntries(void)
00289 {
00290     SpecialEntries.DeleteAll();
00291 }
00292 
00293 
00294 
00295 /********************************************************************************************
00296 
00297 >   BOOL ColourDropDown::AddSpecialEntry(StringBase *Text, DocColour *Colour = NULL)
00298 
00299     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00300     Date:       29/8/95
00301 
00302     Inputs:     Text - The text to put in the entry (this will be copied)
00303                 Colour - NULL or a DocColour. If non-NULL, this describes the colour of
00304                 the colour patch placed to the left of the text. If NULL, no colour patch
00305                 will be drawn.
00306 
00307     Returns:    TRUE if it added to the list successfully
00308 
00309     Purpose:    Adds a "special entry" to the top of the colour list
00310 
00311     Notes:      All special items MUST be added before calling FillInColourList
00312 
00313                 The colour list can be augmented with a number of "special" entries.
00314                 Each call to this method adds another entry to the bottom of the special
00315                 entries list. If there are special entries, they are added to to top
00316                 of the colour list, with a divider item between them and the colours.
00317                 There can only be one divider.
00318 
00319                 Special entries are indexed by their order of addition, with the first
00320                 entry being number 0. When decoding a selection, DecodeSelection will
00321                 return an IndexedColour pointer (if a colour was selected), or NULL,
00322                 in which case, use the Index you passed in to determine which Special
00323                 Entry was selected. Note that the divider will be treated as a special
00324                 entry (e.g. with 2 special items, you can get an entry 2 selected - this
00325                 corresponds to the divider, and should be ignored)
00326 
00327     SeeAlso:    ColourDropDown::DecodeSelection; ColourDropDown::FillInColourList
00328 
00329 ********************************************************************************************/
00330 
00331 BOOL ColourDropDown::AddSpecialEntry(StringBase *Text, DocColour *Colour)
00332 {
00333     ERROR2IF(ParentDlg == NULL, FALSE, "ColourDropDown not properly initialised");
00334 
00335     SpecialEntry *NewEntry = new SpecialEntry;
00336     if (NewEntry != NULL && NewEntry->Init(Text, Colour))   
00337     {
00338         SpecialEntries.AddTail(NewEntry);
00339         return(TRUE);
00340     }
00341     return(FALSE);
00342 }
00343 
00344 
00345 
00346 /********************************************************************************************
00347 
00348 >   BOOL ColourDropDown::UpdateSpecialEntry(StringBase *Text, DocColour *NewColour)
00349 
00350     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00351     Date:       20/10/95
00352 
00353     Inputs:     Text - The text in the existing entry
00354                 NewColour - The colour to chnage the display to
00355 
00356     Returns:    TRUE for success, FALSE if the entry was not found
00357 
00358     Purpose:    Modifies a "special entry" to display a different colour.
00359                 Cannot be used if the entry has no colour associated with it.
00360 
00361     Notes:      Also causes a redraw of the dropdown control to update the screen display.
00362 
00363     SeeAlso:    ColourDropDown::DecodeSelection; ColourDropDown::FillInColourList
00364 
00365 ********************************************************************************************/
00366 
00367 BOOL ColourDropDown::UpdateSpecialEntry(StringBase *Text, DocColour *NewColour)
00368 {
00369     ERROR3IF(Text == NULL || NewColour == NULL, "Illegal NULL params");
00370 
00371     SpecialEntry *Ptr = (SpecialEntry *) SpecialEntries.GetHead();
00372     while (Ptr != NULL)
00373     {
00374         if (Ptr->ItemHasColour && Ptr->ItemText == *Text)
00375         {
00376             // Set the new colour
00377             Ptr->ItemColour = *NewColour;
00378             
00379             // And cause the combobox to redraw
00380             DialogManager::InvalidateGadget(ParentDlg, ParentGadget);
00381 
00382             return(TRUE);
00383         }
00384 
00385         Ptr = (SpecialEntry *) SpecialEntries.GetNext(Ptr);
00386     }
00387 
00388     return(FALSE);
00389 }
00390 
00391 
00392 
00393 /********************************************************************************************
00394 
00395 >   BOOL ColourDropDown::FillInColourList(IndexedColour *Selected = NULL,
00396                                             INT32 SelectIndex = -1,
00397                                             IndexedColour *NotDescendantOf = NULL)
00398 
00399     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00400     Date:       29/8/95
00401 
00402     Inputs:     Selected - NULL or a pointer to the selected colour
00403                     (Only one of Selected, SelectedIndex should indicate the selection)
00404 
00405                 SelectIndex - -1 or the 0-based index of the special item to select
00406                     (Only one of Selected, SelectedIndex should indicate the selection.
00407                     SelectIndex will actually override Selected if it is valid)
00408 
00409                 NotDescendantOf - NULL, or a pointer to an IndexedColour. If this is non-null
00410                 then this does not include "NotADescendantOf" or any of its children in the
00411                 list (this allows a list of all available parent colours for a colour to be
00412                 compiled by passing that colour in this field)
00413 
00414     Returns:    TRUE if it filled in the list successfully
00415 
00416     Purpose:    "Fills in" the attached control with appropriate entries for the current
00417                 ColourDropDown settings, and (if neccessary) a separated set of special
00418                 entries at the top thereof.
00419 
00420     Notes:      Only special entries added before this call is made will appear in the
00421                 list, so add them first.
00422 
00423                 Call this after initialising the control, and after any subsequent calls
00424                 to change the contents of the list.
00425 
00426     SeeAlso:    ColourDropDown::DecodeSelection; ColourDropDown::AddSpecialEntry
00427 
00428 ********************************************************************************************/
00429 
00430 BOOL ColourDropDown::FillInColourList(IndexedColour *Selected, INT32 SelectIndex,
00431                                         IndexedColour *NotDescendantOf)
00432 {
00433     ERROR2IF(ParentDlg == NULL, FALSE, "ColourDropDown not properly initialised");
00434 
00435     BOOL Result = FALSE;        // Assume we've failed until we add an item!
00436 
00437     Progress Hourglass;         // Start an hourglass running
00438 
00439     ColourList *ParentList = ColourManager::GetCurrentColourList();
00440 
00441     SetListRedraw(FALSE);                                       // Disable redraw while updating
00442     ClearList();                                                // Delete combobox contents
00443 
00444     INT32 SelectedIndex = 0;
00445 
00446     if (!SpecialEntries.IsEmpty())
00447     {
00448         // Add an entry for each special entry
00449         ListItem *Ptr = SpecialEntries.GetHead();
00450 
00451         while (Ptr != NULL)
00452         {
00453             AddItem((void *) Ptr);
00454             Ptr = SpecialEntries.GetNext(Ptr);
00455         }
00456 
00457         AddItem(NULL);                                          // And add a separator
00458         Result = TRUE;      // There are items in the list, so we can return "OK" now
00459     }
00460 
00461     // If we have a "NotDescendantOf" colour, then we can only add parent colours to the list
00462     // if the "NotDescendantOf" colour is tint/shade/linked - normal/spot colours cannot have parents
00463 
00464     // Of course, we have to rely on the caller to be sensible here, because they might be about
00465     // to change the type of the colour (e.g. New Colour dialogue shows potential parents and
00466     // converts the colour to a shade if a parent is chosen. Thus, we don't want to present a blank
00467     // list of parent colours!)
00468 
00469     if (ParentList != NULL)
00470     {
00471         // Determine (precalculate) if NotADescendant (if any) is a tint colour
00472         BOOL NotATint = TRUE;
00473         if (NotDescendantOf != NULL &&
00474             NotDescendantOf->GetType() == COLOURTYPE_TINT &&
00475             !NotDescendantOf->TintIsShade())
00476         {
00477             NotATint = FALSE;
00478         }
00479 
00480         // Now scan the colour list, adding any legal parent colours to the list
00481         IndexedColour *Ptr = (IndexedColour *) ParentList->GetHead();
00482         INT32 Index = (SpecialEntries.IsEmpty()) ? 0 : (SpecialEntries.GetCount() + 1);
00483         
00484         while (Ptr != NULL)
00485         {
00486             Hourglass.Update();     // Update the houglass
00487 
00488             // Is the colour a named, live colour and not descended from NotADescendant? (Note: we
00489             // can safely pass NULL into IsADescendantOf())
00490             if (!Ptr->IsDeleted() && Ptr->IsNamed() && !Ptr->IsADescendantOf(NotDescendantOf))
00491             {
00492                 AddItem((void *) Ptr);
00493                 Result = TRUE;          // We've succeeded in adding at least 1 item
00494                 if (Ptr == Selected)
00495                     SelectedIndex = Index;
00496 
00497                 Index++;
00498             }
00499 
00500             Ptr = (IndexedColour *) ParentList->GetNext(Ptr);
00501         }
00502     }
00503 
00504     SetListRedraw(TRUE);                                    // Re-enable redraw
00505 
00506     // Override any selection index we have with the caller-provided selection index, if
00507     // it indicates a valid "special item"
00508     if (SelectIndex >= 0 && SelectIndex < (INT32)SpecialEntries.GetCount())
00509         SelectedIndex = SelectIndex;
00510 
00511     if (Result)
00512         SetSelectedIndex(SelectedIndex);                        // And set the appropriate selected item
00513 
00514     // Finally, enable the gadget, and trim its length down if necessary to fit the
00515     // number of displayed items.
00516 //  DialogManager::SetComboListLength(ParentDlg, ParentGadget);  -- causes nasty redraw of document behind!
00517     DialogManager::EnableGadget(ParentDlg, ParentGadget, TRUE);
00518 
00519     return(Result);
00520 }
00521 
00522 
00523 
00524 /********************************************************************************************
00525 
00526 >   BOOL ColourDropDown::SetSelection(IndexedColour *Selected, INT32 SelectIndex = -1)
00527 
00528     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00529     Date:       1/9/95
00530 
00531     Inputs:     Selected - NULL or a pointer to the selected colour
00532                     (Only one of Selected, SelectedIndex should indicate the selection)
00533 
00534                 SelectIndex - -1 or the 0-based index of the special item to select
00535                     (Only one of Selected, SelectedIndex should indicate the selection.
00536                     SelectIndex will actually override Selected if it is valid)
00537 
00538     Returns:    TRUE if it set the selection OK
00539 
00540     Purpose:    To set the selected item in the list
00541 
00542     SeeAlso:    ColourDropDown::DecodeSelection; ColourDropDown::FillInColourList
00543 
00544 ********************************************************************************************/
00545 
00546 BOOL ColourDropDown::SetSelection(IndexedColour *Selected, INT32 SelectIndex)
00547 {
00548     ERROR2IF(ParentDlg == NULL, FALSE, "ColourDropDown not properly initialised");
00549 
00550     INT32 SelectedIndex = 0;
00551 
00552     if (SelectIndex >= 0 && SelectIndex < (INT32)SpecialEntries.GetCount())     // Use special item
00553         SelectedIndex = SelectIndex;
00554     else if (Selected != NULL)                                                  // Use colour ptr
00555     {
00556         INT32 Index = (SpecialEntries.IsEmpty()) ? 0 : (SpecialEntries.GetCount() + 1);
00557         INT32 MaxIndex = GetNumberOfItems();
00558 
00559         while (Index < MaxIndex)
00560         {
00561             if (Selected == (IndexedColour *) GetItemData(Index))
00562             {
00563                 SelectedIndex = Index;
00564                 break;
00565             }
00566 
00567             Index++;
00568         }
00569     }
00570 
00571     SetSelectedIndex(SelectedIndex);                        // And set the appropriate selected item
00572     return(TRUE);
00573 }
00574 
00575 
00576 
00577 /********************************************************************************************
00578 
00579 >   IndexedColour *ColourDropDown::DecodeSelection(INT32 SelectionIndex)
00580 
00581     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00582     Date:       29/8/95
00583 
00584     Inputs:     SelectionIndex - The index of the item (which is usually the selected one)
00585                 in the combo box.
00586 
00587     Returns:    NULL if the SelectionIndex should be treated as a "special item", else
00588                 a pointer to the selected IndexedColour.
00589                 (Note: If the list is empty, it will also return NULL)
00590 
00591     Purpose:    Decodes an index in the dropdown list back into either a special-item index
00592                 or an IndexedColour pointer. (See AddSpecialEntry for details)
00593 
00594     Notes:      The colour list can be augmented with a number of "special" entries.
00595                 Each call to this method adds another entry to the bottom of the special
00596                 entries list. If there are special entries, they are added to to top
00597                 of the colour list, with a divider item between them and the colours.
00598                 There can only be one divider.
00599 
00600                 Special entries are indexed by their order of addition, with the first
00601                 entry being number 0. When decoding a selection, DecodeSelection will
00602                 return an IndexedColour pointer (if a colour was selected), or NULL,
00603                 in which case, use the Index you passed in to determine which Special
00604                 Entry was selected. Note that the divider will be treated as a special
00605                 entry (e.g. with 2 special items, you can get an entry 2 selected - this
00606                 corresponds to the divider, and should be ignored)
00607 
00608     SeeAlso:    ColourDropDown::FillInColourList; ColourDropDown::AddSpecialEntry
00609 
00610 ********************************************************************************************/
00611 
00612 IndexedColour *ColourDropDown::DecodeSelection(INT32 SelectionIndex)
00613 {
00614     // If it's at the top of the list, it could be a "special" (extra) entry
00615     if (!SpecialEntries.IsEmpty() && SelectionIndex <= (INT32)SpecialEntries.GetCount())
00616         return(NULL);
00617 
00618     void * Data = GetItemData(SelectionIndex);
00619 //  if (Data == -1)             // If the list is empty, we will get a -1 back, so weed it out
00620 //      return(NULL);
00621 
00622     // Otherwise, it must be a colour, so fetch the colour pointer...
00623     return( (IndexedColour *) Data);
00624 }
00625 
00626 
00627 
00628 /********************************************************************************************
00629 
00630 >   static void ColourDropDown::UpdateForNewColourList(void)
00631 
00632     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00633     Date:       6/10/95
00634 
00635     Purpose:    Called by the ColourDropMsgHandler whenever a colour list changes or
00636                 we swap to a different document, etc. Will automatically clear the
00637                 list and shade it if there are no documents around.
00638 
00639                 Basically just calls FillInColourList for all active ColourDropDowns
00640 
00641     Scope:      sorta private
00642 
00643 ********************************************************************************************/
00644 
00645 void ColourDropDown::UpdateForNewColourList(void)
00646 {
00647     Document *SelDoc = Document::GetSelected();
00648 
00649     if (SelDoc != NULL)     // No need to shade, so return now
00650         return;
00651 
00652     DropDown *Ptr = (DropDown *) CurrentDropDowns.GetHead();
00653     while (Ptr != NULL)
00654     {
00655         if (Ptr->IsKindOf(CC_RUNTIME_CLASS(ColourDropDown)))
00656         {
00657             ColourDropDown *CPtr = (ColourDropDown *)Ptr;
00658             if (CPtr->AutoUpdateOnChange)
00659             {
00660                 CPtr->ClearList();
00661                 DialogManager::EnableGadget(CPtr->ParentDlg, CPtr->ParentGadget, FALSE);    // Shade
00662             }
00663         }
00664 
00665         Ptr = (DropDown *) CurrentDropDowns.GetNext(Ptr);
00666     }
00667 }
00668 
00669 
00670 
00671 /********************************************************************************************
00672 
00673 >   static void ColourDropDown::RedrawColourDropDowns(void)
00674 
00675     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00676     Date:       23/5/96
00677 
00678     Purpose:    Called by the ColourDropMsgHandler whenever the selected view's colour
00679                 context is changed, so we redraw using the new correction/separation
00680                 options.
00681 
00682     Scope:      sorta private
00683 
00684 ********************************************************************************************/
00685 
00686 void ColourDropDown::RedrawColourDropDowns(void)
00687 {
00688     DropDown *Ptr = (DropDown *) CurrentDropDowns.GetHead();
00689     while (Ptr != NULL)
00690     {
00691         if (Ptr->IsKindOf(CC_RUNTIME_CLASS(ColourDropDown)))
00692         {
00693             ColourDropDown *CPtr = (ColourDropDown *)Ptr;
00694             DialogManager::InvalidateGadget(CPtr->ParentDlg, CPtr->ParentGadget);
00695         }
00696 
00697         Ptr = (DropDown *) CurrentDropDowns.GetNext(Ptr);
00698     }
00699 }
00700 
00701 
00702 
00703 /********************************************************************************************
00704 
00705 >   virtual BOOL ColourDropDown::HasIcon(void * ItemData)
00706 
00707     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00708     Date:       13/9/95
00709 
00710     Inputs:     ItemData - Your item data
00711 
00712     Returns:    TRUE if this item needs an icon to the left of it, FALSE if not
00713 
00714     Purpose:    Determine if an item needs an icon next to it
00715 
00716     Notes:      Called by HandleDrawItemInternal when this object has been identified as the 
00717                 owner of the control to be redrawn.
00718 
00719                 This method MUST be overridden by derived classes to provide redraw of their
00720                 ColourDropDown list items. The base class returns FALSE
00721 
00722                 If you return TRUE, you must also provide the DrawIcon method
00723 
00724     SeeAlso:    ColourDropDown::DrawIcon; ColourDropDown::DrawText
00725 
00726 ********************************************************************************************/
00727 
00728 BOOL ColourDropDown::HasIcon(void * ItemData)
00729 {
00730     // All our items have a colour splodge
00731     return(TRUE);
00732 }
00733 
00734 
00735 
00736 /********************************************************************************************
00737 
00738 >   virtual BOOL ColourDropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect,
00739                                             BOOL Disabled)
00740 
00741     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00742     Date:       13/9/95
00743 
00744     Inputs:     ItemData - Your item data
00745                 dc - The DC to render into
00746                 IconRect - points at a rectangle (square in fact) to be drawn within
00747                 Disabled - TRUE if this item is disabled so the icon should be drawn greyed
00748 
00749     Returns:    TRUE if this item needs an icon to the left of it, FALSE if not
00750 
00751     Purpose:    Draws the icon for an item
00752 
00753 
00754 ********************************************************************************************/
00755 
00756 BOOL ColourDropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect, BOOL Disabled, INT32 flags)
00757 {
00758     GDrawBrush.Init(&dc);
00759     GDrawBrush.Start();
00760 
00761     wxBrush OldBrush=dc.GetBrush();
00762     wxPen OldPen=dc.GetPen();
00763 
00764     COLORREF rgb;
00765 
00766     BOOL IsSpotColour = FALSE;
00767 
00768     if (Disabled)
00769     {
00770         // The item is disabled, so just put a light grey splodge in the place of the colour
00771         rgb = RGB(192, 192, 192);
00772         dc.SetPen(*wxTRANSPARENT_PEN);
00773     }
00774     else
00775     {
00776         ColourContextRGBT *CCrgbt = (ColourContextRGBT *)
00777                 ColourManager::GetColourContext(COLOURMODEL_RGBT, DocView::GetSelected());
00778 
00779         ERROR3IF(CCrgbt == NULL, "No available RGB colour context?!");
00780 
00781         CCObject *Item = (CCObject *)ItemData;
00782         if (Item->IsKindOf(CC_RUNTIME_CLASS(IndexedColour)))
00783         {
00784             DocColour Bob;
00785             Bob.MakeRefToIndexedColour((IndexedColour *)ItemData);
00786             rgb = ConvertColourToScreenWord(CCrgbt, &Bob);
00787 
00788             if ( ((IndexedColour *) ItemData)->IsSpotOrTintOfSpot() )
00789                 IsSpotColour = TRUE;
00790         }
00791         else
00792             rgb = ConvertColourToScreenWord(CCrgbt, &(((SpecialEntry *)ItemData)->ItemColour));
00793 
00794         dc.SetPen(*wxBLACK_PEN);
00795     }
00796 
00797     wxBrush brush;
00798     if (GDrawBrush.Available())
00799         GDrawBrush.GetLogBrush(rgb, &brush);
00800     else
00801         brush=wxBrush(rgb);
00802 
00803     dc.SetBrush(brush);
00804 
00805     if (IsSpotColour)
00806         dc.DrawEllipse(IconRect.GetLeft(), IconRect.GetTop(), IconRect.GetWidth(), IconRect.GetHeight());
00807     else
00808         dc.DrawRectangle(IconRect.GetLeft(), IconRect.GetTop(), IconRect.GetWidth(), IconRect.GetHeight());
00809 
00810     // Finish with GBrush
00811     GDrawBrush.Stop();
00812 
00813     dc.SetBrush(OldBrush);
00814     dc.SetPen(OldPen);
00815 
00816     return(TRUE);
00817 }
00818 
00819 
00820 
00821 /********************************************************************************************
00822 
00823 >   virtual wxString ColourDropDown::GetText(void * ItemData, INT32 Item)
00824 
00825     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00826     Date:       13/9/95
00827 
00828     Inputs:     ItemData - Your item data
00829                 Item - the number of the item
00830                 
00831     Returns:    The text for the item
00832 
00833     Purpose:    Draws the text for an item
00834 
00835     Notes:      Called by HandleDrawItemInternal when this object has been identified as the 
00836                 owner of the control to be redrawn, if HasIcon returned TRUE
00837 
00838                 This method MUST be overridden by derived classes to provide redraw of their
00839                 ColourDropDown list items. The base class draws nothing.
00840 
00841                 Note that on entry, the text FG/BG colours have been set up appropriately
00842                 for the state of the item (shaded, selected, etc)
00843                 Basically, all you have to do is find the text and do a DrawText call.
00844 
00845     SeeAlso:    ColourDropDown::DrawIcon; ColourDropDown::DrawText
00846 
00847 ********************************************************************************************/
00848 
00849 wxString ColourDropDown::GetText(void * ItemData, INT32 Item)
00850 {
00851     ERROR3IF(ItemData == NULL, "NULL Itemdata in ColourDropDown::DrawText");
00852 
00853     // Determine if it's a colour or a special item, and find the text to draw
00854     TCHAR * TextToDraw = NULL;
00855 
00856     CCObject *pItem = (CCObject *) ItemData;
00857 
00858     if (pItem->IsKindOf(CC_RUNTIME_CLASS(IndexedColour)))
00859         TextToDraw = ( (TCHAR *) (*((IndexedColour *)ItemData)->GetName()) );
00860     else
00861         TextToDraw = ( (TCHAR *) ((SpecialEntry *)ItemData)->ItemText );
00862 
00863     if (TextToDraw)
00864         return wxString(TextToDraw);
00865     else
00866         return wxEmptyString;
00867 }
00868 
00869 
00870 
00871 
00872 
00873 
00874 
00875 
00876 /********************************************************************************************
00877 
00878 >   ColourDropMsgHandler::ColourDropMsgHandler()
00879 
00880     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00881     Created:    6/10/95
00882     Purpose:    Constructs a ColourDropMsgHandler, an object which, surprisingly,
00883                 handles messages for its parent ColourDropDown.
00884     Errors:     -
00885     SeeAlso:    MessageHandler
00886 
00887 ********************************************************************************************/
00888 
00889 ColourDropMsgHandler::ColourDropMsgHandler()
00890   : MessageHandler(CC_RUNTIME_CLASS(MessageHandler), TRUE)
00891 {
00892 }
00893 
00894 
00895 
00896 /********************************************************************************************
00897 
00898 >   virtual MsgResult ColourDropMsgHandler::Message(Msg* Message)
00899 
00900     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00901     Created:    6/10/95
00902     Inputs:     Message: The message
00903 
00904     Purpose:    Process messages on behalf of ColourDropDowns
00905 
00906 ********************************************************************************************/
00907 
00908 MsgResult ColourDropMsgHandler::Message(Msg* Message)
00909 {
00910     if (MESSAGE_IS_A(Message, ColourChangingMsg))
00911     {
00912         ColourChangingMsg *Msg = (ColourChangingMsg *) Message;
00913         switch ( Msg->State )
00914         {
00915             case ColourChangingMsg::LISTDESELECTED:
00916 //          case ColourChangingMsg::LISTPAGED:
00917 //          case ColourChangingMsg::LISTUPDATED:
00918 //          case ColourChangingMsg::COLOURUPDATED:
00919                 ColourDropDown::UpdateForNewColourList();
00920                 break;
00921 
00922             case ColourChangingMsg::SELVIEWCONTEXTCHANGE:
00923                 // The colour context for the selected view has chnaged, so we must immediately
00924                 // force a redraw to make sure we show the colours with correction/separation.
00925                 ColourDropDown::RedrawColourDropDowns();
00926                 break;
00927             default:
00928                 break;
00929         }
00930     }
00931 
00932     return OK; 
00933 }
00934 

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