#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Sat, 10 Nov 2018 00:34:47 +0100
changeset 8584 25494bb91c16
parent 8583 c06d2b2b5457
child 8585 f98df434dee2
#REFACTORING by cg class: SimpleView added: #flushCachedPreferredExtent #keyboardZoomReset #keyboardZoomkeyboardZoomReset changed: #computePreferredExtent #keyPress:x:y: #preferredExtent
SimpleView.st
--- a/SimpleView.st	Fri Nov 09 09:55:20 2018 +0100
+++ b/SimpleView.st	Sat Nov 10 00:34:47 2018 +0100
@@ -2852,6 +2852,12 @@
     ^ extentRule
 !
 
+flushCachedPreferredExtent
+    preferredExtent := nil.
+
+    "Created: / 09-11-2018 / 20:14:13 / Claus Gittinger"
+!
+
 frame
     "compatibility with displayObjects: returns my bounds"
 
@@ -6464,7 +6470,7 @@
      Otherwise, forward it to the superview, if there is any."
 
     <resource: #keyboard ( #Menu 
-                           #ZoomIn #ZoomOut
+                           #ZoomIn #ZoomOut #ZoomReset
                            #ZoomInAll #ZoomOutAll) >
 
     |focusView|
@@ -6489,6 +6495,10 @@
         ^ self activateMenu.
     ].
 
+    (key == #ZoomReset) ifTrue:[ 
+        self keyboardZoomReset.
+        ^ self
+    ].
     (key == #ZoomIn or:[key == #ZoomOut]) ifTrue:[ 
         self keyboardZoom:(key == #ZoomIn).
         ^ self
@@ -6512,7 +6522,8 @@
         super keyPress:key x:x y:y
     ]
 
-    "Modified: / 20.5.1998 / 22:55:08 / cg"
+    "Modified: / 20-05-1998 / 22:55:08 / cg"
+    "Modified: / 09-11-2018 / 23:56:19 / Claus Gittinger"
 !
 
 keyRelease:key x:x y:y
@@ -6553,6 +6564,23 @@
     "Modified: / 26-05-2018 / 11:49:43 / Claus Gittinger"
 !
 
+keyboardZoomReset
+    "CTRL0 action"
+
+    "/ self changeScaleForMouseWheelZoom:nil
+
+    "Created: / 09-11-2018 / 23:57:43 / Claus Gittinger"
+!
+
+keyboardZoomkeyboardZoomReset
+    "CTRL0 action.
+     ignored here - redefined in views which can zoom"
+
+    "/ self changeScaleForMouseWheelZoom:nil
+
+    "Created: / 09-11-2018 / 23:56:38 / Claus Gittinger"
+!
+
 mapped
     "the view has been mapped (by some outside
      action - i.e. window manager de-iconified me)"
@@ -9231,23 +9259,47 @@
 !
 
 computePreferredExtent
-    "compute answer the preferred extent, 
-     ignoring any explicit or cached preferred extent for the computation"
-
-    |savedPref savedExplicit computedPref|
-
-    savedPref := preferredExtent.
-    savedExplicit := explicitExtent.
-    [
-        preferredExtent := explicitExtent := nil.
-        computedPref := self preferredExtent.
-    ] ensure:[
-        preferredExtent := savedPref.
-        explicitExtent := savedExplicit.
-    ].
-    ^ computedPref
-
-    "Modified (comment): / 01-10-2018 / 16:21:02 / Claus Gittinger"
+    "return my computed preferred extent - this is the minimum size I would like to have.
+     If there are any components, a rectangle enclosing them
+     is returned. Otherwise, the actual extent is returned."
+
+    |maxX maxY|
+
+    subViews notNil ifTrue:[
+        maxX := maxY := 0.
+        subViews do:[:aSubView |
+            |org corn|
+
+            org := aSubView computeOrigin.
+            corn := org + aSubView preferredExtent.
+            maxX := maxX max:corn x.
+            maxY := maxY max:corn y.
+        ]
+    ].
+
+    "/ mhmh - if I have components, collect their preferred bounds ...
+    components notNil ifTrue:[
+        maxX isNil ifTrue:[
+            maxX := maxY := 0.
+        ].
+        components do:[:aComponent |
+            |bounds org corn|
+
+            bounds := aComponent preferredBounds.
+            corn := bounds corner.
+            maxX := maxX max:corn x.
+            maxY := maxY max:corn y.
+        ]
+    ].
+
+    "/ nothing found - return the actual size
+    maxX isNil ifTrue:[
+        ^ self extent.
+    ].
+
+    ^ maxX @ maxY.
+
+    "Modified: / 09-11-2018 / 19:43:30 / Claus Gittinger"
 !
 
 cornerChangedFlag
@@ -9581,57 +9633,23 @@
      Otherwise, if there are any components, a rectangle enclosing them
      is returned. Otherwise, the actual extent is returned."
 
-    |maxX maxY|
-
     "/ If I have an explicit preferredExtent..
-    explicitExtent notNil ifTrue:[
-	^ explicitExtent
+    explicitExtent notNil ifTrue:[ 
+        ^ explicitExtent
     ].
 
     "/ If I have a cached preferredExtent value..
+    "/ notice: subviews should only cache, if the contents does not
+    "/ change dynamically, OR if they make sure to flush the cached
+    "/ value as required.
     preferredExtent notNil ifTrue:[
-	^ preferredExtent
-    ].
-
-    "/ mhmh - if I have subViews, collect their
-    "/ preferred bounds ...
-
-    subViews notNil ifTrue:[
-	maxX := maxY := 0.
-	subViews do:[:aSubView |
-	    |org corn|
-
-	    org := aSubView computeOrigin.
-	    corn := org + aSubView preferredExtent.
-	    maxX := maxX max:corn x.
-	    maxY := maxY max:corn y.
-	]
-    ].
-
-    "/ mhmh - if I have components, collect their preferred bounds ...
-    components notNil ifTrue:[
-	maxX isNil ifTrue:[
-	    maxX := maxY := 0.
-	].
-	components do:[:aComponent |
-	    |bounds org corn|
-
-	    bounds := aComponent preferredBounds.
-	    corn := bounds corner.
-	    maxX := maxX max:corn x.
-	    maxY := maxY max:corn y.
-	]
-    ].
-
-    "/ nothing found - return the actual size
-
-    maxX isNil ifTrue:[
-	^ self extent.
-    ].
-
-    ^ maxX @ maxY.
-
-    "Modified: 19.7.1996 / 20:43:32 / cg"
+        ^ preferredExtent
+    ].
+
+    ^ self computePreferredExtent
+
+    "Modified: / 19-07-1996 / 20:43:32 / cg"
+    "Modified: / 09-11-2018 / 20:10:55 / Claus Gittinger"
 !
 
 preferredHeight