Esempio n. 1
0
BOOL ScaleTab::InitSection()
{
TRACEUSER( "Neville", _T("ScaleTab::InitSection\n"));
	ERROR2IF(pPrefsDlg == NULL,FALSE,"ScaleTab::InitSection called with no dialog pointer");

//	BOOL ReadOk = FALSE; 	// Flag to say whether the preference value was read ok 

	// Make sure the information field displaying the name of the current document
	// is correct.
	String_256	DocumentName(_R(IDT_OPTS_SCALING_INFO)); 
	DocumentName +=	*GetDocumentName();
	pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);

	// Section = Scale settings

	DocView* pSelectedView = DocView::GetSelected();
	// This may now be a valid state so must not error
	//ERROR3IF(pSelectedView == NULL,"ScaleTab::InitSection Where's the current view eh?");
	if (pSelectedView != NULL)
	{
		Spread* pSpread = pSelectedView->GetFirstSelectedSpread();

		// If no selected spread then use the visible spread
		if (pSpread == NULL)
			pSpread = pSelectedView->GetVisibleSpread();

		// If no selected spread then use the first spread
		// Of course, this should not be here but above routines seem to return
		// null a bit too often for my liking
		if (pSpread == NULL)
		{
TRACEUSER( "Neville", _T("ScaleTab::InitSection BODGE! using 1st spread\n"));
			Document* pSelectedDoc = Document::GetSelected();
			if (pSelectedDoc !=NULL )
				pSpread = pSelectedDoc->FindFirstSpread();
		}

		// Go and get a pointer to the scaling values
		if (pSpread != NULL)
		{
			pDimScale = pSpread->GetPtrDimScale();
			if (pDimScale != NULL)
			{
				// And now show the initial state of the controls given this
				// scaling 
				ShowScaleDetails();
			}
		}
	}
	else
	{
		// If no current view then ensure section is greyed
		GreySection();
	}

	return TRUE;
}
Esempio n. 2
0
BOOL ScaleTab::CommitSection()
{
TRACEUSER( "Neville", _T("commit Scale section\n"));
	ERROR3IF(pPrefsDlg == NULL, "ScaleTab::CommitSection called with no dialog pointer");

	BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_SCALE));	// The Scale tab identifier
	if (!ok)
		return TRUE;	// Talk to View failed to return now

	// Ok has been pressed so take the values from this section of the dialog box
	// Takes the values in the dialog and sets the DimScale object accordingly.
	BOOL Valid=TRUE;		// Flag for validity of value
//	BOOL State=FALSE;		// Flag for state of button/switch
	BOOL SetOk=TRUE;		// Preference value set ok

	// Section = Scale settings

	// Now check that we have the selected view still, just in case it has switched
	// without us being told about it or even we have no current document/view.
	// This may be a valid state now, so do not complain about it. 
	DocView* pCurrentView = DocView::GetSelected();
	if (pCurrentView != NULL)
	{
		// Only if there is a current view do we read the values.
		String_256 DrawingStr;
		String_256 RealStr;
		//TCHAR* pDrawingStr = DrawingStr;
		//TCHAR* pRealStr = RealStr;
		BOOL Active;

		// Get the values from the dialog box
		Active 		= pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_USESCALEFACTOR),0,1,0, &Valid);
		DrawingStr  = pPrefsDlg->GetStringGadgetValue(_R(IDC_OPTS_DRAWINGSCALE), &Valid);
		RealStr 	= pPrefsDlg->GetStringGadgetValue(_R(IDC_OPTS_REALSCALE), &Valid);

		Spread* pSpread = pCurrentView->GetFirstSelectedSpread();
		// If no selected spread then use the visible spread
		if (pSpread == NULL)
			pSpread = pCurrentView->GetVisibleSpread();

		// Only do the chnage if we have a valid spread pointer and we have changed something.
		if ( (pSpread != NULL) &&
			 (
			 	(OldActiveState != Active) ||
			 	(OldDrawingStr != DrawingStr) ||
			 	(OldRealStr != RealStr)
			 )
		   )
		{
			pDimScale = pSpread->GetPtrDimScale();
			if (pDimScale != NULL)
			{
				// Only if active is set do we need to try and set new strings
				// and hence a new drawing scale
				if (Active)
				{
					// Dim Scales can only be 32 characters long
					String_32 DrawingStr32 = _T("");
					String_32 RealStr32 = _T("");
					// Check if read in strings are longer than this
					if (DrawingStr.Length() > DrawingStr32.MaxLength())
					{
						InformError(_R(IDE_OPTS_INVALIDDRAWSCALE));
						return FALSE;
					}
					if (RealStr.Length() > RealStr32.MaxLength())
					{
						InformError(_R(IDE_OPTS_INVALIDREALSCALE));
						return FALSE;
					}

					RealStr32 = RealStr;
					DrawingStr32 = DrawingStr;

					// Try and set these strings as new drawing and real scales strings
					SetOk = pDimScale->SetDrawingScaleStr(DrawingStr32);
					if (!SetOk)
					{
						InformError(_R(IDE_OPTS_INVALIDDRAWSCALE));
						return FALSE;
					}

					SetOk = SetOk && pDimScale->SetRealScaleStr(RealStr32);
					if (!SetOk)
					{
						InformError(_R(IDE_OPTS_INVALIDREALSCALE));
						return FALSE;
					}
				
					// Now try to convert these into a new scaling factor
					if (SetOk)
						SetOk = SetOk && pDimScale->SetScaleFactor();
				
					// If we failed in any of the conversions then warn the user and fail
					if (!SetOk)
					{
						InformError(_R(IDE_OPTS_INVALIDSCALING));
						return FALSE;
					}
				}
				
				// Set up a possibly new active state
				pDimScale->SetActiveState(Active);

			}

			// Now tell other users of units/scaling factors that there they are likely
			// to need to update any currently displayed units. 
			Document *pCurrentDoc = (Document *)pSpread->FindOwnerDoc();
			BROADCAST_TO_ALL(OptionsChangingMsg(pCurrentDoc, OptionsChangingMsg::NEWUNITS));
// unfortunately pScopeDoc is NULL!, and since pCurrentDoc is calulated I thought it ought to use! - Ed 17/10/95
//			BROADCAST_TO_ALL(OptionsChangingMsg(pScopeDocument, OptionsChangingMsg::OptionsState::NEWUNITS));

			// Make sure the document is marked as modified.
			pCurrentDoc->SetModified(TRUE);
			
			// And note the new states
			OldActiveState = Active;
			OldDrawingStr = DrawingStr;
			OldRealStr = RealStr;
		}
	}
//	else
//		ERROR2(FALSE,_R(IDE_OPTS_READPREF_SCALE));
	
	return TRUE;
}