soc.2009.vulture: e1dd6a10: Fundamentals of IM window.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Sat Jun 13 17:35:39 EDT 2009


-----------------------------------------------------------------
Revision: e1dd6a103c2334295d082dcaebbd4f7758224a10
Ancestor: a1526d1e3e37b26642695e75bbb8421623200a08
Author: gdick at soc.pidgin.im
Date: 2009-06-13T21:30:18
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/e1dd6a103c2334295d082dcaebbd4f7758224a10

Modified files:
        vulture/resource.h vulture/vulture-res.rc vulture/vulture.c
        vulture/vultureconv.c

ChangeLog: 

Fundamentals of IM window.

-------------- next part --------------
============================================================
--- vulture/resource.h	d106cf2f44a2af555a8278fa173fecfe7ec485c3
+++ vulture/resource.h	c8fb6d5e7659ea613f5f6afdba671100bb735ef8
@@ -9,6 +9,7 @@
 #define IDR_ACCEL_MAIN                          109
 #define IDM_CONV                                111
 #define IDD_CONVCONT                            113
+#define IDD_IM                                  115
 #define IDC_TAB_CONVERSATIONS                   1001
 #define IDC_BUDDY_ICON                          1002
 #define IDC_LIST_ACCOUNTS                       1003
@@ -24,5 +25,10 @@
 #define IDC_TREE_BLIST                          40004
 #define IDS_ERROR_CONVCONTCLASS                 40004
 #define IDC_BTN_ACCOUNT_ADD                     40005
+#define IDS_ERROR_RICHEDIT                      40005
 #define IDC_BTN_ACCOUNT_PROPERTIES              40006
 #define IDC_BTN_ACCOUNT_DELETE                  40007
+#define IDC_RICHEDIT_CONV                       40008
+#define IDC_RICHEDIT_INPUT                      40010
+#define IDC_STATIC_NAME                         40011
+#define IDC_STATIC_STATUS                       40013
============================================================
--- vulture/vulture-res.rc	65230b716419b95bb111f8b085aa1fad14e80969
+++ vulture/vulture-res.rc	70ce7ab95b472375ade589844dfb705c9fd551ff
@@ -81,6 +81,20 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_U
 
 
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
+IDD_IM DIALOG 0, 0, 325, 235
+STYLE DS_3DLOOK | DS_CENTER | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW
+FONT 8, "Ms Shell Dlg"
+{
+    CONTROL         "", IDC_RICHEDIT_CONV, RICHEDIT_CLASS, WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL | ES_READONLY, 5, 35, 310, 150
+    CONTROL         "", IDC_RICHEDIT_INPUT, RICHEDIT_CLASS, WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL, 5, 190, 310, 40
+    CONTROL         "", IDC_STATIC, WC_STATIC, SS_BITMAP, 5, 5, 20, 17
+    LTEXT           "", IDC_STATIC_NAME, 40, 5, 275, 8, SS_LEFT
+    LTEXT           "", IDC_STATIC_STATUS, 40, 15, 275, 8, SS_LEFT
+}
+
+
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
 IDD_STATUS DIALOG 0, 0, 161, 41
 STYLE DS_3DLOOK | DS_CENTER | DS_CONTROL | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW
 FONT 8, "Ms Shell Dlg"
@@ -104,6 +118,7 @@ STRINGTABLE
     IDS_ACCMGR_ACCOUNT            "Account"
     IDS_ACCMGR_PROTOCOL           "Protocol"
     IDS_ERROR_CONVCONTCLASS       "Couldn't register conversation container class."
+    IDS_ERROR_RICHEDIT            "Couldn't load RichEdit."
 }
 
 
============================================================
--- vulture/vulture.c	b0a2971e40e97bbe423f58855f873937948413a0
+++ vulture/vulture.c	e57fb7b45650012c7e434f91ba04ff44c06decf8
@@ -56,6 +56,7 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 	HANDLE hthreadPurple;
 	INITCOMMONCONTROLSEX iccx;
 	HACCEL haccel;
+	HANDLE hlibRichEdit;
 
 	g_hInstance = hinst;
 	g_hProcHeap = GetProcessHeap();
@@ -64,6 +65,16 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 	iccx.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES;
 	InitCommonControlsEx(&iccx);
 
+	/* Attempt to load RichEdit. This needs to be done before the dialogue
+	 * manager tries to create any RichEdit controls.
+	 */
+	hlibRichEdit = LoadLibrary(TEXT("riched20.dll"));
+	if(!hlibRichEdit)
+	{
+		MessageBoxFromStringTable(NULL, IDS_ERROR_RICHEDIT, MB_ICONERROR);
+		return VEC_ERROR_RICHEDIT;
+	}
+
 	g_thread_init(NULL);
 
 	VultureParseCommandLine();
@@ -109,6 +120,8 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 
 	VultureCommandLineCleanup();
 
+	FreeLibrary(hlibRichEdit);
+
 	return msg.wParam;
 }
 
============================================================
--- vulture/vultureconv.c	6a58a82ec94ae3e84c985c2241511db200ef0430
+++ vulture/vultureconv.c	98651fdbac3dcd67b7a633cbcc6bd4245e9ffcba
@@ -34,6 +34,7 @@
 
 
 #define CONVCONTAINERCLASS	TEXT("VULTURECONVCONTAINER")
+#define CONV_DLG_MARGIN		4
 
 
 typedef struct _CONVCONTAINERDATA
@@ -42,9 +43,15 @@ typedef struct _CONVCONTAINERDATA
 } CONVCONTAINERDATA;
 
 
+static int g_cyInput = 48;
+
+
 static LRESULT CALLBACK ConvContainerWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
 static INT_PTR CALLBACK ConvContTabDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
 static void RecalcTabIndices(HWND hwndTabs);
+static INT_PTR CALLBACK IMDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
+static void ResizeConversationWindows(HWND hwndConvContainer, HWND hwndTabs);
+static void RepositionConvControls(HWND hwndConvDlg);
 
 
 /**
@@ -152,6 +159,11 @@ static LRESULT CALLBACK ConvContainerWnd
 					tcitem.pszText = lpvconv->sync.szTitle;
 					lpvconv->iTabIndex = TabCtrl_InsertItem(hwndTabs, TabCtrl_GetItemCount(hwndTabs), &tcitem);
 				LeaveCriticalSection(&lpvconv->sync.cs);
+
+				/* Create conversation dialogue. */
+				lpvconv->hwndConv = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_IM), hwndTabs, IMDlgProc);
+
+				ResizeConversationWindows(hwnd, hwndTabs);
 			}
 
 			break;
@@ -185,6 +197,37 @@ static LRESULT CALLBACK ConvContainerWnd
 
 		return 0;
 
+
+	case WM_COMMAND:
+		switch(LOWORD(wParam))
+		{
+		case IDM_CONV_CONV_CLOSE:
+			SendMessage(hwnd, WM_CLOSE, 0, 0);
+			return 0;
+		}
+
+		break;
+
+
+	case WM_NOTIFY:
+		{
+			LPNMHDR lpnmhdr = (LPNMHDR)lParam;
+
+			if(lpnmhdr->idFrom == IDC_TAB_CONVERSATIONS && lpnmhdr->code == TCN_SELCHANGE)
+			{
+				TCITEM tcitem;
+
+				tcitem.mask = TCIF_PARAM;
+				TabCtrl_GetItem(lpnmhdr->hwndFrom, TabCtrl_GetCurSel(lpnmhdr->hwndFrom), &tcitem);
+
+				SetWindowPos(((VULTURE_CONVERSATION*)tcitem.lParam)->hwndConv, HWND_TOP, 0, 0, 0, 0, SWP_NOREPOSITION | SWP_NOSIZE);
+
+				return 0;
+			}
+		}
+
+		break;
+
 	case WM_SIZE:
 		lpccd = (CONVCONTAINERDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
 		SetWindowPos(
@@ -195,6 +238,7 @@ static LRESULT CALLBACK ConvContainerWnd
 			LOWORD(lParam),
 			HIWORD(lParam),
 			SWP_NOZORDER | SWP_NOACTIVATE);
+		ResizeConversationWindows(hwnd, GetDlgItem(lpccd->hwndTabDlg, IDC_TAB_CONVERSATIONS));
 
 		return 0;
 
@@ -243,8 +287,6 @@ static LRESULT CALLBACK ConvContainerWnd
 
 
 
-#define CONV_CONT_TAB_MARGIN	4
-
 /**
  * Dialogue procedure for conversation tabs.
  *
@@ -268,13 +310,18 @@ static INT_PTR CALLBACK ConvContTabDlgPr
 		SetWindowPos(
 			GetDlgItem(hwndDlg, IDC_TAB_CONVERSATIONS),
 			NULL,
-			CONV_CONT_TAB_MARGIN,
-			CONV_CONT_TAB_MARGIN,
-			LOWORD(lParam) - 2 * CONV_CONT_TAB_MARGIN,
-			HIWORD(lParam) - 2 * CONV_CONT_TAB_MARGIN,
+			CONV_DLG_MARGIN,
+			CONV_DLG_MARGIN,
+			LOWORD(lParam) - 2 * CONV_DLG_MARGIN,
+			HIWORD(lParam) - 2 * CONV_DLG_MARGIN,
 			SWP_NOZORDER | SWP_NOACTIVATE);
 
 		return TRUE;
+
+	case WM_NOTIFY:
+		/* Forward to parent. */
+		SendMessage(GetParent(hwndDlg), uiMsg, wParam, lParam);
+		return TRUE;
 	}
 
 	return FALSE;
@@ -299,3 +346,110 @@ static void RecalcTabIndices(HWND hwndTa
 		((VULTURE_CONVERSATION*)tcitem.lParam)->iTabIndex = i;
 	}
 }
+
+
+/**
+ * Dialogue procedure for IM dialogues. Delegates processing common with chats
+ * to ConvCommonDlgProc.
+ *
+ * @param	hwndDlg		Dialogue window handle.
+ * @param	uiMsg		Message ID.
+ * @param	wParam		Message-specific.
+ * @param	lParam		Message-specific.
+ *
+ * @return Usually TRUE if message processed and FALSE otherwise. There are
+ * some exceptions for particular messages.
+ */
+static INT_PTR CALLBACK IMDlgProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+	switch(uiMsg)
+	{
+	case WM_INITDIALOG:
+		/* Let the system set the focus. */
+		return TRUE;
+
+	case WM_SIZE:
+		RepositionConvControls(hwndDlg);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+
+
+/**
+ * Resizes all conversation dialogues to fit in the tabs.
+ *
+ * @param	hwndConvContainer	Conversation container window.
+ * @param	hwndTabs		Tab control.
+ */
+static void ResizeConversationWindows(HWND hwndConvContainer, HWND hwndTabs)
+{
+	int i, iCount = TabCtrl_GetItemCount(hwndTabs);
+	TCITEM tcitem;
+	RECT rc;
+	HDWP hdwp;
+
+	tcitem.mask = TCIF_PARAM;
+
+	GetWindowRect(hwndTabs, &rc);
+	TabCtrl_AdjustRect(hwndTabs, FALSE, &rc);
+	MapWindowPoints(HWND_DESKTOP, hwndTabs, (LPPOINT)(void*)&rc, 2);
+
+	hdwp = BeginDeferWindowPos(iCount);
+
+	for(i = 0; i < iCount; i++)
+	{
+		TabCtrl_GetItem(hwndTabs, i, &tcitem);
+		hdwp = DeferWindowPos(
+			hdwp,
+			((VULTURE_CONVERSATION*)tcitem.lParam)->hwndConv,
+			NULL,
+			rc.left,
+			rc.top,
+			rc.right - rc.left,
+			rc.bottom - rc.top,
+			SWP_NOZORDER | SWP_NOACTIVATE);
+	}
+
+	EndDeferWindowPos(hdwp);
+}
+
+
+#define CONV_TOP_MARGIN		48
+
+/**
+ * Repositions and resizes controls in a conversation window.
+ *
+ * @param	hwndConvDlg	Conversation window.
+ */
+static void RepositionConvControls(HWND hwndConvDlg)
+{
+	RECT rcClient;
+	HDWP hdwp = BeginDeferWindowPos(2);
+
+	GetClientRect(hwndConvDlg, &rcClient);
+
+	hdwp = DeferWindowPos(
+		hdwp,
+		GetDlgItem(hwndConvDlg, IDC_RICHEDIT_CONV),
+		NULL,
+		CONV_DLG_MARGIN,
+		CONV_DLG_MARGIN + CONV_TOP_MARGIN,
+		rcClient.right - 2 * CONV_DLG_MARGIN,
+		rcClient.bottom - g_cyInput - 3 * CONV_DLG_MARGIN - CONV_TOP_MARGIN,
+		SWP_NOACTIVATE | SWP_NOZORDER);
+
+	hdwp = DeferWindowPos(
+		hdwp,
+		GetDlgItem(hwndConvDlg, IDC_RICHEDIT_INPUT),
+		NULL,
+		CONV_DLG_MARGIN,
+		rcClient.bottom - g_cyInput - CONV_DLG_MARGIN,
+		rcClient.right - 2 * CONV_DLG_MARGIN,
+		g_cyInput,
+		SWP_NOACTIVATE | SWP_NOZORDER);
+
+	EndDeferWindowPos(hdwp);
+}


More information about the Commits mailing list