void CRepositoryBrowser::OnLButtonDown(UINT nFlags, CPoint point) { RECT rect, tree, list, treelist, treelistclient; // create an union of the tree and list control rectangle GetDlgItem(IDC_REPOLIST)->GetWindowRect(&list); GetDlgItem(IDC_REPOTREE)->GetWindowRect(&tree); UnionRect(&treelist, &tree, &list); treelistclient = treelist; ScreenToClient(&treelistclient); //convert the mouse coordinates relative to the top-left of //the window ClientToScreen(&point); GetClientRect(&rect); ClientToScreen(&rect); point.x -= rect.left; point.y -= treelist.top; //same for the window coordinates - make them relative to 0,0 OffsetRect(&treelist, -treelist.left, -treelist.top); if (point.x < treelist.left + REPOBROWSER_CTRL_MIN_WIDTH) return CStandAloneDialogTmpl < CResizableDialog>::OnLButtonDown(nFlags, point); if (point.x > treelist.right - 3) return CStandAloneDialogTmpl < CResizableDialog>::OnLButtonDown(nFlags, point); if (point.x > treelist.right - REPOBROWSER_CTRL_MIN_WIDTH) point.x = treelist.right - REPOBROWSER_CTRL_MIN_WIDTH; if ((point.y < treelist.top + 3) || (point.y > treelist.bottom - 3)) return CStandAloneDialogTmpl<CResizableDialog>::OnLButtonDown(nFlags, point); bDragMode = true; SetCapture(); CDC * pDC = GetDC(); DrawXorBar(pDC, point.x + 2, treelistclient.top, 4, treelistclient.bottom - treelistclient.top - 2); ReleaseDC(pDC); oldx = point.x; oldy = point.y; CStandAloneDialogTmpl<CResizableDialog>::OnLButtonDown(nFlags, point); }
SIZE Toolbar::minimumSize() { RECT start, end, sum = { 0 }; unsigned int totalNum = sendMessage( TB_BUTTONCOUNT, 0, 0 ); if( totalNum != 0 ) { if( totalNum == 1 ) sendMessage( TB_GETITEMRECT, 0, (LPARAM)&sum ); else { sendMessage( TB_GETITEMRECT, 0, (LPARAM)&start ); sendMessage( TB_GETITEMRECT, totalNum - 1, (LPARAM)&end ); UnionRect( &sum, &start, &end ); } } SIZE result = { sum.right - sum.left, sum.bottom - sum.top }; return result; }
void wf_info_find_invalid_region(wfInfo* wfi) { #ifdef WITH_DXGI_1_2 wf_dxgi_getInvalidRegion(&wfi->invalid); #else int i; GETCHANGESBUF* buf; buf = (GETCHANGESBUF*) wfi->changeBuffer; for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF) { LPRECT lpR = &buf->buffer->pointrect[i].rect; //need to make sure we only get updates from the selected screen if ( (lpR->left >= wfi->servscreen_xoffset) && (lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width) ) && (lpR->top >= wfi->servscreen_yoffset) && (lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height) ) ) { UnionRect(&wfi->invalid, &wfi->invalid, lpR); } else { continue; } } #endif if (wfi->invalid.left < 0) wfi->invalid.left = 0; if (wfi->invalid.top < 0) wfi->invalid.top = 0; if (wfi->invalid.right >= wfi->servscreen_width) wfi->invalid.right = wfi->servscreen_width - 1; if (wfi->invalid.bottom >= wfi->servscreen_height) wfi->invalid.bottom = wfi->servscreen_height - 1; //WLog_DBG(TAG, "invalid region: (%d, %d), (%d, %d)", wfi->invalid.left, wfi->invalid.top, wfi->invalid.right, wfi->invalid.bottom); }
// ---------------------------------------------------------------------------- // // CenterRectangles() // Move all the rectangles so their origin is the center of their union. // // ---------------------------------------------------------------------------- void NEAR PASCAL CenterRectangles(LPRECT arc, UINT count) { LPRECT lprc, lprcL; RECT rcUnion; CopyRect(&rcUnion, arc); lprcL = arc + count; for (lprc = arc + 1; lprc < lprcL; lprc++) { UnionRect(&rcUnion, &rcUnion, lprc); } for (lprc = arc; count; count--) { OffsetRect(lprc, -RectCenterX(&rcUnion), -RectCenterY(&rcUnion)); lprc++; } }
void get_ctrl_row_metrics(struct ctrl_row_dimensions * dim, HWND hw_lbl, HWND hw_ctl) { assert(hw_lbl); assert(hw_ctl); GetWindowRect(hw_lbl, &dim->label); GetWindowRect(hw_ctl, &dim->control); UnionRect(&dim->enclosure, &dim->label, &dim->control); OffsetRect(&dim->label, -dim->enclosure.left, -dim->enclosure.top); OffsetRect(&dim->control, -dim->enclosure.left, -dim->enclosure.top); OffsetRect(&dim->enclosure, -dim->enclosure.left, -dim->enclosure.top); }
void ToolbarGetUnionRect(RECT* prcRect) { int i; if (!prcRect) return; prcRect->left = 0; prcRect->top = 0; prcRect->right = 0; prcRect->bottom = 0; for (i = 0; i < num_buttons; i++) { RECT rcButton; GetWindowRect(buttons[i].hwnd, &rcButton); ScreenToClient(hMain, (POINT*)&rcButton); ScreenToClient(hMain, (POINT*)(&rcButton)+1); if (IsWindowVisible(buttons[i].hwnd)) UnionRect(prcRect, prcRect, &rcButton); } }
///////////////////////////////////////////////////////////////////////////// // CFragment::AddString void CFragment::AddString( CSTR_line* Comingline, PageElementCount* Count) { CFPage Page; CSTR_line line; CSTR_attr line_attr; CFString* String; RECT TmpRect,*PrevStringRect; uchar Flag_Continuation_Strings = FALSE; uchar dist; if(CheckLineForFilling(Comingline)==FALSE) return; line = *Comingline; CSTR_GetLineAttr(line , &line_attr); SetRect(&TmpRect, line_attr.col - TemplateOffset.x , line_attr.row - TemplateOffset.y, line_attr.col - TemplateOffset.x+ line_attr.wid, line_attr.row - TemplateOffset.y + line_attr.hei); UnionRect(&m_rectFrag, &m_rectFrag, &TmpRect); dist = line_attr.hei/2; if( m_wStringsCount>0 ) { String = (CFString*)m_arStrings[m_wStringsCount-1]; PrevStringRect=&String->m_rectString ; if( TmpRect.top < PrevStringRect->bottom && TmpRect.left > PrevStringRect->right && abs(TmpRect.top - PrevStringRect->top) <=dist && abs(TmpRect.bottom - PrevStringRect->bottom) <=dist ) Flag_Continuation_Strings = TRUE; } if(!Flag_Continuation_Strings) { ++m_wStringsCount; ++Count->Strings; m_arStrings.push_back( new CFString() ); String = m_arStrings[m_wStringsCount-1]; String->S_Flags = line_attr.Flags; //NEGA_STR } assert(String); String->ExtractWordsFromString( Comingline ,Count ); }
start_edit(TableUI *tui, int edit_existing) { RECT rt = get_cell_rect(tui, tui->cur_row, tui->cur_col), rt_cont = rt; if (is_editing(tui)) end_edit(tui); if (edit_existing) { Cell cell = try_cell(tui->table, tui->cur_row, tui->cur_col); SetWindowTextA(tui->edit, cell.str); /* Resize Edit to fit content; at least as big as the cell */ DrawTextA(tui->bitmap, cell.str, cell.len, &rt_cont, DT_NOPREFIX | DT_RIGHT | DT_CALCRECT | DT_EDITCONTROL); UnionRect(&rt, &rt, &rt_cont); } else SetWindowText(tui->edit, L""); MoveWindow(tui->edit, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, 0); ShowWindow(tui->edit, SW_NORMAL); SetFocus(tui->edit); }
static void in_ArrangeWindows(int n, void** windows, int action, int preserve, int outer) { int j; if (action == MINIMIZE || action == RESTORE) { for (j=0; j<n; j++) ShowWindow((HWND)windows[j], action == MINIMIZE ? SW_MINIMIZE : SW_RESTORE); } else { RECT rect = {0,0,0,0}; RECT *prect = ▭ HWND parent; if (preserve) { WINDOWPLACEMENT wp; wp.length = sizeof(wp); for (j=0; j<n; j++) { if (GetWindowPlacement((HWND)windows[j], &wp)) { UnionRect(prect, prect, &wp.rcNormalPosition); if (wp.showCmd == SW_SHOWMINIMIZED || wp.showCmd == SW_SHOWMAXIMIZED) { wp.showCmd = SW_RESTORE; SetWindowPlacement((HWND)windows[j], &wp); } } } } if (rect.left == rect.right || rect.top == rect.bottom) prect = NULL; if (!outer && ismdi()) parent = GetParent(getHandle(RConsole)); else parent = NULL; switch (action) { case CASCADE: CascadeWindows(parent, 0, prect, n, (HWND FAR *)windows); break; case TILEHORIZ: TileWindows(parent, MDITILE_HORIZONTAL, prect, n, (HWND FAR *)windows); break; case TILEVERT: TileWindows(parent, MDITILE_VERTICAL, prect, n, (HWND FAR *)windows); break; } } }
/* * newChildPositions - handle re-location of a child window */ static void newChildPositions( void ) { mdi_data *curr; RECT r; RECT orig; if( childrenMaximized ) { return; } curr = mdiHead; memset( &minChildRect, 0, sizeof( RECT ) ); while( curr != NULL ) { _wpi_getwindowrect( curr->hwnd, &r ); orig = minChildRect; UnionRect( &minChildRect, &orig, &r ); haveMinChildRect = TRUE; curr = curr->next; } tryContainerScrollBars(); } /* newChildPositions */
void xinerama_init( unsigned int width, unsigned int height ) { MONITORINFOEXW *primary; int i; RECT rect; SetRect( &rect, 0, 0, width, height ); if (root_window != DefaultRootWindow( gdi_display ) || !query_screens()) { default_monitor.rcWork = default_monitor.rcMonitor = rect; if (root_window == DefaultRootWindow( gdi_display )) query_work_area( &default_monitor.rcWork ); else query_desktop_work_area( &default_monitor.rcWork ); nb_monitors = 1; monitors = &default_monitor; } primary = get_primary(); SetRectEmpty( &virtual_screen_rect ); /* coordinates (0,0) have to point to the primary monitor origin */ OffsetRect( &rect, -primary->rcMonitor.left, -primary->rcMonitor.top ); for (i = 0; i < nb_monitors; i++) { OffsetRect( &monitors[i].rcMonitor, rect.left, rect.top ); OffsetRect( &monitors[i].rcWork, rect.left, rect.top ); UnionRect( &virtual_screen_rect, &virtual_screen_rect, &monitors[i].rcMonitor ); TRACE( "monitor %p: %s work %s%s\n", index_to_monitor(i), wine_dbgstr_rect(&monitors[i].rcMonitor), wine_dbgstr_rect(&monitors[i].rcWork), (monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? " (primary)" : "" ); } TRACE( "virtual size: %s primary: %s\n", wine_dbgstr_rect(&virtual_screen_rect), wine_dbgstr_rect(&primary->rcMonitor) ); }
int wf_dxgi_getInvalidRegion(RECT* invalid) { UINT i; HRESULT status; UINT dirty; UINT BufSize; RECT* pRect; BYTE* DirtyRects; UINT DataBufferSize = 0; BYTE* DataBuffer = NULL; if (FrameInfo.AccumulatedFrames == 0) { return 1; } if (FrameInfo.TotalMetadataBufferSize) { if (FrameInfo.TotalMetadataBufferSize > DataBufferSize) { if (DataBuffer) { free(DataBuffer); DataBuffer = NULL; } DataBuffer = (BYTE*) malloc(FrameInfo.TotalMetadataBufferSize); if (!DataBuffer) { DataBufferSize = 0; _tprintf(_T("Failed to allocate memory for metadata\n")); exit(1); } DataBufferSize = FrameInfo.TotalMetadataBufferSize; } BufSize = FrameInfo.TotalMetadataBufferSize; status = gOutputDuplication->lpVtbl->GetFrameMoveRects(gOutputDuplication, BufSize, (DXGI_OUTDUPL_MOVE_RECT*) DataBuffer, &BufSize); if (FAILED(status)) { _tprintf(_T("Failed to get frame move rects\n")); return 1; } DirtyRects = DataBuffer + BufSize; BufSize = FrameInfo.TotalMetadataBufferSize - BufSize; status = gOutputDuplication->lpVtbl->GetFrameDirtyRects(gOutputDuplication, BufSize, (RECT*) DirtyRects, &BufSize); if (FAILED(status)) { _tprintf(_T("Failed to get frame dirty rects\n")); return 1; } dirty = BufSize / sizeof(RECT); pRect = (RECT*) DirtyRects; for(i = 0; i<dirty; ++i) { UnionRect(invalid, invalid, pRect); ++pRect; } } return 0; }
// // Position / size controls and main window based // on current system metrics // void WinSpyDlg_SizeContents(HWND hwnd) { int x, y, cx, cy; int i; RECT rect, rect1; HWND hwndTab; HWND hwndCtrl; int nPaneWidth; // width of each dialog-pane int nPaneHeight; // height of each dialog-pane int nActualPaneWidth; // what the tab-control is set to. int nTabWidth; int nTabHeight; int nDesiredTabWidth; // HARD-CODED sizes for each window layout. // These are DIALOG UNITS, so it's not too bad. duMinimized.cx = 254; duMinimized.cy = 25;//6; duNormal.cx = duMinimized.cx; duNormal.cy = 251; duExpanded.cx = 432;//390; duExpanded.cy = duNormal.cy; // work out the size (in pixels) of each window layout CalcDlgWindowSize(hwnd, &duMinimized, 0, &szMinimized); CalcDlgWindowSize(hwnd, &duNormal, 0, &szNormal); CalcDlgWindowSize(hwnd, &duExpanded, 0, &szExpanded); // resize to NORMAL layout (temporarily) SetWindowPos(hwnd, 0, 0, 0, szNormal.cx, szNormal.cy, SWP_SIZEONLY | SWP_NOREDRAW); // Locate main Property sheet control hwndTab = GetDlgItem(hwnd, IDC_TAB1); // Get SCREEN coords of tab control GetWindowRect(hwndTab, &rect); // Get SCREEN coords of dialog's CLIENT area if (IsIconic(hwnd)) { // If the window is minimized, calc the client rect manually rect1.left = 0; rect1.top = 0; rect1.right = szNormal.cx - 2 * GetSystemMetrics(SM_CXFRAME); rect1.bottom = szNormal.cy - 2 * GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYCAPTION); } else GetClientRect(hwnd, &rect1); MapWindowPoints(hwnd, 0, (POINT *)&rect1, 2); // Now we know what the border is between TAB and left-side nLeftBorder = rect.left - rect1.left; nBottomBorder = rect1.bottom - rect.bottom; nDesiredTabWidth = (rect1.right - rect1.left) - nLeftBorder * 2; // // Find out the size of the biggest dialog-tab-pane // SetRect(&rect, 0, 0, 0, 0); for (i = 0; i < NUMTABCONTROLITEMS; i++) { // Get tab-pane relative to parent (main) window GetClientRect(WinSpyTab[i].hwnd, &rect1); MapWindowPoints(WinSpyTab[i].hwnd, hwnd, (POINT *)&rect1, 2); // find biggest UnionRect(&rect, &rect, &rect1); } nPaneWidth = GetRectWidth(&rect); nPaneHeight = GetRectHeight(&rect); // Resize the tab control based on this biggest rect SendMessage(hwndTab, TCM_ADJUSTRECT, TRUE, (LPARAM)&rect); nTabWidth = GetRectWidth(&rect); nTabHeight = GetRectHeight(&rect); // Resize the tab control now we know how big it needs to be SetWindowPos(hwndTab, hwnd, 0, 0, nDesiredTabWidth, nTabHeight, SWP_SIZEONLY); // // Tab control is now in place. // Now find out exactly where to position every // tab-pane. (We know how big they are, but we need // to find where to move them to). // GetWindowRect(hwndTab, &rect); ScreenToClient(hwnd, (POINT *)&rect.left); ScreenToClient(hwnd, (POINT *)&rect.right); SendMessage(hwndTab, TCM_ADJUSTRECT, FALSE, (LPARAM)&rect); x = rect.left; y = rect.top; cx = nPaneWidth; cy = nPaneHeight; nActualPaneWidth = GetRectWidth(&rect); // Center each dialog-tab in the tab control x += (nActualPaneWidth - nPaneWidth) / 2; // position each dialog in the right place for (i = 0; i < NUMTABCONTROLITEMS; i++) { SetWindowPos(WinSpyTab[i].hwnd, hwndTab, x, y, cx, cy, SWP_NOACTIVATE); } SetWindowPos(hwnd, 0, 0, 0, szMinimized.cx, szMinimized.cy, SWP_NOMOVE | SWP_NOZORDER); // Even though we are initially minimized, we want to // automatically expand to normal view the first time a // window is selected. szCurrent = szMinimized; szLastMax = szNormal; szLastExp = szExpanded; SetWindowPos(hwndTab, //GetDlgItem(hwnd, IDC_MINIMIZE) HWND_BOTTOM, 0, 0, 0, 0, SWP_ZONLY); // Finally, move the little expand / shrink button // so it is right-aligned with the edge of the tab. hwndCtrl = GetDlgItem(hwnd, IDC_EXPAND); GetWindowRect(hwndCtrl, &rect); MapWindowPoints(0, hwnd, (POINT *)&rect, 2); x = nDesiredTabWidth + nLeftBorder - GetRectWidth(&rect); y = rect.top; SetWindowPos(hwndCtrl, 0, x, y, 0, 0, SWP_MOVEONLY); }
//纯文本式的右下角浮出窗口过程 LRESULT CALLBACK NotifyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LPNOTIFYWND_DATA pInfo = NULL; RECT rc; POINT pt; //这是一个广播消息 if(message == g_NotifyInfo.nMsg_ExitNow) { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); //通知主窗口退出(即客户端主程序退出) if(pInfo != NULL && pInfo->mode == MODE_TEXT) PostMessage(g_NotifyInfo.hWndMainFrm, WM_EXITNOW, 0, 0); return TRUE; } switch (message) { case WM_NCCREATE: { SIZE _size = { 0 }; LPCREATESTRUCT pCreateStruct = (LPCREATESTRUCT)lParam; LPCTSTR pStr = _T("啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"); pInfo = (LPNOTIFYWND_DATA)malloc(sizeof(NOTIFYWND_DATA)); memset(pInfo, 0, sizeof(NOTIFYWND_DATA)); pInfo->mode = (int)(pCreateStruct->lpCreateParams); //创建内存位图和DC HDC hdc = GetDC(hWnd); pInfo->hMemDC = CreateCompatibleDC(hdc); HGDIOBJ hOldFont = SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontContent); GetTextExtentPoint32(pInfo->hMemDC, pStr, _tcslen(pStr), &_size); pInfo->hMemBm = CreateCompatibleBitmap(hdc, _size.cx + g_NotifyInfo.imgSize + 48, 600); ReleaseDC(hWnd, hdc); SelectObject(pInfo->hMemDC, hOldFont); SelectObject(pInfo->hMemDC, pInfo->hMemBm); pInfo->contentWidth = _size.cx + g_NotifyInfo.gap; pInfo->titleHeight = _size.cy; pInfo->rcIcon.left = 3 + g_NotifyInfo.gap; pInfo->rcTitle.left = pInfo->rcIcon.left + g_NotifyInfo.iconSize + g_NotifyInfo.gap; pInfo->rcTitle.top = 3 + g_NotifyInfo.gap; pInfo->rcTitle.bottom = pInfo->rcTitle.top + pInfo->titleHeight; pInfo->rcIcon.top = (pInfo->rcTitle.top + pInfo->rcTitle.bottom - g_NotifyInfo.iconSize)/2; pInfo->rcIcon.right = pInfo->rcIcon.left + g_NotifyInfo.iconSize; pInfo->rcIcon.bottom = pInfo->rcIcon.top + g_NotifyInfo.iconSize; pInfo->rcContentOutter.left = 3; pInfo->rcContentOutter.top = pInfo->rcTitle.bottom + g_NotifyInfo.gap; pInfo->rcImg.left = pInfo->rcContentOutter.left + g_NotifyInfo.gap; pInfo->rcImg.top = pInfo->rcContentOutter.top + g_NotifyInfo.gap; pInfo->rcImg.right = pInfo->rcImg.left + g_NotifyInfo.imgSize; pInfo->rcImg.bottom = pInfo->rcImg.top + g_NotifyInfo.imgSize; SetWindowPos(hWnd, HWND_TOPMOST, -10000, -10000, pInfo->wndWidth, pInfo->wndHeight, SWP_HIDEWINDOW); pInfo->tme.cbSize = sizeof(TRACKMOUSEEVENT); pInfo->tme.dwFlags = TME_LEAVE; //我们需要 WM_MOUSELEAVE 消息; pInfo->tme.hwndTrack = hWnd; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)pInfo); } return TRUE; case WM_PAINT: { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); BitBlt(hdc, 0, 0, pInfo->wndWidth, pInfo->wndHeight, pInfo->hMemDC, 0, 0, SRCCOPY); //绘制closebtn(有进度条时,不能关闭) int imgIndex = IMG_NORMAL; if(pInfo->bMouseOnClose) { imgIndex = (pInfo->bMouseDown && pInfo->bCloseBtnPushed)? IMG_PUSHED : IMG_HOVER; } g_NotifyInfo.pImgCloseBtns->TransparentBlt(hdc, pInfo->rcCloseBtn.left, pInfo->rcCloseBtn.top, g_NotifyInfo.closeBtnSize, g_NotifyInfo.closeBtnSize, imgIndex * g_NotifyInfo.closeBtnSize, 0, g_NotifyInfo.closeBtnSize, g_NotifyInfo.closeBtnSize, RGB(255, 0, 255)); EndPaint(hWnd, &ps); } return TRUE; case WM_ERASEBKGND: return TRUE; case WM_UPDATEPROGRESS: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; if(pInfo->mode == MODE_PROGRESS) { LPCTSTR pStr = (LPCTSTR)lParam; if(pStr != NULL) _tcscpy_s(pInfo->szProgressText, _ARRAYSIZE(pInfo->szProgressText), pStr); pInfo->progress = (int)wParam; //绘制进度条 HGDIOBJ hOldFont = SelectObject(pInfo->hMemDC, g_NotifyInfo.hFontContent); SetTextColor(pInfo->hMemDC, g_NotifyInfo.clrContent); FillRect(pInfo->hMemDC, &pInfo->rcProgressText, (HBRUSH)GetStockObject(WHITE_BRUSH)); DrawText(pInfo->hMemDC, pInfo->szProgressText, -1, &pInfo->rcProgressText, DT_LEFT | DT_TOP | DT_SINGLELINE); SelectObject(pInfo->hMemDC, hOldFont); FillRect(pInfo->hMemDC, &pInfo->rcProgressBar, (HBRUSH)GetStockObject(WHITE_BRUSH)); CopyRect(&rc, &pInfo->rcProgressBar); rc.right = pInfo->rcProgressBar.left + (pInfo->rcProgressBar.right - pInfo->rcProgressBar.left) * pInfo->progress / 100; FillRect(pInfo->hMemDC, &rc, GetSysColorBrush(COLOR_ACTIVECAPTION)); //pInfo->hBrush); if(pInfo->progress >= 100) { //5 秒后自动隐藏 pInfo->bDownloading = FALSE; SetTimer(hWnd, TIMERID_NOTIFY_HIDE, 2000, NULL); } UnionRect(&rc, &pInfo->rcProgressText, &pInfo->rcProgressBar); InvalidateRect(hWnd, &rc, FALSE); } return TRUE; case WM_MOUSEMOVE: { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); BOOL bTmp = PtInRect(&pInfo->rcCloseBtn, pt); if(bTmp != pInfo->bMouseOnClose) { pInfo->bMouseOnClose = bTmp; InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); } TrackMouseEvent(&pInfo->tme); } break; case WM_MOUSELEAVE: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; if(pInfo->bMouseOnClose) { pInfo->bMouseOnClose = FALSE; InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); } break; case WM_LBUTTONDOWN: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); pInfo->bMouseDown = TRUE; if(PtInRect(&pInfo->rcCloseBtn, pt)) { pInfo->bCloseBtnPushed = TRUE; InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); SetCapture(hWnd); } break; case WM_LBUTTONUP: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); pInfo->bMouseDown = FALSE; if(pInfo->bCloseBtnPushed) { pInfo->bCloseBtnPushed = FALSE; ReleaseCapture(); if(PtInRect(&pInfo->rcCloseBtn, pt)) { KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); KillTimer(hWnd, TIMERID_NOTIFY_HIDING); KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); InvalidateRect(hWnd, &pInfo->rcCloseBtn, FALSE); //ShowWindow(hDlg, SW_HIDE); //用渐隐( AW_BLEND )的方式隐藏窗口,动画时间:200ms AnimateWindow(hWnd, 200, AW_HIDE | AW_BLEND); } } break; case WM_TIMER: pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; GetWindowRect(hWnd, &rc); switch(wParam) { case TIMERID_NOTIFY_SHOWING: if((rc.bottom - rc.top) >= (pInfo->wndHeight - g_NotifyInfo.dy)) { KillTimer(hWnd, wParam); SetWindowPos(hWnd, NULL, rc.left, rc.bottom - pInfo->wndHeight, pInfo->wndWidth, pInfo->wndHeight, SWP_NOZORDER | SWP_NOACTIVATE); } else { SetWindowPos(hWnd, NULL, rc.left, rc.top - g_NotifyInfo.dy, pInfo->wndWidth, (rc.bottom - rc.top) + g_NotifyInfo.dy, SWP_NOZORDER | SWP_NOACTIVATE); } break; case TIMERID_NOTIFY_HIDING: { UINT flags = SWP_NOZORDER | SWP_NOACTIVATE; if((rc.bottom - rc.top) <= 0) { KillTimer(hWnd, wParam); flags = flags | SWP_HIDEWINDOW; } SetWindowPos(hWnd, NULL, rc.left, rc.top + g_NotifyInfo.dy, pInfo->wndWidth, rc.bottom - rc.top - g_NotifyInfo.dy, flags); } break; case TIMERID_NOTIFY_TIMEOUT: { KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); SetTimer(hWnd, TIMERID_NOTIFY_HIDING, INTERVAL_NOTIFYWND, NULL); } break; case TIMERID_NOTIFY_HIDE: //立即隐藏 { KillTimer(hWnd, TIMERID_NOTIFY_SHOWING); KillTimer(hWnd, TIMERID_NOTIFY_HIDING); KillTimer(hWnd, TIMERID_NOTIFY_TIMEOUT); KillTimer(hWnd, TIMERID_NOTIFY_HIDE); AnimateWindow(hWnd, 200, AW_HIDE | AW_BLEND); } break; } break; case WM_POWERBROADCAST: { //TCHAR szText[256]; //PBT_APMQUERYSUSPEND //_stprintf_s(szText, _ARRAYSIZE(szText), _T("NotifyWnd_PowerEvent: event = %x"), wParam); //WriteLogLine(szText); pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo != NULL && pInfo->mode == MODE_TEXT) return SendMessage(g_NotifyInfo.hWndMainFrm, WM_POWERBROADCAST, wParam, lParam); } break; case WM_NCDESTROY: { pInfo = (LPNOTIFYWND_DATA)GetWindowLongPtr(hWnd, GWLP_USERDATA); if(pInfo == NULL) return TRUE; //DeleteCriticalSection(&g_NotifyInfo.cs); DeleteObject(pInfo->hMemBm); DeleteDC(pInfo->hMemDC); free(pInfo); SetWindowLongPtr(hWnd, GWLP_USERDATA, NULL); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
inline void CRectTplt<T>::operator|=(const CRectTplt& rect) { UnionRect(this, &rect); }
void CEmotionButton::DoEvent(TEventUI& event) { switch( event.Type) { case UIEVENT_MOUSEMOVE: { RECT rc1, rc2, invalidRect; int lastCol = -1, curCol = -1; unsigned char changetype = _PosChangeType::NoChange; //预览矩形是否需要改变 POINT pt = event.ptMouse; int tmpSel = GetCellIndex(pt.x, pt.y); //是否超出了图片数量 if((tmpSel + curPage * CELLCOUNT_PAGE) >= m_ImageCount) tmpSel = -1; if(tmpSel != curSel) { //两个cell 索引行进 lastSel = curSel; curSel = tmpSel; curFrame = 0; //预览矩形需要移动吗? lastCol = (lastSel % 15); curCol = (curSel % 15); //每行15个 GetBlueRect(lastSel, &rc1); GetBlueRect(curSel, &rc2); UnionRect(&invalidRect, &rc1, &rc2); invalidRect.right++; invalidRect.bottom++; //判断缩略矩形是否发生位置改变? if(pvstatus == _PVStatus::Hide) { if(curSel >= 0) { if((curSel%15) > 7) { pvstatus = _PVStatus::Left; changetype = _PosChangeType::HideToLeft; } else { pvstatus = _PVStatus::Right; changetype = _PosChangeType::HideToRight; } } } else if(pvstatus == _PVStatus::Left) { if(curSel < 0) { pvstatus = _PVStatus::Hide; changetype = _PosChangeType::LeftToHide; } else if(curCol < 4 || (curCol == 4 && lastCol == 4)) { pvstatus = _PVStatus::Right; changetype = _PosChangeType::LeftToRight; } } else if(pvstatus == _PVStatus::Right) { if(curSel < 0) { pvstatus = _PVStatus::Hide; changetype = _PosChangeType::RightToHide; } else if(curCol > 10 || (curCol == 10 && lastCol == 10)) { pvstatus = _PVStatus::Left; changetype = _PosChangeType::RightToLeft; } } //刷新蓝色矩形框 UpdateSelectedFace(curPage, curSel, curFrame, pvstatus); this->Invalidate(); if(changetype == _PosChangeType::NoChange) { //刷新预览图片 if(pvstatus == _PVStatus::Left) { this->Invalidate(); //InvalidateRect(hDlg, &rcLeft, FALSE); } else if(pvstatus == _PVStatus::Right) { this->Invalidate(); //InvalidateRect(hDlg, &rcRight, FALSE); } } else { CopyRect(&rc1, &rcLeft); CopyRect(&rc2, &rcRight); rc1.right++; rc1.bottom++; rc2.right++; rc2.bottom++; //擦除原位置的缩略图 switch(changetype & 0xf0) { case 0x00: break; case 0x10: this->Invalidate(); //InvalidateRect(hDlg, &rc1, FALSE); break; case 0x20: this->Invalidate(); //InvalidateRect(hDlg, &rc2, FALSE); break; } //显示新位置上的缩略图 switch(changetype & 0x0f) { case 0x00: pvstatus == _PVStatus::Hide; break; case 0x01: this->Invalidate(); //InvalidateRect(hDlg, &rc1, FALSE); break; case 0x02: this->Invalidate(); //InvalidateRect(hDlg, &rc2, FALSE); break; } } //安装定时器(显示动画) if(curSel >= 0) { UINT frameDelay = 200; CxImage* pImg = GetSelectedImage(curPage, curSel); CxImage* pFrame = pImg->GetFrame(curFrame); //QQ表情的帧延时通常是10毫秒,显示速度过快,因此增大到50毫秒 if(pFrame != NULL) frameDelay = max(frameDelay, pFrame->GetFrameDelay()); frameCount = pImg->GetNumFrames(); this->m_pManager->SetTimer(this, TIMER_SHOWGIF, frameDelay); } else { this->m_pManager->KillTimer(this, TIMER_SHOWGIF); } } //使系统通知我们 WM_MOUSELEAVE ; TrackMouseEvent(&m_tme); //注意版本需求:_WIN32_WINNT 0x0510 } break; case UIEVENT_MOUSELEAVE: { if(curSel >= 0) { RECT rc; GetBlueRect(curSel, &rc); lastSel = curSel; curSel = -1; curFrame = 0; pvstatus = _PVStatus::Hide; UpdateSelectedFace(curPage, curSel, curFrame, pvstatus); this->Invalidate(); //InvalidateRect(hDlg, &rc, FALSE); } } break; case UIEVENT_TIMER: { this->m_pManager->KillTimer(this, TIMER_SHOWGIF); if(curSel >= 0 && frameCount > 1) { CxImage *pImg = GetSelectedImage(curPage, curSel); CxImage *pFrame = NULL; UINT frameDelay = 200; LPRECT lpRect = (pvstatus == _PVStatus::Left)? &rcLeft:&rcRight; //移动到下一帧! curFrame = (curFrame + 1) % frameCount; //QQ表情的帧延时通常是10毫秒,显示速度过快,因此增大到100毫秒 pFrame = pImg->GetFrame(curFrame); if(pFrame) frameDelay = max(frameDelay, pFrame->GetFrameDelay()); UpdateSelectedFace(curPage, curSel, curFrame, pvstatus); this->Invalidate(); //InvalidateRect(hDlg, lpRect, FALSE); //下一帧的定时时间 this->m_pManager->SetTimer(this, TIMER_SHOWGIF, frameDelay); } } break; } }
void CUIRect::Union(CUIRect& rc) { UnionRect(this, this, &rc); }
/* * DescDialogProc: Dialog procedure for dialog containing an * item's long description. */ BOOL CALLBACK DescDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { DescDialogStruct *info; static HWND hwndBitmap; static Bool changed; // True when player has changed description HWND hEdit, hwndOK, hURL, hFixed; HDC hdc; HFONT hFont; RECT dlg_rect, edit_rect, fixed_rect; AREA area; char *desc, *str, url[MAX_URL + 1], *pPageBreak; DRAWITEMSTRUCT *lpdis; char descriptionBuffer[MAX_PAGE_DESCRIPTION_TEXT+1]; int height; info = (DescDialogStruct *) GetWindowLong(hDlg, DWL_USER); switch (message) { case WM_INITDIALOG: info = (DescDialogStruct *) lParam; /* Store structure in dialog box's extra bytes */ SetWindowLong(hDlg, DWL_USER, (long) info); hwndBitmap = GetDlgItem(hDlg, IDC_DESCBITMAP); hFixed = GetDlgItem(hDlg, IDC_DESCFIXED); hEdit = GetDlgItem(hDlg, IDC_DESCBOX); hwndOK = GetDlgItem(hDlg, IDOK); // Item Name. height = SetFontToFitText(info,GetDlgItem(hDlg, IDC_DESCNAME), (int)FONT_TITLES, info->name); SetDlgItemText(hDlg, IDC_DESCNAME, info->name); hdc = GetDC(hDlg); SetTextColor(hdc,GetPlayerNameColor(info->obj,info->name)); ReleaseDC(hDlg,hdc); // Item Description. hFont = GetFont(FONT_EDIT); SetWindowFont(hFixed, hFont, FALSE); SetWindowFont(hEdit, hFont, FALSE); str = info->description; if (str) { pPageBreak = strchr(str,PAGE_BREAK_CHAR); while (pPageBreak) { info->numPages++; str = pPageBreak+1; pPageBreak = strchr(str,PAGE_BREAK_CHAR); } info->numPages++; GetPageText(descriptionBuffer,info); Edit_SetText(hEdit, descriptionBuffer); } // Show fixed string, if appropriate if (info->fixed_string != NULL) { SetDlgItemText(hDlg, IDC_DESCFIXED, info->fixed_string); SetWindowFont(GetDlgItem(hDlg, IDC_DESCFIXED), GetFont(FONT_EDIT), FALSE); } // Can this player edit this object's description? if (info->flags & DF_EDITABLE) Edit_SetReadOnly(hEdit, FALSE); Edit_LimitText(hEdit, MAX_DESCRIPTION); if (!(info->flags & (DF_EDITABLE | DF_INSCRIBED)) && !str) { GetWindowRect(hFixed, &fixed_rect); GetWindowRect(hEdit, &edit_rect); UnionRect(&fixed_rect, &fixed_rect, &edit_rect); ScreenToClient(hDlg, (LPPOINT)(&fixed_rect)); ScreenToClient(hDlg, (LPPOINT)(&fixed_rect)+1); MoveWindow(hFixed, fixed_rect.left, fixed_rect.top, fixed_rect.right - fixed_rect.left, fixed_rect.bottom - fixed_rect.top, FALSE); ShowWindow(hEdit, SW_HIDE); } // Resize and move dialog controls GetWindowRect(hDlg, &dlg_rect); if (GetWindowLong(hEdit, GWL_STYLE) & WS_VISIBLE) { ShowWindow(hEdit, SW_HIDE); ResizeEditToFitText(hFixed, hFont); ResizeDialog(hDlg, &dlg_rect, desc_controls); ShowWindow(hEdit, SW_SHOW); } else { ResizeEditToFitText(hFixed, hFont); ResizeDialog(hDlg, &dlg_rect, desc_controls); } if (GetWindowLong(hEdit, GWL_STYLE) & WS_VISIBLE) { GetWindowRect(hFixed, &fixed_rect); GetWindowRect(hEdit, &edit_rect); height = fixed_rect.bottom-edit_rect.top; ScreenToClient(hDlg, (LPPOINT)(&edit_rect)); ScreenToClient(hDlg, (LPPOINT)(&edit_rect)+1); ShowWindow(hFixed, SW_HIDE); OffsetRect(&edit_rect, 0, height); MoveWindow(hEdit, edit_rect.left, edit_rect.top, edit_rect.right - edit_rect.left, edit_rect.bottom - edit_rect.top, FALSE); GetWindowRect(hDlg, &dlg_rect); ResizeEditToFitText(hEdit, hFont); ResizeDialog(hDlg, &dlg_rect, desc_controls); ShowWindow(hFixed, SW_SHOW); } CenterWindow(hDlg, GetParent(hDlg)); // Show URL, if appropriate if (info->url != NULL) { hURL = GetDlgItem(hDlg, IDC_URL); SetWindowText(hURL, info->url); SetWindowFont(hURL, GetFont(FONT_EDIT), FALSE); if (info->flags & DF_EDITABLE) Edit_SetReadOnly(hURL, FALSE); Edit_LimitText(hURL, MAX_URL); } // Show appropriate buttons if (!(desc_flags & DESC_GET)) DestroyWindow(GetDlgItem(hDlg, IDC_GET)); if (!(desc_flags & DESC_DROP)) DestroyWindow(GetDlgItem(hDlg, IDC_DROP)); if (!(desc_flags & DESC_USE)) DestroyWindow(GetDlgItem(hDlg, IDC_USE)); if (!(desc_flags & DESC_UNUSE)) DestroyWindow(GetDlgItem(hDlg, IDC_UNUSE)); if (!(desc_flags & DESC_INSIDE)) DestroyWindow(GetDlgItem(hDlg, IDC_INSIDE)); if (!(desc_flags & DESC_ACTIVATE)) DestroyWindow(GetDlgItem(hDlg, IDC_ACTIVATE)); if (!(desc_flags & DESC_APPLY)) DestroyWindow(GetDlgItem(hDlg, IDC_APPLY)); SetLookPageButtons(hDlg, info); #if 0 if (info->numPages < 2) { HWND hwnd = GetDlgItem(hDlg,IDC_NEXT); if (hwnd) DestroyWindow(GetDlgItem(hDlg, IDC_NEXT)); hwnd = GetDlgItem(hDlg,IDC_PREV); if (hwnd) DestroyWindow(GetDlgItem(hDlg, IDC_PREV)); } else { HWND hwnd = GetDlgItem(hDlg,IDC_PREV); if (hwnd) EnableWindow(hwnd,FALSE); } #endif SetFocus(hwndOK); hDescDialog = hDlg; changed = False; return FALSE; case WM_PAINT: InvalidateRect(hwndBitmap, NULL, TRUE); UpdateWindow(hwndBitmap); /* fall through */ case BK_ANIMATE: /* Draw object's bitmap */ hdc = GetDC(hwndBitmap); GetClientRect(hwndBitmap, &dlg_rect); RectToArea(&dlg_rect, &area); DrawStretchedObjectGroup(hdc, info->obj, info->obj->animate->group, &area, GetSysColorBrush(COLOR_3DFACE)); ReleaseDC(hwndBitmap, hdc); break; HANDLE_MSG(hDlg, WM_CTLCOLOREDIT, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORLISTBOX, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORSTATIC, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORDLG, DialogCtlColor); case WM_DESTROY: hDescDialog = NULL; return TRUE; case WM_DRAWITEM: // Draw player name in color that reflects murderer status lpdis = (DRAWITEMSTRUCT *) lParam; switch (lpdis->itemAction) { case ODA_SELECT: case ODA_DRAWENTIRE: SelectPalette(lpdis->hDC, hPal, FALSE); hFont = info->hFontTitle; SelectObject(lpdis->hDC, hFont); SetBkMode(lpdis->hDC, TRANSPARENT); str = LookupNameRsc(info->obj->name_res); SetTextColor(lpdis->hDC, NAME_COLOR_NORMAL_BG); DrawText(lpdis->hDC, str, strlen(str), &lpdis->rcItem, DT_LEFT | DT_VCENTER | DT_NOPREFIX); OffsetRect(&lpdis->rcItem, -1, -1); SetTextColor(lpdis->hDC, GetPlayerNameColor(info->obj, info->name)); DrawText(lpdis->hDC, str, strlen(str), &lpdis->rcItem, DT_LEFT | DT_VCENTER | DT_NOPREFIX); break; } return TRUE; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_PREV: if (info->currentPage > 0) info->currentPage--; GetPageText(descriptionBuffer,info); SetLookPageButtons(hDlg, info); Edit_SetText(GetDlgItem(hDlg, IDC_DESCBOX), descriptionBuffer); #if 0 EnableWindow(GetDlgItem(hDlg,IDC_PREV),info->currentPage > 0); EnableWindow(GetDlgItem(hDlg,IDC_NEXT),info->currentPage < info->numPages-1); #endif return TRUE; case IDC_NEXT: if (info->currentPage < info->numPages-1) info->currentPage++; GetPageText(descriptionBuffer,info); Edit_SetText(GetDlgItem(hDlg, IDC_DESCBOX), descriptionBuffer); SetLookPageButtons(hDlg, info); #if 0 EnableWindow(GetDlgItem(hDlg,IDC_PREV),info->currentPage > 0); EnableWindow(GetDlgItem(hDlg,IDC_NEXT),info->currentPage < info->numPages-1); #endif return TRUE; case IDC_GET: RequestPickup(info->obj->id); EndDialog(hDlg, 0); return TRUE; case IDC_DROP: // Drop all of number items info->obj->temp_amount = info->obj->amount; RequestDrop(info->obj); EndDialog(hDlg, 0); return TRUE; case IDC_USE: // If player isn't holding the object (i.e. there's a Get button), pick object up first if (IsWindowVisible(GetDlgItem(hDlg, IDC_GET))) RequestPickup(info->obj->id); RequestUse(info->obj->id); EndDialog(hDlg, 0); return TRUE; case IDC_UNUSE: RequestUnuse(info->obj->id); EndDialog(hDlg, 0); return TRUE; case IDC_INSIDE: RequestObjectContents(info->obj->id); EndDialog(hDlg, 0); return TRUE; case IDC_ACTIVATE: RequestActivate(info->obj->id); EndDialog(hDlg, 0); return TRUE; case IDC_APPLY: StartApply(info->obj->id); EndDialog(hDlg, 0); return TRUE; case IDC_DESCBOX: if (GET_WM_COMMAND_CMD(wParam, lParam) != EN_CHANGE) break; changed = True; return TRUE; case IDC_URLBUTTON: hURL = GetDlgItem(hDlg, IDC_URL); Edit_GetText(hURL, url, MAX_URL); WebLaunchBrowser(url); return TRUE; case IDOK: // Send new description if changed if (changed) { desc = (char *) SafeMalloc(MAX_DESCRIPTION + 1); GetDlgItemText(hDlg, IDC_DESCBOX, desc, MAX_DESCRIPTION); RequestChangeDescription(info->obj->id, desc); SafeFree(desc); } // Send new URL if changed if (info->url != NULL) { GetDlgItemText(hDlg, IDC_URL, url, MAX_URL); if (strcmp(url, info->url)) RequestChangeURL(player.id, url); } // FALLTHRU case IDCANCEL: SetWindowFont(GetDlgItem(hDlg,IDC_DESCNAME), GetFont(FONT_TITLES), FALSE); if (info->hFontTitle && info->hFontTitle != GetFont(FONT_TITLES)) DeleteObject(info->hFontTitle); info->hFontTitle = NULL; EndDialog(hDlg, IDOK == GET_WM_COMMAND_ID(wParam, lParam)); return TRUE; } break; } return FALSE; }
int FileDialog::ShowModal() { OSErr err; NavDialogCreationOptions dialogCreateOptions; // set default options ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions); // this was always unset in the old code dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; wxMacCFStringHolder message(m_message, GetFont().GetEncoding()); dialogCreateOptions.windowTitle = message; wxMacCFStringHolder defaultFileName(m_fileName, GetFont().GetEncoding()); dialogCreateOptions.saveFileName = defaultFileName; NavDialogRef dialog; NavObjectFilterUPP navFilterUPP = NULL; CustomData myData; SetRect(&myData.bounds, 0, 0, 0, 0); myData.me = this; myData.window = NULL; myData.defaultLocation = m_dir; myData.userpane = NULL; myData.choice = NULL; myData.button = NULL; myData.saveMode = false; myData.showing = true; Rect r; SInt16 base; SInt16 margin = 3; SInt16 gap = 0; MakeUserDataRec(&myData , m_wildCard); myData.currentfilter = m_filterIndex; size_t numFilters = myData.extensions.GetCount(); if (numFilters) { CreateNewMenu(0, 0, &myData.menu); for ( size_t i = 0 ; i < numFilters ; ++i ) { ::AppendMenuItemTextWithCFString(myData.menu, wxMacCFStringHolder(myData.name[i], GetFont().GetEncoding()), 4, i, NULL); } SetRect(&r, 0, margin, 0, 0); CreatePopupButtonControl(NULL, &r, CFSTR("Format:"), -12345, true, -1, teJustLeft, normal, &myData.choice); SetControlID(myData.choice, &kChoiceID); SetControlPopupMenuRef(myData.choice, myData.menu); SetControl32BitMinimum(myData.choice, 1); SetControl32BitMaximum(myData.choice, myData.name.GetCount()); SetControl32BitValue(myData.choice, myData.currentfilter + 1); GetBestControlRect(myData.choice, &r, &base); SizeControl(myData.choice, r.right - r.left, r.bottom - r.top); UnionRect(&myData.bounds, &r, &myData.bounds); gap = 15; HIObjectSetAuxiliaryAccessibilityAttribute((HIObjectRef)myData.choice, 0, kAXDescriptionAttribute, CFSTR("Format")); } if (!m_buttonlabel.IsEmpty()) { wxMacCFStringHolder cfString(wxStripMenuCodes(m_buttonlabel).c_str(), wxFONTENCODING_DEFAULT); SetRect(&r, myData.bounds.right + gap, margin, 0, 0); CreatePushButtonControl(NULL, &r, cfString, &myData.button); SetControlID(myData.button, &kButtonID); GetBestControlRect(myData.button, &r, &base); SizeControl(myData.button, r.right - r.left, r.bottom - r.top); UnionRect(&myData.bounds, &r, &myData.bounds); } // Expand bounding rectangle to include a top and bottom margin myData.bounds.top -= margin; myData.bounds.bottom += margin; dialogCreateOptions.optionFlags |= kNavNoTypePopup; if (m_dialogStyle & wxFD_SAVE) { dialogCreateOptions.modality = kWindowModalityWindowModal; dialogCreateOptions.parentWindow = (WindowRef) GetParent()->MacGetTopLevelWindowRef(); myData.saveMode = true; if (!numFilters) { dialogCreateOptions.optionFlags |= kNavNoTypePopup; } dialogCreateOptions.optionFlags |= kNavDontAutoTranslate; dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems; // The extension is important if (numFilters < 2) dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension; #if TARGET_API_MAC_OSX if (!(m_dialogStyle & wxFD_OVERWRITE_PROMPT)) { dialogCreateOptions.optionFlags |= kNavDontConfirmReplacement; } #endif err = ::NavCreatePutFileDialog(&dialogCreateOptions, // Suppresses the 'Default' (top) menu item kNavGenericSignature, kNavGenericSignature, sStandardNavEventFilter, &myData, // for defaultLocation &dialog); } else { //let people select bundles/programs in dialogs dialogCreateOptions.optionFlags |= kNavSupportPackages; navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback); err = ::NavCreateGetFileDialog(&dialogCreateOptions, NULL, // NavTypeListHandle sStandardNavEventFilter, NULL, // NavPreviewUPP navFilterUPP, (void *) &myData, // inClientData &dialog); } if (err == noErr) err = ::NavDialogRun(dialog); if (err == noErr) { myData.window = NavDialogGetWindow(dialog); Rect r; // This creates our "fake" dialog with the same dimensions as the sheet so // that Options dialogs will center properly on the sheet. The "fake" dialog // is never actually seen. GetWindowBounds(myData.window, kWindowStructureRgn, &r); wxDialog::Create(NULL, // no parent...otherwise strange things happen wxID_ANY, wxEmptyString, wxPoint(r.left, r.top), wxSize(r.right - r.left, r.bottom - r.top)); BeginAppModalStateForWindow(myData.window); while (myData.showing) { wxTheApp->MacDoOneEvent(); } EndAppModalStateForWindow(myData.window); } // clean up filter related data, etc. if (navFilterUPP) ::DisposeNavObjectFilterUPP(navFilterUPP); if (err != noErr) return wxID_CANCEL; NavReplyRecord navReply; err = ::NavDialogGetReply(dialog, &navReply); if (err == noErr && navReply.validRecord) { AEKeyword theKeyword; DescType actualType; Size actualSize; FSRef theFSRef; wxString thePath ; m_filterIndex = myData.currentfilter; long count; ::AECountItems(&navReply.selection , &count); for (long i = 1; i <= count; ++i) { err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType, &theFSRef, sizeof(theFSRef), &actualSize); if (err != noErr) break; if (m_dialogStyle & wxFD_SAVE) thePath = wxMacFSRefToPath( &theFSRef , navReply.saveFileName ) ; else thePath = wxMacFSRefToPath( &theFSRef ) ; if (!thePath) { ::NavDisposeReply(&navReply); return wxID_CANCEL; } m_path = ConvertSlashInFileName(thePath); m_paths.Add(m_path); m_fileName = wxFileNameFromPath(m_path); m_fileNames.Add(m_fileName); } // set these to the first hit m_path = m_paths[0]; m_fileName = wxFileNameFromPath(m_path); m_dir = wxPathOnly(m_path); } ::NavDisposeReply(&navReply); return (err == noErr) ? wxID_OK : wxID_CANCEL; }
HRESULT CMatrixBox::OnItemDrag(CMatrixItem* pEventSource) { if(m_pParentFrame == NULL) { return E_FAIL; } CPoint pt; GetCursorPos(&pt); CRect rcScreen = GetScreenRect(); CRect rcScreenParent = m_pParentFrame->GetScreenRect(); CRect rcClip; ::IntersectRect(&rcClip,&rcScreen,&rcScreenParent); CRect rcDrag = pEventSource->GetDragRect(); int nWidth = rcDrag.Width()/2 + 9 ; int nHeight = rcDrag.Height()/2 + 3; CRect rcDragItem = pEventSource->GetRect(); int nOverFlow = 0; if(pt.x < rcClip.left + nWidth) { nOverFlow = 1; pt.x = rcClip.left + nWidth; } if(pt.y < rcClip.top + nHeight) { nOverFlow = 2; pt.y = rcClip.top + nHeight; } if(pt.x > rcClip.right - (rcDragItem.Width() - nWidth)) { nOverFlow = 3; pt.x = rcClip.right - (rcDragItem.Width() - nWidth); } if(pt.y > rcClip.bottom - (rcDragItem.Height() - nHeight)) { nOverFlow = 4; pt.y = rcClip.bottom - (rcDragItem.Height() - nHeight); } pt.x = pt.x - nWidth - rcScreen.left ; pt.y = pt.y - nHeight - rcScreen.top ; CRect rcOldPaint = pEventSource->GetPaintRect(); pEventSource->SetPosition(pt); pt.x += nWidth; pt.y += nHeight; vector<CXFrame*> vec = m_vecItem; int nIndexMine = 0; for(vector<CXFrame*>::iterator it = vec.begin();it != vec.end();it++) { if(*it == pEventSource) { vec.erase(it); break; } nIndexMine ++; } BOOL bMoved = FALSE; int nIndex = 0; for(vector<CXFrame*>::iterator it = vec.begin();it != vec.end();it++) { CMatrixItem* pItem = (CMatrixItem*)*it; CRect rcItem = pItem->GetRect(); if(pItem->GetEnableDrag() && rcItem.PtInRect(pt)) { if(nIndex < nIndexMine) { vec.insert(it,pEventSource); } else if(nIndex == vec.size() - 1) { vec.push_back(pEventSource); } else { vec.insert(it+1,pEventSource); } bMoved = TRUE; break; } nIndex ++; } if(bMoved) { m_vecItem.clear(); m_vecItem = vec; Relayout(); QuickPaint(GetPaintRect()); } else { pEventSource->Relayout(); CRect rcDst; CRect rcCur = pEventSource->GetPaintRect(); UnionRect(&rcDst,&rcOldPaint,&rcCur); QuickPaint(rcDst); } if(nOverFlow) { ThrowEvent(EVENT_MATRIX_DRAG_OVERFLOW,&nOverFlow); } return S_OK; }
void MoveAndResizeTool::continueDraw( int x, int y, DWORD flags ) { if ( currentElement_ && draggedBoundary_.bt!= btNone ) { POINT* elementBasePoint = 0; if ( draggedBoundary_.gpt == MovableElement::gptStartPoint ) { elementBasePoint = ¤tElement_->startPoint_; } else if ( draggedBoundary_.gpt == MovableElement::gptEndPoint ) { elementBasePoint = ¤tElement_->endPoint_; } int elWidth = 0; int elHeight = 0; int elX = 0; int elY = 0; if ( elementBasePoint ) { elementBasePoint->x = x; elementBasePoint->y = y; elWidth = currentElement_->getWidth(); elHeight = currentElement_->getHeight(); elX = currentElement_->getX(); elY = currentElement_->getY(); } else { elWidth = currentElement_->getWidth(); elHeight = currentElement_->getHeight(); elX = currentElement_->getX(); elY = currentElement_->getY(); switch ( draggedBoundary_.bt ) { case btBottomRight: elWidth = x - elX+1; elHeight = y - elY+1; break; case btBottom: elHeight = y - elY+1; break; case btRight: elWidth = x - elX+1; break; case btTopLeft: elWidth = elX - x + elWidth; elHeight = elY - y + elHeight; elX = x; elY = y; case btLeft: elWidth = elX - x + elWidth; elX = x; break; case btTop: elHeight = elY - y + elHeight; elY = y; break; case btBottomLeft: elWidth = elX - x + elWidth; elHeight = y - elY+1; elX = x; break; case btTopRight: elWidth = x - elX+1; elHeight = elY - y + elHeight; elY = y; //currentElement_->setEndPoint() } //LOG(INFO) << "Resizing object to " << elX << " "<< elY << " " << elWidth << " "<<elHeight; currentElement_->resize( elWidth,elHeight); currentElement_->setX(elX); currentElement_->setY(elY); } if ( currentElement_ && currentElement_->getType() == etCrop && canvas_->onCropChanged ) { canvas_->onCropChanged(currentElement_->getX(), currentElement_->getY(), currentElement_->getWidth(), currentElement_->getHeight()); } RECT paintBoundingRect = currentElement_->getPaintBoundingRect(); RECT updateRect; UnionRect(&updateRect, &paintBoundingRect, &prevPaintBoundingRect_); canvas_->updateView(updateRect); prevPaintBoundingRect_ = paintBoundingRect; return; } if ( isMoving_ && currentElement_ ) { int newX = currentElement_->getX() + x - startPoint_.x; int newY = currentElement_->getY() + y - startPoint_.y; //LOG(INFO) << "Moving object to new position " << newX << " "<<newY; currentElement_->setX(newX); currentElement_->setY(newY); startPoint_.x = x; startPoint_.y = y; RECT paintBoundingRect = currentElement_->getPaintBoundingRect(); RECT updateRect; UnionRect(&updateRect, &paintBoundingRect, &prevPaintBoundingRect_); canvas_->updateView(updateRect); if ( currentElement_ && currentElement_->getType() == etCrop && canvas_->onCropChanged ) { canvas_->onCropChanged(currentElement_->getX(), currentElement_->getY(), currentElement_->getWidth(), currentElement_->getHeight()); } prevPaintBoundingRect_ = currentElement_->getPaintBoundingRect(); return; } if ( currentElement_ ) { POINT pt = { x, y }; currentElement_->setEndPoint( pt ); /*if ( currentElement_ && currentElement_->getType() == etCrop && canvas_->onCropChanged ) { //LOG(INFO) << "onCropChanged"; canvas_->onCropChanged(currentElement_->getX(), currentElement_->getY(), currentElement_->getWidth(), currentElement_->getHeight()); }*/ RECT paintBoundingRect = currentElement_->getPaintBoundingRect(); RECT updateRect; UnionRect(&updateRect, &paintBoundingRect, &prevPaintBoundingRect_); canvas_->updateView(updateRect); prevPaintBoundingRect_ = currentElement_->getPaintBoundingRect(); } }