UISpecificationTool.st
author Claus Gittinger <cg@exept.de>
Tue, 07 Jul 2015 12:20:42 +0200
changeset 3221 0bd301f4d1e1
parent 3214 eceb5d2c5526
child 3517 e7224542f1a3
child 3630 5e718e0a754e
permissions -rw-r--r--
class: UISpecificationTool
comment/format in: #helpSpec
     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     ^ UIPainter browseActionImage
   120 !
   121 
   122 editTableIcon
   123     ^ UIPainter editTableIcon
   124 ! !
   125 
   126 !UISpecificationTool class methodsFor:'interface specs'!
   127 
   128 windowSpec
   129     "This resource specification was automatically generated
   130      by the UIPainter of ST/X."
   131 
   132     "Do not manually edit this!! If it is corrupted,
   133      the UIPainter may not be able to read the specification."
   134 
   135     "
   136      UIPainter new openOnClass:UISpecificationTool andSelector:#windowSpec
   137      UISpecificationTool new openInterface:#windowSpec
   138      UISpecificationTool open
   139     "
   140 
   141     <resource: #canvas>
   142 
   143     ^ 
   144     #(FullSpec
   145        name: windowSpec
   146        window: 
   147       (WindowSpec
   148          label: 'unnamed canvas'
   149          name: 'unnamed canvas'
   150          bounds: (Rectangle 0 0 300 300)
   151        )
   152        component: 
   153       (SpecCollection
   154          collection: (
   155           (ArbitraryComponentSpec
   156              name: 'BuildInView'
   157              layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
   158              hasVerticalScrollBar: false
   159              miniScrollerVertical: false
   160              autoHideScrollBars: true
   161              hasBorder: false
   162              component: buildInView
   163            )
   164           )
   165         
   166        )
   167      )
   168 ! !
   169 
   170 !UISpecificationTool class methodsFor:'resources'!
   171 
   172 classResources
   173     "my translations are found in the UIPainter classes resources"
   174 
   175     ^ UIPainter classResources 
   176 ! !
   177 
   178 !UISpecificationTool methodsFor:'accessing-channels'!
   179 
   180 modifiedHolder:aValueHolder
   181     "set the value holder set to true in case of modifying attributes
   182     "
   183 
   184     modifiedHolder removeDependent:self.
   185 
   186     (modifiedHolder := aValueHolder) notNil ifTrue:[
   187         modifiedHolder addDependent:self.
   188     ].
   189 
   190 ! !
   191 
   192 !UISpecificationTool methodsFor:'accessing-specification'!
   193 
   194 listOfAspects
   195     ^ masterApplication listOfAspects
   196 
   197     "Created: / 12-01-2008 / 19:24:39 / cg"
   198 !
   199 
   200 listOfCallbacks
   201     ^ masterApplication listOfCallbacks
   202 
   203     "Created: / 12-01-2008 / 19:25:05 / cg"
   204 !
   205 
   206 specification
   207     "gets current edit specification
   208     "
   209     ^ specification
   210 
   211 
   212 !
   213 
   214 specification:aSpec
   215     "sets current edit specification
   216     "
   217     aSpec notNil ifTrue:[
   218         "/ same type of spec - simply change the spec;  no need to setup everything
   219         specification class == aSpec class ifTrue:[
   220             specification := aSpec.
   221             specChannel value:specification.
   222           ^ self
   223         ]
   224     ].
   225 
   226     "/ release resources
   227     specChannel release.
   228     aspects     release.
   229     selection := listOfSpecViews := nil.
   230     buildInView destroyAllClientViews.
   231 
   232     (specification := aSpec) isNil ifTrue:[
   233         aspects := specChannel := nil.
   234       ^ self
   235     ].
   236     
   237     "/ some tricky specs need the builder during the addBindings phase.
   238     "/ This is passed down in a special UIBindingsDictionary
   239     "/ (remain backward compatible)
   240 
   241     aspects := UISpecification newBindingsDictionary.
   242     aspects builder:builder.
   243     aspects at:#modifiedChannel put:modifiedHolder.
   244     aspects at:#acceptChannel   put:self acceptChannel.
   245 
   246     aspects at:#listOfAspects put:[self listOfAspects].
   247     aspects at:#listOfCallbacks put:[self listOfCallbacks].
   248 
   249     specChannel := specification asValue.
   250     specification class addBindingsTo:aspects for:specification channel:specChannel.
   251 
   252     "/ arrange for being notified, if any aspect changes
   253     aspects do:[:el| el addDependent:self ].
   254 
   255     "Modified: / 12-01-2008 / 19:28:47 / cg"
   256 ! !
   257 
   258 !UISpecificationTool methodsFor:'actions'!
   259 
   260 setMaxExtent
   261     "set the windows maxExtent from its current extent"
   262 
   263     |canvas currentExtent|
   264 
   265     canvas := self masterApplication canvas.
   266     currentExtent := canvas extent.
   267     (self aspectFor:#maxX) value:currentExtent x.
   268     (self aspectFor:#maxY) value:currentExtent y.
   269 
   270     "Modified: / 29.10.1997 / 18:29:17 / cg"
   271 !
   272 
   273 setMinExtent
   274     "set the windows minExtent from its current extent"
   275 
   276     |canvas currentExtent|
   277 
   278     canvas := self masterApplication canvas.
   279     currentExtent := canvas extent.
   280     (self aspectFor:#minX) value:currentExtent x.
   281     (self aspectFor:#minY) value:currentExtent y.
   282 
   283     "Created: / 29.10.1997 / 18:17:55 / cg"
   284     "Modified: / 29.10.1997 / 18:28:53 / cg"
   285 ! !
   286 
   287 !UISpecificationTool methodsFor:'bindings'!
   288 
   289 acceptChannel
   290     ^ masterApplication acceptChannel
   291 
   292     "Modified: / 12-01-2008 / 11:28:38 / cg"
   293 !
   294 
   295 aspectFor:aKey
   296     "returns the aspect for a key or nil"
   297 
   298     aspects notNil ifTrue:[
   299         ^ aspects at:aKey ifAbsent:nil
   300     ].
   301     ^ super aspectFor:aKey
   302 
   303     "Modified: / 12-01-2008 / 11:28:52 / cg"
   304 !
   305 
   306 buildInView
   307     ^ buildInView
   308 !
   309 
   310 specificationFor:aKey
   311     "this is called if our current specification contains 
   312      subspecifications or subcanvases.
   313      Get the subspecification from the current specification"
   314 
   315     specification notNil ifTrue:[
   316         ^ specification class perform:aKey ifNotUnderstood:nil
   317     ].
   318     ^ nil
   319 ! !
   320 
   321 !UISpecificationTool methodsFor:'change & update'!
   322 
   323 update
   324     "reload specification
   325     "
   326     specChannel notNil ifTrue:[
   327         specChannel value:specification.
   328     ]
   329 
   330 
   331 !
   332 
   333 update:something with:someArgument from:someone
   334     "any attribute changed its state in the current specification
   335     "
   336     someone ~~ modifiedHolder ifTrue:[
   337         "/ any in the spec has changed.
   338         "/ update my modified holders value
   339 
   340         modifiedHolder value:true
   341     ]
   342 
   343     "Modified: / 16.7.1998 / 19:25:59 / cg"
   344 ! !
   345 
   346 !UISpecificationTool methodsFor:'help'!
   347 
   348 basicFlyByHelpTextForKey:aKey
   349     "activeHelp interface: return some help text for a key.
   350      Redefined to ask the current components Spec first."
   351 
   352     |helpText|
   353 
   354     "/ first, ask the master (a hook for expecco, to provide different help texts)
   355     masterApplication notNil ifTrue:[
   356         helpText := masterApplication basicFlyByHelpTextForKey:aKey.
   357         helpText notNil ifTrue:[^ helpText ].
   358 
   359         "/ then, ask the master about the spec
   360         helpText := masterApplication basicHelpTextFromSpecification:specification forKey:aKey.
   361     ] ifFalse:[
   362         "/ then, ask the spec
   363         helpText := (specification helpSpec) at:aKey ifAbsent:nil.
   364     ].
   365     helpText notNil ifTrue:[^ helpText ].
   366 
   367     "/ finally, ask myself...
   368     ^ super basicFlyByHelpTextForKey:aKey.
   369 !
   370 
   371 basicHelpTextForKey:aKey
   372     "activeHelp interface: return some help text for a key.
   373      Redefined to ask the current components Spec first."
   374 
   375     |helpText|
   376 
   377     "/ first, ask the master (a hook for expecco, to provide different help texts)
   378     masterApplication notNil ifTrue:[
   379         helpText := masterApplication basicHelpTextForKey:aKey.
   380         helpText notNil ifTrue:[^ helpText ].
   381 
   382         "/ then, ask the master about the spec
   383         helpText := masterApplication basicHelpTextFromSpecification:specification forKey:aKey.
   384     ] ifFalse:[
   385         "/ then, ask the spec
   386         helpText := (specification helpSpec) at:aKey ifAbsent:nil.
   387     ].
   388     helpText notNil ifTrue:[^ helpText ].
   389 
   390     "/ finally, ask myself...
   391     ^ super basicHelpTextForKey:aKey.
   392 ! !
   393 
   394 !UISpecificationTool methodsFor:'initialization'!
   395 
   396 initialize
   397     super initialize.
   398     buildInView := BuildInView new.
   399     buildInView keepViews:true.
   400 ! !
   401 
   402 !UISpecificationTool methodsFor:'selection'!
   403 
   404 selection:something
   405     "selection changed"
   406 
   407     |slices index spec window|
   408 
   409     specification notNil ifTrue:[
   410         slices := specification class slices.
   411         index  := slices findFirst:[:aSlice| aSlice first = something ].
   412 
   413         index ~~ 0 ifTrue:[
   414             spec := specification class perform:((slices at:index) last)
   415         ]
   416     ].
   417 
   418     spec ~= selection ifTrue:[
   419         (selection := spec) notNil ifTrue:[
   420             listOfSpecViews isNil ifTrue:[
   421                 listOfSpecViews := Array new:(slices size).
   422             ] ifFalse:[
   423                 window := listOfSpecViews at:index
   424             ].
   425             window isNil ifTrue:[
   426                 builder buildFromSpec:spec in:(window := SimpleView new).
   427                 listOfSpecViews at:index put:window.
   428             ].
   429         ].
   430         buildInView scrolledView:window.
   431     ].
   432 ! !
   433 
   434 !UISpecificationTool::BuildInView methodsFor:'accessing'!
   435 
   436 mapped
   437     super mapped.
   438 
   439     scrolledView notNil ifTrue:[
   440         scrolledView beVisible.
   441         scrolledView raise.
   442     ].
   443 !
   444 
   445 scrolledView:aView
   446     "set the view to be scrolled"
   447     |wrapper y|
   448 
   449     scrolledView == aView ifTrue:[^ self].
   450 
   451     scrolledView notNil ifTrue:[
   452         scrolledView unmap.
   453     ].
   454     (scrolledView := aView) notNil ifTrue:[
   455         scrolledView superView ~~ frame ifTrue:[
   456             frame addSubView:scrolledView.
   457         ].
   458         true ifTrue:[
   459             scrolledView borderWidth:0; level:0.
   460             scrolledView subViews size == 1 ifTrue:[
   461                 wrapper := scrolledView subViews first.
   462                 wrapper isScrollWrapper ifTrue:[
   463                     "/ give it a full-relative size, and let it do
   464                     "/ the scrolling itself.
   465                     y := 1.0
   466                 ]
   467             ].
   468             y isNil ifTrue:[
   469                 y := scrolledView preferredHeight
   470             ].
   471             scrolledView allViewBackground:(self viewBackground).
   472             scrolledView origin:0@0 corner:1.0 @ y.
   473         ].
   474     ].    
   475     shown ifTrue:[
   476         scrolledView beVisible.
   477         scrolledView raise.
   478         self sizeChanged:nil.
   479     ].
   480     model value:scrolledView.
   481 ! !
   482 
   483 !UISpecificationTool::BuildInView methodsFor:'initialization'!
   484 
   485 initialize
   486     super initialize.
   487     resizeScrolledViewHorizontal := true.
   488     resizeScrolledViewVertical   := true.
   489 !
   490 
   491 realize
   492 
   493     super realize.
   494    superView notNil ifTrue:[superView level:0].
   495 ! !
   496 
   497 !UISpecificationTool class methodsFor:'documentation'!
   498 
   499 version
   500     ^ '$Header$'
   501 !
   502 
   503 version_CVS
   504     ^ '$Header$'
   505 ! !
   506