PluggableTextMorph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

PluggableTextMorph

Keith McKay-2
Hi

I'm looking for some advice on setting the margins in a
PluggableTextMorph(PTM) programaticaly. It can be done easily once the PTM
is open in the World by drilling down to the TextMorph and invoking its menu
using the halos, but I would like the option of initialising them, or adding
as an item to a menu of the PTM.

Am I missing something obvious? Should I just use a TextMorph instead?
Hints rather than solutions would be preferable.

Thanks

Keith
Hamilton, Scotland

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/428 - Release Date: 25/08/2006
 

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: PluggableTextMorph

Keith McKay-2
Hi

I have found a solution to my problem.

If you send the message allMorphs to a morph it returns a collection
containing all morphs in the composite morph including the receiver.

In this case a PluggableTextMorph would give:

aPluggableTextMorph allMorphs>> an OrderedCollection(a RectangleMorph(1207)
a RectangleMorph(3700) a RectangleMorph(1462) an ImageMorph(2630) a
RectangleMorph(2661) an ImageMorph(3061) a RectangleMorph(299) an
ImageMorph(464) a RectangleMorph(1782) a ScrollBar(1419) a
TextMorphForEditView(2717) a TransformMorph(726) a PluggableTextMorph(127))

I had used submorphs at first but this confused me because it returned #(a
ScrollBar(1109) a TransformMorph(2472)).  But then I found allMorphs which
worked.

I had thought that the PluggableTextMorph contained a TextMorph as a
submorph since it had an instance variable of that name but it turns out
that it is a TextMorphForEditView which I found after browsing the
PluggableTextMorph class.  So knowing that TextMorphForEditView inherits
from TextMorph I knew I could play about with the margins and other layout
properties of TextMorphs. But how to get to the TextMorphForEditView?  The
instance method in Morph held a clue

allMorphs
        "Return a collection containing all morphs in this composite morph
(including the receiver)."

        | all |
        all _ OrderedCollection new: 100.
        self allMorphsDo: [: m | all add: m].
        ^ all

The message allMorphsDo: aBlock was the answer!

My solution is..

| aPluggableTextMorph |

aPluggableTextMorph allMorphsDo:[:each | (each isKindOf:
TextMorphForEditView)
                                                ifTrue:[ each margins:
100@100]].

This works well but is it the best way to access submorphs?

Thanks
Keith

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Keith
McKay
Sent: 27 August 2006 17:03
To: [hidden email]
Subject: [Newbies] PluggableTextMorph


Hi

I'm looking for some advice on setting the margins in a
PluggableTextMorph(PTM) programaticaly. It can be done easily once the PTM
is open in the World by drilling down to the TextMorph and invoking its menu
using the halos, but I would like the option of initialising them, or adding
as an item to a menu of the PTM.

Am I missing something obvious? Should I just use a TextMorph instead? Hints
rather than solutions would be preferable.

Thanks

Keith
Hamilton, Scotland

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/428 - Release Date: 25/08/2006
 

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/428 - Release Date: 25/08/2006
 

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/428 - Release Date: 25/08/2006
 

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: PluggableTextMorph

Alain Plantec
Le Monday 28 August 2006 22:34, Keith McKay a écrit :

> My solution is..
>
> | aPluggableTextMorph |
>
> aPluggableTextMorph allMorphsDo:[:each | (each isKindOf:
> TextMorphForEditView)
>                                                 ifTrue:[ each margins:
> 100@100]].
>
> This works well but is it the best way to access submorphs?
>
hi Keith,
maybe with :
aPluggableTextMorph textMorph margins: 100@100

alain
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: PluggableTextMorph

Alain Plantec
In reply to this post by Keith McKay-2
Le Sunday 27 August 2006 18:02, Keith McKay a écrit :

> Hi
>
> I'm looking for some advice on setting the margins in a
> PluggableTextMorph(PTM) programaticaly. It can be done easily once the PTM
> is open in the World by drilling down to the TextMorph and invoking its menu
> using the halos, but I would like the option of initialising them, or adding
> as an item to a menu of the PTM.
>
> Am I missing something obvious? Should I just use a TextMorph instead?
> Hints rather than solutions would be preferable.
I see two solutions :

one is to make two new classes :
PluggableTextMorphWithMargins that is a subclass of PluggableTextMorph
TextMorphForEditViewWithMargins that is a subclass of TextMorphForEditView

and one method in each new subclass :
PluggableTextMorphWithMargins>>textMorphClass
        "Answer the class used to create the receiver's textMorph"
        ^ TextMorphForEditViewWithMargins

TextMorphForEditViewWithMargins>>initialize
        super initialize.
        self margins: 10@10

And now you can use PluggableTextMorphWithMargins instead of PluggableTextMorph.

another solution is two send 'ptm textMorph margins: 10@10' to your PluggableTextMorph instance (ptm) from
PluggableTextMorph instance owner (in your GUI class initialize instance method for example).
I think this is a better way ('one particular need, one subclass' is often not a good scheme...)

alain
>
> Thanks
>
> Keith
> Hamilton, Scotland
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners