|
From: <kr_...@us...> - 2003-11-25 14:12:27
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32
In directory sc8-pr-cvs1:/tmp/cvs-serv32518/src/cbits/Win32
Modified Files:
Internals.h ListBox.c Util.c Window.c
Log Message:
Add support for CheckListBox control
Index: Internals.h
===================================================================
RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Internals.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Internals.h 24 Nov 2003 22:58:59 -0000 1.16
--- Internals.h 25 Nov 2003 14:12:22 -0000 1.17
***************
*** 74,76 ****
--- 74,78 ----
void RefreshStatusBarIndicators();
+ void DrawCheckListBoxItem(LPDRAWITEMSTRUCT lpDIS);
+
#endif
Index: ListBox.c
===================================================================
RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/ListBox.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ListBox.c 8 Oct 2003 22:21:57 -0000 1.7
--- ListBox.c 25 Nov 2003 14:12:22 -0000 1.8
***************
*** 2,5 ****
--- 2,122 ----
#include "Internals.h"
#include "Handlers_stub.h"
+ #include <windowsx.h>
+
+ void DrawCheckListBoxItem(LPDRAWITEMSTRUCT lpDIS)
+ {
+ if ((((LONG) lpDIS->itemID) >= 0) && (lpDIS->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)))
+ {
+ int cyItem;
+ BOOL fDisabled;
+ HFONT hFont, hOldFont;
+ COLORREF newBkColor, oldBkColor;
+ COLORREF newTextColor, oldTextColor;
+ TEXTMETRIC tm;
+ int nTextLen;
+ LPCSTR lpszText;
+
+ cyItem = SendMessage(lpDIS->hwndItem, LB_GETITEMHEIGHT, lpDIS->itemID, 0);
+
+ fDisabled = !IsWindowEnabled(lpDIS->hwndItem);
+
+ newTextColor = fDisabled ? RGB(0x80, 0x80, 0x80) : GetSysColor(COLOR_WINDOWTEXT); // light gray
+ oldTextColor = SetTextColor(lpDIS->hDC, newTextColor);
+
+ newBkColor = GetSysColor(COLOR_WINDOW);
+ oldBkColor = SetBkColor(lpDIS->hDC, newBkColor);
+
+ if (newTextColor == newBkColor)
+ newTextColor = RGB(0xC0, 0xC0, 0xC0); // dark gray
+
+ if (!fDisabled && ((lpDIS->itemState & ODS_SELECTED) != 0))
+ {
+ SetTextColor(lpDIS->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
+ SetBkColor(lpDIS->hDC, GetSysColor(COLOR_HIGHLIGHT));
+ }
+
+ hFont = (HFONT) SendMessage(lpDIS->hwndItem,WM_GETFONT,0,0);
+ hOldFont = SelectObject(lpDIS->hDC, hFont);
+ GetTextMetrics(lpDIS->hDC, &tm);
+
+ nTextLen = SendMessage(lpDIS->hwndItem, LB_GETTEXTLEN, lpDIS->itemID, 0);
+ lpszText = rmalloc(nTextLen+1);
+ SendMessage(lpDIS->hwndItem, LB_GETTEXT, lpDIS->itemID, (LPARAM) lpszText);
+
+ ExtTextOut(lpDIS->hDC, lpDIS->rcItem.left + cyItem,
+ lpDIS->rcItem.top + max(0, (cyItem - tm.tmHeight) / 2),
+ ETO_OPAQUE, &lpDIS->rcItem, lpszText, nTextLen, NULL);
+
+ Rectangle(lpDIS->hDC, 1, lpDIS->rcItem.top+1, cyItem-1, lpDIS->rcItem.top+cyItem-1);
+
+ if (SendMessage(lpDIS->hwndItem, LB_GETITEMDATA, lpDIS->itemID, 0) > 0)
+ {
+ HPEN hPen, hOldPen;
+
+ hPen = CreatePen(PS_SOLID, 2, newTextColor);
+ hOldPen = SelectObject(lpDIS->hDC, hPen);
+
+ MoveToEx(lpDIS->hDC, 3, lpDIS->rcItem.top+cyItem/2-1, NULL);
+ LineTo(lpDIS->hDC, cyItem/2, lpDIS->rcItem.top+cyItem-4);
+ LineTo(lpDIS->hDC, cyItem-4, lpDIS->rcItem.top+3);
+
+ SelectObject(lpDIS->hDC, hOldPen);
+ }
+
+ rfree(lpszText);
+
+ SelectObject(lpDIS->hDC, hOldFont);
+ SetBkColor(lpDIS->hDC, oldBkColor);
+ SetTextColor(lpDIS->hDC, oldTextColor);
+ }
+
+ if ((lpDIS->itemAction & ODA_FOCUS) != 0)
+ DrawFocusRect(lpDIS->hDC, &lpDIS->rcItem);
+ }
+
+ WNDPROC DefCheckListBoxProc = NULL;
+
+ LRESULT CALLBACK HCheckListBoxFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+ {
+ switch (uMsg)
+ {
+ case WM_LBUTTONDOWN:
+ {
+ int cyItem;
+ int nTopIndex, nIndex, nCount;
+ BOOL bCheck;
+ POINT pos;
+ RECT rect;
+
+ pos.x = GET_X_LPARAM(lParam);
+ pos.y = GET_Y_LPARAM(lParam);
+
+ SetFocus(hWnd);
+
+ cyItem = SendMessage(hWnd, LB_GETITEMHEIGHT, 0, 0);
+ nCount = SendMessage(hWnd, LB_GETCOUNT, 0, 0);
+ nTopIndex = SendMessage(hWnd, LB_GETTOPINDEX, 0, 0);
+
+ if (pos.y < cyItem * nCount)
+ {
+ nIndex = nTopIndex + pos.y / cyItem;
+ if (pos.x < cyItem)
+ {
+ bCheck = SendMessage(hWnd, LB_GETITEMDATA, nIndex, 0);
+ SendMessage(hWnd, LB_SETITEMDATA, nIndex, !bCheck);
+
+ handleControlCommand(hWnd);
+
+ SendMessage(hWnd, LB_GETITEMRECT, nIndex, (LPARAM)&rect);
+ rect.right = rect.left + cyItem;
+ InvalidateRect(hWnd, &rect, TRUE);
+ }
+ }
+ }
+ break;
+ };
+
+ return CallWindowProc(DefCheckListBoxProc, hWnd, uMsg, wParam, lParam);
+ }
WindowHandle osCreateListBox(WindowHandle window, BOOL multisel)
***************
*** 21,24 ****
--- 138,159 ----
};
+ WindowHandle osCreateCheckListBox(WindowHandle window)
+ {
+ HWND hListBox;
+
+ hListBox = CreateWindowEx(
+ WS_EX_CLIENTEDGE,
+ "HCHECKLISTBOX",
+ NULL,
+ WS_CHILD | WS_VSCROLL | WS_BORDER | LBS_NOTIFY | WS_TABSTOP | LBS_HASSTRINGS | LBS_OWNERDRAWFIXED,
+ 0,0,0,0,
+ window,
+ NULL,
+ ghModule,
+ NULL
+ );
+ return checkWindow(hListBox, "LISTBOX");
+ };
+
void osAppendListBoxItem(WindowHandle listbox, char *title)
{
***************
*** 86,90 ****
BOOL osGetListBoxItemSelectState(WindowHandle listbox, int index)
{
! return SendMessage(listbox, LB_GETSEL, index, 0) > 0;
}
--- 221,231 ----
BOOL osGetListBoxItemSelectState(WindowHandle listbox, int index)
{
! char buffer[20];
! GetClassName(listbox,buffer,sizeof(buffer));
!
! if (_stricmp(buffer, "HCHECKLISTBOX") == 0)
! return SendMessage(listbox, LB_GETITEMDATA, index, 0) > 0;
! else
! return SendMessage(listbox, LB_GETSEL, index, 0) > 0;
}
***************
*** 97,101 ****
void osSetListBoxItemSelectState(WindowHandle listbox, int index, BOOL state)
{
! SendMessage(listbox, LB_SETSEL, state, index);
};
--- 238,257 ----
void osSetListBoxItemSelectState(WindowHandle listbox, int index, BOOL state)
{
! char buffer[20];
! GetClassName(listbox,buffer,sizeof(buffer));
!
! if (_stricmp(buffer, "HCHECKLISTBOX") == 0)
! {
! RECT rect;
! int cyItem = SendMessage(listbox, LB_GETITEMHEIGHT, 0, 0);
!
! SendMessage(listbox, LB_SETITEMDATA, index, state);
!
! SendMessage(listbox, LB_GETITEMRECT, index, (LPARAM)&rect);
! rect.right = rect.left + cyItem;
! InvalidateRect(listbox, &rect, TRUE);
! }
! else
! SendMessage(listbox, LB_SETSEL, state, index);
};
Index: Util.c
===================================================================
RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Util.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** Util.c 24 Nov 2003 22:40:41 -0000 1.28
--- Util.c 25 Nov 2003 14:12:22 -0000 1.29
***************
*** 38,45 ****
--- 38,47 ----
extern LRESULT CALLBACK HNotebookPageFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern LRESULT CALLBACK HGroupBoxFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ extern LRESULT CALLBACK HCheckListBoxFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern WNDPROC DefToolBarProc;
extern WNDPROC DefTabCtrlProc;
extern WNDPROC DefGroupBoxProc;
+ extern WNDPROC DefCheckListBoxProc;
void osInit(char *appName, char *appVersion, int DocumentInterface)
***************
*** 136,139 ****
--- 138,149 ----
wc.lpfnWndProc = HGroupBoxFunction;
wc.lpszClassName = "HGROUPBOX";
+ RegisterClass(&wc);
+
+ // GroupBox class
+ GetClassInfo(ghModule, "LISTBOX", &wc);
+ DefCheckListBoxProc = wc.lpfnWndProc;
+ wc.style = CS_DBLCLKS;
+ wc.lpfnWndProc = HCheckListBoxFunction;
+ wc.lpszClassName = "HCHECKLISTBOX";
RegisterClass(&wc);
Index: Window.c
===================================================================
RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Window.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -d -r1.61 -r1.62
*** Window.c 23 Nov 2003 10:23:14 -0000 1.61
--- Window.c 25 Nov 2003 14:12:22 -0000 1.62
***************
*** 642,645 ****
--- 642,652 ----
}
return (LRESULT) pData->hBackBrush;
+ case WM_DRAWITEM:
+ {
+ LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) lParam;
+
+ if (lpDIS->CtlType == ODT_LISTBOX)
+ DrawCheckListBoxItem(lpDIS);
+ }
}
|