FontPanel.st
changeset 5531 d5ed61031306
parent 5524 56e7888d6438
child 5532 db6b004f8e1a
equal deleted inserted replaced
5530:6e888d60be5a 5531:d5ed61031306
    17 	instanceVariableNames:'previewField listOfEncodings allFonts fontsPerFamily familyList
    17 	instanceVariableNames:'previewField listOfEncodings allFonts fontsPerFamily familyList
    18 		faceList sizeList revertButton currentFamily currentFace
    18 		faceList sizeList revertButton currentFamily currentFace
    19 		currentStyle currentFaceAndStyle currentSize sizeUnit
    19 		currentStyle currentFaceAndStyle currentSize sizeUnit
    20 		currentEncoding selectedFont nameLabel encodingFilter
    20 		currentEncoding selectedFont nameLabel encodingFilter
    21 		encodingLabel filter combinedFilter encoding sizeLabelHolder
    21 		encodingLabel filter combinedFilter encoding sizeLabelHolder
    22 		pixelPointSwitch xftFontsOnlyHolder'
    22 		pixelPointSwitch xftFontsOnlyHolder changeFontInAllViewsHolder
       
    23 		withChangeFontInAllViewsCheckBox
       
    24 		withChangeFontInAllViewsCheckBoxVisibleHolder'
    23 	classVariableNames:''
    25 	classVariableNames:''
    24 	poolDictionaries:''
    26 	poolDictionaries:''
    25 	category:'Views-DialogBoxes'
    27 	category:'Views-DialogBoxes'
    26 !
    28 !
    27 
    29 
    43 
    45 
    44 !
    46 !
    45 
    47 
    46 documentation
    48 documentation
    47 "
    49 "
    48     this class implements a font chooser.
    50     this class implements the font chooser.
    49 
    51 
    50     Notice: 
    52     Notice: 
    51         this is a very old dialog; 
    53         this is a very old dialog; 
    52         it was written before the UI-framework was available and is completely
    54         it was written before the UI-framework was available and the UI is completely
    53         setup manually (initialize method).
    55         programmed manually (see initialize method).
    54         Therefore, it desperately asks to be rewritten using the UIPainter...
    56         Therefore, it desperately asks to be rewritten using the UIPainter...
    55 
    57 
    56     [author:]
    58     [author:]
    57         Claus Gittinger
    59         Claus Gittinger
    58 
    60 
   288 ! !
   290 ! !
   289 
   291 
   290 !FontPanel class methodsFor:'startup'!
   292 !FontPanel class methodsFor:'startup'!
   291 
   293 
   292 fontFromUser
   294 fontFromUser
   293     "open a fontPanel and return the selected font, or nil
   295     "open a fontPanel and return the selected font, 
   294      if abort is pressed"
   296      or nil if abort is pressed"
   295 
   297 
   296     ^ self 
   298     ^ self new fontFromUser
   297         fontFromUserInitial:nil
       
   298         title:nil
       
   299         filter:nil
       
   300         encoding:nil
       
   301         enabled:true
       
   302 
   299 
   303     "
   300     "
   304      FontPanel fontFromUser
   301      FontPanel fontFromUser
   305     "
   302     "
   306 
   303 
   309 
   306 
   310 fontFromUserInitial:aFont
   307 fontFromUserInitial:aFont
   311     "open a fontPanel showing aFont initially,
   308     "open a fontPanel showing aFont initially,
   312      and return the selected font, or nil if abort is pressed"
   309      and return the selected font, or nil if abort is pressed"
   313 
   310 
   314     ^ self 
   311     ^ self new fontFromUserInitial:aFont
   315         fontFromUserInitial:aFont 
       
   316         title:nil
       
   317         filter:nil
       
   318         encoding:nil
       
   319         enabled:true
       
   320 
   312 
   321     "
   313     "
   322      FontPanel fontFromUserInitial:(Font family:'courier' size:12)
   314      FontPanel fontFromUserInitial:(Font family:'courier' size:12)
   323      FontPanel fontFromUserInitial:MenuPanel defaultFont
   315      FontPanel fontFromUserInitial:MenuPanel defaultFont
   324     "
   316     "
   326 
   318 
   327 fontFromUserInitial:aFont title:someTitle
   319 fontFromUserInitial:aFont title:someTitle
   328     "open a fontPanel with title and return the selected font, 
   320     "open a fontPanel with title and return the selected font, 
   329      or nil if abort is pressed"
   321      or nil if abort is pressed"
   330 
   322 
   331     ^ self 
   323     ^ self new 
   332         fontFromUserInitial:aFont 
   324         fontFromUserInitial:aFont title:someTitle
   333         title:someTitle 
       
   334         filter:nil
       
   335         encoding:nil
       
   336         enabled:true
       
   337 
   325 
   338     "
   326     "
   339      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   327      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   340     "
   328     "
   341 
   329 
   345 
   333 
   346 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock
   334 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock
   347     "open a fontPanel with title and font-filter
   335     "open a fontPanel with title and font-filter
   348      and return the selected font, or nil if abort is pressed"
   336      and return the selected font, or nil if abort is pressed"
   349 
   337 
   350     ^ self 
   338     ^ self new 
   351         fontFromUserInitial:initialFont 
   339         fontFromUserInitial:initialFont title:someTitle 
   352         title:someTitle 
   340         filter:aFilterBlock
   353         filter:aFilterBlock 
       
   354         encoding:nil
       
   355         enabled:true
       
   356 
   341 
   357     "
   342     "
   358      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   343      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   359     "
   344     "
   360 
   345 
   364 
   349 
   365 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding
   350 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding
   366     "open a fontPanel with title and font-filter
   351     "open a fontPanel with title and font-filter
   367      and return the selected font, or nil if abort is pressed"
   352      and return the selected font, or nil if abort is pressed"
   368 
   353 
   369     ^ self
   354     ^ self new 
   370         fontFromUserInitial:initialFont 
   355         fontFromUserInitial:initialFont title:someTitle 
   371         title:someTitle 
   356         filter:aFilterBlock encoding:encoding
   372         filter:aFilterBlock 
       
   373         encoding:encoding 
       
   374         enabled:true
       
   375 
   357 
   376     "
   358     "
   377      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   359      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   378     "
   360     "
   379 !
   361 !
   380 
   362 
   381 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
   363 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
   382     "open a fontPanel with title and font-filter
   364     "open a fontPanel with title and font-filter
   383      and return the selected font, or nil if abort is pressed"
   365      and return the selected font, or nil if abort is pressed"
   384 
   366 
   385     |fontPanel selectedFont|
   367     ^ self new
   386 
   368         fontFromUserInitial:initialFont title:someTitle 
   387     fontPanel := self new.
   369         filter:aFilterBlock encoding:encoding 
   388     fontPanel filter:aFilterBlock.
   370         enabled:enabled
   389     someTitle notNil ifTrue:[
       
   390         fontPanel label:someTitle
       
   391     ].
       
   392     fontPanel action:[:aFontDescription | selectedFont := aFontDescription].
       
   393     initialFont notNil ifTrue:[
       
   394         fontPanel initialFont:initialFont.
       
   395     ].
       
   396     encoding notNil ifTrue:[
       
   397         fontPanel encoding:encoding.
       
   398     ] ifFalse:[
       
   399         initialFont notNil ifTrue:[
       
   400             fontPanel encoding:initialFont encoding
       
   401         ].
       
   402     ].
       
   403     fontPanel enabled:enabled.
       
   404     fontPanel showAtPointer.
       
   405     fontPanel destroy.
       
   406     ^ selectedFont
       
   407 
   371 
   408     "
   372     "
   409      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   373      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
   410     "
   374     "
   411 
   375 
   438      The block will be evaluated with family, face, style, size and encoding."
   402      The block will be evaluated with family, face, style, size and encoding."
   439 
   403 
   440     okAction := aFourArgBlock
   404     okAction := aFourArgBlock
   441 
   405 
   442     "Modified: 10.4.1997 / 09:49:58 / cg"
   406     "Modified: 10.4.1997 / 09:49:58 / cg"
       
   407 !
       
   408 
       
   409 changeFontInAllViews
       
   410     "valid after closing"
       
   411     
       
   412     ^ self changeFontInAllViewsHolder value    
       
   413 !
       
   414 
       
   415 changeFontInAllViewsHolder
       
   416     changeFontInAllViewsHolder isNil ifTrue:[
       
   417         changeFontInAllViewsHolder := false asValue
       
   418     ].
       
   419     ^ changeFontInAllViewsHolder
   443 !
   420 !
   444 
   421 
   445 encoding:aPattern
   422 encoding:aPattern
   446     "set the encoding goal"
   423     "set the encoding goal"
   447 
   424 
   507     self showSelectedFont.
   484     self showSelectedFont.
   508 
   485 
   509     "Modified: 23.2.1996 / 00:51:32 / cg"
   486     "Modified: 23.2.1996 / 00:51:32 / cg"
   510 !
   487 !
   511 
   488 
       
   489 withChangeFontInAllViewsCheckBoxVisibleHolder
       
   490     withChangeFontInAllViewsCheckBoxVisibleHolder isNil ifTrue:[
       
   491         withChangeFontInAllViewsCheckBoxVisibleHolder := false asValue
       
   492     ].
       
   493     ^ withChangeFontInAllViewsCheckBoxVisibleHolder
       
   494 !
       
   495 
       
   496 withChangeFontInViewsAllCheckBox:aBoolean
       
   497     "to make that check box visible;
       
   498      call before opening"
       
   499      
       
   500     self withChangeFontInAllViewsCheckBoxVisibleHolder value:true
       
   501 !
       
   502 
   512 xftFontsOnlyHolder
   503 xftFontsOnlyHolder
   513     xftFontsOnlyHolder isNil ifTrue:[
   504     xftFontsOnlyHolder isNil ifTrue:[
   514         xftFontsOnlyHolder := true asValue
   505         xftFontsOnlyHolder := true asValue
   515     ].
   506     ].
   516     ^ xftFontsOnlyHolder
   507     ^ xftFontsOnlyHolder
   522     familyList enabled:aBoolean.
   513     familyList enabled:aBoolean.
   523     faceList enabled:aBoolean.
   514     faceList enabled:aBoolean.
   524     sizeList enabled:aBoolean.
   515     sizeList enabled:aBoolean.
   525     encodingFilter notNil ifTrue:[
   516     encodingFilter notNil ifTrue:[
   526         encodingFilter enabled:aBoolean.
   517         encodingFilter enabled:aBoolean.
   527     ]
   518     ].
       
   519     aBoolean ifTrue:[
       
   520         self abortButton label:(resources string:'Cancel').
       
   521         self okButton beVisible.        
       
   522     ] ifFalse:[
       
   523         self abortButton label:(resources string:'Close').
       
   524         self okButton beInvisible.
       
   525     ].
       
   526 
       
   527     "
       
   528      FontPanel openOn:(Font family:'courier' size:12)
       
   529      FontPanel openOn:MenuPanel defaultFont
       
   530      FontPanel fontFromUser
       
   531     "
   528 !
   532 !
   529 
   533 
   530 initialize
   534 initialize
       
   535     "sigh: hand-crafted box creation; TODO: rewrite using UI painter"
       
   536     
   531     |familyLabel faceLabel sizeLabel panel panel2 fontBrowserView fp v1 v2 v3
   537     |familyLabel faceLabel sizeLabel panel panel2 fontBrowserView fp v1 v2 v3
   532      mm fH l box1 box2 showFontNameLabel xftCheckBox vPanel|
   538      mm fH l box1 box2 showFontNameLabel xftCheckBox vPanel changeInAllCheckBox|
   533 
   539 
   534     super initialize.
   540     super initialize.
   535 
   541 
   536     showFontNameLabel := self graphicsDevice isWindowsPlatform not.
   542     showFontNameLabel := self graphicsDevice isWindowsPlatform not.
   537     sizeUnit := #pt.
   543     sizeUnit := #pt.
   550 
   556 
   551     previewField := HVScrollableView for:TextView in:vPanel.
   557     previewField := HVScrollableView for:TextView in:vPanel.
   552     fontBrowserView := View in:vPanel.
   558     fontBrowserView := View in:vPanel.
   553     fp := View in:fontBrowserView.
   559     fp := View in:fontBrowserView.
   554     fp layout:(0.0@0.0 corner:1.0@1.0) asFractionalLayout. 
   560     fp layout:(0.0@0.0 corner:1.0@1.0) asFractionalLayout. 
   555     fp layout bottomOffset:-75.
   561     fp layout bottomOffset:-150.
   556 
   562 
   557     label := resources string:'Font dialog'.
   563     label := resources string:'Font dialog'.
   558 
   564 
   559     panel2 := VerticalPanelView in:fontBrowserView.
   565     panel2 := VerticalPanelView in:fontBrowserView.
   560     panel2 layout:(0.0@1.0 corner:1.0@1.0) asFractionalLayout.
   566     panel2 layout:(0.0@1.0 corner:1.0@1.0) asFractionalLayout.
   561     panel2 layout topOffset:-75.
   567     panel2 layout topOffset:-150.
   562     
   568     
   563     panel2 horizontalLayout:#fit.
   569     panel2 horizontalLayout:#fit.
   564     panel2 verticalLayout:#top.
   570     panel2 verticalLayout:#top.
   565 
   571 
       
   572     box2 := HorizontalPanelView in:panel2.
       
   573     box2 height:25.
       
   574     box2 horizontalLayout:#right.
       
   575 
   566     box1 := HorizontalPanelView in:panel2.
   576     box1 := HorizontalPanelView in:panel2.
   567     box1 height:25.
   577     box1 height:25.
   568     box1 horizontalLayout:#leftSpace.
   578     box1 horizontalLayout:#leftSpace.
   569 
       
   570     box2 := HorizontalPanelView in:panel2.
       
   571     box2 height:25.
       
   572     box2 horizontalLayout:#right.
       
   573 
   579 
   574     l := Label label:(resources string:'Encoding:') in:box1.
   580     l := Label label:(resources string:'Encoding:') in:box1.
   575     l borderWidth:0.
   581     l borderWidth:0.
   576     l adjust:#left.
   582     l adjust:#left.
   577 
   583 
   602         encodingLabel beInvisible
   608         encodingLabel beInvisible
   603     ].
   609     ].
   604 
   610 
   605     Screen current supportsXFTFonts ifTrue:[
   611     Screen current supportsXFTFonts ifTrue:[
   606         self xftFontsOnlyHolder value: (UserPreferences current useXftFontsOnly).
   612         self xftFontsOnlyHolder value: (UserPreferences current useXftFontsOnly).
   607         xftCheckBox := CheckBox label:'XFT Fonts Only' in:box1.
   613         xftCheckBox := CheckBox label:(resources string:'XFT Fonts Only') in:box1.
   608         xftCheckBox model:xftFontsOnlyHolder.
   614         xftCheckBox model:xftFontsOnlyHolder.
   609         xftFontsOnlyHolder onChangeEvaluate:[ self xftFontsOnlyChanged ].
   615         xftFontsOnlyHolder onChangeEvaluate:[ self xftFontsOnlyChanged ].
   610     ].
   616     ].
   611 
   617 
   612 "/    sep := View in:box1.
   618 "/    sep := View in:box1.
   623 
   629 
   624 "/    self showEncodingFilter ifFalse:[
   630 "/    self showEncodingFilter ifFalse:[
   625 "/        encodingFilter beInvisible
   631 "/        encodingFilter beInvisible
   626 "/    ].
   632 "/    ].
   627 
   633 
       
   634     (View in:panel2) height:8. "/ separator
       
   635     changeInAllCheckBox := CheckBox label:(resources string:'Default for New Views') in:panel2.
       
   636     changeInAllCheckBox model:self changeFontInAllViewsHolder.
       
   637     changeInAllCheckBox visibilityChannel:self withChangeFontInAllViewsCheckBoxVisibleHolder.
       
   638     
   628     showFontNameLabel ifTrue:[
   639     showFontNameLabel ifTrue:[
       
   640         (View in:panel2) height:8. "/ separator
   629         nameLabel := Label label:'' in:panel2.
   641         nameLabel := Label label:'' in:panel2.
   630         "/ nameLabel origin:0.0@1.0 corner:1.0@1.0.
   642         "/ nameLabel origin:0.0@1.0 corner:1.0@1.0.
   631         "/ nameLabel bottomInset:(buttonPanel preferredHeight + (mm*2)).
   643         "/ nameLabel bottomInset:(buttonPanel preferredHeight + (mm*2)).
   632         "/ nameLabel topInset:(buttonPanel preferredHeight + (mm*2) + 24) negated; horizontalInset:mm.
   644         "/ nameLabel topInset:(buttonPanel preferredHeight + (mm*2) + 24) negated; horizontalInset:mm.
   633         nameLabel level:0; adjust:#left.
   645         nameLabel level:0; adjust:#left.
  1214 
  1226 
  1215     "/ ^ 450@350
  1227     "/ ^ 450@350
  1216     ^ self class defaultExtent.
  1228     ^ self class defaultExtent.
  1217 
  1229 
  1218     "Modified: 19.7.1996 / 20:44:08 / cg"
  1230     "Modified: 19.7.1996 / 20:44:08 / cg"
       
  1231 ! !
       
  1232 
       
  1233 !FontPanel methodsFor:'startup'!
       
  1234 
       
  1235 fontFromUser
       
  1236     "open this fontPanel and return the selected font, 
       
  1237      or nil if abort is pressed"
       
  1238 
       
  1239     ^ self 
       
  1240         fontFromUserInitial:nil
       
  1241         title:nil
       
  1242         filter:nil
       
  1243         encoding:nil
       
  1244         enabled:true
       
  1245 
       
  1246     "
       
  1247      FontPanel fontFromUser
       
  1248 
       
  1249      FontPanel new
       
  1250         withChangeFontInViewsAllCheckBox:true;
       
  1251         fontFromUser
       
  1252     "
       
  1253 
       
  1254     "Modified: 27.2.1996 / 00:51:59 / cg"
       
  1255 !
       
  1256 
       
  1257 fontFromUserInitial:aFont
       
  1258     "open this fontPanel showing aFont initially,
       
  1259      and return the selected font, or nil if abort is pressed"
       
  1260 
       
  1261     ^ self 
       
  1262         fontFromUserInitial:aFont 
       
  1263         title:nil
       
  1264         filter:nil
       
  1265         encoding:nil
       
  1266         enabled:true
       
  1267 
       
  1268     "
       
  1269      FontPanel fontFromUserInitial:(Font family:'courier' size:12)
       
  1270      FontPanel fontFromUserInitial:MenuPanel defaultFont
       
  1271     "
       
  1272 !
       
  1273 
       
  1274 fontFromUserInitial:aFont title:someTitle
       
  1275     "open this fontPanel with title and return the selected font, 
       
  1276      or nil if abort is pressed"
       
  1277 
       
  1278     ^ self 
       
  1279         fontFromUserInitial:aFont 
       
  1280         title:someTitle 
       
  1281         filter:nil
       
  1282         encoding:nil
       
  1283         enabled:true
       
  1284 
       
  1285     "
       
  1286      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
       
  1287     "
       
  1288 
       
  1289     "Created: 27.2.1996 / 00:59:46 / cg"
       
  1290     "Modified: 29.4.1996 / 09:45:34 / cg"
       
  1291 !
       
  1292 
       
  1293 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock
       
  1294     "open this fontPanel with title and font-filter
       
  1295      and return the selected font, or nil if abort is pressed"
       
  1296 
       
  1297     ^ self 
       
  1298         fontFromUserInitial:initialFont 
       
  1299         title:someTitle 
       
  1300         filter:aFilterBlock 
       
  1301         encoding:nil
       
  1302         enabled:true
       
  1303 
       
  1304     "
       
  1305      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
       
  1306     "
       
  1307 
       
  1308     "Created: 27.2.1996 / 00:59:46 / cg"
       
  1309     "Modified: 10.4.1997 / 09:53:03 / cg"
       
  1310 !
       
  1311 
       
  1312 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding
       
  1313     "open this fontPanel with title and font-filter
       
  1314      and return the selected font, or nil if abort is pressed"
       
  1315 
       
  1316     ^ self
       
  1317         fontFromUserInitial:initialFont 
       
  1318         title:someTitle 
       
  1319         filter:aFilterBlock 
       
  1320         encoding:encoding 
       
  1321         enabled:true
       
  1322 
       
  1323     "
       
  1324      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
       
  1325     "
       
  1326 !
       
  1327 
       
  1328 fontFromUserInitial:initialFont title:someTitle filter:aFilterBlock encoding:encoding enabled:enabled
       
  1329     "open this fontPanel with title and font-filter
       
  1330      and return the selected font, or nil if abort is pressed"
       
  1331 
       
  1332     |selectedFont|
       
  1333 
       
  1334     self filter:aFilterBlock.
       
  1335     someTitle notNil ifTrue:[
       
  1336         self label:someTitle
       
  1337     ].
       
  1338     self action:[:aFontDescription | selectedFont := aFontDescription].
       
  1339     initialFont notNil ifTrue:[
       
  1340         self initialFont:initialFont.
       
  1341     ].
       
  1342     encoding notNil ifTrue:[
       
  1343         self encoding:encoding.
       
  1344     ] ifFalse:[
       
  1345         initialFont notNil ifTrue:[
       
  1346             self encoding:initialFont encoding
       
  1347         ].
       
  1348     ].
       
  1349     self enabled:enabled.
       
  1350     self showAtPointer.
       
  1351     self destroy.
       
  1352     ^ selectedFont
       
  1353 
       
  1354     "
       
  1355      FontPanel fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'.
       
  1356      
       
  1357      FontPanel new
       
  1358         withChangeFontInViewsAllCheckBox:true;
       
  1359         fontFromUserInitial:(Font family:'courier' size:12) title:'select some font'
       
  1360     "
       
  1361 
       
  1362     "Created: 27.2.1996 / 00:59:46 / cg"
       
  1363     "Modified: 10.4.1997 / 09:53:03 / cg"
  1219 ! !
  1364 ! !
  1220 
  1365 
  1221 !FontPanel methodsFor:'user interaction'!
  1366 !FontPanel methodsFor:'user interaction'!
  1222 
  1367 
  1223 copyFontName
  1368 copyFontName