Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/helpers/dialog_resize_helper.cpp @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #include "StdAfx.h" | |
| 2 | |
| 3 #ifdef FOOBAR2000_DESKTOP_WINDOWS | |
| 4 #include "dialog_resize_helper.h" | |
| 5 | |
| 6 static BOOL GetChildWindowRect(HWND wnd, UINT id, RECT* child) | |
| 7 { | |
| 8 RECT temp; | |
| 9 HWND wndChild = GetDlgItem(wnd, id); | |
| 10 if (wndChild == NULL) return FALSE; | |
| 11 if (!GetWindowRect(wndChild, &temp)) return FALSE; | |
| 12 if (!MapWindowPoints(0, wnd, (POINT*)&temp, 2)) return FALSE; | |
| 13 *child = temp; | |
| 14 return TRUE; | |
| 15 } | |
| 16 | |
| 17 void dialog_resize_helper::set_parent(HWND wnd) | |
| 18 { | |
| 19 reset(); | |
| 20 parent = wnd; | |
| 21 GetClientRect(parent,&orig_client); | |
| 22 } | |
| 23 | |
| 24 void dialog_resize_helper::reset() | |
| 25 { | |
| 26 parent = 0; | |
| 27 sizegrip = 0; | |
| 28 } | |
| 29 | |
| 30 void dialog_resize_helper::on_wm_size() | |
| 31 { | |
| 32 if (parent) | |
| 33 { | |
| 34 unsigned count = (unsigned) m_table.get_size(); | |
| 35 if (sizegrip != 0) count++; | |
| 36 HDWP hWinPosInfo = BeginDeferWindowPos(count); | |
| 37 for(unsigned n=0;n<m_table.get_size();n++) | |
| 38 { | |
| 39 param & e = m_table[n]; | |
| 40 const RECT & orig_rect = rects[n]; | |
| 41 RECT cur_client; | |
| 42 GetClientRect(parent,&cur_client); | |
| 43 HWND wnd = GetDlgItem(parent,e.id); | |
| 44 if (wnd != NULL) { | |
| 45 unsigned dest_x = orig_rect.left, dest_y = orig_rect.top, | |
| 46 dest_cx = orig_rect.right - orig_rect.left, dest_cy = orig_rect.bottom - orig_rect.top; | |
| 47 | |
| 48 int delta_x = cur_client.right - orig_client.right, | |
| 49 delta_y = cur_client.bottom - orig_client.bottom; | |
| 50 | |
| 51 if (e.flags & X_MOVE) | |
| 52 dest_x += delta_x; | |
| 53 else if (e.flags & X_SIZE) | |
| 54 dest_cx += delta_x; | |
| 55 | |
| 56 if (e.flags & Y_MOVE) | |
| 57 dest_y += delta_y; | |
| 58 else if (e.flags & Y_SIZE) | |
| 59 dest_cy += delta_y; | |
| 60 | |
| 61 hWinPosInfo = DeferWindowPos(hWinPosInfo, wnd,0,dest_x,dest_y,dest_cx,dest_cy,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); | |
| 62 } | |
| 63 } | |
| 64 if (sizegrip != 0) | |
| 65 { | |
| 66 RECT rc, rc_grip; | |
| 67 GetClientRect(parent, &rc); | |
| 68 GetWindowRect(sizegrip, &rc_grip); | |
| 69 hWinPosInfo = DeferWindowPos(hWinPosInfo, sizegrip, NULL, rc.right - (rc_grip.right - rc_grip.left), rc.bottom - (rc_grip.bottom - rc_grip.top), 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSIZE); | |
| 70 } | |
| 71 EndDeferWindowPos(hWinPosInfo); | |
| 72 //RedrawWindow(parent,0,0,RDW_INVALIDATE); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 bool dialog_resize_helper::process_message(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) { | |
| 77 LRESULT result = 0; | |
| 78 if (!ProcessWindowMessage(wnd,msg,wp,lp,result)) return false; | |
| 79 SetWindowLongPtr(wnd,DWLP_MSGRESULT,result); | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 BOOL dialog_resize_helper::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult) { | |
| 84 switch(uMsg) { | |
| 85 case WM_SIZE: | |
| 86 on_wm_size(); | |
| 87 return FALSE; | |
| 88 case WM_GETMINMAXINFO: | |
| 89 { | |
| 90 RECT r; | |
| 91 LPMINMAXINFO info = (LPMINMAXINFO) lParam; | |
| 92 DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE); | |
| 93 DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE); | |
| 94 if (max_x && max_y) | |
| 95 { | |
| 96 r.left = 0; r.right = max_x; | |
| 97 r.top = 0; r.bottom = max_y; | |
| 98 MapDialogRect(hWnd,&r); | |
| 99 AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle); | |
| 100 info->ptMaxTrackSize.x = r.right - r.left; | |
| 101 info->ptMaxTrackSize.y = r.bottom - r.top; | |
| 102 } | |
| 103 if (min_x && min_y) | |
| 104 { | |
| 105 r.left = 0; r.right = min_x; | |
| 106 r.top = 0; r.bottom = min_y; | |
| 107 MapDialogRect(hWnd,&r); | |
| 108 AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle); | |
| 109 info->ptMinTrackSize.x = r.right - r.left; | |
| 110 info->ptMinTrackSize.y = r.bottom - r.top; | |
| 111 } | |
| 112 } | |
| 113 lResult = 0; | |
| 114 return TRUE; | |
| 115 case WM_INITDIALOG: | |
| 116 set_parent(hWnd); | |
| 117 { | |
| 118 t_size n; | |
| 119 for(n=0;n<m_table.get_size();n++) { | |
| 120 GetChildWindowRect(parent,m_table[n].id,&rects[n]); | |
| 121 } | |
| 122 } | |
| 123 return FALSE; | |
| 124 case WM_DESTROY: | |
| 125 reset(); | |
| 126 return FALSE; | |
| 127 default: | |
| 128 return FALSE; | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 void dialog_resize_helper::add_sizegrip() | |
| 133 { | |
| 134 if (parent != 0 && sizegrip == 0) | |
| 135 { | |
| 136 sizegrip = CreateWindowEx(0, WC_SCROLLBAR, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SBS_SIZEGRIP | SBS_SIZEBOXBOTTOMRIGHTALIGN, | |
| 137 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, | |
| 138 parent, (HMENU)0, NULL, NULL); | |
| 139 if (sizegrip != 0) | |
| 140 { | |
| 141 RECT rc, rc_grip; | |
| 142 GetClientRect(parent, &rc); | |
| 143 GetWindowRect(sizegrip, &rc_grip); | |
| 144 SetWindowPos(sizegrip, NULL, rc.right - (rc_grip.right - rc_grip.left), rc.bottom - (rc_grip.bottom - rc_grip.top), 0, 0, SWP_NOZORDER | SWP_NOSIZE); | |
| 145 } | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 | |
| 150 dialog_resize_helper::dialog_resize_helper(const param * src,unsigned count,unsigned p_min_x,unsigned p_min_y,unsigned p_max_x,unsigned p_max_y) | |
| 151 : min_x(p_min_x), min_y(p_min_y), max_x(p_max_x), max_y(p_max_y), parent(0), sizegrip(0) | |
| 152 { | |
| 153 m_table.set_size(count); | |
| 154 unsigned n; | |
| 155 for(n=0;n<count;n++) | |
| 156 m_table[n] = src[n]; | |
| 157 rects.set_size(count); | |
| 158 } | |
| 159 | |
| 160 dialog_resize_helper::~dialog_resize_helper() | |
| 161 { | |
| 162 } | |
| 163 | |
| 164 #endif // FOOBAR2000_DESKTOP_WINDOWS |
