From: <kr_...@us...> - 2004-05-07 12:44:47
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21144/src/cbits/Win32 Modified Files: Window.c Log Message: Support for the Center/CenterOnParent/Mouse positioning Index: Window.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Window.c,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** Window.c 9 Mar 2004 15:06:22 -0000 1.63 --- Window.c 7 May 2004 12:44:34 -0000 1.64 *************** *** 45,49 **** { if (GetWindowLong(hCtrl,GWL_STYLE) & WS_VISIBLE) ! { GetWindowRect(hCtrl,&rect); upLeft.x = rect.left; --- 45,49 ---- { if (GetWindowLong(hCtrl,GWL_STYLE) & WS_VISIBLE) ! { GetWindowRect(hCtrl,&rect); upLeft.x = rect.left; *************** *** 132,135 **** --- 132,194 ---- DrawSizeGripLine(hDC,rect.right,rect.bottom,GetSysColor(COLOR_3DFACE),3); } + + static void CenterToScreen(POINT *pos, SIZE sz) + { + HDC screen; + screen = CreateDC ("DISPLAY", NULL, NULL, NULL); + if (screen==NULL) + { + printf("CreateDC returned NULL.\n"); + exit(1); + } + pos->x = (GetDeviceCaps(screen,HORZRES)-sz.cx)/2; + pos->y = (GetDeviceCaps(screen,VERTRES)-sz.cy)/2; + DeleteDC (screen); + } + + static void SetupWindowPosition(HWND hWnd) + { + SIZE sz; + POINT pos; + HWND hParent; + WindowData *pData; + RECT rc; + + pData = (WindowData *) GetWindowLong(hWnd,GWL_USERDATA); + + pos.x = pData->windowPosRect.left; + pos.y = pData->windowPosRect.top; + sz.cx = pData->windowPosRect.right-pData->windowPosRect.left; + sz.cy = pData->windowPosRect.bottom-pData->windowPosRect.top; + + hParent = GetParent(hWnd); + + switch (pData->windowPos) + { + case 0: + break; + case 1: + CenterToScreen(&pos, sz); + break; + case 2: + if (hParent) + GetClientRect(hParent, &rc); + else + GetWindowRect(GetWindow(hWnd, GW_OWNER), &rc); + + pos.x = ((rc.right+rc.left)-sz.cx)/2; + pos.y = ((rc.bottom+rc.top)-sz.cy)/2; + break; + case 3: + GetCursorPos(&pos); + if (hParent) + ScreenToClient(hParent, &pos); + break; + default: + return; + } + + SetWindowPos(hWnd,NULL,pos.x,pos.y,sz.cx,sz.cy,SWP_NOZORDER); + } LRESULT CALLBACK HWindowSharedFunction(WNDPROC pDefWindowProc, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) *************** *** 162,167 **** pData->MinTrackSize.cx = 0; pData->MinTrackSize.cy = 0; SetWindowLong(hWnd,GWL_USERDATA,(LONG) pData); ! SetFocus(hWnd); } --- 221,227 ---- pData->MinTrackSize.cx = 0; pData->MinTrackSize.cy = 0; + pData->windowPos = -1; SetWindowLong(hWnd,GWL_USERDATA,(LONG) pData); ! SetFocus(hWnd); } *************** *** 212,216 **** } } ! handleControlCommand(hCtrl); } --- 272,276 ---- } } ! handleControlCommand(hCtrl); } *************** *** 220,224 **** FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); MenuHandle handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) LOWORD(wParam)); ! if (handle) { --- 280,284 ---- FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); MenuHandle handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) LOWORD(wParam)); ! if (handle) { *************** *** 232,236 **** { NMHDR *pNMHDR = (NMHDR *) lParam; ! if (pNMHDR->code == UDN_DELTAPOS) { --- 292,296 ---- { NMHDR *pNMHDR = (NMHDR *) lParam; ! if (pNMHDR->code == UDN_DELTAPOS) { *************** *** 487,494 **** pos.x = pData->Origin.x+GET_X_LPARAM(lParam); pos.y = pData->Origin.y+GET_Y_LPARAM(lParam); ! pData->bInDragMode = TRUE; handleWindowMouse(hWnd,evMouseLeftDown,pos.x,pos.y,GetModifiers()); ! SetCapture(hWnd); } --- 547,554 ---- pos.x = pData->Origin.x+GET_X_LPARAM(lParam); pos.y = pData->Origin.y+GET_Y_LPARAM(lParam); ! pData->bInDragMode = TRUE; handleWindowMouse(hWnd,evMouseLeftDown,pos.x,pos.y,GetModifiers()); ! SetCapture(hWnd); } *************** *** 552,559 **** pos.x = GET_X_LPARAM(lParam); pos.y = GET_Y_LPARAM(lParam); ! if (pos.x != 1 || pos.y != 1) ScreenToClient(hWnd, &pos); ! pos.x += pData->Origin.x; pos.y += pData->Origin.y; --- 612,619 ---- pos.x = GET_X_LPARAM(lParam); pos.y = GET_Y_LPARAM(lParam); ! if (pos.x != 1 || pos.y != 1) ScreenToClient(hWnd, &pos); ! pos.x += pData->Origin.x; pos.y += pData->Origin.y; *************** *** 630,634 **** { HDC hDC = (HDC) wParam; ! while (hWnd && !pData->hBackBrush) { --- 690,694 ---- { HDC hDC = (HDC) wParam; ! while (hWnd && !pData->hBackBrush) { *************** *** 636,640 **** pData = (WindowData *) GetWindowLong(hWnd,GWL_USERDATA); } ! SelectObject(hDC, pData->hBackBrush); SetBkColor(hDC, pData->backColor); --- 696,700 ---- pData = (WindowData *) GetWindowLong(hWnd,GWL_USERDATA); } ! SelectObject(hDC, pData->hBackBrush); SetBkColor(hDC, pData->backColor); *************** *** 671,675 **** char *title; int nTextLen; ! nTextLen = strlen(s); title = malloc(strlen(pFrameData->lpszAppName)+nTextLen+6); --- 731,735 ---- char *title; int nTextLen; ! nTextLen = strlen(s); title = malloc(strlen(pFrameData->lpszAppName)+nTextLen+6); *************** *** 683,687 **** SetWindowText(ghWndFrame, title); } ! free(title); } --- 743,747 ---- SetWindowText(ghWndFrame, title); } ! free(title); } *************** *** 713,717 **** switch (uMsg) ! { case WM_DESTROY: { --- 773,777 ---- switch (uMsg) ! { case WM_DESTROY: { *************** *** 919,923 **** pData->hBackBrush = CreateBrushIndirect(&lb); } ! pData->backColor = backColor; pData->foreColor = foreColor; --- 979,983 ---- pData->hBackBrush = CreateBrushIndirect(&lb); } ! pData->backColor = backColor; pData->foreColor = foreColor; *************** *** 1053,1057 **** void osSetWindowVisible(WindowHandle window, BOOL visible) { ! ShowWindow(window, visible ? SW_SHOW : SW_HIDE); } --- 1113,1123 ---- void osSetWindowVisible(WindowHandle window, BOOL visible) { ! if (visible) ! { ! SetupWindowPosition(window); ! ShowWindow(window, SW_SHOW); ! } ! else ! ShowWindow(window, SW_HIDE); } *************** *** 1065,1069 **** MSG msg; ! ShowWindow(window, SW_SHOW); SetActiveWindow(window); EnableWindow(GetWindow(window, GW_OWNER), FALSE); --- 1131,1135 ---- MSG msg; ! osSetWindowVisible(window, TRUE); SetActiveWindow(window); EnableWindow(GetWindow(window, GW_OWNER), FALSE); *************** *** 1284,1294 **** HWND hParent; LONG lStyle; ! ! lStyle = GetWindowLong(ctrl, GWL_STYLE); ! lStyle = visible ? (lStyle | WS_VISIBLE) : (lStyle & ~WS_VISIBLE); SetWindowLong(ctrl, GWL_STYLE, lStyle); ! hParent = GetParent(ctrl); ! GetWindowRect(ctrl, &rect); ScreenToClient(hParent, ((LPPOINT) &rect) ); --- 1350,1360 ---- HWND hParent; LONG lStyle; ! ! lStyle = GetWindowLong(ctrl, GWL_STYLE); ! lStyle = visible ? (lStyle | WS_VISIBLE) : (lStyle & ~WS_VISIBLE); SetWindowLong(ctrl, GWL_STYLE, lStyle); ! hParent = GetParent(ctrl); ! GetWindowRect(ctrl, &rect); ScreenToClient(hParent, ((LPPOINT) &rect) ); *************** *** 1397,1409 **** } ! void osSetWindowRect(WindowHandle window, int x0, int y0, int x1, int y1) { ! char buffer[20]; ! HWND hTargetWnd; ! GetClassName(window,buffer,sizeof(buffer)); ! hTargetWnd = (_stricmp(buffer, "HSDIWINDOW") == 0) ? ghWndFrame : window; ! ! SetWindowPos(hTargetWnd,NULL,x0,y0,abs(x1-x0),abs(y1-y0),SWP_NOZORDER); } --- 1463,1514 ---- } ! void osSetWindowPosition(WindowHandle window, int position, int x0, int y0, int x1, int y1) { ! char buffer[20]; ! GetClassName(window,buffer,sizeof(buffer)); ! ! if (_stricmp(buffer, "HSDIWINDOW") == 0) ! { ! POINT pos; ! SIZE sz; ! ! pos.x = x0; ! pos.y = y0; ! sz.cx = x1-x0; ! sz.cy = y1-y0; ! ! switch (position) ! { ! // When the window is a SDI window then the WinPosCenterToParent is the same as WinPosCenter ! case 1: ! case 2: ! CenterToScreen(&pos, sz); ! break; ! case 3: ! GetCursorPos(&pos); ! break; ! } ! ! SetWindowPos(ghWndFrame,NULL,pos.x,pos.y,sz.cx,sz.cy,SWP_NOZORDER); ! } ! else ! { ! WindowData *pData = (WindowData *) GetWindowLong(window,GWL_USERDATA); ! ! // if the window is a child window then the WinPosCenter is the same as WinPosCenterToParent ! if (GetParent(window) && position == 1) ! pData->windowPos = 2; ! else ! pData->windowPos = position; ! ! pData->windowPosRect.left = x0; ! pData->windowPosRect.top = y0; ! pData->windowPosRect.right = x1; ! pData->windowPosRect.bottom = y1; ! ! if (GetWindowLong(window,GWL_STYLE) & WS_VISIBLE) ! SetupWindowPosition(window); ! } } *************** *** 1424,1439 **** HWND hTargetWnd; FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! hTargetWnd = hwnd; if (pFrameData->DocumentInterface == 1 && GetParent(hwnd) == ghWndFrame) hTargetWnd = ghWndFrame; ! style = GetWindowLong(hTargetWnd, GWL_STYLE); if (resizeable) ! if (style & DS_MODALFRAME) style |= WS_THICKFRAME; else style |= WS_THICKFRAME | WS_MAXIMIZEBOX; ! else style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); SetWindowLong(hTargetWnd, GWL_STYLE, style); --- 1529,1544 ---- HWND hTargetWnd; FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! hTargetWnd = hwnd; if (pFrameData->DocumentInterface == 1 && GetParent(hwnd) == ghWndFrame) hTargetWnd = ghWndFrame; ! style = GetWindowLong(hTargetWnd, GWL_STYLE); if (resizeable) ! if (style & DS_MODALFRAME) style |= WS_THICKFRAME; else style |= WS_THICKFRAME | WS_MAXIMIZEBOX; ! else style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); SetWindowLong(hTargetWnd, GWL_STYLE, style); *************** *** 1465,1469 **** osForceContainerReLayout(window); } ! handleContainerReLayout(window); } --- 1570,1574 ---- osForceContainerReLayout(window); } ! handleContainerReLayout(window); } |