From: <kr_...@us...> - 2003-08-24 23:59:00
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1:/tmp/cvs-serv6171/port/src/cbits/Win32 Modified Files: Util.c Window.c Added Files: Notebook.c Log Message: Implementation for Notebook control --- NEW FILE: Notebook.c --- #include "Notebook.h" #include "Internals.h" #include "Handlers_stub.h" WNDPROC DefTabCtrlProc; extern LRESULT CALLBACK HCompoundControlFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static void ResizeNotebookPages(HWND hWnd) { RECT rect; int i, nCount; TCITEM item; GetClientRect(hWnd, &rect); SendMessage(hWnd, TCM_ADJUSTRECT, FALSE, (LPARAM) &rect); nCount = SendMessage(hWnd, TCM_GETITEMCOUNT, 0, 0); for (i = 0; i < nCount; i++) { item.mask = TCIF_PARAM; SendMessage(hWnd, TCM_GETITEM, i, (LPARAM) &item); SetWindowPos((HWND) item.lParam,NULL,rect.left,rect.top, (rect.right-rect.left), (rect.bottom-rect.top), SWP_NOZORDER); } } LRESULT CALLBACK HNotebookFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SIZE: ResizeNotebookPages(hWnd); break; case WM_NOTIFY: { NMHDR *pNMHDR = (NMHDR *) lParam; int nIndex; TCITEM item; HWND hNotebookPage; if (pNMHDR->hwndFrom == hWnd) { nIndex = SendMessage(hWnd, TCM_GETCURSEL, 0, 0); item.mask = TCIF_PARAM; SendMessage(hWnd, TCM_GETITEM, nIndex, (LPARAM) &item); hNotebookPage = (HWND) item.lParam; switch (pNMHDR->code) { case TCN_SELCHANGE: ShowWindow(hNotebookPage, SW_SHOW); break; case TCN_SELCHANGING: ShowWindow(hNotebookPage, SW_HIDE); break; } return 0; } } break; } return CallWindowProc(DefTabCtrlProc, hWnd, uMsg, wParam, lParam); } LRESULT CALLBACK HNotebookPageFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SETTEXT: { TCITEM item; item.mask = TCIF_TEXT; item.pszText = (char *) lParam; SendMessage(GetParent(hWnd), TCM_SETITEM, osGetNotebookPagePos(hWnd), (LPARAM) &item); } break; case WM_DESTROY: { handleWindowDestroy(hWnd); SendMessage(GetParent(hWnd), TCM_DELETEITEM, osGetNotebookPagePos(hWnd), 0); } break; case WM_CTLCOLORSTATIC: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return HCompoundControlFunction(hWnd, uMsg, wParam, lParam); } WindowHandle osCreateNotebook(WindowHandle form) { HWND hNotebook; hNotebook = CreateWindow( "HNOTEBOOK", NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0,0,0,0, form, NULL, ghModule, NULL ); return checkWindow(hNotebook, WC_TABCONTROL); }; void osGetNotebookReqSize(WindowHandle notebook, int *res) { RECT rect = {0,0,0,0}; SendMessage(notebook, TCM_ADJUSTRECT, TRUE, (LPARAM) &rect); res[0] = rect.right - rect.left; res[1] = rect.bottom - rect.top; } void osSetNotebookLabelsPosition(WindowHandle notebook, PositionType position) { LONG lStyle; FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); lStyle = GetWindowLong(notebook, GWL_STYLE); lStyle &= ~(TCS_VERTICAL | TCS_RIGHT | TCS_BOTTOM); switch (position) { case PosLeft: lStyle |= TCS_VERTICAL; break; case PosTop: break; case PosRight: lStyle |= TCS_VERTICAL | TCS_RIGHT; break; case PosBottom: lStyle |= TCS_BOTTOM; break; } SendMessage(notebook, WM_SETFONT, (WPARAM)NULL, TRUE); SetWindowLong(notebook, GWL_STYLE, lStyle); SendMessage(notebook, WM_SETFONT, (WPARAM)pFrameData->hControlFont, MAKELPARAM (TRUE,0)); ResizeNotebookPages(notebook); } PositionType osGetNotebookLabelsPosition(WindowHandle notebook) { LONG lStyle = GetWindowLong(notebook, GWL_STYLE); if (lStyle & TCS_VERTICAL) if (lStyle & TCS_RIGHT) return PosRight; else return PosLeft; else if (lStyle & TCS_BOTTOM) return PosBottom; else return PosTop; } int osGetNotebookSelection(WindowHandle notebook) { return SendMessage(notebook, TCM_GETCURSEL, 0, 0); }; void osSetNotebookSelection(WindowHandle notebook, int index) { TCITEM item; HWND hNotebookPage; int nOldIndex; item.mask = TCIF_PARAM; nOldIndex = SendMessage(notebook, TCM_GETCURSEL, 0, 0); SendMessage(notebook, TCM_SETCURSEL, index, 0); SendMessage(notebook, TCM_GETITEM, nOldIndex, (LPARAM) &item); ShowWindow((HWND) item.lParam, SW_HIDE); SendMessage(notebook, TCM_GETITEM, index, (LPARAM) &item); ShowWindow((HWND) item.lParam, SW_SHOW); }; WindowHandle osInsertNotebookPage(WindowHandle notebook, int pos) { HWND hWnd; RECT rect; TCITEM item; int nCount; nCount = SendMessage(notebook, TCM_GETITEMCOUNT, 0, 0); if (pos < 0) pos = nCount; GetWindowRect(notebook, &rect); SendMessage(notebook, TCM_ADJUSTRECT, FALSE, (LPARAM) &rect); hWnd = CreateWindow("HNOTEBOOKPAGE", NULL, WS_CHILD | ((nCount > 0) ? 0 : WS_VISIBLE), 0,0,rect.right-rect.left,rect.bottom-rect.top, notebook, NULL, ghModule, NULL ); item.mask = TCIF_PARAM | TCIF_TEXT; item.lParam = (LPARAM) hWnd; item.pszText = ""; SendMessage(notebook, TCM_INSERTITEM, pos, (LPARAM) &item); return hWnd; } char *osGetNotebookPageTitle(WindowHandle window) { int nLen = GetWindowTextLength(window); char *buffer = (char *) malloc(nLen+1); if (buffer) GetWindowText(window, buffer, nLen+1); return buffer; }; void osSetNotebookPageTitle(WindowHandle window, char *txt) { SetWindowText(window, txt); }; int osGetNotebookPagePos(WindowHandle window) { HWND hNotebook = GetParent(window); int i, nCount = SendMessage(hNotebook, TCM_GETITEMCOUNT, 0, 0); TCITEM item; for (i = 0; i < nCount; i++) { item.mask = TCIF_PARAM; SendMessage(hNotebook, TCM_GETITEM, i, (LPARAM) &item); if (((HWND) item.lParam) == window) return i; } return -1; } void osDestroyNotebookPage(WindowHandle window) { DestroyWindow(window); } void osGetNotebookPageSize(WindowHandle window, int *res) { RECT rect; GetWindowRect(window,&rect); res[0] = rect.right-rect.left; res[1] = rect.bottom-rect.top; } Index: Util.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Util.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Util.c 20 Aug 2003 21:37:26 -0000 1.18 --- Util.c 24 Aug 2003 13:57:34 -0000 1.19 *************** *** 36,41 **** --- 36,44 ---- extern LRESULT CALLBACK HDockBarFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); extern LRESULT CALLBACK HToolBarFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + extern LRESULT CALLBACK HNotebookFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + extern LRESULT CALLBACK HNotebookPageFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); extern WNDPROC DefToolBarProc; + extern WNDPROC DefTabCtrlProc; void osInit(char *appName, char *appVersion, int DocumentInterface) *************** *** 145,148 **** --- 148,172 ---- wc.lpfnWndProc = HToolBarFunction; wc.lpszClassName = "HTOOLBAR"; + RegisterClass(&wc); + + // Notebook class (subclass of the standard TabCtrl class) + GetClassInfo(ghModule, WC_TABCONTROL, &wc); + DefTabCtrlProc = wc.lpfnWndProc; + wc.style = CS_DBLCLKS; + wc.lpfnWndProc = HNotebookFunction; + wc.lpszClassName = "HNOTEBOOK"; + RegisterClass(&wc); + + // NotebookPage class + wc.style = CS_DBLCLKS; + wc.lpfnWndProc = HNotebookPageFunction; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = ghModule; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1); + wc.lpszMenuName = NULL; + wc.lpszClassName = "HNOTEBOOKPAGE"; RegisterClass(&wc); Index: Window.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Window.c,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Window.c 24 Aug 2003 11:30:14 -0000 1.41 --- Window.c 24 Aug 2003 13:57:34 -0000 1.42 *************** *** 212,215 **** --- 212,222 ---- } break; + case WM_NOTIFY: + { + NMHDR *pNMHDR = (NMHDR *) lParam; + if (pNMHDR->hwndFrom != hWnd) + SendMessage(pNMHDR->hwndFrom, uMsg, wParam, lParam); + } + break; case WM_PAINT: { |