WinWorkstation.st
changeset 8887 341943f4a94f
parent 8881 385a6800e902
child 8888 3314cdb1cb9a
equal deleted inserted replaced
8886:eded150affe4 8887:341943f4a94f
  6264     "
  6264     "
  6265      WinWorkstation initializeStandardColorNames
  6265      WinWorkstation initializeStandardColorNames
  6266     "
  6266     "
  6267 ! !
  6267 ! !
  6268 
  6268 
       
  6269 !WinWorkstation class methodsFor:'actions'!
       
  6270 
       
  6271 commonSetDpiAwareModeForExpeccoBinaries:dpiAwareMode
       
  6272     |currentBinary otherBinary 
       
  6273      registryKeyForDpiAware|
       
  6274 
       
  6275     currentBinary := OperatingSystem pathOfSTXExecutable asFilename.
       
  6276     currentBinary suffix asLowercase = 'exe' ifTrue:[
       
  6277         otherBinary := currentBinary withSuffix:'com'. 
       
  6278     ] ifFalse:[
       
  6279         otherBinary := currentBinary withSuffix:'exe'. 
       
  6280     ].
       
  6281 
       
  6282     registryKeyForDpiAware := self registryKeyForHighDpiAware. 
       
  6283 
       
  6284     (Array
       
  6285         with:currentBinary
       
  6286         with:otherBinary) do:[:eachBinaryFilename |
       
  6287             registryKeyForDpiAware
       
  6288                 valueNamed:eachBinaryFilename nameString 
       
  6289                 put:dpiAwareMode.
       
  6290         ].
       
  6291 
       
  6292     "Created: / 25-11-2019 / 09:43:56 / Stefan Reise"
       
  6293 !
       
  6294 
       
  6295 setHighDpiAware
       
  6296     "after set this key,
       
  6297      the next started stx/expecco instance will not be scaled by windows
       
  6298      you can check for success by inspect the binary properties 
       
  6299      via windows context menu of the binary"
       
  6300 
       
  6301     "
       
  6302         self unsetHighDpiAware.    
       
  6303         self isApplicationHighDpiAware.
       
  6304         self setHighDpiAware.          
       
  6305         self isApplicationHighDpiAware.   
       
  6306     "
       
  6307 
       
  6308     self commonSetDpiAwareModeForExpeccoBinaries:self registryValueForHighDpiAware.
       
  6309 
       
  6310     "Created: / 25-11-2019 / 09:44:30 / Stefan Reise"
       
  6311 !
       
  6312 
       
  6313 unsetHighDpiAware
       
  6314     "after unset this key,
       
  6315      the next started stx/expecco instance will be scaled by windows
       
  6316      you can check for success by inspect the binary properties 
       
  6317      via windows context menu of the binary"
       
  6318 
       
  6319     "
       
  6320         self unsetHighDpiAware.    
       
  6321         self isApplicationHighDpiAware.
       
  6322         self setHighDpiAware.          
       
  6323         self isApplicationHighDpiAware.
       
  6324     "
       
  6325 
       
  6326     self commonSetDpiAwareModeForExpeccoBinaries:self regitsryValueForHighDpiUnAware.
       
  6327 
       
  6328     "Created: / 25-11-2019 / 09:44:55 / Stefan Reise"
       
  6329 ! !
       
  6330 
       
  6331 !WinWorkstation class methodsFor:'constants'!
       
  6332 
       
  6333 registryValueForHighDpiAware
       
  6334     ^ '~HIGHDPIAWARE'
       
  6335 
       
  6336     "Created: / 25-11-2019 / 09:52:25 / Stefan Reise"
       
  6337 !
       
  6338 
       
  6339 regitsryValueForHighDpiUnAware
       
  6340     ^ '~DPIUNAWARE'
       
  6341 
       
  6342     "Created: / 25-11-2019 / 09:53:30 / Stefan Reise"
       
  6343 ! !
       
  6344 
  6269 !WinWorkstation class methodsFor:'converting'!
  6345 !WinWorkstation class methodsFor:'converting'!
  6270 
  6346 
  6271 convertVirtualResolutionPointToCurrentResolutionPoint:aPoint
  6347 convertVirtualResolutionPointToCurrentResolutionPoint:aPoint
  6272     "
  6348     "
  6273         self convertVirtualResolutionPointToCurrentResolutionPoint:2000@400    
  6349         self convertVirtualResolutionPointToCurrentResolutionPoint:2000@400    
  6661     "Created: / 22-11-2019 / 10:37:55 / Stefan Reise"
  6737     "Created: / 22-11-2019 / 10:37:55 / Stefan Reise"
  6662 ! !
  6738 ! !
  6663 
  6739 
  6664 !WinWorkstation class methodsFor:'queries'!
  6740 !WinWorkstation class methodsFor:'queries'!
  6665 
  6741 
       
  6742 isApplicationHighDpiAware
       
  6743     "just the query if stx/expecco is high dpi aware,
       
  6744      if not: windows does scale expecco"
       
  6745 
       
  6746     "
       
  6747         self isApplicationHighDpiAware        
       
  6748     "
       
  6749 
       
  6750     ^ (self registryKeyForHighDpiAware 
       
  6751         valueNamed:OperatingSystem pathOfSTXExecutable)
       
  6752             = self registryValueForHighDpiAware
       
  6753 
       
  6754     "Created: / 25-11-2019 / 09:55:34 / Stefan Reise"
       
  6755 !
       
  6756 
  6666 isWindowsPlatform
  6757 isWindowsPlatform
  6667     "return true, if this device is a windows screen"
  6758     "return true, if this device is a windows screen"
  6668 
  6759 
  6669     ^ true
  6760     ^ true
  6670 !
  6761 !
  6675      WinWorkstation always returns 'WIN32'."
  6766      WinWorkstation always returns 'WIN32'."
  6676 
  6767 
  6677     ^ 'WIN32'
  6768     ^ 'WIN32'
  6678 
  6769 
  6679     "Modified: 26.5.1996 / 15:32:46 / cg"
  6770     "Modified: 26.5.1996 / 15:32:46 / cg"
       
  6771 !
       
  6772 
       
  6773 registryKeyForHighDpiAware
       
  6774     "
       
  6775         self registryKeyForHighDpiAware    
       
  6776     "
       
  6777 
       
  6778     ^ Win32OperatingSystem::RegistryEntry
       
  6779         key:'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers'
       
  6780         createIfAbsent:true.
       
  6781 
       
  6782     "Created: / 25-11-2019 / 09:51:45 / Stefan Reise"
  6680 ! !
  6783 ! !
  6681 
  6784 
  6682 !WinWorkstation class methodsFor:'queries - monitor'!
  6785 !WinWorkstation class methodsFor:'queries - monitor'!
  6683 
  6786 
  6684 currentMonitorResolutionByMonitorDeviceName:aMonitorDeviceName
  6787 currentMonitorResolutionByMonitorDeviceName:aMonitorDeviceName
  6693         real current resolution -> 1080p
  6796         real current resolution -> 1080p
  6694         scaling 100%
  6797         scaling 100%
  6695         virtual resolution -> 1080p"         
  6798         virtual resolution -> 1080p"         
  6696 
  6799 
  6697     "
  6800     "
       
  6801         Screen currentMonitorResolutionByMonitorDeviceName:nil.       
       
  6802         Screen currentMonitorResolutionByMonitorDeviceName:'ereswt'.       
  6698         Screen currentMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY1'.       
  6803         Screen currentMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY1'.       
  6699         Screen currentMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY2'.       
  6804         Screen currentMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY2'.       
  6700     "    
  6805     "    
  6701 
  6806 
  6702     |currentX currentY|
  6807     |currentX currentY|
  6703 
  6808 
  6704     aMonitorDeviceName isEmptyOrNil ifTrue:[
  6809     aMonitorDeviceName isEmptyOrNil ifTrue:[
  6705         ^ nil
  6810         "return a default"
       
  6811         ^ Display extent
  6706     ].
  6812     ].
  6707 
  6813 
  6708 %{
  6814 %{
  6709     HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
  6815     HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
  6710     if (hdc == NULL) {
  6816     if (hdc != NULL) {
  6711         RETURN(nil);
  6817         currentX = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPHORZRES));
       
  6818         currentY = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPVERTRES));
       
  6819         DeleteDC(hdc);      
  6712     }                         
  6820     }                         
  6713 
       
  6714     currentX = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPHORZRES));
       
  6715     currentY = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPVERTRES));
       
  6716 
       
  6717     DeleteDC(hdc);      
       
  6718 %}.
  6821 %}.
  6719 
  6822 
       
  6823     currentX isNil ifTrue:[
       
  6824         "return a default"
       
  6825         ^ Display extent
       
  6826     ].
       
  6827 
  6720     ^ currentX@currentY
  6828     ^ currentX@currentY
  6721 
  6829 
  6722     "Created: / 22-11-2019 / 14:25:10 / Stefan Reise"
  6830     "Created: / 22-11-2019 / 14:25:10 / Stefan Reise"
       
  6831     "Modified: / 25-11-2019 / 09:34:50 / Stefan Reise"
  6723 !
  6832 !
  6724 
  6833 
  6725 currentMonitorResolutionByPoint:aPoint
  6834 currentMonitorResolutionByPoint:aPoint
  6726     "this is the current resolution of the display,
  6835     "this is the current resolution of the display,
  6727      without any effect of scaling
  6836      without any effect of scaling
  6743     "    
  6852     "    
  6744 
  6853 
  6745     |monitorName|
  6854     |monitorName|
  6746 
  6855 
  6747     aPoint isNil ifTrue:[
  6856     aPoint isNil ifTrue:[
  6748         ^ nil
  6857         "return a default"    
       
  6858         ^ Display extent
  6749     ].
  6859     ].
  6750 
  6860 
  6751     monitorName := self monitorDeviceNameForPoint:aPoint.
  6861     monitorName := self monitorDeviceNameForPoint:aPoint.
  6752     monitorName isNil ifTrue:[
  6862     monitorName isNil ifTrue:[
  6753         ^ nil
  6863         "return a default"       
       
  6864         ^ Display extent        
  6754     ].
  6865     ].
  6755 
  6866 
  6756     ^ self currentMonitorResolutionByMonitorDeviceName:monitorName
  6867     ^ self currentMonitorResolutionByMonitorDeviceName:monitorName
  6757 
  6868 
  6758     "Created: / 22-11-2019 / 14:26:31 / Stefan Reise"
  6869     "Created: / 22-11-2019 / 14:26:31 / Stefan Reise"
       
  6870     "Modified (format): / 25-11-2019 / 09:35:18 / Stefan Reise"
  6759 !
  6871 !
  6760 
  6872 
  6761 currentMonitorResolutionByView:aView
  6873 currentMonitorResolutionByView:aView
  6762     "this is the current resolution of the display,
  6874     "this is the current resolution of the display,
  6763      without any effect of scaling
  6875      without any effect of scaling
  6777     "    
  6889     "    
  6778 
  6890 
  6779     |monitorName|
  6891     |monitorName|
  6780 
  6892 
  6781     aView isNil ifTrue:[
  6893     aView isNil ifTrue:[
  6782         ^ nil
  6894         "return a default"       
       
  6895         ^ Display extent
  6783     ].
  6896     ].
  6784 
  6897 
  6785     monitorName := self monitorDeviceNameForView:aView.
  6898     monitorName := self monitorDeviceNameForView:aView.
  6786     monitorName isNil ifTrue:[
  6899     monitorName isNil ifTrue:[
  6787         ^ nil
  6900         "return a default"       
       
  6901         ^ Display extent
  6788     ].
  6902     ].
  6789 
  6903 
  6790     ^ self currentMonitorResolutionByMonitorDeviceName:monitorName
  6904     ^ self currentMonitorResolutionByMonitorDeviceName:monitorName
  6791 
  6905 
  6792     "Created: / 22-11-2019 / 14:22:47 / Stefan Reise"
  6906     "Created: / 22-11-2019 / 14:22:47 / Stefan Reise"
       
  6907     "Modified (format): / 25-11-2019 / 09:35:22 / Stefan Reise"
  6793 !
  6908 !
  6794 
  6909 
  6795 monitorDeviceNameForPoint:aPoint
  6910 monitorDeviceNameForPoint:aPoint
  6796     "given a point, return its monitor device name or nil if failed"
  6911     "given a point, return its monitor device name or nil if failed"
  6797 
  6912 
  6864     "Modified: / 21-11-2019 / 18:04:50 / Stefan Reise"
  6979     "Modified: / 21-11-2019 / 18:04:50 / Stefan Reise"
  6865     "Modified (comment): / 22-11-2019 / 10:22:49 / Stefan Reise"
  6980     "Modified (comment): / 22-11-2019 / 10:22:49 / Stefan Reise"
  6866 !
  6981 !
  6867 
  6982 
  6868 scaleFactorForMonitorNamed:aMonitorDeviceName                 
  6983 scaleFactorForMonitorNamed:aMonitorDeviceName                 
  6869     "ATTENTION: returns the may wrong default 1@1 if the package or the tools are missing:
  6984     "ATTENTION: this method always returns the scale factor set by os,
  6870      stx:support/win32/displayResolutionTools/bin/cdr.exe
       
  6871      stx:support/win32/displayResolutionTools/bin/vdr.exe
       
  6872 
       
  6873      ATTENTION: this method always returns the scale factor set by os,
       
  6874      REGARDLESS if the application (stx, expecco) has a virtual resolution or not
  6985      REGARDLESS if the application (stx, expecco) has a virtual resolution or not
  6875      use #scaleFactorForRootViewTranslationOnMonitorNamed: which is dependent on the 
  6986      use #scaleFactorForRootViewTranslationOnMonitorNamed: which is dependent on the 
  6876      application's (stx, expecco) high dpi awareness (if the application has a virtual 
  6987      application's (stx, expecco) high dpi awareness (if the application has a virtual 
  6877      resolution or not).
  6988      resolution or not).
  6878 
  6989 
  6901 
  7012 
  6902     ^ currentMonitorResolution / virtualMonitorResolution
  7013     ^ currentMonitorResolution / virtualMonitorResolution
  6903 
  7014 
  6904     "Created: / 21-11-2019 / 10:12:00 / Stefan Reise"
  7015     "Created: / 21-11-2019 / 10:12:00 / Stefan Reise"
  6905     "Modified: / 22-11-2019 / 15:17:05 / Stefan Reise"
  7016     "Modified: / 22-11-2019 / 15:17:05 / Stefan Reise"
       
  7017     "Modified (comment): / 25-11-2019 / 09:36:06 / Stefan Reise"
  6906 !
  7018 !
  6907 
  7019 
  6908 scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName                 
  7020 scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName                 
  6909     "ATTENTION: returns the may wrong default 1@1 if the package or the tool is missing:
  7021     "ATTENTION: returns the may wrong default 1@1 if the package or the tool is missing:
  6910      stx:support/win32/displayResolutionTools/bin/cdr.exe
  7022      stx:support/win32/displayResolutionTools/bin/cdr.exe
  6971         Screen virtualMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY2'.      
  7083         Screen virtualMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY2'.      
  6972     "    
  7084     "    
  6973 
  7085 
  6974     |virtualX virtualY|
  7086     |virtualX virtualY|
  6975 
  7087 
       
  7088 
       
  7089 
       
  7090 
       
  7091 
  6976     aMonitorDeviceName isEmptyOrNil ifTrue:[
  7092     aMonitorDeviceName isEmptyOrNil ifTrue:[
  6977         ^ nil
  7093         "return a default"
       
  7094         ^ Display extent
  6978     ].
  7095     ].
  6979 
  7096 
  6980 %{
  7097 %{
  6981     HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
  7098     HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
  6982     if (hdc == NULL) {
  7099     if (hdc != NULL) {
  6983         RETURN(nil);
  7100         virtualX = __MKSMALLINT(GetDeviceCaps(hdc, HORZRES));
       
  7101         virtualY = __MKSMALLINT(GetDeviceCaps(hdc, VERTRES)); 
       
  7102         DeleteDC(hdc);
  6984     }                         
  7103     }                         
  6985 
       
  6986     virtualX = __MKSMALLINT(GetDeviceCaps(hdc, HORZRES));
       
  6987     virtualY = __MKSMALLINT(GetDeviceCaps(hdc, VERTRES)); 
       
  6988 
       
  6989     DeleteDC(hdc);
       
  6990 %}.
  7104 %}.
  6991 
  7105 
       
  7106     virtualX isNil ifTrue:[
       
  7107         "return a default"
       
  7108         ^ Display extent
       
  7109     ].
       
  7110 
  6992     ^ virtualX@virtualY
  7111     ^ virtualX@virtualY
  6993 
  7112 
  6994     "Created: / 22-11-2019 / 14:28:41 / Stefan Reise"
  7113     "Created: / 22-11-2019 / 14:28:41 / Stefan Reise"
       
  7114     "Modified (format): / 25-11-2019 / 09:38:42 / Stefan Reise"
  6995 !
  7115 !
  6996 
  7116 
  6997 virtualMonitorResolutionByPoint:aPoint
  7117 virtualMonitorResolutionByPoint:aPoint
  6998     "ATTENTION: this method always returns the virtual resolution,
  7118     "ATTENTION: this method always returns the virtual resolution,
  6999      REGARDLESS if the application (stx, expecco) has a virtual resolution or not
  7119      REGARDLESS if the application (stx, expecco) has a virtual resolution or not
  7018     "    
  7138     "    
  7019 
  7139 
  7020     |monitorName|
  7140     |monitorName|
  7021 
  7141 
  7022     aPoint isNil ifTrue:[
  7142     aPoint isNil ifTrue:[
  7023         ^ nil
  7143         "return a default"
       
  7144         ^ Display extent
  7024     ].
  7145     ].
  7025 
  7146 
  7026     monitorName := self monitorDeviceNameForPoint:aPoint.
  7147     monitorName := self monitorDeviceNameForPoint:aPoint.
  7027     monitorName isNil ifTrue:[
  7148     monitorName isNil ifTrue:[
  7028         ^ nil
  7149         "return a default"
       
  7150         ^ Display extent
  7029     ].
  7151     ].
  7030 
  7152 
  7031     ^ self virtualMonitorResolutionByMonitorDeviceName:monitorName
  7153     ^ self virtualMonitorResolutionByMonitorDeviceName:monitorName
  7032 
  7154 
  7033     "Created: / 22-11-2019 / 14:28:55 / Stefan Reise"
  7155     "Created: / 22-11-2019 / 14:28:55 / Stefan Reise"
       
  7156     "Modified: / 25-11-2019 / 09:37:34 / Stefan Reise"
  7034 !
  7157 !
  7035 
  7158 
  7036 virtualMonitorResolutionByView:aView
  7159 virtualMonitorResolutionByView:aView
  7037     "ATTENTION: this method always returns the virtual resolution,
  7160     "ATTENTION: this method always returns the virtual resolution,
  7038      REGARDLESS if the application (stx, expecco) has a virtual resolution or not
  7161      REGARDLESS if the application (stx, expecco) has a virtual resolution or not
  7055     "    
  7178     "    
  7056 
  7179 
  7057     |monitorName|
  7180     |monitorName|
  7058 
  7181 
  7059     aView isNil ifTrue:[
  7182     aView isNil ifTrue:[
  7060         ^ nil
  7183         "return a default"
       
  7184         ^ Display extent
  7061     ].
  7185     ].
  7062 
  7186 
  7063     monitorName := self monitorDeviceNameForView:aView.
  7187     monitorName := self monitorDeviceNameForView:aView.
  7064     monitorName isNil ifTrue:[
  7188     monitorName isNil ifTrue:[
  7065         ^ nil
  7189         "return a default"
       
  7190         ^ Display extent
  7066     ].
  7191     ].
  7067 
  7192 
  7068     ^ self virtualMonitorResolutionByMonitorDeviceName:monitorName
  7193     ^ self virtualMonitorResolutionByMonitorDeviceName:monitorName
  7069 
  7194 
  7070     "Created: / 22-11-2019 / 14:29:09 / Stefan Reise"
  7195     "Created: / 22-11-2019 / 14:29:09 / Stefan Reise"
       
  7196     "Modified: / 25-11-2019 / 09:37:38 / Stefan Reise"
  7071 ! !
  7197 ! !
  7072 
  7198 
  7073 !WinWorkstation methodsFor:'accessing & queries'!
  7199 !WinWorkstation methodsFor:'accessing & queries'!
  7074 
  7200 
  7075 activateOnClick:aBoolean
  7201 activateOnClick:aBoolean