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 /***************************************************************