DisplaySurface.st
changeset 1134 520b75563476
parent 1133 a90be1f2c699
child 1177 e89408c15bb5
equal deleted inserted replaced
1133:a90be1f2c699 1134:520b75563476
   102     "install the viewBackground for the receiver on the device"
   102     "install the viewBackground for the receiver on the device"
   103 
   103 
   104     |id devBgPixmap bgPixmap w h colors|
   104     |id devBgPixmap bgPixmap w h colors|
   105 
   105 
   106     drawableId notNil ifTrue:[
   106     drawableId notNil ifTrue:[
   107 	viewBackground isColor ifTrue:[
   107         viewBackground isColor ifTrue:[
   108 	    viewBackground := viewBackground on:device.
   108             viewBackground := viewBackground on:device.
   109 	    id := viewBackground colorId.
   109             id := viewBackground colorId.
   110 	    "
   110             "
   111 	     a real color (i.e. one supported by the device) ?
   111              a real color (i.e. one supported by the device) ?
   112 	    "
   112             "
   113 	    id notNil ifTrue:[
   113             id notNil ifTrue:[
   114 		device setWindowBackground:id in:drawableId.
   114                 device setWindowBackground:id in:drawableId.
   115 		^ self
   115                 ^ self
   116 	    ].
   116             ].
   117 	    "
   117             "
   118 	     no, a dithered one - must have a dither-pattern
   118              no, a dithered one - must have a dither-pattern
   119 	     (which is ready for the device, since viewBackground
   119              (which is ready for the device, since viewBackground
   120 	      is already assigned to the device)
   120               is already assigned to the device)
   121 	    "
   121             "
   122 	    bgPixmap := viewBackground ditherForm.
   122             bgPixmap := viewBackground ditherForm.
   123 	] ifFalse:[
   123         ] ifFalse:[
   124 	    "
   124             "
   125 	     assume, it can convert itself to a form
   125              assume, it can convert itself to a form
   126 	    "
   126             "
   127 	    bgPixmap := viewBackground asFormOn:device
   127             bgPixmap := viewBackground asFormOn:device
   128 	].
   128         ].
   129 
   129 
   130 	"
   130         "
   131 	 must now have:
   131          must now have:
   132 	 a dithered color or bitmap or pixmap
   132          a dithered color or bitmap or pixmap
   133 	"
   133         "
   134 	bgPixmap isNil ifTrue:[
   134         bgPixmap isNil ifTrue:[
   135 	    'PSEUDOVIEW: background not convertable - ignored' errorPrintNL.
   135             'DSURFACE: background not convertable - ignored' errorPrintNL.
   136 	    ^ self
   136             ^ self
   137 	].
   137         ].
   138 
   138 
   139 	w := bgPixmap width.
   139         w := bgPixmap width.
   140 	h := bgPixmap height.
   140         h := bgPixmap height.
   141 
   141 
   142 	(bgPixmap depth ~~ device depth) ifTrue:[
   142         (bgPixmap depth ~~ device depth) ifTrue:[
   143 	    (bgPixmap depth ~~ 1) ifTrue:[
   143             (bgPixmap depth ~~ 1) ifTrue:[
   144 		self error:'bad dither depth'.
   144                 self error:'bad dither depth'.
   145 		^ self
   145                 ^ self
   146 	    ].
   146             ].
   147 	    "
   147             "
   148 	     convert it into a deep form
   148              convert it into a deep form
   149 	    "
   149             "
   150 	    colors := bgPixmap colorMap.
   150             colors := bgPixmap colorMap.
   151 	    devBgPixmap := Form width:w height:h depth:(device depth) on:device.
   151             devBgPixmap := Form width:w height:h depth:(device depth) on:device.
   152 	    devBgPixmap paint:(colors at:1).
   152             devBgPixmap paint:(colors at:1).
   153 	    devBgPixmap fillRectangleX:0 y:0 width:w height:h.
   153             devBgPixmap fillRectangleX:0 y:0 width:w height:h.
   154 	    devBgPixmap foreground:(colors at:2) background:(colors at:1).
   154             devBgPixmap foreground:(colors at:2) background:(colors at:1).
   155 	    devBgPixmap copyPlaneFrom:bgPixmap x:0 y:0 toX:0 y:0 width:w height:h.
   155             devBgPixmap copyPlaneFrom:bgPixmap x:0 y:0 toX:0 y:0 width:w height:h.
   156 	    bgPixmap := devBgPixmap.
   156             bgPixmap := devBgPixmap.
   157 	] ifFalse:[
   157         ] ifFalse:[
   158 	    (bgPixmap depth == 1) ifTrue:[
   158             (bgPixmap depth == 1) ifTrue:[
   159 		"
   159                 "
   160 		 although depth matches,
   160                  although depth matches,
   161 		 values in the dither are to be interpreted via the ditherForms
   161                  values in the dither are to be interpreted via the ditherForms
   162 		 colormap, which is not always the same as blackpixel/whitepixel ...
   162                  colormap, which is not always the same as blackpixel/whitepixel ...
   163 		"
   163                 "
   164 		(bgPixmap colorMap at:1) colorId == device whitepixel ifTrue:[
   164                 (bgPixmap colorMap at:1) colorId == device whitepixel ifTrue:[
   165 		    (bgPixmap colorMap at:2) colorId == device blackpixel ifTrue:[
   165                     (bgPixmap colorMap at:2) colorId == device blackpixel ifTrue:[
   166 			"
   166                         "
   167 			 ok, can use it
   167                          ok, can use it
   168 			"
   168                         "
   169 			device setWindowBackgroundPixmap:(bgPixmap id) in:drawableId.
   169                         device setWindowBackgroundPixmap:(bgPixmap id) in:drawableId.
   170 			^ self
   170                         ^ self
   171 		    ]
   171                     ]
   172 		].
   172                 ].
   173 
   173 
   174 		"
   174                 "
   175 		 no, must invert it
   175                  no, must invert it
   176 		"
   176                 "
   177 		devBgPixmap := Form width:w height:h depth:(device depth) on:device.
   177                 devBgPixmap := Form width:w height:h depth:(device depth) on:device.
   178 		devBgPixmap paint:(bgPixmap colorMap at:2) on:(bgPixmap colorMap at:1).
   178                 devBgPixmap paint:(bgPixmap colorMap at:2) on:(bgPixmap colorMap at:1).
   179 		devBgPixmap copyPlaneFrom:bgPixmap x:0 y:0 toX:0 y:0 width:w height:h.
   179                 devBgPixmap copyPlaneFrom:bgPixmap x:0 y:0 toX:0 y:0 width:w height:h.
   180 		bgPixmap := devBgPixmap.
   180                 bgPixmap := devBgPixmap.
   181 	    ]
   181             ]
   182 	].
   182         ].
   183 	device setWindowBackgroundPixmap:(bgPixmap id) in:drawableId.
   183         device setWindowBackgroundPixmap:(bgPixmap id) in:drawableId.
   184     ]
   184     ]
       
   185 
       
   186     "Modified: 12.12.1996 / 14:08:33 / cg"
   185 !
   187 !
   186 
   188 
   187 viewBackground
   189 viewBackground
   188     "return the viewBackground"
   190     "return the viewBackground"
   189 
   191 
   274      Cursors are typically set at view creation time and left as installed."
   276      Cursors are typically set at view creation time and left as installed."
   275 
   277 
   276     |id|
   278     |id|
   277 
   279 
   278     aCursor notNil ifTrue:[
   280     aCursor notNil ifTrue:[
   279 	(aCursor ~~ cursor) ifTrue:[
   281         (aCursor ~~ cursor) ifTrue:[
   280 	    cursor := aCursor.
   282             cursor := aCursor.
   281 	    drawableId notNil ifTrue:[
   283             drawableId notNil ifTrue:[
   282 		cursor := cursor on:device.
   284                 cursor := cursor on:device.
   283 		cursor isNil ifTrue:[ ^ self].
   285                 cursor isNil ifTrue:[ ^ self].
   284 		id := cursor id.
   286                 id := cursor id.
   285 		id isNil ifTrue:[
   287                 id isNil ifTrue:[
   286 		    'PSEUDOVIEW: nil cursorId ignored; shape=' errorPrint. cursor shape errorPrintNL.
   288                     'DSURFACE: nil cursorId ignored; shape=' errorPrint. cursor shape errorPrintNL.
   287 		    ^ self
   289                     ^ self
   288 		].
   290                 ].
   289 		device setCursor:id in:drawableId.
   291                 device setCursor:id in:drawableId.
   290 		(showImmediately and:[realized]) ifTrue:[
   292                 (showImmediately and:[realized]) ifTrue:[
   291 		    "flush, to make cursor immediately visible"
   293                     "flush, to make cursor immediately visible"
   292 		    device flush
   294                     device flush
   293 		]
   295                 ]
   294 	    ]
   296             ]
   295 	]
   297         ]
   296     ]
   298     ]
   297 
   299 
   298     "
   300     "
   299      |v|
   301      |v|
   300 
   302 
   301      v := View new.
   303      v := View new.
   302      v cursor:(Cursor wait).
   304      v cursor:(Cursor wait).
   303      v open.
   305      v open.
   304      [v shown] whileFalse:[Processor yield].
   306      [v shown] whileFalse:[Processor yield].
   305      [v shown] whileTrue:[   
   307      [v shown] whileTrue:[   
   306 	(Delay forSeconds:1) wait.
   308         (Delay forSeconds:1) wait.
   307 	v cursor:(Cursor normal).
   309         v cursor:(Cursor normal).
   308 	(Delay forSeconds:1) wait.
   310         (Delay forSeconds:1) wait.
   309 	v cursor:(Cursor wait).
   311         v cursor:(Cursor wait).
   310      ]
   312      ]
   311     "
   313     "
   312 
   314 
   313     "Created: 14.12.1995 / 21:28:00 / cg"
   315     "Created: 14.12.1995 / 21:28:00 / cg"
       
   316     "Modified: 12.12.1996 / 14:08:22 / cg"
   314 !
   317 !
   315 
   318 
   316 withCursor:aCursor do:aBlock
   319 withCursor:aCursor do:aBlock
   317     "evaluate aBlock showing aCursor until ready; then restore the old cursor
   320     "evaluate aBlock showing aCursor until ready; then restore the old cursor
   318      and return the value as returned by aBlock.
   321      and return the value as returned by aBlock.
  1529     "return the object selection - either the local one, or the displays
  1532     "return the object selection - either the local one, or the displays
  1530      selection buffer."
  1533      selection buffer."
  1531 
  1534 
  1532     |sel|
  1535     |sel|
  1533 
  1536 
  1534 "/    sel := Smalltalk at:#CopyBuffer.
       
  1535     sel := device getCopyBuffer.
  1537     sel := device getCopyBuffer.
  1536     sel isNil ifTrue:[
  1538     sel isNil ifTrue:[
  1537         sel := device getSelectionFor:drawableId.
  1539         sel := device getSelectionFor:drawableId.
  1538         sel isNil ifTrue:[^ nil].
  1540         sel isNil ifTrue:[^ nil].
  1539     ].
  1541     ].
  1540     ^ sel
  1542     ^ sel
  1541 
  1543 
  1542     "Modified: 11.12.1996 / 13:49:50 / cg"
  1544     "Modified: 12.12.1996 / 14:08:48 / cg"
  1543 !
  1545 !
  1544 
  1546 
  1545 getTextSelection
  1547 getTextSelection
  1546     "return the text selection - either the local one, or the displays
  1548     "return the text selection - either the local one, or the displays
  1547      selection buffer."
  1549      selection buffer."
  1548 
  1550 
  1549     |sel|
  1551     |sel|
  1550 
  1552 
  1551 "/    sel := Smalltalk at:#CopyBuffer.
       
  1552     sel := device getCopyBuffer.
  1553     sel := device getCopyBuffer.
  1553     sel isNil ifTrue:[
  1554     sel isNil ifTrue:[
  1554         sel := device getTextSelectionFor:drawableId.
  1555         sel := device getTextSelectionFor:drawableId.
  1555         sel isNil ifTrue:[^ nil].
  1556         sel isNil ifTrue:[^ nil].
  1556     ].
  1557     ].
  1557     ^ sel
  1558     ^ sel
  1558 
  1559 
  1559     "Modified: 11.12.1996 / 13:49:57 / cg"
  1560     "Modified: 12.12.1996 / 14:08:52 / cg"
  1560 !
  1561 !
  1561 
  1562 
  1562 selectionAsString
  1563 selectionAsString
  1563     "our current selection as a string"
  1564     "our current selection as a string"
  1564 
  1565 
  1565     |o s|
  1566     |o s|
  1566 
  1567 
  1567 "/    o := Smalltalk at:#CopyBuffer.
       
  1568     o := device getCopyBuffer.
  1568     o := device getCopyBuffer.
  1569     s := o.
  1569     s := o.
  1570     o isString ifFalse:[
  1570     o isString ifFalse:[
  1571         o isNil ifTrue:[
  1571         o isNil ifTrue:[
  1572             s := ''
  1572             s := ''
  1583             ]
  1583             ]
  1584         ]
  1584         ]
  1585     ].
  1585     ].
  1586     ^ s
  1586     ^ s
  1587 
  1587 
  1588     "Modified: 11.12.1996 / 13:50:09 / cg"
  1588     "Modified: 12.12.1996 / 14:08:55 / cg"
  1589 !
  1589 !
  1590 
  1590 
  1591 selectionClear:selectionID
  1591 selectionClear:selectionID
  1592     "someone else has the selection"
  1592     "someone else has the selection"
  1593 
  1593 
  1594     "
  1594     "
  1595      workaround a bug in olvwm: it clears selections
  1595      workaround a bug in olvwm: it clears selections
  1596      on window raise. In this case, keep my last own selection
  1596      on window raise. In this case, keep my last own selection
  1597     "
  1597     "
  1598 
  1598 
  1599 "/    Smalltalk at:#LastCopyBuffer put:(Smalltalk at:#CopyBuffer).
       
  1600     device setLastCopyBuffer:(device getCopyBuffer).
  1599     device setLastCopyBuffer:(device getCopyBuffer).
  1601 "/    Smalltalk at:#CopyBuffer put:nil.
       
  1602     device setCopyBuffer:nil
  1600     device setCopyBuffer:nil
  1603 
  1601 
  1604     "Modified: 11.12.1996 / 13:52:28 / cg"
  1602     "Modified: 12.12.1996 / 14:09:01 / cg"
  1605 !
  1603 !
  1606 
  1604 
  1607 selectionNotify:propertyID target:targetID selection:selectionID from:windowID
  1605 selectionNotify:propertyID target:targetID selection:selectionID from:windowID
  1608     "this is sent from the display as a reply to a request for a
  1606     "this is sent from the display as a reply to a request for a
  1609      selection. The view should be prepared to paste the received
  1607      selection. The view should be prepared to paste the received
  1615      it looses selection when bringing a view
  1613      it looses selection when bringing a view
  1616      up front
  1614      up front
  1617     "
  1615     "
  1618     propertyID == 0 ifTrue:[
  1616     propertyID == 0 ifTrue:[
  1619         "invalid olvwm behavior"
  1617         "invalid olvwm behavior"
  1620 "/        s := Smalltalk at:#LastCopyBuffer
       
  1621         s := device getLastCopyBuffer
  1618         s := device getLastCopyBuffer
  1622     ] ifFalse:[
  1619     ] ifFalse:[
  1623         targetID == (device atomIDOfSTRING) ifTrue:[
  1620         targetID == (device atomIDOfSTRING) ifTrue:[
  1624             "
  1621             "
  1625              a returned string
  1622              a returned string
  1639     ].
  1636     ].
  1640     s notNil ifTrue:[
  1637     s notNil ifTrue:[
  1641         self paste:s
  1638         self paste:s
  1642     ]
  1639     ]
  1643 
  1640 
  1644     "Modified: 11.12.1996 / 13:52:54 / cg"
  1641     "Modified: 12.12.1996 / 14:09:06 / cg"
  1645 !
  1642 !
  1646 
  1643 
  1647 selectionRequest:propertyID target:targetID selection:selectionID from:windowID
  1644 selectionRequest:propertyID target:targetID selection:selectionID from:windowID
  1648     "someone asks for our selection"
  1645     "someone asks for our selection"
  1649 
  1646 
  1681             from:drawableId 
  1678             from:drawableId 
  1682             to:windowID.
  1679             to:windowID.
  1683         ^ self
  1680         ^ self
  1684     ].
  1681     ].
  1685 
  1682 
  1686 "/    o := Smalltalk at:#CopyBuffer.
       
  1687     o := device getCopyBuffer.
  1683     o := device getCopyBuffer.
  1688     stream := WriteStream on:(ByteArray new:200).
  1684     stream := WriteStream on:(ByteArray new:200).
  1689     o storeBinaryOn:stream.
  1685     o storeBinaryOn:stream.
  1690     device 
  1686     device 
  1691         sendSelection:(stream contents) 
  1687         sendSelection:(stream contents) 
  1692         property:propertyID 
  1688         property:propertyID 
  1693         target:(device atomIDOf:'ST_OBJECT' create:true) 
  1689         target:(device atomIDOf:'ST_OBJECT' create:true) 
  1694         from:drawableId 
  1690         from:drawableId 
  1695         to:windowID
  1691         to:windowID
  1696 
  1692 
  1697     "Modified: 11.12.1996 / 13:53:13 / cg"
  1693     "Modified: 12.12.1996 / 14:09:11 / cg"
  1698 !
  1694 !
  1699 
  1695 
  1700 setSelection:something
  1696 setSelection:something
  1701     "set the object selection - both the local one, and tell the display
  1697     "set the object selection - both the local one, and tell the display
  1702      that we have changed it."
  1698      that we have changed it."
  1703 
  1699 
  1704 "/    Smalltalk at:#LastCopyBuffer put:nil.
       
  1705     device setLastCopyBuffer:nil.
  1700     device setLastCopyBuffer:nil.
  1706 "/    Smalltalk at:#CopyBuffer put:something.
       
  1707     device setCopyBuffer:something.
  1701     device setCopyBuffer:something.
  1708     (device setSelection:something owner:drawableId) ifFalse:[
  1702     (device setSelection:something owner:drawableId) ifFalse:[
  1709         'PSEUDOVIEW: selection failed' errorPrintNL
  1703         'DSURFACE: selection failed' errorPrintNL
  1710     ]
  1704     ]
  1711 
  1705 
  1712     "Modified: 11.12.1996 / 13:53:45 / cg"
  1706     "Modified: 12.12.1996 / 14:09:17 / cg"
  1713 !
  1707 !
  1714 
  1708 
  1715 setTextSelection:something
  1709 setTextSelection:something
  1716     "set the text selection - both the local one, and tell the display
  1710     "set the text selection - both the local one, and tell the display
  1717      that we have changed it."
  1711      that we have changed it."
  1718 
  1712 
  1719     |s|
  1713     |s|
  1720 
  1714 
  1721 "/    Smalltalk at:#LastCopyBuffer put:nil.
       
  1722     device setLastCopyBuffer:nil.
  1715     device setLastCopyBuffer:nil.
  1723 "/    Smalltalk at:#CopyBuffer put:something.
       
  1724     device setCopyBuffer:something.
  1716     device setCopyBuffer:something.
  1725     s := something.
  1717     s := something.
  1726     s isString ifFalse:[
  1718     s isString ifFalse:[
  1727         s := s asStringWithCRsFrom:1 to:(s size) compressTabs:false withCR:false
  1719         s := s asStringWithCRsFrom:1 to:(s size) compressTabs:false withCR:false
  1728     ].
  1720     ].
  1729     (device setTextSelection:s owner:drawableId) ifFalse:[
  1721     (device setTextSelection:s owner:drawableId) ifFalse:[
  1730         'PSEUDOVIEW: selection failed' errorPrintNL
  1722         'DSURFACE: selection failed' errorPrintNL
  1731     ]
  1723     ]
  1732 
  1724 
  1733     "Modified: 11.12.1996 / 13:54:19 / cg"
  1725     "Modified: 12.12.1996 / 14:08:38 / cg"
  1734 ! !
  1726 ! !
  1735 
  1727 
  1736 !DisplaySurface methodsFor:'user notification'!
  1728 !DisplaySurface methodsFor:'user notification'!
  1737 
  1729 
  1738 beep
  1730 beep
  1754 ! !
  1746 ! !
  1755 
  1747 
  1756 !DisplaySurface class methodsFor:'documentation'!
  1748 !DisplaySurface class methodsFor:'documentation'!
  1757 
  1749 
  1758 version
  1750 version
  1759     ^ '$Header: /cvs/stx/stx/libview/DisplaySurface.st,v 1.13 1996-12-11 14:39:58 cg Exp $'
  1751     ^ '$Header: /cvs/stx/stx/libview/DisplaySurface.st,v 1.14 1996-12-12 13:09:37 cg Exp $'
  1760 ! !
  1752 ! !