1
0
Эх сурвалжийг харах

- added paste removing line feeds
- save window position when on-top is set
- allow removing group for a clip
- auto roll-up changes, roll up on paste, remove focus, escape
[SAB]

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@536 595ec19a-5cb4-439b-94a8-42fb3063c22c

sabrogden 15 жил өмнө
parent
commit
df3b2962dc

+ 2 - 0
Addins/DittoUtil/DittoUtil.vcxproj

@@ -130,6 +130,7 @@
     <ClCompile Include="PasteAnyAsText.cpp" />
     <ClCompile Include="PasteImageAsHtmlImage.cpp" />
     <ClCompile Include="ReadOnlyFlag.cpp" />
+    <ClCompile Include="RemoveLineFeeds.cpp" />
     <ClCompile Include="SelectPasteFormat.cpp" />
     <ClCompile Include="stdafx.cpp">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@@ -150,6 +151,7 @@
     <ClInclude Include="PasteAnyAsText.h" />
     <ClInclude Include="PasteImageAsHtmlImage.h" />
     <ClInclude Include="ReadOnlyFlag.h" />
+    <ClInclude Include="RemoveLineFeeds.h" />
     <ClInclude Include="Resource.h" />
     <ClInclude Include="SelectPasteFormat.h" />
     <ClInclude Include="stdafx.h" />

+ 18 - 1
Addins/DittoUtil/Exports.cpp

@@ -3,6 +3,7 @@
 #include "PasteAnyAsText.h"
 #include ".\pasteimageashtmlimage.h"
 #include "ReadOnlyFlag.h"
+#include "RemoveLineFeeds.h"
 
 
 bool DittoAddin(const CDittoInfo &DittoInfo, CDittoAddinInfo &info)
@@ -36,7 +37,7 @@ bool SupportedFunctions(const CDittoInfo &DittoInfo, FunctionType type, std::vec
 
 			CFunction func2;
 			func2.m_csFunction = _T("ConvertPathToHtmlImageTag");
-			func2.m_csDisplayName = _T("Past As html image link");
+			func2.m_csDisplayName = _T("Paste As html image link");
 			func2.m_csDetailDescription = _T("Converts a CF_DIB or CF_HDROP to a html format for pasting into outlook express");
 
 			Functions.push_back(func2);
@@ -54,6 +55,13 @@ bool SupportedFunctions(const CDittoInfo &DittoInfo, FunctionType type, std::vec
 			func4.m_csDetailDescription = _T("Sets the read only flag on the types CF_HDROP, or files paths in text");
 
 			Functions.push_back(func4);
+
+			CFunction func5;
+			func5.m_csFunction = _T("RemoveLineFeeds");
+			func5.m_csDisplayName = _T("Paste Removing Line Feeds");
+			func5.m_csDetailDescription = _T("Removes all line feeds from text and rich text entries");
+
+			Functions.push_back(func5);
 		}
 		break;
 	}
@@ -89,3 +97,12 @@ bool SetReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip)
 	//return false so the clip is not pasted
 	return false;
 }
+
+bool RemoveLineFeeds(const CDittoInfo &DittoInfo, IClip *pClip)
+{
+	CRemoveLineFeeds remove;
+
+	bool didSomething = remove.RemoveLineFeeds(DittoInfo, pClip);
+	//return false so the clip is not pasted
+	return didSomething;
+}

+ 1 - 0
Addins/DittoUtil/Exports.h

@@ -12,4 +12,5 @@ extern "C"
 	bool __declspec(dllexport) ConvertPathToHtmlImageTag(const CDittoInfo &DittoInfo, IClip *pClip);
 	bool __declspec(dllexport) ClearReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip);
 	bool __declspec(dllexport) SetReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip);
+	bool __declspec(dllexport) RemoveLineFeeds(const CDittoInfo &DittoInfo, IClip *pClip);
 }

+ 111 - 0
Addins/DittoUtil/RemoveLineFeeds.cpp

@@ -0,0 +1,111 @@
+#include "StdAfx.h"
+#include "RemoveLineFeeds.h"
+
+#include "../../Shared/Tokenizer.h"
+#include "../../Shared/TextConvert.h"
+
+
+CRemoveLineFeeds::CRemoveLineFeeds(void)
+{
+}
+
+
+CRemoveLineFeeds::~CRemoveLineFeeds(void)
+{
+}
+
+bool CRemoveLineFeeds::RemoveLineFeeds(const CDittoInfo &DittoInfo, IClip *pClip)
+{
+	bool didSomething = false;
+	IClipFormats *pFormats = pClip->Clips();
+	if(pFormats)
+	{
+		didSomething = Handle_CF_TEXT(pFormats);
+
+		didSomething |= Handle_CF_UNICODETEXT(pFormats);
+
+		didSomething |= Handle_RichText(pFormats);
+	}
+
+	return didSomething;
+}
+
+bool CRemoveLineFeeds::Handle_CF_TEXT(IClipFormats *pFormats)
+{	
+	bool didSomething = false;
+
+	IClipFormat *pFormat = pFormats->FindFormatEx(CF_TEXT);
+	if(pFormat != NULL)
+	{
+		char *stringData = (char *)GlobalLock(pFormat->Data());
+		if(stringData != NULL)
+		{
+			CStringA string(stringData);
+
+			int count = string.Replace("\r\n", " ");
+
+			int size = GlobalSize(pFormat->Data());
+			strcpy_s(stringData, GlobalSize(pFormat->Data()), string);
+
+			GlobalUnlock(pFormat->Data());
+
+			didSomething = true;
+		}
+	}
+
+	return didSomething;
+}
+
+bool CRemoveLineFeeds::Handle_CF_UNICODETEXT(IClipFormats *pFormats)
+{	
+	bool didSomething = false;
+
+	IClipFormat *pFormat = pFormats->FindFormatEx(CF_UNICODETEXT);
+	if(pFormat != NULL)
+	{
+		wchar_t *stringData = (wchar_t *)GlobalLock(pFormat->Data());
+		if(stringData != NULL)
+		{
+			CStringW string(stringData);
+
+			int count = string.Replace(_T("\r\n"), _T(" "));
+
+			wcscpy_s(stringData, GlobalSize(pFormat->Data())/2, string);
+
+			GlobalUnlock(pFormat->Data());
+
+			didSomething = true;
+		}
+	}
+
+	return didSomething;
+}
+
+bool CRemoveLineFeeds::Handle_RichText(IClipFormats *pFormats)
+{	
+	bool didSomething = false;
+
+	CLIPFORMAT m_RTFFormat = ::RegisterClipboardFormat(_T("Rich Text Format"));
+
+	IClipFormat *pFormat = pFormats->FindFormatEx(m_RTFFormat);
+	if(pFormat != NULL)
+	{
+		char *stringData = (char *)GlobalLock(pFormat->Data());
+		if(stringData != NULL)
+		{
+			CStringA string(stringData);
+
+			int count = string.Replace("\\par\r\n", " ");
+			int count2 = string.Replace("\\par ", " ");
+			int count3 = string.Replace("\\line ", " ");
+
+			strcpy_s(stringData, GlobalSize(pFormat->Data()), string);
+
+			GlobalUnlock(pFormat->Data());
+
+			didSomething = true;
+		}
+	}
+
+	return didSomething;
+}

+ 20 - 0
Addins/DittoUtil/RemoveLineFeeds.h

@@ -0,0 +1,20 @@
+#pragma once
+
+#include "..\..\Shared\DittoDefines.h"
+#include "..\..\Shared\IClip.h"
+
+class CRemoveLineFeeds
+{
+public:
+	CRemoveLineFeeds(void);
+	~CRemoveLineFeeds(void);
+
+	bool RemoveLineFeeds(const CDittoInfo &DittoInfo, IClip *pClip);
+
+
+private:
+	bool Handle_CF_TEXT(IClipFormats *pFormats);
+	bool Handle_CF_UNICODETEXT(IClipFormats *pFormats);
+	bool Handle_RichText(IClipFormats *pFormats);
+};
+

+ 7 - 6
ClipIds.cpp

@@ -207,12 +207,13 @@ BOOL CClipIDs::MoveTo(long lParentID, double dFirst, double dIncrement)
 		int nCount = GetSize();
 		for(int i = 0; i < nCount; i++)
 		{
-			theApp.m_db.execDMLEx(_T("UPDATE Main SET lParentID = %d, ")
-									_T("lDontAutoDelete = %d WHERE lID = %d AND lID <> %d;"), 
-									lParentID, 
-									(long)CTime::GetCurrentTime().GetTime(),
-									ElementAt(i),
-									lParentID);
+			CString sql = StrF(_T("UPDATE Main SET lParentID = %d ")
+								_T("WHERE lID = %d AND lID <> %d;"), 
+								lParentID,
+								ElementAt(i),
+								lParentID);
+
+			theApp.m_db.execDMLEx(sql);
 		}
 	}
 	CATCH_SQLITE_EXCEPTION

+ 1 - 5
CopyProperties.cpp

@@ -24,7 +24,6 @@ CCopyProperties::CCopyProperties(long lCopyID, CWnd* pParent, CClip *pMemoryClip
 	m_bChangedText = false;
 	m_bHandleKillFocus = false;
 	m_bHideOnKillFocus = false;
-	m_bInGroup = false;
 	m_lGroupChangedTo = -1;
 	m_pMemoryClip = pMemoryClip;
 	m_bSetToTopMost = true;
@@ -132,9 +131,6 @@ void CCopyProperties::LoadDataFromCClip(CClip &Clip)
 
 	m_GroupCombo.SetCurSelOnItemData(Clip.m_lParent);
 
-	if(Clip.m_lParent >= 0)
-		m_bInGroup = true;
-
 	m_HotKey.SetHotKey(LOBYTE(Clip.m_lShortCut), HIBYTE(Clip.m_lShortCut));
 	m_HotKey.SetRules(HKCOMB_A, 0);
 
@@ -257,7 +253,7 @@ void CCopyProperties::LoadDataIntoCClip(CClip &Clip)
 
 	//If we are going from no group to a group or the
 	//don't auto delete check box is checked
-	if(m_bInGroup == false && Clip.m_lParent >= 0 || m_bNeverAutoDelete)
+	if(m_bNeverAutoDelete)
 	{
 		Clip.m_lDontAutoDelete = (long)CTime::GetCurrentTime().GetTime();
 	}

+ 15 - 6
DatabaseUtilities.cpp

@@ -464,15 +464,24 @@ BOOL RemoveOldEntries()
 			if(lMax >= 0)
 			{
 				CClipIDs IDs;
+				int clipId;
 				
-				CppSQLite3Query q = db.execQueryEx(_T("SELECT lID, lShortCut, lDontAutoDelete FROM Main ORDER BY lDate DESC LIMIT -1 OFFSET %d"), lMax);			
+				CppSQLite3Query q = db.execQueryEx(_T("SELECT lID, lShortCut, lParentID, lDontAutoDelete FROM Main WHERE bIsGroup = 0 ORDER BY lDate DESC LIMIT -1 OFFSET %d"), lMax);
 				while(q.eof() == false)
 				{
-					//Only delete entries that have no shortcut and don't have the flag set
-					if(q.getIntField(_T("lShortCut")) == 0 && q.getIntField(_T("lDontAutoDelete")) == 0)
-						IDs.Add(q.getIntField(_T("lID")));
+					int shortcut = q.getIntField(_T("lShortCut"));
+					int dontDelete = q.getIntField(_T("lDontAutoDelete"));
+					int parentId = q.getIntField(_T("lParentID"));
 
-					Log(StrF(_T("From MaxEntries - Deleting Id: %d"), q.getIntField(_T("lID"))));
+					//Only delete entries that have no shortcut and don't have the flag set
+					if(shortcut == 0 && 
+						dontDelete == 0 &&
+						parentId <= 0)
+					{
+						clipId = q.getIntField(_T("lID"));
+						IDs.Add(clipId);
+						Log(StrF(_T("From MaxEntries - Deleting Id: %d"), clipId));
+					}
 
 					q.nextRow();
 				}
@@ -497,7 +506,7 @@ BOOL RemoveOldEntries()
 				
 				CppSQLite3Query q = db.execQueryEx(_T("SELECT lID FROM Main ")
 													_T("WHERE lDate < %d AND ")
-													_T("lShortCut = 0 AND lDontAutoDelete = 0"), now.GetTime());
+													_T("bIsGroup = 0 AND lShortCut = 0 AND lParentID <= 0 AND lDontAutoDelete = 0"), now.GetTime());
 
 				while(q.eof() == false)
 				{

+ 2 - 2
GroupCombo.cpp

@@ -37,8 +37,8 @@ void CGroupCombo::FillCombo()
 {
 	ResetContent();
 
-	int nIndex = AddString(_T("--NONE--"));
-	SetItemData(nIndex, 0);
+	int nIndex = AddString(_T("-No Group-"));
+	SetItemData(nIndex, -1);
 
 	FillCombo(-1, 1);
 }

+ 2 - 1
GroupTree.cpp

@@ -74,8 +74,9 @@ void CGroupTree::FillTree()
 	DeleteAllItems();
 	m_bSendAllready = false;
 
-	HTREEITEM hItem = InsertItem(_T("Root"), TVI_ROOT);
+	HTREEITEM hItem = InsertItem(_T("-No Group-"), TVI_ROOT);
 	SetItemData(hItem, -1);
+
 	SetItemState(hItem, TVIS_EXPANDED, TVIS_EXPANDED);
 
 	if(m_lSelectedFolderID < 0)

+ 1 - 1
MainFrm.cpp

@@ -255,7 +255,7 @@ LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
             m_quickPaste.MoveSelection(true);
             m_bMovedSelectionMoveKeyState = true;
         }
-        else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowVisibleEx())
+        else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowVisibleEx() && g_Opt.GetShowPersistent() == FALSE)
         {
             Log(_T("On Show Ditto HotKey, window is alread visible, hiding window"));
             m_quickPaste.HideQPasteWnd();

+ 1 - 1
MoveToGroupDlg.cpp

@@ -64,7 +64,7 @@ BOOL CMoveToGroupDlg::OnInitDialog()
 LRESULT CMoveToGroupDlg::OnTreeSelect(WPARAM wParam, LPARAM lParam)
 {
 	int nID = (int)wParam;
-	if(nID >= 0)
+	if(nID != 0)
 	{
 		m_nSelectedGroup = nID;
 		OnOK();

+ 34 - 13
QPasteWnd.cpp

@@ -354,7 +354,7 @@ void CQPasteWnd::OnSetFocus(CWnd *pOldWnd)
 {
     CWndEx::OnSetFocus(pOldWnd);
 
-    ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
+    //::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
 
     // Set the focus to the list control
     if(::IsWindow(m_lstHeader.m_hWnd))
@@ -374,12 +374,18 @@ void CQPasteWnd::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
 
     if(nState == WA_INACTIVE)
     {
+		SaveWindowSize();
+
         m_bModifersMoveActive = false;
 
         if(!g_Opt.m_bShowPersistent)
         {
             HideQPasteWindow();
         }
+		else if(g_Opt.GetAutoHide())
+		{
+			MinMaxWindow(FORCE_MIN);
+		}
 
         //re register the global hot keys for the last ten
         if(theApp.m_bAppExiting == false)
@@ -424,10 +430,7 @@ BOOL CQPasteWnd::HideQPasteWindow()
     KillTimer(TIMER_FILL_CACHE);
 
     //Save the size
-    CRect rect;
-    GetWindowRectEx(&rect);
-    CGetSetOptions::SetQuickPasteSize(rect.Size());
-    CGetSetOptions::SetQuickPastePoint(rect.TopLeft());
+    SaveWindowSize();
 
     // Hide the window when the focus is lost
 	m_lstHeader.ShowWindow(SW_HIDE);
@@ -463,6 +466,14 @@ BOOL CQPasteWnd::HideQPasteWindow()
     return TRUE;
 }
 
+void CQPasteWnd::SaveWindowSize()
+{
+	CRect rect;
+	GetWindowRectEx(&rect);
+	CGetSetOptions::SetQuickPasteSize(rect.Size());
+	CGetSetOptions::SetQuickPastePoint(rect.TopLeft());
+}
+
 BOOL CQPasteWnd::ShowQPasteWindow(BOOL bFillList)
 {
     theApp.m_bShowingQuickPaste = true;
@@ -515,7 +526,10 @@ BOOL CQPasteWnd::ShowQPasteWindow(BOOL bFillList)
 
     // always on top... for persistent showing (g_Opt.m_bShowPersistent)
     // SHOWWINDOW was also integrated into this function rather than calling it separately
-    ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
+	if(g_Opt.GetShowPersistent())
+	{
+		::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
+	}
 
     SetKeyModiferState(true);
 
@@ -727,7 +741,7 @@ LRESULT CQPasteWnd::OnListSelect(WPARAM wParam, LPARAM lParam)
 
 LRESULT CQPasteWnd::OnListEnd(WPARAM wParam, LPARAM lParam)
 {
-    HideQPasteWindow();
+    //HideQPasteWindow();
     return 0;
 }
 
@@ -1844,7 +1858,7 @@ void CQPasteWnd::OnMenuGroupsMovetogroup()
     if(nRet == IDOK)
     {
         int nGroup = dlg.GetSelectedGroup();
-        if(nGroup >= 0)
+        if(nGroup >= -1)
         {
             CClipIDs IDs;
             m_lstHeader.GetSelectionItemData(IDs);
@@ -2317,11 +2331,18 @@ BOOL CQPasteWnd::PreTranslateMessage(MSG *pMsg)
                             }
                             else
                             {
-                                if(m_GroupTree.IsWindowVisible() == FALSE)
-                                {
-                                    HideQPasteWindow();
-                                    return TRUE;
-                                }
+								if(g_Opt.GetShowPersistent() && this->GetMinimized() == false)
+								{
+									MinMaxWindow(FORCE_MIN);
+								}
+								else
+								{
+									if(m_GroupTree.IsWindowVisible() == FALSE)
+									{
+										HideQPasteWindow();
+										return TRUE;
+									}
+								}
                             }
                         }
                     }

+ 1 - 0
QPasteWnd.h

@@ -145,6 +145,7 @@ public:
     void MoveSelection(bool down);
     void OnKeyStateUp();
     void SetKeyModiferState(bool bActive);
+	void SaveWindowSize();
 
     // Generated message map functions
 protected:

+ 246 - 246
QuickPaste.cpp

@@ -1,254 +1,254 @@
-// QuickPaste.cpp: implementation of the CQuickPaste class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "stdafx.h"
-#include "CP_Main.h"
-#include "QuickPaste.h"
-
-#ifdef _DEBUG
-#undef THIS_FILE
-static char THIS_FILE[]=__FILE__;
-#define new DEBUG_NEW
-#endif
-
-#define ID_QPASTE_WND			0x1001
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CQuickPaste::CQuickPaste()
-{
-	m_pwndPaste = NULL;
-}
-
-CQuickPaste::~CQuickPaste()
-{
-	if(m_pwndPaste)
-	{
-		delete m_pwndPaste;
-		m_pwndPaste = NULL;
-	}	
-}
-
-void CQuickPaste::Create(CWnd *pParent)
-{
-	CPoint point;
-	CSize csSize;
-	
-	ASSERT(!m_pwndPaste);
-	m_pwndPaste = new CQPasteWnd;
-	ASSERT(m_pwndPaste);
-	// load previous position and size
-	CGetSetOptions::GetQuickPastePoint(point);
-	CGetSetOptions::GetQuickPasteSize(csSize);
-	// Create the window
-	ASSERT( m_pwndPaste->Create(point, pParent) );
-	// place it at the previous position and size
-	m_pwndPaste->MoveWindow(CRect(point, csSize));
-
-	Log(_T("Creating QPasteWnd"));
-}
-
-BOOL CQuickPaste::CloseQPasteWnd()
-{
-	if(m_pwndPaste)
-	{
-		if(m_pwndPaste->IsWindowVisible())
-		{
-			Log(_T("CloseQPasteWnd called but the window is visible"));
-			return FALSE;
-		}
-		
-		if(m_pwndPaste)
-			m_pwndPaste->DestroyWindow();
-
-		Log(_T("CloseQPasteWnd called closing qpastewnd"));
-		
-		delete m_pwndPaste;
-		m_pwndPaste = NULL;
-	}
-	
-	return TRUE;
-}
-
-void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboard, BOOL bReFillList)
-{		
-	Log(StrF(_T("Start of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
-
-	if(bFromKeyboard == false && GetKeyState(VK_SHIFT) & 0x8000 && GetKeyState(VK_CONTROL) & 0x8000)
-	{
-		if(m_pwndPaste)
-			m_pwndPaste->DestroyWindow();
-
-		Log(_T("CloseQPasteWnd called closing qpastewnd from keyboard"));
-
-		delete m_pwndPaste;
-		m_pwndPaste = NULL;
-
-		theApp.m_db.close();
-		OpenDatabase(CGetSetOptions::GetDBPath());
-
-		return;
-	}
-
-	if(g_Opt.m_bShowPersistent && m_pwndPaste != NULL)
-	{
-		m_pwndPaste->ShowWindow(SW_SHOW);
-		m_pwndPaste->MinMaxWindow(FORCE_MAX);
-		m_pwndPaste->SetForegroundWindow();
-		return;
-	}
-	
-	int nPosition = CGetSetOptions::GetQuickPastePosition();
-	
-	CPoint point;
-	CRect rcPrev;
-	CSize csSize;
-	
-	if(!m_pwndPaste)
-		m_pwndPaste = new CQPasteWnd;
-	
-	if(!m_pwndPaste)
-	{
-		ASSERT(FALSE);
-		return;
-	}
-
-	m_pwndPaste->MinMaxWindow(FORCE_MAX);
-	
-	//If it is a window get the rect otherwise get the saved point and size
-	if (IsWindow(m_pwndPaste->m_hWnd))
-	{
-		m_pwndPaste->GetWindowRect(rcPrev);
-		csSize = rcPrev.Size();
-	}
-	else
-	{
-		CGetSetOptions::GetQuickPastePoint(point);
-		CGetSetOptions::GetQuickPasteSize(csSize);
-	}
-
-	CPoint ptCaret = theApp.m_activeWnd.FocusCaret();
-	if(ptCaret.x <= 0 || ptCaret.y <= 0)
-	{
-		CRect cr;
-		::GetWindowRect(theApp.m_activeWnd.ActiveWnd(), cr);
-		
-		if(cr.Width() > 0 && cr.Height() > 0)
-		{
-			ptCaret = cr.CenterPoint();
-			ptCaret.x -= csSize.cx/2;
-			ptCaret.y -= csSize.cy/2;
-		}
-		else
-		{
-			GetCursorPos(&point);
-
-			CRect crPoint(point, CSize(1, 1));
-
+// QuickPaste.cpp: implementation of the CQuickPaste class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "stdafx.h"
+#include "CP_Main.h"
+#include "QuickPaste.h"
+
+#ifdef _DEBUG
+#undef THIS_FILE
+static char THIS_FILE[]=__FILE__;
+#define new DEBUG_NEW
+#endif
+
+#define ID_QPASTE_WND			0x1001
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CQuickPaste::CQuickPaste()
+{
+	m_pwndPaste = NULL;
+}
+
+CQuickPaste::~CQuickPaste()
+{
+	if(m_pwndPaste)
+	{
+		delete m_pwndPaste;
+		m_pwndPaste = NULL;
+	}	
+}
+
+void CQuickPaste::Create(CWnd *pParent)
+{
+	CPoint point;
+	CSize csSize;
+	
+	ASSERT(!m_pwndPaste);
+	m_pwndPaste = new CQPasteWnd;
+	ASSERT(m_pwndPaste);
+	// load previous position and size
+	CGetSetOptions::GetQuickPastePoint(point);
+	CGetSetOptions::GetQuickPasteSize(csSize);
+	// Create the window
+	ASSERT( m_pwndPaste->Create(point, pParent) );
+	// place it at the previous position and size
+	m_pwndPaste->MoveWindow(CRect(point, csSize));
+
+	Log(_T("Creating QPasteWnd"));
+}
+
+BOOL CQuickPaste::CloseQPasteWnd()
+{
+	if(m_pwndPaste)
+	{
+		if(m_pwndPaste->IsWindowVisible())
+		{
+			Log(_T("CloseQPasteWnd called but the window is visible"));
+			return FALSE;
+		}
+		
+		if(m_pwndPaste)
+			m_pwndPaste->DestroyWindow();
+
+		Log(_T("CloseQPasteWnd called closing qpastewnd"));
+		
+		delete m_pwndPaste;
+		m_pwndPaste = NULL;
+	}
+	
+	return TRUE;
+}
+
+void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboard, BOOL bReFillList)
+{		
+	Log(StrF(_T("Start of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
+
+	if(bFromKeyboard == false && GetKeyState(VK_SHIFT) & 0x8000 && GetKeyState(VK_CONTROL) & 0x8000)
+	{
+		if(m_pwndPaste)
+			m_pwndPaste->DestroyWindow();
+
+		Log(_T("CloseQPasteWnd called closing qpastewnd from keyboard"));
+
+		delete m_pwndPaste;
+		m_pwndPaste = NULL;
+
+		theApp.m_db.close();
+		OpenDatabase(CGetSetOptions::GetDBPath());
+
+		return;
+	}
+
+	if(g_Opt.m_bShowPersistent && m_pwndPaste != NULL)
+	{
+		m_pwndPaste->ShowWindow(SW_SHOW);
+		m_pwndPaste->MinMaxWindow(FORCE_MAX);
+		m_pwndPaste->SetForegroundWindow();
+		return;
+	}
+	
+	int nPosition = CGetSetOptions::GetQuickPastePosition();
+	
+	CPoint point;
+	CRect rcPrev;
+	CSize csSize;
+	
+	if(!m_pwndPaste)
+		m_pwndPaste = new CQPasteWnd;
+	
+	if(!m_pwndPaste)
+	{
+		ASSERT(FALSE);
+		return;
+	}
+
+	m_pwndPaste->MinMaxWindow(FORCE_MAX);
+	
+	//If it is a window get the rect otherwise get the saved point and size
+	if (IsWindow(m_pwndPaste->m_hWnd))
+	{
+		m_pwndPaste->GetWindowRect(rcPrev);
+		csSize = rcPrev.Size();
+	}
+	else
+	{
+		CGetSetOptions::GetQuickPastePoint(point);
+		CGetSetOptions::GetQuickPasteSize(csSize);
+	}
+
+	CPoint ptCaret = theApp.m_activeWnd.FocusCaret();
+	if(ptCaret.x <= 0 || ptCaret.y <= 0)
+	{
+		CRect cr;
+		::GetWindowRect(theApp.m_activeWnd.ActiveWnd(), cr);
+		
+		if(cr.Width() > 0 && cr.Height() > 0)
+		{
+			ptCaret = cr.CenterPoint();
+			ptCaret.x -= csSize.cx/2;
+			ptCaret.y -= csSize.cy/2;
+		}
+		else
+		{
+			GetCursorPos(&point);
+
+			CRect crPoint(point, CSize(1, 1));
+
 			int nMonitor = GetMonitorFromRect(crPoint);
 			if(nMonitor >= 0)
 			{
 				CRect crMonitor;
 				GetMonitorRect(nMonitor, crMonitor);
 
-				ptCaret = crMonitor.CenterPoint();
-				ptCaret.x -= csSize.cx/2;
+				ptCaret = crMonitor.CenterPoint();
+				ptCaret.x -= csSize.cx/2;
 				ptCaret.y -= csSize.cy/2;
-			}
-		}
-	}
-	
-	if(bAtPrevPos)
-	{
-		CGetSetOptions::GetQuickPastePoint(point);
-		CGetSetOptions::GetQuickPasteSize(csSize);
-	}
-	else if(nPosition == POS_AT_CARET)
-		point = ptCaret;
-	else if(nPosition == POS_AT_CURSOR)
-		GetCursorPos(&point);
-	else if(nPosition == POS_AT_PREVIOUS)
-		CGetSetOptions::GetQuickPastePoint(point);
-	
-	if( !IsWindow(m_pwndPaste->m_hWnd) )
-	{
-		// Create the window   
-		VERIFY( m_pwndPaste->Create(point, pParent) );
-	}
-
-	CRect crRect = CRect(point, csSize);
-
-	if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
-		EnsureWindowVisible(&crRect);
-	
-	if((nPosition == POS_AT_CARET) ||
-		(nPosition == POS_AT_CURSOR) ||
-		(bAtPrevPos))
-	{
-		m_pwndPaste->MoveWindow(crRect);
-	}
-	
-	// Show the window
-	m_pwndPaste->ShowWindow(SW_SHOW);
-	if(bReFillList)
-	{
-		m_pwndPaste->ShowQPasteWindow(bReFillList);
-	}
-	m_pwndPaste->SetForegroundWindow();
-
-	Log(StrF(_T("END of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
-}
-
-void CQuickPaste::MoveSelection(bool down)
-{
-	if(m_pwndPaste)
-	{
-		if (IsWindow(m_pwndPaste->m_hWnd))
-		{
-			m_pwndPaste->MoveSelection(down);
-		}
-	}
-}
-
-void CQuickPaste::OnKeyStateUp()
-{
-	if(m_pwndPaste)
-	{
-		if (IsWindow(m_pwndPaste->m_hWnd))
-		{
-			m_pwndPaste->OnKeyStateUp();
-		}
-	}
-}
-
-void CQuickPaste::SetKeyModiferState(bool bActive)
-{
-	if(m_pwndPaste)
-	{
-		if (IsWindow(m_pwndPaste->m_hWnd))
-		{
-			m_pwndPaste->SetKeyModiferState(bActive);
-		}
-	}
-}
-
-void CQuickPaste::HideQPasteWnd()
-{
-	// Hide the window
-	if(m_pwndPaste)
-	{
-		if (IsWindow(m_pwndPaste->m_hWnd))
-			m_pwndPaste->HideQPasteWindow();
-	}
-}
-
-BOOL CQuickPaste::IsWindowVisibleEx()
-{
-	if(m_pwndPaste)
-		return IsWindowVisible(m_pwndPaste->m_hWnd);
-
-	return FALSE;
+			}
+		}
+	}
+	
+	if(bAtPrevPos)
+	{
+		CGetSetOptions::GetQuickPastePoint(point);
+		CGetSetOptions::GetQuickPasteSize(csSize);
+	}
+	else if(nPosition == POS_AT_CARET)
+		point = ptCaret;
+	else if(nPosition == POS_AT_CURSOR)
+		GetCursorPos(&point);
+	else if(nPosition == POS_AT_PREVIOUS)
+		CGetSetOptions::GetQuickPastePoint(point);
+	
+	if( !IsWindow(m_pwndPaste->m_hWnd) )
+	{
+		// Create the window   
+		VERIFY( m_pwndPaste->Create(point, pParent) );
+	}
+
+	CRect crRect = CRect(point, csSize);
+
+	if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
+		EnsureWindowVisible(&crRect);
+	
+	if((nPosition == POS_AT_CARET) ||
+		(nPosition == POS_AT_CURSOR) ||
+		(bAtPrevPos))
+	{
+		m_pwndPaste->MoveWindow(crRect);
+	}
+	
+	// Show the window
+	m_pwndPaste->ShowWindow(SW_SHOW);
+	if(bReFillList)
+	{
+		m_pwndPaste->ShowQPasteWindow(bReFillList);
+	}
+	m_pwndPaste->SetForegroundWindow();
+
+	Log(StrF(_T("END of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
+}
+
+void CQuickPaste::MoveSelection(bool down)
+{
+	if(m_pwndPaste)
+	{
+		if (IsWindow(m_pwndPaste->m_hWnd))
+		{
+			m_pwndPaste->MoveSelection(down);
+		}
+	}
+}
+
+void CQuickPaste::OnKeyStateUp()
+{
+	if(m_pwndPaste)
+	{
+		if (IsWindow(m_pwndPaste->m_hWnd))
+		{
+			m_pwndPaste->OnKeyStateUp();
+		}
+	}
+}
+
+void CQuickPaste::SetKeyModiferState(bool bActive)
+{
+	if(m_pwndPaste)
+	{
+		if (IsWindow(m_pwndPaste->m_hWnd))
+		{
+			m_pwndPaste->SetKeyModiferState(bActive);
+		}
+	}
+}
+
+void CQuickPaste::HideQPasteWnd()
+{
+	// Hide the window
+	if(m_pwndPaste)
+	{
+		if (IsWindow(m_pwndPaste->m_hWnd))
+			m_pwndPaste->HideQPasteWindow();
+	}
+}
+
+BOOL CQuickPaste::IsWindowVisibleEx()
+{
+	if(m_pwndPaste)
+		return IsWindowVisible(m_pwndPaste->m_hWnd);
+
+	return FALSE;
 }

+ 4 - 0
WndEx.cpp

@@ -223,6 +223,7 @@ void CWndEx::MinMaxWindow(long lOption)
 			m_crFullSizeWindow.SetRectEmpty();
 			m_DittoWindow.m_bMinimized = false;
 			m_TimeMaximized = COleDateTime::GetCurrentTime();
+			::SetForegroundWindow(this->GetSafeHwnd());
 			OnNcPaint();
 		}
 	}
@@ -248,6 +249,7 @@ void CWndEx::MinMaxWindow(long lOption)
 			m_crFullSizeWindow.SetRectEmpty();
 			m_DittoWindow.m_bMinimized = false;
 			m_TimeMaximized = COleDateTime::GetCurrentTime();
+			::SetForegroundWindow(this->GetSafeHwnd());
 			OnNcPaint();
 		}
 	}
@@ -274,6 +276,7 @@ void CWndEx::MinMaxWindow(long lOption)
 			m_crFullSizeWindow.SetRectEmpty();
 			m_DittoWindow.m_bMinimized = false;
 			m_TimeMaximized = COleDateTime::GetCurrentTime();
+			::SetForegroundWindow(this->GetSafeHwnd());
 			OnNcPaint();
 		}
 	}
@@ -301,6 +304,7 @@ void CWndEx::MinMaxWindow(long lOption)
 			m_crFullSizeWindow.SetRectEmpty();
 			m_DittoWindow.m_bMinimized = false;
 			m_TimeMaximized = COleDateTime::GetCurrentTime();
+			::SetForegroundWindow(this->GetSafeHwnd());
 			OnNcPaint();
 		}
 	}

+ 1 - 0
WndEx.h

@@ -41,6 +41,7 @@ public:
 	void GetWindowRectEx(LPRECT lpRect);
 	bool SetCaptionColorActive(BOOL bPersistant, BOOL ConnectedToClipboard);
 	void SetAutoMaxDelay(long lDelay)	{ m_lDelayMaxSeconds = lDelay; }
+	bool GetMinimized()	{ return m_DittoWindow.m_bMinimized; }
 
 protected:
 	CDittoWindow m_DittoWindow;