optsunit.cpp

Go to the documentation of this file.
00001 // $Id: optsunit.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 // Implementation of the unit setup dialog as a tab of the options dialog box
00099 
00100 /*
00101 
00102 */
00103 
00104 #include "camtypes.h"
00105 #include "appprefs.h"
00106 //#include "simon.h"
00107 //#include "markn.h"
00108 #include "optsunit.h"
00109 //#include "prefsdlg.h" // dialog/gadget ids
00110 //#include "optsres.h"  // error strings
00111 //#include "app.h"      // Camelot object - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "resource.h" // _R(IDS_OK)
00113 #include "optsmsgs.h"   // options changing messages class
00114 //#include "document.h" // document object - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "grid.h"       // checking if deleted units in grid
00116 //#include "spread.h"       // checking if deleted units in grid - in camtypes.h [AUTOMATICALLY REMOVED]
00117 #include "radio.h"      // class RadioGroup
00118 #include "scunit.h"     // class ScaleUnit
00119 
00120 //WEBSTER-ranbirr-13/11/96
00121 #ifndef WEBSTER
00122 CC_IMPLEMENT_DYNAMIC(UnitsTab, OptionsTabs)   
00123 CC_IMPLEMENT_DYNCREATE(UnitPropertiesDlg, DialogOp)   
00124 #endif  //webster
00125 
00126 // This is not compulsory, but you may as well put it in so that the correct version
00127 // of your file can be registered in the .exe
00128 DECLARE_SOURCE("$Revision: 1282 $");
00129 
00130 // Where the default colour units are stored...Use GetColourUnitPreference() to do the fetching.
00131 
00132 static TCHAR*   ColourUnitSection = TEXT("Displays");
00133 static TCHAR*   ColourUnitPreference = TEXT("ColourEditorUnits");
00134 
00135 // Set up the dialog box details stored as statics in the class
00136 // This is for the user units properties dialog box
00137 CDlgResID       UnitPropertiesDlg::IDD  = _R(IDD_OPTS_UNITPROPERTIES);  // default dialog box id
00138 const CDlgMode  UnitPropertiesDlg::Mode = MODAL;                    // This dialog is modal
00139 
00140 // Associations for RadioGroup class for Colour Units
00141 static const UINT32 NUM_CLR_DEFAULTS = 2;
00142 
00143 static CGadgetAssociation   ColourUnitAssociations[NUM_CLR_DEFAULTS] =
00144 {
00145     {_R(IDC_OPTS_CLR_UNIT_USE_PERCENT), &(StandardUnit::UnitPercent)},
00146     {_R(IDC_OPTS_CLR_UNIT_USE_BYTE),    &(StandardUnit::UnitDecimalD)}
00147 };
00148 
00149 //WEBSTER-ranbirr-13/11/96
00150 #ifndef WEBSTER
00151 
00152 /********************************************************************************************
00153 
00154 >   UnitsTab::UnitsTab() 
00155 
00156 
00157     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00158     Created:    7/12/94
00159     Inputs:     -
00160     Outputs:    -
00161     Returns:    -
00162     Purpose:    UnitsTab constructor. Creates a non-undoable operation
00163     Errors:     -
00164     SeeAlso:    -
00165 
00166 ********************************************************************************************/
00167 
00168 UnitsTab::UnitsTab()
00169 {   
00170     // Do nothing at present
00171 }        
00172 
00173 /********************************************************************************************
00174 
00175 >   UnitsTab::~UnitsTab()
00176 
00177 
00178     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00179     Created:    7/12/94
00180     Inputs:     -
00181     Outputs:    -
00182     Returns:    -
00183     Purpose:    UnitsTab destructor
00184     Errors:     -
00185     SeeAlso:    -
00186 
00187 ********************************************************************************************/
00188                                                                                 
00189 UnitsTab::~UnitsTab()
00190 {   
00191 }        
00192 
00193 /********************************************************************************************
00194 
00195 >   BOOL UnitsTab::Init()
00196 
00197 
00198     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00199     Created:    7/12/94
00200     Inputs:     -
00201     Outputs:    -
00202     Returns:    True if initialised ok, False if failed.
00203     Purpose:    UnitsTab initialisation routine
00204     Errors:     -
00205     SeeAlso:    -
00206 
00207 ********************************************************************************************/
00208                                                                                 
00209 BOOL UnitsTab::Init()
00210 {   
00211     CurrentUserUnitType  = NOTYPE;
00212     pDocUnitList         = NULL;
00213 
00214     // Initialise the dialog box that we require to create new and edit user units
00215     BOOL ok = UnitPropertiesDlg::Init();
00216 
00217     return ok;
00218 }        
00219 
00220 
00221 /******************************************************************************************
00222 
00223 >   CDlgResID UnitsTab::GetPageID()()
00224 
00225     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00226     Created:    7/12/94
00227     Inputs:     -
00228     Outputs:    -
00229     Returns:    The dialog ID of this tab section.    
00230     Purpose:    Allows the options dialog code to determine the dialog ID of this section.
00231     Errors:     -
00232     SeeAlso:    -
00233 
00234 ******************************************************************************************/
00235 
00236 CDlgResID UnitsTab::GetPageID()
00237 {
00238     return _R(IDD_OPTSTAB_UNITS);
00239 }
00240 
00241 /******************************************************************************************
00242 
00243 >   BOOL UnitsTab::IsDocumentOption()
00244 
00245     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00246     Created:    14/12/94
00247     Inputs:     -
00248     Outputs:    -
00249     Returns:    Returns True if this tab is a document option.    
00250     Purpose:    Allows the document options dialog code to determine if this tab belongs
00251                 to the group of document options.
00252     Errors:     -
00253     SeeAlso:    IsProgramOption();
00254 
00255 ******************************************************************************************/
00256 
00257 BOOL UnitsTab::IsDocumentOption()
00258 {
00259     return TRUE;    // This tab is a document option 
00260 }
00261 
00262 /******************************************************************************************
00263 
00264 >   BOOL UnitsTab::IsProgramOption()
00265 
00266     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00267     Created:    14/12/94
00268     Inputs:     -
00269     Outputs:    -
00270     Returns:    Returns True if this tab is a program option.     
00271     Purpose:    Allows the program options dialog code to determine if this tab belongs
00272                 to the group of program options.
00273     Errors:     -
00274     SeeAlso:    IsProgramOption();
00275 
00276 ******************************************************************************************/
00277 
00278 BOOL UnitsTab::IsProgramOption()
00279 {
00280     return TRUE;    // This tab is a program option 
00281 }
00282 
00283 
00284 /******************************************************************************************
00285 
00286 >   BOOL AppPrefsDlg::CommitSection()
00287 
00288     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00289     Created:    7/12/94
00290     Inputs:     -
00291     Outputs:    -
00292     Returns:    True if values in dialog box ok, False otherwise.     
00293     Purpose:    Takes the values in the Units section tab of the options dialog box and
00294                 sets the associated preference values accordingly
00295                 Called when ok is pressed on the dialog box.
00296     Errors:     -
00297     SeeAlso:    -
00298 
00299 ******************************************************************************************/
00300 
00301 BOOL UnitsTab::CommitSection()
00302 {
00303 TRACEUSER( "Neville", _T("commit units section\n"));
00304     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::CommitSection called with no dialog pointer");
00305 
00306     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS)); // The units page identifier
00307     if (!ok)
00308         return TRUE;    // Talk to page failed to return now
00309 
00310     // Section = Units
00311 
00312     // All units work off the selected document and so we must do nothing if there is no
00313     // selected document. Check our clas variable to see if this is true or not.
00314     // Units should have been set up by the caller.
00315     if (pDocument == NULL || pSpread == NULL)
00316     {
00317         // If this fails then there is no document and so we must ensure
00318         // things which need a selected document are greyed.
00319         GreySection();
00320         return TRUE;
00321     }
00322 
00323     ok = CommitDialogValues();
00324 
00325     return ok;
00326 }
00327 
00328 /********************************************************************************************
00329 
00330 >   BOOL UnitsTab::GreySection()
00331 
00332     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00333     Created:    4/2/95
00334     Inputs:     -
00335     Outputs:    -
00336     Returns:    -
00337     Purpose:    Called when the user has closed all documents 
00338     Errors:     -
00339     SeeAlso:    UnitsTab::UngreySection;
00340 
00341 ********************************************************************************************/
00342 
00343 BOOL UnitsTab::GreySection()
00344 {
00345 TRACEUSER( "Neville", _T("GreySection in UnitsTab section\n"));
00346     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::GreySection called with no dialog pointer");
00347 
00348     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS)); // The UnitsTab identifier
00349     if (!ok)
00350         return TRUE;    // Talk to page failed to return now
00351 
00352     // Make sure the information field displaying the name of the current document
00353     // is correct.
00354     String_256  DocumentName(_R(IDT_OPTS_UNITS_INFO)); 
00355     DocumentName += *GetDocumentName();
00356     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00357 
00358     // Only update if we are not already grey 
00359     if (GreyStatus == TRUE)
00360         return TRUE;
00361 
00362     m_ColourUnitRadioGroup.Disable();
00363     // Call our central greying/ungreying function
00364     ok = ChangeControlStatus(FALSE);
00365     
00366     GreyStatus = TRUE;
00367 
00368     return ok;
00369 } 
00370 
00371 /********************************************************************************************
00372 
00373 >   BOOL UnitsTab::UngreySection()
00374 
00375     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00376     Created:    4/2/95
00377     Inputs:     -
00378     Outputs:    -
00379     Returns:    -
00380     Purpose:    Called when the user has selected a new document 
00381     Errors:     -
00382     SeeAlso:    UnitsTab::UngreySection;
00383 
00384 ********************************************************************************************/
00385 
00386 BOOL UnitsTab::UngreySection()
00387 {
00388 TRACEUSER( "Neville", _T("UngreySection in UnitsTab section\n"));
00389     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::UngreySection called with no dialog pointer");
00390 
00391     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS)); // The UnitsTab identifier
00392     if (!ok)
00393         return TRUE;    // Talk to page failed to return now
00394 
00395     // Make sure the information field displaying the name of the current document
00396     // is correct.
00397     String_256  DocumentName(_R(IDT_OPTS_UNITS_INFO)); 
00398     DocumentName += *GetDocumentName();
00399     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00400 
00401     // Only update if we are not already ungrey 
00402     if (GreyStatus == FALSE)
00403         return TRUE;
00404 
00405     m_ColourUnitRadioGroup.Enable();
00406     // Call our central greying/ungreying function
00407     ok = ChangeControlStatus(TRUE);
00408     
00409     GreyStatus = FALSE;
00410 
00411     return ok;
00412 }
00413 
00414 /********************************************************************************************
00415 
00416 >   BOOL UnitsTab::ChangeControlStatus(const BOOL Status)
00417 
00418     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00419     Created:    4/2/95
00420     Inputs:     -
00421     Outputs:    -
00422     Returns:    -
00423     Purpose:    Called to grey/ungrey all controls on this tab. 
00424     Errors:     -
00425     SeeAlso:    UnitsTab::GreySection;  UnitsTab::UngreySection;
00426 
00427 ********************************************************************************************/
00428 
00429 BOOL UnitsTab::ChangeControlStatus(const BOOL Status)
00430 {
00431     // Main units section
00432     pPrefsDlg->EnableGadget(_R(IDC_OPTS_INFO), Status);
00433 
00434     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNITSGROUP),    Status);
00435     pPrefsDlg->EnableGadget(_R(IDC_OPTS_PAGEUNITSTXT),  Status);
00436 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_SCALEDUNITSTXT),Status);
00437     pPrefsDlg->EnableGadget(_R(IDC_OPTS_FONTUNITSTXT),  Status);
00438     pPrefsDlg->EnableGadget(_R(IDC_OPTS_PAGEUNITS),     Status);
00439 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_SCALEDUNITS),   Status);
00440     pPrefsDlg->EnableGadget(_R(IDC_OPTS_FONTUNITS),     Status);
00441 
00442     pPrefsDlg->EnableGadget(_R(IDC_OPTS_CLR_UNIT_USE_PERCENT),  Status);
00443     pPrefsDlg->EnableGadget(_R(IDC_OPTS_CLR_UNIT_USE_BYTE),     Status);
00444     
00445     // Buttons in the user units section
00446     pPrefsDlg->EnableGadget(_R(IDC_OPTS_NEWUNIT),       Status);
00447     pPrefsDlg->EnableGadget(_R(IDC_OPTS_DELETEUNIT),    Status);
00448     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNITPROPERTY),  Status);
00449 
00450     return TRUE;
00451 }           
00452 
00453 /********************************************************************************************
00454 
00455 >   BOOL UnitsTab::UpdateSection(String_256 *DocumentName)
00456 
00457     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00458     Created:    4/2/95
00459     Inputs:     Name of document
00460     Outputs:    -
00461     Returns:    -
00462     Purpose:    Called when we have switched to a new document and need to update all the 
00463                 controls on this tab. Should only init the tab if the page is present.  
00464                 The document name allows the info field on the tab to be filled in correctly.
00465     Errors:     -
00466     SeeAlso:    UnitsTab::GreySection; UnitsTab::UngreySection; UnitsTab::InitSection;
00467 
00468 ********************************************************************************************/
00469 
00470 BOOL UnitsTab::UpdateSection(String_256 *DocumentName)
00471 {
00472 TRACEUSER( "Neville", _T("UnitsTab::UpdateSection\n"));
00473     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::UpdateSection called with no dialog pointer");
00474 
00475     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS)); // The UnitsTab identifier
00476     if (!ok)
00477         return TRUE;        // page not present
00478 
00479     // Call the normal init section code
00480     return InitSection();
00481 }
00482 
00483 /********************************************************************************************
00484 
00485 >   BOOL UnitsTab::HandleMsg(DialogMsg* Msg)
00486 
00487     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00488     Created:    7/12/94
00489     Inputs:     -
00490     Outputs:    -
00491     Returns:    -
00492     Purpose:    Handles all the units options tabs messages 
00493     Errors:     -
00494     SeeAlso:    -
00495 
00496 ********************************************************************************************/
00497 
00498 BOOL UnitsTab::HandleMsg(DialogMsg* Msg)
00499 {
00500 TRACEUSER( "Neville", _T("HandleUnitsMsg\n"));
00501     ERROR2IF(Msg == NULL,FALSE,"UnitsTab::Message null message received");
00502     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::HandleMsg called with no dialog pointer");
00503 
00504     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS)); // The edit page identifier
00505     if (!ok)
00506         return TRUE;        // page not present
00507     
00508     switch(Msg->DlgMsg)
00509     {
00510         case DIM_CREATE:    // Initialise controls
00511             GreyStatus = FALSE; // we are ungreyed by default
00512             ok = InitSection();
00513             if (!ok)
00514                 InformError();
00515             break;
00516 
00517         case DIM_LFT_BN_CLICKED:
00518             OptionsTabs::SetApplyNowState(TRUE);
00519             if (Msg->GadgetID == _R(IDC_OPTS_UNITPROPERTY))
00520                 // Show the user the properties of the selected user unit
00521                 ShowUnitProperties();
00522             else if (Msg->GadgetID == _R(IDC_OPTS_NEWUNIT))
00523                 // Create the user a new unit
00524                 CreateNewUnit();
00525             else if (Msg->GadgetID == _R(IDC_OPTS_DELETEUNIT))
00526                 // Delete the currently selected user unit
00527                 DeleteUnit();
00528             break;
00529 
00530         case DIM_SELECTION_CHANGED:
00531         {
00532             OptionsTabs::SetApplyNowState(TRUE);
00533             ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::HandleMsg called with no doc unit list");
00534             
00535             WORD Index = 0;
00536             Unit* pUnit = NULL;
00537 //          Unit* pCurUserUnit = NULL;
00538             
00539             if (Msg->GadgetID == _R(IDC_OPTS_UNITSLIST))
00540             {
00541                 // Clicked on the list of user unit types
00542                 // Now, switch to the new item
00543                 pPrefsDlg->GetValueIndex(_R(IDC_OPTS_UNITSLIST), &Index); 
00544                 pUnit = pDocUnitList->FindUserUnit(Index);
00545                 if (pUnit != NULL)
00546                 {
00547                     CurrentUserUnitType = pUnit->GetUnitType();
00548                 }
00549             }
00550         }
00551         default:
00552             break;
00553     }
00554 
00555     return TRUE;
00556 }  
00557 
00558 
00559 /********************************************************************************************
00560 
00561 >   BOOL UnitsTab::CommitDialogValues()
00562 
00563     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00564     Created:    5/7/94
00565     Inputs:     - 
00566     Outputs:    -
00567     Returns:    -
00568     Purpose:    Takes the values in the dialog.
00569                 Called when the OK button is selected
00570     Errors:     -
00571     SeeAlso:    -
00572 
00573 ********************************************************************************************/
00574 
00575 BOOL UnitsTab::CommitDialogValues()
00576 {
00577     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::CommitDialogValues called with no dialog pointer");
00578     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::HandleMsg called with no doc unit list");
00579 
00580 
00581     // ****
00582     // All of the user units are handled as immediate edits and so no extra actions
00583     // are required.
00584 
00585     // ****
00586     // Now update the defaults units that may have been choosen by the user
00587 
00588     // Set up the units with useful defaults, just in case
00589     UnitType PageUnitType = MILLIMETRES;
00590     //UnitType ScaledUnitType = AUTOMATIC;
00591     UnitType FontUnitType = COMP_POINTS;
00592     WORD Index;
00593 
00594     // Work out which page units menu item is selected and then work out the unit type
00595     pPrefsDlg->GetValueIndex(_R(IDC_OPTS_PAGEUNITS), &Index);
00596     Unit *pPageUnit = pDocUnitList->FindUnit(Index);
00597     if (pPageUnit)
00598         PageUnitType = pPageUnit->GetUnitType();
00599     
00600     pPrefsDlg->GetValueIndex(_R(IDC_OPTS_FONTUNITS),  &Index);
00601     Unit *pFontUnit = pDocUnitList->FindUnit(Index);
00602     if (pFontUnit)
00603         FontUnitType = pFontUnit->GetUnitType();
00604 
00605 //  pPrefsDlg->GetValueIndex(_R(IDC_OPTS_SCALEDUNITS), &Index);
00606 //  if (Index <= 0)
00607 //      ScaledUnitType = AUTOMATIC;
00608 //  else
00609 //  {
00610 //      // Remove the automatic units from the calculation
00611 //      Unit *pScaleUnit = pDocUnitList->FindUnit(Index - 1);
00612 //      if (pScaleUnit)
00613 //          ScaledUnitType = pScaleUnit->GetUnitType();
00614 //  }
00615 
00616     if (pDocUnitList != NULL)
00617     {
00618         pDocUnitList->SetPageUnits(PageUnitType);
00619         //pDocUnitList->SetScaleUnits(ScaledUnitType);
00620         pDocUnitList->SetFontUnits(FontUnitType);
00621     }
00622 
00623     ScaleUnit*  pColourUnit = (ScaleUnit*)m_ColourUnitRadioGroup.GetSelected();
00624     ERROR3IF(pColourUnit == NULL, "UnitsTab::CommitDialogValues - Gibberish from GetSelected()");
00625 
00626     // If we have changed the units from the entry ones then tell other users about the change 
00627     // Do a blantant update if the current user units are the current page or font units
00628     if (
00629         (PageUnitType != OldPageUnits) ||
00630         //(ScaledUnitType != OldScaledUnits) ||
00631         (FontUnitType != OldFontUnits) ||
00632         (pColourUnit != NULL && m_pOldColourUnit != pColourUnit) ||
00633         (CurrentUserUnitType == PageUnitType) ||
00634         (CurrentUserUnitType == FontUnitType)
00635        )
00636     {
00637         // Colour units have changed so store the default as a preference then send a message in case
00638         // the Colour Editor is listening
00639         if (m_pOldColourUnit != pColourUnit)
00640         {
00641             ERROR3IF(!(pColourUnit->IS_KIND_OF(ScaleUnit)), "UnitsTab::CommitDialogValues - Not ScaleUnit");
00642             Camelot.SetPrefDirect(ColourUnitSection, ColourUnitPreference, pColourUnit->GetQualifier()->GetToken(), TRUE);
00643             m_pOldColourUnit = pColourUnit;
00644         }
00645         // Now tell other users of units that there is a possibly new default units in operation
00646         // and so update any currently displayed units. 
00647         BROADCAST_TO_ALL(OptionsChangingMsg(pDocument, OptionsChangingMsg::NEWUNITS));
00648 
00649         // Mark the document as modified as we have changed something that is saved with the
00650         // document but only if the page or font units have changed.
00651         if (pDocument &&
00652             (
00653                 (PageUnitType != OldPageUnits) ||
00654                 (FontUnitType != OldFontUnits)
00655             )
00656            )
00657         {
00658             pDocument->SetModified(TRUE);
00659         }   
00660 
00661         // Note the new entry state of the controls
00662         //OldScaledUnits = ScaledUnitType; 
00663         OldPageUnits = PageUnitType; 
00664         OldFontUnits = FontUnitType; 
00665     }
00666     
00667     // If there is a currently seleted user unit then make sure its name in all the lists is
00668     // correct. Only really true on Apply Now clicks as Oks will of course remove the dialog
00669     // box.
00670     if (CurrentUserUnitType != NOTYPE)
00671     {
00672         // Need to do this as otherwise for some strange reason the DialogManager errors
00673         // denying knowledge of the control. Really saying WindowHandler is 0!
00674         BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS)); // The edit page identifier
00675         if (!ok)
00676             return TRUE;        // page not present
00677 
00678         //InitControls();
00679         UpdateUnitListControls();
00680     }
00681 
00682     return TRUE;
00683 }
00684 
00685 /********************************************************************************************
00686 
00687 >   BOOL UnitsTab::CreateNewUnit()
00688 
00689     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00690     Created:    21/11/95
00691     Inputs:     - 
00692     Outputs:    -
00693     Returns:    -
00694     Purpose:    Creates a new user unit that the user has just requested.
00695     Errors:     -
00696     SeeAlso:    -
00697 
00698 ********************************************************************************************/
00699 
00700 BOOL UnitsTab::CreateNewUnit()
00701 {
00702     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::CreateNewUnit called with no doc unit list");
00703 
00704     Unit* pUnit = NULL;
00705 
00706     BOOL ok;
00707     ok = pDocUnitList->MakeNewUnit(&pUnit);
00708 
00709     if (ok)
00710     {
00711         CurrentUserUnitType = pUnit->GetUnitType();
00712         // Fire up the user units name dialog box, but only if we have
00713         // a current user unit to edit.
00714         BOOL Ok = TRUE; 
00715         if (CurrentUserUnitType != NOTYPE)
00716         {
00717             // This is ok as we are using a modal dialog box
00718             Ok = UnitPropertiesDlg::InvokeDialog(CurrentUserUnitType);
00719             
00720             if (!Ok)
00721                 DeleteUnit();           
00722         }
00723 
00724         // Only do the rest of this if the user named the unit ok
00725         if (Ok)
00726         {
00727             EnableControls();
00728             SetUnitToken(_R(IDC_OPTS_PAGEUNITS),  CurrentUserUnitType, 0,TRUE);
00729             //SetUnitToken(_R(IDC_OPTS_SCALEDUNITS),CurrentUserUnitType,NULL,TRUE);
00730             SetUnitToken(_R(IDC_OPTS_FONTUNITS),  CurrentUserUnitType, 0,TRUE);
00731             InitControls();
00732             // Now make sure the current user unit is selected in the list
00733             SelectCurrentUserUnit();
00734             // Mark the document as modified as we have changed something
00735             // that is saved with the document.
00736             if (pDocument)
00737                 pDocument->SetModified(TRUE);
00738         }
00739     }
00740     else
00741     {
00742         // Failed to create the new unit, usually due to no memory.
00743         // So report this to the user. Error set by new on failure. 
00744         InformError();
00745     }
00746     
00747     return TRUE;
00748 }
00749 
00750 /********************************************************************************************
00751 
00752 >   BOOL UnitsTab::DeleteUnit()
00753 
00754     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00755     Created:    21/11/95
00756     Inputs:     - 
00757     Outputs:    -
00758     Returns:    -
00759     Purpose:    Deletes the currently selected user unit.
00760     Errors:     -
00761     SeeAlso:    -
00762 
00763 ********************************************************************************************/
00764 
00765 BOOL UnitsTab::DeleteUnit()
00766 {
00767     ERROR2IF(pDocument == NULL,FALSE,"UnitsTab::DeleteUnit called with no document");
00768     ERROR2IF(pSpread == NULL,FALSE,"UnitsTab::DeleteUnit called with no document");
00769     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::DeleteUnit called with no doc unit list");
00770 
00771     Unit* pNextUserUnit = NULL;
00772     Unit* pCurUserUnit = NULL;
00773     pCurUserUnit  = pDocUnitList->FindUnit(CurrentUserUnitType);
00774     pNextUserUnit = pDocUnitList->FindNextUserUnit(pCurUserUnit);
00775     if (pNextUserUnit == NULL)
00776     {
00777         pNextUserUnit = pDocUnitList->FindFirstUserUnit();
00778         if (pNextUserUnit->GetUnitType() == CurrentUserUnitType)
00779             pNextUserUnit = NULL;
00780     }
00781 
00782     UnitReason DeleteReason = UNITREASON_OK;
00783 
00784     // Before we try and delete the unit we must check if it is being used
00785     // by the default grid or by the scaling strings. If so then we should not
00786     // allow the operation to continue.
00787     // First check the grid
00788     NodeGrid* pDefaultGrid = pSpread->FindFirstDefaultGridInSpread();
00789     if (pDefaultGrid)
00790     {
00791         // Default grid present so ensure not using these units
00792         // Specify True so that we get the scaled units. Otherwise,
00793         // if scaling is set then the user is warned but cannot see the
00794         // units in the grid tab!
00795         UnitType GridUnits = pDefaultGrid->GetUnits(TRUE);
00796         if (CurrentUserUnitType == GridUnits)
00797             DeleteReason = UNITREASON_BEINGUSED;
00798     }
00799 
00800     // Now the document scaling, returns page units if not active
00801     // If present in inactive strings then user will be warned when they
00802     // try and activate this scale.
00803     DimScale* pDimScale = pSpread->GetPtrDimScale();
00804     if (pDimScale)
00805     {
00806             UnitType ScaleUnits = pDimScale->GetScaleUnits();
00807         if (CurrentUserUnitType == ScaleUnits)
00808             DeleteReason = UNITREASON_BEINGUSED;
00809         else
00810         {
00811             // If scale string ok then check the drawing string, if the scale is
00812             // active
00813             BOOL Active = pDimScale->IsActive();
00814             if (Active)
00815             {
00816                 String_32 Str;
00817                 BOOL ok = TRUE;
00818                 double dummy = 0.0;
00819                 Str = pDimScale->GetDrawingScaleStr();
00820                 ok = Convert::StringToComponents(Str, &dummy, &ScaleUnits);
00821                 if (ok && CurrentUserUnitType == ScaleUnits)
00822                     DeleteReason = UNITREASON_BEINGUSED;
00823             }
00824         }
00825     }
00826 
00827     // Try and delete the unit from the doc unit list, will complain if the
00828     // unit has decendents i.e. units based on it or it is being used for 
00829     // the default page, font or scaling units.
00830     // Only do it if we haven't found above reason not to delete it
00831     if (DeleteReason == UNITREASON_OK)
00832         DeleteReason = pDocUnitList->DeleteUnit(CurrentUserUnitType);
00833 
00834     switch (DeleteReason)
00835     {
00836         case UNITREASON_OK :
00837             if (pNextUserUnit == NULL)
00838                 CurrentUserUnitType = NOTYPE;
00839             else
00840                 CurrentUserUnitType = pNextUserUnit->GetUnitType();
00841 
00842             EnableControls();
00843             InitControls();
00844             // Now make sure the current user unit is selected in the list
00845             SelectCurrentUserUnit();
00846 
00847             // Mark the document as modified as we have changed something
00848             // that is saved with the document.
00849             if (pDocument)
00850                 pDocument->SetModified(TRUE);
00851             break;
00852 
00853         case UNITREASON_HASDESCENDENTS:
00854             Error::SetError(_R(IDS_UNITERROR_HASDESCENDENTS),0);
00855             InformError();
00856             break;
00857 
00858         case UNITREASON_BEINGUSED:
00859             Error::SetError(_R(IDS_UNITERROR_BEINGUSED),0);
00860             InformError();
00861             break;
00862 
00863         default :
00864             ENSURE(FALSE,"Unexpected DeleteUnit reason");
00865             break;
00866     }
00867 
00868     return TRUE;
00869 }
00870 
00871 /********************************************************************************************
00872 
00873 >   BOOL UnitsTab::ShowUnitProperties()
00874 
00875     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00876     Created:    21/11/95
00877     Inputs:     - 
00878     Outputs:    -
00879     Returns:    -
00880     Purpose:    Shows the current properties of the selected user unit.
00881     Errors:     -
00882     SeeAlso:    -
00883 
00884 ********************************************************************************************/
00885 
00886 BOOL UnitsTab::ShowUnitProperties()
00887 {
00888     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::ShowUnitProperties called with no doc unit list");
00889 
00890     // Fire up the user units property dialog box, but only if we have
00891     // a current user unit to edit.
00892     BOOL Ok = TRUE; 
00893     if (CurrentUserUnitType != NOTYPE)
00894     {
00895         // This is ok as we are using a modal dialog box
00896         Ok = UnitPropertiesDlg::InvokeDialog(CurrentUserUnitType);
00897 
00898         // If Oked then make sure everything is updated to reflect this potential new info
00899         if (Ok)
00900         {
00901             // Make sure that the selected user units list item is updated with the new info.
00902             if (CurrentUserUnitType != NOTYPE)
00903             {
00904                 INT32 UnitIndex = pDocUnitList->FindUnitIndex(CurrentUserUnitType);
00905                 Unit * pUnit = pDocUnitList->FindFirstUserUnit();
00906                 if (pUnit)
00907                 {
00908                     UnitType FirstUserUnitType = pUnit->GetUnitType();
00909                     INT32 UserUnitIndex = pDocUnitList->FindUnitIndex(FirstUserUnitType); 
00910                     INT32 Index = UnitIndex - UserUnitIndex;
00911                     pPrefsDlg->DeleteValue(_R(IDC_OPTS_UNITSLIST), FALSE, Index);
00912                     ShowUnitDetails(_R(IDC_OPTS_UNITSLIST), CurrentUserUnitType, Index, FALSE);
00913                     pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_UNITSLIST), Index);
00914                 }
00915             }
00916 
00917             // Make sure the controls displaying user units are updated with this change.
00918             UpdateUnitListControls();
00919         }
00920     }
00921 
00922     return TRUE;
00923 }
00924 
00925 /********************************************************************************************
00926 
00927 >   BOOL UnitsTab::SelectCurrentUserUnit()
00928 
00929     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00930     Created:    21/11/95
00931     Inputs:     - 
00932     Outputs:    -
00933     Returns:    -
00934     Purpose:    Make sure that the current user unit, if any, is selected and hence shown as
00935                 selected in the user units list.
00936     Errors:     -
00937     SeeAlso:    -
00938 
00939 ********************************************************************************************/
00940 
00941 BOOL UnitsTab::SelectCurrentUserUnit()
00942 {
00943     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::CommitUserDialogValues called with no dialog pointer");
00944     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::CommitUserDialogValues called with no doc unit list pointer");
00945 
00946     // Check if the user has selected a valid user unit to edit
00947     // If not do nothing 
00948     if (CurrentUserUnitType != NOTYPE)
00949     {
00950         INT32 UnitIndex = pDocUnitList->FindUnitIndex(CurrentUserUnitType);
00951         Unit * pUnit = pDocUnitList->FindFirstUserUnit();
00952         if (pUnit)
00953         {
00954             UnitType FirstUserUnitType = pUnit->GetUnitType();
00955             INT32 UserUnitIndex = pDocUnitList->FindUnitIndex(FirstUserUnitType); 
00956             INT32 Index = UnitIndex - UserUnitIndex;
00957             pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_UNITSLIST), Index);
00958         }
00959     }
00960     
00961     return TRUE;
00962 }
00963 
00964 /********************************************************************************************
00965 
00966 >   BOOL UnitsTab::UpdateUnitListControls()
00967 
00968     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00969     Created:    8/9/95
00970     Inputs:     -
00971     Outputs:    -
00972     Returns:    -
00973     Purpose:    Updates the new name name of the currently selected user unit, if any in all
00974                 of the lists.
00975     SeeAlso:    UnitPropertiesDlg::DisplayUserUnitDetails;  UnitsTab::ShowUnitDetails;
00976 
00977 ********************************************************************************************/
00978 
00979 BOOL UnitsTab::UpdateUnitListControls()
00980 {
00981 TRACEUSER( "Neville", _T("UnitsTab::UpdateUnitListControls()\n"));
00982     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::UpdateUnitListControls called with no dialog pointer");
00983     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::UpdateUnitListControls called with no doc unit list pointer");
00984 
00985     // Make sure that we have the text for the current unit up to date
00986     String_256 TokenStr = _T("");
00987     String_32 TokenStr_32 = _T("");
00988     Unit* pCurUserUnit = NULL;
00989 
00990     pCurUserUnit = pDocUnitList->FindUnit(CurrentUserUnitType);
00991     if (pCurUserUnit != NULL)
00992     {
00993         // Get the current name for this unit
00994         TokenStr = pCurUserUnit->GetToken();
00995         //TokenStr = TokenStr_32;
00996 
00997         // Now update the name in the lists
00998         INT32 UnitIndex = pDocUnitList->FindUnitIndex(CurrentUserUnitType);
00999         // Have to delete them and then reinsert them back into the list
01000         // These lists have all units on
01001         pPrefsDlg->DeleteValue(_R(IDC_OPTS_PAGEUNITS), FALSE, UnitIndex);
01002         pPrefsDlg->DeleteValue(_R(IDC_OPTS_FONTUNITS), FALSE, UnitIndex);
01003         pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_PAGEUNITS), TokenStr, FALSE, UnitIndex);
01004         pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_FONTUNITS), TokenStr, FALSE, UnitIndex);
01005 
01006         // Must set the selected item as otherwise it will blank the main list item. 
01007 
01008         // Work out the indicies which these units correspond to on a list of units 
01009         // Get the current default settings
01010         UnitType PageUnits  = pDocUnitList->GetPageUnits();
01011         UnitType FontUnits  = pDocUnitList->GetFontUnits();
01012         INT32 PageUnitsIndex = pDocUnitList->FindUnitIndex(PageUnits);
01013         INT32 FontUnitsIndex = pDocUnitList->FindUnitIndex(FontUnits);
01014         
01015         // And now select the correct item on the list of units
01016         pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_PAGEUNITS), PageUnitsIndex);
01017         pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_FONTUNITS), FontUnitsIndex);
01018     }
01019 
01020     return TRUE;
01021 }
01022 
01023 
01024 /********************************************************************************************
01025 
01026 >   void UnitsTab::SetUnitToken(CGadgetID ID, UnitType ThisUnitType, INT32 Index = -1,
01027                                 BOOL EndOfList = FALSE)
01028 
01029     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01030     Created:    7/7/94
01031     Inputs:     ID = the ID of the control to put the unit token in
01032                 ThisUnitType = the type of the unit whose token you want putting in the control
01033                 Index = index into a drop list (-1 = main field)
01034                 EndOfList - if TRUE, item is stuck on end of list, regardless of Index
01035     Outputs:    -
01036     Returns:    -
01037     Purpose:    Readable function for putting unit token strings in controls.
01038     SeeAlso:    -
01039 
01040 ********************************************************************************************/
01041 
01042 void UnitsTab::SetUnitToken(CGadgetID ID, UnitType ThisUnitType, INT32 Index, BOOL EndOfList)
01043 {
01044     String_32 Str = pDocUnitList->GetToken(ThisUnitType);
01045     String_256 Str256 = Str;
01046     pPrefsDlg->SetStringGadgetValue(ID, Str256, EndOfList, Index);
01047 }
01048 
01049 /********************************************************************************************
01050 
01051 >   void UnitsTab::ShowUnitDetails(CGadgetID ID, UnitType ThisUnitType, INT32 Index = -1,
01052                                     BOOL EndOfList = FALSE)
01053 
01054     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01055     Created:    21/11/95
01056     Inputs:     ID = the ID of the control to put the unit token in
01057                 ThisUnitType = the type of the unit whose token you want putting in the control
01058                 Index = index into a drop list (-1 = main field)
01059                 EndOfList - if TRUE, item is stuck on end of list, regardless of Index
01060     Outputs:    -
01061     Returns:    -
01062     Purpose:    Shows the summary of the details of the specified unit for putting user unit
01063                 token strings in the scrollable details list.
01064     SeeAlso:    -
01065 
01066 ********************************************************************************************/
01067 
01068 void UnitsTab::ShowUnitDetails(CGadgetID ID, UnitType ThisUnitType, INT32 Index, BOOL EndOfList)
01069 {
01070     String_256 Details;
01071 
01072     String_32 Name = pDocUnitList->GetToken(ThisUnitType);
01073 
01074     // Add the abbreviation
01075     String_32 Abbrev = pDocUnitList->GetSpecifier(ThisUnitType);
01076 
01077     Unit* pCurUserUnit = NULL;
01078     pCurUserUnit = pDocUnitList->FindUnit(ThisUnitType);
01079 
01080     String_32 PrefixStr;
01081     double BaseNumerator = 0.0;
01082     double BaseDenominator = 0.0;
01083     String_32 Numerator;
01084     String_32 Denominator;
01085     String_32 BasedOn;
01086     if (pCurUserUnit)
01087     {
01088         // Set up the prefix/suffix state for this user's unit.
01089         if (pCurUserUnit->IsPrefix())
01090             PrefixStr.MakeMsg(_R(IDS_UNITS_PREFIX));
01091         else
01092             PrefixStr.MakeMsg(_R(IDS_UNITS_SUFFIX));
01093 
01094         BaseNumerator = pCurUserUnit->GetBaseNumerator();
01095         BaseDenominator = pCurUserUnit->GetBaseDenominator();
01096         Convert::DoubleToString(BaseNumerator, &Numerator);
01097         Convert::DoubleToString(BaseDenominator, &Denominator);
01098 
01099         UnitType BaseUnit = pCurUserUnit->GetBaseUnitType();
01100         BasedOn = pDocUnitList->GetSpecifier(BaseUnit);
01101     }
01102 
01103     Details.MakeMsg(_R(IDS_UNITSDESCRIPTION), (TCHAR*)Name, (TCHAR*)Abbrev, (TCHAR*)PrefixStr,
01104                                           (TCHAR*)Denominator, (TCHAR*)Numerator,
01105                                           (TCHAR*)BasedOn);
01106 
01107     pPrefsDlg->SetStringGadgetValue(ID, Details, EndOfList, Index);
01108 }
01109 
01110 /********************************************************************************************
01111 
01112 >   BOOL UnitsTab::InitControls()
01113 
01114     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01115     Created:    7/7/94
01116     Inputs:     -
01117     Outputs:    -
01118     Returns:    -
01119     Purpose:    Inits all the controls in the dialog
01120                 Called immediately after the bar is created to init drop lists, grey
01121                 out gadgets, etc.
01122     SeeAlso:    -
01123 
01124 ********************************************************************************************/
01125 
01126 BOOL UnitsTab::InitControls()
01127 {                            
01128 TRACEUSER( "Neville", _T("UnitsTab::InitControls\n"));
01129     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::InitControls called with no dialog pointer");
01130     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::InitControls called with no doc unit list pointer");
01131 
01132     InitUnitListControls();
01133 
01134     // Get the current default settings
01135     UnitType PageUnits   = pDocUnitList->GetPageUnits();    // The units used to display page measurements
01136     //UnitType ScaledUnits = pDocUnitList->GetScaleUnits(); // The units to display scaled measurements
01137     UnitType FontUnits   = pDocUnitList->GetFontUnits();    // The units to display font measurements
01138 
01139     // Work out the indicies which these units correspond to on a list of units 
01140     INT32 PageUnitsIndex = pDocUnitList->FindUnitIndex(PageUnits);
01141     INT32 FontUnitsIndex = pDocUnitList->FindUnitIndex(FontUnits);
01142     
01143     // And now select the correct item on the list of units
01144     pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_PAGEUNITS), PageUnitsIndex);
01145     pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_FONTUNITS), FontUnitsIndex);
01146 
01147 //  // Remember to add in the automatic units to the index calculation
01148 //  if (ScaledUnits != AUTOMATIC)
01149 //  {
01150 //      // Not Automatic so work out the index which this item corresponds to on the unit list
01151 //      INT32 ScaleUnitsIndex = pDocUnitList->FindUnitIndex(ScaledUnits);
01152 //      pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_SCALEDUNITS), ScaleUnitsIndex + 1);
01153 //  }
01154 //  else
01155 //      pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_SCALEDUNITS), 0);
01156 
01157     // Note entry state of controls
01158     //OldScaledUnits = ScaledUnits; 
01159     OldPageUnits = PageUnits; 
01160     OldFontUnits = FontUnits; 
01161     
01162     m_pOldColourUnit = GetColourUnitPreference();
01163     if (m_pOldColourUnit == NULL)
01164         return FALSE;
01165     m_ColourUnitRadioGroup.SetDefault(m_pOldColourUnit);
01166 
01167     EnableControls();
01168 
01169     return TRUE;
01170 }
01171 
01172 /********************************************************************************************
01173 
01174 >   ScaleUnit* UnitsTab::GetColourUnitPreference()
01175 
01176     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01177     Created:    26/06/96
01178     Inputs:     -
01179     Outputs:    -
01180     Returns:    A pointer to the preferred colour unit
01181                 NULL if an error occurred
01182     Purpose:    Retrieves the user's Colour Unit preference to be used by the Colour Editor
01183                 If no preference is found StandardUnit::UnitPercent is the default
01184     Scope:      static
01185 
01186 ********************************************************************************************/
01187 ScaleUnit* UnitsTab::GetColourUnitPreference()
01188 {
01189     String_32 DefaultUnitString;
01190     Camelot.GetPrefDirect(ColourUnitSection, ColourUnitPreference, &DefaultUnitString);
01191     ScaleUnit* pColourUnit = StandardUnit::PercentGroup.FindUnitFromQualifier(DefaultUnitString);
01192     if (pColourUnit == NULL)        // no default has been set
01193         pColourUnit = &StandardUnit::UnitPercent;
01194     if (!pColourUnit->IS_KIND_OF(ScaleUnit))
01195     {
01196         ERROR3("m_pOldColourUnit is not");
01197         return NULL;
01198     }
01199     return pColourUnit;
01200 }
01201 
01202         
01203 /********************************************************************************************
01204 
01205 >   BOOL UnitsTab::InitUnitListControls()
01206 
01207     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01208     Created:    7/7/94
01209     Inputs:     -
01210     Outputs:    -
01211     Returns:    -
01212     Purpose:    Fills in all the drop lists and combo boxes of units with the ones in the
01213                 document.
01214     SeeAlso:    -
01215 
01216 ********************************************************************************************/
01217 
01218 BOOL UnitsTab::InitUnitListControls()
01219 {                            
01220 TRACEUSER( "Neville", _T("UnitsTab::InitControls()\n"));
01221     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::InitUnitListControls called with no dialog pointer");
01222     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::InitUnitListControls called with no doc unit list pointer");
01223 
01224     INT32 i;
01225     Unit* pUnit = NULL;
01226 
01227     // Make sure all the lists are blank
01228     pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_PAGEUNITS));
01229     //pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_SCALEDUNITS));
01230     pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_FONTUNITS));
01231 
01232     pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_UNITSLIST));
01233 
01234     //SetUnitToken(_R(IDC_OPTS_SCALEDUNITS),AUTOMATIC,0);
01235 
01236     UnitType ThisUnitType = NOTYPE;
01237     for (i = 0; i < pDocUnitList->GetNumUnits(); i++)
01238     {
01239         pUnit = pDocUnitList->FindUnit(i);
01240         ThisUnitType = pUnit->GetUnitType();
01241         SetUnitToken(_R(IDC_OPTS_PAGEUNITS), ThisUnitType , i);
01242         //SetUnitToken(_R(IDC_OPTS_SCALEDUNITS), ThisUnitType, i+1);
01243         SetUnitToken(_R(IDC_OPTS_FONTUNITS), ThisUnitType, i);
01244     }
01245 
01246     // Update the list of user unit details
01247     pUnit = pDocUnitList->FindFirstUserUnit();
01248     for (i = 0; pUnit != NULL; i++)
01249     {
01250         ShowUnitDetails(_R(IDC_OPTS_UNITSLIST),pUnit->GetUnitType(), i);
01251         pUnit = pDocUnitList->FindNextUserUnit(pUnit);
01252     }
01253 
01254     return TRUE;
01255 }           
01256 
01257 
01258 /********************************************************************************************
01259 
01260 >   BOOL UnitsTab::EnableControls()
01261 
01262     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01263     Created:    7/7/94
01264     Inputs:     -
01265     Outputs:    -
01266     Returns:    -
01267     Purpose:    Enables or disables the controls depending on the current context, i.e.
01268                 the controls are disabled if there is no selection, etc.
01269     SeeAlso:    -
01270 
01271 ********************************************************************************************/
01272 
01273 BOOL UnitsTab::EnableControls()
01274 {
01275 TRACEUSER( "Neville", _T("UnitsTab::EnableControls\n"));
01276     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::EnableControls called with no dialog pointer");
01277     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::EnableControls called with no doc unit list pointer");
01278 
01279     BOOL enable = (pDocUnitList->FindFirstUserUnit() != NULL);
01280 
01281     pPrefsDlg->EnableGadget(_R(IDC_OPTS_DELETEUNIT),    enable);
01282     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNITPROPERTY),  enable);
01283 
01284     return TRUE;
01285 }           
01286 
01287 
01288 
01289 /******************************************************************************************
01290 
01291 >   BOOL UnitsTab::InitSection()
01292 
01293     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01294     Created:    6/12/94
01295     Inputs:     -
01296     Outputs:    -
01297     Returns:    TRUE if successful, else FALSE
01298     Purpose:    Sets initial values for the Units section of the options dialog box.
01299                 This section includes the:-
01300     Errors:     -
01301     SeeAlso:    -
01302 
01303 ******************************************************************************************/
01304 
01305 BOOL UnitsTab::InitSection()
01306 {
01307 TRACEUSER( "Neville", _T("InitUnitsSection\n"));
01308     ERROR2IF(pPrefsDlg == NULL,FALSE,"UnitsTab::InitSection called with no dialog pointer");
01309 
01310     // Make sure the information field displaying the name of the current document
01311     // is correct.
01312     String_256  DocumentName(_R(IDT_OPTS_UNITS_INFO)); 
01313     DocumentName += *GetDocumentName();
01314     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
01315 
01316     m_ColourUnitRadioGroup.SetAssociations((DialogOp*)pPrefsDlg, ColourUnitAssociations, NUM_CLR_DEFAULTS);
01317 
01318     // If no current document then do nothing as this may be valid
01319     // Use the document specified in the base class (OptionsTabs)
01320     if (pDocument != NULL)
01321     {
01322         // This uses current doc instead of selected doc
01323         //pDocUnitList = DocUnitList::GetCurrentDocUnitList();
01324         pDocUnitList = pDocument->GetDocUnitList();
01325         ERROR3IF(pDocUnitList == NULL,"Where's the current doc unit list eh?");
01326 
01327         if (pDocUnitList != NULL)
01328         {
01329             // Find out if we have any user defined units in this document 
01330             Unit* pUserUnit = pDocUnitList->FindFirstUserUnit();
01331             if (pUserUnit != NULL)
01332                 CurrentUserUnitType = pUserUnit->GetUnitType();
01333             else
01334                 CurrentUserUnitType  = NOTYPE;
01335         }
01336         else
01337         {
01338             // Could not create and hence find any units
01339             pDocUnitList = NULL;        // reset the unit list to null just in case
01340             // Ensure our section is greyed.
01341             GreySection();
01342             return FALSE;               // Could not initialise ok so fail 
01343         }                   
01344 
01345         // Section = Units
01346 
01347         InitControls();
01348         SelectCurrentUserUnit();
01349         //ShowUnitDetails();
01350     }
01351     else
01352     {
01353         // Ensure our section is greyed.
01354         GreySection();
01355     }
01356             
01357     return TRUE;
01358 }
01359 
01360 
01361 
01362 /******************************************************************************************
01363 ***** User units properties dialog box                                                  ***
01364 ******************************************************************************************/
01365 
01366 
01367 
01368 /******************************************************************************************
01369 
01370 >   BOOL UnitPropertiesDlg::InvokeDialog(UnitType CurrentUserUnitType) 
01371 
01372     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01373     Created:    20/11/95
01374     Inputs:     The UnitType of the user unit to edit.
01375     Outputs:    -
01376     Returns:    True if Ok used or False if Cancel used.
01377     Purpose:    How to invoke or start a UnitPropertiesDlg box.
01378     Errors:     -
01379     SeeAlso:    -
01380 
01381 ******************************************************************************************/
01382 
01383 BOOL UnitPropertiesDlg::InvokeDialog(UnitType CurrentUserUnitType)
01384 {
01385     OpDescriptor *pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_UNITPROPERTIESDLG);
01386 
01387     ERROR3IF(pOpDesc == NULL,"UnitPropertiesDlg::InvokeDialog is unable to find the UnitPropertiesDlg OpDescriptor");
01388 
01389     // Actually start up the user units properties dialog box.
01390     // Send in some useful paramters
01391     BOOL IsEditOK = FALSE;
01392     UnitType CurUserUnitType = CurrentUserUnitType;
01393     OpParam Params((void *)&CurUserUnitType, (void *)&IsEditOK);
01394     if (pOpDesc != NULL)
01395         pOpDesc->Invoke(&Params);
01396 
01397     return IsEditOK;
01398 }
01399 
01400 
01401 
01402 /******************************************************************************************
01403 
01404 >   UnitPropertiesDlg::UnitPropertiesDlg(): DialogOp(UnitPropertiesDlg::IDD, UnitPropertiesDlg::Mode) 
01405 
01406 
01407     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01408     Created:    20/11/95
01409     Inputs:     -
01410     Outputs:    -
01411     Returns:    -
01412     Purpose:    UnitPropertiesDlg constructor. Creates a non-undoable operation
01413     Errors:     -
01414     SeeAlso:    -
01415 
01416 ******************************************************************************************/
01417 
01418 UnitPropertiesDlg::UnitPropertiesDlg(): DialogOp(UnitPropertiesDlg::IDD, UnitPropertiesDlg::Mode) 
01419 {
01420     // Set up some useful defaults
01421     CurrentUserUnitType = NOTYPE;
01422     pDocUnitList = NULL;
01423     pIsOk = NULL;
01424 }
01425 
01426 /******************************************************************************************
01427 
01428 >   BOOL UnitPropertiesDlg::CommitDialogValues(UnitPropertiesDlg* pBmpPrefs)
01429 
01430     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01431     Created:    20/11/95
01432     Inputs:     pointer to the dialogue box
01433     Outputs:    -
01434     Returns:    True if values in dialog box ok, False otherwise.     
01435     Purpose:    Takes the values in the dialog box and sets the return values accordingly
01436                 Called when ok is pressed on the dialog box.
01437     Errors:     -
01438     SeeAlso:    -
01439 
01440 ******************************************************************************************/
01441 
01442 BOOL UnitPropertiesDlg::CommitDialogValues()
01443 {
01444     ERROR3IF(this == NULL, "UnitPropertiesDlg::CommitDialogValues called after duff initialisation?!");
01445     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitPropertiesDlg::CommitDialogValues called with no doc unit list pointer");
01446 
01447     // Check if the user has selected a valid user unit to edit
01448     // If not do nothing 
01449     if (CurrentUserUnitType != NOTYPE)
01450     {
01451         // Read in the current unit values from the fields available
01452         Unit* pCurUserUnit = NULL;
01453         pCurUserUnit = pDocUnitList->FindUnit(CurrentUserUnitType);
01454 
01455         // General validation BOOLEAN 
01456         BOOL Valid  = FALSE;
01457 
01458         // Is the prefix or suffix radio buttons selected
01459         BOOL Prefix = GetLongGadgetValue(_R(IDC_OPTS_UNITPREFIX), 0, 1, 0, &Valid);
01460 
01461         // Work out the abbreviation that it has been gievn
01462         String_256 SpecifierStr = "";
01463         SpecifierStr = GetStringGadgetValue(_R(IDC_OPTS_UNITSPEC), &Valid);
01464         if (SpecifierStr.Length() == 0)
01465         {
01466             // There is a problem so warn the user that the value is incorrect
01467             InformWarning(_R(IDE_OPTS_BADSPECSTRING));
01468             return FALSE;
01469         }
01470 
01471         // Work out the name that the unit has been given
01472         String_256 TokenStr = "";
01473         TokenStr     = GetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN), &Valid);
01474         if (TokenStr.Length() == 0)
01475         {
01476             // There is a problem so warn the user that the value is incorrect
01477             InformWarning(_R(IDE_OPTS_BADTOKENSTRING));
01478             return FALSE;
01479         }
01480 
01481         // Work out the number of this units that the user has specified as being
01482         // equivalent to the number of specified units.
01483 
01484         // We need to set a maximum value as some things are bound to fall over if not 
01485         // Status line x,y display is usually the first.
01486         const double MaxValue = (double)INT32_MAX;
01487         // Set up useful defaults in case of failure
01488         double NewBaseDenominator = 0.0;
01489         NewBaseDenominator = GetDoubleGadgetValue(_R(IDC_OPTS_NUMNEWUNITS),
01490                                                      0, MaxValue, 
01491                                                      _R(IDE_OPTS_BADUNITDENOMINATOR), &Valid);
01492         // If an invalid value has been entered then exit immeditaely, the user has
01493         // already been warned
01494         if (!Valid)
01495             return FALSE;
01496             
01497         // Must check if zero as this is a very bad value to set and difficult to check above.
01498         if (NewBaseDenominator == 0 )
01499         {
01500             // There is a problem so warn the user that the value is incorrect
01501             InformWarning(_R(IDE_OPTS_BADUNITDENOMINATOR));
01502             return FALSE;
01503         }           
01504 
01505         // Now work out the number of the chosen units that the user has specified as being
01506         // equivalent to this unit. 
01507         // Set up useful defaults in case of failure
01508         double NewBaseNumerator = 0.0;
01509         NewBaseNumerator = GetDoubleGadgetValue(_R(IDC_OPTS_NUMBASEUNITS),
01510                                                  0, MaxValue, 
01511                                                  _R(IDE_OPTS_BADUNITNUMERATOR), &Valid);
01512         // If an invalid value has been entered then exit immeditaely, the user has
01513         // already been warned
01514         if (!Valid)
01515             return FALSE;
01516 
01517         // Must check if zero as this is a very bad value to set and difficult to check above.
01518         if (NewBaseNumerator == 0 )
01519         {
01520             // There is a problem so warn the user that the value is incorrect
01521             InformWarning(_R(IDE_OPTS_BADUNITNUMERATOR));
01522             return FALSE;
01523         }           
01524 
01525         // Work out what unit type has been selected that this user unit is based on  
01526         WORD Index = 0;
01527         UnitType NewBaseUnitType = NOTYPE;
01528         Unit * pBaseUnit = NULL; 
01529         GetValueIndex(_R(IDC_OPTS_BASEUNIT), &Index);
01530         pBaseUnit = pDocUnitList->FindUnit(Index);
01531         if (pBaseUnit)
01532             NewBaseUnitType = pBaseUnit->GetUnitType();
01533 
01534         // As long as we have a valid user unit pointer, go and set the new values in it
01535         //TCHAR* pTokenStr = TokenStr;
01536         //TCHAR* pSpecifierStr = SpecifierStr;
01537         String_32  Str32 = _T("");
01538         if (pCurUserUnit != NULL)
01539         {
01540             BOOL ok = TRUE;
01541             
01542             // Set up the new values that we have verified may be useful new ones to use
01543             pCurUserUnit->SetPrefixState(Prefix);
01544             
01545             //Str32 = pTokenStr;
01546             TokenStr.Left(&Str32, Str32.MaxLength());
01547             ok = pCurUserUnit->SetToken(Str32);
01548             if (!ok)
01549             {
01550                 InformWarning(_R(IDE_OPTS_BADTOKENSTRING));
01551                 return FALSE;
01552             }
01553 
01554             //Str32 = pSpecifierStr;
01555             SpecifierStr.Left(&Str32, Str32.MaxLength());
01556             ok = pCurUserUnit->SetSpecifier(Str32);
01557             if (!ok)
01558             {
01559                 InformWarning(_R(IDE_OPTS_BADSPECSTRING));
01560                 return FALSE;
01561             }
01562 
01563             ok = pCurUserUnit->SetBaseNumerator(NewBaseNumerator);
01564             if (!ok)
01565             {
01566                 InformWarning(_R(IDE_OPTS_BADUNITNUMERATOR));
01567                 return FALSE;
01568             }
01569 
01570             ok = pCurUserUnit->SetBaseDenominator(NewBaseDenominator);
01571             if (!ok)
01572             {
01573                 InformWarning(_R(IDE_OPTS_BADUNITDENOMINATOR));
01574                 return FALSE;
01575             }
01576 
01577             if (NewBaseUnitType != NOTYPE)
01578                 pCurUserUnit->SetBaseUnitType(NewBaseUnitType);
01579 
01580             pDocUnitList->RecalcUnit(pCurUserUnit);
01581             //pDocUnitList->UnitHasChanged(pCurUserUnit->GetUnitType());
01582             pDocUnitList->UnitHasChanged(CurrentUserUnitType);
01583         }
01584     }
01585 
01586     // Everything went swimminlgly and so we can exit in the knowledge that the dialog 
01587     // box can be closed.
01588     return TRUE;
01589 }
01590 
01591 /******************************************************************************************
01592 
01593 >   MsgResult UnitPropertiesDlg::Message(CDlgMessage DlgMsg, CGadgetID Gadget) 
01594 
01595 
01596     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01597     Created:    20/11/95
01598     Inputs:     -
01599     Outputs:    -
01600     Returns:    -
01601     Purpose:    Handles all the bitmap preferences dialog's messages
01602     Errors:     -
01603     SeeAlso:    -
01604 
01605 ******************************************************************************************/
01606 
01607 MsgResult UnitPropertiesDlg::Message(Msg* Message)
01608 {
01609     ERROR3IF(this == NULL, "UnitPropertiesDlg::Message - Null this!");
01610     ERROR3IF(Message == NULL, "UnitPropertiesDlg::Message - Parameters not been set up");
01611 
01612     if (IS_OUR_DIALOG_MSG(Message))
01613     {
01614         DialogMsg* Msg = (DialogMsg*)Message;
01615 
01616         MsgResult Result;
01617 
01618         BOOL EndDialog = FALSE;     // TRUE if we should quit the dialog
01619 
01620         // Should now handle the required messages that we respond to
01621         switch (Msg->DlgMsg)
01622         {
01623             case DIM_CREATE:
01624                 {
01625                     InitDialog();
01626                 }
01627             break;
01628 
01629             case DIM_COMMIT:
01630                 {
01631                     // (ok) accept all changes that the user has made to the settings
01632                     BOOL ok;
01633                     ok = CommitDialogValues();
01634                     if (ok)
01635                     {
01636                         // Values found ok so quit dialogue
01637                         EndDialog = TRUE;               // Flag to close and end
01638                         if (pIsOk)
01639                             *pIsOk = TRUE;              // flag an ok return
01640                     }
01641                     else
01642                         Msg->DlgMsg = DIM_NONE;
01643                 }
01644             break;
01645 
01646             case DIM_CANCEL:
01647                 // Cancel all changes that the user has made to the settings
01648                 EndDialog = TRUE;   // Flag to close and end
01649                 if (pIsOk)
01650                     *pIsOk = FALSE; // flag a bad return
01651             break;
01652 
01653 //          case DIM_LFT_BN_CLICKED:
01654 //              // A control on the dialog box has been clicked...
01655 //              switch (Msg->GadgetID)
01656 //              {
01657 //                  case _R(IDC_BMPOPTS_SPREAD):
01658 //                  break;
01659 //              }
01660 //          break; // DIM_LFT_BN_CLICKED        
01661 //
01662             case DIM_SELECTION_CHANGED:
01663             {
01664                 // A control on the dialog box has been typed in...
01665                 //ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::HandleMsg called with no doc unit list");
01666                 
01667                 WORD Index = 0;
01668                 Unit* pUnit = NULL;
01669                 Unit* pCurUserUnit = NULL;
01670 
01671                 if (Msg->GadgetID == _R(IDC_OPTS_BASEUNIT))
01672                 {
01673                     // The user has chosen a new base unit
01674                     GetValueIndex(_R(IDC_OPTS_BASEUNIT),&Index);
01675                     pUnit        = pDocUnitList->FindUnit(Index);
01676                     pCurUserUnit = pDocUnitList->FindUnit(CurrentUserUnitType);
01677                     if (pUnit->GetUnitType() == CurrentUserUnitType)
01678                     {
01679                         // Warn the user that this is the current unit
01680                         Error::SetError(_R(IDS_UNITERROR_BASEISCURRENT),0);
01681                         InformError();
01682                         // And reselect the old one unit type in the list
01683                         UnitType BaseUnit = pCurUserUnit->GetBaseUnitType(); 
01684                         INT32 BaseUnitIndex = pDocUnitList->FindUnitIndex(BaseUnit);
01685                         SetSelectedValueIndex(_R(IDC_OPTS_BASEUNIT), BaseUnitIndex);
01686                     }
01687                     else if (pDocUnitList->IsDescendent(pUnit,CurrentUserUnitType))
01688                     {
01689                         // Warn the user that the selected unit is a descendent
01690                         Error::SetError(_R(IDS_UNITERROR_BASEISDESCENDENT),0);
01691                         InformError();
01692                         // And reselect the old one unit type in the list
01693                         UnitType BaseUnit = pCurUserUnit->GetBaseUnitType();
01694                         INT32 BaseUnitIndex = pDocUnitList->FindUnitIndex(BaseUnit);
01695                         SetSelectedValueIndex(_R(IDC_OPTS_BASEUNIT), BaseUnitIndex);
01696                     }
01697                     // Otherwise selection is ok so do nothing
01698                 }
01699             }
01700             break; // DIM_SELECTION_CHANGED
01701 
01702             case DIM_TEXT_CHANGED:
01703                 if (Msg->GadgetID == _R(IDC_OPTS_UNITTOKEN))
01704                 {
01705                     // User is editing the main user unit name
01706                     // Update the text in the X <UnitsName> are equivalent to ... field 
01707                     BOOL Valid;
01708                     String_256 TokenStr = GetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN),&Valid);
01709                     SetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN2),TokenStr);
01710                 }
01711                 break;  // DIM_TEXT_CHANGED
01712 
01713             default:
01714                 break;
01715         }
01716 
01717         // Must do this before the Close and End
01718         Result = DialogOp::Message(Message);
01719 
01720 // Commented out as base class closes the dialog in LX.
01721 #if 0
01722         // End dialog here
01723         if (EndDialog) 
01724         {
01725             Close();                // Hide the dialog box
01726             End();                  // Finish the operation
01727         }
01728 #endif
01729 
01730         // The message was for our dialog box so return that we have handled it, if necessary
01731         return Result;
01732     }
01733 
01734     return DialogOp::Message(Message); 
01735 }
01736 
01737 
01738 /******************************************************************************************
01739 
01740 >   OpState UnitPropertiesDlg::GetState(String_256*, OpDescriptor*)
01741 
01742     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01743     Created:    20/11/95
01744     Inputs:     -
01745     Outputs:    -
01746     Returns:    -
01747     Purpose:    UnitPropertiesDlg GetState method
01748     Errors:     -
01749     SeeAlso:    -
01750 
01751 ******************************************************************************************/
01752 
01753 OpState UnitPropertiesDlg::GetState(String_256*, OpDescriptor*)
01754 {    
01755     OpState OpSt;
01756     return(OpSt);
01757 }
01758 
01759 /******************************************************************************************
01760 
01761 >   BOOL UnitPropertiesDlg::InitDialog()
01762 
01763     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01764     Created:    20/11/95
01765     Inputs:     pointer to the dialog box
01766     Outputs:    -
01767     Returns:    TRUE if successful, else FALSE
01768     Purpose:    Sets initial dialog values 
01769     Errors:     -
01770     SeeAlso:    -
01771 
01772 ******************************************************************************************/
01773 
01774 BOOL UnitPropertiesDlg::InitDialog()
01775 {
01776     ERROR3IF(this == NULL, "UnitPropertiesDlg::InitDialog called after duff initialisation?!");
01777 
01778     // Fill in the based on unit list with all the current units that are available
01779     INT32 i;
01780     Unit* pUnit = NULL;
01781 
01782     DeleteAllValues(_R(IDC_OPTS_BASEUNIT));
01783 
01784     UnitType ThisUnitType = NOTYPE;
01785     for (i = 0; i < pDocUnitList->GetNumUnits(); i++)
01786     {
01787         pUnit = pDocUnitList->FindUnit(i);
01788         ThisUnitType = pUnit->GetUnitType();
01789         SetUnitToken(_R(IDC_OPTS_BASEUNIT), ThisUnitType, i);
01790     }
01791 
01792     DisplayUserUnitDetails();
01793 
01794     return TRUE;
01795 }
01796 
01797 
01798 /******************************************************************************************
01799 
01800 >   BOOL UnitPropertiesDlg::Init()
01801 
01802     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01803     Created:    20/11/95
01804     Inputs:     -
01805     Outputs:    -
01806     Returns:    -
01807     Purpose:    UnitPropertiesDlg Init method
01808     Errors:     -
01809     SeeAlso:    -
01810 
01811 ******************************************************************************************/
01812 
01813 BOOL UnitPropertiesDlg::Init()
01814 {
01815     BOOL InitOK;
01816 
01817     InitOK = RegisterOpDescriptor(
01818                                 0,                              // Tool ID
01819                                 _R(IDS_UNITPROPERTIESDLG),              // String resource ID
01820                                 CC_RUNTIME_CLASS(UnitPropertiesDlg),    // Runtime class
01821                                 OPTOKEN_UNITPROPERTIESDLG,      // Token string
01822                                 GetState,                       // GetState function
01823                                 0,                              // help ID
01824                                 0,                              // bubble help
01825                                 0,                              // resource ID
01826                                 0,                              // control ID
01827                                 SYSTEMBAR_ILLEGAL,              // Bar ID
01828                                 TRUE,                           // Recieve system messages
01829                                 FALSE,                          // Smart duplicate operation
01830                                 TRUE,                           // Clean operation
01831                                 0,                              // No vertical counterpart
01832                                 _R(IDS_UNITPROPERTIESDLG_ONE),      // String for one copy only error
01833                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
01834                                 );
01835 
01836     return (InitOK);
01837 }
01838 
01839 
01840 
01841 
01842 /********************************************************************************************
01843 
01844 >   BOOL UnitPropertiesDlg::Create()
01845 
01846     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01847     Created:    20/11/95
01848     Inputs:     -
01849     Outputs:    -
01850     Returns:    TRUE if successful, else FALSE
01851     Purpose:    UnitPropertiesDlg create method 
01852     Errors:     -
01853     SeeAlso:    -
01854 
01855 ********************************************************************************************/
01856 
01857        
01858 BOOL UnitPropertiesDlg::Create()
01859 {                            
01860     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitPropertiesDlg::Create No doc unit list attached to this doc yet");
01861 
01862     if (DialogOp::Create())
01863     { 
01864         // Set the initial control values 
01865         // Dialog now Modal so set up happens in the message handler
01866         //InitDialog(this);
01867 
01868         return TRUE; 
01869     }
01870     else
01871     {
01872         return FALSE; 
01873     }
01874 }
01875 
01876 
01877 
01878 
01879 /******************************************************************************************
01880 
01881 >   void UnitPropertiesDlg::Do(OpDescriptor*)
01882 
01883     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01884     Created:    20/11/95
01885     Inputs:     -
01886     Outputs:    -
01887     Returns:    -
01888     Purpose:    Creates then opens the dialog in response to a request from the user.
01889     Errors:     -
01890     SeeAlso:    -
01891 
01892 ******************************************************************************************/
01893 
01894 void UnitPropertiesDlg::Do(OpDescriptor*)
01895 {
01896     BOOL ok;
01897     
01898     // Get a current document unit list
01899     Document * pDocument = Document::GetSelected();
01900     ERROR3IF(pDocument == NULL,"UnitPropertiesDlg::DoWithParam No selected document");
01901 
01902     // Set up some useful defaults
01903     pDocUnitList = NULL;
01904     pIsOk = NULL;
01905     
01906     if (pDocument)
01907         pDocUnitList = pDocument->GetDocUnitList();
01908     ERROR3IF(pDocUnitList == NULL,"UnitPropertiesDlg::DoWithParam No doc unit list attached to this doc yet");
01909 
01910     // Force a decent CurrentUserUnitType
01911     CurrentUserUnitType = NOTYPE;
01912 
01913     // Force the dialog box to be created, as it is modal it will be opened via a message
01914     ok = Create();
01915 
01916     if ( !ok )
01917     {
01918         // Could not create the dialog box so call inform error 
01919         InformError();
01920         End();         // End the operation 
01921     }
01922 }
01923 
01924 /******************************************************************************************
01925 
01926 >   void UnitPropertiesDlg::DoWithParam(OpDescriptor*, OpParam* Param)
01927 
01928     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01929     Created:    20/11/95
01930     Inputs:     OpDescriptor - Not Used.
01931                 pOpParam->Param1 - The user unit type to be edited.
01932                 pOpParam->Param2 - Should be a pointer to a BOOL that will hold the result of
01933                 the operation.
01934     Outputs:    -
01935     Returns:    -
01936     Purpose:    Creates then opens the dialog in response to a request from the user.
01937                 The parameter is actually the user unit type to be edited.  Errors:     -
01938     SeeAlso:    -
01939 
01940 ******************************************************************************************/
01941 
01942 void UnitPropertiesDlg::DoWithParam(OpDescriptor*, OpParam* pOpParam)
01943 {
01944     ERROR3IF(pOpParam == NULL, "UnitPropertiesDlg::DoWithParam - NULL Param passed in");
01945 
01946     // Get a current document unit list
01947     Document * pDocument = Document::GetSelected();
01948     ERROR3IF(pDocument == NULL,"UnitPropertiesDlg::DoWithParam No selected document");
01949 
01950     // Get the unit list attached to the current document
01951     pDocUnitList = NULL;
01952     if (pDocument)
01953         pDocUnitList = pDocument->GetDocUnitList();
01954     ERROR3IF(pDocUnitList == NULL,"UnitPropertiesDlg::DoWithParam No doc unit list attached to this doc yet");
01955 
01956     // Use the OpParam that has been passed in to us
01957     // Force a decent CurrentUserUnitType
01958     CurrentUserUnitType = NOTYPE;
01959     UnitType * pCurUserUnitType = (UnitType*) (void *) pOpParam->Param1;
01960     pIsOk = (BOOL*) (void *) pOpParam->Param2;
01961 
01962     CurrentUserUnitType = *pCurUserUnitType;
01963 
01964     BOOL ok;
01965     
01966     // Force the dialog box to be created, as it is modal it will be opened via a message
01967     ok = Create();
01968 
01969     if ( !ok )
01970     {
01971         // Could not create the dialog box so call inform error 
01972         InformError();
01973         End();         // End the operation 
01974 
01975         *pIsOk = FALSE; // flag a bad return
01976     }
01977 }
01978 
01979 /********************************************************************************************
01980 
01981 >   void UnitPropertiesDlg::SetUnitToken(CGadgetID ID, UnitType ThisUnitType, INT32 Index = -1,
01982                                 BOOL EndOfList = FALSE)
01983 
01984     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01985     Created:    7/7/94
01986     Inputs:     ID = the ID of the control to put the unit token in
01987                 ThisUnitType = the type of the unit whose token you want putting in the control
01988                 Index = index into a drop list (-1 = main field)
01989                 EndOfList - if TRUE, item is stuck on end of list, regardless of Index
01990     Outputs:    -
01991     Returns:    -
01992     Purpose:    Readable function for putting unit token strings in controls.
01993                 MUST have a valid doc unit list
01994     SeeAlso:    -
01995 
01996 ********************************************************************************************/
01997 
01998 void UnitPropertiesDlg::SetUnitToken(CGadgetID ID, UnitType ThisUnitType, INT32 Index, BOOL EndOfList)
01999 {
02000     if (pDocUnitList)
02001     {
02002         String_32 Str = pDocUnitList->GetToken(ThisUnitType);
02003         String_256 Str256 = Str;
02004         SetStringGadgetValue(ID, Str256, EndOfList, Index);
02005     }
02006 }
02007 
02008 /********************************************************************************************
02009 
02010 >   BOOL UnitPropertiesDlg::DisplayUserUnitDetails()
02011 
02012     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02013     Created:    20/11/95
02014     Inputs:     -
02015     Outputs:    -
02016     Returns:    -
02017     Purpose:    Displays the unit CurrentUserUnitType in the user-definable area of the
02018                 dialog.
02019                 Called when a new unit is made, or when another unit selected from the list
02020                 of user units.
02021                 UpdateUnitName added to allow suppression of the unit name updating. As when
02022                 a new unit is choosen from the user units list, the name is highlighted, and
02023                 hence overtyping works. If we fill the name in then the hightlighting is
02024                 removed but overtyping still works! Only do it if user units present.
02025     SeeAlso:    UnitsTab::ShowUnitDetails 
02026 
02027 ********************************************************************************************/
02028 
02029 BOOL UnitPropertiesDlg::DisplayUserUnitDetails()
02030 {                            
02031     ERROR2IF(this == NULL,FALSE,"UnitPropertiesDlg::DisplayUserUnitDetails called with no dialog pointer");
02032     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitPropertiesDlg::DisplayUserUnitDetails called with no doc unit list pointer");
02033 
02034     if (CurrentUserUnitType != NOTYPE)
02035     {
02036         Unit* pCurUserUnit = pDocUnitList->FindUnit(CurrentUserUnitType);
02037         ERROR2IF(pCurUserUnit == NULL,FALSE,"UnitPropertiesDlg::DisplayUserUnitDetails current user unit pointer null");
02038 
02039         String_32 Str;
02040         //TCHAR* p = Str;
02041         String_256 Str256;
02042         //TCHAR* p256 = Str256;
02043         
02044         // Show the name of the user's unit
02045         Str = pCurUserUnit->GetSpecifier();
02046         Str256 = Str;
02047         SetStringGadgetValue(_R(IDC_OPTS_UNITSPEC), Str256);
02048 
02049         // Set up the prefix/suffix state for this user's unit.
02050         BOOL PrefixState = FALSE;
02051         BOOL SuffixState = TRUE;
02052         if (pCurUserUnit->IsPrefix())
02053         {
02054             PrefixState = TRUE;
02055             SuffixState = FALSE;    
02056         }
02057         else
02058         {
02059             PrefixState = FALSE;
02060             SuffixState = TRUE; 
02061         } 
02062         SetLongGadgetValue(_R(IDC_OPTS_UNITPREFIX), PrefixState);
02063         SetLongGadgetValue(_R(IDC_OPTS_UNITSUFFIX), SuffixState);
02064 
02065         // Show the chosen equivalent settings
02066         // Set up useful defaults in case of failure
02067         double NewBaseNumerator = pCurUserUnit->GetBaseNumerator();
02068         double NewBaseDenominator = pCurUserUnit->GetBaseDenominator();
02069         SetDoubleGadgetValue(_R(IDC_OPTS_NUMBASEUNITS), NewBaseNumerator);
02070         SetDoubleGadgetValue(_R(IDC_OPTS_NUMNEWUNITS), NewBaseDenominator);
02071 
02072         // Update the name
02073         SetUnitToken(_R(IDC_OPTS_UNITTOKEN),  CurrentUserUnitType, -1);
02074         SetUnitToken(_R(IDC_OPTS_UNITTOKEN2), CurrentUserUnitType, 0, TRUE);
02075 
02076         // Now work out which item to select on the menu
02077         UnitType BaseUnit = pCurUserUnit->GetBaseUnitType();
02078         INT32 BaseUnitIndex = pDocUnitList->FindUnitIndex(BaseUnit);
02079         SetSelectedValueIndex(_R(IDC_OPTS_BASEUNIT), BaseUnitIndex);
02080     }
02081     else
02082     {
02083         // Blank everything as unit is NOTYPE
02084         String_256 Str256 = "";
02085 
02086         SetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN),    Str256);
02087         SetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN2),   Str256);
02088         SetStringGadgetValue(_R(IDC_OPTS_UNITSPEC),     Str256);
02089         SetStringGadgetValue(_R(IDC_OPTS_NUMNEWUNITS),  Str256);
02090         SetStringGadgetValue(_R(IDC_OPTS_NUMBASEUNITS), Str256);
02091         SetStringGadgetValue(_R(IDC_OPTS_BASEUNIT),     Str256);
02092     }
02093 
02094     return TRUE;
02095 }           
02096 
02097 #endif //webster

Generated on Sat Nov 10 03:46:22 2007 for Camelot by  doxygen 1.4.4