#include <rulers.h>
Inheritance diagram for RulerPair:
Definition at line 241 of file rulers.h.
|
Constructor for RulerPair.
Definition at line 570 of file rulers.cpp. 00571 { 00572 pSpread = NULL; 00573 pDocView = NULL; 00574 00575 MouseFollowerVisibility = FALSE; 00576 }
|
|
|
|
Definition at line 257 of file rulers.h. 00257 { return MouseFollowerPosition; }
|
|
Definition at line 256 of file rulers.h. 00256 { return MouseFollowerVisibility; }
|
|
Definition at line 259 of file rulers.h. 00259 { return pDocView; }
|
|
Definition at line 262 of file rulers.h. 00262 { return &HRuler; }
|
|
Definition at line 261 of file rulers.h. 00261 { return pOriginGadget; }
|
|
Definition at line 264 of file rulers.h. 00264 { return &RedrawData; }
|
|
Definition at line 260 of file rulers.h. 00260 { return pSpread; }
|
|
Definition at line 263 of file rulers.h. 00263 { return &VRuler; }
|
|
if over a component of the rulers, get the associated help text
Definition at line 941 of file rulers.cpp. 00942 { 00943 ERROR2IF(pText==NULL,FALSE,"RulerPair::GetStatusLineText() - pText==NULL"); 00944 00945 // get pointers to each component window of the rulers 00946 OriginGadget* pOriginGadget = GetpOriginGadget(); 00947 OILVerticalRuler* pOilVRuler = (OILVerticalRuler*) GetpVerticalRuler()->GetpOILRuler(); 00948 OILHorizontalRuler* pOilHRuler = (OILHorizontalRuler*)GetpHorizontalRuler()->GetpOILRuler(); 00949 ERROR2IF(pOriginGadget==NULL,FALSE,"RulerPair::GetStatusLineText() - pOriginGadget==NULL"); 00950 ERROR2IF( pOilVRuler==NULL,FALSE,"RulerPair::GetStatusLineText() - pOilVRuler==NULL"); 00951 ERROR2IF( pOilHRuler==NULL,FALSE,"RulerPair::GetStatusLineText() - pOilHRuler==NULL"); 00952 00953 LegendLabel* pLegendLabel = pOilHRuler->GetpLegendLabel(); 00954 ERROR2IF(pLegendLabel==NULL,FALSE,"RulerPair::GetStatusLineText() - pLegendLabel==NULL"); 00955 00956 BOOL valid=FALSE; 00957 if (!valid) valid = pOilVRuler->GetStatusLineText(pText, MousePos, hWnd); 00958 if (!valid) valid = pOilHRuler->GetStatusLineText(pText, MousePos, hWnd); 00959 if (!valid) valid = pLegendLabel->GetStatusLineText(pText, MousePos, hWnd); 00960 if (!valid) valid = pOriginGadget->GetStatusLineText(pText, MousePos, hWnd); 00961 00962 return valid; 00963 }
|
|
Init the RulerPair.
Definition at line 593 of file rulers.cpp. 00595 { 00596 ERROR2IF( pDView==NULL,FALSE,"RulerPair::Init() - pDocView==NULL"); 00597 ERROR2IF(pOILHRuler==NULL,FALSE,"RulerPair::Init() - pOILHRuler==NULL"); 00598 ERROR2IF(pOILVRuler==NULL,FALSE,"RulerPair::Init() - pOILVRuler==NULL"); 00599 ERROR2IF( pOGadget==NULL,FALSE,"RulerPair::Init() - pOGadget==NULL"); 00600 00601 HRuler.Init(this,pOILHRuler); 00602 VRuler.Init(this,pOILVRuler); 00603 pDocView = pDView; 00604 pOriginGadget = pOGadget; 00605 00606 return TRUE; 00607 }
|
|
handle system messages
Reimplemented from MessageHandler. Definition at line 772 of file rulers.cpp. 00773 { 00774 ERROR2IF( pMsg==NULL,FAIL,"RulerPair::Message() - pMsg==NULL"); 00775 if (pDocView==NULL) 00776 { 00777 // no DocView, so don't process the message 00778 return OK; 00779 } 00780 // get a pointer to the doc associated with this doc view 00781 Document* pDoc=pDocView->GetDoc(); 00782 ERROR2IF(pDoc==NULL,FAIL,"RulerPair::Message() - pDoc==NULL"); 00783 BOOL ok=TRUE; 00784 00785 // if default grid changes or page size changes on do or undo/redo in a doc associated 00786 // with this ruler pair, update the rulers 00787 if ( MESSAGE_IS_A(pMsg,OptionsChangingMsg) && ((OptionsChangingMsg*)pMsg)->pScopeDoc==pDoc ) 00788 { 00789 if ( ((OptionsChangingMsg*)pMsg)->State==OptionsChangingMsg::NEWDEFAULTGRID 00790 || ((OptionsChangingMsg*)pMsg)->State==OptionsChangingMsg::NEWPAGESIZE 00791 || ((OptionsChangingMsg*)pMsg)->State==OptionsChangingMsg::PAGESIZEHASCHANGED 00792 || ((OptionsChangingMsg*)pMsg)->State==OptionsChangingMsg::NEWUNITS ) 00793 { 00794 ok=Update(); 00795 } 00796 } 00797 00798 // if a doc has just been created, init it's associated spread and update rulers 00799 if ( MESSAGE_IS_A(pMsg,DocChangingMsg) && ((DocChangingMsg*)pMsg)->pChangingDoc==pDoc 00800 && ((DocChangingMsg*)pMsg)->State==DocChangingMsg::BORNANDSTABLE ) 00801 { 00802 pSpread=pDocView->GetVisibleSpread(); 00803 ok=Update(); 00804 } 00805 00806 // if spread changes and new spread is in the same doc as the one associated with this ruler pair 00807 // and the spread is differentfrom the previous one associated with this ruler pair 00808 // then change the spread associated with this ruler pair and update the rulers 00809 if ( MESSAGE_IS_A(pMsg,SpreadMsg) && ((SpreadMsg*)pMsg)->Reason==SpreadMsg::SELCHANGED 00810 && ((SpreadMsg*)pMsg)->pNewSpread!=NULL && ((SpreadMsg*)pMsg)->pNewSpread->FindOwnerDoc()==pDoc 00811 && pSpread!=((SpreadMsg*)pMsg)->pNewSpread ) 00812 { 00813 pSpread=((SpreadMsg*)pMsg)->pNewSpread; 00814 ok=Update(); 00815 } 00816 00817 // if a docview message is sent relating to the doc view associated with this ruler pair 00818 if ( MESSAGE_IS_A(pMsg,DocViewMsg) && ((DocViewMsg*)pMsg)->pDocView==pDocView ) 00819 { 00820 // this is now handled by a direct call from the zoom ops (Ed/Chris 29/9/95) 00821 // // if it is a scale changed, just updtae rulers 00822 // if ( ((DocViewMsg*)pMsg)->State==DocViewMsg::SCALECHANGED ) 00823 // ok=Update(); 00824 00825 // if it is a newly created doc view then initialise the associated spread 00826 if ( ((DocViewMsg*)pMsg)->State==DocViewMsg::NEWANDSTABLE ) 00827 { 00828 pSpread=pDocView->GetVisibleSpread(); 00829 ok=Update(); 00830 } 00831 } 00832 00833 // if a docview message is sent relating to the doc view associated with this ruler pair 00834 if ( MESSAGE_IS_A(pMsg,DocViewMsg) && ((DocViewMsg*)pMsg)->State==DocViewMsg::SELCHANGED 00835 && ((DocViewMsg*)pMsg)->pOldDocView==pDocView ) 00836 { 00837 UpdateMouseFollowers(NULL); // remove mouse followers 00838 } 00839 00840 return ok ? OK : FAIL; 00841 }
|
|
update a ruler pair (recache redraw data and force redraw)
Definition at line 853 of file rulers.cpp. 00854 { 00855 if (pSpread!=NULL) 00856 UpdateRedrawData(); 00857 00858 OILHorizontalRuler* pHOilRuler=(OILHorizontalRuler*)HRuler.GetpOILRuler(); 00859 ERROR2IF(pHOilRuler==NULL,FALSE,"RulerPair::Update() - pHOilRuler==NULL"); 00860 pHOilRuler->SetLegendText(&RedrawData.LegendStr); 00861 pHOilRuler->UpdateRuler(); 00862 00863 OILVerticalRuler* pVOilRuler=(OILVerticalRuler*)VRuler.GetpOILRuler(); 00864 ERROR2IF(pVOilRuler==NULL,FALSE,"RulerPair::Update() - pVOilRuler==NULL"); 00865 pVOilRuler->UpdateRuler(); 00866 00867 return TRUE; 00868 }
|
|
Update the mouse followers on the rulers.
Definition at line 882 of file rulers.cpp. 00883 { 00884 ERROR2IF(pDocView==NULL,FALSE,"RulerPair::UpdateMouseFollowers() - pDocView==NULL"); 00885 ERROR2IF( pSpread==NULL,FALSE,"RulerPair::UpdateMouseFollowers() - pSpread==NULL"); 00886 00887 // determine old and new follower visibility and position 00888 BOOL NewVisibility = (pDocCoord!=NULL); 00889 DocCoord NewPos = pDocCoord!=NULL ? *pDocCoord : DocCoord(0,0); 00890 DocCoord OldPos = GetMouseFollowerPosition(); 00891 BOOL OldVisibility = GetMouseFollowerVisibility(); 00892 00893 // if there is no effective change, just return 00894 if (NewVisibility==FALSE && OldVisibility==FALSE) 00895 return TRUE; 00896 if (NewVisibility==TRUE && OldVisibility==TRUE && NewPos==OldPos) 00897 return TRUE; 00898 00899 // get pointers to the oil rulers 00900 OILHorizontalRuler* pHOILRuler = (OILHorizontalRuler*)HRuler.GetpOILRuler(); 00901 OILVerticalRuler* pVOILRuler = (OILVerticalRuler*)VRuler.GetpOILRuler(); 00902 ERROR2IF(pHOILRuler==NULL,FALSE,"RulerPair::UpdateMouseFollowers() - pOILHRuler==NULL"); 00903 ERROR2IF(pVOILRuler==NULL,FALSE,"RulerPair::UpdateMouseFollowers() - pOILVRuler==NULL"); 00904 00905 // remove old followers if there were any 00906 if (OldVisibility==TRUE) 00907 { 00908 OilCoord OldOilPos = OldPos.ToOil(pSpread,pDocView); 00909 pHOILRuler->PaintMouseFollower(OldOilPos, pDocView, RenderOff); 00910 pVOILRuler->PaintMouseFollower(OldOilPos, pDocView, RenderOff); 00911 } 00912 00913 // draw on new followers if there were any 00914 if (NewVisibility==TRUE) 00915 { 00916 OilCoord NewOilPos = NewPos.ToOil(pSpread,pDocView); 00917 pHOILRuler->PaintMouseFollower(NewOilPos, pDocView, RenderOn); 00918 pVOILRuler->PaintMouseFollower(NewOilPos, pDocView, RenderOn); 00919 } 00920 00921 // update the current position of the mouse followers 00922 MouseFollowerVisibility = NewVisibility; 00923 MouseFollowerPosition = NewPos; 00924 00925 return TRUE; 00926 }
|
|
Definition at line 622 of file rulers.cpp. 00623 { 00624 ERROR2IF( pSpread==NULL,FALSE,"RulerPair::UpdateRedrawData() - pSpread==NULL"); 00625 ERROR2IF(pDocView==NULL,FALSE,"RulerPair::UpdateRedrawData() - pDocView==NULL"); 00626 00627 // get a pointer to the default grid associated with this spread 00628 NodeGrid* pDefaultGrid=pSpread->FindFirstDefaultGridInSpread(); 00629 ERROR2IF(pDefaultGrid==NULL,FALSE,"RulerPair::UpdateRedrawData() - pDefaultGrid==NULL"); 00630 00631 // get pointer to the document's unit list 00632 DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList(); 00633 ERROR2IF(pDocUnitList==NULL,FALSE,"RulerPair::UpdateRedrawData() - pDocUnitList==NULL"); 00634 00635 // determine the minimum distance between minor graticules (in Doc/Spread/UserCoords) 00636 OilRect MinGratSpacingOilRect; 00637 BOOL ok = OILRuler::GetMinGraticuleSpacing(&MinGratSpacingOilRect,pDocView); 00638 ERROR2IF(!ok,FALSE,"RulerPair::UpdateRedrawData() - OILRuler::GetMinGraticuleSpacing() failed"); 00639 DocRect MinGratSpacingDocRect = MinGratSpacingOilRect.ToDoc(pSpread,pDocView); 00640 MILLIPOINT MinGratSpacing = max(MinGratSpacingDocRect.Width(),MinGratSpacingDocRect.Height()); 00641 00642 // determine the minimum distance between major graticules (in Doc/Spread/UserCoords) 00643 OilRect LabelSizeOilRect; 00644 ok = OILRuler::GetTextSize(&LabelSizeOilRect,LABEL_SPACING_STRING,pDocView); 00645 ERROR2IF(!ok,FALSE,"RulerPair::UpdateRedrawData() - OILRuler::GetTextSize() failed"); 00646 DocRect LabelSizeDocRect = LabelSizeOilRect.ToDoc(pSpread,pDocView); 00647 MILLIPOINT MinLabelSpacing = max(LabelSizeDocRect.Width(),LabelSizeDocRect.Height()); 00648 00649 // read the grid settings 00650 UnitType GridUnits = pDefaultGrid->GetUnits(); 00651 INT32 GridSubDivisions = pDefaultGrid->GetSubdivisions(); 00652 double GridStepSize = pDefaultGrid->GetMainStep(); 00653 double GridStepSizeInUnits = pDefaultGrid->GetDivisions(); 00654 double GridUnitSize = GridStepSize/GridStepSizeInUnits; 00655 00656 // detemine the major graticule label steps and ruler unit size 00657 // if step not an integer number of units, label in unit multiples of this step (eg 1,2,3; cms x2.54) 00658 // if step is an integer number of units, label in the base unit and step by the integer (eg 4,8,12; Inches) 00659 double GratStepSize = GridStepSize; 00660 INT32 GratStep = 1; 00661 double GratUnitSize = GratStepSize; 00662 if (NEAR_ENOUGH_INTEGER(GridStepSizeInUnits)) 00663 { 00664 GratStep = MAKE_INTEGER(GridStepSizeInUnits); 00665 GratUnitSize = GridUnitSize; 00666 } 00667 00668 // Get pasteboard rect in user coords 00669 DocRect PasteSpreadRect = pSpread->GetPasteboardRect(FALSE, pDocView); 00670 pSpread->DocCoordToSpreadCoord(&PasteSpreadRect); 00671 UserRect PasteBoardUserRect = PasteSpreadRect.ToUser(pSpread); 00672 00673 // Give the current tool the chance to modify the UserCoord displayed by the ruler 00674 UserCoord Offsets(0, 0); 00675 Tool::GetCurrent()->GetRulerOrigin(pSpread, &Offsets); 00676 PasteBoardUserRect.Translate(-Offsets.x, -Offsets.y); 00677 00678 // hence the start and end values in terms of ruler units 00679 double XStart = fabs(PasteBoardUserRect.lo.x/GratStepSize)*GratStep; 00680 double XEnd = fabs(PasteBoardUserRect.hi.x/GratStepSize)*GratStep; 00681 double YStart = fabs(PasteBoardUserRect.lo.y/GratStepSize)*GratStep; 00682 double YEnd = fabs(PasteBoardUserRect.hi.y/GratStepSize)*GratStep; 00683 00684 // hence a scale factor to keep the labels in the range 1..999 00685 double LogMax = log10(max(max(XStart,XEnd),max(YStart,YEnd))); 00686 INT32 MaxDP = (INT32)floor(LogMax); 00687 double ScaleFactor = (MaxDP<=2) ? 1 : 1/pow(10.0,MaxDP-2); 00688 00689 // determine how often major graticules can be drawn (ie 1 in N, where N is 1eX, 2eX, 5eX) 00690 // (note: all done accurately with integers and multiplies) 00691 // tricky problem here - if GratFreq is 5, GratStep is 31 and ScaleFactor 0.1 00692 // then grat labels could be 400,415.5,431 => 400, 416, 431 ie inaccurate, 00693 // to prevent this, GratFreq*ScaleFactor*GratStep must be an integer 00694 INT32 GratFreq = (INT32)ceil(MinLabelSpacing/GratStepSize); 00695 INT32 Mult = 1; 00696 INT32 SafetyCount = 0; // by special request from Alex 16/10/95 00697 while (1) 00698 { 00699 if (GratFreq<=1*Mult && NEAR_ENOUGH_INTEGER(1*Mult*GratStep*ScaleFactor)) { GratFreq=1*Mult; break; } 00700 if (GratFreq<=2*Mult && NEAR_ENOUGH_INTEGER(2*Mult*GratStep*ScaleFactor)) { GratFreq=2*Mult; break; } 00701 if (GratFreq<=5*Mult && NEAR_ENOUGH_INTEGER(5*Mult*GratStep*ScaleFactor)) { GratFreq=5*Mult; break; } 00702 Mult *= 10; 00703 ERROR2IF(SafetyCount++>1000,FALSE,"RulerPair::UpdateRedrawData() - SafetyCount exceeded!"); 00704 } 00705 00706 // and hence determine distance and label increments between visible major graticules 00707 double VisibleGratStepSize = GratStepSize*GratFreq; 00708 INT32 VisibleGratStep = GratStep *GratFreq; 00709 00710 // determine the legend unit multiplier 00711 String_32 LegendUnitMultiplier(_T("")); 00712 if (GratStep*ScaleFactor!=GridStepSizeInUnits) 00713 { 00714 TCHAR mult[4]={' ',(TCHAR)0xD7,' ','\0'}; // ie a space followed by the multiply symbol 00715 LegendUnitMultiplier = mult; 00716 String_32 LegendUnitSize(_T("")); 00717 double GratUnit=GridStepSizeInUnits/GratStep; // ie 1in=>1in, 10in=>1in, 2.54in=>2.54in 00718 ok=Convert::DoubleToString(GratUnit/ScaleFactor,&LegendUnitSize); 00719 SafeAppendString(&LegendUnitMultiplier,LegendUnitSize,FALSE); 00720 } 00721 00722 // determine the ruler legend units 00723 String_32 LegendStr = pDocUnitList->GetToken(GridUnits); 00724 if (LegendStr.Length()+LegendUnitMultiplier.Length() > MAX_LEGEND_CHARS) 00725 LegendStr = pDocUnitList->GetSpecifier(GridUnits); 00726 SafeAppendString(&LegendStr,LegendUnitMultiplier,FALSE); 00727 00728 // calc minor graticule step size, and number of minor graticules 00729 INT32 MinorGrats = GridSubDivisions; 00730 if (GratFreq>1) 00731 MinorGrats = GratFreq; 00732 double MinorGratStepSize = VisibleGratStepSize/MinorGrats; 00733 00734 // hence calc visible minor graticules (ie ensure minimum spacing) 00735 INT32 MinorGratFreq = 1; 00736 if (MinorGratStepSize<MinGratSpacing) 00737 { 00738 // calc MinorGratFreq such that minor grats are not too close and which is a factor of MinorGrats 00739 MinorGratFreq = (INT32)ceil(MinGratSpacing/MinorGratStepSize); 00740 while (MinorGratFreq<MinorGrats && fmod((double)MinorGrats,(double)MinorGratFreq)!=0) 00741 MinorGratFreq+=1; 00742 if (MinorGratFreq>MinorGrats) 00743 MinorGratFreq=MinorGrats; 00744 } 00745 INT32 VisibleMinorGrats = MinorGrats/MinorGratFreq; 00746 double VisibleMinorGratStepSize = VisibleGratStepSize/VisibleMinorGrats; 00747 00748 // cache the necessary values 00749 RedrawData.GratUnitSize = GratUnitSize; 00750 RedrawData.MinorGrats = VisibleMinorGrats; 00751 RedrawData.MinorGratStepSize = VisibleMinorGratStepSize; 00752 RedrawData.GratStep = VisibleGratStep; 00753 RedrawData.GratStepSize = VisibleGratStepSize; 00754 RedrawData.PasteBoardUserRect = PasteBoardUserRect; 00755 RedrawData.ScaleFactor = ScaleFactor; 00756 RedrawData.LegendStr = LegendStr; 00757 00758 return TRUE; 00759 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|