#FEATURE by exept draft
authorClaus Gittinger <cg@exept.de>
Sun, 20 Oct 2019 13:15:20 +0200
changeset 3796 4ed3796c2d60
parent 3795 0b36f57fd1c9
child 3797 5ab4b911e388
#FEATURE by exept class: ShowMeHowItWorks added: #where:inComponent: comment/format in: #movePointerToComponent:speed: changed: #drag:toComponent:dropAt:show: #findComponent:in: #screenBoundsOfComponent: class: ShowMeHowItWorks::ItemInView class definition added: #boundsInView #isMenuItem #isNoteBookTab #item #layout #view #view:item:boundsInView: class: ShowMeHowItWorks::ItemInView class added: #documentation
ShowMeHowItWorks.st
--- a/ShowMeHowItWorks.st	Sun Oct 20 12:01:05 2019 +0200
+++ b/ShowMeHowItWorks.st	Sun Oct 20 13:15:20 2019 +0200
@@ -14,6 +14,13 @@
 	category:'Interface-Help'
 !
 
+Object subclass:#ItemInView
+	instanceVariableNames:'view item boundsInView'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:ShowMeHowItWorks
+!
+
 !ShowMeHowItWorks class methodsFor:'documentation'!
 
 documentation
@@ -548,27 +555,7 @@
         sourceComponent := sourceComponent scrolledView.
     ].
 
-    where == #topLeft ifTrue:[
-        targetPos := targetComponent topLeft + (1@1). 
-    ] ifFalse:[
-        where == #topCenter ifTrue:[
-            targetPos := targetComponent topCenter + (0@5). 
-        ] ifFalse:[
-            where == #center ifTrue:[
-                targetPos := targetComponent center
-            ] ifFalse:[
-                where == #bottomCenter ifTrue:[
-                    targetPos := targetComponent bottomCenter - (0 @ 5)
-                ] ifFalse:[
-                    where == #bottomLeft ifTrue:[
-                        targetPos := targetComponent bottomLeft + (1 @ -5)
-                    ] ifFalse:[
-                        self error:'where is this'
-                    ].
-                ].
-            ].
-        ].
-    ].
+    targetPos := self where:where inComponent:targetComponent. 
 
     (sourceComponent isKindOf:HierarchicalListView) ifTrue:[
 
@@ -584,16 +571,20 @@
                 self error:'no such item in hierarchicalList: ',itemsIndexOrLabelOrPattern
             ].
         ].
+
         yPos := sourceComponent yVisibleOfLine:idx.
         self movePointerToComponent:sourceComponent rightOffset:(10 @ (yPos + 3)).
         Delay waitForSeconds:0.5.
         sourcePosOnScreen := Display pointerPosition.
-        sourcePos := Display translatePoint:sourcePosOnScreen from:nil to:sourceComponent.
+        sourcePos := Display translatePoint:sourcePosOnScreen fromView:nil toView:sourceComponent.
+
+        targetPosOnScreen := Display translatePoint:targetPos fromView:targetComponent toView:nil.
+        targetPosInSource := Display translatePoint:targetPosOnScreen fromView:nil toView:sourceComponent.
 
-        targetPosOnScreen := Display translatePoint:targetPos from:targetComponent to:nil.
-        targetPosInSource := Display translatePoint:targetPosOnScreen from:nil to:sourceComponent.
+        sourceComponent simulateButtonPress:1 at:sourcePos sendDisplayEvent:false.
+        sourceComponent simulateButtonPress:1 at:sourcePos sendDisplayEvent:true.
+        Delay waitForSeconds:0.2.
 
-        sourceComponent simulateButtonPress:1 at:sourcePos sendDisplayEvent:true.
         dNdMgr := sourceComponent startDragAt:sourcePos.
 
         textWhenDroppingOrNil notNil ifTrue:[
@@ -605,8 +596,8 @@
         Delay waitForSeconds:1.
         dNdMgr buttonMotion:1 x:targetPos x y:targetPos y view:targetComponent.
 
-        sourceComponent simulateButtonRelease:1 at:targetPos sendDisplayEvent:true.
         dNdMgr buttonRelease:1 x:targetPos x y:targetPos y view:targetComponent.
+        sourceComponent simulateButtonRelease:1 at:targetPos sendDisplayEvent:false.
         ^ self
     ].
 
@@ -1186,7 +1177,15 @@
         ].
         idx := Integer readFrom:(componentNameOrPath withoutPrefix:'item[') readStream.
         item := anApplicationOrViewOrMenuItem itemAt:idx.
-        ^ item
+        ^ ItemInView new view:anApplicationOrViewOrMenuItem item:item boundsInView:(item layout)
+    ].
+    (componentNameOrPath matchesRegex:'tab\[[0-9]+\]') ifTrue:[
+        (anApplicationOrViewOrMenuItem isKindOf:NoteBookView) ifFalse:[
+            self assert:false message:'container is not a notebook'.
+        ].
+        idx := Integer readFrom:(componentNameOrPath withoutPrefix:'tab[') readStream.
+        item := anApplicationOrViewOrMenuItem tabAtIndex:idx.
+        ^ ItemInView new view:anApplicationOrViewOrMenuItem item:item boundsInView:(item layout)
     ].
 
     componentNameSymbol := componentNameOrPath asSymbolIfInterned ? componentNameOrPath.
@@ -1199,7 +1198,7 @@
         (component := app componentAt:componentNameSymbol) notNil ifTrue:[^ component].
         window := window ? app window.
     ] ifFalse:[
-        app isMenuItem ifTrue:[
+        (app askFor:#isMenuItem) ifTrue:[
             window := app submenu.
         ]
     ].
@@ -1370,23 +1369,37 @@
     "Modified (comment): / 23-07-2019 / 09:32:44 / Claus Gittinger"
 !
 
-screenBoundsOfComponent:aWidgetOrMenuItem
-    aWidgetOrMenuItem isView ifTrue:[
-        ^ aWidgetOrMenuItem screenBounds
+screenBoundsOfComponent:aWidgetOrMenuItemOrTab
+    |itemLayout|
+
+    aWidgetOrMenuItemOrTab isView ifTrue:[
+        ^ aWidgetOrMenuItemOrTab screenBounds
     ].
-    (aWidgetOrMenuItem askFor:#isMenuItem) ifTrue:[
+    (aWidgetOrMenuItemOrTab askFor:#isMenuItem) ifTrue:[
         |menuPanel menuBounds|
 
-        aWidgetOrMenuItem isVisible ifTrue:[
-            aWidgetOrMenuItem layout notNil ifTrue:[
-                menuPanel := aWidgetOrMenuItem menuPanel.
+        aWidgetOrMenuItemOrTab isVisible ifTrue:[
+            (itemLayout := aWidgetOrMenuItemOrTab layout) notNil ifTrue:[
+                menuPanel := aWidgetOrMenuItemOrTab menuPanel.
                 menuPanel shown ifTrue:[
                     menuBounds := menuPanel screenBounds.
-                    ^ aWidgetOrMenuItem layout + menuBounds origin 
+                    ^ itemLayout + menuBounds origin 
                 ].
             ].
         ].
     ].
+    (aWidgetOrMenuItemOrTab askFor:#isNoteBookTab) ifTrue:[
+        (itemLayout := aWidgetOrMenuItemOrTab layout) notNil ifTrue:[
+            |notebook notebookBounds|
+
+            notebook := aWidgetOrMenuItemOrTab view.
+            notebook shown ifTrue:[
+                notebookBounds := notebook screenBounds.
+                ^ itemLayout + notebookBounds origin 
+            ].
+        ]. 
+        self halt.
+    ].
     ^ nil.
 ! !
 
@@ -1571,14 +1584,14 @@
     "Modified: / 23-07-2019 / 09:36:57 / Claus Gittinger"
 !
 
-movePointerToComponent:aWidgetOrMenuItem speed:pixelsPerSecond
+movePointerToComponent:aWidgetOrMenuItemOrTab speed:pixelsPerSecond
     "move the mouse to aWidget's center"
 
     |bounds position|
     
-    bounds := self screenBoundsOfComponent:aWidgetOrMenuItem.
+    bounds := self screenBoundsOfComponent:aWidgetOrMenuItemOrTab.
     bounds isNil ifTrue:[
-        self error:'no bounds found for: ',aWidgetOrMenuItem printString.
+        self error:'no bounds found for: ',aWidgetOrMenuItemOrTab printString.
     ].
     position := bounds center rounded.
     self movePointerToScreenPosition:position speed:pixelsPerSecond.
@@ -1627,6 +1640,37 @@
     ].
 
     "Created: / 23-07-2019 / 09:36:45 / Claus Gittinger"
+!
+
+where:where inComponent:aComponent
+    where == #center ifTrue:[
+        ^ aComponent center
+    ].
+    where == #leftCenter ifTrue:[
+        ^ aComponent leftCenter + (5@0). 
+    ].
+    where == #rightCenter ifTrue:[
+        ^ aComponent rightCenter - (5@0). 
+    ].
+    where == #topLeft ifTrue:[
+        ^ aComponent topLeft + (5@5). 
+    ].
+    where == #topCenter ifTrue:[
+        ^ aComponent topCenter + (0@5). 
+    ].
+    where == #topRight ifTrue:[
+        ^ aComponent topRight - (5@5). 
+    ].
+    where == #bottomCenter ifTrue:[
+        ^ aComponent bottomCenter - (0 @ 5)
+    ].
+    where == #bottomLeft ifTrue:[
+        ^ aComponent bottomLeft + (5 @ -5)
+    ].
+    where == #bottomRight ifTrue:[
+        ^ aComponent bottomLeft - (5 @ 5)
+    ].
+    self error:'where is this'
 ! !
 
 !ShowMeHowItWorks methodsFor:'running'!
@@ -1986,6 +2030,76 @@
     "Created: / 23-07-2019 / 11:48:17 / Claus Gittinger"
 ! !
 
+!ShowMeHowItWorks::ItemInView class methodsFor:'documentation'!
+
+documentation
+"
+    documentation to be added.
+
+    class:
+        <a short class summary here, describing what instances represent>
+
+    responsibilities:    
+        <describing what my main role is>
+
+    collaborators:    
+        <describing with whom and how I talk to>
+
+    API:
+        <public api and main messages>
+        
+    example:
+        <a one-line examples on how to use - can also be in a separate example method>
+
+    implementation:
+        <implementation points>
+
+    [author:]
+        exept MBP
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+! !
+
+!ShowMeHowItWorks::ItemInView methodsFor:'accessing'!
+
+boundsInView
+    ^ boundsInView
+!
+
+item
+    ^ item
+!
+
+layout
+    ^ item layout
+!
+
+view
+    ^ view
+!
+
+view:viewArg item:itemArg boundsInView:boundsInViewArg 
+    view := viewArg.
+    item := itemArg.
+    boundsInView := boundsInViewArg.
+! !
+
+!ShowMeHowItWorks::ItemInView methodsFor:'testing'!
+
+isMenuItem
+    ^ item askFor:#isMenuItem
+!
+
+isNoteBookTab
+    ^ item isKindOf:NoteBookView::Tab
+! !
+
 !ShowMeHowItWorks class methodsFor:'documentation'!
 
 version_CVS