diff -r 12e5a38bf0a8 -r ca403f4c5b86 TextRuler.st --- a/TextRuler.st Thu Nov 17 15:42:58 1994 +0100 +++ b/TextRuler.st Mon Nov 21 17:49:32 1994 +0100 @@ -1,130 +1,368 @@ -" - COPYRIGHT (c) 1991 by Claus Gittinger - All Rights Reserved - - This software is furnished under a license and may be used - only in accordance with the terms of that license and with the - inclusion of the above copyright notice. This software may not - be provided or otherwise made available to, or used by, any - other person. No title to or ownership of the software is - hereby transferred. -" +'From Smalltalk/X, Version:2.10.4 on 18-nov-1994 at 16:11:48'! Ruler subclass:#TextRuler - instanceVariableNames:'leftMargin rightMargin tabSpec moving' - classVariableNames:'LeftAlignForm RightAlignForm - AlignForm CenterForm LeftMarginForm - RightMarginForm LeftTabForm RightTabForm - CenterTabForm DecimalTabForm' - poolDictionaries:'' - category:'Views-Interactors' + instanceVariableNames:'leftMargin rightMargin spec moving settingTab' + classVariableNames:'LeftAlignForm RightAlignForm AlignForm CenterForm LeftMarginForm + RightMarginForm LeftTabForm RightTabForm CenterTabForm + DecimalTabForm' + poolDictionaries:'' + category:'Views-Interactors' ! TextRuler comment:' COPYRIGHT (c) 1991 by Claus Gittinger - All Rights Reserved + All Rights Reserved a Ruler for page layout showing tabs., margins etc. -$Header: /cvs/stx/stx/libwidg2/TextRuler.st,v 1.7 1994-08-23 23:44:32 claus Exp $ +$Header: /cvs/stx/stx/libwidg2/TextRuler.st,v 1.8 1994-11-21 16:48:42 claus Exp $ written oct 91 by claus '! +!TextRuler class methodsFor:'documentation'! + +documentation +" + This is a special ruler built for text processing + applications. Currently, it is not used in the system. + It allows setting of margins, tabs and text-layout. + + TextRuler new open +" + +! ! + !TextRuler class methodsFor:'defaults'! -alignForm - "return the form displayed in the align-button" +rightMarginForm + "return the form displayed for the right margin marker" + + RightMarginForm isNil ifTrue:[ + RightMarginForm := Form fromFile:'rightMarg.xbm' resolution:100 + ]. + ^ RightMarginForm +! + +leftMarginForm + "return the form displayed for the left margin marker" - AlignForm isNil ifTrue:[ - AlignForm := Form fromFile:'align.xbm' resolution:100 + LeftMarginForm isNil ifTrue:[ + LeftMarginForm := Form fromFile:'leftMargin.xbm' resolution:100 ]. - ^ AlignForm + ^ LeftMarginForm +! + +rightAlignForm + "return the form displayed in the rightAlign-button" + + RightAlignForm isNil ifTrue:[ + RightAlignForm := Form fromFile:'rightAlign.xbm' resolution:100 + ]. + ^ RightAlignForm +! + +leftTabForm + "return the form displayed in the leftTab-button" + + LeftTabForm isNil ifTrue:[ + LeftTabForm := Form fromFile:'leftTab.xbm' resolution:100 + ]. + ^ LeftTabForm ! centerForm "return the form displayed in the center-button" CenterForm isNil ifTrue:[ - CenterForm := Form fromFile:'center.xbm' resolution:100 + CenterForm := Form fromFile:'center.xbm' resolution:100 ]. ^ CenterForm ! +alignForm + "return the form displayed in the align-button" + + AlignForm isNil ifTrue:[ + AlignForm := Form fromFile:'align.xbm' resolution:100 + ]. + ^ AlignForm +! + +rightTabForm + "return the form displayed in the rightTab-button" + + RightTabForm isNil ifTrue:[ + RightTabForm := Form fromFile:'rightTab.xbm' resolution:100 + ]. + ^ RightTabForm +! + leftAlignForm "return the form displayed in the leftAlign-button" LeftAlignForm isNil ifTrue:[ - LeftAlignForm := Form fromFile:'leftAlign.xbm' resolution:100 + LeftAlignForm := Form fromFile:'leftAlign.xbm' resolution:100 ]. ^ LeftAlignForm ! -rightAlignForm - "return the form displayed in the rightAlign-button" - - RightAlignForm isNil ifTrue:[ - RightAlignForm := Form fromFile:'rightAlign.xbm' resolution:100 - ]. - ^ RightAlignForm -! - -rightTabForm - "return the form displayed in the rightTab-button" +decimalTabForm + "return the form displayed in the decimalTab-button" - RightTabForm isNil ifTrue:[ - RightTabForm := Form fromFile:'rightTab.xbm' resolution:100 + DecimalTabForm isNil ifTrue:[ + DecimalTabForm := Form fromFile:'decimalTab.xbm' resolution:100 ]. - ^ RightTabForm -! - -leftTabForm - "return the form displayed in the leftTab-button" - - LeftTabForm isNil ifTrue:[ - LeftTabForm := Form fromFile:'leftTab.xbm' resolution:100 - ]. - ^ LeftTabForm + ^ DecimalTabForm ! centerTabForm "return the form displayed in the centerTab-button" CenterTabForm isNil ifTrue:[ - CenterTabForm := Form fromFile:'centerTab.xbm' resolution:100 + CenterTabForm := Form fromFile:'centerTab.xbm' resolution:100 ]. ^ CenterTabForm +! ! + +!TextRuler methodsFor:'accessing'! + +paragraphSpecification:aSpec + spec := aSpec +! ! + +!TextRuler methodsFor:'redrawing'! + +redraw + "redraw margin & tab marks" + + |x top form tab type tabStops tabAlign viewOrigin orgX orgY| + + super redraw. + + viewOrigin := self viewOrigin. + orgX := viewOrigin x. + orgY := viewOrigin y. + + self paint:fgColor. + + top := height - (font height) - (font ascent). + + x := (self inchToPixel:leftMargin) rounded. + form := self class leftMarginForm. + self displayForm:form + x:(x - (form width // 2) - orgX) + y:(top - form height - orgY). + + x := (self inchToPixel:rightMargin) rounded. + form := self class rightMarginForm. + self displayForm:form + x:(x - (form width // 2) - orgX) + y:(top - form height - orgY). + + spec notNil ifTrue:[ + tabStops := spec positions. + tabAlign := spec align. + tabStops notNil ifTrue:[ + 1 to:tabStops size do:[:tabNr | + tab := tabStops at:tabNr. + type := tabAlign at:tabNr. + x := (spec positionOfTab:tabNr on:self) rounded. + (type == #left) ifTrue:[ + form := self class leftTabForm + ] ifFalse:[ + (type == #right) ifTrue:[ + form := self class rightTabForm + ] ifFalse:[ + (type == #center) ifTrue:[ + form := self class centerTabForm + ] ifFalse:[ + (type == #decimal) ifTrue:[ + form := self class decimalTabForm + ] + ] + ] + ]. + self displayForm:form + x:(x - (form width // 2) - orgX) + y:(top - form height - orgY) + ] + ] + ] ! +clearMargin:which + "clear margin" -decimalTabForm - "return the form displayed in the decimalTab-button" + |this other otherX otherX2 x x2 top form symOther viewOrigin| + + self paint:viewBackground. + + top := height - (font height) - (font ascent). - DecimalTabForm isNil ifTrue:[ - DecimalTabForm := Form fromFile:'decimalTab.xbm' resolution:100 + (which == #left) ifTrue:[ + this := leftMargin. + other := rightMargin. symOther := #right. + form := self class leftMarginForm + ]. + (which == #right) ifTrue:[ + this := rightMargin. + other := leftMargin. symOther := #left. + form := self class rightMarginForm ]. - ^ DecimalTabForm + + x := (self inchToPixel:this) rounded - (form width // 2). + viewOrigin := self viewOrigin. + self displayForm:form + x:x + viewOrigin x + y:(top - form height - viewOrigin y). + + " + if it covers any other, redraw them + " + x2 := x + form width. + otherX := (self inchToPixel:other) rounded - (form width // 2). + otherX2 := otherX + form width. + + otherX > x2 ifFalse:[ + otherX2 < x ifFalse:[ + self drawMargin:symOther + ] + ]. ! -leftMarginForm - "return the form displayed for the left margin marker" +drawMargin:which + "clear margin" + + |x top form viewOrigin| + + self paint:fgColor. + + top := height - (font height) - (font ascent). - LeftMarginForm isNil ifTrue:[ - LeftMarginForm := Form fromFile:'leftMargin.xbm' resolution:100 + (which == #left) ifTrue:[ + x := (self inchToPixel:leftMargin) rounded. + form := self class leftMarginForm + ]. + (which == #right) ifTrue:[ + x := (self inchToPixel:rightMargin) rounded. + form := self class rightMarginForm ]. - ^ LeftMarginForm + + viewOrigin := self viewOrigin. + self displayForm:form + x:(x - (form width // 2) - viewOrigin x) + y:(top - form height - viewOrigin y). + +! ! + +!TextRuler methodsFor:'user interaction'! + +buttonRelease:button x:x y:y + "position a tab or start moving a ruler" + + moving := nil ! -rightMarginForm - "return the form displayed for the right margin marker" +buttonPress:button x:pX y:y + "position a tab or start moving a ruler" + + |mpos x| + + ((button == #select) or:[button == 1]) ifFalse:[ + ^ super buttonPress:button x:pX y:y + ]. + + x := pX + self viewOrigin x. + settingTab notNil ifTrue:[ + self setTabX:x. + settingTab := nil. + ^ self + ]. + + mpos := self inchToPixel:leftMargin. + (((mpos - 4) <= x) and:[x <= (mpos + 4)]) ifTrue:[ + "start moving left margin" + moving := #left. + ^ self + ]. + mpos := self inchToPixel:rightMargin. + (((mpos - 4) <= x) and:[x <= (mpos + 4)]) ifTrue:[ + "start moving right margin" + moving := #right. + ^ self + ]. + + ^ self +! + +buttonMotion:state x:x y:y + "position a tab or start moving a ruler" + + |mpos| - RightMarginForm isNil ifTrue:[ - RightMarginForm := Form fromFile:'rightMarg.xbm' resolution:100 - ]. - ^ RightMarginForm + moving notNil ifTrue:[ + self clearMargin:moving. + mpos := self pixelToInch:x + self viewOrigin x. + (mpos < 0) ifTrue:[ + mpos := 0 + ]. + (mpos > paperWidth) ifTrue:[ + mpos := paperWidth + ]. + (moving == #left) ifTrue:[ + leftMargin := mpos + ]. + (moving == #right) ifTrue:[ + rightMargin := mpos + ]. + self drawMargin:moving + ] +! + +leftAlign + ^ self +! + +rightAlign + ^ self +! + +leftTab + settingTab := #left. + +! + +align + ^ self +! + +center + ^ self +! + +centerTab + settingTab := #center. +! + +rightTab + settingTab := #right. + +! + +decimalTab + settingTab := #decimal. + ! ! !TextRuler methodsFor:'initializing'! +initEvents + super initEvents. + self enableButtonEvents. + self enableButtonMotionEvents + +! + initialize |leftAlignToggle alignToggle centerToggle rightAlignToggle leftTabButton centerTabButton rightTabButton decimalTabButton @@ -137,251 +375,59 @@ h := self class leftAlignForm height. panel1 := HorizontalPanelView - origin:(0.0 @ 0.0) - extent:[(width // 3) @ (h*2) "(height - scaleHeight)"] - in:self. + origin:(0.0 @ 0.0) + extent:[(width // 3 * 2) @ (h*2)] + in:self. panel1 borderWidth:0. - panel1 layout:#left. - - panel2 := HorizontalPanelView - origin:[(width // 3) @ margin] - extent:[(width // 3) @ (h*2) "(height - scaleHeight)"] - in:self. - panel2 borderWidth:0. - panel2 layout:#center. + panel1 layout:#leftSpace. panel3 := HorizontalPanelView - origin:[(width // 3 * 2) @ margin] - extent:[((width // 3)-margin) @ (h*2) "(height - scaleHeight)"] - in:self. + origin:[(width // 3 * 2) @ margin] + extent:[((width // 3)-margin) @ (h*2) "(height - scaleHeight)"] + in:self. panel3 borderWidth:0. panel3 layout:#right. leftAlignToggle := RadioButton form:(self class leftAlignForm) - action:[self leftAlign] - in:panel1. + action:[self leftAlign] + in:panel1. alignToggle := RadioButton form:(self class alignForm) - action:[self align] - in:panel1. + action:[self align] + in:panel1. centerToggle := RadioButton form:(self class centerForm) - action:[self center] - in:panel1. + action:[self center] + in:panel1. rightAlignToggle := RadioButton form:(self class rightAlignForm) - action:[self rightAlign] - in:panel1. + action:[self rightAlign] + in:panel1. group := RadioButtonGroup new. group add:leftAlignToggle. group add:alignToggle. group add:centerToggle. group add:rightAlignToggle. + "separator" + (View in:panel1) extent:(50 @ 2); borderWidth:0; level:0. + leftTabButton := Button form:(self class leftTabForm) - action:[self leftTab] - in:panel2. + action:[self leftTab] + in:panel1. centerTabButton := Button form:(self class centerTabForm) - action:[self centerTab] - in:panel2. + action:[self centerTab] + in:panel1. rightTabButton := Button form:(self class rightTabForm) - action:[self rightTab] - in:panel2. + action:[self rightTab] + in:panel1. decimalTabButton := Button form:(self class decimalTabForm) - action:[self decimalTab] - in:panel2. + action:[self decimalTab] + in:panel1. - lineSpacingField := EditField in:panel3. +"/ lineSpacingField := EditField in:panel3. - leftMargin := 0.25. - rightMargin := 8.25 - - "TextRuler new realize" -! + leftMargin := 0.0. + rightMargin := 8.5 -initEvents - super initEvents. - self enableButtonEvents. - self enableButtonMotionEvents - + "TextRuler new open" ! ! -!TextRuler methodsFor:'user interaction'! - -leftAlign - ^ self -! - -rightAlign - ^ self -! - -align - ^ self -! - -center - ^ self -! - -leftTab - ^ self -! - -rightTab - ^ self -! - -centerTab - ^ self -! - -decimalTab - ^ self -! - -buttonPress:button x:x y:y - "position a tab or start moving a ruler" - - |mpos| - - mpos := self inchToPixel:leftMargin. - (((mpos - 4) <= x) and:[x <= (mpos + 4)]) ifTrue:[ - "start moving left margin" - moving := #left. - ^ self - ]. - mpos := self inchToPixel:rightMargin. - (((mpos - 4) <= x) and:[x <= (mpos + 4)]) ifTrue:[ - "start moving right margin" - moving := #right. - ^ self - ]. - - ^ self -! - -buttonMotion:state x:x y:y - "position a tab or start moving a ruler" - - |mpos| - - moving notNil ifTrue:[ - self clearMargin:moving. - mpos := self pixelToInch:x. - (mpos < 0) ifTrue:[ - mpos := 0 - ]. - (mpos > paperWidth) ifTrue:[ - mpos := paperWidth - ]. - (moving == #left) ifTrue:[ - leftMargin := mpos - ]. - (moving == #right) ifTrue:[ - rightMargin := mpos - ]. - self drawMargin:moving - ] -! - -buttonRelease:button x:x y:y - "position a tab or start moving a ruler" - - moving := nil -! ! - -!TextRuler methodsFor:'redrawing'! - -clearMargin:which - "clear margin" - - |x top form| - - self paint:viewBackground. - self background:viewBackground. - - top := height - (font height) - (font ascent). - - (which == #left) ifTrue:[ - x := (self inchToPixel:leftMargin) rounded. - form := self class leftMarginForm - ]. - (which == #right) ifTrue:[ - x := (self inchToPixel:rightMargin) rounded. - form := self class rightMarginForm - ]. - - self displayOpaqueForm:form x:(x - (form width // 2)) -! - -drawMargin:which - "clear margin" - - |x top form| - - self paint:fgColor. - self background:viewBackground. - - top := height - (font height) - (font ascent). - - (which == #left) ifTrue:[ - x := (self inchToPixel:leftMargin) rounded. - form := self class leftMarginForm - ]. - (which == #right) ifTrue:[ - x := (self inchToPixel:rightMargin) rounded. - form := self class rightMarginForm - ]. - - self displayOpaqueForm:form x:(x - (form width // 2)) -! - -redraw - "redraw margin & tab marks" - - |x top form tab type tabStops tabAlign| - - super redraw. - - self paint:fgColor. - self background:viewBackground. - - top := height - (font height) - (font ascent). - - x := (self inchToPixel:leftMargin) rounded. - form := self class leftMarginForm. - self displayOpaqueForm:form x:(x - (form width // 2)) - y:(top - form height). - x := (self inchToPixel:rightMargin) rounded. - form := self class rightMarginForm. - self displayOpaqueForm:form - x:(x - (form width // 2)) - y:(top - form height). - - tabStops := tabSpec positions. - tabAlign := tabSpec align. - tabStops notNil ifTrue:[ - 1 to:tabStops size do:[:tabNr | - tab := tabStops at:tabNr. - type := tabAlign at:tabNr. - x := (tabSpec positionOfTab:tabNr on:self) rounded. - (type == #left) ifTrue:[ - form := self class leftTabForm - ] ifFalse:[ - (type == #right) ifTrue:[ - form := self class rightTabForm - ] ifFalse:[ - (type == #center) ifTrue:[ - form := self class centerTabForm - ] ifFalse:[ - (type == #decimal) ifTrue:[ - form := self class decimalTabForm - ] - ] - ] - ]. - self displayOpaqueForm:form - x:(x - (form width // 2)) - y:(top - form height) - ] - ] -! !