ViewStyle.st
author claus
Sun, 10 Sep 1995 16:50:55 +0200
changeset 182 b5f7fdff0f6d
parent 153 c56277fa4865
child 219 9ff0660f447f
permissions -rw-r--r--
.

"
 COPYRIGHT (c) 1994 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.
"

ResourcePack subclass:#ViewStyle 
	 instanceVariableNames:'name is3D'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Views-Support'
!

ViewStyle comment:'
COPYRIGHT (c) 1994 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.5 1995-09-10 14:50:26 claus Exp $
'!

!ViewStyle class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1993 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.
"
!

version
"
$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.5 1995-09-10 14:50:26 claus Exp $
"
!

documentation
"
    instances of this class keep all view-style specific information.
    The current viewStyle is kept in Views-classvariable called 'StyleSheet'
    and is instantiated with 'View defaultStyle:aStyleSymbol', which reads
    a stylesheet from a file '<aStyleSymbol>.style' (usually in the 'resources'
    directory.
"
! !

!ViewStyle class methodsFor:'instance creation'!

fromFile:aFileName
    "get the preferences definitions from a file"

    |prefs failed nm|

    prefs := self new.
    (aFileName endsWith:'.style') ifTrue:[
	nm := aFileName copyWithoutLast:6
    ] ifFalse:[
	nm := aFileName
    ].
    prefs at:#name put:nm. 

    failed := (prefs readFromFile:aFileName directory:'resources') isNil.
    prefs at:#fileReadFailed put:failed. 
    ^ prefs

    "
     ViewStyle fromFile:'motif.style'
     ViewStyle fromFile:'normal.style'
     ViewStyle fromFile:'iris.style'
    "
! !

!ViewStyle methodsFor:'accessing'!

deviceResourceAt:aKey default:default
    "retrieve a resource - also aquire a device version
     to avoid repeated allocations later"

    |aResource|

    aResource := self at:aKey default:default.
    aResource notNil ifTrue:[
	^ aResource on:Screen current
    ].
    ^ nil
!

colorAt:aKey default:default
    "retrieve a color resource - also aquire a device color
     to avoid repeated color allocations later"

    ^ self deviceResourceAt:aKey default:default
!

colorAt:aKey
    "retrieve a color resource - also aquire a device color
     to avoid repeated color allocations later"

    ^ self deviceResourceAt:aKey default:nil 
!

fontAt:aKey default:default
    "retrieve a font resource - also aquire a device font
     to avoid repeated font allocations later"

    ^ self deviceResourceAt:aKey default:default
!

fontAt:aKey
    "retrieve a font resource - also aquire a device font
     to avoid repeated font allocations later"

    ^ self deviceResourceAt:aKey default:nil 
!

at:aKey
    |sCls val|

    sCls := thisContext sender receiver.
    sCls isBehavior ifFalse:[sCls := sCls class].
    (sCls isSubclassOf:SimpleView) ifTrue:[
	val := self at:(sCls name , '.' , aKey) default:nil.
	val notNil ifTrue:[^ val].
    ].
    ^ self at:aKey default:nil

    "Modified: 10.9.1995 / 10:59:38 / claus"
!

is3D
    is3D isNil ifTrue:[
	is3D := self at:#is3D default:false.
    ].
    ^ is3D
!

name
    name isNil ifTrue:[
	name := self at:#name default:'noname'.
    ].
    ^ name
!

doesNotUnderstand:aMessage
    ^ self at:(aMessage selector) default:nil
! !