newcol.cpp

Go to the documentation of this file.
00001 // $Id: newcol.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 // newcol.cpp - The NewColourDlg class
00099 
00100 #include "camtypes.h"
00101 
00102 #include "coldrop.h"
00103 #include "collist.h"
00104 #include "colpick.h"
00105 #include "colourix.h"
00106 //#include "jason.h"
00107 #include "keypress.h"
00108 #include "newcol.h"
00109 //#include "nwcolres.h"
00110 //#include "resource.h" // For _R(IDS_CANCEL)
00111 //#include "justin2.h"
00112 
00113 #include "ccdc.h"       // For render-into-dialogue support
00114 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "grnddib.h"
00116 
00117 
00118 CC_IMPLEMENT_DYNCREATE(NewColourDlg, DialogOp)
00119 CC_IMPLEMENT_MEMDUMP(NewColourParam, OpParam)
00120 
00121 #define new CAM_DEBUG_NEW
00122 
00123 
00124 const INT32 NewColourDlg::IDD = _R(IDD_NEWCOLOURDLG);
00125 const CDlgMode NewColourDlg::Mode = MODAL;
00126 
00127 BOOL NewColourDlg::MakeShade = FALSE;
00128 
00129 
00130 /********************************************************************************************
00131 
00132 >   NewColourDlg::NewColourDlg(): DialogOp(NewColourDlg::IDD, NewColourDlg::Mode) 
00133 
00134 
00135     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00136     Created:    28/9/95
00137 
00138     Purpose:    NewColourDlg constructor.
00139 
00140 ********************************************************************************************/
00141 
00142 NewColourDlg::NewColourDlg() : DialogOp(NewColourDlg::IDD, NewColourDlg::Mode) 
00143 {
00144     ParentDropDown = NULL;
00145 }        
00146 
00147 
00148 
00149 /********************************************************************************************
00150 
00151 >   NewColourDlg::~NewColourDlg()
00152 
00153 
00154     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00155     Created:    28/9/95
00156 
00157     Purpose:    You'll never guess...
00158 
00159 ********************************************************************************************/
00160 
00161 NewColourDlg::~NewColourDlg()
00162 {
00163     if (ParentDropDown != NULL)
00164         delete ParentDropDown;
00165 }        
00166 
00167 
00168 
00169 /********************************************************************************************
00170 
00171 >   MsgResult NewColourDlg::Message( CDlgMessage DlgMsg, CGadgetID Gadget)
00172 
00173     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00174     Created:    28/9/95
00175     Inputs:     -
00176     Outputs:    -
00177     Returns:    -
00178     Purpose:    Handles all the scale dialog's messages 
00179     Errors:     -
00180     SeeAlso:    -
00181 
00182 ********************************************************************************************/
00183 
00184 MsgResult NewColourDlg::Message(Msg* Message)
00185 {
00186     if (IS_OUR_DIALOG_MSG(Message))
00187     {
00188         DialogMsg* Msg = (DialogMsg*)Message;
00189 //      BOOL EndDialog = FALSE;
00190 
00191         switch (Msg->DlgMsg)
00192         {
00193             case DIM_CREATE:
00194                 {
00195                     // Tick the "make shade" button if it was on the last time
00196                     SetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE), MakeShade);
00197 
00198                     // Set up the colour drop-down menu
00199                     BOOL ok = FALSE;
00200                     ParentDropDown = new ColourDropDown;
00201                     if (ParentDropDown != NULL && ParentDropDown->Init(WindowID, _R(IDC_NEWCOL_COLLIST)))
00202                     {
00203                         IndexedColour *ParentColour = Info->TheColour->FindLastLinkedParent();
00204                         
00205                         // Make sure the parent colour we're setting is legal (not deleted)
00206                         if (ParentColour != NULL && ParentColour->IsDeleted())
00207                             ParentColour = NULL;
00208 
00209                         ok = ParentDropDown->FillInColourList(ParentColour, -1, Info->TheColour);
00210                     }
00211 
00212                     // Shade controls appropriately, and fill in the name text field
00213                     ShadeControls();
00214                     SetNameText();
00215                     SetKeyboardFocus(_R(IDC_NEWCOL_NAME));
00216                     HighlightText(_R(IDC_NEWCOL_NAME));
00217 
00218                     // If the colour deropdown creation failed, then shade it to be safe
00219                     if (!ok)
00220                         EnableGadget(_R(IDC_NEWCOL_COLLIST), FALSE);
00221                 }
00222                 break;
00223 
00224                 
00225             case DIM_COMMIT:
00226             case DIM_SOFT_COMMIT:
00227                 CommitDetails();
00228                 break;
00229 
00230 
00231             case DIM_CANCEL:
00232                 Close();
00233                 End();
00234                 break;
00235 
00236 
00237             case DIM_LFT_BN_CLICKED:
00238                 if (Msg->GadgetID == _R(IDC_NEWCOL_SHADE))
00239                 {
00240                     SetNameText();          // Ensure name text is updated if necessary
00241                     ShadeControls();        // And make sure shading of controls is updated
00242                 }
00243                 break;
00244 
00245 
00246             case DIM_SELECTION_CHANGED:
00247                 if (Msg->GadgetID == _R(IDC_NEWCOL_COLLIST) && ParentDropDown != NULL)
00248                 {
00249                     INT32 Index = GetSelectedValueIndex(_R(IDC_NEWCOL_COLLIST));
00250 
00251                     IndexedColour *NewParent = ParentDropDown->DecodeSelection(Index);
00252                     Info->TheColour->SetLinkedParent(NewParent, Info->TheColour->GetType());
00253 
00254                     ShadeControls();
00255                     SetNameText();
00256                 }
00257                 break;
00258 /*
00259             case DIM_REDRAW:
00260                 if (Msg->GadgetID == _R(IDC_COLNAME_PATCH))
00261                 {
00262                     ReDrawInfoType *RedrawInfo = (ReDrawInfoType*) Msg->DlgMsgParam;
00263                     DocRect VirtualSize(0, 0, RedrawInfo->dx, RedrawInfo->dy);
00264                     RenderRegion *pRender = CreateOSRenderRegion(&VirtualSize, RedrawInfo);
00265                     if (pRender)
00266                     {
00267                         pRender->SaveContext();
00268 
00269                         DocColour PatchCol(128L, 128L, 128L);
00270                         if (Info->TheColour != NULL)
00271                             PatchCol.MakeRefToIndexedColour(Info->TheColour);
00272 
00273                         pRender->SetLineWidth(0);
00274                         pRender->SetLineColour(PatchCol);
00275                         pRender->SetFillColour(PatchCol);
00276                         pRender->DrawRect(&VirtualSize);
00277 
00278                         pRender->RestoreContext();
00279 
00280                         DestroyOSRenderRegion(pRender);
00281                     }
00282                 }
00283                 break;
00284 */
00285             default:
00286                 break;
00287         }
00288 
00289         return (DLG_EAT_IF_HUNGRY(Msg)); 
00290     }
00291 
00292     return OK; 
00293 }  
00294 
00295 
00296 
00297 /********************************************************************************************
00298 
00299 >   void NewColourDlg::ShadeControls(void)
00300 
00301     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00302     Created:    29/9/95
00303 
00304     Purpose:    Shades all controls appropriately to the current selection
00305 
00306 ********************************************************************************************/
00307 
00308 void NewColourDlg::ShadeControls(void)
00309 {
00310     // If there are no valid parent colours in the document, shade the "make shade" controls
00311     if (Info->TheList->GetUndeletedHead() == NULL)
00312     {
00313         EnableGadget(_R(IDC_NEWCOL_COLLIST), FALSE);
00314         EnableGadget(_R(IDC_NEWCOL_SHADE), FALSE);
00315     }
00316     else
00317     {
00318         // Parent colour for local colours is only available if you turn on "make shade"
00319         // but it is always available (copy-of or shade-of) for named colours
00320         if (Info->TheColour->IsNamed())
00321             EnableGadget(_R(IDC_NEWCOL_COLLIST), TRUE);
00322         else
00323             EnableGadget(_R(IDC_NEWCOL_COLLIST), GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE)));
00324     }
00325 }
00326 
00327 
00328 
00329 /********************************************************************************************
00330 
00331 >   void NewColourDlg::SetNameText(void)
00332 
00333     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00334     Created:    29/9/95
00335 
00336     Purpose:    Sets the name field appropriately to the current selection
00337                 If the user has changed the name field, it will not be touched
00338 
00339 ********************************************************************************************/
00340 
00341 void NewColourDlg::SetNameText(void)
00342 {
00343     String_256 CurrentText;
00344 
00345     CurrentText = GetStringGadgetValue(_R(IDC_NEWCOL_NAME));
00346     
00347     // Only change the text if it is blank or if the user has not changed it
00348     if (CurrentText.IsEmpty() || CurrentText == AutoName)
00349     {
00350         IndexedColour *ParentColour = Info->TheColour->FindLastLinkedParent();
00351 
00352         // Make sure the parent colour we're setting is legal (not deleted)
00353         if (ParentColour != NULL && ParentColour->IsDeleted())
00354             ParentColour = NULL;
00355 
00356         if (Info->TheColour->IsNamed() && ParentColour != NULL)
00357         {
00358             String_64 *ParentName = ParentColour->GetName();
00359 
00360             if (GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE)))
00361                 AutoName.MakeMsg(_R(IDS_SHADEOFCOLOUR), (TCHAR *) *ParentName);                 // "Shade of red"
00362             else
00363                 AutoName.MakeMsg(_R(IDS_COPYOFCOLOUR), (TCHAR *) *ParentName);                  // "Copy of red"
00364         }
00365         else
00366         {
00367             if (GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE)) && ParentColour != NULL)
00368                 AutoName.MakeMsg(_R(IDS_SHADEOFCOLOUR), (TCHAR *) *(ParentColour->GetName()));  // "Shade of red"
00369             else
00370                 AutoName.MakeMsg(_R(IDS_NEWCOLOUR));                                            // "New Colour"
00371         }
00372 
00373         SetStringGadgetValue(_R(IDC_NEWCOL_NAME), AutoName);
00374     }
00375 }
00376 
00377 
00378 
00379 /********************************************************************************************
00380 
00381 >   void NewColourDlg::CommitDetails(BOOL Force = FALSE, BOOL ForceMakeShade = FALSE)
00382 
00383     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00384     Created:    28/9/95
00385 
00386     Inputs:     Force - TRUE to override the settings in the window (the window need not
00387                 actually exist if this is TRUE)
00388                 ForceMakeShade - ignored if Force is FALSE, else
00389                                  TRUE to make a Linked "shade", FALSE to make a copy of the parent
00390 
00391     Purpose:    Commits to the current setting for the colour
00392                 Reads the settings the user has chosen and changes the result colour
00393                 to suit those settings. Sets the Result to TRUE if it succeeds.
00394                 Then closes and ends the dialogue.
00395 
00396     Notes:      If the result is placed into TheColour, then a ColourChangingMsg broadcast
00397                 will be sent. Thus, if a caller wants only to rename a colour, they need
00398                 only call up the dialogue upon that colour - set and forget.
00399 
00400 ********************************************************************************************/
00401 
00402 void NewColourDlg::CommitDetails(BOOL Force, BOOL ForceMakeShade)
00403 {
00404     // Set result to 'success'
00405     Info->Result = TRUE;
00406 
00407     // Set the colour type etc as appropriate
00408     IndexedColour *ParentColour = Info->TheColour->FindLastLinkedParent();
00409 
00410     // Make sure the parent colour we're setting is legal (not deleted or in another doc)
00411     if (ParentColour != NULL)
00412     {
00413         IndexedColour *Ptr = Info->TheList->GetUndeletedHead();
00414         while (Ptr != NULL)
00415         {
00416             if (Ptr == ParentColour)
00417                 break;
00418 
00419             Ptr = Info->TheList->GetUndeletedNext(Ptr);
00420         }
00421 
00422         if (Ptr != ParentColour)    // ParentColour not found in the intended destination list!
00423             ParentColour = NULL;    // Set it to NULL, and we'll find a safe ParentColour below
00424 
00425         if (ParentColour != NULL && ParentColour->IsDeleted())
00426             ParentColour = NULL;
00427     }
00428 
00429     if (ParentColour == NULL)
00430     {
00431         // If the parent was illegal, it's a big screwup. Oh bums.
00432         // Luckily, we can fix the problem and continue happily
00433         ERROR3IF(Info->TheColour->FindLastLinkedParent() != NULL,
00434                     "NewColourDlg - had to correct colour with illegal parent pointer!");
00435 
00436         // Set the parent to NULL before we do ourselves an injury!
00437         Info->TheColour->SetLinkedParent(NULL, COLOURTYPE_NORMAL);
00438     }
00439     else
00440     {
00441         // Get the parent and child colour definitions in HSV, as this info is useful
00442         ColourContext *cc = ColourContext::GetGlobalDefault(COLOURMODEL_HSVT);
00443 
00444         if (Force)
00445             MakeShade = ForceMakeShade;
00446         else
00447             MakeShade = GetBoolGadgetSelected(_R(IDC_NEWCOL_SHADE));
00448 
00449         if (MakeShade)
00450         {
00451 /*
00452             Info->TheColour->SetLinkedParent(ParentColour, COLOURTYPE_LINKED);
00453 
00454             // Coerce the colour to be an HSV colour
00455             ColourPicker::ForceColourModel(Info->TheColour, cc);
00456 
00457             // And set it to inherit Hue only
00458             Info->TheColour->SetInheritsComponent(1, TRUE);
00459             Info->TheColour->SetInheritsComponent(2, FALSE);
00460             Info->TheColour->SetInheritsComponent(3, FALSE);
00461             Info->TheColour->SetInheritsComponent(4, FALSE);
00462 */
00463             // Calculate the shading values to keep this colour looking correct
00464             FIXED24 NewX(0.0);
00465             FIXED24 NewY(0.0);
00466 
00467             // Work out saturation scaling factor
00468             ColourHSVT ParentDef;
00469             ColourHSVT ColourDef;
00470             cc->ConvertColour(ParentColour, (ColourGeneric *)&ParentDef);
00471             cc->ConvertColour(Info->TheColour, (ColourGeneric *)&ColourDef);
00472 
00473             double ParentVal = ParentDef.Saturation.MakeDouble();
00474             double ColourVal = ColourDef.Saturation.MakeDouble();
00475 
00476             if (ParentVal > ColourVal)
00477             {
00478                 if (ParentVal > 0.0)
00479                     NewX = -((ParentVal - ColourVal) / ParentVal);
00480             }
00481             else
00482             {
00483                 if (ParentVal < 1.0)
00484                     NewX = (ColourVal - ParentVal) / (1.0 - ParentVal);
00485             }
00486 
00487             // Work out Value scaling factor
00488             ParentVal = ParentDef.Value.MakeDouble();
00489             ColourVal = ColourDef.Value.MakeDouble();
00490             if (ParentVal > ColourVal)
00491             {
00492                 if (ParentVal > 0.0)
00493                     NewY = -((ParentVal - ColourVal) / ParentVal);
00494             }
00495             else
00496             {
00497                 if (ParentVal < 1.0)
00498                     NewY = (ColourVal - ParentVal) / (1.0 - ParentVal);
00499             }
00500 
00501             // And make the colour a shade (a special type of tint)
00502             Info->TheColour->SetLinkedParent(ParentColour, COLOURTYPE_TINT);
00503             Info->TheColour->SetShadeValues(NewX, NewY);
00504         }
00505         else
00506         {
00507             // Only change the colour if it is already named - otherwise, we're making
00508             // a local colour into a named colour, and we don't want to alter it.
00509             if (Info->TheColour->IsNamed())
00510             {
00511                 // Copy the colour from the parent - the name will be fixed up below
00512                 *Info->TheColour = *ParentColour;
00513                 Info->TheColour->SetLinkedParent(ParentColour, Info->TheColour->GetType());
00514             }
00515         }
00516     }
00517 
00518     String_256 NewName("");
00519     if (!Force)
00520         NewName = GetStringGadgetValue(_R(IDC_NEWCOL_NAME));
00521 
00522     if (NewName.IsEmpty())              // User gave NULL name. Use 'New Colour' instead.
00523         NewName.MakeMsg(_R(IDS_NEWCOLOUR));
00524 
00525     // We must set the new name for the colour - first make sure it's unique
00526     String_64 UniqueName;
00527     if (Info->TheList->GenerateUniqueColourName((const StringBase *) &NewName, &UniqueName) && !Force)
00528     {
00529         // If the name had to be changed, and the force flag is off (the user brought up the dialogue
00530         // and entered a name for themselves) then warn them that the name has been changed to
00531         // protect the innocent. If you can call the CamEPS filter innocent...
00532 
00533         TCHAR TempStr[256];
00534         String_256 jcf(_R(IDS_NEWCOL_RENAMED));
00535         camSnprintf(TempStr, 256, jcf, (LPCTSTR) UniqueName);
00536 
00537         // We still don't have a f***ing way of reporting a f***ing message to the user which uses
00538         // a STRING so we can f***ing include f***ing useful information at runtime!
00539         // Thus, we InformError to do it. This will use the error beep and a scary huge pling icon,
00540         // and the user will brown his pants thinking that an access violation complete death
00541         // scenario is upon him.
00542         Error::SetError(0, TempStr, 0);
00543         InformError();
00544     }
00545 
00546     Info->TheColour->SetName(UniqueName);
00547 
00548     if (!Force)
00549         Close();
00550 
00551     End();
00552 }
00553 
00554 
00555 
00556 /********************************************************************************************
00557 
00558 >   OpState NewColourDlg::GetState(String_256*, OpDescriptor*)
00559 
00560     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00561     Created:    28/9/95
00562     Purpose:    NewColourDlg GetState method
00563 
00564 ********************************************************************************************/
00565 
00566 OpState NewColourDlg::GetState(String_256*, OpDescriptor*)
00567 {    
00568     OpState OpSt;
00569     return(OpSt);
00570 }
00571 
00572 
00573          
00574 /********************************************************************************************
00575 
00576 >   BOOL NewColourDlg::Init(void)
00577 
00578     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00579     Created:    28/9/95
00580 
00581     Purpose:    NewColourDlg Init method. Called by sginit.cpp
00582 
00583 ********************************************************************************************/
00584 
00585 BOOL NewColourDlg::Init(void)
00586 {  
00587     return (RegisterOpDescriptor(
00588                                 0,
00589                                 _R(IDS_NEWCOLOURDLG),
00590                                 CC_RUNTIME_CLASS(NewColourDlg),
00591                                 OPTOKEN_NEWCOLOURDLG,
00592                                 NewColourDlg::GetState,
00593                                 0,  // help ID
00594                                 0   // bubble ID
00595                                 )
00596             ); 
00597 }   
00598  
00599 
00600 
00601 /********************************************************************************************
00602 
00603 >   BOOL NewColourDlg::Create()
00604 
00605     Authofosr:      Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00606     Created:    28/9/95
00607     Returns:    TRUE if successful, else FALSE
00608     Purpose:    NewColourDlg create method 
00609 
00610 ********************************************************************************************/
00611 
00612 BOOL NewColourDlg::Create()
00613 {
00614     return(DialogOp::Create());
00615 }
00616 
00617 
00618 
00619 /********************************************************************************************
00620 
00621 >   void NewColourDlg::DoWithParam(OpDescriptor*,OpParam* pOpParam)
00622 
00623     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00624     Created:    28/9/95
00625     Inputs:     pOpParam = ptr to a NewColourParam struct
00626 
00627     Purpose:    Creates then opens the dialog 
00628 
00629 ********************************************************************************************/
00630 
00631 
00632 void NewColourDlg::DoWithParam(OpDescriptor*, OpParam* pOpParam)
00633 {
00634     ERROR3IF(pOpParam == NULL, "Come on, play by the rules");
00635 
00636     Info = (NewColourParam *) pOpParam;
00637 
00638     if (Info->TheColour == NULL || Info->TheList == NULL)
00639     {
00640         ERROR3("NewColourDlg parameters are unhelpful to say the least");
00641         End();
00642         return;
00643     }
00644 
00645     // Check that the colour's intended parent is safe (in the destination document)
00646     IndexedColour *Parent = Info->TheColour->FindLastLinkedParent();
00647     if (Parent != NULL)
00648     {
00649         IndexedColour *Ptr = Info->TheList->GetUndeletedHead();
00650         while (Ptr != NULL)
00651         {
00652             if (Ptr == Parent)
00653                 break;
00654 
00655             Ptr = Info->TheList->GetUndeletedNext(Ptr);
00656         }
00657 
00658         if (Ptr != Parent)  // Parent not found in the intended destination list!
00659             Parent = NULL;  // Set it to NULL, and we'll find a safe parent below
00660     }
00661 
00662     // --- Make sure the colour defaults to having some sort of safe parent hint
00663     if (Parent == NULL || Parent->IsDeleted())
00664     {
00665         IndexedColour *Bob = (IndexedColour *) Info->TheList->GetUndeletedHead();
00666         Info->TheColour->SetLinkedParent(Bob, Info->TheColour->GetType());
00667     }
00668 
00669     // --- Check for key shortcuts
00670     // If various modifier keys are held down when the dlg is invoked, then it will
00671     // shortcut the process by proceeding with certain options set.
00672     if (KeyPress::IsConstrainPressed())
00673     {
00674         if (KeyPress::IsAdjustPressed())
00675             CommitDetails(TRUE, MakeShade);     // Force previously used setting (ctrl-shift)
00676         else
00677             CommitDetails(TRUE, TRUE);          // Force "shade of" (ctrl only)
00678         return;
00679     }
00680 
00681     if (KeyPress::IsAdjustPressed())
00682     {
00683         CommitDetails(TRUE, FALSE);             // Force "a copy of" (shift only)
00684         return;
00685     }
00686 
00687     // --- Otherwise, create and open the dialogue
00688     if (!Create())
00689     {
00690         InformError();
00691         End();
00692     }
00693 }
00694 
00695 
00696 
00697 /********************************************************************************************
00698 
00699 >   static BOOL NewColourDlg::InvokeDialog(ColourList *ParentList, IndexedColour *SourceAndResult,
00700                                             NewColourDlgType Flags = NEWCOLOUR_NAMEDORUNNAMED)
00701 
00702     Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00703     Created:    28/9/95
00704 
00705     Inputs:     ParentList   - the list in which the colour resides (not NULL)
00706                 SourceAndResult - the colour which is being created
00707                 Flags - Indicates if the colour can be either named or unnamed, or if it should
00708                 limit the result to specifically a named or unnamed colour.
00709 
00710     Outputs:    SourceAndResult is updated depending on its original state and the
00711                 users subsequent choices. Normal colours may be made linked (and
00712                 will use the parent colour pointer "hint" if available to provide
00713                 a default parent colour).
00714 
00715                 NOTE: It will be returned as either a local colour or a colour style - check
00716                 IsNamed() to distinguish this case, and add it to the colour list in
00717                 an appropriate manner!
00718 
00719     Returns:    TRUE if it succeeded - in this case, you should add your SourceAndResult colour
00720                 to the colour list in an *appropriate* manner.
00721 
00722                 FALSE if it failed or the user hit Cancel - in this case, you should delete
00723                 your SourceAndResult colour.
00724 
00725     Purpose:    Opens the new colour dialogue on screen, elicits a response, 
00726                 and returns having set up the new colour according to the users instructions.
00727                 This is a MODAL dlg.
00728 
00729 ********************************************************************************************/
00730 
00731 BOOL NewColourDlg::InvokeDialog(ColourList *ParentList, IndexedColour *Result,
00732                                 NewColourDlgType Flags)
00733 {
00734     ERROR3IF(ParentList == NULL || Result == NULL, "Come on, play by the rules");
00735 
00736     NewColourParam Info(ParentList, Result, Flags);
00737     OpDescriptor *TheDlg = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(NewColourDlg));
00738 
00739     ERROR3IF(TheDlg == NULL, "NewColourDlg::InvokeDialog is unable to find the Dlg OpDescriptor");
00740 
00741     if (TheDlg != NULL)
00742         TheDlg->Invoke(&Info);
00743 
00744     return(Info.Result);
00745 }
00746 

Generated on Sat Nov 10 03:45:50 2007 for Camelot by  doxygen 1.4.4