From: <kr_...@us...> - 2003-11-18 18:03:44
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1:/tmp/cvs-serv26058/src/cbits/Win32 Modified Files: Frame.c Internals.h StatusBar.c Log Message: Complete implementation for StatusBar indicators under Windows Index: Frame.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Frame.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Frame.c 16 Nov 2003 09:24:02 -0000 1.21 --- Frame.c 18 Nov 2003 18:03:41 -0000 1.22 *************** *** 48,51 **** --- 48,67 ---- free(context); } + + while (pData->first_indicator) + { + IndicatorHandle indicator; + + indicator = pData->first_indicator; + handleIndicatorDestroy(indicator); + pData->first_indicator = pData->first_indicator->next; + + if (pData->first_indicator) + pData->first_indicator->prev = NULL; + + free(indicator->title); + free(indicator); + } + pData->last_indicator = NULL; free(pData); *************** *** 118,122 **** (HANDLE) ghModule, NULL); ! pData->statusContexts = NULL; SetWindowLong(hWnd,GWL_USERDATA,(LONG) pData); --- 134,140 ---- (HANDLE) ghModule, NULL); ! pData->statusContexts = NULL; ! pData->first_indicator = NULL; ! pData->last_indicator = NULL; SetWindowLong(hWnd,GWL_USERDATA,(LONG) pData); *************** *** 125,128 **** --- 143,147 ---- case WM_SIZE: RelayoutFrameBars(); + RefreshStatusBarIndicators(); break; case WM_COMMAND: *************** *** 373,376 **** --- 392,416 ---- case WM_EXITMENULOOP: osPopStatusBarContext(); + break; + case WM_NOTIFY: + { + int i; + IndicatorHandle indicator; + LPNMMOUSE lpnm = (LPNMMOUSE) lParam; + + if (lpnm->hdr.code == NM_DBLCLK && lpnm->dwItemSpec > 0) + { + i = lpnm->dwItemSpec-1; + indicator = pData->first_indicator; + while (i > 0 && indicator != NULL) + { + indicator = indicator->next; + i--; + } + + if (indicator) + handleIndicatorCommand(indicator); + } + } break; } Index: Internals.h =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Internals.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Internals.h 15 Nov 2003 10:31:49 -0000 1.14 --- Internals.h 18 Nov 2003 18:03:41 -0000 1.15 *************** *** 52,55 **** --- 52,65 ---- #endif + #ifndef NMMOUSE + typedef struct tagNMMOUSE { + NMHDR hdr; + DWORD_PTR dwItemSpec; + DWORD_PTR dwItemData; + POINT pt; + LPARAM dwHitInfo; // any specifics about where on the item or control the mouse is + } NMMOUSE, FAR* LPNMMOUSE; + #endif + extern HMODULE ghModule; extern HWND ghWndFrame; *************** *** 78,81 **** --- 88,92 ---- HWND hStatusBar; StatusContext statusContexts; + IndicatorHandle first_indicator, last_indicator; } FrameData; *************** *** 107,110 **** --- 118,123 ---- void osForceContainerReLayout(HWND hCtrl); + + void RefreshStatusBarIndicators(); #endif Index: StatusBar.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/StatusBar.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StatusBar.c 16 Nov 2003 09:02:00 -0000 1.3 --- StatusBar.c 18 Nov 2003 18:03:41 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- #include "DockBar.h" #include "Internals.h" + #include "Handlers_stub.h" void osSetStatusBarVisible(BOOL visible) *************** *** 59,60 **** --- 60,213 ---- SetWindowText(pData->hStatusBar, title); }; + + void RefreshStatusBarIndicators() + { + int i, x, count, *buffer; + FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); + IndicatorHandle indicator; + HDC hDC; + HFONT hFont; + RECT rect; + + GetClientRect(pData->hStatusBar, &rect); + + // get the actual count of indicators + count = 0; + indicator = pData->first_indicator; + while (indicator) + { + indicator = indicator->next; + count++; + } + + // allocate the "parts" buffer required from SB_SETPARTS message + buffer = rmalloc((count+1)*sizeof(int)); + + // get the device context and the font for the status bar + hDC = GetDC(pData->hStatusBar); + hFont = (HFONT) SendMessage(pData->hStatusBar,WM_GETFONT,0,0); + if (hFont) + SelectObject(hDC, hFont); + + // populate the "parts" buffer + i = count+1; + x = rect.right-rect.left-GetSystemMetrics(SM_CXVSCROLL); + indicator = pData->last_indicator; + while (indicator) + { + SIZE sz; + + buffer[--i] = x; + + sz.cx = 0; + sz.cy = 0; + if (indicator->title) + GetTextExtentPoint32(hDC, indicator->title, strlen(indicator->title), &sz); + x -= sz.cx+5; + + indicator = indicator->prev; + } + buffer[0] = x; + + // set parts + SendMessage(pData->hStatusBar, SB_SETPARTS, count+1, (LPARAM) buffer); + + // refresh the part titles + i = 1; + indicator = pData->first_indicator; + while (indicator) + { + if (indicator->title) + SendMessage(pData->hStatusBar, SB_SETTEXT, i, (LPARAM) indicator->title); + + indicator = indicator->next; + i++; + } + + // release the device context + ReleaseDC(pData->hStatusBar, hDC); + + // free parts buffer + free(buffer); + } + + IndicatorHandle osCreateIndicator(int index) + { + IndicatorHandle indicator, *link, last; + FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); + + indicator = rmalloc(sizeof(struct IndicatorHandle)); + indicator->title = NULL; + + if (index >= 0) + { + last = NULL; + link = &pData->first_indicator; + + while (index > 0 && *link != NULL) + { + last = *link; + link = &last->next; + index--; + } + } + else + { + if (pData->last_indicator) + { + last = pData->last_indicator; + link = &pData->last_indicator->next; + } + else + { + last = NULL; + link = &pData->first_indicator; + } + } + + indicator->next = *link; + indicator->prev = last; + if (*link) (*link)->prev = indicator; + *link = indicator; + + if (last == pData->last_indicator) + pData->last_indicator = indicator; + + RefreshStatusBarIndicators(); + + return indicator; + } + + void osDestroyIndicator(IndicatorHandle indicator) + { + FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); + + handleIndicatorDestroy(indicator); + + if (indicator->next) indicator->next->prev = indicator->prev; + if (indicator->prev) indicator->prev->next = indicator->next; + + if (indicator == pData->first_indicator) + pData->first_indicator = indicator->next; + if (indicator == pData->last_indicator) + pData->last_indicator = indicator->prev; + + free(indicator->title); + free(indicator); + + RefreshStatusBarIndicators(); + } + + char *osGetIndicatorTitle(IndicatorHandle indicator) + { + return strdup(indicator->title); + } + + void osSetIndicatorTitle(IndicatorHandle indicator, char *title) + { + if (indicator->title) + free(indicator->title); + indicator->title = strdup(title); + + RefreshStatusBarIndicators(); + } |