UISpecificationTool.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 14 Nov 2018 12:07:51 +0100
branchjv
changeset 3630 5e718e0a754e
parent 3221 0bd301f4d1e1
permissions -rw-r--r--
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present

- All source *.st files are now Unicode UTF8 without BOM
Files are in two groups (fileOut works this way in Smalltalk/X):
- containing a unicode character have "{ Encoding: utf8 }" at the header
- ASCII only are without the header
     1 "
     2  COPYRIGHT (c) 1995 by eXept Software AG
     3               All Rights Reserved
     4 
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    11 "
    12 "{ Package: 'stx:libtool2' }"
    13 
    14 "{ NameSpace: Smalltalk }"
    15 
    16 ApplicationModel subclass:#UISpecificationTool
    17 	instanceVariableNames:'modifiedHolder aspects specification selection specChannel
    18 		buildInView listOfSpecViews'
    19 	classVariableNames:''
    20 	poolDictionaries:''
    21 	category:'Interface-UIPainter'
    22 !
    23 
    24 ViewScroller subclass:#BuildInView
    25 	instanceVariableNames:''
    26 	classVariableNames:''
    27 	poolDictionaries:''
    28 	privateIn:UISpecificationTool
    29 !
    30 
    31 !UISpecificationTool class methodsFor:'documentation'!
    32 
    33 copyright
    34 "
    35  COPYRIGHT (c) 1995 by eXept Software AG
    36               All Rights Reserved
    37 
    38  This software is furnished under a license and may be used
    39  only in accordance with the terms of that license and with the
    40  inclusion of the above copyright notice.   This software may not
    41  be provided or otherwise made available to, or used by, any
    42  other person.  No title to or ownership of the software is
    43  hereby transferred.
    44 "
    45 
    46 
    47 
    48 !
    49 
    50 documentation
    51 "
    52     used by the UIPainter to manipulate the specifications of the selected component
    53 
    54     [author:]
    55         Claus Atzkern
    56 
    57     [see also:]
    58         UIPainter
    59         UILayoutTool
    60         UIHelpTool
    61 "
    62 ! !
    63 
    64 !UISpecificationTool class methodsFor:'help specs'!
    65 
    66 helpSpec
    67     "This resource specification was automatically generated
    68      by the UIHelpTool of ST/X."
    69 
    70     "Do not manually edit this!! If it is corrupted,
    71      the UIHelpTool may not be able to read the specification."
    72 
    73     "
    74      UIHelpTool openOnClass:UISpecificationTool    
    75     "
    76 
    77     <resource: #help>
    78 
    79     ^ super helpSpec addPairsFrom:#(
    80 
    81 #addTabAction
    82 ''
    83 
    84 #allowNilColor
    85 'Add an option to allow a nil-Color to be choosen'
    86 
    87 #allowSymbolicColors
    88 'ColorMenu is allowed to return a symbolic color name'
    89 
    90 #allowSymbolicFonts
    91 'FontMenu is allowed to return a symbolic font name'
    92 
    93 #browseAction
    94 'Browse/Create the Action method'
    95 
    96 #browseAspectMethod
    97 'Browse/Create the Aspect method'
    98 
    99 #editListSpec
   100 'Edit the contents of the list (inline)'
   101 
   102 #labelsAreColored
   103 'Draw the labels in their color (otherwise, draw the background)'
   104 
   105 #showFrame
   106 'Show the frame'
   107 
   108 #showUseDefaultToggle
   109 'Add a toggle to choose the "default" color (resulting color will be nil)'
   110 
   111 )
   112 ! !
   113 
   114 !UISpecificationTool class methodsFor:'image specs'!
   115 
   116 browseActionImage
   117     ^ UIPainter browseActionImage
   118 !
   119 
   120 editTableIcon
   121     ^ UIPainter editTableIcon
   122 ! !
   123 
   124 !UISpecificationTool class methodsFor:'interface specs'!
   125 
   126 windowSpec
   127     "This resource specification was automatically generated
   128      by the UIPainter of ST/X."
   129 
   130     "Do not manually edit this!! If it is corrupted,
   131      the UIPainter may not be able to read the specification."
   132 
   133     "
   134      UIPainter new openOnClass:UISpecificationTool andSelector:#windowSpec
   135      UISpecificationTool new openInterface:#windowSpec
   136      UISpecificationTool open
   137     "
   138 
   139     <resource: #canvas>
   140 
   141     ^ 
   142     #(FullSpec
   143        name: windowSpec
   144        window: 
   145       (WindowSpec
   146          label: 'unnamed canvas'
   147          name: 'unnamed canvas'
   148          bounds: (Rectangle 0 0 300 300)
   149        )
   150        component: 
   151       (SpecCollection
   152          collection: (
   153           (ArbitraryComponentSpec
   154              name: 'BuildInView'
   155              layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
   156              hasVerticalScrollBar: false
   157              miniScrollerVertical: false
   158              autoHideScrollBars: true
   159              hasBorder: false
   160              component: buildInView
   161            )
   162           )
   163         
   164        )
   165      )
   166 ! !
   167 
   168 !UISpecificationTool class methodsFor:'resources'!
   169 
   170 classResources
   171     "my translations are found in the UIPainter classes resources"
   172 
   173     ^ UIPainter classResources 
   174 ! !
   175 
   176 !UISpecificationTool methodsFor:'accessing-channels'!
   177 
   178 modifiedHolder:aValueHolder
   179     "set the value holder set to true in case of modifying attributes
   180     "
   181 
   182     modifiedHolder removeDependent:self.
   183 
   184     (modifiedHolder := aValueHolder) notNil ifTrue:[
   185         modifiedHolder addDependent:self.
   186     ].
   187 
   188 ! !
   189 
   190 !UISpecificationTool methodsFor:'accessing-specification'!
   191 
   192 listOfAspects
   193     ^ masterApplication listOfAspects
   194 
   195     "Created: / 12-01-2008 / 19:24:39 / cg"
   196 !
   197 
   198 listOfCallbacks
   199     ^ masterApplication listOfCallbacks
   200 
   201     "Created: / 12-01-2008 / 19:25:05 / cg"
   202 !
   203 
   204 specification
   205     "gets current edit specification
   206     "
   207     ^ specification
   208 
   209 
   210 !
   211 
   212 specification:aSpec
   213     "sets current edit specification
   214     "
   215     aSpec notNil ifTrue:[
   216         "/ same type of spec - simply change the spec;  no need to setup everything
   217         specification class == aSpec class ifTrue:[
   218             specification := aSpec.
   219             specChannel value:specification.
   220           ^ self
   221         ]
   222     ].
   223 
   224     "/ release resources
   225     specChannel release.
   226     aspects     release.
   227     selection := listOfSpecViews := nil.
   228     buildInView destroyAllClientViews.
   229 
   230     (specification := aSpec) isNil ifTrue:[
   231         aspects := specChannel := nil.
   232       ^ self
   233     ].
   234     
   235     "/ some tricky specs need the builder during the addBindings phase.
   236     "/ This is passed down in a special UIBindingsDictionary
   237     "/ (remain backward compatible)
   238 
   239     aspects := UISpecification newBindingsDictionary.
   240     aspects builder:builder.
   241     aspects at:#modifiedChannel put:modifiedHolder.
   242     aspects at:#acceptChannel   put:self acceptChannel.
   243 
   244     aspects at:#listOfAspects put:[self listOfAspects].
   245     aspects at:#listOfCallbacks put:[self listOfCallbacks].
   246 
   247     specChannel := specification asValue.
   248     specification class addBindingsTo:aspects for:specification channel:specChannel.
   249 
   250     "/ arrange for being notified, if any aspect changes
   251     aspects do:[:el| el addDependent:self ].
   252 
   253     "Modified: / 12-01-2008 / 19:28:47 / cg"
   254 ! !
   255 
   256 !UISpecificationTool methodsFor:'actions'!
   257 
   258 setMaxExtent
   259     "set the windows maxExtent from its current extent"
   260 
   261     |canvas currentExtent|
   262 
   263     canvas := self masterApplication canvas.
   264     currentExtent := canvas extent.
   265     (self aspectFor:#maxX) value:currentExtent x.
   266     (self aspectFor:#maxY) value:currentExtent y.
   267 
   268     "Modified: / 29.10.1997 / 18:29:17 / cg"
   269 !
   270 
   271 setMinExtent
   272     "set the windows minExtent from its current extent"
   273 
   274     |canvas currentExtent|
   275 
   276     canvas := self masterApplication canvas.
   277     currentExtent := canvas extent.
   278     (self aspectFor:#minX) value:currentExtent x.
   279     (self aspectFor:#minY) value:currentExtent y.
   280 
   281     "Created: / 29.10.1997 / 18:17:55 / cg"
   282     "Modified: / 29.10.1997 / 18:28:53 / cg"
   283 ! !
   284 
   285 !UISpecificationTool methodsFor:'bindings'!
   286 
   287 acceptChannel
   288     ^ masterApplication acceptChannel
   289 
   290     "Modified: / 12-01-2008 / 11:28:38 / cg"
   291 !
   292 
   293 aspectFor:aKey
   294     "returns the aspect for a key or nil"
   295 
   296     aspects notNil ifTrue:[
   297         ^ aspects at:aKey ifAbsent:nil
   298     ].
   299     ^ super aspectFor:aKey
   300 
   301     "Modified: / 12-01-2008 / 11:28:52 / cg"
   302 !
   303 
   304 buildInView
   305     ^ buildInView
   306 !
   307 
   308 specificationFor:aKey
   309     "this is called if our current specification contains 
   310      subspecifications or subcanvases.
   311      Get the subspecification from the current specification"
   312 
   313     specification notNil ifTrue:[
   314         ^ specification class perform:aKey ifNotUnderstood:nil
   315     ].
   316     ^ nil
   317 ! !
   318 
   319 !UISpecificationTool methodsFor:'change & update'!
   320 
   321 update
   322     "reload specification
   323     "
   324     specChannel notNil ifTrue:[
   325         specChannel value:specification.
   326     ]
   327 
   328 
   329 !
   330 
   331 update:something with:someArgument from:someone
   332     "any attribute changed its state in the current specification
   333     "
   334     someone ~~ modifiedHolder ifTrue:[
   335         "/ any in the spec has changed.
   336         "/ update my modified holders value
   337 
   338         modifiedHolder value:true
   339     ]
   340 
   341     "Modified: / 16.7.1998 / 19:25:59 / cg"
   342 ! !
   343 
   344 !UISpecificationTool methodsFor:'help'!
   345 
   346 basicFlyByHelpTextForKey:aKey
   347     "activeHelp interface: return some help text for a key.
   348      Redefined to ask the current components Spec first."
   349 
   350     |helpText|
   351 
   352     "/ first, ask the master (a hook for expecco, to provide different help texts)
   353     masterApplication notNil ifTrue:[
   354         helpText := masterApplication basicFlyByHelpTextForKey:aKey.
   355         helpText notNil ifTrue:[^ helpText ].
   356 
   357         "/ then, ask the master about the spec
   358         helpText := masterApplication basicHelpTextFromSpecification:specification forKey:aKey.
   359     ] ifFalse:[
   360         "/ then, ask the spec
   361         helpText := (specification helpSpec) at:aKey ifAbsent:nil.
   362     ].
   363     helpText notNil ifTrue:[^ helpText ].
   364 
   365     "/ finally, ask myself...
   366     ^ super basicFlyByHelpTextForKey:aKey.
   367 !
   368 
   369 basicHelpTextForKey:aKey
   370     "activeHelp interface: return some help text for a key.
   371      Redefined to ask the current components Spec first."
   372 
   373     |helpText|
   374 
   375     "/ first, ask the master (a hook for expecco, to provide different help texts)
   376     masterApplication notNil ifTrue:[
   377         helpText := masterApplication basicHelpTextForKey:aKey.
   378         helpText notNil ifTrue:[^ helpText ].
   379 
   380         "/ then, ask the master about the spec
   381         helpText := masterApplication basicHelpTextFromSpecification:specification forKey:aKey.
   382     ] ifFalse:[
   383         "/ then, ask the spec
   384         helpText := (specification helpSpec) at:aKey ifAbsent:nil.
   385     ].
   386     helpText notNil ifTrue:[^ helpText ].
   387 
   388     "/ finally, ask myself...
   389     ^ super basicHelpTextForKey:aKey.
   390 ! !
   391 
   392 !UISpecificationTool methodsFor:'initialization'!
   393 
   394 initialize
   395     super initialize.
   396     buildInView := BuildInView new.
   397     buildInView keepViews:true.
   398 ! !
   399 
   400 !UISpecificationTool methodsFor:'selection'!
   401 
   402 selection:something
   403     "selection changed"
   404 
   405     |slices index spec window|
   406 
   407     specification notNil ifTrue:[
   408         slices := specification class slices.
   409         index  := slices findFirst:[:aSlice| aSlice first = something ].
   410 
   411         index ~~ 0 ifTrue:[
   412             spec := specification class perform:((slices at:index) last)
   413         ]
   414     ].
   415 
   416     spec ~= selection ifTrue:[
   417         (selection := spec) notNil ifTrue:[
   418             listOfSpecViews isNil ifTrue:[
   419                 listOfSpecViews := Array new:(slices size).
   420             ] ifFalse:[
   421                 window := listOfSpecViews at:index
   422             ].
   423             window isNil ifTrue:[
   424                 builder buildFromSpec:spec in:(window := SimpleView new).
   425                 listOfSpecViews at:index put:window.
   426             ].
   427         ].
   428         buildInView scrolledView:window.
   429     ].
   430 ! !
   431 
   432 !UISpecificationTool::BuildInView methodsFor:'accessing'!
   433 
   434 mapped
   435     super mapped.
   436 
   437     scrolledView notNil ifTrue:[
   438         scrolledView beVisible.
   439         scrolledView raise.
   440     ].
   441 !
   442 
   443 scrolledView:aView
   444     "set the view to be scrolled"
   445     |wrapper y|
   446 
   447     scrolledView == aView ifTrue:[^ self].
   448 
   449     scrolledView notNil ifTrue:[
   450         scrolledView unmap.
   451     ].
   452     (scrolledView := aView) notNil ifTrue:[
   453         scrolledView superView ~~ frame ifTrue:[
   454             frame addSubView:scrolledView.
   455         ].
   456         true ifTrue:[
   457             scrolledView borderWidth:0; level:0.
   458             scrolledView subViews size == 1 ifTrue:[
   459                 wrapper := scrolledView subViews first.
   460                 wrapper isScrollWrapper ifTrue:[
   461                     "/ give it a full-relative size, and let it do
   462                     "/ the scrolling itself.
   463                     y := 1.0
   464                 ]
   465             ].
   466             y isNil ifTrue:[
   467                 y := scrolledView preferredHeight
   468             ].
   469             scrolledView allViewBackground:(self viewBackground).
   470             scrolledView origin:0@0 corner:1.0 @ y.
   471         ].
   472     ].    
   473     shown ifTrue:[
   474         scrolledView beVisible.
   475         scrolledView raise.
   476         self sizeChanged:nil.
   477     ].
   478     model value:scrolledView.
   479 ! !
   480 
   481 !UISpecificationTool::BuildInView methodsFor:'initialization'!
   482 
   483 initialize
   484     super initialize.
   485     resizeScrolledViewHorizontal := true.
   486     resizeScrolledViewVertical   := true.
   487 !
   488 
   489 realize
   490 
   491     super realize.
   492    superView notNil ifTrue:[superView level:0].
   493 ! !
   494 
   495 !UISpecificationTool class methodsFor:'documentation'!
   496 
   497 version
   498     ^ '$Header$'
   499 !
   500 
   501 version_CVS
   502     ^ '$Header$'
   503 ! !
   504