00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #include "camtypes.h"
00105 #include "appprefs.h"
00106
00107
00108 #include "optsunit.h"
00109
00110
00111
00112
00113 #include "optsmsgs.h"
00114
00115 #include "grid.h"
00116
00117 #include "radio.h"
00118 #include "scunit.h"
00119
00120
00121 #ifndef WEBSTER
00122 CC_IMPLEMENT_DYNAMIC(UnitsTab, OptionsTabs)
00123 CC_IMPLEMENT_DYNCREATE(UnitPropertiesDlg, DialogOp)
00124 #endif
00125
00126
00127
00128 DECLARE_SOURCE("$Revision: 1282 $");
00129
00130
00131
00132 static TCHAR* ColourUnitSection = TEXT("Displays");
00133 static TCHAR* ColourUnitPreference = TEXT("ColourEditorUnits");
00134
00135
00136
00137 CDlgResID UnitPropertiesDlg::IDD = _R(IDD_OPTS_UNITPROPERTIES);
00138 const CDlgMode UnitPropertiesDlg::Mode = MODAL;
00139
00140
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
00150 #ifndef WEBSTER
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 UnitsTab::UnitsTab()
00169 {
00170
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 UnitsTab::~UnitsTab()
00190 {
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 BOOL UnitsTab::Init()
00210 {
00211 CurrentUserUnitType = NOTYPE;
00212 pDocUnitList = NULL;
00213
00214
00215 BOOL ok = UnitPropertiesDlg::Init();
00216
00217 return ok;
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 CDlgResID UnitsTab::GetPageID()
00237 {
00238 return _R(IDD_OPTSTAB_UNITS);
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 BOOL UnitsTab::IsDocumentOption()
00258 {
00259 return TRUE;
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 BOOL UnitsTab::IsProgramOption()
00279 {
00280 return TRUE;
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
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));
00307 if (!ok)
00308 return TRUE;
00309
00310
00311
00312
00313
00314
00315 if (pDocument == NULL || pSpread == NULL)
00316 {
00317
00318
00319 GreySection();
00320 return TRUE;
00321 }
00322
00323 ok = CommitDialogValues();
00324
00325 return ok;
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
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));
00349 if (!ok)
00350 return TRUE;
00351
00352
00353
00354 String_256 DocumentName(_R(IDT_OPTS_UNITS_INFO));
00355 DocumentName += *GetDocumentName();
00356 pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00357
00358
00359 if (GreyStatus == TRUE)
00360 return TRUE;
00361
00362 m_ColourUnitRadioGroup.Disable();
00363
00364 ok = ChangeControlStatus(FALSE);
00365
00366 GreyStatus = TRUE;
00367
00368 return ok;
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
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));
00392 if (!ok)
00393 return TRUE;
00394
00395
00396
00397 String_256 DocumentName(_R(IDT_OPTS_UNITS_INFO));
00398 DocumentName += *GetDocumentName();
00399 pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00400
00401
00402 if (GreyStatus == FALSE)
00403 return TRUE;
00404
00405 m_ColourUnitRadioGroup.Enable();
00406
00407 ok = ChangeControlStatus(TRUE);
00408
00409 GreyStatus = FALSE;
00410
00411 return ok;
00412 }
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 BOOL UnitsTab::ChangeControlStatus(const BOOL Status)
00430 {
00431
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
00437 pPrefsDlg->EnableGadget(_R(IDC_OPTS_FONTUNITSTXT), Status);
00438 pPrefsDlg->EnableGadget(_R(IDC_OPTS_PAGEUNITS), Status);
00439
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
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
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
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));
00476 if (!ok)
00477 return TRUE;
00478
00479
00480 return InitSection();
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
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));
00505 if (!ok)
00506 return TRUE;
00507
00508 switch(Msg->DlgMsg)
00509 {
00510 case DIM_CREATE:
00511 GreyStatus = FALSE;
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
00521 ShowUnitProperties();
00522 else if (Msg->GadgetID == _R(IDC_OPTS_NEWUNIT))
00523
00524 CreateNewUnit();
00525 else if (Msg->GadgetID == _R(IDC_OPTS_DELETEUNIT))
00526
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
00538
00539 if (Msg->GadgetID == _R(IDC_OPTS_UNITSLIST))
00540 {
00541
00542
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
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
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
00583
00584
00585
00586
00587
00588
00589 UnitType PageUnitType = MILLIMETRES;
00590
00591 UnitType FontUnitType = COMP_POINTS;
00592 WORD Index;
00593
00594
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
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 if (pDocUnitList != NULL)
00617 {
00618 pDocUnitList->SetPageUnits(PageUnitType);
00619
00620 pDocUnitList->SetFontUnits(FontUnitType);
00621 }
00622
00623 ScaleUnit* pColourUnit = (ScaleUnit*)m_ColourUnitRadioGroup.GetSelected();
00624 ERROR3IF(pColourUnit == NULL, "UnitsTab::CommitDialogValues - Gibberish from GetSelected()");
00625
00626
00627
00628 if (
00629 (PageUnitType != OldPageUnits) ||
00630
00631 (FontUnitType != OldFontUnits) ||
00632 (pColourUnit != NULL && m_pOldColourUnit != pColourUnit) ||
00633 (CurrentUserUnitType == PageUnitType) ||
00634 (CurrentUserUnitType == FontUnitType)
00635 )
00636 {
00637
00638
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
00646
00647 BROADCAST_TO_ALL(OptionsChangingMsg(pDocument, OptionsChangingMsg::NEWUNITS));
00648
00649
00650
00651 if (pDocument &&
00652 (
00653 (PageUnitType != OldPageUnits) ||
00654 (FontUnitType != OldFontUnits)
00655 )
00656 )
00657 {
00658 pDocument->SetModified(TRUE);
00659 }
00660
00661
00662
00663 OldPageUnits = PageUnitType;
00664 OldFontUnits = FontUnitType;
00665 }
00666
00667
00668
00669
00670 if (CurrentUserUnitType != NOTYPE)
00671 {
00672
00673
00674 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_UNITS));
00675 if (!ok)
00676 return TRUE;
00677
00678
00679 UpdateUnitListControls();
00680 }
00681
00682 return TRUE;
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
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
00713
00714 BOOL Ok = TRUE;
00715 if (CurrentUserUnitType != NOTYPE)
00716 {
00717
00718 Ok = UnitPropertiesDlg::InvokeDialog(CurrentUserUnitType);
00719
00720 if (!Ok)
00721 DeleteUnit();
00722 }
00723
00724
00725 if (Ok)
00726 {
00727 EnableControls();
00728 SetUnitToken(_R(IDC_OPTS_PAGEUNITS), CurrentUserUnitType, 0,TRUE);
00729
00730 SetUnitToken(_R(IDC_OPTS_FONTUNITS), CurrentUserUnitType, 0,TRUE);
00731 InitControls();
00732
00733 SelectCurrentUserUnit();
00734
00735
00736 if (pDocument)
00737 pDocument->SetModified(TRUE);
00738 }
00739 }
00740 else
00741 {
00742
00743
00744 InformError();
00745 }
00746
00747 return TRUE;
00748 }
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
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
00785
00786
00787
00788 NodeGrid* pDefaultGrid = pSpread->FindFirstDefaultGridInSpread();
00789 if (pDefaultGrid)
00790 {
00791
00792
00793
00794
00795 UnitType GridUnits = pDefaultGrid->GetUnits(TRUE);
00796 if (CurrentUserUnitType == GridUnits)
00797 DeleteReason = UNITREASON_BEINGUSED;
00798 }
00799
00800
00801
00802
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
00812
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
00828
00829
00830
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
00845 SelectCurrentUserUnit();
00846
00847
00848
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
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886 BOOL UnitsTab::ShowUnitProperties()
00887 {
00888 ERROR2IF(pDocUnitList == NULL,FALSE,"UnitsTab::ShowUnitProperties called with no doc unit list");
00889
00890
00891
00892 BOOL Ok = TRUE;
00893 if (CurrentUserUnitType != NOTYPE)
00894 {
00895
00896 Ok = UnitPropertiesDlg::InvokeDialog(CurrentUserUnitType);
00897
00898
00899 if (Ok)
00900 {
00901
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
00918 UpdateUnitListControls();
00919 }
00920 }
00921
00922 return TRUE;
00923 }
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
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
00947
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
00967
00968
00969
00970
00971
00972
00973
00974
00975
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
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
00994 TokenStr = pCurUserUnit->GetToken();
00995
00996
00997
00998 INT32 UnitIndex = pDocUnitList->FindUnitIndex(CurrentUserUnitType);
00999
01000
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
01007
01008
01009
01010 UnitType PageUnits = pDocUnitList->GetPageUnits();
01011 UnitType FontUnits = pDocUnitList->GetFontUnits();
01012 INT32 PageUnitsIndex = pDocUnitList->FindUnitIndex(PageUnits);
01013 INT32 FontUnitsIndex = pDocUnitList->FindUnitIndex(FontUnits);
01014
01015
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
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
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
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
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
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
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
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
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
01135 UnitType PageUnits = pDocUnitList->GetPageUnits();
01136
01137 UnitType FontUnits = pDocUnitList->GetFontUnits();
01138
01139
01140 INT32 PageUnitsIndex = pDocUnitList->FindUnitIndex(PageUnits);
01141 INT32 FontUnitsIndex = pDocUnitList->FindUnitIndex(FontUnits);
01142
01143
01144 pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_PAGEUNITS), PageUnitsIndex);
01145 pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_FONTUNITS), FontUnitsIndex);
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
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
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
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)
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
01206
01207
01208
01209
01210
01211
01212
01213
01214
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
01228 pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_PAGEUNITS));
01229
01230 pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_FONTUNITS));
01231
01232 pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_UNITSLIST));
01233
01234
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
01243 SetUnitToken(_R(IDC_OPTS_FONTUNITS), ThisUnitType, i);
01244 }
01245
01246
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
01261
01262
01263
01264
01265
01266
01267
01268
01269
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
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
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
01311
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
01319
01320 if (pDocument != NULL)
01321 {
01322
01323
01324 pDocUnitList = pDocument->GetDocUnitList();
01325 ERROR3IF(pDocUnitList == NULL,"Where's the current doc unit list eh?");
01326
01327 if (pDocUnitList != NULL)
01328 {
01329
01330 Unit* pUserUnit = pDocUnitList->FindFirstUserUnit();
01331 if (pUserUnit != NULL)
01332 CurrentUserUnitType = pUserUnit->GetUnitType();
01333 else
01334 CurrentUserUnitType = NOTYPE;
01335 }
01336 else
01337 {
01338
01339 pDocUnitList = NULL;
01340
01341 GreySection();
01342 return FALSE;
01343 }
01344
01345
01346
01347 InitControls();
01348 SelectCurrentUserUnit();
01349
01350 }
01351 else
01352 {
01353
01354 GreySection();
01355 }
01356
01357 return TRUE;
01358 }
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
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
01390
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
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418 UnitPropertiesDlg::UnitPropertiesDlg(): DialogOp(UnitPropertiesDlg::IDD, UnitPropertiesDlg::Mode)
01419 {
01420
01421 CurrentUserUnitType = NOTYPE;
01422 pDocUnitList = NULL;
01423 pIsOk = NULL;
01424 }
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
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
01448
01449 if (CurrentUserUnitType != NOTYPE)
01450 {
01451
01452 Unit* pCurUserUnit = NULL;
01453 pCurUserUnit = pDocUnitList->FindUnit(CurrentUserUnitType);
01454
01455
01456 BOOL Valid = FALSE;
01457
01458
01459 BOOL Prefix = GetLongGadgetValue(_R(IDC_OPTS_UNITPREFIX), 0, 1, 0, &Valid);
01460
01461
01462 String_256 SpecifierStr = "";
01463 SpecifierStr = GetStringGadgetValue(_R(IDC_OPTS_UNITSPEC), &Valid);
01464 if (SpecifierStr.Length() == 0)
01465 {
01466
01467 InformWarning(_R(IDE_OPTS_BADSPECSTRING));
01468 return FALSE;
01469 }
01470
01471
01472 String_256 TokenStr = "";
01473 TokenStr = GetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN), &Valid);
01474 if (TokenStr.Length() == 0)
01475 {
01476
01477 InformWarning(_R(IDE_OPTS_BADTOKENSTRING));
01478 return FALSE;
01479 }
01480
01481
01482
01483
01484
01485
01486 const double MaxValue = (double)INT32_MAX;
01487
01488 double NewBaseDenominator = 0.0;
01489 NewBaseDenominator = GetDoubleGadgetValue(_R(IDC_OPTS_NUMNEWUNITS),
01490 0, MaxValue,
01491 _R(IDE_OPTS_BADUNITDENOMINATOR), &Valid);
01492
01493
01494 if (!Valid)
01495 return FALSE;
01496
01497
01498 if (NewBaseDenominator == 0 )
01499 {
01500
01501 InformWarning(_R(IDE_OPTS_BADUNITDENOMINATOR));
01502 return FALSE;
01503 }
01504
01505
01506
01507
01508 double NewBaseNumerator = 0.0;
01509 NewBaseNumerator = GetDoubleGadgetValue(_R(IDC_OPTS_NUMBASEUNITS),
01510 0, MaxValue,
01511 _R(IDE_OPTS_BADUNITNUMERATOR), &Valid);
01512
01513
01514 if (!Valid)
01515 return FALSE;
01516
01517
01518 if (NewBaseNumerator == 0 )
01519 {
01520
01521 InformWarning(_R(IDE_OPTS_BADUNITNUMERATOR));
01522 return FALSE;
01523 }
01524
01525
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
01535
01536
01537 String_32 Str32 = _T("");
01538 if (pCurUserUnit != NULL)
01539 {
01540 BOOL ok = TRUE;
01541
01542
01543 pCurUserUnit->SetPrefixState(Prefix);
01544
01545
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
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
01582 pDocUnitList->UnitHasChanged(CurrentUserUnitType);
01583 }
01584 }
01585
01586
01587
01588 return TRUE;
01589 }
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
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;
01619
01620
01621 switch (Msg->DlgMsg)
01622 {
01623 case DIM_CREATE:
01624 {
01625 InitDialog();
01626 }
01627 break;
01628
01629 case DIM_COMMIT:
01630 {
01631
01632 BOOL ok;
01633 ok = CommitDialogValues();
01634 if (ok)
01635 {
01636
01637 EndDialog = TRUE;
01638 if (pIsOk)
01639 *pIsOk = TRUE;
01640 }
01641 else
01642 Msg->DlgMsg = DIM_NONE;
01643 }
01644 break;
01645
01646 case DIM_CANCEL:
01647
01648 EndDialog = TRUE;
01649 if (pIsOk)
01650 *pIsOk = FALSE;
01651 break;
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662 case DIM_SELECTION_CHANGED:
01663 {
01664
01665
01666
01667 WORD Index = 0;
01668 Unit* pUnit = NULL;
01669 Unit* pCurUserUnit = NULL;
01670
01671 if (Msg->GadgetID == _R(IDC_OPTS_BASEUNIT))
01672 {
01673
01674 GetValueIndex(_R(IDC_OPTS_BASEUNIT),&Index);
01675 pUnit = pDocUnitList->FindUnit(Index);
01676 pCurUserUnit = pDocUnitList->FindUnit(CurrentUserUnitType);
01677 if (pUnit->GetUnitType() == CurrentUserUnitType)
01678 {
01679
01680 Error::SetError(_R(IDS_UNITERROR_BASEISCURRENT),0);
01681 InformError();
01682
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
01690 Error::SetError(_R(IDS_UNITERROR_BASEISDESCENDENT),0);
01691 InformError();
01692
01693 UnitType BaseUnit = pCurUserUnit->GetBaseUnitType();
01694 INT32 BaseUnitIndex = pDocUnitList->FindUnitIndex(BaseUnit);
01695 SetSelectedValueIndex(_R(IDC_OPTS_BASEUNIT), BaseUnitIndex);
01696 }
01697
01698 }
01699 }
01700 break;
01701
01702 case DIM_TEXT_CHANGED:
01703 if (Msg->GadgetID == _R(IDC_OPTS_UNITTOKEN))
01704 {
01705
01706
01707 BOOL Valid;
01708 String_256 TokenStr = GetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN),&Valid);
01709 SetStringGadgetValue(_R(IDC_OPTS_UNITTOKEN2),TokenStr);
01710 }
01711 break;
01712
01713 default:
01714 break;
01715 }
01716
01717
01718 Result = DialogOp::Message(Message);
01719
01720
01721 #if 0
01722
01723 if (EndDialog)
01724 {
01725 Close();
01726 End();
01727 }
01728 #endif
01729
01730
01731 return Result;
01732 }
01733
01734 return DialogOp::Message(Message);
01735 }
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753 OpState UnitPropertiesDlg::GetState(String_256*, OpDescriptor*)
01754 {
01755 OpState OpSt;
01756 return(OpSt);
01757 }
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774 BOOL UnitPropertiesDlg::InitDialog()
01775 {
01776 ERROR3IF(this == NULL, "UnitPropertiesDlg::InitDialog called after duff initialisation?!");
01777
01778
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
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813 BOOL UnitPropertiesDlg::Init()
01814 {
01815 BOOL InitOK;
01816
01817 InitOK = RegisterOpDescriptor(
01818 0,
01819 _R(IDS_UNITPROPERTIESDLG),
01820 CC_RUNTIME_CLASS(UnitPropertiesDlg),
01821 OPTOKEN_UNITPROPERTIESDLG,
01822 GetState,
01823 0,
01824 0,
01825 0,
01826 0,
01827 SYSTEMBAR_ILLEGAL,
01828 TRUE,
01829 FALSE,
01830 TRUE,
01831 0,
01832 _R(IDS_UNITPROPERTIESDLG_ONE),
01833 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC)
01834 );
01835
01836 return (InitOK);
01837 }
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
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
01865
01866
01867
01868 return TRUE;
01869 }
01870 else
01871 {
01872 return FALSE;
01873 }
01874 }
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894 void UnitPropertiesDlg::Do(OpDescriptor*)
01895 {
01896 BOOL ok;
01897
01898
01899 Document * pDocument = Document::GetSelected();
01900 ERROR3IF(pDocument == NULL,"UnitPropertiesDlg::DoWithParam No selected document");
01901
01902
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
01911 CurrentUserUnitType = NOTYPE;
01912
01913
01914 ok = Create();
01915
01916 if ( !ok )
01917 {
01918
01919 InformError();
01920 End();
01921 }
01922 }
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942 void UnitPropertiesDlg::DoWithParam(OpDescriptor*, OpParam* pOpParam)
01943 {
01944 ERROR3IF(pOpParam == NULL, "UnitPropertiesDlg::DoWithParam - NULL Param passed in");
01945
01946
01947 Document * pDocument = Document::GetSelected();
01948 ERROR3IF(pDocument == NULL,"UnitPropertiesDlg::DoWithParam No selected document");
01949
01950
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
01957
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
01967 ok = Create();
01968
01969 if ( !ok )
01970 {
01971
01972 InformError();
01973 End();
01974
01975 *pIsOk = FALSE;
01976 }
01977 }
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
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
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
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
02041 String_256 Str256;
02042
02043
02044
02045 Str = pCurUserUnit->GetSpecifier();
02046 Str256 = Str;
02047 SetStringGadgetValue(_R(IDC_OPTS_UNITSPEC), Str256);
02048
02049
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
02066
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
02073 SetUnitToken(_R(IDC_OPTS_UNITTOKEN), CurrentUserUnitType, -1);
02074 SetUnitToken(_R(IDC_OPTS_UNITTOKEN2), CurrentUserUnitType, 0, TRUE);
02075
02076
02077 UnitType BaseUnit = pCurUserUnit->GetBaseUnitType();
02078 INT32 BaseUnitIndex = pDocUnitList->FindUnitIndex(BaseUnit);
02079 SetSelectedValueIndex(_R(IDC_OPTS_BASEUNIT), BaseUnitIndex);
02080 }
02081 else
02082 {
02083
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