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