OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "xfa/fwl/core/fwl_formimp.h" | |
8 | |
9 #include "xfa/fde/tto/fde_textout.h" | |
10 #include "xfa/fwl/basewidget/fwl_formproxyimp.h" | |
11 #include "xfa/fwl/core/cfwl_message.h" | |
12 #include "xfa/fwl/core/cfwl_themebackground.h" | |
13 #include "xfa/fwl/core/cfwl_themepart.h" | |
14 #include "xfa/fwl/core/cfwl_themetext.h" | |
15 #include "xfa/fwl/core/cfwl_widgetmgr.h" | |
16 #include "xfa/fwl/core/fwl_noteimp.h" | |
17 #include "xfa/fwl/core/fwl_widgetimp.h" | |
18 #include "xfa/fwl/core/ifwl_app.h" | |
19 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
20 #include "xfa/fwl/theme/cfwl_widgettp.h" | |
21 | |
22 namespace { | |
23 | |
24 const int kSystemButtonSize = 21; | |
25 const int kSystemButtonMargin = 5; | |
26 const int kSystemButtonSpan = 2; | |
27 | |
28 } // namespace | |
29 | |
30 namespace { | |
31 | |
32 const uint8_t kCornerEnlarge = 10; | |
33 | |
34 } // namespace | |
35 | |
36 // static | |
37 IFWL_Form* IFWL_Form::CreateFormProxy(CFWL_WidgetImpProperties& properties, | |
38 CFX_WideString* classname, | |
39 IFWL_Widget* pOuter) { | |
40 IFWL_Form* pForm = new IFWL_Form; | |
41 CFWL_FormProxyImp* pFormProxyImpl = new CFWL_FormProxyImp(properties, pOuter); | |
42 pForm->SetImpl(pFormProxyImpl); | |
43 pFormProxyImpl->SetInterface(pForm); | |
44 return pForm; | |
45 } | |
46 IFWL_Form::IFWL_Form() {} | |
47 FWL_FORMSIZE IFWL_Form::GetFormSize() { | |
48 return static_cast<CFWL_FormImp*>(GetImpl())->GetFormSize(); | |
49 } | |
50 FWL_Error IFWL_Form::SetFormSize(FWL_FORMSIZE eFormSize) { | |
51 return static_cast<CFWL_FormImp*>(GetImpl())->SetFormSize(eFormSize); | |
52 } | |
53 IFWL_Widget* IFWL_Form::DoModal() { | |
54 return static_cast<CFWL_FormImp*>(GetImpl())->DoModal(); | |
55 } | |
56 IFWL_Widget* IFWL_Form::DoModal(uint32_t& dwCommandID) { | |
57 return static_cast<CFWL_FormImp*>(GetImpl())->DoModal(dwCommandID); | |
58 } | |
59 FWL_Error IFWL_Form::EndDoModal() { | |
60 return static_cast<CFWL_FormImp*>(GetImpl())->EndDoModal(); | |
61 } | |
62 FWL_Error IFWL_Form::SetBorderRegion(CFX_Path* pPath) { | |
63 return static_cast<CFWL_FormImp*>(GetImpl())->SetBorderRegion(pPath); | |
64 } | |
65 | |
66 RestoreResizeInfo::RestoreResizeInfo() {} | |
67 | |
68 RestoreResizeInfo::~RestoreResizeInfo() {} | |
69 | |
70 CFWL_FormImp::CFWL_FormImp(const CFWL_WidgetImpProperties& properties, | |
71 IFWL_Widget* pOuter) | |
72 : CFWL_WidgetImp(properties, pOuter), | |
73 m_pCloseBox(nullptr), | |
74 m_pMinBox(nullptr), | |
75 m_pMaxBox(nullptr), | |
76 m_pCaptionBox(nullptr), | |
77 m_pSubFocus(nullptr), | |
78 m_fCXBorder(0), | |
79 m_fCYBorder(0), | |
80 m_iCaptureBtn(-1), | |
81 m_iSysBox(0), | |
82 m_eResizeType(FORM_RESIZETYPE_None), | |
83 m_bLButtonDown(FALSE), | |
84 m_bMaximized(false), | |
85 m_bSetMaximize(FALSE), | |
86 m_bCustomizeLayout(FALSE), | |
87 m_eFormSize(FWL_FORMSIZE_Manual), | |
88 m_bDoModalFlag(FALSE), | |
89 m_pBigIcon(nullptr), | |
90 m_pSmallIcon(nullptr), | |
91 m_bMouseIn(FALSE) { | |
92 m_rtRelative.Reset(); | |
93 m_rtCaption.Reset(); | |
94 m_rtRestore.Reset(); | |
95 m_rtCaptionText.Reset(); | |
96 m_rtIcon.Reset(); | |
97 } | |
98 | |
99 CFWL_FormImp::~CFWL_FormImp() { | |
100 RemoveSysButtons(); | |
101 } | |
102 | |
103 FWL_Error CFWL_FormImp::GetClassName(CFX_WideString& wsClass) const { | |
104 wsClass = FWL_CLASS_Form; | |
105 return FWL_Error::Succeeded; | |
106 } | |
107 | |
108 FWL_Type CFWL_FormImp::GetClassID() const { | |
109 return FWL_Type::Form; | |
110 } | |
111 | |
112 FX_BOOL CFWL_FormImp::IsInstance(const CFX_WideStringC& wsClass) const { | |
113 if (wsClass == CFX_WideStringC(FWL_CLASS_Form)) | |
114 return TRUE; | |
115 return CFWL_WidgetImp::IsInstance(wsClass); | |
116 } | |
117 | |
118 FWL_Error CFWL_FormImp::Initialize() { | |
119 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
120 return FWL_Error::Indefinite; | |
121 RegisterForm(); | |
122 RegisterEventTarget(); | |
123 m_pDelegate = new CFWL_FormImpDelegate(this); | |
124 return FWL_Error::Succeeded; | |
125 } | |
126 FWL_Error CFWL_FormImp::Finalize() { | |
127 delete m_pDelegate; | |
128 m_pDelegate = nullptr; | |
129 UnregisterEventTarget(); | |
130 UnRegisterForm(); | |
131 return CFWL_WidgetImp::Finalize(); | |
132 } | |
133 FWL_Error CFWL_FormImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
134 if (bAutoSize) { | |
135 rect.Reset(); | |
136 FX_FLOAT fCapHeight = GetCaptionHeight(); | |
137 FX_FLOAT fCXBorder = GetBorderSize(TRUE); | |
138 FX_FLOAT fCYBorder = GetBorderSize(FALSE); | |
139 FX_FLOAT fEdge = GetEdgeWidth(); | |
140 rect.height += fCapHeight + fCYBorder + fEdge + fEdge; | |
141 rect.width += fCXBorder + fCXBorder + fEdge + fEdge; | |
142 } else { | |
143 rect = m_pProperties->m_rtWidget; | |
144 } | |
145 return FWL_Error::Succeeded; | |
146 } | |
147 FWL_Error CFWL_FormImp::GetClientRect(CFX_RectF& rect) { | |
148 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Caption) == 0) { | |
149 rect = m_pProperties->m_rtWidget; | |
150 rect.Offset(-rect.left, -rect.top); | |
151 return FWL_Error::Succeeded; | |
152 } | |
153 #ifdef FWL_UseMacSystemBorder | |
154 rect = m_rtRelative; | |
155 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | |
156 if (!pWidgetMgr) | |
157 return FWL_Error::Indefinite; | |
158 | |
159 rect.left = 0; | |
160 rect.top = 0; | |
161 return FWL_Error::Succeeded; | |
162 #else | |
163 FX_FLOAT x = 0; | |
164 FX_FLOAT y = 0; | |
165 FX_FLOAT t = 0; | |
166 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
167 if (pTheme) { | |
168 CFWL_ThemePart part; | |
169 part.m_pWidget = m_pInterface; | |
170 x = *static_cast<FX_FLOAT*>( | |
171 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::CXBorder)); | |
172 y = *static_cast<FX_FLOAT*>( | |
173 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::CYBorder)); | |
174 t = *static_cast<FX_FLOAT*>( | |
175 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::CYCaption)); | |
176 } | |
177 rect = m_pProperties->m_rtWidget; | |
178 rect.Offset(-rect.left, -rect.top); | |
179 rect.Deflate(x, t, x, y); | |
180 return FWL_Error::Succeeded; | |
181 #endif | |
182 } | |
183 FWL_Error CFWL_FormImp::Update() { | |
184 if (m_iLock > 0) { | |
185 return FWL_Error::Succeeded; | |
186 } | |
187 if (!m_pProperties->m_pThemeProvider) { | |
188 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
189 } | |
190 #ifdef FWL_UseMacSystemBorder | |
191 #else | |
192 SetThemeData(); | |
193 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Icon) { | |
194 UpdateIcon(); | |
195 } | |
196 #endif | |
197 UpdateCaption(); | |
198 Layout(); | |
199 return FWL_Error::Succeeded; | |
200 } | |
201 FWL_WidgetHit CFWL_FormImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
202 GetAvailableTheme(); | |
203 if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) | |
204 return FWL_WidgetHit::CloseBox; | |
205 if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) | |
206 return FWL_WidgetHit::MaxBox; | |
207 if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) | |
208 return FWL_WidgetHit::MinBox; | |
209 CFX_RectF rtCap; | |
210 rtCap.Set(m_rtCaption.left + m_fCYBorder, m_rtCaption.top + m_fCXBorder, | |
211 m_rtCaption.width - kSystemButtonSize * m_iSysBox - 2 * m_fCYBorder, | |
212 m_rtCaption.height - m_fCXBorder); | |
213 if (rtCap.Contains(fx, fy)) | |
214 return FWL_WidgetHit::Titlebar; | |
215 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && | |
216 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize)) { | |
217 FX_FLOAT fWidth = m_rtRelative.width - 2 * (m_fCYBorder + kCornerEnlarge); | |
218 FX_FLOAT fHeight = m_rtRelative.height - 2 * (m_fCXBorder + kCornerEnlarge); | |
219 CFX_RectF rt; | |
220 rt.Set(0, m_fCXBorder + kCornerEnlarge, m_fCYBorder, fHeight); | |
221 if (rt.Contains(fx, fy)) | |
222 return FWL_WidgetHit::Left; | |
223 rt.Set(m_rtRelative.width - m_fCYBorder, m_fCXBorder + kCornerEnlarge, | |
224 m_fCYBorder, fHeight); | |
225 if (rt.Contains(fx, fy)) | |
226 return FWL_WidgetHit::Right; | |
227 rt.Set(m_fCYBorder + kCornerEnlarge, 0, fWidth, m_fCXBorder); | |
228 if (rt.Contains(fx, fy)) | |
229 return FWL_WidgetHit::Top; | |
230 rt.Set(m_fCYBorder + kCornerEnlarge, m_rtRelative.height - m_fCXBorder, | |
231 fWidth, m_fCXBorder); | |
232 if (rt.Contains(fx, fy)) | |
233 return FWL_WidgetHit::Bottom; | |
234 rt.Set(0, 0, m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); | |
235 if (rt.Contains(fx, fy)) | |
236 return FWL_WidgetHit::LeftTop; | |
237 rt.Set(0, m_rtRelative.height - m_fCXBorder - kCornerEnlarge, | |
238 m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); | |
239 if (rt.Contains(fx, fy)) | |
240 return FWL_WidgetHit::LeftBottom; | |
241 rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, 0, | |
242 m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); | |
243 if (rt.Contains(fx, fy)) | |
244 return FWL_WidgetHit::RightTop; | |
245 rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, | |
246 m_rtRelative.height - m_fCXBorder - kCornerEnlarge, | |
247 m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); | |
248 if (rt.Contains(fx, fy)) | |
249 return FWL_WidgetHit::RightBottom; | |
250 } | |
251 return FWL_WidgetHit::Client; | |
252 } | |
253 FWL_Error CFWL_FormImp::DrawWidget(CFX_Graphics* pGraphics, | |
254 const CFX_Matrix* pMatrix) { | |
255 if (!pGraphics) | |
256 return FWL_Error::Indefinite; | |
257 if (!m_pProperties->m_pThemeProvider) | |
258 return FWL_Error::Indefinite; | |
259 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
260 FX_BOOL bInactive = !IsActive(); | |
261 int32_t iState = bInactive ? CFWL_PartState_Inactive : CFWL_PartState_Normal; | |
262 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_NoDrawClient) == 0) { | |
263 DrawBackground(pGraphics, pTheme); | |
264 } | |
265 #ifdef FWL_UseMacSystemBorder | |
266 return FWL_Error::Succeeded; | |
267 #endif | |
268 CFWL_ThemeBackground param; | |
269 param.m_pWidget = m_pInterface; | |
270 param.m_dwStates = iState; | |
271 param.m_pGraphics = pGraphics; | |
272 param.m_rtPart = m_rtRelative; | |
273 if (pMatrix) { | |
274 param.m_matrix.Concat(*pMatrix); | |
275 } | |
276 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { | |
277 param.m_iPart = CFWL_Part::Border; | |
278 pTheme->DrawBackground(¶m); | |
279 } | |
280 if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != | |
281 FWL_WGTSTYLE_EdgeNone) { | |
282 CFX_RectF rtEdge; | |
283 GetEdgeRect(rtEdge); | |
284 param.m_iPart = CFWL_Part::Edge; | |
285 param.m_rtPart = rtEdge; | |
286 param.m_dwStates = iState; | |
287 pTheme->DrawBackground(¶m); | |
288 } | |
289 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Caption) { | |
290 param.m_iPart = CFWL_Part::Caption; | |
291 param.m_dwStates = iState; | |
292 param.m_rtPart = m_rtCaption; | |
293 pTheme->DrawBackground(¶m); | |
294 DrawCaptionText(pGraphics, pTheme, pMatrix); | |
295 } else if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_NarrowCaption) { | |
296 param.m_iPart = CFWL_Part::NarrowCaption; | |
297 param.m_dwStates = iState; | |
298 param.m_rtPart = m_rtCaption; | |
299 pTheme->DrawBackground(¶m); | |
300 DrawCaptionText(pGraphics, pTheme, pMatrix); | |
301 } | |
302 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Icon) { | |
303 param.m_iPart = CFWL_Part::Icon; | |
304 if (HasIcon()) { | |
305 DrawIconImage(pGraphics, pTheme, pMatrix); | |
306 } | |
307 } | |
308 #if (_FX_OS_ == _FX_MACOSX_) | |
309 { | |
310 if (m_pCloseBox) { | |
311 param.m_iPart = CFWL_Part::CloseBox; | |
312 param.m_dwStates = m_pCloseBox->GetPartState(); | |
313 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) { | |
314 param.m_dwStates = CFWL_PartState_Disabled; | |
315 } else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) { | |
316 param.m_dwStates = CFWL_PartState_Hovered; | |
317 } | |
318 param.m_rtPart = m_pCloseBox->m_rtBtn; | |
319 pTheme->DrawBackground(¶m); | |
320 } | |
321 if (m_pMaxBox) { | |
322 param.m_iPart = CFWL_Part::MaximizeBox; | |
323 param.m_dwStates = m_pMaxBox->GetPartState(); | |
324 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) { | |
325 param.m_dwStates = CFWL_PartState_Disabled; | |
326 } else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) { | |
327 param.m_dwStates = CFWL_PartState_Hovered; | |
328 } | |
329 param.m_rtPart = m_pMaxBox->m_rtBtn; | |
330 param.m_bMaximize = m_bMaximized; | |
331 pTheme->DrawBackground(¶m); | |
332 } | |
333 if (m_pMinBox) { | |
334 param.m_iPart = CFWL_Part::MinimizeBox; | |
335 param.m_dwStates = m_pMinBox->GetPartState(); | |
336 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) { | |
337 param.m_dwStates = CFWL_PartState_Disabled; | |
338 } else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) { | |
339 param.m_dwStates = CFWL_PartState_Hovered; | |
340 } | |
341 param.m_rtPart = m_pMinBox->m_rtBtn; | |
342 pTheme->DrawBackground(¶m); | |
343 } | |
344 m_bMouseIn = FALSE; | |
345 } | |
346 #else | |
347 { | |
348 if (m_pCloseBox) { | |
349 param.m_iPart = CFWL_Part::CloseBox; | |
350 param.m_dwStates = m_pCloseBox->GetPartState(); | |
351 param.m_rtPart = m_pCloseBox->m_rtBtn; | |
352 pTheme->DrawBackground(¶m); | |
353 } | |
354 if (m_pMaxBox) { | |
355 param.m_iPart = CFWL_Part::MaximizeBox; | |
356 param.m_dwStates = m_pMaxBox->GetPartState(); | |
357 param.m_rtPart = m_pMaxBox->m_rtBtn; | |
358 param.m_bMaximize = m_bMaximized; | |
359 pTheme->DrawBackground(¶m); | |
360 } | |
361 if (m_pMinBox) { | |
362 param.m_iPart = CFWL_Part::MinimizeBox; | |
363 param.m_dwStates = m_pMinBox->GetPartState(); | |
364 param.m_rtPart = m_pMinBox->m_rtBtn; | |
365 pTheme->DrawBackground(¶m); | |
366 } | |
367 } | |
368 #endif | |
369 return FWL_Error::Succeeded; | |
370 } | |
371 | |
372 FWL_FORMSIZE CFWL_FormImp::GetFormSize() { | |
373 return m_eFormSize; | |
374 } | |
375 | |
376 FWL_Error CFWL_FormImp::SetFormSize(FWL_FORMSIZE eFormSize) { | |
377 m_eFormSize = eFormSize; | |
378 return FWL_Error::Succeeded; | |
379 } | |
380 | |
381 IFWL_Widget* CFWL_FormImp::DoModal() { | |
382 IFWL_App* pApp = GetOwnerApp(); | |
383 if (!pApp) | |
384 return nullptr; | |
385 | |
386 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | |
387 if (!pDriver) | |
388 return nullptr; | |
389 | |
390 m_pNoteLoop.reset(new CFWL_NoteLoop(this)); | |
391 pDriver->PushNoteLoop(m_pNoteLoop.get()); | |
392 m_bDoModalFlag = TRUE; | |
393 SetStates(FWL_WGTSTATE_Invisible, FALSE); | |
394 pDriver->Run(); | |
395 #if (_FX_OS_ == _FX_MACOSX_) | |
396 #else | |
397 pDriver->PopNoteLoop(); | |
398 #endif | |
399 m_pNoteLoop.reset(); | |
400 return nullptr; | |
401 } | |
402 | |
403 IFWL_Widget* CFWL_FormImp::DoModal(uint32_t& dwCommandID) { | |
404 return DoModal(); | |
405 } | |
406 | |
407 FWL_Error CFWL_FormImp::EndDoModal() { | |
408 if (!m_pNoteLoop) | |
409 return FWL_Error::Indefinite; | |
410 m_bDoModalFlag = FALSE; | |
411 #if (_FX_OS_ == _FX_MACOSX_) | |
412 m_pNoteLoop->EndModalLoop(); | |
413 IFWL_App* pApp = GetOwnerApp(); | |
414 if (!pApp) | |
415 return FWL_Error::Indefinite; | |
416 | |
417 CFWL_NoteDriver* pDriver = | |
418 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
419 if (!pDriver) | |
420 return FWL_Error::Indefinite; | |
421 | |
422 pDriver->PopNoteLoop(); | |
423 SetStates(FWL_WGTSTATE_Invisible, TRUE); | |
424 return FWL_Error::Succeeded; | |
425 #else | |
426 SetStates(FWL_WGTSTATE_Invisible, TRUE); | |
427 return m_pNoteLoop->EndModalLoop(); | |
428 #endif | |
429 } | |
430 | |
431 FWL_Error CFWL_FormImp::SetBorderRegion(CFX_Path* pPath) { | |
432 return FWL_Error::Succeeded; | |
433 } | |
434 void CFWL_FormImp::DrawBackground(CFX_Graphics* pGraphics, | |
435 IFWL_ThemeProvider* pTheme) { | |
436 CFWL_ThemeBackground param; | |
437 param.m_pWidget = m_pInterface; | |
438 param.m_iPart = CFWL_Part::Background; | |
439 param.m_pGraphics = pGraphics; | |
440 param.m_rtPart = m_rtRelative; | |
441 param.m_rtPart.Deflate(m_fCYBorder, m_rtCaption.height, m_fCYBorder, | |
442 m_fCXBorder); | |
443 pTheme->DrawBackground(¶m); | |
444 } | |
445 CFWL_WidgetImp* CFWL_FormImp::GetSubFocus() { | |
446 return m_pSubFocus; | |
447 } | |
448 void CFWL_FormImp::SetSubFocus(CFWL_WidgetImp* pWidget) { | |
449 m_pSubFocus = pWidget; | |
450 } | |
451 | |
452 void CFWL_FormImp::ShowChildWidget(IFWL_Widget* pParent) { | |
453 IFWL_App* pApp = FWL_GetApp(); | |
454 if (!pApp) | |
455 return; | |
456 | |
457 CFWL_WidgetMgr* pWidgetMgr = pApp->GetWidgetMgr(); | |
458 if (!pWidgetMgr) | |
459 return; | |
460 | |
461 IFWL_Widget* pChild = pWidgetMgr->GetFirstChildWidget(pParent); | |
462 while (pChild) { | |
463 ShowChildWidget(pChild); | |
464 pChild = pWidgetMgr->GetNextSiblingWidget(pChild); | |
465 } | |
466 } | |
467 | |
468 void CFWL_FormImp::RemoveSysButtons() { | |
469 m_rtCaption.Reset(); | |
470 delete m_pCloseBox; | |
471 m_pCloseBox = nullptr; | |
472 delete m_pMinBox; | |
473 m_pMinBox = nullptr; | |
474 delete m_pMaxBox; | |
475 m_pMaxBox = nullptr; | |
476 delete m_pCaptionBox; | |
477 m_pCaptionBox = nullptr; | |
478 } | |
479 | |
480 void CFWL_FormImp::CalcContentRect(CFX_RectF& rtContent) { | |
481 #ifdef FWL_UseMacSystemBorder | |
482 rtContent = m_rtRelative; | |
483 #else | |
484 GetEdgeRect(rtContent); | |
485 if (HasEdge()) { | |
486 FX_FLOAT fEdge = GetEdgeWidth(); | |
487 rtContent.Deflate(fEdge, fEdge); | |
488 } | |
489 #endif | |
490 } | |
491 CFWL_SysBtn* CFWL_FormImp::GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy) { | |
492 if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) { | |
493 return m_pCloseBox; | |
494 } | |
495 if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) { | |
496 return m_pMaxBox; | |
497 } | |
498 if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) { | |
499 return m_pMinBox; | |
500 } | |
501 if (m_pCaptionBox && m_pCaptionBox->m_rtBtn.Contains(fx, fy)) { | |
502 return m_pCaptionBox; | |
503 } | |
504 return nullptr; | |
505 } | |
506 CFWL_SysBtn* CFWL_FormImp::GetSysBtnByState(uint32_t dwState) { | |
507 if (m_pCloseBox && (m_pCloseBox->m_dwState & dwState)) { | |
508 return m_pCloseBox; | |
509 } | |
510 if (m_pMaxBox && (m_pMaxBox->m_dwState & dwState)) { | |
511 return m_pMaxBox; | |
512 } | |
513 if (m_pMinBox && (m_pMinBox->m_dwState & dwState)) { | |
514 return m_pMinBox; | |
515 } | |
516 if (m_pCaptionBox && (m_pCaptionBox->m_dwState & dwState)) { | |
517 return m_pCaptionBox; | |
518 } | |
519 return nullptr; | |
520 } | |
521 CFWL_SysBtn* CFWL_FormImp::GetSysBtnByIndex(int32_t nIndex) { | |
522 if (nIndex < 0) | |
523 return nullptr; | |
524 | |
525 CFX_ArrayTemplate<CFWL_SysBtn*> arrBtn; | |
526 if (m_pMinBox) | |
527 arrBtn.Add(m_pMinBox); | |
528 | |
529 if (m_pMaxBox) | |
530 arrBtn.Add(m_pMaxBox); | |
531 | |
532 if (m_pCloseBox) | |
533 arrBtn.Add(m_pCloseBox); | |
534 | |
535 return arrBtn[nIndex]; | |
536 } | |
537 int32_t CFWL_FormImp::GetSysBtnIndex(CFWL_SysBtn* pBtn) { | |
538 CFX_ArrayTemplate<CFWL_SysBtn*> arrBtn; | |
539 if (m_pMinBox) | |
540 arrBtn.Add(m_pMinBox); | |
541 | |
542 if (m_pMaxBox) | |
543 arrBtn.Add(m_pMaxBox); | |
544 | |
545 if (m_pCloseBox) | |
546 arrBtn.Add(m_pCloseBox); | |
547 | |
548 return arrBtn.Find(pBtn); | |
549 } | |
550 FX_FLOAT CFWL_FormImp::GetCaptionHeight() { | |
551 CFWL_WidgetCapacity dwCapacity = CFWL_WidgetCapacity::None; | |
552 | |
553 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Caption) { | |
554 dwCapacity = CFWL_WidgetCapacity::CYCaption; | |
555 } else if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_NarrowCaption) { | |
556 dwCapacity = CFWL_WidgetCapacity::CYNarrowCaption; | |
557 } | |
558 if (dwCapacity != CFWL_WidgetCapacity::None) { | |
559 FX_FLOAT* pfCapHeight = | |
560 static_cast<FX_FLOAT*>(GetThemeCapacity(dwCapacity)); | |
561 return pfCapHeight ? *pfCapHeight : 0; | |
562 } | |
563 return 0; | |
564 } | |
565 void CFWL_FormImp::DrawCaptionText(CFX_Graphics* pGs, | |
566 IFWL_ThemeProvider* pTheme, | |
567 const CFX_Matrix* pMatrix) { | |
568 CFX_WideString wsText; | |
569 IFWL_DataProvider* pData = m_pProperties->m_pDataProvider; | |
570 pData->GetCaption(m_pInterface, wsText); | |
571 if (wsText.IsEmpty()) { | |
572 return; | |
573 } | |
574 CFWL_ThemeText textParam; | |
575 textParam.m_pWidget = m_pInterface; | |
576 textParam.m_iPart = CFWL_Part::Caption; | |
577 textParam.m_dwStates = CFWL_PartState_Normal; | |
578 textParam.m_pGraphics = pGs; | |
579 if (pMatrix) { | |
580 textParam.m_matrix.Concat(*pMatrix); | |
581 } | |
582 CFX_RectF rtText; | |
583 if (m_bCustomizeLayout) { | |
584 rtText = m_rtCaptionText; | |
585 rtText.top -= 5; | |
586 } else { | |
587 rtText = m_rtCaption; | |
588 FX_FLOAT fpos; | |
589 fpos = HasIcon() ? 29.0f : 13.0f; | |
590 rtText.left += fpos; | |
591 } | |
592 textParam.m_rtPart = rtText; | |
593 textParam.m_wsText = wsText; | |
594 textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine | FDE_TTOSTYLE_Ellipsis; | |
595 textParam.m_iTTOAlign = m_bCustomizeLayout ? FDE_TTOALIGNMENT_Center | |
596 : FDE_TTOALIGNMENT_CenterLeft; | |
597 pTheme->DrawText(&textParam); | |
598 } | |
599 void CFWL_FormImp::DrawIconImage(CFX_Graphics* pGs, | |
600 IFWL_ThemeProvider* pTheme, | |
601 const CFX_Matrix* pMatrix) { | |
602 IFWL_FormDP* pData = | |
603 static_cast<IFWL_FormDP*>(m_pProperties->m_pDataProvider); | |
604 CFWL_ThemeBackground param; | |
605 param.m_pWidget = m_pInterface; | |
606 param.m_iPart = CFWL_Part::Icon; | |
607 param.m_pGraphics = pGs; | |
608 param.m_pImage = pData->GetIcon(m_pInterface, FALSE); | |
609 param.m_rtPart = m_rtIcon; | |
610 if (pMatrix) { | |
611 param.m_matrix.Concat(*pMatrix); | |
612 } | |
613 pTheme->DrawBackground(¶m); | |
614 } | |
615 void CFWL_FormImp::GetEdgeRect(CFX_RectF& rtEdge) { | |
616 rtEdge = m_rtRelative; | |
617 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { | |
618 FX_FLOAT fCX = GetBorderSize(); | |
619 FX_FLOAT fCY = GetBorderSize(FALSE); | |
620 rtEdge.Deflate(fCX, m_rtCaption.Height(), fCX, fCY); | |
621 } | |
622 } | |
623 void CFWL_FormImp::SetWorkAreaRect() { | |
624 m_rtRestore = m_pProperties->m_rtWidget; | |
625 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | |
626 if (!pWidgetMgr) | |
627 return; | |
628 m_bSetMaximize = TRUE; | |
629 Repaint(&m_rtRelative); | |
630 } | |
631 void CFWL_FormImp::SetCursor(FX_FLOAT fx, FX_FLOAT fy) {} | |
632 void CFWL_FormImp::Layout() { | |
633 GetRelativeRect(m_rtRelative); | |
634 #ifndef FWL_UseMacSystemBorder | |
635 ReSetSysBtn(); | |
636 #endif | |
637 } | |
638 void CFWL_FormImp::ReSetSysBtn() { | |
639 m_fCXBorder = | |
640 *static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::CXBorder)); | |
641 m_fCYBorder = | |
642 *static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::CYBorder)); | |
643 RemoveSysButtons(); | |
644 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
645 m_bCustomizeLayout = pTheme->IsCustomizedLayout(m_pInterface); | |
646 FX_FLOAT fCapHeight = GetCaptionHeight(); | |
647 if (fCapHeight > 0) { | |
648 m_rtCaption = m_rtRelative; | |
649 m_rtCaption.height = fCapHeight; | |
650 } | |
651 m_iSysBox = 0; | |
652 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_CloseBox) { | |
653 m_pCloseBox = new CFWL_SysBtn; | |
654 if (!m_bCustomizeLayout) { | |
655 m_pCloseBox->m_rtBtn.Set( | |
656 m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, | |
657 kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); | |
658 } | |
659 m_iSysBox++; | |
660 } | |
661 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MaximizeBox) { | |
662 m_pMaxBox = new CFWL_SysBtn; | |
663 if (!m_bCustomizeLayout) { | |
664 if (m_pCloseBox) { | |
665 m_pMaxBox->m_rtBtn.Set( | |
666 m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, | |
667 m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); | |
668 } else { | |
669 m_pMaxBox->m_rtBtn.Set( | |
670 m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, | |
671 kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); | |
672 } | |
673 } | |
674 m_iSysBox++; | |
675 } | |
676 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MinimizeBox) { | |
677 m_pMinBox = new CFWL_SysBtn; | |
678 if (!m_bCustomizeLayout) { | |
679 if (m_pMaxBox) { | |
680 m_pMinBox->m_rtBtn.Set( | |
681 m_pMaxBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, | |
682 m_pMaxBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); | |
683 } else if (m_pCloseBox) { | |
684 m_pMinBox->m_rtBtn.Set( | |
685 m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, | |
686 m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); | |
687 } else { | |
688 m_pMinBox->m_rtBtn.Set( | |
689 m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, | |
690 kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); | |
691 } | |
692 } | |
693 m_iSysBox++; | |
694 } | |
695 IFWL_FormDP* pData = | |
696 static_cast<IFWL_FormDP*>(m_pProperties->m_pDataProvider); | |
697 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Icon && | |
698 pData->GetIcon(m_pInterface, FALSE)) { | |
699 if (!m_bCustomizeLayout) { | |
700 m_rtIcon.Set(5, (m_rtCaption.height - m_fSmallIconSz) / 2, m_fSmallIconSz, | |
701 m_fSmallIconSz); | |
702 } | |
703 } | |
704 } | |
705 void CFWL_FormImp::RegisterForm() { | |
706 IFWL_App* pApp = GetOwnerApp(); | |
707 if (!pApp) | |
708 return; | |
709 | |
710 CFWL_NoteDriver* pDriver = | |
711 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
712 if (!pDriver) | |
713 return; | |
714 | |
715 pDriver->RegisterForm(this); | |
716 } | |
717 void CFWL_FormImp::UnRegisterForm() { | |
718 IFWL_App* pApp = GetOwnerApp(); | |
719 if (!pApp) | |
720 return; | |
721 | |
722 CFWL_NoteDriver* pDriver = | |
723 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
724 if (!pDriver) | |
725 return; | |
726 | |
727 pDriver->UnRegisterForm(this); | |
728 } | |
729 FX_BOOL CFWL_FormImp::IsDoModal() { | |
730 return m_bDoModalFlag; | |
731 } | |
732 void CFWL_FormImp::SetThemeData() { | |
733 m_fSmallIconSz = | |
734 *static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::SmallIcon)); | |
735 m_fBigIconSz = | |
736 *static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::BigIcon)); | |
737 } | |
738 FX_BOOL CFWL_FormImp::HasIcon() { | |
739 IFWL_FormDP* pData = | |
740 static_cast<IFWL_FormDP*>(m_pProperties->m_pDataProvider); | |
741 return !!pData->GetIcon(m_pInterface, FALSE); | |
742 } | |
743 void CFWL_FormImp::UpdateIcon() { | |
744 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | |
745 if (!pWidgetMgr) | |
746 return; | |
747 IFWL_FormDP* pData = | |
748 static_cast<IFWL_FormDP*>(m_pProperties->m_pDataProvider); | |
749 CFX_DIBitmap* pBigIcon = pData->GetIcon(m_pInterface, TRUE); | |
750 CFX_DIBitmap* pSmallIcon = pData->GetIcon(m_pInterface, FALSE); | |
751 if (pBigIcon) | |
752 m_pBigIcon = pBigIcon; | |
753 if (pSmallIcon) | |
754 m_pSmallIcon = pSmallIcon; | |
755 } | |
756 void CFWL_FormImp::UpdateCaption() { | |
757 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | |
758 if (!pWidgetMgr) | |
759 return; | |
760 IFWL_DataProvider* pData = m_pProperties->m_pDataProvider; | |
761 if (!pData) | |
762 return; | |
763 CFX_WideString text; | |
764 pData->GetCaption(m_pInterface, text); | |
765 } | |
766 void CFWL_FormImp::DoWidthLimit(FX_FLOAT& fLeft, | |
767 FX_FLOAT& fWidth, | |
768 FX_FLOAT fCurX, | |
769 FX_FLOAT fSpace, | |
770 FX_FLOAT fLimitMin, | |
771 FX_FLOAT fLimitMax, | |
772 FX_BOOL bLeft) { | |
773 FX_FLOAT fx = fCurX; | |
774 FX_FLOAT fy = 0; | |
775 TransformTo(nullptr, fx, fy); | |
776 FX_FLOAT fTemp = | |
777 bLeft ? (fWidth - fx + fLeft + fSpace) : (fx - fLeft + fSpace); | |
778 if (fTemp >= fLimitMin && fTemp <= fLimitMax) { | |
779 fWidth = fTemp; | |
780 fLeft += bLeft ? (fx - fLeft - fSpace) : 0; | |
781 } else { | |
782 if (fTemp < fLimitMin && fWidth > fLimitMin) { | |
783 fLeft += bLeft ? (fWidth - fLimitMin) : 0; | |
784 fWidth = fLimitMin; | |
785 } else if (fTemp > fLimitMax && fWidth < fLimitMax) { | |
786 fLeft -= bLeft ? (fLimitMax - fWidth) : 0; | |
787 fWidth = fLimitMax; | |
788 } | |
789 } | |
790 } | |
791 void CFWL_FormImp::DoHeightLimit(FX_FLOAT& fTop, | |
792 FX_FLOAT& fHeight, | |
793 FX_FLOAT fCurY, | |
794 FX_FLOAT fSpace, | |
795 FX_FLOAT fLimitMin, | |
796 FX_FLOAT fLimitMax, | |
797 FX_BOOL bTop) { | |
798 FX_FLOAT fx = 0; | |
799 FX_FLOAT fy = fCurY; | |
800 TransformTo(nullptr, fx, fy); | |
801 FX_FLOAT fTemp = bTop ? (fHeight - fy + fTop + fSpace) : (fy - fTop + fSpace); | |
802 if (fTemp >= fLimitMin && fTemp <= fLimitMax) { | |
803 fHeight = fTemp; | |
804 fTop += bTop ? (fy - fTop - fSpace) : 0; | |
805 } else { | |
806 if (fTemp < fLimitMin && fHeight > fLimitMin) { | |
807 fTop += bTop ? (fHeight - fLimitMin) : 0; | |
808 fHeight = fLimitMin; | |
809 } else if (fTemp > fLimitMax && fHeight < fLimitMax) { | |
810 fTop -= bTop ? (fLimitMax - fHeight) : 0; | |
811 fHeight = fLimitMax; | |
812 } | |
813 } | |
814 } | |
815 | |
816 CFWL_FormImpDelegate::CFWL_FormImpDelegate(CFWL_FormImp* pOwner) | |
817 : m_pOwner(pOwner) {} | |
818 | |
819 #ifdef FWL_UseMacSystemBorder | |
820 void CFWL_FormImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
821 if (!pMessage) | |
822 return; | |
823 | |
824 switch (pMessage->GetClassID()) { | |
825 case CFWL_MessageType::Activate: { | |
826 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; | |
827 m_pOwner->Repaint(&m_pOwner->m_rtRelative); | |
828 break; | |
829 } | |
830 case CFWL_MessageType::Deactivate: { | |
831 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Deactivated; | |
832 m_pOwner->Repaint(&m_pOwner->m_rtRelative); | |
833 break; | |
834 } | |
835 default: | |
836 break; | |
837 } | |
838 } | |
839 #else | |
840 void CFWL_FormImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
841 if (!pMessage) | |
842 return; | |
843 | |
844 switch (pMessage->GetClassID()) { | |
845 case CFWL_MessageType::Activate: { | |
846 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; | |
847 IFWL_App* pApp = m_pOwner->GetOwnerApp(); | |
848 CFWL_NoteDriver* pDriver = | |
849 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
850 CFWL_WidgetImp* pSubFocusImp = m_pOwner->GetSubFocus(); | |
851 IFWL_Widget* pSubFocus = | |
852 pSubFocusImp ? pSubFocusImp->GetInterface() : nullptr; | |
853 if (pSubFocus && pSubFocus != pDriver->GetFocus()) | |
854 pDriver->SetFocus(pSubFocus); | |
855 | |
856 m_pOwner->Repaint(&m_pOwner->m_rtRelative); | |
857 break; | |
858 } | |
859 case CFWL_MessageType::Deactivate: { | |
860 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Deactivated; | |
861 IFWL_App* pApp = m_pOwner->GetOwnerApp(); | |
862 CFWL_NoteDriver* pDriver = | |
863 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
864 CFWL_WidgetImp* pSubFocusImp = m_pOwner->GetSubFocus(); | |
865 IFWL_Widget* pSubFocus = | |
866 pSubFocusImp ? pSubFocusImp->GetInterface() : nullptr; | |
867 if (pSubFocus) { | |
868 if (pSubFocus == pDriver->GetFocus()) { | |
869 pDriver->SetFocus(nullptr); | |
870 } else if (pSubFocus->GetStates() & FWL_WGTSTATE_Focused) { | |
871 CFWL_MsgKillFocus ms; | |
872 IFWL_WidgetDelegate* pDelegate = pSubFocus->SetDelegate(nullptr); | |
873 if (pDelegate) | |
874 pDelegate->OnProcessMessage(&ms); | |
875 } | |
876 } | |
877 m_pOwner->Repaint(&m_pOwner->m_rtRelative); | |
878 break; | |
879 } | |
880 case CFWL_MessageType::Mouse: { | |
881 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
882 switch (pMsg->m_dwCmd) { | |
883 case FWL_MouseCommand::LeftButtonDown: { | |
884 OnLButtonDown(pMsg); | |
885 break; | |
886 } | |
887 case FWL_MouseCommand::LeftButtonUp: { | |
888 OnLButtonUp(pMsg); | |
889 break; | |
890 } | |
891 case FWL_MouseCommand::Move: { | |
892 OnMouseMove(pMsg); | |
893 break; | |
894 } | |
895 case FWL_MouseCommand::Hover: { | |
896 OnMouseHover(pMsg); | |
897 break; | |
898 } | |
899 case FWL_MouseCommand::Leave: { | |
900 OnMouseLeave(pMsg); | |
901 break; | |
902 } | |
903 case FWL_MouseCommand::LeftButtonDblClk: { | |
904 OnLButtonDblClk(pMsg); | |
905 break; | |
906 } | |
907 default: | |
908 break; | |
909 } | |
910 break; | |
911 } | |
912 case CFWL_MessageType::Size: { | |
913 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | |
914 if (!pWidgetMgr) | |
915 return; | |
916 | |
917 pWidgetMgr->AddRedrawCounts(m_pOwner->m_pInterface); | |
918 if (!m_pOwner->m_bSetMaximize) | |
919 break; | |
920 | |
921 m_pOwner->m_bSetMaximize = FALSE; | |
922 CFWL_MsgSize* pMsg = static_cast<CFWL_MsgSize*>(pMessage); | |
923 m_pOwner->m_pProperties->m_rtWidget.left = 0; | |
924 m_pOwner->m_pProperties->m_rtWidget.top = 0; | |
925 m_pOwner->m_pProperties->m_rtWidget.width = (FX_FLOAT)pMsg->m_iWidth; | |
926 m_pOwner->m_pProperties->m_rtWidget.height = (FX_FLOAT)pMsg->m_iHeight; | |
927 m_pOwner->Update(); | |
928 break; | |
929 } | |
930 case CFWL_MessageType::WindowMove: { | |
931 OnWindowMove(static_cast<CFWL_MsgWindowMove*>(pMessage)); | |
932 break; | |
933 } | |
934 case CFWL_MessageType::Close: { | |
935 OnClose(static_cast<CFWL_MsgClose*>(pMessage)); | |
936 break; | |
937 } | |
938 default: { | |
939 break; | |
940 } | |
941 } | |
942 } | |
943 #endif // FWL_UseMacSystemBorder | |
944 | |
945 void CFWL_FormImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} | |
946 | |
947 void CFWL_FormImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
948 const CFX_Matrix* pMatrix) { | |
949 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
950 } | |
951 | |
952 void CFWL_FormImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
953 m_pOwner->SetGrab(TRUE); | |
954 m_pOwner->m_bLButtonDown = TRUE; | |
955 m_pOwner->m_eResizeType = FORM_RESIZETYPE_None; | |
956 CFWL_SysBtn* pPressBtn = m_pOwner->GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); | |
957 m_pOwner->m_iCaptureBtn = m_pOwner->GetSysBtnIndex(pPressBtn); | |
958 CFX_RectF rtCap; | |
959 rtCap.Set(m_pOwner->m_rtCaption.left + m_pOwner->m_fCYBorder, | |
960 m_pOwner->m_rtCaption.top + m_pOwner->m_fCXBorder, | |
961 m_pOwner->m_rtCaption.width - | |
962 kSystemButtonSize * m_pOwner->m_iSysBox - | |
963 2 * m_pOwner->m_fCYBorder, | |
964 m_pOwner->m_rtCaption.height - m_pOwner->m_fCXBorder); | |
965 if (pPressBtn) { | |
966 pPressBtn->SetPressed(); | |
967 m_pOwner->Repaint(&pPressBtn->m_rtBtn); | |
968 } else if (rtCap.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
969 m_pOwner->m_eResizeType = FORM_RESIZETYPE_Cap; | |
970 } else if ((m_pOwner->m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && | |
971 (m_pOwner->m_pProperties->m_dwStyleExes & | |
972 FWL_STYLEEXT_FRM_Resize) && | |
973 !m_pOwner->m_bMaximized) { | |
974 m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy); | |
975 } | |
976 m_pOwner->m_InfoStart.m_ptStart = CFX_PointF(pMsg->m_fx, pMsg->m_fy); | |
977 m_pOwner->m_InfoStart.m_szStart = | |
978 CFX_SizeF(m_pOwner->m_pProperties->m_rtWidget.width, | |
979 m_pOwner->m_pProperties->m_rtWidget.height); | |
980 } | |
981 void CFWL_FormImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
982 m_pOwner->SetGrab(FALSE); | |
983 m_pOwner->m_bLButtonDown = FALSE; | |
984 CFWL_SysBtn* pPointBtn = m_pOwner->GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); | |
985 CFWL_SysBtn* pPressedBtn = | |
986 m_pOwner->GetSysBtnByIndex(m_pOwner->m_iCaptureBtn); | |
987 if (!pPressedBtn || pPointBtn != pPressedBtn) { | |
988 return; | |
989 } | |
990 if (pPressedBtn == m_pOwner->GetSysBtnByState(FWL_SYSBUTTONSTATE_Pressed)) { | |
991 pPressedBtn->SetNormal(); | |
992 } | |
993 if (pPressedBtn == m_pOwner->m_pMaxBox) { | |
994 if (m_pOwner->m_bMaximized) { | |
995 m_pOwner->SetWidgetRect(m_pOwner->m_rtRestore); | |
996 m_pOwner->Update(); | |
997 m_pOwner->Repaint(); | |
998 } else { | |
999 m_pOwner->SetWorkAreaRect(); | |
1000 m_pOwner->Update(); | |
1001 } | |
1002 m_pOwner->m_bMaximized = !m_pOwner->m_bMaximized; | |
1003 } else if (pPressedBtn != m_pOwner->m_pMinBox) { | |
1004 CFWL_EvtClose eClose; | |
1005 eClose.m_pSrcTarget = m_pOwner->m_pInterface; | |
1006 m_pOwner->DispatchEvent(&eClose); | |
1007 } | |
1008 } | |
1009 void CFWL_FormImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
1010 if (m_pOwner->m_bLButtonDown) { | |
1011 return; | |
1012 } | |
1013 if ((m_pOwner->m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && | |
1014 (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && | |
1015 !m_pOwner->m_bMaximized) { | |
1016 m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy); | |
1017 } | |
1018 CFX_RectF rtInvalidate; | |
1019 rtInvalidate.Reset(); | |
1020 CFWL_SysBtn* pPointBtn = m_pOwner->GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); | |
1021 CFWL_SysBtn* pOldHover = m_pOwner->GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); | |
1022 #if (_FX_OS_ == _FX_MACOSX_) | |
1023 { | |
1024 if (pOldHover && pPointBtn != pOldHover) { | |
1025 pOldHover->SetNormal(); | |
1026 } | |
1027 if (pPointBtn && pPointBtn != pOldHover) { | |
1028 pPointBtn->SetHover(); | |
1029 } | |
1030 if (m_pOwner->m_pCloseBox) { | |
1031 rtInvalidate = m_pOwner->m_pCloseBox->m_rtBtn; | |
1032 } | |
1033 if (m_pOwner->m_pMaxBox) { | |
1034 if (rtInvalidate.IsEmpty()) { | |
1035 rtInvalidate = m_pOwner->m_pMaxBox->m_rtBtn; | |
1036 } else { | |
1037 rtInvalidate.Union(m_pOwner->m_pMaxBox->m_rtBtn); | |
1038 } | |
1039 } | |
1040 if (m_pOwner->m_pMinBox) { | |
1041 if (rtInvalidate.IsEmpty()) { | |
1042 rtInvalidate = m_pOwner->m_pMinBox->m_rtBtn; | |
1043 } else { | |
1044 rtInvalidate.Union(m_pOwner->m_pMinBox->m_rtBtn); | |
1045 } | |
1046 } | |
1047 if (!rtInvalidate.IsEmpty() && | |
1048 rtInvalidate.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
1049 m_pOwner->m_bMouseIn = TRUE; | |
1050 } | |
1051 } | |
1052 #else | |
1053 { | |
1054 if (pOldHover && pPointBtn != pOldHover) { | |
1055 pOldHover->SetNormal(); | |
1056 rtInvalidate = pOldHover->m_rtBtn; | |
1057 } | |
1058 if (pPointBtn && pPointBtn != pOldHover) { | |
1059 pPointBtn->SetHover(); | |
1060 if (rtInvalidate.IsEmpty()) { | |
1061 rtInvalidate = pPointBtn->m_rtBtn; | |
1062 } else { | |
1063 rtInvalidate.Union(pPointBtn->m_rtBtn); | |
1064 } | |
1065 } | |
1066 } | |
1067 #endif | |
1068 if (!rtInvalidate.IsEmpty()) { | |
1069 m_pOwner->Repaint(&rtInvalidate); | |
1070 } | |
1071 } | |
1072 void CFWL_FormImpDelegate::OnMouseHover(CFWL_MsgMouse* pMsg) { | |
1073 m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy); | |
1074 } | |
1075 void CFWL_FormImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | |
1076 CFWL_SysBtn* pHover = m_pOwner->GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); | |
1077 if (pHover) { | |
1078 pHover->SetNormal(); | |
1079 m_pOwner->Repaint(&pHover->m_rtBtn); | |
1080 } | |
1081 if (pMsg->m_dwCmd == FWL_MouseCommand::Leave && !m_pOwner->m_bLButtonDown) { | |
1082 m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy); | |
1083 } | |
1084 } | |
1085 void CFWL_FormImpDelegate::OnLButtonDblClk(CFWL_MsgMouse* pMsg) { | |
1086 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && | |
1087 m_pOwner->HitTest(pMsg->m_fx, pMsg->m_fy) == FWL_WidgetHit::Titlebar) { | |
1088 if (m_pOwner->m_bMaximized) { | |
1089 m_pOwner->SetWidgetRect(m_pOwner->m_rtRestore); | |
1090 } else { | |
1091 m_pOwner->SetWorkAreaRect(); | |
1092 } | |
1093 m_pOwner->Update(); | |
1094 m_pOwner->m_bMaximized = !m_pOwner->m_bMaximized; | |
1095 } | |
1096 } | |
1097 void CFWL_FormImpDelegate::OnWindowMove(CFWL_MsgWindowMove* pMsg) { | |
1098 m_pOwner->m_pProperties->m_rtWidget.left = pMsg->m_fx; | |
1099 m_pOwner->m_pProperties->m_rtWidget.top = pMsg->m_fy; | |
1100 } | |
1101 void CFWL_FormImpDelegate::OnClose(CFWL_MsgClose* pMsg) { | |
1102 CFWL_EvtClose eClose; | |
1103 eClose.m_pSrcTarget = m_pOwner->m_pInterface; | |
1104 m_pOwner->DispatchEvent(&eClose); | |
1105 } | |
1106 | |
1107 CFWL_SysBtn::CFWL_SysBtn() { | |
1108 m_rtBtn.Set(0, 0, 0, 0); | |
1109 m_dwState = 0; | |
1110 } | |
1111 | |
1112 bool CFWL_SysBtn::IsDisabled() const { | |
1113 return !!(m_dwState & FWL_SYSBUTTONSTATE_Disabled); | |
1114 } | |
1115 | |
1116 void CFWL_SysBtn::SetNormal() { | |
1117 m_dwState &= 0xFFF0; | |
1118 } | |
1119 | |
1120 void CFWL_SysBtn::SetPressed() { | |
1121 SetNormal(); | |
1122 m_dwState |= FWL_SYSBUTTONSTATE_Pressed; | |
1123 } | |
1124 | |
1125 void CFWL_SysBtn::SetHover() { | |
1126 SetNormal(); | |
1127 m_dwState |= FWL_SYSBUTTONSTATE_Hover; | |
1128 } | |
1129 | |
1130 void CFWL_SysBtn::SetDisabled(FX_BOOL bDisabled) { | |
1131 bDisabled ? m_dwState |= FWL_SYSBUTTONSTATE_Disabled | |
1132 : m_dwState &= ~FWL_SYSBUTTONSTATE_Disabled; | |
1133 } | |
1134 | |
1135 uint32_t CFWL_SysBtn::GetPartState() const { | |
1136 if (IsDisabled()) | |
1137 return CFWL_PartState_Disabled; | |
1138 if (m_dwState & FWL_SYSBUTTONSTATE_Pressed) | |
1139 return CFWL_PartState_Pressed; | |
1140 if (m_dwState & FWL_SYSBUTTONSTATE_Hover) | |
1141 return CFWL_PartState_Hovered; | |
1142 return CFWL_PartState_Normal; | |
1143 } | |
OLD | NEW |