ngdialog.cpp

Go to the documentation of this file.
00001 // $Id: ngdialog.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 /*
00099     $Header: /Camelot/kernel/ngdialog.cpp 4     12/09/00 12:31 Simonk $
00100     Attribute gallery dialog operations
00101 */
00102 
00103 #include "camtypes.h"
00104 
00105 #include "ngcore.h"
00106 #include "ngdialog.h"
00107 #include "ngitem.h"
00108 #include "ngsentry.h"
00109 #include "ngsetop.h"
00110 
00111 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "sginit.h"
00113 #include "comattrmsg.h"
00114 
00115 //#include "resource.h"
00116 //#include "barsdlgs.h"
00117 //#include "galres.h"
00118 
00119 //#include "mario.h"
00120 //#include "justin.h"
00121 //#include "justin3.h"
00122 #include "slicehelper.h"
00123 // for the use of wix temple attribs
00124 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00125 #include "userattr.h"
00126 #include "tmpltatr.h"
00127 
00128 #ifdef _DEBUG
00129 #undef THIS_FILE
00130 static char BASED_CODE THIS_FILE[] = __FILE__;
00131 #endif
00132 
00133 DECLARE_SOURCE("$Revision: 1282 $");
00134 
00135 // Implement the dynamic class bits...
00136 CC_IMPLEMENT_DYNCREATE(NameObjectsDlg, DialogOp);
00137 CC_IMPLEMENT_DYNCREATE(RenameObjectsDlg, DialogOp);
00138 CC_IMPLEMENT_DYNCREATE(OpNameGalleryPropIndexDesc, OpDescriptor);
00139 CC_IMPLEMENT_DYNCREATE(OpDisplayNameGallery, Operation);
00140 
00141 // This line mustn't go before any CC_IMPLEMENT_... macros
00142 #define new CAM_DEBUG_NEW
00143 
00144 // Preference for modal (default) or modeless Name Objects dialog.
00145 BOOL NameObjectsDlg::m_fModeless = FALSE;
00146 
00147 
00148 /********************************************************************************************
00149 >   BaseNameObjectsDlg::BaseNameObjectsDlg(CDlgResID idRes, CDlgMode nMode)
00150 
00151     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00152     Created:    9/8/99
00153     Inputs:     idRes       ---     resource ID of the dialog template to use
00154                 nMode       ---     mode to run in, MODAL or MODELESS
00155     Purpose:    Create a BaseNameObjectsDlg, an abstract base class for the Name Objects
00156                 and Rename Objects dialogs.
00157     SeeAlso:    NameObjectsDlg; RenameObjectsDlg
00158 ********************************************************************************************/
00159 
00160 BaseNameObjectsDlg::BaseNameObjectsDlg(CDlgResID idRes, CDlgMode nMode)
00161   : DialogOp(idRes, nMode)
00162 {   
00163     // Empty.
00164 }        
00165 
00166 
00167 
00168 
00169 /********************************************************************************************
00170 >   virtual void BaseNameObjectsDlg::Do(OpDescriptor*)
00171 
00172     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00173     Created:    9/8/99
00174     Purpose:    Creates and runs a BaseNameObjectsDlg.
00175     SeeAlso:    NameObjectsDlg; RenameObjectsDlg
00176 ********************************************************************************************/
00177 
00178 void BaseNameObjectsDlg::Do(OpDescriptor*)
00179 {
00180     // Try to run this operation.
00181     if (!Create())
00182     {
00183         InformError(0, _R(IDS_OK));
00184         End();
00185     }
00186 }
00187 
00188 
00189 
00190 /********************************************************************************************
00191 >   virtual MsgResult BaseNameObjectsDlg::Message(Msg* pMessage)
00192 
00193     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00194     Created:    9/8/99
00195     Purpose:    Handles kernel messages for the BaseNameObjectsDlg dialog operation.
00196 ********************************************************************************************/
00197 
00198 MsgResult BaseNameObjectsDlg::Message(Msg* pMessage)
00199 {
00200     // A message from the dialog or its gadgets?
00201     if (IS_OUR_DIALOG_MSG(pMessage))
00202     {
00203         DialogMsg* pMsg = (DialogMsg*) pMessage;
00204         switch (pMsg->DlgMsg)
00205         {
00206         case DIM_CREATE:
00207             InitGadgetText();
00208             break;
00209 
00210         case DIM_TEXT_CHANGED:
00211             // Disable the OK/Apply button if there's no document or entered text.
00212             EnableGadget(_R(IDOK), !GetStringGadgetValue(_R(IDC_NAMEDLG_NAME), 0).IsEmpty()
00213                             && Document::GetSelected() != 0);
00214             break;
00215             
00216         case DIM_COMMIT:
00217             {
00218                 // Check name for validity.
00219                 String_256 strEnter = GetStringGadgetValue(_R(IDC_NAMEDLG_NAME), 0);
00220                 UINT32 nErrID = IsValid(strEnter);
00221                 if (nErrID != 0)
00222                 {
00223                     // Invalid, reinitialise.
00224                     InformError(nErrID);
00225                     InitGadgetText();
00226                     break;
00227                 }
00228                 else
00229                     // Entry is valid, try committing it.
00230                     if (DoCommit(strEnter))
00231                     {
00232                         // Don't close, reinitialise (dialog is modeless).
00233                         InitGadgetText();
00234                         break;
00235                     }
00236             }
00237             
00238         case DIM_CANCEL:
00239             Close();
00240             End();
00241             break;
00242 
00243         default:
00244             break;
00245         }
00246     }
00247     
00248     // Or has something changed the object selection?
00249     else if (MESSAGE_IS_A(pMessage, CommonAttrsChangedMsg) || 
00250              (MESSAGE_IS_A(pMessage, OpMsg) && 
00251                     (((OpMsg*) pMessage)->MsgType == OpMsg::AFTER_UNDO ||
00252                     ((OpMsg*) pMessage)->MsgType == OpMsg::AFTER_REDO)))
00253     {
00254         // Update the description.
00255         String_256 strEnter;
00256         SetStringGadgetValue(_R(IDC_NAMEDLG_DESC), *GetDescription(&strEnter));
00257 
00258         // And if not changed or empty, also the suggestion.
00259         strEnter = GetStringGadgetValue(_R(IDC_NAMEDLG_NAME), 0);
00260         if (strEnter.IsEmpty() || strEnter == m_strSuggest)
00261         {
00262             SetStringGadgetValue(_R(IDC_NAMEDLG_NAME), *GetSuggestion(&m_strSuggest));
00263             HighlightText(_R(IDC_NAMEDLG_NAME));
00264         }
00265     }
00266 
00267     // Has the document been switched or closed?
00268     else if (MESSAGE_IS_A(pMessage, DocChangingMsg))
00269     {
00270         DocChangingMsg* pMsg = (DocChangingMsg*) pMessage;
00271         if (pMsg->State == DocChangingMsg::SELCHANGED)
00272             EnableGadget(_R(IDOK), pMsg->pNewDoc != 0);
00273     }
00274 
00275     // Pass everything on to the base class . . .
00276     return DialogOp::Message(pMessage);
00277 }  
00278 
00279 
00280 
00281 /********************************************************************************************
00282 >   void BaseNameObjectsDlg::InitGadgetText()
00283 
00284     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00285     Created:    9/5/99
00286     Purpose:    Initialises the text of the gadgets in the dialog.
00287     SeeAlso:    BaseNameObjectsDlg::Message
00288 ********************************************************************************************/
00289 
00290 void BaseNameObjectsDlg::InitGadgetText()
00291 {
00292     String_256 str;
00293     SetStringGadgetValue(_R(IDC_NAMEDLG_DESC), *GetDescription(&str));
00294     SetStringGadgetValue(_R(IDC_NAMEDLG_NAME), *GetSuggestion(&m_strSuggest));
00295     HighlightText(_R(IDC_NAMEDLG_NAME));
00296     SetKeyboardFocus(_R(IDC_NAMEDLG_NAME));
00297 }
00298 
00299 
00300 
00301 /********************************************************************************************
00302 >   virtual UINT32 BaseNameObjectsDlg::IsValid(const StringBase& strName)
00303 
00304     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00305     Created:    9/5/99
00306     Inputs:     strName     ---     name to test for suitability
00307     Returns:    0 if valid (by default any non-empty text is valid), or the ID of an
00308                 error string explaining why if it is not.
00309     SeeAlso:    BaseNameObjectsDlg::Message
00310 ********************************************************************************************/
00311 
00312 UINT32 BaseNameObjectsDlg::IsValid(const StringBase& strName)
00313 {
00314     return 0;
00315 }
00316 
00317 
00318 
00319 /********************************************************************************************
00320 >   NameObjectsDlg::NameObjectsDlg()
00321 
00322     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00323     Created:    9/5/99
00324     Purpose:    Constructs a NameObjectsDlg object, a modeless version of the base class
00325                 dialog, which creates names of objects in the Attribute gallery.
00326     SeeAlso:    BaseNameObjectsDlg
00327 ********************************************************************************************/
00328 
00329 NameObjectsDlg::NameObjectsDlg()
00330   : BaseNameObjectsDlg(_R(IDD_NAMEDLG_NAME_TEMPLATE), m_fModeless ? MODELESS : MODAL)
00331 {
00332     // Empty.
00333 }
00334 
00335 
00336 
00337 /********************************************************************************************
00338 >   virtual StringBase* NameObjectsDlg::GetDescription(StringBase* pstrDesc)
00339 
00340     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00341     Created:    9/5/99
00342     Returns:    The input.
00343     Outputs:    pstrDesc    ---     a description of the selected objects, if any,
00344                                     to be named.
00345     SeeAlso:    BaseNameObjectsDlg
00346 ********************************************************************************************/
00347 
00348 StringBase* NameObjectsDlg::GetDescription(StringBase* pstrDesc)
00349 {
00350     // No objects, one object, some objects.
00351     SelRange* pSel = GetApplication()->FindSelection();
00352     if (pSel->IsEmpty())
00353         pstrDesc->Load(_R(IDS_NAMEDLG_DESCRIBE_NOSELECT));
00354     else
00355         if (pSel->Count() == 1)
00356         {
00357             String_256 desc=pSel->Describe(MENU);
00358             pstrDesc->MakeMsg(_R(IDS_NAMEDLG_DESCRIBE_SELECT), &desc);
00359         }
00360         else
00361         {
00362             String_256 desc=pSel->Describe(STATUS_BAR);
00363             pstrDesc->MakeMsg(_R(IDS_NAMEDLG_DESCRIBE_SELECT_PL), &desc);
00364         }
00365 
00366     return pstrDesc;
00367 }
00368 
00369 
00370 
00371 /********************************************************************************************
00372 >   virtual StringBase* NameObjectsDlg::GetSuggestion(StringBase* pstrSuggest)
00373 
00374     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00375     Created:    9/5/99
00376     Outputs:    pstrSuggest  ---    a suggested name for the selected objects, if any.
00377     Returns:    pstrSuggest, ie. the input.
00378     Purpose:    Works out a suggestion for the name of the selected objects, if any.
00379     SeeAlso:    BaseNameObjectsDlg
00380 ********************************************************************************************/
00381 
00382 StringBase* NameObjectsDlg::GetSuggestion(StringBase* pstrSuggest)
00383 {
00384     // Work out what default text to put in the dialog edit-field.
00385     SelRange* pSel = GetApplication()->FindSelection();
00386     if (pSel->IsEmpty())
00387         pstrSuggest->Load(_R(IDS_NAMEDLG_DEFAULT_NAME));
00388     else
00389     {
00390         // Pluralisise / capitalise the selection description.
00391         if (pSel->Count() == 1)
00392         {
00393             *pstrSuggest = pSel->Describe(MENU);
00394             pstrSuggest->toTitle();
00395         }
00396         else
00397             *pstrSuggest = pSel->Describe(STATUS_BAR);
00398     }
00399 
00400     // Make the name unique, if necessary, by appending ascending numerals.
00401     Document* pDoc = Document::GetCurrent();
00402     if (pDoc != 0)
00403     {
00404         NodeSetSentinel* pSentry = pDoc->GetSetSentinel();
00405         if (pSentry != 0)
00406         {
00407             String_256 strBase = *pstrSuggest;
00408             INT32 nAppend = 2;
00409             while (pSentry->GetNameAttr(*pstrSuggest) != 0)
00410                 pstrSuggest->MakeMsg(_R(IDS_NAMEDLG_UNIQUE_MASK), &strBase, nAppend++);
00411         }
00412     }       
00413 
00414     return pstrSuggest;
00415 }
00416 
00417 
00418 
00419 /********************************************************************************************
00420 >   virtual UINT32 NameObjectsDlg::IsValid(const StringBase& strName)
00421 
00422     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00423     Created:    9/5/99
00424     Inputs:     strName     ---     name to test for suitability
00425     Returns:    0 if valid (ie. not a name already in use), ID of an error string
00426                 explaining why if it is not (new names must be _new_, ie. different
00427                 to any existing ones).
00428     SeeAlso:    BaseNameObjectsDlg::Message
00429 ********************************************************************************************/
00430 
00431 UINT32 NameObjectsDlg::IsValid(const StringBase& strName)
00432 {
00433     // All new names must be unique, it's a policy.
00434     return Document::GetSelected()->GetSetSentinel()->GetNameAttr(strName) != 0
00435                         ? _R(IDE_NAMEDLG_NAME_EXISTS) : 0;
00436 }
00437 
00438 
00439 
00440 /********************************************************************************************
00441 >   virtual BOOL NameObjectsDlg::DoCommit(const StringBase& strName)
00442 
00443     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00444     Created:    9/5/99
00445     Inputs:     strName         ---     the name to OpApplyNames
00446     Returns:    TRUE / FALSE    ---     don't / do close the dialog on returning.
00447     Purpose:    Applies the name to the selected objects, if any.
00448     SeeAlso:    BaseNameObjectsDlg::Message; OpApplyNames
00449 ********************************************************************************************/
00450 
00451 BOOL NameObjectsDlg::DoCommit(const StringBase& strName)
00452 {
00453     // Invoke either OpApplyNameToSel or OpApplyNameToNone, with a single name parameter.
00454     const TCHAR* pszTok = (GetApplication()->FindSelection()->IsEmpty())
00455                                 ? OPTOKEN_APPLY_NAME_TO_NONE
00456                                 : OPTOKEN_APPLY_NAME_TO_SEL;
00457 
00458     // Apply and (do or do not) close the dialog.
00459     OpDescriptor* pDesc = OpDescriptor::FindOpDescriptor((TCHAR*) pszTok);
00460     ERROR3IF(pDesc == 0, "NameObjectsDlg::DoCommit: can't find descriptor");
00461     OpParam param((void *) &strName, 0);
00462     pDesc->Invoke(&param);
00463     return m_fModeless;
00464 }
00465 
00466 
00467 
00468 /********************************************************************************************
00469 >   static BOOL NameObjectsDlg::Init()
00470 
00471     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00472     Created:    9/5/99
00473     Returns:    TRUE if successful.
00474     Purpose:    Initialises preferences for this class.
00475     SeeAlso:    BaseNameObjectsDlg; InitNamingSystem
00476 ********************************************************************************************/
00477 
00478 BOOL NameObjectsDlg::Init()
00479 {
00480     ERROR2IF(!GetApplication()->DeclareSection(TEXT("Name Gallery"), 5) ||
00481              !GetApplication()->DeclarePref(TEXT("Name Gallery"),
00482                                             TEXT("ModelessNameObjects"),
00483                                             &m_fModeless, FALSE, TRUE),
00484              FALSE,
00485              _R(IDE_BAD_INI_FILE));
00486 
00487     return TRUE;
00488 }
00489 
00490 
00491 
00492 /********************************************************************************************
00493 >   RenameObjectsDlg::RenameObjectsDlg()
00494 
00495     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00496     Created:    9/5/99
00497     Purpose:    Constructs a RenameObjectsDlg object, a modal version of the base class
00498                 dialog, which renames highlighted name items in the Attribute gallery.
00499     SeeAlso:    BaseNameObjectsDlg
00500 ********************************************************************************************/
00501 
00502 RenameObjectsDlg::RenameObjectsDlg()
00503   : BaseNameObjectsDlg(_R(IDD_NAMEDLG_RENAME_TEMPLATE), MODAL)
00504 {
00505     // Empty.
00506 }
00507 
00508 
00509 
00510 /********************************************************************************************
00511 >   virtual StringBase* RenameObjectsDlg::GetDescription(StringBase* pstrDesc)
00512 
00513     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00514     Created:    9/5/99
00515     Returns:    The input.
00516     Outputs:    pstrDesc    ---     a description of the objects to be renamed, if any.
00517     SeeAlso:    BaseNameObjectsDlg
00518 ********************************************************************************************/
00519 
00520 StringBase* RenameObjectsDlg::GetDescription(StringBase* pstrDesc)
00521 {
00522     // Get the highlighted item from the Attribute gallery.
00523     SGNameItem* pItem =
00524             (SGNameItem*) NameGallery::Instance()->GetUsedNames()->FindNextSelectedItem(0);
00525     ERROR3IF(pItem == 0, "NameGallery::OnRename: no highlighted item to rename");
00526 
00527     // Build up a string description of it.
00528     //INT32 nTotal = pItem->GetObjectCount();
00529 
00530     // dont rely on the object count as it counts the text story, text line and each char if just the story has the tag
00531     // better to count the number of tags found! (sjk 12/9/00)
00532     INT32 nTotal = 0;
00533     INT32 nSel = 0;
00534 
00535     String_256 ItemText = "";
00536     if (pItem)
00537         pItem->GetNameText(&ItemText);
00538 
00539     Node * pSpread = (Node *) Document::GetSelectedSpread();
00540     if (pSpread)
00541     {
00542         Node * pNode = SliceHelper::FindNextNameNode(pSpread, pSpread);
00543         while (pNode)
00544         {
00545             if (ItemText.CompareTo(((TemplateAttribute *)pNode)->GetParam()) == 0)
00546             {
00547                 nTotal++; // found a name
00548 
00549                 // is it selected?
00550                 // or even is its parent selected?
00551                 BOOL ParentSelected = FALSE;
00552                 Node * pParent = pNode->FindParent();
00553                 while (pParent && !ParentSelected)
00554                 {
00555                     if (pParent->IsSelected())
00556                     {
00557                         nSel++;
00558                         ParentSelected = TRUE;
00559                     }
00560 
00561                     pParent = pParent->FindParent();
00562                     if (pParent && pParent->IsLayer())
00563                         pParent = NULL;
00564                 }
00565             }
00566 
00567             pNode = SliceHelper::FindNextNameNode(pNode, pSpread);
00568         }
00569     }
00570 
00571     if (nTotal < 1 && !pSpread)
00572         pstrDesc->Load(_R(IDS_NAMEDLG_DESCRIBE_NOSET));
00573     else
00574     {
00575         // The set has some members, some or all of which might be selected.
00576         UINT32 idMask;
00577         String_256 strSel;
00578         if (nTotal == 1)
00579         {
00580             // Singular.  Work out if it's "which is" or "which isn't".
00581             idMask = _R(IDS_NAMEDLG_DESCRIBE_SET);
00582             if (nSel == 0)
00583                 strSel = _R(IDS_NAMEDLG_WHICH_ISNT);
00584             else 
00585                 strSel = _R(IDS_NAMEDLG_WHICH_IS);
00586         }
00587         else
00588         {       
00589             // Plural.  Work out if it's "none", "all", or "<a number>".
00590             idMask = _R(IDS_NAMEDLG_DESCRIBE_SET_PL);
00591             if (nSel == 0)
00592                 strSel = _R(IDS_NAMEDLG_NONE);
00593             else if (nSel == nTotal)
00594             {
00595                 strSel = _R(IDBBL_NAMEGAL_ALL);
00596                 strSel.toLower();
00597             }
00598             else
00599                 Convert::LongToString(nSel, &strSel);
00600         }
00601 
00602         String_256 strName;
00603         pItem->GetNameText(&strName);
00604         pstrDesc->MakeMsg(idMask, &strName, &strSel, nTotal);
00605     }
00606 
00607     return pstrDesc;
00608 }
00609 
00610 
00611 
00612 /********************************************************************************************
00613 >   virtual StringBase* RenameObjectsDlg::GetSuggestion(StringBase* pstrSuggest)
00614 
00615     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00616     Created:    9/5/99
00617     Returns:    The input.
00618     Outputs:    pstrSuggest ---     a suggested name for the selected objects, if any.
00619     SeeAlso:    BaseNameObjectsDlg
00620 ********************************************************************************************/
00621 
00622 StringBase* RenameObjectsDlg::GetSuggestion(StringBase* pstrSuggest)
00623 {
00624     // Suggest the old name of the highlighted Attribute gallery item.
00625     SGNameItem* pItem =
00626             (SGNameItem*) NameGallery::Instance()->GetUsedNames()->FindNextSelectedItem(0);
00627     ERROR3IF(pItem == 0, "NameGallery::OnRename: no highlighted item to rename");
00628     
00629     String_256 str;
00630     pItem->GetNameText(&str);
00631     *pstrSuggest = str;
00632     return pstrSuggest;
00633 }
00634 
00635 
00636 
00637 /********************************************************************************************
00638 >   virtual BOOL RenameObjectsDlg::DoCommit(const StringBase& strName)
00639 
00640     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00641     Created:    9/5/99
00642     Inputs:     strName     ---     the name to OpRenameNames
00643     Returns:    TRUE - close the dialog on returning.
00644     Purpose:    Called when the user enters a unique name and clicks OK in the Rename
00645                 objects dialog.
00646     SeeAlso:    BaseNameObjectsDlg::Message; OpRenameNames
00647 ********************************************************************************************/
00648 
00649 BOOL RenameObjectsDlg::DoCommit(const StringBase& strName)
00650 {
00651     // Rename all the highlighted items to the new name and close.
00652     OpDescriptor* pDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_RENAME_ALL);
00653     ERROR3IF(pDesc == 0, "RenameObjectsDlg::DoCommit: can't find OPTOKEN_RENAME_ALL");
00654     OpParam param((void *) &strName, 0);
00655     pDesc->Invoke(&param);
00656     return FALSE;
00657 }
00658 
00659 
00660 
00661 /**********************************************************************************************
00662 >   OpNameGalleryPropIndexDesc::OpNameGalleryPropIndexDesc()
00663 
00664     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00665     Created:    9/5/99
00666     Purpose:    Constructs an OpNameGalleryPropIndexDesc object.
00667 **********************************************************************************************/
00668 
00669 /*
00670     OpDescriptor constructor's arguments:-
00671 
00672                  UINT32 toolID,                         // Module Identifier
00673                  UINT32 txID,                         // String Resource ID
00674                  CCRuntimeClass* Op,                // pointer to the Op's runtime class
00675                  TCHAR* tok,                        // pointer to the token string
00676                  pfnGetState gs,                    // pointer to the GetState function
00677                  UINT32 helpId = 0,                 // help identifier 
00678                  UINT32 bubbleID = 0,                   // string resource for bubble help
00679                  UINT32 resourceID = 0,             // bitmap ("icon") or resource ID
00680                  UINT32 controlID =0,                   // control ID
00681                  BOOL ReceiveMessages = FALSE,
00682                  BOOL Smart = FALSE,
00683                  BOOL Clean = TRUE,
00684                  UINT32 OneOpenInstID = 0,          // When not 0 only one live instance
00685                                                     // of the operation is permitted, and
00686                                                     // OneOpenInstID is the string resource
00687                                                     // ID describing why.This will be useful
00688                                                     // for 1 open instance dialogs.
00689                  UINT32 AutoStateFlags = 0          // Flags which indicate conditions when
00690                                                     // the operation should automatically be
00691                                                     // greyed/ticked etc..(This cuts down the 
00692                                                     // number of tests that need to be made
00693                                                     // in the GetState function).
00694 */
00695 
00696 OpNameGalleryPropIndexDesc::OpNameGalleryPropIndexDesc()
00697   : OpDescriptor(0,
00698                  _R(IDS_NAME_GALLERY_PROP_INDEX),
00699                  CC_RUNTIME_CLASS(OpNameGalleryPropIndexDesc),
00700                  OPTOKEN_NAME_GALLERY_PROP_INDEX,
00701                  OpDisplayNameGallery::GetState,
00702                  0,
00703                  _R(IDBBL_NAME_GALLERY_PROP_INDEX),
00704                  0,
00705                  _R(IDC_NAMEGAL_PROP_IDX),
00706                  TRUE)
00707 {
00708     // Empty.
00709 }
00710 
00711 
00712 
00713 
00714 /***********************************************************************************************
00715 >   virtual void OpNameGalleryPropIndexDesc::OnControlCreate(OpDescControlCreateMsg* pCreateMsg)
00716 
00717     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00718     Created:    9/5/99
00719     Inputs:     pCreateMsg      ---     message describing this creation event
00720     Purpose:    Called when the combo-boxes associated with this descriptor are created.
00721 ***********************************************************************************************/
00722 
00723 void OpNameGalleryPropIndexDesc::OnControlCreate(OpDescControlCreateMsg* pCreateMsg)
00724 {
00725     // Fill up the gadget's list with the names of properties.  These must be in
00726     // ascending order of property indices.
00727     pCreateMsg->pDlgOp->SetStringGadgetValue(
00728                             pCreateMsg->SetGadgetID, String(_R(IDS_NAMEGAL_EXPORT_PROP)));
00729     pCreateMsg->pDlgOp->SetStringGadgetValue(
00730                             pCreateMsg->SetGadgetID, String(_R(IDS_NAMEGAL_SLICE_PROP)));
00731     pCreateMsg->pDlgOp->SetStringGadgetValue(
00732                             pCreateMsg->SetGadgetID, String(_R(IDS_NAMEGAL_STRETCH_PROP)));
00733 
00734     // Resize the list to fit and update associated gadgets.
00735     pCreateMsg->pDlgOp->SetComboListLength(pCreateMsg->SetGadgetID);
00736     UpdateGadgets();
00737 }
00738 
00739 
00740 
00741 /**********************************************************************************************
00742 >   void OpNameGalleryPropIndexDesc::OnSelectionChange(OpDescControlMsg* pSelChangedMsg,
00743                                                        List* pGadgetList)
00744 
00745     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00746     Created:    9/5/99
00747     Inputs:     pSelChangedMsg      ---     message describing the change event
00748                 pGadgetList         ---     list of gadgets associated with this
00749     Purpose:    Called when the combo-boxes associated with this descriptor are changed.
00750 **********************************************************************************************/
00751 
00752 void OpNameGalleryPropIndexDesc::OnSelectionChange(OpDescControlMsg* pSelChangedMsg, List*)
00753 {
00754     // Extract the index of the item selected from the list, if any.
00755     INT32 i = pSelChangedMsg->pDlgOp->GetSelectedValueIndex(pSelChangedMsg->SetGadgetID);
00756     if (i == -1) i = NameGallery::Instance()->GetPropertyIndex();
00757 
00758     // Update the gallery's property index.
00759     NameGallery::Instance()->SetPropertyIndex((INT32) i);
00760     UpdateGadgets();
00761 }
00762 
00763 
00764 
00765 /**********************************************************************************************
00766 >   void OpNameGalleryPropIndexDesc::UpdateGadgets()
00767 
00768     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00769     Created:    26/4/99
00770     Purpose:    Sets the text in all the combos associated with this descriptor to the
00771                 currently selected Name gallery property index.
00772     SeeAlso:    OpDescriptor::BuildGadgetList
00773 **********************************************************************************************/
00774 
00775 void OpNameGalleryPropIndexDesc::UpdateGadgets()
00776 {
00777     // Create a list of all the gadget IDs
00778     List theGadgets;
00779     if (BuildGadgetList(&theGadgets))
00780     {
00781         // Iterate over each control in the list.
00782         INT32 nVal = NameGallery::Instance()->GetPropertyIndex();
00783         for (GadgetListItem* pgli = (GadgetListItem*) theGadgets.GetHead(); 
00784              pgli != 0; 
00785              pgli = (GadgetListItem*) theGadgets.GetNext(pgli))
00786         {
00787             // Set each control to display the text.
00788             pgli->pDialogOp->SetSelectedValueIndex(pgli->gidGadgetID, nVal);
00789         }
00790 
00791         // Tidy up.
00792         theGadgets.DeleteAll();
00793     }
00794 } 
00795 
00796 
00797 
00798 /**********************************************************************************************
00799 >   static SuperGallery* OpDisplayNameGallery::FindGallery()
00800 
00801     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00802     Created:    9/5/99
00803     Returns:    0 or a pointer to the Name gallery instance
00804     Purpose:    Finds the Name gallery class instance
00805     Notes:      The bars system always keeps one Name gallery alive for us.
00806                 If one is not found, this usually indicates that it can't be found
00807                 in bars.ini: Check that the 'Name' string *exactly* matches the
00808                 title string given in bars.ini.
00809                 Also check that bars.ini indicates the bar is of the NameGallery class
00810 **********************************************************************************************/
00811 
00812 SuperGallery* OpDisplayNameGallery::FindGallery()
00813 {
00814     SuperGallery* pOp = SuperGallery::FindSuperGallery(_R(IDD_NAMESGALLERY));
00815     if (!pOp) pOp=new NameGallery();
00816     ERROR3IF(pOp == 0 || pOp->GetRuntimeClass() != CC_RUNTIME_CLASS(NameGallery), 
00817         "OpDisplayNameGallery::FindGallery: Can't find the gallery in bars.ini!\n");
00818     return pOp;
00819 }
00820 
00821 
00822 
00823 /**********************************************************************************************
00824 >   static OpState OpDisplayNameGallery::GetState(String_256*, OpDescriptor*)
00825 
00826     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00827     Created:    9/5/99
00828     Purpose:    For finding the OpDisplayNameGallery's state. 
00829 **********************************************************************************************/
00830 
00831 OpState OpDisplayNameGallery::GetState(String_256* UIDescription, OpDescriptor*)
00832 {
00833     // If the gallery is currently open, then the menu item should be ticked
00834     OpState OpSt;  
00835     SuperGallery* pSuperGallery = FindGallery();
00836     if (pSuperGallery != 0) OpSt.Ticked = pSuperGallery->IsVisible();
00837 
00838     // If there are no open documents, you can't toggle the gallery
00839     OpSt.Greyed = (Document::GetSelected() == 0);
00840     return OpSt;
00841 }
00842 
00843 
00844 
00845 /**********************************************************************************************
00846 >   void OpDisplayNameGallery::Do(OpDescriptor*)
00847 
00848     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00849     Created:    9/5/99
00850     Purpose:    Displays the Names gallery
00851                 Updates the button state for this Op (the button sticks down while the
00852                 gallery is open)
00853 **********************************************************************************************/
00854 
00855 void OpDisplayNameGallery::Do(OpDescriptor*)
00856 {
00857     SuperGallery* pOp = FindGallery();
00858     if (pOp != 0)
00859     {
00860         // Toggle the visible state of the gallery window
00861         pOp->SetVisibility(!pOp->IsVisible());
00862         SGInit::UpdateGalleryButton(_R(OPTOKEN_DISPLAY_NAME_GALLERY), pOp->IsVisible());
00863     }
00864 
00865     End();
00866 }
00867 
00868 
00869 
00870 /**********************************************************************************************
00871 >   static BOOL OpDisplayNameGallery::Init()
00872 
00873     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00874     Created:    9/5/99
00875     Returns:    0 or a pointer to the Name gallery instance
00876     Purpose:    Initialises the Attribute gallery and it's associated gadgets.
00877 **********************************************************************************************/
00878 
00879 BOOL OpDisplayNameGallery::Init()
00880 {
00881     ERRORIF(new OpNameGalleryPropIndexDesc == 0, _R(IDE_NOMORE_MEMORY), FALSE);
00882     return OpDisplayNameGallery::RegisterOpDescriptor(
00883                     0,
00884                     _R(IDS_DISPLAY_NAME_GALLERY),
00885                     CC_RUNTIME_CLASS(OpDisplayNameGallery),
00886                     OPTOKEN_DISPLAY_NAME_GALLERY,
00887                     OpDisplayNameGallery::GetState,
00888                     0,
00889                     _R(IDBBL_DISPLAY_NAME_GALLERY),
00890                     _R(IDC_BTN_SGNAME), // UINT32 resourceID = 0,   // resource ID
00891                     _R(IDC_BTN_SGNAME), // UINT32 controlID = 0,    // control ID
00892                     SYSTEMBAR_ILLEGAL,    // SystemBarType GroupBarID = SYSTEMBAR_ILLEGAL,  // group bar ID
00893                     TRUE,     // BOOL ReceiveMessages = TRUE,   // BODGE
00894                     FALSE,    // BOOL Smart = FALSE,
00895                     TRUE,     // BOOL Clean = TRUE,   
00896                     NULL,     // OpDescriptor *pVertOpDesc = NULL,
00897                     0,    // UINT32 OneOpenInstID = 0,      
00898                     0,    // UINT32 AutoStateFlags = 0,
00899                     TRUE      // BOOL fCheckable = FALSE
00900                     );
00901 }

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