UIGalleryView.st
author Claus Gittinger <cg@exept.de>
Wed, 29 Jul 2009 20:02:02 +0200
changeset 2570 4e663bc64364
parent 2563 c2298d24621d
child 3081 feb178704671
permissions -rw-r--r--
changed #requestPackage
ca@181
     1
"
ca@181
     2
 COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG
cg@1120
     3
	      All Rights Reserved
ca@181
     4
ca@181
     5
 This software is furnished under a license and may be used
ca@181
     6
 only in accordance with the terms of that license and with the
ca@181
     7
 inclusion of the above copyright notice.   This software may not
ca@181
     8
 be provided or otherwise made available to, or used by, any
ca@181
     9
 other person.  No title to or ownership of the software is
ca@181
    10
 hereby transferred.
ca@181
    11
"
cg@1399
    12
"{ Package: 'stx:libtool2' }"
cg@1399
    13
ca@181
    14
NoteBookView subclass:#UIGalleryView
ca@181
    15
	instanceVariableNames:'majorKey minorKeys minorKeysHolder'
ca@181
    16
	classVariableNames:''
ca@181
    17
	poolDictionaries:''
ca@181
    18
	category:'Interface-UIPainter'
ca@181
    19
!
ca@181
    20
cg@2563
    21
View subclass:#Palette
ca@1675
    22
	instanceVariableNames:'clientSpecHolder selection specification lastClickPoint
cg@2542
    23
		menuSelector uiBuilder hiddenCounter showBorders
cg@2542
    24
		didWarnAboutUnknownSpecs'
ca@181
    25
	classVariableNames:''
ca@181
    26
	poolDictionaries:''
ca@181
    27
	privateIn:UIGalleryView
ca@181
    28
!
ca@181
    29
ca@181
    30
DropObject subclass:#DropSpec
ca@181
    31
	instanceVariableNames:''
cg@247
    32
	classVariableNames:''
ca@181
    33
	poolDictionaries:''
cg@2563
    34
	privateIn:UIGalleryView::Palette
ca@181
    35
!
ca@181
    36
ca@181
    37
!UIGalleryView class methodsFor:'documentation'!
ca@181
    38
ca@181
    39
copyright
ca@181
    40
"
ca@181
    41
 COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG
cg@1120
    42
	      All Rights Reserved
ca@181
    43
ca@181
    44
 This software is furnished under a license and may be used
ca@181
    45
 only in accordance with the terms of that license and with the
ca@181
    46
 inclusion of the above copyright notice.   This software may not
ca@181
    47
 be provided or otherwise made available to, or used by, any
ca@181
    48
 other person.  No title to or ownership of the software is
ca@181
    49
 hereby transferred.
ca@181
    50
"
ca@181
    51
ca@181
    52
ca@181
    53
!
ca@181
    54
ca@181
    55
documentation
ca@181
    56
"
ca@181
    57
    implements a selection panel, keeping widgets which could be placed
ca@181
    58
    into other components by drag & drop or copy @ paste. The objects
ca@181
    59
    which are draged/droped must be kind of UISpecification's.
ca@181
    60
    The UISelectionPanel used by the UIPainter is implemented in this way.
ca@181
    61
ca@181
    62
    [author:]
cg@1120
    63
	Claus Gittinger
cg@1120
    64
	Claus Atzkern
ca@181
    65
ca@181
    66
    [see also:]
cg@1120
    67
	UIPainter
cg@1120
    68
	UISelectionPanel
ca@181
    69
"
ca@181
    70
ca@181
    71
!
ca@181
    72
ca@181
    73
examples
ca@181
    74
"
ca@181
    75
    opens a gallery
ca@181
    76
cg@1120
    77
									[exBegin]
ca@181
    78
    |top sel|
ca@181
    79
ca@181
    80
    top := StandardSystemView new label:'gallery'; extent:500@300.
ca@181
    81
    sel := UIGalleryView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
ca@181
    82
ca@181
    83
    sel labels:#(    'Buttons'
cg@1120
    84
		     'Panels'
cg@1120
    85
		     'Text'
cg@1120
    86
		   ).
ca@181
    87
ca@191
    88
    sel minorKeys:#( #standardButtonToggle
cg@1120
    89
		     #standardPanels
cg@1120
    90
		     #standardText
cg@1120
    91
		   ).
ca@181
    92
ca@181
    93
    sel majorKey:UISelectionPanel.
ca@181
    94
    top open.
cg@1120
    95
									[exEnd]
ca@181
    96
"
ca@181
    97
! !
ca@181
    98
ca@181
    99
!UIGalleryView methodsFor:'accessing'!
ca@181
   100
ca@181
   101
builder
ca@181
   102
    "get the builder used to setup a window from a specification (or nil in case
ca@181
   103
     of using a new builder)
ca@181
   104
    "
ca@181
   105
  ^ canvas builder
ca@181
   106
!
ca@181
   107
ca@181
   108
builder:aBuilderOrNil
ca@181
   109
    "set the builder used to setup a window from a specification (or nil in case
ca@181
   110
     of using a new builder)
ca@181
   111
    "
ca@181
   112
    canvas builder:aBuilderOrNil
ca@181
   113
!
ca@181
   114
ca@181
   115
canvas:aCanvas
ca@181
   116
    ^ self
ca@181
   117
ca@181
   118
!
ca@181
   119
ca@181
   120
labels:listOfLabels minorKeys:listOfMinorKeys majorKey:aMajorKey
ca@181
   121
    "setup for labels, selectors and class provider
ca@181
   122
    "
ca@181
   123
    self labels:listOfLabels.
ca@181
   124
    minorKeys := listOfMinorKeys.
ca@181
   125
    majorKey  := aMajorKey.
ca@181
   126
!
ca@181
   127
ca@181
   128
majorKey
ca@181
   129
    "get the class providing the window specifications
ca@181
   130
    "
ca@181
   131
  ^ majorKey
ca@181
   132
!
ca@181
   133
ca@181
   134
majorKey:aKey
ca@181
   135
    "get the class providing the window specifications
ca@181
   136
    "
ca@335
   137
    |appl|
ca@335
   138
ca@335
   139
    appl := self application.
ca@335
   140
ca@335
   141
    appl notNil ifTrue:[
cg@1120
   142
	majorKey := appl resolveName:aKey
ca@335
   143
    ] ifFalse:[
cg@1120
   144
	majorKey := Smalltalk resolveName:aKey inClass:self class
ca@335
   145
    ].
ca@181
   146
    self selection:nil
ca@181
   147
!
ca@181
   148
ca@181
   149
minorKeys
ca@181
   150
    "get the list of selector keys
ca@181
   151
    "
ca@181
   152
  ^ minorKeys
ca@181
   153
!
ca@181
   154
ca@181
   155
minorKeys:aListOfSelectors
ca@181
   156
    "set the list of selectors
ca@181
   157
    "
ca@181
   158
    minorKeys := aListOfSelectors.
cg@1140
   159
    self selection:nil.
ca@2200
   160
!
ca@2200
   161
ca@2200
   162
showBorders:aBoolean
ca@2200
   163
    "show borders around dragable objects"
ca@2200
   164
ca@2200
   165
    canvas showBorders:aBoolean.
ca@2200
   166
! !
ca@2200
   167
ca@2200
   168
!UIGalleryView methodsFor:'accessing-colors'!
ca@2200
   169
ca@2200
   170
viewBackground:aColor
ca@2200
   171
    canvas notNil ifTrue:[
ca@2200
   172
        canvas viewBackground:aColor.
ca@2200
   173
    ].
ca@2200
   174
    ^ super viewBackground:aColor
ca@181
   175
! !
ca@181
   176
cg@1399
   177
!UIGalleryView methodsFor:'accessing-holders'!
ca@181
   178
ca@181
   179
clientSpecHolder
ca@181
   180
    "get the holder which keeps the current selection or in case of
ca@181
   181
     no selection the specification under the cursor
ca@181
   182
    "
ca@181
   183
  ^ canvas clientSpecHolder
ca@181
   184
!
ca@181
   185
ca@181
   186
clientSpecHolder:aHolder
ca@181
   187
    "set the holder which keeps the current selection or in case of
ca@181
   188
     no selection the specification under the cursor
ca@181
   189
    "
ca@181
   190
    canvas clientSpecHolder:aHolder
ca@181
   191
!
ca@181
   192
ca@181
   193
menuSelector
ca@181
   194
    ^ canvas menuSelector
ca@181
   195
!
ca@181
   196
ca@181
   197
menuSelector:aSelector
ca@181
   198
    ^ canvas menuSelector:aSelector
ca@181
   199
!
ca@181
   200
ca@181
   201
minorKeysHolder
ca@181
   202
    "get the holder keeping the minor keys; the selectors to access
ca@181
   203
     specifications from a class associated with the majorKey.
ca@181
   204
    "
ca@181
   205
  ^ minorKeysHolder
ca@181
   206
!
ca@181
   207
ca@181
   208
minorKeysHolder:aValueHolder
ca@181
   209
    "set the holder keeping the minor keys; the selectors to access
ca@181
   210
     specifications from a class associated with the majorKey.
ca@181
   211
    "
ca@181
   212
    minorKeysHolder notNil ifTrue:[
cg@1120
   213
	minorKeysHolder removeDependent:self. 
ca@181
   214
    ].
ca@181
   215
ca@181
   216
    (minorKeysHolder := aValueHolder) notNil ifTrue:[
cg@1120
   217
	minorKeysHolder addDependent:self.
ca@181
   218
    ].
ca@181
   219
    self minorKeys:(minorKeysHolder value)
ca@181
   220
! !
ca@181
   221
ca@181
   222
!UIGalleryView methodsFor:'change & update'!
ca@181
   223
cg@1142
   224
selectionHasChanged
ca@181
   225
    "selection changed
ca@181
   226
    "
ca@181
   227
    |specification selector selection application|
ca@181
   228
cg@1140
   229
    selection := self listIndexOf:(self selection).
ca@181
   230
ca@683
   231
    minorKeysHolder notNil ifTrue:[
cg@1128
   232
        minorKeys := minorKeysHolder value.
ca@683
   233
    ].
ca@181
   234
    (selection notNil and:[minorKeys size >= selection]) ifTrue:[
cg@1128
   235
        selector := minorKeys at:selection.
ca@181
   236
cg@1128
   237
        (majorKey respondsTo:selector) ifTrue:[
cg@1128
   238
            specification := majorKey perform:selector
cg@1128
   239
        ] ifFalse:[
cg@1128
   240
            (application := self application) notNil ifTrue:[
ca@1576
   241
                MessageNotUnderstood handle:[:ex|
cg@1128
   242
                    (application class respondsTo:selector) ifTrue:[
cg@1128
   243
                        specification := application class perform:selector
cg@1128
   244
                    ]
cg@1128
   245
                ] do:[
cg@1128
   246
                    specification := application aspectFor:selector
cg@1128
   247
                ]
cg@1128
   248
            ]
cg@1128
   249
        ]
ca@181
   250
    ].
cg@2199
   251
"/    self withWaitCursorDo:[
sv@2242
   252
        [
sv@2242
   253
            canvas specification:specification.
sv@2242
   254
        ] on:NotFoundError do:[:ex|
sv@2242
   255
            Transcript showCR:ex description.
sv@2242
   256
            ex proceed.
sv@2242
   257
        ]
cg@2199
   258
"/    ]
ca@181
   259
!
ca@181
   260
ca@181
   261
update
cg@1142
   262
    self selectionHasChanged.
ca@181
   263
!
ca@181
   264
ca@181
   265
update:something with:aParameter from:changedObject
ca@181
   266
    "one of my models changed its value
ca@181
   267
    "
ca@181
   268
    changedObject == minorKeysHolder ifTrue:[
cg@1128
   269
        ^ self minorKeys:( minorKeysHolder value)
ca@181
   270
    ].
ca@181
   271
    super update:something with:aParameter from:changedObject.
ca@181
   272
ca@181
   273
! !
ca@181
   274
cg@1337
   275
!UIGalleryView methodsFor:'initialization & release'!
ca@181
   276
ca@181
   277
initialize
ca@181
   278
    "setup default attributes
ca@181
   279
    "
cg@2563
   280
    canvas := Palette in:self.
ca@181
   281
ca@181
   282
    super initialize.
ca@683
   283
cg@1142
   284
    self action:[:something| self selectionHasChanged ].
cg@1582
   285
!
cg@1582
   286
cg@1582
   287
release
cg@1582
   288
    minorKeysHolder notNil ifTrue:[
cg@1582
   289
        minorKeysHolder removeDependent:self. 
cg@1582
   290
        minorKeysHolder := nil.
cg@1582
   291
    ].
cg@1582
   292
    super release.
ca@181
   293
! !
ca@181
   294
cg@2563
   295
!UIGalleryView::Palette class methodsFor:'documentation'!
cg@2495
   296
cg@2495
   297
documentation
cg@2495
   298
"
cg@2563
   299
    I am the palette of a gallery. Most of what I do is to allow dragging of a widget out
cg@2495
   300
    of myself and to care for the drawing of the selection.
cg@2495
   301
    The arrangement into multiple pages is done by my container, which holds me
cg@2495
   302
    in a subcanvas.
cg@2495
   303
"
cg@2495
   304
! !
cg@2495
   305
cg@2563
   306
!UIGalleryView::Palette methodsFor:'accessing'!
ca@181
   307
ca@181
   308
builder
ca@181
   309
    "get the builder used to setup a window from a specification (or nil in case
ca@181
   310
     of using a new builder)
ca@181
   311
    "
ca@181
   312
  ^ uiBuilder
ca@181
   313
!
ca@181
   314
ca@181
   315
builder:something
ca@181
   316
    "set the builder used to setup a window from a specification (or nil in case
ca@181
   317
     of using a new builder)
ca@181
   318
    "
ca@181
   319
    uiBuilder := something.
ca@181
   320
!
ca@181
   321
ca@181
   322
clientSpecHolder
ca@181
   323
    "get the holder which keeps the current selection or in case of
ca@181
   324
     no selection the specification under the cursor
ca@181
   325
    "
ca@181
   326
    ^ clientSpecHolder
ca@181
   327
!
ca@181
   328
ca@181
   329
clientSpecHolder:aHolder
ca@181
   330
    "set the holder which keeps the current selection or in case of
ca@181
   331
     no selection the specification under the cursor
ca@181
   332
    "
ca@1674
   333
    |spec|
ca@1674
   334
ca@1674
   335
    spec := clientSpecHolder value.
ca@1674
   336
ca@1674
   337
    aHolder notNil ifTrue:[ clientSpecHolder := aHolder ]
ca@1674
   338
                  ifFalse:[ clientSpecHolder := nil asValue ].
ca@1674
   339
ca@1674
   340
    clientSpecHolder value:spec.
ca@181
   341
!
ca@181
   342
ca@181
   343
menuSelector
ca@181
   344
    "return the value of the instance variable 'menuSelector' (automatically generated)"
ca@181
   345
sv@1455
   346
    ^ menuSelector
sv@1455
   347
!
ca@181
   348
ca@181
   349
menuSelector:something
ca@181
   350
    "set the value of the instance variable 'menuSelector' (automatically generated)"
ca@181
   351
sv@1455
   352
    menuSelector := something.
sv@1455
   353
!
ca@181
   354
ca@2200
   355
showBorders:aBoolean
ca@2200
   356
    showBorders := aBoolean.
ca@2200
   357
!
ca@2200
   358
ca@181
   359
specification
ca@181
   360
    "get current specification
ca@181
   361
    "
ca@1674
   362
    ^ specification
ca@181
   363
!
ca@181
   364
ca@181
   365
specification:aSpecOrSpecArray
cg@2542
   366
    "set a new specification"
cg@2542
   367
cg@2542
   368
    |builder newSpec|
ca@181
   369
ca@181
   370
    self selection:nil.
ca@1674
   371
    self destroySubViews.
ca@1674
   372
cg@2542
   373
    specification := nil.
cg@2542
   374
    aSpecOrSpecArray isNil ifTrue:[^ self].
cg@2542
   375
cg@2542
   376
    "/ only warn once - otherwise, its annoying
cg@2542
   377
    Array missingClassInLiteralArrayErrorSignal handle:[:ex |
cg@2542
   378
        didWarnAboutUnknownSpecs == true ifFalse:[
cg@2542
   379
            Dialog warn:(ex description,'\\(Will not warn again - please check for unloaded classes/packages)' withCRs).
cg@2542
   380
        ].
cg@2542
   381
        didWarnAboutUnknownSpecs := true.
cg@2542
   382
        ex proceed.
cg@2542
   383
    ] do:[
cg@2542
   384
        newSpec := UISpecification from:aSpecOrSpecArray.
ca@1674
   385
    ].
cg@2542
   386
    newSpec isNil ifTrue:[^ self].
cg@2542
   387
    (newSpec respondsTo:#'buildViewFor:in:') ifFalse:[^ self].
cg@2542
   388
    specification := newSpec.
ca@1674
   389
ca@1674
   390
    (builder := uiBuilder) isNil ifTrue:[
ca@1674
   391
        builder := UIBuilder new isEditing:true.
ca@1674
   392
        builder showDefaults:true.
cg@2563
   393
        builder application:self application. "/ for resources like images
ca@1674
   394
    ].
ca@1674
   395
ca@1674
   396
    specification buildViewFor:builder in:self.
ca@181
   397
cg@2502
   398
    "/ components notEmptyOrNil ifTrue:[ self halt ].
ca@1671
   399
    subViews size ~~ 0 ifTrue:[
ca@2200
   400
        showBorders ifTrue:[
ca@2200
   401
            subViews do:[:v|
ca@2200
   402
                (self findSpecFor:v) notNil ifTrue:[
ca@2200
   403
                    v borderWidth:1
ca@2200
   404
                ].
ca@2200
   405
            ].
cg@1561
   406
        ].
ca@1674
   407
        realized ifTrue:[ self realizeAllSubViews ].
ca@1674
   408
    ].
ca@181
   409
! !
ca@181
   410
cg@2563
   411
!UIGalleryView::Palette methodsFor:'building'!
ca@181
   412
cg@2502
   413
recursiveBuildSpecFromSpecPrototype:aSpec
cg@2502
   414
    "build spec out of spec prototype"
cg@2495
   415
ca@181
   416
    |spec comp coll|
ca@181
   417
ca@181
   418
    (aSpec notNil and:[aSpec canUIDrag]) ifFalse:[
cg@2495
   419
        ^ nil
ca@181
   420
    ].
ca@181
   421
ca@181
   422
    spec := aSpec copy.
ca@181
   423
    (aSpec class supportsSubComponents and:[aSpec component notNil]) ifFalse:[
cg@2495
   424
        ^ spec
ca@181
   425
    ].
ca@181
   426
    comp := aSpec component.
ca@181
   427
    spec component:nil.
ca@181
   428
ca@181
   429
    comp canUIDrag ifFalse:[
cg@2495
   430
        ^ spec
ca@181
   431
    ].
ca@181
   432
    coll := OrderedCollection new.
ca@181
   433
cg@2502
   434
    comp do:[:anEntry|
cg@2502
   435
        |spc|
cg@2502
   436
cg@2502
   437
        (spc := self recursiveBuildSpecFromSpecPrototype:anEntry) notNil ifTrue:[
cg@2495
   438
            coll add:spc
cg@2495
   439
        ]
ca@181
   440
    ].
ca@181
   441
    coll isEmpty ifTrue:[
cg@2495
   442
        ^ spec
ca@181
   443
    ].
ca@181
   444
    comp := comp copy.
ca@181
   445
    comp collection:coll.
ca@181
   446
    spec component:comp.
cg@2495
   447
    ^ spec
ca@181
   448
! !
ca@181
   449
cg@2563
   450
!UIGalleryView::Palette methodsFor:'drag & drop'!
ca@181
   451
ca@1675
   452
startDragFrom:evView
cg@2495
   453
    "start drag at lastClickPoint"
cg@2495
   454
ca@2204
   455
    |spec dragObj offset clickPos dragAndDropManager|
ca@1671
   456
ca@1671
   457
    clickPos := lastClickPoint.
ca@1671
   458
    clickPos isNil ifTrue:[^ self].
ca@1671
   459
    lastClickPoint := nil.
ca@1671
   460
ca@1674
   461
    spec := clientSpecHolder value.
ca@1671
   462
    spec isNil ifTrue:[^ self].
ca@181
   463
cg@2495
   464
    self withSelectionHiddenDo:[
cg@2502
   465
        spec := self recursiveBuildSpecFromSpecPrototype:spec.
ca@1675
   466
        spec name:nil.
ca@1674
   467
ca@1675
   468
        dragObj := DropSpec for:selection specification:spec.
ca@1675
   469
        offset  := clickPos - selection origin.
ca@1675
   470
    ].
ca@181
   471
ca@2204
   472
    dragAndDropManager := DragAndDropManager new.
ca@2204
   473
    dragAndDropManager giveFocusToTargetWidget:false.
ca@2204
   474
cg@2495
   475
    dragAndDropManager 
cg@2495
   476
        startDrag:dragObj
cg@2495
   477
        from:self
cg@2495
   478
        offset:offset
cg@2495
   479
        atEnd:nil
cg@2495
   480
        display:nil.
ca@181
   481
! !
ca@181
   482
cg@2563
   483
!UIGalleryView::Palette methodsFor:'event handling'!
ca@181
   484
ca@1671
   485
processEvent:anEvent
cg@1895
   486
    "filter keyboard events.
cg@1895
   487
     Return true, if I have eaten the event"
cg@1895
   488
ca@1674
   489
    |evView p|
ca@181
   490
ca@1671
   491
    evView := anEvent view.
ca@1671
   492
    evView isNil ifTrue:[ ^ false ].
cg@2553
   493
    (evView ~~ self and:[ (evView isComponentOf:self) not ]) ifTrue:[ ^ false ].
ca@181
   494
ca@2201
   495
    (anEvent isButtonPressEvent or:[anEvent isButtonReleaseEvent])ifTrue:[
ca@2201
   496
        lastClickPoint := nil.
ca@2201
   497
    ].
ca@1674
   498
    anEvent isButtonEvent ifFalse:[
ca@1674
   499
        anEvent isInputEvent ifTrue:[^ true].
ca@2201
   500
ca@1675
   501
        anEvent isDamage ifTrue:[ self redrawSelection ].
ca@1671
   502
        ^ false
ca@1671
   503
    ].
ca@1671
   504
ca@2201
   505
    anEvent isButtonReleaseEvent ifTrue:[ ^ true ].
ca@1671
   506
ca@1674
   507
    anEvent isButtonMotionEvent ifTrue:[
ca@1674
   508
        (lastClickPoint notNil and:[anEvent state ~~ 0]) ifTrue:[
ca@1674
   509
            p := Point x:(anEvent x) y:(anEvent y).
ca@2201
   510
            p := device translatePoint:p fromView:evView toView:self.
ca@1671
   511
ca@2201
   512
            (lastClickPoint dist:p) > 20.0 ifTrue:[
ca@1675
   513
                self startDragFrom:evView.
ca@1675
   514
                lastClickPoint := nil.
ca@1671
   515
            ]
ca@1671
   516
        ].
ca@1671
   517
        ^ true
ca@1671
   518
    ].
ca@1671
   519
cg@2495
   520
    anEvent isButtonPressEvent ifTrue:[
cg@2495
   521
        |button application|
cg@2495
   522
ca@1674
   523
        button := anEvent button.
ca@1674
   524
ca@1674
   525
        (button == 1 or:[button == #select]) ifTrue:[
ca@1674
   526
            p := Point x:(anEvent x) y:(anEvent y).
ca@1674
   527
            p := device translatePoint:p fromView:evView toView:self.
ca@1674
   528
ca@1674
   529
            self selection:(self findObjectAt:p).
ca@1674
   530
ca@1674
   531
            selection notNil ifTrue:[
ca@2201
   532
                lastClickPoint := p.
ca@1674
   533
            ]
ca@1674
   534
        ] ifFalse:[
ca@1674
   535
            (menuSelector notNil and:[(application := self application) notNil]) ifTrue:[
ca@1674
   536
                MessageNotUnderstood catch:[
ca@1674
   537
                    application aspectFor:menuSelector
ca@1674
   538
                ]
ca@1671
   539
            ]
ca@1671
   540
        ].
ca@1671
   541
        ^ true
ca@1671
   542
    ].
ca@1671
   543
ca@1671
   544
    ^ true
ca@181
   545
! !
ca@181
   546
cg@2563
   547
!UIGalleryView::Palette methodsFor:'focus handling'!
ca@2201
   548
ca@2201
   549
subviewsInFocusOrder
ca@2201
   550
    "returns none views - focus not handled within buildin canvas"
ca@2201
   551
ca@2201
   552
    ^ #()
ca@2201
   553
! !
ca@2201
   554
cg@2563
   555
!UIGalleryView::Palette methodsFor:'initialization'!
ca@181
   556
ca@2200
   557
destroy
ca@2200
   558
    |winGrp|
ca@2200
   559
ca@2200
   560
    winGrp := self windowGroup.
ca@2200
   561
    winGrp notNil ifTrue:[
ca@2200
   562
        winGrp removePreEventHook:self.
ca@2200
   563
    ].
ca@2200
   564
    super destroy.
ca@2200
   565
!
ca@2200
   566
ca@181
   567
initialize
ca@181
   568
    super initialize.
ca@1674
   569
    clientSpecHolder := nil asValue.
ca@1675
   570
    hiddenCounter := 0.
ca@2200
   571
    showBorders := true.
cg@1128
   572
!
cg@1128
   573
ca@1671
   574
realize
ca@2200
   575
    |winGrp|
ca@2200
   576
ca@1671
   577
    super realize.
ca@2200
   578
    winGrp := self windowGroup.
ca@2200
   579
    winGrp notNil ifTrue:[
ca@2200
   580
        winGrp addPreEventHook:self.
ca@2200
   581
   ].
ca@1671
   582
! !
ca@1671
   583
cg@2563
   584
!UIGalleryView::Palette methodsFor:'searching'!
ca@181
   585
ca@1674
   586
findObjectAt:aPoint
cg@2495
   587
    |seeIfWidgetIsHit p x y|
ca@181
   588
cg@2495
   589
    seeIfWidgetIsHit := 
cg@2495
   590
        [:v |
cg@2495
   591
            p := device translatePoint:aPoint fromView:self toView:v.
cg@2495
   592
            x := p x.
cg@2495
   593
            y := p y.
ca@181
   594
cg@2495
   595
            (     x >= 0 and:[x <= v width
cg@2495
   596
             and:[y >= 0 and:[y <= v height
cg@2495
   597
             and:[(self findSpecFor:v) notNil]]]]
cg@2495
   598
            ) ifTrue:[
cg@2495
   599
                ^ v
cg@2495
   600
            ]
cg@2495
   601
        ].
cg@239
   602
cg@2495
   603
    subViews notNil ifTrue:[ subViews do:seeIfWidgetIsHit ].
cg@2495
   604
    components notNil ifTrue:[ components do:seeIfWidgetIsHit ].
ca@1671
   605
    ^ nil
ca@181
   606
!
ca@181
   607
cg@2495
   608
findSpecFor:aWidget
cg@2495
   609
    "returns the spec which is assigned to aWidget or nil"
cg@2495
   610
cg@239
   611
    |name|
ca@181
   612
cg@2495
   613
    aWidget notNil ifTrue:[
cg@2495
   614
        name := aWidget name.
ca@181
   615
cg@1127
   616
        specification do:[:aSpec|
ca@1674
   617
            (aSpec notNil and:[aSpec name = name]) ifTrue:[
cg@2502
   618
                aSpec canUIDrag ifFalse:[^ nil ].
cg@2502
   619
                ^ aSpec
cg@1127
   620
            ]
cg@1127
   621
        ]
ca@181
   622
    ].
ca@181
   623
    ^ nil
ca@181
   624
cg@1127
   625
    "Modified: / 18.5.1999 / 14:47:25 / cg"
ca@181
   626
! !
ca@181
   627
cg@2563
   628
!UIGalleryView::Palette methodsFor:'selection'!
ca@181
   629
ca@181
   630
handlesOf:aComponent do:aOneArgBlock
cg@2534
   631
    "evaluate the block on each handle; the argument to the block is a rectangle"
cg@2534
   632
cg@2534
   633
    |ext|
cg@2534
   634
cg@2561
   635
    ext := 8@8.
cg@2534
   636
ca@181
   637
    aComponent notNil ifTrue:[
cg@2561
   638
        aOneArgBlock value:(aComponent origin       - (3@3) extent:ext).
cg@2561
   639
        aOneArgBlock value:(aComponent corner       - (2@2) extent:ext).
cg@2561
   640
        aOneArgBlock value:(aComponent topRight     - (2@3) extent:ext).
cg@2561
   641
        aOneArgBlock value:(aComponent bottomLeft   - (3@2) extent:ext).
cg@2561
   642
        aOneArgBlock value:(aComponent leftCenter rounded   - (3@0) extent:ext).
cg@2561
   643
        aOneArgBlock value:(aComponent rightCenter rounded  - (2@0) extent:ext).
cg@2561
   644
        aOneArgBlock value:(aComponent topCenter rounded    - (0@3) extent:ext).
cg@2561
   645
        aOneArgBlock value:(aComponent bottomCenter rounded - (0@2) extent:ext).
ca@181
   646
    ]
ca@181
   647
!
ca@181
   648
ca@1675
   649
redrawSelection
cg@2495
   650
    "redraw all items selected"
cg@2495
   651
ca@1675
   652
    (shown and:[selection notNil and:[hiddenCounter == 0]]) ifTrue:[
ca@1675
   653
        self clippedByChildren:false.
ca@181
   654
ca@1675
   655
        self handlesOf:selection do:[:aRectangle|
cg@2534
   656
            self paint:Color black.
cg@2534
   657
            self fillRectangle:aRectangle.
cg@2534
   658
cg@2534
   659
            self paint:Color white.
cg@2561
   660
            self displayRectangle:(aRectangle insetBy:0).
ca@1675
   661
        ].
ca@1675
   662
        self clippedByChildren:true.
ca@1671
   663
    ].
ca@1671
   664
!
ca@1671
   665
ca@1674
   666
selection:aView
cg@2495
   667
    "selection changed"
cg@2495
   668
ca@1671
   669
    |spec|
ca@1671
   670
ca@1674
   671
    selection == aView ifTrue:[^ self].
ca@1671
   672
cg@2495
   673
    self withSelectionHiddenDo:[
ca@1675
   674
        spec := self findSpecFor:aView.
cg@2502
   675
cg@2495
   676
        selection := (spec isNil) ifTrue:[nil] ifFalse:[aView].
ca@1675
   677
        clientSpecHolder value:spec.
ca@1675
   678
    ].
ca@1675
   679
!
ca@1675
   680
cg@2495
   681
withSelectionHiddenDo:aOneArgBlock
cg@2502
   682
    [ 
cg@2502
   683
        |r forceExpose|
cg@2502
   684
        
cg@2495
   685
        hiddenCounter :=  hiddenCounter + 1.
ca@1675
   686
        hiddenCounter == 1 ifTrue:[
ca@1675
   687
            (shown and:[selection notNil]) ifTrue:[
ca@1675
   688
                self clippedByChildren:false.
ca@1675
   689
ca@1675
   690
                self handlesOf:selection do:[:aRectangle|
cg@2495
   691
                    self clearRectangle:aRectangle.
cg@2495
   692
                    self invalidateRectangle:aRectangle repairNow:false.
ca@1675
   693
                ].
ca@1675
   694
                self clippedByChildren:true.
ca@1675
   695
ca@1675
   696
                r := selection bounds.
cg@2502
   697
cg@2502
   698
                forceExpose := 
cg@2502
   699
                    [:sv|
cg@2495
   700
                        |absOrg absFrame|
ca@1675
   701
cg@2502
   702
                        (sv bounds intersects:r) ifTrue:[   
cg@2502
   703
                            sv isView ifTrue:[
cg@2502
   704
                                sv borderColor:(Color white).           "/ kludge to force a redraw
cg@2502
   705
                                sv borderColor:(Color black).
ca@1675
   706
cg@2502
   707
                                sv withAllSubViewsDo:[:v|
cg@2502
   708
                                    v realized ifTrue:[
cg@2502
   709
                                        v fill:v viewBackground.
cg@2502
   710
                                        v exposeX:0 y:0 width:v width height:v height.
cg@2502
   711
                                    ]
cg@2495
   712
                                ]
cg@2502
   713
                            ] ifFalse:[
cg@2502
   714
                                sv invalidate.
cg@2502
   715
                            ].
ca@1675
   716
                        ]
cg@2502
   717
                    ].
cg@2502
   718
cg@2502
   719
                (subViews ? #()) do:forceExpose.
cg@2502
   720
                (components ? #()) do:forceExpose.
ca@1675
   721
            ].
ca@1675
   722
        ].
cg@2502
   723
        self repairDamage.  "/ ensure that any outstanding clear/redraw of the unselect are done before
ca@1675
   724
        aOneArgBlock value.
ca@1675
   725
    ] ensure:[
cg@2495
   726
        self repairDamage.  "/ ensure that any outstanding clear/redraw of the unselect are done before
cg@2495
   727
ca@1675
   728
        hiddenCounter := hiddenCounter - 1.
ca@1675
   729
        self redrawSelection.
ca@1675
   730
    ].
ca@181
   731
! !
ca@181
   732
cg@2563
   733
!UIGalleryView::Palette::DropSpec class methodsFor:'instance creation'!
ca@181
   734
cg@2495
   735
for:aWidget specification:aSpec
cg@2495
   736
    "create drop object for a widget derived from a specification"
ca@181
   737
cg@2495
   738
    |point extent rootView device inst displayObject view|
cg@2495
   739
cg@2495
   740
    device   := aWidget device.
cg@1501
   741
    rootView := device rootView.
cg@2495
   742
    extent   := aWidget extent.
cg@2495
   743
    aWidget isView ifTrue:[
cg@2495
   744
        view := aWidget.
cg@2495
   745
        point := device translatePoint:0@0 fromView:aWidget toView:rootView.
cg@2495
   746
    ] ifFalse:[
cg@2495
   747
        view := aWidget container.
cg@2495
   748
        point := device translatePoint:(aWidget origin) fromView:view toView:rootView.
cg@2495
   749
    ].
ca@181
   750
    (point x > 0 and:[point y > 0]) ifTrue:[
cg@1501
   751
        point := point + extent.
cg@1501
   752
        (point x < rootView width and:[point y < rootView height]) ifTrue:[
cg@2495
   753
            aWidget topView raise.
cg@1568
   754
            device flush.
cg@2495
   755
            aWidget invalidate.
cg@2495
   756
            aWidget windowGroup processExposeEvents.
cg@2495
   757
            displayObject := Image fromView:aWidget grab:false.
cg@1501
   758
        ]
ca@181
   759
    ].
ca@806
   760
    displayObject isNil ifTrue:[
cg@1501
   761
        displayObject := Form extent:extent depth:1.
cg@1501
   762
        displayObject colorMap:(Array with:Color white with:Color black).
cg@1501
   763
        displayObject fill:(Color colorId:0).
cg@1501
   764
        displayObject paint:(Color colorId:1).
cg@2495
   765
        displayObject displayRectangleX:0 y:0 width:aWidget extent x height:aWidget extent y.
ca@181
   766
    ].
ca@181
   767
    aSpec class == UISubSpecification ifTrue:[
cg@1501
   768
        aSpec layout:(LayoutOrigin fromPoint:0@0)
ca@181
   769
    ].
cg@240
   770
ca@806
   771
    inst := self new.
ca@806
   772
    inst displayObject:displayObject.
ca@806
   773
    inst theObject:aSpec.
cg@2495
   774
    ^ inst.
cg@1501
   775
cg@1501
   776
    "Modified: / 10.10.2001 / 14:03:00 / cg"
ca@181
   777
! !
ca@181
   778
ca@181
   779
!UIGalleryView class methodsFor:'documentation'!
ca@181
   780
ca@181
   781
version
ca@181
   782
    ^ '$Header$'
ca@181
   783
! !