Ver código fonte

added option to not show the thumbnail and draw the bitmap directly without converting it to a cbitmap
[SAB]


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

sabrogden 21 anos atrás
pai
commit
091df16699
9 arquivos alterados com 108 adições e 48 exclusões
  1. 39 0
      BitmapHelper.cpp
  2. 1 0
      BitmapHelper.h
  3. 1 0
      CP_Main.cpp
  4. 8 0
      CP_Main.dsp
  5. 4 3
      CP_Main.rc
  6. 13 0
      Misc.cpp
  7. 4 0
      Misc.h
  8. 37 45
      QListCtrl.cpp
  9. 1 0
      Resource.h

+ 39 - 0
BitmapHelper.cpp

@@ -272,3 +272,42 @@ HANDLE CBitmapHelper::hBitmapToDIB(HBITMAP hBitmap, DWORD dwCompression, HPALETT
     ReleaseDC(NULL,hDC);
     return hDIB;
 }
+
+
+bool CBitmapHelper::DrawDIB(CDC *pDC, HANDLE hData, int nLeft, int nRight, int &nWidth)
+{
+	LPBITMAPINFO	lpBI ;
+	void*           pDIBBits;
+	bool bRet = false;
+	
+	lpBI = (LPBITMAPINFO)GlobalLock(hData);
+	if(lpBI)
+	{
+		int nColors = lpBI->bmiHeader.biClrUsed ? lpBI->bmiHeader.biClrUsed : 1 << lpBI->bmiHeader.biBitCount;
+
+		if( lpBI->bmiHeader.biBitCount > 8 )
+		{
+			pDIBBits = (LPVOID)((LPDWORD)(lpBI->bmiColors + lpBI->bmiHeader.biClrUsed) + 
+				((lpBI->bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
+		}
+		else
+		{
+			pDIBBits = (LPVOID)(lpBI->bmiColors + nColors);
+		}
+
+		::StretchDIBits(pDC->m_hDC,
+					nLeft, nRight, 
+					lpBI->bmiHeader.biWidth, lpBI->bmiHeader.biHeight,
+					0, 0, lpBI->bmiHeader.biWidth, 
+					lpBI->bmiHeader.biHeight,
+					pDIBBits, lpBI, DIB_PAL_COLORS, SRCCOPY);
+
+		nWidth = lpBI->bmiHeader.biWidth;
+
+		GlobalUnlock(hData) ;
+
+		bRet = true;
+	}
+
+	return bRet;
+}

+ 1 - 0
BitmapHelper.h

@@ -23,6 +23,7 @@ public:
 	static HANDLE	hBitmapToDIB(HBITMAP hBitmap, DWORD dwCompression, HPALETTE hPal);
 	static WORD		PaletteSize(LPSTR lpDIB);
 	static WORD		DIBNumColors(LPSTR lpDIB);
+	static bool		DrawDIB(CDC *pDC, HANDLE hData, int nLeft, int nRight, int &nWidth);
 
 };
 

+ 1 - 0
CP_Main.cpp

@@ -34,6 +34,7 @@ END_MESSAGE_MAP()
 /////////////////////////////////////////////////////////////////////////////
 // CCP_MainApp construction
 
+
 CCP_MainApp::CCP_MainApp()
 {
 	m_bAppRunning = false;

+ 8 - 0
CP_Main.dsp

@@ -300,6 +300,10 @@ SOURCE=.\DataTable.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\FormatSQL.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\FriendDetails.cpp
 # End Source File
 # Begin Source File
@@ -449,6 +453,10 @@ SOURCE=.\DialogResizer.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\FormatSQL.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\FriendDetails.h
 # End Source File
 # Begin Source File

+ 4 - 3
CP_Main.rc

@@ -672,11 +672,12 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Move to Group"
 FONT 8, "MS Sans Serif"
 BEGIN
-    DEFPUSHBUTTON   "OK",IDOK,143,156,50,14
-    PUSHBUTTON      "Cancel",IDCANCEL,197,156,50,14
     CONTROL         "Tree1",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | 
                     TVS_HASLINES | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | 
-                    WS_BORDER | WS_TABSTOP,7,7,240,142
+                    TVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,7,7,240,142
+    PUSHBUTTON      "New Group",IDC_BUTTON_NEW_GROUP,7,156,55,14
+    DEFPUSHBUTTON   "OK",IDOK,143,156,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,197,156,50,14
 END
 
 

+ 13 - 0
Misc.cpp

@@ -478,6 +478,7 @@ BOOL CGetSetOptions::m_bLogSendReceiveErrors;
 BOOL CGetSetOptions::m_bUseHookDllForFocus;
 BOOL CGetSetOptions::m_HideDittoOnHotKeyIfAlreadyShown;
 long CGetSetOptions::m_lPort;
+BOOL CGetSetOptions::m_bDrawThumbnail;
 
 CGetSetOptions g_Opt;
 
@@ -501,6 +502,7 @@ CGetSetOptions::CGetSetOptions()
 	m_bUseHookDllForFocus = GetProfileLong("UseHookDllForFocus", TRUE);
 	m_HideDittoOnHotKeyIfAlreadyShown = GetHideDittoOnHotKeyIfAlreadyShown();
 	m_lPort = GetPort();
+	m_bDrawThumbnail = GetDrawThumbnail();
 
 	#ifdef _DEBUG
 	m_bUseHookDllForFocus = FALSE;
@@ -1150,6 +1152,17 @@ void CGetSetOptions::SetFont(LOGFONT &font)
 	SetProfileData("DisplayFont", &font, sizeof(LOGFONT));
 }
 
+void CGetSetOptions::SetDrawThumbnail(long bDraw)
+{
+	SetProfileLong("DrawThumbnail", bDraw); 
+	m_bDrawThumbnail = bDraw;
+}
+
+BOOL CGetSetOptions::GetDrawThumbnail()
+{
+	return GetProfileLong("DrawThumbnail", TRUE);
+}
+
 /*------------------------------------------------------------------*\
 CHotKey - a single system-wide hotkey
 \*------------------------------------------------------------------*/

+ 4 - 0
Misc.h

@@ -306,6 +306,10 @@ public:
 	static BOOL		GetFont(LOGFONT &font);
 	static void		SetFont(LOGFONT &font);
 
+	static BOOL		m_bDrawThumbnail;
+	static void		SetDrawThumbnail(long bDraw);
+	static BOOL		GetDrawThumbnail();
+
 	/*
 	BOOL IsAutoRun();
 	void SetAutoRun(BOOL bRun);

+ 37 - 45
QListCtrl.cpp

@@ -507,66 +507,58 @@ void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
 // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
 BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC)
 {
+	if(g_Opt.m_bDrawThumbnail == FALSE)
+		return FALSE;
+	
 	bool bFromDB = false;
 	long lDatabaseID = GetItemData(nItem);
-	CClipFormat* pThumbnail = NULL; // pointer to the thumbnail in the cache map
-
-	CMapIDtoCF::CPair* pPair = m_ThumbNails.PLookup(lDatabaseID);
-	if( pPair == NULL )
-	{
-		pThumbnail = &(m_ThumbNails[lDatabaseID]);
-		pThumbnail->m_cfType = CF_DIB;
-		GetClipData(nItem, *pThumbnail);
-		bFromDB = true;
-	}
-	else
-		pThumbnail = &(pPair->value);
 
-	// if there's no data, then we're done.
-	if( pThumbnail->m_hgData == NULL )
-		return TRUE;
-
-	CBitmap Bitmap;
-	// Convert DIB to a DDB.
-	if( !CBitmapHelper::GetCBitmap(pThumbnail, pDC, &Bitmap, crRect.Height()) )
-	{
-		Bitmap.DeleteObject();
-		pThumbnail->Free(); // the data is useless, so free it.
+	CClipFormat* pThumbnail = &(m_ThumbNails[lDatabaseID]);
+	if(pThumbnail == NULL)
 		return FALSE;
-	}
-
-	BITMAP bm;
-	Bitmap.GetBitmap(&bm);
-	int nWidth = bm.bmWidth;
-	int nHeight = bm.bmHeight;
 
-	// draw Bitmap
-	CDC MemDc;
-	MemDc.CreateCompatibleDC(pDC);
-	CBitmap* oldBitmap = MemDc.SelectObject(&Bitmap);
-	pDC->BitBlt(crRect.left, crRect.top, nWidth, nHeight, &MemDc, 0, 0, SRCCOPY);
-	MemDc.SelectObject(oldBitmap);
-	MemDc.DeleteDC();
+	//If it has not been read in
+	if(pThumbnail->m_cfType != CF_DIB)
+	{
+		pThumbnail->m_cfType = CF_DIB;
 
-	// adjust the rect so other information can be drawn next to the thumbnail
-	crRect.left += nWidth + 3;
+		//Get the data from the database
+		GetClipData(nItem, *pThumbnail);
+		
+		//convert to a small bitmap
+		CBitmap Bitmap;
+		if( !CBitmapHelper::GetCBitmap(pThumbnail, pDC, &Bitmap, crRect.Height()) )
+		{
+			Bitmap.DeleteObject();
+			// the data is useless, so free it.
+			pThumbnail->Free(); 
+			return FALSE;
+		}
 
-	// if the original DIB came from the DB, cache the smaller version we created above.
-	if( bFromDB )
-	{
-		pThumbnail->Free(); // delete the large image data loaded from the db
+		// delete the large image data loaded from the db
+		pThumbnail->Free();
 		pThumbnail->m_cfType = CF_DIB;
 
-		// Convert the smaller DDB to a DIB to store in the cache
-		//caching the bitmap had problems (???)
+		//Convert the smaller bitmap back to a dib
 		HPALETTE hPal = NULL;
 		pThumbnail->m_hgData = CBitmapHelper::hBitmapToDIB( (HBITMAP)Bitmap, BI_RGB, hPal );
-	//	cf.m_hgData = BitmapToDIB(Bitmap.operator HBITMAP(), hPal);
 
 		ASSERT( pThumbnail->bDeleteData ); // the map owns the data.
+
+		Bitmap.DeleteObject();
 	}
 
-	Bitmap.DeleteObject();
+	// if there's no data, then we're done.
+	if( pThumbnail->m_hgData == NULL )
+		return TRUE;
+
+	//Will return the width of the bitmap in nWidth
+	int nWidth = 0;
+	if(CBitmapHelper::DrawDIB(pDC, pThumbnail->m_hgData, crRect.left, crRect.top, nWidth))
+	{
+		// adjust the rect so other information can be drawn next to the thumbnail
+		crRect.left += nWidth + 3;
+	}
 
 	return TRUE;
 }

+ 1 - 0
Resource.h

@@ -85,6 +85,7 @@
 #define IDC_PARSE_BUTTON                1040
 #define IDC_HIDE_DITO_ON_HOT_KEY        1040
 #define IDC_BUTTON_FONT                 1040
+#define IDC_BUTTON_NEW_GROUP            1040
 #define IDC_PARSE_EDIT                  1041
 #define IDC_CHECK1                      1042
 #define IDC_HISTORY_START_TOP           1042