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