INT32 UnitListComponent::ExportUnitDefinition(BaseCamelotFilter *pFilter, Unit* pUnit) { #ifdef DO_EXPORT ERROR2IF(pFilter == NULL,0L,"UnitListComponent::ExportUnitDefinition null pFilter"); ERROR2IF(pUnit == NULL,0L,"UnitListComponent::ExportUnitDefinition null pUnit"); ERROR2IF(pDocUnitList == NULL,0L,"UnitListComponent::ExportUnitDefinition called with no doc unit list pointer"); ERROR2IF(pUnit->IsDefault(),0L,"UnitListComponent::ExportUnitDefinition trying to save default unit definition"); INT32 RecordNumber = 0L; // See if we have saved the unit definition out by checking our table // If so then do nothing CMapPtrToLong::iterator it = pExpUserUnitMap->find(pUnit); if (it!=pExpUserUnitMap->end()) return it->second; // Export the definition for this unit // First get all the details // UnitType type = pUnit->GetUnitType(); // Set up the prefix/suffix state for this user's unit. BOOL Prefix = pUnit->IsPrefix(); INT32 Tag = 0L; INT32 Size = 0L; if (Prefix) { Tag = TAG_DEFINE_PREFIXUSERUNIT; Size = TAG_DEFINE_PREFIXUSERUNIT_SIZE; } else { Tag = TAG_DEFINE_SUFFIXUSERUNIT; Size = TAG_DEFINE_SUFFIXUSERUNIT_SIZE; } // The main full name of the unit String_32 Name = pUnit->GetToken(); // And the abbreviation String_32 Abbrev = pUnit->GetSpecifier(); // If there are string names, then add it to this size // REMEMBER: We save out unicode strings and so we need to double the length of the returned string length Size += (Name.Length() + 1) * SIZEOF_XAR_UTF16; Size += (Abbrev.Length() + 1) * SIZEOF_XAR_UTF16; BOOL ok = TRUE; CXaraFileRecord Rec(Tag, Size); ok = Rec.Init(); // Write out the name and abbreviation for this unit if (ok) ok = Rec.WriteUnicode(Name); if (ok) ok = Rec.WriteUnicode(Abbrev); // The size of this unit, 0 if based on double UnitSize = pUnit->GetMillipoints(); if (ok) ok = Rec.WriteDOUBLE(UnitSize); // What unit this is based on UnitType BaseUnit = pUnit->GetBaseUnitType(); //INT32 ExportBaseUnit = GetExportUnitType(BaseUnit); INT32 ExportBaseUnit = GetWriteUnitReference(BaseUnit, pFilter); ERROR2IF(ExportBaseUnit == 0,FALSE,"bad base units reference!"); if (ok) ok = Rec.WriteINT32(ExportBaseUnit); // Write out the multipliers for this unit double BaseNumerator = 0.0; double BaseDenominator = 0.0; BaseNumerator = pUnit->GetBaseNumerator(); BaseDenominator = pUnit->GetBaseDenominator(); if (ok) ok = Rec.WriteDOUBLE(BaseNumerator); if (ok) ok = Rec.WriteDOUBLE(BaseDenominator); // Finally, write the record out to file // In the process get the record number that this was written out as if (ok) RecordNumber = pFilter->Write(&Rec); // Get the document comment // Add the unit to the user units map so we can remember the references of the // exported units and hence whether we have exported this before // Reference for this unit is the record number TRACEUSER( "Neville", _T("Exported user unit reference %d\n"), RecordNumber); try { (*pExpUserUnitMap)[pUnit] = RecordNumber; } catch (std::bad_alloc&) { ERROR1(FALSE, _R(IDS_OUT_OF_MEMORY)); } catch (...) { ERROR1(FALSE, _R(IDS_UNKNOWN_ERROR)); } return RecordNumber; #else return 0L; #endif }
MsgResult ToolnameDlg::Message(Msg* Message) { if (IS_OUR_DIALOG_MSG(Message)) { DialogMsg* Msg = (DialogMsg*)Message; BOOL EndDialog = FALSE; switch (Msg->DlgMsg) { case DIM_CREATE: SetKeyboardFocus (_R(IDC_EDITNEWBARNAME)) ; HighlightText (_R(IDC_EDITNEWBARNAME)) ; break ; case DIM_COMMIT: { // Accept all changes that the user wants to make to toolbars... BOOL VV; String_32 NewBarName = GetStringGadgetValue(_R(IDC_EDITNEWBARNAME),&VV); if(NewBarName.Length()==0) { UINT32 Number = DialogBarOp::FindUniqueBarNumber(); NewBarName._MakeMsg(TEXT("Bar #1%ld"),Number); } DialogBarOp* pNewBar = new DialogBarOp(NewBarName); if (pNewBar) { pNewBar->SetDockBarType(DOCKBAR_FLOAT); pNewBar->Create(); // The Create function sends a message which we intercept to update // the list of bars in the Toolbars... dialog. // this is very dangerous in fact it blows up.. // so I have removed it .. chris. /* if (pNewBar) { // Find toolbar dialog and close it... ToolbarDlg* pToolbarDlg = ToolbarDlg::GetToolbarDlg(); if (pToolbarDlg) { pToolbarDlg->Close(); pToolbarDlg->End(); } } */ ToolbarDlg* pToolbarDlg = ToolbarDlg::GetToolbarDlg(); pToolbarDlg->ShowToolbarList(); } EndDialog = TRUE; } break; case DIM_CANCEL: // Cancel all changes the user wants to make to toolbars... EndDialog = TRUE; break; // default: } if (EndDialog) // Dialog communication over { Close(); // Close the dialog End(); // Destroy dialog } // return (DLG_EAT_IF_HUNGRY(Msg)); } // return OK; // Pass everything on to the base-class . . . return DialogOp::Message(Message); }