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

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