Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / logic / logic_editor_dll / ResizablePage.cpp
blobe36a3044bae823bdfce68dfbd77e8f1756da12ec
1 // ResizablePage.cpp : implementation file
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2000 by Paolo Messina
6 // (ppescher@yahoo.com)
7 //
8 // Free for non-commercial use.
9 // You may change the code to your needs,
10 // provided that credits to the original
11 // author is given in the modified files.
12 //
13 /////////////////////////////////////////////////////////////////////////////
15 #include "stdafx.h"
16 #include "ResizablePage.h"
18 #ifdef _DEBUG
19 #define new DEBUG_NEW
20 #undef THIS_FILE
21 static char THIS_FILE[] = __FILE__;
22 #endif
24 /////////////////////////////////////////////////////////////////////////////
25 // CResizablePage
27 IMPLEMENT_DYNCREATE(CResizablePage, CPropertyPage)
29 inline void CResizablePage::Construct()
31 m_bInitDone = FALSE;
34 CResizablePage::CResizablePage()
36 Construct();
39 CResizablePage::CResizablePage(UINT nIDTemplate, UINT nIDCaption)
40 : CPropertyPage(nIDTemplate, nIDCaption)
42 Construct();
45 CResizablePage::CResizablePage(LPCTSTR lpszTemplateName, UINT nIDCaption)
46 : CPropertyPage(lpszTemplateName, nIDCaption)
48 Construct();
51 CResizablePage::~CResizablePage()
53 Layout *pl;
55 POSITION pos = m_plLayoutList.GetHeadPosition();
57 while (pos != NULL)
59 pl = (Layout*)m_plLayoutList.GetNext(pos);
60 delete pl;
65 BEGIN_MESSAGE_MAP(CResizablePage, CPropertyPage)
66 //{{AFX_MSG_MAP(CResizablePage)
67 ON_WM_SIZE()
68 //}}AFX_MSG_MAP
69 END_MESSAGE_MAP()
72 /////////////////////////////////////////////////////////////////////////////
73 // CResizablePage message handlers
76 BOOL CResizablePage::OnInitDialog()
78 CPropertyPage::OnInitDialog();
80 // gets the initial size as the min track size
81 CRect rc;
82 GetWindowRect(&rc);
84 m_bInitDone = TRUE;
86 return TRUE; // return TRUE unless you set the focus to a control
87 // EXCEPTION: OCX Property Pages should return FALSE
90 void CResizablePage::AddAnchor(HWND wnd, CSize tl_type, CSize br_type)
92 ASSERT(wnd != NULL && ::IsWindow(wnd));
93 ASSERT(::IsChild(*this, wnd));
94 ASSERT(tl_type != NOANCHOR);
96 // get control's window class
98 CString st;
99 GetClassName(wnd, st.GetBufferSetLength(MAX_PATH), MAX_PATH);
100 st.ReleaseBuffer();
101 st.MakeUpper();
103 // add the style 'clipsiblings' to a GroupBox
104 // to avoid unnecessary repainting of controls inside
105 if (st == "BUTTON")
107 DWORD style = GetWindowLong(wnd, GWL_STYLE);
108 if (style & BS_GROUPBOX)
109 SetWindowLong(wnd, GWL_STYLE, style | WS_CLIPSIBLINGS);
112 // wnd classes that don't redraw client area correctly
113 // when the hor scroll pos changes due to a resizing
114 BOOL hscroll = FALSE;
115 if (st == "LISTBOX")
116 hscroll = TRUE;
118 // wnd classes that need refresh when resized
119 BOOL refresh = FALSE;
120 if (st == "STATIC")
122 DWORD style = GetWindowLong(wnd, GWL_STYLE);
124 switch (style & SS_TYPEMASK)
126 case SS_LEFT:
127 case SS_CENTER:
128 case SS_RIGHT:
129 // word-wrapped text needs refresh
130 refresh = TRUE;
133 // centered images or text need refresh
134 if (style & SS_CENTERIMAGE)
135 refresh = TRUE;
137 // simple text never needs refresh
138 if ((style & SS_TYPEMASK) == SS_SIMPLE)
139 refresh = FALSE;
142 // get dialog's and control's rect
143 CRect wndrc, objrc;
145 GetClientRect(&wndrc);
146 ::GetWindowRect(wnd, &objrc);
147 ScreenToClient(&objrc);
149 CSize tl_margin, br_margin;
151 if (br_type == NOANCHOR)
152 br_type = tl_type;
154 // calculate margin for the top-left corner
156 tl_margin.cx = objrc.left - wndrc.Width() * tl_type.cx / 100;
157 tl_margin.cy = objrc.top - wndrc.Height() * tl_type.cy / 100;
159 // calculate margin for the bottom-right corner
161 br_margin.cx = objrc.right - wndrc.Width() * br_type.cx / 100;
162 br_margin.cy = objrc.bottom - wndrc.Height() * br_type.cy / 100;
164 // add to the list
165 m_plLayoutList.AddTail(new Layout(wnd, tl_type, tl_margin,
166 br_type, br_margin, hscroll, refresh));
169 void CResizablePage::ArrangeLayout()
171 // init some vars
172 CRect wndrc;
173 GetClientRect(&wndrc);
175 Layout *pl;
176 POSITION pos = m_plLayoutList.GetHeadPosition();
178 HDWP hdwp = BeginDeferWindowPos((int)m_plLayoutList.GetCount());
180 while (pos != NULL)
182 pl = (Layout*)m_plLayoutList.GetNext(pos);
184 CRect objrc, newrc;
185 CWnd* wnd = CWnd::FromHandle(pl->hwnd); // temporary solution
187 wnd->GetWindowRect(&objrc);
188 ScreenToClient(&objrc);
190 // calculate new top-left corner
192 newrc.left = pl->tl_margin.cx + wndrc.Width() * pl->tl_type.cx / 100;
193 newrc.top = pl->tl_margin.cy + wndrc.Height() * pl->tl_type.cy / 100;
195 // calculate new bottom-right corner
197 newrc.right = pl->br_margin.cx + wndrc.Width() * pl->br_type.cx / 100;
198 newrc.bottom = pl->br_margin.cy + wndrc.Height() * pl->br_type.cy / 100;
200 if (!newrc.EqualRect(&objrc))
202 BOOL add = TRUE;
204 if (pl->adj_hscroll)
206 // needs repainting, due to horiz scrolling
207 int diff = newrc.Width() - objrc.Width();
208 int max = wnd->GetScrollLimit(SB_HORZ);
210 if (max > 0 && wnd->GetScrollPos(SB_HORZ) > max - diff)
212 wnd->MoveWindow(&newrc);
213 wnd->Invalidate();
214 wnd->UpdateWindow();
216 add = FALSE;
220 if (pl->need_refresh)
222 wnd->MoveWindow(&newrc);
223 wnd->Invalidate();
224 wnd->UpdateWindow();
226 add = FALSE;
229 if (add)
230 DeferWindowPos(hdwp, pl->hwnd, NULL, newrc.left, newrc.top,
231 newrc.Width(), newrc.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
235 // go re-arrange child windows
236 EndDeferWindowPos(hdwp);
239 void CResizablePage::OnSize(UINT nType, int cx, int cy)
241 CWnd::OnSize(nType, cx, cy);
243 if (m_bInitDone)
244 ArrangeLayout();