tmpltdlg.cpp

Go to the documentation of this file.
00001 // $Id: tmpltdlg.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 // The dialog that lets Mr Smart User make attributes templatable
00099 
00100 #include "camtypes.h"
00101 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00102 #include "tmpltdlg.h"
00103 
00104 //#include "tmpltres.h"
00105 //#include "barsdlgs.h"     // _R(IDD_BARCONTROLSTORE)
00106 #include "xshelpid.h"
00107 
00108 //#include "app.h"          //for GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 
00112 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 
00114 //#include "attrval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "nodeattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 #include "userattr.h"
00117 #include "tmpltatr.h"
00118 
00119 
00120 #include "gadget.h"
00121 #include "uielem.h"
00122 #include "visiattr.h"
00123 
00124 #include "attraggl.h"
00125 
00126 //#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00127 #include "opnode.h"
00128 
00129 #include "tmpltarg.h"
00130 #include "styles.h"
00131 
00132 #include "namedlg.h"
00133 
00134 
00135 DECLARE_SOURCE("$Revision: 1282 $");
00136 
00137 CC_IMPLEMENT_DYNCREATE(TemplateDialog, DialogOp);
00138 
00139 
00140 /**************************************************************************************
00141 
00142 >   class VisibleListWithEditableEntries : public VisibleList
00143 
00144     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00145     Created:    15/10/96
00146 
00147     Purpose:    This rendition of a VisibleList has VisibleListItems that are editable
00148                 The functionality should be in the base class but that TemplateDialog
00149                 parameter ruins things a bit.
00150 
00151 **************************************************************************************/
00152 class VisibleListWithEditableEntries : public VisibleList
00153 {
00154     CC_DECLARE_MEMDUMP(VisibleListWithEditableEntries);
00155 
00156 public:
00157     VisibleListWithEditableEntries() : 
00158         m_pLastSelectedEntry(NULL) {}
00159 
00160     virtual BOOL DeleteSelectedEntries();
00161     virtual BOOL DeleteAllEntries();
00162     virtual void RemoveSelection();
00163     virtual void OnSelectionChange(TemplateDialog& Dialog);
00164 
00165 protected:
00166     BOOL IsLastSelectedEntry() const                            {   return m_pLastSelectedEntry != NULL;    }
00167     VisibleListItem* GetLastSelectedEntry() const               {   return m_pLastSelectedEntry;    }
00168 
00169     void SetNoLastSelectedEntry()                               {   m_pLastSelectedEntry = NULL;    }
00170     void SetLastSelectedEntry(VisibleListItem& Entry)           {   m_pLastSelectedEntry = &Entry;  }
00171 
00172     virtual void HideLastSelectedEntry();
00173 
00174 private:
00175     VisibleListItem*    m_pLastSelectedEntry;
00176 };
00177 
00178 
00179 
00180 
00181 
00182 /**************************************************************************************
00183 
00184 >   class AvailableProperty : public VisibleListItem
00185 
00186     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00187     Created:    15/10/96
00188 
00189     Purpose:    This abstract class represent an item in the "Available Properties"
00190                 list.
00191 
00192 **************************************************************************************/
00193 class AvailableProperty : public VisibleListItem
00194 {
00195     CC_DECLARE_MEMDUMP(AvailableProperty);
00196 
00197 public:
00198     virtual AppliedAttribute* CreateUsedProperty() = 0;
00199     virtual BOOL CanBecomeStyle() const = 0;
00200     virtual Style* MakeStyle(const StringBase& StyleName)   {   return NULL;    }
00201 
00202 private:
00203 };
00204 
00205 
00206 class VisibleWizOpStyle;
00207 /**************************************************************************************
00208 
00209 >   class VisibleTemplateHandler : public AvailableProperty
00210 
00211     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00212     Created:    15/10/96
00213 
00214     Purpose:    Provides the user with something tangible in the way of WizOp's.
00215                 They can appear in a list control via this class.
00216 
00217 **************************************************************************************/
00218 class VisibleTemplateHandler : public AvailableProperty
00219 {
00220     CC_DECLARE_MEMDUMP(VisibleTemplateHandler);
00221 
00222 public:
00223     VisibleTemplateHandler(const WizOp& Handler);
00224     VisibleTemplateHandler(const VisibleTemplateHandler& Other);
00225     VisibleTemplateHandler& operator=(const VisibleTemplateHandler& Other);
00226 
00227     ~VisibleTemplateHandler();
00228 
00229 //  Overridden implementations
00230     virtual BOOL Display(DialogOp& Dialog);
00231     virtual BOOL Interact(DialogOp& Dialog);
00232     virtual void Hide();
00233 
00234     virtual StringBase& GetText(StringBase& Description) const;
00235 
00236     virtual AppliedAttribute* CreateUsedProperty();
00237     virtual BOOL CanBecomeStyle() const                     {   return TRUE;    }
00238     virtual Style* MakeStyle(const StringBase& StyleName);
00239 
00240 protected:
00241     const WizOp& GetWizOp() const       {   return m_Handler;   }
00242     const StringBase& GetWorkingQuestion();
00243     const StringBase& GetWorkingParam();
00244 
00245 private:
00246     const WizOp&                m_Handler;
00247     VisibleTemplateAttribute*   m_pWorkingVisibleAttr;
00248 };
00249 
00250 
00251 /**************************************************************************************
00252 
00253 >   class VisibleWizOpStyle : public AvailableProperty
00254 
00255     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00256     Created:    15/10/96
00257 
00258     Purpose:    Provides the user with a style to play with.
00259                 They can appear in a list control via this class.
00260 
00261 **************************************************************************************/
00262 class VisibleWizOpStyle : public AvailableProperty
00263 {
00264     CC_DECLARE_MEMDUMP(VisibleWizOpStyle);
00265 
00266 public:
00267     VisibleWizOpStyle(const WizOpStyle& Style);
00268 
00269     virtual BOOL Display(DialogOp& Dialog);
00270     virtual BOOL Interact(DialogOp& Dialog);
00271     virtual void Hide();
00272     virtual StringBase& GetText(StringBase& Description) const      {   return (Description = m_Style.GetName());   }
00273 
00274     virtual AppliedAttribute* CreateUsedProperty();
00275     virtual BOOL CanBecomeStyle() const                     {   return FALSE;   }
00276 
00277 private:
00278     const WizOpStyle&   m_Style;
00279     EditableText        m_Question; // actually we can't edit these, but they appear 
00280     EditableText        m_Param;    // in a box, disabled
00281     VisibleLabel        m_ParamHint;
00282 
00283 };
00284 
00285 
00286 /**************************************************************************************
00287 
00288 >   class CustomProperty : public AvailableProperty
00289 
00290     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00291     Created:    15/10/96
00292 
00293     Purpose:    Provides a "custom" visible template handler so the user can enter
00294                 raw user attributes.
00295 
00296 **************************************************************************************/
00297 class CustomProperty : public AvailableProperty
00298 {
00299     CC_DECLARE_MEMDUMP(CustomProperty);
00300 
00301 public:
00302     CustomProperty() : m_pWorkingVisibleAttr(NULL)  {}
00303 
00304 // Overridden functions
00305     virtual BOOL Display(DialogOp& Dialog);
00306     virtual BOOL Interact(DialogOp& Dialog);
00307     virtual void Hide();
00308 
00309     virtual StringBase& GetText(StringBase& Description) const  {   Description.Load(_R(IDS_CUSTOM_WIZOP));return Description;  }
00310     virtual BOOL operator > (const VisibleListItem& OtherItem) const    {   return TRUE;    }
00311 
00312     virtual AppliedAttribute* CreateUsedProperty();
00313     virtual BOOL CanBecomeStyle() const                     {   return FALSE;   }
00314 
00315 private:
00316     VisibleUserAttribute*   m_pWorkingVisibleAttr;
00317 };
00318 
00319 
00320 /**************************************************************************************
00321 
00322 >   class AvailablePropertiesList : public VisibleListWithEditableEntries
00323 
00324     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00325     Created:    15/10/96
00326 
00327     Purpose:    Provides a visible list of template handlers
00328 
00329 **************************************************************************************/
00330 class AvailablePropertiesList : public VisibleListWithEditableEntries
00331 {
00332     CC_DECLARE_MEMDUMP(AvailablePropertiesList);
00333 
00334 public:
00335     BOOL AddFromTemplateHandler(const WizOp& Handler);
00336     BOOL AddStyle(const WizOpStyle& NewStyle);
00337 
00338     BOOL AddTemplateHandlers(const WizOps& Handlers);
00339     BOOL AddStyles(const WizOpStyles& Styles);
00340 
00341 private:
00342 };
00343 
00344 
00345 /**************************************************************************************
00346 
00347 >   class UsedPropertiesList : public VisibleListWithEditableEntries
00348 
00349     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00350     Created:    15/10/96
00351 
00352     Purpose:    Provides a visible list of user attributes
00353 
00354 **************************************************************************************/
00355 class UsedPropertiesList : public VisibleListWithEditableEntries
00356 {
00357     CC_DECLARE_MEMDUMP(UsedPropertiesList);
00358 
00359 public:
00360     UsedPropertiesList() : 
00361         m_pOriginalEntries(NULL), m_pRemovedEntries(NULL), m_ArraysSize(0) {}
00362 
00363     ~UsedPropertiesList();
00364 
00365 // Overridden
00366     virtual BOOL InsertEntry(VisibleListItem& EntryToInsert);
00367     virtual BOOL DeleteAllEntries();
00368 
00369 
00370     BOOL AddAvailableProperty(AvailableProperty& NewProperty);
00371     BOOL BuildFromEnumerator(RenderableNodeEnumerator& Enumerator);
00372     BOOL Commit(Operation& OpToApplyWith);
00373     BOOL DeleteAttributes(String_128 AttrIDs[]);
00374 
00375 protected:
00376 // Overridden
00377     virtual BOOL DeleteEntryAtIndex(UINT32 Index);
00378 //  virtual void HideLastSelectedEntry();
00379 
00380 //  virtual BOOL IsDuplicate(const AppliedAttribute& Entry) const;
00381 //  virtual void WarnUser(StringID WarningResourceID) const;
00382 //  virtual void RetractEntryChanges(VisibleListItem& Entry);
00383 
00384 // Data Access
00385     String_128*                 GetRemovedEntries()     {   return m_pRemovedEntries;   }
00386     const AppliedAttribute**    GetOriginalEntries()    {   return m_pOriginalEntries;  }
00387 
00388 // Implementation
00389     BOOL NoteNewEntries();
00390     CommonAttrMultiSet* FindCommonUserAttributes(RenderableNodeEnumerator& Enumerator);
00391 
00392 
00393 private:
00394     const AppliedAttribute**    m_pOriginalEntries;
00395     String_128*                 m_pRemovedEntries;
00396     UINT32                      m_ArraysSize;
00397 };
00398 
00399 
00400 
00401 /*
00402 class Observer : public Notifiable
00403 {
00404     TemplateDialog* m_pTheDialog;
00405 public:
00406     Observer( EditableText* const pContainer ): m_pTheTextObject(pContainer){}
00407     void Notify( Notifier* const pSender );
00408 };
00409 
00410 
00411 class DynamicDialog : public DialogOp
00412 {
00413     CC_DECLARE_DYNCREATE(DynamicDialog);
00414 
00415     //Constructors, destructors and initialiser
00416 public:
00417     // Metaclass members
00418     static BOOL     Declare();
00419     static OpState  GetState(String_256*, OpDescriptor*);
00420 
00421 public:
00422     DynamicDialog();
00423     virtual ~DynamicDialog();
00424 
00425     // Creating the dialog
00426 public:
00427     // Overridden 
00428     virtual void Do(OpDescriptor* pParam);
00429 
00430     PutMeOnYou(const StringBase& ElementName, Element);
00431 
00432     TextControl& GetValueControl() const;
00433     StaticTextControl& GetParamHintControl() const;
00434 
00435     void SetUserCanModifyQuestion(BOOL TheyAre);
00436 
00437 protected:
00438     // Overridden 
00439     virtual MsgResult Message(Msg* Message);
00440 
00441     virtual void OnCreate();
00442     virtual void OnSelectionChange();
00443 
00444     void OnAvailableSelectionChange();
00445     void OnUsedSelectionChange();
00446 
00447 protected:
00448     // Implementation
00449     BOOL CreateGadgets();
00450 
00451 protected:
00452     void ApplyUsedAttributes();
00453 
00454 protected:
00455     // Data Member Access
00456     AvailablePropertiesList&    GetAvailableProperties();
00457     UsedPropertiesList&         GetUsedProperties();
00458     BOOL UserCanModifyQuestion() const;
00459 
00460     
00461 public:
00462     static const CDlgResID  s_IDD;
00463     static const CDlgMode   s_Mode;
00464 
00465 private:
00466 //  Should generate these dynamically...
00467     m_Fields;
00468 };
00469 
00470 class DialogButton : public UserInterface, public Notifiable
00471 {
00472 public:
00473     DialogButton(DialogMgrGadget& GadgetToUse);
00474 
00475     virtual BOOL Display();
00476     virtual BOOL Interact();
00477     virtual void Hide();
00478     
00479     virtual void Notify (Notifier* pSender);
00480 
00481 private:
00482     Button* m_pButton;
00483 };
00484 
00485 
00486 class AddButton : public DialogButton
00487 {
00488 public:
00489     AddButton();
00490     virtual ~AddButton();
00491 
00492     virtual BOOL Display(DialogOp& Dialog);
00493     virtual void Hide();
00494     
00495     virtual void Notify(Notifier* pSender);
00496 
00497 private:
00498     Button* m_pButton;
00499 };
00500 
00501 
00502 class TemplateDialog::MakeStyleButton : public DialogButton
00503 {
00504     class StyleCreator : public Notifiable
00505     {
00506         MakeStyleButton&    m_Button;
00507         virtual void Notify( Notifier* pSender );
00508     public:
00509         StyleCreator(MakeStyleButton& Button) : m_Button(Button) {}
00510     }
00511     m_Creator;
00512     friend class TemplateDialog::StyleCreator;
00513 
00514     class Disabler : public Notifiable
00515     {
00516         MakeStyleButton&    m_Button;
00517         virtual void Notify( Notifier* pSender );
00518     public:
00519         Disabler(MakeStyleButton& Button) : m_Button(Button) {}
00520     }
00521     m_Disabler;
00522     friend class TemplateDialog::StyleCreator;
00523 };
00524 
00525 TemplateDialog::MakeStyleButton::Disabler::Notify(Notifier* pSender)
00526 {
00527 }
00528 
00529 TemplateDialog::MakeStyleButton::StyleCreator::Notify(Notifier* pSender)
00530 {
00531     ENSURE_NOT_NULL(pSender);
00532     ENSURE_KIND(pSender, ButtonNotifier);
00533 
00534     AvailableProperty* const pSelectedProperty = (AvailableProperty*)GetAvailableProperties().GetFirstSelectedEntry();
00535     if (pSelectedProperty != NULL)
00536     {
00537         // Invoke a dialog for the name
00538         NameDialogParam StyleNameParam;
00539         if (NameDialog::Invoke(StyleNameParam))     // do we still want it?
00540         {
00541             // if so create a new style
00542             Style* pNewStyle = pSelectedProperty->MakeStyle(StyleNameParam.GetNameEntered());
00543             if (pNewStyle != NULL)
00544             {
00545                 Style* pStyleToUse = AddNewStyle(*pNewStyle);
00546                 if (pStyleToUse != NULL)
00547                 {
00548                     GetAvailableProperties().AddStyle(*((WizOpStyle*)pStyleToUse));
00549                     pSelectedProperty->Hide();
00550                 }
00551             }
00552             delete pNewStyle;
00553             pNewStyle = NULL;
00554         }
00555     }
00556 
00557     // And throw away the keyboard focus
00558     DialogManager::DefaultKeyboardFocus();
00559 
00560 }
00561 
00562 
00563 
00564 
00565 
00566 class PropertyAddedNotifier : public Notifiable, public Notifier
00567 {
00568 public:
00569     UsedPropertiesChangedNotifier(UsedProperties, AddButton, RemoveButton, ApplyButton, RemoveAllButton)
00570 
00571     virtual void Notify( Notifier* const pSender )
00572     {
00573         ButtonNotifier Notifier(ButtonNotifier::DISABLE);
00574         m_AddButton->Notify(Notifier);
00575     }
00576 private:
00577     m_UsedProperties;
00578     m_AddButton;
00579     m_RemoveButton;
00580     m_RemoveAllButton;
00581     m_ApplyButton;
00582 };
00583 
00584 class PropertyRemovedNotifier : public Notifiable
00585 {
00586 public:
00587     UsedPropertiesChangedNotifier(AddButton, 
00588     virtual void Notify( Notifier* const pSender ) = 0;
00589     virtual ~Notifiable(){}
00590 };
00591 
00592 */
00593 
00594 
00595 
00596 
00597 
00598 
00599 
00600 CC_IMPLEMENT_MEMDUMP(VisibleListWithEditableEntries, VisibleList);
00601 CC_IMPLEMENT_MEMDUMP(AvailableProperty, VisibleListItem);
00602 CC_IMPLEMENT_MEMDUMP(VisibleTemplateHandler, AvailableProperty);
00603 CC_IMPLEMENT_MEMDUMP(CustomProperty, AvailableProperty);
00604 CC_IMPLEMENT_MEMDUMP(VisibleWizOpStyle, AvailableProperty);
00605 CC_IMPLEMENT_MEMDUMP(AvailablePropertiesList, VisibleListWithEditableEntries);
00606 CC_IMPLEMENT_MEMDUMP(UsedPropertiesList, VisibleListWithEditableEntries);
00607 
00608 #define new CAM_DEBUG_NEW
00609 #define ENSURE_THIS()       ENSURE(this != NULL, "this NULL")
00610 #define ENSURE_KIND(pInstance, Class)   ERROR3IF(!pInstance->IS_KIND_OF(Class), #pInstance" is not kind of "#Class);
00611 
00612 
00613 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00614 //  V  I  S  I  B  L  E  L  I  S  T  W  I  T  H  E  D  I  T  A  B  L  E  E  N  T  R  I  E  S
00615 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00616 
00617 
00618 
00619 /********************************************************************************************
00620 
00621 >   virtual BOOL VisibleListWithEditableEntries::DeleteSelectedEntries()
00622 
00623     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00624     Created:    09/06/97
00625     
00626     Purpose:    Overrides the base class so that the last selected entry is set to
00627                 none when 
00628 
00629     See Also:   VisibleList::DeleteSelectedEntries()
00630 
00631 ********************************************************************************************/
00632 BOOL VisibleListWithEditableEntries::DeleteSelectedEntries()
00633 {
00634     HideLastSelectedEntry();
00635 
00636     SetNoLastSelectedEntry();
00637 
00638     return VisibleList::DeleteSelectedEntries();
00639 }
00640 
00641 
00642 
00643 /********************************************************************************************
00644 
00645 >   virtual BOOL VisibleListWithEditableEntries::DeleteAllEntries()
00646 
00647     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00648     Created:    09/06/97
00649     
00650     Purpose:    Overrides the base class so that the last selected entry is set to
00651                 none when 
00652 
00653     See Also:   VisibleList::DeleteAllEntries()
00654 
00655 ********************************************************************************************/
00656 BOOL VisibleListWithEditableEntries::DeleteAllEntries()
00657 {
00658     HideLastSelectedEntry();
00659 
00660     SetNoLastSelectedEntry();
00661 
00662     return VisibleList::DeleteAllEntries();
00663 }
00664 
00665 
00666 /********************************************************************************************
00667 
00668 >   virtual void VisibleListWithEditableEntries::RemoveSelection()
00669 
00670     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00671     Created:    09/06/97
00672     
00673     Purpose:    Overrides the base class so that when we remove the selection, the entry
00674                 shown is hidden.
00675 
00676     See Also:   VisibleList::DeleteAllEntries()
00677 
00678 ********************************************************************************************/
00679 void VisibleListWithEditableEntries::RemoveSelection()
00680 {
00681     HideLastSelectedEntry();
00682 
00683     VisibleList::RemoveSelection();
00684 }
00685 
00686 
00687 /********************************************************************************************
00688 
00689 >   virtual void VisibleListWithEditableEntries::HideLastSelectedEntry()
00690 
00691     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00692     Created:    09/06/97
00693     
00694     Purpose:    Support function to hide the last selected entry
00695 
00696 ********************************************************************************************/
00697 void VisibleListWithEditableEntries::HideLastSelectedEntry()
00698 {
00699     if (IsLastSelectedEntry())
00700     {
00701         VisibleListItem* const pPreviousSelection = GetLastSelectedEntry();
00702         if (pPreviousSelection != NULL)
00703         {
00704             pPreviousSelection->Hide();
00705         }
00706     }
00707 }
00708 
00709 
00710 /********************************************************************************************
00711 
00712 >   virtual void VisibleListWithEditableEntries::OnSelectionChange(TemplateDialog& Dialog)
00713 
00714     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00715     Created:    09/06/97
00716     
00717     Purpose:    When the selected item(s) in this list, call this function.
00718                 Should do a Notify but hides the last selected "EditableEntry" and Interacts
00719                 with the newly selected one.
00720 
00721 ********************************************************************************************/
00722 void VisibleListWithEditableEntries::OnSelectionChange(TemplateDialog& Dialog)
00723 {
00724     // if there was an entry already showing its innards get rid of it
00725     HideLastSelectedEntry();
00726 
00727     // Display the right question, changing the "last" selected entry to the one we're gonna show
00728     if (GetNumberOfSelectedEntries() == 1)
00729     {
00730         // Show the entry's question / param pair
00731         VisibleListItem* const pSelectedEntry = GetFirstSelectedEntry();
00732         if (pSelectedEntry != NULL)
00733         {
00734             SetLastSelectedEntry(*pSelectedEntry);
00735             pSelectedEntry->Display(Dialog);
00736             pSelectedEntry->Interact(Dialog);
00737         }
00738         else
00739         {
00740             TRACE( _T("VisibleListWithEditableEntries::OnSelectionChange() - Selection count / entries incongruency\n"));
00741         }
00742     }
00743     else
00744     {
00745         // if there's more than one or none selected don't confuse the user by showing the 
00746         // question / param
00747         SetNoLastSelectedEntry();
00748     }
00749 }
00750 
00751 
00752 
00753 
00754 
00755 
00756 
00757 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00758 //          V  I  S  I  B  L  E  T  E  M  P  L  A  T  E  H  A  N  D  L  E  R
00759 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00760 
00761 
00762 
00763 
00764 
00765 
00766 /********************************************************************************************
00767 
00768 >   VisibleTemplateHandler::VisibleTemplateHandler(const WizOp& Handler)
00769 
00770     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00771     Created:    09/06/97
00772     
00773     Purpose:    Constructs us a WizOp that can be on the screen (this is all horribly wrong).
00774 
00775 ********************************************************************************************/
00776 VisibleTemplateHandler::VisibleTemplateHandler(const WizOp& Handler) : 
00777     m_Handler(Handler), 
00778     m_pWorkingVisibleAttr(NULL)
00779 {
00780 }
00781 
00782 
00783 /********************************************************************************************
00784 
00785 >   VisibleTemplateHandler::VisibleTemplateHandler(const VisibleTemplateHandler& Other)
00786     VisibleTemplateHandler& VisibleTemplateHandler::operator=(const VisibleTemplateHandler& Other)
00787 
00788     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00789     Created:    09/06/97
00790     
00791     Purpose:    Warns that I haven't done either of these (but I did do a destructor)
00792 
00793 ********************************************************************************************/
00794 VisibleTemplateHandler::VisibleTemplateHandler(const VisibleTemplateHandler& Other) : 
00795     m_Handler(Other.m_Handler), 
00796     m_pWorkingVisibleAttr(NULL)
00797 {
00798     TRACE( _T("VisibleTemplateHandler copy constructor not implemented\n"));
00799 }
00800 
00801 VisibleTemplateHandler& VisibleTemplateHandler::operator=(const VisibleTemplateHandler& Other)
00802 {
00803     TRACE( _T("VisibleTemplateHandler assignment operator not implemented\n"));
00804     return *this;
00805 }
00806 
00807 
00808 /********************************************************************************************
00809 
00810 >   VisibleTemplateHandler::~VisibleTemplateHandler()
00811 
00812     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00813     Created:    09/06/97
00814     
00815     Purpose:    Destructor gets rid of any working visible attribute
00816 
00817 ********************************************************************************************/
00818 VisibleTemplateHandler::~VisibleTemplateHandler()
00819 {
00820     delete m_pWorkingVisibleAttr;
00821     m_pWorkingVisibleAttr = NULL;
00822 }
00823 
00824 
00825 /********************************************************************************************
00826 
00827 >   StringBase& VisibleTemplateHandler::GetText(StringBase& Description) const
00828 
00829     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00830     Created:    09/06/97
00831     
00832     Purpose:    Creates some text suitable for putting in the "Available Properties" list.
00833 
00834     Outputs:    (Change this) Description:  The description of this VisibleTemplateHandler
00835                 that will appear to the user.
00836 
00837     Returns:    A reference to the Text
00838 
00839 ********************************************************************************************/
00840 StringBase& VisibleTemplateHandler::GetText(StringBase& Description) const
00841 {
00842     return Description = m_Handler.GetUserName();
00843 }
00844 
00845 
00846 
00847 /********************************************************************************************
00848 
00849 >   BOOL VisibleTemplateHandler::Display(DialogOp& Dialog)
00850 
00851     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00852     Created:    09/06/97
00853     
00854     Purpose:    Displays the UI associated with this VisibleTemplateHandler.
00855 
00856     Returns:    Hmmm,,,,
00857 
00858 ********************************************************************************************/
00859 BOOL VisibleTemplateHandler::Display(DialogOp& Dialog)
00860 {
00861     ERROR2IF(m_pWorkingVisibleAttr != NULL, FALSE, "VisibleTemplateHandler member should be NULL");
00862 
00863     BOOL Ok = TRUE;
00864 
00865     m_pWorkingVisibleAttr = new VisibleTemplateAttribute(m_Handler);
00866     Ok = (m_pWorkingVisibleAttr != NULL);
00867 
00868     if (Ok)
00869     {
00870         Ok = m_pWorkingVisibleAttr->Display(Dialog);
00871     }
00872 
00873     return Ok;
00874 }
00875 
00876 
00877 /********************************************************************************************
00878 
00879 >   BOOL VisibleTemplateHandler::Interact(DialogOp& Dialog)
00880 
00881     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00882     Created:    09/06/97
00883     
00884     Purpose:    Displays the UI associated with this VisibleTemplateHandler.
00885                 It creates a new VisibleTemplateAttribute which is binned if the user selects
00886                 another "Available Property" without Adding it (via hide), otherwise it's 
00887                 supplied via CreateUsedProperty() to the Applied Properties list
00888 
00889     Returns:    Hmmm,,,,
00890 
00891 ********************************************************************************************/
00892 BOOL VisibleTemplateHandler::Interact(DialogOp& Dialog)
00893 {
00894     BOOL Ok = TRUE;
00895 
00896     if (m_pWorkingVisibleAttr != NULL)
00897     {
00898         Ok = m_pWorkingVisibleAttr->Interact(Dialog);
00899     }
00900 
00901     return Ok;
00902 }
00903 
00904 
00905 /********************************************************************************************
00906 
00907 >   void VisibleTemplateHandler::Hide()
00908 
00909     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00910     Created:    09/06/97
00911     
00912     Purpose:    Hides whatever was displayed by Display()
00913 
00914     Returns:    Hmmm,,,,
00915 
00916 ********************************************************************************************/
00917 void VisibleTemplateHandler::Hide()
00918 {
00919     if (m_pWorkingVisibleAttr != NULL)
00920     {
00921         m_pWorkingVisibleAttr->Hide();
00922         delete m_pWorkingVisibleAttr;
00923         m_pWorkingVisibleAttr = NULL;
00924     }
00925 }
00926 
00927 const StringBase& VisibleTemplateHandler::GetWorkingQuestion()
00928 {
00929     STRING_ENSURE_NOT_NULL(m_pWorkingVisibleAttr)
00930 
00931     return m_pWorkingVisibleAttr->GetValue();
00932 }
00933 
00934 
00935 const StringBase& VisibleTemplateHandler::GetWorkingParam()
00936 {
00937     STRING_ENSURE_NOT_NULL(m_pWorkingVisibleAttr)
00938 
00939     return m_pWorkingVisibleAttr->GetLongKey();
00940 }
00941 
00942 
00943 
00944 /********************************************************************************************
00945 
00946 >   AppliedAttribute* VisibleTemplateHandler::CreateUsedProperty()
00947 
00948     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00949     Created:    09/06/97
00950     
00951     Purpose:    Creates an item suitable for adding to the "Used Properties" list.
00952 
00953     Returns:    A new AppliedAttribute or derived class which is what Used Properties are.
00954                 (Although this new one's not applied yet)
00955 
00956 ********************************************************************************************/
00957 AppliedAttribute* VisibleTemplateHandler::CreateUsedProperty()
00958 {
00959     AppliedAttribute* pNewAppliedAttr = NULL;
00960 
00961     if (m_pWorkingVisibleAttr != NULL)
00962     {
00963         m_pWorkingVisibleAttr->Hide();
00964         m_pWorkingVisibleAttr->MarkAsUsed();
00965 
00966         pNewAppliedAttr = new SingletonAppliedAttribute(*m_pWorkingVisibleAttr);
00967 
00968         if (pNewAppliedAttr != NULL)
00969         {
00970             // make sure Hide() doesn't throw the not-so-working VisibleAttribute away
00971             m_pWorkingVisibleAttr = NULL;
00972         }
00973     }
00974 
00975     return pNewAppliedAttr;
00976 }
00977 
00978 
00979 
00980 Style* VisibleTemplateHandler::MakeStyle(const StringBase& StyleName)
00981 {
00982     ERROR2IF(GetWorkingQuestion().IsEmpty(), NULL, "Empty Question");
00983 
00984     return new WizOpStyle(StyleName, GetWorkingQuestion(), GetWizOp(), GetWorkingParam());
00985 }
00986 
00987 
00988 
00989 
00990 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00991 //                      C  U  S  T  O  M  P  R  O  P  E  R  T  Y
00992 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00993 
00994 
00995 
00996 
00997 
00998 BOOL CustomProperty::Display(DialogOp& Dialog)
00999 {
01000     ERROR2IF(m_pWorkingVisibleAttr != NULL, FALSE, "CustomProperty member should be NULL");
01001 
01002     BOOL Ok = TRUE;
01003 
01004     m_pWorkingVisibleAttr = new VisibleUserAttribute(NullString, NullString);
01005     Ok = (m_pWorkingVisibleAttr != NULL);
01006 
01007     if (Ok)
01008     {
01009         Ok = m_pWorkingVisibleAttr->Display(Dialog);
01010     }
01011 
01012     return Ok;
01013 }
01014 
01015 BOOL CustomProperty::Interact(DialogOp& Dialog)
01016 {
01017     BOOL Ok = TRUE;
01018 
01019     if (m_pWorkingVisibleAttr != NULL)
01020     {
01021         Ok = m_pWorkingVisibleAttr->Interact(Dialog);
01022     }
01023 
01024     return Ok;
01025 }
01026 
01027 
01028 void CustomProperty::Hide()
01029 {
01030     if (m_pWorkingVisibleAttr != NULL)
01031     {
01032         m_pWorkingVisibleAttr->Hide();
01033         delete m_pWorkingVisibleAttr;
01034         m_pWorkingVisibleAttr = NULL;
01035     }
01036 }
01037 
01038 
01039 AppliedAttribute* CustomProperty::CreateUsedProperty()
01040 {
01041     AppliedAttribute* pNewAppliedAttr = NULL;
01042 
01043     if (m_pWorkingVisibleAttr != NULL)
01044     {
01045         m_pWorkingVisibleAttr->Hide();
01046         m_pWorkingVisibleAttr->MarkAsUsed();
01047 
01048         pNewAppliedAttr = new SingletonAppliedAttribute(*m_pWorkingVisibleAttr);
01049 
01050         if (pNewAppliedAttr != NULL)
01051         {
01052             // make sure Hide() doesn't throw the not-so-working VisibleAttribute away
01053             m_pWorkingVisibleAttr = NULL;
01054         }
01055     }
01056 
01057     return pNewAppliedAttr;
01058 }
01059 
01060 
01061 
01062 
01063 
01064 
01065 
01066 
01067 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01068 //              V  I  S  I  B  L  E  W  I  Z  O  P  S  T  Y  L  E 
01069 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01070 
01071 
01072 
01073 
01074 
01075 
01076 
01077 VisibleWizOpStyle::VisibleWizOpStyle(const WizOpStyle& Style) :
01078     m_Style(Style)
01079 {
01080     m_ParamHint = Style.GetWizOp().GetParamHint();
01081     m_Param     = Style.GetParam();
01082     m_Question  = Style.GetQuestion();
01083 }
01084 
01085 
01086 BOOL VisibleWizOpStyle::Display(DialogOp& Dialog)
01087 {
01088     BOOL Ok = TRUE;
01089 
01090     Ok = m_Param.Display(Dialog);
01091 
01092     if (Ok)
01093     {
01094         Ok = m_Question.Display(Dialog);
01095     }
01096 
01097     if (Ok)
01098     {
01099         Ok = m_ParamHint.Display(Dialog);
01100     }
01101 
01102     return Ok;
01103 }
01104 
01105 BOOL VisibleWizOpStyle::Interact(DialogOp& Dialog)
01106 {
01107     ERROR3IF(!((&Dialog)->IS_KIND_OF(TemplateDialog)), "Dialog isn't kind of TemplateDialog");
01108 
01109     TemplateDialog& BetterBeThisDialog = (TemplateDialog&)Dialog;
01110 
01111     BOOL Ok = TRUE;
01112 
01113     Ok = m_Param.Display(BetterBeThisDialog.GetKeyControl());
01114     if (Ok)
01115     {
01116         Ok = m_Question.Display(BetterBeThisDialog.GetValueControl());
01117     }
01118     if (Ok)
01119     {
01120         Ok = m_ParamHint.Display(Dialog);
01121     }
01122 
01123     return Ok;
01124 }
01125 
01126 
01127 void VisibleWizOpStyle::Hide()
01128 {
01129     m_Param.Hide();
01130     m_Question.Hide();
01131     m_ParamHint.Hide();
01132 }
01133 
01134 AppliedAttribute* VisibleWizOpStyle::CreateUsedProperty()
01135 {
01136     StyleReferenceAttribute NewReference(m_Style);
01137 
01138     AppliedAttribute* pNewVisibleAttr = new SingletonAppliedAttribute(NewReference);
01139 
01140     return pNewVisibleAttr;
01141 }
01142 
01143 
01144 
01145 
01146 
01147 
01148 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01149 //          A  V  A  I  L  A  B  L  E  P  R  O  P  E  R  T  I  E  S  L  I  S  T
01150 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01151 
01152 
01153 
01154 
01155 /********************************************************************************************
01156 
01157 >   BOOL AvailablePropertiesList::AddFromTemplateHandler(const WizOp& Handler)
01158 
01159     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01160     Created:    09/06/97
01161     
01162     Purpose:    Adds a template handler to the list (which is shown in the dialog as
01163                 "Available Properties"
01164 
01165 ********************************************************************************************/
01166 BOOL AvailablePropertiesList::AddFromTemplateHandler(const WizOp& Handler)
01167 {
01168     BOOL Success = TRUE;
01169 
01170     VisibleTemplateHandler* pNewEntry = new VisibleTemplateHandler(Handler);
01171     Success = (pNewEntry != NULL);
01172 
01173     if (Success)
01174     {
01175         Success = InsertEntry(*pNewEntry);
01176     }
01177 
01178     if (!Success)
01179     {
01180         delete pNewEntry;
01181         pNewEntry = NULL;
01182     }
01183 
01184     return Success;
01185 }
01186 
01187 
01188 /********************************************************************************************
01189 
01190 >   BOOL AvailablePropertiesList::AddTemplateHandlers(const WizOps& Handlers)
01191 
01192     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01193     Created:    09/06/97
01194     
01195     Purpose:    Adds a template handler to the list (which is shown in the dialog as
01196                 "Available Properties"
01197 
01198 ********************************************************************************************/
01199 BOOL AvailablePropertiesList::AddTemplateHandlers(const WizOps& Handlers)
01200 {
01201     BOOL Success = TRUE;
01202 
01203     WizOp* pHandler = Handlers.GetFirstWizOp();
01204     while (pHandler != NULL && Success)
01205     {
01206         Success = AddFromTemplateHandler(*pHandler);
01207 
01208         pHandler = Handlers.GetNextWizOp(pHandler);
01209     }
01210 
01211     return Success;
01212 }
01213 
01214 
01215 /********************************************************************************************
01216 
01217 >   BOOL AvailablePropertiesList::AddStyle(const WizOpStyle& NewStyle)
01218 
01219     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01220     Created:    09/06/97
01221     
01222     Purpose:    Adds a WizOpStyle to this list (which is shown in the dialog as
01223                 "Available Properties"
01224 
01225 ********************************************************************************************/
01226 BOOL AvailablePropertiesList::AddStyle(const WizOpStyle& NewStyle)
01227 {
01228     BOOL Ok = TRUE;
01229 
01230     VisibleWizOpStyle* pNewEntry = new VisibleWizOpStyle(NewStyle);
01231     Ok = (pNewEntry != NULL);
01232 
01233     if (Ok)
01234     {
01235         Ok = InsertEntry(*pNewEntry);
01236     }
01237 
01238     if (!Ok)
01239     {
01240         delete pNewEntry;
01241         pNewEntry = NULL;
01242     }
01243 
01244     return Ok;
01245 }
01246 
01247 
01248 /********************************************************************************************
01249 
01250 >   BOOL AvailablePropertiesList::AddStyles(const WizOpStyles& Styles)
01251 
01252     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01253     Created:    09/06/97
01254     
01255     Purpose:    Adds the given WizOpStyles to this list.
01256                 Hence, we can build our list of "Available Properties" to include the 
01257                 WizOpStyle's in the selected document.
01258 
01259 ********************************************************************************************/
01260 BOOL AvailablePropertiesList::AddStyles(const WizOpStyles& Styles)
01261 {
01262     BOOL Ok = TRUE;
01263 
01264     StyleIterator Iterator = Styles.Begin();
01265     while (Iterator != Styles.End() && Ok)
01266     {
01267         Ok = AddStyle((WizOpStyle&)*Iterator);
01268 
01269         ++Iterator;
01270     }
01271 
01272     return Ok;
01273 }
01274 
01275 
01276 
01277 
01278 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01279 //                      U  S  E  D  P  R  O  P  E  R  T  I  E  S  L  I  S  T
01280 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01281 
01282 
01283 
01284 
01285 /********************************************************************************************
01286 
01287 >   UsedPropertiesList::~UsedPropertiesList()
01288 
01289     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01290     Created:    09/06/97
01291     
01292     Purpose:    Makes sure the embedded objects are deleted.
01293 
01294 ********************************************************************************************/
01295 UsedPropertiesList::~UsedPropertiesList()
01296 {
01297     delete [] m_pOriginalEntries;
01298     m_pOriginalEntries = NULL;
01299 
01300     delete [] m_pRemovedEntries;
01301     m_pRemovedEntries = NULL;
01302 }
01303 
01304 
01305 /********************************************************************************************
01306 
01307 >   virtual BOOL UsedPropertiesList::InsertEntry(VisibleListItem& EntryToInsert)
01308 
01309     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01310     Created:    09/06/97
01311     
01312     Purpose:    Overrides the base class function to make sure the entries are unique.
01313 
01314     Notes:      See base class for interface details.
01315 
01316 ********************************************************************************************/
01317 BOOL UsedPropertiesList::InsertEntry(VisibleListItem& EntryToInsert)
01318 {
01319     ENSURE_KIND((&EntryToInsert), AppliedAttribute);
01320 
01321     BOOL Ok = TRUE;
01322 
01323     AppliedAttribute& AppliedAttributeToInsert = (AppliedAttribute&)EntryToInsert;
01324 
01325     // We don't want the user to think they can apply WizOps of the same class so
01326     // go through the VisibleList looking for one with a duplicate AttributeIdentifier
01327     VisibleListIterator Iterator = Begin();
01328     while (Iterator != End() && Ok)
01329     {
01330         AppliedAttribute& UsedProperty = (AppliedAttribute&)*Iterator;
01331         if (UsedProperty.GetAttrID() == AppliedAttributeToInsert.GetAttrID())
01332         {
01333             Ok = FALSE;
01334         }
01335         else
01336         {
01337             ++Iterator;
01338         }
01339     }
01340 
01341     if (Ok)
01342     {
01343         Ok = VisibleListWithEditableEntries::InsertEntry(EntryToInsert);
01344     }
01345 
01346     return Ok;
01347 }
01348 
01349 
01350 /********************************************************************************************
01351 
01352 >   BOOL UsedPropertiesList::DeleteEntryAtIndex(UINT32 Index)
01353 
01354     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01355     Created:    09/06/97
01356     
01357     Purpose:    Overrides the base class function to allow this UsePropertiesList to note 
01358                 which items have been deleted.
01359 
01360     Notes:      See base class for interface details.
01361                 This is a bit yuck (no class for original entries, etc.)
01362 
01363 ********************************************************************************************/
01364 BOOL UsedPropertiesList::DeleteEntryAtIndex(UINT32 Index)
01365 {
01366     BOOL Ok = TRUE;
01367 
01368     AppliedAttribute& Entry = (AppliedAttribute&)GetEntryAt(Index);
01369 
01370     UINT32 ArrayIndex = 0;
01371     BOOL Found = FALSE;
01372     while (ArrayIndex < m_ArraysSize && !Found)
01373     {
01374         if (m_pOriginalEntries[ArrayIndex] == &Entry)
01375         {
01376             Found = TRUE;
01377         }
01378         else
01379         {
01380             ++ArrayIndex;
01381         }
01382     }
01383 
01384     if (Found)
01385     {
01386         m_pOriginalEntries[ArrayIndex] = NULL;
01387     }
01388 
01389     // Find the last entry in the removed array
01390     ArrayIndex = 0;
01391     Found = FALSE;
01392     while (ArrayIndex < m_ArraysSize && !Found)
01393     {
01394         if (m_pRemovedEntries[ArrayIndex].IsEmpty())
01395         {
01396             Found = TRUE;
01397         }
01398         else
01399         {
01400             ++ArrayIndex;
01401         }
01402     }
01403 
01404     if (Found)
01405     {
01406         AttributeIdentifier AttrID = Entry.GetAttrID();
01407 
01408         m_pRemovedEntries[ArrayIndex] = AttrID;
01409     }
01410 
01411 
01412     Ok = VisibleListWithEditableEntries::DeleteEntryAtIndex(Index);
01413 
01414     return Ok;
01415 }
01416 
01417 
01418 /********************************************************************************************
01419 
01420 >   BOOL UsedPropertiesList::DeleteAllEntries()
01421 
01422     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01423     Created:    09/06/97
01424     
01425     Purpose:    Overrides the base class function to allow this UsePropertiesList to note 
01426                 which items have been deleted.
01427 
01428     Notes:      See base class for interface details.
01429                 This is a bit yuck (no class for original entries, etc.)
01430 
01431 ********************************************************************************************/
01432 BOOL UsedPropertiesList::DeleteAllEntries()
01433 {
01434     BOOL Ok = TRUE;
01435 
01436     // Find the last entry in the removed array
01437     UINT32 RemovedEntriesIndex = 0;
01438     BOOL Found = FALSE;
01439 
01440     while (RemovedEntriesIndex < m_ArraysSize && !Found)
01441     {
01442         if (m_pRemovedEntries[RemovedEntriesIndex].IsEmpty())
01443         {
01444             Found = TRUE;
01445         }
01446         else
01447         {
01448             ++RemovedEntriesIndex;
01449         }
01450     }
01451 
01452     if (Found)
01453     {
01454         // Look through the original entries array to find any that haven't been removed
01455         UINT32 OriginalEntriesIndex = 0;
01456         while (OriginalEntriesIndex < m_ArraysSize)
01457         {
01458             if (m_pOriginalEntries[OriginalEntriesIndex] != NULL)
01459             {
01460                 AttributeIdentifier AttrID = m_pOriginalEntries[OriginalEntriesIndex]->GetAttrID();
01461                 
01462                 m_pRemovedEntries[RemovedEntriesIndex] = AttrID;
01463                 m_pOriginalEntries[OriginalEntriesIndex] = NULL;
01464 
01465                 ++RemovedEntriesIndex;
01466             }
01467             ++OriginalEntriesIndex;
01468         }
01469     }
01470 
01471 
01472     Ok = VisibleListWithEditableEntries::DeleteAllEntries();
01473 
01474     return Ok;
01475 }
01476 
01477 
01478 /********************************************************************************************
01479 
01480 >   virtual void UsedPropertiesList::HideLastSelectedEntry()
01481 
01482     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01483     Created:    09/06/97
01484     
01485     Purpose:    Overrides the base class so the UsedPropertiesList can make sure the entry
01486                 hasn't changed into another duplicate entry.
01487 
01488 ********************************************************************************************/
01489 /*
01490 void UsedPropertiesList::HideLastSelectedEntry()
01491 {
01492     VisibleListItem* const pEntryShowing = GetLastSelectedEntry();
01493 
01494     if (pEntryShowing != NULL)
01495     {
01496         if (IsDuplicate(*pEntryShowing))
01497         {
01498             WarnUser(_R(IDS_ERROR_DUPLICATE_PARAM));
01499 
01500             RetractEntryChanges(*pEntryShowing);
01501         }
01502         //  If the current entry has changed
01503     }
01504 
01505     VisibleListWithEditableEntries::HideLastSelectedEntry();
01506 }
01507 */
01508 
01509 /********************************************************************************************
01510 
01511 >   virtual BOOL UsedPropertiesList::IsDuplicate(const VisibleListItem& Entry) const
01512 
01513     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01514     Created:    09/06/97
01515     
01516     Purpose:    Adds an available property to this list (which is shown in the dialog as
01517                 "Used Properties"
01518 
01519 ********************************************************************************************/
01520 /*
01521 BOOL UsedPropertiesList::IsDuplicate(const VisibleListItem& Entry) const
01522 {
01523     BOOL IsDuplicate = FALSE;
01524 
01525     return IsDuplicate;
01526 }
01527 */
01528 
01529 /********************************************************************************************
01530 
01531 >   virtual void UsedPropertiesList::WarnUser(StringID WarningResourceID) const
01532 
01533     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01534     Created:    09/06/97
01535     
01536     Purpose:    Tells the user that what they've done is a no-no.
01537 
01538     Inputs:     WarningResourceID   The resource id of the warning string that will appear
01539                                     in the message to the user.
01540 
01541 ********************************************************************************************/
01542 /*
01543 void UsedPropertiesList::WarnUser(StringID WarningResourceID) const
01544 {
01545     Error::InformWarning(WarningResourceID);
01546 }
01547 */
01548 
01549 /********************************************************************************************
01550 
01551 >   virtual void UsedPropertiesList::RetractEntryChanges(VisibleListItem& Entry)
01552 
01553     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01554     Created:    09/06/97
01555     
01556     Purpose:    When a user has changed a Used Property to something they shouldn't have
01557                 this member is called to undo the changes.
01558 
01559 
01560 ********************************************************************************************/
01561 /*
01562 void UsedPropertiesList::RetractEntryChanges(VisibleListItem& Entry)
01563 {
01564     
01565 }
01566 */
01567 
01568 
01569 /********************************************************************************************
01570 
01571 >   BOOL UsedPropertiesList::AddAvailableProperty(AvailableProperty& NewProperty)
01572 
01573     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01574     Created:    09/06/97
01575     
01576     Purpose:    Adds an available property to this list (which is shown in the dialog as
01577                 "Used Properties"
01578 
01579 ********************************************************************************************/
01580 BOOL UsedPropertiesList::AddAvailableProperty(AvailableProperty& NewProperty)
01581 {
01582     BOOL Success = TRUE;
01583 
01584     // Create a new AppliedAttribute
01585     AppliedAttribute* pNewListEntry = NewProperty.CreateUsedProperty();
01586     Success = (pNewListEntry != NULL);
01587 
01588     if (Success)
01589     {
01590         Success = InsertEntry(*pNewListEntry);
01591     }
01592 
01593     if (!Success)
01594     {
01595         if (pNewListEntry != NULL)
01596         {
01597             delete pNewListEntry;
01598             pNewListEntry = NULL;
01599         }
01600     }
01601 
01602     return Success;
01603 }
01604 
01605 
01606 /********************************************************************************************
01607 
01608 >   BOOL UsedPropertiesList::BuildFromEnumerator(RenderableNodeEnumerator& Enumerator)
01609 
01610     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01611     Created:    09/06/97
01612 
01613     Purpose:    Builds this UsedPropertiesList by finding the attributes applied to the
01614                 objects found in the given iterator (the selection or a node).
01615 
01616     Inputs:     Enumerator: This should return the collection of nodes for which this list
01617                             represents the applied attributes.
01618 
01619 ********************************************************************************************/
01620 BOOL UsedPropertiesList::BuildFromEnumerator(RenderableNodeEnumerator& Enumerator)
01621 {
01622     BOOL Ok = TRUE;
01623 
01624     // Build a set of applied attributes, deleting any old list before we do
01625 
01626     CommonAttrMultiSet* pAttrSet = FindCommonUserAttributes(Enumerator);
01627     Ok = (pAttrSet != NULL);
01628 
01629     // For each applied attribute create a visible version and add it to this list in reverse
01630     // order so they come out in the same order in which they're applied. (Each is added as 
01631     // the first entry)
01632     MultiCommonAttrItem* pCommonItem = NULL;
01633     if (Ok)
01634     {
01635         pCommonItem = pAttrSet->FindFirst();
01636     }
01637 
01638     while (pCommonItem != NULL && Ok)
01639     {
01640         AppliedAttribute* const pNewVisibleAppliedAttr = pCommonItem->CreateVisibleAppliedAttribute();
01641         Ok = (pNewVisibleAppliedAttr != NULL);
01642         if (Ok)
01643         {
01644             Ok = InsertEntry(*pNewVisibleAppliedAttr);
01645         }
01646 
01647         pCommonItem = pAttrSet->FindNext(pCommonItem);
01648     }
01649 
01650     delete pAttrSet;
01651 
01652     if (Ok)
01653     {
01654         Ok = NoteNewEntries();
01655     }
01656 
01657     return Ok;
01658 }
01659 
01660 
01661 /********************************************************************************************
01662 
01663 >   BOOL UsedPropertiesList::NoteNewEntries()
01664 
01665     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01666     Created:    09/06/97
01667 
01668     Purpose:    Support function which takes all the entries in this list and marks them
01669                 as original entries. When it comes to commiting the entries, i.e., 
01670                 applying them it then knows which ones to delete from the selection.
01671 
01672     Returns:    TRUE if it worked, FALSE if it didn't
01673 
01674 ********************************************************************************************/
01675 BOOL UsedPropertiesList::NoteNewEntries()
01676 {
01677     BOOL Ok = TRUE;
01678 
01679     delete [] m_pOriginalEntries;
01680     m_pOriginalEntries = NULL;
01681 
01682     delete [] m_pRemovedEntries;
01683     m_pRemovedEntries = NULL;
01684 
01685     m_ArraysSize = GetContainer().GetCount();
01686 
01687     if (m_ArraysSize != 0)
01688     {
01689         m_pOriginalEntries  = new const AppliedAttribute*[m_ArraysSize];
01690         m_pRemovedEntries   = new String_128[m_ArraysSize];
01691     }
01692 
01693     Ok = (m_pOriginalEntries != NULL && m_pRemovedEntries != NULL);
01694 
01695     if (Ok)
01696     {
01697         UINT32 Index = 0;
01698         VisibleListIterator Iterator = Begin();
01699         while (Iterator != End())
01700         {
01701             AppliedAttribute& ListEntry = (AppliedAttribute&)*Iterator;
01702 
01703             m_pOriginalEntries[Index]   = &ListEntry;
01704             m_pRemovedEntries[Index]    = NullString;
01705 
01706             ++Iterator;
01707             ++Index;
01708         }
01709     }
01710 
01711     return Ok;
01712 }
01713 
01714 
01715 /********************************************************************************************
01716 
01717 >   CommonAttrMultiSet* UsedPropertiesList::FindCommonUserAttributes(
01718                                                 RenderableNodeEnumerator& Enumerator)
01719 
01720     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01721     Created:    09/06/97
01722     
01723     Purpose:    Support function to create a CommonAttrMultiSet using the given Enumerator.
01724 
01725 ********************************************************************************************/
01726 CommonAttrMultiSet* UsedPropertiesList::FindCommonUserAttributes(RenderableNodeEnumerator& Enumerator)
01727 {
01728     CommonAttrMultiSet* pCommonAttrs = new CommonAttrMultiSet();    // return this
01729 
01730     if (pCommonAttrs != NULL)
01731     {
01732         UserAttributeAgglomerator AttrAgglr;
01733         AttrAgglr.FindCommonAttributes(Enumerator, pCommonAttrs);
01734     }
01735 
01736     return pCommonAttrs;
01737 }
01738 
01739 
01740 /********************************************************************************************
01741 
01742 >   BOOL UsedPropertiesList::Commit(Operation& OpToApplyWith)
01743 
01744     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01745     Created:    09/06/97
01746     
01747     Purpose:    Applies all the attributes in this UsedPropertiesList list to the
01748                 node.
01749 
01750 ********************************************************************************************/
01751 BOOL UsedPropertiesList::Commit(Operation& OpToApplyWith)
01752 {
01753     BOOL Ok = TRUE;
01754 
01755     // Remove any attributes that were removed
01756     if (GetRemovedEntries() != NULL)
01757     {
01758         Ok = DeleteAttributes(GetRemovedEntries());
01759     }
01760 
01761     // and apply the new attributes in reverse order, because the OpApply...sticks them in 
01762     // nearest the Node
01763     VisibleListIterator Iterator = BeginOfEnd();
01764     while (Iterator != End() && Ok)
01765     {
01766         AppliedAttribute& Entry = (AppliedAttribute&)(*Iterator);
01767         Ok = Entry.ApplyAttribute(OpToApplyWith);
01768         --Iterator;
01769     }
01770 
01771     return Ok;
01772 }
01773 
01774 
01775 
01776 /********************************************************************************************
01777 
01778 >   BOOL UsedPropertiesList::DeleteAttributes(const StringBase* AttrIDs[])
01779 
01780     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01781     Created:    09/06/97
01782     
01783     Purpose:    Support function to delete the given AttributeIdentifiers from the objects
01784                 in the selection.
01785 
01786     Notes:      This isn't quite true 'cos it looks at the data members for size info
01787                 (The array should be a class). We won't talk about the StringBase being
01788                 an AttributeIdentifier.
01789 
01790 ********************************************************************************************/
01791 BOOL UsedPropertiesList::DeleteAttributes(String_128 AttrIDs[])
01792 {
01793     BOOL Ok = TRUE;
01794 
01795     // Obtain a pointer to the op descriptor for the attribute operation 
01796     OpDescriptor* const pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpRemoveAttributeFromSelection));
01797     ENSURE_NOT_NULL(pOpDesc);
01798 
01799     UINT32 Index = 0;
01800     while (Index < m_ArraysSize && !AttrIDs[Index].IsEmpty() && Ok)
01801     {
01802         AttributeIdentifier AttrID = (AttributeIdentifier)AttrIDs[Index];
01803         // Invoke the operation, passing AttrID as a parameter
01804         pOpDesc->Invoke(&(OpParam&)RemoveAttributeParam(AttrID), TRUE); // do want undo
01805 
01806         // we've deleted that one so mark it as gone
01807         AttrIDs[Index] = NullString;
01808 
01809         ++Index;
01810     }
01811 
01812     return Ok;
01813 }
01814 
01815 
01816 
01817 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01818 //                      T  E  M  P  L  A  T  E  D  I  A  L  O  G
01819 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
01820 
01821 
01822 
01823 
01824 
01825 
01826 // All Temmplate Dialogs are created equal
01827 const CDlgMode TemplateDialog::s_Mode   = MODELESS;
01828 const CDlgResID TemplateDialog::s_IDD   = _R(IDD_TEMPLATE_DIALOG);
01829 
01830 // Preference Strings
01831 String_32 TemplateDialog::s_PreferenceSection       = TEXT("Wizard Properties");
01832 const UINT32 TemplateDialog::s_NumberOfPreferences  = 1;    // ...in the section
01833 
01834 /********************************************************************************************
01835 
01836     Preference:     Show Custom
01837     Section:        Wizard Properties
01838     Range:          TRUE or FALSE
01839     Purpose:        If TRUE, the Wizard Properties dialog will show an Available Property
01840                     "Custom" through which the user can add 
01841 
01842 ********************************************************************************************/
01843 String_16 TemplateDialog::s_ShowCustom          = TEXT("Show Custom");
01844 BOOL TemplateDialog::s_ShowCustomProperty       = FALSE;
01845 
01846 
01847 /*******************************************************************************************
01848 
01849 >   static BOOL TemplateDialog::Init()
01850 
01851     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01852     Created:    09/06/97
01853 
01854     Purpose:    Creates an OpDescriptor for a TemplateDialog so you can make a template
01855                 dialog pop up using pOpDescriptor->Invoke(). Call this before even thinking
01856                 of invoking it 'cos otherwise it won't work. Somewhere in main3.cpp would be
01857                 nice.
01858 
01859     Returns:    FALSE if it fails
01860 
01861 *******************************************************************************************/
01862 BOOL TemplateDialog::Init()
01863 {
01864     BOOL Ok = TRUE;
01865 
01866     Ok = OpRemoveAttributeFromSelection::Declare();
01867 
01868 
01869     Ok |= RegisterOpDescriptor(
01870                 0,                                  // Tool ID
01871                 _R(IDS_TEMPLATE_DIALOG),                // String resouirce ID
01872                 CC_RUNTIME_CLASS(TemplateDialog),   // Runtime class
01873                 OPTOKEN_TEMPLATEDLG,                // Token string
01874                 TemplateDialog::GetState,           // GetState function
01875                 0, // is now helpless _R(IDH_Command_Wizard_Properties),        // Help ID
01876                 _R(IDBBL_TEMPLATE_DIALOG),              // Bubble ID
01877                 _R(IDD_BARCONTROLSTORE),                // Resource ID
01878                 _R(IDC_TMPLTDLG),                       // Control ID
01879                 SYSTEMBAR_UTILITIES,                // Bar ID
01880                 TRUE,                               // Recieve system messages (and button msgs)
01881                 FALSE,                              // Smart duplicate operation
01882                 TRUE,                               // Clean operation
01883                 NULL,                               // No vertical counterpart
01884                 NULL,                               // String to say only one instance allowed
01885                 (   DONT_GREY_WHEN_SELECT_INSIDE | 
01886                     GREY_WHEN_NO_CURRENT_DOC)
01887             );  
01888     
01889     Ok |= NameDialog::Init();
01890 
01891     Ok |= Camelot.DeclareSection(s_PreferenceSection, s_NumberOfPreferences);
01892     Ok |= Camelot.DeclarePref(s_PreferenceSection, s_ShowCustom, &s_ShowCustomProperty );
01893 
01894     return Ok;                  
01895 }   
01896  
01897       
01898 static TemplateDialog* g_TheOneTemplateDialogInTheEntireUniverse = NULL;
01899 
01900 /*******************************************************************************************
01901 
01902 >   static OpState  TemplateDialog::GetState(String_256*, OpDescriptor*)
01903 
01904     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01905     Created:    09/06/97
01906 
01907     Purpose:    Silliness with statics (derived classes anyone?)
01908 
01909 *******************************************************************************************/
01910 OpState TemplateDialog::GetState(String_256*, OpDescriptor*)
01911 {
01912     OpState OpSt;
01913 
01914     if (g_TheOneTemplateDialogInTheEntireUniverse != NULL)
01915     {
01916         OpSt.Ticked = TRUE;
01917     }
01918 
01919     return OpSt;
01920 }
01921 
01922          
01923 /*******************************************************************************************
01924 
01925 >   static BOOL TemplateDialog::ShowCustomProperty()
01926 
01927     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01928     Created:    09/06/97
01929 
01930     Purpose:    Tells us if we should add a custom property to the Available Properties 
01931                 list according to preference.
01932 
01933 *******************************************************************************************/
01934 BOOL TemplateDialog::ShowCustomProperty()
01935 {
01936     return s_ShowCustomProperty;
01937 }
01938 
01939 
01940 /*******************************************************************************************
01941 
01942 >   TemplateDialog::TemplateDialog() : DialogOp(TemplateDialog::IDD, TemplateDialog::Mode) 
01943 
01944     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01945     Created:    09/06/97
01946 
01947     Purpose:    Required constructor for DialogManager, gives Modeless dialog and resource
01948                 ID.
01949 
01950 *******************************************************************************************/
01951 TemplateDialog::TemplateDialog() : DialogOp(TemplateDialog::s_IDD, TemplateDialog::s_Mode) 
01952 {
01953     m_pAvailableProperties  = NULL;
01954     m_pUsedProperties       = NULL;
01955 
01956     m_pUsedListGadget       = NULL;
01957     m_pAvailableListGadget  = NULL;
01958     m_pQuestionGadget       = NULL;
01959     m_pParamHintGadget      = NULL;
01960     m_pParamGadget          = NULL;
01961     m_pAddButton            = NULL;
01962     m_pRemoveButton         = NULL;
01963     m_pRemoveAllButton      = NULL;
01964     m_pApplyButton          = NULL;
01965     m_pMakeStyleButton      = NULL;
01966 
01967     m_UserCanModifyQuestion = FALSE;
01968 }       
01969 
01970 
01971 
01972 /*******************************************************************************************
01973 
01974 >   TemplateDialog::~TemplateDialog()
01975 
01976     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
01977     Created:    09/06/97
01978 
01979     Purpose:    Destructor deletes those member variables
01980 
01981 *******************************************************************************************/
01982 TemplateDialog::~TemplateDialog()
01983 {
01984     delete m_pAvailableProperties;
01985     m_pAvailableProperties = NULL;
01986 
01987     delete m_pUsedProperties;
01988     m_pUsedProperties = NULL;
01989 
01990 
01991     delete m_pUsedListGadget;
01992     m_pUsedListGadget       = NULL;
01993 
01994     delete m_pAvailableListGadget;
01995     m_pAvailableListGadget  = NULL;
01996 
01997     delete m_pQuestionGadget;
01998     m_pQuestionGadget       = NULL;
01999 
02000     delete m_pParamHintGadget;
02001     m_pParamHintGadget      = NULL;
02002 
02003     delete m_pParamGadget;
02004     m_pParamGadget          = NULL;
02005 
02006     delete m_pAddButton;
02007     m_pAddButton            = NULL;
02008 
02009     delete m_pRemoveButton;
02010     m_pRemoveButton         = NULL;
02011 
02012     delete m_pRemoveAllButton;
02013     m_pRemoveAllButton      = NULL;
02014 
02015     delete m_pApplyButton;
02016     m_pApplyButton          = NULL;
02017 
02018     delete m_pMakeStyleButton;
02019     m_pMakeStyleButton      = NULL;
02020 }       
02021 
02022 
02023 
02024 /********************************************************************************************
02025 
02026 >   void TemplateDialog::Do(OpDescriptor*)
02027 
02028     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02029     Created:    09/06/97
02030 
02031     Purpose:    Waste some space
02032         
02033 ********************************************************************************************/
02034 void TemplateDialog::Do(OpDescriptor*)
02035 {
02036     // We're called when the menu item / button is clicked: once to open the dialog, once
02037     // to close it. This is pseudo model isn't it and rather silly.
02038     if (g_TheOneTemplateDialogInTheEntireUniverse == NULL)
02039     {
02040         // First time so stick the dialog on the screen
02041         if (Create())
02042         {
02043             g_TheOneTemplateDialogInTheEntireUniverse = this;
02044 
02045             Open();
02046         }
02047         else
02048         {
02049             End();
02050         }
02051     }
02052     else
02053     {
02054         // Clicked button / menu to close the dialog
02055         g_TheOneTemplateDialogInTheEntireUniverse->Close();
02056         g_TheOneTemplateDialogInTheEntireUniverse->End();
02057 
02058         End();      // throw away the TemplateDialog that was created for this Do()
02059 
02060         g_TheOneTemplateDialogInTheEntireUniverse = NULL;
02061     }
02062 }
02063 
02064 
02065 /********************************************************************************************
02066 
02067 >   MsgResult TemplateDialog::Message( Msg* pMessage)
02068 
02069     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02070     Created:    09/06/97
02071 
02072     Inputs:     pMessage: The message that DialogManager may or may not send us
02073         
02074     Returns:    DialogOp::MsgResult
02075 
02076     Purpose:    Bog standard dispatch the message type switch statement.
02077      
02078 ********************************************************************************************/
02079 MsgResult TemplateDialog::Message( Msg* pMessage)
02080 {
02081     if (IS_OUR_DIALOG_MSG(pMessage))
02082     {
02083         DialogMsg* const pDialogMsg = ((DialogMsg*) pMessage); 
02084     
02085         switch (pDialogMsg->DlgMsg)
02086         {
02087             case DIM_TEXT_CHANGED:
02088                 // just respond to changes to the question
02089                 // should use Notify really
02090                 switch (pDialogMsg->GadgetID)
02091                 {
02092                     case _R(IDC_TMLPTDLG_QUESTION):
02093                         // Make sure we don't respond to the changes we make internally
02094                         OnTextChange();
02095                         break;
02096 
02097                     case _R(IDC_TMPLTDLG_PARAM):
02098                         OnParamChange();
02099                         break;
02100                 }
02101 
02102                 break;
02103 
02104             case DIM_SELECTION_CHANGED_COMMIT:  // who named this???
02105                 if (pDialogMsg->GadgetID == _R(IDC_TMLPTDLG_AVAILABLE))
02106                 {
02107                     OnAvailableListDoubleClicked();
02108                 }
02109                 break;
02110                 
02111             case DIM_LFT_BN_CLICKED:
02112                 switch(pDialogMsg->GadgetID)
02113                 {
02114                     case _R(IDC_TMPLTDLG_ADD):
02115                         OnAddButtonClicked();                   
02116                         break;
02117 
02118                     case _R(IDC_TMPLTDLG_REMOVE):
02119                         OnRemoveButtonClicked();
02120                         break;
02121 
02122                     case _R(IDC_TMPLTDLG_REMOVE_ALL):
02123                         OnRemoveAllButtonClicked();
02124                         break;
02125 
02126                     case _R(IDC_TMPLTDLG_MAKE_STYLE):
02127                         OnMakeStyleClicked();
02128                         break;
02129                 }
02130                 break;
02131 
02132             case DIM_SELECTION_CHANGED: 
02133                 // NB: This means Messrs Mouse & Keyboard have manipulated one of the list boxes.
02134                 // It doesn't mean the selection has changed!
02135                 if (pDialogMsg->GadgetID == _R(IDC_TMLPTDLG_AVAILABLE))
02136                 {
02137                     OnAvailableListHighlightChanged();
02138                 }
02139                 else if (pDialogMsg->GadgetID == _R(IDC_TMLPTDLG_USED))
02140                 {
02141                     OnUsedListHighlightChanged();
02142                 }
02143                 break;
02144 
02145             case DIM_CREATE:
02146                 OnCreate();
02147                 break;
02148 
02149             case DIM_COMMIT:
02150                 OnApplyClicked();
02151                 break;
02152 
02153             case DIM_CANCEL:    
02154                 Close();           
02155                 End();
02156                 g_TheOneTemplateDialogInTheEntireUniverse = NULL;
02157                 break;
02158         }
02159     }
02160     else if (MESSAGE_IS_A(pMessage, SelChangingMsg))
02161     {
02162         if ( ((SelChangingMsg*)pMessage)->State == SelChangingMsg::SELECTIONCHANGED )
02163             OnSelectionChange();
02164     }
02165     else if (MESSAGE_IS_A(pMessage, DocChangingMsg))
02166     {
02167         // Look out for the selected document changing
02168         DocChangingMsg::DocState State = ((DocChangingMsg*)pMessage)->State;
02169         if (State == DocChangingMsg::SELCHANGED)
02170         {
02171             SetDialogInitialState(((DocChangingMsg*)pMessage)->pNewDoc);
02172         }
02173     }
02174     else if (MESSAGE_IS_A(pMessage, StylesMessage))
02175     {
02176         // We're sent one of these when the styles are added to (not by us)
02177 
02178         // Make sure they're the styles we've got displayed that are changing
02179         if (&(((StylesMessage*)pMessage)->GetStylesChanging()) == GetStyles())
02180         {
02181             SetDialogInitialState(Document::GetSelected());
02182         }
02183     }
02184         
02185     return DialogOp::Message(pMessage);
02186 } 
02187 
02188 
02189 /********************************************************************************************
02190 
02191 >   void TemplateDialog::OnCreate()
02192 
02193     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02194     Created:    09/06/97
02195     
02196     Purpose:    Handles a message that the dialog has just been created.
02197 
02198 ********************************************************************************************/
02199 void TemplateDialog::OnCreate()
02200 {
02201     CreateGadgets();
02202 
02203     // Set up the dialog in its initial state
02204     SetDialogInitialState(Document::GetSelected());
02205 
02206     // And put the keyboard focus in the available properties list
02207     SetKeyboardFocus(_R(IDC_TMLPTDLG_AVAILABLE));
02208 }
02209 
02210 
02211 /********************************************************************************************
02212 
02213 >   void TemplateDialog::OnTextChange()
02214 
02215     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02216     Created:    09/06/97
02217     
02218     Purpose:    Responds to the user's request to add the selected template argument to the
02219                 list of used properties.
02220 
02221 ********************************************************************************************/
02222 void TemplateDialog::OnTextChange()
02223 {
02224     // if we're modifying a question, that means it's a Used Property, so
02225     // allow them to Apply the change
02226     if (UserCanModifyQuestion())
02227     {
02228         // bit bodgy this...
02229         m_pApplyButton->Enable();
02230         SetUserCanModifyQuestion(FALSE);    // well they can but who cares now?
02231     }
02232     else
02233     {
02234         // If we've got one Available Property selected we might want to
02235         // allow them to make a style of it
02236 
02237         BOOL ShouldEnableMakeStyle = FALSE;
02238 
02239         if (GetAvailableProperties().GetNumberOfSelectedEntries() == 1)
02240         {
02241             String_256 Question;
02242             VOID_ENSURE_NOT_NULL(m_pQuestionGadget);
02243             if (m_pQuestionGadget != NULL)
02244             {
02245                 m_pQuestionGadget->RetrieveText(&Question);
02246             }
02247 
02248             AvailableProperty* pSelectedEntry = (AvailableProperty*)GetAvailableProperties().GetFirstSelectedEntry();
02249             if (pSelectedEntry != NULL)
02250             {
02251                 ShouldEnableMakeStyle = pSelectedEntry->CanBecomeStyle() && !Question.IsEmpty();
02252             }
02253         }
02254 
02255         if (ShouldEnableMakeStyle)
02256         {
02257             m_pMakeStyleButton->Enable();
02258         }
02259         else
02260         {
02261             m_pMakeStyleButton->Disable();
02262         }
02263     }
02264 
02265 }
02266 
02267 
02268 /********************************************************************************************
02269 
02270 >   void TemplateDialog::OnParamChange()
02271 
02272     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02273     Created:    09/06/97
02274     
02275     Purpose:    Responds to the user's request to add the selected template argument to the
02276                 list of used properties.
02277 
02278     Notes:      The order of events should go:
02279                     m_pParamGadget->OnChange()
02280                     Notify(this)
02281                     this->OnParamChange()
02282                 but we'll bodge it a bit & go directly here 'cos DialogOp's a bit of a mess
02283                 at the moment.
02284 
02285 ********************************************************************************************/
02286 void TemplateDialog::OnParamChange()
02287 {
02288 /*
02289     if (UserCanModifyQuestion())
02290     {
02291         // bit bodgy this...
02292         m_pApplyButton->Enable();
02293         SetUserCanModifyQuestion(FALSE);    // well they can but who cares now?
02294     }
02295 */
02296 }
02297 
02298 
02299 /********************************************************************************************
02300 
02301 >   void TemplateDialog::OnAvailableDoubleClicked()
02302 
02303     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02304     Created:    09/06/97
02305     
02306     Purpose:    Responds to the user's request to add the selected template argument to the
02307                 list of used properties.
02308 
02309 ********************************************************************************************/
02310 void TemplateDialog::OnAvailableListDoubleClicked()
02311 {
02312     MakePropertyUsed();
02313 
02314     //And throw away the keyboard focus
02315     DialogManager::DefaultKeyboardFocus();
02316 }
02317 
02318 
02319 /********************************************************************************************
02320 
02321 >   void TemplateDialog::OnAddButtonClicked()
02322 
02323     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02324     Created:    09/06/97
02325     
02326     Purpose:    Responds to the user's request to add the selected template argument to the
02327                 list of used properties.
02328 
02329 ********************************************************************************************/
02330 void TemplateDialog::OnAddButtonClicked()
02331 {
02332     // For each selected item in the Available list add the appropriate attribute
02333     MakePropertyUsed();
02334 
02335     // And throw away the keyboard focus
02336     DialogManager::DefaultKeyboardFocus();
02337 }
02338 
02339 
02340 /********************************************************************************************
02341 
02342 >   void TemplateDialog::OnRemoveButtonClicked()
02343 
02344     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02345     Created:    09/06/97
02346     
02347     Purpose:    Handles the message when the user clicks on the Remove button
02348 
02349 ********************************************************************************************/
02350 void TemplateDialog::OnRemoveButtonClicked()
02351 {
02352     RemoveUsedProperty();
02353 
02354     // And throw away the keyboard focus
02355     DialogManager::DefaultKeyboardFocus();
02356 }
02357 
02358 
02359 /********************************************************************************************
02360 
02361 >   void TemplateDialog::OnRemoveAllButtonClicked()
02362 
02363     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02364     Created:    09/06/97
02365     
02366     Purpose:
02367 
02368 ********************************************************************************************/
02369 void TemplateDialog::OnRemoveAllButtonClicked()
02370 {   
02371     RemoveAllUsedProperties();
02372 
02373     // And throw away the keyboard focus
02374     DialogManager::DefaultKeyboardFocus();
02375 }
02376 
02377 
02378 /********************************************************************************************
02379 
02380 >   void TemplateDialog::OnMakeStyleClicked()
02381 
02382     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02383     Created:    09/06/97
02384     
02385     Purpose:    Responds to a request to make a style from a WizOp
02386 
02387 ********************************************************************************************/
02388 void TemplateDialog::OnMakeStyleClicked()
02389 {   
02390     // (should probably do this somewhere else - GOD this is ugly)
02391     AvailableProperty* const pSelectedProperty = (AvailableProperty*)GetAvailableProperties().GetFirstSelectedEntry();
02392     if (pSelectedProperty != NULL)
02393     {
02394         // Invoke a dialog for the name
02395         NameDialogParam StyleNameParam;
02396         if (NameDialog::Invoke(StyleNameParam))     // returns TRUE if they didn't cancel
02397         {
02398             // if so create a new style
02399             Style* pNewStyle = pSelectedProperty->MakeStyle(StyleNameParam.GetNameEntered());
02400             if (pNewStyle != NULL)
02401             {
02402                 WizOpStyle* pStyleToUse = (WizOpStyle*)AddNewStyle(*pNewStyle);
02403                 if (pStyleToUse != NULL)
02404                 {
02405                     GetAvailableProperties().AddStyle(*pStyleToUse);
02406                     pSelectedProperty->Hide();
02407                 }
02408 
02409                 // AddNewStyle creates a copy, so we can bin this
02410                 delete pNewStyle;
02411                 pNewStyle = NULL;
02412             }
02413             // disable the Make Style button 'cos we don't have a working attribute now
02414             m_pMakeStyleButton->Disable();
02415             m_pAddButton->Disable();
02416         }
02417     }
02418 
02419     // And throw away the keyboard focus
02420     DialogManager::DefaultKeyboardFocus();
02421 }
02422 
02423 
02424 
02425 
02426 /********************************************************************************************
02427 
02428 >   void TemplateDialog::OnAvailableListHighlightChanged()
02429 
02430     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes, mostly Graham's Web/Hot/URL/Link Dialog)
02431     Created:    09/06/97
02432     
02433     Purpose:    Handles the message that the Available Properties list box has had its 
02434                 highlight changed. If there wasn't a highlight before you can now press the
02435                 add button.
02436 
02437 ********************************************************************************************/
02438 void TemplateDialog::OnAvailableListHighlightChanged()
02439 {
02440     OnAvailableSelectionChange();
02441 
02442     // And throw away the keyboard focus
02443     DialogManager::DefaultKeyboardFocus();
02444 }
02445 
02446 
02447 /********************************************************************************************
02448 
02449 >   void TemplateDialog::OnUsedListHighlightChanged()
02450 
02451     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes, mostly Graham's Web/Hot/URL/Link Dialog)
02452     Created:    09/06/97
02453     
02454     Purpose:    Handles the message that the Used Properties list box has had its highlight
02455                 changed. Updates the question edit box as appropriate.
02456 
02457 ********************************************************************************************/
02458 void TemplateDialog::OnUsedListHighlightChanged()
02459 {
02460     OnUsedSelectionChange();
02461 
02462     // And throw away the keyboard focus
02463     DialogManager::DefaultKeyboardFocus();
02464 }
02465 
02466 
02467 /********************************************************************************************
02468 
02469 >   void TemplateDialog::OnApplyClicked()
02470 
02471     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02472     Created:    09/06/97
02473     
02474     Purpose:    Responds to the user's request to apply the Name and Template Property
02475                 attributes to the selection.
02476 
02477 ********************************************************************************************/
02478 void TemplateDialog::OnApplyClicked()
02479 {
02480     GetUsedProperties().RemoveSelection();  // this ensures the shown question is updated
02481 
02482     ApplyUsedAttributes();
02483     
02484     //And throw away the keyboard focus
02485     DialogManager::DefaultKeyboardFocus();
02486 }
02487 
02488 
02489 /********************************************************************************************
02490 
02491 >   void TemplateDialog::OnSelectionChange()
02492 
02493     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes, mostly Graham's Web/Hot/URL/Link Dialog)
02494     Created:    09/06/97
02495     
02496     Purpose:    Handles a message that there's been a selection change
02497 
02498 ********************************************************************************************/
02499 void TemplateDialog::OnSelectionChange()
02500 {   
02501     //Put the dialog into its initial state
02502     InitializeControls();
02503 }
02504 
02505 
02506 /********************************************************************************************
02507 
02508 >   void TemplateDialog::SetDialogInitialState(BaseDocument* const pSelectedDocument)
02509 
02510     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes, mostly Graham's Web/Hot/URL/Link Dialog)
02511     Created:    09/06/97
02512     
02513     Purpose:    Handles a message that there's been a selection change
02514 
02515 ********************************************************************************************/
02516 void TemplateDialog::SetDialogInitialState(BaseDocument* const pSelectedDocument)
02517 {   
02518     m_UserCanModifyQuestion = FALSE;
02519 
02520     // Fill the left-hand list box with the available WizOps / Styles & a Custom property
02521     BuildAvailablePropertiesList(pSelectedDocument);
02522 
02523     // Set the controls up in their correct initial state
02524     InitializeControls();
02525 }
02526 
02527 
02528 /********************************************************************************************
02529 
02530 >   void TemplateDialog::InitializeControls()
02531 
02532     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02533     Created:    09/06/97
02534     
02535     Purpose:    Sets up the dialog according to what attributes are applied to the
02536                 selection. The cases are:
02537 
02538 ********************************************************************************************/
02539 void TemplateDialog::InitializeControls()
02540 {
02541     // Fill the right-hand one with applied user attributes
02542     BuildUsedPropertiesList();
02543 
02544     ShowInitialControlAvailablity();
02545 }
02546 
02547 
02548 /********************************************************************************************
02549 
02550 >   void TemplateDialog::ShowInitialControlAvailablity()
02551 
02552     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02553     Created:    09/06/97
02554     
02555 ********************************************************************************************/
02556 void TemplateDialog::ShowInitialControlAvailablity()
02557 {
02558     m_pQuestionGadget->Disable();
02559     m_pParamGadget->Disable();
02560 
02561     m_pAddButton->Disable();
02562     m_pRemoveButton->Disable();
02563     m_pRemoveAllButton->Disable();
02564 
02565     m_pMakeStyleButton->Disable();
02566 
02567     m_pApplyButton->Disable();
02568 
02569     // if nothing's selected don't let them click on it
02570     SelRange* const pSelRange = GetApplication()->FindSelection();
02571     if (pSelRange != NULL && pSelRange->IsEmpty())
02572     {
02573         m_pAvailableListGadget->Disable();
02574         m_pUsedListGadget->Disable();
02575     }
02576     else
02577     {
02578         m_pAvailableListGadget->Enable();
02579         m_pUsedListGadget->Enable();
02580     }
02581 }
02582 
02583 
02584 /********************************************************************************************
02585 
02586 >   void TemplateDialog::OnAvailableSelectionChange()
02587 
02588     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02589     Created:    09/06/97
02590 
02591     Purpose:    Responds to a change to the selected item in the Available List
02592     
02593 ********************************************************************************************/
02594 void TemplateDialog::OnAvailableSelectionChange()
02595 {
02596     VOID_ENSURE_NOT_NULL(m_pAddButton);
02597 
02598     if (m_pAddButton != NULL)
02599     {
02600         // Remove the selection from the selected list. This will remove any question / param 
02601         // so they can be used to add new entries
02602         if (GetUsedProperties().GetNumberOfSelectedEntries() > 0)
02603         {
02604             GetUsedProperties().RemoveSelection();
02605         }
02606 
02607         GetAvailableProperties().OnSelectionChange(*this);
02608 
02609         // should use a Notify for this...
02610         if (GetAvailableProperties().GetNumberOfSelectedEntries() > 0)
02611         {
02612             m_pAddButton->Enable();
02613         }
02614         else
02615         {
02616             m_pAddButton->Disable();
02617         }
02618     }
02619 
02620     VOID_ENSURE_NOT_NULL(m_pMakeStyleButton);
02621 
02622     if (m_pMakeStyleButton != NULL)
02623     {
02624         // ensure the style button is disabled
02625         m_pMakeStyleButton->Disable();
02626     }
02627 
02628 }
02629 
02630 
02631 /********************************************************************************************
02632 
02633 >   void TemplateDialog::ReflectAvailableListChange()
02634 
02635     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02636     Created:    09/06/97
02637 
02638     Purpose:    Updates the state of the buttons which are determined solely by the 
02639                 Available properties list.
02640     
02641 ********************************************************************************************/
02642 /*
02643 void TemplateDialog::ReflectAvailableListChange()
02644 {
02645     // should use a Notify for this...
02646     if (GetAvailableProperties().GetNumberOfSelectedEntries() > 0)
02647     {
02648         m_pAddButton->Enable();
02649     }
02650     else
02651     {
02652         m_pAddButton->Disable();
02653     }
02654 
02655 
02656     BOOL ShouldEnableMakeStyle = FALSE;
02657     if (GetAvailableProperties().GetNumberOfSelectedEntries() == 1)
02658     {
02659         AvailableProperty* pSelectedEntry = (AvailableProperty*)GetAvailableProperties().GetFirstSelectedEntry();
02660         VOID_ENSURE_NOT_NULL(pSelectedEntry);
02661 
02662         ShouldEnableMakeStyle = pSelectedEntry->CanBecomeStyle();
02663     }
02664 
02665     if (ShouldEnableMakeStyle)
02666     {
02667         m_pMakeStyleButton->Enable();
02668     }
02669     else
02670     {
02671         m_pMakeStyleButton->Disable();
02672     }
02673 }
02674 */
02675 
02676 /********************************************************************************************
02677 
02678 >   void TemplateDialog::OnUsedSelectionChange()
02679 
02680     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02681     Created:    09/06/97
02682     
02683 ********************************************************************************************/
02684 void TemplateDialog::OnUsedSelectionChange()
02685 {
02686     VOID_ENSURE_NOT_NULL(m_pRemoveButton);
02687     VOID_ENSURE_NOT_NULL(m_pRemoveAllButton);
02688     VOID_ENSURE_NOT_NULL(m_pMakeStyleButton);
02689     VOID_ENSURE_NOT_NULL(m_pAddButton);
02690 
02691     if (m_pRemoveButton != NULL && m_pRemoveAllButton != NULL && m_pMakeStyleButton != NULL &&
02692         m_pAddButton != NULL)
02693     {
02694         // Remove the selection from the available list
02695         if (GetAvailableProperties().GetNumberOfSelectedEntries() > 0)
02696         {
02697             GetAvailableProperties().RemoveSelection();
02698             m_pMakeStyleButton->Disable();
02699             m_pAddButton->Disable();
02700         }
02701 
02702         GetUsedProperties().OnSelectionChange(*this);
02703 
02704         // Can only remove selected items
02705         if (GetUsedProperties().GetNumberOfSelectedEntries() > 0)
02706         {
02707             m_pRemoveButton->Enable();
02708         }
02709         else
02710         {
02711             m_pRemoveButton->Disable();
02712         }
02713 
02714         // Whenever there's anything in the used list, enable the Remove All Button
02715         if (GetUsedProperties().GetNumberOfEntries() > 0)
02716         {
02717             m_pRemoveAllButton->Enable();
02718         }
02719         else
02720         {
02721             m_pRemoveAllButton->Disable();
02722         }
02723     }
02724 }
02725 
02726 
02727 /********************************************************************************************
02728 
02729 >   void TemplateDialog::ReflectUsedListChange()
02730 
02731     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02732     Created:    09/06/97
02733 
02734     Purpose:    Updates the state of the buttons which are determined solely by the 
02735                 Available properties list.
02736     
02737 ********************************************************************************************/
02738 /*
02739 void TemplateDialog::ReflectUsedListChange()
02740 {
02741     // Can only remove selected items
02742     if (GetUsedProperties().GetNumberOfSelectedEntries() > 0)
02743     {
02744         m_pRemoveButton->Enable();
02745     }
02746     else
02747     {
02748         m_pRemoveButton->Disable();
02749     }
02750 
02751     // Whenever there's anything in the used list, enable the Remove All Button
02752     if (GetUsedProperties().GetNumberOfEntries() > 0)
02753     {
02754         m_pRemoveAllButton->Enable();
02755     }
02756     else
02757     {
02758         m_pRemoveAllButton->Disable();
02759     }
02760 }
02761 */
02762 
02763 
02764 /********************************************************************************************
02765 
02766 >   BOOL TemplateDialog::BuildAvailablePropertiesList(BaseDocument* const pSelectedDocument)
02767 
02768     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02769     Created:    09/06/97
02770     
02771 ********************************************************************************************/
02772 BOOL TemplateDialog::BuildAvailablePropertiesList(BaseDocument* const pSelectedDocument)
02773 {
02774     BOOL Ok = TRUE;
02775 
02776     // Delete the last load of available properties we got when the selected document changed
02777     delete m_pAvailableProperties;
02778     m_pAvailableProperties = NULL;
02779 
02780     if (pSelectedDocument != NULL)
02781     {
02782         // Fill 'er up with template handlers aka WizOps
02783         m_pAvailableProperties = new AvailablePropertiesList();
02784     }
02785 
02786     Ok = (m_pAvailableProperties != NULL && m_pAvailableListGadget != NULL);
02787 
02788     if (Ok)
02789     {
02790         Ok = m_pAvailableProperties->Interact(*m_pAvailableListGadget);
02791     }
02792 
02793     if (Ok)
02794     {
02795         Ok = m_pAvailableProperties->AddTemplateHandlers(GetWizOps());
02796     }
02797 
02798     // ...and any styles that are hanging about
02799     if (Ok)
02800     {
02801         WizOpStyles* const pStyles = GetStyles();
02802         Ok = (pStyles != NULL);
02803 
02804         if (Ok)
02805         {
02806 #if FALSE
02807             WizOpStyle NewStyle(String_8("Style"), String_64("The shading in the trees"), 
02808                                 *GetWizOps().GetFirstWizOp(), String_8("P1"));
02809             pStyles->AddStyle(NewStyle);
02810 #endif
02811             Ok = m_pAvailableProperties->AddStyles(*pStyles);
02812         }
02813     }
02814     // ...and add a Custom Property entry
02815     if (Ok && ShowCustomProperty())
02816     {
02817         CustomProperty* pCustomProperty = new CustomProperty();
02818         if (pCustomProperty != NULL)
02819         {
02820             Ok = m_pAvailableProperties->InsertEntry(*pCustomProperty);
02821         }
02822     }
02823 
02824     if (!Ok)
02825     {
02826         delete m_pAvailableProperties;
02827         m_pAvailableProperties = NULL;
02828     }
02829 
02830     return Ok;
02831 }
02832 
02833 
02834 
02835 /********************************************************************************************
02836 
02837 >   BOOL TemplateDialog::BuildUsedPropertiesList()
02838 
02839     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02840     Created:    09/06/97
02841 
02842 ********************************************************************************************/
02843 BOOL TemplateDialog::BuildUsedPropertiesList()
02844 {
02845     BOOL Ok = TRUE;
02846 
02847     // when the selection changes, bin the old used properties list, and start afresh
02848     delete m_pUsedProperties;
02849     m_pUsedProperties = NULL;
02850 
02851     m_pUsedProperties = new UsedPropertiesList();
02852 
02853     Ok = (m_pUsedProperties != NULL && m_pUsedListGadget != NULL);
02854 
02855     if (Ok)
02856     {
02857         Ok = m_pUsedProperties->Interact(*m_pUsedListGadget);
02858     }
02859 
02860     RenderableNodeEnumerator* pEnumerator = NULL;
02861 
02862     if (Ok)
02863     {
02864         pEnumerator = CreateEnumerator();
02865         if (pEnumerator != NULL)
02866         {
02867             Ok = m_pUsedProperties->BuildFromEnumerator(*pEnumerator);
02868         }
02869     }
02870 
02871     delete pEnumerator;
02872     pEnumerator = NULL;
02873 
02874     return Ok;
02875 }
02876 
02877 
02878 /********************************************************************************************
02879 
02880 >   void TemplateDialog::MakePropertyUsed()
02881 
02882     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02883     Created:    09/06/97
02884 
02885 ********************************************************************************************/
02886 void TemplateDialog::MakePropertyUsed()
02887 {
02888     ENSURE_THIS();
02889 
02890     const UINT32 OrignalEntries = GetUsedProperties().GetNumberOfEntries(); // should be Notified really
02891 
02892     // Get the selected template handler in the available properties list
02893     VisibleListIterator Iterator = GetAvailableProperties().SelectionBegin();
02894     while (Iterator != GetAvailableProperties().End())
02895     {
02896         //  and add a new entry in the used list
02897         AvailableProperty& PropertyToUse = (AvailableProperty&)*Iterator;
02898         ENSURE_KIND((&PropertyToUse), AvailableProperty);
02899 
02900         GetUsedProperties().AddAvailableProperty(PropertyToUse);
02901         ++Iterator;
02902     }
02903 
02904     // if we actually added something then enable the Apply button
02905     if (GetUsedProperties().GetNumberOfEntries() > OrignalEntries)
02906     {
02907         m_pApplyButton->Enable();       // should be Notified really
02908         m_pRemoveAllButton->Enable();   // should be Notified really
02909     }
02910 
02911     // disable the Make Style button 'cos we don't have a working attribute now
02912     m_pMakeStyleButton->Disable();
02913     m_pAddButton->Disable();
02914 }
02915 
02916 
02917 
02918 /********************************************************************************************
02919 
02920 >   void TemplateDialog::RemoveUsedProperty()
02921 
02922     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02923     Created:    09/06/97
02924 
02925 ********************************************************************************************/
02926 void TemplateDialog::RemoveUsedProperty()
02927 {
02928     ENSURE_THIS();
02929 
02930     GetUsedProperties().DeleteSelectedEntries();
02931 
02932     m_pApplyButton->Enable();   // should be Notified really
02933 
02934     m_pRemoveButton->Disable(); // should be Notified really
02935 
02936     if (GetUsedProperties().GetNumberOfEntries() == 0)
02937     {
02938         m_pRemoveAllButton->Disable();  // should be Notified really
02939     }
02940 }
02941 
02942 
02943 /********************************************************************************************
02944 
02945 >   void TemplateDialog::RemoveAllUsedProperties()
02946 
02947     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02948     Created:    09/06/97
02949 
02950 ********************************************************************************************/
02951 void TemplateDialog::RemoveAllUsedProperties()
02952 {
02953     ENSURE_THIS();
02954 
02955     GetUsedProperties().DeleteAllEntries();
02956 
02957     m_pApplyButton->Enable();   // should be Notified really
02958 
02959     m_pRemoveButton->Disable(); // should be Notified really
02960 
02961     m_pRemoveAllButton->Disable();  // should be Notified really
02962 }
02963 
02964 
02965 /********************************************************************************************
02966 
02967 >   Style* TemplateDialog::AddNewStyle(const Style& NewStyle) const
02968 
02969     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
02970     Created:    09/06/97
02971 
02972     Purpose:    Support function that attempts to add the given style to the styles
02973                 associated with the selected document.
02974 
02975     Returns:    A pointer to the style to use (the one that was added)
02976                 NULL if the addition failed or the Style Name already exists in the selected
02977                 document's style component.
02978 
02979 ********************************************************************************************/
02980 Style* TemplateDialog::AddNewStyle(const Style& NewStyle) const
02981 {
02982     Style* pStyleToUse = NULL;
02983 
02984     WizOpStyles* const pStyles = GetStyles();
02985     if (pStyles != NULL)
02986     {
02987         // don't give them a style to use if one with the same name already exists
02988         pStyleToUse = pStyles->FindStyleFromName(NewStyle.GetName());
02989         if (pStyleToUse == NULL)
02990         {
02991             pStyleToUse = pStyles->AddStyle(NewStyle);
02992         }
02993         else
02994         {
02995             pStyleToUse = NULL;
02996         }
02997     }
02998     
02999     return pStyleToUse;
03000 }
03001 
03002 
03003 
03004 /********************************************************************************************
03005 
03006 >   WizOps& TemplateDialog::GetWizOps()
03007 
03008     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
03009     Created:    09/06/97
03010 
03011 ********************************************************************************************/
03012 WizOps& TemplateDialog::GetWizOps() const
03013 {
03014     return ::GetWizOps();
03015 }
03016 
03017 
03018 /********************************************************************************************
03019 
03020 >   RenderableNodeEnumerator* TemplateDialog::CreateEnumerator() const
03021 
03022     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
03023     Created:    09/06/97
03024 
03025     Purpose:    Provides a suitable Node enumerator depending on the selection
03026 
03027 ********************************************************************************************/
03028 RenderableNodeEnumerator* TemplateDialog::CreateEnumerator() const
03029 {
03030     RenderableNodeEnumerator* pEnumerator = NULL;
03031 
03032     SelRange* const pSelRange = GetApplication()->FindSelection();
03033 
03034     if (pSelRange != NULL && !pSelRange->IsEmpty())
03035     {
03036         pEnumerator = new RangeEnumerator(pSelRange);
03037     }
03038     else if (pSelRange != NULL && pSelRange->IsEmpty())
03039     {
03040         // If there's no selection the AttrUser's need to be applied to the Document (maybe)
03041 //      pEnumerator = new DocPseudoEnumerator(Document::GetSelected());
03042     }
03043 
03044     return pEnumerator;
03045 }
03046 
03047 
03048 
03049 /********************************************************************************************
03050 
03051 >   void TemplateDialog::ApplyUsedAttributes()
03052 
03053     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from assorted dialog classes)
03054     Created:    09/06/97
03055     
03056     Purpose:    Applies all the properties marked as used to the current selection
03057 
03058 ********************************************************************************************/
03059 void TemplateDialog::ApplyUsedAttributes()
03060 {
03061     GetUsedProperties().Commit(*this);
03062 
03063     m_pApplyButton->Disable();
03064 }
03065 
03066 
03067 
03068 
03069 
03070 
03071 /********************************************************************************************
03072 
03073 >   AvailablePropertiesList& TemplateDialog::GetAvailableProperties()
03074     UsedPropertiesList& TemplateDialog::GetUsedProperties()
03075 
03076     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
03077     Created:    09/06/97
03078     
03079     Purpose:    Data Member access
03080 
03081 ********************************************************************************************/
03082 AvailablePropertiesList& TemplateDialog::GetAvailableProperties()
03083 {
03084     // This static dummy object is used for returning in the ERROR2 case
03085     // The original used to return a ptr to a local variable, which is a tad dangerous.
03086     // This solution is not ideal, because there's a permanent instance of an object
03087     // that will probably never be used.
03088     static AvailablePropertiesList DummyList;
03089 
03090     ERROR2IF(m_pAvailableProperties == NULL, DummyList, "NULL Member");
03091     return *m_pAvailableProperties;
03092 }
03093 
03094 
03095 UsedPropertiesList& TemplateDialog::GetUsedProperties()
03096 {
03097     // This static dummy object is used for returning in the ERROR2 case
03098     // The original used to return a ptr to a local variable, which is a tad dangerous.
03099     // This solution is not ideal, because there's a permanent instance of an object
03100     // that will probably never be used.
03101     static UsedPropertiesList DummyList;
03102 
03103     ERROR2IF(m_pUsedProperties == NULL, DummyList, "NULL Member");
03104     return *m_pUsedProperties;
03105 }
03106 
03107 
03108 TextControl& TemplateDialog::GetKeyControl() const
03109 {
03110     ASSERT(m_pParamGadget != NULL);
03111 
03112     return *m_pParamGadget;
03113 }
03114 
03115 
03116 TextControl& TemplateDialog::GetValueControl() const
03117 {
03118     ASSERT(m_pQuestionGadget != NULL);
03119 
03120     return *m_pQuestionGadget;
03121 }
03122 
03123 StaticTextControl& TemplateDialog::GetParamHintControl() const
03124 {
03125     ASSERT(m_pParamHintGadget != NULL);
03126 
03127     return *m_pParamHintGadget;
03128 }
03129 
03130 WizOpStyles* TemplateDialog::GetStyles() const
03131 {
03132     WizOpStyles* pStyles = NULL;
03133 
03134     BaseDocument* pDoc = Document::GetSelected();
03135     if (pDoc != NULL)
03136     {
03137         pStyles = (WizOpStyles*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(WizOpStyles));
03138     }
03139 
03140     return pStyles;
03141 }
03142 
03143 
03144 BOOL TemplateDialog::UserCanModifyQuestion() const
03145 {
03146     return m_UserCanModifyQuestion;
03147 }
03148 
03149 void TemplateDialog::SetUserCanModifyQuestion(BOOL TheyCan)
03150 {
03151     m_UserCanModifyQuestion = TheyCan;
03152 }
03153 
03154 /********************************************************************************************
03155 
03156 >   BOOL TemplateDialog::CreateGadgets()
03157 
03158     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
03159     Created:    09/06/97
03160     
03161     Purpose:    Support function to create the controls in the dialog.
03162                 The DialogManager should do this but I haven't time.
03163 
03164 ********************************************************************************************/
03165 BOOL TemplateDialog::CreateGadgets()
03166 {
03167     m_pUsedListGadget = new ListControl(this, _R(IDC_TMLPTDLG_USED));
03168 
03169     m_pAvailableListGadget = new ListControl(this, _R(IDC_TMLPTDLG_AVAILABLE));
03170 
03171     m_pQuestionGadget = new TextControl(this, _R(IDC_TMLPTDLG_QUESTION));
03172 
03173     m_pParamHintGadget = new StaticTextControl(this, _R(IDC_TMPLTDLG_PARAM_TEXT));
03174 
03175     m_pParamGadget = new TextControl(this, _R(IDC_TMPLTDLG_PARAM));
03176 
03177     m_pAddButton = new Button(this, _R(IDC_TMPLTDLG_ADD));
03178 
03179     m_pRemoveButton = new Button(this, _R(IDC_TMPLTDLG_REMOVE));
03180 
03181     m_pRemoveAllButton = new Button(this, _R(IDC_TMPLTDLG_REMOVE_ALL));
03182 
03183     m_pApplyButton = new Button(this, IDOK);
03184 
03185     m_pMakeStyleButton = new Button(this, _R(IDC_TMPLTDLG_MAKE_STYLE));
03186 
03187     return (m_pUsedListGadget != NULL && m_pAvailableListGadget != NULL &&
03188             m_pQuestionGadget != NULL && m_pParamHintGadget != NULL && m_pParamGadget != NULL && 
03189             m_pAddButton != NULL && m_pRemoveButton != NULL && m_pRemoveAllButton != NULL &&
03190             m_pApplyButton != NULL &&
03191             m_pMakeStyleButton != NULL
03192             );
03193 }
03194 
03195 

Generated on Sat Nov 10 03:47:11 2007 for Camelot by  doxygen 1.4.4