barcreationdlg.cpp

Go to the documentation of this file.
00001 // $Id: barcreationdlg.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 #include "camtypes.h"
00099 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00100 #include "barcreationdlg.h"     //This file's header
00101 #include "menuops.h"    
00102 #include "ccdc.h"           // specific #includes needed for kernel-rendered dialogues
00103 //#include "barsdlgs.h"     // _R(IDD_BARCONTROLSTORE)
00104 //#include "simon.h"            // contians the resources of the dlg
00105 //#include "sliceres.h"     // more resources
00106 //#include "resimmap.h"
00107 #include "nodetxts.h"
00108 #include "sprdmsg.h"    // SpreadMsg
00109 #include "slice.h" // so export can invoke this op
00110 #include "opbarcreation.h" // to invoke the create op
00111 #include "slicetool.h" // for the findstate static fn
00112 
00113 // these are for the template attribute definitions
00114 // required for the scanning for existing bar attribs
00115 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 #include "userattr.h"
00117 #include "tmpltatr.h"
00118 
00119 #include "layermsg.h"   // the layer messaging
00120 
00121 // named set stuff
00122 #include "ngcore.h"
00123 #include "ngitem.h"
00124 #include "ngsentry.h"
00125 #include "ngsetop.h"
00126 
00127 //#include "resource.h" // for _R(IDS_CANCEL)
00128 
00129 #include "xshelpid.h"
00130 
00131 
00132 CC_IMPLEMENT_DYNCREATE(BarCreationDlg, DialogOp);
00133 CC_IMPLEMENT_DYNCREATE(BarStatesDlg, DialogOp);
00134 CC_IMPLEMENT_DYNCREATE(BarRedefineStateDlg, DialogOp);
00135 
00136 #define new CAM_DEBUG_NEW
00137 
00138 #define DLG_TIMER   2020
00139 
00140 // Set up our static variables
00141 const CDlgMode BarCreationDlg::Mode = MODELESS;
00142 const UINT32 BarCreationDlg::IDD = _R(IDD_BARCREATIONDLG);
00143 
00144 BarCreationDlg *BarCreationDlg::TheDialog = NULL;   
00145 
00146 
00147 // statics to hold the status of the controls
00148 // so when the dlg is closed and re-openned they
00149 // remember what they were
00150 BOOL BarCreationDlg::ms_WantDefault = TRUE; 
00151 BOOL BarCreationDlg::ms_WantMouse = FALSE; 
00152 BOOL BarCreationDlg::ms_WantClicked = FALSE; 
00153 BOOL BarCreationDlg::ms_WantSelected = FALSE; 
00154 BOOL BarCreationDlg::ms_IsVertical = TRUE; 
00155 BOOL BarCreationDlg::ms_SuggestDesign = TRUE;
00156 BOOL BarCreationDlg::ms_Continuous = TRUE;
00157 BOOL BarCreationDlg::ms_FromSelection = TRUE;
00158 INT32 BarCreationDlg::ms_StateToCreate = 0;
00159 INT32 BarCreationDlg::ms_SizeJustification = 0;
00160  
00161 INT32 BarCreationDlg::ms_NoOfButtons = 4; 
00162 INT32 BarCreationDlg::ms_Spacing = 0; 
00163 INT32 BarCreationDlg::ms_Mode = NEW_BAR; 
00164 INT32 BarCreationDlg::ms_Stretching = 0;
00165 BOOL BarCreationDlg::ms_GroupsStretch = TRUE;
00166 
00167 /*******************************************************************************************
00168 
00169 >   BarCreationDlg::BarCreationDlg() : DialogOp(RenderDlg::IDD, RenderDlg::Mode) 
00170 
00171     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> from Alex
00172     Created:    13/8/99
00173     Purpose:    Constructor
00174 
00175 *******************************************************************************************/
00176 
00177 BarCreationDlg::BarCreationDlg() : DialogOp(BarCreationDlg::IDD, BarCreationDlg::Mode) 
00178 {
00179     //Set our member variable pointer so it points at ourself
00180     if (TheDialog == NULL)
00181         TheDialog = this;
00182 
00183     m_IsEditing = FALSE;
00184     m_FirstIsEditing = FALSE;
00185     m_AlreadyInThisFunction = FALSE;
00186     m_HasBackBar = FALSE;
00187     m_ValidBar = TRUE;
00188 }       
00189 
00190 
00191 
00192 /*******************************************************************************************
00193 
00194 >   BarCreationDlg::~BarCreationDlg()
00195 
00196     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> from Alex
00197     Created:    13/8/99
00198     Purpose:    Destructor
00199 
00200 *******************************************************************************************/
00201 
00202 BarCreationDlg::~BarCreationDlg()
00203 {
00204     //Set our member variable pointer to NULL
00205     if (TheDialog == this)
00206         TheDialog = NULL;
00207 } 
00208  
00209 /********************************************************************************************
00210 >   MsgResult BarCreationDlg::Message( Msg* Message)
00211 
00212     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00213     Created:    13/8/99
00214     Inputs:     Message: The incoming message 
00215         
00216     Returns:    DialogOp::Message (Message)
00217 
00218     Purpose:    This is the message handler for the BarCreationDlg. It simply takes the
00219                 message and redirects it to one of our Message Handler functions.
00220      
00221 ********************************************************************************************/
00222 
00223 MsgResult BarCreationDlg::Message( Msg* Message)
00224 {
00225     BOOL fEndDialog=FALSE;
00226 
00227     //If the message is a dialog message
00228     if (IS_OUR_DIALOG_MSG(Message))
00229     {
00230         //Then work out what it says
00231         DialogMsg* pDialogMsg = ((DialogMsg*) Message); 
00232     
00233         switch (pDialogMsg->DlgMsg)
00234         {
00235             case DIM_CREATE:
00236                 SetStringGadgetValue(_R(IDC_BC_DIRECTION), _R(IDS_HORIZ), FALSE, 0);
00237                 SetStringGadgetValue(_R(IDC_BC_DIRECTION), _R(IDS_VERT), FALSE, 1);
00238                 SetStringGadgetValue(_R(IDC_BC_DIRECTION), _R(IDS_SCATTERED), TRUE, 2);
00239 
00240                 SetStringGadgetValue(_R(IDC_BC_BUTTON_SIZE), _R(IDS_EXTENDS), FALSE, 0);
00241                 SetStringGadgetValue(_R(IDC_BC_BUTTON_SIZE), _R(IDS_SCALES), FALSE, 1);
00242                 SetStringGadgetValue(_R(IDC_BC_BUTTON_SIZE), _R(IDS_IS_STATIC), TRUE, 2);
00243 
00244                 SetStringGadgetValue(_R(IDC_BC_BUTTONS_SAME), _R(IDS_BUTTONS_SAME_SIZE), FALSE, 0);
00245                 SetStringGadgetValue(_R(IDC_BC_BUTTONS_SAME), _R(IDS_BUTTONS_LEFT_SIZE), FALSE, 1);
00246                 SetStringGadgetValue(_R(IDC_BC_BUTTONS_SAME), _R(IDS_BUTTONS_RIGHT_SIZE), FALSE, 2);
00247                 SetStringGadgetValue(_R(IDC_BC_BUTTONS_SAME), _R(IDS_BUTTONS_DIFF_SIZE), TRUE, 3);
00248                 
00249                 SetUpControls();
00250 
00251                 // throw the keyboard focus
00252                 //DialogManager::DefaultKeyboardFocus();
00253                 break;
00254     
00255             // these two messages are used to throw the focus back to the main window
00256             case DIM_TITLEFOCUSWARN:
00257                 //DialogManager::DefaultKeyboardFocus();
00258                 break;
00259 
00260             // focus throw
00261             case DIM_LFT_BN_UP:
00262                 //DialogManager::DefaultKeyboardFocus();
00263                 break;
00264 
00265             case DIM_CANCEL:    
00266                 fEndDialog = TRUE;
00267                 break;
00268 
00269             // special case to find the one typed into the field
00270             case DIM_TIMER:
00271                 {
00272                     KillTimer(DLG_TIMER);
00273                     INT32 NewNoOfButtons = GetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), 1, MAX_BUTTONS_IN_A_BAR);
00274 
00275                     if (NewNoOfButtons == 1)
00276                     {
00277                         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_SHORTENBAROP); 
00278                         if (pOpDesc != NULL)
00279                         {
00280                             OpParamShortenBar ParamShortenBar(m_BarName, NewNoOfButtons);
00281                             pOpDesc->Invoke(&ParamShortenBar);
00282                             // update the dialog value
00283                             ms_NoOfButtons = NewNoOfButtons;
00284                             SetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), ms_NoOfButtons);
00285                         }
00286                         else
00287                         {
00288                             ERROR3("Couldn't find OPTOKEN_SHORTENBAROP op descriptor");
00289                         }
00290                     }
00291                 }
00292                 break;
00293 
00294             case DIM_TEXT_CHANGED:
00295                 if (m_IsEditing)
00296                     switch(pDialogMsg->GadgetID)
00297                 {
00298                 case _R(IDC_BC_SPACING):
00299                     {
00300                     // the text has changed for the spacing field
00301                         INT32 spacing = 0;
00302                         BOOL Valid=0;
00303                         MILLIPOINT ActualSpacing = GetUnitGadgetValue(_R(IDC_BC_SPACING), PIXELS, -75000, 75000, 0, &Valid);
00304                         String_256 ActualText = GetStringGadgetValue(_R(IDC_BC_SPACING));
00305                         spacing = ActualSpacing;
00306 
00307 
00308                         if (Valid && !ActualText.IsEmpty() && ms_Spacing != spacing)
00309                         {
00310                             ms_Spacing = spacing;
00311 
00312                             if (m_IsEditing)
00313                                 WriteBarProperties();
00314                         }
00315                     }
00316                     //DialogManager::DefaultKeyboardFocus(); // throws focus
00317                     break;
00318 
00319                 case _R(IDC_BC_NO_OF_BUTTONS):
00320                     {
00321                     // the text has changed for the spacing field
00322                         INT32 NewNoOfButtons = GetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), 1, MAX_BUTTONS_IN_A_BAR);
00323 
00324                         // get what the set abr props are then
00325                         ReadBarProperties();
00326 
00327                         if (NewNoOfButtons > ms_NoOfButtons && NewNoOfButtons <= MAX_BUTTONS_IN_A_BAR)
00328                         {
00329                             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BARDUPLICATIONOP); 
00330                             if (pOpDesc != NULL)
00331                             {
00332                                 OpParamBarDuplication AddButtonsParam(m_BarName, m_BarName, NewNoOfButtons - ms_NoOfButtons, ms_Spacing, !ms_IsVertical);
00333                                 pOpDesc->Invoke(&AddButtonsParam);
00334 
00335                                 // update the dialog value
00336                                 ms_NoOfButtons = NewNoOfButtons;
00337                                 SetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), ms_NoOfButtons);
00338                             }
00339                             else
00340                             {
00341                                 ERROR3("Couldn't find OPTOKEN_BARDUPLICATIONOP op descriptor");
00342                             }
00343                         }
00344                         else
00345                         if (NewNoOfButtons < ms_NoOfButtons && NewNoOfButtons > 1)
00346                         {
00347                             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_SHORTENBAROP); 
00348                             if (pOpDesc != NULL)
00349                             {
00350                                 OpParamShortenBar ParamShortenBar(m_BarName, NewNoOfButtons);
00351                                 pOpDesc->Invoke(&ParamShortenBar);
00352                                 // update the dialog value
00353                                 ms_NoOfButtons = NewNoOfButtons;
00354                                 SetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), ms_NoOfButtons);
00355                             }
00356                             else
00357                             {
00358                                 ERROR3("Couldn't find OPTOKEN_SHORTENBAROP op descriptor");
00359                             }
00360                         }
00361                         else
00362                         if (NewNoOfButtons < ms_NoOfButtons && NewNoOfButtons == 1)
00363                         {
00364                             SetTimer(DLG_TIMER, 1000, NULL);
00365                         }
00366 
00367                     }
00368                     //DialogManager::DefaultKeyboardFocus(); // throws focus
00369                     break;
00370 
00371                 } // end switch
00372 
00373                 break;
00374 
00375             // manage button controls
00376             case DIM_LFT_BN_CLICKED:
00377                 switch(pDialogMsg->GadgetID)
00378                 {
00379                 case _R(IDC_BC_CREATE):
00380                     if (m_IsEditing)
00381                     { // open up the states dlg
00382                         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BARSTATESDLG); 
00383                         if (pOpDesc != NULL)
00384                         {
00385                             OpParamBarStatesDlg ParamBarStatesDlg(m_BarName);
00386                             pOpDesc->Invoke(&ParamBarStatesDlg);
00387                         }
00388 
00389                     }
00390                     else
00391                     {
00392                         if(CreateBar()) // behave in a modal manner - close the dialog having done the deed.
00393                         {
00394                             fEndDialog = TRUE;
00395                             m_IsEditing = TRUE;
00396                             SetUpControls(TRUE);
00397                         }
00398                     }
00399                     break;
00400 
00401                 case _R(IDC_BC_REDEF_BACKBAR):
00402                     if (m_IsEditing)
00403                     {
00404                         // create a back bar
00405                         INT32 temp = ms_StateToCreate;
00406                         ms_StateToCreate = BACKBAR;
00407                         CreateBar();
00408                         ms_StateToCreate = temp;
00409                         SetUpControls(TRUE);
00410                     }
00411                     break;
00412 
00413                 case _R(IDC_BC_GROUPS_STRETCH):
00414                     ms_GroupsStretch = !GetBoolGadgetSelected(_R(IDC_BC_GROUPS_STRETCH));
00415                     if (m_IsEditing)
00416                         WriteBarProperties();
00417                     break;
00418                 }
00419                 //DialogManager::DefaultKeyboardFocus(); // throws focus
00420                 break;
00421 
00422             
00423                 //NB: This means someone has altered the combo box. It doesn't mean
00424                 //the selection has changed!
00425             case DIM_SELECTION_CHANGED: 
00426                 switch(pDialogMsg->GadgetID)
00427                 {
00428                     // changed the direction of the bar
00429                 case _R(IDC_BC_DIRECTION):
00430                     switch (GetSelectedValueIndex(_R(IDC_BC_DIRECTION)))
00431                     {
00432                     case 0: // horz
00433                         ms_IsVertical = FALSE;
00434                         ms_Continuous = TRUE;
00435                         break;
00436 
00437                     case 1: // vert
00438                         ms_IsVertical = TRUE;
00439                         ms_Continuous = TRUE;
00440                         break;
00441 
00442                     case 2: // scattered
00443                         ms_IsVertical = TRUE;
00444                         ms_Continuous = FALSE;
00445                         break;
00446                     }
00447 
00448                     EnableGadget(_R(IDC_BC_SPACING), ms_Continuous && m_ValidBar);
00449 
00450                     if (m_IsEditing) // update the bar direction now!
00451                         WriteBarProperties();
00452 
00453                     //DialogManager::DefaultKeyboardFocus(); // throws focus
00454                     break;
00455 
00456                 case _R(IDC_BC_BUTTONS_SAME):
00457                     ms_SizeJustification = GetSelectedValueIndex(_R(IDC_BC_BUTTONS_SAME));
00458 
00459                     if (m_IsEditing)
00460                         WriteBarProperties();
00461                     //DialogManager::DefaultKeyboardFocus(); // throws focus
00462                     break;
00463 
00464                 case _R(IDC_BC_BUTTON_SIZE):
00465                     ms_Stretching = GetSelectedValueIndex(_R(IDC_BC_BUTTON_SIZE));
00466                     EnableGadget(_R(IDC_BC_GROUPS_STRETCH), ms_Stretching ? 0 : 1);
00467                     if (m_IsEditing)
00468                     {
00469                         BYTE ExtendFlags = 0; // dont extend
00470 
00471                         if (ms_Stretching == 0)
00472                         {
00473                             ExtendFlags = X_EXTEND | Y_EXTEND;
00474                         }
00475                         else
00476                             if (ms_Stretching == 1)
00477                             {
00478                                 ExtendFlags = X_STRETCH | Y_STRETCH;
00479                             }
00480 
00481                         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_CHANGE_BAR_EXTENDS); 
00482                         if (pOpDesc != NULL)
00483                         {
00484                             OpParam BarStretchParam(SliceHelper::GetBarNumberFromBarName(m_BarName), ExtendFlags);
00485                             pOpDesc->Invoke(&BarStretchParam);
00486                         }
00487                         else
00488                         {
00489                             ERROR3("Couldn't find OPTOKEN_CHANGE_BAR_EXTENDS op descriptor");
00490                         }
00491 
00492                         WriteBarProperties();
00493                     }
00494                     //DialogManager::DefaultKeyboardFocus(); // throws focus
00495                     break;
00496 
00497                 }
00498                 break;
00499         }
00500     }
00501     else if (MESSAGE_IS_A(Message, OpMsg))
00502     {
00503         if (((OpMsg *)Message)->MsgType == OpMsg::AFTER_UNDO ||
00504             ((OpMsg *)Message)->MsgType == OpMsg::AFTER_REDO ||
00505             IS_A( ((OpMsg *)Message)->pOp, OpDelete) )
00506         {
00507             ReadBarProperties(); // set the controls from what the bar thinks it is
00508             SetUpControls(TRUE); // set all the controls
00509         }
00510     }
00511     // for whenever someone announces that they have changed the selection.
00512     else if (MESSAGE_IS_A(Message, SelChangingMsg))
00513     {
00514         SelChangingMsg* pSelChange = (SelChangingMsg*)Message;
00515 
00516         if (pSelChange->State == SelChangingMsg::SelectionState::SELECTIONCHANGED ||
00517             pSelChange->State == SelChangingMsg::SelectionState::NONCOLOURATTCHANGED)
00518         {
00519             SetUpDynamicControls();
00520         }
00521     }
00522     // If we've changed to a different document then get rid of the dlg.
00523     else if (MESSAGE_IS_A(Message, DocChangingMsg))
00524     {
00525         DocChangingMsg* TheMsg = (DocChangingMsg*) Message;
00526         if (TheMsg->State == DocChangingMsg::BORN || TheMsg->State == DocChangingMsg::SELCHANGED)
00527             Close();
00528     }
00529         
00530     if (fEndDialog) 
00531     {
00532         // read the number of buttons if the dlg is closed
00533         // so we don't have to re-type
00534         ms_NoOfButtons = GetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), 1, 20);
00535         if (ms_NoOfButtons > 20) ms_NoOfButtons = 20;
00536         if (ms_NoOfButtons < 1) ms_NoOfButtons = 1;
00537 
00538         // close the dlg
00539         Close();           
00540         End();
00541     }
00542 
00543 
00544     return DialogOp::Message(Message);
00545 } 
00546 
00547 /*******************************************************************************************
00548 
00549 >   OpState BarCreationDlg::GetState(String_256*, OpDescriptor*)
00550 
00551     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Alex
00552     Created:    13/8/99
00553     Purpose:    Returns the OpState of the dialogue operation
00554 
00555 *******************************************************************************************/
00556 
00557 OpState BarCreationDlg::GetState(String_256*, OpDescriptor*)
00558 {
00559     OpState OpSt;
00560 
00561     // if we don't allow it
00562     OpSt.Greyed = TRUE;
00563     Spread* pSpread = Document::GetSelectedSpread();
00564     if (pSpread && !pSpread->FindActiveLayer()->IsFrame())
00565         OpSt.Greyed = FALSE;
00566 
00567     // Tick the menu while the editor is open
00568     if (TheDialog != NULL)
00569         OpSt.Ticked = TRUE;
00570 
00571     return(OpSt);
00572 }
00573 
00574          
00575 
00576 /*******************************************************************************************
00577 
00578 >   BOOL BarCreationDlg::Init()
00579 
00580     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Alex
00581     Created:    13/8/99
00582     Returns:    FALSE if it fails (due to lack of memory)
00583     Purpose:    Creates an OpDescriptor for a HotLink Dialog and declares
00584                 some preferences
00585 
00586 *******************************************************************************************/
00587 BOOL BarCreationDlg::Init()
00588 {
00589     return (RegisterOpDescriptor(0,                             // Tool ID
00590                                 _R(IDS_BARCREATION),                    // String resource ID
00591                                 CC_RUNTIME_CLASS(BarCreationDlg),       // Runtime class
00592                                 OPTOKEN_BARCREATIONDLG,             // Token string
00593                                 BarCreationDlg::GetState,               // GetState function
00594                                 _R(IDH_NavBar_Create_Dialog_Box),                               // Help ID
00595                                 _R(IDBBL_BARCREATION),              // Bubble ID
00596                                 _R(IDD_BARCONTROLSTORE),            // Resource ID
00597                                 _R(IDC_BARCREATION),                // Control ID
00598                                 SYSTEMBAR_UTILITIES,            // Bar ID
00599                                 TRUE,                           // Recieve system messages
00600                                 FALSE,                          // Smart duplicate operation
00601                                 TRUE,                           // Clean operation
00602                                 0,                              // No vertical counterpart
00603                                 NULL,
00604                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC),
00605                                 TRUE
00606                                 )); 
00607                         
00608 }   
00609  
00610       
00611 
00612 
00613 /********************************************************************************************
00614 
00615 >   void BarCreationDlg::Do(OpDescriptor*)
00616 
00617     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Jason
00618     Created:    13/8/99
00619 
00620     Purpose:    Opens the dialog if it is closed. Closes it if it is open.
00621                 Should no longer be called, but use the with param instead
00622         
00623 ********************************************************************************************/
00624 
00625 void BarCreationDlg::Do(OpDescriptor*)
00626 {
00627     m_IsEditing = FALSE;
00628     m_BarName = "Bar1";
00629     m_FirstBarName = m_BarName;
00630     ms_Spacing = 0; // reset the spacing to zero
00631 
00632     if (TheDialog==NULL || TheDialog==this)
00633     {
00634         if (Create())
00635             Open();
00636         else
00637             End();
00638     }
00639     else
00640     {
00641         TheDialog->Open();
00642         TheDialog->BringToTop();
00643 
00644         End();              // Kill ourself
00645     }
00646 }
00647 
00648 /********************************************************************************************
00649 
00650 >   BOOL BarCreationDlg::Create()
00651 
00652     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Jason
00653     Created:    13/8/99
00654     Inputs:     -
00655     Outputs:    -
00656     Returns:    FALSE if it fails
00657     Purpose:    Creates a Web Address dialogue box. Fails if DialogOp::Create
00658                 fails to create the box.
00659     Errors:     -
00660     SeeAlso:    -
00661 
00662 ********************************************************************************************/
00663 
00664 BOOL BarCreationDlg::Create()
00665 {
00666 
00667     ReadBarProperties();    
00668 
00669     // manipulate the ticks if we are editing a state
00670     if (!m_IsEditing)
00671         // if we are creating we must create the default state
00672     {
00673         ms_StateToCreate = 0; // create the off state as default
00674         ms_FromSelection = TRUE; // from the selection of course
00675 
00676         ms_WantDefault = TRUE;
00677         ms_WantMouse = FALSE;
00678         ms_WantClicked = FALSE;
00679         ms_WantSelected = FALSE;
00680 
00681         ms_Spacing = 0; // reset the spacing to zero
00682         ms_GroupsStretch = TRUE;
00683     }
00684 
00685 
00686     if (TheDialog != this)      // Allow only one instance of this dialogue open at once
00687         return(FALSE);
00688 
00689     if (DialogOp::Create())
00690     { 
00691         return(TRUE);
00692     }
00693 
00694     return(FALSE);
00695 }
00696 
00697 /********************************************************************************************
00698 
00699 >   void BarCreationDlg::DoWithParam(OpDescriptor* pOp, OpParam* pParam)       
00700 
00701     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Alex
00702     Created:    13/8/99
00703     Inputs:     OpDescriptor
00704     Outputs:    -
00705     Returns:    -
00706     Purpose:    Performs the BarCreationDlg operation
00707     Errors:     -
00708     SeeAlso:    -
00709 
00710 ********************************************************************************************/
00711 
00712 void BarCreationDlg::DoWithParam(OpDescriptor* pOp, OpParam* pParam)
00713 {
00714     m_IsEditing = ((OpParamBarCreationDlg *)pParam)->m_IsEditing;
00715     m_BarName = ((OpParamBarCreationDlg *)pParam)->m_BarName;
00716     m_FirstBarName = m_BarName;
00717     m_FirstIsEditing = m_IsEditing;
00718 
00719     if (((OpParamBarCreationDlg *)pParam)->m_ButtonsToEdit)
00720         ms_NoOfButtons = ((OpParamBarCreationDlg *)pParam)->m_ButtonsToEdit;
00721 
00722     if (TheDialog==NULL || TheDialog==this)
00723     {
00724         if (Create())
00725         {
00726             Open();
00727             SetUpControls(TRUE);
00728         }
00729         else
00730             End();
00731     }
00732     else
00733     {
00734         TheDialog->Open();
00735         TheDialog->BringToTop();
00736 
00737         TheDialog->m_IsEditing = ((OpParamBarCreationDlg *)pParam)->m_IsEditing;
00738         TheDialog->m_BarName = ((OpParamBarCreationDlg *)pParam)->m_BarName;
00739         TheDialog->m_FirstBarName = m_BarName;
00740         TheDialog->m_FirstIsEditing = m_IsEditing;
00741         TheDialog->m_ValidBar = TRUE;
00742         TheDialog->ms_Spacing = 0; // reset the spacing to zero
00743         TheDialog->ms_GroupsStretch = TRUE;
00744 
00745         TheDialog->EnableAllMyControls(TRUE);
00746 
00747         TheDialog->SetUpControls(TRUE);
00748 
00749         End();              // Kill ourself
00750     }
00751 }
00752 
00753 
00754 /********************************************************************************************
00755 
00756 >   BOOL BarCreationDlg::SetUpControls( BOOL DoScan )
00757 
00758     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00759     Created:    18/8/99
00760     Returns:    TRUE always at present!
00761     Purpose:    Spookily enough it sets up all the controls in the dlg
00762 
00763 ********************************************************************************************/
00764 
00765 BOOL BarCreationDlg::SetUpControls( BOOL DoScan )
00766 {
00767     if (m_AlreadyInThisFunction)
00768         return TRUE;
00769 
00770     SetUpDynamicControls();
00771 
00772     m_AlreadyInThisFunction = TRUE;
00773     if (m_IsEditing)
00774     {
00775         if (DoScan)
00776         {
00777             // find out how many buttons there are
00778             INT32 NumberOfButtons = SliceHelper::CountButtonsInBar(m_BarName);
00779             if (NumberOfButtons > 0)
00780                 ms_NoOfButtons = NumberOfButtons;
00781 
00782             String_256 BackBarLayer(_R(IDS_BACK_BAR));
00783             m_HasBackBar = SliceHelper::BarExistsOnLayer(m_BarName, BackBarLayer);
00784         }
00785 
00786         if (m_HasBackBar)
00787         {
00788             SetStringGadgetValue(_R(IDC_BC_REDEF_BACKBAR), _R(IDS_REDEFINE_BACKBAR)); // Redefine
00789             SetStringGadgetValue(_R(IDC_BACKBAR_TEXT), _R(IDS_RECREATE_BACKBAR_TEXT));
00790         }
00791         else
00792         {
00793             SetStringGadgetValue(_R(IDC_BC_REDEF_BACKBAR), _R(IDS_CREATE_BACKBAR)); // Create
00794             SetStringGadgetValue(_R(IDC_BACKBAR_TEXT), _R(IDS_CREATE_BACKBAR_TEXT));
00795         }
00796     }
00797     else
00798     {
00799         // if we're creating a new bar, we must have the option for default to be ticked.
00800         ms_WantDefault = TRUE;
00801     }
00802 
00803     HideGadget(_R(IDC_BC_CREATE_BACKBAR), m_IsEditing);
00804     HideGadget(_R(IDC_BACKBAR_TEXT), !m_IsEditing);
00805     HideGadget(_R(IDC_BC_REDEF_BACKBAR), !m_IsEditing);
00806 
00807     SetSelectedValueIndex(_R(IDC_BC_BUTTONS_SAME), ms_SizeJustification);
00808     SetSelectedValueIndex(_R(IDC_BC_BUTTON_SIZE), ms_Stretching);
00809 
00810     SetStringGadgetValue(_R(IDC_BC_CREATE), m_IsEditing ? _R(IDS_CREATE_STATES) : _R(IDS_CREATE_STATE)); // States.. or Create
00811     HideGadget(_R(IDC_BC_CREATE), m_IsEditing); // actually hide the control if we are editing (remove states...)
00812     
00813     SetStringGadgetValue(IDCANCEL, m_IsEditing ? _R(IDS_DLG_DONE) : _R(IDS_CANCEL_DIALOG)); // Close or Cancel
00814 
00815     // grey the spacing if it is scattered
00816     EnableGadget(_R(IDC_BC_SPACING), ms_Continuous && m_ValidBar);
00817 
00818     if (!ms_Continuous)
00819         SetSelectedValueIndex(_R(IDC_BC_DIRECTION), 2);
00820     else
00821         SetSelectedValueIndex(_R(IDC_BC_DIRECTION), ms_IsVertical ? 1 : 0);
00822 
00823     SetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), ms_NoOfButtons);
00824     SetBoolGadgetSelected(_R(IDC_BC_GROUPS_STRETCH), !ms_GroupsStretch);
00825     EnableGadget(_R(IDC_BC_GROUPS_STRETCH), ms_Stretching ? 0 : 1);
00826 
00827     SetUnitGadgetValue(_R(IDC_BC_SPACING), PIXELS, ms_Spacing);
00828 
00829     String_256 Title;
00830     if (m_IsEditing)
00831         Title.Load(_R(IDS_BAR_EDIT_TITLE));
00832     else
00833         Title.Load(_R(IDS_BAR_CREATION_TITLE));
00834 
00835     if (m_ValidBar)
00836         Title += m_BarName;
00837     else
00838     {
00839         String_256 temp(_R(IDS_NO_VALID_BAR));
00840         Title += temp;
00841     }
00842 
00843     SetTitlebarName(&Title);
00844 
00845     m_AlreadyInThisFunction = FALSE;
00846 
00847     return TRUE;
00848 }
00849 
00850 
00851 /********************************************************************************************
00852 
00853 >   BOOL BarCreationDlg::SetUpDynamicControls()
00854 
00855     Author:     Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
00856     Created:    1/9/99
00857     Returns:    TRUE always at present!
00858     Purpose:    Sets up all the controls in the dlg that are
00859                 dynamic and reviewed upon a timer.
00860                 So this function is called on a poll, to read the
00861                 states and set the controls.
00862 
00863 ********************************************************************************************/
00864 BOOL BarCreationDlg::SetUpDynamicControls()
00865 {
00866     // show the current layer in the dlg
00867     String_256 LayerName = "";
00868     Spread* pSpread = Document::GetSelectedSpread();
00869     if (pSpread == NULL)
00870         return FALSE;
00871 
00872     SelRange * pSelection = GetApplication()->FindSelection();
00873 
00874     // scan the selection has the bar name changed?
00875 
00876     String_256 TempBarName = "";
00877 
00878     Node * pCurrent = pSelection->FindFirst();
00879     TemplateAttribute * pTemplAttrib = NULL;
00880     Node * pTempNode = NULL;
00881 
00882     BOOL HasASelection = pCurrent != NULL;
00883 
00884     while (pCurrent && TempBarName.IsEmpty())
00885     {
00886         // look at the bar name on the attrib
00887         pTemplAttrib = (TemplateAttribute *) SliceHelper::FindNextOfClass(pCurrent, pCurrent, CC_RUNTIME_CLASS(TemplateAttribute));
00888         while (pTemplAttrib && TempBarName.IsEmpty())
00889         {
00890             TempBarName = SliceHelper::GetBarName(pTemplAttrib);
00891             pTemplAttrib = (TemplateAttribute *) SliceHelper::FindNextOfClass(pTemplAttrib, pCurrent, CC_RUNTIME_CLASS(TemplateAttribute));
00892         }
00893 
00894         pCurrent = pSelection->FindNext(pCurrent);
00895     }
00896 
00897     // something is selected but that doesn't have a bar name
00898     if (HasASelection && TempBarName.IsEmpty() && m_IsEditing)
00899     {
00900         // does the selection intersect with any known bars?
00901         SliceHelper::BarNameInRect(pSelection->GetBoundingRect(), &TempBarName);
00902     }
00903 
00904     if (m_IsEditing && HasASelection && TempBarName.IsEmpty() && m_ValidBar)
00905     {
00906         m_ValidBar = FALSE;
00907         EnableAllMyControls(FALSE);
00908         SetUpControls(FALSE);
00909     }
00910     else
00911         if (!m_ValidBar && !TempBarName.IsEmpty() )
00912         {
00913             m_ValidBar = TRUE;
00914             EnableAllMyControls(TRUE);
00915             m_BarName = "";
00916         }
00917 
00918     if (TempBarName.CompareTo(m_BarName) != 0 && !TempBarName.IsEmpty())
00919     {
00920         m_BarName = TempBarName;
00921         m_IsEditing = TRUE;
00922         ReadBarProperties();
00923         SetUpControls();
00924     }
00925 
00926     // enable disable the create button if there is no selection
00927     EnableGadget(_R(IDC_BC_CREATE), m_ValidBar && (HasASelection || m_IsEditing));
00928     // enable disable the create backbar button if there is no selection
00929     EnableGadget(_R(IDC_BC_REDEF_BACKBAR), m_ValidBar && HasASelection);
00930     
00931     return TRUE;
00932 }
00933 
00934 void BarCreationDlg::EnableAllMyControls(BOOL enable)
00935 {
00936     EnableGadget(_R(IDC_BC_NO_OF_BUTTONS),  enable);
00937     EnableGadget(_R(IDC_BC_DIRECTION),      enable);
00938     EnableGadget(_R(IDC_BC_SPACING),        enable);
00939     EnableGadget(_R(IDC_BC_BUTTON_SIZE),    enable);
00940     EnableGadget(_R(IDC_BC_BUTTONS_SAME),   enable);
00941     EnableGadget(_R(IDC_BC_REDEF_BACKBAR),  enable);
00942     EnableGadget(_R(IDC_BC_CREATE),         enable);
00943 }
00944 
00945 
00946 BOOL BarCreationDlg::CreateBar()
00947 {
00948     BOOL Valid = TRUE;
00949     ms_NoOfButtons = GetLongGadgetValue(_R(IDC_BC_NO_OF_BUTTONS), 1, 20, 0 /*error id*/, &Valid);
00950     if (!Valid)
00951     {
00952         InformWarning(_R(IDS_TOO_MANY_BUTTONS));
00953         return FALSE;
00954     }
00955 
00956     // run the Op that does the copying of the selection / bar creation bit
00957 
00958     BOOL MakeBackBarAswell = !m_IsEditing && GetBoolGadgetSelected(_R(IDC_BC_CREATE_BACKBAR));
00959 
00960     ms_WantDefault = FALSE;
00961     ms_WantMouse = FALSE;
00962     ms_WantClicked = FALSE;
00963     ms_WantSelected = FALSE;
00964     switch(ms_StateToCreate)
00965     {
00966     case 0:
00967         ms_WantDefault = TRUE;
00968         break;
00969 
00970     case 1:
00971         ms_WantMouse = TRUE;
00972         break;
00973 
00974     case 2:
00975         ms_WantClicked = TRUE;
00976         break;
00977 
00978     case 3:
00979         ms_WantSelected = TRUE;
00980         break;
00981 
00982     }
00983 
00984     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BARCREATIONOP); 
00985     if (pOpDesc != NULL)
00986     {
00987         // set the mode of the create from
00988         // the editing flag for now
00989         if (m_IsEditing)
00990             ms_Mode = REPLACE_SOME_STATES;
00991         else
00992         {
00993             ms_Mode = NEW_BAR;
00994 
00995             // the text has changed for the spacing field
00996             INT32 spacing = 0;
00997             BOOL Valid=0; 
00998             MILLIPOINT ActualSpacing = GetUnitGadgetValue(_R(IDC_BC_SPACING), PIXELS, 0, 75000, 0, &Valid);
00999             String_256 ActualText = GetStringGadgetValue(_R(IDC_BC_SPACING));
01000             spacing = ActualSpacing;
01001 
01002             if (Valid && !ActualText.IsEmpty() && ms_Spacing != spacing)
01003             {
01004                 ms_Spacing = spacing;
01005             }
01006         }
01007 
01008         // add the bar details
01009         WriteBarProperties();
01010 
01011         BYTE ExtendFlags = 0; // dont extend
01012 
01013         if (ms_Stretching == 0)
01014             ExtendFlags = X_EXTEND | Y_EXTEND;
01015         else
01016             if (ms_Stretching == 1)
01017                 ExtendFlags = X_STRETCH | Y_STRETCH;
01018 
01019         OpParamBarCreation BarParam(ms_WantMouse,
01020                                     ms_WantClicked,
01021                                     ms_WantSelected,
01022                                     (ms_StateToCreate == BACKBAR) || MakeBackBarAswell,
01023                                     ms_IsVertical,
01024                                     ms_SuggestDesign,
01025                                     ms_NoOfButtons,
01026                                     ms_WantDefault,
01027                                     ms_Mode,
01028                                     ms_Spacing,
01029                                     ms_Continuous,
01030                                     ms_SizeJustification != 3, // are they the same size ?  0 = same centered 1 = same left 2 = same right 3 = independant
01031                                     m_BarName,
01032                                     (ms_StateToCreate == DEFAULT || ms_StateToCreate == BACKBAR) ? TRUE : ms_FromSelection,
01033                                     ExtendFlags);
01034         pOpDesc->Invoke(&BarParam);
01035     }
01036     else
01037     {
01038         ERROR3("Couldn't find OPTOKEN_BARCREATIONOP op descriptor");
01039     }
01040 
01041     return TRUE;
01042 }
01043 
01044 
01045 
01046 
01047 
01048 void BarCreationDlg::ReadBarProperties()
01049 {
01050     NodeBarProperty* pNodeBarProperty = (NodeBarProperty*) Document::GetCurrent()->GetSetSentinel()->FindBarProperty();
01051     INT32 BarNumber = SliceHelper::GetBarNumberFromBarName(m_BarName);
01052 
01053     if (pNodeBarProperty && BarNumber < pNodeBarProperty->HowMany())
01054     {
01055         BarDataType NewBarData = pNodeBarProperty->Bar(BarNumber);
01056         ms_IsVertical = NewBarData.IsHorizontal ? FALSE : TRUE;
01057         ms_Continuous = NewBarData.RequiresShuffle;
01058         ms_SizeJustification = NewBarData.SameSize;
01059         ms_Spacing = NewBarData.Spacing;
01060         ms_Stretching = 2; // static no stretching
01061         if (NewBarData.ButtonsExtend)
01062             ms_Stretching = 0;
01063         else if (NewBarData.ButtonsScale)
01064             ms_Stretching = 1;
01065         ms_GroupsStretch = NewBarData.GroupsStretch;
01066     }
01067 }
01068 
01069 void BarCreationDlg::WriteBarProperties()
01070 {
01071     NodeBarProperty* pNodeBarProperty = (NodeBarProperty*) Document::GetCurrent()->GetSetSentinel()->FindBarProperty();
01072     INT32 BarNumber = SliceHelper::GetBarNumberFromBarName(m_BarName);
01073 
01074     if (pNodeBarProperty )
01075     {
01076         BarDataType NewBarData;
01077 
01078         NewBarData.IsHorizontal = !ms_IsVertical;
01079         NewBarData.RequiresShuffle = ms_Continuous;
01080         NewBarData.SameSize = ms_SizeJustification;
01081         NewBarData.Spacing = ms_Spacing;
01082         NewBarData.ButtonsExtend = (ms_Stretching == 0 ? 1 : 0);
01083         NewBarData.ButtonsScale = (ms_Stretching == 1 ? 1 : 0);
01084         NewBarData.GroupsStretch = ms_GroupsStretch;
01085 
01086         pNodeBarProperty->MakeChange(BarNumber, NewBarData);
01087         // tell everyone that the selection may have changed
01088         // actually it wont have but the position of the blobs may well have
01089         // and sending this message means that everyone like the tool will
01090         // re-evaluate the postitions of the selection (sjk 11/7/00)
01091         BROADCAST_TO_ALL(SelChangingMsg(SelChangingMsg::NONCOLOURATTCHANGED));
01092     }
01093 }
01094 
01095 
01096 /*****************************************************************************************************/
01097 
01098 // Set up our static variables
01099 const CDlgMode BarStatesDlg::Mode = MODELESS;
01100 const UINT32 BarStatesDlg::IDD = _R(IDD_BARSTATESDLG);
01101 
01102 BarStatesDlg *BarStatesDlg::TheDialog = NULL;
01103 INT32 BarStatesDlg::m_State = 1;
01104 BOOL BarStatesDlg::ms_SuggestDesign = TRUE;
01105 
01106 
01107 /*******************************************************************************************
01108 
01109 >   BarStatesDlg::BarStatesDlg() : DialogOp(RenderDlg::IDD, RenderDlg::Mode) 
01110 
01111     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01112     Created:    8/5/00
01113     Purpose:    Constructor
01114 
01115 *******************************************************************************************/
01116 
01117 BarStatesDlg::BarStatesDlg() : DialogOp(BarStatesDlg::IDD, BarStatesDlg::Mode) 
01118 {
01119     //Set our member variable pointer so it points at ourself
01120     if (TheDialog == NULL)
01121         TheDialog = this;
01122 
01123     m_ValidBar = TRUE;
01124 }       
01125 
01126 
01127 
01128 /*******************************************************************************************
01129 
01130 >   BarStatesDlg::~BarStatesDlg()
01131 
01132     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> from Alex
01133     Created:    13/8/99
01134     Purpose:    Destructor
01135 
01136 *******************************************************************************************/
01137 
01138 BarStatesDlg::~BarStatesDlg()
01139 {
01140     //Set our member variable pointer to NULL
01141     if (TheDialog == this)
01142         TheDialog = NULL;
01143 } 
01144  
01145 /********************************************************************************************
01146 >   MsgResult BarStatesDlg::Message( Msg* Message)
01147 
01148     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01149     Created:    8/5/00
01150     Inputs:     Message: The incoming message 
01151         
01152     Returns:    DialogOp::Message (Message)
01153 
01154     Purpose:    This is the message handler for the BarStatesDlg. It simply takes the
01155                 message and redirects it to one of our Message Handler functions.
01156      
01157 ********************************************************************************************/
01158 
01159 MsgResult BarStatesDlg::Message( Msg* Message)
01160 {
01161     BOOL fEndDialog=FALSE;
01162 
01163     //If the message is a dialog message
01164     if (IS_OUR_DIALOG_MSG(Message))
01165     {
01166         //Then work out what it says
01167         DialogMsg* pDialogMsg = ((DialogMsg*) Message); 
01168     
01169         switch (pDialogMsg->DlgMsg)
01170         {
01171             case DIM_CREATE:
01172                 SetStringGadgetValue(_R(IDC_MUTATE_COLOURS), _R(IDS_STATE_COPY), FALSE, 0);
01173                 SetStringGadgetValue(_R(IDC_MUTATE_COLOURS), _R(IDS_STATE_DISTINCT), TRUE, 1);
01174                 ScanForBarDetails();
01175                 SetUpControls();
01176                 // throw the keyboard focus
01177                 //DialogManager::DefaultKeyboardFocus();
01178                 break;
01179     
01180             // these two messages are used to throw the focus back to the main window
01181             case DIM_TITLEFOCUSWARN:
01182                 //DialogManager::DefaultKeyboardFocus();
01183                 break;
01184 
01185             // focus throw
01186             case DIM_LFT_BN_UP:
01187                 //DialogManager::DefaultKeyboardFocus();
01188                 break;
01189 
01190             case DIM_CANCEL:    
01191                 fEndDialog = TRUE;
01192                 break;
01193 
01194             // manage button controls
01195             case DIM_LFT_BN_CLICKED:
01196                 switch(pDialogMsg->GadgetID)
01197                 {
01198                 case _R(IDC_MOUSE_OFF):
01199                     m_State = 0;
01200                     SetUpControls();
01201                     //DialogManager::DefaultKeyboardFocus(); // throws focus
01202                     break;
01203                 case _R(IDC_MOUSE_OVER):
01204                     m_State = 1;
01205                     SetUpControls();
01206                     //DialogManager::DefaultKeyboardFocus(); // throws focus
01207                     break;
01208                 case _R(IDC_CLICKED):
01209                     m_State = 2;
01210                     SetUpControls();
01211                     //DialogManager::DefaultKeyboardFocus(); // throws focus
01212                     break;
01213                 case _R(IDC_SELECTED):
01214                     m_State = 3;
01215                     SetUpControls();
01216                     //DialogManager::DefaultKeyboardFocus(); // throws focus
01217                     break;
01218                 //case _R(IDC_BACK_BAR):
01219                 //  m_State = 4;
01220                 //  SetUpControls();
01221                 //  break;
01222 
01223                 case _R(IDC_CREATE_STATE):
01224                     // create the state
01225                     CreateBarStates(m_StateExists[m_State]);
01226                     ScanForBarDetails();
01227                     SetUpControls();
01228                     //DialogManager::DefaultKeyboardFocus(); // throws focus
01229                     break;
01230                     
01231                 case _R(IDC_DELETE_STATE):
01232                     {
01233                         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_DELBAROP);
01234 
01235                         if (pOpDesc && m_State > 0) // dont allow this to delete the MouseOff State!
01236                         {
01237                             OpParamDelBar ParamDelBar(m_BarName, m_State);
01238                             pOpDesc->Invoke(&ParamDelBar);
01239 
01240                             ScanForBarDetails();
01241                             SetUpControls();
01242                         }
01243                         else if (pOpDesc)
01244                         {
01245                             if (AskQuestion(_R(IDS_DEL_WHOLE_BAR), _R(IDS_YES), _R(IDS_NO)) == 1)
01246                             {
01247                                 OpParamDelBar ParamDelBar(m_BarName, 5 /* all states */);
01248                                 pOpDesc->Invoke(&ParamDelBar);
01249 
01250                                 // if the bar has been removed close this dlg
01251                                 fEndDialog = TRUE;
01252                             }
01253                         }
01254                     }
01255                     //DialogManager::DefaultKeyboardFocus(); // throws focus
01256                     break;
01257                 }
01258                 break;  
01259             
01260             //NB: This means someone has altered the combo box. It doesn't mean
01261             //the selection has changed!
01262             case DIM_SELECTION_CHANGED: 
01263                 switch(pDialogMsg->GadgetID)
01264                 {
01265                     // changed the direction of the bar
01266                     case _R(IDC_MUTATE_COLOURS):
01267                         ms_SuggestDesign = GetSelectedValueIndex(_R(IDC_MUTATE_COLOURS));;
01268                     break;
01269                 }
01270                 break;
01271 
01272         }
01273     }
01274     // for whenever someone announces that they have changed the selection.
01275     else if (MESSAGE_IS_A(Message, SelChangingMsg))
01276     {
01277         SelChangingMsg* pSelChange = (SelChangingMsg*)Message;
01278 
01279         if (pSelChange->State == SelChangingMsg::SelectionState::SELECTIONCHANGED ||
01280             pSelChange->State == SelChangingMsg::SelectionState::NONCOLOURATTCHANGED)
01281             OnSelectionChanged();
01282     }
01283     // If we've changed to a different document then get rid of the dlg.
01284     else if (MESSAGE_IS_A(Message, DocChangingMsg))
01285     {
01286         DocChangingMsg* TheMsg = (DocChangingMsg*) Message;
01287         if (TheMsg->State == DocChangingMsg::BORN || TheMsg->State == DocChangingMsg::SELCHANGED)
01288             Close();
01289     }
01290     else if (MESSAGE_IS_A(Message, OpMsg))
01291     {
01292         if (((OpMsg *)Message)->MsgType == OpMsg::AFTER_UNDO ||
01293             ((OpMsg *)Message)->MsgType == OpMsg::AFTER_REDO ||
01294             IS_A( ((OpMsg *)Message)->pOp, OpDelete) )
01295         {
01296             ScanForBarDetails();
01297             SetUpControls();
01298             OnSelectionChanged();
01299         }
01300     }
01301         
01302     if (fEndDialog) 
01303     {
01304         // close the dlg
01305         Close();           
01306         End();
01307     }
01308 
01309 
01310     return DialogOp::Message(Message);
01311 } 
01312 
01313 /*******************************************************************************************
01314 
01315 >   OpState BarCreationDlg::GetState(String_256*, OpDescriptor*)
01316 
01317     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Alex
01318     Created:    13/8/99
01319     Purpose:    Returns the OpState of the dialogue operation
01320 
01321 *******************************************************************************************/
01322 
01323 OpState BarStatesDlg::GetState(String_256*, OpDescriptor*)
01324 {
01325     OpState OpSt;
01326 
01327     // if we don't allow it
01328     OpSt.Greyed = TRUE;
01329     Spread* pSpread = Document::GetSelectedSpread();
01330     if (pSpread && !pSpread->FindActiveLayer()->IsFrame())
01331         OpSt.Greyed = FALSE;
01332 
01333     // Tick the menu while the editor is open
01334     if (TheDialog != NULL)
01335         OpSt.Ticked = TRUE;
01336 
01337     return(OpSt);
01338 }
01339 
01340          
01341 
01342 /*******************************************************************************************
01343 
01344 >   BOOL BarStatesDlg::Init()
01345 
01346     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01347     Created:    8/5/00
01348     Returns:    FALSE if it fails (due to lack of memory)
01349     Purpose:    Creates an OpDescriptor for a HotLink Dialog and declares
01350                 some preferences
01351 
01352 *******************************************************************************************/
01353 BOOL BarStatesDlg::Init()
01354 {
01355     return (RegisterOpDescriptor(0,                             // Tool ID
01356                                 _R(IDS_CREATE_STATES),                  // String resource ID
01357                                 CC_RUNTIME_CLASS(BarStatesDlg),     // Runtime class
01358                                 OPTOKEN_BARSTATESDLG,               // Token string
01359                                 BarStatesDlg::GetState,             // GetState function
01360                                 _R(IDH_NavBar_Edit_States_Dialog_Box),  // Help ID
01361                                 _R(IDBBL_STATES),               // Bubble ID
01362                                 _R(IDD_BARCONTROLSTORE),            // Resource ID
01363                                 _R(IDC_STATES),             // Control ID
01364                                 SYSTEMBAR_UTILITIES,            // Bar ID
01365                                 TRUE,                           // Recieve system messages
01366                                 FALSE,                          // Smart duplicate operation
01367                                 TRUE,                           // Clean operation
01368                                 0,                              // No vertical counterpart
01369                                 NULL,
01370                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC),
01371                                 TRUE
01372                                 )); 
01373                         
01374 }   
01375  
01376       
01377 
01378 
01379 /********************************************************************************************
01380 
01381 >   void BarStatesDlg::Do(OpDescriptor*)
01382 
01383     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 
01384     Created:    8/5/00
01385 
01386     Purpose:    Opens the dialog if it is closed. Closes it if it is open.
01387                 Should no longer be called, but use the with param instead
01388         
01389 ********************************************************************************************/
01390 
01391 void BarStatesDlg::Do(OpDescriptor*)
01392 {
01393     m_BarName = "Bar1";
01394 
01395     if (TheDialog==NULL || TheDialog==this)
01396     {
01397         if (Create())
01398             Open();
01399         else
01400             End();
01401     }
01402     else
01403     {
01404         TheDialog->Open();
01405         TheDialog->BringToTop();
01406 
01407         End();              // Kill ourself
01408     }
01409 }
01410 
01411 /********************************************************************************************
01412 
01413 >   BOOL BarStatesDlg::Create()
01414 
01415     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01416     Created:    8/5/00
01417     Inputs:     -
01418     Outputs:    -
01419     Returns:    FALSE if it fails
01420     Purpose:    Creates a dlg
01421     Errors:     -
01422     SeeAlso:    -
01423 
01424 ********************************************************************************************/
01425 
01426 BOOL BarStatesDlg::Create()
01427 {
01428     if (TheDialog != this)      // Allow only one instance of this dialogue open at once
01429         return(FALSE);
01430 
01431     for (INT32 i = 0; i < 5; i++)
01432         m_StateExists[i] = FALSE;
01433 
01434     ScanForBarDetails();
01435 
01436     if (DialogOp::Create())
01437     { 
01438         return(TRUE);
01439     }
01440 
01441     return(FALSE);
01442 }
01443 
01444 /********************************************************************************************
01445 
01446 >   void BarStatesDlg::DoWithParam(OpDescriptor* pOp, OpParam* pParam)     
01447 
01448     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 
01449     Created:    8/5/00
01450     Inputs:     OpDescriptor
01451     Outputs:    -
01452     Returns:    -
01453     Purpose:    Performs the BarCreationDlg operation
01454     Errors:     -
01455     SeeAlso:    -
01456 
01457 ********************************************************************************************/
01458 
01459 void BarStatesDlg::DoWithParam(OpDescriptor* pOp, OpParam* pParam)
01460 {
01461     m_BarName = ((OpParamBarStatesDlg *)pParam)->m_BarName;
01462 
01463     if (TheDialog==NULL || TheDialog==this)
01464     {
01465         if (Create())
01466             Open();
01467         else
01468             End();
01469     }
01470     else
01471     {
01472         TheDialog->Open();
01473         TheDialog->BringToTop();
01474 
01475         TheDialog->m_BarName = ((OpParamBarStatesDlg *)pParam)->m_BarName;
01476 
01477         TheDialog->ScanForBarDetails(); // we may be looking at a different bar now
01478         TheDialog->SetUpControls();
01479 
01480         End();              // Kill ourself
01481     }
01482 }
01483 
01484 
01485 /********************************************************************************************
01486 
01487 >   BOOL BarStatesDlg::ScanForBarDetails(INT32 &NoOfButtons)
01488 
01489     Author:     Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
01490     Created:    14/10/99 - modified much on 8/5/00
01491     Returns:    TRUE for success FALSE for failure
01492     Purpose:    Scans the tree to fill in the variables passed to it
01493     Params:     NoOfButtons-How many buttons there are in the bar
01494 
01495 ********************************************************************************************/
01496 BOOL BarStatesDlg::ScanForBarDetails()
01497 {
01498     // find me the buttons in this bar
01499     String_256 templayer;
01500 
01501     // build up a list of the buttons in the bar
01502     // so that we can shift them along
01503     // it must be better to use a list than keep on
01504     // scanning each time
01505 
01506     Layer * pLayer = NULL;
01507 
01508     List BarList;
01509 
01510     templayer.Load(_R(IDS_ROLLOVER_DEFAULT));
01511     pLayer = SliceHelper::FindLayerCalled(templayer);
01512     if (pLayer)
01513         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, m_BarName);
01514     DWORD BarElements = BarList.GetCount();
01515     DWORD NextElements = BarElements;
01516     if (BarElements > 0)
01517         m_StateExists[0] = TRUE;
01518     else
01519         m_StateExists[0] = FALSE;
01520 
01521     templayer.Load(_R(IDS_ROLLOVER_MOUSE));
01522     pLayer = SliceHelper::FindLayerCalled(templayer);
01523     if (pLayer)
01524         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, m_BarName);
01525     NextElements = BarList.GetCount();
01526     if (NextElements > BarElements)
01527     {
01528         BarElements = NextElements;
01529         m_StateExists[1] = TRUE;
01530     }
01531     else
01532         m_StateExists[1] = FALSE;
01533 
01534     templayer.Load(_R(IDS_ROLLOVER_CLICKED));
01535     pLayer = SliceHelper::FindLayerCalled(templayer);
01536     if (pLayer)
01537         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, m_BarName);
01538     NextElements = BarList.GetCount();
01539     if (NextElements > BarElements)
01540     {
01541         BarElements = NextElements;
01542         m_StateExists[2] = TRUE;
01543     }
01544     else
01545         m_StateExists[2] = FALSE;
01546 
01547     templayer.Load(_R(IDS_ROLLOVER_SELECTED));
01548     pLayer = SliceHelper::FindLayerCalled(templayer);
01549     if (pLayer)
01550         SliceHelper::BuildListOfNodesInBar(&BarList, pLayer, m_BarName);
01551     NextElements = BarList.GetCount();
01552     if (NextElements > BarElements)
01553     {
01554         BarElements = NextElements;
01555         m_StateExists[3] = TRUE;
01556     }
01557     else
01558         m_StateExists[3] = FALSE;
01559 
01560 
01561     // need to do a scan to see if the bar has a back bar or not
01562     templayer.Load(_R(IDS_BACK_BAR));
01563     pLayer = SliceHelper::FindLayerCalled(templayer);
01564     m_StateExists[4] = FALSE;
01565     if (pLayer)
01566     {
01567         Node * pTemplAttrib = SliceHelper::FindNextOfClass(pLayer, pLayer, CC_RUNTIME_CLASS(TemplateAttribute));
01568         while (pTemplAttrib)
01569         {
01570             if (m_BarName == SliceHelper::GetBarName((TemplateAttribute *)pTemplAttrib))
01571             {
01572                 m_StateExists[4] = TRUE;
01573                 break;
01574             }
01575             pTemplAttrib = SliceHelper::FindNextOfClass(pTemplAttrib, pLayer, CC_RUNTIME_CLASS(TemplateAttribute));
01576         }
01577     }
01578 
01579     NodeListItem *pNodeListItem = NULL;
01580     NodeListItem *pDelThisToo = NULL;
01581     
01582     // tidy up the list
01583     pNodeListItem = (NodeListItem *)BarList.GetHead();
01584 
01585     while(pNodeListItem)
01586     {
01587         pDelThisToo = pNodeListItem;
01588 
01589         pNodeListItem = (NodeListItem *)BarList.GetNext(pNodeListItem);
01590 
01591         // tidy up the list as we go along
01592         BarList.RemoveItem((NodeListItem *)pDelThisToo);
01593         delete pDelThisToo;
01594     }
01595 
01596     // if we have done this scan we are looking at a new bar
01597     // set the bar name in the title
01598     String_256 Title;
01599     Title.Load(_R(IDS_BAR_STATES_TITLE));
01600     if (m_ValidBar)
01601         Title += m_BarName;
01602     else
01603     {
01604         String_256 temp(_R(IDS_NO_VALID_BAR));
01605         Title += temp;
01606     }
01607 
01608     SetTitlebarName(&Title);
01609 
01610     return TRUE;
01611 }
01612 
01613 
01614 
01615 void BarStatesDlg::SetUpControls()
01616 {
01617     SetLongGadgetValue(_R(IDC_MOUSE_OFF), m_State == 0);
01618     SetLongGadgetValue(_R(IDC_MOUSE_OVER), m_State == 1);
01619     SetLongGadgetValue(_R(IDC_CLICKED), m_State == 2);
01620     SetLongGadgetValue(_R(IDC_SELECTED), m_State == 3);
01621     //SetLongGadgetValue(_R(IDC_BACK_BAR), m_State == 4);
01622 
01623     HideGadget(_R(IDC_MOUSE_OFF_EXISTS), !m_StateExists[0]);
01624     HideGadget(_R(IDC_MOUSE_OVER_EXISTS), !m_StateExists[1]);
01625     HideGadget(_R(IDC_CLICKED_EXISTS), !m_StateExists[2]);
01626     HideGadget(_R(IDC_SELECTED_EXISTS), !m_StateExists[3]);
01627     //HideGadget(_R(IDC_BACK_BAR_EXISTS), !m_StateExists[4]);
01628 
01629     EnableGadget(_R(IDC_DELETE_STATE), m_StateExists[m_State]);
01630 
01631     if (m_StateExists[m_State])
01632         SetStringGadgetValue(_R(IDC_CREATE_STATE), _R(IDS_RECREATE));
01633     else
01634         SetStringGadgetValue(_R(IDC_CREATE_STATE), _R(IDS_CREATE_BUTTON_TEXT));
01635 
01636     SetSelectedValueIndex(_R(IDC_MUTATE_COLOURS), ms_SuggestDesign);
01637     HideGadget(_R(IDC_MUTATE_COLOURS), m_State == 4);
01638 
01639     if (m_State == 4)
01640         SetStringGadgetValue(_R(IDC_SOURCE_TEXT), _R(IDS_FROM_SELECTION));
01641     else
01642         SetStringGadgetValue(_R(IDC_SOURCE_TEXT), _R(IDS_FROM_MOUSE_OFF));
01643 }
01644 
01645 BOOL BarStatesDlg::CreateBarStates(BOOL ReCreate)
01646 {
01647     NodeBarProperty* pNodeBarProperty = (NodeBarProperty*) Document::GetCurrent()->GetSetSentinel()->FindBarProperty();
01648     INT32 BarNumber = SliceHelper::GetBarNumberFromBarName(m_BarName);
01649 
01650     if (!pNodeBarProperty || BarNumber >= pNodeBarProperty->HowMany())
01651         return FALSE;
01652 
01653     BarDataType NewBarData = pNodeBarProperty->Bar(BarNumber);
01654     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BARCREATIONOP); 
01655 
01656     if (!pOpDesc)
01657         return FALSE;
01658 
01659     BYTE ExtendFlags = 0; // dont extend
01660 
01661     if (NewBarData.ButtonsExtend)
01662         ExtendFlags = X_EXTEND | Y_EXTEND;
01663     else
01664         if (NewBarData.ButtonsScale)
01665             ExtendFlags = X_STRETCH | Y_STRETCH;
01666 
01667     OpParamBarCreation BarParam(m_State == 1,   //ms_WantMouse,
01668                                 m_State == 2,   //ms_WantClicked,
01669                                 m_State == 3,   //ms_WantSelected,
01670                                 m_State == 4,   //(ms_StateToCreate == BACKBAR),
01671                                 NewBarData.IsHorizontal ? FALSE : TRUE,
01672                                 ms_SuggestDesign,
01673                                 0, //ms_NoOfButtons,
01674                                 m_State == 0, // ms_WantDefault - dont use this to make the default from this dlg
01675                                 REPLACE_SOME_STATES,
01676                                 NewBarData.Spacing,
01677                                 NewBarData.RequiresShuffle,
01678                                 NewBarData.SameSize,
01679                                 m_BarName,
01680                                 (m_State == DEFAULT || m_State == BACKBAR) ? TRUE : FALSE, // from selection or from MouseOff?
01681                                 ExtendFlags,
01682                                 ReCreate);
01683     pOpDesc->Invoke(&BarParam);
01684 
01685     return TRUE;
01686 }
01687 
01688 
01689 
01690 BOOL BarStatesDlg::OnSelectionChanged()
01691 {
01692     // show the current layer in the dlg
01693     String_256 LayerName = "";
01694     Spread* pSpread = Document::GetSelectedSpread();
01695     if (pSpread == NULL)
01696         return FALSE;
01697 
01698     SelRange * pSelection = GetApplication()->FindSelection();
01699 
01700     // scan the selection has the bar name changed?
01701 
01702     String_256 TempBarName = "";
01703 
01704     Node * pCurrent = pSelection->FindFirst();
01705     TemplateAttribute * pTemplAttrib = NULL;
01706     Node * pTempNode = NULL;
01707 
01708     BOOL HasASelection = pCurrent != NULL;
01709 
01710     while (pCurrent && TempBarName.IsEmpty())
01711     {
01712         // look at the bar name on the attrib
01713         pTemplAttrib = (TemplateAttribute *) SliceHelper::FindNextOfClass(pCurrent, pCurrent, CC_RUNTIME_CLASS(TemplateAttribute));
01714         while (pTemplAttrib && TempBarName.IsEmpty())
01715         {
01716             TempBarName = SliceHelper::GetBarName(pTemplAttrib);
01717             pTemplAttrib = (TemplateAttribute *) SliceHelper::FindNextOfClass(pTemplAttrib, pCurrent, CC_RUNTIME_CLASS(TemplateAttribute));
01718         }
01719 
01720         pCurrent = pSelection->FindNext(pCurrent);
01721     }
01722 
01723     // something is selected but that doesn't have a bar name
01724     if (HasASelection && TempBarName.IsEmpty())
01725     {
01726         // does the selection intersect with any known bars?
01727         SliceHelper::BarNameInRect(pSelection->GetBoundingRect(), &TempBarName);
01728     }
01729 
01730     if (HasASelection && TempBarName.IsEmpty() && m_ValidBar)
01731     {
01732         m_ValidBar = FALSE;
01733 
01734         EnableGadget(_R(IDC_CREATE_STATE),      FALSE);
01735         EnableGadget(_R(IDC_MUTATE_COLOURS),    FALSE);
01736         EnableGadget(_R(IDC_DELETE_STATE),      FALSE);
01737 
01738         ScanForBarDetails();
01739     }
01740     else
01741         if (!m_ValidBar && !TempBarName.IsEmpty())
01742         {
01743             m_ValidBar = TRUE;
01744 
01745             EnableGadget(_R(IDC_CREATE_STATE),      TRUE);
01746             EnableGadget(_R(IDC_MUTATE_COLOURS),    TRUE);
01747             EnableGadget(_R(IDC_DELETE_STATE),      TRUE);
01748 
01749             m_BarName = "";
01750         }
01751 
01752     if (TempBarName.CompareTo(m_BarName) != 0 && !TempBarName.IsEmpty())
01753     {
01754         // found a new bar, reset the dlg
01755         m_BarName = TempBarName;
01756         ScanForBarDetails();
01757         SetUpControls();
01758     }
01759 
01760     return TRUE;
01761 }
01762 
01763 
01764 
01765 
01766 
01767 /*****************************************************************************************************/
01768 
01769 // Set up our static variables
01770 const CDlgMode BarRedefineStateDlg::Mode = MODELESS;
01771 const UINT32 BarRedefineStateDlg::IDD = _R(IDD_REDEFINE_STATE);
01772 
01773 BarRedefineStateDlg *BarRedefineStateDlg::TheDialog = NULL;
01774 
01775 
01776 /*******************************************************************************************
01777 
01778 >   BarRedefineStateDlg::BarRedefineStateDlg() : DialogOp(RenderDlg::IDD, RenderDlg::Mode) 
01779 
01780     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01781     Created:    8/5/00
01782     Purpose:    Constructor
01783 
01784 *******************************************************************************************/
01785 
01786 BarRedefineStateDlg::BarRedefineStateDlg() : DialogOp(BarRedefineStateDlg::IDD, BarRedefineStateDlg::Mode) 
01787 {
01788     //Set our member variable pointer so it points at ourself
01789     if (TheDialog == NULL)
01790         TheDialog = this;
01791 
01792 }       
01793 
01794 
01795 
01796 /*******************************************************************************************
01797 
01798 >   BarRedefineStateDlg::~BarRedefineStateDlg()
01799 
01800     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 
01801     Created:    9/5/00
01802     Purpose:    Destructor
01803 
01804 *******************************************************************************************/
01805 
01806 BarRedefineStateDlg::~BarRedefineStateDlg()
01807 {
01808     //Set our member variable pointer to NULL
01809     if (TheDialog == this)
01810         TheDialog = NULL;
01811 } 
01812  
01813 /********************************************************************************************
01814 >   MsgResult BarRedefineStateDlg::Message( Msg* Message)
01815 
01816     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01817     Created:    9/5/00
01818     Inputs:     Message: The incoming message 
01819         
01820     Returns:    DialogOp::Message (Message)
01821 
01822     Purpose:    This is the message handler for the BarStatesDlg. It simply takes the
01823                 message and redirects it to one of our Message Handler functions.
01824      
01825 ********************************************************************************************/
01826 
01827 MsgResult BarRedefineStateDlg::Message( Msg* Message)
01828 {
01829     BOOL fEndDialog=FALSE;
01830 
01831     //If the message is a dialog message
01832     if (IS_OUR_DIALOG_MSG(Message))
01833     {
01834         //Then work out what it says
01835         DialogMsg* pDialogMsg = ((DialogMsg*) Message); 
01836     
01837         switch (pDialogMsg->DlgMsg)
01838         {
01839             case DIM_CREATE:
01840                 SetUpControls();
01841                 //DialogManager::DefaultKeyboardFocus(); // throws focus
01842                 break;
01843     
01844             // these two messages are used to throw the focus back to the main window
01845             case DIM_TITLEFOCUSWARN:
01846                 //DialogManager::DefaultKeyboardFocus();
01847                 break;
01848 
01849             // focus throw
01850             case DIM_LFT_BN_UP:
01851                 //DialogManager::DefaultKeyboardFocus();
01852                 break;
01853     
01854             case DIM_CANCEL:    
01855                 fEndDialog = TRUE;
01856                 break;
01857 
01858             case DIM_COMMIT:
01859                 RedefineState();
01860                 fEndDialog = TRUE;
01861                 break;
01862         }
01863     }
01864     // If we've changed to a different document then get rid of the dlg.
01865     else if (MESSAGE_IS_A(Message, DocChangingMsg))
01866     {
01867         DocChangingMsg* TheMsg = (DocChangingMsg*) Message;
01868         if (TheMsg->State == DocChangingMsg::BORN || TheMsg->State == DocChangingMsg::SELCHANGED)
01869             Close();
01870     }
01871         
01872     if (fEndDialog) 
01873     {
01874         // close the dlg
01875         Close();           
01876         End();
01877     }
01878 
01879 
01880     return DialogOp::Message(Message);
01881 } 
01882 
01883 /*******************************************************************************************
01884 
01885 >   OpState BarRedefineStateDlg::GetState(String_256*, OpDescriptor*)
01886 
01887     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> after Alex
01888     Created:    13/8/99
01889     Purpose:    Returns the OpState of the dialogue operation
01890 
01891 *******************************************************************************************/
01892 
01893 OpState BarRedefineStateDlg::GetState(String_256*, OpDescriptor*)
01894 {
01895     OpState OpSt;
01896 
01897     // if we don't allow it
01898     OpSt.Greyed = TRUE;
01899     Spread* pSpread = Document::GetSelectedSpread();
01900     if (pSpread && !pSpread->FindActiveLayer()->IsFrame())
01901         OpSt.Greyed = FALSE;
01902 
01903     // Tick the menu while the editor is open
01904     if (TheDialog != NULL)
01905         OpSt.Ticked = TRUE;
01906 
01907     return(OpSt);
01908 }
01909 
01910          
01911 
01912 /*******************************************************************************************
01913 
01914 >   BOOL BarRedefineStateDlg::Init()
01915 
01916     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01917     Created:    9/5/00
01918     Returns:    FALSE if it fails (due to lack of memory)
01919     Purpose:    Creates an OpDescriptor for a HotLink Dialog and declares
01920                 some preferences
01921 
01922 *******************************************************************************************/
01923 BOOL BarRedefineStateDlg::Init()
01924 {
01925     return (RegisterOpDescriptor(0,                             // Tool ID
01926                                 _R(IDS_RECREATE_STATES),                    // String resource ID
01927                                 CC_RUNTIME_CLASS(BarRedefineStateDlg),      // Runtime class
01928                                 OPTOKEN_BARREDEFINESTATEDLG,                // Token string
01929                                 BarRedefineStateDlg::GetState,              // GetState function
01930                                 _R(IDH_NavBar_Edit_Design_Dialog_Box),          // Help ID
01931                                 _R(IDBBL_REDEFINE_STATE),               // Bubble ID
01932                                 _R(IDD_BARCONTROLSTORE),            // Resource ID
01933                                 _R(IDC_REDEFINE_STATE),             // Control ID
01934                                 SYSTEMBAR_UTILITIES,            // Bar ID
01935                                 TRUE,                           // Recieve system messages
01936                                 FALSE,                          // Smart duplicate operation
01937                                 TRUE,                           // Clean operation
01938                                 0,                              // No vertical counterpart
01939                                 NULL,
01940                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC),
01941                                 TRUE
01942                                 )); 
01943                         
01944 }   
01945  
01946       
01947 
01948 
01949 /********************************************************************************************
01950 
01951 >   void BarRedefineStateDlg::Do(OpDescriptor*)
01952 
01953     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 
01954     Created:    8/5/00
01955 
01956     Purpose:    Opens the dialog if it is closed. Closes it if it is open.
01957                 Should no longer be called, but use the with param instead
01958         
01959 ********************************************************************************************/
01960 
01961 void BarRedefineStateDlg::Do(OpDescriptor*)
01962 {
01963     m_BarName = "Bar1";
01964     m_State = 0;
01965 
01966     if (TheDialog==NULL || TheDialog==this)
01967     {
01968         if (Create())
01969             Open();
01970         else
01971             End();
01972     }
01973     else
01974     {
01975         TheDialog->Open();
01976         TheDialog->BringToTop();
01977 
01978         End();              // Kill ourself
01979     }
01980 }
01981 
01982 /********************************************************************************************
01983 
01984 >   BOOL BarRedefineStateDlg::Create()
01985 
01986     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01987     Created:    8/5/00
01988     Inputs:     -
01989     Outputs:    -
01990     Returns:    FALSE if it fails
01991     Purpose:    Creates a dlg
01992     Errors:     -
01993     SeeAlso:    -
01994 
01995 ********************************************************************************************/
01996 
01997 BOOL BarRedefineStateDlg::Create()
01998 {
01999     if (TheDialog != this)      // Allow only one instance of this dialogue open at once
02000         return(FALSE);
02001 
02002     if (DialogOp::Create())
02003     { 
02004         return(TRUE);
02005     }
02006 
02007     return(FALSE);
02008 }
02009 
02010 /********************************************************************************************
02011 
02012 >   void BarRedefineStateDlg::DoWithParam(OpDescriptor* pOp, OpParam* pParam)      
02013 
02014     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 
02015     Created:    8/5/00
02016     Inputs:     OpDescriptor
02017     Outputs:    -
02018     Returns:    -
02019     Purpose:    Performs the BarCreationDlg operation
02020     Errors:     -
02021     SeeAlso:    -
02022 
02023 ********************************************************************************************/
02024 
02025 void BarRedefineStateDlg::DoWithParam(OpDescriptor* pOp, OpParam* pParam)
02026 {
02027     m_BarName = ((OpParamBarRedefineStateDlg *)pParam)->m_BarName;
02028     m_State = ((OpParamBarRedefineStateDlg *)pParam)->m_State;
02029 
02030     if (TheDialog==NULL || TheDialog==this)
02031     {
02032         if (Create())
02033             Open();
02034         else
02035             End();
02036     }
02037     else
02038     {
02039         TheDialog->Open();
02040         TheDialog->BringToTop();
02041 
02042         End();              // Kill ourself
02043     }
02044 }
02045 
02046 BOOL BarRedefineStateDlg::SetUpControls()
02047 {
02048     // fill in the bar state we are creating
02049 
02050     // set the text in the redefine state button
02051     String_256 Temp(_R(IDS_ROLLOVER_DEFAULT));
02052     if (m_State == 1)
02053         Temp.Load(_R(IDS_ROLLOVER_MOUSE));
02054     else if (m_State == 2)
02055         Temp.Load(_R(IDS_ROLLOVER_CLICKED));
02056     else if (m_State == 3)
02057         Temp.Load(_R(IDS_ROLLOVER_SELECTED));
02058     else if (m_State == 4)
02059         Temp.Load(_R(IDS_BACK_BAR));
02060     String_256 StateText = Temp;
02061     Temp.Load(_R(IDS_STATE_TEXT));
02062     StateText += Temp;
02063     SetStringGadgetValue(_R(IDC_STATE_TEXT), &StateText);
02064 
02065 
02066     // first find all the bar names available
02067     String_256 DefLayerName;
02068     DefLayerName.Load(_R(IDS_ROLLOVER_DEFAULT));
02069     Layer * pDef = SliceHelper::FindLayerCalled(DefLayerName);
02070 
02071     if (!pDef) return FALSE;
02072 
02073     NameGallery* pNameGallery = NameGallery::Instance();
02074         // make sure we are dealing with the most uptodate information
02075     if (pNameGallery)
02076         pNameGallery->FastUpdateNamedSetSizes();
02077 
02078     String_256 BarName = "";
02079 
02080     // find a new bar name
02081     INT32 BarNo = 0;
02082     INT32 misses = 0;
02083     INT32 selthis = 0;
02084     do
02085     {
02086         BarNo++;
02087         BarName.MakeMsg(_R(IDS_BARNAME), BarNo);
02088         BOOL BarExists = SliceHelper::BarNameExists(pDef, BarName);
02089         if (BarExists)
02090         {
02091             SetStringGadgetValue(_R(IDC_BAR_NO_COMBO), &BarName, FALSE, BarNo-1-misses);
02092             if (BarName == m_BarName)
02093                 selthis = BarNo-1-misses;
02094         }
02095         else
02096             misses++;
02097     }
02098     while (misses < 3);
02099 
02100     // then select the bar name we have been passed
02101     SetSelectedValueIndex(_R(IDC_BAR_NO_COMBO), selthis);
02102 
02103 
02104     return TRUE;
02105 }
02106 
02107 
02108 
02109 BOOL BarRedefineStateDlg::IsAttribInSelected(Node * pNode)
02110 {
02111     Node *pParent = pNode->FindParent();
02112 
02113     // if it is a bevel controller check the bev components for selection
02114     if (pParent->IsCompound())
02115     {
02116         pNode = pParent->FindFirstChild();
02117         while (pNode)
02118         {
02119             if (pNode->IsSelected())
02120                 return TRUE;
02121 
02122             pNode = pNode->FindNext();
02123         }
02124     }
02125 
02126     // look for selected parents
02127     while (pParent && !pParent->IsLayer())
02128     {
02129         if (pParent->IsSelected())
02130             return TRUE;
02131 
02132         pParent = pParent->FindParent();
02133     }
02134 
02135     return FALSE;
02136 }
02137 
02138 
02139 BOOL BarRedefineStateDlg::RedefineState()
02140 {
02141     // get the barname from the drop down
02142     m_BarName = GetStringGadgetValue(_R(IDC_BAR_NO_COMBO));
02143 
02144     // get the no of buttons in the bar
02145     INT32 NoOfButtons = SliceHelper::CountButtonsInBar(m_BarName);
02146 
02147     NodeBarProperty* pNodeBarProperty = (NodeBarProperty*) Document::GetCurrent()->GetSetSentinel()->FindBarProperty();
02148     INT32 BarNumber = SliceHelper::GetBarNumberFromBarName(m_BarName);
02149 
02150     if (!pNodeBarProperty || BarNumber >= pNodeBarProperty->HowMany())
02151         return FALSE;
02152 
02153     BarDataType NewBarData = pNodeBarProperty->Bar(BarNumber);
02154 
02155     // we need to check if the user doesn't have selected all the elements of a button from this bar
02156     // if not warn the user that elements not selected will be deleted
02157     // first which button is it that we think we have selected - if none then use a different warning
02158     String_256 ButtonName = "";
02159 
02160     Node * pNode = NULL;
02161     Layer * pLayer = NULL;
02162     String_256 templayer = "";
02163 
02164     switch (m_State)
02165     {
02166     case 0:
02167         templayer.Load(_R(IDS_ROLLOVER_DEFAULT));
02168         break;
02169 
02170     case 1:
02171         templayer.Load(_R(IDS_ROLLOVER_MOUSE));
02172         break;
02173 
02174     case 2:
02175         templayer.Load(_R(IDS_ROLLOVER_CLICKED));
02176         break;
02177 
02178     case 3:
02179         templayer.Load(_R(IDS_ROLLOVER_SELECTED));
02180         break;
02181 
02182     case 4:
02183         templayer.Load(_R(IDS_BACK_BAR));
02184         break;
02185     }
02186 
02187     if (!templayer.IsEmpty())
02188         pLayer = SliceHelper::FindLayerCalled(templayer);
02189 
02190     if (!pLayer)
02191         return FALSE;
02192 
02193     BOOL FoundSelected = FALSE;
02194 
02195     // scan this layer for which button is selected
02196     pNode = SliceHelper::FindNextOfClass(pLayer, pLayer, CC_RUNTIME_CLASS(TemplateAttribute));
02197     while (pNode && !FoundSelected)
02198     {
02199         if (m_BarName.CompareTo(SliceHelper::GetBarName((TemplateAttribute *)pNode)) == 0)
02200         {
02201             // set the button name we are looking for
02202             if (IsAttribInSelected(pNode)) 
02203             {
02204                 ButtonName = ((TemplateAttribute *)pNode)->GetParam();
02205                 FoundSelected = TRUE;
02206             }
02207         }
02208 
02209         pNode = SliceHelper::FindNextOfClass(pNode, pLayer, CC_RUNTIME_CLASS(TemplateAttribute));
02210     }
02211 
02212     // scan this layer for none selected elements of the button
02213     pNode = SliceHelper::FindNextOfClass(pLayer, pLayer, CC_RUNTIME_CLASS(TemplateAttribute));
02214     while (FoundSelected && pNode)
02215     {
02216         if (m_BarName.CompareTo(SliceHelper::GetBarName((TemplateAttribute *)pNode)) == 0)
02217         {
02218             // if we have found a selected button name are other
02219             if (ButtonName.CompareTo(((TemplateAttribute *)pNode)->GetParam()) == 0)
02220             {
02221                 if (!IsAttribInSelected(pNode))
02222                 {
02223                     INT32 msg = InformWarning(_R(IDS_BUTTON_NOT_ALL_SELECTED), _R(IDS_CANCEL), _R(IDS_CARRY_ON));
02224                     if (msg == 1)
02225                         return FALSE; // give up & go back
02226                     else
02227                         break; // stop the test and go ahead
02228                 }
02229             }
02230         }
02231 
02232         pNode = SliceHelper::FindNextOfClass(pNode, pLayer, CC_RUNTIME_CLASS(TemplateAttribute));
02233     }
02234 
02235     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BARCREATIONOP); 
02236 
02237     if (!pOpDesc)
02238         return FALSE;
02239 
02240     BYTE ExtendFlags = 0; // dont extend
02241 
02242     if (NewBarData.ButtonsExtend)
02243         ExtendFlags = X_EXTEND | Y_EXTEND;
02244     else
02245         if (NewBarData.ButtonsScale)
02246             ExtendFlags = X_STRETCH | Y_STRETCH;
02247 
02248     OpParamBarCreation BarParam(m_State == 1,   //ms_WantMouse,
02249                                 m_State == 2,   //ms_WantClicked,
02250                                 m_State == 3,   //ms_WantSelected,
02251                                 m_State == 4,   //(ms_StateToCreate == BACKBAR),
02252                                 NewBarData.IsHorizontal ? FALSE : TRUE,
02253                                 FALSE,
02254                                 NoOfButtons,
02255                                 m_State == 0, // ms_WantDefault - dont use this to make the default from this dlg
02256                                 REPLACE_SOME_STATES,
02257                                 NewBarData.Spacing,
02258                                 NewBarData.RequiresShuffle,
02259                                 NewBarData.SameSize,
02260                                 m_BarName,
02261                                 TRUE, // alsways from selection
02262                                 ExtendFlags);
02263     pOpDesc->Invoke(&BarParam);
02264 
02265     return TRUE;
02266 }

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