Cursor.st
changeset 2841 d6894d63291f
parent 2626 dae14cd01925
child 2844 4cdd25ab106e
equal deleted inserted replaced
2840:c8f5ba536263 2841:d6894d63291f
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 Object subclass:#Cursor
    13 Object subclass:#Cursor
    14 	instanceVariableNames:'shape sourceForm maskForm hotX hotY device cursorId'
    14 	instanceVariableNames:'shape sourceForm maskForm hotX hotY device cursorId'
    15 	classVariableNames:'Lobby DefaultFgColor DefaultBgColor NormalCursor HandCursor
    15 	classVariableNames:'DefaultFgColor DefaultBgColor NormalCursor HandCursor ArrowCursor
    16 		ArrowCursor WaitCursor CrossHairCursor OriginCursor CornerCursor
    16 		WaitCursor CrossHairCursor OriginCursor CornerCursor SquareCursor
    17 		SquareCursor FourWayCursor UpDownArrowCursor LeftRightArrowCursor
    17 		FourWayCursor UpDownArrowCursor LeftRightArrowCursor
    18 		ThumbsUpCursor ThumbsDownCursor ReadCursor WriteCursor XeqCursor
    18 		ThumbsUpCursor ThumbsDownCursor ReadCursor WriteCursor XeqCursor
    19 		StopCursor EyeCursor BlankCursor MarkerCursor UpCursor DownCursor
    19 		StopCursor EyeCursor BlankCursor MarkerCursor UpCursor DownCursor
    20 		LeftCursor RightCursor XMarkerCursor CaretCursor
    20 		LeftCursor RightCursor XMarkerCursor CaretCursor
    21 		UpRightHandCursor DocumentCursor FolderCursor CrossCursor
    21 		UpRightHandCursor DocumentCursor FolderCursor CrossCursor
    22 		QuestionMarkCursor LeftHandCursor'
    22 		QuestionMarkCursor LeftHandCursor'
   356 !Cursor class methodsFor:'initialization'!
   356 !Cursor class methodsFor:'initialization'!
   357 
   357 
   358 flushDeviceCursors
   358 flushDeviceCursors
   359     "unassign all cursors from their device"
   359     "unassign all cursors from their device"
   360 
   360 
   361     Lobby notNil ifTrue:[
   361     DeviceWorkstation allScreens do:[:aDevice |
   362 	Lobby do:[:aCursor |
   362         aDevice releaseDeviceCursors
   363 	    aCursor restored.
   363     ].
   364 	    Lobby registerChange:aCursor
   364 
   365 	]
   365 "/    Lobby notNil ifTrue:[
   366     ]
   366 "/        Lobby do:[:aCursor |
       
   367 "/            aCursor restored.
       
   368 "/            Lobby registerChange:aCursor
       
   369 "/        ]
       
   370 "/    ]
   367 !
   371 !
   368 
   372 
   369 initialize
   373 initialize
   370     Lobby isNil ifTrue:[
   374 "/    Lobby isNil ifTrue:[
   371         Lobby := Registry new.
   375 "/        Lobby := Registry new.
   372 
   376 "/    ].
   373         "want to be informed when returning from snapshot"
   377 
   374         ObjectMemory addDependent:self.
   378     "want to be informed when returning from snapshot"
   375     ]
   379     ObjectMemory addDependent:self.
   376 
   380 
   377     "Modified: / 28.4.1999 / 15:14:14 / cg"
   381     "Modified: / 28.4.1999 / 15:14:14 / cg"
   378 !
   382 !
   379 
   383 
   380 initializeNewCursors
   384 initializeNewCursors
  1808 shape:aShape 
  1812 shape:aShape 
  1809     "return one of the standard cursors.
  1813     "return one of the standard cursors.
  1810      Each display may offer different shapes - see for example XWorkstation
  1814      Each display may offer different shapes - see for example XWorkstation
  1811      for details (however a basic minimum set should be supported by all)"
  1815      for details (however a basic minimum set should be supported by all)"
  1812 
  1816 
  1813     |newCursor|
  1817     ^ self basicNew setShape:aShape.
  1814 
  1818 
  1815     "first look if not already known"
  1819 "/    |newCursor|
  1816     Lobby isNil ifTrue:[
  1820 "/
  1817 	self initialize
  1821 "/    "first look if not already known"
  1818     ].
  1822 "/
  1819     Lobby do:[:aCursor |
  1823 "/    Lobby isNil ifTrue:[
  1820 	(aCursor shape == aShape) ifTrue:[
  1824 "/        self initialize
  1821 	    ^ aCursor
  1825 "/    ].
  1822 	]
  1826 "/    Lobby do:[:aCursor |
  1823     ].
  1827 "/        (aCursor shape == aShape) ifTrue:[
  1824     newCursor := self basicNew setShape:aShape.
  1828 "/            ^ aCursor
  1825     Lobby register:newCursor.
  1829 "/        ]
  1826     ^ newCursor
  1830 "/    ].
       
  1831 "/    newCursor := self basicNew setShape:aShape.
       
  1832 "/    Lobby register:newCursor.
       
  1833 "/    ^ newCursor
  1827 !
  1834 !
  1828 
  1835 
  1829 shape:aShape on:aDevice
  1836 shape:aShape on:aDevice
  1830     "return one of the standard cursors already associated to aDevice.
  1837     "return one of the standard cursors already associated to aDevice.
  1831      This is the same as '(Cursor shape:aShape) on:aDevice' but somwehat faster."
  1838      This is the same as '(Cursor shape:aShape) on:aDevice' but somwehat faster."
  1832 
  1839 
  1833     |newCursor oldCursor|
       
  1834 
       
  1835     "first look if not already known"
  1840     "first look if not already known"
  1836     Lobby isNil ifTrue:[
  1841 
  1837 	self initialize
  1842     aDevice deviceCursors do:[:aCursor |
  1838     ].
  1843         aCursor shape == aShape ifTrue:[
  1839     Lobby do:[:aCursor |
  1844             ^ aCursor
  1840 	(aCursor shape == aShape) ifTrue:[
  1845         ]
  1841 	    (aCursor graphicsDevice == aDevice) ifTrue:[^ aCursor].
  1846     ].
  1842 	    oldCursor := aCursor
  1847 
  1843 	].
  1848     ^ (self basicNew setShape:aShape) onDevice:aDevice
  1844     ].
       
  1845 
       
  1846     "found one with same shape, but different device"
       
  1847     oldCursor notNil ifTrue:[
       
  1848 	^ oldCursor newOn:aDevice
       
  1849     ].
       
  1850 
       
  1851     newCursor := self basicNew setShape:aShape.
       
  1852     Lobby register:newCursor.
       
  1853     ^ newCursor
       
  1854 
       
  1855     "Modified: 5.7.1996 / 17:58:06 / cg"
       
  1856 !
  1849 !
  1857 
  1850 
  1858 sourceForm:aForm
  1851 sourceForm:aForm
  1859     "return a new cursor.
  1852     "return a new cursor.
  1860      Source- and mask-Bits are taken from aForm; hotSpot is center"
  1853      Source- and mask-Bits are taken from aForm; hotSpot is center"
  1883 !
  1876 !
  1884 
  1877 
  1885 sourceForm:sourceForm maskForm:maskForm hotX:hotX hotY:hotY
  1878 sourceForm:sourceForm maskForm:maskForm hotX:hotX hotY:hotY
  1886     "return a new cursor"
  1879     "return a new cursor"
  1887 
  1880 
  1888     |newCursor|
       
  1889 
       
  1890     "first look if not already known"
       
  1891     Lobby isNil ifTrue:[
       
  1892 	self initialize
       
  1893     ].
       
  1894     Lobby do:[:aCursor |
       
  1895 	(aCursor sourceForm == sourceForm) ifTrue:[
       
  1896 	    (aCursor maskForm == maskForm) ifTrue:[
       
  1897 		(aCursor hotX == hotX) ifTrue:[
       
  1898 		    (aCursor hotY == hotY) ifTrue:[
       
  1899 			^ aCursor
       
  1900 		    ]
       
  1901 		]
       
  1902 	    ]
       
  1903 	]
       
  1904     ].
       
  1905     (sourceForm isNil or:[maskForm isNil]) ifTrue:[^ nil].
  1881     (sourceForm isNil or:[maskForm isNil]) ifTrue:[^ nil].
  1906 
  1882 
  1907     newCursor := self basicNew setSourceForm:sourceForm 
  1883     ^ self basicNew 
  1908 				    maskForm:maskForm
  1884         setSourceForm:sourceForm 
  1909 					hotX:hotX
  1885         maskForm:maskForm
  1910 					hotY:hotY.
  1886         hotX:hotX
  1911     Lobby register:newCursor.
  1887         hotY:hotY.
  1912     ^ newCursor
       
  1913 ! !
       
  1914 
       
  1915 !Cursor class methodsFor:'cleanup'!
       
  1916 
       
  1917 releaseResourcesOnDevice:aDevice
       
  1918     "this is sent when a display connection is closed,
       
  1919      to release all cached Cursors from that device"
       
  1920 
       
  1921     Lobby unregisterAllForWhich:[:aCursor | aCursor graphicsDevice == aDevice]
       
  1922 
       
  1923     "Created: 16.1.1997 / 16:43:59 / cg"
       
  1924 ! !
  1888 ! !
  1925 
  1889 
  1926 !Cursor class methodsFor:'default access'!
  1890 !Cursor class methodsFor:'default access'!
  1927 
  1891 
  1928 defaultFgColor:fgColor defaultBgColor:bgColor
  1892 defaultFgColor:fgColor defaultBgColor:bgColor
  2723 
  2687 
  2724 onDevice:aDevice
  2688 onDevice:aDevice
  2725     "create a new Cursor representing the same cursor as
  2689     "create a new Cursor representing the same cursor as
  2726      myself on aDevice; if one already exists, return the one"
  2690      myself on aDevice; if one already exists, return the one"
  2727 
  2691 
  2728     aDevice isNil ifTrue:[
  2692     |newCursor|
  2729 	"this may not happen"
       
  2730 	self error:'nil device'
       
  2731     ].
       
  2732 
  2693 
  2733     "if I am already assigned to that device ..."
  2694     "if I am already assigned to that device ..."
  2734     (device == aDevice) ifTrue:[^ self].
  2695     (device == aDevice) ifTrue:[^ self].
       
  2696     aDevice isNil ifTrue:[
       
  2697         "this may not happen"
       
  2698         self error:'nil device'
       
  2699     ].
  2735 
  2700 
  2736     "first look if not already there"
  2701     "first look if not already there"
  2737     Lobby do:[:aCursor |
  2702     aDevice deviceCursors do:[:aCursor |
  2738 	(aCursor graphicsDevice == aDevice) ifTrue:[
  2703         shape notNil ifTrue:[
  2739 	    shape notNil ifTrue:[
  2704             (aCursor shape == shape) ifTrue:[
  2740 		(aCursor shape == shape) ifTrue:[
  2705                 ^ aCursor
  2741 		    ^ aCursor
  2706             ]
  2742 		]
  2707         ] ifFalse:[
  2743 	    ] ifFalse:[
  2708             (aCursor sourceForm == sourceForm) ifTrue:[
  2744 		(aCursor sourceForm == sourceForm) ifTrue:[
  2709                 (aCursor maskForm == maskForm) ifTrue:[
  2745 		    (aCursor maskForm == maskForm) ifTrue:[
  2710                     (aCursor hotX == hotX) ifTrue:[
  2746 			(aCursor hotX == hotX) ifTrue:[
  2711                         (aCursor hotY == hotY) ifTrue:[
  2747 			    (aCursor hotY == hotY) ifTrue:[
  2712                             ^ aCursor
  2748 				^ aCursor
  2713                         ]
  2749 			    ]
  2714                     ]
  2750 			]
  2715                 ]
  2751 		    ]
  2716             ]
  2752 		]
  2717         ]
  2753 	    ]
  2718     ].
  2754 	]
  2719 
  2755     ].
  2720     device isNil ifTrue:[
  2756     ^ self newOn:aDevice
  2721         ^ self allocateOnDevice:aDevice
       
  2722     ].
       
  2723     newCursor := self shallowCopy.
       
  2724     newCursor setDevice:nil id:nil.
       
  2725     ^ newCursor allocateOnDevice:aDevice
  2757 
  2726 
  2758     "Modified: 5.7.1996 / 17:58:00 / cg"
  2727     "Modified: 5.7.1996 / 17:58:00 / cg"
  2759     "Created: 28.3.1997 / 13:46:38 / cg"
  2728     "Created: 28.3.1997 / 13:46:38 / cg"
  2760 ! !
  2729 ! !
  2761 
  2730 
  2781     "Modified: 20.4.1996 / 23:23:19 / cg"
  2750     "Modified: 20.4.1996 / 23:23:19 / cg"
  2782 ! !
  2751 ! !
  2783 
  2752 
  2784 !Cursor methodsFor:'private'!
  2753 !Cursor methodsFor:'private'!
  2785 
  2754 
  2786 device:aDevice
  2755 allocateOnDevice:aDevice
  2787     "set the cursors device"
       
  2788 
       
  2789     device := aDevice
       
  2790 !
       
  2791 
       
  2792 id:anId
       
  2793     "set the cursors id"
       
  2794 
       
  2795     cursorId := anId
       
  2796 !
       
  2797 
       
  2798 newOn:aDevice
       
  2799     "create a new Cursor representing the same cursor as
  2756     "create a new Cursor representing the same cursor as
  2800      myself on aDevice. Dont search the lobby."
  2757      myself on aDevice. Dont search the lobby."
  2801 
  2758 
  2802     |newCursor id sF mF w h deviceSf deviceMf|
  2759     |newCursor id sF mF w h deviceSf deviceMf|
       
  2760 
       
  2761     device notNil ifTrue:[
       
  2762         self halt:'should not happen'.
       
  2763         device unregisterCursor:self.
       
  2764         device := cursorId := nil.
       
  2765     ].
  2803 
  2766 
  2804     "ask that device for the cursor"
  2767     "ask that device for the cursor"
  2805     shape notNil ifTrue:[
  2768     shape notNil ifTrue:[
  2806         id := aDevice createCursorShape:shape.
  2769         id := aDevice createCursorShape:shape.
  2807         id isNil ifTrue:[
  2770         id isNil ifTrue:[
  2852     DefaultFgColor notNil ifTrue:[
  2815     DefaultFgColor notNil ifTrue:[
  2853         aDevice colorCursor:id foreground:DefaultFgColor
  2816         aDevice colorCursor:id foreground:DefaultFgColor
  2854                                background:DefaultBgColor
  2817                                background:DefaultBgColor
  2855     ].
  2818     ].
  2856 
  2819 
  2857     device isNil ifTrue:[
  2820     device := aDevice.
  2858         "receiver was not associated - do it now"
  2821     cursorId := id.
  2859         device := aDevice.
  2822     sourceForm := deviceSf.
  2860         cursorId := id.
  2823     maskForm := deviceMf.
  2861         sourceForm := deviceSf.
  2824 
  2862         maskForm := deviceMf.
  2825     "must register"
  2863 
  2826     device registerCursor:self.
  2864         "must re-register, the old registration had a nil cursorId in it"
  2827     ^ self
  2865         Lobby registerChange:self.
  2828 !
  2866         ^ self
  2829 
  2867     ].
  2830 device:aDevice
  2868 
  2831     "set the cursors device"
  2869     "receiver was already associated to another device - need a new cursor"
  2832 
  2870     newCursor := self class basicNew.
  2833     device := aDevice
  2871     shape notNil ifTrue:[
  2834 !
  2872         newCursor setShape:shape.
  2835 
  2873     ] ifFalse:[
  2836 id:anId
  2874         newCursor setSourceForm:deviceSf
  2837     "set the cursors id"
  2875                        maskForm:deviceMf
  2838 
  2876                            hotX:hotX
  2839     cursorId := anId
  2877                            hotY:hotY
       
  2878     ].
       
  2879     newCursor setDevice:aDevice id:id.
       
  2880     Lobby register:newCursor.
       
  2881     ^ newCursor
       
  2882 
       
  2883     "Modified: 10.1.1997 / 19:08:20 / cg"
       
  2884 !
  2840 !
  2885 
  2841 
  2886 restored
  2842 restored
  2887     "set both device and id"
  2843     "set both device and id"
  2888 
  2844 
  2923 ! !
  2879 ! !
  2924 
  2880 
  2925 !Cursor class methodsFor:'documentation'!
  2881 !Cursor class methodsFor:'documentation'!
  2926 
  2882 
  2927 version
  2883 version
  2928     ^ '$Header: /cvs/stx/stx/libview/Cursor.st,v 1.71 1999-05-03 17:12:39 cg Exp $'
  2884     ^ '$Header: /cvs/stx/stx/libview/Cursor.st,v 1.72 1999-08-18 17:22:38 cg Exp $'
  2929 ! !
  2885 ! !
  2930 Cursor initialize!
  2886 Cursor initialize!