UIPainterView.st
changeset 89 35c5711729c2
parent 86 06bdbae8bd8e
child 96 73725336b4fe
equal deleted inserted replaced
88:d6dccf1ad344 89:35c5711729c2
   181 !
   181 !
   182 
   182 
   183 pasteBuffer
   183 pasteBuffer
   184     "add the objects in the paste-buffer to the object view
   184     "add the objects in the paste-buffer to the object view
   185     "
   185     "
       
   186     self pasteSpecifications:(self getSelection) keepLayout:false
       
   187 
       
   188 !
       
   189 
       
   190 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
       
   191     "add the specs to the object view
       
   192     "
   186     |paste frame pasteOrigin pasteOffset builder|
   193     |paste frame pasteOrigin pasteOffset builder|
   187 
   194 
   188     paste := self getSelection.
   195     (self canPaste:aSpecificationOrList) ifFalse:[
   189 
   196         ^ self
   190     (self canPaste:paste) ifFalse:[ ^ self].
   197     ].
   191     (paste isCollection)  ifFalse:[ paste := Array with:paste].
   198     aSpecificationOrList isCollection ifTrue:[
   192 
   199         paste := aSpecificationOrList
       
   200     ] ifFalse:[
       
   201         paste := Array with:aSpecificationOrList
       
   202     ].
   193     frame := self singleSelection.
   203     frame := self singleSelection.
   194 
   204 
   195     (self canPasteInto:frame) ifFalse:[
   205     (self canPasteInto:frame) ifFalse:[
   196         frame := self
   206         frame := self
   197     ].
   207     ].
   198     self unselect.
   208     self unselect.
   199 
   209 
   200     selection   := OrderedCollection new.
   210     selection := OrderedCollection new.
   201     pasteOffset := 0@0.
   211     builder   := UIBuilder new.
   202     pasteOrigin := self sensor mousePoint.
   212 
   203     pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
   213     keepLayout ifFalse:[
   204     builder     := UIBuilder new.
   214         pasteOffset := 0@0.
       
   215         pasteOrigin := self sensor mousePoint.
       
   216         pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
       
   217     ].
   205 
   218 
   206     paste do:[:aSpec|
   219     paste do:[:aSpec|
   207         |view|
   220         |view|
   208 
   221 
   209         view := self addSpec:aSpec builder:builder in:frame.
   222         view := self addSpec:aSpec builder:builder in:frame.
   210 
   223 
   211         (frame bounds containsPoint:pasteOrigin) ifFalse:[
   224         keepLayout ifFalse:[
   212             self moveObject:view to:pasteOffset.
   225             (frame bounds containsPoint:pasteOrigin) ifFalse:[
   213         ] ifTrue:[
   226                 self moveObject:view to:pasteOffset.
   214             self moveObject:view to:pasteOrigin + pasteOffset.
   227             ] ifTrue:[
       
   228                 self moveObject:view to:pasteOrigin + pasteOffset.
       
   229             ].
       
   230             pasteOffset := pasteOffset + 4
   215         ].
   231         ].
   216 
       
   217         view realize.
   232         view realize.
   218         selection add:view.
   233         selection add:view.
   219         pasteOffset := pasteOffset + 4.
       
   220     ].
   234     ].
   221 
   235 
   222     self transaction:#paste selectionDo:[:v|
   236     self transaction:#paste selectionDo:[:v|
   223         self undoCreate:((self propertyOfView:v) identifier)
   237         self undoCreate:((self propertyOfView:v) identifier)
   224     ].
   238     ].
   229     self realizeAllSubViews.
   243     self realizeAllSubViews.
   230     inputView raise.
   244     inputView raise.
   231     self elementChangedSize:frame.
   245     self elementChangedSize:frame.
   232     self changed:#tree
   246     self changed:#tree
   233 
   247 
       
   248 !
       
   249 
       
   250 pasteWithLayout
       
   251     "add the objects in the paste-buffer to the object view; don't change the
       
   252      layout
       
   253     "
       
   254     self pasteSpecifications:(self getSelection) keepLayout:true
       
   255 
   234 ! !
   256 ! !
   235 
   257 
   236 !UIPainterView methodsFor:'drag & drop'!
   258 !UIPainterView methodsFor:'drag & drop'!
   237 
   259 
   238 canDrop:anObjectOrCollection
   260 canDrop:anObjectOrCollection
   239     Transcript showCR:'canDrop'.
   261     |spec|
   240     ^ true
   262 
   241 
   263     testMode ifFalse:[
   242 
   264         anObjectOrCollection size == 1 ifTrue:[
       
   265             spec := (anObjectOrCollection at:1) theObject.
       
   266           ^ (spec isKindOf:UISpecification)
       
   267         ]
       
   268     ].
       
   269     ^ false
   243 !
   270 !
   244 
   271 
   245 drop:anObjectOrCollection at:aPoint
   272 drop:anObjectOrCollection at:aPoint
   246     Transcript showCR:'drop:anObjectOrCollection at:aPoint'.
   273     |spec|
       
   274 
       
   275     spec := (anObjectOrCollection at:1) theObject.
       
   276     self pasteSpecifications:spec keepLayout:false.
   247 
   277 
   248 
   278 
   249 ! !
   279 ! !
   250 
   280 
   251 !UIPainterView methodsFor:'generating output'!
   281 !UIPainterView methodsFor:'generating output'!
   281 
   311 
   282     className isNil ifTrue:[
   312     className isNil ifTrue:[
   283         self warn:'set the class first'.
   313         self warn:'set the class first'.
   284         ^ code
   314         ^ code
   285     ].
   315     ].
       
   316     cls := Smalltalk classNamed:className.
   286 
   317 
   287     viewProperties do:[:aProp |
   318     viewProperties do:[:aProp |
   288         |modelSelector menuSelector protoSpec thisCode|
   319         |modelSelector menuSelector protoSpec thisCode|
   289 
   320 
   290         (modelSelector := aProp model) notNil ifTrue:[
   321         (modelSelector := aProp model) notNil ifTrue:[
   309             ]
   340             ]
   310         ]
   341         ]
   311     ].
   342     ].
   312     ^ code
   343     ^ code
   313 
   344 
   314 ! !
   345 !
   315 
       
   316 !UIPainterView ignoredMethodsFor:'generating output'!
       
   317 
   346 
   318 generateClassDefinition
   347 generateClassDefinition
   319     |defCode|
   348     |defCode|
   320 
   349 
   321     defCode := superclassName , ' subclass:#' , className , '\'.
   350     defCode := superclassName , ' subclass:#' , className , '\'.
   328 
   357 
   329     ^ defCode withCRs
   358     ^ defCode withCRs
   330 
   359 
   331 
   360 
   332 
   361 
   333 ! !
   362 !
   334 
       
   335 !UIPainterView methodsFor:'generating output'!
       
   336 
   363 
   337 generateCode
   364 generateCode
   338     "generate code for the windowSpec method"
   365     "generate code for the windowSpec method"
   339 
   366 
   340     |code|
   367     |code|
   351 "/    code := code , self generateAspectMethods.
   378 "/    code := code , self generateAspectMethods.
   352 
   379 
   353     ^ code withCRs
   380     ^ code withCRs
   354 
   381 
   355     "Modified: 5.9.1995 / 20:57:53 / claus"
   382     "Modified: 5.9.1995 / 20:57:53 / claus"
   356 ! !
   383 !
   357 
       
   358 !UIPainterView ignoredMethodsFor:'generating output'!
       
   359 
   384 
   360 generateInitCodeForGroup:aGroup
   385 generateInitCodeForGroup:aGroup
   361     |code c name p objects outlets moreCode sym typ val|
   386     |code c name p objects outlets moreCode sym typ val|
   362 
   387 
   363     " <name> := <GroupClass> in:<name-of-superview>"
   388     " <name> := <GroupClass> in:<name-of-superview>"
   511 
   536 
   512 !
   537 !
   513 
   538 
   514 generateOutlets
   539 generateOutlets
   515     ^ self
   540     ^ self
   516 ! !
   541 !
   517 
       
   518 !UIPainterView methodsFor:'generating output'!
       
   519 
   542 
   520 generateWindowSpecMethodSource
   543 generateWindowSpecMethodSource
   521     |t s spec specArray str code|
   544     |t s spec specArray str code|
   522 
   545 
   523     specArray := OrderedCollection new.
   546     specArray := OrderedCollection new.
   562             , '\\'.
   585             , '\\'.
   563 
   586 
   564     ^ code withCRs
   587     ^ code withCRs
   565 
   588 
   566     "Modified: 5.9.1995 / 21:01:35 / claus"
   589     "Modified: 5.9.1995 / 21:01:35 / claus"
   567 ! !
   590 !
   568 
       
   569 !UIPainterView ignoredMethodsFor:'generating output'!
       
   570 
   591 
   571 nameOfClass
   592 nameOfClass
   572     ^ 'NewView'
   593     ^ 'NewView'
   573 ! !
   594 !
   574 
       
   575 !UIPainterView methodsFor:'generating output'!
       
   576 
   595 
   577 outletValueOf:aSymbol for:aView
   596 outletValueOf:aSymbol for:aView
   578 "/    |c name p outlets moreCode sym typ val|
   597 "/    |c name p outlets moreCode sym typ val|
   579 "/
   598 "/
   580 "/    p := self propertyOfView:aView.
   599 "/    p := self propertyOfView:aView.
   748 
   767 
   749     selection isNil ifTrue:[
   768     selection isNil ifTrue:[
   750         undoIdx := 2.
   769         undoIdx := 2.
   751 
   770 
   752         menu := PopUpMenu labels:( resources array:#('paste' 'undo') )
   771         menu := PopUpMenu labels:( resources array:#('paste' 'undo') )
   753                        selectors:#( #pasteBuffer #undoLast )
   772                        selectors:#( #paste #undoLast )
   754                     accelerators:#( #Paste       nil )
   773                         receiver:self
   755                         receiver:self.
       
   756 
       
   757         canPaste ifFalse:[menu disable:#pasteBuffer].
       
   758     ] ifFalse:[    
   774     ] ifFalse:[    
   759         undoIdx := 4.
   775         undoIdx := 4.
   760 
   776 
   761         menu := PopUpMenu labels:( resources array:#(
   777         menu := PopUpMenu labels:( resources array:#(
   762                                       'copy' 
   778                                       'copy' 
   769                                       'align'
   785                                       'align'
   770                                     )
   786                                     )
   771                                   )
   787                                   )
   772                        selectors:#(   #copySelection
   788                        selectors:#(   #copySelection
   773                                       #deleteSelection
   789                                       #deleteSelection
   774                                       #pasteBuffer
   790                                       #paste
   775                                       #undoLast
   791                                       #undoLast
   776                                       nil
   792                                       nil
   777                                       #arrange
   793                                       #arrange
   778                                       #dimension
   794                                       #dimension
   779                                       #align
   795                                       #align
   780                                   )
   796                                   )
   781                        accelerators:#(#Copy
   797                        accelerators:#(#Copy
   782                                       #Cut
   798                                       #Cut
   783                                       #Paste
   799                                       nil
   784                                       nil
   800                                       nil
   785                                       nil
   801                                       nil
   786                                       nil
   802                                       nil
   787                                       nil
   803                                       nil
   788                                       nil
   804                                       nil
   789                                   )
   805                                   )
   790                          receiver:self.
   806                          receiver:self.
   791 
   807 
   792         (canPaste and:[self canPasteInto:selection]) ifFalse:[
   808         canPaste := (canPaste and:[self canPasteInto:selection]).
   793             menu disable:#pasteBuffer
       
   794         ].
       
   795         menu subMenuAt:#arrange   put:(self subMenuArrange).
   809         menu subMenuAt:#arrange   put:(self subMenuArrange).
   796         menu subMenuAt:#dimension put:(self subMenuDimension).
   810         menu subMenuAt:#dimension put:(self subMenuDimension).
   797         menu subMenuAt:#align     put:(self subMenuAlign).
   811         menu subMenuAt:#align     put:(self subMenuAlign).
   798     ].
   812     ].
       
   813 
       
   814     menu subMenuAt:#paste put:(self subMenuPaste).
       
   815     canPaste ifFalse:[menu disable:#paste].
   799 
   816 
   800     undoText notNil ifTrue:[
   817     undoText notNil ifTrue:[
   801         menu labelAt:undoIdx put:((menu labels at:undoIdx), ':  ', undoText)
   818         menu labelAt:undoIdx put:((menu labels at:undoIdx), ':  ', undoText)
   802     ] ifFalse:[
   819     ] ifFalse:[
   803         menu disable:#undoLast
   820         menu disable:#undoLast
   901                                     'copy extent'
   918                                     'copy extent'
   902                                     '-'
   919                                     '-'
   903                                     'paste extent'
   920                                     'paste extent'
   904                                     'paste width'
   921                                     'paste width'
   905                                     'paste height'
   922                                     'paste height'
       
   923                                     '-'
       
   924                                     'copy  layout'
       
   925                                     'paste layout'
   906                                  )
   926                                  )
   907                               )
   927                               )
   908                    selectors:#(
   928                    selectors:#(
   909                                     setToDefaultExtent
   929                                     setToDefaultExtent
   910                                     setToDefaultWidth
   930                                     setToDefaultWidth
   913                                     copyExtent
   933                                     copyExtent
   914                                     nil
   934                                     nil
   915                                     pasteExtent
   935                                     pasteExtent
   916                                     pasteWidth
   936                                     pasteWidth
   917                                     pasteHeight
   937                                     pasteHeight
       
   938                                     nil
       
   939                                     copyLayout
       
   940                                     pasteLayout
   918                               )
   941                               )
   919                      receiver:self.
   942                      receiver:self.
   920   ^ menu
   943   ^ menu
   921 !
   944 !
   922 
   945 
   949                                     nil
   972                                     nil
   950                                     showFontPanel
   973                                     showFontPanel
   951                               )
   974                               )
   952                      receiver:self.
   975                      receiver:self.
   953   ^ menu
   976   ^ menu
       
   977 !
       
   978 
       
   979 subMenuPaste
       
   980     "returns submenu Paste
       
   981     "
       
   982     |menu|
       
   983 
       
   984     menu := PopUpMenu labels:( resources array:#('paste' 'keep layout') )
       
   985                    selectors:#( #pasteBuffer #pasteWithLayout )
       
   986                 accelerators:#( #Paste       nil )
       
   987                     receiver:self.
       
   988 
       
   989   ^ menu    
       
   990 
   954 ! !
   991 ! !
   955 
   992 
   956 !UIPainterView methodsFor:'misc'!
   993 !UIPainterView methodsFor:'misc'!
   957 
   994 
   958 changeFontFamily:family face:face style:style size:size
   995 changeFontFamily:family face:face style:style size:size
  1012     undoHistory reinitialize.
  1049     undoHistory reinitialize.
  1013     self changed:#tree
  1050     self changed:#tree
  1014 ! !
  1051 ! !
  1015 
  1052 
  1016 !UIPainterView methodsFor:'searching'!
  1053 !UIPainterView methodsFor:'searching'!
       
  1054 
       
  1055 findContainerViewAt:aPoint
       
  1056     "find container view responds to aPoint.
       
  1057     "
       
  1058     |view|
       
  1059 
       
  1060     (view := self findObjectAt:aPoint) isNil ifTrue:[
       
  1061         ^ self
       
  1062     ].
       
  1063 
       
  1064     [(view specClass supportsSubComponents or:[(view := view superView) == self])
       
  1065     ] whileFalse:[
       
  1066         [(self propertyOfView:view) isNil] whileTrue:[
       
  1067             (view := view superView) == self ifTrue:[^ self]
       
  1068         ].
       
  1069     ].
       
  1070     ^ view
       
  1071 !
  1017 
  1072 
  1018 findObjectAt:aPoint
  1073 findObjectAt:aPoint
  1019     "find the origin/corner of the currentWidget
  1074     "find the origin/corner of the currentWidget
  1020     "
  1075     "
  1021     |view|
  1076     |view|