Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: xfa/src/fwl/core/fwl_formimp.cpp

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

Powered by Google App Engine
This is Rietveld 408576698