Browse Source

starting to get ditto working when text is set to be viewed at 125% or 150%

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@653 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 13 years ago
parent
commit
adae143bb4
9 changed files with 126 additions and 22 deletions
  1. 3 0
      CP_Main.h
  2. 8 0
      CP_Main.vcxproj
  3. 7 0
      CP_Main.vcxproj.filters
  4. 9 9
      CP_Main_10.sln
  5. 4 0
      DPI.cpp
  6. 75 0
      DPI.h
  7. 7 0
      DeclareDPIAware.manifest
  8. 2 2
      QListCtrl.cpp
  9. 11 11
      QPasteWnd.cpp

+ 3 - 0
CP_Main.h

@@ -20,6 +20,7 @@
 #include "DittoAddins.h"
 #include "externalwindowtracker.h"
 #include "HotKeys.h"
+#include "DPI.h"
 
 extern class CCP_MainApp theApp;
 
@@ -157,6 +158,8 @@ public:
 
 	CDittoAddins m_Addins;
 
+	CDPI m_metrics;
+
 public:
 	virtual BOOL InitInstance();
 	virtual int ExitInstance();

+ 8 - 0
CP_Main.vcxproj

@@ -307,6 +307,9 @@
       <Command>
       </Command>
     </PostBuildEvent>
+    <Manifest>
+      <AdditionalManifestFiles>DeclareDPIAware.manifest</AdditionalManifestFiles>
+    </Manifest>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="About.cpp">
@@ -547,6 +550,7 @@
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
+    <ClCompile Include="DPI.cpp" />
     <ClCompile Include="EditWithButton.cpp" />
     <ClCompile Include="EventThread.cpp" />
     <ClCompile Include="GlobalClips.cpp" />
@@ -1743,6 +1747,7 @@
     <ClInclude Include="ArrayEx.h" />
     <ClInclude Include="AutoSendToClientThread.h" />
     <ClInclude Include="ClipFormatQListCtrl.h" />
+    <ClInclude Include="DPI.h" />
     <ClInclude Include="EditWithButton.h" />
     <ClInclude Include="EventThread.h" />
     <ClInclude Include="FormattedTextDraw.h" />
@@ -1903,6 +1908,9 @@
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Manifest Include="DeclareDPIAware.manifest" />
+  </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>

+ 7 - 0
CP_Main.vcxproj.filters

@@ -325,6 +325,7 @@
     <ClCompile Include="EditWithButton.cpp">
       <Filter>source</Filter>
     </ClCompile>
+    <ClCompile Include="DPI.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="sqlite\CppSQLite3.h">
@@ -693,6 +694,7 @@
     <ClInclude Include="EditWithButton.h">
       <Filter>header</Filter>
     </ClInclude>
+    <ClInclude Include="DPI.h" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="CP_Main.rc">
@@ -801,4 +803,9 @@
       <UniqueIdentifier>{08b8a44d-887f-48e0-8396-e9e9f573f337}</UniqueIdentifier>
     </Filter>
   </ItemGroup>
+  <ItemGroup>
+    <Manifest Include="DeclareDPIAware.manifest">
+      <Filter>header</Filter>
+    </Manifest>
+  </ItemGroup>
 </Project>

+ 9 - 9
CP_Main_10.sln

@@ -1,6 +1,6 @@
 Microsoft Visual Studio Solution File, Format Version 11.00
 # Visual Studio 2010
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CP_Main", "CP_Main.vcxproj", "{79061F25-7568-DF56-7574-69777BB05183}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CP_Main", "CP_Main.vcxproj", "{86BF16D0-77B0-8955-B18E-4F78C3083D5E}"
 	ProjectSection(ProjectDependencies) = postProject
 		{F08A8736-1116-4166-AF88-CF533E41E958} = {F08A8736-1116-4166-AF88-CF533E41E958}
 		{CF8F6379-5340-4494-8E59-2807ADF37B95} = {CF8F6379-5340-4494-8E59-2807ADF37B95}
@@ -23,14 +23,14 @@ Global
 		Release|x64 = Release|x64
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{79061F25-7568-DF56-7574-69777BB05183}.Debug|Win32.ActiveCfg = Debug|Win32
-		{79061F25-7568-DF56-7574-69777BB05183}.Debug|Win32.Build.0 = Debug|Win32
-		{79061F25-7568-DF56-7574-69777BB05183}.Debug|x64.ActiveCfg = Debug|x64
-		{79061F25-7568-DF56-7574-69777BB05183}.Debug|x64.Build.0 = Debug|x64
-		{79061F25-7568-DF56-7574-69777BB05183}.Release|Win32.ActiveCfg = Release|Win32
-		{79061F25-7568-DF56-7574-69777BB05183}.Release|Win32.Build.0 = Release|Win32
-		{79061F25-7568-DF56-7574-69777BB05183}.Release|x64.ActiveCfg = Release|x64
-		{79061F25-7568-DF56-7574-69777BB05183}.Release|x64.Build.0 = Release|x64
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Debug|Win32.ActiveCfg = Debug|Win32
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Debug|Win32.Build.0 = Debug|Win32
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Debug|x64.ActiveCfg = Debug|x64
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Debug|x64.Build.0 = Debug|x64
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Release|Win32.ActiveCfg = Release|Win32
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Release|Win32.Build.0 = Release|Win32
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Release|x64.ActiveCfg = Release|x64
+		{86BF16D0-77B0-8955-B18E-4F78C3083D5E}.Release|x64.Build.0 = Release|x64
 		{CF8F6379-5340-4494-8E59-2807ADF37B95}.Debug|Win32.ActiveCfg = Debug|Win32
 		{CF8F6379-5340-4494-8E59-2807ADF37B95}.Debug|Win32.Build.0 = Debug|Win32
 		{CF8F6379-5340-4494-8E59-2807ADF37B95}.Debug|x64.ActiveCfg = Debug|x64

+ 4 - 0
DPI.cpp

@@ -0,0 +1,4 @@
+#include "stdafx.h"
+#include "DPI.h"
+
+

+ 75 - 0
DPI.h

@@ -0,0 +1,75 @@
+#pragma once
+// Definition: relative pixel = 1 pixel at 96 DPI and scaled based on actual DPI.
+class CDPI
+{
+public:
+	CDPI() : _fInitialized(false), _dpiX(96), _dpiY(96) { }
+
+	// Get screen DPI.
+	int GetDPIX() { _Init(); return _dpiX; }
+	int GetDPIY() { _Init(); return _dpiY; }
+
+	// Convert between raw pixels and relative pixels.
+	int ScaleX(int x) { _Init(); return MulDiv(x, _dpiX, 96); }
+	int ScaleY(int y) { _Init(); return MulDiv(y, _dpiY, 96); }
+	int UnscaleX(int x) { _Init(); return MulDiv(x, 96, _dpiX); }
+	int UnscaleY(int y) { _Init(); return MulDiv(y, 96, _dpiY); }
+
+	// Determine the screen dimensions in relative pixels.
+	int ScaledScreenWidth() { return _ScaledSystemMetricX(SM_CXSCREEN); }
+	int ScaledScreenHeight() { return _ScaledSystemMetricY(SM_CYSCREEN); }
+
+	// Scale rectangle from raw pixels to relative pixels.
+	void ScaleRect(__inout RECT *pRect)
+	{
+		pRect->left = ScaleX(pRect->left);
+		pRect->right = ScaleX(pRect->right);
+		pRect->top = ScaleY(pRect->top);
+		pRect->bottom = ScaleY(pRect->bottom);
+	}
+	// Determine if screen resolution meets minimum requirements in relative
+	// pixels.
+	bool IsResolutionAtLeast(int cxMin, int cyMin) 
+	{ 
+		return (ScaledScreenWidth() >= cxMin) && (ScaledScreenHeight() >= cyMin); 
+	}
+
+	// Convert a point size (1/72 of an inch) to raw pixels.
+	int PointsToPixels(int pt) { _Init(); return MulDiv(pt, _dpiY, 72); }
+
+	// Invalidate any cached metrics.
+	void Invalidate() { _fInitialized = false; }
+
+private:
+	void _Init()
+	{
+		if (!_fInitialized)
+		{
+			HDC hdc = GetDC(NULL);
+			if (hdc)
+			{
+				_dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
+				_dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
+				ReleaseDC(NULL, hdc);
+			}
+			_fInitialized = true;
+		}
+	}
+
+	int _ScaledSystemMetricX(int nIndex) 
+	{ 
+		_Init(); 
+		return MulDiv(GetSystemMetrics(nIndex), 96, _dpiX); 
+	}
+
+	int _ScaledSystemMetricY(int nIndex) 
+	{ 
+		_Init(); 
+		return MulDiv(GetSystemMetrics(nIndex), 96, _dpiY); 
+	}
+private:
+	bool _fInitialized;
+
+	int _dpiX;
+	int _dpiY;
+};

+ 7 - 0
DeclareDPIAware.manifest

@@ -0,0 +1,7 @@
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
+  <asmv3:application>
+    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
+      <dpiAware>true</dpiAware>
+    </asmv3:windowsSettings>
+  </asmv3:application>
+</assembly>

+ 2 - 2
QListCtrl.cpp

@@ -1410,8 +1410,8 @@ bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
 	CRect crRight(crWindow);
 	CRect crBottom(crWindow);	
 
-	crRight.left = crRight.right - 30;
-	crBottom.top = crBottom.bottom - 30;
+	crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
+	crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
 
 	if(crRight.PtInRect(point) || crBottom.PtInRect(point))
 	{

+ 11 - 11
QPasteWnd.cpp

@@ -228,10 +228,10 @@ int CQPasteWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
     m_search.Create(WS_TABSTOP | WS_CHILD | WS_VISIBLE | ES_MULTILINE, CRect(0, 0, 0, 0), this, ID_EDIT_SEARCH);
 	m_search.SetBitmaps(IDB_BITMAP_SEARCH_NORMAL, IDB_BITMAP_SEARCH_CLOSE);
 
-	CRect rcEditArea(4, 2, 20, 2);
+	CRect rcEditArea(theApp.m_metrics.ScaleX(4), theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(20), theApp.m_metrics.ScaleY(2));
 	m_search.SetBorder(rcEditArea);
 
-	CRect rcCloseArea(85, 3, 99, 15);
+	CRect rcCloseArea(theApp.m_metrics.ScaleX(85), theApp.m_metrics.ScaleY(3), theApp.m_metrics.ScaleX(99), theApp.m_metrics.ScaleY(15));
 	m_search.SetButtonArea(rcCloseArea);
 
     // Create the header control
@@ -324,11 +324,11 @@ void CQPasteWnd::MoveControls()
         m_ShowGroupsFolderTop.ShowWindow(SW_SHOW);
         m_BackButton.ShowWindow(SW_SHOW);
 
-		m_BackButton.MoveWindow(0, 0, 18, 16);
-		m_ShowGroupsFolderTop.MoveWindow(22, 0, 18, 16);
-		m_stGroup.MoveWindow(44, 0, cx, 16);
+		m_BackButton.MoveWindow(0, 0, theApp.m_metrics.ScaleX(18), theApp.m_metrics.ScaleY(16));
+		m_ShowGroupsFolderTop.MoveWindow(theApp.m_metrics.ScaleX(22), 0, theApp.m_metrics.ScaleX(18), theApp.m_metrics.ScaleY(16));
+		m_stGroup.MoveWindow(theApp.m_metrics.ScaleX(44), 0, cx, theApp.m_metrics.ScaleY(16));
 
-		topOfListBox = 16;
+		topOfListBox = theApp.m_metrics.ScaleY(16);
 	}
 	else
 	{
@@ -338,13 +338,13 @@ void CQPasteWnd::MoveControls()
 	}
 
     int nWidth = cx;
-	int listBoxBottomOffset = 24;
-
+	int listBoxBottomOffset = theApp.m_metrics.ScaleY(30);
+	
 	int extraSize = 0;
 
 	if(m_showScrollBars == false)
 	{
-		extraSize = 20;
+		extraSize = ::GetSystemMetrics(SM_CXVSCROLL);
 
 		CRgn rgnRect;
 		CRect r;
@@ -356,9 +356,9 @@ void CQPasteWnd::MoveControls()
 	}
 
 	m_lstHeader.MoveWindow(0, topOfListBox, cx+extraSize, cy - listBoxBottomOffset-topOfListBox + extraSize);
-    m_search.MoveWindow(18, cy - 22, cx - 20, 20);
+    m_search.MoveWindow(theApp.m_metrics.ScaleX(18), cy - theApp.m_metrics.ScaleY(21), cx - theApp.m_metrics.ScaleX(20), theApp.m_metrics.ScaleY(20));
 
-    m_ShowGroupsFolderBottom.MoveWindow(0, cy - 19, 18, 19);
+    m_ShowGroupsFolderBottom.MoveWindow(theApp.m_metrics.ScaleY(2), cy - theApp.m_metrics.ScaleY(15), theApp.m_metrics.ScaleX(18), theApp.m_metrics.ScaleY(19));
 }
 
 void CQPasteWnd::OnSetFocus(CWnd *pOldWnd)