FontPanel.st
changeset 3740 dd192b87bd0b
parent 3607 242d08639bcc
child 3769 758f8b0b6cf2
--- a/FontPanel.st	Mon Oct 20 16:36:37 2008 +0200
+++ b/FontPanel.st	Tue Oct 21 17:43:25 2008 +0200
@@ -288,7 +288,12 @@
     "open a fontPanel and return the selected font, or nil
      if abort is pressed"
 
-    ^ self fontFromUserInitial:nil
+    ^ self 
+        fontFromUserInitial:nil
+        title:nil
+        filter:nil
+        encoding:nil
+        enabled:true
 
     "
      FontPanel fontFromUser
@@ -301,21 +306,29 @@
     "open a fontPanel showing aFont initially,
      and return the selected font, or nil if abort is pressed"
 
-    ^ self fontFromUserInitial:aFont title:nil
+    ^ self 
+        fontFromUserInitial:aFont 
+        title:nil
+        filter:nil
+        encoding:nil
+        enabled:true
 
     "
      FontPanel fontFromUserInitial:(Font family:'courier' size:12)
+     FontPanel fontFromUserInitial:MenuPanel defaultFont
     "
-
-    "Created: 27.2.1996 / 00:51:44 / cg"
-    "Modified: 29.4.1996 / 09:45:52 / cg"
 !
 
 fontFromUserInitial:aFont title:someTitle
     "open a fontPanel with title and return the selected font, 
      or nil if abort is pressed"
 
-    ^ self fontFromUserInitial:aFont title:someTitle filter:nil
+    ^ self 
+        fontFromUserInitial:aFont 
+        title:someTitle 
+        filter:nil
+        encoding:nil
+        enabled:true
 
     "
      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
@@ -329,7 +342,12 @@
     "open a fontPanel with title and font-filter
      and return the selected font, or nil if abort is pressed"
 
-    ^ self fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:nil
+    ^ self 
+        fontFromUserInitial:initialFont 
+        title:someTitle 
+        filter:aFilterBlock 
+        encoding:nil
+        enabled:true
 
     "
      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
@@ -343,6 +361,22 @@
     "open a fontPanel with title and font-filter
      and return the selected font, or nil if abort is pressed"
 
+    ^ self
+        fontFromUserInitial:initialFont 
+        title:someTitle 
+        filter:aFilterBlock 
+        encoding:encoding 
+        enabled:true
+
+    "
+     FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
+    "
+!
+
+fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
+    "open a fontPanel with title and font-filter
+     and return the selected font, or nil if abort is pressed"
+
     |fontPanel selectedFont|
 
     fontPanel := FontPanel new.
@@ -361,6 +395,7 @@
             fontPanel encoding:initialFont encoding
         ].
     ].
+    fontPanel enabled:enabled.
     fontPanel showAtPointer.
     fontPanel destroy.
     ^ selectedFont
@@ -371,6 +406,23 @@
 
     "Created: 27.2.1996 / 00:59:46 / cg"
     "Modified: 10.4.1997 / 09:53:03 / cg"
+!
+
+openOn:aFont
+    "open a fontPanel showing aFont initially.
+     This panel is for information only - no font selection is possible."
+
+    ^ self 
+        fontFromUserInitial:aFont 
+        title:(aFont userFriendlyName)
+        filter:nil
+        encoding:nil
+        enabled:false
+
+    "
+     FontPanel openOn:(Font family:'courier' size:12)
+     FontPanel openOn:MenuPanel defaultFont
+    "
 ! !
 
 !FontPanel methodsFor:'accessing'!
@@ -430,6 +482,13 @@
 
 !FontPanel methodsFor:'initialization'!
 
+enabled:aBoolean
+    familyList enabled:aBoolean.
+    faceList enabled:aBoolean.
+    sizeList enabled:aBoolean.
+    encodingFilter enabled:aBoolean.
+!
+
 initialize
     |familyLabel faceLabel sizeLabel panel fontBrowserView v1 v2 v3
      mm fH eH l box showFontNameLabel|
@@ -838,7 +897,7 @@
 faceSelected:aFaceAndStyleName showPreview:showPreview
     "a fonts face was selected; find available sizes and update lists"
 
-    |sizes didShow|
+    |sizes sizeStrings didShow|
 
     aFaceAndStyleName notNil ifTrue:[    
         self extractFaceAndStyleFrom:aFaceAndStyleName.
@@ -860,10 +919,18 @@
 
     didShow := false.
 
-    sizes := (sizes asOrderedCollection sort) collect:[:entry | entry printString].
-    sizeList list:sizes.
+    sizes := sizes asOrderedCollection.
+    selectedFont notNil ifTrue:[
+        (sizes includes:selectedFont size) ifFalse:[
+            sizes add:selectedFont size
+        ].
+    ].
+    sizes sort.
+
+    sizeStrings := sizes collect:[:entry | entry printString].
+    sizeList list:sizeStrings.
     currentSize notNil ifTrue:[
-        (sizes includes:(currentSize printString)) ifTrue:[
+        (sizeStrings includes:(currentSize printString)) ifTrue:[
             sizeList setSelectElement:currentSize printString.
             showPreview ifTrue:[
                 self showPreview.
@@ -983,5 +1050,5 @@
 !FontPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.92 2008-05-30 12:24:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.93 2008-10-21 15:43:25 cg Exp $'
 ! !