From 447b1f3ffc7e0df233d15300bbf8a85ce2bc7278 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 8 Dec 2016 10:06:32 -0800 Subject: Move xfa/fwl/core to xfa/fwl. The core/ directory in FWL no-longer provides any context. This Cl moves all of the core/ files up to the fwl/ folder. As well, the CFWL_EvtFoo files are renamed CFWL_EventFoo and the CFWL_MsgFoo files are renamed CFWL_MessageFoo. The event and message preceed the type in order to keep the files sorted together and to make it clear that they're all related. Review-Url: https://codereview.chromium.org/2559173002 --- BUILD.gn | 194 ++-- fpdfsdk/DEPS | 2 +- fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 4 +- fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h | 4 +- xfa/fde/cfde_txtedtdorecord_deleterange.cpp | 2 +- xfa/fde/cfde_txtedtdorecord_insert.cpp | 2 +- xfa/fde/cfde_txtedtengine.cpp | 2 +- xfa/fwl/cfwl_app.cpp | 22 + xfa/fwl/cfwl_app.h | 45 + xfa/fwl/cfwl_barcode.cpp | 232 ++++ xfa/fwl/cfwl_barcode.h | 93 ++ xfa/fwl/cfwl_caret.cpp | 112 ++ xfa/fwl/cfwl_caret.h | 57 + xfa/fwl/cfwl_checkbox.cpp | 458 ++++++++ xfa/fwl/cfwl_checkbox.h | 90 ++ xfa/fwl/cfwl_combobox.cpp | 1078 ++++++++++++++++++ xfa/fwl/cfwl_combobox.h | 172 +++ xfa/fwl/cfwl_comboboxproxy.cpp | 117 ++ xfa/fwl/cfwl_comboboxproxy.h | 41 + xfa/fwl/cfwl_comboedit.cpp | 75 ++ xfa/fwl/cfwl_comboedit.h | 35 + xfa/fwl/cfwl_combolist.cpp | 245 ++++ xfa/fwl/cfwl_combolist.h | 43 + xfa/fwl/cfwl_datetimeedit.cpp | 60 + xfa/fwl/cfwl_datetimeedit.h | 30 + xfa/fwl/cfwl_datetimepicker.cpp | 625 ++++++++++ xfa/fwl/cfwl_datetimepicker.h | 112 ++ xfa/fwl/cfwl_edit.cpp | 1644 +++++++++++++++++++++++++++ xfa/fwl/cfwl_edit.h | 191 ++++ xfa/fwl/cfwl_event.cpp | 20 + xfa/fwl/cfwl_event.h | 52 + xfa/fwl/cfwl_eventcheckword.cpp | 12 + xfa/fwl/cfwl_eventcheckword.h | 21 + xfa/fwl/cfwl_eventmouse.cpp | 16 + xfa/fwl/cfwl_eventmouse.h | 21 + xfa/fwl/cfwl_eventscroll.cpp | 12 + xfa/fwl/cfwl_eventscroll.h | 34 + xfa/fwl/cfwl_eventselectchanged.cpp | 12 + xfa/fwl/cfwl_eventselectchanged.h | 26 + xfa/fwl/cfwl_eventtarget.cpp | 31 + xfa/fwl/cfwl_eventtarget.h | 35 + xfa/fwl/cfwl_eventtextchanged.cpp | 12 + xfa/fwl/cfwl_eventtextchanged.h | 20 + xfa/fwl/cfwl_eventvalidate.cpp | 12 + xfa/fwl/cfwl_eventvalidate.h | 21 + xfa/fwl/cfwl_form.cpp | 624 ++++++++++ xfa/fwl/cfwl_form.h | 99 ++ xfa/fwl/cfwl_formproxy.cpp | 40 + xfa/fwl/cfwl_formproxy.h | 31 + xfa/fwl/cfwl_listbox.cpp | 1130 ++++++++++++++++++ xfa/fwl/cfwl_listbox.h | 169 +++ xfa/fwl/cfwl_listitem.cpp | 19 + xfa/fwl/cfwl_listitem.h | 30 + xfa/fwl/cfwl_message.cpp | 24 + xfa/fwl/cfwl_message.h | 38 + xfa/fwl/cfwl_messagekey.cpp | 21 + xfa/fwl/cfwl_messagekey.h | 29 + xfa/fwl/cfwl_messagekillfocus.cpp | 24 + xfa/fwl/cfwl_messagekillfocus.h | 26 + xfa/fwl/cfwl_messagemouse.cpp | 21 + xfa/fwl/cfwl_messagemouse.h | 41 + xfa/fwl/cfwl_messagemousewheel.cpp | 21 + xfa/fwl/cfwl_messagemousewheel.h | 29 + xfa/fwl/cfwl_messagesetfocus.cpp | 21 + xfa/fwl/cfwl_messagesetfocus.h | 23 + xfa/fwl/cfwl_monthcalendar.cpp | 1089 ++++++++++++++++++ xfa/fwl/cfwl_monthcalendar.h | 227 ++++ xfa/fwl/cfwl_notedriver.cpp | 480 ++++++++ xfa/fwl/cfwl_notedriver.h | 78 ++ xfa/fwl/cfwl_noteloop.cpp | 9 + xfa/fwl/cfwl_noteloop.h | 27 + xfa/fwl/cfwl_picturebox.cpp | 52 + xfa/fwl/cfwl_picturebox.h | 51 + xfa/fwl/cfwl_pushbutton.cpp | 291 +++++ xfa/fwl/cfwl_pushbutton.h | 69 ++ xfa/fwl/cfwl_scrollbar.cpp | 504 ++++++++ xfa/fwl/cfwl_scrollbar.h | 148 +++ xfa/fwl/cfwl_spinbutton.cpp | 363 ++++++ xfa/fwl/cfwl_spinbutton.h | 73 ++ xfa/fwl/cfwl_sysbtn.cpp | 49 + xfa/fwl/cfwl_sysbtn.h | 33 + xfa/fwl/cfwl_themebackground.h | 27 + xfa/fwl/cfwl_themepart.cpp | 18 + xfa/fwl/cfwl_themepart.h | 96 ++ xfa/fwl/cfwl_themetext.h | 24 + xfa/fwl/cfwl_timer.cpp | 31 + xfa/fwl/cfwl_timer.h | 27 + xfa/fwl/cfwl_timerinfo.cpp | 13 + xfa/fwl/cfwl_timerinfo.h | 27 + xfa/fwl/cfwl_widget.cpp | 729 ++++++++++++ xfa/fwl/cfwl_widget.h | 196 ++++ xfa/fwl/cfwl_widgetmgr.cpp | 732 ++++++++++++ xfa/fwl/cfwl_widgetmgr.h | 133 +++ xfa/fwl/cfwl_widgetproperties.cpp | 19 + xfa/fwl/cfwl_widgetproperties.h | 32 + xfa/fwl/cfx_barcode.cpp | 316 +++++ xfa/fwl/cfx_barcode.h | 65 ++ xfa/fwl/core/cfwl_app.cpp | 22 - xfa/fwl/core/cfwl_app.h | 45 - xfa/fwl/core/cfwl_barcode.cpp | 232 ---- xfa/fwl/core/cfwl_barcode.h | 93 -- xfa/fwl/core/cfwl_caret.cpp | 112 -- xfa/fwl/core/cfwl_caret.h | 57 - xfa/fwl/core/cfwl_checkbox.cpp | 458 -------- xfa/fwl/core/cfwl_checkbox.h | 90 -- xfa/fwl/core/cfwl_combobox.cpp | 1078 ------------------ xfa/fwl/core/cfwl_combobox.h | 172 --- xfa/fwl/core/cfwl_comboboxproxy.cpp | 117 -- xfa/fwl/core/cfwl_comboboxproxy.h | 41 - xfa/fwl/core/cfwl_comboedit.cpp | 75 -- xfa/fwl/core/cfwl_comboedit.h | 35 - xfa/fwl/core/cfwl_combolist.cpp | 245 ---- xfa/fwl/core/cfwl_combolist.h | 43 - xfa/fwl/core/cfwl_datetimeedit.cpp | 60 - xfa/fwl/core/cfwl_datetimeedit.h | 30 - xfa/fwl/core/cfwl_datetimepicker.cpp | 625 ---------- xfa/fwl/core/cfwl_datetimepicker.h | 112 -- xfa/fwl/core/cfwl_edit.cpp | 1644 --------------------------- xfa/fwl/core/cfwl_edit.h | 191 ---- xfa/fwl/core/cfwl_event.cpp | 20 - xfa/fwl/core/cfwl_event.h | 52 - xfa/fwl/core/cfwl_eventtarget.cpp | 31 - xfa/fwl/core/cfwl_eventtarget.h | 35 - xfa/fwl/core/cfwl_evtcheckword.cpp | 13 - xfa/fwl/core/cfwl_evtcheckword.h | 21 - xfa/fwl/core/cfwl_evtmouse.cpp | 15 - xfa/fwl/core/cfwl_evtmouse.h | 21 - xfa/fwl/core/cfwl_evtscroll.cpp | 12 - xfa/fwl/core/cfwl_evtscroll.h | 34 - xfa/fwl/core/cfwl_evtselectchanged.cpp | 12 - xfa/fwl/core/cfwl_evtselectchanged.h | 26 - xfa/fwl/core/cfwl_evttextchanged.cpp | 12 - xfa/fwl/core/cfwl_evttextchanged.h | 20 - xfa/fwl/core/cfwl_evtvalidate.cpp | 12 - xfa/fwl/core/cfwl_evtvalidate.h | 21 - xfa/fwl/core/cfwl_form.cpp | 624 ---------- xfa/fwl/core/cfwl_form.h | 99 -- xfa/fwl/core/cfwl_formproxy.cpp | 40 - xfa/fwl/core/cfwl_formproxy.h | 31 - xfa/fwl/core/cfwl_listbox.cpp | 1131 ------------------ xfa/fwl/core/cfwl_listbox.h | 169 --- xfa/fwl/core/cfwl_listitem.cpp | 19 - xfa/fwl/core/cfwl_listitem.h | 30 - xfa/fwl/core/cfwl_message.cpp | 26 - xfa/fwl/core/cfwl_message.h | 39 - xfa/fwl/core/cfwl_monthcalendar.cpp | 1089 ------------------ xfa/fwl/core/cfwl_monthcalendar.h | 227 ---- xfa/fwl/core/cfwl_msgkey.cpp | 20 - xfa/fwl/core/cfwl_msgkey.h | 29 - xfa/fwl/core/cfwl_msgkillfocus.cpp | 24 - xfa/fwl/core/cfwl_msgkillfocus.h | 26 - xfa/fwl/core/cfwl_msgmouse.cpp | 20 - xfa/fwl/core/cfwl_msgmouse.h | 41 - xfa/fwl/core/cfwl_msgmousewheel.cpp | 21 - xfa/fwl/core/cfwl_msgmousewheel.h | 29 - xfa/fwl/core/cfwl_msgsetfocus.cpp | 21 - xfa/fwl/core/cfwl_msgsetfocus.h | 23 - xfa/fwl/core/cfwl_notedriver.cpp | 480 -------- xfa/fwl/core/cfwl_notedriver.h | 78 -- xfa/fwl/core/cfwl_noteloop.cpp | 9 - xfa/fwl/core/cfwl_noteloop.h | 27 - xfa/fwl/core/cfwl_picturebox.cpp | 52 - xfa/fwl/core/cfwl_picturebox.h | 51 - xfa/fwl/core/cfwl_pushbutton.cpp | 291 ----- xfa/fwl/core/cfwl_pushbutton.h | 69 -- xfa/fwl/core/cfwl_scrollbar.cpp | 503 -------- xfa/fwl/core/cfwl_scrollbar.h | 148 --- xfa/fwl/core/cfwl_spinbutton.cpp | 363 ------ xfa/fwl/core/cfwl_spinbutton.h | 73 -- xfa/fwl/core/cfwl_sysbtn.cpp | 49 - xfa/fwl/core/cfwl_sysbtn.h | 33 - xfa/fwl/core/cfwl_themebackground.h | 27 - xfa/fwl/core/cfwl_themepart.cpp | 18 - xfa/fwl/core/cfwl_themepart.h | 96 -- xfa/fwl/core/cfwl_themetext.h | 24 - xfa/fwl/core/cfwl_timer.cpp | 31 - xfa/fwl/core/cfwl_timer.h | 27 - xfa/fwl/core/cfwl_timerinfo.cpp | 13 - xfa/fwl/core/cfwl_timerinfo.h | 27 - xfa/fwl/core/cfwl_widget.cpp | 729 ------------ xfa/fwl/core/cfwl_widget.h | 196 ---- xfa/fwl/core/cfwl_widgetmgr.cpp | 732 ------------ xfa/fwl/core/cfwl_widgetmgr.h | 133 --- xfa/fwl/core/cfwl_widgetproperties.cpp | 19 - xfa/fwl/core/cfwl_widgetproperties.h | 32 - xfa/fwl/core/cfx_barcode.cpp | 316 ----- xfa/fwl/core/cfx_barcode.h | 65 -- xfa/fwl/core/fwl_error.h | 19 - xfa/fwl/core/fwl_widgetdef.h | 224 ---- xfa/fwl/core/fwl_widgethit.h | 35 - xfa/fwl/core/ifwl_adaptertimermgr.h | 21 - xfa/fwl/core/ifwl_themeprovider.h | 29 - xfa/fwl/core/ifwl_widgetdelegate.h | 27 - xfa/fwl/core/ifwl_widgetmgrdelegate.h | 24 - xfa/fwl/fwl_error.h | 19 + xfa/fwl/fwl_widgetdef.h | 224 ++++ xfa/fwl/fwl_widgethit.h | 35 + xfa/fwl/ifwl_adaptertimermgr.h | 21 + xfa/fwl/ifwl_themeprovider.h | 29 + xfa/fwl/ifwl_widgetdelegate.h | 27 + xfa/fwl/ifwl_widgetmgrdelegate.h | 24 + xfa/fwl/theme/cfwl_barcodetp.cpp | 6 +- xfa/fwl/theme/cfwl_carettp.cpp | 6 +- xfa/fwl/theme/cfwl_checkboxtp.cpp | 8 +- xfa/fwl/theme/cfwl_comboboxtp.cpp | 8 +- xfa/fwl/theme/cfwl_datetimepickertp.cpp | 4 +- xfa/fwl/theme/cfwl_edittp.cpp | 6 +- xfa/fwl/theme/cfwl_listboxtp.cpp | 6 +- xfa/fwl/theme/cfwl_monthcalendartp.cpp | 10 +- xfa/fwl/theme/cfwl_pictureboxtp.cpp | 6 +- xfa/fwl/theme/cfwl_pushbuttontp.cpp | 8 +- xfa/fwl/theme/cfwl_scrollbartp.cpp | 8 +- xfa/fwl/theme/cfwl_widgettp.cpp | 12 +- xfa/fwl/theme/cfwl_widgettp.h | 2 +- xfa/fxfa/app/xfa_ffapp.cpp | 4 +- xfa/fxfa/app/xfa_ffbarcode.cpp | 6 +- xfa/fxfa/app/xfa_ffcheckbutton.cpp | 10 +- xfa/fxfa/app/xfa_ffchoicelist.cpp | 18 +- xfa/fxfa/app/xfa_ffdoc.cpp | 2 +- xfa/fxfa/app/xfa_fffield.cpp | 50 +- xfa/fxfa/app/xfa_fffield.h | 4 +- xfa/fxfa/app/xfa_ffimageedit.cpp | 10 +- xfa/fxfa/app/xfa_ffpushbutton.cpp | 6 +- xfa/fxfa/app/xfa_fftext.cpp | 4 +- xfa/fxfa/app/xfa_fftextedit.cpp | 38 +- xfa/fxfa/app/xfa_ffwidget.cpp | 2 +- xfa/fxfa/app/xfa_fwladapter.h | 2 +- xfa/fxfa/app/xfa_fwltheme.cpp | 26 +- xfa/fxfa/app/xfa_fwltheme.h | 2 +- xfa/fxfa/xfa_ffapp.h | 2 +- xfa/fxfa/xfa_ffwidget.h | 2 +- xfa/fxgraphics/cfx_graphics.h | 2 +- 232 files changed, 15047 insertions(+), 15046 deletions(-) create mode 100644 xfa/fwl/cfwl_app.cpp create mode 100644 xfa/fwl/cfwl_app.h create mode 100644 xfa/fwl/cfwl_barcode.cpp create mode 100644 xfa/fwl/cfwl_barcode.h create mode 100644 xfa/fwl/cfwl_caret.cpp create mode 100644 xfa/fwl/cfwl_caret.h create mode 100644 xfa/fwl/cfwl_checkbox.cpp create mode 100644 xfa/fwl/cfwl_checkbox.h create mode 100644 xfa/fwl/cfwl_combobox.cpp create mode 100644 xfa/fwl/cfwl_combobox.h create mode 100644 xfa/fwl/cfwl_comboboxproxy.cpp create mode 100644 xfa/fwl/cfwl_comboboxproxy.h create mode 100644 xfa/fwl/cfwl_comboedit.cpp create mode 100644 xfa/fwl/cfwl_comboedit.h create mode 100644 xfa/fwl/cfwl_combolist.cpp create mode 100644 xfa/fwl/cfwl_combolist.h create mode 100644 xfa/fwl/cfwl_datetimeedit.cpp create mode 100644 xfa/fwl/cfwl_datetimeedit.h create mode 100644 xfa/fwl/cfwl_datetimepicker.cpp create mode 100644 xfa/fwl/cfwl_datetimepicker.h create mode 100644 xfa/fwl/cfwl_edit.cpp create mode 100644 xfa/fwl/cfwl_edit.h create mode 100644 xfa/fwl/cfwl_event.cpp create mode 100644 xfa/fwl/cfwl_event.h create mode 100644 xfa/fwl/cfwl_eventcheckword.cpp create mode 100644 xfa/fwl/cfwl_eventcheckword.h create mode 100644 xfa/fwl/cfwl_eventmouse.cpp create mode 100644 xfa/fwl/cfwl_eventmouse.h create mode 100644 xfa/fwl/cfwl_eventscroll.cpp create mode 100644 xfa/fwl/cfwl_eventscroll.h create mode 100644 xfa/fwl/cfwl_eventselectchanged.cpp create mode 100644 xfa/fwl/cfwl_eventselectchanged.h create mode 100644 xfa/fwl/cfwl_eventtarget.cpp create mode 100644 xfa/fwl/cfwl_eventtarget.h create mode 100644 xfa/fwl/cfwl_eventtextchanged.cpp create mode 100644 xfa/fwl/cfwl_eventtextchanged.h create mode 100644 xfa/fwl/cfwl_eventvalidate.cpp create mode 100644 xfa/fwl/cfwl_eventvalidate.h create mode 100644 xfa/fwl/cfwl_form.cpp create mode 100644 xfa/fwl/cfwl_form.h create mode 100644 xfa/fwl/cfwl_formproxy.cpp create mode 100644 xfa/fwl/cfwl_formproxy.h create mode 100644 xfa/fwl/cfwl_listbox.cpp create mode 100644 xfa/fwl/cfwl_listbox.h create mode 100644 xfa/fwl/cfwl_listitem.cpp create mode 100644 xfa/fwl/cfwl_listitem.h create mode 100644 xfa/fwl/cfwl_message.cpp create mode 100644 xfa/fwl/cfwl_message.h create mode 100644 xfa/fwl/cfwl_messagekey.cpp create mode 100644 xfa/fwl/cfwl_messagekey.h create mode 100644 xfa/fwl/cfwl_messagekillfocus.cpp create mode 100644 xfa/fwl/cfwl_messagekillfocus.h create mode 100644 xfa/fwl/cfwl_messagemouse.cpp create mode 100644 xfa/fwl/cfwl_messagemouse.h create mode 100644 xfa/fwl/cfwl_messagemousewheel.cpp create mode 100644 xfa/fwl/cfwl_messagemousewheel.h create mode 100644 xfa/fwl/cfwl_messagesetfocus.cpp create mode 100644 xfa/fwl/cfwl_messagesetfocus.h create mode 100644 xfa/fwl/cfwl_monthcalendar.cpp create mode 100644 xfa/fwl/cfwl_monthcalendar.h create mode 100644 xfa/fwl/cfwl_notedriver.cpp create mode 100644 xfa/fwl/cfwl_notedriver.h create mode 100644 xfa/fwl/cfwl_noteloop.cpp create mode 100644 xfa/fwl/cfwl_noteloop.h create mode 100644 xfa/fwl/cfwl_picturebox.cpp create mode 100644 xfa/fwl/cfwl_picturebox.h create mode 100644 xfa/fwl/cfwl_pushbutton.cpp create mode 100644 xfa/fwl/cfwl_pushbutton.h create mode 100644 xfa/fwl/cfwl_scrollbar.cpp create mode 100644 xfa/fwl/cfwl_scrollbar.h create mode 100644 xfa/fwl/cfwl_spinbutton.cpp create mode 100644 xfa/fwl/cfwl_spinbutton.h create mode 100644 xfa/fwl/cfwl_sysbtn.cpp create mode 100644 xfa/fwl/cfwl_sysbtn.h create mode 100644 xfa/fwl/cfwl_themebackground.h create mode 100644 xfa/fwl/cfwl_themepart.cpp create mode 100644 xfa/fwl/cfwl_themepart.h create mode 100644 xfa/fwl/cfwl_themetext.h create mode 100644 xfa/fwl/cfwl_timer.cpp create mode 100644 xfa/fwl/cfwl_timer.h create mode 100644 xfa/fwl/cfwl_timerinfo.cpp create mode 100644 xfa/fwl/cfwl_timerinfo.h create mode 100644 xfa/fwl/cfwl_widget.cpp create mode 100644 xfa/fwl/cfwl_widget.h create mode 100644 xfa/fwl/cfwl_widgetmgr.cpp create mode 100644 xfa/fwl/cfwl_widgetmgr.h create mode 100644 xfa/fwl/cfwl_widgetproperties.cpp create mode 100644 xfa/fwl/cfwl_widgetproperties.h create mode 100644 xfa/fwl/cfx_barcode.cpp create mode 100644 xfa/fwl/cfx_barcode.h delete mode 100644 xfa/fwl/core/cfwl_app.cpp delete mode 100644 xfa/fwl/core/cfwl_app.h delete mode 100644 xfa/fwl/core/cfwl_barcode.cpp delete mode 100644 xfa/fwl/core/cfwl_barcode.h delete mode 100644 xfa/fwl/core/cfwl_caret.cpp delete mode 100644 xfa/fwl/core/cfwl_caret.h delete mode 100644 xfa/fwl/core/cfwl_checkbox.cpp delete mode 100644 xfa/fwl/core/cfwl_checkbox.h delete mode 100644 xfa/fwl/core/cfwl_combobox.cpp delete mode 100644 xfa/fwl/core/cfwl_combobox.h delete mode 100644 xfa/fwl/core/cfwl_comboboxproxy.cpp delete mode 100644 xfa/fwl/core/cfwl_comboboxproxy.h delete mode 100644 xfa/fwl/core/cfwl_comboedit.cpp delete mode 100644 xfa/fwl/core/cfwl_comboedit.h delete mode 100644 xfa/fwl/core/cfwl_combolist.cpp delete mode 100644 xfa/fwl/core/cfwl_combolist.h delete mode 100644 xfa/fwl/core/cfwl_datetimeedit.cpp delete mode 100644 xfa/fwl/core/cfwl_datetimeedit.h delete mode 100644 xfa/fwl/core/cfwl_datetimepicker.cpp delete mode 100644 xfa/fwl/core/cfwl_datetimepicker.h delete mode 100644 xfa/fwl/core/cfwl_edit.cpp delete mode 100644 xfa/fwl/core/cfwl_edit.h delete mode 100644 xfa/fwl/core/cfwl_event.cpp delete mode 100644 xfa/fwl/core/cfwl_event.h delete mode 100644 xfa/fwl/core/cfwl_eventtarget.cpp delete mode 100644 xfa/fwl/core/cfwl_eventtarget.h delete mode 100644 xfa/fwl/core/cfwl_evtcheckword.cpp delete mode 100644 xfa/fwl/core/cfwl_evtcheckword.h delete mode 100644 xfa/fwl/core/cfwl_evtmouse.cpp delete mode 100644 xfa/fwl/core/cfwl_evtmouse.h delete mode 100644 xfa/fwl/core/cfwl_evtscroll.cpp delete mode 100644 xfa/fwl/core/cfwl_evtscroll.h delete mode 100644 xfa/fwl/core/cfwl_evtselectchanged.cpp delete mode 100644 xfa/fwl/core/cfwl_evtselectchanged.h delete mode 100644 xfa/fwl/core/cfwl_evttextchanged.cpp delete mode 100644 xfa/fwl/core/cfwl_evttextchanged.h delete mode 100644 xfa/fwl/core/cfwl_evtvalidate.cpp delete mode 100644 xfa/fwl/core/cfwl_evtvalidate.h delete mode 100644 xfa/fwl/core/cfwl_form.cpp delete mode 100644 xfa/fwl/core/cfwl_form.h delete mode 100644 xfa/fwl/core/cfwl_formproxy.cpp delete mode 100644 xfa/fwl/core/cfwl_formproxy.h delete mode 100644 xfa/fwl/core/cfwl_listbox.cpp delete mode 100644 xfa/fwl/core/cfwl_listbox.h delete mode 100644 xfa/fwl/core/cfwl_listitem.cpp delete mode 100644 xfa/fwl/core/cfwl_listitem.h delete mode 100644 xfa/fwl/core/cfwl_message.cpp delete mode 100644 xfa/fwl/core/cfwl_message.h delete mode 100644 xfa/fwl/core/cfwl_monthcalendar.cpp delete mode 100644 xfa/fwl/core/cfwl_monthcalendar.h delete mode 100644 xfa/fwl/core/cfwl_msgkey.cpp delete mode 100644 xfa/fwl/core/cfwl_msgkey.h delete mode 100644 xfa/fwl/core/cfwl_msgkillfocus.cpp delete mode 100644 xfa/fwl/core/cfwl_msgkillfocus.h delete mode 100644 xfa/fwl/core/cfwl_msgmouse.cpp delete mode 100644 xfa/fwl/core/cfwl_msgmouse.h delete mode 100644 xfa/fwl/core/cfwl_msgmousewheel.cpp delete mode 100644 xfa/fwl/core/cfwl_msgmousewheel.h delete mode 100644 xfa/fwl/core/cfwl_msgsetfocus.cpp delete mode 100644 xfa/fwl/core/cfwl_msgsetfocus.h delete mode 100644 xfa/fwl/core/cfwl_notedriver.cpp delete mode 100644 xfa/fwl/core/cfwl_notedriver.h delete mode 100644 xfa/fwl/core/cfwl_noteloop.cpp delete mode 100644 xfa/fwl/core/cfwl_noteloop.h delete mode 100644 xfa/fwl/core/cfwl_picturebox.cpp delete mode 100644 xfa/fwl/core/cfwl_picturebox.h delete mode 100644 xfa/fwl/core/cfwl_pushbutton.cpp delete mode 100644 xfa/fwl/core/cfwl_pushbutton.h delete mode 100644 xfa/fwl/core/cfwl_scrollbar.cpp delete mode 100644 xfa/fwl/core/cfwl_scrollbar.h delete mode 100644 xfa/fwl/core/cfwl_spinbutton.cpp delete mode 100644 xfa/fwl/core/cfwl_spinbutton.h delete mode 100644 xfa/fwl/core/cfwl_sysbtn.cpp delete mode 100644 xfa/fwl/core/cfwl_sysbtn.h delete mode 100644 xfa/fwl/core/cfwl_themebackground.h delete mode 100644 xfa/fwl/core/cfwl_themepart.cpp delete mode 100644 xfa/fwl/core/cfwl_themepart.h delete mode 100644 xfa/fwl/core/cfwl_themetext.h delete mode 100644 xfa/fwl/core/cfwl_timer.cpp delete mode 100644 xfa/fwl/core/cfwl_timer.h delete mode 100644 xfa/fwl/core/cfwl_timerinfo.cpp delete mode 100644 xfa/fwl/core/cfwl_timerinfo.h delete mode 100644 xfa/fwl/core/cfwl_widget.cpp delete mode 100644 xfa/fwl/core/cfwl_widget.h delete mode 100644 xfa/fwl/core/cfwl_widgetmgr.cpp delete mode 100644 xfa/fwl/core/cfwl_widgetmgr.h delete mode 100644 xfa/fwl/core/cfwl_widgetproperties.cpp delete mode 100644 xfa/fwl/core/cfwl_widgetproperties.h delete mode 100644 xfa/fwl/core/cfx_barcode.cpp delete mode 100644 xfa/fwl/core/cfx_barcode.h delete mode 100644 xfa/fwl/core/fwl_error.h delete mode 100644 xfa/fwl/core/fwl_widgetdef.h delete mode 100644 xfa/fwl/core/fwl_widgethit.h delete mode 100644 xfa/fwl/core/ifwl_adaptertimermgr.h delete mode 100644 xfa/fwl/core/ifwl_themeprovider.h delete mode 100644 xfa/fwl/core/ifwl_widgetdelegate.h delete mode 100644 xfa/fwl/core/ifwl_widgetmgrdelegate.h create mode 100644 xfa/fwl/fwl_error.h create mode 100644 xfa/fwl/fwl_widgetdef.h create mode 100644 xfa/fwl/fwl_widgethit.h create mode 100644 xfa/fwl/ifwl_adaptertimermgr.h create mode 100644 xfa/fwl/ifwl_themeprovider.h create mode 100644 xfa/fwl/ifwl_widgetdelegate.h create mode 100644 xfa/fwl/ifwl_widgetmgrdelegate.h diff --git a/BUILD.gn b/BUILD.gn index c6d90365b5..2a680c0b80 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1197,103 +1197,103 @@ if (pdf_enable_xfa) { "xfa/fgas/localization/fgas_locale.cpp", "xfa/fgas/localization/fgas_locale.h", "xfa/fgas/localization/fgas_localeimp.h", - "xfa/fwl/core/cfwl_app.cpp", - "xfa/fwl/core/cfwl_app.h", - "xfa/fwl/core/cfwl_barcode.cpp", - "xfa/fwl/core/cfwl_barcode.h", - "xfa/fwl/core/cfwl_caret.cpp", - "xfa/fwl/core/cfwl_caret.h", - "xfa/fwl/core/cfwl_checkbox.cpp", - "xfa/fwl/core/cfwl_checkbox.h", - "xfa/fwl/core/cfwl_combobox.cpp", - "xfa/fwl/core/cfwl_combobox.h", - "xfa/fwl/core/cfwl_comboboxproxy.cpp", - "xfa/fwl/core/cfwl_comboboxproxy.h", - "xfa/fwl/core/cfwl_comboedit.cpp", - "xfa/fwl/core/cfwl_comboedit.h", - "xfa/fwl/core/cfwl_combolist.cpp", - "xfa/fwl/core/cfwl_combolist.h", - "xfa/fwl/core/cfwl_datetimeedit.cpp", - "xfa/fwl/core/cfwl_datetimeedit.h", - "xfa/fwl/core/cfwl_datetimepicker.cpp", - "xfa/fwl/core/cfwl_datetimepicker.h", - "xfa/fwl/core/cfwl_edit.cpp", - "xfa/fwl/core/cfwl_edit.h", - "xfa/fwl/core/cfwl_event.cpp", - "xfa/fwl/core/cfwl_event.h", - "xfa/fwl/core/cfwl_eventtarget.cpp", - "xfa/fwl/core/cfwl_eventtarget.h", - "xfa/fwl/core/cfwl_evtcheckword.cpp", - "xfa/fwl/core/cfwl_evtcheckword.h", - "xfa/fwl/core/cfwl_evtmouse.cpp", - "xfa/fwl/core/cfwl_evtmouse.h", - "xfa/fwl/core/cfwl_evtscroll.cpp", - "xfa/fwl/core/cfwl_evtscroll.h", - "xfa/fwl/core/cfwl_evtselectchanged.cpp", - "xfa/fwl/core/cfwl_evtselectchanged.h", - "xfa/fwl/core/cfwl_evttextchanged.cpp", - "xfa/fwl/core/cfwl_evttextchanged.h", - "xfa/fwl/core/cfwl_evtvalidate.cpp", - "xfa/fwl/core/cfwl_evtvalidate.h", - "xfa/fwl/core/cfwl_form.cpp", - "xfa/fwl/core/cfwl_form.h", - "xfa/fwl/core/cfwl_formproxy.cpp", - "xfa/fwl/core/cfwl_formproxy.h", - "xfa/fwl/core/cfwl_listbox.cpp", - "xfa/fwl/core/cfwl_listbox.h", - "xfa/fwl/core/cfwl_listitem.cpp", - "xfa/fwl/core/cfwl_listitem.h", - "xfa/fwl/core/cfwl_message.cpp", - "xfa/fwl/core/cfwl_message.h", - "xfa/fwl/core/cfwl_monthcalendar.cpp", - "xfa/fwl/core/cfwl_monthcalendar.h", - "xfa/fwl/core/cfwl_msgkey.cpp", - "xfa/fwl/core/cfwl_msgkey.h", - "xfa/fwl/core/cfwl_msgkillfocus.cpp", - "xfa/fwl/core/cfwl_msgkillfocus.h", - "xfa/fwl/core/cfwl_msgmouse.cpp", - "xfa/fwl/core/cfwl_msgmouse.h", - "xfa/fwl/core/cfwl_msgmousewheel.cpp", - "xfa/fwl/core/cfwl_msgmousewheel.h", - "xfa/fwl/core/cfwl_msgsetfocus.cpp", - "xfa/fwl/core/cfwl_msgsetfocus.h", - "xfa/fwl/core/cfwl_notedriver.cpp", - "xfa/fwl/core/cfwl_notedriver.h", - "xfa/fwl/core/cfwl_noteloop.cpp", - "xfa/fwl/core/cfwl_noteloop.h", - "xfa/fwl/core/cfwl_picturebox.cpp", - "xfa/fwl/core/cfwl_picturebox.h", - "xfa/fwl/core/cfwl_pushbutton.cpp", - "xfa/fwl/core/cfwl_pushbutton.h", - "xfa/fwl/core/cfwl_scrollbar.cpp", - "xfa/fwl/core/cfwl_scrollbar.h", - "xfa/fwl/core/cfwl_spinbutton.cpp", - "xfa/fwl/core/cfwl_spinbutton.h", - "xfa/fwl/core/cfwl_sysbtn.cpp", - "xfa/fwl/core/cfwl_sysbtn.h", - "xfa/fwl/core/cfwl_themebackground.h", - "xfa/fwl/core/cfwl_themepart.cpp", - "xfa/fwl/core/cfwl_themepart.h", - "xfa/fwl/core/cfwl_themetext.h", - "xfa/fwl/core/cfwl_timer.cpp", - "xfa/fwl/core/cfwl_timer.h", - "xfa/fwl/core/cfwl_timerinfo.cpp", - "xfa/fwl/core/cfwl_timerinfo.h", - "xfa/fwl/core/cfwl_widget.cpp", - "xfa/fwl/core/cfwl_widget.h", - "xfa/fwl/core/cfwl_widgetmgr.cpp", - "xfa/fwl/core/cfwl_widgetmgr.h", - "xfa/fwl/core/cfwl_widgetproperties.cpp", - "xfa/fwl/core/cfwl_widgetproperties.h", - "xfa/fwl/core/cfx_barcode.cpp", - "xfa/fwl/core/cfx_barcode.h", - "xfa/fwl/core/fwl_error.h", - "xfa/fwl/core/fwl_widgetdef.h", - "xfa/fwl/core/fwl_widgethit.h", - "xfa/fwl/core/ifwl_adaptertimermgr.h", - "xfa/fwl/core/ifwl_themeprovider.h", - "xfa/fwl/core/ifwl_widgetdelegate.h", - "xfa/fwl/core/ifwl_widgetmgrdelegate.h", + "xfa/fwl/cfwl_app.cpp", + "xfa/fwl/cfwl_app.h", + "xfa/fwl/cfwl_barcode.cpp", + "xfa/fwl/cfwl_barcode.h", + "xfa/fwl/cfwl_caret.cpp", + "xfa/fwl/cfwl_caret.h", + "xfa/fwl/cfwl_checkbox.cpp", + "xfa/fwl/cfwl_checkbox.h", + "xfa/fwl/cfwl_combobox.cpp", + "xfa/fwl/cfwl_combobox.h", + "xfa/fwl/cfwl_comboboxproxy.cpp", + "xfa/fwl/cfwl_comboboxproxy.h", + "xfa/fwl/cfwl_comboedit.cpp", + "xfa/fwl/cfwl_comboedit.h", + "xfa/fwl/cfwl_combolist.cpp", + "xfa/fwl/cfwl_combolist.h", + "xfa/fwl/cfwl_datetimeedit.cpp", + "xfa/fwl/cfwl_datetimeedit.h", + "xfa/fwl/cfwl_datetimepicker.cpp", + "xfa/fwl/cfwl_datetimepicker.h", + "xfa/fwl/cfwl_edit.cpp", + "xfa/fwl/cfwl_edit.h", + "xfa/fwl/cfwl_event.cpp", + "xfa/fwl/cfwl_event.h", + "xfa/fwl/cfwl_eventcheckword.cpp", + "xfa/fwl/cfwl_eventcheckword.h", + "xfa/fwl/cfwl_eventmouse.cpp", + "xfa/fwl/cfwl_eventmouse.h", + "xfa/fwl/cfwl_eventscroll.cpp", + "xfa/fwl/cfwl_eventscroll.h", + "xfa/fwl/cfwl_eventselectchanged.cpp", + "xfa/fwl/cfwl_eventselectchanged.h", + "xfa/fwl/cfwl_eventtarget.cpp", + "xfa/fwl/cfwl_eventtarget.h", + "xfa/fwl/cfwl_eventtextchanged.cpp", + "xfa/fwl/cfwl_eventtextchanged.h", + "xfa/fwl/cfwl_eventvalidate.cpp", + "xfa/fwl/cfwl_eventvalidate.h", + "xfa/fwl/cfwl_form.cpp", + "xfa/fwl/cfwl_form.h", + "xfa/fwl/cfwl_formproxy.cpp", + "xfa/fwl/cfwl_formproxy.h", + "xfa/fwl/cfwl_listbox.cpp", + "xfa/fwl/cfwl_listbox.h", + "xfa/fwl/cfwl_listitem.cpp", + "xfa/fwl/cfwl_listitem.h", + "xfa/fwl/cfwl_message.cpp", + "xfa/fwl/cfwl_message.h", + "xfa/fwl/cfwl_messagekey.cpp", + "xfa/fwl/cfwl_messagekey.h", + "xfa/fwl/cfwl_messagekillfocus.cpp", + "xfa/fwl/cfwl_messagekillfocus.h", + "xfa/fwl/cfwl_messagemouse.cpp", + "xfa/fwl/cfwl_messagemouse.h", + "xfa/fwl/cfwl_messagemousewheel.cpp", + "xfa/fwl/cfwl_messagemousewheel.h", + "xfa/fwl/cfwl_messagesetfocus.cpp", + "xfa/fwl/cfwl_messagesetfocus.h", + "xfa/fwl/cfwl_monthcalendar.cpp", + "xfa/fwl/cfwl_monthcalendar.h", + "xfa/fwl/cfwl_notedriver.cpp", + "xfa/fwl/cfwl_notedriver.h", + "xfa/fwl/cfwl_noteloop.cpp", + "xfa/fwl/cfwl_noteloop.h", + "xfa/fwl/cfwl_picturebox.cpp", + "xfa/fwl/cfwl_picturebox.h", + "xfa/fwl/cfwl_pushbutton.cpp", + "xfa/fwl/cfwl_pushbutton.h", + "xfa/fwl/cfwl_scrollbar.cpp", + "xfa/fwl/cfwl_scrollbar.h", + "xfa/fwl/cfwl_spinbutton.cpp", + "xfa/fwl/cfwl_spinbutton.h", + "xfa/fwl/cfwl_sysbtn.cpp", + "xfa/fwl/cfwl_sysbtn.h", + "xfa/fwl/cfwl_themebackground.h", + "xfa/fwl/cfwl_themepart.cpp", + "xfa/fwl/cfwl_themepart.h", + "xfa/fwl/cfwl_themetext.h", + "xfa/fwl/cfwl_timer.cpp", + "xfa/fwl/cfwl_timer.h", + "xfa/fwl/cfwl_timerinfo.cpp", + "xfa/fwl/cfwl_timerinfo.h", + "xfa/fwl/cfwl_widget.cpp", + "xfa/fwl/cfwl_widget.h", + "xfa/fwl/cfwl_widgetmgr.cpp", + "xfa/fwl/cfwl_widgetmgr.h", + "xfa/fwl/cfwl_widgetproperties.cpp", + "xfa/fwl/cfwl_widgetproperties.h", + "xfa/fwl/cfx_barcode.cpp", + "xfa/fwl/cfx_barcode.h", + "xfa/fwl/fwl_error.h", + "xfa/fwl/fwl_widgetdef.h", + "xfa/fwl/fwl_widgethit.h", + "xfa/fwl/ifwl_adaptertimermgr.h", + "xfa/fwl/ifwl_themeprovider.h", + "xfa/fwl/ifwl_widgetdelegate.h", + "xfa/fwl/ifwl_widgetmgrdelegate.h", "xfa/fwl/theme/cfwl_arrowdata.cpp", "xfa/fwl/theme/cfwl_arrowdata.h", "xfa/fwl/theme/cfwl_barcodetp.cpp", diff --git a/fpdfsdk/DEPS b/fpdfsdk/DEPS index ce037d902e..e077225b17 100644 --- a/fpdfsdk/DEPS +++ b/fpdfsdk/DEPS @@ -2,7 +2,7 @@ include_rules = [ '+core', '+public', '+v8', - '+xfa/fwl/core', + '+xfa/fwl', '+xfa/fxbarcode', '+xfa/fxfa', '+xfa/fxgraphics', diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index 11c560b53f..eff351b55d 100644 --- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -13,8 +13,8 @@ #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_xfawidget.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/fwl_widgethit.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/fwl_widgethit.h" #include "xfa/fxfa/fxfa_basic.h" #include "xfa/fxfa/xfa_ffdocview.h" #include "xfa/fxfa/xfa_ffpageview.h" diff --git a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h index 3904ba5300..fdb5635ff0 100644 --- a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h +++ b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h @@ -11,8 +11,8 @@ #include #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/ifwl_adaptertimermgr.h" +#include "xfa/fwl/cfwl_timerinfo.h" +#include "xfa/fwl/ifwl_adaptertimermgr.h" class CXFA_FWLAdapterTimerMgr : public IFWL_AdapterTimerMgr { public: diff --git a/xfa/fde/cfde_txtedtdorecord_deleterange.cpp b/xfa/fde/cfde_txtedtdorecord_deleterange.cpp index d1682ddccd..df6387e084 100644 --- a/xfa/fde/cfde_txtedtdorecord_deleterange.cpp +++ b/xfa/fde/cfde_txtedtdorecord_deleterange.cpp @@ -7,7 +7,7 @@ #include "xfa/fde/cfde_txtedtdorecord_deleterange.h" #include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fwl/core/cfwl_edit.h" +#include "xfa/fwl/cfwl_edit.h" CFDE_TxtEdtDoRecord_DeleteRange::CFDE_TxtEdtDoRecord_DeleteRange( CFDE_TxtEdtEngine* pEngine, diff --git a/xfa/fde/cfde_txtedtdorecord_insert.cpp b/xfa/fde/cfde_txtedtdorecord_insert.cpp index e659f020ca..b80b15dff6 100644 --- a/xfa/fde/cfde_txtedtdorecord_insert.cpp +++ b/xfa/fde/cfde_txtedtdorecord_insert.cpp @@ -7,7 +7,7 @@ #include "xfa/fde/cfde_txtedtdorecord_insert.h" #include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fwl/core/cfwl_edit.h" +#include "xfa/fwl/cfwl_edit.h" CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( CFDE_TxtEdtEngine* pEngine, diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp index 6e113e1738..ced5bdca52 100644 --- a/xfa/fde/cfde_txtedtengine.cpp +++ b/xfa/fde/cfde_txtedtengine.cpp @@ -18,7 +18,7 @@ #include "xfa/fde/ifx_chariter.h" #include "xfa/fde/tto/fde_textout.h" #include "xfa/fgas/layout/fgas_textbreak.h" -#include "xfa/fwl/core/cfwl_edit.h" +#include "xfa/fwl/cfwl_edit.h" namespace { diff --git a/xfa/fwl/cfwl_app.cpp b/xfa/fwl/cfwl_app.cpp new file mode 100644 index 0000000000..febc8a0fdf --- /dev/null +++ b/xfa/fwl/cfwl_app.cpp @@ -0,0 +1,22 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_app.h" + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fxfa/app/xfa_fwladapter.h" + +CFWL_App::CFWL_App(CXFA_FFApp* pAdapter) + : m_pAdapterNative(pAdapter), + m_pWidgetMgr(pdfium::MakeUnique(pAdapter)), + m_pNoteDriver(pdfium::MakeUnique()) { + ASSERT(m_pAdapterNative); +} + +CFWL_App::~CFWL_App() {} diff --git a/xfa/fwl/cfwl_app.h b/xfa/fwl/cfwl_app.h new file mode 100644 index 0000000000..c2779e8a25 --- /dev/null +++ b/xfa/fwl/cfwl_app.h @@ -0,0 +1,45 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_APP_H_ +#define XFA_FWL_CFWL_APP_H_ + +#include + +#include "core/fxcrt/fx_string.h" + +class CFWL_NoteDriver; +class CFWL_WidgetMgr; +class CXFA_FFApp; +class CXFA_FWLAdapterWidgetMgr; +class CFWL_Widget; + +enum FWL_KeyFlag { + FWL_KEYFLAG_Ctrl = 1 << 0, + FWL_KEYFLAG_Alt = 1 << 1, + FWL_KEYFLAG_Shift = 1 << 2, + FWL_KEYFLAG_Command = 1 << 3, + FWL_KEYFLAG_LButton = 1 << 4, + FWL_KEYFLAG_RButton = 1 << 5, + FWL_KEYFLAG_MButton = 1 << 6 +}; + +class CFWL_App { + public: + explicit CFWL_App(CXFA_FFApp* pAdapter); + ~CFWL_App(); + + CXFA_FFApp* GetAdapterNative() const { return m_pAdapterNative; } + CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr.get(); } + CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); } + + private: + CXFA_FFApp* const m_pAdapterNative; + std::unique_ptr m_pWidgetMgr; + std::unique_ptr m_pNoteDriver; +}; + +#endif // XFA_FWL_CFWL_APP_H_ diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp new file mode 100644 index 0000000000..83ab74a608 --- /dev/null +++ b/xfa/fwl/cfwl_barcode.cpp @@ -0,0 +1,232 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_barcode.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fgas/font/cfgas_gefont.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfx_barcode.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +CFWL_Barcode::CFWL_Barcode(const CFWL_App* app) + : CFWL_Edit(app, pdfium::MakeUnique(), nullptr), + m_dwStatus(0), + m_type(BC_UNKNOWN), + m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {} + +CFWL_Barcode::~CFWL_Barcode() {} + +FWL_Type CFWL_Barcode::GetClassID() const { + return FWL_Type::Barcode; +} + +void CFWL_Barcode::Update() { + if (IsLocked()) + return; + + CFWL_Edit::Update(); + GenerateBarcodeImageCache(); +} + +void CFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { + GenerateBarcodeImageCache(); + if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) + return; + + CFX_Matrix mt; + mt.e = GetRTClient().left; + mt.f = GetRTClient().top; + if (pMatrix) + mt.Concat(*pMatrix); + + int32_t errorCode = 0; + m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, + errorCode); + return; + } + CFWL_Edit::DrawWidget(pGraphics, pMatrix); +} + +void CFWL_Barcode::SetType(BC_TYPE type) { + if (m_type == type) + return; + + m_pBarcodeEngine.reset(); + m_type = type; + m_dwStatus = XFA_BCS_NeedUpdate; +} + +void CFWL_Barcode::SetText(const CFX_WideString& wsText) { + m_pBarcodeEngine.reset(); + m_dwStatus = XFA_BCS_NeedUpdate; + CFWL_Edit::SetText(wsText); +} + +bool CFWL_Barcode::IsProtectedType() const { + if (!m_pBarcodeEngine) + return true; + + BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); + if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || + tEngineType == BC_DATAMATRIX) { + return true; + } + return false; +} + +void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) { + if (pEvent->GetType() == CFWL_Event::Type::TextChanged) { + m_pBarcodeEngine.reset(); + m_dwStatus = XFA_BCS_NeedUpdate; + } + CFWL_Edit::OnProcessEvent(pEvent); +} + +void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING; + m_eCharEncoding = encoding; +} + +void CFWL_Barcode::SetModuleHeight(int32_t height) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT; + m_nModuleHeight = height; +} + +void CFWL_Barcode::SetModuleWidth(int32_t width) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH; + m_nModuleWidth = width; +} + +void CFWL_Barcode::SetDataLength(int32_t dataLength) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; + m_nDataLength = dataLength; + SetLimit(dataLength); +} + +void CFWL_Barcode::SetCalChecksum(bool calChecksum) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; + m_bCalChecksum = calChecksum; +} + +void CFWL_Barcode::SetPrintChecksum(bool printChecksum) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM; + m_bPrintChecksum = printChecksum; +} + +void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_TEXTLOCATION; + m_eTextLocation = location; +} + +void CFWL_Barcode::SetWideNarrowRatio(int32_t ratio) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO; + m_nWideNarrowRatio = ratio; +} + +void CFWL_Barcode::SetStartChar(FX_CHAR startChar) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR; + m_cStartChar = startChar; +} + +void CFWL_Barcode::SetEndChar(FX_CHAR endChar) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_ENDCHAR; + m_cEndChar = endChar; +} + +void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL; + m_nECLevel = ecLevel; +} + +void CFWL_Barcode::SetTruncated(bool truncated) { + m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED; + m_bTruncated = truncated; +} + +void CFWL_Barcode::GenerateBarcodeImageCache() { + if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) + return; + + m_dwStatus = 0; + CreateBarcodeEngine(); + if (!m_pBarcodeEngine) + return; + + CFX_WideString wsText = GetText(); + + CFWL_ThemePart part; + part.m_pWidget = this; + + IFWL_ThemeProvider* pTheme = GetAvailableTheme(); + CFGAS_GEFont* pFont = static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); + CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr; + if (pCXFont) + m_pBarcodeEngine->SetFont(pCXFont); + + FX_FLOAT* pFontSize = static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize)); + if (pFontSize) + m_pBarcodeEngine->SetFontSize(*pFontSize); + + FX_ARGB* pFontColor = static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TextColor)); + if (pFontColor) + m_pBarcodeEngine->SetFontColor(*pFontColor); + + m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height)); + m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width)); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING) + m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT) + m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH) + m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH) + m_pBarcodeEngine->SetDataLength(m_nDataLength); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM) + m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM) + m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION) + m_pBarcodeEngine->SetTextLocation(m_eTextLocation); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO) + m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR) + m_pBarcodeEngine->SetStartChar(m_cStartChar); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR) + m_pBarcodeEngine->SetEndChar(m_cEndChar); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_VERSION) + m_pBarcodeEngine->SetVersion(0); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL) + m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel); + if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) + m_pBarcodeEngine->SetTruncated(m_bTruncated); + + int32_t errorCode = 0; + m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), true, errorCode) + ? XFA_BCS_EncodeSuccess + : 0; +} + +void CFWL_Barcode::CreateBarcodeEngine() { + if (m_pBarcodeEngine || m_type == BC_UNKNOWN) + return; + + std::unique_ptr pBarcode(new CFX_Barcode); + if (pBarcode->Create(m_type)) + m_pBarcodeEngine = std::move(pBarcode); +} diff --git a/xfa/fwl/cfwl_barcode.h b/xfa/fwl/cfwl_barcode.h new file mode 100644 index 0000000000..2e9799172b --- /dev/null +++ b/xfa/fwl/cfwl_barcode.h @@ -0,0 +1,93 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_BARCODE_H_ +#define XFA_FWL_CFWL_BARCODE_H_ + +#include + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_scrollbar.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxbarcode/BC_Library.h" + +class CFWL_WidgetProperties; +class CFX_Barcode; +class CFWL_Widget; + +#define XFA_BCS_NeedUpdate 0x0001 +#define XFA_BCS_EncodeSuccess 0x0002 + +enum FWL_BCDAttribute { + FWL_BCDATTRIBUTE_NONE = 0, + FWL_BCDATTRIBUTE_CHARENCODING = 1 << 0, + FWL_BCDATTRIBUTE_MODULEHEIGHT = 1 << 1, + FWL_BCDATTRIBUTE_MODULEWIDTH = 1 << 2, + FWL_BCDATTRIBUTE_DATALENGTH = 1 << 3, + FWL_BCDATTRIBUTE_CALCHECKSUM = 1 << 4, + FWL_BCDATTRIBUTE_PRINTCHECKSUM = 1 << 5, + FWL_BCDATTRIBUTE_TEXTLOCATION = 1 << 6, + FWL_BCDATTRIBUTE_WIDENARROWRATIO = 1 << 7, + FWL_BCDATTRIBUTE_STARTCHAR = 1 << 8, + FWL_BCDATTRIBUTE_ENDCHAR = 1 << 9, + FWL_BCDATTRIBUTE_VERSION = 1 << 10, + FWL_BCDATTRIBUTE_ECLEVEL = 1 << 11, + FWL_BCDATTRIBUTE_TRUNCATED = 1 << 12 +}; + +class CFWL_Barcode : public CFWL_Edit { + public: + explicit CFWL_Barcode(const CFWL_App* pApp); + ~CFWL_Barcode() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + + // CFWL_Edit + void SetText(const CFX_WideString& wsText) override; + + void SetType(BC_TYPE type); + bool IsProtectedType() const; + + void SetCharEncoding(BC_CHAR_ENCODING encoding); + void SetModuleHeight(int32_t height); + void SetModuleWidth(int32_t width); + void SetDataLength(int32_t dataLength); + void SetCalChecksum(bool calChecksum); + void SetPrintChecksum(bool printChecksum); + void SetTextLocation(BC_TEXT_LOC location); + void SetWideNarrowRatio(int32_t ratio); + void SetStartChar(FX_CHAR startChar); + void SetEndChar(FX_CHAR endChar); + void SetErrorCorrectionLevel(int32_t ecLevel); + void SetTruncated(bool truncated); + + private: + void GenerateBarcodeImageCache(); + void CreateBarcodeEngine(); + + std::unique_ptr m_pBarcodeEngine; + uint32_t m_dwStatus; + BC_TYPE m_type; + BC_CHAR_ENCODING m_eCharEncoding; + int32_t m_nModuleHeight; + int32_t m_nModuleWidth; + int32_t m_nDataLength; + bool m_bCalChecksum; + bool m_bPrintChecksum; + BC_TEXT_LOC m_eTextLocation; + int32_t m_nWideNarrowRatio; + FX_CHAR m_cStartChar; + FX_CHAR m_cEndChar; + int32_t m_nECLevel; + bool m_bTruncated; + uint32_t m_dwAttributeMask; +}; + +#endif // XFA_FWL_CFWL_BARCODE_H_ diff --git a/xfa/fwl/cfwl_caret.cpp b/xfa/fwl/cfwl_caret.cpp new file mode 100644 index 0000000000..fdac8ec040 --- /dev/null +++ b/xfa/fwl/cfwl_caret.cpp @@ -0,0 +1,112 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_caret.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_timerinfo.h" +#include "xfa/fwl/cfwl_widgetproperties.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +namespace { + +const uint32_t kFrequency = 400; + +} // namespace + +CFWL_Caret::CFWL_Caret(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Widget(app, std::move(properties), pOuter), + m_pTimer(new CFWL_Caret::Timer(this)), + m_pTimerInfo(nullptr) { + SetStates(FWL_STATE_CAT_HightLight); +} + +CFWL_Caret::~CFWL_Caret() { + if (m_pTimerInfo) { + m_pTimerInfo->StopTimer(); + m_pTimerInfo = nullptr; + } +} + +FWL_Type CFWL_Caret::GetClassID() const { + return FWL_Type::Caret; +} + +void CFWL_Caret::Update() {} + +void CFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + if (!m_pProperties->m_pThemeProvider) + return; + + DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); +} + +void CFWL_Caret::ShowCaret() { + if (m_pTimerInfo) + m_pTimerInfo->StopTimer(); + m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); + RemoveStates(FWL_WGTSTATE_Invisible); +} + +void CFWL_Caret::HideCaret() { + if (m_pTimerInfo) { + m_pTimerInfo->StopTimer(); + m_pTimerInfo = nullptr; + } + SetStates(FWL_WGTSTATE_Invisible); +} + +void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) + return; + + CFX_RectF rect = GetWidgetRect(); + rect.Set(0, 0, rect.width, rect.height); + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_pGraphics = pGraphics; + param.m_rtPart = rect; + param.m_iPart = CFWL_Part::Background; + param.m_dwStates = CFWL_PartState_HightLight; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶m); +} + +void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} + +void CFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +CFWL_Caret::Timer::Timer(CFWL_Caret* pCaret) : CFWL_Timer(pCaret) {} + +void CFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) { + CFWL_Caret* pCaret = static_cast(m_pWidget); + if (!(pCaret->GetStates() & FWL_STATE_CAT_HightLight)) + pCaret->SetStates(FWL_STATE_CAT_HightLight); + else + pCaret->RemoveStates(FWL_STATE_CAT_HightLight); + + CFX_RectF rt = pCaret->GetWidgetRect(); + rt.Set(0, 0, rt.width + 1, rt.height); + pCaret->Repaint(&rt); +} diff --git a/xfa/fwl/cfwl_caret.h b/xfa/fwl/cfwl_caret.h new file mode 100644 index 0000000000..e0c07d301a --- /dev/null +++ b/xfa/fwl/cfwl_caret.h @@ -0,0 +1,57 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_CARET_H_ +#define XFA_FWL_CFWL_CARET_H_ + +#include + +#include "xfa/fwl/cfwl_timer.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxgraphics/cfx_color.h" + +class CFWL_WidgetProperties; +class CFWL_Widget; + +#define FWL_STATE_CAT_HightLight 1 + +class CFWL_Caret : public CFWL_Widget { + public: + CFWL_Caret(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_Caret() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + void Update() override; + + void ShowCaret(); + void HideCaret(); + + private: + class Timer : public CFWL_Timer { + public: + explicit Timer(CFWL_Caret* pCaret); + ~Timer() override {} + + void Run(CFWL_TimerInfo* hTimer) override; + }; + friend class CFWL_Caret::Timer; + + void DrawCaretBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + + std::unique_ptr m_pTimer; + CFWL_TimerInfo* m_pTimerInfo; // not owned. +}; + +#endif // XFA_FWL_CFWL_CARET_H_ diff --git a/xfa/fwl/cfwl_checkbox.cpp b/xfa/fwl/cfwl_checkbox.cpp new file mode 100644 index 0000000000..2e37548954 --- /dev/null +++ b/xfa/fwl/cfwl_checkbox.cpp @@ -0,0 +1,458 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_checkbox.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +namespace { + +const int kCaptionMargin = 5; + +} // namespace + +CFWL_CheckBox::CFWL_CheckBox(const CFWL_App* app) + : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), + m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), + m_iTTOAlign(FDE_TTOALIGNMENT_Center), + m_bBtnDown(false), + m_fBoxHeight(16.0f) { + m_rtClient.Reset(); + m_rtBox.Reset(); + m_rtCaption.Reset(); + m_rtFocus.Reset(); +} + +CFWL_CheckBox::~CFWL_CheckBox() {} + +FWL_Type CFWL_CheckBox::GetClassID() const { + return FWL_Type::CheckBox; +} + +void CFWL_CheckBox::SetBoxSize(FX_FLOAT fHeight) { + m_fBoxHeight = fHeight; +} + +void CFWL_CheckBox::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + UpdateTextOutStyles(); + Layout(); +} + +void CFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) { + DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, + pMatrix); + } + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + int32_t dwStates = GetPartStates(); + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_dwStates = dwStates; + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtClient; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + param.m_pData = &m_rtFocus; + pTheme->DrawBackground(¶m); + + param.m_iPart = CFWL_Part::CheckBox; + param.m_rtPart = m_rtBox; + pTheme->DrawBackground(¶m); + + CFWL_ThemeText textParam; + textParam.m_pWidget = this; + textParam.m_iPart = CFWL_Part::Caption; + textParam.m_dwStates = dwStates; + textParam.m_pGraphics = pGraphics; + if (pMatrix) + textParam.m_matrix.Concat(*pMatrix); + textParam.m_rtPart = m_rtCaption; + textParam.m_wsText = L"Check box"; + textParam.m_dwTTOStyles = m_dwTTOStyles; + textParam.m_iTTOAlign = m_iTTOAlign; + pTheme->DrawText(&textParam); +} + +void CFWL_CheckBox::SetCheckState(int32_t iCheck) { + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; + switch (iCheck) { + case 1: + m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; + break; + case 2: + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) + m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; + break; + default: + break; + } + Repaint(&m_rtClient); +} + +void CFWL_CheckBox::Layout() { + m_pProperties->m_rtWidget.width = + FXSYS_round(m_pProperties->m_rtWidget.width); + m_pProperties->m_rtWidget.height = + FXSYS_round(m_pProperties->m_rtWidget.height); + GetClientRect(m_rtClient); + + FX_FLOAT fBoxTop = m_rtClient.top; + FX_FLOAT fClientBottom = m_rtClient.bottom(); + + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { + case FWL_STYLEEXT_CKB_Top: + break; + case FWL_STYLEEXT_CKB_Bottom: { + fBoxTop = fClientBottom - m_fBoxHeight; + break; + } + case FWL_STYLEEXT_CKB_VCenter: + default: { + fBoxTop = m_rtClient.top + (m_rtClient.height - m_fBoxHeight) / 2; + fBoxTop = FXSYS_floor(fBoxTop); + break; + } + } + + FX_FLOAT fBoxLeft = m_rtClient.left; + FX_FLOAT fTextLeft = 0.0; + FX_FLOAT fTextRight = 0.0; + FX_FLOAT fClientRight = m_rtClient.right(); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { + fBoxLeft = fClientRight - m_fBoxHeight; + fTextLeft = m_rtClient.left; + fTextRight = fBoxLeft; + } else { + fTextLeft = fBoxLeft + m_fBoxHeight; + fTextRight = fClientRight; + } + m_rtBox.Set(fBoxLeft, fBoxTop, m_fBoxHeight, m_fBoxHeight); + m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, + m_rtClient.height); + m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); + + CFX_RectF rtFocus; + rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, + m_rtCaption.height); + + CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider, m_dwTTOStyles, + m_iTTOAlign, rtFocus); + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { + FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); + FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); + FX_FLOAT fLeft = m_rtCaption.left; + FX_FLOAT fTop = m_rtCaption.top; + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == + FWL_STYLEEXT_CKB_Center) { + fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == + FWL_STYLEEXT_CKB_Right) { + fLeft = m_rtCaption.right() - fWidth; + } + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == + FWL_STYLEEXT_CKB_VCenter) { + fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == + FWL_STYLEEXT_CKB_Bottom) { + fTop = m_rtCaption.bottom() - fHeight; + } + m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); + } else { + m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); + } + m_rtFocus.Inflate(1, 1); +} + +uint32_t CFWL_CheckBox::GetPartStates() const { + int32_t dwStates = CFWL_PartState_Normal; + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == + FWL_STATE_CKB_Neutral) { + dwStates = CFWL_PartState_Neutral; + } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == + FWL_STATE_CKB_Checked) { + dwStates = CFWL_PartState_Checked; + } + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + dwStates |= CFWL_PartState_Disabled; + else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) + dwStates |= CFWL_PartState_Hovered; + else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) + dwStates |= CFWL_PartState_Pressed; + else + dwStates |= CFWL_PartState_Normal; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + dwStates |= CFWL_PartState_Focused; + return dwStates; +} + +void CFWL_CheckBox::UpdateTextOutStyles() { + switch (m_pProperties->m_dwStyleExes & + (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) { + case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: { + m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; + break; + } + case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Top: { + m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; + break; + } + case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Top: { + m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; + break; + } + case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_VCenter: { + m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + break; + } + case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: { + m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; + break; + } + case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Bottom: { + m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; + break; + } + case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Bottom: { + m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; + break; + } + case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Bottom: { + m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; + break; + } + case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: + default: { + m_iTTOAlign = FDE_TTOALIGNMENT_Center; + break; + } + } + m_dwTTOStyles = 0; + if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) + m_dwTTOStyles |= FDE_TTOSTYLE_RTL; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) + m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap; + else + m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; +} + +void CFWL_CheckBox::NextStates() { + uint32_t dwFirststate = m_pProperties->m_dwStates; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) { + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == + FWL_STATE_CKB_Unchecked) { + CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr->IsFormDisabled()) { + CFX_ArrayTemplate radioarr; + pWidgetMgr->GetSameGroupRadioButton(this, radioarr); + CFWL_CheckBox* pCheckBox = nullptr; + int32_t iCount = radioarr.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + pCheckBox = static_cast(radioarr[i]); + if (pCheckBox != this && + pCheckBox->GetStates() & FWL_STATE_CKB_Checked) { + pCheckBox->SetCheckState(0); + CFX_RectF rt = pCheckBox->GetWidgetRect(); + rt.left = rt.top = 0; + m_pWidgetMgr->RepaintWidget(pCheckBox, &rt); + break; + } + } + } + m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; + } + } else { + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == + FWL_STATE_CKB_Neutral) { + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) + m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; + } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == + FWL_STATE_CKB_Checked) { + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; + } else { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) + m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; + else + m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; + } + } + + Repaint(&m_rtClient); + if (dwFirststate == m_pProperties->m_dwStates) + return; + + CFWL_Event wmCheckBoxState(CFWL_Event::Type::CheckStateChanged, this); + DispatchEvent(&wmCheckBoxState); +} + +void CFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + OnFocusChanged(true); + break; + case CFWL_Message::Type::KillFocus: + OnFocusChanged(false); + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: { + CFWL_MessageKey* pKey = static_cast(pMessage); + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) + OnKeyDown(pKey); + break; + } + default: + break; + } + + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_CheckBox::OnFocusChanged(bool bSet) { + if (bSet) + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + else + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + + Repaint(&m_rtClient); +} + +void CFWL_CheckBox::OnLButtonDown() { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + return; + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + SetFocus(true); + + m_bBtnDown = true; + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; + m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; + Repaint(&m_rtClient); +} + +void CFWL_CheckBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { + if (!m_bBtnDown) + return; + + m_bBtnDown = false; + if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; + NextStates(); +} + +void CFWL_CheckBox::OnMouseMove(CFWL_MessageMouse* pMsg) { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + return; + + bool bRepaint = false; + if (m_bBtnDown) { + if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { + bRepaint = true; + m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; + } + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { + bRepaint = true; + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; + } + } else { + if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { + bRepaint = true; + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; + } + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { + bRepaint = true; + m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; + } + } + } else { + if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { + if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { + bRepaint = true; + m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; + } + } + } + if (bRepaint) + Repaint(&m_rtBox); +} + +void CFWL_CheckBox::OnMouseLeave() { + if (m_bBtnDown) + m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; + else + m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; + + Repaint(&m_rtBox); +} + +void CFWL_CheckBox::OnKeyDown(CFWL_MessageKey* pMsg) { + if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) + return; + if (pMsg->m_dwKeyCode == FWL_VKEY_Return || + pMsg->m_dwKeyCode == FWL_VKEY_Space) { + NextStates(); + } +} diff --git a/xfa/fwl/cfwl_checkbox.h b/xfa/fwl/cfwl_checkbox.h new file mode 100644 index 0000000000..d228eee057 --- /dev/null +++ b/xfa/fwl/cfwl_checkbox.h @@ -0,0 +1,90 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_CHECKBOX_H_ +#define XFA_FWL_CFWL_CHECKBOX_H_ + +#include + +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_STYLEEXT_CKB_Left (0L << 0) +#define FWL_STYLEEXT_CKB_Center (1L << 0) +#define FWL_STYLEEXT_CKB_Right (2L << 0) +#define FWL_STYLEEXT_CKB_Top (0L << 2) +#define FWL_STYLEEXT_CKB_VCenter (1L << 2) +#define FWL_STYLEEXT_CKB_Bottom (2L << 2) +#define FWL_STYLEEXT_CKB_LeftText (1L << 4) +#define FWL_STYLEEXT_CKB_MultiLine (1L << 5) +#define FWL_STYLEEXT_CKB_3State (1L << 6) +#define FWL_STYLEEXT_CKB_RadioButton (1L << 7) +#define FWL_STYLEEXT_CKB_ShapeSolidSquare (0L << 8) +#define FWL_STYLEEXT_CKB_ShapeSunkenSquare (1L << 8) +#define FWL_STYLEEXT_CKB_ShapeSolidCircle (2L << 8) +#define FWL_STYLEEXT_CKB_ShapeSunkenCircle (3L << 8) +#define FWL_STYLEEXT_CKB_SignShapeCheck (0L << 10) +#define FWL_STYLEEXT_CKB_SignShapeCircle (1L << 10) +#define FWL_STYLEEXT_CKB_SignShapeCross (2L << 10) +#define FWL_STYLEEXT_CKB_SignShapeDiamond (3L << 10) +#define FWL_STYLEEXT_CKB_SignShapeSquare (4L << 10) +#define FWL_STYLEEXT_CKB_SignShapeStar (5L << 10) +#define FWL_STYLEEXT_CKB_HLayoutMask (3L << 0) +#define FWL_STYLEEXT_CKB_VLayoutMask (3L << 2) +#define FWL_STYLEEXT_CKB_ShapeMask (3L << 8) +#define FWL_STYLEEXT_CKB_SignShapeMask (7L << 10) +#define FWL_STATE_CKB_Hovered (1 << FWL_WGTSTATE_MAX) +#define FWL_STATE_CKB_Pressed (1 << (FWL_WGTSTATE_MAX + 1)) +#define FWL_STATE_CKB_Unchecked (0 << (FWL_WGTSTATE_MAX + 2)) +#define FWL_STATE_CKB_Checked (1 << (FWL_WGTSTATE_MAX + 2)) +#define FWL_STATE_CKB_Neutral (2 << (FWL_WGTSTATE_MAX + 2)) +#define FWL_STATE_CKB_CheckMask (3L << (FWL_WGTSTATE_MAX + 2)) + +class CFWL_MessageMouse; +class CFWL_WidgetProperties; +class CFWL_Widget; + +class CFWL_CheckBox : public CFWL_Widget { + public: + explicit CFWL_CheckBox(const CFWL_App* pApp); + ~CFWL_CheckBox() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void SetBoxSize(FX_FLOAT fHeight); + + private: + void SetCheckState(int32_t iCheck); + void Layout(); + uint32_t GetPartStates() const; + void UpdateTextOutStyles(); + void NextStates(); + void OnFocusChanged(bool bSet); + void OnLButtonDown(); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(); + void OnKeyDown(CFWL_MessageKey* pMsg); + + CFX_RectF m_rtClient; + CFX_RectF m_rtBox; + CFX_RectF m_rtCaption; + CFX_RectF m_rtFocus; + uint32_t m_dwTTOStyles; + int32_t m_iTTOAlign; + bool m_bBtnDown; + FX_FLOAT m_fBoxHeight; +}; + +#endif // XFA_FWL_CFWL_CHECKBOX_H_ diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp new file mode 100644 index 0000000000..90366979f4 --- /dev/null +++ b/xfa/fwl/cfwl_combobox.cpp @@ -0,0 +1,1078 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_combobox.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/cfde_txtedtengine.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_eventtextchanged.h" +#include "xfa/fwl/cfwl_formproxy.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app) + : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), + m_pComboBoxProxy(nullptr), + m_bLButtonDown(false), + m_iCurSel(-1), + m_iBtnState(CFWL_PartState_Normal), + m_fComboFormHandler(0) { + m_rtClient.Reset(); + m_rtBtn.Reset(); + m_rtHandler.Reset(); + + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_InitComboList(); + DisForm_InitComboEdit(); + return; + } + + auto prop = pdfium::MakeUnique(); + prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; + prop->m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) + prop->m_dwStyleExes |= FWL_STYLEEXT_LTB_Icon; + m_pListBox = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); + + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { + m_pEdit.reset(new CFWL_ComboEdit( + m_pOwnerApp, pdfium::MakeUnique(), this)); + m_pEdit->SetOuter(this); + } + if (m_pEdit) + m_pEdit->SetParent(this); + + SetStates(m_pProperties->m_dwStates); +} + +CFWL_ComboBox::~CFWL_ComboBox() {} + +FWL_Type CFWL_ComboBox::GetClassID() const { + return FWL_Type::ComboBox; +} + +void CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { + m_pListBox->AddString(wsText); +} + +bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { + return m_pListBox->RemoveAt(iIndex); +} + +void CFWL_ComboBox::RemoveAll() { + m_pListBox->DeleteAll(); +} + +void CFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved) { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); + return; + } + + bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); + bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); + if (bAddDropDown && !m_pEdit) { + m_pEdit = pdfium::MakeUnique( + m_pOwnerApp, pdfium::MakeUnique(), nullptr); + m_pEdit->SetOuter(this); + m_pEdit->SetParent(this); + } else if (bRemoveDropDown && m_pEdit) { + m_pEdit->SetStates(FWL_WGTSTATE_Invisible); + } + CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); +} + +void CFWL_ComboBox::Update() { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_Update(); + return; + } + if (IsLocked()) + return; + + ResetTheme(); + if (IsDropDownStyle() && m_pEdit) + ResetEditAlignment(); + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + Layout(); + CFWL_ThemePart part; + part.m_pWidget = this; + m_fComboFormHandler = + *static_cast(m_pProperties->m_pThemeProvider->GetCapacity( + &part, CFWL_WidgetCapacity::ComboFormHandler)); +} + +FWL_WidgetHit CFWL_ComboBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_HitTest(fx, fy); + return CFWL_Widget::HitTest(fx, fy); +} + +void CFWL_ComboBox::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_DrawWidget(pGraphics, pMatrix); + return; + } + + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + if (!IsDropDownStyle()) { + CFX_RectF rtTextBk(m_rtClient); + rtTextBk.width -= m_rtBtn.width; + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = rtTextBk; + + if (m_iCurSel >= 0) { + if (void* p = m_pListBox->GetItemData( + m_pListBox.get(), + m_pListBox->GetItem(m_pListBox.get(), m_iCurSel))) { + param.m_pData = p; + } + } + + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { + param.m_dwStates = CFWL_PartState_Disabled; + } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && + (m_iCurSel >= 0)) { + param.m_dwStates = CFWL_PartState_Selected; + } else { + param.m_dwStates = CFWL_PartState_Normal; + } + pTheme->DrawBackground(¶m); + + if (m_iCurSel >= 0) { + if (!m_pListBox) + return; + + CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); + CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); + + CFWL_ThemeText theme_text; + theme_text.m_pWidget = this; + theme_text.m_iPart = CFWL_Part::Caption; + theme_text.m_dwStates = m_iBtnState; + theme_text.m_pGraphics = pGraphics; + theme_text.m_matrix.Concat(*pMatrix); + theme_text.m_rtPart = rtTextBk; + theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + ? CFWL_PartState_Selected + : CFWL_PartState_Normal; + theme_text.m_wsText = wsText; + theme_text.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + theme_text.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + pTheme->DrawText(&theme_text); + } + } + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::DropDownButton; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : m_iBtnState; + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtBtn; + pTheme->DrawBackground(¶m); +} + +void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { + if (!pThemeProvider) + return; + + m_pProperties->m_pThemeProvider = pThemeProvider; + if (m_pListBox) + m_pListBox->SetThemeProvider(pThemeProvider); + if (m_pEdit) + m_pEdit->SetThemeProvider(pThemeProvider); +} + +CFX_WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const { + CFWL_ListItem* pItem = static_cast( + m_pListBox->GetItem(m_pListBox.get(), iIndex)); + return pItem ? pItem->m_wsText : L""; +} + +void CFWL_ComboBox::SetCurSel(int32_t iSel) { + int32_t iCount = m_pListBox->CountItems(nullptr); + bool bClearSel = iSel < 0 || iSel >= iCount; + if (IsDropDownStyle() && m_pEdit) { + if (bClearSel) { + m_pEdit->SetText(CFX_WideString()); + } else { + CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel); + CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); + m_pEdit->SetText(wsText); + } + m_pEdit->Update(); + } + m_iCurSel = bClearSel ? -1 : iSel; +} + +void CFWL_ComboBox::SetStates(uint32_t dwStates) { + if (IsDropDownStyle() && m_pEdit) + m_pEdit->SetStates(dwStates); + if (m_pListBox) + m_pListBox->SetStates(dwStates); + CFWL_Widget::SetStates(dwStates); +} + +void CFWL_ComboBox::RemoveStates(uint32_t dwStates) { + if (IsDropDownStyle() && m_pEdit) + m_pEdit->RemoveStates(dwStates); + if (m_pListBox) + m_pListBox->RemoveStates(dwStates); + CFWL_Widget::RemoveStates(dwStates); +} + +void CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { + if (!m_pEdit) + return; + + m_pEdit->SetText(wsText); + m_pEdit->Update(); +} + +CFX_WideString CFWL_ComboBox::GetEditText() const { + if (m_pEdit) + return m_pEdit->GetText(); + if (!m_pListBox) + return L""; + + CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); + return m_pListBox->GetDataProviderItemText(hItem); +} + +void CFWL_ComboBox::OpenDropDownList(bool bActivate) { + ShowDropList(bActivate); +} + +CFX_RectF CFWL_ComboBox::GetBBox() const { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_GetBBox(); + + CFX_RectF rect = m_pProperties->m_rtWidget; + if (!m_pListBox || !IsDropListVisible()) + return rect; + + CFX_RectF rtList = m_pListBox->GetWidgetRect(); + rtList.Offset(rect.left, rect.top); + rect.Union(rtList); + return rect; +} + +void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved) { + if (m_pEdit) + m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); +} + +void CFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pGraphics = pGraphics; + param.m_iPart = CFWL_Part::StretchHandler; + param.m_dwStates = CFWL_PartState_Normal; + param.m_pWidget = this; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtHandler; + m_pProperties->m_pThemeProvider->DrawBackground(¶m); +} + +void CFWL_ComboBox::ShowDropList(bool bActivate) { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_ShowDropList(bActivate); + if (IsDropListVisible() == bActivate) + return; + if (!m_pComboBoxProxy) + InitProxyForm(); + + m_pComboBoxProxy->Reset(); + if (!bActivate) { + m_pComboBoxProxy->EndDoModal(); + + m_bLButtonDown = false; + m_pListBox->SetNotifyOwner(true); + SetFocus(true); + return; + } + + m_pListBox->ChangeSelected(m_iCurSel); + ResetListItemAlignment(); + + uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & + (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); + m_pListBox->ModifyStylesEx(dwStyleAdd, 0); + m_rtList = m_pListBox->GetAutosizedWidgetRect(); + + CFX_RectF rtAnchor; + rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + + m_rtList.width = std::max(m_rtList.width, m_rtClient.width); + m_rtProxy = m_rtList; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) + m_rtProxy.height += m_fComboFormHandler; + + GetPopupPos(0, m_rtProxy.height, rtAnchor, m_rtProxy); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { + FX_FLOAT fx = 0; + FX_FLOAT fy = m_rtClient.top + m_rtClient.height / 2; + TransformTo(nullptr, fx, fy); + + m_bUpFormHandler = fy > m_rtProxy.top; + if (m_bUpFormHandler) { + m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); + m_rtList.top = m_fComboFormHandler; + } else { + m_rtHandler.Set(0, m_rtList.height, m_rtList.width, m_fComboFormHandler); + } + } + m_pComboBoxProxy->SetWidgetRect(m_rtProxy); + m_pComboBoxProxy->Update(); + m_pListBox->SetWidgetRect(m_rtList); + m_pListBox->Update(); + + CFWL_Event ev(CFWL_Event::Type::PreDropDown, this); + DispatchEvent(&ev); + + m_fItemHeight = m_pListBox->GetItemHeight(); + m_pListBox->SetFocus(true); + m_pComboBoxProxy->DoModal(); + m_pListBox->SetFocus(false); +} + +void CFWL_ComboBox::MatchEditText() { + CFX_WideString wsText = m_pEdit->GetText(); + int32_t iMatch = m_pListBox->MatchItem(wsText); + if (iMatch != m_iCurSel) { + m_pListBox->ChangeSelected(iMatch); + if (iMatch >= 0) + SyncEditText(iMatch); + } else if (iMatch >= 0) { + m_pEdit->SetSelected(); + } + m_iCurSel = iMatch; +} + +void CFWL_ComboBox::SyncEditText(int32_t iListItem) { + CFWL_ListItem* hItem = m_pListBox->GetItem(this, iListItem); + CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); + m_pEdit->SetText(wsText); + m_pEdit->Update(); + m_pEdit->SetSelected(); +} + +void CFWL_ComboBox::Layout() { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_Layout(); + + GetClientRect(m_rtClient); + FX_FLOAT* pFWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pFWidth) + return; + + FX_FLOAT fBtn = *pFWidth; + m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, + m_rtClient.height); + if (!IsDropDownStyle() || !m_pEdit) + return; + + CFX_RectF rtEdit; + rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, + m_rtClient.height); + m_pEdit->SetWidgetRect(rtEdit); + + if (m_iCurSel >= 0) { + CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); + CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); + m_pEdit->LockUpdate(); + m_pEdit->SetText(wsText); + m_pEdit->UnlockUpdate(); + } + m_pEdit->Update(); +} + +void CFWL_ComboBox::ResetTheme() { + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (!pTheme) { + pTheme = GetAvailableTheme(); + m_pProperties->m_pThemeProvider = pTheme; + } + if (m_pListBox && !m_pListBox->GetThemeProvider()) + m_pListBox->SetThemeProvider(pTheme); + if (m_pEdit && !m_pEdit->GetThemeProvider()) + m_pEdit->SetThemeProvider(pTheme); +} + +void CFWL_ComboBox::ResetEditAlignment() { + if (!m_pEdit) + return; + + uint32_t dwAdd = 0; + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditHAlignMask) { + case FWL_STYLEEXT_CMB_EditHCenter: { + dwAdd |= FWL_STYLEEXT_EDT_HCenter; + break; + } + case FWL_STYLEEXT_CMB_EditHFar: { + dwAdd |= FWL_STYLEEXT_EDT_HFar; + break; + } + default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } + } + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditVAlignMask) { + case FWL_STYLEEXT_CMB_EditVCenter: { + dwAdd |= FWL_STYLEEXT_EDT_VCenter; + break; + } + case FWL_STYLEEXT_CMB_EditVFar: { + dwAdd |= FWL_STYLEEXT_EDT_VFar; + break; + } + default: { + dwAdd |= FWL_STYLEEXT_EDT_VNear; + break; + } + } + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditJustified) + dwAdd |= FWL_STYLEEXT_EDT_Justified; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditDistributed) + dwAdd |= FWL_STYLEEXT_EDT_Distributed; + + m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | + FWL_STYLEEXT_EDT_HAlignModeMask | + FWL_STYLEEXT_EDT_VAlignMask); +} + +void CFWL_ComboBox::ResetListItemAlignment() { + if (!m_pListBox) + return; + + uint32_t dwAdd = 0; + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemAlignMask) { + case FWL_STYLEEXT_CMB_ListItemCenterAlign: { + dwAdd |= FWL_STYLEEXT_LTB_CenterAlign; + break; + } + case FWL_STYLEEXT_CMB_ListItemRightAlign: { + dwAdd |= FWL_STYLEEXT_LTB_RightAlign; + break; + } + default: { + dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; + break; + } + } + m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); +} + +void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { + m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0)); + if (!IsDropDownStyle()) { + Repaint(&m_rtClient); + return; + } + + CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); + if (!hItem) + return; + + CFX_WideString wsText = m_pListBox->GetItemText(this, hItem); + if (m_pEdit) { + m_pEdit->SetText(wsText); + m_pEdit->Update(); + m_pEdit->SetSelected(); + } + + CFWL_EventSelectChanged ev(this); + ev.bLButtonUp = bLButtonUp; + DispatchEvent(&ev); +} + +void CFWL_ComboBox::InitProxyForm() { + if (m_pComboBoxProxy) + return; + if (!m_pListBox) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_pOwner = this; + prop->m_dwStyles = FWL_WGTSTYLE_Popup; + prop->m_dwStates = FWL_WGTSTATE_Invisible; + + // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure + // if the SetParent call is going to transfer ownership. + m_pComboBoxProxy = new CFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), + m_pListBox.get()); + m_pListBox->SetParent(m_pComboBoxProxy); +} + +void CFWL_ComboBox::DisForm_InitComboList() { + if (m_pListBox) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_pParent = this; + prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; + prop->m_dwStates = FWL_WGTSTATE_Invisible; + prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; + m_pListBox = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); +} + +void CFWL_ComboBox::DisForm_InitComboEdit() { + if (m_pEdit) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_pParent = this; + prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; + + m_pEdit = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); + m_pEdit->SetOuter(this); +} + +void CFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { + if (DisForm_IsDropListVisible() == bActivate) + return; + + if (bActivate) { + CFWL_Event preEvent(CFWL_Event::Type::PreDropDown, this); + DispatchEvent(&preEvent); + + CFWL_ComboList* pComboList = m_pListBox.get(); + int32_t iItems = pComboList->CountItems(nullptr); + if (iItems < 1) + return; + + ResetListItemAlignment(); + pComboList->ChangeSelected(m_iCurSel); + + FX_FLOAT fItemHeight = pComboList->CalcItemHeight(); + FX_FLOAT fBorder = GetBorderSize(true); + FX_FLOAT fPopupMin = 0.0f; + if (iItems > 3) + fPopupMin = fItemHeight * 3 + fBorder * 2; + + FX_FLOAT fPopupMax = fItemHeight * iItems + fBorder * 2; + CFX_RectF rtList; + rtList.left = m_rtClient.left; + rtList.width = m_pProperties->m_rtWidget.width; + rtList.top = 0; + rtList.height = 0; + GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); + + m_pListBox->SetWidgetRect(rtList); + m_pListBox->Update(); + } else { + SetFocus(true); + } + + if (bActivate) { + m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); + CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); + DispatchEvent(&postEvent); + } else { + m_pListBox->SetStates(FWL_WGTSTATE_Invisible); + } + + CFX_RectF rect = m_pListBox->GetWidgetRect(); + rect.Inflate(2, 2); + Repaint(&rect); +} + +void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved) { + if (!m_pEdit) + DisForm_InitComboEdit(); + + bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); + bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); + + dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown; + m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown; + + if (bAddDropDown) + m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly); + else if (bDelDropDown) + m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0); + CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); +} + +void CFWL_ComboBox::DisForm_Update() { + if (m_iLock) + return; + if (m_pEdit) + ResetEditAlignment(); + ResetTheme(); + Layout(); +} + +FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { + CFX_RectF rect; + rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, + m_pProperties->m_rtWidget.height); + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::Edit; + if (m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::Client; + if (DisForm_IsDropListVisible()) { + rect = m_pListBox->GetWidgetRect(); + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::Client; + } + return FWL_WidgetHit::Unknown; +} + +void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + CFX_Matrix mtOrg; + mtOrg.Set(1, 0, 0, 1, 0, 0); + if (pMatrix) + mtOrg = *pMatrix; + + pGraphics->SaveGraphState(); + pGraphics->ConcatMatrix(&mtOrg); + if (!m_rtBtn.IsEmpty(0.1f)) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::DropDownButton; + param.m_dwStates = m_iBtnState; + param.m_pGraphics = pGraphics; + param.m_rtPart = m_rtBtn; + pTheme->DrawBackground(¶m); + } + pGraphics->RestoreGraphState(); + + if (m_pEdit) { + CFX_RectF rtEdit = m_pEdit->GetWidgetRect(); + CFX_Matrix mt; + mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); + mt.Concat(mtOrg); + m_pEdit->DrawWidget(pGraphics, &mt); + } + if (m_pListBox && DisForm_IsDropListVisible()) { + CFX_RectF rtList = m_pListBox->GetWidgetRect(); + CFX_Matrix mt; + mt.Set(1, 0, 0, 1, rtList.left, rtList.top); + mt.Concat(mtOrg); + m_pListBox->DrawWidget(pGraphics, &mt); + } +} + +CFX_RectF CFWL_ComboBox::DisForm_GetBBox() const { + CFX_RectF rect = m_pProperties->m_rtWidget; + if (!m_pListBox || !DisForm_IsDropListVisible()) + return rect; + + CFX_RectF rtList = m_pListBox->GetWidgetRect(); + rtList.Offset(rect.left, rect.top); + rect.Union(rtList); + return rect; +} + +void CFWL_ComboBox::DisForm_Layout() { + GetClientRect(m_rtClient); + m_rtContent = m_rtClient; + FX_FLOAT* pFWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pFWidth) + return; + + FX_FLOAT borderWidth = 1; + FX_FLOAT fBtn = *pFWidth; + if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { + m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, + fBtn - borderWidth, m_rtClient.height - 2 * borderWidth); + } + + CFX_RectF* pUIMargin = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); + if (pUIMargin) { + m_rtContent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, + pUIMargin->height); + } + + if (!IsDropDownStyle() || !m_pEdit) + return; + + CFX_RectF rtEdit; + rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, + m_rtContent.height); + m_pEdit->SetWidgetRect(rtEdit); + + if (m_iCurSel >= 0) { + CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); + CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); + m_pEdit->LockUpdate(); + m_pEdit->SetText(wsText); + m_pEdit->UnlockUpdate(); + } + m_pEdit->Update(); +} + +void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_OnProcessMessage(pMessage); + return; + } + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + OnFocusChanged(pMessage, true); + break; + case CFWL_Message::Type::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: + OnKey(static_cast(pMessage)); + break; + default: + break; + } + + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) { + CFWL_Event::Type type = pEvent->GetType(); + if (type == CFWL_Event::Type::Scroll) { + CFWL_EventScroll* pScrollEvent = static_cast(pEvent); + CFWL_EventScroll pScrollEv(this); + pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode; + pScrollEv.m_fPos = pScrollEvent->m_fPos; + DispatchEvent(&pScrollEv); + } else if (type == CFWL_Event::Type::TextChanged) { + CFWL_Event pTemp(CFWL_Event::Type::EditChanged, this); + DispatchEvent(&pTemp); + } +} + +void CFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + if (IsDropDownStyle() && pMsg->m_pSrcTarget != m_pListBox.get()) { + if (!m_pEdit) + return; + m_pEdit->SetSelected(); + return; + } + + Repaint(&m_rtClient); + return; + } + + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + if (!IsDropDownStyle() || pMsg->m_pDstTarget == m_pListBox.get()) { + Repaint(&m_rtClient); + return; + } + if (!m_pEdit) + return; + + m_pEdit->FlagFocus(false); + m_pEdit->ClearSelected(); +} + +void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + return; + + CFX_RectF& rtBtn = IsDropDownStyle() ? m_rtBtn : m_rtClient; + if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + if (IsDropDownStyle() && m_pEdit) + MatchEditText(); + + m_bLButtonDown = true; + m_iBtnState = CFWL_PartState_Pressed; + Repaint(&m_rtClient); + + ShowDropList(true); + m_iBtnState = CFWL_PartState_Normal; + Repaint(&m_rtClient); +} + +void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { + m_bLButtonDown = false; + if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) + m_iBtnState = CFWL_PartState_Hovered; + else + m_iBtnState = CFWL_PartState_Normal; + + Repaint(&m_rtBtn); +} + +void CFWL_ComboBox::OnMouseMove(CFWL_MessageMouse* pMsg) { + int32_t iOldState = m_iBtnState; + if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iBtnState = + m_bLButtonDown ? CFWL_PartState_Pressed : CFWL_PartState_Hovered; + } else { + m_iBtnState = CFWL_PartState_Normal; + } + if ((iOldState != m_iBtnState) && + !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == + FWL_WGTSTATE_Disabled)) { + Repaint(&m_rtBtn); + } +} + +void CFWL_ComboBox::OnMouseLeave(CFWL_MessageMouse* pMsg) { + if (!IsDropListVisible() && + !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == + FWL_WGTSTATE_Disabled)) { + m_iBtnState = CFWL_PartState_Normal; + Repaint(&m_rtBtn); + } +} + +void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) { + uint32_t dwKeyCode = pMsg->m_dwKeyCode; + if (dwKeyCode == FWL_VKEY_Tab) + return; + if (pMsg->m_pDstTarget == this) + DoSubCtrlKey(pMsg); +} + +void CFWL_ComboBox::DoSubCtrlKey(CFWL_MessageKey* pMsg) { + uint32_t dwKeyCode = pMsg->m_dwKeyCode; + const bool bUp = dwKeyCode == FWL_VKEY_Up; + const bool bDown = dwKeyCode == FWL_VKEY_Down; + if (bUp || bDown) { + int32_t iCount = m_pListBox->CountItems(nullptr); + if (iCount < 1) + return; + + bool bMatchEqual = false; + int32_t iCurSel = m_iCurSel; + bool bDropDown = IsDropDownStyle(); + if (bDropDown && m_pEdit) { + CFX_WideString wsText = m_pEdit->GetText(); + iCurSel = m_pListBox->MatchItem(wsText); + if (iCurSel >= 0) { + CFWL_ListItem* hItem = m_pListBox->GetItem(this, iCurSel); + CFX_WideString wsTemp = m_pListBox->GetDataProviderItemText(hItem); + bMatchEqual = wsText == wsTemp; + } + } + if (iCurSel < 0) { + iCurSel = 0; + } else if (!bDropDown || bMatchEqual) { + if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) + return; + if (bUp) + iCurSel--; + else + iCurSel++; + } + m_iCurSel = iCurSel; + if (bDropDown && m_pEdit) + SyncEditText(m_iCurSel); + else + Repaint(&m_rtClient); + return; + } + + if (IsDropDownStyle()) + m_pEdit->GetDelegate()->OnProcessMessage(pMsg); +} + +void CFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + bool backDefault = true; + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: { + backDefault = false; + DisForm_OnFocusChanged(pMessage, true); + break; + } + case CFWL_Message::Type::KillFocus: { + backDefault = false; + DisForm_OnFocusChanged(pMessage, false); + break; + } + case CFWL_Message::Type::Mouse: { + backDefault = false; + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + DisForm_OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: { + backDefault = false; + CFWL_MessageKey* pKey = static_cast(pMessage); + if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp) + break; + if (DisForm_IsDropListVisible() && + pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { + bool bListKey = pKey->m_dwKeyCode == FWL_VKEY_Up || + pKey->m_dwKeyCode == FWL_VKEY_Down || + pKey->m_dwKeyCode == FWL_VKEY_Return || + pKey->m_dwKeyCode == FWL_VKEY_Escape; + if (bListKey) { + m_pListBox->GetDelegate()->OnProcessMessage(pMessage); + break; + } + } + DisForm_OnKey(pKey); + break; + } + default: + break; + } + if (backDefault) + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_ComboBox::DisForm_OnLButtonDown(CFWL_MessageMouse* pMsg) { + bool bDropDown = DisForm_IsDropListVisible(); + CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient; + if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + if (DisForm_IsDropListVisible()) { + DisForm_ShowDropList(false); + return; + } + if (m_pEdit) + MatchEditText(); + DisForm_ShowDropList(true); +} + +void CFWL_ComboBox::DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + if ((m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) { + CFWL_MessageSetFocus msg(nullptr, m_pEdit.get()); + m_pEdit->GetDelegate()->OnProcessMessage(&msg); + } + } else { + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + DisForm_ShowDropList(false); + CFWL_MessageKillFocus msg(m_pEdit.get()); + m_pEdit->GetDelegate()->OnProcessMessage(&msg); + } +} + +void CFWL_ComboBox::DisForm_OnKey(CFWL_MessageKey* pMsg) { + uint32_t dwKeyCode = pMsg->m_dwKeyCode; + const bool bUp = dwKeyCode == FWL_VKEY_Up; + const bool bDown = dwKeyCode == FWL_VKEY_Down; + if (bUp || bDown) { + CFWL_ComboList* pComboList = m_pListBox.get(); + int32_t iCount = pComboList->CountItems(nullptr); + if (iCount < 1) + return; + + bool bMatchEqual = false; + int32_t iCurSel = m_iCurSel; + if (m_pEdit) { + CFX_WideString wsText = m_pEdit->GetText(); + iCurSel = pComboList->MatchItem(wsText); + if (iCurSel >= 0) { + CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); + CFX_WideString wsTemp = m_pListBox->GetDataProviderItemText(item); + bMatchEqual = wsText == wsTemp; + } + } + if (iCurSel < 0) { + iCurSel = 0; + } else if (bMatchEqual) { + if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) + return; + if (bUp) + iCurSel--; + else + iCurSel++; + } + m_iCurSel = iCurSel; + SyncEditText(m_iCurSel); + return; + } + if (m_pEdit) + m_pEdit->GetDelegate()->OnProcessMessage(pMsg); +} diff --git a/xfa/fwl/cfwl_combobox.h b/xfa/fwl/cfwl_combobox.h new file mode 100644 index 0000000000..9927b65c04 --- /dev/null +++ b/xfa/fwl/cfwl_combobox.h @@ -0,0 +1,172 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_COMBOBOX_H_ +#define XFA_FWL_CFWL_COMBOBOX_H_ + +#include + +#include "xfa/fwl/cfwl_comboboxproxy.h" +#include "xfa/fwl/cfwl_comboedit.h" +#include "xfa/fwl/cfwl_combolist.h" +#include "xfa/fwl/cfwl_form.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fxgraphics/cfx_graphics.h" + +class CFWL_WidgetProperties; +class CFWL_ComboBox; +class CFWL_ComboBoxProxy; +class CFWL_FormProxy; +class CFWL_ListBox; +class CFWL_Widget; + +#define FWL_STYLEEXT_CMB_DropList (0L << 0) +#define FWL_STYLEEXT_CMB_DropDown (1L << 0) +#define FWL_STYLEEXT_CMB_Sort (1L << 1) +#define FWL_STYLEEXT_CMB_ListDrag (1L << 2) +#define FWL_STYLEEXT_CMB_OwnerDraw (1L << 3) +#define FWL_STYLEEXT_CMB_EditHNear (0L << 4) +#define FWL_STYLEEXT_CMB_EditHCenter (1L << 4) +#define FWL_STYLEEXT_CMB_EditHFar (2L << 4) +#define FWL_STYLEEXT_CMB_EditVNear (0L << 6) +#define FWL_STYLEEXT_CMB_EditVCenter (1L << 6) +#define FWL_STYLEEXT_CMB_EditVFar (2L << 6) +#define FWL_STYLEEXT_CMB_EditJustified (1L << 8) +#define FWL_STYLEEXT_CMB_EditDistributed (2L << 8) +#define FWL_STYLEEXT_CMB_EditHAlignMask (3L << 4) +#define FWL_STYLEEXT_CMB_EditVAlignMask (3L << 6) +#define FWL_STYLEEXT_CMB_EditHAlignModeMask (3L << 8) +#define FWL_STYLEEXT_CMB_ListItemLeftAlign (0L << 10) +#define FWL_STYLEEXT_CMB_ListItemCenterAlign (1L << 10) +#define FWL_STYLEEXT_CMB_ListItemRightAlign (2L << 10) +#define FWL_STYLEEXT_CMB_ListItemAlignMask (3L << 10) +#define FWL_STYLEEXT_CMB_ListItemText (0L << 12) +#define FWL_STYLEEXT_CMB_ListItemIconText (1L << 12) +#define FWL_STYLEEXT_CMB_ReadOnly (1L << 13) + +class CFWL_ComboBox : public CFWL_Widget { + public: + explicit CFWL_ComboBox(const CFWL_App* pApp); + ~CFWL_ComboBox() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void ModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved) override; + void SetStates(uint32_t dwStates) override; + void RemoveStates(uint32_t dwStates) override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + CFX_WideString GetTextByIndex(int32_t iIndex) const; + int32_t GetCurSel() const { return m_iCurSel; } + void SetCurSel(int32_t iSel); + + void AddString(const CFX_WideStringC& wsText); + bool RemoveAt(int32_t iIndex); // Returns false iff |iIndex| out of range. + void RemoveAll(); + + void SetEditText(const CFX_WideString& wsText); + CFX_WideString GetEditText() const; + + void OpenDropDownList(bool bActivate); + + bool EditCanUndo() const { return m_pEdit->CanUndo(); } + bool EditCanRedo() const { return m_pEdit->CanRedo(); } + bool EditUndo() { return m_pEdit->Undo(); } + bool EditRedo() { return m_pEdit->Redo(); } + bool EditCanCopy() const { return m_pEdit->CountSelRanges() > 0; } + bool EditCanCut() const { + if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) + return false; + return EditCanCopy(); + } + bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; } + bool EditCopy(CFX_WideString& wsCopy) const { return m_pEdit->Copy(wsCopy); } + bool EditCut(CFX_WideString& wsCut) { return m_pEdit->Cut(wsCut); } + bool EditPaste(const CFX_WideString& wsPaste) { + return m_pEdit->Paste(wsPaste); + } + void EditSelectAll() { m_pEdit->AddSelRange(0); } + void EditDelete() { m_pEdit->ClearText(); } + void EditDeSelect() { m_pEdit->ClearSelections(); } + + CFX_RectF GetBBox() const; + void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); + + void DrawStretchHandler(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + bool IsDropListVisible() const { + return m_pComboBoxProxy && + !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); + } + void ShowDropList(bool bActivate); + + CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); } + + void ProcessSelChanged(bool bLButtonUp); + int32_t GetCurrentSelection() const { return m_iCurSel; } + + private: + bool IsDropDownStyle() const { + return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown); + } + void MatchEditText(); + void SyncEditText(int32_t iListItem); + void Layout(); + void ResetTheme(); + void ResetEditAlignment(); + void ResetListItemAlignment(); + void InitProxyForm(); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(CFWL_MessageMouse* pMsg); + void OnKey(CFWL_MessageKey* pMsg); + void DoSubCtrlKey(CFWL_MessageKey* pMsg); + + void DisForm_InitComboList(); + void DisForm_InitComboEdit(); + void DisForm_ShowDropList(bool bActivate); + bool DisForm_IsDropListVisible() const { + return !(m_pListBox->GetStates() & FWL_WGTSTATE_Invisible); + } + void DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved); + void DisForm_Update(); + FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy); + void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + CFX_RectF DisForm_GetBBox() const; + void DisForm_Layout(); + void DisForm_OnProcessMessage(CFWL_Message* pMessage); + void DisForm_OnLButtonDown(CFWL_MessageMouse* pMsg); + void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void DisForm_OnKey(CFWL_MessageKey* pMsg); + + CFX_RectF m_rtClient; + CFX_RectF m_rtContent; + CFX_RectF m_rtBtn; + CFX_RectF m_rtList; + CFX_RectF m_rtProxy; + CFX_RectF m_rtHandler; + std::unique_ptr m_pEdit; + std::unique_ptr m_pListBox; + CFWL_ComboBoxProxy* m_pComboBoxProxy; // Can this be a unique_ptr? + bool m_bLButtonDown; + bool m_bUpFormHandler; + int32_t m_iCurSel; + int32_t m_iBtnState; + FX_FLOAT m_fComboFormHandler; + FX_FLOAT m_fItemHeight; +}; + +#endif // XFA_FWL_CFWL_COMBOBOX_H_ diff --git a/xfa/fwl/cfwl_comboboxproxy.cpp b/xfa/fwl/cfwl_comboboxproxy.cpp new file mode 100644 index 0000000000..7bf311d198 --- /dev/null +++ b/xfa/fwl/cfwl_comboboxproxy.cpp @@ -0,0 +1,117 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_comboboxproxy.h" + +#include +#include + +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" + +CFWL_ComboBoxProxy::CFWL_ComboBoxProxy( + CFWL_ComboBox* pComboBox, + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_FormProxy(app, std::move(properties), pOuter), + m_bLButtonDown(false), + m_bLButtonUpSelf(false), + m_pComboBox(pComboBox) {} + +CFWL_ComboBoxProxy::~CFWL_ComboBoxProxy() {} + +void CFWL_ComboBoxProxy::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_Message::Type::SetFocus: + OnFocusChanged(pMessage, true); + break; + default: + break; + } + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_ComboBoxProxy::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); +} + +void CFWL_ComboBoxProxy::OnLButtonDown(CFWL_Message* pMessage) { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + CFX_RectF rtWidget = GetWidgetRect(); + rtWidget.left = rtWidget.top = 0; + + CFWL_MessageMouse* pMsg = static_cast(pMessage); + if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_bLButtonDown = true; + pDriver->SetGrab(this, true); + } else { + m_bLButtonDown = false; + pDriver->SetGrab(this, false); + m_pComboBox->ShowDropList(false); + } +} + +void CFWL_ComboBoxProxy::OnLButtonUp(CFWL_Message* pMessage) { + m_bLButtonDown = false; + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + pDriver->SetGrab(this, false); + if (!m_bLButtonUpSelf) { + m_bLButtonUpSelf = true; + return; + } + + CFWL_MessageMouse* pMsg = static_cast(pMessage); + CFX_RectF rect = GetWidgetRect(); + rect.left = rect.top = 0; + if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && + m_pComboBox->IsDropListVisible()) { + m_pComboBox->ShowDropList(false); + } +} + +void CFWL_ComboBoxProxy::OnFocusChanged(CFWL_Message* pMessage, bool bSet) { + if (bSet) + return; + + CFWL_MessageKillFocus* pMsg = static_cast(pMessage); + if (!pMsg->m_pSetFocus) + m_pComboBox->ShowDropList(false); +} diff --git a/xfa/fwl/cfwl_comboboxproxy.h b/xfa/fwl/cfwl_comboboxproxy.h new file mode 100644 index 0000000000..4be14b9e65 --- /dev/null +++ b/xfa/fwl/cfwl_comboboxproxy.h @@ -0,0 +1,41 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_COMBOBOXPROXY_H_ +#define XFA_FWL_CFWL_COMBOBOXPROXY_H_ + +#include + +#include "xfa/fwl/cfwl_formproxy.h" + +class CFWL_ComboBox; + +class CFWL_ComboBoxProxy : public CFWL_FormProxy { + public: + CFWL_ComboBoxProxy(CFWL_ComboBox* pCombobBox, + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_ComboBoxProxy() override; + + // CFWL_FormProxy + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void Reset() { m_bLButtonUpSelf = false; } + + private: + void OnLButtonDown(CFWL_Message* pMsg); + void OnLButtonUp(CFWL_Message* pMsg); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + + bool m_bLButtonDown; + bool m_bLButtonUpSelf; + CFWL_ComboBox* m_pComboBox; +}; + +#endif // XFA_FWL_CFWL_COMBOBOXPROXY_H_ diff --git a/xfa/fwl/cfwl_comboedit.cpp b/xfa/fwl/cfwl_comboedit.cpp new file mode 100644 index 0000000000..5981fd79b4 --- /dev/null +++ b/xfa/fwl/cfwl_comboedit.cpp @@ -0,0 +1,75 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_comboedit.h" + +#include +#include + +#include "xfa/fde/cfde_txtedtengine.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_messagemouse.h" + +CFWL_ComboEdit::CFWL_ComboEdit( + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Edit(app, std::move(properties), pOuter) { + m_pOuter = static_cast(pOuter); +} + +void CFWL_ComboEdit::ClearSelected() { + ClearSelections(); + Repaint(&GetRTClient()); +} + +void CFWL_ComboEdit::SetSelected() { + FlagFocus(true); + GetTxtEdtEngine()->MoveCaretPos(MC_End); + AddSelRange(0); +} + +void CFWL_ComboEdit::FlagFocus(bool bSet) { + if (bSet) { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + return; + } + + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + HideCaret(nullptr); +} + +void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + bool backDefault = true; + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + backDefault = false; + break; + } + case CFWL_Message::Type::KillFocus: { + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + backDefault = false; + break; + } + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) && + ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) { + SetSelected(); + m_pOuter->SetFocus(true); + } + break; + } + default: + break; + } + if (backDefault) + CFWL_Edit::OnProcessMessage(pMessage); +} diff --git a/xfa/fwl/cfwl_comboedit.h b/xfa/fwl/cfwl_comboedit.h new file mode 100644 index 0000000000..efdabd3669 --- /dev/null +++ b/xfa/fwl/cfwl_comboedit.h @@ -0,0 +1,35 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_COMBOEDIT_H_ +#define XFA_FWL_CFWL_COMBOEDIT_H_ + +#include + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +class CFWL_ComboBox; + +class CFWL_ComboEdit : public CFWL_Edit { + public: + CFWL_ComboEdit(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + + // CFWL_Edit. + void OnProcessMessage(CFWL_Message* pMessage) override; + + void ClearSelected(); + void SetSelected(); + void FlagFocus(bool bSet); + + private: + CFWL_ComboBox* m_pOuter; +}; + +#endif // XFA_FWL_CFWL_COMBOEDIT_H_ diff --git a/xfa/fwl/cfwl_combolist.cpp b/xfa/fwl/cfwl_combolist.cpp new file mode 100644 index 0000000000..4ec3abe072 --- /dev/null +++ b/xfa/fwl/cfwl_combolist.cpp @@ -0,0 +1,245 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_combolist.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_comboedit.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" + +CFWL_ComboList::CFWL_ComboList( + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { + ASSERT(pOuter); +} + +int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { + if (wsMatch.IsEmpty()) + return -1; + + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* hItem = GetItem(this, i); + CFX_WideString wsText = GetItemText(this, hItem); + FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); + if (!pos) + return i; + } + return -1; +} + +void CFWL_ComboList::ChangeSelected(int32_t iSel) { + CFWL_ListItem* hItem = GetItem(this, iSel); + CFX_RectF rtInvalidate; + rtInvalidate.Reset(); + CFWL_ListItem* hOld = GetSelItem(0); + int32_t iOld = GetItemIndex(this, hOld); + if (iOld == iSel) + return; + if (iOld > -1) { + CFWL_ListItem* hItem = GetItem(this, iOld); + GetItemRect(this, hItem, rtInvalidate); + SetSelItem(hOld, false); + } + if (hItem) { + CFX_RectF rect; + CFWL_ListItem* hItem = GetItem(this, iSel); + GetItemRect(this, hItem, rect); + rtInvalidate.Union(rect); + CFWL_ListItem* hSel = GetItem(this, iSel); + SetSelItem(hSel, true); + } + if (!rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +void CFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { + fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; + CFWL_Widget* pOwner = GetOwner(); + if (!pOwner) + return; + pOwner->TransformTo(m_pOuter, fx, fy); +} + +void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + CFWL_Message::Type type = pMessage->GetType(); + bool backDefault = true; + if (type == CFWL_Message::Type::SetFocus || + type == CFWL_Message::Type::KillFocus) { + OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::SetFocus); + } else if (type == CFWL_Message::Type::Mouse) { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + CFWL_ScrollBar* vertSB = GetVertScrollBar(); + if (IsShowScrollBar(true) && vertSB) { + CFX_RectF rect = vertSB->GetWidgetRect(); + if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { + pMsg->m_fx -= rect.left; + pMsg->m_fy -= rect.top; + vertSB->GetDelegate()->OnProcessMessage(pMsg); + return; + } + } + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::Move: { + backDefault = false; + OnDropListMouseMove(pMsg); + break; + } + case FWL_MouseCommand::LeftButtonDown: { + backDefault = false; + OnDropListLButtonDown(pMsg); + break; + } + case FWL_MouseCommand::LeftButtonUp: { + backDefault = false; + OnDropListLButtonUp(pMsg); + break; + } + default: + break; + } + } else if (type == CFWL_Message::Type::Key) { + backDefault = !OnDropListKey(static_cast(pMessage)); + } + if (backDefault) + CFWL_ListBox::OnProcessMessage(pMessage); +} + +void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) + return; + + CFWL_MessageKillFocus* pKill = static_cast(pMsg); + CFWL_ComboBox* pOuter = static_cast(m_pOuter); + if (pKill->m_pSetFocus == m_pOuter || + pKill->m_pSetFocus == pOuter->GetComboEdit()) { + pOuter->ShowDropList(false); + } +} + +void CFWL_ComboList::OnDropListMouseMove(CFWL_MessageMouse* pMsg) { + if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { + if (m_bNotifyOwner) + m_bNotifyOwner = false; + + CFWL_ScrollBar* vertSB = GetVertScrollBar(); + if (IsShowScrollBar(true) && vertSB) { + CFX_RectF rect = vertSB->GetWidgetRect(); + if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + } + + CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); + if (!hItem) + return; + + ChangeSelected(GetItemIndex(this, hItem)); + } else if (m_bNotifyOwner) { + ClientToOuter(pMsg->m_fx, pMsg->m_fy); + CFWL_ComboBox* pOuter = static_cast(m_pOuter); + pOuter->GetDelegate()->OnProcessMessage(pMsg); + } +} + +void CFWL_ComboList::OnDropListLButtonDown(CFWL_MessageMouse* pMsg) { + if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + CFWL_ComboBox* pOuter = static_cast(m_pOuter); + pOuter->ShowDropList(false); +} + +void CFWL_ComboList::OnDropListLButtonUp(CFWL_MessageMouse* pMsg) { + CFWL_ComboBox* pOuter = static_cast(m_pOuter); + if (m_bNotifyOwner) { + ClientToOuter(pMsg->m_fx, pMsg->m_fy); + pOuter->GetDelegate()->OnProcessMessage(pMsg); + return; + } + + CFWL_ScrollBar* vertSB = GetVertScrollBar(); + if (IsShowScrollBar(true) && vertSB) { + CFX_RectF rect = vertSB->GetWidgetRect(); + if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + } + pOuter->ShowDropList(false); + + CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); + if (hItem) + pOuter->ProcessSelChanged(true); +} + +bool CFWL_ComboList::OnDropListKey(CFWL_MessageKey* pKey) { + CFWL_ComboBox* pOuter = static_cast(m_pOuter); + bool bPropagate = false; + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { + uint32_t dwKeyCode = pKey->m_dwKeyCode; + switch (dwKeyCode) { + case FWL_VKEY_Return: + case FWL_VKEY_Escape: { + pOuter->ShowDropList(false); + return true; + } + case FWL_VKEY_Up: + case FWL_VKEY_Down: { + OnDropListKeyDown(pKey); + pOuter->ProcessSelChanged(false); + return true; + } + default: { + bPropagate = true; + break; + } + } + } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { + bPropagate = true; + } + if (bPropagate) { + pKey->m_pDstTarget = m_pOuter; + pOuter->GetDelegate()->OnProcessMessage(pKey); + return true; + } + return false; +} + +void CFWL_ComboList::OnDropListKeyDown(CFWL_MessageKey* pKey) { + uint32_t dwKeyCode = pKey->m_dwKeyCode; + switch (dwKeyCode) { + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_End: { + CFWL_ComboBox* pOuter = static_cast(m_pOuter); + CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); + hItem = GetListItem(hItem, dwKeyCode); + if (!hItem) + break; + + SetSelection(hItem, hItem, true); + ScrollToVisible(hItem); + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + Repaint(&rtInvalidate); + break; + } + default: + break; + } +} diff --git a/xfa/fwl/cfwl_combolist.h b/xfa/fwl/cfwl_combolist.h new file mode 100644 index 0000000000..e1d5fd9b24 --- /dev/null +++ b/xfa/fwl/cfwl_combolist.h @@ -0,0 +1,43 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_COMBOLIST_H_ +#define XFA_FWL_CFWL_COMBOLIST_H_ + +#include + +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +class CFWL_ComboList : public CFWL_ListBox { + public: + CFWL_ComboList(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + + // CFWL_ListBox. + void OnProcessMessage(CFWL_Message* pMessage) override; + + int32_t MatchItem(const CFX_WideString& wsMatch); + + void ChangeSelected(int32_t iSel); + + void SetNotifyOwner(bool notify) { m_bNotifyOwner = notify; } + + private: + void ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy); + void OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnDropListMouseMove(CFWL_MessageMouse* pMsg); + void OnDropListLButtonDown(CFWL_MessageMouse* pMsg); + void OnDropListLButtonUp(CFWL_MessageMouse* pMsg); + bool OnDropListKey(CFWL_MessageKey* pKey); + void OnDropListKeyDown(CFWL_MessageKey* pKey); + + bool m_bNotifyOwner; +}; + +#endif // XFA_FWL_CFWL_COMBOLIST_H_ diff --git a/xfa/fwl/cfwl_datetimeedit.cpp b/xfa/fwl/cfwl_datetimeedit.cpp new file mode 100644 index 0000000000..869f08ad33 --- /dev/null +++ b/xfa/fwl/cfwl_datetimeedit.cpp @@ -0,0 +1,60 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_datetimeedit.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_widgetmgr.h" + +CFWL_DateTimeEdit::CFWL_DateTimeEdit( + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Edit(app, std::move(properties), pOuter) {} + +void CFWL_DateTimeEdit::OnProcessMessage(CFWL_Message* pMessage) { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_OnProcessMessage(pMessage); + return; + } + + CFWL_Message::Type type = pMessage->GetType(); + if (type == CFWL_Message::Type::SetFocus || + type == CFWL_Message::Type::KillFocus) { + CFWL_Widget* pOuter = GetOuter(); + pOuter->GetDelegate()->OnProcessMessage(pMessage); + } +} + +void CFWL_DateTimeEdit::DisForm_OnProcessMessage(CFWL_Message* pMessage) { + if (!m_pWidgetMgr->IsFormDisabled() || + pMessage->GetType() != CFWL_Message::Type::Mouse) { + CFWL_Edit::OnProcessMessage(pMessage); + return; + } + + CFWL_MessageMouse* pMouse = static_cast(pMessage); + if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown || + pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) { + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + + CFWL_DateTimePicker* pDateTime = + static_cast(m_pOuter); + if (pDateTime->IsMonthCalendarVisible()) { + CFX_RectF rtInvalidate = pDateTime->GetWidgetRect(); + pDateTime->ShowMonthCalendar(false); + rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top); + pDateTime->Repaint(&rtInvalidate); + } + } + CFWL_Edit::OnProcessMessage(pMessage); +} diff --git a/xfa/fwl/cfwl_datetimeedit.h b/xfa/fwl/cfwl_datetimeedit.h new file mode 100644 index 0000000000..bde14ddf49 --- /dev/null +++ b/xfa/fwl/cfwl_datetimeedit.h @@ -0,0 +1,30 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_DATETIMEEDIT_H_ +#define XFA_FWL_CFWL_DATETIMEEDIT_H_ + +#include + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" +#include "xfa/fwl/fwl_error.h" + +class CFWL_DateTimeEdit : public CFWL_Edit { + public: + CFWL_DateTimeEdit(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + + // CFWL_Edit. + void OnProcessMessage(CFWL_Message* pMessage) override; + + private: + void DisForm_OnProcessMessage(CFWL_Message* pMessage); +}; + +#endif // XFA_FWL_CFWL_DATETIMEEDIT_H_ diff --git a/xfa/fwl/cfwl_datetimepicker.cpp b/xfa/fwl/cfwl_datetimepicker.cpp new file mode 100644 index 0000000000..8bc17f3c57 --- /dev/null +++ b/xfa/fwl/cfwl_datetimepicker.cpp @@ -0,0 +1,625 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_datetimepicker.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_formproxy.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_spinbutton.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +namespace { + +const int kDateTimePickerHeight = 20; + +} // namespace +CFWL_DateTimePicker::CFWL_DateTimePicker(const CFWL_App* app) + : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), + m_iBtnState(1), + m_iYear(-1), + m_iMonth(-1), + m_iDay(-1), + m_bLBtnDown(false) { + m_rtBtn.Set(0, 0, 0, 0); + + m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; + + auto monthProp = pdfium::MakeUnique(); + monthProp->m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border; + monthProp->m_dwStates = FWL_WGTSTATE_Invisible; + monthProp->m_pParent = this; + monthProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; + m_pMonthCal.reset( + new CFWL_MonthCalendar(m_pOwnerApp, std::move(monthProp), this)); + + CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); + rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height); + m_pMonthCal->SetWidgetRect(rtMonthCal); + + auto editProp = pdfium::MakeUnique(); + editProp->m_pParent = this; + editProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; + + m_pEdit.reset(new CFWL_DateTimeEdit(m_pOwnerApp, std::move(editProp), this)); + RegisterEventTarget(m_pMonthCal.get()); + RegisterEventTarget(m_pEdit.get()); +} + +CFWL_DateTimePicker::~CFWL_DateTimePicker() { + UnregisterEventTarget(); +} + +FWL_Type CFWL_DateTimePicker::GetClassID() const { + return FWL_Type::DateTimePicker; +} + +void CFWL_DateTimePicker::Update() { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_Update(); + return; + } + if (m_iLock) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); + GetClientRect(m_rtClient); + FX_FLOAT* pFWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pFWidth) + return; + + FX_FLOAT fBtn = *pFWidth; + m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1, + m_rtClient.height - 1); + + CFX_RectF rtEdit; + rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, + m_rtClient.height); + m_pEdit->SetWidgetRect(rtEdit); + ResetEditAlignment(); + m_pEdit->Update(); + if (!(m_pMonthCal->GetThemeProvider())) + m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); + + CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); + CFX_RectF rtPopUp; + rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, + rtMonthCal.width, rtMonthCal.height); + m_pMonthCal->SetWidgetRect(rtPopUp); + m_pMonthCal->Update(); + return; +} + +FWL_WidgetHit CFWL_DateTimePicker::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_HitTest(fx, fy); + if (m_rtClient.Contains(fx, fy)) + return FWL_WidgetHit::Client; + if (IsMonthCalendarVisible()) { + CFX_RectF rect = m_pMonthCal->GetWidgetRect(); + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::Client; + } + return FWL_WidgetHit::Unknown; +} + +void CFWL_DateTimePicker::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + if (!m_rtBtn.IsEmpty()) + DrawDropDownButton(pGraphics, pTheme, pMatrix); + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_DrawWidget(pGraphics, pMatrix); + return; + } +} + +void CFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) { + m_pProperties->m_pThemeProvider = pTP; + m_pMonthCal->SetThemeProvider(pTP); +} + +void CFWL_DateTimePicker::GetCurSel(int32_t& iYear, + int32_t& iMonth, + int32_t& iDay) { + iYear = m_iYear; + iMonth = m_iMonth; + iDay = m_iDay; +} + +void CFWL_DateTimePicker::SetCurSel(int32_t iYear, + int32_t iMonth, + int32_t iDay) { + if (iYear <= 0 || iYear >= 3000) + return; + if (iMonth <= 0 || iMonth >= 13) + return; + if (iDay <= 0 || iDay >= 32) + return; + + m_iYear = iYear; + m_iMonth = iMonth; + m_iDay = iDay; + m_pMonthCal->SetSelect(iYear, iMonth, iDay); +} + +void CFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) { + if (!m_pEdit) + return; + + m_pEdit->SetText(wsText); + Repaint(&m_rtClient); + + CFWL_Event ev(CFWL_Event::Type::EditChanged); + DispatchEvent(&ev); +} + +CFX_WideString CFWL_DateTimePicker::GetEditText() const { + return m_pEdit ? m_pEdit->GetText() : L""; +} + +void CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_GetBBox(rect); + return; + } + + rect = m_pProperties->m_rtWidget; + if (IsMonthCalendarVisible()) { + CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); + rtMonth.Offset(m_pProperties->m_rtWidget.left, + m_pProperties->m_rtWidget.top); + rect.Union(rtMonth); + } +} + +void CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved) { + m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); +} + +void CFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) == + FWL_STYLEEXT_DTP_Spin) { + return; + } + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::DropDownButton; + param.m_dwStates = m_iBtnState; + param.m_pGraphics = pGraphics; + param.m_rtPart = m_rtBtn; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶m); +} + +void CFWL_DateTimePicker::FormatDateString(int32_t iYear, + int32_t iMonth, + int32_t iDay, + CFX_WideString& wsText) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) == + FWL_STYLEEXT_DTP_ShortDateFormat) { + wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay); + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) == + FWL_STYLEEXT_DTP_LongDateFormat) { + wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay); + } +} + +void CFWL_DateTimePicker::ShowMonthCalendar(bool bActivate) { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_ShowMonthCalendar(bActivate); + if (IsMonthCalendarVisible() == bActivate) + return; + if (!m_pForm) + InitProxyForm(); + + if (!bActivate) { + m_pForm->EndDoModal(); + return; + } + + CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); + + CFX_RectF rtAnchor; + rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + GetPopupPos(0, rtMonth.height, rtAnchor, rtMonth); + m_pForm->SetWidgetRect(rtMonth); + + rtMonth.left = rtMonth.top = 0; + if (bActivate) + m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible); + else + m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible); + m_pMonthCal->SetWidgetRect(rtMonth); + m_pMonthCal->Update(); + m_pForm->DoModal(); +} + +bool CFWL_DateTimePicker::IsMonthCalendarVisible() const { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_IsMonthCalendarVisible(); + if (!m_pForm) + return false; + return !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible); +} + +void CFWL_DateTimePicker::ResetEditAlignment() { + if (!m_pEdit) + return; + + uint32_t dwAdd = 0; + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditHAlignMask) { + case FWL_STYLEEXT_DTP_EditHCenter: { + dwAdd |= FWL_STYLEEXT_EDT_HCenter; + break; + } + case FWL_STYLEEXT_DTP_EditHFar: { + dwAdd |= FWL_STYLEEXT_EDT_HFar; + break; + } + default: { + dwAdd |= FWL_STYLEEXT_EDT_HNear; + break; + } + } + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditVAlignMask) { + case FWL_STYLEEXT_DTP_EditVCenter: { + dwAdd |= FWL_STYLEEXT_EDT_VCenter; + break; + } + case FWL_STYLEEXT_DTP_EditVFar: { + dwAdd |= FWL_STYLEEXT_EDT_VFar; + break; + } + default: { + dwAdd |= FWL_STYLEEXT_EDT_VNear; + break; + } + } + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditJustified) + dwAdd |= FWL_STYLEEXT_EDT_Justified; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditDistributed) + dwAdd |= FWL_STYLEEXT_EDT_Distributed; + + m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | + FWL_STYLEEXT_EDT_HAlignModeMask | + FWL_STYLEEXT_EDT_VAlignMask); +} + +void CFWL_DateTimePicker::ProcessSelChanged(int32_t iYear, + int32_t iMonth, + int32_t iDay) { + m_iYear = iYear; + m_iMonth = iMonth; + m_iDay = iDay; + + CFX_WideString wsText; + FormatDateString(m_iYear, m_iMonth, m_iDay, wsText); + m_pEdit->SetText(wsText); + m_pEdit->Update(); + Repaint(&m_rtClient); + + CFWL_EventSelectChanged ev(this); + ev.iYear = m_iYear; + ev.iMonth = m_iMonth; + ev.iDay = m_iDay; + DispatchEvent(&ev); +} + +void CFWL_DateTimePicker::InitProxyForm() { + if (m_pForm) + return; + if (!m_pMonthCal) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_dwStyles = FWL_WGTSTYLE_Popup; + prop->m_dwStates = FWL_WGTSTATE_Invisible; + prop->m_pOwner = this; + + m_pForm = pdfium::MakeUnique(m_pOwnerApp, std::move(prop), + m_pMonthCal.get()); + m_pMonthCal->SetParent(m_pForm.get()); +} + +bool CFWL_DateTimePicker::DisForm_IsMonthCalendarVisible() const { + if (!m_pMonthCal) + return false; + return !(m_pMonthCal->GetStates() & FWL_WGTSTATE_Invisible); +} + +void CFWL_DateTimePicker::DisForm_ShowMonthCalendar(bool bActivate) { + if (IsMonthCalendarVisible() == bActivate) + return; + + if (bActivate) { + CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); + FX_FLOAT fPopupMin = rtMonthCal.height; + FX_FLOAT fPopupMax = rtMonthCal.height; + CFX_RectF rtAnchor(m_pProperties->m_rtWidget); + rtAnchor.width = rtMonthCal.width; + rtMonthCal.left = m_rtClient.left; + rtMonthCal.top = rtAnchor.Height(); + GetPopupPos(fPopupMin, fPopupMax, rtAnchor, rtMonthCal); + m_pMonthCal->SetWidgetRect(rtMonthCal); + if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0) + m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay); + m_pMonthCal->Update(); + } + if (bActivate) + m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible); + else + m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible); + + if (bActivate) { + CFWL_MessageSetFocus msg(m_pEdit.get(), m_pMonthCal.get()); + m_pEdit->GetDelegate()->OnProcessMessage(&msg); + } + + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + + CFX_RectF rtCal = m_pMonthCal->GetWidgetRect(); + rtInvalidate.Union(rtCal); + rtInvalidate.Inflate(2, 2); + Repaint(&rtInvalidate); +} + +FWL_WidgetHit CFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx, + FX_FLOAT fy) const { + CFX_RectF rect; + rect.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::Edit; + if (DisForm_IsNeedShowButton()) + rect.width += m_fBtn; + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::Client; + if (IsMonthCalendarVisible()) { + if (m_pMonthCal->GetWidgetRect().Contains(fx, fy)) + return FWL_WidgetHit::Client; + } + return FWL_WidgetHit::Unknown; +} + +bool CFWL_DateTimePicker::DisForm_IsNeedShowButton() const { + return m_pProperties->m_dwStates & FWL_WGTSTATE_Focused || + m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused || + m_pEdit->GetStates() & FWL_WGTSTATE_Focused; +} + +void CFWL_DateTimePicker::DisForm_Update() { + if (m_iLock) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); + GetClientRect(m_rtClient); + m_pEdit->SetWidgetRect(m_rtClient); + ResetEditAlignment(); + m_pEdit->Update(); + + if (!m_pMonthCal->GetThemeProvider()) + m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); + + FX_FLOAT* pWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pWidth) + return; + + m_fBtn = *pWidth; + CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); + CFX_RectF rtPopUp; + rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, + rtMonthCal.width, rtMonthCal.height); + m_pMonthCal->SetWidgetRect(rtPopUp); + m_pMonthCal->Update(); +} + +void CFWL_DateTimePicker::DisForm_GetBBox(CFX_RectF& rect) const { + rect = m_pProperties->m_rtWidget; + if (DisForm_IsNeedShowButton()) + rect.width += m_fBtn; + if (!IsMonthCalendarVisible()) + return; + + CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); + rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); + rect.Union(rtMonth); +} + +void CFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (m_pEdit) { + CFX_RectF rtEdit = m_pEdit->GetWidgetRect(); + + CFX_Matrix mt; + mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); + if (pMatrix) + mt.Concat(*pMatrix); + m_pEdit->DrawWidget(pGraphics, &mt); + } + if (!IsMonthCalendarVisible()) + return; + + CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); + CFX_Matrix mt; + mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top); + if (pMatrix) + mt.Concat(*pMatrix); + m_pMonthCal->DrawWidget(pGraphics, &mt); +} + +void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + OnFocusChanged(pMessage, true); + break; + case CFWL_Message::Type::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMouse = static_cast(pMessage); + switch (pMouse->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMouse); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMouse); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMouse); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMouse); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: { + if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { + m_pEdit->GetDelegate()->OnProcessMessage(pMessage); + return; + } + break; + } + default: + break; + } + + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_DateTimePicker::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (!pMsg) + return; + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_OnFocusChanged(pMsg, bSet); + + if (bSet) { + m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); + Repaint(&m_rtClient); + } else { + m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); + Repaint(&m_rtClient); + } + if (pMsg->m_pSrcTarget == m_pMonthCal.get() && IsMonthCalendarVisible()) { + ShowMonthCalendar(false); + } + Repaint(&m_rtClient); +} + +void CFWL_DateTimePicker::OnLButtonDown(CFWL_MessageMouse* pMsg) { + if (!pMsg) + return; + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + SetFocus(true); + if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + if (IsMonthCalendarVisible()) { + ShowMonthCalendar(false); + return; + } + if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) + ShowMonthCalendar(true); + + m_bLBtnDown = true; + Repaint(&m_rtClient); +} + +void CFWL_DateTimePicker::OnLButtonUp(CFWL_MessageMouse* pMsg) { + if (!pMsg) + return; + + m_bLBtnDown = false; + if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) + m_iBtnState = CFWL_PartState_Hovered; + else + m_iBtnState = CFWL_PartState_Normal; + Repaint(&m_rtBtn); +} + +void CFWL_DateTimePicker::OnMouseMove(CFWL_MessageMouse* pMsg) { + if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) + m_iBtnState = CFWL_PartState_Normal; + Repaint(&m_rtBtn); +} + +void CFWL_DateTimePicker::OnMouseLeave(CFWL_MessageMouse* pMsg) { + if (!pMsg) + return; + m_iBtnState = CFWL_PartState_Normal; + Repaint(&m_rtBtn); +} + +void CFWL_DateTimePicker::DisForm_OnFocusChanged(CFWL_Message* pMsg, + bool bSet) { + CFX_RectF rtInvalidate(m_rtBtn); + if (bSet) { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { + m_rtBtn.Set(m_pProperties->m_rtWidget.width, 0, m_fBtn, + m_pProperties->m_rtWidget.height - 1); + } + rtInvalidate = m_rtBtn; + pMsg->m_pDstTarget = m_pEdit.get(); + m_pEdit->GetDelegate()->OnProcessMessage(pMsg); + } else { + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + m_rtBtn.Set(0, 0, 0, 0); + if (DisForm_IsMonthCalendarVisible()) + ShowMonthCalendar(false); + if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { + pMsg->m_pSrcTarget = m_pEdit.get(); + m_pEdit->GetDelegate()->OnProcessMessage(pMsg); + } + } + rtInvalidate.Inflate(2, 2); + Repaint(&rtInvalidate); +} diff --git a/xfa/fwl/cfwl_datetimepicker.h b/xfa/fwl/cfwl_datetimepicker.h new file mode 100644 index 0000000000..7ddb4c248d --- /dev/null +++ b/xfa/fwl/cfwl_datetimepicker.h @@ -0,0 +1,112 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_DATETIMEPICKER_H_ +#define XFA_FWL_CFWL_DATETIMEPICKER_H_ + +#include + +#include "xfa/fwl/cfwl_datetimeedit.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_monthcalendar.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_STYLEEXT_DTP_AllowEdit (1L << 0) +#define FWL_STYLEEXT_DTP_LongDateFormat (0L << 1) +#define FWL_STYLEEXT_DTP_ShortDateFormat (1L << 1) +#define FWL_STYLEEXT_DTP_TimeFormat (2L << 1) +#define FWL_STYLEEXT_DTP_Spin (1L << 3) +#define FWL_STYLEEXT_DTP_EditHNear (0L << 4) +#define FWL_STYLEEXT_DTP_EditHCenter (1L << 4) +#define FWL_STYLEEXT_DTP_EditHFar (2L << 4) +#define FWL_STYLEEXT_DTP_EditVNear (0L << 6) +#define FWL_STYLEEXT_DTP_EditVCenter (1L << 6) +#define FWL_STYLEEXT_DTP_EditVFar (2L << 6) +#define FWL_STYLEEXT_DTP_EditJustified (1L << 8) +#define FWL_STYLEEXT_DTP_EditDistributed (2L << 8) +#define FWL_STYLEEXT_DTP_EditHAlignMask (3L << 4) +#define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6) +#define FWL_STYLEEXT_DTP_EditHAlignModeMask (3L << 8) + +class CFWL_DateTimeEdit; +class CFWL_FormProxy; + +class CFWL_DateTimePicker : public CFWL_Widget { + public: + explicit CFWL_DateTimePicker(const CFWL_App* pApp); + ~CFWL_DateTimePicker() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void SetThemeProvider(IFWL_ThemeProvider* pTP) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay); + void SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay); + + void SetEditText(const CFX_WideString& wsText); + CFX_WideString GetEditText() const; + + int32_t CountSelRanges() const { return m_pEdit->CountSelRanges(); } + int32_t GetSelRange(int32_t nIndex, int32_t* nStart) const { + return m_pEdit->GetSelRange(nIndex, nStart); + } + + void GetBBox(CFX_RectF& rect) const; + void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); } + void ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); + + bool IsMonthCalendarVisible() const; + void ShowMonthCalendar(bool bActivate); + void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay); + + CFWL_FormProxy* GetFormProxy() const { return m_pForm.get(); } + + private: + void DrawDropDownButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void FormatDateString(int32_t iYear, + int32_t iMonth, + int32_t iDay, + CFX_WideString& wsText); + void ResetEditAlignment(); + void InitProxyForm(); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(CFWL_MessageMouse* pMsg); + + bool DisForm_IsMonthCalendarVisible() const; + void DisForm_ShowMonthCalendar(bool bActivate); + FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) const; + bool DisForm_IsNeedShowButton() const; + void DisForm_Update(); + void DisForm_GetBBox(CFX_RectF& rect) const; + void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); + + CFX_RectF m_rtBtn; + CFX_RectF m_rtClient; + int32_t m_iBtnState; + int32_t m_iYear; + int32_t m_iMonth; + int32_t m_iDay; + bool m_bLBtnDown; + std::unique_ptr m_pEdit; + std::unique_ptr m_pMonthCal; + std::unique_ptr m_pForm; + FX_FLOAT m_fBtn; +}; + +#endif // XFA_FWL_CFWL_DATETIMEPICKER_H_ diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp new file mode 100644 index 0000000000..321303942e --- /dev/null +++ b/xfa/fwl/cfwl_edit.cpp @@ -0,0 +1,1644 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_edit.h" + +#include +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" +#include "xfa/fde/cfde_txtedtengine.h" +#include "xfa/fde/fde_gedevice.h" +#include "xfa/fde/fde_render.h" +#include "xfa/fde/ifde_txtedtpage.h" +#include "xfa/fgas/font/cfgas_gefont.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_caret.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_eventcheckword.h" +#include "xfa/fwl/cfwl_eventtextchanged.h" +#include "xfa/fwl/cfwl_eventvalidate.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" +#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxgraphics/cfx_path.h" + +namespace { + +const int kEditMargin = 3; + +bool FX_EDIT_ISLATINWORD(FX_WCHAR c) { + return c == 0x2D || (c <= 0x005A && c >= 0x0041) || + (c <= 0x007A && c >= 0x0061) || (c <= 0x02AF && c >= 0x00C0) || + c == 0x0027; +} + +void AddSquigglyPath(CFX_Path* pPathData, + FX_FLOAT fStartX, + FX_FLOAT fEndX, + FX_FLOAT fY, + FX_FLOAT fStep) { + pPathData->MoveTo(fStartX, fY); + int i = 1; + for (FX_FLOAT fx = fStartX + fStep; fx < fEndX; fx += fStep, ++i) + pPathData->LineTo(fx, fY + (i & 1) * fStep); +} + +} // namespace + +CFWL_Edit::CFWL_Edit(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Widget(app, std::move(properties), pOuter), + m_fVAlignOffset(0.0f), + m_fScrollOffsetX(0.0f), + m_fScrollOffsetY(0.0f), + m_bLButtonDown(false), + m_nSelStart(0), + m_nLimit(-1), + m_fFontSize(0), + m_bSetRange(false), + m_iMax(0xFFFFFFF), + m_iCurRecord(-1), + m_iMaxRecord(128) { + m_rtClient.Reset(); + m_rtEngine.Reset(); + m_rtStatic.Reset(); + + InitCaret(); +} + +CFWL_Edit::~CFWL_Edit() { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + HideCaret(nullptr); + ClearRecord(); +} + +FWL_Type CFWL_Edit::GetClassID() const { + return FWL_Type::Edit; +} + +CFX_RectF CFWL_Edit::GetWidgetRect() { + CFX_RectF rect = m_pProperties->m_rtWidget; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { + if (IsShowScrollBar(true)) { + FX_FLOAT* pfWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + rect.width += *pfWidth; + rect.width += kEditMargin; + } + if (IsShowScrollBar(false)) { + FX_FLOAT* pfWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + rect.height += *pfWidth; + rect.height += kEditMargin; + } + } + return rect; +} + +CFX_RectF CFWL_Edit::GetAutosizedWidgetRect() { + CFX_RectF rect; + if (m_EdtEngine.GetTextLength() > 0) { + CFX_SizeF sz = CalcTextSize( + m_EdtEngine.GetText(0, -1), m_pProperties->m_pThemeProvider, + !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); + rect.Set(0, 0, sz.x, sz.y); + } + InflateWidgetRect(rect); + return rect; +} + +void CFWL_Edit::SetStates(uint32_t dwStates) { + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { + HideCaret(nullptr); + } + CFWL_Widget::SetStates(dwStates); +} + +void CFWL_Edit::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + Layout(); + if (m_rtClient.IsEmpty()) + return; + + UpdateEditEngine(); + UpdateVAlignment(); + UpdateScroll(); + InitCaret(); +} + +FWL_WidgetHit CFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { + if (IsShowScrollBar(true)) { + if (m_pVertScrollBar->GetWidgetRect().Contains(fx, fy)) + return FWL_WidgetHit::VScrollBar; + } + if (IsShowScrollBar(false)) { + if (m_pHorzScrollBar->GetWidgetRect().Contains(fx, fy)) + return FWL_WidgetHit::HScrollBar; + } + } + if (m_rtClient.Contains(fx, fy)) + return FWL_WidgetHit::Edit; + return FWL_WidgetHit::Unknown; +} + +void CFWL_Edit::AddSpellCheckObj(CFX_Path& PathData, + int32_t nStart, + int32_t nCount, + FX_FLOAT fOffSetX, + FX_FLOAT fOffSetY) { + FX_FLOAT fStartX = 0.0f; + FX_FLOAT fEndX = 0.0f; + FX_FLOAT fY = 0.0f; + FX_FLOAT fStep = 0.0f; + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + CFX_RectFArray rectArray; + CFX_RectF rectText; + const FDE_TXTEDTPARAMS* txtEdtParams = m_EdtEngine.GetEditParams(); + FX_FLOAT fAsent = static_cast(txtEdtParams->pFont->GetAscent()) * + txtEdtParams->fFontSize / 1000; + pPage->CalcRangeRectArray(nStart, nCount, rectArray); + + for (int i = 0; i < rectArray.GetSize(); i++) { + rectText = rectArray.GetAt(i); + fY = rectText.top + fAsent + fOffSetY; + fStep = txtEdtParams->fFontSize / 16.0f; + fStartX = rectText.left + fOffSetX; + fEndX = fStartX + rectText.Width(); + AddSquigglyPath(&PathData, fStartX, fEndX, fY, fStep); + } +} + +void CFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + pGraphics->SaveGraphState(); + if (pMatrix) + pGraphics->ConcatMatrix(const_cast(pMatrix)); + + CFX_Color crLine(0xFFFF0000); + CFWL_EventCheckWord checkWordEvent(this); + + CFX_ByteString sLatinWord; + CFX_Path pathSpell; + pathSpell.Create(); + + int32_t nStart = 0; + FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; + FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; + + CFX_WideString wsSpell = GetText(); + int32_t nContentLen = wsSpell.GetLength(); + for (int i = 0; i < nContentLen; i++) { + if (FX_EDIT_ISLATINWORD(wsSpell[i])) { + if (sLatinWord.IsEmpty()) + nStart = i; + sLatinWord += (FX_CHAR)wsSpell[i]; + continue; + } + checkWordEvent.bsWord = sLatinWord; + checkWordEvent.bCheckWord = true; + DispatchEvent(&checkWordEvent); + + if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { + AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, + fOffSetY); + } + sLatinWord.clear(); + } + + checkWordEvent.bsWord = sLatinWord; + checkWordEvent.bCheckWord = true; + DispatchEvent(&checkWordEvent); + + if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { + AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, + fOffSetY); + } + if (!pathSpell.IsEmpty()) { + CFX_RectF rtClip = m_rtEngine; + CFX_Matrix mt; + mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); + if (pMatrix) { + pMatrix->TransformRect(rtClip); + mt.Concat(*pMatrix); + } + pGraphics->SetClipRect(rtClip); + pGraphics->SetStrokeColor(&crLine); + pGraphics->SetLineWidth(0); + pGraphics->StrokePath(&pathSpell, nullptr); + } + pGraphics->RestoreGraphState(); +} + +void CFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + if (m_rtClient.IsEmpty()) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (!m_pWidgetMgr->IsFormDisabled()) + DrawTextBk(pGraphics, pTheme, pMatrix); + DrawContent(pGraphics, pTheme, pMatrix); + + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && + !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) { + DrawSpellCheck(pGraphics, pMatrix); + } + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); +} + +void CFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { + if (!pThemeProvider) + return; + if (m_pHorzScrollBar) + m_pHorzScrollBar->SetThemeProvider(pThemeProvider); + if (m_pVertScrollBar) + m_pVertScrollBar->SetThemeProvider(pThemeProvider); + if (m_pCaret) + m_pCaret->SetThemeProvider(pThemeProvider); + m_pProperties->m_pThemeProvider = pThemeProvider; +} + +void CFWL_Edit::SetText(const CFX_WideString& wsText) { + m_EdtEngine.SetText(wsText); +} + +int32_t CFWL_Edit::GetTextLength() const { + return m_EdtEngine.GetTextLength(); +} + +CFX_WideString CFWL_Edit::GetText() const { + return m_EdtEngine.GetText(0, -1); +} + +void CFWL_Edit::ClearText() { + m_EdtEngine.ClearText(); +} + +void CFWL_Edit::AddSelRange(int32_t nStart) { + m_EdtEngine.AddSelRange(nStart, -1); +} + +int32_t CFWL_Edit::CountSelRanges() const { + return m_EdtEngine.CountSelRanges(); +} + +int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t* nStart) const { + return m_EdtEngine.GetSelRange(nIndex, nStart); +} + +void CFWL_Edit::ClearSelections() { + m_EdtEngine.ClearSelection(); +} + +int32_t CFWL_Edit::GetLimit() const { + return m_nLimit; +} + +void CFWL_Edit::SetLimit(int32_t nLimit) { + m_nLimit = nLimit; + m_EdtEngine.SetLimit(nLimit); +} + +void CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { + m_EdtEngine.SetAliasChar(wAlias); +} + +bool CFWL_Edit::Copy(CFX_WideString& wsCopy) { + int32_t nCount = m_EdtEngine.CountSelRanges(); + if (nCount == 0) + return false; + + wsCopy.clear(); + int32_t nStart; + int32_t nLength; + for (int32_t i = 0; i < nCount; i++) { + nLength = m_EdtEngine.GetSelRange(i, &nStart); + wsCopy += m_EdtEngine.GetText(nStart, nLength); + } + return true; +} + +bool CFWL_Edit::Cut(CFX_WideString& wsCut) { + int32_t nCount = m_EdtEngine.CountSelRanges(); + if (nCount == 0) + return false; + + wsCut.clear(); + CFX_WideString wsTemp; + int32_t nStart, nLength; + for (int32_t i = 0; i < nCount; i++) { + nLength = m_EdtEngine.GetSelRange(i, &nStart); + wsTemp = m_EdtEngine.GetText(nStart, nLength); + wsCut += wsTemp; + wsTemp.clear(); + } + m_EdtEngine.Delete(0); + return true; +} + +bool CFWL_Edit::Paste(const CFX_WideString& wsPaste) { + int32_t nCaret = m_EdtEngine.GetCaretPos(); + int32_t iError = + m_EdtEngine.Insert(nCaret, wsPaste.c_str(), wsPaste.GetLength()); + if (iError < 0) { + ProcessInsertError(iError); + return false; + } + return true; +} + +bool CFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) + return true; + return m_EdtEngine.Redo(pRecord); +} + +bool CFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) + return true; + return m_EdtEngine.Undo(pRecord); +} + +bool CFWL_Edit::Undo() { + if (!CanUndo()) + return false; + return Undo(m_DoRecords[m_iCurRecord--].get()); +} + +bool CFWL_Edit::Redo() { + if (!CanRedo()) + return false; + return Redo(m_DoRecords[++m_iCurRecord].get()); +} + +bool CFWL_Edit::CanUndo() { + return m_iCurRecord >= 0; +} + +bool CFWL_Edit::CanRedo() { + return m_iCurRecord < pdfium::CollectionSize(m_DoRecords) - 1; +} + +void CFWL_Edit::SetOuter(CFWL_Widget* pOuter) { + m_pOuter = pOuter; +} + +void CFWL_Edit::OnCaretChanged() { + if (m_rtEngine.IsEmpty()) + return; + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + return; + + bool bRepaintContent = UpdateOffset(); + UpdateCaret(); + CFX_RectF rtInvalid; + rtInvalid.Set(0, 0, 0, 0); + bool bRepaintScroll = false; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { + CFWL_ScrollBar* pScroll = UpdateScroll(); + if (pScroll) { + rtInvalid = pScroll->GetWidgetRect(); + bRepaintScroll = true; + } + } + if (bRepaintContent || bRepaintScroll) { + if (bRepaintContent) + rtInvalid.Union(m_rtEngine); + Repaint(&rtInvalid); + } +} + +void CFWL_Edit::OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask) + UpdateVAlignment(); + + CFX_RectF rtTemp; + GetClientRect(rtTemp); + + CFWL_EventTextChanged event(this); + event.wsPrevText = ChangeInfo.wsPrevText; + DispatchEvent(&event); + + LayoutScrollBar(); + Repaint(&rtTemp); +} + +void CFWL_Edit::OnSelChanged() { + CFX_RectF rtTemp; + GetClientRect(rtTemp); + Repaint(&rtTemp); +} + +bool CFWL_Edit::OnPageLoad(int32_t nPageIndex) { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); + if (!pPage) + return false; + + pPage->LoadPage(nullptr, nullptr); + return true; +} + +bool CFWL_Edit::OnPageUnload(int32_t nPageIndex) { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); + if (!pPage) + return false; + + pPage->UnloadPage(nullptr); + return true; +} + +void CFWL_Edit::OnAddDoRecord(std::unique_ptr pRecord) { + AddDoRecord(std::move(pRecord)); +} + +bool CFWL_Edit::OnValidate(const CFX_WideString& wsText) { + CFWL_Widget* pDst = GetOuter(); + if (!pDst) + pDst = this; + + CFWL_EventValidate event(this); + event.wsInsert = wsText; + event.bValidate = true; + DispatchEvent(&event); + return event.bValidate; +} + +void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { + m_fScrollOffsetY = fScrollOffset; +} + +void CFWL_Edit::DrawTextBk(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_bStaticBackground = false; + param.m_dwStates = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly + ? CFWL_PartState_ReadOnly + : CFWL_PartState_Normal; + uint32_t dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); + if (dwStates) + param.m_dwStates = CFWL_PartState_Disabled; + param.m_pGraphics = pGraphics; + param.m_matrix = *pMatrix; + param.m_rtPart = m_rtClient; + pTheme->DrawBackground(¶m); + + if (!IsShowScrollBar(true) || !IsShowScrollBar(false)) + return; + + CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect(); + + CFX_RectF rtStatic; + rtStatic.Set(m_rtClient.right() - rtScroll.height, + m_rtClient.bottom() - rtScroll.height, rtScroll.height, + rtScroll.height); + param.m_bStaticBackground = true; + param.m_bMaximize = true; + param.m_rtPart = rtStatic; + pTheme->DrawBackground(¶m); +} + +void CFWL_Edit::DrawContent(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return; + + pGraphics->SaveGraphState(); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) + pGraphics->SaveGraphState(); + + CFX_RectF rtClip = m_rtEngine; + FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; + FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; + CFX_Matrix mt; + mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); + if (pMatrix) { + pMatrix->TransformRect(rtClip); + mt.Concat(*pMatrix); + } + + bool bShowSel = (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoHideSel) || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); + if (bShowSel) { + CFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(this); + if (pForm) { + bShowSel = (pForm->GetStates() & FWL_WGTSTATE_Deactivated) != + FWL_WGTSTATE_Deactivated; + } + } + + int32_t nSelCount = m_EdtEngine.CountSelRanges(); + if (bShowSel && nSelCount > 0) { + int32_t nPageCharStart = pPage->GetCharStart(); + int32_t nPageCharCount = pPage->GetCharCount(); + int32_t nPageCharEnd = nPageCharStart + nPageCharCount - 1; + int32_t nCharCount; + int32_t nCharStart; + CFX_RectFArray rectArr; + int32_t i = 0; + for (i = 0; i < nSelCount; i++) { + nCharCount = m_EdtEngine.GetSelRange(i, &nCharStart); + int32_t nCharEnd = nCharStart + nCharCount - 1; + if (nCharEnd < nPageCharStart || nCharStart > nPageCharEnd) + continue; + + int32_t nBgn = std::max(nCharStart, nPageCharStart); + int32_t nEnd = std::min(nCharEnd, nPageCharEnd); + pPage->CalcRangeRectArray(nBgn - nPageCharStart, nEnd - nBgn + 1, + rectArr); + } + + int32_t nCount = rectArr.GetSize(); + CFX_Path path; + path.Create(); + for (i = 0; i < nCount; i++) { + rectArr[i].left += fOffSetX; + rectArr[i].top += fOffSetY; + path.AddRectangle(rectArr[i].left, rectArr[i].top, rectArr[i].width, + rectArr[i].height); + } + pGraphics->SetClipRect(rtClip); + + CFWL_ThemeBackground param; + param.m_pGraphics = pGraphics; + param.m_matrix = *pMatrix; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_pPath = &path; + pTheme->DrawBackground(¶m); + } + + CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice(); + if (!pRenderDev) + return; + + std::unique_ptr pRenderDevice( + new CFDE_RenderDevice(pRenderDev, false)); + std::unique_ptr pRenderContext(new CFDE_RenderContext); + pRenderDevice->SetClipRect(rtClip); + pRenderContext->StartRender(pRenderDevice.get(), pPage, mt); + pRenderContext->DoRender(nullptr); + + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { + pGraphics->RestoreGraphState(); + CFX_Path path; + path.Create(); + int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1; + FX_FLOAT fStep = m_rtEngine.width / iLimit; + FX_FLOAT fLeft = m_rtEngine.left + 1; + for (int32_t i = 1; i < iLimit; i++) { + fLeft += fStep; + path.AddLine(fLeft, m_rtClient.top, fLeft, m_rtClient.bottom()); + } + + CFWL_ThemeBackground param; + param.m_pGraphics = pGraphics; + param.m_matrix = *pMatrix; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::CombTextLine; + param.m_pPath = &path; + pTheme->DrawBackground(¶m); + } + pGraphics->RestoreGraphState(); +} + +void CFWL_Edit::UpdateEditEngine() { + UpdateEditParams(); + UpdateEditLayout(); + if (m_nLimit > -1) + m_EdtEngine.SetLimit(m_nLimit); +} + +void CFWL_Edit::UpdateEditParams() { + FDE_TXTEDTPARAMS params; + params.nHorzScale = 100; + params.fPlateWidth = m_rtEngine.width; + params.fPlateHeight = m_rtEngine.height; + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_RTLLayout) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_RTL; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalLayout) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_DocVertical; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalChars) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CharVertial; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReverseLine) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LineReserve; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ArabicShapes) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ArabicShapes; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ExpandTab) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ExpandTab; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CombText; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_LastLineHeight) + params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LastLineHeight; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Validate) + params.dwMode |= FDE_TEXTEDITMODE_Validate; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Password) + params.dwMode |= FDE_TEXTEDITMODE_Password; + + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignMask) { + case FWL_STYLEEXT_EDT_HNear: { + params.dwAlignment |= FDE_TEXTEDITALIGN_Left; + break; + } + case FWL_STYLEEXT_EDT_HCenter: { + params.dwAlignment |= FDE_TEXTEDITALIGN_Center; + break; + } + case FWL_STYLEEXT_EDT_HFar: { + params.dwAlignment |= FDE_TEXTEDITALIGN_Right; + break; + } + default: + break; + } + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignModeMask) { + case FWL_STYLEEXT_EDT_Justified: { + params.dwAlignment |= FDE_TEXTEDITALIGN_Justified; + break; + } + case FWL_STYLEEXT_EDT_Distributed: { + params.dwAlignment |= FDE_TEXTEDITALIGN_Distributed; + break; + } + default: { + params.dwAlignment |= FDE_TEXTEDITALIGN_Normal; + break; + } + } + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { + params.dwMode |= FDE_TEXTEDITMODE_MultiLines; + if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) == 0 && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) { + params.dwMode |= + FDE_TEXTEDITMODE_AutoLineWrap | FDE_TEXTEDITMODE_LimitArea_Horz; + } + if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) == 0 && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoVScroll) == 0) { + params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Vert; + } else { + params.fPlateHeight = 0x00FFFFFF; + } + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == + 0) { + params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Horz; + } + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { + params.dwMode |= FDE_TEXTEDITMODE_ReadOnly; + } + + FX_FLOAT* pFontSize = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); + if (!pFontSize) + return; + + m_fFontSize = *pFontSize; + uint32_t* pFontColor = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::TextColor)); + if (!pFontColor) + return; + + params.dwFontColor = *pFontColor; + FX_FLOAT* pLineHeight = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::LineHeight)); + if (!pLineHeight) + return; + + params.fLineSpace = *pLineHeight; + CFGAS_GEFont* pFont = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::Font)); + if (!pFont) + return; + + params.pFont = pFont; + params.fFontSize = m_fFontSize; + params.nLineCount = (int32_t)(params.fPlateHeight / params.fLineSpace); + if (params.nLineCount <= 0) + params.nLineCount = 1; + params.fTabWidth = params.fFontSize * 1; + params.bTabEquidistant = true; + params.wLineBreakChar = L'\n'; + params.nCharRotation = 0; + params.pEventSink = this; + m_EdtEngine.SetEditParams(params); +} + +void CFWL_Edit::UpdateEditLayout() { + if (m_EdtEngine.GetTextLength() <= 0) + m_EdtEngine.SetTextByStream(nullptr); + + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (pPage) + pPage->UnloadPage(nullptr); + + m_EdtEngine.StartLayout(); + m_EdtEngine.DoLayout(nullptr); + m_EdtEngine.EndLayout(); + pPage = m_EdtEngine.GetPage(0); + if (pPage) + pPage->LoadPage(nullptr, nullptr); +} + +bool CFWL_Edit::UpdateOffset() { + CFX_RectF rtCaret; + m_EdtEngine.GetCaretRect(rtCaret); + FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; + FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; + rtCaret.Offset(fOffSetX, fOffSetY); + const CFX_RectF& rtEidt = m_rtEngine; + if (rtEidt.Contains(rtCaret)) { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return false; + + CFX_RectF rtFDE = pPage->GetContentsBox(); + rtFDE.Offset(fOffSetX, fOffSetY); + if (rtFDE.right() < rtEidt.right() && m_fScrollOffsetX > 0) { + m_fScrollOffsetX += rtFDE.right() - rtEidt.right(); + m_fScrollOffsetX = std::max(m_fScrollOffsetX, 0.0f); + } + if (rtFDE.bottom() < rtEidt.bottom() && m_fScrollOffsetY > 0) { + m_fScrollOffsetY += rtFDE.bottom() - rtEidt.bottom(); + m_fScrollOffsetY = std::max(m_fScrollOffsetY, 0.0f); + } + return false; + } + + FX_FLOAT offsetX = 0.0; + FX_FLOAT offsetY = 0.0; + if (rtCaret.left < rtEidt.left) + offsetX = rtCaret.left - rtEidt.left; + if (rtCaret.right() > rtEidt.right()) + offsetX = rtCaret.right() - rtEidt.right(); + if (rtCaret.top < rtEidt.top) + offsetY = rtCaret.top - rtEidt.top; + if (rtCaret.bottom() > rtEidt.bottom()) + offsetY = rtCaret.bottom() - rtEidt.bottom(); + m_fScrollOffsetX += offsetX; + m_fScrollOffsetY += offsetY; + if (m_fFontSize > m_rtEngine.height) + m_fScrollOffsetY = 0; + return true; +} + +bool CFWL_Edit::UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged) { + if (pScrollBar == m_pHorzScrollBar.get()) + m_fScrollOffsetX += fPosChanged; + else + m_fScrollOffsetY += fPosChanged; + return true; +} + +void CFWL_Edit::UpdateVAlignment() { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return; + + const CFX_RectF& rtFDE = pPage->GetContentsBox(); + FX_FLOAT fOffsetY = 0.0f; + FX_FLOAT fSpaceAbove = 0.0f; + FX_FLOAT fSpaceBelow = 0.0f; + CFX_SizeF* pSpace = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::SpaceAboveBelow)); + if (pSpace) { + fSpaceAbove = pSpace->x; + fSpaceBelow = pSpace->y; + } + if (fSpaceAbove < 0.1f) + fSpaceAbove = 0; + if (fSpaceBelow < 0.1f) + fSpaceBelow = 0; + + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VCenter) { + fOffsetY = (m_rtEngine.height - rtFDE.height) / 2; + if (fOffsetY < (fSpaceAbove + fSpaceBelow) / 2 && + fSpaceAbove < fSpaceBelow) { + return; + } + fOffsetY += (fSpaceAbove - fSpaceBelow) / 2; + } else if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VFar) { + fOffsetY = (m_rtEngine.height - rtFDE.height); + fOffsetY -= fSpaceBelow; + } else { + fOffsetY += fSpaceAbove; + } + m_fVAlignOffset = std::max(fOffsetY, 0.0f); +} + +void CFWL_Edit::UpdateCaret() { + CFX_RectF rtFDE; + m_EdtEngine.GetCaretRect(rtFDE); + + rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX, + m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset); + CFX_RectF rtCaret; + rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height); + + CFX_RectF rtClient; + GetClientRect(rtClient); + rtCaret.Intersect(rtClient); + + if (rtCaret.left > rtClient.right()) { + FX_FLOAT right = rtCaret.right(); + rtCaret.left = rtClient.right() - 1; + rtCaret.width = right - rtCaret.left; + } + + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty()) + ShowCaret(&rtCaret); + else + HideCaret(&rtCaret); +} + +CFWL_ScrollBar* CFWL_Edit::UpdateScroll() { + bool bShowHorz = + m_pHorzScrollBar && + ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); + bool bShowVert = + m_pVertScrollBar && + ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); + if (!bShowHorz && !bShowVert) + return nullptr; + + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return nullptr; + + const CFX_RectF& rtFDE = pPage->GetContentsBox(); + CFWL_ScrollBar* pRepaint = nullptr; + if (bShowHorz) { + CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect(); + if (rtScroll.width < rtFDE.width) { + m_pHorzScrollBar->LockUpdate(); + FX_FLOAT fRange = rtFDE.width - rtScroll.width; + m_pHorzScrollBar->SetRange(0.0f, fRange); + + FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetX, 0.0f), fRange); + m_pHorzScrollBar->SetPos(fPos); + m_pHorzScrollBar->SetTrackPos(fPos); + m_pHorzScrollBar->SetPageSize(rtScroll.width); + m_pHorzScrollBar->SetStepSize(rtScroll.width / 10); + m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Disabled); + m_pHorzScrollBar->UnlockUpdate(); + m_pHorzScrollBar->Update(); + pRepaint = m_pHorzScrollBar.get(); + } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { + m_pHorzScrollBar->LockUpdate(); + m_pHorzScrollBar->SetRange(0, -1); + m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled); + m_pHorzScrollBar->UnlockUpdate(); + m_pHorzScrollBar->Update(); + pRepaint = m_pHorzScrollBar.get(); + } + } + + if (bShowVert) { + CFX_RectF rtScroll = m_pVertScrollBar->GetWidgetRect(); + if (rtScroll.height < rtFDE.height) { + m_pVertScrollBar->LockUpdate(); + FX_FLOAT fStep = m_EdtEngine.GetEditParams()->fLineSpace; + FX_FLOAT fRange = std::max(rtFDE.height - m_rtEngine.height, fStep); + + m_pVertScrollBar->SetRange(0.0f, fRange); + FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetY, 0.0f), fRange); + m_pVertScrollBar->SetPos(fPos); + m_pVertScrollBar->SetTrackPos(fPos); + m_pVertScrollBar->SetPageSize(rtScroll.height); + m_pVertScrollBar->SetStepSize(fStep); + m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Disabled); + m_pVertScrollBar->UnlockUpdate(); + m_pVertScrollBar->Update(); + pRepaint = m_pVertScrollBar.get(); + } else if ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { + m_pVertScrollBar->LockUpdate(); + m_pVertScrollBar->SetRange(0, -1); + m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled); + m_pVertScrollBar->UnlockUpdate(); + m_pVertScrollBar->Update(); + pRepaint = m_pVertScrollBar.get(); + } + } + return pRepaint; +} + +bool CFWL_Edit::IsShowScrollBar(bool bVert) { + bool bShow = + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) + ? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == + FWL_WGTSTATE_Focused + : true; + if (bVert) { + return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) && + IsContentHeightOverflow(); + } + return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine); +} + +bool CFWL_Edit::IsContentHeightOverflow() { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return false; + return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f; +} + +int32_t CFWL_Edit::AddDoRecord(std::unique_ptr pRecord) { + int32_t nCount = pdfium::CollectionSize(m_DoRecords); + if (m_iCurRecord == nCount - 1) { + if (nCount == m_iMaxRecord) { + m_DoRecords.pop_front(); + m_iCurRecord--; + } + } else { + m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, + m_DoRecords.end()); + } + + m_DoRecords.push_back(std::move(pRecord)); + m_iCurRecord = pdfium::CollectionSize(m_DoRecords) - 1; + return m_iCurRecord; +} + +void CFWL_Edit::Layout() { + GetClientRect(m_rtClient); + m_rtEngine = m_rtClient; + FX_FLOAT* pfWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pfWidth) + return; + + FX_FLOAT fWidth = *pfWidth; + if (!m_pOuter) { + CFX_RectF* pUIMargin = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); + if (pUIMargin) { + m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, + pUIMargin->height); + } + } else if (m_pOuter->GetClassID() == FWL_Type::DateTimePicker) { + CFWL_ThemePart part; + part.m_pWidget = m_pOuter; + CFX_RectF* pUIMargin = + static_cast(m_pOuter->GetThemeProvider()->GetCapacity( + &part, CFWL_WidgetCapacity::UIMargin)); + if (pUIMargin) { + m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, + pUIMargin->height); + } + } + + bool bShowVertScrollbar = IsShowScrollBar(true); + bool bShowHorzScrollbar = IsShowScrollBar(false); + if (bShowVertScrollbar) { + InitVerticalScrollBar(); + + CFX_RectF rtVertScr; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { + rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, + m_rtClient.height); + } else { + rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, + m_rtClient.height); + if (bShowHorzScrollbar) + rtVertScr.height -= fWidth; + m_rtEngine.width -= fWidth; + } + + m_pVertScrollBar->SetWidgetRect(rtVertScr); + m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + m_pVertScrollBar->Update(); + } else if (m_pVertScrollBar) { + m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + + if (bShowHorzScrollbar) { + InitHorizontalScrollBar(); + + CFX_RectF rtHoriScr; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { + rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, + m_rtClient.width, fWidth); + } else { + rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, + m_rtClient.width, fWidth); + if (bShowVertScrollbar) + rtHoriScr.width -= fWidth; + m_rtEngine.height -= fWidth; + } + m_pHorzScrollBar->SetWidgetRect(rtHoriScr); + m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + m_pHorzScrollBar->Update(); + } else if (m_pHorzScrollBar) { + m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } +} + +void CFWL_Edit::LayoutScrollBar() { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) == + 0) { + return; + } + + FX_FLOAT* pfWidth = nullptr; + bool bShowVertScrollbar = IsShowScrollBar(true); + bool bShowHorzScrollbar = IsShowScrollBar(false); + if (bShowVertScrollbar) { + if (!m_pVertScrollBar) { + pfWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; + InitVerticalScrollBar(); + CFX_RectF rtVertScr; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { + rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, + m_rtClient.height); + } else { + rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, + m_rtClient.height); + if (bShowHorzScrollbar) + rtVertScr.height -= fWidth; + } + m_pVertScrollBar->SetWidgetRect(rtVertScr); + m_pVertScrollBar->Update(); + } + m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + } else if (m_pVertScrollBar) { + m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + + if (bShowHorzScrollbar) { + if (!m_pHorzScrollBar) { + if (!pfWidth) { + pfWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + } + + FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; + InitHorizontalScrollBar(); + CFX_RectF rtHoriScr; + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { + rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, + m_rtClient.width, fWidth); + } else { + rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, + m_rtClient.width, fWidth); + if (bShowVertScrollbar) + rtHoriScr.width -= (fWidth); + } + m_pHorzScrollBar->SetWidgetRect(rtHoriScr); + m_pHorzScrollBar->Update(); + } + m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + } else if (m_pHorzScrollBar) { + m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + if (bShowVertScrollbar || bShowHorzScrollbar) + UpdateScroll(); +} + +void CFWL_Edit::DeviceToEngine(CFX_PointF& pt) { + pt.x += m_fScrollOffsetX - m_rtEngine.left; + pt.y += m_fScrollOffsetY - m_rtEngine.top - m_fVAlignOffset; +} + +void CFWL_Edit::InitVerticalScrollBar() { + if (m_pVertScrollBar) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert; + prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; + prop->m_pParent = this; + prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; + m_pVertScrollBar = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); +} + +void CFWL_Edit::InitHorizontalScrollBar() { + if (m_pHorzScrollBar) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz; + prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; + prop->m_pParent = this; + prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; + m_pHorzScrollBar = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); +} + +void CFWL_Edit::ShowCaret(CFX_RectF* pRect) { + if (m_pCaret) { + m_pCaret->ShowCaret(); + if (!pRect->IsEmpty()) + m_pCaret->SetWidgetRect(*pRect); + Repaint(&m_rtEngine); + return; + } + + CFWL_Widget* pOuter = this; + pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); + while (pOuter->GetOuter()) { + pOuter = pOuter->GetOuter(); + + CFX_RectF rtOuter = pOuter->GetWidgetRect(); + pRect->Offset(rtOuter.left, rtOuter.top); + } + + CXFA_FFWidget* pXFAWidget = + static_cast(pOuter->GetLayoutItem()); + if (!pXFAWidget) + return; + + IXFA_DocEnvironment* pDocEnvironment = + pXFAWidget->GetDoc()->GetDocEnvironment(); + if (!pDocEnvironment) + return; + + CFX_Matrix mt; + pXFAWidget->GetRotateMatrix(mt); + + CFX_RectF rt(*pRect); + mt.TransformRect(rt); + pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt); +} + +void CFWL_Edit::HideCaret(CFX_RectF* pRect) { + if (m_pCaret) { + m_pCaret->HideCaret(); + Repaint(&m_rtEngine); + return; + } + + CFWL_Widget* pOuter = this; + while (pOuter->GetOuter()) + pOuter = pOuter->GetOuter(); + + CXFA_FFWidget* pXFAWidget = + static_cast(pOuter->GetLayoutItem()); + if (!pXFAWidget) + return; + + IXFA_DocEnvironment* pDocEnvironment = + pXFAWidget->GetDoc()->GetDocEnvironment(); + if (!pDocEnvironment) + return; + + pDocEnvironment->DisplayCaret(pXFAWidget, false, pRect); +} + +bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { + if (!m_bSetRange) + return true; + + CFX_WideString wsText = m_EdtEngine.GetText(0, -1); + if (wsText.IsEmpty()) { + if (cNum == L'0') + return false; + return true; + } + + int32_t caretPos = m_EdtEngine.GetCaretPos(); + if (CountSelRanges() == 0) { + if (cNum == L'0' && caretPos == 0) + return false; + + int32_t nLen = wsText.GetLength(); + CFX_WideString l = wsText.Mid(0, caretPos); + CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos); + CFX_WideString wsNew = l + cNum + r; + if (wsNew.GetInteger() <= m_iMax) + return true; + return false; + } + + if (wsText.GetInteger() <= m_iMax) + return true; + return false; +} + +void CFWL_Edit::InitCaret() { + if (!m_pCaret) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { + m_pCaret = pdfium::MakeUnique( + m_pOwnerApp, pdfium::MakeUnique(), this); + m_pCaret->SetParent(this); + m_pCaret->SetStates(m_pProperties->m_dwStates); + } + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) == + 0) { + m_pCaret.reset(); + } +} + +void CFWL_Edit::ClearRecord() { + m_iCurRecord = -1; + m_DoRecords.clear(); +} + +void CFWL_Edit::ProcessInsertError(int32_t iError) { + if (iError != -2) + return; + + CFWL_Event textFullEvent(CFWL_Event::Type::TextFull, this); + DispatchEvent(&textFullEvent); +} + +void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + OnFocusChanged(pMessage, true); + break; + case CFWL_Message::Type::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::LeftButtonDblClk: + OnButtonDblClk(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::RightButtonDown: + DoButtonDown(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: { + CFWL_MessageKey* pKey = static_cast(pMessage); + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) + OnKeyDown(pKey); + else if (pKey->m_dwCmd == FWL_KeyCommand::Char) + OnChar(pKey); + break; + } + default: + break; + } + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { + if (!pEvent) + return; + if (pEvent->GetType() != CFWL_Event::Type::Scroll) + return; + + CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; + if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || + (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { + CFWL_EventScroll* pScrollEvent = static_cast(pEvent); + OnScroll(static_cast(pSrcTarget), + pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); + } +} + +void CFWL_Edit::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_Edit::DoButtonDown(CFWL_MessageMouse* pMsg) { + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + SetFocus(true); + + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return; + + CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); + DeviceToEngine(pt); + bool bBefore = true; + int32_t nIndex = pPage->GetCharIndex(pt, bBefore); + if (nIndex < 0) + nIndex = 0; + + m_EdtEngine.SetCaretPos(nIndex, bBefore); +} + +void CFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + uint32_t dwStyleEx = GetStylesEx(); + bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret); + if (bSet) { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + + UpdateVAlignment(); + UpdateOffset(); + UpdateCaret(); + } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + HideCaret(nullptr); + if ((dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) { + int32_t nSel = CountSelRanges(); + if (nSel > 0) { + ClearSelections(); + bRepaint = true; + } + m_EdtEngine.SetCaretPos(0, true); + UpdateOffset(); + } + ClearRecord(); + } + + LayoutScrollBar(); + if (!bRepaint) + return; + + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + Repaint(&rtInvalidate); +} + +void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + return; + + m_bLButtonDown = true; + SetGrab(true); + DoButtonDown(pMsg); + int32_t nIndex = m_EdtEngine.GetCaretPos(); + bool bRepaint = false; + if (m_EdtEngine.CountSelRanges() > 0) { + m_EdtEngine.ClearSelection(); + bRepaint = true; + } + + if ((pMsg->m_dwFlags & FWL_KEYFLAG_Shift) && m_nSelStart != nIndex) { + int32_t iStart = std::min(m_nSelStart, nIndex); + int32_t iEnd = std::max(m_nSelStart, nIndex); + m_EdtEngine.AddSelRange(iStart, iEnd - iStart); + bRepaint = true; + } else { + m_nSelStart = nIndex; + } + if (bRepaint) + Repaint(&m_rtEngine); +} + +void CFWL_Edit::OnLButtonUp(CFWL_MessageMouse* pMsg) { + m_bLButtonDown = false; + SetGrab(false); +} + +void CFWL_Edit::OnButtonDblClk(CFWL_MessageMouse* pMsg) { + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return; + + CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); + DeviceToEngine(pt); + int32_t nCount = 0; + int32_t nIndex = pPage->SelectWord(pt, nCount); + if (nIndex < 0) + return; + + m_EdtEngine.AddSelRange(nIndex, nCount); + m_EdtEngine.SetCaretPos(nIndex + nCount - 1, false); + Repaint(&m_rtEngine); +} + +void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) { + if (m_nSelStart == -1 || !m_bLButtonDown) + return; + + IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); + if (!pPage) + return; + + CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); + DeviceToEngine(pt); + bool bBefore = true; + int32_t nIndex = pPage->GetCharIndex(pt, bBefore); + m_EdtEngine.SetCaretPos(nIndex, bBefore); + nIndex = m_EdtEngine.GetCaretPos(); + m_EdtEngine.ClearSelection(); + + if (nIndex == m_nSelStart) + return; + + int32_t nLen = m_EdtEngine.GetTextLength(); + if (m_nSelStart >= nLen) + m_nSelStart = nLen; + + m_EdtEngine.AddSelRange(std::min(m_nSelStart, nIndex), + FXSYS_abs(nIndex - m_nSelStart)); +} + +void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) { + FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone; + bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); + bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); + uint32_t dwKeyCode = pMsg->m_dwKeyCode; + switch (dwKeyCode) { + case FWL_VKEY_Left: { + MoveCaret = MC_Left; + break; + } + case FWL_VKEY_Right: { + MoveCaret = MC_Right; + break; + } + case FWL_VKEY_Up: { + MoveCaret = MC_Up; + break; + } + case FWL_VKEY_Down: { + MoveCaret = MC_Down; + break; + } + case FWL_VKEY_Home: { + MoveCaret = bCtrl ? MC_Home : MC_LineStart; + break; + } + case FWL_VKEY_End: { + MoveCaret = bCtrl ? MC_End : MC_LineEnd; + break; + } + case FWL_VKEY_Insert: + break; + case FWL_VKEY_Delete: { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { + break; + } + int32_t nCaret = m_EdtEngine.GetCaretPos(); +#if (_FX_OS_ == _FX_MACOSX_) + m_EdtEngine.Delete(nCaret, true); +#else + m_EdtEngine.Delete(nCaret); +#endif + break; + } + case FWL_VKEY_F2: + case FWL_VKEY_Tab: + default: + break; + } + if (MoveCaret != MC_MoveNone) + m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl); +} + +void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { + return; + } + + int32_t iError = 0; + FX_WCHAR c = static_cast(pMsg->m_dwKeyCode); + int32_t nCaret = m_EdtEngine.GetCaretPos(); + switch (c) { + case FWL_VKEY_Back: + m_EdtEngine.Delete(nCaret, true); + break; + case FWL_VKEY_NewLine: + case FWL_VKEY_Escape: + break; + case FWL_VKEY_Tab: { + iError = m_EdtEngine.Insert(nCaret, L"\t", 1); + break; + } + case FWL_VKEY_Return: { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) { + iError = m_EdtEngine.Insert(nCaret, L"\n", 1); + } + break; + } + default: { + if (!m_pWidgetMgr->IsFormDisabled()) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Number) { + if (((pMsg->m_dwKeyCode < FWL_VKEY_0) && + (pMsg->m_dwKeyCode != 0x2E && pMsg->m_dwKeyCode != 0x2D)) || + pMsg->m_dwKeyCode > FWL_VKEY_9) { + break; + } + if (!ValidateNumberChar(c)) + break; + } + } +#if (_FX_OS_ == _FX_MACOSX_) + if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) +#else + if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) +#endif + { + break; + } + iError = m_EdtEngine.Insert(nCaret, &c, 1); + break; + } + } + if (iError < 0) + ProcessInsertError(iError); +} + +bool CFWL_Edit::OnScroll(CFWL_ScrollBar* pScrollBar, + CFWL_EventScroll::Code dwCode, + FX_FLOAT fPos) { + CFX_SizeF fs; + pScrollBar->GetRange(&fs.x, &fs.y); + FX_FLOAT iCurPos = pScrollBar->GetPos(); + FX_FLOAT fStep = pScrollBar->GetStepSize(); + switch (dwCode) { + case CFWL_EventScroll::Code::Min: { + fPos = fs.x; + break; + } + case CFWL_EventScroll::Code::Max: { + fPos = fs.y; + break; + } + case CFWL_EventScroll::Code::StepBackward: { + fPos -= fStep; + if (fPos < fs.x + fStep / 2) { + fPos = fs.x; + } + break; + } + case CFWL_EventScroll::Code::StepForward: { + fPos += fStep; + if (fPos > fs.y - fStep / 2) { + fPos = fs.y; + } + break; + } + case CFWL_EventScroll::Code::PageBackward: { + fPos -= pScrollBar->GetPageSize(); + if (fPos < fs.x) { + fPos = fs.x; + } + break; + } + case CFWL_EventScroll::Code::PageForward: { + fPos += pScrollBar->GetPageSize(); + if (fPos > fs.y) { + fPos = fs.y; + } + break; + } + case CFWL_EventScroll::Code::Pos: + case CFWL_EventScroll::Code::TrackPos: + case CFWL_EventScroll::Code::None: + break; + case CFWL_EventScroll::Code::EndScroll: + return false; + } + if (iCurPos == fPos) + return true; + + pScrollBar->SetPos(fPos); + pScrollBar->SetTrackPos(fPos); + UpdateOffset(pScrollBar, fPos - iCurPos); + UpdateCaret(); + + CFX_RectF rect = GetWidgetRect(); + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); + Repaint(&rtInvalidate); + return true; +} diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h new file mode 100644 index 0000000000..f975bb2ba4 --- /dev/null +++ b/xfa/fwl/cfwl_edit.h @@ -0,0 +1,191 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EDIT_H_ +#define XFA_FWL_CFWL_EDIT_H_ + +#include +#include +#include + +#include "xfa/fde/cfde_txtedtengine.h" +#include "xfa/fde/ifde_txtedtdorecord.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_scrollbar.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxgraphics/cfx_path.h" + +#define FWL_STYLEEXT_EDT_ReadOnly (1L << 0) +#define FWL_STYLEEXT_EDT_MultiLine (1L << 1) +#define FWL_STYLEEXT_EDT_WantReturn (1L << 2) +#define FWL_STYLEEXT_EDT_NoHideSel (1L << 3) +#define FWL_STYLEEXT_EDT_AutoHScroll (1L << 4) +#define FWL_STYLEEXT_EDT_AutoVScroll (1L << 5) +#define FWL_STYLEEXT_EDT_NoRedoUndo (1L << 6) +#define FWL_STYLEEXT_EDT_Validate (1L << 7) +#define FWL_STYLEEXT_EDT_Password (1L << 8) +#define FWL_STYLEEXT_EDT_Number (1L << 9) +#define FWL_STYLEEXT_EDT_VerticalLayout (1L << 12) +#define FWL_STYLEEXT_EDT_VerticalChars (1L << 13) +#define FWL_STYLEEXT_EDT_ReverseLine (1L << 14) +#define FWL_STYLEEXT_EDT_ArabicShapes (1L << 15) +#define FWL_STYLEEXT_EDT_ExpandTab (1L << 16) +#define FWL_STYLEEXT_EDT_CombText (1L << 17) +#define FWL_STYLEEXT_EDT_HNear (0L << 18) +#define FWL_STYLEEXT_EDT_HCenter (1L << 18) +#define FWL_STYLEEXT_EDT_HFar (2L << 18) +#define FWL_STYLEEXT_EDT_VNear (0L << 20) +#define FWL_STYLEEXT_EDT_VCenter (1L << 20) +#define FWL_STYLEEXT_EDT_VFar (2L << 20) +#define FWL_STYLEEXT_EDT_Justified (1L << 22) +#define FWL_STYLEEXT_EDT_Distributed (2L << 22) +#define FWL_STYLEEXT_EDT_HAlignMask (3L << 18) +#define FWL_STYLEEXT_EDT_VAlignMask (3L << 20) +#define FWL_STYLEEXT_EDT_HAlignModeMask (3L << 22) +#define FWL_STYLEEXT_EDT_InnerCaret (1L << 24) +#define FWL_STYLEEXT_EDT_ShowScrollbarFocus (1L << 25) +#define FWL_STYLEEXT_EDT_OuterScrollbar (1L << 26) +#define FWL_STYLEEXT_EDT_LastLineHeight (1L << 27) + +class IFDE_TxtEdtDoRecord; +class CFWL_Edit; +class CFWL_MessageMouse; +class CFWL_WidgetProperties; +class CFWL_Caret; + +class CFWL_Edit : public CFWL_Widget { + public: + CFWL_Edit(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_Edit() override; + + // CFWL_Widget: + FWL_Type GetClassID() const override; + CFX_RectF GetAutosizedWidgetRect() override; + CFX_RectF GetWidgetRect() override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void SetStates(uint32_t dwStates) override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + virtual void SetText(const CFX_WideString& wsText); + + int32_t GetTextLength() const; + CFX_WideString GetText() const; + void ClearText(); + + void AddSelRange(int32_t nStart); + int32_t CountSelRanges() const; + int32_t GetSelRange(int32_t nIndex, int32_t* nStart) const; + void ClearSelections(); + int32_t GetLimit() const; + void SetLimit(int32_t nLimit); + void SetAliasChar(FX_WCHAR wAlias); + bool Copy(CFX_WideString& wsCopy); + bool Cut(CFX_WideString& wsCut); + bool Paste(const CFX_WideString& wsPaste); + bool Redo(const IFDE_TxtEdtDoRecord* pRecord); + bool Undo(const IFDE_TxtEdtDoRecord* pRecord); + bool Undo(); + bool Redo(); + bool CanUndo(); + bool CanRedo(); + + void SetOuter(CFWL_Widget* pOuter); + + void OnCaretChanged(); + void OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo); + void OnSelChanged(); + bool OnPageLoad(int32_t nPageIndex); + bool OnPageUnload(int32_t nPageIndex); + void OnAddDoRecord(std::unique_ptr pRecord); + bool OnValidate(const CFX_WideString& wsText); + void SetScrollOffset(FX_FLOAT fScrollOffset); + + protected: + void ShowCaret(CFX_RectF* pRect); + void HideCaret(CFX_RectF* pRect); + const CFX_RectF& GetRTClient() const { return m_rtClient; } + CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } + + private: + void DrawTextBk(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawContent(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawSpellCheck(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + + void UpdateEditEngine(); + void UpdateEditParams(); + void UpdateEditLayout(); + bool UpdateOffset(); + bool UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); + void UpdateVAlignment(); + void UpdateCaret(); + CFWL_ScrollBar* UpdateScroll(); + void Layout(); + void LayoutScrollBar(); + void DeviceToEngine(CFX_PointF& pt); + void InitVerticalScrollBar(); + void InitHorizontalScrollBar(); + void InitEngine(); + void InitCaret(); + bool ValidateNumberChar(FX_WCHAR cNum); + void ClearRecord(); + bool IsShowScrollBar(bool bVert); + bool IsContentHeightOverflow(); + int32_t AddDoRecord(std::unique_ptr pRecord); + void ProcessInsertError(int32_t iError); + void AddSpellCheckObj(CFX_Path& PathData, + int32_t nStart, + int32_t nCount, + FX_FLOAT fOffSetX, + FX_FLOAT fOffSetY); + + void DoButtonDown(CFWL_MessageMouse* pMsg); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnButtonDblClk(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnKeyDown(CFWL_MessageKey* pMsg); + void OnChar(CFWL_MessageKey* pMsg); + bool OnScroll(CFWL_ScrollBar* pScrollBar, + CFWL_EventScroll::Code dwCode, + FX_FLOAT fPos); + + CFX_RectF m_rtClient; + CFX_RectF m_rtEngine; + CFX_RectF m_rtStatic; + FX_FLOAT m_fVAlignOffset; + FX_FLOAT m_fScrollOffsetX; + FX_FLOAT m_fScrollOffsetY; + CFDE_TxtEdtEngine m_EdtEngine; + bool m_bLButtonDown; + int32_t m_nSelStart; + int32_t m_nLimit; + FX_FLOAT m_fFontSize; + bool m_bSetRange; + int32_t m_iMax; + std::unique_ptr m_pVertScrollBar; + std::unique_ptr m_pHorzScrollBar; + std::unique_ptr m_pCaret; + CFX_WideString m_wsCache; + CFX_WideString m_wsFont; + std::deque> m_DoRecords; + int32_t m_iCurRecord; + int32_t m_iMaxRecord; +}; + +#endif // XFA_FWL_CFWL_EDIT_H_ diff --git a/xfa/fwl/cfwl_event.cpp b/xfa/fwl/cfwl_event.cpp new file mode 100644 index 0000000000..827ecccc10 --- /dev/null +++ b/xfa/fwl/cfwl_event.cpp @@ -0,0 +1,20 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_event.h" + +CFWL_Event::CFWL_Event(CFWL_Event::Type type) + : CFWL_Event(type, nullptr, nullptr) {} + +CFWL_Event::CFWL_Event(Type type, CFWL_Widget* pSrcTarget) + : CFWL_Event(type, pSrcTarget, nullptr) {} + +CFWL_Event::CFWL_Event(Type type, + CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : m_pSrcTarget(pSrcTarget), m_pDstTarget(pDstTarget), m_type(type) {} + +CFWL_Event::~CFWL_Event() {} diff --git a/xfa/fwl/cfwl_event.h b/xfa/fwl/cfwl_event.h new file mode 100644 index 0000000000..9a9f30ab47 --- /dev/null +++ b/xfa/fwl/cfwl_event.h @@ -0,0 +1,52 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENT_H_ +#define XFA_FWL_CFWL_EVENT_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/fwl_error.h" + +class CFX_Graphics; +class CFWL_Widget; + +class CFWL_Event { + public: + enum class Type { + CheckStateChanged, + CheckWord, + Click, + Close, + EditChanged, + Mouse, + PostDropDown, + PreDropDown, + Scroll, + SelectChanged, + TextChanged, + TextFull, + Validate + }; + + explicit CFWL_Event(Type type); + CFWL_Event(Type type, CFWL_Widget* pSrcTarget); + CFWL_Event(Type type, CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + virtual ~CFWL_Event(); + + Type GetType() const { return m_type; } + + CFWL_Widget* m_pSrcTarget; + CFWL_Widget* m_pDstTarget; + + private: + Type m_type; +}; + +#endif // XFA_FWL_CFWL_EVENT_H_ diff --git a/xfa/fwl/cfwl_eventcheckword.cpp b/xfa/fwl/cfwl_eventcheckword.cpp new file mode 100644 index 0000000000..fb0ce6e77e --- /dev/null +++ b/xfa/fwl/cfwl_eventcheckword.cpp @@ -0,0 +1,12 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventcheckword.h" + +CFWL_EventCheckWord::CFWL_EventCheckWord(CFWL_Widget* pSrcTarget) + : CFWL_Event(CFWL_Event::Type::CheckWord, pSrcTarget) {} + +CFWL_EventCheckWord::~CFWL_EventCheckWord() {} diff --git a/xfa/fwl/cfwl_eventcheckword.h b/xfa/fwl/cfwl_eventcheckword.h new file mode 100644 index 0000000000..3de1e75c24 --- /dev/null +++ b/xfa/fwl/cfwl_eventcheckword.h @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTCHECKWORD_H_ +#define XFA_FWL_CFWL_EVENTCHECKWORD_H_ + +#include "xfa/fwl/cfwl_event.h" + +class CFWL_EventCheckWord : public CFWL_Event { + public: + explicit CFWL_EventCheckWord(CFWL_Widget* pSrcTarget); + ~CFWL_EventCheckWord() override; + + CFX_ByteString bsWord; + bool bCheckWord; +}; + +#endif // XFA_FWL_CFWL_EVENTCHECKWORD_H_ diff --git a/xfa/fwl/cfwl_eventmouse.cpp b/xfa/fwl/cfwl_eventmouse.cpp new file mode 100644 index 0000000000..3f8c7734c4 --- /dev/null +++ b/xfa/fwl/cfwl_eventmouse.cpp @@ -0,0 +1,16 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventmouse.h" + +CFWL_EventMouse::CFWL_EventMouse(CFWL_Widget* pSrcTarget) + : CFWL_EventMouse(pSrcTarget, nullptr) {} + +CFWL_EventMouse::CFWL_EventMouse(CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : CFWL_Event(CFWL_Event::Type::Mouse, pSrcTarget, pDstTarget) {} + +CFWL_EventMouse::~CFWL_EventMouse() {} diff --git a/xfa/fwl/cfwl_eventmouse.h b/xfa/fwl/cfwl_eventmouse.h new file mode 100644 index 0000000000..a5caa93959 --- /dev/null +++ b/xfa/fwl/cfwl_eventmouse.h @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTMOUSE_H_ +#define XFA_FWL_CFWL_EVENTMOUSE_H_ + +#include "xfa/fwl/cfwl_event.h" + +class CFWL_EventMouse : public CFWL_Event { + public: + explicit CFWL_EventMouse(CFWL_Widget* pSrcTarget); + CFWL_EventMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + ~CFWL_EventMouse() override; + + FWL_MouseCommand m_dwCmd; +}; + +#endif // XFA_FWL_CFWL_EVENTMOUSE_H_ diff --git a/xfa/fwl/cfwl_eventscroll.cpp b/xfa/fwl/cfwl_eventscroll.cpp new file mode 100644 index 0000000000..0e9e26c1cb --- /dev/null +++ b/xfa/fwl/cfwl_eventscroll.cpp @@ -0,0 +1,12 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventscroll.h" + +CFWL_EventScroll::CFWL_EventScroll(CFWL_Widget* pSrcTarget) + : CFWL_Event(CFWL_Event::Type::Scroll, pSrcTarget) {} + +CFWL_EventScroll::~CFWL_EventScroll() {} diff --git a/xfa/fwl/cfwl_eventscroll.h b/xfa/fwl/cfwl_eventscroll.h new file mode 100644 index 0000000000..2fdef9e7b1 --- /dev/null +++ b/xfa/fwl/cfwl_eventscroll.h @@ -0,0 +1,34 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTSCROLL_H_ +#define XFA_FWL_CFWL_EVENTSCROLL_H_ + +#include "xfa/fwl/cfwl_event.h" + +class CFWL_EventScroll : public CFWL_Event { + public: + enum class Code { + None = 1, + Min, + Max, + PageBackward, + PageForward, + StepBackward, + StepForward, + Pos, + TrackPos, + EndScroll, + }; + + explicit CFWL_EventScroll(CFWL_Widget* pSrcTarget); + ~CFWL_EventScroll() override; + + Code m_iScrollCode; + FX_FLOAT m_fPos; +}; + +#endif // XFA_FWL_CFWL_EVENTSCROLL_H_ diff --git a/xfa/fwl/cfwl_eventselectchanged.cpp b/xfa/fwl/cfwl_eventselectchanged.cpp new file mode 100644 index 0000000000..bc6859590b --- /dev/null +++ b/xfa/fwl/cfwl_eventselectchanged.cpp @@ -0,0 +1,12 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventselectchanged.h" + +CFWL_EventSelectChanged::CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget) + : CFWL_Event(CFWL_Event::Type::SelectChanged, pSrcTarget) {} + +CFWL_EventSelectChanged::~CFWL_EventSelectChanged() {} diff --git a/xfa/fwl/cfwl_eventselectchanged.h b/xfa/fwl/cfwl_eventselectchanged.h new file mode 100644 index 0000000000..30f1e2d5c7 --- /dev/null +++ b/xfa/fwl/cfwl_eventselectchanged.h @@ -0,0 +1,26 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTSELECTCHANGED_H_ +#define XFA_FWL_CFWL_EVENTSELECTCHANGED_H_ + +#include "xfa/fwl/cfwl_event.h" + +class CFWL_EventSelectChanged : public CFWL_Event { + public: + explicit CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget); + ~CFWL_EventSelectChanged() override; + + // Used by ComboBox. + bool bLButtonUp; + + // Used by DateTimePIcker + int32_t iYear; + int32_t iMonth; + int32_t iDay; +}; + +#endif // XFA_FWL_CFWL_EVENTSELECTCHANGED_H_ diff --git a/xfa/fwl/cfwl_eventtarget.cpp b/xfa/fwl/cfwl_eventtarget.cpp new file mode 100644 index 0000000000..55f8e1fc78 --- /dev/null +++ b/xfa/fwl/cfwl_eventtarget.cpp @@ -0,0 +1,31 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventtarget.h" + +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_widgetdelegate.h" + +CFWL_EventTarget::CFWL_EventTarget(CFWL_Widget* pListener) + : m_pListener(pListener), m_bInvalid(false) {} + +CFWL_EventTarget::~CFWL_EventTarget() {} + +void CFWL_EventTarget::SetEventSource(CFWL_Widget* pSource) { + if (pSource) + m_widgets.insert(pSource); +} + +bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { + IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); + if (!pDelegate) + return false; + if (!m_widgets.empty() && m_widgets.count(pEvent->m_pSrcTarget) == 0) + return false; + + pDelegate->OnProcessEvent(pEvent); + return true; +} diff --git a/xfa/fwl/cfwl_eventtarget.h b/xfa/fwl/cfwl_eventtarget.h new file mode 100644 index 0000000000..1bca97232c --- /dev/null +++ b/xfa/fwl/cfwl_eventtarget.h @@ -0,0 +1,35 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTTARGET_H_ +#define XFA_FWL_CFWL_EVENTTARGET_H_ + +#include + +#include "core/fxcrt/fx_basic.h" +#include "xfa/fwl/cfwl_event.h" + +class CFWL_Event; +class CFWL_Widget; + +class CFWL_EventTarget { + public: + explicit CFWL_EventTarget(CFWL_Widget* pListener); + ~CFWL_EventTarget(); + + void SetEventSource(CFWL_Widget* pSource); + bool ProcessEvent(CFWL_Event* pEvent); + + bool IsInvalid() const { return m_bInvalid; } + void FlagInvalid() { m_bInvalid = true; } + + private: + std::set m_widgets; + CFWL_Widget* m_pListener; + bool m_bInvalid; +}; + +#endif // XFA_FWL_CFWL_EVENTTARGET_H_ diff --git a/xfa/fwl/cfwl_eventtextchanged.cpp b/xfa/fwl/cfwl_eventtextchanged.cpp new file mode 100644 index 0000000000..439d99d927 --- /dev/null +++ b/xfa/fwl/cfwl_eventtextchanged.cpp @@ -0,0 +1,12 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventtextchanged.h" + +CFWL_EventTextChanged::CFWL_EventTextChanged(CFWL_Widget* pSrcTarget) + : CFWL_Event(CFWL_Event::Type::TextChanged, pSrcTarget) {} + +CFWL_EventTextChanged::~CFWL_EventTextChanged() {} diff --git a/xfa/fwl/cfwl_eventtextchanged.h b/xfa/fwl/cfwl_eventtextchanged.h new file mode 100644 index 0000000000..8ae27627b5 --- /dev/null +++ b/xfa/fwl/cfwl_eventtextchanged.h @@ -0,0 +1,20 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTTEXTCHANGED_H_ +#define XFA_FWL_CFWL_EVENTTEXTCHANGED_H_ + +#include "xfa/fwl/cfwl_event.h" + +class CFWL_EventTextChanged : public CFWL_Event { + public: + explicit CFWL_EventTextChanged(CFWL_Widget* pSrcTarget); + ~CFWL_EventTextChanged() override; + + CFX_WideString wsPrevText; +}; + +#endif // XFA_FWL_CFWL_EVENTTEXTCHANGED_H_ diff --git a/xfa/fwl/cfwl_eventvalidate.cpp b/xfa/fwl/cfwl_eventvalidate.cpp new file mode 100644 index 0000000000..c54d491528 --- /dev/null +++ b/xfa/fwl/cfwl_eventvalidate.cpp @@ -0,0 +1,12 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_eventvalidate.h" + +CFWL_EventValidate::CFWL_EventValidate(CFWL_Widget* pSrcTarget) + : CFWL_Event(CFWL_Event::Type::Validate, pSrcTarget) {} + +CFWL_EventValidate::~CFWL_EventValidate() {} diff --git a/xfa/fwl/cfwl_eventvalidate.h b/xfa/fwl/cfwl_eventvalidate.h new file mode 100644 index 0000000000..512161212a --- /dev/null +++ b/xfa/fwl/cfwl_eventvalidate.h @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_EVENTVALIDATE_H_ +#define XFA_FWL_CFWL_EVENTVALIDATE_H_ + +#include "xfa/fwl/cfwl_event.h" + +class CFWL_EventValidate : public CFWL_Event { + public: + explicit CFWL_EventValidate(CFWL_Widget* pSrcTarget); + ~CFWL_EventValidate() override; + + CFX_WideString wsInsert; + bool bValidate; +}; + +#endif // XFA_FWL_CFWL_EVENTVALIDATE_H_ diff --git a/xfa/fwl/cfwl_form.cpp b/xfa/fwl/cfwl_form.cpp new file mode 100644 index 0000000000..624957163f --- /dev/null +++ b/xfa/fwl/cfwl_form.cpp @@ -0,0 +1,624 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_form.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_formproxy.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_noteloop.h" +#include "xfa/fwl/cfwl_sysbtn.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" +#include "xfa/fwl/theme/cfwl_widgettp.h" + +namespace { + +const int kSystemButtonSize = 21; +const int kSystemButtonMargin = 5; +const int kSystemButtonSpan = 2; + +} // namespace + +namespace { + +const uint8_t kCornerEnlarge = 10; + +} // namespace + +CFWL_Form::CFWL_Form(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Widget(app, std::move(properties), pOuter), +#if (_FX_OS_ == _FX_MACOSX_) + m_bMouseIn(false), +#endif + m_pCloseBox(nullptr), + m_pMinBox(nullptr), + m_pMaxBox(nullptr), + m_pSubFocus(nullptr), + m_fCXBorder(0), + m_fCYBorder(0), + m_iCaptureBtn(-1), + m_iSysBox(0), + m_bLButtonDown(false), + m_bMaximized(false), + m_bSetMaximize(false), + m_bDoModalFlag(false) { + m_rtRelative.Reset(); + m_rtRestore.Reset(); + + RegisterForm(); + RegisterEventTarget(nullptr); +} + +CFWL_Form::~CFWL_Form() { + UnregisterEventTarget(); + UnRegisterForm(); + RemoveSysButtons(); +} + +FWL_Type CFWL_Form::GetClassID() const { + return FWL_Type::Form; +} + +bool CFWL_Form::IsInstance(const CFX_WideStringC& wsClass) const { + if (wsClass == CFX_WideStringC(FWL_CLASS_Form)) + return true; + return CFWL_Widget::IsInstance(wsClass); +} + +void CFWL_Form::GetClientRect(CFX_RectF& rect) { + rect = m_pProperties->m_rtWidget; + rect.Offset(-rect.left, -rect.top); +} + +void CFWL_Form::Update() { + if (m_iLock > 0) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + Layout(); +} + +FWL_WidgetHit CFWL_Form::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + GetAvailableTheme(); + + if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::CloseBox; + if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::MaxBox; + if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::MinBox; + + CFX_RectF rtCap; + rtCap.Set(m_fCYBorder, m_fCXBorder, + 0 - kSystemButtonSize * m_iSysBox - 2 * m_fCYBorder, + 0 - m_fCXBorder); + if (rtCap.Contains(fx, fy)) + return FWL_WidgetHit::Titlebar; + if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize)) { + FX_FLOAT fWidth = m_rtRelative.width - 2 * (m_fCYBorder + kCornerEnlarge); + FX_FLOAT fHeight = m_rtRelative.height - 2 * (m_fCXBorder + kCornerEnlarge); + + CFX_RectF rt; + rt.Set(0, m_fCXBorder + kCornerEnlarge, m_fCYBorder, fHeight); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Left; + + rt.Set(m_rtRelative.width - m_fCYBorder, m_fCXBorder + kCornerEnlarge, + m_fCYBorder, fHeight); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Right; + + rt.Set(m_fCYBorder + kCornerEnlarge, 0, fWidth, m_fCXBorder); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Top; + + rt.Set(m_fCYBorder + kCornerEnlarge, m_rtRelative.height - m_fCXBorder, + fWidth, m_fCXBorder); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Bottom; + + rt.Set(0, 0, m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::LeftTop; + + rt.Set(0, m_rtRelative.height - m_fCXBorder - kCornerEnlarge, + m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::LeftBottom; + + rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, 0, + m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::RightTop; + + rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, + m_rtRelative.height - m_fCXBorder - kCornerEnlarge, + m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::RightBottom; + } + return FWL_WidgetHit::Client; +} + +void CFWL_Form::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + bool bInactive = !IsActive(); + int32_t iState = bInactive ? CFWL_PartState_Inactive : CFWL_PartState_Normal; + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_NoDrawClient) == 0) + DrawBackground(pGraphics, pTheme); + +#ifdef FWL_UseMacSystemBorder + return; +#endif + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_dwStates = iState; + param.m_pGraphics = pGraphics; + param.m_rtPart = m_rtRelative; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { + param.m_iPart = CFWL_Part::Border; + pTheme->DrawBackground(¶m); + } + if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != + FWL_WGTSTYLE_EdgeNone) { + CFX_RectF rtEdge; + GetEdgeRect(rtEdge); + param.m_iPart = CFWL_Part::Edge; + param.m_rtPart = rtEdge; + param.m_dwStates = iState; + pTheme->DrawBackground(¶m); + } + +#if (_FX_OS_ == _FX_MACOSX_) + { + if (m_pCloseBox) { + param.m_iPart = CFWL_Part::CloseBox; + param.m_dwStates = m_pCloseBox->GetPartState(); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) + param.m_dwStates = CFWL_PartState_Disabled; + else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) + param.m_dwStates = CFWL_PartState_Hovered; + param.m_rtPart = m_pCloseBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + if (m_pMaxBox) { + param.m_iPart = CFWL_Part::MaximizeBox; + param.m_dwStates = m_pMaxBox->GetPartState(); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) + param.m_dwStates = CFWL_PartState_Disabled; + else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) + param.m_dwStates = CFWL_PartState_Hovered; + param.m_rtPart = m_pMaxBox->m_rtBtn; + param.m_bMaximize = m_bMaximized; + pTheme->DrawBackground(¶m); + } + if (m_pMinBox) { + param.m_iPart = CFWL_Part::MinimizeBox; + param.m_dwStates = m_pMinBox->GetPartState(); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) + param.m_dwStates = CFWL_PartState_Disabled; + else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) + param.m_dwStates = CFWL_PartState_Hovered; + param.m_rtPart = m_pMinBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + m_bMouseIn = false; + } +#else + { + if (m_pCloseBox) { + param.m_iPart = CFWL_Part::CloseBox; + param.m_dwStates = m_pCloseBox->GetPartState(); + param.m_rtPart = m_pCloseBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + if (m_pMaxBox) { + param.m_iPart = CFWL_Part::MaximizeBox; + param.m_dwStates = m_pMaxBox->GetPartState(); + param.m_rtPart = m_pMaxBox->m_rtBtn; + param.m_bMaximize = m_bMaximized; + pTheme->DrawBackground(¶m); + } + if (m_pMinBox) { + param.m_iPart = CFWL_Part::MinimizeBox; + param.m_dwStates = m_pMinBox->GetPartState(); + param.m_rtPart = m_pMinBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + } +#endif +} + +CFWL_Widget* CFWL_Form::DoModal() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return nullptr; + + CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); + if (!pDriver) + return nullptr; + + m_pNoteLoop = pdfium::MakeUnique(); + m_pNoteLoop->SetMainForm(this); + + pDriver->PushNoteLoop(m_pNoteLoop.get()); + m_bDoModalFlag = true; + RemoveStates(FWL_WGTSTATE_Invisible); + pDriver->Run(); + +#if _FX_OS_ != _FX_MACOSX_ + pDriver->PopNoteLoop(); +#endif + + m_pNoteLoop.reset(); + return nullptr; +} + +void CFWL_Form::EndDoModal() { + if (!m_pNoteLoop) + return; + + m_bDoModalFlag = false; + +#if (_FX_OS_ == _FX_MACOSX_) + m_pNoteLoop->EndModalLoop(); + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->PopNoteLoop(); + SetStates(FWL_WGTSTATE_Invisible); +#else + SetStates(FWL_WGTSTATE_Invisible); + m_pNoteLoop->EndModalLoop(); +#endif +} + +void CFWL_Form::DrawBackground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_pGraphics = pGraphics; + param.m_rtPart = m_rtRelative; + param.m_rtPart.Deflate(m_fCYBorder, m_fCXBorder, m_fCYBorder, m_fCXBorder); + pTheme->DrawBackground(¶m); +} + +void CFWL_Form::RemoveSysButtons() { + delete m_pCloseBox; + m_pCloseBox = nullptr; + delete m_pMinBox; + m_pMinBox = nullptr; + delete m_pMaxBox; + m_pMaxBox = nullptr; +} + +CFWL_SysBtn* CFWL_Form::GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy) { + if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) + return m_pCloseBox; + if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) + return m_pMaxBox; + if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) + return m_pMinBox; + return nullptr; +} + +CFWL_SysBtn* CFWL_Form::GetSysBtnByState(uint32_t dwState) { + if (m_pCloseBox && (m_pCloseBox->m_dwState & dwState)) + return m_pCloseBox; + if (m_pMaxBox && (m_pMaxBox->m_dwState & dwState)) + return m_pMaxBox; + if (m_pMinBox && (m_pMinBox->m_dwState & dwState)) + return m_pMinBox; + return nullptr; +} + +CFWL_SysBtn* CFWL_Form::GetSysBtnByIndex(int32_t nIndex) { + if (nIndex < 0) + return nullptr; + + CFX_ArrayTemplate arrBtn; + if (m_pMinBox) + arrBtn.Add(m_pMinBox); + if (m_pMaxBox) + arrBtn.Add(m_pMaxBox); + if (m_pCloseBox) + arrBtn.Add(m_pCloseBox); + return arrBtn[nIndex]; +} + +int32_t CFWL_Form::GetSysBtnIndex(CFWL_SysBtn* pBtn) { + CFX_ArrayTemplate arrBtn; + if (m_pMinBox) + arrBtn.Add(m_pMinBox); + if (m_pMaxBox) + arrBtn.Add(m_pMaxBox); + if (m_pCloseBox) + arrBtn.Add(m_pCloseBox); + return arrBtn.Find(pBtn); +} + +void CFWL_Form::GetEdgeRect(CFX_RectF& rtEdge) { + rtEdge = m_rtRelative; + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { + FX_FLOAT fCX = GetBorderSize(true); + FX_FLOAT fCY = GetBorderSize(false); + rtEdge.Deflate(fCX, fCY, fCX, fCY); + } +} + +void CFWL_Form::SetWorkAreaRect() { + m_rtRestore = m_pProperties->m_rtWidget; + CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr) + return; + + m_bSetMaximize = true; + Repaint(&m_rtRelative); +} + +void CFWL_Form::Layout() { + GetRelativeRect(m_rtRelative); + +#ifndef FWL_UseMacSystemBorder + ResetSysBtn(); +#endif +} + +void CFWL_Form::ResetSysBtn() { + m_fCXBorder = + *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CXBorder)); + m_fCYBorder = + *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CYBorder)); + RemoveSysButtons(); + + m_iSysBox = 0; + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_CloseBox) { + m_pCloseBox = new CFWL_SysBtn; + m_pCloseBox->m_rtBtn.Set( + m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, + kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); + m_iSysBox++; + } + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MaximizeBox) { + m_pMaxBox = new CFWL_SysBtn; + if (m_pCloseBox) { + m_pMaxBox->m_rtBtn.Set( + m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, + m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); + } else { + m_pMaxBox->m_rtBtn.Set( + m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, + kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); + } + m_iSysBox++; + } + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MinimizeBox) { + m_pMinBox = new CFWL_SysBtn; + if (m_pMaxBox) { + m_pMinBox->m_rtBtn.Set( + m_pMaxBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, + m_pMaxBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); + } else if (m_pCloseBox) { + m_pMinBox->m_rtBtn.Set( + m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, + m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); + } else { + m_pMinBox->m_rtBtn.Set( + m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, + kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); + } + m_iSysBox++; + } +} + +void CFWL_Form::RegisterForm() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->RegisterForm(this); +} + +void CFWL_Form::UnRegisterForm() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->UnRegisterForm(this); +} + +void CFWL_Form::OnProcessMessage(CFWL_Message* pMessage) { +#ifndef FWL_UseMacSystemBorder + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMsg); + break; + case FWL_MouseCommand::LeftButtonDblClk: + OnLButtonDblClk(pMsg); + break; + default: + break; + } + break; + } + default: + break; + } +#endif // FWL_UseMacSystemBorder +} + +void CFWL_Form::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_Form::OnLButtonDown(CFWL_MessageMouse* pMsg) { + SetGrab(true); + m_bLButtonDown = true; + + CFWL_SysBtn* pPressBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); + m_iCaptureBtn = GetSysBtnIndex(pPressBtn); + + if (!pPressBtn) + return; + + pPressBtn->SetPressed(); + Repaint(&pPressBtn->m_rtBtn); +} + +void CFWL_Form::OnLButtonUp(CFWL_MessageMouse* pMsg) { + SetGrab(false); + m_bLButtonDown = false; + CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); + CFWL_SysBtn* pPressedBtn = GetSysBtnByIndex(m_iCaptureBtn); + if (!pPressedBtn || pPointBtn != pPressedBtn) + return; + if (pPressedBtn == GetSysBtnByState(FWL_SYSBUTTONSTATE_Pressed)) + pPressedBtn->SetNormal(); + if (pPressedBtn == m_pMaxBox) { + if (m_bMaximized) { + SetWidgetRect(m_rtRestore); + Update(); + Repaint(nullptr); + } else { + SetWorkAreaRect(); + Update(); + } + m_bMaximized = !m_bMaximized; + } else if (pPressedBtn != m_pMinBox) { + CFWL_Event eClose(CFWL_Event::Type::Close, this); + DispatchEvent(&eClose); + } +} + +void CFWL_Form::OnMouseMove(CFWL_MessageMouse* pMsg) { + if (m_bLButtonDown) + return; + + CFX_RectF rtInvalidate; + rtInvalidate.Reset(); + CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); + CFWL_SysBtn* pOldHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); + +#if _FX_OS_ == _FX_MACOSX_ + { + if (pOldHover && pPointBtn != pOldHover) + pOldHover->SetNormal(); + if (pPointBtn && pPointBtn != pOldHover) + pPointBtn->SetHover(); + if (m_pCloseBox) + rtInvalidate = m_pCloseBox->m_rtBtn; + if (m_pMaxBox) { + if (rtInvalidate.IsEmpty()) + rtInvalidate = m_pMaxBox->m_rtBtn; + else + rtInvalidate.Union(m_pMaxBox->m_rtBtn); + } + if (m_pMinBox) { + if (rtInvalidate.IsEmpty()) + rtInvalidate = m_pMinBox->m_rtBtn; + else + rtInvalidate.Union(m_pMinBox->m_rtBtn); + } + if (!rtInvalidate.IsEmpty() && + rtInvalidate.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_bMouseIn = true; + } + } +#else + { + if (pOldHover && pPointBtn != pOldHover) { + pOldHover->SetNormal(); + rtInvalidate = pOldHover->m_rtBtn; + } + if (pPointBtn && pPointBtn != pOldHover) { + pPointBtn->SetHover(); + if (rtInvalidate.IsEmpty()) + rtInvalidate = pPointBtn->m_rtBtn; + else + rtInvalidate.Union(pPointBtn->m_rtBtn); + } + } +#endif + + if (!rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +void CFWL_Form::OnMouseLeave(CFWL_MessageMouse* pMsg) { + CFWL_SysBtn* pHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); + if (!pHover) + return; + + pHover->SetNormal(); + Repaint(&pHover->m_rtBtn); +} + +void CFWL_Form::OnLButtonDblClk(CFWL_MessageMouse* pMsg) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && + HitTest(pMsg->m_fx, pMsg->m_fy) == FWL_WidgetHit::Titlebar) { + if (m_bMaximized) + SetWidgetRect(m_rtRestore); + else + SetWorkAreaRect(); + + Update(); + m_bMaximized = !m_bMaximized; + } +} diff --git a/xfa/fwl/cfwl_form.h b/xfa/fwl/cfwl_form.h new file mode 100644 index 0000000000..725e82b46e --- /dev/null +++ b/xfa/fwl/cfwl_form.h @@ -0,0 +1,99 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_FORM_H_ +#define XFA_FWL_CFWL_FORM_H_ + +#include + +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_CLASS_Form L"FWL_FORM" +#define FWL_CLASS_FormProxy L"FWL_FORMPROXY" +#define FWL_STYLEEXT_FRM_Resize (1L << 0) +#define FWL_STYLEEXT_FRM_NativeBorder (1L << 1) +#define FWL_STYLEEXT_FRM_RoundCorner (2L << 1) +#define FWL_STYLEEXT_FRM_RoundCorner4 (3L << 1) +#define FWL_STYLEEXT_FRM_NoDrawClient (1L << 3) +#define FWL_STYLEEXT_FRM_BorderCornerMask (3L << 1) +#define FWL_STYLEEXT_FRM_Max (3) + +#if (_FX_OS_ == _FX_MACOSX_) +#define FWL_UseMacSystemBorder +#endif + +class CFWL_MessageMouse; +class CFWL_NoteLoop; +class CFWL_Widget; +class IFWL_ThemeProvider; +class CFWL_SysBtn; + +class CFWL_Form : public CFWL_Widget { + public: + CFWL_Form(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_Form() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + bool IsInstance(const CFX_WideStringC& wsClass) const override; + void GetClientRect(CFX_RectF& rect) override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + CFWL_Widget* DoModal(); + void EndDoModal(); + + CFWL_Widget* GetSubFocus() const { return m_pSubFocus; } + void SetSubFocus(CFWL_Widget* pWidget) { m_pSubFocus = pWidget; } + + private: + void DrawBackground(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); + void RemoveSysButtons(); + CFWL_SysBtn* GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy); + CFWL_SysBtn* GetSysBtnByState(uint32_t dwState); + CFWL_SysBtn* GetSysBtnByIndex(int32_t nIndex); + int32_t GetSysBtnIndex(CFWL_SysBtn* pBtn); + void GetEdgeRect(CFX_RectF& rtEdge); + void SetWorkAreaRect(); + void Layout(); + void ResetSysBtn(); + void RegisterForm(); + void UnRegisterForm(); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(CFWL_MessageMouse* pMsg); + void OnLButtonDblClk(CFWL_MessageMouse* pMsg); + +#if (_FX_OS_ == _FX_MACOSX_) + bool m_bMouseIn; +#endif + CFX_RectF m_rtRestore; + CFX_RectF m_rtRelative; + CFWL_SysBtn* m_pCloseBox; + CFWL_SysBtn* m_pMinBox; + CFWL_SysBtn* m_pMaxBox; + std::unique_ptr m_pNoteLoop; + CFWL_Widget* m_pSubFocus; + FX_FLOAT m_fCXBorder; + FX_FLOAT m_fCYBorder; + int32_t m_iCaptureBtn; + int32_t m_iSysBox; + bool m_bLButtonDown; + bool m_bMaximized; + bool m_bSetMaximize; + bool m_bDoModalFlag; +}; + +#endif // XFA_FWL_CFWL_FORM_H_ diff --git a/xfa/fwl/cfwl_formproxy.cpp b/xfa/fwl/cfwl_formproxy.cpp new file mode 100644 index 0000000000..776ba0ac61 --- /dev/null +++ b/xfa/fwl/cfwl_formproxy.cpp @@ -0,0 +1,40 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_formproxy.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_notedriver.h" + +CFWL_FormProxy::CFWL_FormProxy( + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Form(app, std::move(properties), pOuter) {} + +CFWL_FormProxy::~CFWL_FormProxy() {} + +FWL_Type CFWL_FormProxy::GetClassID() const { + return FWL_Type::FormProxy; +} + +bool CFWL_FormProxy::IsInstance(const CFX_WideStringC& wsClass) const { + if (wsClass == CFX_WideStringC(FWL_CLASS_FormProxy)) + return true; + return CFWL_Form::IsInstance(wsClass); +} + +void CFWL_FormProxy::Update() {} + +void CFWL_FormProxy::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) {} + +void CFWL_FormProxy::OnProcessMessage(CFWL_Message* pMessage) { + m_pOuter->GetDelegate()->OnProcessMessage(pMessage); +} diff --git a/xfa/fwl/cfwl_formproxy.h b/xfa/fwl/cfwl_formproxy.h new file mode 100644 index 0000000000..4ad70bf15c --- /dev/null +++ b/xfa/fwl/cfwl_formproxy.h @@ -0,0 +1,31 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_FORMPROXY_H_ +#define XFA_FWL_CFWL_FORMPROXY_H_ + +#include + +#include "xfa/fwl/cfwl_form.h" + +class CFWL_WidgetProperties; + +class CFWL_FormProxy : public CFWL_Form { + public: + CFWL_FormProxy(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_FormProxy() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + bool IsInstance(const CFX_WideStringC& wsClass) const override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; +}; + +#endif // XFA_FWL_CFWL_FORMPROXY_H_ diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp new file mode 100644 index 0000000000..30c160a248 --- /dev/null +++ b/xfa/fwl/cfwl_listbox.cpp @@ -0,0 +1,1130 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_listbox.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagemousewheel.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +namespace { + +const int kItemTextMargin = 2; + +} // namespace + +CFWL_ListBox::CFWL_ListBox(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Widget(app, std::move(properties), pOuter), + m_dwTTOStyles(0), + m_iTTOAligns(0), + m_hAnchor(nullptr), + m_fScorllBarWidth(0), + m_bLButtonDown(false), + m_pScrollBarTP(nullptr) { + m_rtClient.Reset(); + m_rtConent.Reset(); + m_rtStatic.Reset(); +} + +CFWL_ListBox::~CFWL_ListBox() {} + +FWL_Type CFWL_ListBox::GetClassID() const { + return FWL_Type::ListBox; +} + +void CFWL_ListBox::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_AlignMask) { + case FWL_STYLEEXT_LTB_LeftAlign: { + m_iTTOAligns = FDE_TTOALIGNMENT_CenterLeft; + break; + } + case FWL_STYLEEXT_LTB_RightAlign: { + m_iTTOAligns = FDE_TTOALIGNMENT_CenterRight; + break; + } + case FWL_STYLEEXT_LTB_CenterAlign: + default: { + m_iTTOAligns = FDE_TTOALIGNMENT_Center; + break; + } + } + if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) + m_dwTTOStyles |= FDE_TTOSTYLE_RTL; + + m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; + m_fScorllBarWidth = GetScrollWidth(); + CalcSize(false); +} + +FWL_WidgetHit CFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (IsShowScrollBar(false)) { + CFX_RectF rect = m_pHorzScrollBar->GetWidgetRect(); + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::HScrollBar; + } + if (IsShowScrollBar(true)) { + CFX_RectF rect = m_pVertScrollBar->GetWidgetRect(); + if (rect.Contains(fx, fy)) + return FWL_WidgetHit::VScrollBar; + } + if (m_rtClient.Contains(fx, fy)) + return FWL_WidgetHit::Client; + return FWL_WidgetHit::Unknown; +} + +void CFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + pGraphics->SaveGraphState(); + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + CFX_RectF rtClip(m_rtConent); + if (IsShowScrollBar(false)) + rtClip.height -= m_fScorllBarWidth; + if (IsShowScrollBar(true)) + rtClip.width -= m_fScorllBarWidth; + if (pMatrix) + pMatrix->TransformRect(rtClip); + + pGraphics->SetClipRect(rtClip); + if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0) + DrawBkground(pGraphics, pTheme, pMatrix); + + DrawItems(pGraphics, pTheme, pMatrix); + pGraphics->RestoreGraphState(); +} + +void CFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { + if (pThemeProvider) + m_pProperties->m_pThemeProvider = pThemeProvider; +} + +int32_t CFWL_ListBox::CountSelItems() { + int32_t iRet = 0; + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + if (!pItem) + continue; + + uint32_t dwStyle = GetItemStyles(this, pItem); + if (dwStyle & FWL_ITEMSTATE_LTB_Selected) + iRet++; + } + return iRet; +} + +CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { + int32_t idx = GetSelIndex(nIndexSel); + if (idx < 0) + return nullptr; + return GetItem(this, idx); +} + +int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { + int32_t index = 0; + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + if (!pItem) + return -1; + + uint32_t dwStyle = GetItemStyles(this, pItem); + if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { + if (index == nIndex) + return i; + index++; + } + } + return -1; +} + +void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { + if (!pItem) { + if (bSelect) { + SelectAll(); + } else { + ClearSelection(); + SetFocusItem(nullptr); + } + return; + } + if (IsMultiSelection()) + SetSelectionDirect(pItem, bSelect); + else + SetSelection(pItem, pItem, bSelect); +} + +CFX_WideString CFWL_ListBox::GetDataProviderItemText(CFWL_ListItem* pItem) { + if (!pItem) + return L""; + return GetItemText(this, pItem); +} + +CFWL_ListItem* CFWL_ListBox::GetListItem(CFWL_ListItem* pItem, + uint32_t dwKeyCode) { + CFWL_ListItem* hRet = nullptr; + switch (dwKeyCode) { + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_End: { + const bool bUp = dwKeyCode == FWL_VKEY_Up; + const bool bDown = dwKeyCode == FWL_VKEY_Down; + const bool bHome = dwKeyCode == FWL_VKEY_Home; + int32_t iDstItem = -1; + if (bUp || bDown) { + int32_t index = GetItemIndex(this, pItem); + iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; + } else if (bHome) { + iDstItem = 0; + } else { + int32_t iCount = CountItems(this); + iDstItem = iCount - 1; + } + hRet = GetItem(this, iDstItem); + break; + } + default: + break; + } + return hRet; +} + +void CFWL_ListBox::SetSelection(CFWL_ListItem* hStart, + CFWL_ListItem* hEnd, + bool bSelected) { + int32_t iStart = GetItemIndex(this, hStart); + int32_t iEnd = GetItemIndex(this, hEnd); + if (iStart > iEnd) { + int32_t iTemp = iStart; + iStart = iEnd; + iEnd = iTemp; + } + if (bSelected) { + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + SetSelectionDirect(pItem, false); + } + } + for (; iStart <= iEnd; iStart++) { + CFWL_ListItem* pItem = GetItem(this, iStart); + SetSelectionDirect(pItem, bSelected); + } +} + +void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { + uint32_t dwOldStyle = GetItemStyles(this, pItem); + bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected + : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; + SetItemStyles(this, pItem, dwOldStyle); +} + +bool CFWL_ListBox::IsMultiSelection() const { + return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; +} + +bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { + uint32_t dwState = GetItemStyles(this, pItem); + return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; +} + +void CFWL_ListBox::ClearSelection() { + bool bMulti = IsMultiSelection(); + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + uint32_t dwState = GetItemStyles(this, pItem); + if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) + continue; + SetSelectionDirect(pItem, false); + if (!bMulti) + return; + } +} + +void CFWL_ListBox::SelectAll() { + if (!IsMultiSelection()) + return; + + int32_t iCount = CountItems(this); + if (iCount <= 0) + return; + + CFWL_ListItem* pItemStart = GetItem(this, 0); + CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1); + SetSelection(pItemStart, pItemEnd, false); +} + +CFWL_ListItem* CFWL_ListBox::GetFocusedItem() { + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + if (!pItem) + return nullptr; + if (GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) + return pItem; + } + return nullptr; +} + +void CFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { + CFWL_ListItem* hFocus = GetFocusedItem(); + if (pItem == hFocus) + return; + + if (hFocus) { + uint32_t dwStyle = GetItemStyles(this, hFocus); + dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; + SetItemStyles(this, hFocus, dwStyle); + } + if (pItem) { + uint32_t dwStyle = GetItemStyles(this, pItem); + dwStyle |= FWL_ITEMSTATE_LTB_Focused; + SetItemStyles(this, pItem, dwStyle); + } +} + +CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { + fx -= m_rtConent.left, fy -= m_rtConent.top; + FX_FLOAT fPosX = 0.0f; + if (m_pHorzScrollBar) + fPosX = m_pHorzScrollBar->GetPos(); + + FX_FLOAT fPosY = 0.0; + if (m_pVertScrollBar) + fPosY = m_pVertScrollBar->GetPos(); + + int32_t nCount = CountItems(this); + for (int32_t i = 0; i < nCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + if (!pItem) + continue; + + CFX_RectF rtItem; + GetItemRect(this, pItem, rtItem); + rtItem.Offset(-fPosX, -fPosY); + if (rtItem.Contains(fx, fy)) + return pItem; + } + return nullptr; +} + +bool CFWL_ListBox::GetItemCheckRectInternal(CFWL_ListItem* pItem, + CFX_RectF& rtCheck) { + if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) + return false; + GetItemCheckRect(this, pItem, rtCheck); + return true; +} + +bool CFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { + if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) + return false; + return !!(GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); +} + +bool CFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { + if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) + return false; + + SetItemCheckState(this, pItem, bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); + return true; +} + +bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { + if (!m_pVertScrollBar) + return false; + + CFX_RectF rtItem; + GetItemRect(this, pItem, rtItem); + + bool bScroll = false; + FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); + rtItem.Offset(0, -fPosY + m_rtConent.top); + if (rtItem.top < m_rtConent.top) { + fPosY += rtItem.top - m_rtConent.top; + bScroll = true; + } else if (rtItem.bottom() > m_rtConent.bottom()) { + fPosY += rtItem.bottom() - m_rtConent.bottom(); + bScroll = true; + } + if (!bScroll) + return false; + + m_pVertScrollBar->SetPos(fPosY); + m_pVertScrollBar->SetTrackPos(fPosY); + Repaint(&m_rtClient); + return true; +} + +void CFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!pTheme) + return; + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_dwStates = 0; + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtClient; + if (IsShowScrollBar(false) && IsShowScrollBar(true)) + param.m_pData = &m_rtStatic; + if (!IsEnabled()) + param.m_dwStates = CFWL_PartState_Disabled; + + pTheme->DrawBackground(¶m); +} + +void CFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + FX_FLOAT fPosX = 0.0f; + if (m_pHorzScrollBar) + fPosX = m_pHorzScrollBar->GetPos(); + + FX_FLOAT fPosY = 0.0f; + if (m_pVertScrollBar) + fPosY = m_pVertScrollBar->GetPos(); + + CFX_RectF rtView(m_rtConent); + if (m_pHorzScrollBar) + rtView.height -= m_fScorllBarWidth; + if (m_pVertScrollBar) + rtView.width -= m_fScorllBarWidth; + + bool bMultiCol = + !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + if (!pItem) + continue; + + CFX_RectF rtItem; + GetItemRect(this, pItem, rtItem); + rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); + if (rtItem.bottom() < m_rtConent.top) + continue; + if (rtItem.top >= m_rtConent.bottom()) + break; + if (bMultiCol && rtItem.left > m_rtConent.right()) + break; + + if (!(GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw)) + DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); + } +} + +void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + CFWL_ListItem* pItem, + int32_t Index, + const CFX_RectF& rtItem, + const CFX_Matrix* pMatrix) { + uint32_t dwItemStyles = GetItemStyles(this, pItem); + uint32_t dwPartStates = CFWL_PartState_Normal; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + dwPartStates = CFWL_PartState_Disabled; + else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) + dwPartStates = CFWL_PartState_Selected; + + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && + dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { + dwPartStates |= CFWL_PartState_Focused; + } + + CFWL_ThemeBackground bg_param; + bg_param.m_pWidget = this; + bg_param.m_iPart = CFWL_Part::ListItem; + bg_param.m_dwStates = dwPartStates; + bg_param.m_pGraphics = pGraphics; + bg_param.m_matrix.Concat(*pMatrix); + bg_param.m_rtPart = rtItem; + bg_param.m_bMaximize = true; + CFX_RectF rtFocus(rtItem); + bg_param.m_pData = &rtFocus; + if (m_pVertScrollBar && !m_pHorzScrollBar && + (dwPartStates & CFWL_PartState_Focused)) { + bg_param.m_rtPart.left += 1; + bg_param.m_rtPart.width -= (m_fScorllBarWidth + 1); + rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1); + } + pTheme->DrawBackground(&bg_param); + + bool bHasIcon = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Icon); + if (bHasIcon) { + CFX_RectF rtDIB; + CFX_DIBitmap* pDib = GetItemIcon(this, pItem); + rtDIB.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); + if (pDib) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Icon; + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = rtDIB; + param.m_bMaximize = true; + param.m_pImage = pDib; + pTheme->DrawBackground(¶m); + } + } + + bool bHasCheck = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Check); + if (bHasCheck) { + CFX_RectF rtCheck; + rtCheck.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); + rtCheck.Deflate(2, 2, 2, 2); + SetItemCheckRect(this, pItem, rtCheck); + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Check; + param.m_pGraphics = pGraphics; + if (GetItemChecked(pItem)) + param.m_dwStates = CFWL_PartState_Checked; + else + param.m_dwStates = CFWL_PartState_Normal; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = rtCheck; + param.m_bMaximize = true; + pTheme->DrawBackground(¶m); + } + + CFX_WideString wsText = GetItemText(this, pItem); + if (wsText.GetLength() <= 0) + return; + + CFX_RectF rtText(rtItem); + rtText.Deflate(kItemTextMargin, kItemTextMargin); + if (bHasIcon || bHasCheck) + rtText.Deflate(rtItem.height, 0, 0, 0); + + CFWL_ThemeText textParam; + textParam.m_pWidget = this; + textParam.m_iPart = CFWL_Part::ListItem; + textParam.m_dwStates = dwPartStates; + textParam.m_pGraphics = pGraphics; + textParam.m_matrix.Concat(*pMatrix); + textParam.m_rtPart = rtText; + textParam.m_wsText = wsText; + textParam.m_dwTTOStyles = m_dwTTOStyles; + textParam.m_iTTOAlign = m_iTTOAligns; + textParam.m_bMaximize = true; + pTheme->DrawText(&textParam); +} + +CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) { + CFX_SizeF fs; + if (!m_pProperties->m_pThemeProvider) + return fs; + + GetClientRect(m_rtClient); + m_rtConent = m_rtClient; + CFX_RectF rtUIMargin; + rtUIMargin.Set(0, 0, 0, 0); + if (!m_pOuter) { + CFX_RectF* pUIMargin = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); + if (pUIMargin) { + m_rtConent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, + pUIMargin->height); + } + } + + FX_FLOAT fWidth = GetMaxTextWidth(); + fWidth += 2 * kItemTextMargin; + if (!bAutoSize) { + FX_FLOAT fActualWidth = + m_rtClient.width - rtUIMargin.left - rtUIMargin.width; + fWidth = std::max(fWidth, fActualWidth); + } + + m_fItemHeight = CalcItemHeight(); + if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) + fWidth += m_fItemHeight; + + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* htem = GetItem(this, i); + GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); + } + if (bAutoSize) + return fs; + + FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; + FX_FLOAT iHeight = m_rtClient.height; + bool bShowVertScr = + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && + (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); + bool bShowHorzScr = + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && + (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); + if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { + bShowVertScr = (fs.y > iHeight); + } + if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) + bShowHorzScr = (fs.x > iWidth); + + CFX_SizeF szRange; + if (bShowVertScr) { + if (!m_pVertScrollBar) + InitVerticalScrollBar(); + + CFX_RectF rtScrollBar; + rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, + m_fScorllBarWidth, m_rtClient.height - 1); + if (bShowHorzScr) + rtScrollBar.height -= m_fScorllBarWidth; + + m_pVertScrollBar->SetWidgetRect(rtScrollBar); + szRange.x = 0, szRange.y = fs.y - m_rtConent.height; + szRange.y = std::max(szRange.y, m_fItemHeight); + + m_pVertScrollBar->SetRange(szRange.x, szRange.y); + m_pVertScrollBar->SetPageSize(rtScrollBar.height * 9 / 10); + m_pVertScrollBar->SetStepSize(m_fItemHeight); + + FX_FLOAT fPos = + std::min(std::max(m_pVertScrollBar->GetPos(), 0.f), szRange.y); + m_pVertScrollBar->SetPos(fPos); + m_pVertScrollBar->SetTrackPos(fPos); + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == + 0 || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { + m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + } + m_pVertScrollBar->Update(); + } else if (m_pVertScrollBar) { + m_pVertScrollBar->SetPos(0); + m_pVertScrollBar->SetTrackPos(0); + m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + if (bShowHorzScr) { + if (!m_pHorzScrollBar) + InitHorizontalScrollBar(); + + CFX_RectF rtScrollBar; + rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, + m_rtClient.width, m_fScorllBarWidth); + if (bShowVertScr) + rtScrollBar.width -= m_fScorllBarWidth; + + m_pHorzScrollBar->SetWidgetRect(rtScrollBar); + szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; + m_pHorzScrollBar->SetRange(szRange.x, szRange.y); + m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10); + m_pHorzScrollBar->SetStepSize(fWidth / 10); + + FX_FLOAT fPos = + std::min(std::max(m_pHorzScrollBar->GetPos(), 0.f), szRange.y); + m_pHorzScrollBar->SetPos(fPos); + m_pHorzScrollBar->SetTrackPos(fPos); + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == + 0 || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { + m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + } + m_pHorzScrollBar->Update(); + } else if (m_pHorzScrollBar) { + m_pHorzScrollBar->SetPos(0); + m_pHorzScrollBar->SetTrackPos(0); + m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + if (bShowVertScr && bShowHorzScr) { + m_rtStatic.Set(m_rtClient.right() - m_fScorllBarWidth, + m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, + m_fScorllBarWidth); + } + return fs; +} + +void CFWL_ListBox::GetItemSize(CFX_SizeF& size, + CFWL_ListItem* pItem, + FX_FLOAT fWidth, + FX_FLOAT fItemHeight, + bool bAutoSize) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) + return; + + if (!bAutoSize) { + CFX_RectF rtItem; + rtItem.Set(0, size.y, fWidth, fItemHeight); + SetItemRect(this, pItem, rtItem); + } + size.x = fWidth; + size.y += fItemHeight; +} + +FX_FLOAT CFWL_ListBox::GetMaxTextWidth() { + FX_FLOAT fRet = 0.0f; + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* pItem = GetItem(this, i); + if (!pItem) + continue; + + CFX_WideString wsText = GetItemText(this, pItem); + CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider, false); + fRet = std::max(fRet, sz.x); + } + return fRet; +} + +FX_FLOAT CFWL_ListBox::GetScrollWidth() { + FX_FLOAT* pfWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pfWidth) + return 0; + return *pfWidth; +} + +FX_FLOAT CFWL_ListBox::CalcItemHeight() { + FX_FLOAT* pfFont = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); + if (!pfFont) + return 20; + return *pfFont + 2 * kItemTextMargin; +} + +void CFWL_ListBox::InitVerticalScrollBar() { + if (m_pVertScrollBar) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert; + prop->m_dwStates = FWL_WGTSTATE_Invisible; + prop->m_pParent = this; + prop->m_pThemeProvider = m_pScrollBarTP; + m_pVertScrollBar = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); +} + +void CFWL_ListBox::InitHorizontalScrollBar() { + if (m_pHorzScrollBar) + return; + + auto prop = pdfium::MakeUnique(); + prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz; + prop->m_dwStates = FWL_WGTSTATE_Invisible; + prop->m_pParent = this; + prop->m_pThemeProvider = m_pScrollBarTP; + m_pHorzScrollBar = + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); +} + +bool CFWL_ListBox::IsShowScrollBar(bool bVert) { + CFWL_ScrollBar* pScrollbar = + bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); + if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) + return false; + return !(m_pProperties->m_dwStyleExes & + FWL_STYLEEXT_LTB_ShowScrollBarFocus) || + (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); +} + +void CFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + if (!IsEnabled()) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + OnFocusChanged(pMessage, true); + break; + case CFWL_Message::Type::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::MouseWheel: + OnMouseWheel(static_cast(pMessage)); + break; + case CFWL_Message::Type::Key: { + CFWL_MessageKey* pMsg = static_cast(pMessage); + if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown) + OnKeyDown(pMsg); + break; + } + default: + break; + } + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) { + if (!pEvent) + return; + if (pEvent->GetType() != CFWL_Event::Type::Scroll) + return; + + CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; + if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || + (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { + CFWL_EventScroll* pScrollEvent = static_cast(pEvent); + OnScroll(static_cast(pSrcTarget), + pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); + } +} + +void CFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_ListBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (GetStylesEx() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) { + if (m_pVertScrollBar) { + if (bSet) + m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + else + m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + if (m_pHorzScrollBar) { + if (bSet) + m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); + else + m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); + } + } + if (bSet) + m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); + else + m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); + + Repaint(&m_rtClient); +} + +void CFWL_ListBox::OnLButtonDown(CFWL_MessageMouse* pMsg) { + m_bLButtonDown = true; + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + SetFocus(true); + + CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); + if (!pItem) + return; + + if (IsMultiSelection()) { + if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { + bool bSelected = IsItemSelected(pItem); + SetSelectionDirect(pItem, !bSelected); + m_hAnchor = pItem; + } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) { + if (m_hAnchor) + SetSelection(m_hAnchor, pItem, true); + else + SetSelectionDirect(pItem, true); + } else { + SetSelection(pItem, pItem, true); + m_hAnchor = pItem; + } + } else { + SetSelection(pItem, pItem, true); + } + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) { + CFWL_ListItem* hSelectedItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); + CFX_RectF rtCheck; + GetItemCheckRectInternal(hSelectedItem, rtCheck); + bool bChecked = GetItemChecked(pItem); + if (rtCheck.Contains(pMsg->m_fx, pMsg->m_fy)) { + SetItemChecked(pItem, !bChecked); + Update(); + } + } + SetFocusItem(pItem); + ScrollToVisible(pItem); + SetGrab(true); + Repaint(&m_rtClient); +} + +void CFWL_ListBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { + if (!m_bLButtonDown) + return; + + m_bLButtonDown = false; + SetGrab(false); +} + +void CFWL_ListBox::OnMouseWheel(CFWL_MessageMouseWheel* pMsg) { + if (IsShowScrollBar(true)) + m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); +} + +void CFWL_ListBox::OnKeyDown(CFWL_MessageKey* pMsg) { + uint32_t dwKeyCode = pMsg->m_dwKeyCode; + switch (dwKeyCode) { + case FWL_VKEY_Tab: + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_End: { + CFWL_ListItem* pItem = GetFocusedItem(); + pItem = GetListItem(pItem, dwKeyCode); + bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); + bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); + OnVK(pItem, bShift, bCtrl); + break; + } + default: + break; + } +} + +void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { + if (!pItem) + return; + + if (IsMultiSelection()) { + if (bCtrl) { + // Do nothing. + } else if (bShift) { + if (m_hAnchor) + SetSelection(m_hAnchor, pItem, true); + else + SetSelectionDirect(pItem, true); + } else { + SetSelection(pItem, pItem, true); + m_hAnchor = pItem; + } + } else { + SetSelection(pItem, pItem, true); + } + + SetFocusItem(pItem); + ScrollToVisible(pItem); + + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + Repaint(&rtInvalidate); +} + +bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar, + CFWL_EventScroll::Code dwCode, + FX_FLOAT fPos) { + CFX_SizeF fs; + pScrollBar->GetRange(&fs.x, &fs.y); + FX_FLOAT iCurPos = pScrollBar->GetPos(); + FX_FLOAT fStep = pScrollBar->GetStepSize(); + switch (dwCode) { + case CFWL_EventScroll::Code::Min: { + fPos = fs.x; + break; + } + case CFWL_EventScroll::Code::Max: { + fPos = fs.y; + break; + } + case CFWL_EventScroll::Code::StepBackward: { + fPos -= fStep; + if (fPos < fs.x + fStep / 2) + fPos = fs.x; + break; + } + case CFWL_EventScroll::Code::StepForward: { + fPos += fStep; + if (fPos > fs.y - fStep / 2) + fPos = fs.y; + break; + } + case CFWL_EventScroll::Code::PageBackward: { + fPos -= pScrollBar->GetPageSize(); + if (fPos < fs.x) + fPos = fs.x; + break; + } + case CFWL_EventScroll::Code::PageForward: { + fPos += pScrollBar->GetPageSize(); + if (fPos > fs.y) + fPos = fs.y; + break; + } + case CFWL_EventScroll::Code::Pos: + case CFWL_EventScroll::Code::TrackPos: + case CFWL_EventScroll::Code::None: + break; + case CFWL_EventScroll::Code::EndScroll: + return false; + } + if (iCurPos != fPos) { + pScrollBar->SetPos(fPos); + pScrollBar->SetTrackPos(fPos); + Repaint(&m_rtClient); + } + return true; +} + +CFX_WideString CFWL_ListBox::GetItemText(CFWL_Widget* pWidget, + CFWL_ListItem* pItem) { + return pItem ? static_cast(pItem)->m_wsText : L""; +} + +int32_t CFWL_ListBox::CountItems(const CFWL_Widget* pWidget) const { + return pdfium::CollectionSize(m_ItemArray); +} + +CFWL_ListItem* CFWL_ListBox::GetItem(const CFWL_Widget* pWidget, + int32_t nIndex) const { + if (nIndex < 0 || nIndex >= CountItems(pWidget)) + return nullptr; + return m_ItemArray[nIndex].get(); +} + +int32_t CFWL_ListBox::GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem) { + auto it = std::find_if( + m_ItemArray.begin(), m_ItemArray.end(), + [pItem](const std::unique_ptr& candidate) { + return candidate.get() == static_cast(pItem); + }); + return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; +} + +uint32_t CFWL_ListBox::GetItemStyles(CFWL_Widget* pWidget, + CFWL_ListItem* pItem) { + return pItem ? static_cast(pItem)->m_dwStates : 0; +} + +void CFWL_ListBox::GetItemRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + CFX_RectF& rtItem) { + if (pItem) + rtItem = static_cast(pItem)->m_rtItem; +} + +void* CFWL_ListBox::GetItemData(CFWL_Widget* pWidget, CFWL_ListItem* pItem) { + return pItem ? static_cast(pItem)->m_pData : nullptr; +} + +void CFWL_ListBox::SetItemStyles(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + uint32_t dwStyle) { + if (pItem) + static_cast(pItem)->m_dwStates = dwStyle; +} + +void CFWL_ListBox::SetItemRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + const CFX_RectF& rtItem) { + if (pItem) + static_cast(pItem)->m_rtItem = rtItem; +} + +CFX_DIBitmap* CFWL_ListBox::GetItemIcon(CFWL_Widget* pWidget, + CFWL_ListItem* pItem) { + return static_cast(pItem)->m_pDIB; +} + +void CFWL_ListBox::GetItemCheckRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + CFX_RectF& rtCheck) { + rtCheck = static_cast(pItem)->m_rtCheckBox; +} + +void CFWL_ListBox::SetItemCheckRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + const CFX_RectF& rtCheck) { + static_cast(pItem)->m_rtCheckBox = rtCheck; +} + +uint32_t CFWL_ListBox::GetItemCheckState(CFWL_Widget* pWidget, + CFWL_ListItem* pItem) { + return static_cast(pItem)->m_dwCheckState; +} + +void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + uint32_t dwCheckState) { + static_cast(pItem)->m_dwCheckState = dwCheckState; +} + +CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd) { + auto pItem = pdfium::MakeUnique(); + pItem->m_dwStates = 0; + pItem->m_wsText = wsAdd; + pItem->m_dwStates = 0; + m_ItemArray.push_back(std::move(pItem)); + return m_ItemArray.back().get(); +} + +bool CFWL_ListBox::RemoveAt(int32_t iIndex) { + if (iIndex < 0 || static_cast(iIndex) >= m_ItemArray.size()) + return false; + + m_ItemArray.erase(m_ItemArray.begin() + iIndex); + return true; +} + +bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { + int32_t nIndex = GetItemIndex(this, pItem); + if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) + return false; + + int32_t iSel = nIndex + 1; + if (iSel >= CountItems(this)) + iSel = nIndex - 1; + if (iSel >= 0) { + CFWL_ListItem* pSel = static_cast(GetItem(this, iSel)); + pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; + } + m_ItemArray.erase(m_ItemArray.begin() + nIndex); + return true; +} + +void CFWL_ListBox::DeleteAll() { + m_ItemArray.clear(); +} + +uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { + if (!pItem) + return 0; + return pItem->m_dwStates | pItem->m_dwCheckState; +} diff --git a/xfa/fwl/cfwl_listbox.h b/xfa/fwl/cfwl_listbox.h new file mode 100644 index 0000000000..cdc3ef8933 --- /dev/null +++ b/xfa/fwl/cfwl_listbox.h @@ -0,0 +1,169 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_LISTBOX_H_ +#define XFA_FWL_CFWL_LISTBOX_H_ + +#include +#include + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_listitem.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_STYLEEXT_LTB_MultiSelection (1L << 0) +#define FWL_STYLEEXT_LTB_ShowScrollBarAlaways (1L << 2) +#define FWL_STYLEEXT_LTB_MultiColumn (1L << 3) +#define FWL_STYLEEXT_LTB_LeftAlign (0L << 4) +#define FWL_STYLEEXT_LTB_CenterAlign (1L << 4) +#define FWL_STYLEEXT_LTB_RightAlign (2L << 4) +#define FWL_STYLEEXT_LTB_MultiLine (1L << 6) +#define FWL_STYLEEXT_LTB_OwnerDraw (1L << 7) +#define FWL_STYLEEXT_LTB_Icon (1L << 8) +#define FWL_STYLEEXT_LTB_Check (1L << 9) +#define FWL_STYLEEXT_LTB_AlignMask (3L << 4) +#define FWL_STYLEEXT_LTB_ShowScrollBarFocus (1L << 10) +#define FWL_ITEMSTATE_LTB_Selected (1L << 0) +#define FWL_ITEMSTATE_LTB_Focused (1L << 1) +#define FWL_ITEMSTATE_LTB_Checked (1L << 2) + +class CFWL_MessageKillFocus; +class CFWL_MessageMouse; +class CFWL_MessageMouseWheel; +class CFX_DIBitmap; + +class CFWL_ListBox : public CFWL_Widget { + public: + explicit CFWL_ListBox(const CFWL_App* pApp, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_ListBox() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + int32_t CountItems(const CFWL_Widget* pWidget) const; + CFWL_ListItem* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const; + int32_t GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem); + uint32_t GetItemStyles(CFWL_Widget* pWidget, CFWL_ListItem* pItem); + uint32_t GetItemStates(CFWL_ListItem* pItem); + CFX_WideString GetItemText(CFWL_Widget* pWidget, CFWL_ListItem* pItem); + void GetItemRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + CFX_RectF& rtItem); + void* GetItemData(CFWL_Widget* pWidget, CFWL_ListItem* pItem); + void SetItemStyles(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + uint32_t dwStyle); + void SetItemRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + const CFX_RectF& rtItem); + CFX_DIBitmap* GetItemIcon(CFWL_Widget* pWidget, CFWL_ListItem* pItem); + void GetItemCheckRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + CFX_RectF& rtCheck); + void SetItemCheckRect(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + const CFX_RectF& rtCheck); + uint32_t GetItemCheckState(CFWL_Widget* pWidget, CFWL_ListItem* pItem); + void SetItemCheckState(CFWL_Widget* pWidget, + CFWL_ListItem* pItem, + uint32_t dwCheckState); + CFWL_ListItem* AddString(const CFX_WideStringC& wsAdd); + bool RemoveAt(int32_t iIndex); + bool DeleteString(CFWL_ListItem* pItem); + void DeleteAll(); + + int32_t CountSelItems(); + CFWL_ListItem* GetSelItem(int32_t nIndexSel); + int32_t GetSelIndex(int32_t nIndex); + void SetSelItem(CFWL_ListItem* hItem, bool bSelect); + CFX_WideString GetDataProviderItemText(CFWL_ListItem* hItem); + + FX_FLOAT GetItemHeight() const { return m_fItemHeight; } + FX_FLOAT CalcItemHeight(); + + protected: + CFWL_ListItem* GetListItem(CFWL_ListItem* hItem, uint32_t dwKeyCode); + void SetSelection(CFWL_ListItem* hStart, CFWL_ListItem* hEnd, bool bSelected); + CFWL_ListItem* GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy); + bool ScrollToVisible(CFWL_ListItem* hItem); + void InitVerticalScrollBar(); + void InitHorizontalScrollBar(); + bool IsShowScrollBar(bool bVert); + CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar.get(); } + const CFX_RectF& GetRTClient() const { return m_rtClient; } + + private: + void SetSelectionDirect(CFWL_ListItem* hItem, bool bSelect); + bool IsMultiSelection() const; + bool IsItemSelected(CFWL_ListItem* hItem); + void ClearSelection(); + void SelectAll(); + CFWL_ListItem* GetFocusedItem(); + void SetFocusItem(CFWL_ListItem* hItem); + bool GetItemCheckRectInternal(CFWL_ListItem* hItem, CFX_RectF& rtCheck); + bool SetItemChecked(CFWL_ListItem* hItem, bool bChecked); + bool GetItemChecked(CFWL_ListItem* hItem); + void DrawBkground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawItems(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawItem(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + CFWL_ListItem* hItem, + int32_t Index, + const CFX_RectF& rtItem, + const CFX_Matrix* pMatrix); + void DrawStatic(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); + CFX_SizeF CalcSize(bool bAutoSize); + void GetItemSize(CFX_SizeF& size, + CFWL_ListItem* hItem, + FX_FLOAT fWidth, + FX_FLOAT fHeight, + bool bAutoSize); + FX_FLOAT GetMaxTextWidth(); + FX_FLOAT GetScrollWidth(); + + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseWheel(CFWL_MessageMouseWheel* pMsg); + void OnKeyDown(CFWL_MessageKey* pMsg); + void OnVK(CFWL_ListItem* hItem, bool bShift, bool bCtrl); + bool OnScroll(CFWL_ScrollBar* pScrollBar, + CFWL_EventScroll::Code dwCode, + FX_FLOAT fPos); + + CFX_RectF m_rtClient; + CFX_RectF m_rtStatic; + CFX_RectF m_rtConent; + std::unique_ptr m_pHorzScrollBar; + std::unique_ptr m_pVertScrollBar; + uint32_t m_dwTTOStyles; + int32_t m_iTTOAligns; + CFWL_ListItem* m_hAnchor; + FX_FLOAT m_fItemHeight; + FX_FLOAT m_fScorllBarWidth; + bool m_bLButtonDown; + IFWL_ThemeProvider* m_pScrollBarTP; + std::vector> m_ItemArray; +}; + +#endif // XFA_FWL_CFWL_LISTBOX_H_ diff --git a/xfa/fwl/cfwl_listitem.cpp b/xfa/fwl/cfwl_listitem.cpp new file mode 100644 index 0000000000..c46b8a06a1 --- /dev/null +++ b/xfa/fwl/cfwl_listitem.cpp @@ -0,0 +1,19 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_listitem.h" + +CFWL_ListItem::CFWL_ListItem() + : m_dwStates(0), + m_wsText(L""), + m_pDIB(nullptr), + m_pData(nullptr), + m_dwCheckState(0) { + m_rtCheckBox.Reset(); + m_rtItem.Reset(); +} + +CFWL_ListItem::~CFWL_ListItem() {} diff --git a/xfa/fwl/cfwl_listitem.h b/xfa/fwl/cfwl_listitem.h new file mode 100644 index 0000000000..d4f5d6d62d --- /dev/null +++ b/xfa/fwl/cfwl_listitem.h @@ -0,0 +1,30 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_LISTITEM_H_ +#define XFA_FWL_CFWL_LISTITEM_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" + +class CFX_DIBitmap; + +class CFWL_ListItem { + public: + CFWL_ListItem(); + ~CFWL_ListItem(); + + CFX_RectF m_rtItem; + uint32_t m_dwStates; + uint32_t m_dwStyles; + CFX_WideString m_wsText; + CFX_DIBitmap* m_pDIB; + void* m_pData; + uint32_t m_dwCheckState; + CFX_RectF m_rtCheckBox; +}; + +#endif // XFA_FWL_CFWL_LISTITEM_H_ diff --git a/xfa/fwl/cfwl_message.cpp b/xfa/fwl/cfwl_message.cpp new file mode 100644 index 0000000000..258fe62060 --- /dev/null +++ b/xfa/fwl/cfwl_message.cpp @@ -0,0 +1,24 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_message.h" + +CFWL_Message::CFWL_Message(CFWL_Message::Type type) + : CFWL_Message(type, nullptr, nullptr) {} + +CFWL_Message::CFWL_Message(Type type, CFWL_Widget* pSrcTarget) + : CFWL_Message(type, pSrcTarget, nullptr) {} + +CFWL_Message::CFWL_Message(Type type, + CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : m_pSrcTarget(pSrcTarget), m_pDstTarget(pDstTarget), m_type(type) {} + +CFWL_Message::~CFWL_Message() {} + +std::unique_ptr CFWL_Message::Clone() { + return nullptr; +} diff --git a/xfa/fwl/cfwl_message.h b/xfa/fwl/cfwl_message.h new file mode 100644 index 0000000000..67e1f05cd3 --- /dev/null +++ b/xfa/fwl/cfwl_message.h @@ -0,0 +1,38 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MESSAGE_H_ +#define XFA_FWL_CFWL_MESSAGE_H_ + +#include + +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/fwl_error.h" + +class CFWL_Widget; + +class CFWL_Message { + public: + enum class Type { Key, KillFocus, Mouse, MouseWheel, SetFocus }; + + explicit CFWL_Message(Type type); + CFWL_Message(Type type, CFWL_Widget* pSrcTarget); + CFWL_Message(Type type, CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + virtual ~CFWL_Message(); + + virtual std::unique_ptr Clone(); + Type GetType() const { return m_type; } + + CFWL_Widget* m_pSrcTarget; + CFWL_Widget* m_pDstTarget; + + private: + Type m_type; +}; + +#endif // XFA_FWL_CFWL_MESSAGE_H_ diff --git a/xfa/fwl/cfwl_messagekey.cpp b/xfa/fwl/cfwl_messagekey.cpp new file mode 100644 index 0000000000..38d4ea0580 --- /dev/null +++ b/xfa/fwl/cfwl_messagekey.cpp @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_messagekey.h" + +#include + +#include "third_party/base/ptr_util.h" + +CFWL_MessageKey::CFWL_MessageKey(CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : CFWL_Message(CFWL_Message::Type::Key, pSrcTarget, pDstTarget) {} + +CFWL_MessageKey::~CFWL_MessageKey() {} + +std::unique_ptr CFWL_MessageKey::Clone() { + return pdfium::MakeUnique(*this); +} diff --git a/xfa/fwl/cfwl_messagekey.h b/xfa/fwl/cfwl_messagekey.h new file mode 100644 index 0000000000..bf430d3ba5 --- /dev/null +++ b/xfa/fwl/cfwl_messagekey.h @@ -0,0 +1,29 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MESSAGEKEY_H_ +#define XFA_FWL_CFWL_MESSAGEKEY_H_ + +#include + +#include "xfa/fwl/cfwl_message.h" + +enum class FWL_KeyCommand { KeyDown, KeyUp, Char }; + +class CFWL_MessageKey : public CFWL_Message { + public: + CFWL_MessageKey(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + ~CFWL_MessageKey() override; + + // CFWL_Message + std::unique_ptr Clone() override; + + uint32_t m_dwKeyCode; + uint32_t m_dwFlags; + FWL_KeyCommand m_dwCmd; +}; + +#endif // XFA_FWL_CFWL_MESSAGEKEY_H_ diff --git a/xfa/fwl/cfwl_messagekillfocus.cpp b/xfa/fwl/cfwl_messagekillfocus.cpp new file mode 100644 index 0000000000..55247d1f2e --- /dev/null +++ b/xfa/fwl/cfwl_messagekillfocus.cpp @@ -0,0 +1,24 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_messagekillfocus.h" + +#include + +#include "third_party/base/ptr_util.h" + +CFWL_MessageKillFocus::CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget) + : CFWL_MessageKillFocus(pSrcTarget, nullptr) {} + +CFWL_MessageKillFocus::CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : CFWL_Message(CFWL_Message::Type::KillFocus, pSrcTarget, pDstTarget) {} + +CFWL_MessageKillFocus::~CFWL_MessageKillFocus() {} + +std::unique_ptr CFWL_MessageKillFocus::Clone() { + return pdfium::MakeUnique(*this); +} diff --git a/xfa/fwl/cfwl_messagekillfocus.h b/xfa/fwl/cfwl_messagekillfocus.h new file mode 100644 index 0000000000..d6ca799efb --- /dev/null +++ b/xfa/fwl/cfwl_messagekillfocus.h @@ -0,0 +1,26 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MESSAGEKILLFOCUS_H_ +#define XFA_FWL_CFWL_MESSAGEKILLFOCUS_H_ + +#include + +#include "xfa/fwl/cfwl_message.h" + +class CFWL_MessageKillFocus : public CFWL_Message { + public: + explicit CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget); + CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + ~CFWL_MessageKillFocus() override; + + // CFWL_Message + std::unique_ptr Clone() override; + + CFWL_Widget* m_pSetFocus; +}; + +#endif // XFA_FWL_CFWL_MESSAGEKILLFOCUS_H_ diff --git a/xfa/fwl/cfwl_messagemouse.cpp b/xfa/fwl/cfwl_messagemouse.cpp new file mode 100644 index 0000000000..110292a1de --- /dev/null +++ b/xfa/fwl/cfwl_messagemouse.cpp @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_messagemouse.h" + +#include + +#include "third_party/base/ptr_util.h" + +CFWL_MessageMouse::CFWL_MessageMouse(CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : CFWL_Message(CFWL_Message::Type::Mouse, pSrcTarget, pDstTarget) {} + +CFWL_MessageMouse::~CFWL_MessageMouse() {} + +std::unique_ptr CFWL_MessageMouse::Clone() { + return pdfium::MakeUnique(*this); +} diff --git a/xfa/fwl/cfwl_messagemouse.h b/xfa/fwl/cfwl_messagemouse.h new file mode 100644 index 0000000000..ac45745df1 --- /dev/null +++ b/xfa/fwl/cfwl_messagemouse.h @@ -0,0 +1,41 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MESSAGEMOUSE_H_ +#define XFA_FWL_CFWL_MESSAGEMOUSE_H_ + +#include + +#include "xfa/fwl/cfwl_message.h" + +enum class FWL_MouseCommand { + LeftButtonDown, + LeftButtonUp, + LeftButtonDblClk, + RightButtonDown, + RightButtonUp, + RightButtonDblClk, + Move, + Enter, + Leave, + Hover +}; + +class CFWL_MessageMouse : public CFWL_Message { + public: + CFWL_MessageMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + ~CFWL_MessageMouse() override; + + // CFWL_Message + std::unique_ptr Clone() override; + + FX_FLOAT m_fx; + FX_FLOAT m_fy; + uint32_t m_dwFlags; + FWL_MouseCommand m_dwCmd; +}; + +#endif // XFA_FWL_CFWL_MESSAGEMOUSE_H_ diff --git a/xfa/fwl/cfwl_messagemousewheel.cpp b/xfa/fwl/cfwl_messagemousewheel.cpp new file mode 100644 index 0000000000..3646b6c30d --- /dev/null +++ b/xfa/fwl/cfwl_messagemousewheel.cpp @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_messagemousewheel.h" + +#include + +#include "third_party/base/ptr_util.h" + +CFWL_MessageMouseWheel::CFWL_MessageMouseWheel(CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : CFWL_Message(CFWL_Message::Type::MouseWheel, pSrcTarget, pDstTarget) {} + +CFWL_MessageMouseWheel::~CFWL_MessageMouseWheel() {} + +std::unique_ptr CFWL_MessageMouseWheel::Clone() { + return pdfium::MakeUnique(*this); +} diff --git a/xfa/fwl/cfwl_messagemousewheel.h b/xfa/fwl/cfwl_messagemousewheel.h new file mode 100644 index 0000000000..4d568c8e45 --- /dev/null +++ b/xfa/fwl/cfwl_messagemousewheel.h @@ -0,0 +1,29 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MESSAGEMOUSEWHEEL_H_ +#define XFA_FWL_CFWL_MESSAGEMOUSEWHEEL_H_ + +#include + +#include "xfa/fwl/cfwl_message.h" + +class CFWL_MessageMouseWheel : public CFWL_Message { + public: + CFWL_MessageMouseWheel(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + ~CFWL_MessageMouseWheel() override; + + // CFWL_Message + std::unique_ptr Clone() override; + + FX_FLOAT m_fx; + FX_FLOAT m_fy; + FX_FLOAT m_fDeltaX; + FX_FLOAT m_fDeltaY; + uint32_t m_dwFlags; +}; + +#endif // XFA_FWL_CFWL_MESSAGEMOUSEWHEEL_H_ diff --git a/xfa/fwl/cfwl_messagesetfocus.cpp b/xfa/fwl/cfwl_messagesetfocus.cpp new file mode 100644 index 0000000000..f7653c9ef2 --- /dev/null +++ b/xfa/fwl/cfwl_messagesetfocus.cpp @@ -0,0 +1,21 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_messagesetfocus.h" + +#include + +#include "third_party/base/ptr_util.h" + +CFWL_MessageSetFocus::CFWL_MessageSetFocus(CFWL_Widget* pSrcTarget, + CFWL_Widget* pDstTarget) + : CFWL_Message(CFWL_Message::Type::SetFocus, pSrcTarget, pDstTarget) {} + +CFWL_MessageSetFocus::~CFWL_MessageSetFocus() {} + +std::unique_ptr CFWL_MessageSetFocus::Clone() { + return pdfium::MakeUnique(*this); +} diff --git a/xfa/fwl/cfwl_messagesetfocus.h b/xfa/fwl/cfwl_messagesetfocus.h new file mode 100644 index 0000000000..05616fbe2e --- /dev/null +++ b/xfa/fwl/cfwl_messagesetfocus.h @@ -0,0 +1,23 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MESSAGESETFOCUS_H_ +#define XFA_FWL_CFWL_MESSAGESETFOCUS_H_ + +#include + +#include "xfa/fwl/cfwl_message.h" + +class CFWL_MessageSetFocus : public CFWL_Message { + public: + CFWL_MessageSetFocus(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); + ~CFWL_MessageSetFocus() override; + + // CFWL_Message + std::unique_ptr Clone() override; +}; + +#endif // XFA_FWL_CFWL_MESSAGESETFOCUS_H_ diff --git a/xfa/fwl/cfwl_monthcalendar.cpp b/xfa/fwl/cfwl_monthcalendar.cpp new file mode 100644 index 0000000000..94d198599d --- /dev/null +++ b/xfa/fwl/cfwl_monthcalendar.cpp @@ -0,0 +1,1089 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_monthcalendar.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_formproxy.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +#define MONTHCAL_HSEP_HEIGHT 1 +#define MONTHCAL_VSEP_WIDTH 1 +#define MONTHCAL_HMARGIN 3 +#define MONTHCAL_VMARGIN 2 +#define MONTHCAL_ROWS 9 +#define MONTHCAL_COLUMNS 7 +#define MONTHCAL_HEADER_BTN_VMARGIN 7 +#define MONTHCAL_HEADER_BTN_HMARGIN 5 + +namespace { + +CFX_WideString* GetCapacityForDay(IFWL_ThemeProvider* pTheme, + CFWL_ThemePart& params, + uint32_t day) { + ASSERT(day < 7); + + if (day == 0) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sun)); + } + if (day == 1) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Mon)); + } + if (day == 2) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Tue)); + } + if (day == 3) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Wed)); + } + if (day == 4) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Thu)); + } + if (day == 5) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Fri)); + } + + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sat)); +} + +CFX_WideString* GetCapacityForMonth(IFWL_ThemeProvider* pTheme, + CFWL_ThemePart& params, + uint32_t month) { + ASSERT(month < 12); + + if (month == 0) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::January)); + } + if (month == 1) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::February)); + } + if (month == 2) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::March)); + } + if (month == 3) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::April)); + } + if (month == 4) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::May)); + } + if (month == 5) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::June)); + } + if (month == 6) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::July)); + } + if (month == 7) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::August)); + } + if (month == 8) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::September)); + } + if (month == 9) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::October)); + } + if (month == 10) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::November)); + } + + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::December)); +} + +} // namespace + +CFWL_MonthCalendar::CFWL_MonthCalendar( + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Widget(app, std::move(properties), pOuter), + m_bInitialized(false), + m_pDateTime(new CFX_DateTime), + m_iCurYear(2011), + m_iCurMonth(1), + m_iYear(2011), + m_iMonth(1), + m_iDay(1), + m_iHovered(-1), + m_iLBtnPartStates(CFWL_PartState_Normal), + m_iRBtnPartStates(CFWL_PartState_Normal), + m_bFlag(false) { + m_rtHead.Reset(); + m_rtWeek.Reset(); + m_rtLBtn.Reset(); + m_rtRBtn.Reset(); + m_rtDates.Reset(); + m_rtHSep.Reset(); + m_rtHeadText.Reset(); + m_rtToday.Reset(); + m_rtTodayFlag.Reset(); + m_rtClient.Reset(); + m_rtWeekNum.Reset(); + m_rtWeekNumSep.Reset(); +} + +CFWL_MonthCalendar::~CFWL_MonthCalendar() { + ClearDateItem(); + m_arrSelDays.RemoveAll(); +} + +FWL_Type CFWL_MonthCalendar::GetClassID() const { + return FWL_Type::MonthCalendar; +} + +CFX_RectF CFWL_MonthCalendar::GetAutosizedWidgetRect() { + CFX_SizeF fs = CalcSize(); + CFX_RectF rect; + rect.Set(0, 0, fs.x, fs.y); + InflateWidgetRect(rect); + return rect; +} + +void CFWL_MonthCalendar::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + GetCapValue(); + if (!m_bInitialized) { + InitDate(); + m_bInitialized = true; + } + + ClearDateItem(); + ResetDateItem(); + Layout(); +} + +void CFWL_MonthCalendar::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + DrawBackground(pGraphics, pTheme, pMatrix); + DrawHeadBK(pGraphics, pTheme, pMatrix); + DrawLButton(pGraphics, pTheme, pMatrix); + DrawRButton(pGraphics, pTheme, pMatrix); + DrawSeperator(pGraphics, pTheme, pMatrix); + DrawDatesInBK(pGraphics, pTheme, pMatrix); + DrawDatesInCircle(pGraphics, pTheme, pMatrix); + DrawCaption(pGraphics, pTheme, pMatrix); + DrawWeek(pGraphics, pTheme, pMatrix); + DrawDatesIn(pGraphics, pTheme, pMatrix); + DrawDatesOut(pGraphics, pTheme, pMatrix); + DrawToday(pGraphics, pTheme, pMatrix); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { + DrawWeekNumberSep(pGraphics, pTheme, pMatrix); + DrawWeekNumber(pGraphics, pTheme, pMatrix); + } +} + +void CFWL_MonthCalendar::SetSelect(int32_t iYear, + int32_t iMonth, + int32_t iDay) { + ChangeToMonth(iYear, iMonth); + AddSelDay(iDay); +} + +void CFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Background; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtClient; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Header; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtHead; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::LBtn; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_iLBtnPartStates; + params.m_rtPart = m_rtLBtn; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::RBtn; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_iRBtnPartStates; + params.m_rtPart = m_rtRBtn; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText textParam; + textParam.m_pWidget = this; + textParam.m_iPart = CFWL_Part::Caption; + textParam.m_dwStates = CFWL_PartState_Normal; + textParam.m_pGraphics = pGraphics; + int32_t iYear; + int32_t iMonth; + iYear = m_iCurYear; + iMonth = m_iCurMonth; + CFX_WideString wsCation; + GetHeadText(iYear, iMonth, wsCation); + textParam.m_wsText = wsCation; + m_szHead = + CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider, false); + CalcHeadSize(); + textParam.m_rtPart = m_rtHeadText; + textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + textParam.m_matrix.Concat(*pMatrix); + pTheme->DrawText(&textParam); +} + +void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::HSeparator; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtHSep; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DateInBK; + params.m_pGraphics = pGraphics; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + int32_t iCount = m_arrDates.GetSize(); + for (int32_t j = 0; j < iCount; j++) { + DATEINFO* pDataInfo = m_arrDates.GetAt(j); + if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { + params.m_dwStates |= CFWL_PartState_Selected; + if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == + 0) && + pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { + params.m_dwStates |= CFWL_PartState_Flagged; + } + if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) + params.m_dwStates |= CFWL_PartState_Focused; + } else if (j == m_iHovered - 1) { + params.m_dwStates |= CFWL_PartState_Hovered; + } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { + params.m_dwStates = CFWL_PartState_Flagged; + pTheme->DrawBackground(¶ms); + } + params.m_rtPart = pDataInfo->rect; + pTheme->DrawBackground(¶ms); + params.m_dwStates = 0; + } +} + +void CFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Week; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + CFX_RectF rtDayOfWeek; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + for (int32_t i = 0; i < 7; i++) { + rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2), + m_rtWeek.top, m_szCell.x, m_szCell.y); + params.m_rtPart = rtDayOfWeek; + params.m_wsText = *GetCapacityForDay(pTheme, params, i); + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + pTheme->DrawText(¶ms); + } +} + +void CFWL_MonthCalendar::DrawWeekNumber(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::WeekNum; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + CFX_WideString wsWeekNum; + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + int32_t iMonthNum = m_pDateTime->GetMonth(); + int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum); + int32_t iTemp = 0; + FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei; + FX_FLOAT fHStartPos = m_rtClient.left; + for (int32_t i = 1; i <= iDayNum; i += 7) { + iTemp++; + m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp, + m_fWeekNumWid, m_fDateCellHei); + wsWeekNum.Format(L"0"); + params.m_wsText = wsWeekNum; + params.m_rtPart = m_rtWeekNum; + pTheme->DrawText(¶ms); + } +} + +void CFWL_MonthCalendar::DrawWeekNumberSep(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::WeekNumSep; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtWeekNumSep; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) + return; + + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Today; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + + CFX_WideString* wsDay = static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); + CFX_WideString wsText; + GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); + params.m_wsText = *wsDay + wsText; + + m_szToday = + CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider, false); + CalcTodaySize(); + params.m_rtPart = m_rtToday; + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawText(¶ms); +} + +void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DatesIn; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + int32_t iCount = m_arrDates.GetSize(); + for (int32_t j = 0; j < iCount; j++) { + DATEINFO* pDataInfo = m_arrDates.GetAt(j); + params.m_wsText = pDataInfo->wsDay; + params.m_rtPart = pDataInfo->rect; + params.m_dwStates = pDataInfo->dwStates; + if (j + 1 == m_iHovered) + params.m_dwStates |= CFWL_PartState_Hovered; + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + pTheme->DrawText(¶ms); + } +} + +void CFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DatesOut; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawText(¶ms); +} + +void CFWL_MonthCalendar::DrawDatesInCircle(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) + return; + if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) + return; + if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) + return; + + DATEINFO* pDate = m_arrDates[m_iDay - 1]; + if (!pDate) + return; + + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DateInCircle; + params.m_pGraphics = pGraphics; + params.m_rtPart = pDate->rect; + params.m_dwStates = CFWL_PartState_Normal; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +CFX_SizeF CFWL_MonthCalendar::CalcSize() { + if (!m_pProperties->m_pThemeProvider) + return CFX_SizeF(); + + CFX_SizeF fs; + CFWL_ThemePart params; + params.m_pWidget = this; + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + FX_FLOAT fMaxWeekW = 0.0f; + FX_FLOAT fMaxWeekH = 0.0f; + + for (uint32_t i = 0; i < 7; ++i) { + CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), + m_pProperties->m_pThemeProvider, false); + fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; + fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; + } + + FX_FLOAT fDayMaxW = 0.0f; + FX_FLOAT fDayMaxH = 0.0f; + for (int day = 10; day <= 31; day++) { + CFX_WideString wsDay; + wsDay.Format(L"%d", day); + CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider, false); + fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; + fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; + } + m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) + : (int)(fDayMaxW + 0.5)); + m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; + fs.x = m_szCell.x * MONTHCAL_COLUMNS + + MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + + MONTHCAL_HEADER_BTN_HMARGIN * 2; + FX_FLOAT fMonthMaxW = 0.0f; + FX_FLOAT fMonthMaxH = 0.0f; + + for (uint32_t i = 0; i < 12; ++i) { + CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), + m_pProperties->m_pThemeProvider, false); + fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; + fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; + } + + CFX_WideString wsYear; + GetHeadText(m_iYear, m_iMonth, wsYear); + + CFX_SizeF szYear = + CalcTextSize(wsYear, m_pProperties->m_pThemeProvider, false); + fMonthMaxH = std::max(fMonthMaxH, szYear.y); + m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); + fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; + fs.x = std::max(fs.x, fMonthMaxW); + + CFX_WideString wsToday; + GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); + CFX_WideString* wsText = static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); + m_wsToday = *wsText + wsToday; + m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider, false); + m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; + fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + + MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; + return fs; +} + +void CFWL_MonthCalendar::CalcHeadSize() { + FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; + FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; + m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, + m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN + + MONTHCAL_VMARGIN + fHeadVMargin, + m_szHead.x, m_szHead.y); +} + +void CFWL_MonthCalendar::CalcTodaySize() { + m_rtTodayFlag.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, + m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, + m_szCell.x, m_szToday.y); + m_rtToday.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x + + MONTHCAL_HMARGIN * 2, + m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, + m_szToday.x, m_szToday.y); +} + +void CFWL_MonthCalendar::Layout() { + GetClientRect(m_rtClient); + + m_rtHead.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top, + m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, + m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2); + m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtHead.bottom(), + m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, + m_szCell.y + MONTHCAL_VMARGIN * 2); + m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, + m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, + m_szCell.x); + m_rtRBtn.Set(m_rtClient.left + m_rtClient.width - + MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x, + m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, + m_szCell.x); + m_rtHSep.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, + m_rtWeek.bottom() - MONTHCAL_VMARGIN, + m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2, + MONTHCAL_HSEP_HEIGHT); + m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, + m_rtWeek.bottom(), + m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, + m_szCell.y * (MONTHCAL_ROWS - 3) + + MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2); + + CalDateItem(); +} + +void CFWL_MonthCalendar::CalDateItem() { + bool bNewWeek = false; + int32_t iWeekOfMonth = 0; + FX_FLOAT fLeft = m_rtDates.left; + FX_FLOAT fTop = m_rtDates.top; + int32_t iCount = m_arrDates.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + DATEINFO* pDateInfo = m_arrDates.GetAt(i); + if (bNewWeek) { + iWeekOfMonth++; + bNewWeek = false; + } + pDateInfo->rect.Set( + fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)), + fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)), + m_szCell.x + (MONTHCAL_HMARGIN * 2), + m_szCell.y + (MONTHCAL_VMARGIN * 2)); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) + pDateInfo->rect.Offset(m_fWeekNumWid, 0); + if (pDateInfo->iDayOfWeek >= 6) + bNewWeek = true; + } +} + +void CFWL_MonthCalendar::GetCapValue() { + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + CFWL_ThemePart part; + part.m_pWidget = this; + m_fHeadWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderWidth)); + m_fHeadHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderHeight)); + m_fHeadBtnWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnWidth)); + m_fHeadBtnHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHeight)); + m_fHeadBtnHMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHMargin)); + m_fHeadBtnVMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnVMargin)); + m_fHeadTextWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextWidth)); + m_fHeadTextHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHeight)); + m_fHeadTextHMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHMargin)); + m_fHeadTextVMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextVMargin)); + m_fHSepWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepWidth)); + m_fHSepHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepHeight)); + m_fWeekNumWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumWidth)); + m_fSepDOffset = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepDOffset)); + m_fSepX = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepX)); + m_fSepY = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepY)); + m_fWeekNumHeigh = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumHeight)); + m_fWeekWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekWidth)); + m_fWeekHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekHeight)); + m_fDateCellWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellWidth)); + m_fDateCellHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellHeight)); + m_fTodayWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayWidth)); + m_fTodayHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayHeight)); + m_fTodayFlagWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayFlagWidth)); + m_fMCWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Width)); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) + m_fMCWid += m_fWeekNumWid; + + m_fMCHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Height)); +} + +void CFWL_MonthCalendar::InitDate() { + // TODO(dsinclair): These should pull the real today values instead of + // pretending it's 2011-01-01. + m_iYear = 2011; + m_iMonth = 1; + m_iDay = 1; + m_iCurYear = m_iYear; + m_iCurMonth = m_iMonth; + + GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday); + GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); + m_dtMin = DATE(1500, 12, 1); + m_dtMax = DATE(2200, 1, 1); +} + +void CFWL_MonthCalendar::ClearDateItem() { + for (int32_t i = 0; i < m_arrDates.GetSize(); i++) + delete m_arrDates.GetAt(i); + m_arrDates.RemoveAll(); +} + +void CFWL_MonthCalendar::ResetDateItem() { + m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); + int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); + int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek(); + for (int32_t i = 0; i < iDays; i++) { + if (iDayOfWeek >= 7) + iDayOfWeek = 0; + + CFX_WideString wsDay; + wsDay.Format(L"%d", i + 1); + uint32_t dwStates = 0; + if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) + dwStates |= FWL_ITEMSTATE_MCD_Flag; + if (m_arrSelDays.Find(i + 1) != -1) + dwStates |= FWL_ITEMSTATE_MCD_Selected; + + CFX_RectF rtDate; + rtDate.Set(0, 0, 0, 0); + m_arrDates.Add(new DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay)); + iDayOfWeek++; + } +} + +void CFWL_MonthCalendar::NextMonth() { + int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; + if (iMonth >= 12) { + iMonth = 1; + iYear++; + } else { + iMonth++; + } + DATE dt(m_iCurYear, m_iCurMonth, 1); + if (!(dt < m_dtMax)) + return; + + m_iCurYear = iYear, m_iCurMonth = iMonth; + ChangeToMonth(m_iCurYear, m_iCurMonth); +} + +void CFWL_MonthCalendar::PrevMonth() { + int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; + if (iMonth <= 1) { + iMonth = 12; + iYear--; + } else { + iMonth--; + } + + DATE dt(m_iCurYear, m_iCurMonth, 1); + if (!(dt > m_dtMin)) + return; + + m_iCurYear = iYear, m_iCurMonth = iMonth; + ChangeToMonth(m_iCurYear, m_iCurMonth); +} + +void CFWL_MonthCalendar::ChangeToMonth(int32_t iYear, int32_t iMonth) { + m_iCurYear = iYear; + m_iCurMonth = iMonth; + m_iHovered = -1; + + ClearDateItem(); + ResetDateItem(); + CalDateItem(); + GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); +} + +void CFWL_MonthCalendar::RemoveSelDay() { + int32_t iCount = m_arrSelDays.GetSize(); + int32_t iDatesCount = m_arrDates.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + int32_t iSelDay = m_arrSelDays.GetAt(i); + if (iSelDay <= iDatesCount) { + DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); + pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; + } + } + m_arrSelDays.RemoveAll(); + return; +} + +void CFWL_MonthCalendar::AddSelDay(int32_t iDay) { + ASSERT(iDay > 0); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) + return; + + if (m_arrSelDays.Find(iDay) != -1) + return; + + RemoveSelDay(); + if (iDay <= m_arrDates.GetSize()) { + DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); + pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; + } + m_arrSelDays.Add(iDay); +} + +void CFWL_MonthCalendar::JumpToToday() { + if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { + m_iCurYear = m_iYear; + m_iCurMonth = m_iMonth; + ChangeToMonth(m_iYear, m_iMonth); + AddSelDay(m_iDay); + return; + } + + if (m_arrSelDays.Find(m_iDay) == -1) + AddSelDay(m_iDay); +} + +void CFWL_MonthCalendar::GetHeadText(int32_t iYear, + int32_t iMonth, + CFX_WideString& wsHead) { + ASSERT(iMonth > 0 && iMonth < 13); + static const FX_WCHAR* const pMonth[] = { + L"January", L"February", L"March", L"April", + L"May", L"June", L"July", L"August", + L"September", L"October", L"November", L"December"}; + wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear); +} + +void CFWL_MonthCalendar::GetTodayText(int32_t iYear, + int32_t iMonth, + int32_t iDay, + CFX_WideString& wsToday) { + wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear); +} + +int32_t CFWL_MonthCalendar::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { + int32_t iCount = m_arrDates.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + DATEINFO* pDateInfo = m_arrDates.GetAt(i); + if (pDateInfo->rect.Contains(x, y)) + return ++i; + } + return -1; +} + +void CFWL_MonthCalendar::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { + if (iDay <= 0 || iDay > m_arrDates.GetSize()) + return; + + DATEINFO* pDateInfo = m_arrDates[iDay - 1]; + if (!pDateInfo) + return; + rtDay = pDateInfo->rect; +} + +void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + case CFWL_Message::Type::KillFocus: + GetOuter()->GetDelegate()->OnProcessMessage(pMessage); + break; + case CFWL_Message::Type::Key: + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMouse = static_cast(pMessage); + switch (pMouse->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMouse); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMouse); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMouse); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMouse); + break; + default: + break; + } + break; + } + default: + break; + } + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_MonthCalendar::OnLButtonDown(CFWL_MessageMouse* pMsg) { + if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iLBtnPartStates = CFWL_PartState_Pressed; + PrevMonth(); + Repaint(&m_rtClient); + } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iRBtnPartStates |= CFWL_PartState_Pressed; + NextMonth(); + Repaint(&m_rtClient); + } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { + JumpToToday(); + Repaint(&m_rtClient); + } + } else { + CFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); + if (pIPicker->IsMonthCalendarVisible()) + m_bFlag = 1; + } +} + +void CFWL_MonthCalendar::OnLButtonUp(CFWL_MessageMouse* pMsg) { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_OnLButtonUp(pMsg); + + if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iLBtnPartStates = 0; + Repaint(&m_rtLBtn); + return; + } + if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iRBtnPartStates = 0; + Repaint(&m_rtRBtn); + return; + } + if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + int32_t iOldSel = 0; + if (m_arrSelDays.GetSize() > 0) + iOldSel = m_arrSelDays[0]; + + int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); + CFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); + CFX_RectF rt = pIPicker->GetFormProxy()->GetWidgetRect(); + rt.Set(0, 0, rt.width, rt.height); + if (iCurSel > 0) { + DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); + CFX_RectF rtInvalidate(lpDatesInfo->rect); + if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { + lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); + rtInvalidate.Union(lpDatesInfo->rect); + } + AddSelDay(iCurSel); + if (!m_pOuter) + return; + + pIPicker->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); + pIPicker->ShowMonthCalendar(false); + } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { + pIPicker->ShowMonthCalendar(false); + } + m_bFlag = 0; +} + +void CFWL_MonthCalendar::DisForm_OnLButtonUp(CFWL_MessageMouse* pMsg) { + if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iLBtnPartStates = 0; + Repaint(&(m_rtLBtn)); + return; + } + if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iRBtnPartStates = 0; + Repaint(&(m_rtRBtn)); + return; + } + if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + int32_t iOldSel = 0; + if (m_arrSelDays.GetSize() > 0) + iOldSel = m_arrSelDays[0]; + + int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); + if (iCurSel > 0) { + DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); + CFX_RectF rtInvalidate(lpDatesInfo->rect); + if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { + lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); + rtInvalidate.Union(lpDatesInfo->rect); + } + AddSelDay(iCurSel); + CFWL_DateTimePicker* pDateTime = + static_cast(m_pOuter); + pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); + pDateTime->ShowMonthCalendar(false); + } +} + +void CFWL_MonthCalendar::OnMouseMove(CFWL_MessageMouse* pMsg) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) + return; + + bool bRepaint = false; + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, 0, 0); + if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { + int32_t iHover = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); + bRepaint = m_iHovered != iHover; + if (bRepaint) { + if (m_iHovered > 0) + GetDayRect(m_iHovered, rtInvalidate); + if (iHover > 0) { + CFX_RectF rtDay; + GetDayRect(iHover, rtDay); + if (rtInvalidate.IsEmpty()) + rtInvalidate = rtDay; + else + rtInvalidate.Union(rtDay); + } + } + m_iHovered = iHover; + } else { + bRepaint = m_iHovered > 0; + if (bRepaint) + GetDayRect(m_iHovered, rtInvalidate); + + m_iHovered = -1; + } + if (bRepaint && !rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +void CFWL_MonthCalendar::OnMouseLeave(CFWL_MessageMouse* pMsg) { + if (m_iHovered <= 0) + return; + + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, 0, 0); + GetDayRect(m_iHovered, rtInvalidate); + m_iHovered = -1; + if (!rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +CFWL_MonthCalendar::DATEINFO::DATEINFO(int32_t day, + int32_t dayofweek, + uint32_t dwSt, + CFX_RectF rc, + CFX_WideString& wsday) + : iDay(day), + iDayOfWeek(dayofweek), + dwStates(dwSt), + rect(rc), + wsDay(wsday) {} + +CFWL_MonthCalendar::DATEINFO::~DATEINFO() {} diff --git a/xfa/fwl/cfwl_monthcalendar.h b/xfa/fwl/cfwl_monthcalendar.h new file mode 100644 index 0000000000..0d5ce648b9 --- /dev/null +++ b/xfa/fwl/cfwl_monthcalendar.h @@ -0,0 +1,227 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_MONTHCALENDAR_H_ +#define XFA_FWL_CFWL_MONTHCALENDAR_H_ + +#include + +#include "xfa/fgas/localization/fgas_datetime.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_STYLEEXT_MCD_MultiSelect (1L << 0) +#define FWL_STYLEEXT_MCD_NoToday (1L << 1) +#define FWL_STYLEEXT_MCD_NoTodayCircle (1L << 2) +#define FWL_STYLEEXT_MCD_WeekNumbers (1L << 3) +#define FWL_ITEMSTATE_MCD_Nomal (0L << 0) +#define FWL_ITEMSTATE_MCD_Flag (1L << 0) +#define FWL_ITEMSTATE_MCD_Selected (1L << 1) +#define FWL_ITEMSTATE_MCD_Focused (1L << 2) + +class CFWL_MessageMouse; +class CFWL_Widget; + +class CFWL_MonthCalendar : public CFWL_Widget { + public: + CFWL_MonthCalendar(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_MonthCalendar() override; + + // FWL_WidgetImp + FWL_Type GetClassID() const override; + CFX_RectF GetAutosizedWidgetRect() override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay); + + private: + struct DATE { + DATE() : iYear(0), iMonth(0), iDay(0) {} + + DATE(int32_t year, int32_t month, int32_t day) + : iYear(year), iMonth(month), iDay(day) {} + + bool operator<(const DATE& right) { + if (iYear < right.iYear) + return true; + if (iYear == right.iYear) { + if (iMonth < right.iMonth) + return true; + if (iMonth == right.iMonth) + return iDay < right.iDay; + } + return false; + } + + bool operator>(const DATE& right) { + if (iYear > right.iYear) + return true; + if (iYear == right.iYear) { + if (iMonth > right.iMonth) + return true; + if (iMonth == right.iMonth) + return iDay > right.iDay; + } + return false; + } + + int32_t iYear; + int32_t iMonth; + int32_t iDay; + }; + struct DATEINFO { + DATEINFO(int32_t day, + int32_t dayofweek, + uint32_t dwSt, + CFX_RectF rc, + CFX_WideString& wsday); + ~DATEINFO(); + + int32_t iDay; + int32_t iDayOfWeek; + uint32_t dwStates; + CFX_RectF rect; + CFX_WideString wsDay; + }; + + void DrawBackground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawHeadBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawLButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawRButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawCaption(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawSeperator(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesInBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawWeek(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawWeekNumber(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawWeekNumberSep(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawToday(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesIn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesOut(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesInCircle(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + CFX_SizeF CalcSize(); + void Layout(); + void CalcHeadSize(); + void CalcTodaySize(); + void CalDateItem(); + void GetCapValue(); + void InitDate(); + void ClearDateItem(); + void ResetDateItem(); + void NextMonth(); + void PrevMonth(); + void ChangeToMonth(int32_t iYear, int32_t iMonth); + void RemoveSelDay(); + void AddSelDay(int32_t iDay); + void JumpToToday(); + void GetHeadText(int32_t iYear, int32_t iMonth, CFX_WideString& wsHead); + void GetTodayText(int32_t iYear, + int32_t iMonth, + int32_t iDay, + CFX_WideString& wsToday); + int32_t GetDayAtPoint(FX_FLOAT x, FX_FLOAT y); + void GetDayRect(int32_t iDay, CFX_RectF& rtDay); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void DisForm_OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(CFWL_MessageMouse* pMsg); + + bool m_bInitialized; + CFX_RectF m_rtHead; + CFX_RectF m_rtWeek; + CFX_RectF m_rtLBtn; + CFX_RectF m_rtRBtn; + CFX_RectF m_rtDates; + CFX_RectF m_rtHSep; + CFX_RectF m_rtHeadText; + CFX_RectF m_rtToday; + CFX_RectF m_rtTodayFlag; + CFX_RectF m_rtWeekNum; + CFX_RectF m_rtWeekNumSep; + CFX_WideString m_wsHead; + CFX_WideString m_wsToday; + std::unique_ptr m_pDateTime; + CFX_ArrayTemplate m_arrDates; + int32_t m_iCurYear; + int32_t m_iCurMonth; + int32_t m_iYear; + int32_t m_iMonth; + int32_t m_iDay; + int32_t m_iHovered; + int32_t m_iLBtnPartStates; + int32_t m_iRBtnPartStates; + DATE m_dtMin; + DATE m_dtMax; + CFX_SizeF m_szHead; + CFX_SizeF m_szCell; + CFX_SizeF m_szToday; + CFX_ArrayTemplate m_arrSelDays; + CFX_RectF m_rtClient; + FX_FLOAT m_fHeadWid; + FX_FLOAT m_fHeadHei; + FX_FLOAT m_fHeadBtnWid; + FX_FLOAT m_fHeadBtnHei; + FX_FLOAT m_fHeadBtnHMargin; + FX_FLOAT m_fHeadBtnVMargin; + FX_FLOAT m_fHeadTextWid; + FX_FLOAT m_fHeadTextHei; + FX_FLOAT m_fHeadTextHMargin; + FX_FLOAT m_fHeadTextVMargin; + FX_FLOAT m_fHSepWid; + FX_FLOAT m_fHSepHei; + FX_FLOAT m_fWeekNumWid; + FX_FLOAT m_fSepDOffset; + FX_FLOAT m_fSepX; + FX_FLOAT m_fSepY; + FX_FLOAT m_fWeekNumHeigh; + FX_FLOAT m_fWeekWid; + FX_FLOAT m_fWeekHei; + FX_FLOAT m_fDateCellWid; + FX_FLOAT m_fDateCellHei; + FX_FLOAT m_fTodayWid; + FX_FLOAT m_fTodayHei; + FX_FLOAT m_fTodayFlagWid; + FX_FLOAT m_fMCWid; + FX_FLOAT m_fMCHei; + bool m_bFlag; +}; + +#endif // XFA_FWL_CFWL_MONTHCALENDAR_H_ diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp new file mode 100644 index 0000000000..09663f8bcf --- /dev/null +++ b/xfa/fwl/cfwl_notedriver.cpp @@ -0,0 +1,480 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_notedriver.h" + +#include + +#include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_eventtarget.h" +#include "xfa/fwl/cfwl_form.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagemousewheel.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_noteloop.h" +#include "xfa/fwl/cfwl_widgetmgr.h" + +CFWL_NoteDriver::CFWL_NoteDriver() + : m_pHover(nullptr), + m_pFocus(nullptr), + m_pGrab(nullptr), + m_pNoteLoop(pdfium::MakeUnique()) { + PushNoteLoop(m_pNoteLoop.get()); +} + +CFWL_NoteDriver::~CFWL_NoteDriver() { + ClearEventTargets(true); +} + +void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { + if (m_eventTargets.empty()) + return; + + for (const auto& pair : m_eventTargets) { + CFWL_EventTarget* pEventTarget = pair.second; + if (pEventTarget && !pEventTarget->IsInvalid()) + pEventTarget->ProcessEvent(pNote); + } +} + +void CFWL_NoteDriver::RegisterEventTarget(CFWL_Widget* pListener, + CFWL_Widget* pEventSource) { + uint32_t key = pListener->GetEventKey(); + if (key == 0) { + do { + key = rand(); + } while (key == 0 || pdfium::ContainsKey(m_eventTargets, key)); + pListener->SetEventKey(key); + } + if (!m_eventTargets[key]) + m_eventTargets[key] = new CFWL_EventTarget(pListener); + + m_eventTargets[key]->SetEventSource(pEventSource); +} + +void CFWL_NoteDriver::UnregisterEventTarget(CFWL_Widget* pListener) { + uint32_t key = pListener->GetEventKey(); + if (key == 0) + return; + + auto it = m_eventTargets.find(key); + if (it != m_eventTargets.end()) + it->second->FlagInvalid(); +} + +void CFWL_NoteDriver::PushNoteLoop(CFWL_NoteLoop* pNoteLoop) { + m_noteLoopQueue.Add(pNoteLoop); +} + +CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() { + int32_t pos = m_noteLoopQueue.GetSize(); + if (pos <= 0) + return nullptr; + + CFWL_NoteLoop* p = m_noteLoopQueue.GetAt(pos - 1); + m_noteLoopQueue.RemoveAt(pos - 1); + return p; +} + +bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) { + if (m_pFocus == pFocus) + return true; + + CFWL_Widget* pPrev = m_pFocus; + m_pFocus = pFocus; + if (pPrev) { + if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) { + CFWL_MessageKillFocus ms(pPrev, pPrev); + pDelegate->OnProcessMessage(&ms); + } + } + if (pFocus) { + CFWL_Widget* pWidget = + pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus); + CFWL_Form* pForm = static_cast(pWidget); + if (pForm) + pForm->SetSubFocus(pFocus); + + if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) { + CFWL_MessageSetFocus ms(nullptr, pFocus); + pDelegate->OnProcessMessage(&ms); + } + } + return true; +} + +void CFWL_NoteDriver::Run() { +#if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \ + _FX_OS_ == _FX_WIN64_) + for (;;) { + CFWL_NoteLoop* pTopLoop = GetTopLoop(); + if (!pTopLoop || !pTopLoop->ContinueModal()) + break; + UnqueueMessage(pTopLoop); + } +#endif +} + +void CFWL_NoteDriver::NotifyTargetHide(CFWL_Widget* pNoteTarget) { + if (m_pFocus == pNoteTarget) + m_pFocus = nullptr; + if (m_pHover == pNoteTarget) + m_pHover = nullptr; + if (m_pGrab == pNoteTarget) + m_pGrab = nullptr; +} + +void CFWL_NoteDriver::NotifyTargetDestroy(CFWL_Widget* pNoteTarget) { + if (m_pFocus == pNoteTarget) + m_pFocus = nullptr; + if (m_pHover == pNoteTarget) + m_pHover = nullptr; + if (m_pGrab == pNoteTarget) + m_pGrab = nullptr; + + UnregisterEventTarget(pNoteTarget); + + for (int32_t nIndex = 0; nIndex < m_forms.GetSize(); nIndex++) { + CFWL_Form* pForm = static_cast(m_forms[nIndex]); + if (!pForm) + continue; + + CFWL_Widget* pSubFocus = pForm->GetSubFocus(); + if (!pSubFocus) + return; + if (pSubFocus == pNoteTarget) + pForm->SetSubFocus(nullptr); + } +} + +void CFWL_NoteDriver::RegisterForm(CFWL_Widget* pForm) { + if (!pForm || m_forms.Find(pForm) >= 0) + return; + + m_forms.Add(pForm); + if (m_forms.GetSize() != 1) + return; + + CFWL_NoteLoop* pLoop = m_noteLoopQueue.GetAt(0); + if (!pLoop) + return; + + pLoop->SetMainForm(pForm); +} + +void CFWL_NoteDriver::UnRegisterForm(CFWL_Widget* pForm) { + if (!pForm) + return; + + int32_t nIndex = m_forms.Find(pForm); + if (nIndex < 0) + return; + + m_forms.RemoveAt(nIndex); +} + +void CFWL_NoteDriver::QueueMessage(std::unique_ptr pMessage) { + m_noteQueue.push_back(std::move(pMessage)); +} + +void CFWL_NoteDriver::UnqueueMessage(CFWL_NoteLoop* pNoteLoop) { + if (m_noteQueue.empty()) + return; + + std::unique_ptr pMessage = std::move(m_noteQueue[0]); + m_noteQueue.pop_front(); + + if (!IsValidMessage(pMessage.get())) + return; + + ProcessMessage(pMessage.get()); +} + +CFWL_NoteLoop* CFWL_NoteDriver::GetTopLoop() const { + int32_t size = m_noteLoopQueue.GetSize(); + if (size <= 0) + return nullptr; + return m_noteLoopQueue[size - 1]; +} + +void CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) { + CFWL_WidgetMgr* pWidgetMgr = + pMessage->m_pDstTarget->GetOwnerApp()->GetWidgetMgr(); + CFWL_Widget* pMessageForm = pWidgetMgr->IsFormDisabled() + ? pMessage->m_pDstTarget + : GetMessageForm(pMessage->m_pDstTarget); + if (!pMessageForm) + return; + if (!DispatchMessage(pMessage, pMessageForm)) + return; + + if (pMessage->GetType() == CFWL_Message::Type::Mouse) + MouseSecondary(pMessage); +} + +bool CFWL_NoteDriver::DispatchMessage(CFWL_Message* pMessage, + CFWL_Widget* pMessageForm) { + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: { + if (!DoSetFocus(pMessage, pMessageForm)) + return false; + break; + } + case CFWL_Message::Type::KillFocus: { + if (!DoKillFocus(pMessage, pMessageForm)) + return false; + break; + } + case CFWL_Message::Type::Key: { + if (!DoKey(pMessage, pMessageForm)) + return false; + break; + } + case CFWL_Message::Type::Mouse: { + if (!DoMouse(pMessage, pMessageForm)) + return false; + break; + } + case CFWL_Message::Type::MouseWheel: { + if (!DoWheel(pMessage, pMessageForm)) + return false; + break; + } + default: + break; + } + if (IFWL_WidgetDelegate* pDelegate = pMessage->m_pDstTarget->GetDelegate()) + pDelegate->OnProcessMessage(pMessage); + + return true; +} + +bool CFWL_NoteDriver::DoSetFocus(CFWL_Message* pMessage, + CFWL_Widget* pMessageForm) { + CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); + if (pWidgetMgr->IsFormDisabled()) { + m_pFocus = pMessage->m_pDstTarget; + return true; + } + + CFWL_Widget* pWidget = pMessage->m_pDstTarget; + if (!pWidget) + return false; + + CFWL_Form* pForm = static_cast(pWidget); + CFWL_Widget* pSubFocus = pForm->GetSubFocus(); + if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) { + pMessage->m_pDstTarget = pSubFocus; + if (m_pFocus != pMessage->m_pDstTarget) { + m_pFocus = pMessage->m_pDstTarget; + return true; + } + } + return false; +} + +bool CFWL_NoteDriver::DoKillFocus(CFWL_Message* pMessage, + CFWL_Widget* pMessageForm) { + CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); + if (pWidgetMgr->IsFormDisabled()) { + if (m_pFocus == pMessage->m_pDstTarget) + m_pFocus = nullptr; + return true; + } + + CFWL_Form* pForm = static_cast(pMessage->m_pDstTarget); + if (!pForm) + return false; + + CFWL_Widget* pSubFocus = pForm->GetSubFocus(); + if (pSubFocus && (pSubFocus->GetStates() & FWL_WGTSTATE_Focused)) { + pMessage->m_pDstTarget = pSubFocus; + if (m_pFocus == pMessage->m_pDstTarget) { + m_pFocus = nullptr; + return true; + } + } + return false; +} + +bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) { + CFWL_MessageKey* pMsg = static_cast(pMessage); +#if (_FX_OS_ != _FX_MACOSX_) + if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && + pMsg->m_dwKeyCode == FWL_VKEY_Tab) { + CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); + CFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget); + CFWL_Widget* pFocus = m_pFocus; + if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) + pFocus = nullptr; + + bool bFind = false; + CFWL_Widget* pNextTabStop = pWidgetMgr->NextTab(pForm, pFocus, bFind); + if (!pNextTabStop) { + bFind = false; + pNextTabStop = pWidgetMgr->NextTab(pForm, nullptr, bFind); + } + if (pNextTabStop == pFocus) + return true; + if (pNextTabStop) + SetFocus(pNextTabStop); + return true; + } +#endif + + if (!m_pFocus) { + if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && + pMsg->m_dwKeyCode == FWL_VKEY_Return) { + CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); + CFWL_Widget* defButton = pWidgetMgr->GetDefaultButton(pMessageForm); + if (defButton) { + pMsg->m_pDstTarget = defButton; + return true; + } + } + return false; + } + pMsg->m_pDstTarget = m_pFocus; + return true; +} + +bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage, + CFWL_Widget* pMessageForm) { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + if (pMsg->m_dwCmd == FWL_MouseCommand::Leave || + pMsg->m_dwCmd == FWL_MouseCommand::Hover || + pMsg->m_dwCmd == FWL_MouseCommand::Enter) { + return !!pMsg->m_pDstTarget; + } + if (pMsg->m_pDstTarget != pMessageForm) + pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy); + if (!DoMouseEx(pMsg, pMessageForm)) + pMsg->m_pDstTarget = pMessageForm; + return true; +} + +bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage, + CFWL_Widget* pMessageForm) { + CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr) + return false; + + CFWL_MessageMouseWheel* pMsg = static_cast(pMessage); + CFWL_Widget* pDst = + pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); + if (!pDst) + return false; + + pMessageForm->TransformTo(pDst, pMsg->m_fx, pMsg->m_fy); + pMsg->m_pDstTarget = pDst; + return true; +} + +bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage, + CFWL_Widget* pMessageForm) { + CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr) + return false; + CFWL_Widget* pTarget = nullptr; + if (m_pGrab) + pTarget = m_pGrab; + + CFWL_MessageMouse* pMsg = static_cast(pMessage); + if (!pTarget) { + pTarget = + pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); + } + if (pTarget) { + if (pMessageForm != pTarget) + pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy); + } + if (!pTarget) + return false; + + pMsg->m_pDstTarget = pTarget; + return true; +} + +void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { + CFWL_Widget* pTarget = pMessage->m_pDstTarget; + if (pTarget == m_pHover) + return; + + CFWL_MessageMouse* pMsg = static_cast(pMessage); + if (m_pHover) { + CFWL_MessageMouse msLeave(nullptr, m_pHover); + msLeave.m_fx = pMsg->m_fx; + msLeave.m_fy = pMsg->m_fy; + pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy); + + msLeave.m_dwFlags = 0; + msLeave.m_dwCmd = FWL_MouseCommand::Leave; + DispatchMessage(&msLeave, nullptr); + } + if (pTarget->GetClassID() == FWL_Type::Form) { + m_pHover = nullptr; + return; + } + m_pHover = pTarget; + + CFWL_MessageMouse msHover(nullptr, pTarget); + msHover.m_fx = pMsg->m_fx; + msHover.m_fy = pMsg->m_fy; + msHover.m_dwFlags = 0; + msHover.m_dwCmd = FWL_MouseCommand::Hover; + DispatchMessage(&msHover, nullptr); +} + +bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { + for (int32_t i = 0; i < m_noteLoopQueue.GetSize(); i++) { + CFWL_NoteLoop* pNoteLoop = m_noteLoopQueue[i]; + CFWL_Widget* pForm = pNoteLoop->GetForm(); + if (pForm && (pForm == pMessage->m_pDstTarget)) + return true; + } + + for (int32_t j = 0; j < m_forms.GetSize(); j++) { + CFWL_Form* pForm = static_cast(m_forms[j]); + if (pForm == pMessage->m_pDstTarget) + return true; + } + return false; +} + +CFWL_Widget* CFWL_NoteDriver::GetMessageForm(CFWL_Widget* pDstTarget) { + int32_t iTrackLoop = m_noteLoopQueue.GetSize(); + if (iTrackLoop <= 0) + return nullptr; + + CFWL_Widget* pMessageForm = nullptr; + if (iTrackLoop > 1) + pMessageForm = m_noteLoopQueue[iTrackLoop - 1]->GetForm(); + else if (m_forms.Find(pDstTarget) < 0) + pMessageForm = pDstTarget; + if (!pMessageForm && pDstTarget) { + CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr) + return nullptr; + pMessageForm = pWidgetMgr->GetSystemFormWidget(pDstTarget); + } + return pMessageForm; +} + +void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { + auto it = m_eventTargets.begin(); + while (it != m_eventTargets.end()) { + auto old = it++; + if (old->second && (bRemoveAll || old->second->IsInvalid())) { + delete old->second; + m_eventTargets.erase(old); + } + } +} diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h new file mode 100644 index 0000000000..f2ef87aabe --- /dev/null +++ b/xfa/fwl/cfwl_notedriver.h @@ -0,0 +1,78 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_NOTEDRIVER_H_ +#define XFA_FWL_CFWL_NOTEDRIVER_H_ + +#include +#include +#include + +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxgraphics/cfx_graphics.h" + +class CFWL_EventTarget; +class CFWL_NoteLoop; +class CFWL_TargetImp; +class CFWL_Widget; + +class CFWL_NoteDriver { + public: + CFWL_NoteDriver(); + ~CFWL_NoteDriver(); + + void SendEvent(CFWL_Event* pNote); + + void RegisterEventTarget(CFWL_Widget* pListener, CFWL_Widget* pEventSource); + void UnregisterEventTarget(CFWL_Widget* pListener); + void ClearEventTargets(bool bRemoveAll); + + CFWL_NoteLoop* GetTopLoop() const; + void PushNoteLoop(CFWL_NoteLoop* pNoteLoop); + CFWL_NoteLoop* PopNoteLoop(); + + CFWL_Widget* GetFocus() const { return m_pFocus; } + bool SetFocus(CFWL_Widget* pFocus); + void SetGrab(CFWL_Widget* pGrab, bool bSet) { + m_pGrab = bSet ? pGrab : nullptr; + } + + void Run(); + + void NotifyTargetHide(CFWL_Widget* pNoteTarget); + void NotifyTargetDestroy(CFWL_Widget* pNoteTarget); + + void RegisterForm(CFWL_Widget* pForm); + void UnRegisterForm(CFWL_Widget* pForm); + + void QueueMessage(std::unique_ptr pMessage); + void UnqueueMessage(CFWL_NoteLoop* pNoteLoop); + void ProcessMessage(CFWL_Message* pMessage); + + private: + bool DispatchMessage(CFWL_Message* pMessage, CFWL_Widget* pMessageForm); + bool DoSetFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); + bool DoKillFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); + bool DoKey(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); + bool DoMouse(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); + bool DoWheel(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); + bool DoMouseEx(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); + void MouseSecondary(CFWL_Message* pMsg); + bool IsValidMessage(CFWL_Message* pMessage); + CFWL_Widget* GetMessageForm(CFWL_Widget* pDstTarget); + + CFX_ArrayTemplate m_forms; + std::deque> m_noteQueue; + CFX_ArrayTemplate m_noteLoopQueue; + std::unordered_map m_eventTargets; + CFWL_Widget* m_pHover; + CFWL_Widget* m_pFocus; + CFWL_Widget* m_pGrab; + std::unique_ptr m_pNoteLoop; +}; + +#endif // XFA_FWL_CFWL_NOTEDRIVER_H_ diff --git a/xfa/fwl/cfwl_noteloop.cpp b/xfa/fwl/cfwl_noteloop.cpp new file mode 100644 index 0000000000..ff35a1af2c --- /dev/null +++ b/xfa/fwl/cfwl_noteloop.cpp @@ -0,0 +1,9 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_noteloop.h" + +CFWL_NoteLoop::CFWL_NoteLoop() : m_bContinueModal(true) {} diff --git a/xfa/fwl/cfwl_noteloop.h b/xfa/fwl/cfwl_noteloop.h new file mode 100644 index 0000000000..57e1a140c2 --- /dev/null +++ b/xfa/fwl/cfwl_noteloop.h @@ -0,0 +1,27 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_NOTELOOP_H_ +#define XFA_FWL_CFWL_NOTELOOP_H_ + +class CFWL_Widget; + +class CFWL_NoteLoop { + public: + CFWL_NoteLoop(); + ~CFWL_NoteLoop() {} + + CFWL_Widget* GetForm() const { return m_pForm; } + bool ContinueModal() const { return m_bContinueModal; } + void EndModalLoop() { m_bContinueModal = false; } + void SetMainForm(CFWL_Widget* pForm) { m_pForm = pForm; } + + private: + CFWL_Widget* m_pForm; + bool m_bContinueModal; +}; + +#endif // XFA_FWL_CFWL_NOTELOOP_H_ diff --git a/xfa/fwl/cfwl_picturebox.cpp b/xfa/fwl/cfwl_picturebox.cpp new file mode 100644 index 0000000000..b62aac942e --- /dev/null +++ b/xfa/fwl/cfwl_picturebox.cpp @@ -0,0 +1,52 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_picturebox.h" + +#include + +#include "third_party/base/ptr_util.h" + +CFWL_PictureBox::CFWL_PictureBox(const CFWL_App* app) + : CFWL_Widget(app, pdfium::MakeUnique(), nullptr) { + m_rtClient.Reset(); + m_rtImage.Reset(); + m_matrix.SetIdentity(); +} + +CFWL_PictureBox::~CFWL_PictureBox() {} + +FWL_Type CFWL_PictureBox::GetClassID() const { + return FWL_Type::PictureBox; +} + +void CFWL_PictureBox::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + GetClientRect(m_rtClient); +} + +void CFWL_PictureBox::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = GetAvailableTheme(); + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); +} + +void CFWL_PictureBox::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} diff --git a/xfa/fwl/cfwl_picturebox.h b/xfa/fwl/cfwl_picturebox.h new file mode 100644 index 0000000000..81ff3911f6 --- /dev/null +++ b/xfa/fwl/cfwl_picturebox.h @@ -0,0 +1,51 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_PICTUREBOX_H_ +#define XFA_FWL_CFWL_PICTUREBOX_H_ + +#include + +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_STYLEEXT_PTB_Left 0L << 0 +#define FWL_STYLEEXT_PTB_Center 1L << 0 +#define FWL_STYLEEXT_PTB_Right 2L << 0 +#define FWL_STYLEEXT_PTB_Top 0L << 2 +#define FWL_STYLEEXT_PTB_Vcenter 1L << 2 +#define FWL_STYLEEXT_PTB_Bottom 2L << 2 +#define FWL_STYLEEXT_PTB_Normal 0L << 4 +#define FWL_STYLEEXT_PTB_AutoSize 1L << 4 +#define FWL_STYLEEXT_PTB_StretchImage 2L << 4 +#define FWL_STYLEEXT_PTB_StretchHImage 3L << 4 +#define FWL_STYLEEXT_PTB_StretchVImage 4L << 4 +#define FWL_STYLEEXT_PTB_HAlignMask 3L << 0 +#define FWL_STYLEEXT_PTB_VAlignMask 3L << 2 +#define FWL_STYLEEXT_PTB_StretchAlignMask 7L << 4 + +class CFX_DIBitmap; +class CFWL_Widget; + +class CFWL_PictureBox : public CFWL_Widget { + public: + explicit CFWL_PictureBox(const CFWL_App* pApp); + ~CFWL_PictureBox() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + private: + CFX_RectF m_rtClient; + CFX_RectF m_rtImage; + CFX_Matrix m_matrix; +}; + +#endif // XFA_FWL_CFWL_PICTUREBOX_H_ diff --git a/xfa/fwl/cfwl_pushbutton.cpp b/xfa/fwl/cfwl_pushbutton.cpp new file mode 100644 index 0000000000..4e5ab8baf6 --- /dev/null +++ b/xfa/fwl/cfwl_pushbutton.cpp @@ -0,0 +1,291 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_pushbutton.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_eventmouse.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +CFWL_PushButton::CFWL_PushButton(const CFWL_App* app) + : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), + m_bBtnDown(false), + m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), + m_iTTOAlign(FDE_TTOALIGNMENT_Center) { + m_rtClient.Set(0, 0, 0, 0); + m_rtCaption.Set(0, 0, 0, 0); +} + +CFWL_PushButton::~CFWL_PushButton() {} + +FWL_Type CFWL_PushButton::GetClassID() const { + return FWL_Type::PushButton; +} + +void CFWL_PushButton::SetStates(uint32_t dwStates) { + if (dwStates & FWL_WGTSTATE_Disabled) { + m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; + return; + } + CFWL_Widget::SetStates(dwStates); +} + +void CFWL_PushButton::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + UpdateTextOutStyles(); + GetClientRect(m_rtClient); + m_rtCaption = m_rtClient; + FX_FLOAT* fcaption = + static_cast(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); + m_rtCaption.Inflate(-*fcaption, -*fcaption); +} + +void CFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + if (HasBorder()) { + DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, + pMatrix); + } + if (HasEdge()) { + DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, + pMatrix); + } + DrawBkground(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); +} + +void CFWL_PushButton::DrawBkground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_dwStates = GetPartStates(); + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtClient; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + param.m_pData = &m_rtCaption; + pTheme->DrawBackground(¶m); +} + +uint32_t CFWL_PushButton::GetPartStates() { + uint32_t dwStates = CFWL_PartState_Normal; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + dwStates |= CFWL_PartState_Focused; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + dwStates = CFWL_PartState_Disabled; + else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) + dwStates |= CFWL_PartState_Pressed; + else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) + dwStates |= CFWL_PartState_Hovered; + else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Default) + dwStates |= CFWL_PartState_Default; + return dwStates; +} + +void CFWL_PushButton::UpdateTextOutStyles() { + switch (m_pProperties->m_dwStyleExes & + (FWL_STYLEEXT_PSB_HLayoutMask | FWL_STYLEEXT_PSB_VLayoutMask)) { + case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Top: { + m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; + break; + } + case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Top: { + m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; + break; + } + case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Top: { + m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; + break; + } + case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_VCenter: { + m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + break; + } + case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_VCenter: { + m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; + break; + } + case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Bottom: { + m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; + break; + } + case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Bottom: { + m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; + break; + } + case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Bottom: { + m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; + break; + } + case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_VCenter: + default: { + m_iTTOAlign = FDE_TTOALIGNMENT_Center; + break; + } + } + m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) + m_dwTTOStyles |= FDE_TTOSTYLE_RTL; +} + +void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + if (!IsEnabled()) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: + OnFocusChanged(pMessage, true); + break; + case CFWL_Message::Type::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: { + CFWL_MessageKey* pKey = static_cast(pMessage); + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) + OnKeyDown(pKey); + break; + } + default: + break; + } + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_PushButton::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_PushButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + else + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + + Repaint(&m_rtClient); +} + +void CFWL_PushButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + SetFocus(true); + + m_bBtnDown = true; + m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; + m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; + Repaint(&m_rtClient); +} + +void CFWL_PushButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { + m_bBtnDown = false; + if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; + m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; + } else { + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; + } + if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { + CFWL_Event wmClick(CFWL_Event::Type::Click, this); + DispatchEvent(&wmClick); + } + Repaint(&m_rtClient); +} + +void CFWL_PushButton::OnMouseMove(CFWL_MessageMouse* pMsg) { + bool bRepaint = false; + if (m_bBtnDown) { + if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { + if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) { + m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; + bRepaint = true; + } + if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) { + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; + bRepaint = true; + } + } else { + if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) { + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; + bRepaint = true; + } + if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { + m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; + bRepaint = true; + } + } + } else { + if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { + m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; + bRepaint = true; + } + } + if (bRepaint) + Repaint(&m_rtClient); +} + +void CFWL_PushButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { + m_bBtnDown = false; + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; + m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; + Repaint(&m_rtClient); +} + +void CFWL_PushButton::OnKeyDown(CFWL_MessageKey* pMsg) { + if (pMsg->m_dwKeyCode != FWL_VKEY_Return) + return; + + CFWL_EventMouse wmMouse(this); + wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp; + DispatchEvent(&wmMouse); + + CFWL_Event wmClick(CFWL_Event::Type::Click, this); + DispatchEvent(&wmClick); +} diff --git a/xfa/fwl/cfwl_pushbutton.h b/xfa/fwl/cfwl_pushbutton.h new file mode 100644 index 0000000000..4f6939a953 --- /dev/null +++ b/xfa/fwl/cfwl_pushbutton.h @@ -0,0 +1,69 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_PUSHBUTTON_H_ +#define XFA_FWL_CFWL_PUSHBUTTON_H_ + +#include + +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +#define FWL_STYLEEXT_PSB_Left (0L << 0) +#define FWL_STYLEEXT_PSB_Center (1L << 0) +#define FWL_STYLEEXT_PSB_Right (2L << 0) +#define FWL_STYLEEXT_PSB_Top (0L << 2) +#define FWL_STYLEEXT_PSB_VCenter (1L << 2) +#define FWL_STYLEEXT_PSB_Bottom (2L << 2) +#define FWL_STYLEEXT_PSB_TextOnly (0L << 4) +#define FWL_STYLEEXT_PSB_IconOnly (1L << 4) +#define FWL_STYLEEXT_PSB_TextIcon (2L << 4) +#define FWL_STYLEEXT_PSB_HLayoutMask (3L << 0) +#define FWL_STYLEEXT_PSB_VLayoutMask (3L << 2) +#define FWL_STYLEEXT_PSB_ModeMask (3L << 4) +#define FWL_STATE_PSB_Hovered (1 << FWL_WGTSTATE_MAX) +#define FWL_STATE_PSB_Pressed (1 << (FWL_WGTSTATE_MAX + 1)) +#define FWL_STATE_PSB_Default (1 << (FWL_WGTSTATE_MAX + 2)) + +class CFWL_MessageMouse; +class CFX_DIBitmap; +class CFWL_Widget; + +class CFWL_PushButton : public CFWL_Widget { + public: + explicit CFWL_PushButton(const CFWL_App*); + ~CFWL_PushButton() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void SetStates(uint32_t dwStates) override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + private: + void DrawBkground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + uint32_t GetPartStates(); + void UpdateTextOutStyles(); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(CFWL_MessageMouse* pMsg); + void OnKeyDown(CFWL_MessageKey* pMsg); + + CFX_RectF m_rtClient; + CFX_RectF m_rtCaption; + bool m_bBtnDown; + uint32_t m_dwTTOStyles; + int32_t m_iTTOAlign; +}; + +#endif // XFA_FWL_CFWL_PUSHBUTTON_H_ diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp new file mode 100644 index 0000000000..d6124c6515 --- /dev/null +++ b/xfa/fwl/cfwl_scrollbar.cpp @@ -0,0 +1,504 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_scrollbar.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagemousewheel.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_timerinfo.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +#define FWL_SCROLLBAR_Elapse 500 +#define FWL_SCROLLBAR_MinThumb 5 + +CFWL_ScrollBar::CFWL_ScrollBar( + const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : CFWL_Widget(app, std::move(properties), pOuter), + m_pTimerInfo(nullptr), + m_fRangeMin(0), + m_fRangeMax(-1), + m_fPageSize(0), + m_fStepSize(0), + m_fPos(0), + m_fTrackPos(0), + m_iMinButtonState(CFWL_PartState_Normal), + m_iMaxButtonState(CFWL_PartState_Normal), + m_iThumbButtonState(CFWL_PartState_Normal), + m_iMinTrackState(CFWL_PartState_Normal), + m_iMaxTrackState(CFWL_PartState_Normal), + m_fLastTrackPos(0), + m_cpTrackPointX(0), + m_cpTrackPointY(0), + m_iMouseWheel(0), + m_bMouseDown(false), + m_fButtonLen(0), + m_bMinSize(false), + m_fMinThumb(FWL_SCROLLBAR_MinThumb), + m_Timer(this) { + m_rtClient.Reset(); + m_rtThumb.Reset(); + m_rtMinBtn.Reset(); + m_rtMaxBtn.Reset(); + m_rtMinTrack.Reset(); + m_rtMaxTrack.Reset(); +} + +CFWL_ScrollBar::~CFWL_ScrollBar() {} + +FWL_Type CFWL_ScrollBar::GetClassID() const { + return FWL_Type::ScrollBar; +} + +void CFWL_ScrollBar::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + Layout(); +} + +void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + DrawTrack(pGraphics, pTheme, true, pMatrix); + DrawTrack(pGraphics, pTheme, false, pMatrix); + DrawArrowBtn(pGraphics, pTheme, true, pMatrix); + DrawArrowBtn(pGraphics, pTheme, false, pMatrix); + DrawThumb(pGraphics, pTheme, pMatrix); +} + +void CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { + m_fTrackPos = fTrackPos; + CalcThumbButtonRect(m_rtThumb); + CalcMinTrackRect(m_rtMinTrack); + CalcMaxTrackRect(m_rtMaxTrack); +} + +bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos) { + if (dwCode == CFWL_EventScroll::Code::None) + return false; + return OnScroll(dwCode, fPos); +} + +void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bLower, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : (bLower ? m_iMinTrackState : m_iMaxTrackState); + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; + pTheme->DrawBackground(¶m); +} + +void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bMinBtn, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; + if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) + pTheme->DrawBackground(¶m); +} + +void CFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Thumb; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : m_iThumbButtonState; + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtThumb; + pTheme->DrawBackground(¶m); +} + +void CFWL_ScrollBar::Layout() { + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + CFWL_ThemePart part; + part.m_pWidget = this; + m_fMinThumb = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); + GetClientRect(m_rtClient); + CalcButtonLen(); + CalcMinButtonRect(m_rtMinBtn); + CalcMaxButtonRect(m_rtMaxBtn); + CalcThumbButtonRect(m_rtThumb); + CalcMinTrackRect(m_rtMinTrack); + CalcMaxTrackRect(m_rtMaxTrack); +} + +void CFWL_ScrollBar::CalcButtonLen() { + m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; + FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; + if (fLength < m_fButtonLen * 2) { + m_fButtonLen = fLength / 2; + m_bMinSize = true; + } else { + m_bMinSize = false; + } +} + +void CFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) { + rect.left = m_rtClient.left; + rect.top = m_rtClient.top; + rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; + rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; +} + +void CFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) { + rect.left = + IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen; + rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top; + rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; + rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; +} + +void CFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { + if (!IsEnabled()) { + m_rtThumb.Reset(); + return; + } + if (m_bMinSize) { + m_rtThumb.Empty(); + return; + } + + FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; + memset(&rect, 0, sizeof(CFX_Rect)); + if (fRange < 0) { + if (IsVertical()) + rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); + else + rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); + return; + } + + CFX_RectF rtClient = m_rtClient; + FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; + FX_FLOAT fSize = m_fButtonLen; + fLength -= fSize * 2.0f; + if (fLength < fSize) + fLength = 0.0f; + + FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); + fThumbSize = std::max(fThumbSize, m_fMinThumb); + + FX_FLOAT fDiff = std::max(fLength - fThumbSize, 0.0f); + FX_FLOAT fTrackPos = + std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin); + if (!fRange) + return; + + FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; + rect.left = rtClient.left; + if (!IsVertical()) + rect.left += iPos; + + rect.top = rtClient.top; + if (IsVertical()) + rect.top += iPos; + + rect.width = IsVertical() ? rtClient.width : fThumbSize; + rect.height = IsVertical() ? fThumbSize : rtClient.height; +} + +void CFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { + if (m_bMinSize) { + rect.Empty(); + return; + } + + FX_FLOAT fBottom = m_rtThumb.bottom(); + FX_FLOAT fRight = m_rtThumb.right(); + FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; + FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; + rect.left = m_rtClient.left; + rect.top = m_rtClient.top; + bool bVertical = IsVertical(); + rect.width = bVertical ? m_rtClient.width : ix; + rect.height = bVertical ? iy : m_rtClient.height; +} + +void CFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { + if (m_bMinSize) { + rect.Empty(); + return; + } + + FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; + FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; + bool bVertical = IsVertical(); + rect.left = bVertical ? m_rtClient.left : ix; + rect.top = bVertical ? iy : m_rtClient.top; + rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; + rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; +} + +FX_FLOAT CFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { + FX_FLOAT fDiffX = fx - m_cpTrackPointX; + FX_FLOAT fDiffY = fy - m_cpTrackPointY; + FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; + FX_FLOAT fPos; + + if (IsVertical()) { + fPos = fRange * fDiffY / + (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); + } else { + fPos = fRange * fDiffX / + (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); + } + + fPos += m_fLastTrackPos; + return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); +} + +bool CFWL_ScrollBar::SendEvent() { + if (m_iMinButtonState == CFWL_PartState_Pressed) { + DoScroll(CFWL_EventScroll::Code::StepBackward, m_fTrackPos); + return false; + } + if (m_iMaxButtonState == CFWL_PartState_Pressed) { + DoScroll(CFWL_EventScroll::Code::StepForward, m_fTrackPos); + return false; + } + if (m_iMinTrackState == CFWL_PartState_Pressed) { + DoScroll(CFWL_EventScroll::Code::PageBackward, m_fTrackPos); + return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); + } + if (m_iMaxTrackState == CFWL_PartState_Pressed) { + DoScroll(CFWL_EventScroll::Code::PageForward, m_fTrackPos); + return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); + } + if (m_iMouseWheel) { + CFWL_EventScroll::Code dwCode = m_iMouseWheel < 0 + ? CFWL_EventScroll::Code::StepForward + : CFWL_EventScroll::Code::StepBackward; + DoScroll(dwCode, m_fTrackPos); + } + return true; +} + +bool CFWL_ScrollBar::OnScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos) { + CFWL_EventScroll ev(this); + ev.m_iScrollCode = dwCode; + ev.m_fPos = fPos; + DispatchEvent(&ev); + return true; +} + +void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + CFWL_Message::Type type = pMessage->GetType(); + if (type == CFWL_Message::Type::Mouse) { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(); + break; + default: + break; + } + } else if (type == CFWL_Message::Type::MouseWheel) { + CFWL_MessageMouseWheel* pMsg = + static_cast(pMessage); + OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, + pMsg->m_fDeltaY); + } +} + +void CFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { + if (!IsEnabled()) + return; + + m_bMouseDown = true; + SetGrab(true); + m_cpTrackPointX = fx; + m_cpTrackPointY = fy; + m_fLastTrackPos = m_fTrackPos; + if (m_rtMinBtn.Contains(fx, fy)) + DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); + else if (m_rtThumb.Contains(fx, fy)) + DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); + else if (m_rtMaxBtn.Contains(fx, fy)) + DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); + else if (m_rtMinTrack.Contains(fx, fy)) + DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); + else + DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); + + if (!SendEvent()) + m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); +} + +void CFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { + m_pTimerInfo->StopTimer(); + m_bMouseDown = false; + DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); + DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); + DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); + DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); + DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); + SetGrab(false); +} + +void CFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { + DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); + DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); + DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); + DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); + DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); +} + +void CFWL_ScrollBar::OnMouseLeave() { + DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); + DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); + DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); + DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); + DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); +} + +void CFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, + FX_FLOAT fy, + uint32_t dwFlags, + FX_FLOAT fDeltaX, + FX_FLOAT fDeltaY) { + m_iMouseWheel = (int32_t)fDeltaX; + SendEvent(); + m_iMouseWheel = 0; +} + +void CFWL_ScrollBar::DoMouseDown(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy) { + if (!rtItem.Contains(fx, fy)) + return; + if (iState == CFWL_PartState_Pressed) + return; + + iState = CFWL_PartState_Pressed; + Repaint(&rtItem); +} + +void CFWL_ScrollBar::DoMouseUp(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy) { + int32_t iNewState = + rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; + if (iState == iNewState) + return; + + iState = iNewState; + Repaint(&rtItem); + OnScroll(CFWL_EventScroll::Code::EndScroll, m_fTrackPos); +} + +void CFWL_ScrollBar::DoMouseMove(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy) { + if (!m_bMouseDown) { + int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered + : CFWL_PartState_Normal; + if (iState == iNewState) + return; + + iState = iNewState; + Repaint(&rtItem); + } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { + FX_FLOAT fPos = GetTrackPointPos(fx, fy); + m_fTrackPos = fPos; + OnScroll(CFWL_EventScroll::Code::TrackPos, fPos); + } +} + +void CFWL_ScrollBar::DoMouseLeave(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState) { + if (iState == CFWL_PartState_Normal) + return; + + iState = CFWL_PartState_Normal; + Repaint(&rtItem); +} + +void CFWL_ScrollBar::DoMouseHover(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState) { + if (iState == CFWL_PartState_Hovered) + return; + + iState = CFWL_PartState_Hovered; + Repaint(&rtItem); +} + +CFWL_ScrollBar::Timer::Timer(CFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {} + +void CFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) { + CFWL_ScrollBar* pButton = static_cast(m_pWidget); + + if (pButton->m_pTimerInfo) + pButton->m_pTimerInfo->StopTimer(); + + if (!pButton->SendEvent()) + pButton->m_pTimerInfo = StartTimer(0, true); +} diff --git a/xfa/fwl/cfwl_scrollbar.h b/xfa/fwl/cfwl_scrollbar.h new file mode 100644 index 0000000000..808975ed81 --- /dev/null +++ b/xfa/fwl/cfwl_scrollbar.h @@ -0,0 +1,148 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_SCROLLBAR_H_ +#define XFA_FWL_CFWL_SCROLLBAR_H_ + +#include + +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/cfwl_eventscroll.h" +#include "xfa/fwl/cfwl_timer.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetproperties.h" + +class CFWL_Widget; + +#define FWL_STYLEEXT_SCB_Horz (0L << 0) +#define FWL_STYLEEXT_SCB_Vert (1L << 0) + +class CFWL_ScrollBar : public CFWL_Widget { + public: + CFWL_ScrollBar(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + ~CFWL_ScrollBar() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void GetRange(FX_FLOAT* fMin, FX_FLOAT* fMax) const { + ASSERT(fMin); + ASSERT(fMax); + *fMin = m_fRangeMin; + *fMax = m_fRangeMax; + } + void SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { + m_fRangeMin = fMin; + m_fRangeMax = fMax; + } + FX_FLOAT GetPageSize() const { return m_fPageSize; } + void SetPageSize(FX_FLOAT fPageSize) { m_fPageSize = fPageSize; } + FX_FLOAT GetStepSize() const { return m_fStepSize; } + void SetStepSize(FX_FLOAT fStepSize) { m_fStepSize = fStepSize; } + FX_FLOAT GetPos() const { return m_fPos; } + void SetPos(FX_FLOAT fPos) { m_fPos = fPos; } + void SetTrackPos(FX_FLOAT fTrackPos); + + private: + class Timer : public CFWL_Timer { + public: + explicit Timer(CFWL_ScrollBar* pToolTip); + ~Timer() override {} + + void Run(CFWL_TimerInfo* pTimerInfo) override; + }; + friend class CFWL_ScrollBar::Timer; + + bool IsVertical() const { + return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert); + } + void DrawTrack(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bLower, + const CFX_Matrix* pMatrix); + void DrawArrowBtn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bMinBtn, + const CFX_Matrix* pMatrix); + void DrawThumb(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void Layout(); + void CalcButtonLen(); + void CalcMinButtonRect(CFX_RectF& rect); + void CalcMaxButtonRect(CFX_RectF& rect); + void CalcThumbButtonRect(CFX_RectF& rect); + void CalcMinTrackRect(CFX_RectF& rect); + void CalcMaxTrackRect(CFX_RectF& rect); + FX_FLOAT GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy); + + bool SendEvent(); + bool OnScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos); + void OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); + void OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); + void OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); + void OnMouseLeave(); + void OnMouseWheel(FX_FLOAT fx, + FX_FLOAT fy, + uint32_t dwFlags, + FX_FLOAT fDeltaX, + FX_FLOAT fDeltaY); + bool DoScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos); + void DoMouseDown(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy); + void DoMouseUp(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy); + void DoMouseMove(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy); + void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); + void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); + + CFWL_TimerInfo* m_pTimerInfo; + FX_FLOAT m_fRangeMin; + FX_FLOAT m_fRangeMax; + FX_FLOAT m_fPageSize; + FX_FLOAT m_fStepSize; + FX_FLOAT m_fPos; + FX_FLOAT m_fTrackPos; + int32_t m_iMinButtonState; + int32_t m_iMaxButtonState; + int32_t m_iThumbButtonState; + int32_t m_iMinTrackState; + int32_t m_iMaxTrackState; + FX_FLOAT m_fLastTrackPos; + FX_FLOAT m_cpTrackPointX; + FX_FLOAT m_cpTrackPointY; + int32_t m_iMouseWheel; + bool m_bMouseDown; + FX_FLOAT m_fButtonLen; + bool m_bMinSize; + CFX_RectF m_rtClient; + CFX_RectF m_rtThumb; + CFX_RectF m_rtMinBtn; + CFX_RectF m_rtMaxBtn; + CFX_RectF m_rtMinTrack; + CFX_RectF m_rtMaxTrack; + FX_FLOAT m_fMinThumb; + CFWL_ScrollBar::Timer m_Timer; +}; + +#endif // XFA_FWL_CFWL_SCROLLBAR_H_ diff --git a/xfa/fwl/cfwl_spinbutton.cpp b/xfa/fwl/cfwl_spinbutton.cpp new file mode 100644 index 0000000000..1c6662e702 --- /dev/null +++ b/xfa/fwl/cfwl_spinbutton.cpp @@ -0,0 +1,363 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_spinbutton.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_timerinfo.h" +#include "xfa/fwl/cfwl_widgetproperties.h" +#include "xfa/fwl/ifwl_themeprovider.h" + +namespace { +const int kElapseTime = 200; + +} // namespace + +CFWL_SpinButton::CFWL_SpinButton( + const CFWL_App* app, + std::unique_ptr properties) + : CFWL_Widget(app, std::move(properties), nullptr), + m_dwUpState(CFWL_PartState_Normal), + m_dwDnState(CFWL_PartState_Normal), + m_iButtonIndex(0), + m_bLButtonDwn(false), + m_pTimerInfo(nullptr), + m_Timer(this) { + m_rtClient.Reset(); + m_rtUpButton.Reset(); + m_rtDnButton.Reset(); + m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; +} + +CFWL_SpinButton::~CFWL_SpinButton() {} + +FWL_Type CFWL_SpinButton::GetClassID() const { + return FWL_Type::SpinButton; +} + +void CFWL_SpinButton::Update() { + if (IsLocked()) + return; + + GetClientRect(m_rtClient); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { + m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, + m_rtClient.height / 2); + m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, + m_rtClient.width, m_rtClient.height / 2); + } else { + m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, + m_rtClient.height); + m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, + m_rtClient.width / 2, m_rtClient.height); + } +} + +FWL_WidgetHit CFWL_SpinButton::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (m_rtClient.Contains(fx, fy)) + return FWL_WidgetHit::Client; + if (HasBorder() && (m_rtClient.Contains(fx, fy))) + return FWL_WidgetHit::Border; + if (HasEdge()) { + CFX_RectF rtEdge; + GetEdgeRect(rtEdge); + if (rtEdge.Contains(fx, fy)) + return FWL_WidgetHit::Left; + } + if (m_rtUpButton.Contains(fx, fy)) + return FWL_WidgetHit::UpButton; + if (m_rtDnButton.Contains(fx, fy)) + return FWL_WidgetHit::DownButton; + return FWL_WidgetHit::Unknown; +} + +void CFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + + CFX_RectF rtClip(m_rtClient); + if (pMatrix) + pMatrix->TransformRect(rtClip); + + IFWL_ThemeProvider* pTheme = GetAvailableTheme(); + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + DrawUpButton(pGraphics, pTheme, pMatrix); + DrawDownButton(pGraphics, pTheme, pMatrix); +} + +void CFWL_SpinButton::DisableButton() { + m_dwDnState = CFWL_PartState_Disabled; +} + +bool CFWL_SpinButton::IsUpButtonEnabled() { + return m_dwUpState != CFWL_PartState_Disabled; +} + +bool CFWL_SpinButton::IsDownButtonEnabled() { + return m_dwDnState != CFWL_PartState_Disabled; +} + +void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::UpButton; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_dwUpState + 1; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + params.m_rtPart = m_rtUpButton; + pTheme->DrawBackground(¶ms); +} + +void CFWL_SpinButton::DrawDownButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DownButton; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_dwDnState + 1; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + params.m_rtPart = m_rtDnButton; + pTheme->DrawBackground(¶ms); +} + +void CFWL_SpinButton::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetType()) { + case CFWL_Message::Type::SetFocus: { + OnFocusChanged(pMessage, true); + break; + } + case CFWL_Message::Type::KillFocus: { + OnFocusChanged(pMessage, false); + break; + } + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMsg); + break; + default: + break; + } + break; + } + case CFWL_Message::Type::Key: { + CFWL_MessageKey* pKey = static_cast(pMessage); + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) + OnKeyDown(pKey); + break; + } + default: + break; + } + CFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) + m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); + else + m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); + + Repaint(&m_rtClient); +} + +void CFWL_SpinButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { + m_bLButtonDwn = true; + SetGrab(true); + SetFocus(true); + + bool bUpPress = + (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); + bool bDnPress = + (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); + if (!bUpPress && !bDnPress) + return; + if (bUpPress) { + m_iButtonIndex = 0; + m_dwUpState = CFWL_PartState_Pressed; + } + if (bDnPress) { + m_iButtonIndex = 1; + m_dwDnState = CFWL_PartState_Pressed; + } + + CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); + DispatchEvent(&wmPosChanged); + + Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); + m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); +} + +void CFWL_SpinButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { + if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) + return; + + m_bLButtonDwn = false; + SetGrab(false); + SetFocus(false); + if (m_pTimerInfo) { + m_pTimerInfo->StopTimer(); + m_pTimerInfo = nullptr; + } + bool bRepaint = false; + CFX_RectF rtInvalidate; + if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { + m_dwUpState = CFWL_PartState_Normal; + bRepaint = true; + rtInvalidate = m_rtUpButton; + } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { + m_dwDnState = CFWL_PartState_Normal; + bRepaint = true; + rtInvalidate = m_rtDnButton; + } + if (bRepaint) + Repaint(&rtInvalidate); +} + +void CFWL_SpinButton::OnMouseMove(CFWL_MessageMouse* pMsg) { + if (m_bLButtonDwn) + return; + + bool bRepaint = false; + CFX_RectF rtInvlidate; + rtInvlidate.Reset(); + if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { + if (IsUpButtonEnabled()) { + if (m_dwUpState == CFWL_PartState_Hovered) { + m_dwUpState = CFWL_PartState_Hovered; + bRepaint = true; + rtInvlidate = m_rtUpButton; + } + if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) { + m_dwDnState = CFWL_PartState_Normal; + if (bRepaint) + rtInvlidate.Union(m_rtDnButton); + else + rtInvlidate = m_rtDnButton; + + bRepaint = true; + } + } + if (!IsDownButtonEnabled()) + DisableButton(); + + } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { + if (IsDownButtonEnabled()) { + if (m_dwDnState != CFWL_PartState_Hovered) { + m_dwDnState = CFWL_PartState_Hovered; + bRepaint = true; + rtInvlidate = m_rtDnButton; + } + if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) { + m_dwUpState = CFWL_PartState_Normal; + if (bRepaint) + rtInvlidate.Union(m_rtUpButton); + else + rtInvlidate = m_rtUpButton; + bRepaint = true; + } + } + } else if (m_dwUpState != CFWL_PartState_Normal || + m_dwDnState != CFWL_PartState_Normal) { + if (m_dwUpState != CFWL_PartState_Normal) { + m_dwUpState = CFWL_PartState_Normal; + bRepaint = true; + rtInvlidate = m_rtUpButton; + } + if (m_dwDnState != CFWL_PartState_Normal) { + m_dwDnState = CFWL_PartState_Normal; + if (bRepaint) + rtInvlidate.Union(m_rtDnButton); + else + rtInvlidate = m_rtDnButton; + + bRepaint = true; + } + } + if (bRepaint) + Repaint(&rtInvlidate); +} + +void CFWL_SpinButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { + if (!pMsg) + return; + if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) + m_dwUpState = CFWL_PartState_Normal; + if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) + m_dwDnState = CFWL_PartState_Normal; + + Repaint(&m_rtClient); +} + +void CFWL_SpinButton::OnKeyDown(CFWL_MessageKey* pMsg) { + bool bUp = + pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; + bool bDown = + pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; + if (!bUp && !bDown) + return; + + bool bUpEnable = IsUpButtonEnabled(); + bool bDownEnable = IsDownButtonEnabled(); + if (!bUpEnable && !bDownEnable) + return; + + CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); + DispatchEvent(&wmPosChanged); + + Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); +} + +CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) + : CFWL_Timer(pToolTip) {} + +void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { + CFWL_SpinButton* pButton = static_cast(m_pWidget); + + if (!pButton->m_pTimerInfo) + return; + + CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); + pButton->DispatchEvent(&wmPosChanged); +} diff --git a/xfa/fwl/cfwl_spinbutton.h b/xfa/fwl/cfwl_spinbutton.h new file mode 100644 index 0000000000..4794461fb2 --- /dev/null +++ b/xfa/fwl/cfwl_spinbutton.h @@ -0,0 +1,73 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_SPINBUTTON_H_ +#define XFA_FWL_CFWL_SPINBUTTON_H_ + +#include + +#include "xfa/fwl/cfwl_timer.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxfa/cxfa_eventparam.h" + +#define FWL_STYLEEXE_SPB_Vert (1L << 0) + +class CFWL_MessageMouse; +class CFWL_WidgetProperties; + +class CFWL_SpinButton : public CFWL_Widget { + public: + CFWL_SpinButton(const CFWL_App* app, + std::unique_ptr properties); + ~CFWL_SpinButton() override; + + // CFWL_Widget + FWL_Type GetClassID() const override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + private: + class Timer : public CFWL_Timer { + public: + explicit Timer(CFWL_SpinButton* pToolTip); + ~Timer() override {} + + void Run(CFWL_TimerInfo* pTimerInfo) override; + }; + friend class CFWL_SpinButton::Timer; + + void DisableButton(); + bool IsUpButtonEnabled(); + bool IsDownButtonEnabled(); + void DrawUpButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDownButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MessageMouse* pMsg); + void OnLButtonUp(CFWL_MessageMouse* pMsg); + void OnMouseMove(CFWL_MessageMouse* pMsg); + void OnMouseLeave(CFWL_MessageMouse* pMsg); + void OnKeyDown(CFWL_MessageKey* pMsg); + + CFX_RectF m_rtClient; + CFX_RectF m_rtUpButton; + CFX_RectF m_rtDnButton; + uint32_t m_dwUpState; + uint32_t m_dwDnState; + int32_t m_iButtonIndex; + bool m_bLButtonDwn; + CFWL_TimerInfo* m_pTimerInfo; + CFWL_SpinButton::Timer m_Timer; +}; + +#endif // XFA_FWL_CFWL_SPINBUTTON_H_ diff --git a/xfa/fwl/cfwl_sysbtn.cpp b/xfa/fwl/cfwl_sysbtn.cpp new file mode 100644 index 0000000000..6f78d0245d --- /dev/null +++ b/xfa/fwl/cfwl_sysbtn.cpp @@ -0,0 +1,49 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_sysbtn.h" + +#include "xfa/fwl/cfwl_themepart.h" + +CFWL_SysBtn::CFWL_SysBtn() { + m_rtBtn.Set(0, 0, 0, 0); + m_dwState = 0; +} + +CFWL_SysBtn::~CFWL_SysBtn() {} + +bool CFWL_SysBtn::IsDisabled() const { + return !!(m_dwState & FWL_SYSBUTTONSTATE_Disabled); +} + +void CFWL_SysBtn::SetNormal() { + m_dwState &= 0xFFF0; +} + +void CFWL_SysBtn::SetPressed() { + SetNormal(); + m_dwState |= FWL_SYSBUTTONSTATE_Pressed; +} + +void CFWL_SysBtn::SetHover() { + SetNormal(); + m_dwState |= FWL_SYSBUTTONSTATE_Hover; +} + +void CFWL_SysBtn::SetDisabled(bool bDisabled) { + bDisabled ? m_dwState |= FWL_SYSBUTTONSTATE_Disabled + : m_dwState &= ~FWL_SYSBUTTONSTATE_Disabled; +} + +uint32_t CFWL_SysBtn::GetPartState() const { + if (IsDisabled()) + return CFWL_PartState_Disabled; + if (m_dwState & FWL_SYSBUTTONSTATE_Pressed) + return CFWL_PartState_Pressed; + if (m_dwState & FWL_SYSBUTTONSTATE_Hover) + return CFWL_PartState_Hovered; + return CFWL_PartState_Normal; +} diff --git a/xfa/fwl/cfwl_sysbtn.h b/xfa/fwl/cfwl_sysbtn.h new file mode 100644 index 0000000000..e79b438f6a --- /dev/null +++ b/xfa/fwl/cfwl_sysbtn.h @@ -0,0 +1,33 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_SYSBTN_H_ +#define XFA_FWL_CFWL_SYSBTN_H_ + +#include "core/fxcrt/fx_coordinates.h" + +#define FWL_SYSBUTTONSTATE_Hover 0x0001 +#define FWL_SYSBUTTONSTATE_Pressed 0x0002 +#define FWL_SYSBUTTONSTATE_Disabled 0x0010 + +class CFWL_SysBtn { + public: + CFWL_SysBtn(); + ~CFWL_SysBtn(); + + bool IsDisabled() const; + uint32_t GetPartState() const; + + void SetNormal(); + void SetPressed(); + void SetHover(); + void SetDisabled(bool bDisabled); + + CFX_RectF m_rtBtn; + uint32_t m_dwState; +}; + +#endif // XFA_FWL_CFWL_SYSBTN_H_ diff --git a/xfa/fwl/cfwl_themebackground.h b/xfa/fwl/cfwl_themebackground.h new file mode 100644 index 0000000000..3f20488830 --- /dev/null +++ b/xfa/fwl/cfwl_themebackground.h @@ -0,0 +1,27 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_THEMEBACKGROUND_H_ +#define XFA_FWL_CFWL_THEMEBACKGROUND_H_ + +#include "core/fxge/fx_dib.h" +#include "xfa/fwl/cfwl_themepart.h" + +class CFX_DIBitmpa; +class CFX_Graphics; +class CFX_Path; + +class CFWL_ThemeBackground : public CFWL_ThemePart { + public: + CFWL_ThemeBackground() + : m_pGraphics(nullptr), m_pImage(nullptr), m_pPath(nullptr) {} + + CFX_Graphics* m_pGraphics; + CFX_DIBitmap* m_pImage; + CFX_Path* m_pPath; +}; + +#endif // XFA_FWL_CFWL_THEMEBACKGROUND_H_ diff --git a/xfa/fwl/cfwl_themepart.cpp b/xfa/fwl/cfwl_themepart.cpp new file mode 100644 index 0000000000..25592f3c9e --- /dev/null +++ b/xfa/fwl/cfwl_themepart.cpp @@ -0,0 +1,18 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_themepart.h" + +CFWL_ThemePart::CFWL_ThemePart() + : m_pWidget(nullptr), + m_iPart(CFWL_Part::None), + m_dwStates(CFWL_PartState_Normal), + m_bMaximize(false), + m_bStaticBackground(false), + m_pData(nullptr) { + m_rtPart.Reset(); + m_matrix.SetIdentity(); +} diff --git a/xfa/fwl/cfwl_themepart.h b/xfa/fwl/cfwl_themepart.h new file mode 100644 index 0000000000..677d07b9c0 --- /dev/null +++ b/xfa/fwl/cfwl_themepart.h @@ -0,0 +1,96 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_THEMEPART_H_ +#define XFA_FWL_CFWL_THEMEPART_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_system.h" + +enum class CFWL_Part { + None = 0, + + BackArrow, + Background, + Border, + Caption, + Check, + CheckBox, + CloseBox, + CombTextLine, + DateInBK, + DateInCircle, + DatesIn, + DatesOut, + DownButton, + DropDownButton, + Edge, + ForeArrow, + HSeparator, + HeadText, + Header, + Icon, + Image, + LBtn, + ListItem, + LowerTrack, + MinimizeBox, + MaximizeBox, + NarrowCaption, + RBtn, + StretchHandler, + Thumb, + ThumbBackArrow, + ThumbForeArrow, + ThumbLowerTrack, + ThumbThumb, + ThumbUpperTrack, + Today, + TodayCircle, + UpButton, + UpperTrack, + VSeparator, + Week, + WeekNum, + WeekNumSep +}; + +enum CFWL_PartState { + CFWL_PartState_Normal = 0, + + CFWL_PartState_Checked = 1 << 1, + CFWL_PartState_Default = 1 << 2, + CFWL_PartState_Disabled = 1 << 3, + CFWL_PartState_Flagged = 1 << 4, + CFWL_PartState_Focused = 1 << 5, + CFWL_PartState_HightLight = 1 << 6, + CFWL_PartState_Hovered = 1 << 7, + CFWL_PartState_Inactive = 1 << 8, + CFWL_PartState_Neutral = 1 << 9, + CFWL_PartState_Pressed = 1 << 10, + CFWL_PartState_ReadOnly = 1 << 11, + CFWL_PartState_LSelected = 1 << 12, + CFWL_PartState_RSelected = 1 << 13, + CFWL_PartState_Selected = 1 << 14 +}; + +class CFWL_Widget; + +class CFWL_ThemePart { + public: + CFWL_ThemePart(); + + CFX_Matrix m_matrix; + CFX_RectF m_rtPart; + CFWL_Widget* m_pWidget; + CFWL_Part m_iPart; + uint32_t m_dwStates; + bool m_bMaximize; + bool m_bStaticBackground; + void* m_pData; +}; + +#endif // XFA_FWL_CFWL_THEMEPART_H_ diff --git a/xfa/fwl/cfwl_themetext.h b/xfa/fwl/cfwl_themetext.h new file mode 100644 index 0000000000..6cbc465bf3 --- /dev/null +++ b/xfa/fwl/cfwl_themetext.h @@ -0,0 +1,24 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_THEMETEXT_H_ +#define XFA_FWL_CFWL_THEMETEXT_H_ + +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/cfwl_themepart.h" + +class CFWL_ThemeText : public CFWL_ThemePart { + public: + CFWL_ThemeText() : m_pGraphics(nullptr) {} + + CFX_WideString m_wsText; + uint32_t m_dwTTOStyles; + int32_t m_iTTOAlign; + CFX_Graphics* m_pGraphics; +}; + +#endif // XFA_FWL_CFWL_THEMETEXT_H_ diff --git a/xfa/fwl/cfwl_timer.cpp b/xfa/fwl/cfwl_timer.cpp new file mode 100644 index 0000000000..c7214a4f72 --- /dev/null +++ b/xfa/fwl/cfwl_timer.cpp @@ -0,0 +1,31 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_timer.h" + +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_timerinfo.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_adaptertimermgr.h" +#include "xfa/fxfa/xfa_ffapp.h" + +CFWL_TimerInfo* CFWL_Timer::StartTimer(uint32_t dwElapse, bool bImmediately) { + const CFWL_App* pApp = m_pWidget->GetOwnerApp(); + if (!pApp) + return nullptr; + + CXFA_FFApp* pAdapterNative = pApp->GetAdapterNative(); + if (!pAdapterNative) + return nullptr; + + IFWL_AdapterTimerMgr* pAdapterTimerMgr = pAdapterNative->GetTimerMgr(); + if (!pAdapterTimerMgr) + return nullptr; + + CFWL_TimerInfo* pTimerInfo = nullptr; + pAdapterTimerMgr->Start(this, dwElapse, bImmediately, &pTimerInfo); + return pTimerInfo; +} diff --git a/xfa/fwl/cfwl_timer.h b/xfa/fwl/cfwl_timer.h new file mode 100644 index 0000000000..6c9079acfe --- /dev/null +++ b/xfa/fwl/cfwl_timer.h @@ -0,0 +1,27 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_TIMER_H_ +#define XFA_FWL_CFWL_TIMER_H_ + +#include "core/fxcrt/fx_system.h" + +class CFWL_TimerInfo; +class CFWL_Widget; + +class CFWL_Timer { + public: + explicit CFWL_Timer(CFWL_Widget* parent) : m_pWidget(parent) {} + virtual ~CFWL_Timer() {} + + virtual void Run(CFWL_TimerInfo* hTimer) = 0; + CFWL_TimerInfo* StartTimer(uint32_t dwElapse, bool bImmediately); + + protected: + CFWL_Widget* m_pWidget; // Not owned. +}; + +#endif // XFA_FWL_CFWL_TIMER_H_ diff --git a/xfa/fwl/cfwl_timerinfo.cpp b/xfa/fwl/cfwl_timerinfo.cpp new file mode 100644 index 0000000000..8c7aaebbbb --- /dev/null +++ b/xfa/fwl/cfwl_timerinfo.cpp @@ -0,0 +1,13 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_timerinfo.h" + +#include "xfa/fwl/ifwl_adaptertimermgr.h" + +void CFWL_TimerInfo::StopTimer() { + m_pMgr->Stop(this); +} diff --git a/xfa/fwl/cfwl_timerinfo.h b/xfa/fwl/cfwl_timerinfo.h new file mode 100644 index 0000000000..a47fede60f --- /dev/null +++ b/xfa/fwl/cfwl_timerinfo.h @@ -0,0 +1,27 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_TIMERINFO_H_ +#define XFA_FWL_CFWL_TIMERINFO_H_ + +#include "core/fxcrt/fx_system.h" + +class IFWL_AdapterTimerMgr; + +class CFWL_TimerInfo { + public: + explicit CFWL_TimerInfo(IFWL_AdapterTimerMgr* mgr) : m_pMgr(mgr) { + ASSERT(mgr); + } + virtual ~CFWL_TimerInfo() {} + + void StopTimer(); + + private: + IFWL_AdapterTimerMgr* m_pMgr; // Not owned. +}; + +#endif // XFA_FWL_CFWL_TIMERINFO_H_ diff --git a/xfa/fwl/cfwl_widget.cpp b/xfa/fwl/cfwl_widget.cpp new file mode 100644 index 0000000000..4da576423a --- /dev/null +++ b/xfa/fwl/cfwl_widget.cpp @@ -0,0 +1,729 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_widget.h" + +#include +#include + +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_eventmouse.h" +#include "xfa/fwl/cfwl_form.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagemousewheel.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" +#include "xfa/fxfa/xfa_ffapp.h" + +#define FWL_STYLEEXT_MNU_Vert (1L << 0) +#define FWL_WGT_CalcHeight 2048 +#define FWL_WGT_CalcWidth 2048 +#define FWL_WGT_CalcMultiLineDefWidth 120.0f + +CFWL_Widget::CFWL_Widget(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter) + : m_pOwnerApp(app), + m_pWidgetMgr(app->GetWidgetMgr()), + m_pProperties(std::move(properties)), + m_pOuter(pOuter), + m_iLock(0), + m_pLayoutItem(nullptr), + m_nEventKey(0), + m_pDelegate(nullptr) { + ASSERT(m_pWidgetMgr); + + CFWL_Widget* pParent = m_pProperties->m_pParent; + m_pWidgetMgr->InsertWidget(pParent, this); + if (IsChild()) + return; + + CFWL_Widget* pOwner = m_pProperties->m_pOwner; + if (pOwner) + m_pWidgetMgr->SetOwner(pOwner, this); +} + +CFWL_Widget::~CFWL_Widget() { + NotifyDriver(); + m_pWidgetMgr->RemoveWidget(this); +} + +bool CFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { + return false; +} + +CFX_RectF CFWL_Widget::GetAutosizedWidgetRect() { + return CFX_RectF(); +} + +CFX_RectF CFWL_Widget::GetWidgetRect() { + return m_pProperties->m_rtWidget; +} + +void CFWL_Widget::InflateWidgetRect(CFX_RectF& rect) { + if (HasEdge()) { + FX_FLOAT fEdge = GetEdgeWidth(); + rect.Inflate(fEdge, fEdge); + } + if (HasBorder()) { + FX_FLOAT fBorder = GetBorderSize(true); + rect.Inflate(fBorder, fBorder); + } +} + +void CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { + m_pProperties->m_rtWidget = rect; + if (IsChild()) + return; + + m_pWidgetMgr->SetWidgetRect_Native(this, rect); +} + +void CFWL_Widget::GetClientRect(CFX_RectF& rect) { + GetEdgeRect(rect); + if (HasEdge()) { + FX_FLOAT fEdge = GetEdgeWidth(); + rect.Deflate(fEdge, fEdge); + } +} + +void CFWL_Widget::SetParent(CFWL_Widget* pParent) { + m_pProperties->m_pParent = pParent; + m_pWidgetMgr->SetParent(pParent, this); +} + +uint32_t CFWL_Widget::GetStyles() const { + return m_pProperties->m_dwStyles; +} + +void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, + uint32_t dwStylesRemoved) { + m_pProperties->m_dwStyles = + (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded; +} + +uint32_t CFWL_Widget::GetStylesEx() const { + return m_pProperties->m_dwStyleExes; +} +uint32_t CFWL_Widget::GetStates() const { + return m_pProperties->m_dwStates; +} + +void CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved) { + m_pProperties->m_dwStyleExes = + (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded; +} + +static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr, + CFWL_Widget* widget, + CFWL_NoteDriver* noteDriver) { + CFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget); + while (child) { + noteDriver->NotifyTargetHide(child); + NotifyHideChildWidget(widgetMgr, child, noteDriver); + child = widgetMgr->GetNextSiblingWidget(child); + } +} + +void CFWL_Widget::SetStates(uint32_t dwStates) { + m_pProperties->m_dwStates |= dwStates; + if (!(dwStates & FWL_WGTSTATE_Invisible)) + return; + + CFWL_NoteDriver* noteDriver = + static_cast(GetOwnerApp()->GetNoteDriver()); + CFWL_WidgetMgr* widgetMgr = GetOwnerApp()->GetWidgetMgr(); + noteDriver->NotifyTargetHide(this); + CFWL_Widget* child = widgetMgr->GetFirstChildWidget(this); + while (child) { + noteDriver->NotifyTargetHide(child); + NotifyHideChildWidget(widgetMgr, child, noteDriver); + child = widgetMgr->GetNextSiblingWidget(child); + } + return; +} + +void CFWL_Widget::RemoveStates(uint32_t dwStates) { + m_pProperties->m_dwStates &= ~dwStates; +} + +FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + CFX_RectF rtClient; + GetClientRect(rtClient); + if (rtClient.Contains(fx, fy)) + return FWL_WidgetHit::Client; + if (HasEdge()) { + CFX_RectF rtEdge; + GetEdgeRect(rtEdge); + if (rtEdge.Contains(fx, fy)) + return FWL_WidgetHit::Edge; + } + if (HasBorder()) { + CFX_RectF rtRelative; + GetRelativeRect(rtRelative); + if (rtRelative.Contains(fx, fy)) + return FWL_WidgetHit::Border; + } + return FWL_WidgetHit::Unknown; +} + +void CFWL_Widget::TransformTo(CFWL_Widget* pWidget, + FX_FLOAT& fx, + FX_FLOAT& fy) { + if (m_pWidgetMgr->IsFormDisabled()) { + CFX_SizeF szOffset; + if (IsParent(pWidget)) { + szOffset = GetOffsetFromParent(pWidget); + } else { + szOffset = pWidget->GetOffsetFromParent(this); + szOffset.x = -szOffset.x; + szOffset.y = -szOffset.y; + } + fx += szOffset.x; + fy += szOffset.y; + return; + } + CFX_RectF r; + CFX_Matrix m; + CFWL_Widget* parent = GetParent(); + if (parent) { + r = GetWidgetRect(); + fx += r.left; + fy += r.top; + GetMatrix(m, true); + m.TransformPoint(fx, fy); + } + CFWL_Widget* form1 = m_pWidgetMgr->GetSystemFormWidget(this); + if (!form1) + return; + + if (!pWidget) { + r = form1->GetWidgetRect(); + fx += r.left; + fy += r.top; + return; + } + CFWL_Widget* form2 = m_pWidgetMgr->GetSystemFormWidget(pWidget); + if (!form2) + return; + if (form1 != form2) { + r = form1->GetWidgetRect(); + fx += r.left; + fy += r.top; + r = form2->GetWidgetRect(); + fx -= r.left; + fy -= r.top; + } + parent = pWidget->GetParent(); + if (parent) { + pWidget->GetMatrix(m, true); + CFX_Matrix m1; + m1.SetIdentity(); + m1.SetReverse(m); + m1.TransformPoint(fx, fy); + r = pWidget->GetWidgetRect(); + fx -= r.left; + fy -= r.top; + } +} + +void CFWL_Widget::GetMatrix(CFX_Matrix& matrix, bool bGlobal) { + if (!m_pProperties) + return; + if (!bGlobal) { + matrix.SetIdentity(); + return; + } + + CFWL_Widget* parent = GetParent(); + CFX_ArrayTemplate parents; + while (parent) { + parents.Add(parent); + parent = parent->GetParent(); + } + matrix.SetIdentity(); + CFX_Matrix ctmOnParent; + CFX_RectF rect; + int32_t count = parents.GetSize(); + for (int32_t i = count - 2; i >= 0; i--) { + parent = parents.GetAt(i); + parent->GetMatrix(ctmOnParent, false); + rect = parent->GetWidgetRect(); + matrix.Concat(ctmOnParent, true); + matrix.Translate(rect.left, rect.top, true); + } + CFX_Matrix m; + m.SetIdentity(); + matrix.Concat(m, true); + parents.RemoveAll(); +} + +IFWL_ThemeProvider* CFWL_Widget::GetThemeProvider() const { + return m_pProperties->m_pThemeProvider; +} + +void CFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { + m_pProperties->m_pThemeProvider = pThemeProvider; +} + +bool CFWL_Widget::IsEnabled() const { + return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0; +} + +bool CFWL_Widget::IsActive() const { + return (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) == 0; +} + +bool CFWL_Widget::HasBorder() const { + return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border); +} + +bool CFWL_Widget::HasEdge() const { + return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask); +} + +bool CFWL_Widget::IsVisible() const { + return (m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) == 0; +} + +bool CFWL_Widget::IsOverLapper() const { + return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) == + FWL_WGTSTYLE_OverLapper; +} + +bool CFWL_Widget::IsPopup() const { + return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup); +} + +bool CFWL_Widget::IsChild() const { + return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child); +} + +bool CFWL_Widget::IsOffscreen() const { + return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen); +} + +void CFWL_Widget::GetEdgeRect(CFX_RectF& rtEdge) { + rtEdge = m_pProperties->m_rtWidget; + rtEdge.left = rtEdge.top = 0; + if (HasBorder()) { + FX_FLOAT fCX = GetBorderSize(true); + FX_FLOAT fCY = GetBorderSize(false); + rtEdge.Deflate(fCX, fCY); + } +} + +FX_FLOAT CFWL_Widget::GetBorderSize(bool bCX) { + FX_FLOAT* pfBorder = static_cast(GetThemeCapacity( + bCX ? CFWL_WidgetCapacity::CXBorder : CFWL_WidgetCapacity::CYBorder)); + if (!pfBorder) + return 0; + return *pfBorder; +} + +FX_FLOAT CFWL_Widget::GetEdgeWidth() { + CFWL_WidgetCapacity dwCapacity = CFWL_WidgetCapacity::None; + switch (m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask) { + case FWL_WGTSTYLE_EdgeFlat: { + dwCapacity = CFWL_WidgetCapacity::EdgeFlat; + break; + } + case FWL_WGTSTYLE_EdgeRaised: { + dwCapacity = CFWL_WidgetCapacity::EdgeRaised; + break; + } + case FWL_WGTSTYLE_EdgeSunken: { + dwCapacity = CFWL_WidgetCapacity::EdgeSunken; + break; + } + } + if (dwCapacity != CFWL_WidgetCapacity::None) { + FX_FLOAT* fRet = static_cast(GetThemeCapacity(dwCapacity)); + return fRet ? *fRet : 0; + } + return 0; +} + +void CFWL_Widget::GetRelativeRect(CFX_RectF& rect) { + rect = m_pProperties->m_rtWidget; + rect.left = rect.top = 0; +} + +void* CFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) { + IFWL_ThemeProvider* pTheme = GetAvailableTheme(); + if (!pTheme) + return nullptr; + + CFWL_ThemePart part; + part.m_pWidget = this; + return pTheme->GetCapacity(&part, dwCapacity); +} + +IFWL_ThemeProvider* CFWL_Widget::GetAvailableTheme() { + if (m_pProperties->m_pThemeProvider) + return m_pProperties->m_pThemeProvider; + + CFWL_Widget* pUp = this; + do { + pUp = (pUp->GetStyles() & FWL_WGTSTYLE_Popup) + ? m_pWidgetMgr->GetOwnerWidget(pUp) + : m_pWidgetMgr->GetParentWidget(pUp); + if (pUp) { + IFWL_ThemeProvider* pRet = pUp->GetThemeProvider(); + if (pRet) + return pRet; + } + } while (pUp); + return nullptr; +} + +CFWL_Widget* CFWL_Widget::GetRootOuter() { + CFWL_Widget* pRet = m_pOuter; + if (!pRet) + return nullptr; + + while (CFWL_Widget* pOuter = pRet->GetOuter()) + pRet = pOuter; + return pRet; +} + +CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText, + IFWL_ThemeProvider* pTheme, + bool bMultiLine) { + if (!pTheme) + return CFX_SizeF(); + + CFWL_ThemeText calPart; + calPart.m_pWidget = this; + calPart.m_wsText = wsText; + calPart.m_dwTTOStyles = + bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; + calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; + CFX_RectF rect; + FX_FLOAT fWidth = + bMultiLine ? FWL_WGT_CalcMultiLineDefWidth : FWL_WGT_CalcWidth; + rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); + pTheme->CalcTextRect(&calPart, rect); + return CFX_SizeF(rect.width, rect.height); +} + +void CFWL_Widget::CalcTextRect(const CFX_WideString& wsText, + IFWL_ThemeProvider* pTheme, + uint32_t dwTTOStyles, + int32_t iTTOAlign, + CFX_RectF& rect) { + CFWL_ThemeText calPart; + calPart.m_pWidget = this; + calPart.m_wsText = wsText; + calPart.m_dwTTOStyles = dwTTOStyles; + calPart.m_iTTOAlign = iTTOAlign; + pTheme->CalcTextRect(&calPart, rect); +} + +void CFWL_Widget::SetFocus(bool bFocus) { + if (m_pWidgetMgr->IsFormDisabled()) + return; + + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + CFWL_Widget* curFocus = pDriver->GetFocus(); + if (bFocus && curFocus != this) + pDriver->SetFocus(this); + else if (!bFocus && curFocus == this) + pDriver->SetFocus(nullptr); +} + +void CFWL_Widget::SetGrab(bool bSet) { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + pDriver->SetGrab(this, bSet); +} + +void CFWL_Widget::GetPopupPos(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) { + if (GetClassID() == FWL_Type::ComboBox) { + if (m_pWidgetMgr->IsFormDisabled()) { + m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor, + rtPopup); + return; + } + GetPopupPosComboBox(fMinHeight, fMaxHeight, rtAnchor, rtPopup); + return; + } + if (GetClassID() == FWL_Type::DateTimePicker && + m_pWidgetMgr->IsFormDisabled()) { + m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor, + rtPopup); + return; + } + GetPopupPosGeneral(fMinHeight, fMaxHeight, rtAnchor, rtPopup); +} + +bool CFWL_Widget::GetPopupPosMenu(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) { + FX_FLOAT fx = 0; + FX_FLOAT fy = 0; + + if (GetStylesEx() & FWL_STYLEEXT_MNU_Vert) { + bool bLeft = m_pProperties->m_rtWidget.left < 0; + FX_FLOAT fRight = rtAnchor.right() + rtPopup.width; + TransformTo(nullptr, fx, fy); + if (fRight + fx > 0.0f || bLeft) { + rtPopup.Set(rtAnchor.left - rtPopup.width, rtAnchor.top, rtPopup.width, + rtPopup.height); + } else { + rtPopup.Set(rtAnchor.right(), rtAnchor.top, rtPopup.width, + rtPopup.height); + } + } else { + FX_FLOAT fBottom = rtAnchor.bottom() + rtPopup.height; + TransformTo(nullptr, fx, fy); + if (fBottom + fy > 0.0f) { + rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, + rtPopup.height); + } else { + rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, + rtPopup.height); + } + } + rtPopup.Offset(fx, fy); + return true; +} + +bool CFWL_Widget::GetPopupPosComboBox(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) { + FX_FLOAT fx = 0; + FX_FLOAT fy = 0; + + FX_FLOAT fPopHeight = rtPopup.height; + if (rtPopup.height > fMaxHeight) + fPopHeight = fMaxHeight; + else if (rtPopup.height < fMinHeight) + fPopHeight = fMinHeight; + + FX_FLOAT fWidth = std::max(rtAnchor.width, rtPopup.width); + FX_FLOAT fBottom = rtAnchor.bottom() + fPopHeight; + TransformTo(nullptr, fx, fy); + if (fBottom + fy > 0.0f) + rtPopup.Set(rtAnchor.left, rtAnchor.top - fPopHeight, fWidth, fPopHeight); + else + rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), fWidth, fPopHeight); + + rtPopup.Offset(fx, fy); + return true; +} + +bool CFWL_Widget::GetPopupPosGeneral(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) { + FX_FLOAT fx = 0; + FX_FLOAT fy = 0; + + TransformTo(nullptr, fx, fy); + if (rtAnchor.bottom() + fy > 0.0f) { + rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, + rtPopup.height); + } else { + rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, + rtPopup.height); + } + rtPopup.Offset(fx, fy); + return true; +} + +void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource) { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); + if (!pNoteDriver) + return; + + pNoteDriver->RegisterEventTarget(this, pEventSource); +} + +void CFWL_Widget::UnregisterEventTarget() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); + if (!pNoteDriver) + return; + + pNoteDriver->UnregisterEventTarget(this); +} + +void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { + if (m_pOuter) { + m_pOuter->GetDelegate()->OnProcessEvent(pEvent); + return; + } + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); + if (!pNoteDriver) + return; + pNoteDriver->SendEvent(pEvent); +} + +void CFWL_Widget::Repaint(const CFX_RectF* pRect) { + if (pRect) { + m_pWidgetMgr->RepaintWidget(this, pRect); + return; + } + CFX_RectF rect; + rect = m_pProperties->m_rtWidget; + rect.left = rect.top = 0; + m_pWidgetMgr->RepaintWidget(this, &rect); +} + +void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, + CFWL_Part iPartBk, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFX_RectF rtRelative; + GetRelativeRect(rtRelative); + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = iPartBk; + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix, true); + param.m_rtPart = rtRelative; + pTheme->DrawBackground(¶m); +} + +void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics, + CFWL_Part iPartBorder, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFX_RectF rtRelative; + GetRelativeRect(rtRelative); + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = iPartBorder; + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix, true); + param.m_rtPart = rtRelative; + pTheme->DrawBackground(¶m); +} + +void CFWL_Widget::DrawEdge(CFX_Graphics* pGraphics, + CFWL_Part iPartEdge, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFX_RectF rtEdge; + GetEdgeRect(rtEdge); + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = iPartEdge; + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix, true); + param.m_rtPart = rtEdge; + pTheme->DrawBackground(¶m); +} + +void CFWL_Widget::NotifyDriver() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->NotifyTargetDestroy(this); +} + +CFX_SizeF CFWL_Widget::GetOffsetFromParent(CFWL_Widget* pParent) { + if (pParent == this) + return CFX_SizeF(); + + CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr) + return CFX_SizeF(); + + CFX_SizeF szRet(m_pProperties->m_rtWidget.left, + m_pProperties->m_rtWidget.top); + + CFWL_Widget* pDstWidget = GetParent(); + while (pDstWidget && pDstWidget != pParent) { + CFX_RectF rtDst = pDstWidget->GetWidgetRect(); + szRet += CFX_SizeF(rtDst.left, rtDst.top); + pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget); + } + return szRet; +} + +bool CFWL_Widget::IsParent(CFWL_Widget* pParent) { + CFWL_Widget* pUpWidget = GetParent(); + while (pUpWidget) { + if (pUpWidget == pParent) + return true; + pUpWidget = pUpWidget->GetParent(); + } + return false; +} + +void CFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage->m_pDstTarget) + return; + + CFWL_Widget* pWidget = pMessage->m_pDstTarget; + switch (pMessage->GetType()) { + case CFWL_Message::Type::Mouse: { + CFWL_MessageMouse* pMsgMouse = static_cast(pMessage); + + CFWL_EventMouse evt(pWidget, pWidget); + evt.m_dwCmd = pMsgMouse->m_dwCmd; + pWidget->DispatchEvent(&evt); + break; + } + default: + break; + } +} + +void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {} + +void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) {} diff --git a/xfa/fwl/cfwl_widget.h b/xfa/fwl/cfwl_widget.h new file mode 100644 index 0000000000..53839a761b --- /dev/null +++ b/xfa/fwl/cfwl_widget.h @@ -0,0 +1,196 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_WIDGET_H_ +#define XFA_FWL_CFWL_WIDGET_H_ +#include + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/cfwl_event.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/fwl_widgethit.h" +#include "xfa/fwl/ifwl_widgetdelegate.h" +#include "xfa/fwl/theme/cfwl_widgettp.h" + +enum class FWL_Type { + Unknown = 0, + + Barcode, + Caret, + CheckBox, + ComboBox, + DateTimePicker, + Edit, + Form, + FormProxy, + ListBox, + MonthCalendar, + PictureBox, + PushButton, + ScrollBar, + SpinButton, + ToolTip +}; + +class CFWL_App; +class CFWL_AppImp; +class CFWL_MessageKey; +class CFWL_Widget; +class CFWL_WidgetMgr; +class CFWL_WidgetProperties; +class IFWL_ThemeProvider; + +class CFWL_Widget : public IFWL_WidgetDelegate { + public: + ~CFWL_Widget() override; + + virtual FWL_Type GetClassID() const = 0; + virtual bool IsInstance(const CFX_WideStringC& wsClass) const; + virtual CFX_RectF GetAutosizedWidgetRect(); + virtual CFX_RectF GetWidgetRect(); + virtual void GetClientRect(CFX_RectF& rect); + virtual void ModifyStylesEx(uint32_t dwStylesExAdded, + uint32_t dwStylesExRemoved); + virtual void SetStates(uint32_t dwStates); + virtual void RemoveStates(uint32_t dwStates); + virtual void Update() = 0; + virtual FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy); + virtual void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) = 0; + virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); + + // IFWL_WidgetDelegate. + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void InflateWidgetRect(CFX_RectF& rect); + void SetWidgetRect(const CFX_RectF& rect); + + void SetParent(CFWL_Widget* pParent); + + CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); } + CFWL_Widget* GetOuter() const { return m_pOuter; } + + uint32_t GetStyles() const; + void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); + uint32_t GetStylesEx() const; + uint32_t GetStates() const; + + void LockUpdate() { m_iLock++; } + void UnlockUpdate() { + if (IsLocked()) + m_iLock--; + } + + void TransformTo(CFWL_Widget* pWidget, FX_FLOAT& fx, FX_FLOAT& fy); + void GetMatrix(CFX_Matrix& matrix, bool bGlobal); + IFWL_ThemeProvider* GetThemeProvider() const; + + void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } + IFWL_WidgetDelegate* GetDelegate() { + return m_pDelegate ? m_pDelegate : this; + } + const IFWL_WidgetDelegate* GetDelegate() const { + return m_pDelegate ? m_pDelegate : this; + } + + const CFWL_App* GetOwnerApp() const { return m_pOwnerApp; } + uint32_t GetEventKey() const { return m_nEventKey; } + void SetEventKey(uint32_t key) { m_nEventKey = key; } + + void* GetLayoutItem() const { return m_pLayoutItem; } + void SetLayoutItem(void* pItem) { m_pLayoutItem = pItem; } + + void SetFocus(bool bFocus); + void Repaint(const CFX_RectF* pRect); + + protected: + CFWL_Widget(const CFWL_App* app, + std::unique_ptr properties, + CFWL_Widget* pOuter); + + bool IsEnabled() const; + bool IsActive() const; + bool IsLocked() const { return m_iLock > 0; } + bool HasBorder() const; + bool HasEdge() const; + void GetEdgeRect(CFX_RectF& rtEdge); + FX_FLOAT GetBorderSize(bool bCX); + FX_FLOAT GetEdgeWidth(); + void GetRelativeRect(CFX_RectF& rect); + void* GetThemeCapacity(CFWL_WidgetCapacity dwCapacity); + IFWL_ThemeProvider* GetAvailableTheme(); + CFX_SizeF CalcTextSize(const CFX_WideString& wsText, + IFWL_ThemeProvider* pTheme, + bool bMultiLine); + void CalcTextRect(const CFX_WideString& wsText, + IFWL_ThemeProvider* pTheme, + uint32_t dwTTOStyles, + int32_t iTTOAlign, + CFX_RectF& rect); + void SetGrab(bool bSet); + void GetPopupPos(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup); + void RegisterEventTarget(CFWL_Widget* pEventSource); + void UnregisterEventTarget(); + void DispatchEvent(CFWL_Event* pEvent); + void DrawBorder(CFX_Graphics* pGraphics, + CFWL_Part iPartBorder, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawEdge(CFX_Graphics* pGraphics, + CFWL_Part iPartEdge, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + + const CFWL_App* const m_pOwnerApp; + CFWL_WidgetMgr* const m_pWidgetMgr; + std::unique_ptr m_pProperties; + CFWL_Widget* m_pOuter; + int32_t m_iLock; + + private: + CFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); } + CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent); + + bool IsVisible() const; + bool IsOverLapper() const; + bool IsPopup() const; + bool IsChild() const; + bool IsOffscreen() const; + CFWL_Widget* GetRootOuter(); + bool GetPopupPosMenu(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup); + bool GetPopupPosComboBox(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup); + bool GetPopupPosGeneral(FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup); + bool GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy); + void DrawBackground(CFX_Graphics* pGraphics, + CFWL_Part iPartBk, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void NotifyDriver(); + bool IsParent(CFWL_Widget* pParent); + + void* m_pLayoutItem; + uint32_t m_nEventKey; + IFWL_WidgetDelegate* m_pDelegate; // Not owned. +}; + +#endif // XFA_FWL_CFWL_WIDGET_H_ diff --git a/xfa/fwl/cfwl_widgetmgr.cpp b/xfa/fwl/cfwl_widgetmgr.cpp new file mode 100644 index 0000000000..825de0e14e --- /dev/null +++ b/xfa/fwl/cfwl_widgetmgr.cpp @@ -0,0 +1,732 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_widgetmgr.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_form.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/xfa_ffapp.h" + +namespace { + +const int kNeedRepaintHitPoints = 12; +const int kNeedRepaintHitPiece = 3; + +struct FWL_NEEDREPAINTHITDATA { + CFX_PointF hitPoint; + bool bNotNeedRepaint; + bool bNotContainByDirty; +}; + +} // namespace + +bool FWL_UseOffscreen(CFWL_Widget* pWidget) { +#if (_FX_OS_ == _FX_MACOSX_) + return false; +#else + return !!(pWidget->GetStyles() & FWL_WGTSTYLE_Offscreen); +#endif +} + +CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative) + : m_dwCapability(0), m_pAdapter(pAdapterNative->GetWidgetMgr(this)) { + ASSERT(m_pAdapter); + m_mapWidgetItem[nullptr] = pdfium::MakeUnique(); +#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) + m_rtScreen.Reset(); +#endif +} + +CFWL_WidgetMgr::~CFWL_WidgetMgr() {} + +CFWL_Widget* CFWL_WidgetMgr::GetParentWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + return pItem && pItem->pParent ? pItem->pParent->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetOwnerWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + return pItem && pItem->pOwner ? pItem->pOwner->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetFirstSiblingWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + if (!pItem) + return nullptr; + + pItem = pItem->pPrevious; + while (pItem && pItem->pPrevious) + pItem = pItem->pPrevious; + return pItem ? pItem->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetPriorSiblingWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + return pItem && pItem->pPrevious ? pItem->pPrevious->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetNextSiblingWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + return pItem && pItem->pNext ? pItem->pNext->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetFirstChildWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + return pItem && pItem->pChild ? pItem->pChild->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetLastChildWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + if (!pItem) + return nullptr; + + pItem = pItem->pChild; + while (pItem && pItem->pNext) + pItem = pItem->pNext; + return pItem ? pItem->pWidget : nullptr; +} + +CFWL_Widget* CFWL_WidgetMgr::GetSystemFormWidget(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + while (pItem) { + if (IsAbleNative(pItem->pWidget)) + return pItem->pWidget; + pItem = pItem->pParent; + } + return nullptr; +} + +void CFWL_WidgetMgr::AppendWidget(CFWL_Widget* pWidget) { + Item* pItem = GetWidgetMgrItem(pWidget); + if (!pItem) + return; + if (!pItem->pParent) + return; + + Item* pChild = pItem->pParent->pChild; + int32_t i = 0; + while (pChild) { + if (pChild == pItem) { + if (pChild->pPrevious) + pChild->pPrevious->pNext = pChild->pNext; + if (pChild->pNext) + pChild->pNext->pPrevious = pChild->pPrevious; + if (pItem->pParent->pChild == pItem) + pItem->pParent->pChild = pItem->pNext; + + pItem->pNext = nullptr; + pItem->pPrevious = nullptr; + break; + } + if (!pChild->pNext) + break; + + pChild = pChild->pNext; + ++i; + } + + pChild = pItem->pParent->pChild; + if (pChild) { + while (pChild->pNext) + pChild = pChild->pNext; + + pChild->pNext = pItem; + pItem->pPrevious = pChild; + } else { + pItem->pParent->pChild = pItem; + pItem->pPrevious = nullptr; + } + pItem->pNext = nullptr; +} + +void CFWL_WidgetMgr::RepaintWidget(CFWL_Widget* pWidget, + const CFX_RectF* pRect) { + if (!m_pAdapter) + return; + + CFWL_Widget* pNative = pWidget; + CFX_RectF rect(*pRect); + if (IsFormDisabled()) { + CFWL_Widget* pOuter = pWidget->GetOuter(); + while (pOuter) { + CFX_RectF rtTemp = pNative->GetWidgetRect(); + rect.left += rtTemp.left; + rect.top += rtTemp.top; + pNative = pOuter; + pOuter = pOuter->GetOuter(); + } + } else if (!IsAbleNative(pWidget)) { + pNative = GetSystemFormWidget(pWidget); + if (!pNative) + return; + + pWidget->TransformTo(pNative, rect.left, rect.top); + } + AddRedrawCounts(pNative); + m_pAdapter->RepaintWidget(pNative, &rect); +} + +void CFWL_WidgetMgr::InsertWidget(CFWL_Widget* pParent, CFWL_Widget* pChild) { + Item* pParentItem = GetWidgetMgrItem(pParent); + if (!pParentItem) { + auto item = pdfium::MakeUnique(pParent); + pParentItem = item.get(); + m_mapWidgetItem[pParent] = std::move(item); + + pParentItem->pParent = GetWidgetMgrItem(nullptr); + AppendWidget(pParent); + } + + Item* pItem = GetWidgetMgrItem(pChild); + if (!pItem) { + auto item = pdfium::MakeUnique(pChild); + pItem = item.get(); + m_mapWidgetItem[pChild] = std::move(item); + } + if (pItem->pParent && pItem->pParent != pParentItem) { + if (pItem->pPrevious) + pItem->pPrevious->pNext = pItem->pNext; + if (pItem->pNext) + pItem->pNext->pPrevious = pItem->pPrevious; + if (pItem->pParent->pChild == pItem) + pItem->pParent->pChild = pItem->pNext; + } + pItem->pParent = pParentItem; + AppendWidget(pChild); +} + +void CFWL_WidgetMgr::RemoveWidget(CFWL_Widget* pWidget) { + Item* pItem = GetWidgetMgrItem(pWidget); + if (!pItem) + return; + if (pItem->pPrevious) + pItem->pPrevious->pNext = pItem->pNext; + if (pItem->pNext) + pItem->pNext->pPrevious = pItem->pPrevious; + if (pItem->pParent && pItem->pParent->pChild == pItem) + pItem->pParent->pChild = pItem->pNext; + + Item* pChild = pItem->pChild; + while (pChild) { + Item* pNext = pChild->pNext; + RemoveWidget(pChild->pWidget); + pChild = pNext; + } + m_mapWidgetItem.erase(pWidget); +} + +void CFWL_WidgetMgr::SetOwner(CFWL_Widget* pOwner, CFWL_Widget* pOwned) { + Item* pParentItem = GetWidgetMgrItem(pOwner); + if (!pParentItem) { + auto item = pdfium::MakeUnique(pOwner); + pParentItem = item.get(); + m_mapWidgetItem[pOwner] = std::move(item); + + pParentItem->pParent = GetWidgetMgrItem(nullptr); + AppendWidget(pOwner); + } + + Item* pItem = GetWidgetMgrItem(pOwned); + if (!pItem) { + auto item = pdfium::MakeUnique(pOwned); + pItem = item.get(); + m_mapWidgetItem[pOwned] = std::move(item); + } + pItem->pOwner = pParentItem; +} +void CFWL_WidgetMgr::SetParent(CFWL_Widget* pParent, CFWL_Widget* pChild) { + Item* pParentItem = GetWidgetMgrItem(pParent); + Item* pItem = GetWidgetMgrItem(pChild); + if (!pItem) + return; + if (pItem->pParent && pItem->pParent != pParentItem) { + if (pItem->pPrevious) + pItem->pPrevious->pNext = pItem->pNext; + if (pItem->pNext) + pItem->pNext->pPrevious = pItem->pPrevious; + if (pItem->pParent->pChild == pItem) + pItem->pParent->pChild = pItem->pNext; + + pItem->pNext = nullptr; + pItem->pPrevious = nullptr; + } + pItem->pParent = pParentItem; + AppendWidget(pChild); +} + +void CFWL_WidgetMgr::SetWidgetRect_Native(CFWL_Widget* pWidget, + const CFX_RectF& rect) { + if (!FWL_UseOffscreen(pWidget)) + return; + + Item* pItem = GetWidgetMgrItem(pWidget); + pItem->iRedrawCounter++; + if (pItem->pOffscreen) { + CFX_RenderDevice* pDevice = pItem->pOffscreen->GetRenderDevice(); + if (pDevice && pDevice->GetBitmap()) { + CFX_DIBitmap* pBitmap = pDevice->GetBitmap(); + if (pBitmap->GetWidth() - rect.width > 1 || + pBitmap->GetHeight() - rect.height > 1) { + pItem->pOffscreen.reset(); + } + } + } +#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) + pItem->bOutsideChanged = !m_rtScreen.Contains(rect); +#endif +} + +CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent, + FX_FLOAT x, + FX_FLOAT y) { + if (!parent) + return nullptr; + + FX_FLOAT x1; + FX_FLOAT y1; + CFWL_Widget* child = GetLastChildWidget(parent); + while (child) { + if ((child->GetStates() & FWL_WGTSTATE_Invisible) == 0) { + x1 = x; + y1 = y; + CFX_Matrix matrixOnParent; + child->GetMatrix(matrixOnParent, false); + CFX_Matrix m; + m.SetIdentity(); + m.SetReverse(matrixOnParent); + m.TransformPoint(x1, y1); + CFX_RectF bounds = child->GetWidgetRect(); + if (bounds.Contains(x1, y1)) { + x1 -= bounds.left; + y1 -= bounds.top; + return GetWidgetAtPoint(child, x1, y1); + } + } + child = GetPriorSiblingWidget(child); + } + return parent; +} + +void CFWL_WidgetMgr::NotifySizeChanged(CFWL_Widget* pForm, + FX_FLOAT fx, + FX_FLOAT fy) { + if (FWL_UseOffscreen(pForm)) + GetWidgetMgrItem(pForm)->pOffscreen.reset(); +} + +CFWL_Widget* CFWL_WidgetMgr::NextTab(CFWL_Widget* parent, + CFWL_Widget* focus, + bool& bFind) { + CFWL_WidgetMgr* pMgr = parent->GetOwnerApp()->GetWidgetMgr(); + CFWL_Widget* child = pMgr->GetFirstChildWidget(parent); + while (child) { + if (focus == child) + bFind = true; + + if ((child->GetStyles() & FWL_WGTSTYLE_TabStop) && + (!focus || (focus != child && bFind))) { + return child; + } + CFWL_Widget* bRet = NextTab(child, focus, bFind); + if (bRet) + return bRet; + + child = pMgr->GetNextSiblingWidget(child); + } + return nullptr; +} + +int32_t CFWL_WidgetMgr::CountRadioButtonGroup(CFWL_Widget* pFirst) const { + int32_t iRet = 0; + CFWL_Widget* pChild = pFirst; + while (pChild) { + pChild = GetNextSiblingWidget(pChild); + ++iRet; + } + return iRet; +} + +CFWL_Widget* CFWL_WidgetMgr::GetRadioButtonGroupHeader( + CFWL_Widget* pRadioButton) const { + CFWL_Widget* pNext = pRadioButton; + if (pNext && (pNext->GetStyles() & FWL_WGTSTYLE_Group)) + return pNext; + return nullptr; +} + +void CFWL_WidgetMgr::GetSameGroupRadioButton( + CFWL_Widget* pRadioButton, + CFX_ArrayTemplate& group) const { + CFWL_Widget* pFirst = GetFirstSiblingWidget(pRadioButton); + if (!pFirst) + pFirst = pRadioButton; + + int32_t iGroup = CountRadioButtonGroup(pFirst); + if (iGroup < 2) + return; + group.Add(GetRadioButtonGroupHeader(pRadioButton)); +} + +CFWL_Widget* CFWL_WidgetMgr::GetDefaultButton(CFWL_Widget* pParent) const { + if ((pParent->GetClassID() == FWL_Type::PushButton) && + (pParent->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) { + return pParent; + } + + CFWL_Widget* child = + pParent->GetOwnerApp()->GetWidgetMgr()->GetFirstChildWidget(pParent); + while (child) { + if ((child->GetClassID() == FWL_Type::PushButton) && + (child->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) { + return child; + } + if (CFWL_Widget* find = GetDefaultButton(child)) + return find; + + child = child->GetOwnerApp()->GetWidgetMgr()->GetNextSiblingWidget(child); + } + return nullptr; +} + +void CFWL_WidgetMgr::AddRedrawCounts(CFWL_Widget* pWidget) { + GetWidgetMgrItem(pWidget)->iRedrawCounter++; +} + +void CFWL_WidgetMgr::ResetRedrawCounts(CFWL_Widget* pWidget) { + GetWidgetMgrItem(pWidget)->iRedrawCounter = 0; +} + +CFWL_WidgetMgr::Item* CFWL_WidgetMgr::GetWidgetMgrItem( + CFWL_Widget* pWidget) const { + auto it = m_mapWidgetItem.find(pWidget); + return it != m_mapWidgetItem.end() ? static_cast(it->second.get()) + : nullptr; +} + +bool CFWL_WidgetMgr::IsAbleNative(CFWL_Widget* pWidget) const { + if (!pWidget) + return false; + if (!pWidget->IsInstance(FX_WSTRC(FWL_CLASS_Form))) + return false; + + uint32_t dwStyles = pWidget->GetStyles(); + return ((dwStyles & FWL_WGTSTYLE_WindowTypeMask) == + FWL_WGTSTYLE_OverLapper) || + (dwStyles & FWL_WGTSTYLE_Popup); +} + +void CFWL_WidgetMgr::GetAdapterPopupPos(CFWL_Widget* pWidget, + FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) const { + m_pAdapter->GetPopupPos(pWidget, fMinHeight, fMaxHeight, rtAnchor, rtPopup); +} + +void CFWL_WidgetMgr::OnSetCapability(uint32_t dwCapability) { + m_dwCapability = dwCapability; +} + +void CFWL_WidgetMgr::OnProcessMessageToForm(CFWL_Message* pMessage) { + if (!pMessage) + return; + if (!pMessage->m_pDstTarget) + return; + + CFWL_Widget* pDstWidget = pMessage->m_pDstTarget; + const CFWL_App* pApp = pDstWidget->GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pNoteDriver = + static_cast(pApp->GetNoteDriver()); + if (!pNoteDriver) + return; + + std::unique_ptr pClonedMessage = pMessage->Clone(); + if (IsFormDisabled()) + pNoteDriver->ProcessMessage(pClonedMessage.get()); + else + pNoteDriver->QueueMessage(std::move(pClonedMessage)); + +#if (_FX_OS_ == _FX_MACOSX_) + CFWL_NoteLoop* pTopLoop = pNoteDriver->GetTopLoop(); + if (pTopLoop) + pNoteDriver->UnqueueMessage(pTopLoop); +#endif +} + +void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pWidget || !pGraphics) + return; + + CFX_Graphics* pTemp = DrawWidgetBefore(pWidget, pGraphics, pMatrix); + CFX_RectF clipCopy = pWidget->GetWidgetRect(); + clipCopy.left = clipCopy.top = 0; + + if (UseOffscreenDirect(pWidget)) { + DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); + return; + } + CFX_RectF clipBounds; + +#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ || \ + _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_ + pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); + pGraphics->GetClipRect(clipBounds); + clipCopy = clipBounds; +#elif _FX_OS_ == _FX_MACOSX_ + if (IsFormDisabled()) { + pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); + pGraphics->GetClipRect(clipBounds); + clipCopy = clipBounds; + } else { + clipBounds.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d); + const_cast(pMatrix)->SetIdentity(); // FIXME: const cast. + pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); + } +#endif // _FX_OS_ == _FX_MACOSX_ + + if (!IsFormDisabled()) { + CFX_RectF rtClient; + pWidget->GetClientRect(rtClient); + clipBounds.Intersect(rtClient); + } + if (!clipBounds.IsEmpty()) + DrawChild(pWidget, clipBounds, pTemp, pMatrix); + + DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); + ResetRedrawCounts(pWidget); +} + +void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent, + const CFX_RectF& rtClip, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!parent) + return; + + bool bFormDisable = IsFormDisabled(); + CFWL_Widget* pNextChild = GetFirstChildWidget(parent); + while (pNextChild) { + CFWL_Widget* child = pNextChild; + pNextChild = GetNextSiblingWidget(child); + if (child->GetStates() & FWL_WGTSTATE_Invisible) + continue; + + CFX_RectF rtWidget = child->GetWidgetRect(); + if (rtWidget.IsEmpty()) + continue; + + CFX_Matrix widgetMatrix; + CFX_RectF clipBounds(rtWidget); + if (!bFormDisable) + child->GetMatrix(widgetMatrix, true); + if (pMatrix) + widgetMatrix.Concat(*pMatrix); + + if (!bFormDisable) { + widgetMatrix.TransformPoint(clipBounds.left, clipBounds.top); + clipBounds.Intersect(rtClip); + if (clipBounds.IsEmpty()) + continue; + + pGraphics->SaveGraphState(); + pGraphics->SetClipRect(clipBounds); + } + widgetMatrix.Translate(rtWidget.left, rtWidget.top, true); + + if (IFWL_WidgetDelegate* pDelegate = child->GetDelegate()) { + if (IsFormDisabled() || IsNeedRepaint(child, &widgetMatrix, rtClip)) + pDelegate->OnDrawWidget(pGraphics, &widgetMatrix); + } + if (!bFormDisable) + pGraphics->RestoreGraphState(); + + DrawChild(child, clipBounds, pGraphics, + bFormDisable ? &widgetMatrix : pMatrix); + child = GetNextSiblingWidget(child); + } +} + +CFX_Graphics* CFWL_WidgetMgr::DrawWidgetBefore(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!FWL_UseOffscreen(pWidget)) + return pGraphics; + + Item* pItem = GetWidgetMgrItem(pWidget); + if (!pItem->pOffscreen) { + pItem->pOffscreen.reset(new CFX_Graphics); + CFX_RectF rect = pWidget->GetWidgetRect(); + pItem->pOffscreen->Create((int32_t)rect.width, (int32_t)rect.height, + FXDIB_Argb); + } + CFX_RectF rect; + pGraphics->GetClipRect(rect); + pItem->pOffscreen->SetClipRect(rect); + return pItem->pOffscreen.get(); +} + +void CFWL_WidgetMgr::DrawWidgetAfter(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + CFX_RectF& rtClip, + const CFX_Matrix* pMatrix) { + if (FWL_UseOffscreen(pWidget)) { + Item* pItem = GetWidgetMgrItem(pWidget); + pGraphics->Transfer(pItem->pOffscreen.get(), rtClip.left, rtClip.top, + rtClip, pMatrix); +#ifdef _WIN32 + pItem->pOffscreen->ClearClip(); +#endif + } + Item* pItem = GetWidgetMgrItem(pWidget); + pItem->iRedrawCounter = 0; +} + +bool CFWL_WidgetMgr::IsNeedRepaint(CFWL_Widget* pWidget, + CFX_Matrix* pMatrix, + const CFX_RectF& rtDirty) { + Item* pItem = GetWidgetMgrItem(pWidget); + if (pItem && pItem->iRedrawCounter > 0) { + pItem->iRedrawCounter = 0; + return true; + } + + CFX_RectF rtWidget = pWidget->GetWidgetRect(); + rtWidget.left = rtWidget.top = 0; + pMatrix->TransformRect(rtWidget); + if (!rtWidget.IntersectWith(rtDirty)) + return false; + + CFWL_Widget* pChild = + pWidget->GetOwnerApp()->GetWidgetMgr()->GetFirstChildWidget(pWidget); + if (!pChild) + return true; + + CFX_RectF rtChilds; + rtChilds.Empty(); + bool bChildIntersectWithDirty = false; + bool bOrginPtIntersectWidthChild = false; + bool bOrginPtIntersectWidthDirty = + rtDirty.Contains(rtWidget.left, rtWidget.top); + static FWL_NEEDREPAINTHITDATA hitPoint[kNeedRepaintHitPoints]; + FXSYS_memset(hitPoint, 0, sizeof(hitPoint)); + FX_FLOAT fxPiece = rtWidget.width / kNeedRepaintHitPiece; + FX_FLOAT fyPiece = rtWidget.height / kNeedRepaintHitPiece; + hitPoint[2].hitPoint.x = hitPoint[6].hitPoint.x = rtWidget.left; + hitPoint[0].hitPoint.x = hitPoint[3].hitPoint.x = hitPoint[7].hitPoint.x = + hitPoint[10].hitPoint.x = fxPiece + rtWidget.left; + hitPoint[1].hitPoint.x = hitPoint[4].hitPoint.x = hitPoint[8].hitPoint.x = + hitPoint[11].hitPoint.x = fxPiece * 2 + rtWidget.left; + hitPoint[5].hitPoint.x = hitPoint[9].hitPoint.x = + rtWidget.width + rtWidget.left; + hitPoint[0].hitPoint.y = hitPoint[1].hitPoint.y = rtWidget.top; + hitPoint[2].hitPoint.y = hitPoint[3].hitPoint.y = hitPoint[4].hitPoint.y = + hitPoint[5].hitPoint.y = fyPiece + rtWidget.top; + hitPoint[6].hitPoint.y = hitPoint[7].hitPoint.y = hitPoint[8].hitPoint.y = + hitPoint[9].hitPoint.y = fyPiece * 2 + rtWidget.top; + hitPoint[10].hitPoint.y = hitPoint[11].hitPoint.y = + rtWidget.height + rtWidget.top; + do { + CFX_RectF rect = pChild->GetWidgetRect(); + CFX_RectF r = rect; + r.left += rtWidget.left; + r.top += rtWidget.top; + if (r.IsEmpty()) + continue; + if (r.Contains(rtDirty)) + return false; + if (!bChildIntersectWithDirty && r.IntersectWith(rtDirty)) + bChildIntersectWithDirty = true; + if (bOrginPtIntersectWidthDirty && !bOrginPtIntersectWidthChild) + bOrginPtIntersectWidthChild = rect.Contains(0, 0); + + if (rtChilds.IsEmpty()) + rtChilds = rect; + else if (!(pChild->GetStates() & FWL_WGTSTATE_Invisible)) + rtChilds.Union(rect); + + for (int32_t i = 0; i < kNeedRepaintHitPoints; i++) { + if (hitPoint[i].bNotContainByDirty || hitPoint[i].bNotNeedRepaint) + continue; + if (!rtDirty.Contains(hitPoint[i].hitPoint)) { + hitPoint[i].bNotContainByDirty = true; + continue; + } + if (r.Contains(hitPoint[i].hitPoint)) + hitPoint[i].bNotNeedRepaint = true; + } + pChild = + pChild->GetOwnerApp()->GetWidgetMgr()->GetNextSiblingWidget(pChild); + } while (pChild); + + if (!bChildIntersectWithDirty) + return true; + if (bOrginPtIntersectWidthDirty && !bOrginPtIntersectWidthChild) + return true; + if (rtChilds.IsEmpty()) + return true; + + int32_t repaintPoint = kNeedRepaintHitPoints; + for (int32_t i = 0; i < kNeedRepaintHitPoints; i++) { + if (hitPoint[i].bNotNeedRepaint) + repaintPoint--; + } + if (repaintPoint > 0) + return true; + + pMatrix->TransformRect(rtChilds); + if (rtChilds.Contains(rtDirty) || rtChilds.Contains(rtWidget)) + return false; + return true; +} + +bool CFWL_WidgetMgr::UseOffscreenDirect(CFWL_Widget* pWidget) const { + Item* pItem = GetWidgetMgrItem(pWidget); + if (!FWL_UseOffscreen(pWidget) || !(pItem->pOffscreen)) + return false; + +#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) + if (pItem->bOutsideChanged) { + CFX_RectF r = pWidget->GetWidgetRect(); + CFX_RectF temp(m_rtScreen); + temp.Deflate(50, 50); + if (!temp.Contains(r)) + return false; + + pItem->bOutsideChanged = false; + } +#endif + + return pItem->iRedrawCounter == 0; +} + +CFWL_WidgetMgr::Item::Item() : CFWL_WidgetMgr::Item(nullptr) {} + +CFWL_WidgetMgr::Item::Item(CFWL_Widget* widget) + : pParent(nullptr), + pOwner(nullptr), + pChild(nullptr), + pPrevious(nullptr), + pNext(nullptr), + pWidget(widget), + iRedrawCounter(0) +#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) + , + bOutsideChanged(false) +#endif +{ +} + +CFWL_WidgetMgr::Item::~Item() {} diff --git a/xfa/fwl/cfwl_widgetmgr.h b/xfa/fwl/cfwl_widgetmgr.h new file mode 100644 index 0000000000..10825b941d --- /dev/null +++ b/xfa/fwl/cfwl_widgetmgr.h @@ -0,0 +1,133 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_WIDGETMGR_H_ +#define XFA_FWL_CFWL_WIDGETMGR_H_ + +#include +#include + +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/fwl_error.h" +#include "xfa/fwl/ifwl_widgetmgrdelegate.h" +#include "xfa/fxgraphics/cfx_graphics.h" + +#define FWL_WGTMGR_DisableForm 0x00000002 + +class CFWL_Message; +class CXFA_FFApp; +class CXFA_FWLAdapterWidgetMgr; +class CFX_Graphics; +class CFX_Matrix; +class CFWL_Widget; + +class CFWL_WidgetMgr : public CFWL_WidgetMgrDelegate { + public: + explicit CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative); + ~CFWL_WidgetMgr(); + + // CFWL_WidgetMgrDelegate + void OnSetCapability(uint32_t dwCapability) override; + void OnProcessMessageToForm(CFWL_Message* pMessage) override; + void OnDrawWidget(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + CFWL_Widget* GetParentWidget(CFWL_Widget* pWidget) const; + CFWL_Widget* GetOwnerWidget(CFWL_Widget* pWidget) const; + CFWL_Widget* GetNextSiblingWidget(CFWL_Widget* pWidget) const; + CFWL_Widget* GetFirstChildWidget(CFWL_Widget* pWidget) const; + CFWL_Widget* GetSystemFormWidget(CFWL_Widget* pWidget) const; + + void RepaintWidget(CFWL_Widget* pWidget, const CFX_RectF* pRect); + + void InsertWidget(CFWL_Widget* pParent, CFWL_Widget* pChild); + void RemoveWidget(CFWL_Widget* pWidget); + void SetOwner(CFWL_Widget* pOwner, CFWL_Widget* pOwned); + void SetParent(CFWL_Widget* pParent, CFWL_Widget* pChild); + + void SetWidgetRect_Native(CFWL_Widget* pWidget, const CFX_RectF& rect); + + CFWL_Widget* GetWidgetAtPoint(CFWL_Widget* pParent, FX_FLOAT fx, FX_FLOAT fy); + + void NotifySizeChanged(CFWL_Widget* pForm, FX_FLOAT fx, FX_FLOAT fy); + + CFWL_Widget* NextTab(CFWL_Widget* parent, CFWL_Widget* focus, bool& bFind); + + void GetSameGroupRadioButton(CFWL_Widget* pRadioButton, + CFX_ArrayTemplate& group) const; + CFWL_Widget* GetDefaultButton(CFWL_Widget* pParent) const; + void AddRedrawCounts(CFWL_Widget* pWidget); + + bool IsFormDisabled() const { + return !!(m_dwCapability & FWL_WGTMGR_DisableForm); + } + + void GetAdapterPopupPos(CFWL_Widget* pWidget, + FX_FLOAT fMinHeight, + FX_FLOAT fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) const; + + private: + class Item { + public: + Item(); + explicit Item(CFWL_Widget* widget); + ~Item(); + + Item* pParent; + Item* pOwner; + Item* pChild; + Item* pPrevious; + Item* pNext; + CFWL_Widget* const pWidget; + std::unique_ptr pOffscreen; + int32_t iRedrawCounter; +#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) + bool bOutsideChanged; +#endif + }; + + CFWL_Widget* GetFirstSiblingWidget(CFWL_Widget* pWidget) const; + CFWL_Widget* GetPriorSiblingWidget(CFWL_Widget* pWidget) const; + CFWL_Widget* GetLastChildWidget(CFWL_Widget* pWidget) const; + Item* GetWidgetMgrItem(CFWL_Widget* pWidget) const; + + void AppendWidget(CFWL_Widget* pWidget); + + int32_t CountRadioButtonGroup(CFWL_Widget* pFirst) const; + CFWL_Widget* GetRadioButtonGroupHeader(CFWL_Widget* pRadioButton) const; + + void ResetRedrawCounts(CFWL_Widget* pWidget); + + void DrawChild(CFWL_Widget* pParent, + const CFX_RectF& rtClip, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix); + CFX_Graphics* DrawWidgetBefore(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix); + void DrawWidgetAfter(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + CFX_RectF& rtClip, + const CFX_Matrix* pMatrix); + bool IsNeedRepaint(CFWL_Widget* pWidget, + CFX_Matrix* pMatrix, + const CFX_RectF& rtDirty); + bool UseOffscreenDirect(CFWL_Widget* pWidget) const; + + bool IsAbleNative(CFWL_Widget* pWidget) const; + + uint32_t m_dwCapability; + std::map> m_mapWidgetItem; + CXFA_FWLAdapterWidgetMgr* const m_pAdapter; +#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) + CFX_RectF m_rtScreen; +#endif +}; + +#endif // XFA_FWL_CFWL_WIDGETMGR_H_ diff --git a/xfa/fwl/cfwl_widgetproperties.cpp b/xfa/fwl/cfwl_widgetproperties.cpp new file mode 100644 index 0000000000..1b41105ef3 --- /dev/null +++ b/xfa/fwl/cfwl_widgetproperties.cpp @@ -0,0 +1,19 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfwl_widgetproperties.h" + +CFWL_WidgetProperties::CFWL_WidgetProperties() + : m_dwStyles(FWL_WGTSTYLE_Child), + m_dwStyleExes(0), + m_dwStates(0), + m_pThemeProvider(nullptr), + m_pParent(nullptr), + m_pOwner(nullptr) { + m_rtWidget.Set(0, 0, 0, 0); +} + +CFWL_WidgetProperties::~CFWL_WidgetProperties() {} diff --git a/xfa/fwl/cfwl_widgetproperties.h b/xfa/fwl/cfwl_widgetproperties.h new file mode 100644 index 0000000000..065acad30f --- /dev/null +++ b/xfa/fwl/cfwl_widgetproperties.h @@ -0,0 +1,32 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFWL_WIDGETPROPERTIES_H_ +#define XFA_FWL_CFWL_WIDGETPROPERTIES_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/fwl_widgetdef.h" + +class IFWL_ThemeProvider; +class CFWL_Widget; + +class CFWL_WidgetProperties { + public: + CFWL_WidgetProperties(); + ~CFWL_WidgetProperties(); + + CFX_RectF m_rtWidget; + uint32_t m_dwStyles; + uint32_t m_dwStyleExes; + uint32_t m_dwStates; + IFWL_ThemeProvider* m_pThemeProvider; + CFWL_Widget* m_pParent; + CFWL_Widget* m_pOwner; +}; + +#endif // XFA_FWL_CFWL_WIDGETPROPERTIES_H_ diff --git a/xfa/fwl/cfx_barcode.cpp b/xfa/fwl/cfx_barcode.cpp new file mode 100644 index 0000000000..7af3aa1888 --- /dev/null +++ b/xfa/fwl/cfx_barcode.cpp @@ -0,0 +1,316 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/cfx_barcode.h" + +#include "xfa/fxbarcode/cbc_codabar.h" +#include "xfa/fxbarcode/cbc_code128.h" +#include "xfa/fxbarcode/cbc_code39.h" +#include "xfa/fxbarcode/cbc_codebase.h" +#include "xfa/fxbarcode/cbc_datamatrix.h" +#include "xfa/fxbarcode/cbc_ean13.h" +#include "xfa/fxbarcode/cbc_ean8.h" +#include "xfa/fxbarcode/cbc_pdf417i.h" +#include "xfa/fxbarcode/cbc_qrcode.h" +#include "xfa/fxbarcode/cbc_upca.h" +#include "xfa/fxbarcode/utils.h" + +namespace { + +CBC_CodeBase* CreateBarCodeEngineObject(BC_TYPE type) { + switch (type) { + case BC_CODE39: + return new CBC_Code39(); + case BC_CODABAR: + return new CBC_Codabar(); + case BC_CODE128: + return new CBC_Code128(BC_CODE128_B); + case BC_CODE128_B: + return new CBC_Code128(BC_CODE128_B); + case BC_CODE128_C: + return new CBC_Code128(BC_CODE128_C); + case BC_EAN8: + return new CBC_EAN8(); + case BC_UPCA: + return new CBC_UPCA(); + case BC_EAN13: + return new CBC_EAN13(); + case BC_QR_CODE: + return new CBC_QRCode(); + case BC_PDF417: + return new CBC_PDF417I(); + case BC_DATAMATRIX: + return new CBC_DataMatrix(); + case BC_UNKNOWN: + default: + return nullptr; + } +} + +} // namespace + +CFX_Barcode::CFX_Barcode() {} + +CFX_Barcode::~CFX_Barcode() {} + +bool CFX_Barcode::Create(BC_TYPE type) { + m_pBCEngine.reset(CreateBarCodeEngineObject(type)); + return !!m_pBCEngine; +} + +BC_TYPE CFX_Barcode::GetType() { + return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN; +} + +bool CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { + return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : false; +} + +bool CFX_Barcode::SetModuleHeight(int32_t moduleHeight) { + return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : false; +} + +bool CFX_Barcode::SetModuleWidth(int32_t moduleWidth) { + return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : false; +} + +bool CFX_Barcode::SetHeight(int32_t height) { + return m_pBCEngine ? m_pBCEngine->SetHeight(height) : false; +} + +bool CFX_Barcode::SetWidth(int32_t width) { + return m_pBCEngine ? m_pBCEngine->SetWidth(width) : false; +} + +bool CFX_Barcode::SetPrintChecksum(bool checksum) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine.get()) + ->SetPrintChecksum(checksum), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetDataLength(int32_t length) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine.get()) + ->SetDataLength(length), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetCalChecksum(bool state) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine.get()) + ->SetCalChecksum(state), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetFont(CFX_Font* pFont) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine + ? static_cast(m_pBCEngine.get())->SetFont(pFont) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetFontSize(FX_FLOAT size) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine.get()) + ->SetFontSize(size), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetFontColor(FX_ARGB color) { + switch (GetType()) { + case BC_CODE39: + case BC_CODABAR: + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + case BC_EAN8: + case BC_EAN13: + case BC_UPCA: + return m_pBCEngine ? (static_cast(m_pBCEngine.get()) + ->SetFontColor(color), + true) + : false; + default: + return false; + } +} + +bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { + typedef bool (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_CODE39: + memptr = (memptrtype)&CBC_Code39::SetTextLocation; + break; + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetTextLocation; + break; + case BC_CODE128: + case BC_CODE128_B: + case BC_CODE128_C: + memptr = (memptrtype)&CBC_Code128::SetTextLocation; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(location) : false; +} + +bool CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { + typedef bool (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_CODE39: + memptr = (memptrtype)&CBC_Code39::SetWideNarrowRatio; + break; + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetWideNarrowRatio; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(ratio) : false; +} + +bool CFX_Barcode::SetStartChar(FX_CHAR start) { + typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetStartChar; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(start) : false; +} + +bool CFX_Barcode::SetEndChar(FX_CHAR end) { + typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_CODABAR: + memptr = (memptrtype)&CBC_Codabar::SetEndChar; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(end) : false; +} + +bool CFX_Barcode::SetVersion(int32_t version) { + typedef bool (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_QR_CODE: + memptr = (memptrtype)&CBC_QRCode::SetVersion; + break; + default: + break; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(version) : false; +} + +bool CFX_Barcode::SetErrorCorrectionLevel(int32_t level) { + typedef bool (CBC_CodeBase::*memptrtype)(int32_t); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_QR_CODE: + memptr = (memptrtype)&CBC_QRCode::SetErrorCorrectionLevel; + break; + case BC_PDF417: + memptr = (memptrtype)&CBC_PDF417I::SetErrorCorrectionLevel; + break; + default: + return false; + } + return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(level) : false; +} +bool CFX_Barcode::SetTruncated(bool truncated) { + typedef void (CBC_CodeBase::*memptrtype)(bool); + memptrtype memptr = nullptr; + switch (GetType()) { + case BC_PDF417: + memptr = (memptrtype)&CBC_PDF417I::SetTruncated; + break; + default: + break; + } + return m_pBCEngine && memptr ? ((m_pBCEngine.get()->*memptr)(truncated), true) + : false; +} + +bool CFX_Barcode::Encode(const CFX_WideStringC& contents, + bool isDevice, + int32_t& e) { + return m_pBCEngine && m_pBCEngine->Encode(contents, isDevice, e); +} + +bool CFX_Barcode::RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matrix, + int32_t& e) { + return m_pBCEngine && m_pBCEngine->RenderDevice(device, matrix, e); +} diff --git a/xfa/fwl/cfx_barcode.h b/xfa/fwl/cfx_barcode.h new file mode 100644 index 0000000000..f639977cfc --- /dev/null +++ b/xfa/fwl/cfx_barcode.h @@ -0,0 +1,65 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CFX_BARCODE_H_ +#define XFA_FWL_CFX_BARCODE_H_ + +#include + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" +#include "core/fxge/fx_dib.h" +#include "xfa/fxbarcode/BC_Library.h" + +class CBC_CodeBase; +class CFX_Font; +class CFX_RenderDevice; +class CFX_Matrix; + +class CFX_Barcode { + public: + CFX_Barcode(); + ~CFX_Barcode(); + + bool Create(BC_TYPE type); + BC_TYPE GetType(); + bool Encode(const CFX_WideStringC& contents, bool isDevice, int32_t& e); + + bool RenderDevice(CFX_RenderDevice* device, + const CFX_Matrix* matrix, + int32_t& e); + + bool SetCharEncoding(BC_CHAR_ENCODING encoding); + + bool SetModuleHeight(int32_t moduleHeight); + bool SetModuleWidth(int32_t moduleWidth); + + bool SetHeight(int32_t height); + bool SetWidth(int32_t width); + + bool SetPrintChecksum(bool checksum); + bool SetDataLength(int32_t length); + bool SetCalChecksum(bool state); + + bool SetFont(CFX_Font* pFont); + bool SetFontSize(FX_FLOAT size); + bool SetFontColor(FX_ARGB color); + + bool SetTextLocation(BC_TEXT_LOC location); + + bool SetWideNarrowRatio(int32_t ratio); + bool SetStartChar(FX_CHAR start); + bool SetEndChar(FX_CHAR end); + bool SetVersion(int32_t version); + bool SetErrorCorrectionLevel(int32_t level); + bool SetTruncated(bool truncated); + + private: + std::unique_ptr m_pBCEngine; +}; + +#endif // XFA_FWL_CFX_BARCODE_H_ diff --git a/xfa/fwl/core/cfwl_app.cpp b/xfa/fwl/core/cfwl_app.cpp deleted file mode 100644 index fd4bb0816b..0000000000 --- a/xfa/fwl/core/cfwl_app.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_app.h" - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" - -CFWL_App::CFWL_App(CXFA_FFApp* pAdapter) - : m_pAdapterNative(pAdapter), - m_pWidgetMgr(pdfium::MakeUnique(pAdapter)), - m_pNoteDriver(pdfium::MakeUnique()) { - ASSERT(m_pAdapterNative); -} - -CFWL_App::~CFWL_App() {} diff --git a/xfa/fwl/core/cfwl_app.h b/xfa/fwl/core/cfwl_app.h deleted file mode 100644 index 26b514aca7..0000000000 --- a/xfa/fwl/core/cfwl_app.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_APP_H_ -#define XFA_FWL_CORE_CFWL_APP_H_ - -#include - -#include "core/fxcrt/fx_string.h" - -class CFWL_NoteDriver; -class CFWL_WidgetMgr; -class CXFA_FFApp; -class CXFA_FWLAdapterWidgetMgr; -class CFWL_Widget; - -enum FWL_KeyFlag { - FWL_KEYFLAG_Ctrl = 1 << 0, - FWL_KEYFLAG_Alt = 1 << 1, - FWL_KEYFLAG_Shift = 1 << 2, - FWL_KEYFLAG_Command = 1 << 3, - FWL_KEYFLAG_LButton = 1 << 4, - FWL_KEYFLAG_RButton = 1 << 5, - FWL_KEYFLAG_MButton = 1 << 6 -}; - -class CFWL_App { - public: - explicit CFWL_App(CXFA_FFApp* pAdapter); - ~CFWL_App(); - - CXFA_FFApp* GetAdapterNative() const { return m_pAdapterNative; } - CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr.get(); } - CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); } - - private: - CXFA_FFApp* const m_pAdapterNative; - std::unique_ptr m_pWidgetMgr; - std::unique_ptr m_pNoteDriver; -}; - -#endif // XFA_FWL_CORE_CFWL_APP_H_ diff --git a/xfa/fwl/core/cfwl_barcode.cpp b/xfa/fwl/core/cfwl_barcode.cpp deleted file mode 100644 index 8f5b08113c..0000000000 --- a/xfa/fwl/core/cfwl_barcode.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_barcode.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfx_barcode.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -CFWL_Barcode::CFWL_Barcode(const CFWL_App* app) - : CFWL_Edit(app, pdfium::MakeUnique(), nullptr), - m_dwStatus(0), - m_type(BC_UNKNOWN), - m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {} - -CFWL_Barcode::~CFWL_Barcode() {} - -FWL_Type CFWL_Barcode::GetClassID() const { - return FWL_Type::Barcode; -} - -void CFWL_Barcode::Update() { - if (IsLocked()) - return; - - CFWL_Edit::Update(); - GenerateBarcodeImageCache(); -} - -void CFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { - GenerateBarcodeImageCache(); - if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) - return; - - CFX_Matrix mt; - mt.e = GetRTClient().left; - mt.f = GetRTClient().top; - if (pMatrix) - mt.Concat(*pMatrix); - - int32_t errorCode = 0; - m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, - errorCode); - return; - } - CFWL_Edit::DrawWidget(pGraphics, pMatrix); -} - -void CFWL_Barcode::SetType(BC_TYPE type) { - if (m_type == type) - return; - - m_pBarcodeEngine.reset(); - m_type = type; - m_dwStatus = XFA_BCS_NeedUpdate; -} - -void CFWL_Barcode::SetText(const CFX_WideString& wsText) { - m_pBarcodeEngine.reset(); - m_dwStatus = XFA_BCS_NeedUpdate; - CFWL_Edit::SetText(wsText); -} - -bool CFWL_Barcode::IsProtectedType() const { - if (!m_pBarcodeEngine) - return true; - - BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); - if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || - tEngineType == BC_DATAMATRIX) { - return true; - } - return false; -} - -void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) { - if (pEvent->GetType() == CFWL_Event::Type::TextChanged) { - m_pBarcodeEngine.reset(); - m_dwStatus = XFA_BCS_NeedUpdate; - } - CFWL_Edit::OnProcessEvent(pEvent); -} - -void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING; - m_eCharEncoding = encoding; -} - -void CFWL_Barcode::SetModuleHeight(int32_t height) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT; - m_nModuleHeight = height; -} - -void CFWL_Barcode::SetModuleWidth(int32_t width) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH; - m_nModuleWidth = width; -} - -void CFWL_Barcode::SetDataLength(int32_t dataLength) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; - m_nDataLength = dataLength; - SetLimit(dataLength); -} - -void CFWL_Barcode::SetCalChecksum(bool calChecksum) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; - m_bCalChecksum = calChecksum; -} - -void CFWL_Barcode::SetPrintChecksum(bool printChecksum) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM; - m_bPrintChecksum = printChecksum; -} - -void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_TEXTLOCATION; - m_eTextLocation = location; -} - -void CFWL_Barcode::SetWideNarrowRatio(int32_t ratio) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO; - m_nWideNarrowRatio = ratio; -} - -void CFWL_Barcode::SetStartChar(FX_CHAR startChar) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR; - m_cStartChar = startChar; -} - -void CFWL_Barcode::SetEndChar(FX_CHAR endChar) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_ENDCHAR; - m_cEndChar = endChar; -} - -void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL; - m_nECLevel = ecLevel; -} - -void CFWL_Barcode::SetTruncated(bool truncated) { - m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED; - m_bTruncated = truncated; -} - -void CFWL_Barcode::GenerateBarcodeImageCache() { - if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) - return; - - m_dwStatus = 0; - CreateBarcodeEngine(); - if (!m_pBarcodeEngine) - return; - - CFX_WideString wsText = GetText(); - - CFWL_ThemePart part; - part.m_pWidget = this; - - IFWL_ThemeProvider* pTheme = GetAvailableTheme(); - CFGAS_GEFont* pFont = static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); - CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr; - if (pCXFont) - m_pBarcodeEngine->SetFont(pCXFont); - - FX_FLOAT* pFontSize = static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize)); - if (pFontSize) - m_pBarcodeEngine->SetFontSize(*pFontSize); - - FX_ARGB* pFontColor = static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TextColor)); - if (pFontColor) - m_pBarcodeEngine->SetFontColor(*pFontColor); - - m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height)); - m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width)); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING) - m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT) - m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH) - m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH) - m_pBarcodeEngine->SetDataLength(m_nDataLength); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM) - m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM) - m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION) - m_pBarcodeEngine->SetTextLocation(m_eTextLocation); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO) - m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR) - m_pBarcodeEngine->SetStartChar(m_cStartChar); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR) - m_pBarcodeEngine->SetEndChar(m_cEndChar); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_VERSION) - m_pBarcodeEngine->SetVersion(0); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL) - m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel); - if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) - m_pBarcodeEngine->SetTruncated(m_bTruncated); - - int32_t errorCode = 0; - m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), true, errorCode) - ? XFA_BCS_EncodeSuccess - : 0; -} - -void CFWL_Barcode::CreateBarcodeEngine() { - if (m_pBarcodeEngine || m_type == BC_UNKNOWN) - return; - - std::unique_ptr pBarcode(new CFX_Barcode); - if (pBarcode->Create(m_type)) - m_pBarcodeEngine = std::move(pBarcode); -} diff --git a/xfa/fwl/core/cfwl_barcode.h b/xfa/fwl/core/cfwl_barcode.h deleted file mode 100644 index 66b47ce3f0..0000000000 --- a/xfa/fwl/core/cfwl_barcode.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_BARCODE_H_ -#define XFA_FWL_CORE_CFWL_BARCODE_H_ - -#include - -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_scrollbar.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fxbarcode/BC_Library.h" - -class CFWL_WidgetProperties; -class CFX_Barcode; -class CFWL_Widget; - -#define XFA_BCS_NeedUpdate 0x0001 -#define XFA_BCS_EncodeSuccess 0x0002 - -enum FWL_BCDAttribute { - FWL_BCDATTRIBUTE_NONE = 0, - FWL_BCDATTRIBUTE_CHARENCODING = 1 << 0, - FWL_BCDATTRIBUTE_MODULEHEIGHT = 1 << 1, - FWL_BCDATTRIBUTE_MODULEWIDTH = 1 << 2, - FWL_BCDATTRIBUTE_DATALENGTH = 1 << 3, - FWL_BCDATTRIBUTE_CALCHECKSUM = 1 << 4, - FWL_BCDATTRIBUTE_PRINTCHECKSUM = 1 << 5, - FWL_BCDATTRIBUTE_TEXTLOCATION = 1 << 6, - FWL_BCDATTRIBUTE_WIDENARROWRATIO = 1 << 7, - FWL_BCDATTRIBUTE_STARTCHAR = 1 << 8, - FWL_BCDATTRIBUTE_ENDCHAR = 1 << 9, - FWL_BCDATTRIBUTE_VERSION = 1 << 10, - FWL_BCDATTRIBUTE_ECLEVEL = 1 << 11, - FWL_BCDATTRIBUTE_TRUNCATED = 1 << 12 -}; - -class CFWL_Barcode : public CFWL_Edit { - public: - explicit CFWL_Barcode(const CFWL_App* pApp); - ~CFWL_Barcode() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - - // CFWL_Edit - void SetText(const CFX_WideString& wsText) override; - - void SetType(BC_TYPE type); - bool IsProtectedType() const; - - void SetCharEncoding(BC_CHAR_ENCODING encoding); - void SetModuleHeight(int32_t height); - void SetModuleWidth(int32_t width); - void SetDataLength(int32_t dataLength); - void SetCalChecksum(bool calChecksum); - void SetPrintChecksum(bool printChecksum); - void SetTextLocation(BC_TEXT_LOC location); - void SetWideNarrowRatio(int32_t ratio); - void SetStartChar(FX_CHAR startChar); - void SetEndChar(FX_CHAR endChar); - void SetErrorCorrectionLevel(int32_t ecLevel); - void SetTruncated(bool truncated); - - private: - void GenerateBarcodeImageCache(); - void CreateBarcodeEngine(); - - std::unique_ptr m_pBarcodeEngine; - uint32_t m_dwStatus; - BC_TYPE m_type; - BC_CHAR_ENCODING m_eCharEncoding; - int32_t m_nModuleHeight; - int32_t m_nModuleWidth; - int32_t m_nDataLength; - bool m_bCalChecksum; - bool m_bPrintChecksum; - BC_TEXT_LOC m_eTextLocation; - int32_t m_nWideNarrowRatio; - FX_CHAR m_cStartChar; - FX_CHAR m_cEndChar; - int32_t m_nECLevel; - bool m_bTruncated; - uint32_t m_dwAttributeMask; -}; - -#endif // XFA_FWL_CORE_CFWL_BARCODE_H_ diff --git a/xfa/fwl/core/cfwl_caret.cpp b/xfa/fwl/core/cfwl_caret.cpp deleted file mode 100644 index f9e26a7e9f..0000000000 --- a/xfa/fwl/core/cfwl_caret.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_caret.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { - -const uint32_t kFrequency = 400; - -} // namespace - -CFWL_Caret::CFWL_Caret(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Widget(app, std::move(properties), pOuter), - m_pTimer(new CFWL_Caret::Timer(this)), - m_pTimerInfo(nullptr) { - SetStates(FWL_STATE_CAT_HightLight); -} - -CFWL_Caret::~CFWL_Caret() { - if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; - } -} - -FWL_Type CFWL_Caret::GetClassID() const { - return FWL_Type::Caret; -} - -void CFWL_Caret::Update() {} - -void CFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - if (!m_pProperties->m_pThemeProvider) - return; - - DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); -} - -void CFWL_Caret::ShowCaret() { - if (m_pTimerInfo) - m_pTimerInfo->StopTimer(); - m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); - RemoveStates(FWL_WGTSTATE_Invisible); -} - -void CFWL_Caret::HideCaret() { - if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; - } - SetStates(FWL_WGTSTATE_Invisible); -} - -void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) - return; - - CFX_RectF rect = GetWidgetRect(); - rect.Set(0, 0, rect.width, rect.height); - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_pGraphics = pGraphics; - param.m_rtPart = rect; - param.m_iPart = CFWL_Part::Background; - param.m_dwStates = CFWL_PartState_HightLight; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶m); -} - -void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} - -void CFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -CFWL_Caret::Timer::Timer(CFWL_Caret* pCaret) : CFWL_Timer(pCaret) {} - -void CFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) { - CFWL_Caret* pCaret = static_cast(m_pWidget); - if (!(pCaret->GetStates() & FWL_STATE_CAT_HightLight)) - pCaret->SetStates(FWL_STATE_CAT_HightLight); - else - pCaret->RemoveStates(FWL_STATE_CAT_HightLight); - - CFX_RectF rt = pCaret->GetWidgetRect(); - rt.Set(0, 0, rt.width + 1, rt.height); - pCaret->Repaint(&rt); -} diff --git a/xfa/fwl/core/cfwl_caret.h b/xfa/fwl/core/cfwl_caret.h deleted file mode 100644 index aa718b7af3..0000000000 --- a/xfa/fwl/core/cfwl_caret.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_CARET_H_ -#define XFA_FWL_CORE_CFWL_CARET_H_ - -#include - -#include "xfa/fwl/core/cfwl_timer.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_color.h" - -class CFWL_WidgetProperties; -class CFWL_Widget; - -#define FWL_STATE_CAT_HightLight 1 - -class CFWL_Caret : public CFWL_Widget { - public: - CFWL_Caret(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_Caret() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - void Update() override; - - void ShowCaret(); - void HideCaret(); - - private: - class Timer : public CFWL_Timer { - public: - explicit Timer(CFWL_Caret* pCaret); - ~Timer() override {} - - void Run(CFWL_TimerInfo* hTimer) override; - }; - friend class CFWL_Caret::Timer; - - void DrawCaretBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - - std::unique_ptr m_pTimer; - CFWL_TimerInfo* m_pTimerInfo; // not owned. -}; - -#endif // XFA_FWL_CORE_CFWL_CARET_H_ diff --git a/xfa/fwl/core/cfwl_checkbox.cpp b/xfa/fwl/core/cfwl_checkbox.cpp deleted file mode 100644 index 8d99d7acf5..0000000000 --- a/xfa/fwl/core/cfwl_checkbox.cpp +++ /dev/null @@ -1,458 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_checkbox.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { - -const int kCaptionMargin = 5; - -} // namespace - -CFWL_CheckBox::CFWL_CheckBox(const CFWL_App* app) - : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), - m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), - m_iTTOAlign(FDE_TTOALIGNMENT_Center), - m_bBtnDown(false), - m_fBoxHeight(16.0f) { - m_rtClient.Reset(); - m_rtBox.Reset(); - m_rtCaption.Reset(); - m_rtFocus.Reset(); -} - -CFWL_CheckBox::~CFWL_CheckBox() {} - -FWL_Type CFWL_CheckBox::GetClassID() const { - return FWL_Type::CheckBox; -} - -void CFWL_CheckBox::SetBoxSize(FX_FLOAT fHeight) { - m_fBoxHeight = fHeight; -} - -void CFWL_CheckBox::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - UpdateTextOutStyles(); - Layout(); -} - -void CFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) { - DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, - pMatrix); - } - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - int32_t dwStates = GetPartStates(); - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_dwStates = dwStates; - param.m_pGraphics = pGraphics; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtClient; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - param.m_pData = &m_rtFocus; - pTheme->DrawBackground(¶m); - - param.m_iPart = CFWL_Part::CheckBox; - param.m_rtPart = m_rtBox; - pTheme->DrawBackground(¶m); - - CFWL_ThemeText textParam; - textParam.m_pWidget = this; - textParam.m_iPart = CFWL_Part::Caption; - textParam.m_dwStates = dwStates; - textParam.m_pGraphics = pGraphics; - if (pMatrix) - textParam.m_matrix.Concat(*pMatrix); - textParam.m_rtPart = m_rtCaption; - textParam.m_wsText = L"Check box"; - textParam.m_dwTTOStyles = m_dwTTOStyles; - textParam.m_iTTOAlign = m_iTTOAlign; - pTheme->DrawText(&textParam); -} - -void CFWL_CheckBox::SetCheckState(int32_t iCheck) { - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; - switch (iCheck) { - case 1: - m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; - break; - case 2: - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) - m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; - break; - default: - break; - } - Repaint(&m_rtClient); -} - -void CFWL_CheckBox::Layout() { - m_pProperties->m_rtWidget.width = - FXSYS_round(m_pProperties->m_rtWidget.width); - m_pProperties->m_rtWidget.height = - FXSYS_round(m_pProperties->m_rtWidget.height); - GetClientRect(m_rtClient); - - FX_FLOAT fBoxTop = m_rtClient.top; - FX_FLOAT fClientBottom = m_rtClient.bottom(); - - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { - case FWL_STYLEEXT_CKB_Top: - break; - case FWL_STYLEEXT_CKB_Bottom: { - fBoxTop = fClientBottom - m_fBoxHeight; - break; - } - case FWL_STYLEEXT_CKB_VCenter: - default: { - fBoxTop = m_rtClient.top + (m_rtClient.height - m_fBoxHeight) / 2; - fBoxTop = FXSYS_floor(fBoxTop); - break; - } - } - - FX_FLOAT fBoxLeft = m_rtClient.left; - FX_FLOAT fTextLeft = 0.0; - FX_FLOAT fTextRight = 0.0; - FX_FLOAT fClientRight = m_rtClient.right(); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { - fBoxLeft = fClientRight - m_fBoxHeight; - fTextLeft = m_rtClient.left; - fTextRight = fBoxLeft; - } else { - fTextLeft = fBoxLeft + m_fBoxHeight; - fTextRight = fClientRight; - } - m_rtBox.Set(fBoxLeft, fBoxTop, m_fBoxHeight, m_fBoxHeight); - m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, - m_rtClient.height); - m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); - - CFX_RectF rtFocus; - rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, - m_rtCaption.height); - - CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider, m_dwTTOStyles, - m_iTTOAlign, rtFocus); - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { - FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); - FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); - FX_FLOAT fLeft = m_rtCaption.left; - FX_FLOAT fTop = m_rtCaption.top; - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == - FWL_STYLEEXT_CKB_Center) { - fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; - } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == - FWL_STYLEEXT_CKB_Right) { - fLeft = m_rtCaption.right() - fWidth; - } - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == - FWL_STYLEEXT_CKB_VCenter) { - fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; - } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == - FWL_STYLEEXT_CKB_Bottom) { - fTop = m_rtCaption.bottom() - fHeight; - } - m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); - } else { - m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); - } - m_rtFocus.Inflate(1, 1); -} - -uint32_t CFWL_CheckBox::GetPartStates() const { - int32_t dwStates = CFWL_PartState_Normal; - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == - FWL_STATE_CKB_Neutral) { - dwStates = CFWL_PartState_Neutral; - } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == - FWL_STATE_CKB_Checked) { - dwStates = CFWL_PartState_Checked; - } - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - dwStates |= CFWL_PartState_Disabled; - else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) - dwStates |= CFWL_PartState_Hovered; - else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) - dwStates |= CFWL_PartState_Pressed; - else - dwStates |= CFWL_PartState_Normal; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - dwStates |= CFWL_PartState_Focused; - return dwStates; -} - -void CFWL_CheckBox::UpdateTextOutStyles() { - switch (m_pProperties->m_dwStyleExes & - (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) { - case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: { - m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; - break; - } - case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Top: { - m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; - break; - } - case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Top: { - m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; - break; - } - case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_VCenter: { - m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - break; - } - case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: { - m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; - break; - } - case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Bottom: { - m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; - break; - } - case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Bottom: { - m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; - break; - } - case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Bottom: { - m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; - break; - } - case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: - default: { - m_iTTOAlign = FDE_TTOALIGNMENT_Center; - break; - } - } - m_dwTTOStyles = 0; - if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) - m_dwTTOStyles |= FDE_TTOSTYLE_RTL; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) - m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap; - else - m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; -} - -void CFWL_CheckBox::NextStates() { - uint32_t dwFirststate = m_pProperties->m_dwStates; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) { - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == - FWL_STATE_CKB_Unchecked) { - CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr->IsFormDisabled()) { - CFX_ArrayTemplate radioarr; - pWidgetMgr->GetSameGroupRadioButton(this, radioarr); - CFWL_CheckBox* pCheckBox = nullptr; - int32_t iCount = radioarr.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - pCheckBox = static_cast(radioarr[i]); - if (pCheckBox != this && - pCheckBox->GetStates() & FWL_STATE_CKB_Checked) { - pCheckBox->SetCheckState(0); - CFX_RectF rt = pCheckBox->GetWidgetRect(); - rt.left = rt.top = 0; - m_pWidgetMgr->RepaintWidget(pCheckBox, &rt); - break; - } - } - } - m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; - } - } else { - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == - FWL_STATE_CKB_Neutral) { - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) - m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; - } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == - FWL_STATE_CKB_Checked) { - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; - } else { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) - m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; - else - m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; - } - } - - Repaint(&m_rtClient); - if (dwFirststate == m_pProperties->m_dwStates) - return; - - CFWL_Event wmCheckBoxState(CFWL_Event::Type::CheckStateChanged, this); - DispatchEvent(&wmCheckBoxState); -} - -void CFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: { - CFWL_MsgKey* pKey = static_cast(pMessage); - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) - OnKeyDown(pKey); - break; - } - default: - break; - } - - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_CheckBox::OnFocusChanged(bool bSet) { - if (bSet) - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - else - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - - Repaint(&m_rtClient); -} - -void CFWL_CheckBox::OnLButtonDown() { - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - return; - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - SetFocus(true); - - m_bBtnDown = true; - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; - m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; - Repaint(&m_rtClient); -} - -void CFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (!m_bBtnDown) - return; - - m_bBtnDown = false; - if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; - NextStates(); -} - -void CFWL_CheckBox::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - return; - - bool bRepaint = false; - if (m_bBtnDown) { - if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { - bRepaint = true; - m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; - } - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { - bRepaint = true; - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; - } - } else { - if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { - bRepaint = true; - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; - } - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { - bRepaint = true; - m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; - } - } - } else { - if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { - if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { - bRepaint = true; - m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; - } - } - } - if (bRepaint) - Repaint(&m_rtBox); -} - -void CFWL_CheckBox::OnMouseLeave() { - if (m_bBtnDown) - m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; - else - m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; - - Repaint(&m_rtBox); -} - -void CFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { - if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) - return; - if (pMsg->m_dwKeyCode == FWL_VKEY_Return || - pMsg->m_dwKeyCode == FWL_VKEY_Space) { - NextStates(); - } -} diff --git a/xfa/fwl/core/cfwl_checkbox.h b/xfa/fwl/core/cfwl_checkbox.h deleted file mode 100644 index f699aa0059..0000000000 --- a/xfa/fwl/core/cfwl_checkbox.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_CHECKBOX_H_ -#define XFA_FWL_CORE_CFWL_CHECKBOX_H_ - -#include - -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_STYLEEXT_CKB_Left (0L << 0) -#define FWL_STYLEEXT_CKB_Center (1L << 0) -#define FWL_STYLEEXT_CKB_Right (2L << 0) -#define FWL_STYLEEXT_CKB_Top (0L << 2) -#define FWL_STYLEEXT_CKB_VCenter (1L << 2) -#define FWL_STYLEEXT_CKB_Bottom (2L << 2) -#define FWL_STYLEEXT_CKB_LeftText (1L << 4) -#define FWL_STYLEEXT_CKB_MultiLine (1L << 5) -#define FWL_STYLEEXT_CKB_3State (1L << 6) -#define FWL_STYLEEXT_CKB_RadioButton (1L << 7) -#define FWL_STYLEEXT_CKB_ShapeSolidSquare (0L << 8) -#define FWL_STYLEEXT_CKB_ShapeSunkenSquare (1L << 8) -#define FWL_STYLEEXT_CKB_ShapeSolidCircle (2L << 8) -#define FWL_STYLEEXT_CKB_ShapeSunkenCircle (3L << 8) -#define FWL_STYLEEXT_CKB_SignShapeCheck (0L << 10) -#define FWL_STYLEEXT_CKB_SignShapeCircle (1L << 10) -#define FWL_STYLEEXT_CKB_SignShapeCross (2L << 10) -#define FWL_STYLEEXT_CKB_SignShapeDiamond (3L << 10) -#define FWL_STYLEEXT_CKB_SignShapeSquare (4L << 10) -#define FWL_STYLEEXT_CKB_SignShapeStar (5L << 10) -#define FWL_STYLEEXT_CKB_HLayoutMask (3L << 0) -#define FWL_STYLEEXT_CKB_VLayoutMask (3L << 2) -#define FWL_STYLEEXT_CKB_ShapeMask (3L << 8) -#define FWL_STYLEEXT_CKB_SignShapeMask (7L << 10) -#define FWL_STATE_CKB_Hovered (1 << FWL_WGTSTATE_MAX) -#define FWL_STATE_CKB_Pressed (1 << (FWL_WGTSTATE_MAX + 1)) -#define FWL_STATE_CKB_Unchecked (0 << (FWL_WGTSTATE_MAX + 2)) -#define FWL_STATE_CKB_Checked (1 << (FWL_WGTSTATE_MAX + 2)) -#define FWL_STATE_CKB_Neutral (2 << (FWL_WGTSTATE_MAX + 2)) -#define FWL_STATE_CKB_CheckMask (3L << (FWL_WGTSTATE_MAX + 2)) - -class CFWL_MsgMouse; -class CFWL_WidgetProperties; -class CFWL_Widget; - -class CFWL_CheckBox : public CFWL_Widget { - public: - explicit CFWL_CheckBox(const CFWL_App* pApp); - ~CFWL_CheckBox() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void SetBoxSize(FX_FLOAT fHeight); - - private: - void SetCheckState(int32_t iCheck); - void Layout(); - uint32_t GetPartStates() const; - void UpdateTextOutStyles(); - void NextStates(); - void OnFocusChanged(bool bSet); - void OnLButtonDown(); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(); - void OnKeyDown(CFWL_MsgKey* pMsg); - - CFX_RectF m_rtClient; - CFX_RectF m_rtBox; - CFX_RectF m_rtCaption; - CFX_RectF m_rtFocus; - uint32_t m_dwTTOStyles; - int32_t m_iTTOAlign; - bool m_bBtnDown; - FX_FLOAT m_fBoxHeight; -}; - -#endif // XFA_FWL_CORE_CFWL_CHECKBOX_H_ diff --git a/xfa/fwl/core/cfwl_combobox.cpp b/xfa/fwl/core/cfwl_combobox.cpp deleted file mode 100644 index bfc3f32f46..0000000000 --- a/xfa/fwl/core/cfwl_combobox.cpp +++ /dev/null @@ -1,1078 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_combobox.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_evtselectchanged.h" -#include "xfa/fwl/core/cfwl_evttextchanged.h" -#include "xfa/fwl/core/cfwl_formproxy.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgsetfocus.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app) - : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), - m_pComboBoxProxy(nullptr), - m_bLButtonDown(false), - m_iCurSel(-1), - m_iBtnState(CFWL_PartState_Normal), - m_fComboFormHandler(0) { - m_rtClient.Reset(); - m_rtBtn.Reset(); - m_rtHandler.Reset(); - - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_InitComboList(); - DisForm_InitComboEdit(); - return; - } - - auto prop = pdfium::MakeUnique(); - prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - prop->m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) - prop->m_dwStyleExes |= FWL_STYLEEXT_LTB_Icon; - m_pListBox = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); - - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { - m_pEdit.reset(new CFWL_ComboEdit( - m_pOwnerApp, pdfium::MakeUnique(), this)); - m_pEdit->SetOuter(this); - } - if (m_pEdit) - m_pEdit->SetParent(this); - - SetStates(m_pProperties->m_dwStates); -} - -CFWL_ComboBox::~CFWL_ComboBox() {} - -FWL_Type CFWL_ComboBox::GetClassID() const { - return FWL_Type::ComboBox; -} - -void CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { - m_pListBox->AddString(wsText); -} - -bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { - return m_pListBox->RemoveAt(iIndex); -} - -void CFWL_ComboBox::RemoveAll() { - m_pListBox->DeleteAll(); -} - -void CFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); - return; - } - - bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); - bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); - if (bAddDropDown && !m_pEdit) { - m_pEdit = pdfium::MakeUnique( - m_pOwnerApp, pdfium::MakeUnique(), nullptr); - m_pEdit->SetOuter(this); - m_pEdit->SetParent(this); - } else if (bRemoveDropDown && m_pEdit) { - m_pEdit->SetStates(FWL_WGTSTATE_Invisible); - } - CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); -} - -void CFWL_ComboBox::Update() { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_Update(); - return; - } - if (IsLocked()) - return; - - ResetTheme(); - if (IsDropDownStyle() && m_pEdit) - ResetEditAlignment(); - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); - CFWL_ThemePart part; - part.m_pWidget = this; - m_fComboFormHandler = - *static_cast(m_pProperties->m_pThemeProvider->GetCapacity( - &part, CFWL_WidgetCapacity::ComboFormHandler)); -} - -FWL_WidgetHit CFWL_ComboBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_HitTest(fx, fy); - return CFWL_Widget::HitTest(fx, fy); -} - -void CFWL_ComboBox::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_DrawWidget(pGraphics, pMatrix); - return; - } - - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - if (!IsDropDownStyle()) { - CFX_RectF rtTextBk(m_rtClient); - rtTextBk.width -= m_rtBtn.width; - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_pGraphics = pGraphics; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = rtTextBk; - - if (m_iCurSel >= 0) { - if (void* p = m_pListBox->GetItemData( - m_pListBox.get(), - m_pListBox->GetItem(m_pListBox.get(), m_iCurSel))) { - param.m_pData = p; - } - } - - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { - param.m_dwStates = CFWL_PartState_Disabled; - } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && - (m_iCurSel >= 0)) { - param.m_dwStates = CFWL_PartState_Selected; - } else { - param.m_dwStates = CFWL_PartState_Normal; - } - pTheme->DrawBackground(¶m); - - if (m_iCurSel >= 0) { - if (!m_pListBox) - return; - - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); - - CFWL_ThemeText theme_text; - theme_text.m_pWidget = this; - theme_text.m_iPart = CFWL_Part::Caption; - theme_text.m_dwStates = m_iBtnState; - theme_text.m_pGraphics = pGraphics; - theme_text.m_matrix.Concat(*pMatrix); - theme_text.m_rtPart = rtTextBk; - theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - ? CFWL_PartState_Selected - : CFWL_PartState_Normal; - theme_text.m_wsText = wsText; - theme_text.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - theme_text.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - pTheme->DrawText(&theme_text); - } - } - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::DropDownButton; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : m_iBtnState; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtBtn; - pTheme->DrawBackground(¶m); -} - -void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - if (!pThemeProvider) - return; - - m_pProperties->m_pThemeProvider = pThemeProvider; - if (m_pListBox) - m_pListBox->SetThemeProvider(pThemeProvider); - if (m_pEdit) - m_pEdit->SetThemeProvider(pThemeProvider); -} - -CFX_WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const { - CFWL_ListItem* pItem = static_cast( - m_pListBox->GetItem(m_pListBox.get(), iIndex)); - return pItem ? pItem->m_wsText : L""; -} - -void CFWL_ComboBox::SetCurSel(int32_t iSel) { - int32_t iCount = m_pListBox->CountItems(nullptr); - bool bClearSel = iSel < 0 || iSel >= iCount; - if (IsDropDownStyle() && m_pEdit) { - if (bClearSel) { - m_pEdit->SetText(CFX_WideString()); - } else { - CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel); - CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); - m_pEdit->SetText(wsText); - } - m_pEdit->Update(); - } - m_iCurSel = bClearSel ? -1 : iSel; -} - -void CFWL_ComboBox::SetStates(uint32_t dwStates) { - if (IsDropDownStyle() && m_pEdit) - m_pEdit->SetStates(dwStates); - if (m_pListBox) - m_pListBox->SetStates(dwStates); - CFWL_Widget::SetStates(dwStates); -} - -void CFWL_ComboBox::RemoveStates(uint32_t dwStates) { - if (IsDropDownStyle() && m_pEdit) - m_pEdit->RemoveStates(dwStates); - if (m_pListBox) - m_pListBox->RemoveStates(dwStates); - CFWL_Widget::RemoveStates(dwStates); -} - -void CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { - if (!m_pEdit) - return; - - m_pEdit->SetText(wsText); - m_pEdit->Update(); -} - -CFX_WideString CFWL_ComboBox::GetEditText() const { - if (m_pEdit) - return m_pEdit->GetText(); - if (!m_pListBox) - return L""; - - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - return m_pListBox->GetDataProviderItemText(hItem); -} - -void CFWL_ComboBox::OpenDropDownList(bool bActivate) { - ShowDropList(bActivate); -} - -CFX_RectF CFWL_ComboBox::GetBBox() const { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_GetBBox(); - - CFX_RectF rect = m_pProperties->m_rtWidget; - if (!m_pListBox || !IsDropListVisible()) - return rect; - - CFX_RectF rtList = m_pListBox->GetWidgetRect(); - rtList.Offset(rect.left, rect.top); - rect.Union(rtList); - return rect; -} - -void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved) { - if (m_pEdit) - m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); -} - -void CFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pGraphics = pGraphics; - param.m_iPart = CFWL_Part::StretchHandler; - param.m_dwStates = CFWL_PartState_Normal; - param.m_pWidget = this; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtHandler; - m_pProperties->m_pThemeProvider->DrawBackground(¶m); -} - -void CFWL_ComboBox::ShowDropList(bool bActivate) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_ShowDropList(bActivate); - if (IsDropListVisible() == bActivate) - return; - if (!m_pComboBoxProxy) - InitProxyForm(); - - m_pComboBoxProxy->Reset(); - if (!bActivate) { - m_pComboBoxProxy->EndDoModal(); - - m_bLButtonDown = false; - m_pListBox->SetNotifyOwner(true); - SetFocus(true); - return; - } - - m_pListBox->ChangeSelected(m_iCurSel); - ResetListItemAlignment(); - - uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & - (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); - m_pListBox->ModifyStylesEx(dwStyleAdd, 0); - m_rtList = m_pListBox->GetAutosizedWidgetRect(); - - CFX_RectF rtAnchor; - rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - - m_rtList.width = std::max(m_rtList.width, m_rtClient.width); - m_rtProxy = m_rtList; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) - m_rtProxy.height += m_fComboFormHandler; - - GetPopupPos(0, m_rtProxy.height, rtAnchor, m_rtProxy); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { - FX_FLOAT fx = 0; - FX_FLOAT fy = m_rtClient.top + m_rtClient.height / 2; - TransformTo(nullptr, fx, fy); - - m_bUpFormHandler = fy > m_rtProxy.top; - if (m_bUpFormHandler) { - m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); - m_rtList.top = m_fComboFormHandler; - } else { - m_rtHandler.Set(0, m_rtList.height, m_rtList.width, m_fComboFormHandler); - } - } - m_pComboBoxProxy->SetWidgetRect(m_rtProxy); - m_pComboBoxProxy->Update(); - m_pListBox->SetWidgetRect(m_rtList); - m_pListBox->Update(); - - CFWL_Event ev(CFWL_Event::Type::PreDropDown, this); - DispatchEvent(&ev); - - m_fItemHeight = m_pListBox->GetItemHeight(); - m_pListBox->SetFocus(true); - m_pComboBoxProxy->DoModal(); - m_pListBox->SetFocus(false); -} - -void CFWL_ComboBox::MatchEditText() { - CFX_WideString wsText = m_pEdit->GetText(); - int32_t iMatch = m_pListBox->MatchItem(wsText); - if (iMatch != m_iCurSel) { - m_pListBox->ChangeSelected(iMatch); - if (iMatch >= 0) - SyncEditText(iMatch); - } else if (iMatch >= 0) { - m_pEdit->SetSelected(); - } - m_iCurSel = iMatch; -} - -void CFWL_ComboBox::SyncEditText(int32_t iListItem) { - CFWL_ListItem* hItem = m_pListBox->GetItem(this, iListItem); - CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); - m_pEdit->SetText(wsText); - m_pEdit->Update(); - m_pEdit->SetSelected(); -} - -void CFWL_ComboBox::Layout() { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_Layout(); - - GetClientRect(m_rtClient); - FX_FLOAT* pFWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pFWidth) - return; - - FX_FLOAT fBtn = *pFWidth; - m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, - m_rtClient.height); - if (!IsDropDownStyle() || !m_pEdit) - return; - - CFX_RectF rtEdit; - rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, - m_rtClient.height); - m_pEdit->SetWidgetRect(rtEdit); - - if (m_iCurSel >= 0) { - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); - m_pEdit->LockUpdate(); - m_pEdit->SetText(wsText); - m_pEdit->UnlockUpdate(); - } - m_pEdit->Update(); -} - -void CFWL_ComboBox::ResetTheme() { - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (!pTheme) { - pTheme = GetAvailableTheme(); - m_pProperties->m_pThemeProvider = pTheme; - } - if (m_pListBox && !m_pListBox->GetThemeProvider()) - m_pListBox->SetThemeProvider(pTheme); - if (m_pEdit && !m_pEdit->GetThemeProvider()) - m_pEdit->SetThemeProvider(pTheme); -} - -void CFWL_ComboBox::ResetEditAlignment() { - if (!m_pEdit) - return; - - uint32_t dwAdd = 0; - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditHAlignMask) { - case FWL_STYLEEXT_CMB_EditHCenter: { - dwAdd |= FWL_STYLEEXT_EDT_HCenter; - break; - } - case FWL_STYLEEXT_CMB_EditHFar: { - dwAdd |= FWL_STYLEEXT_EDT_HFar; - break; - } - default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } - } - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditVAlignMask) { - case FWL_STYLEEXT_CMB_EditVCenter: { - dwAdd |= FWL_STYLEEXT_EDT_VCenter; - break; - } - case FWL_STYLEEXT_CMB_EditVFar: { - dwAdd |= FWL_STYLEEXT_EDT_VFar; - break; - } - default: { - dwAdd |= FWL_STYLEEXT_EDT_VNear; - break; - } - } - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditJustified) - dwAdd |= FWL_STYLEEXT_EDT_Justified; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditDistributed) - dwAdd |= FWL_STYLEEXT_EDT_Distributed; - - m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | - FWL_STYLEEXT_EDT_HAlignModeMask | - FWL_STYLEEXT_EDT_VAlignMask); -} - -void CFWL_ComboBox::ResetListItemAlignment() { - if (!m_pListBox) - return; - - uint32_t dwAdd = 0; - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemAlignMask) { - case FWL_STYLEEXT_CMB_ListItemCenterAlign: { - dwAdd |= FWL_STYLEEXT_LTB_CenterAlign; - break; - } - case FWL_STYLEEXT_CMB_ListItemRightAlign: { - dwAdd |= FWL_STYLEEXT_LTB_RightAlign; - break; - } - default: { - dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; - break; - } - } - m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); -} - -void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { - m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0)); - if (!IsDropDownStyle()) { - Repaint(&m_rtClient); - return; - } - - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - if (!hItem) - return; - - CFX_WideString wsText = m_pListBox->GetItemText(this, hItem); - if (m_pEdit) { - m_pEdit->SetText(wsText); - m_pEdit->Update(); - m_pEdit->SetSelected(); - } - - CFWL_EvtSelectChanged ev(this); - ev.bLButtonUp = bLButtonUp; - DispatchEvent(&ev); -} - -void CFWL_ComboBox::InitProxyForm() { - if (m_pComboBoxProxy) - return; - if (!m_pListBox) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_pOwner = this; - prop->m_dwStyles = FWL_WGTSTYLE_Popup; - prop->m_dwStates = FWL_WGTSTATE_Invisible; - - // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure - // if the SetParent call is going to transfer ownership. - m_pComboBoxProxy = new CFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), - m_pListBox.get()); - m_pListBox->SetParent(m_pComboBoxProxy); -} - -void CFWL_ComboBox::DisForm_InitComboList() { - if (m_pListBox) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_pParent = this; - prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; - prop->m_dwStates = FWL_WGTSTATE_Invisible; - prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - m_pListBox = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); -} - -void CFWL_ComboBox::DisForm_InitComboEdit() { - if (m_pEdit) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_pParent = this; - prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - - m_pEdit = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); - m_pEdit->SetOuter(this); -} - -void CFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { - if (DisForm_IsDropListVisible() == bActivate) - return; - - if (bActivate) { - CFWL_Event preEvent(CFWL_Event::Type::PreDropDown, this); - DispatchEvent(&preEvent); - - CFWL_ComboList* pComboList = m_pListBox.get(); - int32_t iItems = pComboList->CountItems(nullptr); - if (iItems < 1) - return; - - ResetListItemAlignment(); - pComboList->ChangeSelected(m_iCurSel); - - FX_FLOAT fItemHeight = pComboList->CalcItemHeight(); - FX_FLOAT fBorder = GetBorderSize(true); - FX_FLOAT fPopupMin = 0.0f; - if (iItems > 3) - fPopupMin = fItemHeight * 3 + fBorder * 2; - - FX_FLOAT fPopupMax = fItemHeight * iItems + fBorder * 2; - CFX_RectF rtList; - rtList.left = m_rtClient.left; - rtList.width = m_pProperties->m_rtWidget.width; - rtList.top = 0; - rtList.height = 0; - GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); - - m_pListBox->SetWidgetRect(rtList); - m_pListBox->Update(); - } else { - SetFocus(true); - } - - if (bActivate) { - m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); - CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); - DispatchEvent(&postEvent); - } else { - m_pListBox->SetStates(FWL_WGTSTATE_Invisible); - } - - CFX_RectF rect = m_pListBox->GetWidgetRect(); - rect.Inflate(2, 2); - Repaint(&rect); -} - -void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved) { - if (!m_pEdit) - DisForm_InitComboEdit(); - - bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); - bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); - - dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown; - m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown; - - if (bAddDropDown) - m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly); - else if (bDelDropDown) - m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0); - CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); -} - -void CFWL_ComboBox::DisForm_Update() { - if (m_iLock) - return; - if (m_pEdit) - ResetEditAlignment(); - ResetTheme(); - Layout(); -} - -FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { - CFX_RectF rect; - rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, - m_pProperties->m_rtWidget.height); - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::Edit; - if (m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::Client; - if (DisForm_IsDropListVisible()) { - rect = m_pListBox->GetWidgetRect(); - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::Client; - } - return FWL_WidgetHit::Unknown; -} - -void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - CFX_Matrix mtOrg; - mtOrg.Set(1, 0, 0, 1, 0, 0); - if (pMatrix) - mtOrg = *pMatrix; - - pGraphics->SaveGraphState(); - pGraphics->ConcatMatrix(&mtOrg); - if (!m_rtBtn.IsEmpty(0.1f)) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::DropDownButton; - param.m_dwStates = m_iBtnState; - param.m_pGraphics = pGraphics; - param.m_rtPart = m_rtBtn; - pTheme->DrawBackground(¶m); - } - pGraphics->RestoreGraphState(); - - if (m_pEdit) { - CFX_RectF rtEdit = m_pEdit->GetWidgetRect(); - CFX_Matrix mt; - mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); - mt.Concat(mtOrg); - m_pEdit->DrawWidget(pGraphics, &mt); - } - if (m_pListBox && DisForm_IsDropListVisible()) { - CFX_RectF rtList = m_pListBox->GetWidgetRect(); - CFX_Matrix mt; - mt.Set(1, 0, 0, 1, rtList.left, rtList.top); - mt.Concat(mtOrg); - m_pListBox->DrawWidget(pGraphics, &mt); - } -} - -CFX_RectF CFWL_ComboBox::DisForm_GetBBox() const { - CFX_RectF rect = m_pProperties->m_rtWidget; - if (!m_pListBox || !DisForm_IsDropListVisible()) - return rect; - - CFX_RectF rtList = m_pListBox->GetWidgetRect(); - rtList.Offset(rect.left, rect.top); - rect.Union(rtList); - return rect; -} - -void CFWL_ComboBox::DisForm_Layout() { - GetClientRect(m_rtClient); - m_rtContent = m_rtClient; - FX_FLOAT* pFWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pFWidth) - return; - - FX_FLOAT borderWidth = 1; - FX_FLOAT fBtn = *pFWidth; - if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { - m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, - fBtn - borderWidth, m_rtClient.height - 2 * borderWidth); - } - - CFX_RectF* pUIMargin = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); - if (pUIMargin) { - m_rtContent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, - pUIMargin->height); - } - - if (!IsDropDownStyle() || !m_pEdit) - return; - - CFX_RectF rtEdit; - rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, - m_rtContent.height); - m_pEdit->SetWidgetRect(rtEdit); - - if (m_iCurSel >= 0) { - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); - m_pEdit->LockUpdate(); - m_pEdit->SetText(wsText); - m_pEdit->UnlockUpdate(); - } - m_pEdit->Update(); -} - -void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_OnProcessMessage(pMessage); - return; - } - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: - OnKey(static_cast(pMessage)); - break; - default: - break; - } - - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) { - CFWL_Event::Type type = pEvent->GetType(); - if (type == CFWL_Event::Type::Scroll) { - CFWL_EvtScroll* pScrollEvent = static_cast(pEvent); - CFWL_EvtScroll pScrollEv(this); - pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode; - pScrollEv.m_fPos = pScrollEvent->m_fPos; - DispatchEvent(&pScrollEv); - } else if (type == CFWL_Event::Type::TextChanged) { - CFWL_Event pTemp(CFWL_Event::Type::EditChanged, this); - DispatchEvent(&pTemp); - } -} - -void CFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - if (IsDropDownStyle() && pMsg->m_pSrcTarget != m_pListBox.get()) { - if (!m_pEdit) - return; - m_pEdit->SetSelected(); - return; - } - - Repaint(&m_rtClient); - return; - } - - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - if (!IsDropDownStyle() || pMsg->m_pDstTarget == m_pListBox.get()) { - Repaint(&m_rtClient); - return; - } - if (!m_pEdit) - return; - - m_pEdit->FlagFocus(false); - m_pEdit->ClearSelected(); -} - -void CFWL_ComboBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - return; - - CFX_RectF& rtBtn = IsDropDownStyle() ? m_rtBtn : m_rtClient; - if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - if (IsDropDownStyle() && m_pEdit) - MatchEditText(); - - m_bLButtonDown = true; - m_iBtnState = CFWL_PartState_Pressed; - Repaint(&m_rtClient); - - ShowDropList(true); - m_iBtnState = CFWL_PartState_Normal; - Repaint(&m_rtClient); -} - -void CFWL_ComboBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { - m_bLButtonDown = false; - if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) - m_iBtnState = CFWL_PartState_Hovered; - else - m_iBtnState = CFWL_PartState_Normal; - - Repaint(&m_rtBtn); -} - -void CFWL_ComboBox::OnMouseMove(CFWL_MsgMouse* pMsg) { - int32_t iOldState = m_iBtnState; - if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iBtnState = - m_bLButtonDown ? CFWL_PartState_Pressed : CFWL_PartState_Hovered; - } else { - m_iBtnState = CFWL_PartState_Normal; - } - if ((iOldState != m_iBtnState) && - !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == - FWL_WGTSTATE_Disabled)) { - Repaint(&m_rtBtn); - } -} - -void CFWL_ComboBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { - if (!IsDropListVisible() && - !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == - FWL_WGTSTATE_Disabled)) { - m_iBtnState = CFWL_PartState_Normal; - Repaint(&m_rtBtn); - } -} - -void CFWL_ComboBox::OnKey(CFWL_MsgKey* pMsg) { - uint32_t dwKeyCode = pMsg->m_dwKeyCode; - if (dwKeyCode == FWL_VKEY_Tab) - return; - if (pMsg->m_pDstTarget == this) - DoSubCtrlKey(pMsg); -} - -void CFWL_ComboBox::DoSubCtrlKey(CFWL_MsgKey* pMsg) { - uint32_t dwKeyCode = pMsg->m_dwKeyCode; - const bool bUp = dwKeyCode == FWL_VKEY_Up; - const bool bDown = dwKeyCode == FWL_VKEY_Down; - if (bUp || bDown) { - int32_t iCount = m_pListBox->CountItems(nullptr); - if (iCount < 1) - return; - - bool bMatchEqual = false; - int32_t iCurSel = m_iCurSel; - bool bDropDown = IsDropDownStyle(); - if (bDropDown && m_pEdit) { - CFX_WideString wsText = m_pEdit->GetText(); - iCurSel = m_pListBox->MatchItem(wsText); - if (iCurSel >= 0) { - CFWL_ListItem* hItem = m_pListBox->GetItem(this, iCurSel); - CFX_WideString wsTemp = m_pListBox->GetDataProviderItemText(hItem); - bMatchEqual = wsText == wsTemp; - } - } - if (iCurSel < 0) { - iCurSel = 0; - } else if (!bDropDown || bMatchEqual) { - if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) - return; - if (bUp) - iCurSel--; - else - iCurSel++; - } - m_iCurSel = iCurSel; - if (bDropDown && m_pEdit) - SyncEditText(m_iCurSel); - else - Repaint(&m_rtClient); - return; - } - - if (IsDropDownStyle()) - m_pEdit->GetDelegate()->OnProcessMessage(pMsg); -} - -void CFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - bool backDefault = true; - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: { - backDefault = false; - DisForm_OnFocusChanged(pMessage, true); - break; - } - case CFWL_Message::Type::KillFocus: { - backDefault = false; - DisForm_OnFocusChanged(pMessage, false); - break; - } - case CFWL_Message::Type::Mouse: { - backDefault = false; - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - DisForm_OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: { - backDefault = false; - CFWL_MsgKey* pKey = static_cast(pMessage); - if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp) - break; - if (DisForm_IsDropListVisible() && - pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { - bool bListKey = pKey->m_dwKeyCode == FWL_VKEY_Up || - pKey->m_dwKeyCode == FWL_VKEY_Down || - pKey->m_dwKeyCode == FWL_VKEY_Return || - pKey->m_dwKeyCode == FWL_VKEY_Escape; - if (bListKey) { - m_pListBox->GetDelegate()->OnProcessMessage(pMessage); - break; - } - } - DisForm_OnKey(pKey); - break; - } - default: - break; - } - if (backDefault) - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_ComboBox::DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg) { - bool bDropDown = DisForm_IsDropListVisible(); - CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient; - if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - if (DisForm_IsDropListVisible()) { - DisForm_ShowDropList(false); - return; - } - if (m_pEdit) - MatchEditText(); - DisForm_ShowDropList(true); -} - -void CFWL_ComboBox::DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - if ((m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) { - CFWL_MsgSetFocus msg(nullptr, m_pEdit.get()); - m_pEdit->GetDelegate()->OnProcessMessage(&msg); - } - } else { - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - DisForm_ShowDropList(false); - CFWL_MsgKillFocus msg(m_pEdit.get()); - m_pEdit->GetDelegate()->OnProcessMessage(&msg); - } -} - -void CFWL_ComboBox::DisForm_OnKey(CFWL_MsgKey* pMsg) { - uint32_t dwKeyCode = pMsg->m_dwKeyCode; - const bool bUp = dwKeyCode == FWL_VKEY_Up; - const bool bDown = dwKeyCode == FWL_VKEY_Down; - if (bUp || bDown) { - CFWL_ComboList* pComboList = m_pListBox.get(); - int32_t iCount = pComboList->CountItems(nullptr); - if (iCount < 1) - return; - - bool bMatchEqual = false; - int32_t iCurSel = m_iCurSel; - if (m_pEdit) { - CFX_WideString wsText = m_pEdit->GetText(); - iCurSel = pComboList->MatchItem(wsText); - if (iCurSel >= 0) { - CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); - CFX_WideString wsTemp = m_pListBox->GetDataProviderItemText(item); - bMatchEqual = wsText == wsTemp; - } - } - if (iCurSel < 0) { - iCurSel = 0; - } else if (bMatchEqual) { - if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) - return; - if (bUp) - iCurSel--; - else - iCurSel++; - } - m_iCurSel = iCurSel; - SyncEditText(m_iCurSel); - return; - } - if (m_pEdit) - m_pEdit->GetDelegate()->OnProcessMessage(pMsg); -} diff --git a/xfa/fwl/core/cfwl_combobox.h b/xfa/fwl/core/cfwl_combobox.h deleted file mode 100644 index 26c54b5377..0000000000 --- a/xfa/fwl/core/cfwl_combobox.h +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_COMBOBOX_H_ -#define XFA_FWL_CORE_CFWL_COMBOBOX_H_ - -#include - -#include "xfa/fwl/core/cfwl_comboboxproxy.h" -#include "xfa/fwl/core/cfwl_comboedit.h" -#include "xfa/fwl/core/cfwl_combolist.h" -#include "xfa/fwl/core/cfwl_form.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fxgraphics/cfx_graphics.h" - -class CFWL_WidgetProperties; -class CFWL_ComboBox; -class CFWL_ComboBoxProxy; -class CFWL_FormProxy; -class CFWL_ListBox; -class CFWL_Widget; - -#define FWL_STYLEEXT_CMB_DropList (0L << 0) -#define FWL_STYLEEXT_CMB_DropDown (1L << 0) -#define FWL_STYLEEXT_CMB_Sort (1L << 1) -#define FWL_STYLEEXT_CMB_ListDrag (1L << 2) -#define FWL_STYLEEXT_CMB_OwnerDraw (1L << 3) -#define FWL_STYLEEXT_CMB_EditHNear (0L << 4) -#define FWL_STYLEEXT_CMB_EditHCenter (1L << 4) -#define FWL_STYLEEXT_CMB_EditHFar (2L << 4) -#define FWL_STYLEEXT_CMB_EditVNear (0L << 6) -#define FWL_STYLEEXT_CMB_EditVCenter (1L << 6) -#define FWL_STYLEEXT_CMB_EditVFar (2L << 6) -#define FWL_STYLEEXT_CMB_EditJustified (1L << 8) -#define FWL_STYLEEXT_CMB_EditDistributed (2L << 8) -#define FWL_STYLEEXT_CMB_EditHAlignMask (3L << 4) -#define FWL_STYLEEXT_CMB_EditVAlignMask (3L << 6) -#define FWL_STYLEEXT_CMB_EditHAlignModeMask (3L << 8) -#define FWL_STYLEEXT_CMB_ListItemLeftAlign (0L << 10) -#define FWL_STYLEEXT_CMB_ListItemCenterAlign (1L << 10) -#define FWL_STYLEEXT_CMB_ListItemRightAlign (2L << 10) -#define FWL_STYLEEXT_CMB_ListItemAlignMask (3L << 10) -#define FWL_STYLEEXT_CMB_ListItemText (0L << 12) -#define FWL_STYLEEXT_CMB_ListItemIconText (1L << 12) -#define FWL_STYLEEXT_CMB_ReadOnly (1L << 13) - -class CFWL_ComboBox : public CFWL_Widget { - public: - explicit CFWL_ComboBox(const CFWL_App* pApp); - ~CFWL_ComboBox() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void ModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved) override; - void SetStates(uint32_t dwStates) override; - void RemoveStates(uint32_t dwStates) override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - CFX_WideString GetTextByIndex(int32_t iIndex) const; - int32_t GetCurSel() const { return m_iCurSel; } - void SetCurSel(int32_t iSel); - - void AddString(const CFX_WideStringC& wsText); - bool RemoveAt(int32_t iIndex); // Returns false iff |iIndex| out of range. - void RemoveAll(); - - void SetEditText(const CFX_WideString& wsText); - CFX_WideString GetEditText() const; - - void OpenDropDownList(bool bActivate); - - bool EditCanUndo() const { return m_pEdit->CanUndo(); } - bool EditCanRedo() const { return m_pEdit->CanRedo(); } - bool EditUndo() { return m_pEdit->Undo(); } - bool EditRedo() { return m_pEdit->Redo(); } - bool EditCanCopy() const { return m_pEdit->CountSelRanges() > 0; } - bool EditCanCut() const { - if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) - return false; - return EditCanCopy(); - } - bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; } - bool EditCopy(CFX_WideString& wsCopy) const { return m_pEdit->Copy(wsCopy); } - bool EditCut(CFX_WideString& wsCut) { return m_pEdit->Cut(wsCut); } - bool EditPaste(const CFX_WideString& wsPaste) { - return m_pEdit->Paste(wsPaste); - } - void EditSelectAll() { m_pEdit->AddSelRange(0); } - void EditDelete() { m_pEdit->ClearText(); } - void EditDeSelect() { m_pEdit->ClearSelections(); } - - CFX_RectF GetBBox() const; - void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); - - void DrawStretchHandler(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); - bool IsDropListVisible() const { - return m_pComboBoxProxy && - !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); - } - void ShowDropList(bool bActivate); - - CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); } - - void ProcessSelChanged(bool bLButtonUp); - int32_t GetCurrentSelection() const { return m_iCurSel; } - - private: - bool IsDropDownStyle() const { - return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown); - } - void MatchEditText(); - void SyncEditText(int32_t iListItem); - void Layout(); - void ResetTheme(); - void ResetEditAlignment(); - void ResetListItemAlignment(); - void InitProxyForm(); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - void OnKey(CFWL_MsgKey* pMsg); - void DoSubCtrlKey(CFWL_MsgKey* pMsg); - - void DisForm_InitComboList(); - void DisForm_InitComboEdit(); - void DisForm_ShowDropList(bool bActivate); - bool DisForm_IsDropListVisible() const { - return !(m_pListBox->GetStates() & FWL_WGTSTATE_Invisible); - } - void DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved); - void DisForm_Update(); - FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy); - void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); - CFX_RectF DisForm_GetBBox() const; - void DisForm_Layout(); - void DisForm_OnProcessMessage(CFWL_Message* pMessage); - void DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg); - void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void DisForm_OnKey(CFWL_MsgKey* pMsg); - - CFX_RectF m_rtClient; - CFX_RectF m_rtContent; - CFX_RectF m_rtBtn; - CFX_RectF m_rtList; - CFX_RectF m_rtProxy; - CFX_RectF m_rtHandler; - std::unique_ptr m_pEdit; - std::unique_ptr m_pListBox; - CFWL_ComboBoxProxy* m_pComboBoxProxy; // Can this be a unique_ptr? - bool m_bLButtonDown; - bool m_bUpFormHandler; - int32_t m_iCurSel; - int32_t m_iBtnState; - FX_FLOAT m_fComboFormHandler; - FX_FLOAT m_fItemHeight; -}; - -#endif // XFA_FWL_CORE_CFWL_COMBOBOX_H_ diff --git a/xfa/fwl/core/cfwl_comboboxproxy.cpp b/xfa/fwl/core/cfwl_comboboxproxy.cpp deleted file mode 100644 index b7c56378cf..0000000000 --- a/xfa/fwl/core/cfwl_comboboxproxy.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_comboboxproxy.h" - -#include -#include - -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" - -CFWL_ComboBoxProxy::CFWL_ComboBoxProxy( - CFWL_ComboBox* pComboBox, - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_FormProxy(app, std::move(properties), pOuter), - m_bLButtonDown(false), - m_bLButtonUpSelf(false), - m_pComboBox(pComboBox) {} - -CFWL_ComboBoxProxy::~CFWL_ComboBoxProxy() {} - -void CFWL_ComboBoxProxy::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - default: - break; - } - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_ComboBoxProxy::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); -} - -void CFWL_ComboBoxProxy::OnLButtonDown(CFWL_Message* pMessage) { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - CFX_RectF rtWidget = GetWidgetRect(); - rtWidget.left = rtWidget.top = 0; - - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_bLButtonDown = true; - pDriver->SetGrab(this, true); - } else { - m_bLButtonDown = false; - pDriver->SetGrab(this, false); - m_pComboBox->ShowDropList(false); - } -} - -void CFWL_ComboBoxProxy::OnLButtonUp(CFWL_Message* pMessage) { - m_bLButtonDown = false; - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - pDriver->SetGrab(this, false); - if (!m_bLButtonUpSelf) { - m_bLButtonUpSelf = true; - return; - } - - CFWL_MsgMouse* pMsg = static_cast(pMessage); - CFX_RectF rect = GetWidgetRect(); - rect.left = rect.top = 0; - if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && - m_pComboBox->IsDropListVisible()) { - m_pComboBox->ShowDropList(false); - } -} - -void CFWL_ComboBoxProxy::OnFocusChanged(CFWL_Message* pMessage, bool bSet) { - if (bSet) - return; - - CFWL_MsgKillFocus* pMsg = static_cast(pMessage); - if (!pMsg->m_pSetFocus) - m_pComboBox->ShowDropList(false); -} diff --git a/xfa/fwl/core/cfwl_comboboxproxy.h b/xfa/fwl/core/cfwl_comboboxproxy.h deleted file mode 100644 index 11fb364cdc..0000000000 --- a/xfa/fwl/core/cfwl_comboboxproxy.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_COMBOBOXPROXY_H_ -#define XFA_FWL_CORE_CFWL_COMBOBOXPROXY_H_ - -#include - -#include "xfa/fwl/core/cfwl_formproxy.h" - -class CFWL_ComboBox; - -class CFWL_ComboBoxProxy : public CFWL_FormProxy { - public: - CFWL_ComboBoxProxy(CFWL_ComboBox* pCombobBox, - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_ComboBoxProxy() override; - - // CFWL_FormProxy - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void Reset() { m_bLButtonUpSelf = false; } - - private: - void OnLButtonDown(CFWL_Message* pMsg); - void OnLButtonUp(CFWL_Message* pMsg); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - - bool m_bLButtonDown; - bool m_bLButtonUpSelf; - CFWL_ComboBox* m_pComboBox; -}; - -#endif // XFA_FWL_CORE_CFWL_COMBOBOXPROXY_H_ diff --git a/xfa/fwl/core/cfwl_comboedit.cpp b/xfa/fwl/core/cfwl_comboedit.cpp deleted file mode 100644 index 8ee9da6f14..0000000000 --- a/xfa/fwl/core/cfwl_comboedit.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_comboedit.h" - -#include -#include - -#include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" - -CFWL_ComboEdit::CFWL_ComboEdit( - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Edit(app, std::move(properties), pOuter) { - m_pOuter = static_cast(pOuter); -} - -void CFWL_ComboEdit::ClearSelected() { - ClearSelections(); - Repaint(&GetRTClient()); -} - -void CFWL_ComboEdit::SetSelected() { - FlagFocus(true); - GetTxtEdtEngine()->MoveCaretPos(MC_End); - AddSelRange(0); -} - -void CFWL_ComboEdit::FlagFocus(bool bSet) { - if (bSet) { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - return; - } - - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - HideCaret(nullptr); -} - -void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - bool backDefault = true; - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - backDefault = false; - break; - } - case CFWL_Message::Type::KillFocus: { - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - backDefault = false; - break; - } - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) && - ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) { - SetSelected(); - m_pOuter->SetFocus(true); - } - break; - } - default: - break; - } - if (backDefault) - CFWL_Edit::OnProcessMessage(pMessage); -} diff --git a/xfa/fwl/core/cfwl_comboedit.h b/xfa/fwl/core/cfwl_comboedit.h deleted file mode 100644 index 5ac6082a50..0000000000 --- a/xfa/fwl/core/cfwl_comboedit.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_COMBOEDIT_H_ -#define XFA_FWL_CORE_CFWL_COMBOEDIT_H_ - -#include - -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -class CFWL_ComboBox; - -class CFWL_ComboEdit : public CFWL_Edit { - public: - CFWL_ComboEdit(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - - // CFWL_Edit. - void OnProcessMessage(CFWL_Message* pMessage) override; - - void ClearSelected(); - void SetSelected(); - void FlagFocus(bool bSet); - - private: - CFWL_ComboBox* m_pOuter; -}; - -#endif // XFA_FWL_CORE_CFWL_COMBOEDIT_H_ diff --git a/xfa/fwl/core/cfwl_combolist.cpp b/xfa/fwl/core/cfwl_combolist.cpp deleted file mode 100644 index ff7bd2722c..0000000000 --- a/xfa/fwl/core/cfwl_combolist.cpp +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_combolist.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_comboedit.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" - -CFWL_ComboList::CFWL_ComboList( - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { - ASSERT(pOuter); -} - -int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { - if (wsMatch.IsEmpty()) - return -1; - - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* hItem = GetItem(this, i); - CFX_WideString wsText = GetItemText(this, hItem); - FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); - if (!pos) - return i; - } - return -1; -} - -void CFWL_ComboList::ChangeSelected(int32_t iSel) { - CFWL_ListItem* hItem = GetItem(this, iSel); - CFX_RectF rtInvalidate; - rtInvalidate.Reset(); - CFWL_ListItem* hOld = GetSelItem(0); - int32_t iOld = GetItemIndex(this, hOld); - if (iOld == iSel) - return; - if (iOld > -1) { - CFWL_ListItem* hItem = GetItem(this, iOld); - GetItemRect(this, hItem, rtInvalidate); - SetSelItem(hOld, false); - } - if (hItem) { - CFX_RectF rect; - CFWL_ListItem* hItem = GetItem(this, iSel); - GetItemRect(this, hItem, rect); - rtInvalidate.Union(rect); - CFWL_ListItem* hSel = GetItem(this, iSel); - SetSelItem(hSel, true); - } - if (!rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void CFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { - fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; - CFWL_Widget* pOwner = GetOwner(); - if (!pOwner) - return; - pOwner->TransformTo(m_pOuter, fx, fy); -} - -void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - CFWL_Message::Type type = pMessage->GetType(); - bool backDefault = true; - if (type == CFWL_Message::Type::SetFocus || - type == CFWL_Message::Type::KillFocus) { - OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::SetFocus); - } else if (type == CFWL_Message::Type::Mouse) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - CFWL_ScrollBar* vertSB = GetVertScrollBar(); - if (IsShowScrollBar(true) && vertSB) { - CFX_RectF rect = vertSB->GetWidgetRect(); - if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { - pMsg->m_fx -= rect.left; - pMsg->m_fy -= rect.top; - vertSB->GetDelegate()->OnProcessMessage(pMsg); - return; - } - } - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::Move: { - backDefault = false; - OnDropListMouseMove(pMsg); - break; - } - case FWL_MouseCommand::LeftButtonDown: { - backDefault = false; - OnDropListLButtonDown(pMsg); - break; - } - case FWL_MouseCommand::LeftButtonUp: { - backDefault = false; - OnDropListLButtonUp(pMsg); - break; - } - default: - break; - } - } else if (type == CFWL_Message::Type::Key) { - backDefault = !OnDropListKey(static_cast(pMessage)); - } - if (backDefault) - CFWL_ListBox::OnProcessMessage(pMessage); -} - -void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) - return; - - CFWL_MsgKillFocus* pKill = static_cast(pMsg); - CFWL_ComboBox* pOuter = static_cast(m_pOuter); - if (pKill->m_pSetFocus == m_pOuter || - pKill->m_pSetFocus == pOuter->GetComboEdit()) { - pOuter->ShowDropList(false); - } -} - -void CFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { - if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { - if (m_bNotifyOwner) - m_bNotifyOwner = false; - - CFWL_ScrollBar* vertSB = GetVertScrollBar(); - if (IsShowScrollBar(true) && vertSB) { - CFX_RectF rect = vertSB->GetWidgetRect(); - if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - } - - CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); - if (!hItem) - return; - - ChangeSelected(GetItemIndex(this, hItem)); - } else if (m_bNotifyOwner) { - ClientToOuter(pMsg->m_fx, pMsg->m_fy); - CFWL_ComboBox* pOuter = static_cast(m_pOuter); - pOuter->GetDelegate()->OnProcessMessage(pMsg); - } -} - -void CFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { - if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - CFWL_ComboBox* pOuter = static_cast(m_pOuter); - pOuter->ShowDropList(false); -} - -void CFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { - CFWL_ComboBox* pOuter = static_cast(m_pOuter); - if (m_bNotifyOwner) { - ClientToOuter(pMsg->m_fx, pMsg->m_fy); - pOuter->GetDelegate()->OnProcessMessage(pMsg); - return; - } - - CFWL_ScrollBar* vertSB = GetVertScrollBar(); - if (IsShowScrollBar(true) && vertSB) { - CFX_RectF rect = vertSB->GetWidgetRect(); - if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - } - pOuter->ShowDropList(false); - - CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); - if (hItem) - pOuter->ProcessSelChanged(true); -} - -bool CFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { - CFWL_ComboBox* pOuter = static_cast(m_pOuter); - bool bPropagate = false; - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { - uint32_t dwKeyCode = pKey->m_dwKeyCode; - switch (dwKeyCode) { - case FWL_VKEY_Return: - case FWL_VKEY_Escape: { - pOuter->ShowDropList(false); - return true; - } - case FWL_VKEY_Up: - case FWL_VKEY_Down: { - OnDropListKeyDown(pKey); - pOuter->ProcessSelChanged(false); - return true; - } - default: { - bPropagate = true; - break; - } - } - } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { - bPropagate = true; - } - if (bPropagate) { - pKey->m_pDstTarget = m_pOuter; - pOuter->GetDelegate()->OnProcessMessage(pKey); - return true; - } - return false; -} - -void CFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { - uint32_t dwKeyCode = pKey->m_dwKeyCode; - switch (dwKeyCode) { - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_End: { - CFWL_ComboBox* pOuter = static_cast(m_pOuter); - CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); - hItem = GetListItem(hItem, dwKeyCode); - if (!hItem) - break; - - SetSelection(hItem, hItem, true); - ScrollToVisible(hItem); - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - Repaint(&rtInvalidate); - break; - } - default: - break; - } -} diff --git a/xfa/fwl/core/cfwl_combolist.h b/xfa/fwl/core/cfwl_combolist.h deleted file mode 100644 index 0c1cd579b0..0000000000 --- a/xfa/fwl/core/cfwl_combolist.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_COMBOLIST_H_ -#define XFA_FWL_CORE_CFWL_COMBOLIST_H_ - -#include - -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -class CFWL_ComboList : public CFWL_ListBox { - public: - CFWL_ComboList(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - - // CFWL_ListBox. - void OnProcessMessage(CFWL_Message* pMessage) override; - - int32_t MatchItem(const CFX_WideString& wsMatch); - - void ChangeSelected(int32_t iSel); - - void SetNotifyOwner(bool notify) { m_bNotifyOwner = notify; } - - private: - void ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy); - void OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnDropListMouseMove(CFWL_MsgMouse* pMsg); - void OnDropListLButtonDown(CFWL_MsgMouse* pMsg); - void OnDropListLButtonUp(CFWL_MsgMouse* pMsg); - bool OnDropListKey(CFWL_MsgKey* pKey); - void OnDropListKeyDown(CFWL_MsgKey* pKey); - - bool m_bNotifyOwner; -}; - -#endif // XFA_FWL_CORE_CFWL_COMBOLIST_H_ diff --git a/xfa/fwl/core/cfwl_datetimeedit.cpp b/xfa/fwl/core/cfwl_datetimeedit.cpp deleted file mode 100644 index 37d79b6024..0000000000 --- a/xfa/fwl/core/cfwl_datetimeedit.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_datetimeedit.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_datetimepicker.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" - -CFWL_DateTimeEdit::CFWL_DateTimeEdit( - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Edit(app, std::move(properties), pOuter) {} - -void CFWL_DateTimeEdit::OnProcessMessage(CFWL_Message* pMessage) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_OnProcessMessage(pMessage); - return; - } - - CFWL_Message::Type type = pMessage->GetType(); - if (type == CFWL_Message::Type::SetFocus || - type == CFWL_Message::Type::KillFocus) { - CFWL_Widget* pOuter = GetOuter(); - pOuter->GetDelegate()->OnProcessMessage(pMessage); - } -} - -void CFWL_DateTimeEdit::DisForm_OnProcessMessage(CFWL_Message* pMessage) { - if (!m_pWidgetMgr->IsFormDisabled() || - pMessage->GetType() != CFWL_Message::Type::Mouse) { - CFWL_Edit::OnProcessMessage(pMessage); - return; - } - - CFWL_MsgMouse* pMouse = static_cast(pMessage); - if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown || - pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) { - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - - CFWL_DateTimePicker* pDateTime = - static_cast(m_pOuter); - if (pDateTime->IsMonthCalendarVisible()) { - CFX_RectF rtInvalidate = pDateTime->GetWidgetRect(); - pDateTime->ShowMonthCalendar(false); - rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top); - pDateTime->Repaint(&rtInvalidate); - } - } - CFWL_Edit::OnProcessMessage(pMessage); -} diff --git a/xfa/fwl/core/cfwl_datetimeedit.h b/xfa/fwl/core/cfwl_datetimeedit.h deleted file mode 100644 index 15fea74286..0000000000 --- a/xfa/fwl/core/cfwl_datetimeedit.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_DATETIMEEDIT_H_ -#define XFA_FWL_CORE_CFWL_DATETIMEEDIT_H_ - -#include - -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/fwl_error.h" - -class CFWL_DateTimeEdit : public CFWL_Edit { - public: - CFWL_DateTimeEdit(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - - // CFWL_Edit. - void OnProcessMessage(CFWL_Message* pMessage) override; - - private: - void DisForm_OnProcessMessage(CFWL_Message* pMessage); -}; - -#endif // XFA_FWL_CORE_CFWL_DATETIMEEDIT_H_ diff --git a/xfa/fwl/core/cfwl_datetimepicker.cpp b/xfa/fwl/core/cfwl_datetimepicker.cpp deleted file mode 100644 index 63f8955a0e..0000000000 --- a/xfa/fwl/core/cfwl_datetimepicker.cpp +++ /dev/null @@ -1,625 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_datetimepicker.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_evtselectchanged.h" -#include "xfa/fwl/core/cfwl_formproxy.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgsetfocus.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_spinbutton.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { - -const int kDateTimePickerHeight = 20; - -} // namespace -CFWL_DateTimePicker::CFWL_DateTimePicker(const CFWL_App* app) - : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), - m_iBtnState(1), - m_iYear(-1), - m_iMonth(-1), - m_iDay(-1), - m_bLBtnDown(false) { - m_rtBtn.Set(0, 0, 0, 0); - - m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; - - auto monthProp = pdfium::MakeUnique(); - monthProp->m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border; - monthProp->m_dwStates = FWL_WGTSTATE_Invisible; - monthProp->m_pParent = this; - monthProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; - m_pMonthCal.reset( - new CFWL_MonthCalendar(m_pOwnerApp, std::move(monthProp), this)); - - CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); - rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height); - m_pMonthCal->SetWidgetRect(rtMonthCal); - - auto editProp = pdfium::MakeUnique(); - editProp->m_pParent = this; - editProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; - - m_pEdit.reset(new CFWL_DateTimeEdit(m_pOwnerApp, std::move(editProp), this)); - RegisterEventTarget(m_pMonthCal.get()); - RegisterEventTarget(m_pEdit.get()); -} - -CFWL_DateTimePicker::~CFWL_DateTimePicker() { - UnregisterEventTarget(); -} - -FWL_Type CFWL_DateTimePicker::GetClassID() const { - return FWL_Type::DateTimePicker; -} - -void CFWL_DateTimePicker::Update() { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_Update(); - return; - } - if (m_iLock) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); - GetClientRect(m_rtClient); - FX_FLOAT* pFWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pFWidth) - return; - - FX_FLOAT fBtn = *pFWidth; - m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1, - m_rtClient.height - 1); - - CFX_RectF rtEdit; - rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, - m_rtClient.height); - m_pEdit->SetWidgetRect(rtEdit); - ResetEditAlignment(); - m_pEdit->Update(); - if (!(m_pMonthCal->GetThemeProvider())) - m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); - - CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); - CFX_RectF rtPopUp; - rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, - rtMonthCal.width, rtMonthCal.height); - m_pMonthCal->SetWidgetRect(rtPopUp); - m_pMonthCal->Update(); - return; -} - -FWL_WidgetHit CFWL_DateTimePicker::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_HitTest(fx, fy); - if (m_rtClient.Contains(fx, fy)) - return FWL_WidgetHit::Client; - if (IsMonthCalendarVisible()) { - CFX_RectF rect = m_pMonthCal->GetWidgetRect(); - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::Client; - } - return FWL_WidgetHit::Unknown; -} - -void CFWL_DateTimePicker::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - if (!m_rtBtn.IsEmpty()) - DrawDropDownButton(pGraphics, pTheme, pMatrix); - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_DrawWidget(pGraphics, pMatrix); - return; - } -} - -void CFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) { - m_pProperties->m_pThemeProvider = pTP; - m_pMonthCal->SetThemeProvider(pTP); -} - -void CFWL_DateTimePicker::GetCurSel(int32_t& iYear, - int32_t& iMonth, - int32_t& iDay) { - iYear = m_iYear; - iMonth = m_iMonth; - iDay = m_iDay; -} - -void CFWL_DateTimePicker::SetCurSel(int32_t iYear, - int32_t iMonth, - int32_t iDay) { - if (iYear <= 0 || iYear >= 3000) - return; - if (iMonth <= 0 || iMonth >= 13) - return; - if (iDay <= 0 || iDay >= 32) - return; - - m_iYear = iYear; - m_iMonth = iMonth; - m_iDay = iDay; - m_pMonthCal->SetSelect(iYear, iMonth, iDay); -} - -void CFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) { - if (!m_pEdit) - return; - - m_pEdit->SetText(wsText); - Repaint(&m_rtClient); - - CFWL_Event ev(CFWL_Event::Type::EditChanged); - DispatchEvent(&ev); -} - -CFX_WideString CFWL_DateTimePicker::GetEditText() const { - return m_pEdit ? m_pEdit->GetText() : L""; -} - -void CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_GetBBox(rect); - return; - } - - rect = m_pProperties->m_rtWidget; - if (IsMonthCalendarVisible()) { - CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); - rtMonth.Offset(m_pProperties->m_rtWidget.left, - m_pProperties->m_rtWidget.top); - rect.Union(rtMonth); - } -} - -void CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved) { - m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); -} - -void CFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) == - FWL_STYLEEXT_DTP_Spin) { - return; - } - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::DropDownButton; - param.m_dwStates = m_iBtnState; - param.m_pGraphics = pGraphics; - param.m_rtPart = m_rtBtn; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶m); -} - -void CFWL_DateTimePicker::FormatDateString(int32_t iYear, - int32_t iMonth, - int32_t iDay, - CFX_WideString& wsText) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) == - FWL_STYLEEXT_DTP_ShortDateFormat) { - wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay); - } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) == - FWL_STYLEEXT_DTP_LongDateFormat) { - wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay); - } -} - -void CFWL_DateTimePicker::ShowMonthCalendar(bool bActivate) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_ShowMonthCalendar(bActivate); - if (IsMonthCalendarVisible() == bActivate) - return; - if (!m_pForm) - InitProxyForm(); - - if (!bActivate) { - m_pForm->EndDoModal(); - return; - } - - CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); - - CFX_RectF rtAnchor; - rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - GetPopupPos(0, rtMonth.height, rtAnchor, rtMonth); - m_pForm->SetWidgetRect(rtMonth); - - rtMonth.left = rtMonth.top = 0; - if (bActivate) - m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible); - else - m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible); - m_pMonthCal->SetWidgetRect(rtMonth); - m_pMonthCal->Update(); - m_pForm->DoModal(); -} - -bool CFWL_DateTimePicker::IsMonthCalendarVisible() const { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_IsMonthCalendarVisible(); - if (!m_pForm) - return false; - return !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible); -} - -void CFWL_DateTimePicker::ResetEditAlignment() { - if (!m_pEdit) - return; - - uint32_t dwAdd = 0; - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditHAlignMask) { - case FWL_STYLEEXT_DTP_EditHCenter: { - dwAdd |= FWL_STYLEEXT_EDT_HCenter; - break; - } - case FWL_STYLEEXT_DTP_EditHFar: { - dwAdd |= FWL_STYLEEXT_EDT_HFar; - break; - } - default: { - dwAdd |= FWL_STYLEEXT_EDT_HNear; - break; - } - } - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditVAlignMask) { - case FWL_STYLEEXT_DTP_EditVCenter: { - dwAdd |= FWL_STYLEEXT_EDT_VCenter; - break; - } - case FWL_STYLEEXT_DTP_EditVFar: { - dwAdd |= FWL_STYLEEXT_EDT_VFar; - break; - } - default: { - dwAdd |= FWL_STYLEEXT_EDT_VNear; - break; - } - } - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditJustified) - dwAdd |= FWL_STYLEEXT_EDT_Justified; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditDistributed) - dwAdd |= FWL_STYLEEXT_EDT_Distributed; - - m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | - FWL_STYLEEXT_EDT_HAlignModeMask | - FWL_STYLEEXT_EDT_VAlignMask); -} - -void CFWL_DateTimePicker::ProcessSelChanged(int32_t iYear, - int32_t iMonth, - int32_t iDay) { - m_iYear = iYear; - m_iMonth = iMonth; - m_iDay = iDay; - - CFX_WideString wsText; - FormatDateString(m_iYear, m_iMonth, m_iDay, wsText); - m_pEdit->SetText(wsText); - m_pEdit->Update(); - Repaint(&m_rtClient); - - CFWL_EvtSelectChanged ev(this); - ev.iYear = m_iYear; - ev.iMonth = m_iMonth; - ev.iDay = m_iDay; - DispatchEvent(&ev); -} - -void CFWL_DateTimePicker::InitProxyForm() { - if (m_pForm) - return; - if (!m_pMonthCal) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_dwStyles = FWL_WGTSTYLE_Popup; - prop->m_dwStates = FWL_WGTSTATE_Invisible; - prop->m_pOwner = this; - - m_pForm = pdfium::MakeUnique(m_pOwnerApp, std::move(prop), - m_pMonthCal.get()); - m_pMonthCal->SetParent(m_pForm.get()); -} - -bool CFWL_DateTimePicker::DisForm_IsMonthCalendarVisible() const { - if (!m_pMonthCal) - return false; - return !(m_pMonthCal->GetStates() & FWL_WGTSTATE_Invisible); -} - -void CFWL_DateTimePicker::DisForm_ShowMonthCalendar(bool bActivate) { - if (IsMonthCalendarVisible() == bActivate) - return; - - if (bActivate) { - CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); - FX_FLOAT fPopupMin = rtMonthCal.height; - FX_FLOAT fPopupMax = rtMonthCal.height; - CFX_RectF rtAnchor(m_pProperties->m_rtWidget); - rtAnchor.width = rtMonthCal.width; - rtMonthCal.left = m_rtClient.left; - rtMonthCal.top = rtAnchor.Height(); - GetPopupPos(fPopupMin, fPopupMax, rtAnchor, rtMonthCal); - m_pMonthCal->SetWidgetRect(rtMonthCal); - if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0) - m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay); - m_pMonthCal->Update(); - } - if (bActivate) - m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible); - else - m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible); - - if (bActivate) { - CFWL_MsgSetFocus msg(m_pEdit.get(), m_pMonthCal.get()); - m_pEdit->GetDelegate()->OnProcessMessage(&msg); - } - - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - - CFX_RectF rtCal = m_pMonthCal->GetWidgetRect(); - rtInvalidate.Union(rtCal); - rtInvalidate.Inflate(2, 2); - Repaint(&rtInvalidate); -} - -FWL_WidgetHit CFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx, - FX_FLOAT fy) const { - CFX_RectF rect; - rect.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::Edit; - if (DisForm_IsNeedShowButton()) - rect.width += m_fBtn; - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::Client; - if (IsMonthCalendarVisible()) { - if (m_pMonthCal->GetWidgetRect().Contains(fx, fy)) - return FWL_WidgetHit::Client; - } - return FWL_WidgetHit::Unknown; -} - -bool CFWL_DateTimePicker::DisForm_IsNeedShowButton() const { - return m_pProperties->m_dwStates & FWL_WGTSTATE_Focused || - m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused || - m_pEdit->GetStates() & FWL_WGTSTATE_Focused; -} - -void CFWL_DateTimePicker::DisForm_Update() { - if (m_iLock) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); - GetClientRect(m_rtClient); - m_pEdit->SetWidgetRect(m_rtClient); - ResetEditAlignment(); - m_pEdit->Update(); - - if (!m_pMonthCal->GetThemeProvider()) - m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); - - FX_FLOAT* pWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pWidth) - return; - - m_fBtn = *pWidth; - CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect(); - CFX_RectF rtPopUp; - rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, - rtMonthCal.width, rtMonthCal.height); - m_pMonthCal->SetWidgetRect(rtPopUp); - m_pMonthCal->Update(); -} - -void CFWL_DateTimePicker::DisForm_GetBBox(CFX_RectF& rect) const { - rect = m_pProperties->m_rtWidget; - if (DisForm_IsNeedShowButton()) - rect.width += m_fBtn; - if (!IsMonthCalendarVisible()) - return; - - CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); - rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); - rect.Union(rtMonth); -} - -void CFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (m_pEdit) { - CFX_RectF rtEdit = m_pEdit->GetWidgetRect(); - - CFX_Matrix mt; - mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); - if (pMatrix) - mt.Concat(*pMatrix); - m_pEdit->DrawWidget(pGraphics, &mt); - } - if (!IsMonthCalendarVisible()) - return; - - CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); - CFX_Matrix mt; - mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top); - if (pMatrix) - mt.Concat(*pMatrix); - m_pMonthCal->DrawWidget(pGraphics, &mt); -} - -void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMouse = static_cast(pMessage); - switch (pMouse->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMouse); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMouse); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMouse); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMouse); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: { - if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { - m_pEdit->GetDelegate()->OnProcessMessage(pMessage); - return; - } - break; - } - default: - break; - } - - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_DateTimePicker::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (!pMsg) - return; - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_OnFocusChanged(pMsg, bSet); - - if (bSet) { - m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); - Repaint(&m_rtClient); - } else { - m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); - Repaint(&m_rtClient); - } - if (pMsg->m_pSrcTarget == m_pMonthCal.get() && IsMonthCalendarVisible()) { - ShowMonthCalendar(false); - } - Repaint(&m_rtClient); -} - -void CFWL_DateTimePicker::OnLButtonDown(CFWL_MsgMouse* pMsg) { - if (!pMsg) - return; - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - SetFocus(true); - if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - if (IsMonthCalendarVisible()) { - ShowMonthCalendar(false); - return; - } - if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) - ShowMonthCalendar(true); - - m_bLBtnDown = true; - Repaint(&m_rtClient); -} - -void CFWL_DateTimePicker::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (!pMsg) - return; - - m_bLBtnDown = false; - if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) - m_iBtnState = CFWL_PartState_Hovered; - else - m_iBtnState = CFWL_PartState_Normal; - Repaint(&m_rtBtn); -} - -void CFWL_DateTimePicker::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) - m_iBtnState = CFWL_PartState_Normal; - Repaint(&m_rtBtn); -} - -void CFWL_DateTimePicker::OnMouseLeave(CFWL_MsgMouse* pMsg) { - if (!pMsg) - return; - m_iBtnState = CFWL_PartState_Normal; - Repaint(&m_rtBtn); -} - -void CFWL_DateTimePicker::DisForm_OnFocusChanged(CFWL_Message* pMsg, - bool bSet) { - CFX_RectF rtInvalidate(m_rtBtn); - if (bSet) { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { - m_rtBtn.Set(m_pProperties->m_rtWidget.width, 0, m_fBtn, - m_pProperties->m_rtWidget.height - 1); - } - rtInvalidate = m_rtBtn; - pMsg->m_pDstTarget = m_pEdit.get(); - m_pEdit->GetDelegate()->OnProcessMessage(pMsg); - } else { - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - m_rtBtn.Set(0, 0, 0, 0); - if (DisForm_IsMonthCalendarVisible()) - ShowMonthCalendar(false); - if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { - pMsg->m_pSrcTarget = m_pEdit.get(); - m_pEdit->GetDelegate()->OnProcessMessage(pMsg); - } - } - rtInvalidate.Inflate(2, 2); - Repaint(&rtInvalidate); -} diff --git a/xfa/fwl/core/cfwl_datetimepicker.h b/xfa/fwl/core/cfwl_datetimepicker.h deleted file mode 100644 index e88cdc2f96..0000000000 --- a/xfa/fwl/core/cfwl_datetimepicker.h +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_DATETIMEPICKER_H_ -#define XFA_FWL_CORE_CFWL_DATETIMEPICKER_H_ - -#include - -#include "xfa/fwl/core/cfwl_datetimeedit.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_monthcalendar.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_STYLEEXT_DTP_AllowEdit (1L << 0) -#define FWL_STYLEEXT_DTP_LongDateFormat (0L << 1) -#define FWL_STYLEEXT_DTP_ShortDateFormat (1L << 1) -#define FWL_STYLEEXT_DTP_TimeFormat (2L << 1) -#define FWL_STYLEEXT_DTP_Spin (1L << 3) -#define FWL_STYLEEXT_DTP_EditHNear (0L << 4) -#define FWL_STYLEEXT_DTP_EditHCenter (1L << 4) -#define FWL_STYLEEXT_DTP_EditHFar (2L << 4) -#define FWL_STYLEEXT_DTP_EditVNear (0L << 6) -#define FWL_STYLEEXT_DTP_EditVCenter (1L << 6) -#define FWL_STYLEEXT_DTP_EditVFar (2L << 6) -#define FWL_STYLEEXT_DTP_EditJustified (1L << 8) -#define FWL_STYLEEXT_DTP_EditDistributed (2L << 8) -#define FWL_STYLEEXT_DTP_EditHAlignMask (3L << 4) -#define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6) -#define FWL_STYLEEXT_DTP_EditHAlignModeMask (3L << 8) - -class CFWL_DateTimeEdit; -class CFWL_FormProxy; - -class CFWL_DateTimePicker : public CFWL_Widget { - public: - explicit CFWL_DateTimePicker(const CFWL_App* pApp); - ~CFWL_DateTimePicker() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void SetThemeProvider(IFWL_ThemeProvider* pTP) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay); - void SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay); - - void SetEditText(const CFX_WideString& wsText); - CFX_WideString GetEditText() const; - - int32_t CountSelRanges() const { return m_pEdit->CountSelRanges(); } - int32_t GetSelRange(int32_t nIndex, int32_t* nStart) const { - return m_pEdit->GetSelRange(nIndex, nStart); - } - - void GetBBox(CFX_RectF& rect) const; - void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); } - void ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); - - bool IsMonthCalendarVisible() const; - void ShowMonthCalendar(bool bActivate); - void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay); - - CFWL_FormProxy* GetFormProxy() const { return m_pForm.get(); } - - private: - void DrawDropDownButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void FormatDateString(int32_t iYear, - int32_t iMonth, - int32_t iDay, - CFX_WideString& wsText); - void ResetEditAlignment(); - void InitProxyForm(); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - - bool DisForm_IsMonthCalendarVisible() const; - void DisForm_ShowMonthCalendar(bool bActivate); - FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) const; - bool DisForm_IsNeedShowButton() const; - void DisForm_Update(); - void DisForm_GetBBox(CFX_RectF& rect) const; - void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); - void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); - - CFX_RectF m_rtBtn; - CFX_RectF m_rtClient; - int32_t m_iBtnState; - int32_t m_iYear; - int32_t m_iMonth; - int32_t m_iDay; - bool m_bLBtnDown; - std::unique_ptr m_pEdit; - std::unique_ptr m_pMonthCal; - std::unique_ptr m_pForm; - FX_FLOAT m_fBtn; -}; - -#endif // XFA_FWL_CORE_CFWL_DATETIMEPICKER_H_ diff --git a/xfa/fwl/core/cfwl_edit.cpp b/xfa/fwl/core/cfwl_edit.cpp deleted file mode 100644 index c6c0ce29ba..0000000000 --- a/xfa/fwl/core/cfwl_edit.cpp +++ /dev/null @@ -1,1644 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_edit.h" - -#include -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fde/fde_gedevice.h" -#include "xfa/fde/fde_render.h" -#include "xfa/fde/ifde_txtedtpage.h" -#include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_caret.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_evtcheckword.h" -#include "xfa/fwl/core/cfwl_evttextchanged.h" -#include "xfa/fwl/core/cfwl_evtvalidate.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_path.h" - -namespace { - -const int kEditMargin = 3; - -bool FX_EDIT_ISLATINWORD(FX_WCHAR c) { - return c == 0x2D || (c <= 0x005A && c >= 0x0041) || - (c <= 0x007A && c >= 0x0061) || (c <= 0x02AF && c >= 0x00C0) || - c == 0x0027; -} - -void AddSquigglyPath(CFX_Path* pPathData, - FX_FLOAT fStartX, - FX_FLOAT fEndX, - FX_FLOAT fY, - FX_FLOAT fStep) { - pPathData->MoveTo(fStartX, fY); - int i = 1; - for (FX_FLOAT fx = fStartX + fStep; fx < fEndX; fx += fStep, ++i) - pPathData->LineTo(fx, fY + (i & 1) * fStep); -} - -} // namespace - -CFWL_Edit::CFWL_Edit(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Widget(app, std::move(properties), pOuter), - m_fVAlignOffset(0.0f), - m_fScrollOffsetX(0.0f), - m_fScrollOffsetY(0.0f), - m_bLButtonDown(false), - m_nSelStart(0), - m_nLimit(-1), - m_fFontSize(0), - m_bSetRange(false), - m_iMax(0xFFFFFFF), - m_iCurRecord(-1), - m_iMaxRecord(128) { - m_rtClient.Reset(); - m_rtEngine.Reset(); - m_rtStatic.Reset(); - - InitCaret(); -} - -CFWL_Edit::~CFWL_Edit() { - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - HideCaret(nullptr); - ClearRecord(); -} - -FWL_Type CFWL_Edit::GetClassID() const { - return FWL_Type::Edit; -} - -CFX_RectF CFWL_Edit::GetWidgetRect() { - CFX_RectF rect = m_pProperties->m_rtWidget; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { - if (IsShowScrollBar(true)) { - FX_FLOAT* pfWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - rect.width += *pfWidth; - rect.width += kEditMargin; - } - if (IsShowScrollBar(false)) { - FX_FLOAT* pfWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - rect.height += *pfWidth; - rect.height += kEditMargin; - } - } - return rect; -} - -CFX_RectF CFWL_Edit::GetAutosizedWidgetRect() { - CFX_RectF rect; - if (m_EdtEngine.GetTextLength() > 0) { - CFX_SizeF sz = CalcTextSize( - m_EdtEngine.GetText(0, -1), m_pProperties->m_pThemeProvider, - !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); - rect.Set(0, 0, sz.x, sz.y); - } - InflateWidgetRect(rect); - return rect; -} - -void CFWL_Edit::SetStates(uint32_t dwStates) { - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { - HideCaret(nullptr); - } - CFWL_Widget::SetStates(dwStates); -} - -void CFWL_Edit::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); - if (m_rtClient.IsEmpty()) - return; - - UpdateEditEngine(); - UpdateVAlignment(); - UpdateScroll(); - InitCaret(); -} - -FWL_WidgetHit CFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { - if (IsShowScrollBar(true)) { - if (m_pVertScrollBar->GetWidgetRect().Contains(fx, fy)) - return FWL_WidgetHit::VScrollBar; - } - if (IsShowScrollBar(false)) { - if (m_pHorzScrollBar->GetWidgetRect().Contains(fx, fy)) - return FWL_WidgetHit::HScrollBar; - } - } - if (m_rtClient.Contains(fx, fy)) - return FWL_WidgetHit::Edit; - return FWL_WidgetHit::Unknown; -} - -void CFWL_Edit::AddSpellCheckObj(CFX_Path& PathData, - int32_t nStart, - int32_t nCount, - FX_FLOAT fOffSetX, - FX_FLOAT fOffSetY) { - FX_FLOAT fStartX = 0.0f; - FX_FLOAT fEndX = 0.0f; - FX_FLOAT fY = 0.0f; - FX_FLOAT fStep = 0.0f; - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - CFX_RectFArray rectArray; - CFX_RectF rectText; - const FDE_TXTEDTPARAMS* txtEdtParams = m_EdtEngine.GetEditParams(); - FX_FLOAT fAsent = static_cast(txtEdtParams->pFont->GetAscent()) * - txtEdtParams->fFontSize / 1000; - pPage->CalcRangeRectArray(nStart, nCount, rectArray); - - for (int i = 0; i < rectArray.GetSize(); i++) { - rectText = rectArray.GetAt(i); - fY = rectText.top + fAsent + fOffSetY; - fStep = txtEdtParams->fFontSize / 16.0f; - fStartX = rectText.left + fOffSetX; - fEndX = fStartX + rectText.Width(); - AddSquigglyPath(&PathData, fStartX, fEndX, fY, fStep); - } -} - -void CFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - pGraphics->SaveGraphState(); - if (pMatrix) - pGraphics->ConcatMatrix(const_cast(pMatrix)); - - CFX_Color crLine(0xFFFF0000); - CFWL_EvtCheckWord checkWordEvent(this); - - CFX_ByteString sLatinWord; - CFX_Path pathSpell; - pathSpell.Create(); - - int32_t nStart = 0; - FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; - FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; - - CFX_WideString wsSpell = GetText(); - int32_t nContentLen = wsSpell.GetLength(); - for (int i = 0; i < nContentLen; i++) { - if (FX_EDIT_ISLATINWORD(wsSpell[i])) { - if (sLatinWord.IsEmpty()) - nStart = i; - sLatinWord += (FX_CHAR)wsSpell[i]; - continue; - } - checkWordEvent.bsWord = sLatinWord; - checkWordEvent.bCheckWord = true; - DispatchEvent(&checkWordEvent); - - if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { - AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, - fOffSetY); - } - sLatinWord.clear(); - } - - checkWordEvent.bsWord = sLatinWord; - checkWordEvent.bCheckWord = true; - DispatchEvent(&checkWordEvent); - - if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { - AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, - fOffSetY); - } - if (!pathSpell.IsEmpty()) { - CFX_RectF rtClip = m_rtEngine; - CFX_Matrix mt; - mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); - if (pMatrix) { - pMatrix->TransformRect(rtClip); - mt.Concat(*pMatrix); - } - pGraphics->SetClipRect(rtClip); - pGraphics->SetStrokeColor(&crLine); - pGraphics->SetLineWidth(0); - pGraphics->StrokePath(&pathSpell, nullptr); - } - pGraphics->RestoreGraphState(); -} - -void CFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - if (m_rtClient.IsEmpty()) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (!m_pWidgetMgr->IsFormDisabled()) - DrawTextBk(pGraphics, pTheme, pMatrix); - DrawContent(pGraphics, pTheme, pMatrix); - - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && - !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) { - DrawSpellCheck(pGraphics, pMatrix); - } - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); -} - -void CFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - if (!pThemeProvider) - return; - if (m_pHorzScrollBar) - m_pHorzScrollBar->SetThemeProvider(pThemeProvider); - if (m_pVertScrollBar) - m_pVertScrollBar->SetThemeProvider(pThemeProvider); - if (m_pCaret) - m_pCaret->SetThemeProvider(pThemeProvider); - m_pProperties->m_pThemeProvider = pThemeProvider; -} - -void CFWL_Edit::SetText(const CFX_WideString& wsText) { - m_EdtEngine.SetText(wsText); -} - -int32_t CFWL_Edit::GetTextLength() const { - return m_EdtEngine.GetTextLength(); -} - -CFX_WideString CFWL_Edit::GetText() const { - return m_EdtEngine.GetText(0, -1); -} - -void CFWL_Edit::ClearText() { - m_EdtEngine.ClearText(); -} - -void CFWL_Edit::AddSelRange(int32_t nStart) { - m_EdtEngine.AddSelRange(nStart, -1); -} - -int32_t CFWL_Edit::CountSelRanges() const { - return m_EdtEngine.CountSelRanges(); -} - -int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t* nStart) const { - return m_EdtEngine.GetSelRange(nIndex, nStart); -} - -void CFWL_Edit::ClearSelections() { - m_EdtEngine.ClearSelection(); -} - -int32_t CFWL_Edit::GetLimit() const { - return m_nLimit; -} - -void CFWL_Edit::SetLimit(int32_t nLimit) { - m_nLimit = nLimit; - m_EdtEngine.SetLimit(nLimit); -} - -void CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { - m_EdtEngine.SetAliasChar(wAlias); -} - -bool CFWL_Edit::Copy(CFX_WideString& wsCopy) { - int32_t nCount = m_EdtEngine.CountSelRanges(); - if (nCount == 0) - return false; - - wsCopy.clear(); - int32_t nStart; - int32_t nLength; - for (int32_t i = 0; i < nCount; i++) { - nLength = m_EdtEngine.GetSelRange(i, &nStart); - wsCopy += m_EdtEngine.GetText(nStart, nLength); - } - return true; -} - -bool CFWL_Edit::Cut(CFX_WideString& wsCut) { - int32_t nCount = m_EdtEngine.CountSelRanges(); - if (nCount == 0) - return false; - - wsCut.clear(); - CFX_WideString wsTemp; - int32_t nStart, nLength; - for (int32_t i = 0; i < nCount; i++) { - nLength = m_EdtEngine.GetSelRange(i, &nStart); - wsTemp = m_EdtEngine.GetText(nStart, nLength); - wsCut += wsTemp; - wsTemp.clear(); - } - m_EdtEngine.Delete(0); - return true; -} - -bool CFWL_Edit::Paste(const CFX_WideString& wsPaste) { - int32_t nCaret = m_EdtEngine.GetCaretPos(); - int32_t iError = - m_EdtEngine.Insert(nCaret, wsPaste.c_str(), wsPaste.GetLength()); - if (iError < 0) { - ProcessInsertError(iError); - return false; - } - return true; -} - -bool CFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) - return true; - return m_EdtEngine.Redo(pRecord); -} - -bool CFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) - return true; - return m_EdtEngine.Undo(pRecord); -} - -bool CFWL_Edit::Undo() { - if (!CanUndo()) - return false; - return Undo(m_DoRecords[m_iCurRecord--].get()); -} - -bool CFWL_Edit::Redo() { - if (!CanRedo()) - return false; - return Redo(m_DoRecords[++m_iCurRecord].get()); -} - -bool CFWL_Edit::CanUndo() { - return m_iCurRecord >= 0; -} - -bool CFWL_Edit::CanRedo() { - return m_iCurRecord < pdfium::CollectionSize(m_DoRecords) - 1; -} - -void CFWL_Edit::SetOuter(CFWL_Widget* pOuter) { - m_pOuter = pOuter; -} - -void CFWL_Edit::OnCaretChanged() { - if (m_rtEngine.IsEmpty()) - return; - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - return; - - bool bRepaintContent = UpdateOffset(); - UpdateCaret(); - CFX_RectF rtInvalid; - rtInvalid.Set(0, 0, 0, 0); - bool bRepaintScroll = false; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { - CFWL_ScrollBar* pScroll = UpdateScroll(); - if (pScroll) { - rtInvalid = pScroll->GetWidgetRect(); - bRepaintScroll = true; - } - } - if (bRepaintContent || bRepaintScroll) { - if (bRepaintContent) - rtInvalid.Union(m_rtEngine); - Repaint(&rtInvalid); - } -} - -void CFWL_Edit::OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask) - UpdateVAlignment(); - - CFX_RectF rtTemp; - GetClientRect(rtTemp); - - CFWL_EvtTextChanged event(this); - event.wsPrevText = ChangeInfo.wsPrevText; - DispatchEvent(&event); - - LayoutScrollBar(); - Repaint(&rtTemp); -} - -void CFWL_Edit::OnSelChanged() { - CFX_RectF rtTemp; - GetClientRect(rtTemp); - Repaint(&rtTemp); -} - -bool CFWL_Edit::OnPageLoad(int32_t nPageIndex) { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); - if (!pPage) - return false; - - pPage->LoadPage(nullptr, nullptr); - return true; -} - -bool CFWL_Edit::OnPageUnload(int32_t nPageIndex) { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); - if (!pPage) - return false; - - pPage->UnloadPage(nullptr); - return true; -} - -void CFWL_Edit::OnAddDoRecord(std::unique_ptr pRecord) { - AddDoRecord(std::move(pRecord)); -} - -bool CFWL_Edit::OnValidate(const CFX_WideString& wsText) { - CFWL_Widget* pDst = GetOuter(); - if (!pDst) - pDst = this; - - CFWL_EvtValidate event(this); - event.wsInsert = wsText; - event.bValidate = true; - DispatchEvent(&event); - return event.bValidate; -} - -void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { - m_fScrollOffsetY = fScrollOffset; -} - -void CFWL_Edit::DrawTextBk(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_bStaticBackground = false; - param.m_dwStates = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly - ? CFWL_PartState_ReadOnly - : CFWL_PartState_Normal; - uint32_t dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); - if (dwStates) - param.m_dwStates = CFWL_PartState_Disabled; - param.m_pGraphics = pGraphics; - param.m_matrix = *pMatrix; - param.m_rtPart = m_rtClient; - pTheme->DrawBackground(¶m); - - if (!IsShowScrollBar(true) || !IsShowScrollBar(false)) - return; - - CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect(); - - CFX_RectF rtStatic; - rtStatic.Set(m_rtClient.right() - rtScroll.height, - m_rtClient.bottom() - rtScroll.height, rtScroll.height, - rtScroll.height); - param.m_bStaticBackground = true; - param.m_bMaximize = true; - param.m_rtPart = rtStatic; - pTheme->DrawBackground(¶m); -} - -void CFWL_Edit::DrawContent(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return; - - pGraphics->SaveGraphState(); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) - pGraphics->SaveGraphState(); - - CFX_RectF rtClip = m_rtEngine; - FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; - FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; - CFX_Matrix mt; - mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); - if (pMatrix) { - pMatrix->TransformRect(rtClip); - mt.Concat(*pMatrix); - } - - bool bShowSel = (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoHideSel) || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); - if (bShowSel) { - CFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(this); - if (pForm) { - bShowSel = (pForm->GetStates() & FWL_WGTSTATE_Deactivated) != - FWL_WGTSTATE_Deactivated; - } - } - - int32_t nSelCount = m_EdtEngine.CountSelRanges(); - if (bShowSel && nSelCount > 0) { - int32_t nPageCharStart = pPage->GetCharStart(); - int32_t nPageCharCount = pPage->GetCharCount(); - int32_t nPageCharEnd = nPageCharStart + nPageCharCount - 1; - int32_t nCharCount; - int32_t nCharStart; - CFX_RectFArray rectArr; - int32_t i = 0; - for (i = 0; i < nSelCount; i++) { - nCharCount = m_EdtEngine.GetSelRange(i, &nCharStart); - int32_t nCharEnd = nCharStart + nCharCount - 1; - if (nCharEnd < nPageCharStart || nCharStart > nPageCharEnd) - continue; - - int32_t nBgn = std::max(nCharStart, nPageCharStart); - int32_t nEnd = std::min(nCharEnd, nPageCharEnd); - pPage->CalcRangeRectArray(nBgn - nPageCharStart, nEnd - nBgn + 1, - rectArr); - } - - int32_t nCount = rectArr.GetSize(); - CFX_Path path; - path.Create(); - for (i = 0; i < nCount; i++) { - rectArr[i].left += fOffSetX; - rectArr[i].top += fOffSetY; - path.AddRectangle(rectArr[i].left, rectArr[i].top, rectArr[i].width, - rectArr[i].height); - } - pGraphics->SetClipRect(rtClip); - - CFWL_ThemeBackground param; - param.m_pGraphics = pGraphics; - param.m_matrix = *pMatrix; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_pPath = &path; - pTheme->DrawBackground(¶m); - } - - CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice(); - if (!pRenderDev) - return; - - std::unique_ptr pRenderDevice( - new CFDE_RenderDevice(pRenderDev, false)); - std::unique_ptr pRenderContext(new CFDE_RenderContext); - pRenderDevice->SetClipRect(rtClip); - pRenderContext->StartRender(pRenderDevice.get(), pPage, mt); - pRenderContext->DoRender(nullptr); - - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { - pGraphics->RestoreGraphState(); - CFX_Path path; - path.Create(); - int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1; - FX_FLOAT fStep = m_rtEngine.width / iLimit; - FX_FLOAT fLeft = m_rtEngine.left + 1; - for (int32_t i = 1; i < iLimit; i++) { - fLeft += fStep; - path.AddLine(fLeft, m_rtClient.top, fLeft, m_rtClient.bottom()); - } - - CFWL_ThemeBackground param; - param.m_pGraphics = pGraphics; - param.m_matrix = *pMatrix; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::CombTextLine; - param.m_pPath = &path; - pTheme->DrawBackground(¶m); - } - pGraphics->RestoreGraphState(); -} - -void CFWL_Edit::UpdateEditEngine() { - UpdateEditParams(); - UpdateEditLayout(); - if (m_nLimit > -1) - m_EdtEngine.SetLimit(m_nLimit); -} - -void CFWL_Edit::UpdateEditParams() { - FDE_TXTEDTPARAMS params; - params.nHorzScale = 100; - params.fPlateWidth = m_rtEngine.width; - params.fPlateHeight = m_rtEngine.height; - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_RTLLayout) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_RTL; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalLayout) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_DocVertical; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalChars) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CharVertial; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReverseLine) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LineReserve; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ArabicShapes) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ArabicShapes; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ExpandTab) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ExpandTab; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CombText; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_LastLineHeight) - params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LastLineHeight; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Validate) - params.dwMode |= FDE_TEXTEDITMODE_Validate; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Password) - params.dwMode |= FDE_TEXTEDITMODE_Password; - - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignMask) { - case FWL_STYLEEXT_EDT_HNear: { - params.dwAlignment |= FDE_TEXTEDITALIGN_Left; - break; - } - case FWL_STYLEEXT_EDT_HCenter: { - params.dwAlignment |= FDE_TEXTEDITALIGN_Center; - break; - } - case FWL_STYLEEXT_EDT_HFar: { - params.dwAlignment |= FDE_TEXTEDITALIGN_Right; - break; - } - default: - break; - } - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignModeMask) { - case FWL_STYLEEXT_EDT_Justified: { - params.dwAlignment |= FDE_TEXTEDITALIGN_Justified; - break; - } - case FWL_STYLEEXT_EDT_Distributed: { - params.dwAlignment |= FDE_TEXTEDITALIGN_Distributed; - break; - } - default: { - params.dwAlignment |= FDE_TEXTEDITALIGN_Normal; - break; - } - } - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { - params.dwMode |= FDE_TEXTEDITMODE_MultiLines; - if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) == 0 && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) { - params.dwMode |= - FDE_TEXTEDITMODE_AutoLineWrap | FDE_TEXTEDITMODE_LimitArea_Horz; - } - if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) == 0 && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoVScroll) == 0) { - params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Vert; - } else { - params.fPlateHeight = 0x00FFFFFF; - } - } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == - 0) { - params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Horz; - } - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { - params.dwMode |= FDE_TEXTEDITMODE_ReadOnly; - } - - FX_FLOAT* pFontSize = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); - if (!pFontSize) - return; - - m_fFontSize = *pFontSize; - uint32_t* pFontColor = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::TextColor)); - if (!pFontColor) - return; - - params.dwFontColor = *pFontColor; - FX_FLOAT* pLineHeight = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::LineHeight)); - if (!pLineHeight) - return; - - params.fLineSpace = *pLineHeight; - CFGAS_GEFont* pFont = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::Font)); - if (!pFont) - return; - - params.pFont = pFont; - params.fFontSize = m_fFontSize; - params.nLineCount = (int32_t)(params.fPlateHeight / params.fLineSpace); - if (params.nLineCount <= 0) - params.nLineCount = 1; - params.fTabWidth = params.fFontSize * 1; - params.bTabEquidistant = true; - params.wLineBreakChar = L'\n'; - params.nCharRotation = 0; - params.pEventSink = this; - m_EdtEngine.SetEditParams(params); -} - -void CFWL_Edit::UpdateEditLayout() { - if (m_EdtEngine.GetTextLength() <= 0) - m_EdtEngine.SetTextByStream(nullptr); - - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (pPage) - pPage->UnloadPage(nullptr); - - m_EdtEngine.StartLayout(); - m_EdtEngine.DoLayout(nullptr); - m_EdtEngine.EndLayout(); - pPage = m_EdtEngine.GetPage(0); - if (pPage) - pPage->LoadPage(nullptr, nullptr); -} - -bool CFWL_Edit::UpdateOffset() { - CFX_RectF rtCaret; - m_EdtEngine.GetCaretRect(rtCaret); - FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; - FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; - rtCaret.Offset(fOffSetX, fOffSetY); - const CFX_RectF& rtEidt = m_rtEngine; - if (rtEidt.Contains(rtCaret)) { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return false; - - CFX_RectF rtFDE = pPage->GetContentsBox(); - rtFDE.Offset(fOffSetX, fOffSetY); - if (rtFDE.right() < rtEidt.right() && m_fScrollOffsetX > 0) { - m_fScrollOffsetX += rtFDE.right() - rtEidt.right(); - m_fScrollOffsetX = std::max(m_fScrollOffsetX, 0.0f); - } - if (rtFDE.bottom() < rtEidt.bottom() && m_fScrollOffsetY > 0) { - m_fScrollOffsetY += rtFDE.bottom() - rtEidt.bottom(); - m_fScrollOffsetY = std::max(m_fScrollOffsetY, 0.0f); - } - return false; - } - - FX_FLOAT offsetX = 0.0; - FX_FLOAT offsetY = 0.0; - if (rtCaret.left < rtEidt.left) - offsetX = rtCaret.left - rtEidt.left; - if (rtCaret.right() > rtEidt.right()) - offsetX = rtCaret.right() - rtEidt.right(); - if (rtCaret.top < rtEidt.top) - offsetY = rtCaret.top - rtEidt.top; - if (rtCaret.bottom() > rtEidt.bottom()) - offsetY = rtCaret.bottom() - rtEidt.bottom(); - m_fScrollOffsetX += offsetX; - m_fScrollOffsetY += offsetY; - if (m_fFontSize > m_rtEngine.height) - m_fScrollOffsetY = 0; - return true; -} - -bool CFWL_Edit::UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged) { - if (pScrollBar == m_pHorzScrollBar.get()) - m_fScrollOffsetX += fPosChanged; - else - m_fScrollOffsetY += fPosChanged; - return true; -} - -void CFWL_Edit::UpdateVAlignment() { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return; - - const CFX_RectF& rtFDE = pPage->GetContentsBox(); - FX_FLOAT fOffsetY = 0.0f; - FX_FLOAT fSpaceAbove = 0.0f; - FX_FLOAT fSpaceBelow = 0.0f; - CFX_SizeF* pSpace = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::SpaceAboveBelow)); - if (pSpace) { - fSpaceAbove = pSpace->x; - fSpaceBelow = pSpace->y; - } - if (fSpaceAbove < 0.1f) - fSpaceAbove = 0; - if (fSpaceBelow < 0.1f) - fSpaceBelow = 0; - - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VCenter) { - fOffsetY = (m_rtEngine.height - rtFDE.height) / 2; - if (fOffsetY < (fSpaceAbove + fSpaceBelow) / 2 && - fSpaceAbove < fSpaceBelow) { - return; - } - fOffsetY += (fSpaceAbove - fSpaceBelow) / 2; - } else if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VFar) { - fOffsetY = (m_rtEngine.height - rtFDE.height); - fOffsetY -= fSpaceBelow; - } else { - fOffsetY += fSpaceAbove; - } - m_fVAlignOffset = std::max(fOffsetY, 0.0f); -} - -void CFWL_Edit::UpdateCaret() { - CFX_RectF rtFDE; - m_EdtEngine.GetCaretRect(rtFDE); - - rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX, - m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset); - CFX_RectF rtCaret; - rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height); - - CFX_RectF rtClient; - GetClientRect(rtClient); - rtCaret.Intersect(rtClient); - - if (rtCaret.left > rtClient.right()) { - FX_FLOAT right = rtCaret.right(); - rtCaret.left = rtClient.right() - 1; - rtCaret.width = right - rtCaret.left; - } - - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty()) - ShowCaret(&rtCaret); - else - HideCaret(&rtCaret); -} - -CFWL_ScrollBar* CFWL_Edit::UpdateScroll() { - bool bShowHorz = - m_pHorzScrollBar && - ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); - bool bShowVert = - m_pVertScrollBar && - ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); - if (!bShowHorz && !bShowVert) - return nullptr; - - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return nullptr; - - const CFX_RectF& rtFDE = pPage->GetContentsBox(); - CFWL_ScrollBar* pRepaint = nullptr; - if (bShowHorz) { - CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect(); - if (rtScroll.width < rtFDE.width) { - m_pHorzScrollBar->LockUpdate(); - FX_FLOAT fRange = rtFDE.width - rtScroll.width; - m_pHorzScrollBar->SetRange(0.0f, fRange); - - FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetX, 0.0f), fRange); - m_pHorzScrollBar->SetPos(fPos); - m_pHorzScrollBar->SetTrackPos(fPos); - m_pHorzScrollBar->SetPageSize(rtScroll.width); - m_pHorzScrollBar->SetStepSize(rtScroll.width / 10); - m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Disabled); - m_pHorzScrollBar->UnlockUpdate(); - m_pHorzScrollBar->Update(); - pRepaint = m_pHorzScrollBar.get(); - } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { - m_pHorzScrollBar->LockUpdate(); - m_pHorzScrollBar->SetRange(0, -1); - m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled); - m_pHorzScrollBar->UnlockUpdate(); - m_pHorzScrollBar->Update(); - pRepaint = m_pHorzScrollBar.get(); - } - } - - if (bShowVert) { - CFX_RectF rtScroll = m_pVertScrollBar->GetWidgetRect(); - if (rtScroll.height < rtFDE.height) { - m_pVertScrollBar->LockUpdate(); - FX_FLOAT fStep = m_EdtEngine.GetEditParams()->fLineSpace; - FX_FLOAT fRange = std::max(rtFDE.height - m_rtEngine.height, fStep); - - m_pVertScrollBar->SetRange(0.0f, fRange); - FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetY, 0.0f), fRange); - m_pVertScrollBar->SetPos(fPos); - m_pVertScrollBar->SetTrackPos(fPos); - m_pVertScrollBar->SetPageSize(rtScroll.height); - m_pVertScrollBar->SetStepSize(fStep); - m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Disabled); - m_pVertScrollBar->UnlockUpdate(); - m_pVertScrollBar->Update(); - pRepaint = m_pVertScrollBar.get(); - } else if ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { - m_pVertScrollBar->LockUpdate(); - m_pVertScrollBar->SetRange(0, -1); - m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled); - m_pVertScrollBar->UnlockUpdate(); - m_pVertScrollBar->Update(); - pRepaint = m_pVertScrollBar.get(); - } - } - return pRepaint; -} - -bool CFWL_Edit::IsShowScrollBar(bool bVert) { - bool bShow = - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) - ? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == - FWL_WGTSTATE_Focused - : true; - if (bVert) { - return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) && - IsContentHeightOverflow(); - } - return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine); -} - -bool CFWL_Edit::IsContentHeightOverflow() { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return false; - return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f; -} - -int32_t CFWL_Edit::AddDoRecord(std::unique_ptr pRecord) { - int32_t nCount = pdfium::CollectionSize(m_DoRecords); - if (m_iCurRecord == nCount - 1) { - if (nCount == m_iMaxRecord) { - m_DoRecords.pop_front(); - m_iCurRecord--; - } - } else { - m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, - m_DoRecords.end()); - } - - m_DoRecords.push_back(std::move(pRecord)); - m_iCurRecord = pdfium::CollectionSize(m_DoRecords) - 1; - return m_iCurRecord; -} - -void CFWL_Edit::Layout() { - GetClientRect(m_rtClient); - m_rtEngine = m_rtClient; - FX_FLOAT* pfWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pfWidth) - return; - - FX_FLOAT fWidth = *pfWidth; - if (!m_pOuter) { - CFX_RectF* pUIMargin = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); - if (pUIMargin) { - m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, - pUIMargin->height); - } - } else if (m_pOuter->GetClassID() == FWL_Type::DateTimePicker) { - CFWL_ThemePart part; - part.m_pWidget = m_pOuter; - CFX_RectF* pUIMargin = - static_cast(m_pOuter->GetThemeProvider()->GetCapacity( - &part, CFWL_WidgetCapacity::UIMargin)); - if (pUIMargin) { - m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, - pUIMargin->height); - } - } - - bool bShowVertScrollbar = IsShowScrollBar(true); - bool bShowHorzScrollbar = IsShowScrollBar(false); - if (bShowVertScrollbar) { - InitVerticalScrollBar(); - - CFX_RectF rtVertScr; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { - rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, - m_rtClient.height); - } else { - rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, - m_rtClient.height); - if (bShowHorzScrollbar) - rtVertScr.height -= fWidth; - m_rtEngine.width -= fWidth; - } - - m_pVertScrollBar->SetWidgetRect(rtVertScr); - m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - m_pVertScrollBar->Update(); - } else if (m_pVertScrollBar) { - m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - - if (bShowHorzScrollbar) { - InitHorizontalScrollBar(); - - CFX_RectF rtHoriScr; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { - rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, - m_rtClient.width, fWidth); - } else { - rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, - m_rtClient.width, fWidth); - if (bShowVertScrollbar) - rtHoriScr.width -= fWidth; - m_rtEngine.height -= fWidth; - } - m_pHorzScrollBar->SetWidgetRect(rtHoriScr); - m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - m_pHorzScrollBar->Update(); - } else if (m_pHorzScrollBar) { - m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } -} - -void CFWL_Edit::LayoutScrollBar() { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) == - 0) { - return; - } - - FX_FLOAT* pfWidth = nullptr; - bool bShowVertScrollbar = IsShowScrollBar(true); - bool bShowHorzScrollbar = IsShowScrollBar(false); - if (bShowVertScrollbar) { - if (!m_pVertScrollBar) { - pfWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; - InitVerticalScrollBar(); - CFX_RectF rtVertScr; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { - rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, - m_rtClient.height); - } else { - rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, - m_rtClient.height); - if (bShowHorzScrollbar) - rtVertScr.height -= fWidth; - } - m_pVertScrollBar->SetWidgetRect(rtVertScr); - m_pVertScrollBar->Update(); - } - m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - } else if (m_pVertScrollBar) { - m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - - if (bShowHorzScrollbar) { - if (!m_pHorzScrollBar) { - if (!pfWidth) { - pfWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - } - - FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; - InitHorizontalScrollBar(); - CFX_RectF rtHoriScr; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { - rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, - m_rtClient.width, fWidth); - } else { - rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, - m_rtClient.width, fWidth); - if (bShowVertScrollbar) - rtHoriScr.width -= (fWidth); - } - m_pHorzScrollBar->SetWidgetRect(rtHoriScr); - m_pHorzScrollBar->Update(); - } - m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - } else if (m_pHorzScrollBar) { - m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - if (bShowVertScrollbar || bShowHorzScrollbar) - UpdateScroll(); -} - -void CFWL_Edit::DeviceToEngine(CFX_PointF& pt) { - pt.x += m_fScrollOffsetX - m_rtEngine.left; - pt.y += m_fScrollOffsetY - m_rtEngine.top - m_fVAlignOffset; -} - -void CFWL_Edit::InitVerticalScrollBar() { - if (m_pVertScrollBar) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert; - prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; - prop->m_pParent = this; - prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - m_pVertScrollBar = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); -} - -void CFWL_Edit::InitHorizontalScrollBar() { - if (m_pHorzScrollBar) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz; - prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; - prop->m_pParent = this; - prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - m_pHorzScrollBar = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); -} - -void CFWL_Edit::ShowCaret(CFX_RectF* pRect) { - if (m_pCaret) { - m_pCaret->ShowCaret(); - if (!pRect->IsEmpty()) - m_pCaret->SetWidgetRect(*pRect); - Repaint(&m_rtEngine); - return; - } - - CFWL_Widget* pOuter = this; - pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); - while (pOuter->GetOuter()) { - pOuter = pOuter->GetOuter(); - - CFX_RectF rtOuter = pOuter->GetWidgetRect(); - pRect->Offset(rtOuter.left, rtOuter.top); - } - - CXFA_FFWidget* pXFAWidget = - static_cast(pOuter->GetLayoutItem()); - if (!pXFAWidget) - return; - - IXFA_DocEnvironment* pDocEnvironment = - pXFAWidget->GetDoc()->GetDocEnvironment(); - if (!pDocEnvironment) - return; - - CFX_Matrix mt; - pXFAWidget->GetRotateMatrix(mt); - - CFX_RectF rt(*pRect); - mt.TransformRect(rt); - pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt); -} - -void CFWL_Edit::HideCaret(CFX_RectF* pRect) { - if (m_pCaret) { - m_pCaret->HideCaret(); - Repaint(&m_rtEngine); - return; - } - - CFWL_Widget* pOuter = this; - while (pOuter->GetOuter()) - pOuter = pOuter->GetOuter(); - - CXFA_FFWidget* pXFAWidget = - static_cast(pOuter->GetLayoutItem()); - if (!pXFAWidget) - return; - - IXFA_DocEnvironment* pDocEnvironment = - pXFAWidget->GetDoc()->GetDocEnvironment(); - if (!pDocEnvironment) - return; - - pDocEnvironment->DisplayCaret(pXFAWidget, false, pRect); -} - -bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { - if (!m_bSetRange) - return true; - - CFX_WideString wsText = m_EdtEngine.GetText(0, -1); - if (wsText.IsEmpty()) { - if (cNum == L'0') - return false; - return true; - } - - int32_t caretPos = m_EdtEngine.GetCaretPos(); - if (CountSelRanges() == 0) { - if (cNum == L'0' && caretPos == 0) - return false; - - int32_t nLen = wsText.GetLength(); - CFX_WideString l = wsText.Mid(0, caretPos); - CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos); - CFX_WideString wsNew = l + cNum + r; - if (wsNew.GetInteger() <= m_iMax) - return true; - return false; - } - - if (wsText.GetInteger() <= m_iMax) - return true; - return false; -} - -void CFWL_Edit::InitCaret() { - if (!m_pCaret) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { - m_pCaret = pdfium::MakeUnique( - m_pOwnerApp, pdfium::MakeUnique(), this); - m_pCaret->SetParent(this); - m_pCaret->SetStates(m_pProperties->m_dwStates); - } - } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) == - 0) { - m_pCaret.reset(); - } -} - -void CFWL_Edit::ClearRecord() { - m_iCurRecord = -1; - m_DoRecords.clear(); -} - -void CFWL_Edit::ProcessInsertError(int32_t iError) { - if (iError != -2) - return; - - CFWL_Event textFullEvent(CFWL_Event::Type::TextFull, this); - DispatchEvent(&textFullEvent); -} - -void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::LeftButtonDblClk: - OnButtonDblClk(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::RightButtonDown: - DoButtonDown(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: { - CFWL_MsgKey* pKey = static_cast(pMessage); - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) - OnKeyDown(pKey); - else if (pKey->m_dwCmd == FWL_KeyCommand::Char) - OnChar(pKey); - break; - } - default: - break; - } - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { - if (!pEvent) - return; - if (pEvent->GetType() != CFWL_Event::Type::Scroll) - return; - - CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; - if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || - (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { - CFWL_EvtScroll* pScrollEvent = static_cast(pEvent); - OnScroll(static_cast(pSrcTarget), - pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); - } -} - -void CFWL_Edit::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_Edit::DoButtonDown(CFWL_MsgMouse* pMsg) { - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - SetFocus(true); - - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return; - - CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); - DeviceToEngine(pt); - bool bBefore = true; - int32_t nIndex = pPage->GetCharIndex(pt, bBefore); - if (nIndex < 0) - nIndex = 0; - - m_EdtEngine.SetCaretPos(nIndex, bBefore); -} - -void CFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - uint32_t dwStyleEx = GetStylesEx(); - bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret); - if (bSet) { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - - UpdateVAlignment(); - UpdateOffset(); - UpdateCaret(); - } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - HideCaret(nullptr); - if ((dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) { - int32_t nSel = CountSelRanges(); - if (nSel > 0) { - ClearSelections(); - bRepaint = true; - } - m_EdtEngine.SetCaretPos(0, true); - UpdateOffset(); - } - ClearRecord(); - } - - LayoutScrollBar(); - if (!bRepaint) - return; - - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - Repaint(&rtInvalidate); -} - -void CFWL_Edit::OnLButtonDown(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - return; - - m_bLButtonDown = true; - SetGrab(true); - DoButtonDown(pMsg); - int32_t nIndex = m_EdtEngine.GetCaretPos(); - bool bRepaint = false; - if (m_EdtEngine.CountSelRanges() > 0) { - m_EdtEngine.ClearSelection(); - bRepaint = true; - } - - if ((pMsg->m_dwFlags & FWL_KEYFLAG_Shift) && m_nSelStart != nIndex) { - int32_t iStart = std::min(m_nSelStart, nIndex); - int32_t iEnd = std::max(m_nSelStart, nIndex); - m_EdtEngine.AddSelRange(iStart, iEnd - iStart); - bRepaint = true; - } else { - m_nSelStart = nIndex; - } - if (bRepaint) - Repaint(&m_rtEngine); -} - -void CFWL_Edit::OnLButtonUp(CFWL_MsgMouse* pMsg) { - m_bLButtonDown = false; - SetGrab(false); -} - -void CFWL_Edit::OnButtonDblClk(CFWL_MsgMouse* pMsg) { - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return; - - CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); - DeviceToEngine(pt); - int32_t nCount = 0; - int32_t nIndex = pPage->SelectWord(pt, nCount); - if (nIndex < 0) - return; - - m_EdtEngine.AddSelRange(nIndex, nCount); - m_EdtEngine.SetCaretPos(nIndex + nCount - 1, false); - Repaint(&m_rtEngine); -} - -void CFWL_Edit::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_nSelStart == -1 || !m_bLButtonDown) - return; - - IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); - if (!pPage) - return; - - CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); - DeviceToEngine(pt); - bool bBefore = true; - int32_t nIndex = pPage->GetCharIndex(pt, bBefore); - m_EdtEngine.SetCaretPos(nIndex, bBefore); - nIndex = m_EdtEngine.GetCaretPos(); - m_EdtEngine.ClearSelection(); - - if (nIndex == m_nSelStart) - return; - - int32_t nLen = m_EdtEngine.GetTextLength(); - if (m_nSelStart >= nLen) - m_nSelStart = nLen; - - m_EdtEngine.AddSelRange(std::min(m_nSelStart, nIndex), - FXSYS_abs(nIndex - m_nSelStart)); -} - -void CFWL_Edit::OnKeyDown(CFWL_MsgKey* pMsg) { - FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone; - bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); - bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); - uint32_t dwKeyCode = pMsg->m_dwKeyCode; - switch (dwKeyCode) { - case FWL_VKEY_Left: { - MoveCaret = MC_Left; - break; - } - case FWL_VKEY_Right: { - MoveCaret = MC_Right; - break; - } - case FWL_VKEY_Up: { - MoveCaret = MC_Up; - break; - } - case FWL_VKEY_Down: { - MoveCaret = MC_Down; - break; - } - case FWL_VKEY_Home: { - MoveCaret = bCtrl ? MC_Home : MC_LineStart; - break; - } - case FWL_VKEY_End: { - MoveCaret = bCtrl ? MC_End : MC_LineEnd; - break; - } - case FWL_VKEY_Insert: - break; - case FWL_VKEY_Delete: { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { - break; - } - int32_t nCaret = m_EdtEngine.GetCaretPos(); -#if (_FX_OS_ == _FX_MACOSX_) - m_EdtEngine.Delete(nCaret, true); -#else - m_EdtEngine.Delete(nCaret); -#endif - break; - } - case FWL_VKEY_F2: - case FWL_VKEY_Tab: - default: - break; - } - if (MoveCaret != MC_MoveNone) - m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl); -} - -void CFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { - return; - } - - int32_t iError = 0; - FX_WCHAR c = static_cast(pMsg->m_dwKeyCode); - int32_t nCaret = m_EdtEngine.GetCaretPos(); - switch (c) { - case FWL_VKEY_Back: - m_EdtEngine.Delete(nCaret, true); - break; - case FWL_VKEY_NewLine: - case FWL_VKEY_Escape: - break; - case FWL_VKEY_Tab: { - iError = m_EdtEngine.Insert(nCaret, L"\t", 1); - break; - } - case FWL_VKEY_Return: { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) { - iError = m_EdtEngine.Insert(nCaret, L"\n", 1); - } - break; - } - default: { - if (!m_pWidgetMgr->IsFormDisabled()) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Number) { - if (((pMsg->m_dwKeyCode < FWL_VKEY_0) && - (pMsg->m_dwKeyCode != 0x2E && pMsg->m_dwKeyCode != 0x2D)) || - pMsg->m_dwKeyCode > FWL_VKEY_9) { - break; - } - if (!ValidateNumberChar(c)) - break; - } - } -#if (_FX_OS_ == _FX_MACOSX_) - if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) -#else - if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) -#endif - { - break; - } - iError = m_EdtEngine.Insert(nCaret, &c, 1); - break; - } - } - if (iError < 0) - ProcessInsertError(iError); -} - -bool CFWL_Edit::OnScroll(CFWL_ScrollBar* pScrollBar, - CFWL_EvtScroll::Code dwCode, - FX_FLOAT fPos) { - CFX_SizeF fs; - pScrollBar->GetRange(&fs.x, &fs.y); - FX_FLOAT iCurPos = pScrollBar->GetPos(); - FX_FLOAT fStep = pScrollBar->GetStepSize(); - switch (dwCode) { - case CFWL_EvtScroll::Code::Min: { - fPos = fs.x; - break; - } - case CFWL_EvtScroll::Code::Max: { - fPos = fs.y; - break; - } - case CFWL_EvtScroll::Code::StepBackward: { - fPos -= fStep; - if (fPos < fs.x + fStep / 2) { - fPos = fs.x; - } - break; - } - case CFWL_EvtScroll::Code::StepForward: { - fPos += fStep; - if (fPos > fs.y - fStep / 2) { - fPos = fs.y; - } - break; - } - case CFWL_EvtScroll::Code::PageBackward: { - fPos -= pScrollBar->GetPageSize(); - if (fPos < fs.x) { - fPos = fs.x; - } - break; - } - case CFWL_EvtScroll::Code::PageForward: { - fPos += pScrollBar->GetPageSize(); - if (fPos > fs.y) { - fPos = fs.y; - } - break; - } - case CFWL_EvtScroll::Code::Pos: - case CFWL_EvtScroll::Code::TrackPos: - case CFWL_EvtScroll::Code::None: - break; - case CFWL_EvtScroll::Code::EndScroll: - return false; - } - if (iCurPos == fPos) - return true; - - pScrollBar->SetPos(fPos); - pScrollBar->SetTrackPos(fPos); - UpdateOffset(pScrollBar, fPos - iCurPos); - UpdateCaret(); - - CFX_RectF rect = GetWidgetRect(); - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); - Repaint(&rtInvalidate); - return true; -} diff --git a/xfa/fwl/core/cfwl_edit.h b/xfa/fwl/core/cfwl_edit.h deleted file mode 100644 index d31f148cd0..0000000000 --- a/xfa/fwl/core/cfwl_edit.h +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EDIT_H_ -#define XFA_FWL_CORE_CFWL_EDIT_H_ - -#include -#include -#include - -#include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fde/ifde_txtedtdorecord.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_scrollbar.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_path.h" - -#define FWL_STYLEEXT_EDT_ReadOnly (1L << 0) -#define FWL_STYLEEXT_EDT_MultiLine (1L << 1) -#define FWL_STYLEEXT_EDT_WantReturn (1L << 2) -#define FWL_STYLEEXT_EDT_NoHideSel (1L << 3) -#define FWL_STYLEEXT_EDT_AutoHScroll (1L << 4) -#define FWL_STYLEEXT_EDT_AutoVScroll (1L << 5) -#define FWL_STYLEEXT_EDT_NoRedoUndo (1L << 6) -#define FWL_STYLEEXT_EDT_Validate (1L << 7) -#define FWL_STYLEEXT_EDT_Password (1L << 8) -#define FWL_STYLEEXT_EDT_Number (1L << 9) -#define FWL_STYLEEXT_EDT_VerticalLayout (1L << 12) -#define FWL_STYLEEXT_EDT_VerticalChars (1L << 13) -#define FWL_STYLEEXT_EDT_ReverseLine (1L << 14) -#define FWL_STYLEEXT_EDT_ArabicShapes (1L << 15) -#define FWL_STYLEEXT_EDT_ExpandTab (1L << 16) -#define FWL_STYLEEXT_EDT_CombText (1L << 17) -#define FWL_STYLEEXT_EDT_HNear (0L << 18) -#define FWL_STYLEEXT_EDT_HCenter (1L << 18) -#define FWL_STYLEEXT_EDT_HFar (2L << 18) -#define FWL_STYLEEXT_EDT_VNear (0L << 20) -#define FWL_STYLEEXT_EDT_VCenter (1L << 20) -#define FWL_STYLEEXT_EDT_VFar (2L << 20) -#define FWL_STYLEEXT_EDT_Justified (1L << 22) -#define FWL_STYLEEXT_EDT_Distributed (2L << 22) -#define FWL_STYLEEXT_EDT_HAlignMask (3L << 18) -#define FWL_STYLEEXT_EDT_VAlignMask (3L << 20) -#define FWL_STYLEEXT_EDT_HAlignModeMask (3L << 22) -#define FWL_STYLEEXT_EDT_InnerCaret (1L << 24) -#define FWL_STYLEEXT_EDT_ShowScrollbarFocus (1L << 25) -#define FWL_STYLEEXT_EDT_OuterScrollbar (1L << 26) -#define FWL_STYLEEXT_EDT_LastLineHeight (1L << 27) - -class IFDE_TxtEdtDoRecord; -class CFWL_Edit; -class CFWL_MsgMouse; -class CFWL_WidgetProperties; -class CFWL_Caret; - -class CFWL_Edit : public CFWL_Widget { - public: - CFWL_Edit(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_Edit() override; - - // CFWL_Widget: - FWL_Type GetClassID() const override; - CFX_RectF GetAutosizedWidgetRect() override; - CFX_RectF GetWidgetRect() override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void SetStates(uint32_t dwStates) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - virtual void SetText(const CFX_WideString& wsText); - - int32_t GetTextLength() const; - CFX_WideString GetText() const; - void ClearText(); - - void AddSelRange(int32_t nStart); - int32_t CountSelRanges() const; - int32_t GetSelRange(int32_t nIndex, int32_t* nStart) const; - void ClearSelections(); - int32_t GetLimit() const; - void SetLimit(int32_t nLimit); - void SetAliasChar(FX_WCHAR wAlias); - bool Copy(CFX_WideString& wsCopy); - bool Cut(CFX_WideString& wsCut); - bool Paste(const CFX_WideString& wsPaste); - bool Redo(const IFDE_TxtEdtDoRecord* pRecord); - bool Undo(const IFDE_TxtEdtDoRecord* pRecord); - bool Undo(); - bool Redo(); - bool CanUndo(); - bool CanRedo(); - - void SetOuter(CFWL_Widget* pOuter); - - void OnCaretChanged(); - void OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo); - void OnSelChanged(); - bool OnPageLoad(int32_t nPageIndex); - bool OnPageUnload(int32_t nPageIndex); - void OnAddDoRecord(std::unique_ptr pRecord); - bool OnValidate(const CFX_WideString& wsText); - void SetScrollOffset(FX_FLOAT fScrollOffset); - - protected: - void ShowCaret(CFX_RectF* pRect); - void HideCaret(CFX_RectF* pRect); - const CFX_RectF& GetRTClient() const { return m_rtClient; } - CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } - - private: - void DrawTextBk(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawContent(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawSpellCheck(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); - - void UpdateEditEngine(); - void UpdateEditParams(); - void UpdateEditLayout(); - bool UpdateOffset(); - bool UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); - void UpdateVAlignment(); - void UpdateCaret(); - CFWL_ScrollBar* UpdateScroll(); - void Layout(); - void LayoutScrollBar(); - void DeviceToEngine(CFX_PointF& pt); - void InitVerticalScrollBar(); - void InitHorizontalScrollBar(); - void InitEngine(); - void InitCaret(); - bool ValidateNumberChar(FX_WCHAR cNum); - void ClearRecord(); - bool IsShowScrollBar(bool bVert); - bool IsContentHeightOverflow(); - int32_t AddDoRecord(std::unique_ptr pRecord); - void ProcessInsertError(int32_t iError); - void AddSpellCheckObj(CFX_Path& PathData, - int32_t nStart, - int32_t nCount, - FX_FLOAT fOffSetX, - FX_FLOAT fOffSetY); - - void DoButtonDown(CFWL_MsgMouse* pMsg); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnButtonDblClk(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnKeyDown(CFWL_MsgKey* pMsg); - void OnChar(CFWL_MsgKey* pMsg); - bool OnScroll(CFWL_ScrollBar* pScrollBar, - CFWL_EvtScroll::Code dwCode, - FX_FLOAT fPos); - - CFX_RectF m_rtClient; - CFX_RectF m_rtEngine; - CFX_RectF m_rtStatic; - FX_FLOAT m_fVAlignOffset; - FX_FLOAT m_fScrollOffsetX; - FX_FLOAT m_fScrollOffsetY; - CFDE_TxtEdtEngine m_EdtEngine; - bool m_bLButtonDown; - int32_t m_nSelStart; - int32_t m_nLimit; - FX_FLOAT m_fFontSize; - bool m_bSetRange; - int32_t m_iMax; - std::unique_ptr m_pVertScrollBar; - std::unique_ptr m_pHorzScrollBar; - std::unique_ptr m_pCaret; - CFX_WideString m_wsCache; - CFX_WideString m_wsFont; - std::deque> m_DoRecords; - int32_t m_iCurRecord; - int32_t m_iMaxRecord; -}; - -#endif // XFA_FWL_CORE_CFWL_EDIT_H_ diff --git a/xfa/fwl/core/cfwl_event.cpp b/xfa/fwl/core/cfwl_event.cpp deleted file mode 100644 index d598f6974a..0000000000 --- a/xfa/fwl/core/cfwl_event.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_event.h" - -CFWL_Event::CFWL_Event(CFWL_Event::Type type) - : CFWL_Event(type, nullptr, nullptr) {} - -CFWL_Event::CFWL_Event(Type type, CFWL_Widget* pSrcTarget) - : CFWL_Event(type, pSrcTarget, nullptr) {} - -CFWL_Event::CFWL_Event(Type type, - CFWL_Widget* pSrcTarget, - CFWL_Widget* pDstTarget) - : m_pSrcTarget(pSrcTarget), m_pDstTarget(pDstTarget), m_type(type) {} - -CFWL_Event::~CFWL_Event() {} diff --git a/xfa/fwl/core/cfwl_event.h b/xfa/fwl/core/cfwl_event.h deleted file mode 100644 index aa435e54b2..0000000000 --- a/xfa/fwl/core/cfwl_event.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVENT_H_ -#define XFA_FWL_CORE_CFWL_EVENT_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/fwl_error.h" - -class CFX_Graphics; -class CFWL_Widget; - -class CFWL_Event { - public: - enum class Type { - CheckStateChanged, - CheckWord, - Click, - Close, - EditChanged, - Mouse, - PostDropDown, - PreDropDown, - Scroll, - SelectChanged, - TextChanged, - TextFull, - Validate - }; - - explicit CFWL_Event(Type type); - CFWL_Event(Type type, CFWL_Widget* pSrcTarget); - CFWL_Event(Type type, CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - virtual ~CFWL_Event(); - - Type GetType() const { return m_type; } - - CFWL_Widget* m_pSrcTarget; - CFWL_Widget* m_pDstTarget; - - private: - Type m_type; -}; - -#endif // XFA_FWL_CORE_CFWL_EVENT_H_ diff --git a/xfa/fwl/core/cfwl_eventtarget.cpp b/xfa/fwl/core/cfwl_eventtarget.cpp deleted file mode 100644 index 34377c2d73..0000000000 --- a/xfa/fwl/core/cfwl_eventtarget.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_eventtarget.h" - -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_widgetdelegate.h" - -CFWL_EventTarget::CFWL_EventTarget(CFWL_Widget* pListener) - : m_pListener(pListener), m_bInvalid(false) {} - -CFWL_EventTarget::~CFWL_EventTarget() {} - -void CFWL_EventTarget::SetEventSource(CFWL_Widget* pSource) { - if (pSource) - m_widgets.insert(pSource); -} - -bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { - IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); - if (!pDelegate) - return false; - if (!m_widgets.empty() && m_widgets.count(pEvent->m_pSrcTarget) == 0) - return false; - - pDelegate->OnProcessEvent(pEvent); - return true; -} diff --git a/xfa/fwl/core/cfwl_eventtarget.h b/xfa/fwl/core/cfwl_eventtarget.h deleted file mode 100644 index 5f0ee35b9b..0000000000 --- a/xfa/fwl/core/cfwl_eventtarget.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVENTTARGET_H_ -#define XFA_FWL_CORE_CFWL_EVENTTARGET_H_ - -#include - -#include "core/fxcrt/fx_basic.h" -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_Event; -class CFWL_Widget; - -class CFWL_EventTarget { - public: - explicit CFWL_EventTarget(CFWL_Widget* pListener); - ~CFWL_EventTarget(); - - void SetEventSource(CFWL_Widget* pSource); - bool ProcessEvent(CFWL_Event* pEvent); - - bool IsInvalid() const { return m_bInvalid; } - void FlagInvalid() { m_bInvalid = true; } - - private: - std::set m_widgets; - CFWL_Widget* m_pListener; - bool m_bInvalid; -}; - -#endif // XFA_FWL_CORE_CFWL_EVENTTARGET_H_ diff --git a/xfa/fwl/core/cfwl_evtcheckword.cpp b/xfa/fwl/core/cfwl_evtcheckword.cpp deleted file mode 100644 index 88bdcf6760..0000000000 --- a/xfa/fwl/core/cfwl_evtcheckword.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_evtcheckword.h" - -CFWL_EvtCheckWord::CFWL_EvtCheckWord(CFWL_Widget* pSrcTarget) - : CFWL_Event(CFWL_Event::Type::CheckWord, pSrcTarget) {} - -CFWL_EvtCheckWord::~CFWL_EvtCheckWord() {} - diff --git a/xfa/fwl/core/cfwl_evtcheckword.h b/xfa/fwl/core/cfwl_evtcheckword.h deleted file mode 100644 index aa853c6a8f..0000000000 --- a/xfa/fwl/core/cfwl_evtcheckword.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVTCHECKWORD_H_ -#define XFA_FWL_CORE_CFWL_EVTCHECKWORD_H_ - -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_EvtCheckWord : public CFWL_Event { - public: - explicit CFWL_EvtCheckWord(CFWL_Widget* pSrcTarget); - ~CFWL_EvtCheckWord() override; - - CFX_ByteString bsWord; - bool bCheckWord; -}; - -#endif // XFA_FWL_CORE_CFWL_EVTCHECKWORD_H_ diff --git a/xfa/fwl/core/cfwl_evtmouse.cpp b/xfa/fwl/core/cfwl_evtmouse.cpp deleted file mode 100644 index 8bfce8a9c5..0000000000 --- a/xfa/fwl/core/cfwl_evtmouse.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_evtmouse.h" - -CFWL_EvtMouse::CFWL_EvtMouse(CFWL_Widget* pSrcTarget) - : CFWL_EvtMouse(pSrcTarget, nullptr) {} - -CFWL_EvtMouse::CFWL_EvtMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget) - : CFWL_Event(CFWL_Event::Type::Mouse, pSrcTarget, pDstTarget) {} - -CFWL_EvtMouse::~CFWL_EvtMouse() {} diff --git a/xfa/fwl/core/cfwl_evtmouse.h b/xfa/fwl/core/cfwl_evtmouse.h deleted file mode 100644 index e8b1fd541b..0000000000 --- a/xfa/fwl/core/cfwl_evtmouse.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVTMOUSE_H_ -#define XFA_FWL_CORE_CFWL_EVTMOUSE_H_ - -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_EvtMouse : public CFWL_Event { - public: - explicit CFWL_EvtMouse(CFWL_Widget* pSrcTarget); - CFWL_EvtMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - ~CFWL_EvtMouse() override; - - FWL_MouseCommand m_dwCmd; -}; - -#endif // XFA_FWL_CORE_CFWL_EVTMOUSE_H_ diff --git a/xfa/fwl/core/cfwl_evtscroll.cpp b/xfa/fwl/core/cfwl_evtscroll.cpp deleted file mode 100644 index 00ca57eb84..0000000000 --- a/xfa/fwl/core/cfwl_evtscroll.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_evtscroll.h" - -CFWL_EvtScroll::CFWL_EvtScroll(CFWL_Widget* pSrcTarget) - : CFWL_Event(CFWL_Event::Type::Scroll, pSrcTarget) {} - -CFWL_EvtScroll::~CFWL_EvtScroll() {} diff --git a/xfa/fwl/core/cfwl_evtscroll.h b/xfa/fwl/core/cfwl_evtscroll.h deleted file mode 100644 index 64ee7815f6..0000000000 --- a/xfa/fwl/core/cfwl_evtscroll.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVTSCROLL_H_ -#define XFA_FWL_CORE_CFWL_EVTSCROLL_H_ - -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_EvtScroll : public CFWL_Event { - public: - enum class Code { - None = 1, - Min, - Max, - PageBackward, - PageForward, - StepBackward, - StepForward, - Pos, - TrackPos, - EndScroll, - }; - - explicit CFWL_EvtScroll(CFWL_Widget* pSrcTarget); - ~CFWL_EvtScroll() override; - - Code m_iScrollCode; - FX_FLOAT m_fPos; -}; - -#endif // XFA_FWL_CORE_CFWL_EVTSCROLL_H_ diff --git a/xfa/fwl/core/cfwl_evtselectchanged.cpp b/xfa/fwl/core/cfwl_evtselectchanged.cpp deleted file mode 100644 index 811fc9490f..0000000000 --- a/xfa/fwl/core/cfwl_evtselectchanged.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_evtselectchanged.h" - -CFWL_EvtSelectChanged::CFWL_EvtSelectChanged(CFWL_Widget* pSrcTarget) - : CFWL_Event(CFWL_Event::Type::SelectChanged, pSrcTarget) {} - -CFWL_EvtSelectChanged::~CFWL_EvtSelectChanged() {} diff --git a/xfa/fwl/core/cfwl_evtselectchanged.h b/xfa/fwl/core/cfwl_evtselectchanged.h deleted file mode 100644 index 94381c7063..0000000000 --- a/xfa/fwl/core/cfwl_evtselectchanged.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVTSELECTCHANGED_H_ -#define XFA_FWL_CORE_CFWL_EVTSELECTCHANGED_H_ - -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_EvtSelectChanged : public CFWL_Event { - public: - explicit CFWL_EvtSelectChanged(CFWL_Widget* pSrcTarget); - ~CFWL_EvtSelectChanged() override; - - // Used by ComboBox. - bool bLButtonUp; - - // Used by DateTimePIcker - int32_t iYear; - int32_t iMonth; - int32_t iDay; -}; - -#endif // XFA_FWL_CORE_CFWL_EVTSELECTCHANGED_H_ diff --git a/xfa/fwl/core/cfwl_evttextchanged.cpp b/xfa/fwl/core/cfwl_evttextchanged.cpp deleted file mode 100644 index d21dd037c1..0000000000 --- a/xfa/fwl/core/cfwl_evttextchanged.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_evttextchanged.h" - -CFWL_EvtTextChanged::CFWL_EvtTextChanged(CFWL_Widget* pSrcTarget) - : CFWL_Event(CFWL_Event::Type::TextChanged, pSrcTarget) {} - -CFWL_EvtTextChanged::~CFWL_EvtTextChanged() {} diff --git a/xfa/fwl/core/cfwl_evttextchanged.h b/xfa/fwl/core/cfwl_evttextchanged.h deleted file mode 100644 index a2d0761f80..0000000000 --- a/xfa/fwl/core/cfwl_evttextchanged.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVTTEXTCHANGED_H_ -#define XFA_FWL_CORE_CFWL_EVTTEXTCHANGED_H_ - -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_EvtTextChanged : public CFWL_Event { - public: - explicit CFWL_EvtTextChanged(CFWL_Widget* pSrcTarget); - ~CFWL_EvtTextChanged() override; - - CFX_WideString wsPrevText; -}; - -#endif // XFA_FWL_CORE_CFWL_EVTTEXTCHANGED_H_ diff --git a/xfa/fwl/core/cfwl_evtvalidate.cpp b/xfa/fwl/core/cfwl_evtvalidate.cpp deleted file mode 100644 index 1f2b6977fa..0000000000 --- a/xfa/fwl/core/cfwl_evtvalidate.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_evtvalidate.h" - -CFWL_EvtValidate::CFWL_EvtValidate(CFWL_Widget* pSrcTarget) - : CFWL_Event(CFWL_Event::Type::Validate, pSrcTarget) {} - -CFWL_EvtValidate::~CFWL_EvtValidate() {} diff --git a/xfa/fwl/core/cfwl_evtvalidate.h b/xfa/fwl/core/cfwl_evtvalidate.h deleted file mode 100644 index dbd5413aa4..0000000000 --- a/xfa/fwl/core/cfwl_evtvalidate.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_EVTVALIDATE_H_ -#define XFA_FWL_CORE_CFWL_EVTVALIDATE_H_ - -#include "xfa/fwl/core/cfwl_event.h" - -class CFWL_EvtValidate : public CFWL_Event { - public: - explicit CFWL_EvtValidate(CFWL_Widget* pSrcTarget); - ~CFWL_EvtValidate() override; - - CFX_WideString wsInsert; - bool bValidate; -}; - -#endif // XFA_FWL_CORE_CFWL_EVTVALIDATE_H_ diff --git a/xfa/fwl/core/cfwl_form.cpp b/xfa/fwl/core/cfwl_form.cpp deleted file mode 100644 index 5b494fe1e2..0000000000 --- a/xfa/fwl/core/cfwl_form.cpp +++ /dev/null @@ -1,624 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_form.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_formproxy.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_noteloop.h" -#include "xfa/fwl/core/cfwl_sysbtn.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" -#include "xfa/fwl/theme/cfwl_widgettp.h" - -namespace { - -const int kSystemButtonSize = 21; -const int kSystemButtonMargin = 5; -const int kSystemButtonSpan = 2; - -} // namespace - -namespace { - -const uint8_t kCornerEnlarge = 10; - -} // namespace - -CFWL_Form::CFWL_Form(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Widget(app, std::move(properties), pOuter), -#if (_FX_OS_ == _FX_MACOSX_) - m_bMouseIn(false), -#endif - m_pCloseBox(nullptr), - m_pMinBox(nullptr), - m_pMaxBox(nullptr), - m_pSubFocus(nullptr), - m_fCXBorder(0), - m_fCYBorder(0), - m_iCaptureBtn(-1), - m_iSysBox(0), - m_bLButtonDown(false), - m_bMaximized(false), - m_bSetMaximize(false), - m_bDoModalFlag(false) { - m_rtRelative.Reset(); - m_rtRestore.Reset(); - - RegisterForm(); - RegisterEventTarget(nullptr); -} - -CFWL_Form::~CFWL_Form() { - UnregisterEventTarget(); - UnRegisterForm(); - RemoveSysButtons(); -} - -FWL_Type CFWL_Form::GetClassID() const { - return FWL_Type::Form; -} - -bool CFWL_Form::IsInstance(const CFX_WideStringC& wsClass) const { - if (wsClass == CFX_WideStringC(FWL_CLASS_Form)) - return true; - return CFWL_Widget::IsInstance(wsClass); -} - -void CFWL_Form::GetClientRect(CFX_RectF& rect) { - rect = m_pProperties->m_rtWidget; - rect.Offset(-rect.left, -rect.top); -} - -void CFWL_Form::Update() { - if (m_iLock > 0) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); -} - -FWL_WidgetHit CFWL_Form::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - GetAvailableTheme(); - - if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::CloseBox; - if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::MaxBox; - if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::MinBox; - - CFX_RectF rtCap; - rtCap.Set(m_fCYBorder, m_fCXBorder, - 0 - kSystemButtonSize * m_iSysBox - 2 * m_fCYBorder, - 0 - m_fCXBorder); - if (rtCap.Contains(fx, fy)) - return FWL_WidgetHit::Titlebar; - if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize)) { - FX_FLOAT fWidth = m_rtRelative.width - 2 * (m_fCYBorder + kCornerEnlarge); - FX_FLOAT fHeight = m_rtRelative.height - 2 * (m_fCXBorder + kCornerEnlarge); - - CFX_RectF rt; - rt.Set(0, m_fCXBorder + kCornerEnlarge, m_fCYBorder, fHeight); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Left; - - rt.Set(m_rtRelative.width - m_fCYBorder, m_fCXBorder + kCornerEnlarge, - m_fCYBorder, fHeight); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Right; - - rt.Set(m_fCYBorder + kCornerEnlarge, 0, fWidth, m_fCXBorder); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Top; - - rt.Set(m_fCYBorder + kCornerEnlarge, m_rtRelative.height - m_fCXBorder, - fWidth, m_fCXBorder); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Bottom; - - rt.Set(0, 0, m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::LeftTop; - - rt.Set(0, m_rtRelative.height - m_fCXBorder - kCornerEnlarge, - m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::LeftBottom; - - rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, 0, - m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::RightTop; - - rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, - m_rtRelative.height - m_fCXBorder - kCornerEnlarge, - m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::RightBottom; - } - return FWL_WidgetHit::Client; -} - -void CFWL_Form::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - bool bInactive = !IsActive(); - int32_t iState = bInactive ? CFWL_PartState_Inactive : CFWL_PartState_Normal; - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_NoDrawClient) == 0) - DrawBackground(pGraphics, pTheme); - -#ifdef FWL_UseMacSystemBorder - return; -#endif - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_dwStates = iState; - param.m_pGraphics = pGraphics; - param.m_rtPart = m_rtRelative; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { - param.m_iPart = CFWL_Part::Border; - pTheme->DrawBackground(¶m); - } - if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != - FWL_WGTSTYLE_EdgeNone) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); - param.m_iPart = CFWL_Part::Edge; - param.m_rtPart = rtEdge; - param.m_dwStates = iState; - pTheme->DrawBackground(¶m); - } - -#if (_FX_OS_ == _FX_MACOSX_) - { - if (m_pCloseBox) { - param.m_iPart = CFWL_Part::CloseBox; - param.m_dwStates = m_pCloseBox->GetPartState(); - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) - param.m_dwStates = CFWL_PartState_Disabled; - else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) - param.m_dwStates = CFWL_PartState_Hovered; - param.m_rtPart = m_pCloseBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - if (m_pMaxBox) { - param.m_iPart = CFWL_Part::MaximizeBox; - param.m_dwStates = m_pMaxBox->GetPartState(); - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) - param.m_dwStates = CFWL_PartState_Disabled; - else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) - param.m_dwStates = CFWL_PartState_Hovered; - param.m_rtPart = m_pMaxBox->m_rtBtn; - param.m_bMaximize = m_bMaximized; - pTheme->DrawBackground(¶m); - } - if (m_pMinBox) { - param.m_iPart = CFWL_Part::MinimizeBox; - param.m_dwStates = m_pMinBox->GetPartState(); - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) - param.m_dwStates = CFWL_PartState_Disabled; - else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) - param.m_dwStates = CFWL_PartState_Hovered; - param.m_rtPart = m_pMinBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - m_bMouseIn = false; - } -#else - { - if (m_pCloseBox) { - param.m_iPart = CFWL_Part::CloseBox; - param.m_dwStates = m_pCloseBox->GetPartState(); - param.m_rtPart = m_pCloseBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - if (m_pMaxBox) { - param.m_iPart = CFWL_Part::MaximizeBox; - param.m_dwStates = m_pMaxBox->GetPartState(); - param.m_rtPart = m_pMaxBox->m_rtBtn; - param.m_bMaximize = m_bMaximized; - pTheme->DrawBackground(¶m); - } - if (m_pMinBox) { - param.m_iPart = CFWL_Part::MinimizeBox; - param.m_dwStates = m_pMinBox->GetPartState(); - param.m_rtPart = m_pMinBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - } -#endif -} - -CFWL_Widget* CFWL_Form::DoModal() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return nullptr; - - CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); - if (!pDriver) - return nullptr; - - m_pNoteLoop = pdfium::MakeUnique(); - m_pNoteLoop->SetMainForm(this); - - pDriver->PushNoteLoop(m_pNoteLoop.get()); - m_bDoModalFlag = true; - RemoveStates(FWL_WGTSTATE_Invisible); - pDriver->Run(); - -#if _FX_OS_ != _FX_MACOSX_ - pDriver->PopNoteLoop(); -#endif - - m_pNoteLoop.reset(); - return nullptr; -} - -void CFWL_Form::EndDoModal() { - if (!m_pNoteLoop) - return; - - m_bDoModalFlag = false; - -#if (_FX_OS_ == _FX_MACOSX_) - m_pNoteLoop->EndModalLoop(); - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->PopNoteLoop(); - SetStates(FWL_WGTSTATE_Invisible); -#else - SetStates(FWL_WGTSTATE_Invisible); - m_pNoteLoop->EndModalLoop(); -#endif -} - -void CFWL_Form::DrawBackground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_pGraphics = pGraphics; - param.m_rtPart = m_rtRelative; - param.m_rtPart.Deflate(m_fCYBorder, m_fCXBorder, m_fCYBorder, m_fCXBorder); - pTheme->DrawBackground(¶m); -} - -void CFWL_Form::RemoveSysButtons() { - delete m_pCloseBox; - m_pCloseBox = nullptr; - delete m_pMinBox; - m_pMinBox = nullptr; - delete m_pMaxBox; - m_pMaxBox = nullptr; -} - -CFWL_SysBtn* CFWL_Form::GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy) { - if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) - return m_pCloseBox; - if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) - return m_pMaxBox; - if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) - return m_pMinBox; - return nullptr; -} - -CFWL_SysBtn* CFWL_Form::GetSysBtnByState(uint32_t dwState) { - if (m_pCloseBox && (m_pCloseBox->m_dwState & dwState)) - return m_pCloseBox; - if (m_pMaxBox && (m_pMaxBox->m_dwState & dwState)) - return m_pMaxBox; - if (m_pMinBox && (m_pMinBox->m_dwState & dwState)) - return m_pMinBox; - return nullptr; -} - -CFWL_SysBtn* CFWL_Form::GetSysBtnByIndex(int32_t nIndex) { - if (nIndex < 0) - return nullptr; - - CFX_ArrayTemplate arrBtn; - if (m_pMinBox) - arrBtn.Add(m_pMinBox); - if (m_pMaxBox) - arrBtn.Add(m_pMaxBox); - if (m_pCloseBox) - arrBtn.Add(m_pCloseBox); - return arrBtn[nIndex]; -} - -int32_t CFWL_Form::GetSysBtnIndex(CFWL_SysBtn* pBtn) { - CFX_ArrayTemplate arrBtn; - if (m_pMinBox) - arrBtn.Add(m_pMinBox); - if (m_pMaxBox) - arrBtn.Add(m_pMaxBox); - if (m_pCloseBox) - arrBtn.Add(m_pCloseBox); - return arrBtn.Find(pBtn); -} - -void CFWL_Form::GetEdgeRect(CFX_RectF& rtEdge) { - rtEdge = m_rtRelative; - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { - FX_FLOAT fCX = GetBorderSize(true); - FX_FLOAT fCY = GetBorderSize(false); - rtEdge.Deflate(fCX, fCY, fCX, fCY); - } -} - -void CFWL_Form::SetWorkAreaRect() { - m_rtRestore = m_pProperties->m_rtWidget; - CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr) - return; - - m_bSetMaximize = true; - Repaint(&m_rtRelative); -} - -void CFWL_Form::Layout() { - GetRelativeRect(m_rtRelative); - -#ifndef FWL_UseMacSystemBorder - ResetSysBtn(); -#endif -} - -void CFWL_Form::ResetSysBtn() { - m_fCXBorder = - *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CXBorder)); - m_fCYBorder = - *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CYBorder)); - RemoveSysButtons(); - - m_iSysBox = 0; - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_CloseBox) { - m_pCloseBox = new CFWL_SysBtn; - m_pCloseBox->m_rtBtn.Set( - m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, - kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); - m_iSysBox++; - } - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MaximizeBox) { - m_pMaxBox = new CFWL_SysBtn; - if (m_pCloseBox) { - m_pMaxBox->m_rtBtn.Set( - m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, - m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); - } else { - m_pMaxBox->m_rtBtn.Set( - m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, - kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); - } - m_iSysBox++; - } - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MinimizeBox) { - m_pMinBox = new CFWL_SysBtn; - if (m_pMaxBox) { - m_pMinBox->m_rtBtn.Set( - m_pMaxBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, - m_pMaxBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); - } else if (m_pCloseBox) { - m_pMinBox->m_rtBtn.Set( - m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, - m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); - } else { - m_pMinBox->m_rtBtn.Set( - m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, - kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); - } - m_iSysBox++; - } -} - -void CFWL_Form::RegisterForm() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->RegisterForm(this); -} - -void CFWL_Form::UnRegisterForm() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->UnRegisterForm(this); -} - -void CFWL_Form::OnProcessMessage(CFWL_Message* pMessage) { -#ifndef FWL_UseMacSystemBorder - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - case FWL_MouseCommand::LeftButtonDblClk: - OnLButtonDblClk(pMsg); - break; - default: - break; - } - break; - } - default: - break; - } -#endif // FWL_UseMacSystemBorder -} - -void CFWL_Form::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_Form::OnLButtonDown(CFWL_MsgMouse* pMsg) { - SetGrab(true); - m_bLButtonDown = true; - - CFWL_SysBtn* pPressBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); - m_iCaptureBtn = GetSysBtnIndex(pPressBtn); - - if (!pPressBtn) - return; - - pPressBtn->SetPressed(); - Repaint(&pPressBtn->m_rtBtn); -} - -void CFWL_Form::OnLButtonUp(CFWL_MsgMouse* pMsg) { - SetGrab(false); - m_bLButtonDown = false; - CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); - CFWL_SysBtn* pPressedBtn = GetSysBtnByIndex(m_iCaptureBtn); - if (!pPressedBtn || pPointBtn != pPressedBtn) - return; - if (pPressedBtn == GetSysBtnByState(FWL_SYSBUTTONSTATE_Pressed)) - pPressedBtn->SetNormal(); - if (pPressedBtn == m_pMaxBox) { - if (m_bMaximized) { - SetWidgetRect(m_rtRestore); - Update(); - Repaint(nullptr); - } else { - SetWorkAreaRect(); - Update(); - } - m_bMaximized = !m_bMaximized; - } else if (pPressedBtn != m_pMinBox) { - CFWL_Event eClose(CFWL_Event::Type::Close, this); - DispatchEvent(&eClose); - } -} - -void CFWL_Form::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_bLButtonDown) - return; - - CFX_RectF rtInvalidate; - rtInvalidate.Reset(); - CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); - CFWL_SysBtn* pOldHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); - -#if _FX_OS_ == _FX_MACOSX_ - { - if (pOldHover && pPointBtn != pOldHover) - pOldHover->SetNormal(); - if (pPointBtn && pPointBtn != pOldHover) - pPointBtn->SetHover(); - if (m_pCloseBox) - rtInvalidate = m_pCloseBox->m_rtBtn; - if (m_pMaxBox) { - if (rtInvalidate.IsEmpty()) - rtInvalidate = m_pMaxBox->m_rtBtn; - else - rtInvalidate.Union(m_pMaxBox->m_rtBtn); - } - if (m_pMinBox) { - if (rtInvalidate.IsEmpty()) - rtInvalidate = m_pMinBox->m_rtBtn; - else - rtInvalidate.Union(m_pMinBox->m_rtBtn); - } - if (!rtInvalidate.IsEmpty() && - rtInvalidate.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_bMouseIn = true; - } - } -#else - { - if (pOldHover && pPointBtn != pOldHover) { - pOldHover->SetNormal(); - rtInvalidate = pOldHover->m_rtBtn; - } - if (pPointBtn && pPointBtn != pOldHover) { - pPointBtn->SetHover(); - if (rtInvalidate.IsEmpty()) - rtInvalidate = pPointBtn->m_rtBtn; - else - rtInvalidate.Union(pPointBtn->m_rtBtn); - } - } -#endif - - if (!rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void CFWL_Form::OnMouseLeave(CFWL_MsgMouse* pMsg) { - CFWL_SysBtn* pHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); - if (!pHover) - return; - - pHover->SetNormal(); - Repaint(&pHover->m_rtBtn); -} - -void CFWL_Form::OnLButtonDblClk(CFWL_MsgMouse* pMsg) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && - HitTest(pMsg->m_fx, pMsg->m_fy) == FWL_WidgetHit::Titlebar) { - if (m_bMaximized) - SetWidgetRect(m_rtRestore); - else - SetWorkAreaRect(); - - Update(); - m_bMaximized = !m_bMaximized; - } -} diff --git a/xfa/fwl/core/cfwl_form.h b/xfa/fwl/core/cfwl_form.h deleted file mode 100644 index 847256a57c..0000000000 --- a/xfa/fwl/core/cfwl_form.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_FORM_H_ -#define XFA_FWL_CORE_CFWL_FORM_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_CLASS_Form L"FWL_FORM" -#define FWL_CLASS_FormProxy L"FWL_FORMPROXY" -#define FWL_STYLEEXT_FRM_Resize (1L << 0) -#define FWL_STYLEEXT_FRM_NativeBorder (1L << 1) -#define FWL_STYLEEXT_FRM_RoundCorner (2L << 1) -#define FWL_STYLEEXT_FRM_RoundCorner4 (3L << 1) -#define FWL_STYLEEXT_FRM_NoDrawClient (1L << 3) -#define FWL_STYLEEXT_FRM_BorderCornerMask (3L << 1) -#define FWL_STYLEEXT_FRM_Max (3) - -#if (_FX_OS_ == _FX_MACOSX_) -#define FWL_UseMacSystemBorder -#endif - -class CFWL_MsgMouse; -class CFWL_NoteLoop; -class CFWL_Widget; -class IFWL_ThemeProvider; -class CFWL_SysBtn; - -class CFWL_Form : public CFWL_Widget { - public: - CFWL_Form(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_Form() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - bool IsInstance(const CFX_WideStringC& wsClass) const override; - void GetClientRect(CFX_RectF& rect) override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - CFWL_Widget* DoModal(); - void EndDoModal(); - - CFWL_Widget* GetSubFocus() const { return m_pSubFocus; } - void SetSubFocus(CFWL_Widget* pWidget) { m_pSubFocus = pWidget; } - - private: - void DrawBackground(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); - void RemoveSysButtons(); - CFWL_SysBtn* GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy); - CFWL_SysBtn* GetSysBtnByState(uint32_t dwState); - CFWL_SysBtn* GetSysBtnByIndex(int32_t nIndex); - int32_t GetSysBtnIndex(CFWL_SysBtn* pBtn); - void GetEdgeRect(CFX_RectF& rtEdge); - void SetWorkAreaRect(); - void Layout(); - void ResetSysBtn(); - void RegisterForm(); - void UnRegisterForm(); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - void OnLButtonDblClk(CFWL_MsgMouse* pMsg); - -#if (_FX_OS_ == _FX_MACOSX_) - bool m_bMouseIn; -#endif - CFX_RectF m_rtRestore; - CFX_RectF m_rtRelative; - CFWL_SysBtn* m_pCloseBox; - CFWL_SysBtn* m_pMinBox; - CFWL_SysBtn* m_pMaxBox; - std::unique_ptr m_pNoteLoop; - CFWL_Widget* m_pSubFocus; - FX_FLOAT m_fCXBorder; - FX_FLOAT m_fCYBorder; - int32_t m_iCaptureBtn; - int32_t m_iSysBox; - bool m_bLButtonDown; - bool m_bMaximized; - bool m_bSetMaximize; - bool m_bDoModalFlag; -}; - -#endif // XFA_FWL_CORE_CFWL_FORM_H_ diff --git a/xfa/fwl/core/cfwl_formproxy.cpp b/xfa/fwl/core/cfwl_formproxy.cpp deleted file mode 100644 index c6d667f40e..0000000000 --- a/xfa/fwl/core/cfwl_formproxy.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_formproxy.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_notedriver.h" - -CFWL_FormProxy::CFWL_FormProxy( - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Form(app, std::move(properties), pOuter) {} - -CFWL_FormProxy::~CFWL_FormProxy() {} - -FWL_Type CFWL_FormProxy::GetClassID() const { - return FWL_Type::FormProxy; -} - -bool CFWL_FormProxy::IsInstance(const CFX_WideStringC& wsClass) const { - if (wsClass == CFX_WideStringC(FWL_CLASS_FormProxy)) - return true; - return CFWL_Form::IsInstance(wsClass); -} - -void CFWL_FormProxy::Update() {} - -void CFWL_FormProxy::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) {} - -void CFWL_FormProxy::OnProcessMessage(CFWL_Message* pMessage) { - m_pOuter->GetDelegate()->OnProcessMessage(pMessage); -} diff --git a/xfa/fwl/core/cfwl_formproxy.h b/xfa/fwl/core/cfwl_formproxy.h deleted file mode 100644 index 9c12597c09..0000000000 --- a/xfa/fwl/core/cfwl_formproxy.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_FORMPROXY_H_ -#define XFA_FWL_CORE_CFWL_FORMPROXY_H_ - -#include - -#include "xfa/fwl/core/cfwl_form.h" - -class CFWL_WidgetProperties; - -class CFWL_FormProxy : public CFWL_Form { - public: - CFWL_FormProxy(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_FormProxy() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - bool IsInstance(const CFX_WideStringC& wsClass) const override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; -}; - -#endif // XFA_FWL_CORE_CFWL_FORMPROXY_H_ diff --git a/xfa/fwl/core/cfwl_listbox.cpp b/xfa/fwl/core/cfwl_listbox.cpp deleted file mode 100644 index 45898b1ed7..0000000000 --- a/xfa/fwl/core/cfwl_listbox.cpp +++ /dev/null @@ -1,1131 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_listbox.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgmousewheel.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { - -const int kItemTextMargin = 2; - -} // namespace - -CFWL_ListBox::CFWL_ListBox(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Widget(app, std::move(properties), pOuter), - m_dwTTOStyles(0), - m_iTTOAligns(0), - m_hAnchor(nullptr), - m_fScorllBarWidth(0), - m_bLButtonDown(false), - m_pScrollBarTP(nullptr) { - m_rtClient.Reset(); - m_rtConent.Reset(); - m_rtStatic.Reset(); -} - -CFWL_ListBox::~CFWL_ListBox() {} - -FWL_Type CFWL_ListBox::GetClassID() const { - return FWL_Type::ListBox; -} - -void CFWL_ListBox::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_AlignMask) { - case FWL_STYLEEXT_LTB_LeftAlign: { - m_iTTOAligns = FDE_TTOALIGNMENT_CenterLeft; - break; - } - case FWL_STYLEEXT_LTB_RightAlign: { - m_iTTOAligns = FDE_TTOALIGNMENT_CenterRight; - break; - } - case FWL_STYLEEXT_LTB_CenterAlign: - default: { - m_iTTOAligns = FDE_TTOALIGNMENT_Center; - break; - } - } - if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) - m_dwTTOStyles |= FDE_TTOSTYLE_RTL; - - m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; - m_fScorllBarWidth = GetScrollWidth(); - CalcSize(false); -} - -FWL_WidgetHit CFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - if (IsShowScrollBar(false)) { - CFX_RectF rect = m_pHorzScrollBar->GetWidgetRect(); - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::HScrollBar; - } - if (IsShowScrollBar(true)) { - CFX_RectF rect = m_pVertScrollBar->GetWidgetRect(); - if (rect.Contains(fx, fy)) - return FWL_WidgetHit::VScrollBar; - } - if (m_rtClient.Contains(fx, fy)) - return FWL_WidgetHit::Client; - return FWL_WidgetHit::Unknown; -} - -void CFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - pGraphics->SaveGraphState(); - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - CFX_RectF rtClip(m_rtConent); - if (IsShowScrollBar(false)) - rtClip.height -= m_fScorllBarWidth; - if (IsShowScrollBar(true)) - rtClip.width -= m_fScorllBarWidth; - if (pMatrix) - pMatrix->TransformRect(rtClip); - - pGraphics->SetClipRect(rtClip); - if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0) - DrawBkground(pGraphics, pTheme, pMatrix); - - DrawItems(pGraphics, pTheme, pMatrix); - pGraphics->RestoreGraphState(); -} - -void CFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - if (pThemeProvider) - m_pProperties->m_pThemeProvider = pThemeProvider; -} - -int32_t CFWL_ListBox::CountSelItems() { - int32_t iRet = 0; - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - if (!pItem) - continue; - - uint32_t dwStyle = GetItemStyles(this, pItem); - if (dwStyle & FWL_ITEMSTATE_LTB_Selected) - iRet++; - } - return iRet; -} - -CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { - int32_t idx = GetSelIndex(nIndexSel); - if (idx < 0) - return nullptr; - return GetItem(this, idx); -} - -int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { - int32_t index = 0; - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - if (!pItem) - return -1; - - uint32_t dwStyle = GetItemStyles(this, pItem); - if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { - if (index == nIndex) - return i; - index++; - } - } - return -1; -} - -void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { - if (!pItem) { - if (bSelect) { - SelectAll(); - } else { - ClearSelection(); - SetFocusItem(nullptr); - } - return; - } - if (IsMultiSelection()) - SetSelectionDirect(pItem, bSelect); - else - SetSelection(pItem, pItem, bSelect); -} - -CFX_WideString CFWL_ListBox::GetDataProviderItemText(CFWL_ListItem* pItem) { - if (!pItem) - return L""; - return GetItemText(this, pItem); -} - -CFWL_ListItem* CFWL_ListBox::GetListItem(CFWL_ListItem* pItem, - uint32_t dwKeyCode) { - CFWL_ListItem* hRet = nullptr; - switch (dwKeyCode) { - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_End: { - const bool bUp = dwKeyCode == FWL_VKEY_Up; - const bool bDown = dwKeyCode == FWL_VKEY_Down; - const bool bHome = dwKeyCode == FWL_VKEY_Home; - int32_t iDstItem = -1; - if (bUp || bDown) { - int32_t index = GetItemIndex(this, pItem); - iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; - } else if (bHome) { - iDstItem = 0; - } else { - int32_t iCount = CountItems(this); - iDstItem = iCount - 1; - } - hRet = GetItem(this, iDstItem); - break; - } - default: - break; - } - return hRet; -} - -void CFWL_ListBox::SetSelection(CFWL_ListItem* hStart, - CFWL_ListItem* hEnd, - bool bSelected) { - int32_t iStart = GetItemIndex(this, hStart); - int32_t iEnd = GetItemIndex(this, hEnd); - if (iStart > iEnd) { - int32_t iTemp = iStart; - iStart = iEnd; - iEnd = iTemp; - } - if (bSelected) { - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - SetSelectionDirect(pItem, false); - } - } - for (; iStart <= iEnd; iStart++) { - CFWL_ListItem* pItem = GetItem(this, iStart); - SetSelectionDirect(pItem, bSelected); - } -} - -void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { - uint32_t dwOldStyle = GetItemStyles(this, pItem); - bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected - : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; - SetItemStyles(this, pItem, dwOldStyle); -} - -bool CFWL_ListBox::IsMultiSelection() const { - return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; -} - -bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { - uint32_t dwState = GetItemStyles(this, pItem); - return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; -} - -void CFWL_ListBox::ClearSelection() { - bool bMulti = IsMultiSelection(); - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - uint32_t dwState = GetItemStyles(this, pItem); - if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) - continue; - SetSelectionDirect(pItem, false); - if (!bMulti) - return; - } -} - -void CFWL_ListBox::SelectAll() { - if (!IsMultiSelection()) - return; - - int32_t iCount = CountItems(this); - if (iCount <= 0) - return; - - CFWL_ListItem* pItemStart = GetItem(this, 0); - CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1); - SetSelection(pItemStart, pItemEnd, false); -} - -CFWL_ListItem* CFWL_ListBox::GetFocusedItem() { - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - if (!pItem) - return nullptr; - if (GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) - return pItem; - } - return nullptr; -} - -void CFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { - CFWL_ListItem* hFocus = GetFocusedItem(); - if (pItem == hFocus) - return; - - if (hFocus) { - uint32_t dwStyle = GetItemStyles(this, hFocus); - dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; - SetItemStyles(this, hFocus, dwStyle); - } - if (pItem) { - uint32_t dwStyle = GetItemStyles(this, pItem); - dwStyle |= FWL_ITEMSTATE_LTB_Focused; - SetItemStyles(this, pItem, dwStyle); - } -} - -CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { - fx -= m_rtConent.left, fy -= m_rtConent.top; - FX_FLOAT fPosX = 0.0f; - if (m_pHorzScrollBar) - fPosX = m_pHorzScrollBar->GetPos(); - - FX_FLOAT fPosY = 0.0; - if (m_pVertScrollBar) - fPosY = m_pVertScrollBar->GetPos(); - - int32_t nCount = CountItems(this); - for (int32_t i = 0; i < nCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - if (!pItem) - continue; - - CFX_RectF rtItem; - GetItemRect(this, pItem, rtItem); - rtItem.Offset(-fPosX, -fPosY); - if (rtItem.Contains(fx, fy)) - return pItem; - } - return nullptr; -} - -bool CFWL_ListBox::GetItemCheckRectInternal(CFWL_ListItem* pItem, - CFX_RectF& rtCheck) { - if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) - return false; - GetItemCheckRect(this, pItem, rtCheck); - return true; -} - -bool CFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { - if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) - return false; - return !!(GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); -} - -bool CFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { - if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) - return false; - - SetItemCheckState(this, pItem, bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); - return true; -} - -bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { - if (!m_pVertScrollBar) - return false; - - CFX_RectF rtItem; - GetItemRect(this, pItem, rtItem); - - bool bScroll = false; - FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); - rtItem.Offset(0, -fPosY + m_rtConent.top); - if (rtItem.top < m_rtConent.top) { - fPosY += rtItem.top - m_rtConent.top; - bScroll = true; - } else if (rtItem.bottom() > m_rtConent.bottom()) { - fPosY += rtItem.bottom() - m_rtConent.bottom(); - bScroll = true; - } - if (!bScroll) - return false; - - m_pVertScrollBar->SetPos(fPosY); - m_pVertScrollBar->SetTrackPos(fPosY); - Repaint(&m_rtClient); - return true; -} - -void CFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!pTheme) - return; - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_dwStates = 0; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtClient; - if (IsShowScrollBar(false) && IsShowScrollBar(true)) - param.m_pData = &m_rtStatic; - if (!IsEnabled()) - param.m_dwStates = CFWL_PartState_Disabled; - - pTheme->DrawBackground(¶m); -} - -void CFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - FX_FLOAT fPosX = 0.0f; - if (m_pHorzScrollBar) - fPosX = m_pHorzScrollBar->GetPos(); - - FX_FLOAT fPosY = 0.0f; - if (m_pVertScrollBar) - fPosY = m_pVertScrollBar->GetPos(); - - CFX_RectF rtView(m_rtConent); - if (m_pHorzScrollBar) - rtView.height -= m_fScorllBarWidth; - if (m_pVertScrollBar) - rtView.width -= m_fScorllBarWidth; - - bool bMultiCol = - !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - if (!pItem) - continue; - - CFX_RectF rtItem; - GetItemRect(this, pItem, rtItem); - rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); - if (rtItem.bottom() < m_rtConent.top) - continue; - if (rtItem.top >= m_rtConent.bottom()) - break; - if (bMultiCol && rtItem.left > m_rtConent.right()) - break; - - if (!(GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw)) - DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); - } -} - -void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - CFWL_ListItem* pItem, - int32_t Index, - const CFX_RectF& rtItem, - const CFX_Matrix* pMatrix) { - uint32_t dwItemStyles = GetItemStyles(this, pItem); - uint32_t dwPartStates = CFWL_PartState_Normal; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - dwPartStates = CFWL_PartState_Disabled; - else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) - dwPartStates = CFWL_PartState_Selected; - - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && - dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { - dwPartStates |= CFWL_PartState_Focused; - } - - CFWL_ThemeBackground bg_param; - bg_param.m_pWidget = this; - bg_param.m_iPart = CFWL_Part::ListItem; - bg_param.m_dwStates = dwPartStates; - bg_param.m_pGraphics = pGraphics; - bg_param.m_matrix.Concat(*pMatrix); - bg_param.m_rtPart = rtItem; - bg_param.m_bMaximize = true; - CFX_RectF rtFocus(rtItem); - bg_param.m_pData = &rtFocus; - if (m_pVertScrollBar && !m_pHorzScrollBar && - (dwPartStates & CFWL_PartState_Focused)) { - bg_param.m_rtPart.left += 1; - bg_param.m_rtPart.width -= (m_fScorllBarWidth + 1); - rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1); - } - pTheme->DrawBackground(&bg_param); - - bool bHasIcon = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Icon); - if (bHasIcon) { - CFX_RectF rtDIB; - CFX_DIBitmap* pDib = GetItemIcon(this, pItem); - rtDIB.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); - if (pDib) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Icon; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = rtDIB; - param.m_bMaximize = true; - param.m_pImage = pDib; - pTheme->DrawBackground(¶m); - } - } - - bool bHasCheck = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Check); - if (bHasCheck) { - CFX_RectF rtCheck; - rtCheck.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); - rtCheck.Deflate(2, 2, 2, 2); - SetItemCheckRect(this, pItem, rtCheck); - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Check; - param.m_pGraphics = pGraphics; - if (GetItemChecked(pItem)) - param.m_dwStates = CFWL_PartState_Checked; - else - param.m_dwStates = CFWL_PartState_Normal; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = rtCheck; - param.m_bMaximize = true; - pTheme->DrawBackground(¶m); - } - - CFX_WideString wsText = GetItemText(this, pItem); - if (wsText.GetLength() <= 0) - return; - - CFX_RectF rtText(rtItem); - rtText.Deflate(kItemTextMargin, kItemTextMargin); - if (bHasIcon || bHasCheck) - rtText.Deflate(rtItem.height, 0, 0, 0); - - CFWL_ThemeText textParam; - textParam.m_pWidget = this; - textParam.m_iPart = CFWL_Part::ListItem; - textParam.m_dwStates = dwPartStates; - textParam.m_pGraphics = pGraphics; - textParam.m_matrix.Concat(*pMatrix); - textParam.m_rtPart = rtText; - textParam.m_wsText = wsText; - textParam.m_dwTTOStyles = m_dwTTOStyles; - textParam.m_iTTOAlign = m_iTTOAligns; - textParam.m_bMaximize = true; - pTheme->DrawText(&textParam); -} - -CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) { - CFX_SizeF fs; - if (!m_pProperties->m_pThemeProvider) - return fs; - - GetClientRect(m_rtClient); - m_rtConent = m_rtClient; - CFX_RectF rtUIMargin; - rtUIMargin.Set(0, 0, 0, 0); - if (!m_pOuter) { - CFX_RectF* pUIMargin = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); - if (pUIMargin) { - m_rtConent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, - pUIMargin->height); - } - } - - FX_FLOAT fWidth = GetMaxTextWidth(); - fWidth += 2 * kItemTextMargin; - if (!bAutoSize) { - FX_FLOAT fActualWidth = - m_rtClient.width - rtUIMargin.left - rtUIMargin.width; - fWidth = std::max(fWidth, fActualWidth); - } - - m_fItemHeight = CalcItemHeight(); - if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) - fWidth += m_fItemHeight; - - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* htem = GetItem(this, i); - GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); - } - if (bAutoSize) - return fs; - - FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; - FX_FLOAT iHeight = m_rtClient.height; - bool bShowVertScr = - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && - (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); - bool bShowHorzScr = - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && - (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); - if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { - bShowVertScr = (fs.y > iHeight); - } - if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) - bShowHorzScr = (fs.x > iWidth); - - CFX_SizeF szRange; - if (bShowVertScr) { - if (!m_pVertScrollBar) - InitVerticalScrollBar(); - - CFX_RectF rtScrollBar; - rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, - m_fScorllBarWidth, m_rtClient.height - 1); - if (bShowHorzScr) - rtScrollBar.height -= m_fScorllBarWidth; - - m_pVertScrollBar->SetWidgetRect(rtScrollBar); - szRange.x = 0, szRange.y = fs.y - m_rtConent.height; - szRange.y = std::max(szRange.y, m_fItemHeight); - - m_pVertScrollBar->SetRange(szRange.x, szRange.y); - m_pVertScrollBar->SetPageSize(rtScrollBar.height * 9 / 10); - m_pVertScrollBar->SetStepSize(m_fItemHeight); - - FX_FLOAT fPos = - std::min(std::max(m_pVertScrollBar->GetPos(), 0.f), szRange.y); - m_pVertScrollBar->SetPos(fPos); - m_pVertScrollBar->SetTrackPos(fPos); - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == - 0 || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { - m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - } - m_pVertScrollBar->Update(); - } else if (m_pVertScrollBar) { - m_pVertScrollBar->SetPos(0); - m_pVertScrollBar->SetTrackPos(0); - m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - if (bShowHorzScr) { - if (!m_pHorzScrollBar) - InitHorizontalScrollBar(); - - CFX_RectF rtScrollBar; - rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, - m_rtClient.width, m_fScorllBarWidth); - if (bShowVertScr) - rtScrollBar.width -= m_fScorllBarWidth; - - m_pHorzScrollBar->SetWidgetRect(rtScrollBar); - szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; - m_pHorzScrollBar->SetRange(szRange.x, szRange.y); - m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10); - m_pHorzScrollBar->SetStepSize(fWidth / 10); - - FX_FLOAT fPos = - std::min(std::max(m_pHorzScrollBar->GetPos(), 0.f), szRange.y); - m_pHorzScrollBar->SetPos(fPos); - m_pHorzScrollBar->SetTrackPos(fPos); - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == - 0 || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { - m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - } - m_pHorzScrollBar->Update(); - } else if (m_pHorzScrollBar) { - m_pHorzScrollBar->SetPos(0); - m_pHorzScrollBar->SetTrackPos(0); - m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - if (bShowVertScr && bShowHorzScr) { - m_rtStatic.Set(m_rtClient.right() - m_fScorllBarWidth, - m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, - m_fScorllBarWidth); - } - return fs; -} - -void CFWL_ListBox::GetItemSize(CFX_SizeF& size, - CFWL_ListItem* pItem, - FX_FLOAT fWidth, - FX_FLOAT fItemHeight, - bool bAutoSize) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) - return; - - if (!bAutoSize) { - CFX_RectF rtItem; - rtItem.Set(0, size.y, fWidth, fItemHeight); - SetItemRect(this, pItem, rtItem); - } - size.x = fWidth; - size.y += fItemHeight; -} - -FX_FLOAT CFWL_ListBox::GetMaxTextWidth() { - FX_FLOAT fRet = 0.0f; - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* pItem = GetItem(this, i); - if (!pItem) - continue; - - CFX_WideString wsText = GetItemText(this, pItem); - CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider, false); - fRet = std::max(fRet, sz.x); - } - return fRet; -} - -FX_FLOAT CFWL_ListBox::GetScrollWidth() { - FX_FLOAT* pfWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pfWidth) - return 0; - return *pfWidth; -} - -FX_FLOAT CFWL_ListBox::CalcItemHeight() { - FX_FLOAT* pfFont = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); - if (!pfFont) - return 20; - return *pfFont + 2 * kItemTextMargin; -} - -void CFWL_ListBox::InitVerticalScrollBar() { - if (m_pVertScrollBar) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert; - prop->m_dwStates = FWL_WGTSTATE_Invisible; - prop->m_pParent = this; - prop->m_pThemeProvider = m_pScrollBarTP; - m_pVertScrollBar = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); -} - -void CFWL_ListBox::InitHorizontalScrollBar() { - if (m_pHorzScrollBar) - return; - - auto prop = pdfium::MakeUnique(); - prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz; - prop->m_dwStates = FWL_WGTSTATE_Invisible; - prop->m_pParent = this; - prop->m_pThemeProvider = m_pScrollBarTP; - m_pHorzScrollBar = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); -} - -bool CFWL_ListBox::IsShowScrollBar(bool bVert) { - CFWL_ScrollBar* pScrollbar = - bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); - if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) - return false; - return !(m_pProperties->m_dwStyleExes & - FWL_STYLEEXT_LTB_ShowScrollBarFocus) || - (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); -} - -void CFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - if (!IsEnabled()) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::MouseWheel: - OnMouseWheel(static_cast(pMessage)); - break; - case CFWL_Message::Type::Key: { - CFWL_MsgKey* pMsg = static_cast(pMessage); - if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown) - OnKeyDown(pMsg); - break; - } - default: - break; - } - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) { - if (!pEvent) - return; - if (pEvent->GetType() != CFWL_Event::Type::Scroll) - return; - - CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; - if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || - (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { - CFWL_EvtScroll* pScrollEvent = static_cast(pEvent); - OnScroll(static_cast(pSrcTarget), - pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); - } -} - -void CFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_ListBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (GetStylesEx() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) { - if (m_pVertScrollBar) { - if (bSet) - m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - else - m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - if (m_pHorzScrollBar) { - if (bSet) - m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); - else - m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible); - } - } - if (bSet) - m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); - else - m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); - - Repaint(&m_rtClient); -} - -void CFWL_ListBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { - m_bLButtonDown = true; - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - SetFocus(true); - - CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); - if (!pItem) - return; - - if (IsMultiSelection()) { - if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { - bool bSelected = IsItemSelected(pItem); - SetSelectionDirect(pItem, !bSelected); - m_hAnchor = pItem; - } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) { - if (m_hAnchor) - SetSelection(m_hAnchor, pItem, true); - else - SetSelectionDirect(pItem, true); - } else { - SetSelection(pItem, pItem, true); - m_hAnchor = pItem; - } - } else { - SetSelection(pItem, pItem, true); - } - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) { - CFWL_ListItem* hSelectedItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); - CFX_RectF rtCheck; - GetItemCheckRectInternal(hSelectedItem, rtCheck); - bool bChecked = GetItemChecked(pItem); - if (rtCheck.Contains(pMsg->m_fx, pMsg->m_fy)) { - SetItemChecked(pItem, !bChecked); - Update(); - } - } - SetFocusItem(pItem); - ScrollToVisible(pItem); - SetGrab(true); - Repaint(&m_rtClient); -} - -void CFWL_ListBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (!m_bLButtonDown) - return; - - m_bLButtonDown = false; - SetGrab(false); -} - -void CFWL_ListBox::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { - if (IsShowScrollBar(true)) - m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); -} - -void CFWL_ListBox::OnKeyDown(CFWL_MsgKey* pMsg) { - uint32_t dwKeyCode = pMsg->m_dwKeyCode; - switch (dwKeyCode) { - case FWL_VKEY_Tab: - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_End: { - CFWL_ListItem* pItem = GetFocusedItem(); - pItem = GetListItem(pItem, dwKeyCode); - bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); - bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); - OnVK(pItem, bShift, bCtrl); - break; - } - default: - break; - } -} - -void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { - if (!pItem) - return; - - if (IsMultiSelection()) { - if (bCtrl) { - // Do nothing. - } else if (bShift) { - if (m_hAnchor) - SetSelection(m_hAnchor, pItem, true); - else - SetSelectionDirect(pItem, true); - } else { - SetSelection(pItem, pItem, true); - m_hAnchor = pItem; - } - } else { - SetSelection(pItem, pItem, true); - } - - SetFocusItem(pItem); - ScrollToVisible(pItem); - - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - Repaint(&rtInvalidate); -} - -bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar, - CFWL_EvtScroll::Code dwCode, - FX_FLOAT fPos) { - CFX_SizeF fs; - pScrollBar->GetRange(&fs.x, &fs.y); - FX_FLOAT iCurPos = pScrollBar->GetPos(); - FX_FLOAT fStep = pScrollBar->GetStepSize(); - switch (dwCode) { - case CFWL_EvtScroll::Code::Min: { - fPos = fs.x; - break; - } - case CFWL_EvtScroll::Code::Max: { - fPos = fs.y; - break; - } - case CFWL_EvtScroll::Code::StepBackward: { - fPos -= fStep; - if (fPos < fs.x + fStep / 2) - fPos = fs.x; - break; - } - case CFWL_EvtScroll::Code::StepForward: { - fPos += fStep; - if (fPos > fs.y - fStep / 2) - fPos = fs.y; - break; - } - case CFWL_EvtScroll::Code::PageBackward: { - fPos -= pScrollBar->GetPageSize(); - if (fPos < fs.x) - fPos = fs.x; - break; - } - case CFWL_EvtScroll::Code::PageForward: { - fPos += pScrollBar->GetPageSize(); - if (fPos > fs.y) - fPos = fs.y; - break; - } - case CFWL_EvtScroll::Code::Pos: - case CFWL_EvtScroll::Code::TrackPos: - case CFWL_EvtScroll::Code::None: - break; - case CFWL_EvtScroll::Code::EndScroll: - return false; - } - if (iCurPos != fPos) { - pScrollBar->SetPos(fPos); - pScrollBar->SetTrackPos(fPos); - Repaint(&m_rtClient); - } - return true; -} - -CFX_WideString CFWL_ListBox::GetItemText(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return pItem ? static_cast(pItem)->m_wsText : L""; -} - -int32_t CFWL_ListBox::CountItems(const CFWL_Widget* pWidget) const { - return pdfium::CollectionSize(m_ItemArray); -} - -CFWL_ListItem* CFWL_ListBox::GetItem(const CFWL_Widget* pWidget, - int32_t nIndex) const { - if (nIndex < 0 || nIndex >= CountItems(pWidget)) - return nullptr; - return m_ItemArray[nIndex].get(); -} - -int32_t CFWL_ListBox::GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem) { - auto it = std::find_if( - m_ItemArray.begin(), m_ItemArray.end(), - [pItem](const std::unique_ptr& candidate) { - return candidate.get() == static_cast(pItem); - }); - return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; -} - -uint32_t CFWL_ListBox::GetItemStyles(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return pItem ? static_cast(pItem)->m_dwStates : 0; -} - -void CFWL_ListBox::GetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtItem) { - if (pItem) - rtItem = static_cast(pItem)->m_rtItem; -} - -void* CFWL_ListBox::GetItemData(CFWL_Widget* pWidget, CFWL_ListItem* pItem) { - return pItem ? static_cast(pItem)->m_pData : nullptr; -} - -void CFWL_ListBox::SetItemStyles(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwStyle) { - if (pItem) - static_cast(pItem)->m_dwStates = dwStyle; -} - -void CFWL_ListBox::SetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtItem) { - if (pItem) - static_cast(pItem)->m_rtItem = rtItem; -} - -CFX_DIBitmap* CFWL_ListBox::GetItemIcon(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return static_cast(pItem)->m_pDIB; -} - -void CFWL_ListBox::GetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtCheck) { - rtCheck = static_cast(pItem)->m_rtCheckBox; -} - -void CFWL_ListBox::SetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtCheck) { - static_cast(pItem)->m_rtCheckBox = rtCheck; -} - -uint32_t CFWL_ListBox::GetItemCheckState(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return static_cast(pItem)->m_dwCheckState; -} - -void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwCheckState) { - static_cast(pItem)->m_dwCheckState = dwCheckState; -} - -CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd) { - auto pItem = pdfium::MakeUnique(); - pItem->m_dwStates = 0; - pItem->m_wsText = wsAdd; - pItem->m_dwStates = 0; - m_ItemArray.push_back(std::move(pItem)); - return m_ItemArray.back().get(); -} - -bool CFWL_ListBox::RemoveAt(int32_t iIndex) { - if (iIndex < 0 || static_cast(iIndex) >= m_ItemArray.size()) - return false; - - m_ItemArray.erase(m_ItemArray.begin() + iIndex); - return true; -} - -bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { - int32_t nIndex = GetItemIndex(this, pItem); - if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) - return false; - - int32_t iSel = nIndex + 1; - if (iSel >= CountItems(this)) - iSel = nIndex - 1; - if (iSel >= 0) { - CFWL_ListItem* pSel = static_cast(GetItem(this, iSel)); - pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; - } - m_ItemArray.erase(m_ItemArray.begin() + nIndex); - return true; -} - -void CFWL_ListBox::DeleteAll() { - m_ItemArray.clear(); -} - -uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { - if (!pItem) - return 0; - return pItem->m_dwStates | pItem->m_dwCheckState; -} - diff --git a/xfa/fwl/core/cfwl_listbox.h b/xfa/fwl/core/cfwl_listbox.h deleted file mode 100644 index 905a040326..0000000000 --- a/xfa/fwl/core/cfwl_listbox.h +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_LISTBOX_H_ -#define XFA_FWL_CORE_CFWL_LISTBOX_H_ - -#include -#include - -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_listitem.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_STYLEEXT_LTB_MultiSelection (1L << 0) -#define FWL_STYLEEXT_LTB_ShowScrollBarAlaways (1L << 2) -#define FWL_STYLEEXT_LTB_MultiColumn (1L << 3) -#define FWL_STYLEEXT_LTB_LeftAlign (0L << 4) -#define FWL_STYLEEXT_LTB_CenterAlign (1L << 4) -#define FWL_STYLEEXT_LTB_RightAlign (2L << 4) -#define FWL_STYLEEXT_LTB_MultiLine (1L << 6) -#define FWL_STYLEEXT_LTB_OwnerDraw (1L << 7) -#define FWL_STYLEEXT_LTB_Icon (1L << 8) -#define FWL_STYLEEXT_LTB_Check (1L << 9) -#define FWL_STYLEEXT_LTB_AlignMask (3L << 4) -#define FWL_STYLEEXT_LTB_ShowScrollBarFocus (1L << 10) -#define FWL_ITEMSTATE_LTB_Selected (1L << 0) -#define FWL_ITEMSTATE_LTB_Focused (1L << 1) -#define FWL_ITEMSTATE_LTB_Checked (1L << 2) - -class CFWL_MsgKillFocus; -class CFWL_MsgMouse; -class CFWL_MsgMouseWheel; -class CFX_DIBitmap; - -class CFWL_ListBox : public CFWL_Widget { - public: - explicit CFWL_ListBox(const CFWL_App* pApp, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_ListBox() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - int32_t CountItems(const CFWL_Widget* pWidget) const; - CFWL_ListItem* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const; - int32_t GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - uint32_t GetItemStyles(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - uint32_t GetItemStates(CFWL_ListItem* pItem); - CFX_WideString GetItemText(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void GetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtItem); - void* GetItemData(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void SetItemStyles(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwStyle); - void SetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtItem); - CFX_DIBitmap* GetItemIcon(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void GetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtCheck); - void SetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtCheck); - uint32_t GetItemCheckState(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void SetItemCheckState(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwCheckState); - CFWL_ListItem* AddString(const CFX_WideStringC& wsAdd); - bool RemoveAt(int32_t iIndex); - bool DeleteString(CFWL_ListItem* pItem); - void DeleteAll(); - - int32_t CountSelItems(); - CFWL_ListItem* GetSelItem(int32_t nIndexSel); - int32_t GetSelIndex(int32_t nIndex); - void SetSelItem(CFWL_ListItem* hItem, bool bSelect); - CFX_WideString GetDataProviderItemText(CFWL_ListItem* hItem); - - FX_FLOAT GetItemHeight() const { return m_fItemHeight; } - FX_FLOAT CalcItemHeight(); - - protected: - CFWL_ListItem* GetListItem(CFWL_ListItem* hItem, uint32_t dwKeyCode); - void SetSelection(CFWL_ListItem* hStart, CFWL_ListItem* hEnd, bool bSelected); - CFWL_ListItem* GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy); - bool ScrollToVisible(CFWL_ListItem* hItem); - void InitVerticalScrollBar(); - void InitHorizontalScrollBar(); - bool IsShowScrollBar(bool bVert); - CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar.get(); } - const CFX_RectF& GetRTClient() const { return m_rtClient; } - - private: - void SetSelectionDirect(CFWL_ListItem* hItem, bool bSelect); - bool IsMultiSelection() const; - bool IsItemSelected(CFWL_ListItem* hItem); - void ClearSelection(); - void SelectAll(); - CFWL_ListItem* GetFocusedItem(); - void SetFocusItem(CFWL_ListItem* hItem); - bool GetItemCheckRectInternal(CFWL_ListItem* hItem, CFX_RectF& rtCheck); - bool SetItemChecked(CFWL_ListItem* hItem, bool bChecked); - bool GetItemChecked(CFWL_ListItem* hItem); - void DrawBkground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawItems(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawItem(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - CFWL_ListItem* hItem, - int32_t Index, - const CFX_RectF& rtItem, - const CFX_Matrix* pMatrix); - void DrawStatic(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); - CFX_SizeF CalcSize(bool bAutoSize); - void GetItemSize(CFX_SizeF& size, - CFWL_ListItem* hItem, - FX_FLOAT fWidth, - FX_FLOAT fHeight, - bool bAutoSize); - FX_FLOAT GetMaxTextWidth(); - FX_FLOAT GetScrollWidth(); - - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseWheel(CFWL_MsgMouseWheel* pMsg); - void OnKeyDown(CFWL_MsgKey* pMsg); - void OnVK(CFWL_ListItem* hItem, bool bShift, bool bCtrl); - bool OnScroll(CFWL_ScrollBar* pScrollBar, - CFWL_EvtScroll::Code dwCode, - FX_FLOAT fPos); - - CFX_RectF m_rtClient; - CFX_RectF m_rtStatic; - CFX_RectF m_rtConent; - std::unique_ptr m_pHorzScrollBar; - std::unique_ptr m_pVertScrollBar; - uint32_t m_dwTTOStyles; - int32_t m_iTTOAligns; - CFWL_ListItem* m_hAnchor; - FX_FLOAT m_fItemHeight; - FX_FLOAT m_fScorllBarWidth; - bool m_bLButtonDown; - IFWL_ThemeProvider* m_pScrollBarTP; - std::vector> m_ItemArray; -}; - -#endif // XFA_FWL_CORE_CFWL_LISTBOX_H_ diff --git a/xfa/fwl/core/cfwl_listitem.cpp b/xfa/fwl/core/cfwl_listitem.cpp deleted file mode 100644 index 4419839024..0000000000 --- a/xfa/fwl/core/cfwl_listitem.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_listitem.h" - -CFWL_ListItem::CFWL_ListItem() - : m_dwStates(0), - m_wsText(L""), - m_pDIB(nullptr), - m_pData(nullptr), - m_dwCheckState(0) { - m_rtCheckBox.Reset(); - m_rtItem.Reset(); -} - -CFWL_ListItem::~CFWL_ListItem() {} diff --git a/xfa/fwl/core/cfwl_listitem.h b/xfa/fwl/core/cfwl_listitem.h deleted file mode 100644 index 0a5f0a3088..0000000000 --- a/xfa/fwl/core/cfwl_listitem.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_LISTITEM_H_ -#define XFA_FWL_CORE_CFWL_LISTITEM_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" - -class CFX_DIBitmap; - -class CFWL_ListItem { - public: - CFWL_ListItem(); - ~CFWL_ListItem(); - - CFX_RectF m_rtItem; - uint32_t m_dwStates; - uint32_t m_dwStyles; - CFX_WideString m_wsText; - CFX_DIBitmap* m_pDIB; - void* m_pData; - uint32_t m_dwCheckState; - CFX_RectF m_rtCheckBox; -}; - -#endif // XFA_FWL_CORE_CFWL_LISTITEM_H_ diff --git a/xfa/fwl/core/cfwl_message.cpp b/xfa/fwl/core/cfwl_message.cpp deleted file mode 100644 index a8d13fc740..0000000000 --- a/xfa/fwl/core/cfwl_message.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_message.h" - -CFWL_Message::CFWL_Message(CFWL_Message::Type type) - : CFWL_Message(type, nullptr, nullptr) {} - -CFWL_Message::CFWL_Message(Type type, CFWL_Widget* pSrcTarget) - : CFWL_Message(type, pSrcTarget, nullptr) {} - -CFWL_Message::CFWL_Message(Type type, - CFWL_Widget* pSrcTarget, - CFWL_Widget* pDstTarget) - : m_pSrcTarget(pSrcTarget), - m_pDstTarget(pDstTarget), - m_type(type) {} - -CFWL_Message::~CFWL_Message() {} - -std::unique_ptr CFWL_Message::Clone() { - return nullptr; -} diff --git a/xfa/fwl/core/cfwl_message.h b/xfa/fwl/core/cfwl_message.h deleted file mode 100644 index 0c980066cc..0000000000 --- a/xfa/fwl/core/cfwl_message.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MESSAGE_H_ -#define XFA_FWL_CORE_CFWL_MESSAGE_H_ - -#include - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/fwl_error.h" - -class CFWL_Widget; - -class CFWL_Message { - public: - enum class Type { Key, KillFocus, Mouse, MouseWheel, SetFocus }; - - explicit CFWL_Message(Type type); - CFWL_Message(Type type, CFWL_Widget* pSrcTarget); - CFWL_Message(Type type, CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - virtual ~CFWL_Message(); - - virtual std::unique_ptr Clone(); - Type GetType() const { return m_type; } - - CFWL_Widget* m_pSrcTarget; - CFWL_Widget* m_pDstTarget; - - private: - Type m_type; -}; - - -#endif // XFA_FWL_CORE_CFWL_MESSAGE_H_ diff --git a/xfa/fwl/core/cfwl_monthcalendar.cpp b/xfa/fwl/core/cfwl_monthcalendar.cpp deleted file mode 100644 index 8a284aae52..0000000000 --- a/xfa/fwl/core/cfwl_monthcalendar.cpp +++ /dev/null @@ -1,1089 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_monthcalendar.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_datetimepicker.h" -#include "xfa/fwl/core/cfwl_formproxy.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -#define MONTHCAL_HSEP_HEIGHT 1 -#define MONTHCAL_VSEP_WIDTH 1 -#define MONTHCAL_HMARGIN 3 -#define MONTHCAL_VMARGIN 2 -#define MONTHCAL_ROWS 9 -#define MONTHCAL_COLUMNS 7 -#define MONTHCAL_HEADER_BTN_VMARGIN 7 -#define MONTHCAL_HEADER_BTN_HMARGIN 5 - -namespace { - -CFX_WideString* GetCapacityForDay(IFWL_ThemeProvider* pTheme, - CFWL_ThemePart& params, - uint32_t day) { - ASSERT(day < 7); - - if (day == 0) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sun)); - } - if (day == 1) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Mon)); - } - if (day == 2) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Tue)); - } - if (day == 3) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Wed)); - } - if (day == 4) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Thu)); - } - if (day == 5) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Fri)); - } - - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sat)); -} - -CFX_WideString* GetCapacityForMonth(IFWL_ThemeProvider* pTheme, - CFWL_ThemePart& params, - uint32_t month) { - ASSERT(month < 12); - - if (month == 0) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::January)); - } - if (month == 1) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::February)); - } - if (month == 2) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::March)); - } - if (month == 3) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::April)); - } - if (month == 4) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::May)); - } - if (month == 5) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::June)); - } - if (month == 6) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::July)); - } - if (month == 7) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::August)); - } - if (month == 8) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::September)); - } - if (month == 9) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::October)); - } - if (month == 10) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::November)); - } - - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::December)); -} - -} // namespace - -CFWL_MonthCalendar::CFWL_MonthCalendar( - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Widget(app, std::move(properties), pOuter), - m_bInitialized(false), - m_pDateTime(new CFX_DateTime), - m_iCurYear(2011), - m_iCurMonth(1), - m_iYear(2011), - m_iMonth(1), - m_iDay(1), - m_iHovered(-1), - m_iLBtnPartStates(CFWL_PartState_Normal), - m_iRBtnPartStates(CFWL_PartState_Normal), - m_bFlag(false) { - m_rtHead.Reset(); - m_rtWeek.Reset(); - m_rtLBtn.Reset(); - m_rtRBtn.Reset(); - m_rtDates.Reset(); - m_rtHSep.Reset(); - m_rtHeadText.Reset(); - m_rtToday.Reset(); - m_rtTodayFlag.Reset(); - m_rtClient.Reset(); - m_rtWeekNum.Reset(); - m_rtWeekNumSep.Reset(); -} - -CFWL_MonthCalendar::~CFWL_MonthCalendar() { - ClearDateItem(); - m_arrSelDays.RemoveAll(); -} - -FWL_Type CFWL_MonthCalendar::GetClassID() const { - return FWL_Type::MonthCalendar; -} - -CFX_RectF CFWL_MonthCalendar::GetAutosizedWidgetRect() { - CFX_SizeF fs = CalcSize(); - CFX_RectF rect; - rect.Set(0, 0, fs.x, fs.y); - InflateWidgetRect(rect); - return rect; -} - -void CFWL_MonthCalendar::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - GetCapValue(); - if (!m_bInitialized) { - InitDate(); - m_bInitialized = true; - } - - ClearDateItem(); - ResetDateItem(); - Layout(); -} - -void CFWL_MonthCalendar::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - DrawBackground(pGraphics, pTheme, pMatrix); - DrawHeadBK(pGraphics, pTheme, pMatrix); - DrawLButton(pGraphics, pTheme, pMatrix); - DrawRButton(pGraphics, pTheme, pMatrix); - DrawSeperator(pGraphics, pTheme, pMatrix); - DrawDatesInBK(pGraphics, pTheme, pMatrix); - DrawDatesInCircle(pGraphics, pTheme, pMatrix); - DrawCaption(pGraphics, pTheme, pMatrix); - DrawWeek(pGraphics, pTheme, pMatrix); - DrawDatesIn(pGraphics, pTheme, pMatrix); - DrawDatesOut(pGraphics, pTheme, pMatrix); - DrawToday(pGraphics, pTheme, pMatrix); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { - DrawWeekNumberSep(pGraphics, pTheme, pMatrix); - DrawWeekNumber(pGraphics, pTheme, pMatrix); - } -} - -void CFWL_MonthCalendar::SetSelect(int32_t iYear, - int32_t iMonth, - int32_t iDay) { - ChangeToMonth(iYear, iMonth); - AddSelDay(iDay); -} - -void CFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Background; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtClient; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void CFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Header; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtHead; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void CFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::LBtn; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_iLBtnPartStates; - params.m_rtPart = m_rtLBtn; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void CFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::RBtn; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_iRBtnPartStates; - params.m_rtPart = m_rtRBtn; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void CFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText textParam; - textParam.m_pWidget = this; - textParam.m_iPart = CFWL_Part::Caption; - textParam.m_dwStates = CFWL_PartState_Normal; - textParam.m_pGraphics = pGraphics; - int32_t iYear; - int32_t iMonth; - iYear = m_iCurYear; - iMonth = m_iCurMonth; - CFX_WideString wsCation; - GetHeadText(iYear, iMonth, wsCation); - textParam.m_wsText = wsCation; - m_szHead = - CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider, false); - CalcHeadSize(); - textParam.m_rtPart = m_rtHeadText; - textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - textParam.m_matrix.Concat(*pMatrix); - pTheme->DrawText(&textParam); -} - -void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::HSeparator; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtHSep; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void CFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DateInBK; - params.m_pGraphics = pGraphics; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - int32_t iCount = m_arrDates.GetSize(); - for (int32_t j = 0; j < iCount; j++) { - DATEINFO* pDataInfo = m_arrDates.GetAt(j); - if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { - params.m_dwStates |= CFWL_PartState_Selected; - if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == - 0) && - pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { - params.m_dwStates |= CFWL_PartState_Flagged; - } - if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) - params.m_dwStates |= CFWL_PartState_Focused; - } else if (j == m_iHovered - 1) { - params.m_dwStates |= CFWL_PartState_Hovered; - } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { - params.m_dwStates = CFWL_PartState_Flagged; - pTheme->DrawBackground(¶ms); - } - params.m_rtPart = pDataInfo->rect; - pTheme->DrawBackground(¶ms); - params.m_dwStates = 0; - } -} - -void CFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Week; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - CFX_RectF rtDayOfWeek; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - for (int32_t i = 0; i < 7; i++) { - rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2), - m_rtWeek.top, m_szCell.x, m_szCell.y); - params.m_rtPart = rtDayOfWeek; - params.m_wsText = *GetCapacityForDay(pTheme, params, i); - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - pTheme->DrawText(¶ms); - } -} - -void CFWL_MonthCalendar::DrawWeekNumber(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::WeekNum; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - CFX_WideString wsWeekNum; - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - int32_t iMonthNum = m_pDateTime->GetMonth(); - int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum); - int32_t iTemp = 0; - FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei; - FX_FLOAT fHStartPos = m_rtClient.left; - for (int32_t i = 1; i <= iDayNum; i += 7) { - iTemp++; - m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp, - m_fWeekNumWid, m_fDateCellHei); - wsWeekNum.Format(L"0"); - params.m_wsText = wsWeekNum; - params.m_rtPart = m_rtWeekNum; - pTheme->DrawText(¶ms); - } -} - -void CFWL_MonthCalendar::DrawWeekNumberSep(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::WeekNumSep; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtWeekNumSep; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void CFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) - return; - - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Today; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - - CFX_WideString* wsDay = static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); - CFX_WideString wsText; - GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); - params.m_wsText = *wsDay + wsText; - - m_szToday = - CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider, false); - CalcTodaySize(); - params.m_rtPart = m_rtToday; - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawText(¶ms); -} - -void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DatesIn; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - int32_t iCount = m_arrDates.GetSize(); - for (int32_t j = 0; j < iCount; j++) { - DATEINFO* pDataInfo = m_arrDates.GetAt(j); - params.m_wsText = pDataInfo->wsDay; - params.m_rtPart = pDataInfo->rect; - params.m_dwStates = pDataInfo->dwStates; - if (j + 1 == m_iHovered) - params.m_dwStates |= CFWL_PartState_Hovered; - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - pTheme->DrawText(¶ms); - } -} - -void CFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DatesOut; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawText(¶ms); -} - -void CFWL_MonthCalendar::DrawDatesInCircle(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) - return; - if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) - return; - if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) - return; - - DATEINFO* pDate = m_arrDates[m_iDay - 1]; - if (!pDate) - return; - - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DateInCircle; - params.m_pGraphics = pGraphics; - params.m_rtPart = pDate->rect; - params.m_dwStates = CFWL_PartState_Normal; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -CFX_SizeF CFWL_MonthCalendar::CalcSize() { - if (!m_pProperties->m_pThemeProvider) - return CFX_SizeF(); - - CFX_SizeF fs; - CFWL_ThemePart params; - params.m_pWidget = this; - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - FX_FLOAT fMaxWeekW = 0.0f; - FX_FLOAT fMaxWeekH = 0.0f; - - for (uint32_t i = 0; i < 7; ++i) { - CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), - m_pProperties->m_pThemeProvider, false); - fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; - fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; - } - - FX_FLOAT fDayMaxW = 0.0f; - FX_FLOAT fDayMaxH = 0.0f; - for (int day = 10; day <= 31; day++) { - CFX_WideString wsDay; - wsDay.Format(L"%d", day); - CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider, false); - fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; - fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; - } - m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) - : (int)(fDayMaxW + 0.5)); - m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; - fs.x = m_szCell.x * MONTHCAL_COLUMNS + - MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + - MONTHCAL_HEADER_BTN_HMARGIN * 2; - FX_FLOAT fMonthMaxW = 0.0f; - FX_FLOAT fMonthMaxH = 0.0f; - - for (uint32_t i = 0; i < 12; ++i) { - CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), - m_pProperties->m_pThemeProvider, false); - fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; - fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; - } - - CFX_WideString wsYear; - GetHeadText(m_iYear, m_iMonth, wsYear); - - CFX_SizeF szYear = - CalcTextSize(wsYear, m_pProperties->m_pThemeProvider, false); - fMonthMaxH = std::max(fMonthMaxH, szYear.y); - m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); - fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; - fs.x = std::max(fs.x, fMonthMaxW); - - CFX_WideString wsToday; - GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); - CFX_WideString* wsText = static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); - m_wsToday = *wsText + wsToday; - m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider, false); - m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; - fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + - MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; - return fs; -} - -void CFWL_MonthCalendar::CalcHeadSize() { - FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; - FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; - m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, - m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN + - MONTHCAL_VMARGIN + fHeadVMargin, - m_szHead.x, m_szHead.y); -} - -void CFWL_MonthCalendar::CalcTodaySize() { - m_rtTodayFlag.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, - m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, - m_szCell.x, m_szToday.y); - m_rtToday.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x + - MONTHCAL_HMARGIN * 2, - m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, - m_szToday.x, m_szToday.y); -} - -void CFWL_MonthCalendar::Layout() { - GetClientRect(m_rtClient); - - m_rtHead.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top, - m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, - m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2); - m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtHead.bottom(), - m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, - m_szCell.y + MONTHCAL_VMARGIN * 2); - m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, - m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, - m_szCell.x); - m_rtRBtn.Set(m_rtClient.left + m_rtClient.width - - MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x, - m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, - m_szCell.x); - m_rtHSep.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, - m_rtWeek.bottom() - MONTHCAL_VMARGIN, - m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2, - MONTHCAL_HSEP_HEIGHT); - m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, - m_rtWeek.bottom(), - m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, - m_szCell.y * (MONTHCAL_ROWS - 3) + - MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2); - - CalDateItem(); -} - -void CFWL_MonthCalendar::CalDateItem() { - bool bNewWeek = false; - int32_t iWeekOfMonth = 0; - FX_FLOAT fLeft = m_rtDates.left; - FX_FLOAT fTop = m_rtDates.top; - int32_t iCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - DATEINFO* pDateInfo = m_arrDates.GetAt(i); - if (bNewWeek) { - iWeekOfMonth++; - bNewWeek = false; - } - pDateInfo->rect.Set( - fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)), - fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)), - m_szCell.x + (MONTHCAL_HMARGIN * 2), - m_szCell.y + (MONTHCAL_VMARGIN * 2)); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) - pDateInfo->rect.Offset(m_fWeekNumWid, 0); - if (pDateInfo->iDayOfWeek >= 6) - bNewWeek = true; - } -} - -void CFWL_MonthCalendar::GetCapValue() { - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - CFWL_ThemePart part; - part.m_pWidget = this; - m_fHeadWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderWidth)); - m_fHeadHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderHeight)); - m_fHeadBtnWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnWidth)); - m_fHeadBtnHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHeight)); - m_fHeadBtnHMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHMargin)); - m_fHeadBtnVMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnVMargin)); - m_fHeadTextWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextWidth)); - m_fHeadTextHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHeight)); - m_fHeadTextHMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHMargin)); - m_fHeadTextVMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextVMargin)); - m_fHSepWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepWidth)); - m_fHSepHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepHeight)); - m_fWeekNumWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumWidth)); - m_fSepDOffset = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepDOffset)); - m_fSepX = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepX)); - m_fSepY = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepY)); - m_fWeekNumHeigh = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumHeight)); - m_fWeekWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekWidth)); - m_fWeekHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekHeight)); - m_fDateCellWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellWidth)); - m_fDateCellHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellHeight)); - m_fTodayWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayWidth)); - m_fTodayHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayHeight)); - m_fTodayFlagWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayFlagWidth)); - m_fMCWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Width)); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) - m_fMCWid += m_fWeekNumWid; - - m_fMCHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Height)); -} - -void CFWL_MonthCalendar::InitDate() { - // TODO(dsinclair): These should pull the real today values instead of - // pretending it's 2011-01-01. - m_iYear = 2011; - m_iMonth = 1; - m_iDay = 1; - m_iCurYear = m_iYear; - m_iCurMonth = m_iMonth; - - GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday); - GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); - m_dtMin = DATE(1500, 12, 1); - m_dtMax = DATE(2200, 1, 1); -} - -void CFWL_MonthCalendar::ClearDateItem() { - for (int32_t i = 0; i < m_arrDates.GetSize(); i++) - delete m_arrDates.GetAt(i); - m_arrDates.RemoveAll(); -} - -void CFWL_MonthCalendar::ResetDateItem() { - m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); - int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); - int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek(); - for (int32_t i = 0; i < iDays; i++) { - if (iDayOfWeek >= 7) - iDayOfWeek = 0; - - CFX_WideString wsDay; - wsDay.Format(L"%d", i + 1); - uint32_t dwStates = 0; - if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) - dwStates |= FWL_ITEMSTATE_MCD_Flag; - if (m_arrSelDays.Find(i + 1) != -1) - dwStates |= FWL_ITEMSTATE_MCD_Selected; - - CFX_RectF rtDate; - rtDate.Set(0, 0, 0, 0); - m_arrDates.Add(new DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay)); - iDayOfWeek++; - } -} - -void CFWL_MonthCalendar::NextMonth() { - int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; - if (iMonth >= 12) { - iMonth = 1; - iYear++; - } else { - iMonth++; - } - DATE dt(m_iCurYear, m_iCurMonth, 1); - if (!(dt < m_dtMax)) - return; - - m_iCurYear = iYear, m_iCurMonth = iMonth; - ChangeToMonth(m_iCurYear, m_iCurMonth); -} - -void CFWL_MonthCalendar::PrevMonth() { - int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; - if (iMonth <= 1) { - iMonth = 12; - iYear--; - } else { - iMonth--; - } - - DATE dt(m_iCurYear, m_iCurMonth, 1); - if (!(dt > m_dtMin)) - return; - - m_iCurYear = iYear, m_iCurMonth = iMonth; - ChangeToMonth(m_iCurYear, m_iCurMonth); -} - -void CFWL_MonthCalendar::ChangeToMonth(int32_t iYear, int32_t iMonth) { - m_iCurYear = iYear; - m_iCurMonth = iMonth; - m_iHovered = -1; - - ClearDateItem(); - ResetDateItem(); - CalDateItem(); - GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); -} - -void CFWL_MonthCalendar::RemoveSelDay() { - int32_t iCount = m_arrSelDays.GetSize(); - int32_t iDatesCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - int32_t iSelDay = m_arrSelDays.GetAt(i); - if (iSelDay <= iDatesCount) { - DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); - pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; - } - } - m_arrSelDays.RemoveAll(); - return; -} - -void CFWL_MonthCalendar::AddSelDay(int32_t iDay) { - ASSERT(iDay > 0); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) - return; - - if (m_arrSelDays.Find(iDay) != -1) - return; - - RemoveSelDay(); - if (iDay <= m_arrDates.GetSize()) { - DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); - pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; - } - m_arrSelDays.Add(iDay); -} - -void CFWL_MonthCalendar::JumpToToday() { - if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { - m_iCurYear = m_iYear; - m_iCurMonth = m_iMonth; - ChangeToMonth(m_iYear, m_iMonth); - AddSelDay(m_iDay); - return; - } - - if (m_arrSelDays.Find(m_iDay) == -1) - AddSelDay(m_iDay); -} - -void CFWL_MonthCalendar::GetHeadText(int32_t iYear, - int32_t iMonth, - CFX_WideString& wsHead) { - ASSERT(iMonth > 0 && iMonth < 13); - static const FX_WCHAR* const pMonth[] = { - L"January", L"February", L"March", L"April", - L"May", L"June", L"July", L"August", - L"September", L"October", L"November", L"December"}; - wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear); -} - -void CFWL_MonthCalendar::GetTodayText(int32_t iYear, - int32_t iMonth, - int32_t iDay, - CFX_WideString& wsToday) { - wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear); -} - -int32_t CFWL_MonthCalendar::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { - int32_t iCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - DATEINFO* pDateInfo = m_arrDates.GetAt(i); - if (pDateInfo->rect.Contains(x, y)) - return ++i; - } - return -1; -} - -void CFWL_MonthCalendar::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { - if (iDay <= 0 || iDay > m_arrDates.GetSize()) - return; - - DATEINFO* pDateInfo = m_arrDates[iDay - 1]; - if (!pDateInfo) - return; - rtDay = pDateInfo->rect; -} - -void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - case CFWL_Message::Type::KillFocus: - GetOuter()->GetDelegate()->OnProcessMessage(pMessage); - break; - case CFWL_Message::Type::Key: - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMouse = static_cast(pMessage); - switch (pMouse->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMouse); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMouse); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMouse); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMouse); - break; - default: - break; - } - break; - } - default: - break; - } - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { - if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iLBtnPartStates = CFWL_PartState_Pressed; - PrevMonth(); - Repaint(&m_rtClient); - } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iRBtnPartStates |= CFWL_PartState_Pressed; - NextMonth(); - Repaint(&m_rtClient); - } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { - JumpToToday(); - Repaint(&m_rtClient); - } - } else { - CFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); - if (pIPicker->IsMonthCalendarVisible()) - m_bFlag = 1; - } -} - -void CFWL_MonthCalendar::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_OnLButtonUp(pMsg); - - if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iLBtnPartStates = 0; - Repaint(&m_rtLBtn); - return; - } - if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iRBtnPartStates = 0; - Repaint(&m_rtRBtn); - return; - } - if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - int32_t iOldSel = 0; - if (m_arrSelDays.GetSize() > 0) - iOldSel = m_arrSelDays[0]; - - int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - CFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); - CFX_RectF rt = pIPicker->GetFormProxy()->GetWidgetRect(); - rt.Set(0, 0, rt.width, rt.height); - if (iCurSel > 0) { - DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); - CFX_RectF rtInvalidate(lpDatesInfo->rect); - if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { - lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); - rtInvalidate.Union(lpDatesInfo->rect); - } - AddSelDay(iCurSel); - if (!m_pOuter) - return; - - pIPicker->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); - pIPicker->ShowMonthCalendar(false); - } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { - pIPicker->ShowMonthCalendar(false); - } - m_bFlag = 0; -} - -void CFWL_MonthCalendar::DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iLBtnPartStates = 0; - Repaint(&(m_rtLBtn)); - return; - } - if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iRBtnPartStates = 0; - Repaint(&(m_rtRBtn)); - return; - } - if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - int32_t iOldSel = 0; - if (m_arrSelDays.GetSize() > 0) - iOldSel = m_arrSelDays[0]; - - int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - if (iCurSel > 0) { - DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); - CFX_RectF rtInvalidate(lpDatesInfo->rect); - if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { - lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); - rtInvalidate.Union(lpDatesInfo->rect); - } - AddSelDay(iCurSel); - CFWL_DateTimePicker* pDateTime = - static_cast(m_pOuter); - pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); - pDateTime->ShowMonthCalendar(false); - } -} - -void CFWL_MonthCalendar::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) - return; - - bool bRepaint = false; - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, 0, 0); - if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { - int32_t iHover = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - bRepaint = m_iHovered != iHover; - if (bRepaint) { - if (m_iHovered > 0) - GetDayRect(m_iHovered, rtInvalidate); - if (iHover > 0) { - CFX_RectF rtDay; - GetDayRect(iHover, rtDay); - if (rtInvalidate.IsEmpty()) - rtInvalidate = rtDay; - else - rtInvalidate.Union(rtDay); - } - } - m_iHovered = iHover; - } else { - bRepaint = m_iHovered > 0; - if (bRepaint) - GetDayRect(m_iHovered, rtInvalidate); - - m_iHovered = -1; - } - if (bRepaint && !rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void CFWL_MonthCalendar::OnMouseLeave(CFWL_MsgMouse* pMsg) { - if (m_iHovered <= 0) - return; - - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, 0, 0); - GetDayRect(m_iHovered, rtInvalidate); - m_iHovered = -1; - if (!rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -CFWL_MonthCalendar::DATEINFO::DATEINFO(int32_t day, - int32_t dayofweek, - uint32_t dwSt, - CFX_RectF rc, - CFX_WideString& wsday) - : iDay(day), - iDayOfWeek(dayofweek), - dwStates(dwSt), - rect(rc), - wsDay(wsday) {} - -CFWL_MonthCalendar::DATEINFO::~DATEINFO() {} diff --git a/xfa/fwl/core/cfwl_monthcalendar.h b/xfa/fwl/core/cfwl_monthcalendar.h deleted file mode 100644 index 7586a586f6..0000000000 --- a/xfa/fwl/core/cfwl_monthcalendar.h +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MONTHCALENDAR_H_ -#define XFA_FWL_CORE_CFWL_MONTHCALENDAR_H_ - -#include - -#include "xfa/fgas/localization/fgas_datetime.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_STYLEEXT_MCD_MultiSelect (1L << 0) -#define FWL_STYLEEXT_MCD_NoToday (1L << 1) -#define FWL_STYLEEXT_MCD_NoTodayCircle (1L << 2) -#define FWL_STYLEEXT_MCD_WeekNumbers (1L << 3) -#define FWL_ITEMSTATE_MCD_Nomal (0L << 0) -#define FWL_ITEMSTATE_MCD_Flag (1L << 0) -#define FWL_ITEMSTATE_MCD_Selected (1L << 1) -#define FWL_ITEMSTATE_MCD_Focused (1L << 2) - -class CFWL_MsgMouse; -class CFWL_Widget; - -class CFWL_MonthCalendar : public CFWL_Widget { - public: - CFWL_MonthCalendar(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_MonthCalendar() override; - - // FWL_WidgetImp - FWL_Type GetClassID() const override; - CFX_RectF GetAutosizedWidgetRect() override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay); - - private: - struct DATE { - DATE() : iYear(0), iMonth(0), iDay(0) {} - - DATE(int32_t year, int32_t month, int32_t day) - : iYear(year), iMonth(month), iDay(day) {} - - bool operator<(const DATE& right) { - if (iYear < right.iYear) - return true; - if (iYear == right.iYear) { - if (iMonth < right.iMonth) - return true; - if (iMonth == right.iMonth) - return iDay < right.iDay; - } - return false; - } - - bool operator>(const DATE& right) { - if (iYear > right.iYear) - return true; - if (iYear == right.iYear) { - if (iMonth > right.iMonth) - return true; - if (iMonth == right.iMonth) - return iDay > right.iDay; - } - return false; - } - - int32_t iYear; - int32_t iMonth; - int32_t iDay; - }; - struct DATEINFO { - DATEINFO(int32_t day, - int32_t dayofweek, - uint32_t dwSt, - CFX_RectF rc, - CFX_WideString& wsday); - ~DATEINFO(); - - int32_t iDay; - int32_t iDayOfWeek; - uint32_t dwStates; - CFX_RectF rect; - CFX_WideString wsDay; - }; - - void DrawBackground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawHeadBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawLButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawRButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawCaption(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawSeperator(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesInBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawWeek(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawWeekNumber(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawWeekNumberSep(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawToday(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesIn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesOut(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesInCircle(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - CFX_SizeF CalcSize(); - void Layout(); - void CalcHeadSize(); - void CalcTodaySize(); - void CalDateItem(); - void GetCapValue(); - void InitDate(); - void ClearDateItem(); - void ResetDateItem(); - void NextMonth(); - void PrevMonth(); - void ChangeToMonth(int32_t iYear, int32_t iMonth); - void RemoveSelDay(); - void AddSelDay(int32_t iDay); - void JumpToToday(); - void GetHeadText(int32_t iYear, int32_t iMonth, CFX_WideString& wsHead); - void GetTodayText(int32_t iYear, - int32_t iMonth, - int32_t iDay, - CFX_WideString& wsToday); - int32_t GetDayAtPoint(FX_FLOAT x, FX_FLOAT y); - void GetDayRect(int32_t iDay, CFX_RectF& rtDay); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - - bool m_bInitialized; - CFX_RectF m_rtHead; - CFX_RectF m_rtWeek; - CFX_RectF m_rtLBtn; - CFX_RectF m_rtRBtn; - CFX_RectF m_rtDates; - CFX_RectF m_rtHSep; - CFX_RectF m_rtHeadText; - CFX_RectF m_rtToday; - CFX_RectF m_rtTodayFlag; - CFX_RectF m_rtWeekNum; - CFX_RectF m_rtWeekNumSep; - CFX_WideString m_wsHead; - CFX_WideString m_wsToday; - std::unique_ptr m_pDateTime; - CFX_ArrayTemplate m_arrDates; - int32_t m_iCurYear; - int32_t m_iCurMonth; - int32_t m_iYear; - int32_t m_iMonth; - int32_t m_iDay; - int32_t m_iHovered; - int32_t m_iLBtnPartStates; - int32_t m_iRBtnPartStates; - DATE m_dtMin; - DATE m_dtMax; - CFX_SizeF m_szHead; - CFX_SizeF m_szCell; - CFX_SizeF m_szToday; - CFX_ArrayTemplate m_arrSelDays; - CFX_RectF m_rtClient; - FX_FLOAT m_fHeadWid; - FX_FLOAT m_fHeadHei; - FX_FLOAT m_fHeadBtnWid; - FX_FLOAT m_fHeadBtnHei; - FX_FLOAT m_fHeadBtnHMargin; - FX_FLOAT m_fHeadBtnVMargin; - FX_FLOAT m_fHeadTextWid; - FX_FLOAT m_fHeadTextHei; - FX_FLOAT m_fHeadTextHMargin; - FX_FLOAT m_fHeadTextVMargin; - FX_FLOAT m_fHSepWid; - FX_FLOAT m_fHSepHei; - FX_FLOAT m_fWeekNumWid; - FX_FLOAT m_fSepDOffset; - FX_FLOAT m_fSepX; - FX_FLOAT m_fSepY; - FX_FLOAT m_fWeekNumHeigh; - FX_FLOAT m_fWeekWid; - FX_FLOAT m_fWeekHei; - FX_FLOAT m_fDateCellWid; - FX_FLOAT m_fDateCellHei; - FX_FLOAT m_fTodayWid; - FX_FLOAT m_fTodayHei; - FX_FLOAT m_fTodayFlagWid; - FX_FLOAT m_fMCWid; - FX_FLOAT m_fMCHei; - bool m_bFlag; -}; - -#endif // XFA_FWL_CORE_CFWL_MONTHCALENDAR_H_ diff --git a/xfa/fwl/core/cfwl_msgkey.cpp b/xfa/fwl/core/cfwl_msgkey.cpp deleted file mode 100644 index 3eda29ab49..0000000000 --- a/xfa/fwl/core/cfwl_msgkey.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_msgkey.h" - -#include - -#include "third_party/base/ptr_util.h" - -CFWL_MsgKey::CFWL_MsgKey(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget) - : CFWL_Message(CFWL_Message::Type::Key, pSrcTarget, pDstTarget) {} - -CFWL_MsgKey::~CFWL_MsgKey() {} - -std::unique_ptr CFWL_MsgKey::Clone() { - return pdfium::MakeUnique(*this); -} diff --git a/xfa/fwl/core/cfwl_msgkey.h b/xfa/fwl/core/cfwl_msgkey.h deleted file mode 100644 index 36089ea43e..0000000000 --- a/xfa/fwl/core/cfwl_msgkey.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MSGKEY_H_ -#define XFA_FWL_CORE_CFWL_MSGKEY_H_ - -#include - -#include "xfa/fwl/core/cfwl_message.h" - -enum class FWL_KeyCommand { KeyDown, KeyUp, Char }; - -class CFWL_MsgKey : public CFWL_Message { - public: - CFWL_MsgKey(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - ~CFWL_MsgKey() override; - - // CFWL_Message - std::unique_ptr Clone() override; - - uint32_t m_dwKeyCode; - uint32_t m_dwFlags; - FWL_KeyCommand m_dwCmd; -}; - -#endif // XFA_FWL_CORE_CFWL_MSGKEY_H_ diff --git a/xfa/fwl/core/cfwl_msgkillfocus.cpp b/xfa/fwl/core/cfwl_msgkillfocus.cpp deleted file mode 100644 index c7164850d1..0000000000 --- a/xfa/fwl/core/cfwl_msgkillfocus.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_msgkillfocus.h" - -#include - -#include "third_party/base/ptr_util.h" - -CFWL_MsgKillFocus::CFWL_MsgKillFocus(CFWL_Widget* pSrcTarget) - : CFWL_MsgKillFocus(pSrcTarget, nullptr) {} - -CFWL_MsgKillFocus::CFWL_MsgKillFocus(CFWL_Widget* pSrcTarget, - CFWL_Widget* pDstTarget) - : CFWL_Message(CFWL_Message::Type::KillFocus, pSrcTarget, pDstTarget) {} - -CFWL_MsgKillFocus::~CFWL_MsgKillFocus() {} - -std::unique_ptr CFWL_MsgKillFocus::Clone() { - return pdfium::MakeUnique(*this); -} diff --git a/xfa/fwl/core/cfwl_msgkillfocus.h b/xfa/fwl/core/cfwl_msgkillfocus.h deleted file mode 100644 index 1c176b122a..0000000000 --- a/xfa/fwl/core/cfwl_msgkillfocus.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MSGKILLFOCUS_H_ -#define XFA_FWL_CORE_CFWL_MSGKILLFOCUS_H_ - -#include - -#include "xfa/fwl/core/cfwl_message.h" - -class CFWL_MsgKillFocus : public CFWL_Message { - public: - explicit CFWL_MsgKillFocus(CFWL_Widget* pSrcTarget); - CFWL_MsgKillFocus(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - ~CFWL_MsgKillFocus() override; - - // CFWL_Message - std::unique_ptr Clone() override; - - CFWL_Widget* m_pSetFocus; -}; - -#endif // XFA_FWL_CORE_CFWL_MSGKILLFOCUS_H_ diff --git a/xfa/fwl/core/cfwl_msgmouse.cpp b/xfa/fwl/core/cfwl_msgmouse.cpp deleted file mode 100644 index f8a4e64608..0000000000 --- a/xfa/fwl/core/cfwl_msgmouse.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_msgmouse.h" - -#include - -#include "third_party/base/ptr_util.h" - -CFWL_MsgMouse::CFWL_MsgMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget) - : CFWL_Message(CFWL_Message::Type::Mouse, pSrcTarget, pDstTarget) {} - -CFWL_MsgMouse::~CFWL_MsgMouse() {} - -std::unique_ptr CFWL_MsgMouse::Clone() { - return pdfium::MakeUnique(*this); -} diff --git a/xfa/fwl/core/cfwl_msgmouse.h b/xfa/fwl/core/cfwl_msgmouse.h deleted file mode 100644 index 0765cbc500..0000000000 --- a/xfa/fwl/core/cfwl_msgmouse.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MSGMOUSE_H_ -#define XFA_FWL_CORE_CFWL_MSGMOUSE_H_ - -#include - -#include "xfa/fwl/core/cfwl_message.h" - -enum class FWL_MouseCommand { - LeftButtonDown, - LeftButtonUp, - LeftButtonDblClk, - RightButtonDown, - RightButtonUp, - RightButtonDblClk, - Move, - Enter, - Leave, - Hover -}; - -class CFWL_MsgMouse : public CFWL_Message { - public: - CFWL_MsgMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - ~CFWL_MsgMouse() override; - - // CFWL_Message - std::unique_ptr Clone() override; - - FX_FLOAT m_fx; - FX_FLOAT m_fy; - uint32_t m_dwFlags; - FWL_MouseCommand m_dwCmd; -}; - -#endif // XFA_FWL_CORE_CFWL_MSGMOUSE_H_ diff --git a/xfa/fwl/core/cfwl_msgmousewheel.cpp b/xfa/fwl/core/cfwl_msgmousewheel.cpp deleted file mode 100644 index 02629ec909..0000000000 --- a/xfa/fwl/core/cfwl_msgmousewheel.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_msgmousewheel.h" - -#include - -#include "third_party/base/ptr_util.h" - -CFWL_MsgMouseWheel::CFWL_MsgMouseWheel(CFWL_Widget* pSrcTarget, - CFWL_Widget* pDstTarget) - : CFWL_Message(CFWL_Message::Type::MouseWheel, pSrcTarget, pDstTarget) {} - -CFWL_MsgMouseWheel::~CFWL_MsgMouseWheel() {} - -std::unique_ptr CFWL_MsgMouseWheel::Clone() { - return pdfium::MakeUnique(*this); -} diff --git a/xfa/fwl/core/cfwl_msgmousewheel.h b/xfa/fwl/core/cfwl_msgmousewheel.h deleted file mode 100644 index 503bcdebe8..0000000000 --- a/xfa/fwl/core/cfwl_msgmousewheel.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MSGMOUSEWHEEL_H_ -#define XFA_FWL_CORE_CFWL_MSGMOUSEWHEEL_H_ - -#include - -#include "xfa/fwl/core/cfwl_message.h" - -class CFWL_MsgMouseWheel : public CFWL_Message { - public: - CFWL_MsgMouseWheel(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - ~CFWL_MsgMouseWheel() override; - - // CFWL_Message - std::unique_ptr Clone() override; - - FX_FLOAT m_fx; - FX_FLOAT m_fy; - FX_FLOAT m_fDeltaX; - FX_FLOAT m_fDeltaY; - uint32_t m_dwFlags; -}; - -#endif // XFA_FWL_CORE_CFWL_MSGMOUSEWHEEL_H_ diff --git a/xfa/fwl/core/cfwl_msgsetfocus.cpp b/xfa/fwl/core/cfwl_msgsetfocus.cpp deleted file mode 100644 index 82e9610b15..0000000000 --- a/xfa/fwl/core/cfwl_msgsetfocus.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_msgsetfocus.h" - -#include - -#include "third_party/base/ptr_util.h" - -CFWL_MsgSetFocus::CFWL_MsgSetFocus(CFWL_Widget* pSrcTarget, - CFWL_Widget* pDstTarget) - : CFWL_Message(CFWL_Message::Type::SetFocus, pSrcTarget, pDstTarget) {} - -CFWL_MsgSetFocus::~CFWL_MsgSetFocus() {} - -std::unique_ptr CFWL_MsgSetFocus::Clone() { - return pdfium::MakeUnique(*this); -} diff --git a/xfa/fwl/core/cfwl_msgsetfocus.h b/xfa/fwl/core/cfwl_msgsetfocus.h deleted file mode 100644 index 628f7a6d66..0000000000 --- a/xfa/fwl/core/cfwl_msgsetfocus.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_MSGSETFOCUS_H_ -#define XFA_FWL_CORE_CFWL_MSGSETFOCUS_H_ - -#include - -#include "xfa/fwl/core/cfwl_message.h" - -class CFWL_MsgSetFocus : public CFWL_Message { - public: - CFWL_MsgSetFocus(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget); - ~CFWL_MsgSetFocus() override; - - // CFWL_Message - std::unique_ptr Clone() override; -}; - -#endif // XFA_FWL_CORE_CFWL_MSGSETFOCUS_H_ diff --git a/xfa/fwl/core/cfwl_notedriver.cpp b/xfa/fwl/core/cfwl_notedriver.cpp deleted file mode 100644 index 8402b2b90c..0000000000 --- a/xfa/fwl/core/cfwl_notedriver.cpp +++ /dev/null @@ -1,480 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_notedriver.h" - -#include - -#include "core/fxcrt/fx_ext.h" -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_eventtarget.h" -#include "xfa/fwl/core/cfwl_form.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgmousewheel.h" -#include "xfa/fwl/core/cfwl_msgsetfocus.h" -#include "xfa/fwl/core/cfwl_noteloop.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" - -CFWL_NoteDriver::CFWL_NoteDriver() - : m_pHover(nullptr), - m_pFocus(nullptr), - m_pGrab(nullptr), - m_pNoteLoop(pdfium::MakeUnique()) { - PushNoteLoop(m_pNoteLoop.get()); -} - -CFWL_NoteDriver::~CFWL_NoteDriver() { - ClearEventTargets(true); -} - -void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { - if (m_eventTargets.empty()) - return; - - for (const auto& pair : m_eventTargets) { - CFWL_EventTarget* pEventTarget = pair.second; - if (pEventTarget && !pEventTarget->IsInvalid()) - pEventTarget->ProcessEvent(pNote); - } -} - -void CFWL_NoteDriver::RegisterEventTarget(CFWL_Widget* pListener, - CFWL_Widget* pEventSource) { - uint32_t key = pListener->GetEventKey(); - if (key == 0) { - do { - key = rand(); - } while (key == 0 || pdfium::ContainsKey(m_eventTargets, key)); - pListener->SetEventKey(key); - } - if (!m_eventTargets[key]) - m_eventTargets[key] = new CFWL_EventTarget(pListener); - - m_eventTargets[key]->SetEventSource(pEventSource); -} - -void CFWL_NoteDriver::UnregisterEventTarget(CFWL_Widget* pListener) { - uint32_t key = pListener->GetEventKey(); - if (key == 0) - return; - - auto it = m_eventTargets.find(key); - if (it != m_eventTargets.end()) - it->second->FlagInvalid(); -} - -void CFWL_NoteDriver::PushNoteLoop(CFWL_NoteLoop* pNoteLoop) { - m_noteLoopQueue.Add(pNoteLoop); -} - -CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() { - int32_t pos = m_noteLoopQueue.GetSize(); - if (pos <= 0) - return nullptr; - - CFWL_NoteLoop* p = m_noteLoopQueue.GetAt(pos - 1); - m_noteLoopQueue.RemoveAt(pos - 1); - return p; -} - -bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) { - if (m_pFocus == pFocus) - return true; - - CFWL_Widget* pPrev = m_pFocus; - m_pFocus = pFocus; - if (pPrev) { - if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) { - CFWL_MsgKillFocus ms(pPrev, pPrev); - pDelegate->OnProcessMessage(&ms); - } - } - if (pFocus) { - CFWL_Widget* pWidget = - pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus); - CFWL_Form* pForm = static_cast(pWidget); - if (pForm) - pForm->SetSubFocus(pFocus); - - if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) { - CFWL_MsgSetFocus ms(nullptr, pFocus); - pDelegate->OnProcessMessage(&ms); - } - } - return true; -} - -void CFWL_NoteDriver::Run() { -#if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \ - _FX_OS_ == _FX_WIN64_) - for (;;) { - CFWL_NoteLoop* pTopLoop = GetTopLoop(); - if (!pTopLoop || !pTopLoop->ContinueModal()) - break; - UnqueueMessage(pTopLoop); - } -#endif -} - -void CFWL_NoteDriver::NotifyTargetHide(CFWL_Widget* pNoteTarget) { - if (m_pFocus == pNoteTarget) - m_pFocus = nullptr; - if (m_pHover == pNoteTarget) - m_pHover = nullptr; - if (m_pGrab == pNoteTarget) - m_pGrab = nullptr; -} - -void CFWL_NoteDriver::NotifyTargetDestroy(CFWL_Widget* pNoteTarget) { - if (m_pFocus == pNoteTarget) - m_pFocus = nullptr; - if (m_pHover == pNoteTarget) - m_pHover = nullptr; - if (m_pGrab == pNoteTarget) - m_pGrab = nullptr; - - UnregisterEventTarget(pNoteTarget); - - for (int32_t nIndex = 0; nIndex < m_forms.GetSize(); nIndex++) { - CFWL_Form* pForm = static_cast(m_forms[nIndex]); - if (!pForm) - continue; - - CFWL_Widget* pSubFocus = pForm->GetSubFocus(); - if (!pSubFocus) - return; - if (pSubFocus == pNoteTarget) - pForm->SetSubFocus(nullptr); - } -} - -void CFWL_NoteDriver::RegisterForm(CFWL_Widget* pForm) { - if (!pForm || m_forms.Find(pForm) >= 0) - return; - - m_forms.Add(pForm); - if (m_forms.GetSize() != 1) - return; - - CFWL_NoteLoop* pLoop = m_noteLoopQueue.GetAt(0); - if (!pLoop) - return; - - pLoop->SetMainForm(pForm); -} - -void CFWL_NoteDriver::UnRegisterForm(CFWL_Widget* pForm) { - if (!pForm) - return; - - int32_t nIndex = m_forms.Find(pForm); - if (nIndex < 0) - return; - - m_forms.RemoveAt(nIndex); -} - -void CFWL_NoteDriver::QueueMessage(std::unique_ptr pMessage) { - m_noteQueue.push_back(std::move(pMessage)); -} - -void CFWL_NoteDriver::UnqueueMessage(CFWL_NoteLoop* pNoteLoop) { - if (m_noteQueue.empty()) - return; - - std::unique_ptr pMessage = std::move(m_noteQueue[0]); - m_noteQueue.pop_front(); - - if (!IsValidMessage(pMessage.get())) - return; - - ProcessMessage(pMessage.get()); -} - -CFWL_NoteLoop* CFWL_NoteDriver::GetTopLoop() const { - int32_t size = m_noteLoopQueue.GetSize(); - if (size <= 0) - return nullptr; - return m_noteLoopQueue[size - 1]; -} - -void CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) { - CFWL_WidgetMgr* pWidgetMgr = - pMessage->m_pDstTarget->GetOwnerApp()->GetWidgetMgr(); - CFWL_Widget* pMessageForm = pWidgetMgr->IsFormDisabled() - ? pMessage->m_pDstTarget - : GetMessageForm(pMessage->m_pDstTarget); - if (!pMessageForm) - return; - if (!DispatchMessage(pMessage, pMessageForm)) - return; - - if (pMessage->GetType() == CFWL_Message::Type::Mouse) - MouseSecondary(pMessage); -} - -bool CFWL_NoteDriver::DispatchMessage(CFWL_Message* pMessage, - CFWL_Widget* pMessageForm) { - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: { - if (!DoSetFocus(pMessage, pMessageForm)) - return false; - break; - } - case CFWL_Message::Type::KillFocus: { - if (!DoKillFocus(pMessage, pMessageForm)) - return false; - break; - } - case CFWL_Message::Type::Key: { - if (!DoKey(pMessage, pMessageForm)) - return false; - break; - } - case CFWL_Message::Type::Mouse: { - if (!DoMouse(pMessage, pMessageForm)) - return false; - break; - } - case CFWL_Message::Type::MouseWheel: { - if (!DoWheel(pMessage, pMessageForm)) - return false; - break; - } - default: - break; - } - if (IFWL_WidgetDelegate* pDelegate = pMessage->m_pDstTarget->GetDelegate()) - pDelegate->OnProcessMessage(pMessage); - - return true; -} - -bool CFWL_NoteDriver::DoSetFocus(CFWL_Message* pMessage, - CFWL_Widget* pMessageForm) { - CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); - if (pWidgetMgr->IsFormDisabled()) { - m_pFocus = pMessage->m_pDstTarget; - return true; - } - - CFWL_Widget* pWidget = pMessage->m_pDstTarget; - if (!pWidget) - return false; - - CFWL_Form* pForm = static_cast(pWidget); - CFWL_Widget* pSubFocus = pForm->GetSubFocus(); - if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) { - pMessage->m_pDstTarget = pSubFocus; - if (m_pFocus != pMessage->m_pDstTarget) { - m_pFocus = pMessage->m_pDstTarget; - return true; - } - } - return false; -} - -bool CFWL_NoteDriver::DoKillFocus(CFWL_Message* pMessage, - CFWL_Widget* pMessageForm) { - CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); - if (pWidgetMgr->IsFormDisabled()) { - if (m_pFocus == pMessage->m_pDstTarget) - m_pFocus = nullptr; - return true; - } - - CFWL_Form* pForm = static_cast(pMessage->m_pDstTarget); - if (!pForm) - return false; - - CFWL_Widget* pSubFocus = pForm->GetSubFocus(); - if (pSubFocus && (pSubFocus->GetStates() & FWL_WGTSTATE_Focused)) { - pMessage->m_pDstTarget = pSubFocus; - if (m_pFocus == pMessage->m_pDstTarget) { - m_pFocus = nullptr; - return true; - } - } - return false; -} - -bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) { - CFWL_MsgKey* pMsg = static_cast(pMessage); -#if (_FX_OS_ != _FX_MACOSX_) - if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && - pMsg->m_dwKeyCode == FWL_VKEY_Tab) { - CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); - CFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget); - CFWL_Widget* pFocus = m_pFocus; - if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) - pFocus = nullptr; - - bool bFind = false; - CFWL_Widget* pNextTabStop = pWidgetMgr->NextTab(pForm, pFocus, bFind); - if (!pNextTabStop) { - bFind = false; - pNextTabStop = pWidgetMgr->NextTab(pForm, nullptr, bFind); - } - if (pNextTabStop == pFocus) - return true; - if (pNextTabStop) - SetFocus(pNextTabStop); - return true; - } -#endif - - if (!m_pFocus) { - if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && - pMsg->m_dwKeyCode == FWL_VKEY_Return) { - CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); - CFWL_Widget* defButton = pWidgetMgr->GetDefaultButton(pMessageForm); - if (defButton) { - pMsg->m_pDstTarget = defButton; - return true; - } - } - return false; - } - pMsg->m_pDstTarget = m_pFocus; - return true; -} - -bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage, - CFWL_Widget* pMessageForm) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (pMsg->m_dwCmd == FWL_MouseCommand::Leave || - pMsg->m_dwCmd == FWL_MouseCommand::Hover || - pMsg->m_dwCmd == FWL_MouseCommand::Enter) { - return !!pMsg->m_pDstTarget; - } - if (pMsg->m_pDstTarget != pMessageForm) - pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy); - if (!DoMouseEx(pMsg, pMessageForm)) - pMsg->m_pDstTarget = pMessageForm; - return true; -} - -bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage, - CFWL_Widget* pMessageForm) { - CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr) - return false; - - CFWL_MsgMouseWheel* pMsg = static_cast(pMessage); - CFWL_Widget* pDst = - pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); - if (!pDst) - return false; - - pMessageForm->TransformTo(pDst, pMsg->m_fx, pMsg->m_fy); - pMsg->m_pDstTarget = pDst; - return true; -} - -bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage, - CFWL_Widget* pMessageForm) { - CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr) - return false; - CFWL_Widget* pTarget = nullptr; - if (m_pGrab) - pTarget = m_pGrab; - - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (!pTarget) { - pTarget = - pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); - } - if (pTarget) { - if (pMessageForm != pTarget) - pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy); - } - if (!pTarget) - return false; - - pMsg->m_pDstTarget = pTarget; - return true; -} - -void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { - CFWL_Widget* pTarget = pMessage->m_pDstTarget; - if (pTarget == m_pHover) - return; - - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (m_pHover) { - CFWL_MsgMouse msLeave(nullptr, m_pHover); - msLeave.m_fx = pMsg->m_fx; - msLeave.m_fy = pMsg->m_fy; - pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy); - - msLeave.m_dwFlags = 0; - msLeave.m_dwCmd = FWL_MouseCommand::Leave; - DispatchMessage(&msLeave, nullptr); - } - if (pTarget->GetClassID() == FWL_Type::Form) { - m_pHover = nullptr; - return; - } - m_pHover = pTarget; - - CFWL_MsgMouse msHover(nullptr, pTarget); - msHover.m_fx = pMsg->m_fx; - msHover.m_fy = pMsg->m_fy; - msHover.m_dwFlags = 0; - msHover.m_dwCmd = FWL_MouseCommand::Hover; - DispatchMessage(&msHover, nullptr); -} - -bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { - for (int32_t i = 0; i < m_noteLoopQueue.GetSize(); i++) { - CFWL_NoteLoop* pNoteLoop = m_noteLoopQueue[i]; - CFWL_Widget* pForm = pNoteLoop->GetForm(); - if (pForm && (pForm == pMessage->m_pDstTarget)) - return true; - } - - for (int32_t j = 0; j < m_forms.GetSize(); j++) { - CFWL_Form* pForm = static_cast(m_forms[j]); - if (pForm == pMessage->m_pDstTarget) - return true; - } - return false; -} - -CFWL_Widget* CFWL_NoteDriver::GetMessageForm(CFWL_Widget* pDstTarget) { - int32_t iTrackLoop = m_noteLoopQueue.GetSize(); - if (iTrackLoop <= 0) - return nullptr; - - CFWL_Widget* pMessageForm = nullptr; - if (iTrackLoop > 1) - pMessageForm = m_noteLoopQueue[iTrackLoop - 1]->GetForm(); - else if (m_forms.Find(pDstTarget) < 0) - pMessageForm = pDstTarget; - if (!pMessageForm && pDstTarget) { - CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr) - return nullptr; - pMessageForm = pWidgetMgr->GetSystemFormWidget(pDstTarget); - } - return pMessageForm; -} - -void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { - auto it = m_eventTargets.begin(); - while (it != m_eventTargets.end()) { - auto old = it++; - if (old->second && (bRemoveAll || old->second->IsInvalid())) { - delete old->second; - m_eventTargets.erase(old); - } - } -} diff --git a/xfa/fwl/core/cfwl_notedriver.h b/xfa/fwl/core/cfwl_notedriver.h deleted file mode 100644 index 47f11daec3..0000000000 --- a/xfa/fwl/core/cfwl_notedriver.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_NOTEDRIVER_H_ -#define XFA_FWL_CORE_CFWL_NOTEDRIVER_H_ - -#include -#include -#include - -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_graphics.h" - -class CFWL_EventTarget; -class CFWL_NoteLoop; -class CFWL_TargetImp; -class CFWL_Widget; - -class CFWL_NoteDriver { - public: - CFWL_NoteDriver(); - ~CFWL_NoteDriver(); - - void SendEvent(CFWL_Event* pNote); - - void RegisterEventTarget(CFWL_Widget* pListener, CFWL_Widget* pEventSource); - void UnregisterEventTarget(CFWL_Widget* pListener); - void ClearEventTargets(bool bRemoveAll); - - CFWL_NoteLoop* GetTopLoop() const; - void PushNoteLoop(CFWL_NoteLoop* pNoteLoop); - CFWL_NoteLoop* PopNoteLoop(); - - CFWL_Widget* GetFocus() const { return m_pFocus; } - bool SetFocus(CFWL_Widget* pFocus); - void SetGrab(CFWL_Widget* pGrab, bool bSet) { - m_pGrab = bSet ? pGrab : nullptr; - } - - void Run(); - - void NotifyTargetHide(CFWL_Widget* pNoteTarget); - void NotifyTargetDestroy(CFWL_Widget* pNoteTarget); - - void RegisterForm(CFWL_Widget* pForm); - void UnRegisterForm(CFWL_Widget* pForm); - - void QueueMessage(std::unique_ptr pMessage); - void UnqueueMessage(CFWL_NoteLoop* pNoteLoop); - void ProcessMessage(CFWL_Message* pMessage); - - private: - bool DispatchMessage(CFWL_Message* pMessage, CFWL_Widget* pMessageForm); - bool DoSetFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); - bool DoKillFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); - bool DoKey(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); - bool DoMouse(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); - bool DoWheel(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); - bool DoMouseEx(CFWL_Message* pMsg, CFWL_Widget* pMessageForm); - void MouseSecondary(CFWL_Message* pMsg); - bool IsValidMessage(CFWL_Message* pMessage); - CFWL_Widget* GetMessageForm(CFWL_Widget* pDstTarget); - - CFX_ArrayTemplate m_forms; - std::deque> m_noteQueue; - CFX_ArrayTemplate m_noteLoopQueue; - std::unordered_map m_eventTargets; - CFWL_Widget* m_pHover; - CFWL_Widget* m_pFocus; - CFWL_Widget* m_pGrab; - std::unique_ptr m_pNoteLoop; -}; - -#endif // XFA_FWL_CORE_CFWL_NOTEDRIVER_H_ diff --git a/xfa/fwl/core/cfwl_noteloop.cpp b/xfa/fwl/core/cfwl_noteloop.cpp deleted file mode 100644 index 4b2b6105ed..0000000000 --- a/xfa/fwl/core/cfwl_noteloop.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_noteloop.h" - -CFWL_NoteLoop::CFWL_NoteLoop() : m_bContinueModal(true) {} diff --git a/xfa/fwl/core/cfwl_noteloop.h b/xfa/fwl/core/cfwl_noteloop.h deleted file mode 100644 index 20bc03f560..0000000000 --- a/xfa/fwl/core/cfwl_noteloop.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_NOTELOOP_H_ -#define XFA_FWL_CORE_CFWL_NOTELOOP_H_ - -class CFWL_Widget; - -class CFWL_NoteLoop { - public: - CFWL_NoteLoop(); - ~CFWL_NoteLoop() {} - - CFWL_Widget* GetForm() const { return m_pForm; } - bool ContinueModal() const { return m_bContinueModal; } - void EndModalLoop() { m_bContinueModal = false; } - void SetMainForm(CFWL_Widget* pForm) { m_pForm = pForm; } - - private: - CFWL_Widget* m_pForm; - bool m_bContinueModal; -}; - -#endif // XFA_FWL_CORE_CFWL_NOTELOOP_H_ diff --git a/xfa/fwl/core/cfwl_picturebox.cpp b/xfa/fwl/core/cfwl_picturebox.cpp deleted file mode 100644 index 96a52c9638..0000000000 --- a/xfa/fwl/core/cfwl_picturebox.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_picturebox.h" - -#include - -#include "third_party/base/ptr_util.h" - -CFWL_PictureBox::CFWL_PictureBox(const CFWL_App* app) - : CFWL_Widget(app, pdfium::MakeUnique(), nullptr) { - m_rtClient.Reset(); - m_rtImage.Reset(); - m_matrix.SetIdentity(); -} - -CFWL_PictureBox::~CFWL_PictureBox() {} - -FWL_Type CFWL_PictureBox::GetClassID() const { - return FWL_Type::PictureBox; -} - -void CFWL_PictureBox::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - GetClientRect(m_rtClient); -} - -void CFWL_PictureBox::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = GetAvailableTheme(); - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); -} - -void CFWL_PictureBox::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} diff --git a/xfa/fwl/core/cfwl_picturebox.h b/xfa/fwl/core/cfwl_picturebox.h deleted file mode 100644 index f4ece5bb2d..0000000000 --- a/xfa/fwl/core/cfwl_picturebox.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_PICTUREBOX_H_ -#define XFA_FWL_CORE_CFWL_PICTUREBOX_H_ - -#include - -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_STYLEEXT_PTB_Left 0L << 0 -#define FWL_STYLEEXT_PTB_Center 1L << 0 -#define FWL_STYLEEXT_PTB_Right 2L << 0 -#define FWL_STYLEEXT_PTB_Top 0L << 2 -#define FWL_STYLEEXT_PTB_Vcenter 1L << 2 -#define FWL_STYLEEXT_PTB_Bottom 2L << 2 -#define FWL_STYLEEXT_PTB_Normal 0L << 4 -#define FWL_STYLEEXT_PTB_AutoSize 1L << 4 -#define FWL_STYLEEXT_PTB_StretchImage 2L << 4 -#define FWL_STYLEEXT_PTB_StretchHImage 3L << 4 -#define FWL_STYLEEXT_PTB_StretchVImage 4L << 4 -#define FWL_STYLEEXT_PTB_HAlignMask 3L << 0 -#define FWL_STYLEEXT_PTB_VAlignMask 3L << 2 -#define FWL_STYLEEXT_PTB_StretchAlignMask 7L << 4 - -class CFX_DIBitmap; -class CFWL_Widget; - -class CFWL_PictureBox : public CFWL_Widget { - public: - explicit CFWL_PictureBox(const CFWL_App* pApp); - ~CFWL_PictureBox() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - private: - CFX_RectF m_rtClient; - CFX_RectF m_rtImage; - CFX_Matrix m_matrix; -}; - -#endif // XFA_FWL_CORE_CFWL_PICTUREBOX_H_ diff --git a/xfa/fwl/core/cfwl_pushbutton.cpp b/xfa/fwl/core/cfwl_pushbutton.cpp deleted file mode 100644 index d3bf7e6552..0000000000 --- a/xfa/fwl/core/cfwl_pushbutton.cpp +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_pushbutton.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_evtmouse.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -CFWL_PushButton::CFWL_PushButton(const CFWL_App* app) - : CFWL_Widget(app, pdfium::MakeUnique(), nullptr), - m_bBtnDown(false), - m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), - m_iTTOAlign(FDE_TTOALIGNMENT_Center) { - m_rtClient.Set(0, 0, 0, 0); - m_rtCaption.Set(0, 0, 0, 0); -} - -CFWL_PushButton::~CFWL_PushButton() {} - -FWL_Type CFWL_PushButton::GetClassID() const { - return FWL_Type::PushButton; -} - -void CFWL_PushButton::SetStates(uint32_t dwStates) { - if (dwStates & FWL_WGTSTATE_Disabled) { - m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; - return; - } - CFWL_Widget::SetStates(dwStates); -} - -void CFWL_PushButton::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - UpdateTextOutStyles(); - GetClientRect(m_rtClient); - m_rtCaption = m_rtClient; - FX_FLOAT* fcaption = - static_cast(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); - m_rtCaption.Inflate(-*fcaption, -*fcaption); -} - -void CFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - if (HasBorder()) { - DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, - pMatrix); - } - if (HasEdge()) { - DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, - pMatrix); - } - DrawBkground(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); -} - -void CFWL_PushButton::DrawBkground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_dwStates = GetPartStates(); - param.m_pGraphics = pGraphics; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtClient; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - param.m_pData = &m_rtCaption; - pTheme->DrawBackground(¶m); -} - -uint32_t CFWL_PushButton::GetPartStates() { - uint32_t dwStates = CFWL_PartState_Normal; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - dwStates |= CFWL_PartState_Focused; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - dwStates = CFWL_PartState_Disabled; - else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) - dwStates |= CFWL_PartState_Pressed; - else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) - dwStates |= CFWL_PartState_Hovered; - else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Default) - dwStates |= CFWL_PartState_Default; - return dwStates; -} - -void CFWL_PushButton::UpdateTextOutStyles() { - switch (m_pProperties->m_dwStyleExes & - (FWL_STYLEEXT_PSB_HLayoutMask | FWL_STYLEEXT_PSB_VLayoutMask)) { - case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Top: { - m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; - break; - } - case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Top: { - m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; - break; - } - case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Top: { - m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; - break; - } - case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_VCenter: { - m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - break; - } - case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_VCenter: { - m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; - break; - } - case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Bottom: { - m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; - break; - } - case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Bottom: { - m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; - break; - } - case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Bottom: { - m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; - break; - } - case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_VCenter: - default: { - m_iTTOAlign = FDE_TTOALIGNMENT_Center; - break; - } - } - m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) - m_dwTTOStyles |= FDE_TTOSTYLE_RTL; -} - -void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - if (!IsEnabled()) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: { - CFWL_MsgKey* pKey = static_cast(pMessage); - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) - OnKeyDown(pKey); - break; - } - default: - break; - } - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_PushButton::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_PushButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - else - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - - Repaint(&m_rtClient); -} - -void CFWL_PushButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - SetFocus(true); - - m_bBtnDown = true; - m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; - m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; - Repaint(&m_rtClient); -} - -void CFWL_PushButton::OnLButtonUp(CFWL_MsgMouse* pMsg) { - m_bBtnDown = false; - if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; - m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; - } else { - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; - } - if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { - CFWL_Event wmClick(CFWL_Event::Type::Click, this); - DispatchEvent(&wmClick); - } - Repaint(&m_rtClient); -} - -void CFWL_PushButton::OnMouseMove(CFWL_MsgMouse* pMsg) { - bool bRepaint = false; - if (m_bBtnDown) { - if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { - if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) { - m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; - bRepaint = true; - } - if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) { - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; - bRepaint = true; - } - } else { - if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) { - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; - bRepaint = true; - } - if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { - m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; - bRepaint = true; - } - } - } else { - if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { - m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; - bRepaint = true; - } - } - if (bRepaint) - Repaint(&m_rtClient); -} - -void CFWL_PushButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { - m_bBtnDown = false; - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; - m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; - Repaint(&m_rtClient); -} - -void CFWL_PushButton::OnKeyDown(CFWL_MsgKey* pMsg) { - if (pMsg->m_dwKeyCode != FWL_VKEY_Return) - return; - - CFWL_EvtMouse wmMouse(this); - wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp; - DispatchEvent(&wmMouse); - - CFWL_Event wmClick(CFWL_Event::Type::Click, this); - DispatchEvent(&wmClick); -} diff --git a/xfa/fwl/core/cfwl_pushbutton.h b/xfa/fwl/core/cfwl_pushbutton.h deleted file mode 100644 index e5bd295a8c..0000000000 --- a/xfa/fwl/core/cfwl_pushbutton.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_PUSHBUTTON_H_ -#define XFA_FWL_CORE_CFWL_PUSHBUTTON_H_ - -#include - -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -#define FWL_STYLEEXT_PSB_Left (0L << 0) -#define FWL_STYLEEXT_PSB_Center (1L << 0) -#define FWL_STYLEEXT_PSB_Right (2L << 0) -#define FWL_STYLEEXT_PSB_Top (0L << 2) -#define FWL_STYLEEXT_PSB_VCenter (1L << 2) -#define FWL_STYLEEXT_PSB_Bottom (2L << 2) -#define FWL_STYLEEXT_PSB_TextOnly (0L << 4) -#define FWL_STYLEEXT_PSB_IconOnly (1L << 4) -#define FWL_STYLEEXT_PSB_TextIcon (2L << 4) -#define FWL_STYLEEXT_PSB_HLayoutMask (3L << 0) -#define FWL_STYLEEXT_PSB_VLayoutMask (3L << 2) -#define FWL_STYLEEXT_PSB_ModeMask (3L << 4) -#define FWL_STATE_PSB_Hovered (1 << FWL_WGTSTATE_MAX) -#define FWL_STATE_PSB_Pressed (1 << (FWL_WGTSTATE_MAX + 1)) -#define FWL_STATE_PSB_Default (1 << (FWL_WGTSTATE_MAX + 2)) - -class CFWL_MsgMouse; -class CFX_DIBitmap; -class CFWL_Widget; - -class CFWL_PushButton : public CFWL_Widget { - public: - explicit CFWL_PushButton(const CFWL_App*); - ~CFWL_PushButton() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void SetStates(uint32_t dwStates) override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - private: - void DrawBkground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - uint32_t GetPartStates(); - void UpdateTextOutStyles(); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - void OnKeyDown(CFWL_MsgKey* pMsg); - - CFX_RectF m_rtClient; - CFX_RectF m_rtCaption; - bool m_bBtnDown; - uint32_t m_dwTTOStyles; - int32_t m_iTTOAlign; -}; - -#endif // XFA_FWL_CORE_CFWL_PUSHBUTTON_H_ diff --git a/xfa/fwl/core/cfwl_scrollbar.cpp b/xfa/fwl/core/cfwl_scrollbar.cpp deleted file mode 100644 index 6c2ad99601..0000000000 --- a/xfa/fwl/core/cfwl_scrollbar.cpp +++ /dev/null @@ -1,503 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_scrollbar.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgmousewheel.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -#define FWL_SCROLLBAR_Elapse 500 -#define FWL_SCROLLBAR_MinThumb 5 - -CFWL_ScrollBar::CFWL_ScrollBar( - const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : CFWL_Widget(app, std::move(properties), pOuter), - m_pTimerInfo(nullptr), - m_fRangeMin(0), - m_fRangeMax(-1), - m_fPageSize(0), - m_fStepSize(0), - m_fPos(0), - m_fTrackPos(0), - m_iMinButtonState(CFWL_PartState_Normal), - m_iMaxButtonState(CFWL_PartState_Normal), - m_iThumbButtonState(CFWL_PartState_Normal), - m_iMinTrackState(CFWL_PartState_Normal), - m_iMaxTrackState(CFWL_PartState_Normal), - m_fLastTrackPos(0), - m_cpTrackPointX(0), - m_cpTrackPointY(0), - m_iMouseWheel(0), - m_bMouseDown(false), - m_fButtonLen(0), - m_bMinSize(false), - m_fMinThumb(FWL_SCROLLBAR_MinThumb), - m_Timer(this) { - m_rtClient.Reset(); - m_rtThumb.Reset(); - m_rtMinBtn.Reset(); - m_rtMaxBtn.Reset(); - m_rtMinTrack.Reset(); - m_rtMaxTrack.Reset(); -} - -CFWL_ScrollBar::~CFWL_ScrollBar() {} - -FWL_Type CFWL_ScrollBar::GetClassID() const { - return FWL_Type::ScrollBar; -} - -void CFWL_ScrollBar::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); -} - -void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - DrawTrack(pGraphics, pTheme, true, pMatrix); - DrawTrack(pGraphics, pTheme, false, pMatrix); - DrawArrowBtn(pGraphics, pTheme, true, pMatrix); - DrawArrowBtn(pGraphics, pTheme, false, pMatrix); - DrawThumb(pGraphics, pTheme, pMatrix); -} - -void CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { - m_fTrackPos = fTrackPos; - CalcThumbButtonRect(m_rtThumb); - CalcMinTrackRect(m_rtMinTrack); - CalcMaxTrackRect(m_rtMaxTrack); -} - -bool CFWL_ScrollBar::DoScroll(CFWL_EvtScroll::Code dwCode, FX_FLOAT fPos) { - if (dwCode == CFWL_EvtScroll::Code::None) - return false; - return OnScroll(dwCode, fPos); -} - -void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bLower, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : (bLower ? m_iMinTrackState : m_iMaxTrackState); - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; - pTheme->DrawBackground(¶m); -} - -void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bMinBtn, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; - if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) - pTheme->DrawBackground(¶m); -} - -void CFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Thumb; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : m_iThumbButtonState; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtThumb; - pTheme->DrawBackground(¶m); -} - -void CFWL_ScrollBar::Layout() { - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - CFWL_ThemePart part; - part.m_pWidget = this; - m_fMinThumb = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); - GetClientRect(m_rtClient); - CalcButtonLen(); - CalcMinButtonRect(m_rtMinBtn); - CalcMaxButtonRect(m_rtMaxBtn); - CalcThumbButtonRect(m_rtThumb); - CalcMinTrackRect(m_rtMinTrack); - CalcMaxTrackRect(m_rtMaxTrack); -} - -void CFWL_ScrollBar::CalcButtonLen() { - m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; - FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; - if (fLength < m_fButtonLen * 2) { - m_fButtonLen = fLength / 2; - m_bMinSize = true; - } else { - m_bMinSize = false; - } -} - -void CFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) { - rect.left = m_rtClient.left; - rect.top = m_rtClient.top; - rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; - rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; -} - -void CFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) { - rect.left = - IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen; - rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top; - rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; - rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; -} - -void CFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { - if (!IsEnabled()) { - m_rtThumb.Reset(); - return; - } - if (m_bMinSize) { - m_rtThumb.Empty(); - return; - } - - FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; - memset(&rect, 0, sizeof(CFX_Rect)); - if (fRange < 0) { - if (IsVertical()) - rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); - else - rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); - return; - } - - CFX_RectF rtClient = m_rtClient; - FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; - FX_FLOAT fSize = m_fButtonLen; - fLength -= fSize * 2.0f; - if (fLength < fSize) - fLength = 0.0f; - - FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); - fThumbSize = std::max(fThumbSize, m_fMinThumb); - - FX_FLOAT fDiff = std::max(fLength - fThumbSize, 0.0f); - FX_FLOAT fTrackPos = - std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin); - if (!fRange) - return; - - FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; - rect.left = rtClient.left; - if (!IsVertical()) - rect.left += iPos; - - rect.top = rtClient.top; - if (IsVertical()) - rect.top += iPos; - - rect.width = IsVertical() ? rtClient.width : fThumbSize; - rect.height = IsVertical() ? fThumbSize : rtClient.height; -} - -void CFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { - if (m_bMinSize) { - rect.Empty(); - return; - } - - FX_FLOAT fBottom = m_rtThumb.bottom(); - FX_FLOAT fRight = m_rtThumb.right(); - FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; - FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; - rect.left = m_rtClient.left; - rect.top = m_rtClient.top; - bool bVertical = IsVertical(); - rect.width = bVertical ? m_rtClient.width : ix; - rect.height = bVertical ? iy : m_rtClient.height; -} - -void CFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { - if (m_bMinSize) { - rect.Empty(); - return; - } - - FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; - FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; - bool bVertical = IsVertical(); - rect.left = bVertical ? m_rtClient.left : ix; - rect.top = bVertical ? iy : m_rtClient.top; - rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; - rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; -} - -FX_FLOAT CFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { - FX_FLOAT fDiffX = fx - m_cpTrackPointX; - FX_FLOAT fDiffY = fy - m_cpTrackPointY; - FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; - FX_FLOAT fPos; - - if (IsVertical()) { - fPos = fRange * fDiffY / - (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); - } else { - fPos = fRange * fDiffX / - (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); - } - - fPos += m_fLastTrackPos; - return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); -} - -bool CFWL_ScrollBar::SendEvent() { - if (m_iMinButtonState == CFWL_PartState_Pressed) { - DoScroll(CFWL_EvtScroll::Code::StepBackward, m_fTrackPos); - return false; - } - if (m_iMaxButtonState == CFWL_PartState_Pressed) { - DoScroll(CFWL_EvtScroll::Code::StepForward, m_fTrackPos); - return false; - } - if (m_iMinTrackState == CFWL_PartState_Pressed) { - DoScroll(CFWL_EvtScroll::Code::PageBackward, m_fTrackPos); - return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); - } - if (m_iMaxTrackState == CFWL_PartState_Pressed) { - DoScroll(CFWL_EvtScroll::Code::PageForward, m_fTrackPos); - return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); - } - if (m_iMouseWheel) { - CFWL_EvtScroll::Code dwCode = m_iMouseWheel < 0 - ? CFWL_EvtScroll::Code::StepForward - : CFWL_EvtScroll::Code::StepBackward; - DoScroll(dwCode, m_fTrackPos); - } - return true; -} - -bool CFWL_ScrollBar::OnScroll(CFWL_EvtScroll::Code dwCode, FX_FLOAT fPos) { - CFWL_EvtScroll ev(this); - ev.m_iScrollCode = dwCode; - ev.m_fPos = fPos; - DispatchEvent(&ev); - return true; -} - -void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - CFWL_Message::Type type = pMessage->GetType(); - if (type == CFWL_Message::Type::Mouse) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(); - break; - default: - break; - } - } else if (type == CFWL_Message::Type::MouseWheel) { - CFWL_MsgMouseWheel* pMsg = static_cast(pMessage); - OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, - pMsg->m_fDeltaY); - } -} - -void CFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { - if (!IsEnabled()) - return; - - m_bMouseDown = true; - SetGrab(true); - m_cpTrackPointX = fx; - m_cpTrackPointY = fy; - m_fLastTrackPos = m_fTrackPos; - if (m_rtMinBtn.Contains(fx, fy)) - DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); - else if (m_rtThumb.Contains(fx, fy)) - DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); - else if (m_rtMaxBtn.Contains(fx, fy)) - DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); - else if (m_rtMinTrack.Contains(fx, fy)) - DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); - else - DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); - - if (!SendEvent()) - m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); -} - -void CFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { - m_pTimerInfo->StopTimer(); - m_bMouseDown = false; - DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); - DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); - DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); - DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); - DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); - SetGrab(false); -} - -void CFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { - DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); - DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); - DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); - DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); - DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); -} - -void CFWL_ScrollBar::OnMouseLeave() { - DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); - DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); - DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); - DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); - DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); -} - -void CFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, - FX_FLOAT fy, - uint32_t dwFlags, - FX_FLOAT fDeltaX, - FX_FLOAT fDeltaY) { - m_iMouseWheel = (int32_t)fDeltaX; - SendEvent(); - m_iMouseWheel = 0; -} - -void CFWL_ScrollBar::DoMouseDown(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy) { - if (!rtItem.Contains(fx, fy)) - return; - if (iState == CFWL_PartState_Pressed) - return; - - iState = CFWL_PartState_Pressed; - Repaint(&rtItem); -} - -void CFWL_ScrollBar::DoMouseUp(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy) { - int32_t iNewState = - rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; - if (iState == iNewState) - return; - - iState = iNewState; - Repaint(&rtItem); - OnScroll(CFWL_EvtScroll::Code::EndScroll, m_fTrackPos); -} - -void CFWL_ScrollBar::DoMouseMove(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy) { - if (!m_bMouseDown) { - int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered - : CFWL_PartState_Normal; - if (iState == iNewState) - return; - - iState = iNewState; - Repaint(&rtItem); - } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { - FX_FLOAT fPos = GetTrackPointPos(fx, fy); - m_fTrackPos = fPos; - OnScroll(CFWL_EvtScroll::Code::TrackPos, fPos); - } -} - -void CFWL_ScrollBar::DoMouseLeave(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState) { - if (iState == CFWL_PartState_Normal) - return; - - iState = CFWL_PartState_Normal; - Repaint(&rtItem); -} - -void CFWL_ScrollBar::DoMouseHover(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState) { - if (iState == CFWL_PartState_Hovered) - return; - - iState = CFWL_PartState_Hovered; - Repaint(&rtItem); -} - -CFWL_ScrollBar::Timer::Timer(CFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {} - -void CFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) { - CFWL_ScrollBar* pButton = static_cast(m_pWidget); - - if (pButton->m_pTimerInfo) - pButton->m_pTimerInfo->StopTimer(); - - if (!pButton->SendEvent()) - pButton->m_pTimerInfo = StartTimer(0, true); -} diff --git a/xfa/fwl/core/cfwl_scrollbar.h b/xfa/fwl/core/cfwl_scrollbar.h deleted file mode 100644 index f1eb35b327..0000000000 --- a/xfa/fwl/core/cfwl_scrollbar.h +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_SCROLLBAR_H_ -#define XFA_FWL_CORE_CFWL_SCROLLBAR_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_evtscroll.h" -#include "xfa/fwl/core/cfwl_timer.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -class CFWL_Widget; - -#define FWL_STYLEEXT_SCB_Horz (0L << 0) -#define FWL_STYLEEXT_SCB_Vert (1L << 0) - -class CFWL_ScrollBar : public CFWL_Widget { - public: - CFWL_ScrollBar(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - ~CFWL_ScrollBar() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void GetRange(FX_FLOAT* fMin, FX_FLOAT* fMax) const { - ASSERT(fMin); - ASSERT(fMax); - *fMin = m_fRangeMin; - *fMax = m_fRangeMax; - } - void SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { - m_fRangeMin = fMin; - m_fRangeMax = fMax; - } - FX_FLOAT GetPageSize() const { return m_fPageSize; } - void SetPageSize(FX_FLOAT fPageSize) { m_fPageSize = fPageSize; } - FX_FLOAT GetStepSize() const { return m_fStepSize; } - void SetStepSize(FX_FLOAT fStepSize) { m_fStepSize = fStepSize; } - FX_FLOAT GetPos() const { return m_fPos; } - void SetPos(FX_FLOAT fPos) { m_fPos = fPos; } - void SetTrackPos(FX_FLOAT fTrackPos); - - private: - class Timer : public CFWL_Timer { - public: - explicit Timer(CFWL_ScrollBar* pToolTip); - ~Timer() override {} - - void Run(CFWL_TimerInfo* pTimerInfo) override; - }; - friend class CFWL_ScrollBar::Timer; - - bool IsVertical() const { - return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert); - } - void DrawTrack(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bLower, - const CFX_Matrix* pMatrix); - void DrawArrowBtn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bMinBtn, - const CFX_Matrix* pMatrix); - void DrawThumb(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void Layout(); - void CalcButtonLen(); - void CalcMinButtonRect(CFX_RectF& rect); - void CalcMaxButtonRect(CFX_RectF& rect); - void CalcThumbButtonRect(CFX_RectF& rect); - void CalcMinTrackRect(CFX_RectF& rect); - void CalcMaxTrackRect(CFX_RectF& rect); - FX_FLOAT GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy); - - bool SendEvent(); - bool OnScroll(CFWL_EvtScroll::Code dwCode, FX_FLOAT fPos); - void OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); - void OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); - void OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); - void OnMouseLeave(); - void OnMouseWheel(FX_FLOAT fx, - FX_FLOAT fy, - uint32_t dwFlags, - FX_FLOAT fDeltaX, - FX_FLOAT fDeltaY); - bool DoScroll(CFWL_EvtScroll::Code dwCode, FX_FLOAT fPos); - void DoMouseDown(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy); - void DoMouseUp(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy); - void DoMouseMove(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy); - void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); - void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); - - CFWL_TimerInfo* m_pTimerInfo; - FX_FLOAT m_fRangeMin; - FX_FLOAT m_fRangeMax; - FX_FLOAT m_fPageSize; - FX_FLOAT m_fStepSize; - FX_FLOAT m_fPos; - FX_FLOAT m_fTrackPos; - int32_t m_iMinButtonState; - int32_t m_iMaxButtonState; - int32_t m_iThumbButtonState; - int32_t m_iMinTrackState; - int32_t m_iMaxTrackState; - FX_FLOAT m_fLastTrackPos; - FX_FLOAT m_cpTrackPointX; - FX_FLOAT m_cpTrackPointY; - int32_t m_iMouseWheel; - bool m_bMouseDown; - FX_FLOAT m_fButtonLen; - bool m_bMinSize; - CFX_RectF m_rtClient; - CFX_RectF m_rtThumb; - CFX_RectF m_rtMinBtn; - CFX_RectF m_rtMaxBtn; - CFX_RectF m_rtMinTrack; - CFX_RectF m_rtMaxTrack; - FX_FLOAT m_fMinThumb; - CFWL_ScrollBar::Timer m_Timer; -}; - -#endif // XFA_FWL_CORE_CFWL_SCROLLBAR_H_ diff --git a/xfa/fwl/core/cfwl_spinbutton.cpp b/xfa/fwl/core/cfwl_spinbutton.cpp deleted file mode 100644 index 68844f9900..0000000000 --- a/xfa/fwl/core/cfwl_spinbutton.cpp +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_spinbutton.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { -const int kElapseTime = 200; - -} // namespace - -CFWL_SpinButton::CFWL_SpinButton( - const CFWL_App* app, - std::unique_ptr properties) - : CFWL_Widget(app, std::move(properties), nullptr), - m_dwUpState(CFWL_PartState_Normal), - m_dwDnState(CFWL_PartState_Normal), - m_iButtonIndex(0), - m_bLButtonDwn(false), - m_pTimerInfo(nullptr), - m_Timer(this) { - m_rtClient.Reset(); - m_rtUpButton.Reset(); - m_rtDnButton.Reset(); - m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; -} - -CFWL_SpinButton::~CFWL_SpinButton() {} - -FWL_Type CFWL_SpinButton::GetClassID() const { - return FWL_Type::SpinButton; -} - -void CFWL_SpinButton::Update() { - if (IsLocked()) - return; - - GetClientRect(m_rtClient); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { - m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, - m_rtClient.height / 2); - m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, - m_rtClient.width, m_rtClient.height / 2); - } else { - m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, - m_rtClient.height); - m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, - m_rtClient.width / 2, m_rtClient.height); - } -} - -FWL_WidgetHit CFWL_SpinButton::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - if (m_rtClient.Contains(fx, fy)) - return FWL_WidgetHit::Client; - if (HasBorder() && (m_rtClient.Contains(fx, fy))) - return FWL_WidgetHit::Border; - if (HasEdge()) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); - if (rtEdge.Contains(fx, fy)) - return FWL_WidgetHit::Left; - } - if (m_rtUpButton.Contains(fx, fy)) - return FWL_WidgetHit::UpButton; - if (m_rtDnButton.Contains(fx, fy)) - return FWL_WidgetHit::DownButton; - return FWL_WidgetHit::Unknown; -} - -void CFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - - CFX_RectF rtClip(m_rtClient); - if (pMatrix) - pMatrix->TransformRect(rtClip); - - IFWL_ThemeProvider* pTheme = GetAvailableTheme(); - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - DrawUpButton(pGraphics, pTheme, pMatrix); - DrawDownButton(pGraphics, pTheme, pMatrix); -} - -void CFWL_SpinButton::DisableButton() { - m_dwDnState = CFWL_PartState_Disabled; -} - -bool CFWL_SpinButton::IsUpButtonEnabled() { - return m_dwUpState != CFWL_PartState_Disabled; -} - -bool CFWL_SpinButton::IsDownButtonEnabled() { - return m_dwDnState != CFWL_PartState_Disabled; -} - -void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::UpButton; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_dwUpState + 1; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - params.m_rtPart = m_rtUpButton; - pTheme->DrawBackground(¶ms); -} - -void CFWL_SpinButton::DrawDownButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DownButton; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_dwDnState + 1; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - params.m_rtPart = m_rtDnButton; - pTheme->DrawBackground(¶ms); -} - -void CFWL_SpinButton::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: { - OnFocusChanged(pMessage, true); - break; - } - case CFWL_Message::Type::KillFocus: { - OnFocusChanged(pMessage, false); - break; - } - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: { - CFWL_MsgKey* pKey = static_cast(pMessage); - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) - OnKeyDown(pKey); - break; - } - default: - break; - } - CFWL_Widget::OnProcessMessage(pMessage); -} - -void CFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) - m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); - else - m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); - - Repaint(&m_rtClient); -} - -void CFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { - m_bLButtonDwn = true; - SetGrab(true); - SetFocus(true); - - bool bUpPress = - (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); - bool bDnPress = - (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); - if (!bUpPress && !bDnPress) - return; - if (bUpPress) { - m_iButtonIndex = 0; - m_dwUpState = CFWL_PartState_Pressed; - } - if (bDnPress) { - m_iButtonIndex = 1; - m_dwDnState = CFWL_PartState_Pressed; - } - - CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); - DispatchEvent(&wmPosChanged); - - Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); - m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); -} - -void CFWL_SpinButton::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) - return; - - m_bLButtonDwn = false; - SetGrab(false); - SetFocus(false); - if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; - } - bool bRepaint = false; - CFX_RectF rtInvalidate; - if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { - m_dwUpState = CFWL_PartState_Normal; - bRepaint = true; - rtInvalidate = m_rtUpButton; - } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { - m_dwDnState = CFWL_PartState_Normal; - bRepaint = true; - rtInvalidate = m_rtDnButton; - } - if (bRepaint) - Repaint(&rtInvalidate); -} - -void CFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_bLButtonDwn) - return; - - bool bRepaint = false; - CFX_RectF rtInvlidate; - rtInvlidate.Reset(); - if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { - if (IsUpButtonEnabled()) { - if (m_dwUpState == CFWL_PartState_Hovered) { - m_dwUpState = CFWL_PartState_Hovered; - bRepaint = true; - rtInvlidate = m_rtUpButton; - } - if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) { - m_dwDnState = CFWL_PartState_Normal; - if (bRepaint) - rtInvlidate.Union(m_rtDnButton); - else - rtInvlidate = m_rtDnButton; - - bRepaint = true; - } - } - if (!IsDownButtonEnabled()) - DisableButton(); - - } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { - if (IsDownButtonEnabled()) { - if (m_dwDnState != CFWL_PartState_Hovered) { - m_dwDnState = CFWL_PartState_Hovered; - bRepaint = true; - rtInvlidate = m_rtDnButton; - } - if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) { - m_dwUpState = CFWL_PartState_Normal; - if (bRepaint) - rtInvlidate.Union(m_rtUpButton); - else - rtInvlidate = m_rtUpButton; - bRepaint = true; - } - } - } else if (m_dwUpState != CFWL_PartState_Normal || - m_dwDnState != CFWL_PartState_Normal) { - if (m_dwUpState != CFWL_PartState_Normal) { - m_dwUpState = CFWL_PartState_Normal; - bRepaint = true; - rtInvlidate = m_rtUpButton; - } - if (m_dwDnState != CFWL_PartState_Normal) { - m_dwDnState = CFWL_PartState_Normal; - if (bRepaint) - rtInvlidate.Union(m_rtDnButton); - else - rtInvlidate = m_rtDnButton; - - bRepaint = true; - } - } - if (bRepaint) - Repaint(&rtInvlidate); -} - -void CFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { - if (!pMsg) - return; - if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) - m_dwUpState = CFWL_PartState_Normal; - if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) - m_dwDnState = CFWL_PartState_Normal; - - Repaint(&m_rtClient); -} - -void CFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { - bool bUp = - pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; - bool bDown = - pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; - if (!bUp && !bDown) - return; - - bool bUpEnable = IsUpButtonEnabled(); - bool bDownEnable = IsDownButtonEnabled(); - if (!bUpEnable && !bDownEnable) - return; - - CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); - DispatchEvent(&wmPosChanged); - - Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); -} - -CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) - : CFWL_Timer(pToolTip) {} - -void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { - CFWL_SpinButton* pButton = static_cast(m_pWidget); - - if (!pButton->m_pTimerInfo) - return; - - CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); - pButton->DispatchEvent(&wmPosChanged); -} diff --git a/xfa/fwl/core/cfwl_spinbutton.h b/xfa/fwl/core/cfwl_spinbutton.h deleted file mode 100644 index dc480071ec..0000000000 --- a/xfa/fwl/core/cfwl_spinbutton.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_SPINBUTTON_H_ -#define XFA_FWL_CORE_CFWL_SPINBUTTON_H_ - -#include - -#include "xfa/fwl/core/cfwl_timer.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fxfa/cxfa_eventparam.h" - -#define FWL_STYLEEXE_SPB_Vert (1L << 0) - -class CFWL_MsgMouse; -class CFWL_WidgetProperties; - -class CFWL_SpinButton : public CFWL_Widget { - public: - CFWL_SpinButton(const CFWL_App* app, - std::unique_ptr properties); - ~CFWL_SpinButton() override; - - // CFWL_Widget - FWL_Type GetClassID() const override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - private: - class Timer : public CFWL_Timer { - public: - explicit Timer(CFWL_SpinButton* pToolTip); - ~Timer() override {} - - void Run(CFWL_TimerInfo* pTimerInfo) override; - }; - friend class CFWL_SpinButton::Timer; - - void DisableButton(); - bool IsUpButtonEnabled(); - bool IsDownButtonEnabled(); - void DrawUpButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDownButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - void OnKeyDown(CFWL_MsgKey* pMsg); - - CFX_RectF m_rtClient; - CFX_RectF m_rtUpButton; - CFX_RectF m_rtDnButton; - uint32_t m_dwUpState; - uint32_t m_dwDnState; - int32_t m_iButtonIndex; - bool m_bLButtonDwn; - CFWL_TimerInfo* m_pTimerInfo; - CFWL_SpinButton::Timer m_Timer; -}; - -#endif // XFA_FWL_CORE_CFWL_SPINBUTTON_H_ diff --git a/xfa/fwl/core/cfwl_sysbtn.cpp b/xfa/fwl/core/cfwl_sysbtn.cpp deleted file mode 100644 index 0ccc4c4b1d..0000000000 --- a/xfa/fwl/core/cfwl_sysbtn.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_sysbtn.h" - -#include "xfa/fwl/core/cfwl_themepart.h" - -CFWL_SysBtn::CFWL_SysBtn() { - m_rtBtn.Set(0, 0, 0, 0); - m_dwState = 0; -} - -CFWL_SysBtn::~CFWL_SysBtn() {} - -bool CFWL_SysBtn::IsDisabled() const { - return !!(m_dwState & FWL_SYSBUTTONSTATE_Disabled); -} - -void CFWL_SysBtn::SetNormal() { - m_dwState &= 0xFFF0; -} - -void CFWL_SysBtn::SetPressed() { - SetNormal(); - m_dwState |= FWL_SYSBUTTONSTATE_Pressed; -} - -void CFWL_SysBtn::SetHover() { - SetNormal(); - m_dwState |= FWL_SYSBUTTONSTATE_Hover; -} - -void CFWL_SysBtn::SetDisabled(bool bDisabled) { - bDisabled ? m_dwState |= FWL_SYSBUTTONSTATE_Disabled - : m_dwState &= ~FWL_SYSBUTTONSTATE_Disabled; -} - -uint32_t CFWL_SysBtn::GetPartState() const { - if (IsDisabled()) - return CFWL_PartState_Disabled; - if (m_dwState & FWL_SYSBUTTONSTATE_Pressed) - return CFWL_PartState_Pressed; - if (m_dwState & FWL_SYSBUTTONSTATE_Hover) - return CFWL_PartState_Hovered; - return CFWL_PartState_Normal; -} diff --git a/xfa/fwl/core/cfwl_sysbtn.h b/xfa/fwl/core/cfwl_sysbtn.h deleted file mode 100644 index b973b92ff8..0000000000 --- a/xfa/fwl/core/cfwl_sysbtn.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_SYSBTN_H_ -#define XFA_FWL_CORE_CFWL_SYSBTN_H_ - -#include "core/fxcrt/fx_coordinates.h" - -#define FWL_SYSBUTTONSTATE_Hover 0x0001 -#define FWL_SYSBUTTONSTATE_Pressed 0x0002 -#define FWL_SYSBUTTONSTATE_Disabled 0x0010 - -class CFWL_SysBtn { - public: - CFWL_SysBtn(); - ~CFWL_SysBtn(); - - bool IsDisabled() const; - uint32_t GetPartState() const; - - void SetNormal(); - void SetPressed(); - void SetHover(); - void SetDisabled(bool bDisabled); - - CFX_RectF m_rtBtn; - uint32_t m_dwState; -}; - -#endif // XFA_FWL_CORE_CFWL_SYSBTN_H_ diff --git a/xfa/fwl/core/cfwl_themebackground.h b/xfa/fwl/core/cfwl_themebackground.h deleted file mode 100644 index 54d58b38f6..0000000000 --- a/xfa/fwl/core/cfwl_themebackground.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_THEMEBACKGROUND_H_ -#define XFA_FWL_CORE_CFWL_THEMEBACKGROUND_H_ - -#include "core/fxge/fx_dib.h" -#include "xfa/fwl/core/cfwl_themepart.h" - -class CFX_DIBitmpa; -class CFX_Graphics; -class CFX_Path; - -class CFWL_ThemeBackground : public CFWL_ThemePart { - public: - CFWL_ThemeBackground() - : m_pGraphics(nullptr), m_pImage(nullptr), m_pPath(nullptr) {} - - CFX_Graphics* m_pGraphics; - CFX_DIBitmap* m_pImage; - CFX_Path* m_pPath; -}; - -#endif // XFA_FWL_CORE_CFWL_THEMEBACKGROUND_H_ diff --git a/xfa/fwl/core/cfwl_themepart.cpp b/xfa/fwl/core/cfwl_themepart.cpp deleted file mode 100644 index 6b48a1e03e..0000000000 --- a/xfa/fwl/core/cfwl_themepart.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_themepart.h" - -CFWL_ThemePart::CFWL_ThemePart() - : m_pWidget(nullptr), - m_iPart(CFWL_Part::None), - m_dwStates(CFWL_PartState_Normal), - m_bMaximize(false), - m_bStaticBackground(false), - m_pData(nullptr) { - m_rtPart.Reset(); - m_matrix.SetIdentity(); -} diff --git a/xfa/fwl/core/cfwl_themepart.h b/xfa/fwl/core/cfwl_themepart.h deleted file mode 100644 index f80bb8e07a..0000000000 --- a/xfa/fwl/core/cfwl_themepart.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_THEMEPART_H_ -#define XFA_FWL_CORE_CFWL_THEMEPART_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" - -enum class CFWL_Part { - None = 0, - - BackArrow, - Background, - Border, - Caption, - Check, - CheckBox, - CloseBox, - CombTextLine, - DateInBK, - DateInCircle, - DatesIn, - DatesOut, - DownButton, - DropDownButton, - Edge, - ForeArrow, - HSeparator, - HeadText, - Header, - Icon, - Image, - LBtn, - ListItem, - LowerTrack, - MinimizeBox, - MaximizeBox, - NarrowCaption, - RBtn, - StretchHandler, - Thumb, - ThumbBackArrow, - ThumbForeArrow, - ThumbLowerTrack, - ThumbThumb, - ThumbUpperTrack, - Today, - TodayCircle, - UpButton, - UpperTrack, - VSeparator, - Week, - WeekNum, - WeekNumSep -}; - -enum CFWL_PartState { - CFWL_PartState_Normal = 0, - - CFWL_PartState_Checked = 1 << 1, - CFWL_PartState_Default = 1 << 2, - CFWL_PartState_Disabled = 1 << 3, - CFWL_PartState_Flagged = 1 << 4, - CFWL_PartState_Focused = 1 << 5, - CFWL_PartState_HightLight = 1 << 6, - CFWL_PartState_Hovered = 1 << 7, - CFWL_PartState_Inactive = 1 << 8, - CFWL_PartState_Neutral = 1 << 9, - CFWL_PartState_Pressed = 1 << 10, - CFWL_PartState_ReadOnly = 1 << 11, - CFWL_PartState_LSelected = 1 << 12, - CFWL_PartState_RSelected = 1 << 13, - CFWL_PartState_Selected = 1 << 14 -}; - -class CFWL_Widget; - -class CFWL_ThemePart { - public: - CFWL_ThemePart(); - - CFX_Matrix m_matrix; - CFX_RectF m_rtPart; - CFWL_Widget* m_pWidget; - CFWL_Part m_iPart; - uint32_t m_dwStates; - bool m_bMaximize; - bool m_bStaticBackground; - void* m_pData; -}; - -#endif // XFA_FWL_CORE_CFWL_THEMEPART_H_ diff --git a/xfa/fwl/core/cfwl_themetext.h b/xfa/fwl/core/cfwl_themetext.h deleted file mode 100644 index 9662414069..0000000000 --- a/xfa/fwl/core/cfwl_themetext.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_THEMETEXT_H_ -#define XFA_FWL_CORE_CFWL_THEMETEXT_H_ - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_themepart.h" - -class CFWL_ThemeText : public CFWL_ThemePart { - public: - CFWL_ThemeText() : m_pGraphics(nullptr) {} - - CFX_WideString m_wsText; - uint32_t m_dwTTOStyles; - int32_t m_iTTOAlign; - CFX_Graphics* m_pGraphics; -}; - -#endif // XFA_FWL_CORE_CFWL_THEMETEXT_H_ diff --git a/xfa/fwl/core/cfwl_timer.cpp b/xfa/fwl/core/cfwl_timer.cpp deleted file mode 100644 index c909afcc49..0000000000 --- a/xfa/fwl/core/cfwl_timer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_timer.h" - -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_adaptertimermgr.h" -#include "xfa/fxfa/xfa_ffapp.h" - -CFWL_TimerInfo* CFWL_Timer::StartTimer(uint32_t dwElapse, bool bImmediately) { - const CFWL_App* pApp = m_pWidget->GetOwnerApp(); - if (!pApp) - return nullptr; - - CXFA_FFApp* pAdapterNative = pApp->GetAdapterNative(); - if (!pAdapterNative) - return nullptr; - - IFWL_AdapterTimerMgr* pAdapterTimerMgr = pAdapterNative->GetTimerMgr(); - if (!pAdapterTimerMgr) - return nullptr; - - CFWL_TimerInfo* pTimerInfo = nullptr; - pAdapterTimerMgr->Start(this, dwElapse, bImmediately, &pTimerInfo); - return pTimerInfo; -} diff --git a/xfa/fwl/core/cfwl_timer.h b/xfa/fwl/core/cfwl_timer.h deleted file mode 100644 index 7b36c3eb49..0000000000 --- a/xfa/fwl/core/cfwl_timer.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_TIMER_H_ -#define XFA_FWL_CORE_CFWL_TIMER_H_ - -#include "core/fxcrt/fx_system.h" - -class CFWL_TimerInfo; -class CFWL_Widget; - -class CFWL_Timer { - public: - explicit CFWL_Timer(CFWL_Widget* parent) : m_pWidget(parent) {} - virtual ~CFWL_Timer() {} - - virtual void Run(CFWL_TimerInfo* hTimer) = 0; - CFWL_TimerInfo* StartTimer(uint32_t dwElapse, bool bImmediately); - - protected: - CFWL_Widget* m_pWidget; // Not owned. -}; - -#endif // XFA_FWL_CORE_CFWL_TIMER_H_ diff --git a/xfa/fwl/core/cfwl_timerinfo.cpp b/xfa/fwl/core/cfwl_timerinfo.cpp deleted file mode 100644 index 8322a1d6aa..0000000000 --- a/xfa/fwl/core/cfwl_timerinfo.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_timerinfo.h" - -#include "xfa/fwl/core/ifwl_adaptertimermgr.h" - -void CFWL_TimerInfo::StopTimer() { - m_pMgr->Stop(this); -} diff --git a/xfa/fwl/core/cfwl_timerinfo.h b/xfa/fwl/core/cfwl_timerinfo.h deleted file mode 100644 index 5365d38305..0000000000 --- a/xfa/fwl/core/cfwl_timerinfo.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_TIMERINFO_H_ -#define XFA_FWL_CORE_CFWL_TIMERINFO_H_ - -#include "core/fxcrt/fx_system.h" - -class IFWL_AdapterTimerMgr; - -class CFWL_TimerInfo { - public: - explicit CFWL_TimerInfo(IFWL_AdapterTimerMgr* mgr) : m_pMgr(mgr) { - ASSERT(mgr); - } - virtual ~CFWL_TimerInfo() {} - - void StopTimer(); - - private: - IFWL_AdapterTimerMgr* m_pMgr; // Not owned. -}; - -#endif // XFA_FWL_CORE_CFWL_TIMERINFO_H_ diff --git a/xfa/fwl/core/cfwl_widget.cpp b/xfa/fwl/core/cfwl_widget.cpp deleted file mode 100644 index 225721be43..0000000000 --- a/xfa/fwl/core/cfwl_widget.cpp +++ /dev/null @@ -1,729 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_widget.h" - -#include -#include - -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_evtmouse.h" -#include "xfa/fwl/core/cfwl_form.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgmousewheel.h" -#include "xfa/fwl/core/cfwl_msgsetfocus.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" -#include "xfa/fxfa/xfa_ffapp.h" - -#define FWL_STYLEEXT_MNU_Vert (1L << 0) -#define FWL_WGT_CalcHeight 2048 -#define FWL_WGT_CalcWidth 2048 -#define FWL_WGT_CalcMultiLineDefWidth 120.0f - -CFWL_Widget::CFWL_Widget(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter) - : m_pOwnerApp(app), - m_pWidgetMgr(app->GetWidgetMgr()), - m_pProperties(std::move(properties)), - m_pOuter(pOuter), - m_iLock(0), - m_pLayoutItem(nullptr), - m_nEventKey(0), - m_pDelegate(nullptr) { - ASSERT(m_pWidgetMgr); - - CFWL_Widget* pParent = m_pProperties->m_pParent; - m_pWidgetMgr->InsertWidget(pParent, this); - if (IsChild()) - return; - - CFWL_Widget* pOwner = m_pProperties->m_pOwner; - if (pOwner) - m_pWidgetMgr->SetOwner(pOwner, this); -} - -CFWL_Widget::~CFWL_Widget() { - NotifyDriver(); - m_pWidgetMgr->RemoveWidget(this); -} - -bool CFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { - return false; -} - -CFX_RectF CFWL_Widget::GetAutosizedWidgetRect() { - return CFX_RectF(); -} - -CFX_RectF CFWL_Widget::GetWidgetRect() { - return m_pProperties->m_rtWidget; -} - -void CFWL_Widget::InflateWidgetRect(CFX_RectF& rect) { - if (HasEdge()) { - FX_FLOAT fEdge = GetEdgeWidth(); - rect.Inflate(fEdge, fEdge); - } - if (HasBorder()) { - FX_FLOAT fBorder = GetBorderSize(true); - rect.Inflate(fBorder, fBorder); - } -} - -void CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { - m_pProperties->m_rtWidget = rect; - if (IsChild()) - return; - - m_pWidgetMgr->SetWidgetRect_Native(this, rect); -} - -void CFWL_Widget::GetClientRect(CFX_RectF& rect) { - GetEdgeRect(rect); - if (HasEdge()) { - FX_FLOAT fEdge = GetEdgeWidth(); - rect.Deflate(fEdge, fEdge); - } -} - -void CFWL_Widget::SetParent(CFWL_Widget* pParent) { - m_pProperties->m_pParent = pParent; - m_pWidgetMgr->SetParent(pParent, this); -} - -uint32_t CFWL_Widget::GetStyles() const { - return m_pProperties->m_dwStyles; -} - -void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, - uint32_t dwStylesRemoved) { - m_pProperties->m_dwStyles = - (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded; -} - -uint32_t CFWL_Widget::GetStylesEx() const { - return m_pProperties->m_dwStyleExes; -} -uint32_t CFWL_Widget::GetStates() const { - return m_pProperties->m_dwStates; -} - -void CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved) { - m_pProperties->m_dwStyleExes = - (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded; -} - -static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr, - CFWL_Widget* widget, - CFWL_NoteDriver* noteDriver) { - CFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget); - while (child) { - noteDriver->NotifyTargetHide(child); - NotifyHideChildWidget(widgetMgr, child, noteDriver); - child = widgetMgr->GetNextSiblingWidget(child); - } -} - -void CFWL_Widget::SetStates(uint32_t dwStates) { - m_pProperties->m_dwStates |= dwStates; - if (!(dwStates & FWL_WGTSTATE_Invisible)) - return; - - CFWL_NoteDriver* noteDriver = - static_cast(GetOwnerApp()->GetNoteDriver()); - CFWL_WidgetMgr* widgetMgr = GetOwnerApp()->GetWidgetMgr(); - noteDriver->NotifyTargetHide(this); - CFWL_Widget* child = widgetMgr->GetFirstChildWidget(this); - while (child) { - noteDriver->NotifyTargetHide(child); - NotifyHideChildWidget(widgetMgr, child, noteDriver); - child = widgetMgr->GetNextSiblingWidget(child); - } - return; -} - -void CFWL_Widget::RemoveStates(uint32_t dwStates) { - m_pProperties->m_dwStates &= ~dwStates; -} - -FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - CFX_RectF rtClient; - GetClientRect(rtClient); - if (rtClient.Contains(fx, fy)) - return FWL_WidgetHit::Client; - if (HasEdge()) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); - if (rtEdge.Contains(fx, fy)) - return FWL_WidgetHit::Edge; - } - if (HasBorder()) { - CFX_RectF rtRelative; - GetRelativeRect(rtRelative); - if (rtRelative.Contains(fx, fy)) - return FWL_WidgetHit::Border; - } - return FWL_WidgetHit::Unknown; -} - -void CFWL_Widget::TransformTo(CFWL_Widget* pWidget, - FX_FLOAT& fx, - FX_FLOAT& fy) { - if (m_pWidgetMgr->IsFormDisabled()) { - CFX_SizeF szOffset; - if (IsParent(pWidget)) { - szOffset = GetOffsetFromParent(pWidget); - } else { - szOffset = pWidget->GetOffsetFromParent(this); - szOffset.x = -szOffset.x; - szOffset.y = -szOffset.y; - } - fx += szOffset.x; - fy += szOffset.y; - return; - } - CFX_RectF r; - CFX_Matrix m; - CFWL_Widget* parent = GetParent(); - if (parent) { - r = GetWidgetRect(); - fx += r.left; - fy += r.top; - GetMatrix(m, true); - m.TransformPoint(fx, fy); - } - CFWL_Widget* form1 = m_pWidgetMgr->GetSystemFormWidget(this); - if (!form1) - return; - - if (!pWidget) { - r = form1->GetWidgetRect(); - fx += r.left; - fy += r.top; - return; - } - CFWL_Widget* form2 = m_pWidgetMgr->GetSystemFormWidget(pWidget); - if (!form2) - return; - if (form1 != form2) { - r = form1->GetWidgetRect(); - fx += r.left; - fy += r.top; - r = form2->GetWidgetRect(); - fx -= r.left; - fy -= r.top; - } - parent = pWidget->GetParent(); - if (parent) { - pWidget->GetMatrix(m, true); - CFX_Matrix m1; - m1.SetIdentity(); - m1.SetReverse(m); - m1.TransformPoint(fx, fy); - r = pWidget->GetWidgetRect(); - fx -= r.left; - fy -= r.top; - } -} - -void CFWL_Widget::GetMatrix(CFX_Matrix& matrix, bool bGlobal) { - if (!m_pProperties) - return; - if (!bGlobal) { - matrix.SetIdentity(); - return; - } - - CFWL_Widget* parent = GetParent(); - CFX_ArrayTemplate parents; - while (parent) { - parents.Add(parent); - parent = parent->GetParent(); - } - matrix.SetIdentity(); - CFX_Matrix ctmOnParent; - CFX_RectF rect; - int32_t count = parents.GetSize(); - for (int32_t i = count - 2; i >= 0; i--) { - parent = parents.GetAt(i); - parent->GetMatrix(ctmOnParent, false); - rect = parent->GetWidgetRect(); - matrix.Concat(ctmOnParent, true); - matrix.Translate(rect.left, rect.top, true); - } - CFX_Matrix m; - m.SetIdentity(); - matrix.Concat(m, true); - parents.RemoveAll(); -} - -IFWL_ThemeProvider* CFWL_Widget::GetThemeProvider() const { - return m_pProperties->m_pThemeProvider; -} - -void CFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - m_pProperties->m_pThemeProvider = pThemeProvider; -} - -bool CFWL_Widget::IsEnabled() const { - return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0; -} - -bool CFWL_Widget::IsActive() const { - return (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) == 0; -} - -bool CFWL_Widget::HasBorder() const { - return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border); -} - -bool CFWL_Widget::HasEdge() const { - return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask); -} - -bool CFWL_Widget::IsVisible() const { - return (m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) == 0; -} - -bool CFWL_Widget::IsOverLapper() const { - return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) == - FWL_WGTSTYLE_OverLapper; -} - -bool CFWL_Widget::IsPopup() const { - return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup); -} - -bool CFWL_Widget::IsChild() const { - return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child); -} - -bool CFWL_Widget::IsOffscreen() const { - return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen); -} - -void CFWL_Widget::GetEdgeRect(CFX_RectF& rtEdge) { - rtEdge = m_pProperties->m_rtWidget; - rtEdge.left = rtEdge.top = 0; - if (HasBorder()) { - FX_FLOAT fCX = GetBorderSize(true); - FX_FLOAT fCY = GetBorderSize(false); - rtEdge.Deflate(fCX, fCY); - } -} - -FX_FLOAT CFWL_Widget::GetBorderSize(bool bCX) { - FX_FLOAT* pfBorder = static_cast(GetThemeCapacity( - bCX ? CFWL_WidgetCapacity::CXBorder : CFWL_WidgetCapacity::CYBorder)); - if (!pfBorder) - return 0; - return *pfBorder; -} - -FX_FLOAT CFWL_Widget::GetEdgeWidth() { - CFWL_WidgetCapacity dwCapacity = CFWL_WidgetCapacity::None; - switch (m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask) { - case FWL_WGTSTYLE_EdgeFlat: { - dwCapacity = CFWL_WidgetCapacity::EdgeFlat; - break; - } - case FWL_WGTSTYLE_EdgeRaised: { - dwCapacity = CFWL_WidgetCapacity::EdgeRaised; - break; - } - case FWL_WGTSTYLE_EdgeSunken: { - dwCapacity = CFWL_WidgetCapacity::EdgeSunken; - break; - } - } - if (dwCapacity != CFWL_WidgetCapacity::None) { - FX_FLOAT* fRet = static_cast(GetThemeCapacity(dwCapacity)); - return fRet ? *fRet : 0; - } - return 0; -} - -void CFWL_Widget::GetRelativeRect(CFX_RectF& rect) { - rect = m_pProperties->m_rtWidget; - rect.left = rect.top = 0; -} - -void* CFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) { - IFWL_ThemeProvider* pTheme = GetAvailableTheme(); - if (!pTheme) - return nullptr; - - CFWL_ThemePart part; - part.m_pWidget = this; - return pTheme->GetCapacity(&part, dwCapacity); -} - -IFWL_ThemeProvider* CFWL_Widget::GetAvailableTheme() { - if (m_pProperties->m_pThemeProvider) - return m_pProperties->m_pThemeProvider; - - CFWL_Widget* pUp = this; - do { - pUp = (pUp->GetStyles() & FWL_WGTSTYLE_Popup) - ? m_pWidgetMgr->GetOwnerWidget(pUp) - : m_pWidgetMgr->GetParentWidget(pUp); - if (pUp) { - IFWL_ThemeProvider* pRet = pUp->GetThemeProvider(); - if (pRet) - return pRet; - } - } while (pUp); - return nullptr; -} - -CFWL_Widget* CFWL_Widget::GetRootOuter() { - CFWL_Widget* pRet = m_pOuter; - if (!pRet) - return nullptr; - - while (CFWL_Widget* pOuter = pRet->GetOuter()) - pRet = pOuter; - return pRet; -} - -CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText, - IFWL_ThemeProvider* pTheme, - bool bMultiLine) { - if (!pTheme) - return CFX_SizeF(); - - CFWL_ThemeText calPart; - calPart.m_pWidget = this; - calPart.m_wsText = wsText; - calPart.m_dwTTOStyles = - bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; - calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; - CFX_RectF rect; - FX_FLOAT fWidth = - bMultiLine ? FWL_WGT_CalcMultiLineDefWidth : FWL_WGT_CalcWidth; - rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); - pTheme->CalcTextRect(&calPart, rect); - return CFX_SizeF(rect.width, rect.height); -} - -void CFWL_Widget::CalcTextRect(const CFX_WideString& wsText, - IFWL_ThemeProvider* pTheme, - uint32_t dwTTOStyles, - int32_t iTTOAlign, - CFX_RectF& rect) { - CFWL_ThemeText calPart; - calPart.m_pWidget = this; - calPart.m_wsText = wsText; - calPart.m_dwTTOStyles = dwTTOStyles; - calPart.m_iTTOAlign = iTTOAlign; - pTheme->CalcTextRect(&calPart, rect); -} - -void CFWL_Widget::SetFocus(bool bFocus) { - if (m_pWidgetMgr->IsFormDisabled()) - return; - - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - CFWL_Widget* curFocus = pDriver->GetFocus(); - if (bFocus && curFocus != this) - pDriver->SetFocus(this); - else if (!bFocus && curFocus == this) - pDriver->SetFocus(nullptr); -} - -void CFWL_Widget::SetGrab(bool bSet) { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - pDriver->SetGrab(this, bSet); -} - -void CFWL_Widget::GetPopupPos(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) { - if (GetClassID() == FWL_Type::ComboBox) { - if (m_pWidgetMgr->IsFormDisabled()) { - m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor, - rtPopup); - return; - } - GetPopupPosComboBox(fMinHeight, fMaxHeight, rtAnchor, rtPopup); - return; - } - if (GetClassID() == FWL_Type::DateTimePicker && - m_pWidgetMgr->IsFormDisabled()) { - m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor, - rtPopup); - return; - } - GetPopupPosGeneral(fMinHeight, fMaxHeight, rtAnchor, rtPopup); -} - -bool CFWL_Widget::GetPopupPosMenu(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) { - FX_FLOAT fx = 0; - FX_FLOAT fy = 0; - - if (GetStylesEx() & FWL_STYLEEXT_MNU_Vert) { - bool bLeft = m_pProperties->m_rtWidget.left < 0; - FX_FLOAT fRight = rtAnchor.right() + rtPopup.width; - TransformTo(nullptr, fx, fy); - if (fRight + fx > 0.0f || bLeft) { - rtPopup.Set(rtAnchor.left - rtPopup.width, rtAnchor.top, rtPopup.width, - rtPopup.height); - } else { - rtPopup.Set(rtAnchor.right(), rtAnchor.top, rtPopup.width, - rtPopup.height); - } - } else { - FX_FLOAT fBottom = rtAnchor.bottom() + rtPopup.height; - TransformTo(nullptr, fx, fy); - if (fBottom + fy > 0.0f) { - rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, - rtPopup.height); - } else { - rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, - rtPopup.height); - } - } - rtPopup.Offset(fx, fy); - return true; -} - -bool CFWL_Widget::GetPopupPosComboBox(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) { - FX_FLOAT fx = 0; - FX_FLOAT fy = 0; - - FX_FLOAT fPopHeight = rtPopup.height; - if (rtPopup.height > fMaxHeight) - fPopHeight = fMaxHeight; - else if (rtPopup.height < fMinHeight) - fPopHeight = fMinHeight; - - FX_FLOAT fWidth = std::max(rtAnchor.width, rtPopup.width); - FX_FLOAT fBottom = rtAnchor.bottom() + fPopHeight; - TransformTo(nullptr, fx, fy); - if (fBottom + fy > 0.0f) - rtPopup.Set(rtAnchor.left, rtAnchor.top - fPopHeight, fWidth, fPopHeight); - else - rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), fWidth, fPopHeight); - - rtPopup.Offset(fx, fy); - return true; -} - -bool CFWL_Widget::GetPopupPosGeneral(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) { - FX_FLOAT fx = 0; - FX_FLOAT fy = 0; - - TransformTo(nullptr, fx, fy); - if (rtAnchor.bottom() + fy > 0.0f) { - rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, - rtPopup.height); - } else { - rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, - rtPopup.height); - } - rtPopup.Offset(fx, fy); - return true; -} - -void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource) { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); - if (!pNoteDriver) - return; - - pNoteDriver->RegisterEventTarget(this, pEventSource); -} - -void CFWL_Widget::UnregisterEventTarget() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); - if (!pNoteDriver) - return; - - pNoteDriver->UnregisterEventTarget(this); -} - -void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { - if (m_pOuter) { - m_pOuter->GetDelegate()->OnProcessEvent(pEvent); - return; - } - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); - if (!pNoteDriver) - return; - pNoteDriver->SendEvent(pEvent); -} - -void CFWL_Widget::Repaint(const CFX_RectF* pRect) { - if (pRect) { - m_pWidgetMgr->RepaintWidget(this, pRect); - return; - } - CFX_RectF rect; - rect = m_pProperties->m_rtWidget; - rect.left = rect.top = 0; - m_pWidgetMgr->RepaintWidget(this, &rect); -} - -void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, - CFWL_Part iPartBk, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFX_RectF rtRelative; - GetRelativeRect(rtRelative); - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = iPartBk; - param.m_pGraphics = pGraphics; - if (pMatrix) - param.m_matrix.Concat(*pMatrix, true); - param.m_rtPart = rtRelative; - pTheme->DrawBackground(¶m); -} - -void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics, - CFWL_Part iPartBorder, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFX_RectF rtRelative; - GetRelativeRect(rtRelative); - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = iPartBorder; - param.m_pGraphics = pGraphics; - if (pMatrix) - param.m_matrix.Concat(*pMatrix, true); - param.m_rtPart = rtRelative; - pTheme->DrawBackground(¶m); -} - -void CFWL_Widget::DrawEdge(CFX_Graphics* pGraphics, - CFWL_Part iPartEdge, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = iPartEdge; - param.m_pGraphics = pGraphics; - if (pMatrix) - param.m_matrix.Concat(*pMatrix, true); - param.m_rtPart = rtEdge; - pTheme->DrawBackground(¶m); -} - -void CFWL_Widget::NotifyDriver() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->NotifyTargetDestroy(this); -} - -CFX_SizeF CFWL_Widget::GetOffsetFromParent(CFWL_Widget* pParent) { - if (pParent == this) - return CFX_SizeF(); - - CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr) - return CFX_SizeF(); - - CFX_SizeF szRet(m_pProperties->m_rtWidget.left, - m_pProperties->m_rtWidget.top); - - CFWL_Widget* pDstWidget = GetParent(); - while (pDstWidget && pDstWidget != pParent) { - CFX_RectF rtDst = pDstWidget->GetWidgetRect(); - szRet += CFX_SizeF(rtDst.left, rtDst.top); - pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget); - } - return szRet; -} - -bool CFWL_Widget::IsParent(CFWL_Widget* pParent) { - CFWL_Widget* pUpWidget = GetParent(); - while (pUpWidget) { - if (pUpWidget == pParent) - return true; - pUpWidget = pUpWidget->GetParent(); - } - return false; -} - -void CFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage->m_pDstTarget) - return; - - CFWL_Widget* pWidget = pMessage->m_pDstTarget; - switch (pMessage->GetType()) { - case CFWL_Message::Type::Mouse: { - CFWL_MsgMouse* pMsgMouse = static_cast(pMessage); - - CFWL_EvtMouse evt(pWidget, pWidget); - evt.m_dwCmd = pMsgMouse->m_dwCmd; - pWidget->DispatchEvent(&evt); - break; - } - default: - break; - } -} - -void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {} - -void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) {} diff --git a/xfa/fwl/core/cfwl_widget.h b/xfa/fwl/core/cfwl_widget.h deleted file mode 100644 index 15acbf53c0..0000000000 --- a/xfa/fwl/core/cfwl_widget.h +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_WIDGET_H_ -#define XFA_FWL_CORE_CFWL_WIDGET_H_ -#include - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_widgethit.h" -#include "xfa/fwl/core/ifwl_widgetdelegate.h" -#include "xfa/fwl/theme/cfwl_widgettp.h" - -enum class FWL_Type { - Unknown = 0, - - Barcode, - Caret, - CheckBox, - ComboBox, - DateTimePicker, - Edit, - Form, - FormProxy, - ListBox, - MonthCalendar, - PictureBox, - PushButton, - ScrollBar, - SpinButton, - ToolTip -}; - -class CFWL_App; -class CFWL_AppImp; -class CFWL_MsgKey; -class CFWL_Widget; -class CFWL_WidgetMgr; -class CFWL_WidgetProperties; -class IFWL_ThemeProvider; - -class CFWL_Widget : public IFWL_WidgetDelegate { - public: - ~CFWL_Widget() override; - - virtual FWL_Type GetClassID() const = 0; - virtual bool IsInstance(const CFX_WideStringC& wsClass) const; - virtual CFX_RectF GetAutosizedWidgetRect(); - virtual CFX_RectF GetWidgetRect(); - virtual void GetClientRect(CFX_RectF& rect); - virtual void ModifyStylesEx(uint32_t dwStylesExAdded, - uint32_t dwStylesExRemoved); - virtual void SetStates(uint32_t dwStates); - virtual void RemoveStates(uint32_t dwStates); - virtual void Update() = 0; - virtual FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy); - virtual void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) = 0; - virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); - - // IFWL_WidgetDelegate. - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void InflateWidgetRect(CFX_RectF& rect); - void SetWidgetRect(const CFX_RectF& rect); - - void SetParent(CFWL_Widget* pParent); - - CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); } - CFWL_Widget* GetOuter() const { return m_pOuter; } - - uint32_t GetStyles() const; - void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); - uint32_t GetStylesEx() const; - uint32_t GetStates() const; - - void LockUpdate() { m_iLock++; } - void UnlockUpdate() { - if (IsLocked()) - m_iLock--; - } - - void TransformTo(CFWL_Widget* pWidget, FX_FLOAT& fx, FX_FLOAT& fy); - void GetMatrix(CFX_Matrix& matrix, bool bGlobal); - IFWL_ThemeProvider* GetThemeProvider() const; - - void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } - IFWL_WidgetDelegate* GetDelegate() { - return m_pDelegate ? m_pDelegate : this; - } - const IFWL_WidgetDelegate* GetDelegate() const { - return m_pDelegate ? m_pDelegate : this; - } - - const CFWL_App* GetOwnerApp() const { return m_pOwnerApp; } - uint32_t GetEventKey() const { return m_nEventKey; } - void SetEventKey(uint32_t key) { m_nEventKey = key; } - - void* GetLayoutItem() const { return m_pLayoutItem; } - void SetLayoutItem(void* pItem) { m_pLayoutItem = pItem; } - - void SetFocus(bool bFocus); - void Repaint(const CFX_RectF* pRect); - - protected: - CFWL_Widget(const CFWL_App* app, - std::unique_ptr properties, - CFWL_Widget* pOuter); - - bool IsEnabled() const; - bool IsActive() const; - bool IsLocked() const { return m_iLock > 0; } - bool HasBorder() const; - bool HasEdge() const; - void GetEdgeRect(CFX_RectF& rtEdge); - FX_FLOAT GetBorderSize(bool bCX); - FX_FLOAT GetEdgeWidth(); - void GetRelativeRect(CFX_RectF& rect); - void* GetThemeCapacity(CFWL_WidgetCapacity dwCapacity); - IFWL_ThemeProvider* GetAvailableTheme(); - CFX_SizeF CalcTextSize(const CFX_WideString& wsText, - IFWL_ThemeProvider* pTheme, - bool bMultiLine); - void CalcTextRect(const CFX_WideString& wsText, - IFWL_ThemeProvider* pTheme, - uint32_t dwTTOStyles, - int32_t iTTOAlign, - CFX_RectF& rect); - void SetGrab(bool bSet); - void GetPopupPos(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup); - void RegisterEventTarget(CFWL_Widget* pEventSource); - void UnregisterEventTarget(); - void DispatchEvent(CFWL_Event* pEvent); - void DrawBorder(CFX_Graphics* pGraphics, - CFWL_Part iPartBorder, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawEdge(CFX_Graphics* pGraphics, - CFWL_Part iPartEdge, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - - const CFWL_App* const m_pOwnerApp; - CFWL_WidgetMgr* const m_pWidgetMgr; - std::unique_ptr m_pProperties; - CFWL_Widget* m_pOuter; - int32_t m_iLock; - - private: - CFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); } - CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent); - - bool IsVisible() const; - bool IsOverLapper() const; - bool IsPopup() const; - bool IsChild() const; - bool IsOffscreen() const; - CFWL_Widget* GetRootOuter(); - bool GetPopupPosMenu(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup); - bool GetPopupPosComboBox(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup); - bool GetPopupPosGeneral(FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup); - bool GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy); - void DrawBackground(CFX_Graphics* pGraphics, - CFWL_Part iPartBk, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void NotifyDriver(); - bool IsParent(CFWL_Widget* pParent); - - void* m_pLayoutItem; - uint32_t m_nEventKey; - IFWL_WidgetDelegate* m_pDelegate; // Not owned. -}; - -#endif // XFA_FWL_CORE_CFWL_WIDGET_H_ diff --git a/xfa/fwl/core/cfwl_widgetmgr.cpp b/xfa/fwl/core/cfwl_widgetmgr.cpp deleted file mode 100644 index 5bcef7b7df..0000000000 --- a/xfa/fwl/core/cfwl_widgetmgr.cpp +++ /dev/null @@ -1,732 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_widgetmgr.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_form.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" -#include "xfa/fxfa/xfa_ffapp.h" - -namespace { - -const int kNeedRepaintHitPoints = 12; -const int kNeedRepaintHitPiece = 3; - -struct FWL_NEEDREPAINTHITDATA { - CFX_PointF hitPoint; - bool bNotNeedRepaint; - bool bNotContainByDirty; -}; - -} // namespace - -bool FWL_UseOffscreen(CFWL_Widget* pWidget) { -#if (_FX_OS_ == _FX_MACOSX_) - return false; -#else - return !!(pWidget->GetStyles() & FWL_WGTSTYLE_Offscreen); -#endif -} - -CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative) - : m_dwCapability(0), m_pAdapter(pAdapterNative->GetWidgetMgr(this)) { - ASSERT(m_pAdapter); - m_mapWidgetItem[nullptr] = pdfium::MakeUnique(); -#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - m_rtScreen.Reset(); -#endif -} - -CFWL_WidgetMgr::~CFWL_WidgetMgr() {} - -CFWL_Widget* CFWL_WidgetMgr::GetParentWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - return pItem && pItem->pParent ? pItem->pParent->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetOwnerWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - return pItem && pItem->pOwner ? pItem->pOwner->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetFirstSiblingWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - if (!pItem) - return nullptr; - - pItem = pItem->pPrevious; - while (pItem && pItem->pPrevious) - pItem = pItem->pPrevious; - return pItem ? pItem->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetPriorSiblingWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - return pItem && pItem->pPrevious ? pItem->pPrevious->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetNextSiblingWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - return pItem && pItem->pNext ? pItem->pNext->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetFirstChildWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - return pItem && pItem->pChild ? pItem->pChild->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetLastChildWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - if (!pItem) - return nullptr; - - pItem = pItem->pChild; - while (pItem && pItem->pNext) - pItem = pItem->pNext; - return pItem ? pItem->pWidget : nullptr; -} - -CFWL_Widget* CFWL_WidgetMgr::GetSystemFormWidget(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - while (pItem) { - if (IsAbleNative(pItem->pWidget)) - return pItem->pWidget; - pItem = pItem->pParent; - } - return nullptr; -} - -void CFWL_WidgetMgr::AppendWidget(CFWL_Widget* pWidget) { - Item* pItem = GetWidgetMgrItem(pWidget); - if (!pItem) - return; - if (!pItem->pParent) - return; - - Item* pChild = pItem->pParent->pChild; - int32_t i = 0; - while (pChild) { - if (pChild == pItem) { - if (pChild->pPrevious) - pChild->pPrevious->pNext = pChild->pNext; - if (pChild->pNext) - pChild->pNext->pPrevious = pChild->pPrevious; - if (pItem->pParent->pChild == pItem) - pItem->pParent->pChild = pItem->pNext; - - pItem->pNext = nullptr; - pItem->pPrevious = nullptr; - break; - } - if (!pChild->pNext) - break; - - pChild = pChild->pNext; - ++i; - } - - pChild = pItem->pParent->pChild; - if (pChild) { - while (pChild->pNext) - pChild = pChild->pNext; - - pChild->pNext = pItem; - pItem->pPrevious = pChild; - } else { - pItem->pParent->pChild = pItem; - pItem->pPrevious = nullptr; - } - pItem->pNext = nullptr; -} - -void CFWL_WidgetMgr::RepaintWidget(CFWL_Widget* pWidget, - const CFX_RectF* pRect) { - if (!m_pAdapter) - return; - - CFWL_Widget* pNative = pWidget; - CFX_RectF rect(*pRect); - if (IsFormDisabled()) { - CFWL_Widget* pOuter = pWidget->GetOuter(); - while (pOuter) { - CFX_RectF rtTemp = pNative->GetWidgetRect(); - rect.left += rtTemp.left; - rect.top += rtTemp.top; - pNative = pOuter; - pOuter = pOuter->GetOuter(); - } - } else if (!IsAbleNative(pWidget)) { - pNative = GetSystemFormWidget(pWidget); - if (!pNative) - return; - - pWidget->TransformTo(pNative, rect.left, rect.top); - } - AddRedrawCounts(pNative); - m_pAdapter->RepaintWidget(pNative, &rect); -} - -void CFWL_WidgetMgr::InsertWidget(CFWL_Widget* pParent, CFWL_Widget* pChild) { - Item* pParentItem = GetWidgetMgrItem(pParent); - if (!pParentItem) { - auto item = pdfium::MakeUnique(pParent); - pParentItem = item.get(); - m_mapWidgetItem[pParent] = std::move(item); - - pParentItem->pParent = GetWidgetMgrItem(nullptr); - AppendWidget(pParent); - } - - Item* pItem = GetWidgetMgrItem(pChild); - if (!pItem) { - auto item = pdfium::MakeUnique(pChild); - pItem = item.get(); - m_mapWidgetItem[pChild] = std::move(item); - } - if (pItem->pParent && pItem->pParent != pParentItem) { - if (pItem->pPrevious) - pItem->pPrevious->pNext = pItem->pNext; - if (pItem->pNext) - pItem->pNext->pPrevious = pItem->pPrevious; - if (pItem->pParent->pChild == pItem) - pItem->pParent->pChild = pItem->pNext; - } - pItem->pParent = pParentItem; - AppendWidget(pChild); -} - -void CFWL_WidgetMgr::RemoveWidget(CFWL_Widget* pWidget) { - Item* pItem = GetWidgetMgrItem(pWidget); - if (!pItem) - return; - if (pItem->pPrevious) - pItem->pPrevious->pNext = pItem->pNext; - if (pItem->pNext) - pItem->pNext->pPrevious = pItem->pPrevious; - if (pItem->pParent && pItem->pParent->pChild == pItem) - pItem->pParent->pChild = pItem->pNext; - - Item* pChild = pItem->pChild; - while (pChild) { - Item* pNext = pChild->pNext; - RemoveWidget(pChild->pWidget); - pChild = pNext; - } - m_mapWidgetItem.erase(pWidget); -} - -void CFWL_WidgetMgr::SetOwner(CFWL_Widget* pOwner, CFWL_Widget* pOwned) { - Item* pParentItem = GetWidgetMgrItem(pOwner); - if (!pParentItem) { - auto item = pdfium::MakeUnique(pOwner); - pParentItem = item.get(); - m_mapWidgetItem[pOwner] = std::move(item); - - pParentItem->pParent = GetWidgetMgrItem(nullptr); - AppendWidget(pOwner); - } - - Item* pItem = GetWidgetMgrItem(pOwned); - if (!pItem) { - auto item = pdfium::MakeUnique(pOwned); - pItem = item.get(); - m_mapWidgetItem[pOwned] = std::move(item); - } - pItem->pOwner = pParentItem; -} -void CFWL_WidgetMgr::SetParent(CFWL_Widget* pParent, CFWL_Widget* pChild) { - Item* pParentItem = GetWidgetMgrItem(pParent); - Item* pItem = GetWidgetMgrItem(pChild); - if (!pItem) - return; - if (pItem->pParent && pItem->pParent != pParentItem) { - if (pItem->pPrevious) - pItem->pPrevious->pNext = pItem->pNext; - if (pItem->pNext) - pItem->pNext->pPrevious = pItem->pPrevious; - if (pItem->pParent->pChild == pItem) - pItem->pParent->pChild = pItem->pNext; - - pItem->pNext = nullptr; - pItem->pPrevious = nullptr; - } - pItem->pParent = pParentItem; - AppendWidget(pChild); -} - -void CFWL_WidgetMgr::SetWidgetRect_Native(CFWL_Widget* pWidget, - const CFX_RectF& rect) { - if (!FWL_UseOffscreen(pWidget)) - return; - - Item* pItem = GetWidgetMgrItem(pWidget); - pItem->iRedrawCounter++; - if (pItem->pOffscreen) { - CFX_RenderDevice* pDevice = pItem->pOffscreen->GetRenderDevice(); - if (pDevice && pDevice->GetBitmap()) { - CFX_DIBitmap* pBitmap = pDevice->GetBitmap(); - if (pBitmap->GetWidth() - rect.width > 1 || - pBitmap->GetHeight() - rect.height > 1) { - pItem->pOffscreen.reset(); - } - } - } -#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - pItem->bOutsideChanged = !m_rtScreen.Contains(rect); -#endif -} - -CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent, - FX_FLOAT x, - FX_FLOAT y) { - if (!parent) - return nullptr; - - FX_FLOAT x1; - FX_FLOAT y1; - CFWL_Widget* child = GetLastChildWidget(parent); - while (child) { - if ((child->GetStates() & FWL_WGTSTATE_Invisible) == 0) { - x1 = x; - y1 = y; - CFX_Matrix matrixOnParent; - child->GetMatrix(matrixOnParent, false); - CFX_Matrix m; - m.SetIdentity(); - m.SetReverse(matrixOnParent); - m.TransformPoint(x1, y1); - CFX_RectF bounds = child->GetWidgetRect(); - if (bounds.Contains(x1, y1)) { - x1 -= bounds.left; - y1 -= bounds.top; - return GetWidgetAtPoint(child, x1, y1); - } - } - child = GetPriorSiblingWidget(child); - } - return parent; -} - -void CFWL_WidgetMgr::NotifySizeChanged(CFWL_Widget* pForm, - FX_FLOAT fx, - FX_FLOAT fy) { - if (FWL_UseOffscreen(pForm)) - GetWidgetMgrItem(pForm)->pOffscreen.reset(); -} - -CFWL_Widget* CFWL_WidgetMgr::NextTab(CFWL_Widget* parent, - CFWL_Widget* focus, - bool& bFind) { - CFWL_WidgetMgr* pMgr = parent->GetOwnerApp()->GetWidgetMgr(); - CFWL_Widget* child = pMgr->GetFirstChildWidget(parent); - while (child) { - if (focus == child) - bFind = true; - - if ((child->GetStyles() & FWL_WGTSTYLE_TabStop) && - (!focus || (focus != child && bFind))) { - return child; - } - CFWL_Widget* bRet = NextTab(child, focus, bFind); - if (bRet) - return bRet; - - child = pMgr->GetNextSiblingWidget(child); - } - return nullptr; -} - -int32_t CFWL_WidgetMgr::CountRadioButtonGroup(CFWL_Widget* pFirst) const { - int32_t iRet = 0; - CFWL_Widget* pChild = pFirst; - while (pChild) { - pChild = GetNextSiblingWidget(pChild); - ++iRet; - } - return iRet; -} - -CFWL_Widget* CFWL_WidgetMgr::GetRadioButtonGroupHeader( - CFWL_Widget* pRadioButton) const { - CFWL_Widget* pNext = pRadioButton; - if (pNext && (pNext->GetStyles() & FWL_WGTSTYLE_Group)) - return pNext; - return nullptr; -} - -void CFWL_WidgetMgr::GetSameGroupRadioButton( - CFWL_Widget* pRadioButton, - CFX_ArrayTemplate& group) const { - CFWL_Widget* pFirst = GetFirstSiblingWidget(pRadioButton); - if (!pFirst) - pFirst = pRadioButton; - - int32_t iGroup = CountRadioButtonGroup(pFirst); - if (iGroup < 2) - return; - group.Add(GetRadioButtonGroupHeader(pRadioButton)); -} - -CFWL_Widget* CFWL_WidgetMgr::GetDefaultButton(CFWL_Widget* pParent) const { - if ((pParent->GetClassID() == FWL_Type::PushButton) && - (pParent->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) { - return pParent; - } - - CFWL_Widget* child = - pParent->GetOwnerApp()->GetWidgetMgr()->GetFirstChildWidget(pParent); - while (child) { - if ((child->GetClassID() == FWL_Type::PushButton) && - (child->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) { - return child; - } - if (CFWL_Widget* find = GetDefaultButton(child)) - return find; - - child = child->GetOwnerApp()->GetWidgetMgr()->GetNextSiblingWidget(child); - } - return nullptr; -} - -void CFWL_WidgetMgr::AddRedrawCounts(CFWL_Widget* pWidget) { - GetWidgetMgrItem(pWidget)->iRedrawCounter++; -} - -void CFWL_WidgetMgr::ResetRedrawCounts(CFWL_Widget* pWidget) { - GetWidgetMgrItem(pWidget)->iRedrawCounter = 0; -} - -CFWL_WidgetMgr::Item* CFWL_WidgetMgr::GetWidgetMgrItem( - CFWL_Widget* pWidget) const { - auto it = m_mapWidgetItem.find(pWidget); - return it != m_mapWidgetItem.end() ? static_cast(it->second.get()) - : nullptr; -} - -bool CFWL_WidgetMgr::IsAbleNative(CFWL_Widget* pWidget) const { - if (!pWidget) - return false; - if (!pWidget->IsInstance(FX_WSTRC(FWL_CLASS_Form))) - return false; - - uint32_t dwStyles = pWidget->GetStyles(); - return ((dwStyles & FWL_WGTSTYLE_WindowTypeMask) == - FWL_WGTSTYLE_OverLapper) || - (dwStyles & FWL_WGTSTYLE_Popup); -} - -void CFWL_WidgetMgr::GetAdapterPopupPos(CFWL_Widget* pWidget, - FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) const { - m_pAdapter->GetPopupPos(pWidget, fMinHeight, fMaxHeight, rtAnchor, rtPopup); -} - -void CFWL_WidgetMgr::OnSetCapability(uint32_t dwCapability) { - m_dwCapability = dwCapability; -} - -void CFWL_WidgetMgr::OnProcessMessageToForm(CFWL_Message* pMessage) { - if (!pMessage) - return; - if (!pMessage->m_pDstTarget) - return; - - CFWL_Widget* pDstWidget = pMessage->m_pDstTarget; - const CFWL_App* pApp = pDstWidget->GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pNoteDriver = - static_cast(pApp->GetNoteDriver()); - if (!pNoteDriver) - return; - - std::unique_ptr pClonedMessage = pMessage->Clone(); - if (IsFormDisabled()) - pNoteDriver->ProcessMessage(pClonedMessage.get()); - else - pNoteDriver->QueueMessage(std::move(pClonedMessage)); - -#if (_FX_OS_ == _FX_MACOSX_) - CFWL_NoteLoop* pTopLoop = pNoteDriver->GetTopLoop(); - if (pTopLoop) - pNoteDriver->UnqueueMessage(pTopLoop); -#endif -} - -void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pWidget || !pGraphics) - return; - - CFX_Graphics* pTemp = DrawWidgetBefore(pWidget, pGraphics, pMatrix); - CFX_RectF clipCopy = pWidget->GetWidgetRect(); - clipCopy.left = clipCopy.top = 0; - - if (UseOffscreenDirect(pWidget)) { - DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); - return; - } - CFX_RectF clipBounds; - -#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ || \ - _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_ - pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); - pGraphics->GetClipRect(clipBounds); - clipCopy = clipBounds; -#elif _FX_OS_ == _FX_MACOSX_ - if (IsFormDisabled()) { - pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); - pGraphics->GetClipRect(clipBounds); - clipCopy = clipBounds; - } else { - clipBounds.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d); - const_cast(pMatrix)->SetIdentity(); // FIXME: const cast. - pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); - } -#endif // _FX_OS_ == _FX_MACOSX_ - - if (!IsFormDisabled()) { - CFX_RectF rtClient; - pWidget->GetClientRect(rtClient); - clipBounds.Intersect(rtClient); - } - if (!clipBounds.IsEmpty()) - DrawChild(pWidget, clipBounds, pTemp, pMatrix); - - DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); - ResetRedrawCounts(pWidget); -} - -void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent, - const CFX_RectF& rtClip, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!parent) - return; - - bool bFormDisable = IsFormDisabled(); - CFWL_Widget* pNextChild = GetFirstChildWidget(parent); - while (pNextChild) { - CFWL_Widget* child = pNextChild; - pNextChild = GetNextSiblingWidget(child); - if (child->GetStates() & FWL_WGTSTATE_Invisible) - continue; - - CFX_RectF rtWidget = child->GetWidgetRect(); - if (rtWidget.IsEmpty()) - continue; - - CFX_Matrix widgetMatrix; - CFX_RectF clipBounds(rtWidget); - if (!bFormDisable) - child->GetMatrix(widgetMatrix, true); - if (pMatrix) - widgetMatrix.Concat(*pMatrix); - - if (!bFormDisable) { - widgetMatrix.TransformPoint(clipBounds.left, clipBounds.top); - clipBounds.Intersect(rtClip); - if (clipBounds.IsEmpty()) - continue; - - pGraphics->SaveGraphState(); - pGraphics->SetClipRect(clipBounds); - } - widgetMatrix.Translate(rtWidget.left, rtWidget.top, true); - - if (IFWL_WidgetDelegate* pDelegate = child->GetDelegate()) { - if (IsFormDisabled() || IsNeedRepaint(child, &widgetMatrix, rtClip)) - pDelegate->OnDrawWidget(pGraphics, &widgetMatrix); - } - if (!bFormDisable) - pGraphics->RestoreGraphState(); - - DrawChild(child, clipBounds, pGraphics, - bFormDisable ? &widgetMatrix : pMatrix); - child = GetNextSiblingWidget(child); - } -} - -CFX_Graphics* CFWL_WidgetMgr::DrawWidgetBefore(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!FWL_UseOffscreen(pWidget)) - return pGraphics; - - Item* pItem = GetWidgetMgrItem(pWidget); - if (!pItem->pOffscreen) { - pItem->pOffscreen.reset(new CFX_Graphics); - CFX_RectF rect = pWidget->GetWidgetRect(); - pItem->pOffscreen->Create((int32_t)rect.width, (int32_t)rect.height, - FXDIB_Argb); - } - CFX_RectF rect; - pGraphics->GetClipRect(rect); - pItem->pOffscreen->SetClipRect(rect); - return pItem->pOffscreen.get(); -} - -void CFWL_WidgetMgr::DrawWidgetAfter(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - CFX_RectF& rtClip, - const CFX_Matrix* pMatrix) { - if (FWL_UseOffscreen(pWidget)) { - Item* pItem = GetWidgetMgrItem(pWidget); - pGraphics->Transfer(pItem->pOffscreen.get(), rtClip.left, rtClip.top, - rtClip, pMatrix); -#ifdef _WIN32 - pItem->pOffscreen->ClearClip(); -#endif - } - Item* pItem = GetWidgetMgrItem(pWidget); - pItem->iRedrawCounter = 0; -} - -bool CFWL_WidgetMgr::IsNeedRepaint(CFWL_Widget* pWidget, - CFX_Matrix* pMatrix, - const CFX_RectF& rtDirty) { - Item* pItem = GetWidgetMgrItem(pWidget); - if (pItem && pItem->iRedrawCounter > 0) { - pItem->iRedrawCounter = 0; - return true; - } - - CFX_RectF rtWidget = pWidget->GetWidgetRect(); - rtWidget.left = rtWidget.top = 0; - pMatrix->TransformRect(rtWidget); - if (!rtWidget.IntersectWith(rtDirty)) - return false; - - CFWL_Widget* pChild = - pWidget->GetOwnerApp()->GetWidgetMgr()->GetFirstChildWidget(pWidget); - if (!pChild) - return true; - - CFX_RectF rtChilds; - rtChilds.Empty(); - bool bChildIntersectWithDirty = false; - bool bOrginPtIntersectWidthChild = false; - bool bOrginPtIntersectWidthDirty = - rtDirty.Contains(rtWidget.left, rtWidget.top); - static FWL_NEEDREPAINTHITDATA hitPoint[kNeedRepaintHitPoints]; - FXSYS_memset(hitPoint, 0, sizeof(hitPoint)); - FX_FLOAT fxPiece = rtWidget.width / kNeedRepaintHitPiece; - FX_FLOAT fyPiece = rtWidget.height / kNeedRepaintHitPiece; - hitPoint[2].hitPoint.x = hitPoint[6].hitPoint.x = rtWidget.left; - hitPoint[0].hitPoint.x = hitPoint[3].hitPoint.x = hitPoint[7].hitPoint.x = - hitPoint[10].hitPoint.x = fxPiece + rtWidget.left; - hitPoint[1].hitPoint.x = hitPoint[4].hitPoint.x = hitPoint[8].hitPoint.x = - hitPoint[11].hitPoint.x = fxPiece * 2 + rtWidget.left; - hitPoint[5].hitPoint.x = hitPoint[9].hitPoint.x = - rtWidget.width + rtWidget.left; - hitPoint[0].hitPoint.y = hitPoint[1].hitPoint.y = rtWidget.top; - hitPoint[2].hitPoint.y = hitPoint[3].hitPoint.y = hitPoint[4].hitPoint.y = - hitPoint[5].hitPoint.y = fyPiece + rtWidget.top; - hitPoint[6].hitPoint.y = hitPoint[7].hitPoint.y = hitPoint[8].hitPoint.y = - hitPoint[9].hitPoint.y = fyPiece * 2 + rtWidget.top; - hitPoint[10].hitPoint.y = hitPoint[11].hitPoint.y = - rtWidget.height + rtWidget.top; - do { - CFX_RectF rect = pChild->GetWidgetRect(); - CFX_RectF r = rect; - r.left += rtWidget.left; - r.top += rtWidget.top; - if (r.IsEmpty()) - continue; - if (r.Contains(rtDirty)) - return false; - if (!bChildIntersectWithDirty && r.IntersectWith(rtDirty)) - bChildIntersectWithDirty = true; - if (bOrginPtIntersectWidthDirty && !bOrginPtIntersectWidthChild) - bOrginPtIntersectWidthChild = rect.Contains(0, 0); - - if (rtChilds.IsEmpty()) - rtChilds = rect; - else if (!(pChild->GetStates() & FWL_WGTSTATE_Invisible)) - rtChilds.Union(rect); - - for (int32_t i = 0; i < kNeedRepaintHitPoints; i++) { - if (hitPoint[i].bNotContainByDirty || hitPoint[i].bNotNeedRepaint) - continue; - if (!rtDirty.Contains(hitPoint[i].hitPoint)) { - hitPoint[i].bNotContainByDirty = true; - continue; - } - if (r.Contains(hitPoint[i].hitPoint)) - hitPoint[i].bNotNeedRepaint = true; - } - pChild = - pChild->GetOwnerApp()->GetWidgetMgr()->GetNextSiblingWidget(pChild); - } while (pChild); - - if (!bChildIntersectWithDirty) - return true; - if (bOrginPtIntersectWidthDirty && !bOrginPtIntersectWidthChild) - return true; - if (rtChilds.IsEmpty()) - return true; - - int32_t repaintPoint = kNeedRepaintHitPoints; - for (int32_t i = 0; i < kNeedRepaintHitPoints; i++) { - if (hitPoint[i].bNotNeedRepaint) - repaintPoint--; - } - if (repaintPoint > 0) - return true; - - pMatrix->TransformRect(rtChilds); - if (rtChilds.Contains(rtDirty) || rtChilds.Contains(rtWidget)) - return false; - return true; -} - -bool CFWL_WidgetMgr::UseOffscreenDirect(CFWL_Widget* pWidget) const { - Item* pItem = GetWidgetMgrItem(pWidget); - if (!FWL_UseOffscreen(pWidget) || !(pItem->pOffscreen)) - return false; - -#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - if (pItem->bOutsideChanged) { - CFX_RectF r = pWidget->GetWidgetRect(); - CFX_RectF temp(m_rtScreen); - temp.Deflate(50, 50); - if (!temp.Contains(r)) - return false; - - pItem->bOutsideChanged = false; - } -#endif - - return pItem->iRedrawCounter == 0; -} - -CFWL_WidgetMgr::Item::Item() : CFWL_WidgetMgr::Item(nullptr) {} - -CFWL_WidgetMgr::Item::Item(CFWL_Widget* widget) - : pParent(nullptr), - pOwner(nullptr), - pChild(nullptr), - pPrevious(nullptr), - pNext(nullptr), - pWidget(widget), - iRedrawCounter(0) -#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - , - bOutsideChanged(false) -#endif -{ -} - -CFWL_WidgetMgr::Item::~Item() {} diff --git a/xfa/fwl/core/cfwl_widgetmgr.h b/xfa/fwl/core/cfwl_widgetmgr.h deleted file mode 100644 index 5b72d44577..0000000000 --- a/xfa/fwl/core/cfwl_widgetmgr.h +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_WIDGETMGR_H_ -#define XFA_FWL_CORE_CFWL_WIDGETMGR_H_ - -#include -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/fwl_error.h" -#include "xfa/fwl/core/ifwl_widgetmgrdelegate.h" -#include "xfa/fxgraphics/cfx_graphics.h" - -#define FWL_WGTMGR_DisableForm 0x00000002 - -class CFWL_Message; -class CXFA_FFApp; -class CXFA_FWLAdapterWidgetMgr; -class CFX_Graphics; -class CFX_Matrix; -class CFWL_Widget; - -class CFWL_WidgetMgr : public CFWL_WidgetMgrDelegate { - public: - explicit CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative); - ~CFWL_WidgetMgr(); - - // CFWL_WidgetMgrDelegate - void OnSetCapability(uint32_t dwCapability) override; - void OnProcessMessageToForm(CFWL_Message* pMessage) override; - void OnDrawWidget(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - CFWL_Widget* GetParentWidget(CFWL_Widget* pWidget) const; - CFWL_Widget* GetOwnerWidget(CFWL_Widget* pWidget) const; - CFWL_Widget* GetNextSiblingWidget(CFWL_Widget* pWidget) const; - CFWL_Widget* GetFirstChildWidget(CFWL_Widget* pWidget) const; - CFWL_Widget* GetSystemFormWidget(CFWL_Widget* pWidget) const; - - void RepaintWidget(CFWL_Widget* pWidget, const CFX_RectF* pRect); - - void InsertWidget(CFWL_Widget* pParent, CFWL_Widget* pChild); - void RemoveWidget(CFWL_Widget* pWidget); - void SetOwner(CFWL_Widget* pOwner, CFWL_Widget* pOwned); - void SetParent(CFWL_Widget* pParent, CFWL_Widget* pChild); - - void SetWidgetRect_Native(CFWL_Widget* pWidget, const CFX_RectF& rect); - - CFWL_Widget* GetWidgetAtPoint(CFWL_Widget* pParent, FX_FLOAT fx, FX_FLOAT fy); - - void NotifySizeChanged(CFWL_Widget* pForm, FX_FLOAT fx, FX_FLOAT fy); - - CFWL_Widget* NextTab(CFWL_Widget* parent, CFWL_Widget* focus, bool& bFind); - - void GetSameGroupRadioButton(CFWL_Widget* pRadioButton, - CFX_ArrayTemplate& group) const; - CFWL_Widget* GetDefaultButton(CFWL_Widget* pParent) const; - void AddRedrawCounts(CFWL_Widget* pWidget); - - bool IsFormDisabled() const { - return !!(m_dwCapability & FWL_WGTMGR_DisableForm); - } - - void GetAdapterPopupPos(CFWL_Widget* pWidget, - FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) const; - - private: - class Item { - public: - Item(); - explicit Item(CFWL_Widget* widget); - ~Item(); - - Item* pParent; - Item* pOwner; - Item* pChild; - Item* pPrevious; - Item* pNext; - CFWL_Widget* const pWidget; - std::unique_ptr pOffscreen; - int32_t iRedrawCounter; -#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - bool bOutsideChanged; -#endif - }; - - CFWL_Widget* GetFirstSiblingWidget(CFWL_Widget* pWidget) const; - CFWL_Widget* GetPriorSiblingWidget(CFWL_Widget* pWidget) const; - CFWL_Widget* GetLastChildWidget(CFWL_Widget* pWidget) const; - Item* GetWidgetMgrItem(CFWL_Widget* pWidget) const; - - void AppendWidget(CFWL_Widget* pWidget); - - int32_t CountRadioButtonGroup(CFWL_Widget* pFirst) const; - CFWL_Widget* GetRadioButtonGroupHeader(CFWL_Widget* pRadioButton) const; - - void ResetRedrawCounts(CFWL_Widget* pWidget); - - void DrawChild(CFWL_Widget* pParent, - const CFX_RectF& rtClip, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix); - CFX_Graphics* DrawWidgetBefore(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix); - void DrawWidgetAfter(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - CFX_RectF& rtClip, - const CFX_Matrix* pMatrix); - bool IsNeedRepaint(CFWL_Widget* pWidget, - CFX_Matrix* pMatrix, - const CFX_RectF& rtDirty); - bool UseOffscreenDirect(CFWL_Widget* pWidget) const; - - bool IsAbleNative(CFWL_Widget* pWidget) const; - - uint32_t m_dwCapability; - std::map> m_mapWidgetItem; - CXFA_FWLAdapterWidgetMgr* const m_pAdapter; -#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - CFX_RectF m_rtScreen; -#endif -}; - -#endif // XFA_FWL_CORE_CFWL_WIDGETMGR_H_ diff --git a/xfa/fwl/core/cfwl_widgetproperties.cpp b/xfa/fwl/core/cfwl_widgetproperties.cpp deleted file mode 100644 index 6e0330012c..0000000000 --- a/xfa/fwl/core/cfwl_widgetproperties.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfwl_widgetproperties.h" - -CFWL_WidgetProperties::CFWL_WidgetProperties() - : m_dwStyles(FWL_WGTSTYLE_Child), - m_dwStyleExes(0), - m_dwStates(0), - m_pThemeProvider(nullptr), - m_pParent(nullptr), - m_pOwner(nullptr) { - m_rtWidget.Set(0, 0, 0, 0); -} - -CFWL_WidgetProperties::~CFWL_WidgetProperties() {} diff --git a/xfa/fwl/core/cfwl_widgetproperties.h b/xfa/fwl/core/cfwl_widgetproperties.h deleted file mode 100644 index d7bf72e9f9..0000000000 --- a/xfa/fwl/core/cfwl_widgetproperties.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFWL_WIDGETPROPERTIES_H_ -#define XFA_FWL_CORE_CFWL_WIDGETPROPERTIES_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/fwl_widgetdef.h" - -class IFWL_ThemeProvider; -class CFWL_Widget; - -class CFWL_WidgetProperties { - public: - CFWL_WidgetProperties(); - ~CFWL_WidgetProperties(); - - CFX_RectF m_rtWidget; - uint32_t m_dwStyles; - uint32_t m_dwStyleExes; - uint32_t m_dwStates; - IFWL_ThemeProvider* m_pThemeProvider; - CFWL_Widget* m_pParent; - CFWL_Widget* m_pOwner; -}; - -#endif // XFA_FWL_CORE_CFWL_WIDGETPROPERTIES_H_ diff --git a/xfa/fwl/core/cfx_barcode.cpp b/xfa/fwl/core/cfx_barcode.cpp deleted file mode 100644 index 12c0cb0929..0000000000 --- a/xfa/fwl/core/cfx_barcode.cpp +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/cfx_barcode.h" - -#include "xfa/fxbarcode/cbc_codabar.h" -#include "xfa/fxbarcode/cbc_code128.h" -#include "xfa/fxbarcode/cbc_code39.h" -#include "xfa/fxbarcode/cbc_codebase.h" -#include "xfa/fxbarcode/cbc_datamatrix.h" -#include "xfa/fxbarcode/cbc_ean13.h" -#include "xfa/fxbarcode/cbc_ean8.h" -#include "xfa/fxbarcode/cbc_pdf417i.h" -#include "xfa/fxbarcode/cbc_qrcode.h" -#include "xfa/fxbarcode/cbc_upca.h" -#include "xfa/fxbarcode/utils.h" - -namespace { - -CBC_CodeBase* CreateBarCodeEngineObject(BC_TYPE type) { - switch (type) { - case BC_CODE39: - return new CBC_Code39(); - case BC_CODABAR: - return new CBC_Codabar(); - case BC_CODE128: - return new CBC_Code128(BC_CODE128_B); - case BC_CODE128_B: - return new CBC_Code128(BC_CODE128_B); - case BC_CODE128_C: - return new CBC_Code128(BC_CODE128_C); - case BC_EAN8: - return new CBC_EAN8(); - case BC_UPCA: - return new CBC_UPCA(); - case BC_EAN13: - return new CBC_EAN13(); - case BC_QR_CODE: - return new CBC_QRCode(); - case BC_PDF417: - return new CBC_PDF417I(); - case BC_DATAMATRIX: - return new CBC_DataMatrix(); - case BC_UNKNOWN: - default: - return nullptr; - } -} - -} // namespace - -CFX_Barcode::CFX_Barcode() {} - -CFX_Barcode::~CFX_Barcode() {} - -bool CFX_Barcode::Create(BC_TYPE type) { - m_pBCEngine.reset(CreateBarCodeEngineObject(type)); - return !!m_pBCEngine; -} - -BC_TYPE CFX_Barcode::GetType() { - return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN; -} - -bool CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { - return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : false; -} - -bool CFX_Barcode::SetModuleHeight(int32_t moduleHeight) { - return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : false; -} - -bool CFX_Barcode::SetModuleWidth(int32_t moduleWidth) { - return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : false; -} - -bool CFX_Barcode::SetHeight(int32_t height) { - return m_pBCEngine ? m_pBCEngine->SetHeight(height) : false; -} - -bool CFX_Barcode::SetWidth(int32_t width) { - return m_pBCEngine ? m_pBCEngine->SetWidth(width) : false; -} - -bool CFX_Barcode::SetPrintChecksum(bool checksum) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine.get()) - ->SetPrintChecksum(checksum), - true) - : false; - default: - return false; - } -} - -bool CFX_Barcode::SetDataLength(int32_t length) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine.get()) - ->SetDataLength(length), - true) - : false; - default: - return false; - } -} - -bool CFX_Barcode::SetCalChecksum(bool state) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine.get()) - ->SetCalChecksum(state), - true) - : false; - default: - return false; - } -} - -bool CFX_Barcode::SetFont(CFX_Font* pFont) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine - ? static_cast(m_pBCEngine.get())->SetFont(pFont) - : false; - default: - return false; - } -} - -bool CFX_Barcode::SetFontSize(FX_FLOAT size) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine.get()) - ->SetFontSize(size), - true) - : false; - default: - return false; - } -} - -bool CFX_Barcode::SetFontColor(FX_ARGB color) { - switch (GetType()) { - case BC_CODE39: - case BC_CODABAR: - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - case BC_EAN8: - case BC_EAN13: - case BC_UPCA: - return m_pBCEngine ? (static_cast(m_pBCEngine.get()) - ->SetFontColor(color), - true) - : false; - default: - return false; - } -} - -bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { - typedef bool (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_CODE39: - memptr = (memptrtype)&CBC_Code39::SetTextLocation; - break; - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetTextLocation; - break; - case BC_CODE128: - case BC_CODE128_B: - case BC_CODE128_C: - memptr = (memptrtype)&CBC_Code128::SetTextLocation; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(location) : false; -} - -bool CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { - typedef bool (CBC_CodeBase::*memptrtype)(int32_t); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_CODE39: - memptr = (memptrtype)&CBC_Code39::SetWideNarrowRatio; - break; - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetWideNarrowRatio; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(ratio) : false; -} - -bool CFX_Barcode::SetStartChar(FX_CHAR start) { - typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetStartChar; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(start) : false; -} - -bool CFX_Barcode::SetEndChar(FX_CHAR end) { - typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_CODABAR: - memptr = (memptrtype)&CBC_Codabar::SetEndChar; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(end) : false; -} - -bool CFX_Barcode::SetVersion(int32_t version) { - typedef bool (CBC_CodeBase::*memptrtype)(int32_t); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_QR_CODE: - memptr = (memptrtype)&CBC_QRCode::SetVersion; - break; - default: - break; - } - return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(version) : false; -} - -bool CFX_Barcode::SetErrorCorrectionLevel(int32_t level) { - typedef bool (CBC_CodeBase::*memptrtype)(int32_t); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_QR_CODE: - memptr = (memptrtype)&CBC_QRCode::SetErrorCorrectionLevel; - break; - case BC_PDF417: - memptr = (memptrtype)&CBC_PDF417I::SetErrorCorrectionLevel; - break; - default: - return false; - } - return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(level) : false; -} -bool CFX_Barcode::SetTruncated(bool truncated) { - typedef void (CBC_CodeBase::*memptrtype)(bool); - memptrtype memptr = nullptr; - switch (GetType()) { - case BC_PDF417: - memptr = (memptrtype)&CBC_PDF417I::SetTruncated; - break; - default: - break; - } - return m_pBCEngine && memptr ? ((m_pBCEngine.get()->*memptr)(truncated), true) - : false; -} - -bool CFX_Barcode::Encode(const CFX_WideStringC& contents, - bool isDevice, - int32_t& e) { - return m_pBCEngine && m_pBCEngine->Encode(contents, isDevice, e); -} - -bool CFX_Barcode::RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e) { - return m_pBCEngine && m_pBCEngine->RenderDevice(device, matrix, e); -} diff --git a/xfa/fwl/core/cfx_barcode.h b/xfa/fwl/core/cfx_barcode.h deleted file mode 100644 index 21fb7451d4..0000000000 --- a/xfa/fwl/core/cfx_barcode.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_CFX_BARCODE_H_ -#define XFA_FWL_CORE_CFX_BARCODE_H_ - -#include - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fxbarcode/BC_Library.h" - -class CBC_CodeBase; -class CFX_Font; -class CFX_RenderDevice; -class CFX_Matrix; - -class CFX_Barcode { - public: - CFX_Barcode(); - ~CFX_Barcode(); - - bool Create(BC_TYPE type); - BC_TYPE GetType(); - bool Encode(const CFX_WideStringC& contents, bool isDevice, int32_t& e); - - bool RenderDevice(CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t& e); - - bool SetCharEncoding(BC_CHAR_ENCODING encoding); - - bool SetModuleHeight(int32_t moduleHeight); - bool SetModuleWidth(int32_t moduleWidth); - - bool SetHeight(int32_t height); - bool SetWidth(int32_t width); - - bool SetPrintChecksum(bool checksum); - bool SetDataLength(int32_t length); - bool SetCalChecksum(bool state); - - bool SetFont(CFX_Font* pFont); - bool SetFontSize(FX_FLOAT size); - bool SetFontColor(FX_ARGB color); - - bool SetTextLocation(BC_TEXT_LOC location); - - bool SetWideNarrowRatio(int32_t ratio); - bool SetStartChar(FX_CHAR start); - bool SetEndChar(FX_CHAR end); - bool SetVersion(int32_t version); - bool SetErrorCorrectionLevel(int32_t level); - bool SetTruncated(bool truncated); - - private: - std::unique_ptr m_pBCEngine; -}; - -#endif // XFA_FWL_CORE_CFX_BARCODE_H_ diff --git a/xfa/fwl/core/fwl_error.h b/xfa/fwl/core/fwl_error.h deleted file mode 100644 index 1332fbbb31..0000000000 --- a/xfa/fwl/core/fwl_error.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_FWL_ERROR_H_ -#define XFA_FWL_CORE_FWL_ERROR_H_ - -enum class FWL_Error { - Succeeded = 0, - Indefinite, - ParameterInvalid, - PropertyInvalid, - IntermediateValueInvalid, - MethodNotSupported -}; - -#endif // XFA_FWL_CORE_FWL_ERROR_H_ diff --git a/xfa/fwl/core/fwl_widgetdef.h b/xfa/fwl/core/fwl_widgetdef.h deleted file mode 100644 index 8644d99474..0000000000 --- a/xfa/fwl/core/fwl_widgetdef.h +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_FWL_WIDGETDEF_H_ -#define XFA_FWL_CORE_FWL_WIDGETDEF_H_ - -#define FWL_WGTSTYLE_OverLapper (0L << 0) -#define FWL_WGTSTYLE_Popup (1L << 0) -#define FWL_WGTSTYLE_Child (2L << 0) -#define FWL_WGTSTYLE_Border (1L << 2) -#define FWL_WGTSTYLE_MinimizeBox (1L << 6) -#define FWL_WGTSTYLE_MaximizeBox (1L << 7) -#define FWL_WGTSTYLE_CloseBox (1L << 8) -#define FWL_WGTSTYLE_HScroll (1L << 9) -#define FWL_WGTSTYLE_VScroll (1L << 11) -#define FWL_WGTSTYLE_LeftScrollbar (1L << 12) -#define FWL_WGTSTYLE_LeftAlignment (0L << 13) -#define FWL_WGTSTYLE_CenterAlignment (1L << 13) -#define FWL_WGTSTYLE_RightAlignment (2L << 13) -#define FWL_WGTSTYLE_TopAlignment (0L << 15) -#define FWL_WGTSTYLE_VCenterAlignment (1L << 15) -#define FWL_WGTSTYLE_BottomAlignment (2L << 15) -#define FWL_WGTSTYLE_RTLReading (1L << 17) -#define FWL_WGTSTYLE_RTLLayout (1L << 18) -#define FWL_WGTSTYLE_EdgeNone (0L << 19) -#define FWL_WGTSTYLE_EdgeFlat (1L << 19) -#define FWL_WGTSTYLE_EdgeRaised (2L << 19) -#define FWL_WGTSTYLE_EdgeSunken (3L << 19) -#define FWL_WGTSTYLE_EdgeMask (3L << 19) -#define FWL_WGTSTYLE_Shadow (3L << 21) -#define FWL_WGTSTYLE_Group (1L << 22) -#define FWL_WGTSTYLE_TabStop (1L << 23) -#define FWL_WGTSTYLE_Offscreen (1L << 24) -#define FWL_WGTSTYLE_DragAcceptFiles (1L << 25) -#define FWL_WGTSTYLE_TopMost (1L << 26) -#define FWL_WGTSTYLE_TransParent (1L << 27) -#define FWL_WGTSTYLE_NoBackground (1L << 28) -#define FWL_WGTSTYLE_WindowTypeMask (3L << 0) -#define FWL_WGTSTATE_Restored (0L << 0) -#define FWL_WGTSTATE_Minimized (1L << 0) -#define FWL_WGTSTATE_Maximized (2L << 0) -#define FWL_WGTSTATE_Disabled (1L << 2) -#define FWL_WGTSTATE_Deactivated (1L << 3) -#define FWL_WGTSTATE_Focused (1L << 4) -#define FWL_WGTSTATE_Invisible (1L << 5) -#define FWL_WGTSTATE_MAX (6) - -#define FWL_VKEY_LButton 0x01 -#define FWL_VKEY_RButton 0x02 -#define FWL_VKEY_MButton 0x04 -#define FWL_VKEY_Back 0x08 -#define FWL_VKEY_Tab 0x09 -#define FWL_VKEY_NewLine 0x0A -#define FWL_VKEY_Clear 0x0C -#define FWL_VKEY_Return 0x0D -#define FWL_VKEY_Shift 0x10 -#define FWL_VKEY_Control 0x11 -#define FWL_VKEY_Menu 0x12 -#define FWL_VKEY_Pause 0x13 -#define FWL_VKEY_Capital 0x14 -#define FWL_VKEY_Kana 0x15 -#define FWL_VKEY_Hangul 0x15 -#define FWL_VKEY_Junja 0x17 -#define FWL_VKEY_Final 0x18 -#define FWL_VKEY_Hanja 0x19 -#define FWL_VKEY_Kanji 0x19 -#define FWL_VKEY_Escape 0x1B -#define FWL_VKEY_Convert 0x1C -#define FWL_VKEY_NonConvert 0x1D -#define FWL_VKEY_Accept 0x1E -#define FWL_VKEY_ModeChange 0x1F -#define FWL_VKEY_Space 0x20 -#define FWL_VKEY_Prior 0x21 -#define FWL_VKEY_Next 0x22 -#define FWL_VKEY_End 0x23 -#define FWL_VKEY_Home 0x24 -#define FWL_VKEY_Left 0x25 -#define FWL_VKEY_Up 0x26 -#define FWL_VKEY_Right 0x27 -#define FWL_VKEY_Down 0x28 -#define FWL_VKEY_Select 0x29 -#define FWL_VKEY_Print 0x2A -#define FWL_VKEY_Execute 0x2B -#define FWL_VKEY_Snapshot 0x2C -#define FWL_VKEY_Insert 0x2D -#define FWL_VKEY_Delete 0x2E -#define FWL_VKEY_Help 0x2F -#define FWL_VKEY_0 0x30 -#define FWL_VKEY_1 0x31 -#define FWL_VKEY_2 0x32 -#define FWL_VKEY_3 0x33 -#define FWL_VKEY_4 0x34 -#define FWL_VKEY_5 0x35 -#define FWL_VKEY_6 0x36 -#define FWL_VKEY_7 0x37 -#define FWL_VKEY_8 0x38 -#define FWL_VKEY_9 0x39 -#define FWL_VKEY_A 0x41 -#define FWL_VKEY_B 0x42 -#define FWL_VKEY_C 0x43 -#define FWL_VKEY_D 0x44 -#define FWL_VKEY_E 0x45 -#define FWL_VKEY_F 0x46 -#define FWL_VKEY_G 0x47 -#define FWL_VKEY_H 0x48 -#define FWL_VKEY_I 0x49 -#define FWL_VKEY_J 0x4A -#define FWL_VKEY_K 0x4B -#define FWL_VKEY_L 0x4C -#define FWL_VKEY_M 0x4D -#define FWL_VKEY_N 0x4E -#define FWL_VKEY_O 0x4F -#define FWL_VKEY_P 0x50 -#define FWL_VKEY_Q 0x51 -#define FWL_VKEY_R 0x52 -#define FWL_VKEY_S 0x53 -#define FWL_VKEY_T 0x54 -#define FWL_VKEY_U 0x55 -#define FWL_VKEY_V 0x56 -#define FWL_VKEY_W 0x57 -#define FWL_VKEY_X 0x58 -#define FWL_VKEY_Y 0x59 -#define FWL_VKEY_Z 0x5A -#define FWL_VKEY_LWin 0x5B -#define FWL_VKEY_Command 0x5B -#define FWL_VKEY_RWin 0x5C -#define FWL_VKEY_Apps 0x5D -#define FWL_VKEY_Sleep 0x5F -#define FWL_VKEY_NumPad0 0x60 -#define FWL_VKEY_NumPad1 0x61 -#define FWL_VKEY_NumPad2 0x62 -#define FWL_VKEY_NumPad3 0x63 -#define FWL_VKEY_NumPad4 0x64 -#define FWL_VKEY_NumPad5 0x65 -#define FWL_VKEY_NumPad6 0x66 -#define FWL_VKEY_NumPad7 0x67 -#define FWL_VKEY_NumPad8 0x68 -#define FWL_VKEY_NumPad9 0x69 -#define FWL_VKEY_Multiply 0x6A -#define FWL_VKEY_Add 0x6B -#define FWL_VKEY_Separator 0x6C -#define FWL_VKEY_Subtract 0x6D -#define FWL_VKEY_Decimal 0x6E -#define FWL_VKEY_Divide 0x6F -#define FWL_VKEY_F1 0x70 -#define FWL_VKEY_F2 0x71 -#define FWL_VKEY_F3 0x72 -#define FWL_VKEY_F4 0x73 -#define FWL_VKEY_F5 0x74 -#define FWL_VKEY_F6 0x75 -#define FWL_VKEY_F7 0x76 -#define FWL_VKEY_F8 0x77 -#define FWL_VKEY_F9 0x78 -#define FWL_VKEY_F10 0x79 -#define FWL_VKEY_F11 0x7A -#define FWL_VKEY_F12 0x7B -#define FWL_VKEY_F13 0x7C -#define FWL_VKEY_F14 0x7D -#define FWL_VKEY_F15 0x7E -#define FWL_VKEY_F16 0x7F -#define FWL_VKEY_F17 0x80 -#define FWL_VKEY_F18 0x81 -#define FWL_VKEY_F19 0x82 -#define FWL_VKEY_F20 0x83 -#define FWL_VKEY_F21 0x84 -#define FWL_VKEY_F22 0x85 -#define FWL_VKEY_F23 0x86 -#define FWL_VKEY_F24 0x87 -#define FWL_VKEY_NunLock 0x90 -#define FWL_VKEY_Scroll 0x91 -#define FWL_VKEY_LShift 0xA0 -#define FWL_VKEY_RShift 0xA1 -#define FWL_VKEY_LControl 0xA2 -#define FWL_VKEY_RControl 0xA3 -#define FWL_VKEY_LMenu 0xA4 -#define FWL_VKEY_RMenu 0xA5 -#define FWL_VKEY_BROWSER_Back 0xA6 -#define FWL_VKEY_BROWSER_Forward 0xA7 -#define FWL_VKEY_BROWSER_Refresh 0xA8 -#define FWL_VKEY_BROWSER_Stop 0xA9 -#define FWL_VKEY_BROWSER_Search 0xAA -#define FWL_VKEY_BROWSER_Favorites 0xAB -#define FWL_VKEY_BROWSER_Home 0xAC -#define FWL_VKEY_VOLUME_Mute 0xAD -#define FWL_VKEY_VOLUME_Down 0xAE -#define FWL_VKEY_VOLUME_Up 0xAF -#define FWL_VKEY_MEDIA_NEXT_Track 0xB0 -#define FWL_VKEY_MEDIA_PREV_Track 0xB1 -#define FWL_VKEY_MEDIA_Stop 0xB2 -#define FWL_VKEY_MEDIA_PLAY_Pause 0xB3 -#define FWL_VKEY_MEDIA_LAUNCH_Mail 0xB4 -#define FWL_VKEY_MEDIA_LAUNCH_MEDIA_Select 0xB5 -#define FWL_VKEY_MEDIA_LAUNCH_APP1 0xB6 -#define FWL_VKEY_MEDIA_LAUNCH_APP2 0xB7 -#define FWL_VKEY_OEM_1 0xBA -#define FWL_VKEY_OEM_Plus 0xBB -#define FWL_VKEY_OEM_Comma 0xBC -#define FWL_VKEY_OEM_Minus 0xBD -#define FWL_VKEY_OEM_Period 0xBE -#define FWL_VKEY_OEM_2 0xBF -#define FWL_VKEY_OEM_3 0xC0 -#define FWL_VKEY_OEM_4 0xDB -#define FWL_VKEY_OEM_5 0xDC -#define FWL_VKEY_OEM_6 0xDD -#define FWL_VKEY_OEM_7 0xDE -#define FWL_VKEY_OEM_8 0xDF -#define FWL_VKEY_OEM_102 0xE2 -#define FWL_VKEY_ProcessKey 0xE5 -#define FWL_VKEY_Packet 0xE7 -#define FWL_VKEY_Attn 0xF6 -#define FWL_VKEY_Crsel 0xF7 -#define FWL_VKEY_Exsel 0xF8 -#define FWL_VKEY_Ereof 0xF9 -#define FWL_VKEY_Play 0xFA -#define FWL_VKEY_Zoom 0xFB -#define FWL_VKEY_NoName 0xFC -#define FWL_VKEY_PA1 0xFD -#define FWL_VKEY_OEM_Clear 0xFE -#define FWL_VKEY_Unknown 0 - -#endif // XFA_FWL_CORE_FWL_WIDGETDEF_H_ diff --git a/xfa/fwl/core/fwl_widgethit.h b/xfa/fwl/core/fwl_widgethit.h deleted file mode 100644 index 3adecfe49e..0000000000 --- a/xfa/fwl/core/fwl_widgethit.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_FWL_WIDGETHIT_H_ -#define XFA_FWL_CORE_FWL_WIDGETHIT_H_ - -enum class FWL_WidgetHit { - Unknown = 0, - Client, - Left, - Top, - Right, - Bottom, - LeftTop, - RightTop, - LeftBottom, - RightBottom, - Titlebar, - MinBox, - MaxBox, - CloseBox, - HScrollBar, - VScrollBar, - Border, - Edge, - Edit, - HyperLink, - UpButton, - DownButton -}; - -#endif // XFA_FWL_CORE_FWL_WIDGETHIT_H_ diff --git a/xfa/fwl/core/ifwl_adaptertimermgr.h b/xfa/fwl/core/ifwl_adaptertimermgr.h deleted file mode 100644 index 0e07052e65..0000000000 --- a/xfa/fwl/core/ifwl_adaptertimermgr.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_ADAPTERTIMERMGR_H_ -#define XFA_FWL_CORE_IFWL_ADAPTERTIMERMGR_H_ - -#include "xfa/fwl/core/cfwl_timer.h" - -class IFWL_AdapterTimerMgr { - public: - virtual void Start(CFWL_Timer* pTimer, - uint32_t dwElapse, - bool bImmediately, - CFWL_TimerInfo** pTimerInfo) = 0; - virtual void Stop(CFWL_TimerInfo* pTimerInfo) = 0; -}; - -#endif // XFA_FWL_CORE_IFWL_ADAPTERTIMERMGR_H_ diff --git a/xfa/fwl/core/ifwl_themeprovider.h b/xfa/fwl/core/ifwl_themeprovider.h deleted file mode 100644 index e376cb1eea..0000000000 --- a/xfa/fwl/core/ifwl_themeprovider.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_THEMEPROVIDER_H_ -#define XFA_FWL_CORE_IFWL_THEMEPROVIDER_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "xfa/fwl/theme/cfwl_widgettp.h" - -class CFWL_ThemeBackground; -class CFWL_ThemePart; -class CFWL_ThemeText; -class CFWL_Widget; - -class IFWL_ThemeProvider { - public: - virtual ~IFWL_ThemeProvider() {} - - virtual void DrawBackground(CFWL_ThemeBackground* pParams) = 0; - virtual void DrawText(CFWL_ThemeText* pParams) = 0; - virtual void* GetCapacity(CFWL_ThemePart* pThemePart, - CFWL_WidgetCapacity dwCapacity) = 0; - virtual void CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) = 0; -}; - -#endif // XFA_FWL_CORE_IFWL_THEMEPROVIDER_H_ diff --git a/xfa/fwl/core/ifwl_widgetdelegate.h b/xfa/fwl/core/ifwl_widgetdelegate.h deleted file mode 100644 index 042679359c..0000000000 --- a/xfa/fwl/core/ifwl_widgetdelegate.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_WIDGETDELEGATE_H_ -#define XFA_FWL_CORE_IFWL_WIDGETDELEGATE_H_ - -#include - -class CFWL_Event; -class CFWL_Message; -class CFX_Graphics; -class CFX_Matrix; - -class IFWL_WidgetDelegate { - public: - virtual ~IFWL_WidgetDelegate() {} - - virtual void OnProcessMessage(CFWL_Message* pMessage) = 0; - virtual void OnProcessEvent(CFWL_Event* pEvent) = 0; - virtual void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) = 0; -}; - -#endif // XFA_FWL_CORE_IFWL_WIDGETDELEGATE_H_ diff --git a/xfa/fwl/core/ifwl_widgetmgrdelegate.h b/xfa/fwl/core/ifwl_widgetmgrdelegate.h deleted file mode 100644 index 67f73d3315..0000000000 --- a/xfa/fwl/core/ifwl_widgetmgrdelegate.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_WIDGETMGRDELEGATE_H_ -#define XFA_FWL_CORE_IFWL_WIDGETMGRDELEGATE_H_ - -class CFWL_Message; -class CFX_Graphics; -class CFX_Matrix; -class CFWL_Widget; - -class CFWL_WidgetMgrDelegate { - public: - virtual void OnSetCapability(uint32_t dwCapability) = 0; - virtual void OnProcessMessageToForm(CFWL_Message* pMessage) = 0; - virtual void OnDrawWidget(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) = 0; -}; - -#endif // XFA_FWL_CORE_IFWL_WIDGETMGRDELEGATE_H_ diff --git a/xfa/fwl/fwl_error.h b/xfa/fwl/fwl_error.h new file mode 100644 index 0000000000..8ef56d9691 --- /dev/null +++ b/xfa/fwl/fwl_error.h @@ -0,0 +1,19 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_FWL_ERROR_H_ +#define XFA_FWL_FWL_ERROR_H_ + +enum class FWL_Error { + Succeeded = 0, + Indefinite, + ParameterInvalid, + PropertyInvalid, + IntermediateValueInvalid, + MethodNotSupported +}; + +#endif // XFA_FWL_FWL_ERROR_H_ diff --git a/xfa/fwl/fwl_widgetdef.h b/xfa/fwl/fwl_widgetdef.h new file mode 100644 index 0000000000..20013b0e4c --- /dev/null +++ b/xfa/fwl/fwl_widgetdef.h @@ -0,0 +1,224 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_FWL_WIDGETDEF_H_ +#define XFA_FWL_FWL_WIDGETDEF_H_ + +#define FWL_WGTSTYLE_OverLapper (0L << 0) +#define FWL_WGTSTYLE_Popup (1L << 0) +#define FWL_WGTSTYLE_Child (2L << 0) +#define FWL_WGTSTYLE_Border (1L << 2) +#define FWL_WGTSTYLE_MinimizeBox (1L << 6) +#define FWL_WGTSTYLE_MaximizeBox (1L << 7) +#define FWL_WGTSTYLE_CloseBox (1L << 8) +#define FWL_WGTSTYLE_HScroll (1L << 9) +#define FWL_WGTSTYLE_VScroll (1L << 11) +#define FWL_WGTSTYLE_LeftScrollbar (1L << 12) +#define FWL_WGTSTYLE_LeftAlignment (0L << 13) +#define FWL_WGTSTYLE_CenterAlignment (1L << 13) +#define FWL_WGTSTYLE_RightAlignment (2L << 13) +#define FWL_WGTSTYLE_TopAlignment (0L << 15) +#define FWL_WGTSTYLE_VCenterAlignment (1L << 15) +#define FWL_WGTSTYLE_BottomAlignment (2L << 15) +#define FWL_WGTSTYLE_RTLReading (1L << 17) +#define FWL_WGTSTYLE_RTLLayout (1L << 18) +#define FWL_WGTSTYLE_EdgeNone (0L << 19) +#define FWL_WGTSTYLE_EdgeFlat (1L << 19) +#define FWL_WGTSTYLE_EdgeRaised (2L << 19) +#define FWL_WGTSTYLE_EdgeSunken (3L << 19) +#define FWL_WGTSTYLE_EdgeMask (3L << 19) +#define FWL_WGTSTYLE_Shadow (3L << 21) +#define FWL_WGTSTYLE_Group (1L << 22) +#define FWL_WGTSTYLE_TabStop (1L << 23) +#define FWL_WGTSTYLE_Offscreen (1L << 24) +#define FWL_WGTSTYLE_DragAcceptFiles (1L << 25) +#define FWL_WGTSTYLE_TopMost (1L << 26) +#define FWL_WGTSTYLE_TransParent (1L << 27) +#define FWL_WGTSTYLE_NoBackground (1L << 28) +#define FWL_WGTSTYLE_WindowTypeMask (3L << 0) +#define FWL_WGTSTATE_Restored (0L << 0) +#define FWL_WGTSTATE_Minimized (1L << 0) +#define FWL_WGTSTATE_Maximized (2L << 0) +#define FWL_WGTSTATE_Disabled (1L << 2) +#define FWL_WGTSTATE_Deactivated (1L << 3) +#define FWL_WGTSTATE_Focused (1L << 4) +#define FWL_WGTSTATE_Invisible (1L << 5) +#define FWL_WGTSTATE_MAX (6) + +#define FWL_VKEY_LButton 0x01 +#define FWL_VKEY_RButton 0x02 +#define FWL_VKEY_MButton 0x04 +#define FWL_VKEY_Back 0x08 +#define FWL_VKEY_Tab 0x09 +#define FWL_VKEY_NewLine 0x0A +#define FWL_VKEY_Clear 0x0C +#define FWL_VKEY_Return 0x0D +#define FWL_VKEY_Shift 0x10 +#define FWL_VKEY_Control 0x11 +#define FWL_VKEY_Menu 0x12 +#define FWL_VKEY_Pause 0x13 +#define FWL_VKEY_Capital 0x14 +#define FWL_VKEY_Kana 0x15 +#define FWL_VKEY_Hangul 0x15 +#define FWL_VKEY_Junja 0x17 +#define FWL_VKEY_Final 0x18 +#define FWL_VKEY_Hanja 0x19 +#define FWL_VKEY_Kanji 0x19 +#define FWL_VKEY_Escape 0x1B +#define FWL_VKEY_Convert 0x1C +#define FWL_VKEY_NonConvert 0x1D +#define FWL_VKEY_Accept 0x1E +#define FWL_VKEY_ModeChange 0x1F +#define FWL_VKEY_Space 0x20 +#define FWL_VKEY_Prior 0x21 +#define FWL_VKEY_Next 0x22 +#define FWL_VKEY_End 0x23 +#define FWL_VKEY_Home 0x24 +#define FWL_VKEY_Left 0x25 +#define FWL_VKEY_Up 0x26 +#define FWL_VKEY_Right 0x27 +#define FWL_VKEY_Down 0x28 +#define FWL_VKEY_Select 0x29 +#define FWL_VKEY_Print 0x2A +#define FWL_VKEY_Execute 0x2B +#define FWL_VKEY_Snapshot 0x2C +#define FWL_VKEY_Insert 0x2D +#define FWL_VKEY_Delete 0x2E +#define FWL_VKEY_Help 0x2F +#define FWL_VKEY_0 0x30 +#define FWL_VKEY_1 0x31 +#define FWL_VKEY_2 0x32 +#define FWL_VKEY_3 0x33 +#define FWL_VKEY_4 0x34 +#define FWL_VKEY_5 0x35 +#define FWL_VKEY_6 0x36 +#define FWL_VKEY_7 0x37 +#define FWL_VKEY_8 0x38 +#define FWL_VKEY_9 0x39 +#define FWL_VKEY_A 0x41 +#define FWL_VKEY_B 0x42 +#define FWL_VKEY_C 0x43 +#define FWL_VKEY_D 0x44 +#define FWL_VKEY_E 0x45 +#define FWL_VKEY_F 0x46 +#define FWL_VKEY_G 0x47 +#define FWL_VKEY_H 0x48 +#define FWL_VKEY_I 0x49 +#define FWL_VKEY_J 0x4A +#define FWL_VKEY_K 0x4B +#define FWL_VKEY_L 0x4C +#define FWL_VKEY_M 0x4D +#define FWL_VKEY_N 0x4E +#define FWL_VKEY_O 0x4F +#define FWL_VKEY_P 0x50 +#define FWL_VKEY_Q 0x51 +#define FWL_VKEY_R 0x52 +#define FWL_VKEY_S 0x53 +#define FWL_VKEY_T 0x54 +#define FWL_VKEY_U 0x55 +#define FWL_VKEY_V 0x56 +#define FWL_VKEY_W 0x57 +#define FWL_VKEY_X 0x58 +#define FWL_VKEY_Y 0x59 +#define FWL_VKEY_Z 0x5A +#define FWL_VKEY_LWin 0x5B +#define FWL_VKEY_Command 0x5B +#define FWL_VKEY_RWin 0x5C +#define FWL_VKEY_Apps 0x5D +#define FWL_VKEY_Sleep 0x5F +#define FWL_VKEY_NumPad0 0x60 +#define FWL_VKEY_NumPad1 0x61 +#define FWL_VKEY_NumPad2 0x62 +#define FWL_VKEY_NumPad3 0x63 +#define FWL_VKEY_NumPad4 0x64 +#define FWL_VKEY_NumPad5 0x65 +#define FWL_VKEY_NumPad6 0x66 +#define FWL_VKEY_NumPad7 0x67 +#define FWL_VKEY_NumPad8 0x68 +#define FWL_VKEY_NumPad9 0x69 +#define FWL_VKEY_Multiply 0x6A +#define FWL_VKEY_Add 0x6B +#define FWL_VKEY_Separator 0x6C +#define FWL_VKEY_Subtract 0x6D +#define FWL_VKEY_Decimal 0x6E +#define FWL_VKEY_Divide 0x6F +#define FWL_VKEY_F1 0x70 +#define FWL_VKEY_F2 0x71 +#define FWL_VKEY_F3 0x72 +#define FWL_VKEY_F4 0x73 +#define FWL_VKEY_F5 0x74 +#define FWL_VKEY_F6 0x75 +#define FWL_VKEY_F7 0x76 +#define FWL_VKEY_F8 0x77 +#define FWL_VKEY_F9 0x78 +#define FWL_VKEY_F10 0x79 +#define FWL_VKEY_F11 0x7A +#define FWL_VKEY_F12 0x7B +#define FWL_VKEY_F13 0x7C +#define FWL_VKEY_F14 0x7D +#define FWL_VKEY_F15 0x7E +#define FWL_VKEY_F16 0x7F +#define FWL_VKEY_F17 0x80 +#define FWL_VKEY_F18 0x81 +#define FWL_VKEY_F19 0x82 +#define FWL_VKEY_F20 0x83 +#define FWL_VKEY_F21 0x84 +#define FWL_VKEY_F22 0x85 +#define FWL_VKEY_F23 0x86 +#define FWL_VKEY_F24 0x87 +#define FWL_VKEY_NunLock 0x90 +#define FWL_VKEY_Scroll 0x91 +#define FWL_VKEY_LShift 0xA0 +#define FWL_VKEY_RShift 0xA1 +#define FWL_VKEY_LControl 0xA2 +#define FWL_VKEY_RControl 0xA3 +#define FWL_VKEY_LMenu 0xA4 +#define FWL_VKEY_RMenu 0xA5 +#define FWL_VKEY_BROWSER_Back 0xA6 +#define FWL_VKEY_BROWSER_Forward 0xA7 +#define FWL_VKEY_BROWSER_Refresh 0xA8 +#define FWL_VKEY_BROWSER_Stop 0xA9 +#define FWL_VKEY_BROWSER_Search 0xAA +#define FWL_VKEY_BROWSER_Favorites 0xAB +#define FWL_VKEY_BROWSER_Home 0xAC +#define FWL_VKEY_VOLUME_Mute 0xAD +#define FWL_VKEY_VOLUME_Down 0xAE +#define FWL_VKEY_VOLUME_Up 0xAF +#define FWL_VKEY_MEDIA_NEXT_Track 0xB0 +#define FWL_VKEY_MEDIA_PREV_Track 0xB1 +#define FWL_VKEY_MEDIA_Stop 0xB2 +#define FWL_VKEY_MEDIA_PLAY_Pause 0xB3 +#define FWL_VKEY_MEDIA_LAUNCH_Mail 0xB4 +#define FWL_VKEY_MEDIA_LAUNCH_MEDIA_Select 0xB5 +#define FWL_VKEY_MEDIA_LAUNCH_APP1 0xB6 +#define FWL_VKEY_MEDIA_LAUNCH_APP2 0xB7 +#define FWL_VKEY_OEM_1 0xBA +#define FWL_VKEY_OEM_Plus 0xBB +#define FWL_VKEY_OEM_Comma 0xBC +#define FWL_VKEY_OEM_Minus 0xBD +#define FWL_VKEY_OEM_Period 0xBE +#define FWL_VKEY_OEM_2 0xBF +#define FWL_VKEY_OEM_3 0xC0 +#define FWL_VKEY_OEM_4 0xDB +#define FWL_VKEY_OEM_5 0xDC +#define FWL_VKEY_OEM_6 0xDD +#define FWL_VKEY_OEM_7 0xDE +#define FWL_VKEY_OEM_8 0xDF +#define FWL_VKEY_OEM_102 0xE2 +#define FWL_VKEY_ProcessKey 0xE5 +#define FWL_VKEY_Packet 0xE7 +#define FWL_VKEY_Attn 0xF6 +#define FWL_VKEY_Crsel 0xF7 +#define FWL_VKEY_Exsel 0xF8 +#define FWL_VKEY_Ereof 0xF9 +#define FWL_VKEY_Play 0xFA +#define FWL_VKEY_Zoom 0xFB +#define FWL_VKEY_NoName 0xFC +#define FWL_VKEY_PA1 0xFD +#define FWL_VKEY_OEM_Clear 0xFE +#define FWL_VKEY_Unknown 0 + +#endif // XFA_FWL_FWL_WIDGETDEF_H_ diff --git a/xfa/fwl/fwl_widgethit.h b/xfa/fwl/fwl_widgethit.h new file mode 100644 index 0000000000..ff5a80670a --- /dev/null +++ b/xfa/fwl/fwl_widgethit.h @@ -0,0 +1,35 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_FWL_WIDGETHIT_H_ +#define XFA_FWL_FWL_WIDGETHIT_H_ + +enum class FWL_WidgetHit { + Unknown = 0, + Client, + Left, + Top, + Right, + Bottom, + LeftTop, + RightTop, + LeftBottom, + RightBottom, + Titlebar, + MinBox, + MaxBox, + CloseBox, + HScrollBar, + VScrollBar, + Border, + Edge, + Edit, + HyperLink, + UpButton, + DownButton +}; + +#endif // XFA_FWL_FWL_WIDGETHIT_H_ diff --git a/xfa/fwl/ifwl_adaptertimermgr.h b/xfa/fwl/ifwl_adaptertimermgr.h new file mode 100644 index 0000000000..1f655892ea --- /dev/null +++ b/xfa/fwl/ifwl_adaptertimermgr.h @@ -0,0 +1,21 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_IFWL_ADAPTERTIMERMGR_H_ +#define XFA_FWL_IFWL_ADAPTERTIMERMGR_H_ + +#include "xfa/fwl/cfwl_timer.h" + +class IFWL_AdapterTimerMgr { + public: + virtual void Start(CFWL_Timer* pTimer, + uint32_t dwElapse, + bool bImmediately, + CFWL_TimerInfo** pTimerInfo) = 0; + virtual void Stop(CFWL_TimerInfo* pTimerInfo) = 0; +}; + +#endif // XFA_FWL_IFWL_ADAPTERTIMERMGR_H_ diff --git a/xfa/fwl/ifwl_themeprovider.h b/xfa/fwl/ifwl_themeprovider.h new file mode 100644 index 0000000000..69932e7fc9 --- /dev/null +++ b/xfa/fwl/ifwl_themeprovider.h @@ -0,0 +1,29 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_IFWL_THEMEPROVIDER_H_ +#define XFA_FWL_IFWL_THEMEPROVIDER_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "xfa/fwl/theme/cfwl_widgettp.h" + +class CFWL_ThemeBackground; +class CFWL_ThemePart; +class CFWL_ThemeText; +class CFWL_Widget; + +class IFWL_ThemeProvider { + public: + virtual ~IFWL_ThemeProvider() {} + + virtual void DrawBackground(CFWL_ThemeBackground* pParams) = 0; + virtual void DrawText(CFWL_ThemeText* pParams) = 0; + virtual void* GetCapacity(CFWL_ThemePart* pThemePart, + CFWL_WidgetCapacity dwCapacity) = 0; + virtual void CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) = 0; +}; + +#endif // XFA_FWL_IFWL_THEMEPROVIDER_H_ diff --git a/xfa/fwl/ifwl_widgetdelegate.h b/xfa/fwl/ifwl_widgetdelegate.h new file mode 100644 index 0000000000..a96f00dc9e --- /dev/null +++ b/xfa/fwl/ifwl_widgetdelegate.h @@ -0,0 +1,27 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_IFWL_WIDGETDELEGATE_H_ +#define XFA_FWL_IFWL_WIDGETDELEGATE_H_ + +#include + +class CFWL_Event; +class CFWL_Message; +class CFX_Graphics; +class CFX_Matrix; + +class IFWL_WidgetDelegate { + public: + virtual ~IFWL_WidgetDelegate() {} + + virtual void OnProcessMessage(CFWL_Message* pMessage) = 0; + virtual void OnProcessEvent(CFWL_Event* pEvent) = 0; + virtual void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) = 0; +}; + +#endif // XFA_FWL_IFWL_WIDGETDELEGATE_H_ diff --git a/xfa/fwl/ifwl_widgetmgrdelegate.h b/xfa/fwl/ifwl_widgetmgrdelegate.h new file mode 100644 index 0000000000..9f0b5708b3 --- /dev/null +++ b/xfa/fwl/ifwl_widgetmgrdelegate.h @@ -0,0 +1,24 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_IFWL_WIDGETMGRDELEGATE_H_ +#define XFA_FWL_IFWL_WIDGETMGRDELEGATE_H_ + +class CFWL_Message; +class CFX_Graphics; +class CFX_Matrix; +class CFWL_Widget; + +class CFWL_WidgetMgrDelegate { + public: + virtual void OnSetCapability(uint32_t dwCapability) = 0; + virtual void OnProcessMessageToForm(CFWL_Message* pMessage) = 0; + virtual void OnDrawWidget(CFWL_Widget* pWidget, + CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) = 0; +}; + +#endif // XFA_FWL_IFWL_WIDGETMGRDELEGATE_H_ diff --git a/xfa/fwl/theme/cfwl_barcodetp.cpp b/xfa/fwl/theme/cfwl_barcodetp.cpp index 96112e209b..f123857e51 100644 --- a/xfa/fwl/theme/cfwl_barcodetp.cpp +++ b/xfa/fwl/theme/cfwl_barcodetp.cpp @@ -6,9 +6,9 @@ #include "xfa/fwl/theme/cfwl_barcodetp.h" -#include "xfa/fwl/core/cfwl_barcode.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" +#include "xfa/fwl/cfwl_barcode.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" CFWL_BarcodeTP::CFWL_BarcodeTP() {} diff --git a/xfa/fwl/theme/cfwl_carettp.cpp b/xfa/fwl/theme/cfwl_carettp.cpp index ff8c036ecb..63d6270f77 100644 --- a/xfa/fwl/theme/cfwl_carettp.cpp +++ b/xfa/fwl/theme/cfwl_carettp.cpp @@ -6,9 +6,9 @@ #include "xfa/fwl/theme/cfwl_carettp.h" -#include "xfa/fwl/core/cfwl_caret.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" +#include "xfa/fwl/cfwl_caret.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_checkboxtp.cpp b/xfa/fwl/theme/cfwl_checkboxtp.cpp index 5ea849e089..4ff2ccd2a6 100644 --- a/xfa/fwl/theme/cfwl_checkboxtp.cpp +++ b/xfa/fwl/theme/cfwl_checkboxtp.cpp @@ -8,10 +8,10 @@ #include "core/fxge/cfx_pathdata.h" #include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_checkbox.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widget.h" +#include "xfa/fwl/cfwl_checkbox.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widget.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_comboboxtp.cpp b/xfa/fwl/theme/cfwl_comboboxtp.cpp index 8b4041b729..3e06e665ae 100644 --- a/xfa/fwl/theme/cfwl_comboboxtp.cpp +++ b/xfa/fwl/theme/cfwl_comboboxtp.cpp @@ -6,10 +6,10 @@ #include "xfa/fwl/theme/cfwl_comboboxtp.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_datetimepickertp.cpp b/xfa/fwl/theme/cfwl_datetimepickertp.cpp index 3b5befb65c..ef8d0c869b 100644 --- a/xfa/fwl/theme/cfwl_datetimepickertp.cpp +++ b/xfa/fwl/theme/cfwl_datetimepickertp.cpp @@ -6,8 +6,8 @@ #include "xfa/fwl/theme/cfwl_datetimepickertp.h" -#include "xfa/fwl/core/cfwl_datetimepicker.h" -#include "xfa/fwl/core/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_themebackground.h" CFWL_DateTimePickerTP::CFWL_DateTimePickerTP() {} diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp index bd12939fc0..f2fc5cb7a3 100644 --- a/xfa/fwl/theme/cfwl_edittp.cpp +++ b/xfa/fwl/theme/cfwl_edittp.cpp @@ -6,9 +6,9 @@ #include "xfa/fwl/theme/cfwl_edittp.h" -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" #include "xfa/fxfa/app/xfa_fwltheme.h" #include "xfa/fxfa/xfa_ffwidget.h" #include "xfa/fxgraphics/cfx_color.h" diff --git a/xfa/fwl/theme/cfwl_listboxtp.cpp b/xfa/fwl/theme/cfwl_listboxtp.cpp index 8356820606..6f082a8729 100644 --- a/xfa/fwl/theme/cfwl_listboxtp.cpp +++ b/xfa/fwl/theme/cfwl_listboxtp.cpp @@ -6,9 +6,9 @@ #include "xfa/fwl/theme/cfwl_listboxtp.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.cpp b/xfa/fwl/theme/cfwl_monthcalendartp.cpp index d090e70c9d..3684e77c66 100644 --- a/xfa/fwl/theme/cfwl_monthcalendartp.cpp +++ b/xfa/fwl/theme/cfwl_monthcalendartp.cpp @@ -7,11 +7,11 @@ #include "xfa/fwl/theme/cfwl_monthcalendartp.h" #include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_monthcalendar.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/cfwl_monthcalendar.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_pictureboxtp.cpp b/xfa/fwl/theme/cfwl_pictureboxtp.cpp index 600de0e355..75c60387b4 100644 --- a/xfa/fwl/theme/cfwl_pictureboxtp.cpp +++ b/xfa/fwl/theme/cfwl_pictureboxtp.cpp @@ -6,9 +6,9 @@ #include "xfa/fwl/theme/cfwl_pictureboxtp.h" -#include "xfa/fwl/core/cfwl_picturebox.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" +#include "xfa/fwl/cfwl_picturebox.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" CFWL_PictureBoxTP::CFWL_PictureBoxTP() {} diff --git a/xfa/fwl/theme/cfwl_pushbuttontp.cpp b/xfa/fwl/theme/cfwl_pushbuttontp.cpp index 3b37b613aa..31f6b7ade1 100644 --- a/xfa/fwl/theme/cfwl_pushbuttontp.cpp +++ b/xfa/fwl/theme/cfwl_pushbuttontp.cpp @@ -6,10 +6,10 @@ #include "xfa/fwl/theme/cfwl_pushbuttontp.h" -#include "xfa/fwl/core/cfwl_pushbutton.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/cfwl_pushbutton.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_scrollbartp.cpp b/xfa/fwl/theme/cfwl_scrollbartp.cpp index 19022cad26..0129f353ad 100644 --- a/xfa/fwl/theme/cfwl_scrollbartp.cpp +++ b/xfa/fwl/theme/cfwl_scrollbartp.cpp @@ -6,10 +6,10 @@ #include "xfa/fwl/theme/cfwl_scrollbartp.h" -#include "xfa/fwl/core/cfwl_scrollbar.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/cfwl_scrollbar.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index d578435d8a..efc1e96335 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -12,12 +12,12 @@ #include "xfa/fde/tto/fde_textout.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themepart.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fwl/theme/cfwl_arrowdata.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h index 998d3c76e8..761cc89415 100644 --- a/xfa/fwl/theme/cfwl_widgettp.h +++ b/xfa/fwl/theme/cfwl_widgettp.h @@ -12,7 +12,7 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/fwl_error.h" +#include "xfa/fwl/fwl_error.h" #include "xfa/fwl/theme/cfwl_utils.h" #include "xfa/fxgraphics/cfx_graphics.h" diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp index a0674b6522..4de5f70a6d 100644 --- a/xfa/fxfa/app/xfa_ffapp.cpp +++ b/xfa/fxfa/app/xfa_ffapp.cpp @@ -12,8 +12,8 @@ #include #include "xfa/fgas/font/cfgas_fontmgr.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/app/xfa_fwltheme.h" #include "xfa/fxfa/xfa_ffdoc.h" diff --git a/xfa/fxfa/app/xfa_ffbarcode.cpp b/xfa/fxfa/app/xfa_ffbarcode.cpp index 6f83173b71..de0638fb13 100644 --- a/xfa/fxfa/app/xfa_ffbarcode.cpp +++ b/xfa/fxfa/app/xfa_ffbarcode.cpp @@ -7,9 +7,9 @@ #include "xfa/fxfa/app/xfa_ffbarcode.h" #include "core/fxcrt/fx_ext.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_barcode.h" -#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_barcode.h" +#include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fftextedit.h" #include "xfa/fxfa/app/xfa_fwladapter.h" diff --git a/xfa/fxfa/app/xfa_ffcheckbutton.cpp b/xfa/fxfa/app/xfa_ffcheckbutton.cpp index 47b628cdec..30ea09ff4d 100644 --- a/xfa/fxfa/app/xfa_ffcheckbutton.cpp +++ b/xfa/fxfa/app/xfa_ffcheckbutton.cpp @@ -6,10 +6,10 @@ #include "xfa/fxfa/app/xfa_ffcheckbutton.h" -#include "xfa/fwl/core/cfwl_checkbox.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/cfwl_checkbox.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/xfa_ffexclgroup.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/xfa_ffapp.h" @@ -246,7 +246,7 @@ bool CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, return false; SetButtonDown(false); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; ms.m_dwFlags = dwFlags; ms.m_fx = fx; diff --git a/xfa/fxfa/app/xfa_ffchoicelist.cpp b/xfa/fxfa/app/xfa_ffchoicelist.cpp index e8c364a613..72284d6ef7 100644 --- a/xfa/fxfa/app/xfa_ffchoicelist.cpp +++ b/xfa/fxfa/app/xfa_ffchoicelist.cpp @@ -7,13 +7,13 @@ #include "xfa/fxfa/app/xfa_ffchoicelist.h" #include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_evtselectchanged.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widgetproperties.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/cxfa_eventparam.h" @@ -508,8 +508,8 @@ void CXFA_FFComboBox::OnProcessEvent(CFWL_Event* pEvent) { CXFA_FFField::OnProcessEvent(pEvent); switch (pEvent->GetType()) { case CFWL_Event::Type::SelectChanged: { - CFWL_EvtSelectChanged* postEvent = - static_cast(pEvent); + CFWL_EventSelectChanged* postEvent = + static_cast(pEvent); OnSelectChanged(m_pNormalWidget, postEvent->bLButtonUp); break; } diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp index 917c853991..516f3d7fa0 100644 --- a/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/xfa/fxfa/app/xfa_ffdoc.cpp @@ -17,7 +17,7 @@ #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_memory.h" #include "xfa/fde/xml/fde_xml_imp.h" -#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_dataexporter.h" #include "xfa/fxfa/parser/cxfa_dataimporter.h" diff --git a/xfa/fxfa/app/xfa_fffield.cpp b/xfa/fxfa/app/xfa_fffield.cpp index 9b5504708f..68db2ba765 100644 --- a/xfa/fxfa/app/xfa_fffield.cpp +++ b/xfa/fxfa/app/xfa_fffield.cpp @@ -6,15 +6,15 @@ #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_evtmouse.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgmousewheel.h" -#include "xfa/fwl/core/cfwl_msgsetfocus.h" -#include "xfa/fwl/core/cfwl_picturebox.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventmouse.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagemousewheel.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_picturebox.h" +#include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/xfa_fwltheme.h" #include "xfa/fxfa/app/xfa_textlayout.h" #include "xfa/fxfa/xfa_ffapp.h" @@ -349,7 +349,7 @@ bool CXFA_FFField::OnMouseEnter() { if (!m_pNormalWidget) { return false; } - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::Enter; TranslateFWLMessage(&ms); return true; @@ -358,7 +358,7 @@ bool CXFA_FFField::OnMouseExit() { if (!m_pNormalWidget) { return false; } - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::Leave; TranslateFWLMessage(&ms); return true; @@ -385,7 +385,7 @@ bool CXFA_FFField::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { return false; } SetButtonDown(true); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -402,7 +402,7 @@ bool CXFA_FFField::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { return false; } SetButtonDown(false); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -415,7 +415,7 @@ bool CXFA_FFField::OnLButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { if (!m_pNormalWidget) { return false; } - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDblClk; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -428,7 +428,7 @@ bool CXFA_FFField::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { if (!m_pNormalWidget) { return false; } - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::Move; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -444,7 +444,7 @@ bool CXFA_FFField::OnMouseWheel(uint32_t dwFlags, if (!m_pNormalWidget) { return false; } - CFWL_MsgMouseWheel ms(nullptr, m_pNormalWidget); + CFWL_MessageMouseWheel ms(nullptr, m_pNormalWidget); ms.m_dwFlags = dwFlags; ms.m_fx = fx; ms.m_fy = fy; @@ -467,7 +467,7 @@ bool CXFA_FFField::OnRButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { } SetButtonDown(true); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -484,7 +484,7 @@ bool CXFA_FFField::OnRButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { return false; } SetButtonDown(false); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::RightButtonUp; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -497,7 +497,7 @@ bool CXFA_FFField::OnRButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { if (!m_pNormalWidget) { return false; } - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::RightButtonDblClk; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -512,7 +512,7 @@ bool CXFA_FFField::OnSetFocus(CXFA_FFWidget* pOldWidget) { if (!m_pNormalWidget) { return false; } - CFWL_MsgSetFocus ms(nullptr, m_pNormalWidget); + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget); TranslateFWLMessage(&ms); m_dwStatus |= XFA_WidgetStatus_Focused; AddInvalidateRect(); @@ -522,7 +522,7 @@ bool CXFA_FFField::OnKillFocus(CXFA_FFWidget* pNewWidget) { if (!m_pNormalWidget) { return CXFA_FFWidget::OnKillFocus(pNewWidget); } - CFWL_MsgKillFocus ms(nullptr, m_pNormalWidget); + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget); TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; AddInvalidateRect(); @@ -533,7 +533,7 @@ bool CXFA_FFField::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { return false; } - CFWL_MsgKey ms(nullptr, m_pNormalWidget); + CFWL_MessageKey ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_KeyCommand::KeyDown; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwKeyCode; @@ -544,7 +544,7 @@ bool CXFA_FFField::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { return false; } - CFWL_MsgKey ms(nullptr, m_pNormalWidget); + CFWL_MessageKey ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_KeyCommand::KeyUp; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwKeyCode; @@ -564,7 +564,7 @@ bool CXFA_FFField::OnChar(uint32_t dwChar, uint32_t dwFlags) { if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { return false; } - CFWL_MsgKey ms(nullptr, m_pNormalWidget); + CFWL_MessageKey ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_KeyCommand::Char; ms.m_dwFlags = dwFlags; ms.m_dwKeyCode = dwChar; @@ -757,7 +757,7 @@ void CXFA_FFField::OnProcessMessage(CFWL_Message* pMessage) {} void CXFA_FFField::OnProcessEvent(CFWL_Event* pEvent) { switch (pEvent->GetType()) { case CFWL_Event::Type::Mouse: { - CFWL_EvtMouse* event = (CFWL_EvtMouse*)pEvent; + CFWL_EventMouse* event = (CFWL_EventMouse*)pEvent; if (event->m_dwCmd == FWL_MouseCommand::Enter) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_MouseEnter; diff --git a/xfa/fxfa/app/xfa_fffield.h b/xfa/fxfa/app/xfa_fffield.h index 17d33da754..6b4c92ae1d 100644 --- a/xfa/fxfa/app/xfa_fffield.h +++ b/xfa/fxfa/app/xfa_fffield.h @@ -7,8 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFFIELD_H_ #define XFA_FXFA_APP_XFA_FFFIELD_H_ -#include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_widgetdelegate.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_widgetdelegate.h" #include "xfa/fxfa/xfa_ffpageview.h" #include "xfa/fxfa/xfa_ffwidget.h" diff --git a/xfa/fxfa/app/xfa_ffimageedit.cpp b/xfa/fxfa/app/xfa_ffimageedit.cpp index 8ee6510b2d..04ad313a27 100644 --- a/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/xfa/fxfa/app/xfa_ffimageedit.cpp @@ -6,10 +6,10 @@ #include "xfa/fxfa/app/xfa_ffimageedit.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_picturebox.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_picturebox.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/xfa_ffdoc.h" #include "xfa/fxfa/xfa_ffdocview.h" @@ -93,7 +93,7 @@ bool CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, SetButtonDown(true); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; ms.m_dwFlags = dwFlags; ms.m_fx = fx; diff --git a/xfa/fxfa/app/xfa_ffpushbutton.cpp b/xfa/fxfa/app/xfa_ffpushbutton.cpp index a2b11e89ae..c12aa48d1a 100644 --- a/xfa/fxfa/app/xfa_ffpushbutton.cpp +++ b/xfa/fxfa/app/xfa_ffpushbutton.cpp @@ -6,9 +6,9 @@ #include "xfa/fxfa/app/xfa_ffpushbutton.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_pushbutton.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_pushbutton.h" +#include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_ffwidgetacc.h" #include "xfa/fxfa/app/xfa_textlayout.h" diff --git a/xfa/fxfa/app/xfa_fftext.cpp b/xfa/fxfa/app/xfa_fftext.cpp index c7e4f04d3c..cc7b65cabc 100644 --- a/xfa/fxfa/app/xfa_fftext.cpp +++ b/xfa/fxfa/app/xfa_fftext.cpp @@ -6,8 +6,8 @@ #include "xfa/fxfa/app/xfa_fftext.h" -#include "xfa/fwl/core/fwl_widgetdef.h" -#include "xfa/fwl/core/fwl_widgethit.h" +#include "xfa/fwl/fwl_widgetdef.h" +#include "xfa/fwl/fwl_widgethit.h" #include "xfa/fxfa/app/xfa_ffdraw.h" #include "xfa/fxfa/app/xfa_textlayout.h" #include "xfa/fxfa/xfa_ffapp.h" diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp index a678a20f6c..50b087315d 100644 --- a/xfa/fxfa/app/xfa_fftextedit.cpp +++ b/xfa/fxfa/app/xfa_fftextedit.cpp @@ -8,16 +8,16 @@ #include -#include "xfa/fwl/core/cfwl_datetimepicker.h" -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_evtcheckword.h" -#include "xfa/fwl/core/cfwl_evtselectchanged.h" -#include "xfa/fwl/core/cfwl_evttextchanged.h" -#include "xfa/fwl/core/cfwl_evtvalidate.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgsetfocus.h" -#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventcheckword.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_eventtextchanged.h" +#include "xfa/fwl/cfwl_eventvalidate.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/app/xfa_textlayout.h" @@ -117,7 +117,7 @@ bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, AddInvalidateRect(); } SetButtonDown(true); - CFWL_MsgMouse ms(nullptr, m_pNormalWidget); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget); ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -141,7 +141,7 @@ bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, AddInvalidateRect(); } SetButtonDown(true); - CFWL_MsgMouse ms(nullptr, nullptr); + CFWL_MessageMouse ms(nullptr, nullptr); ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; ms.m_dwFlags = dwFlags; ms.m_fx = fx; @@ -165,12 +165,12 @@ bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { AddInvalidateRect(); } CXFA_FFWidget::OnSetFocus(pOldWidget); - CFWL_MsgSetFocus ms(nullptr, m_pNormalWidget); + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget); TranslateFWLMessage(&ms); return true; } bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { - CFWL_MsgKillFocus ms(nullptr, m_pNormalWidget); + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget); TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; SetEditScrollOffset(); @@ -335,7 +335,8 @@ void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { CXFA_FFField::OnProcessEvent(pEvent); switch (pEvent->GetType()) { case CFWL_Event::Type::TextChanged: { - CFWL_EvtTextChanged* event = static_cast(pEvent); + CFWL_EventTextChanged* event = + static_cast(pEvent); CFX_WideString wsChange; OnTextChanged(m_pNormalWidget, wsChange, event->wsPrevText); break; @@ -346,7 +347,7 @@ void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { } case CFWL_Event::Type::CheckWord: { CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); - CFWL_EvtCheckWord* event = static_cast(pEvent); + CFWL_EventCheckWord* event = static_cast(pEvent); event->bCheckWord = CheckWord(event->bsWord.AsStringC()); break; } @@ -414,7 +415,7 @@ void CXFA_FFNumericEdit::UpdateWidgetProperty() { void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { if (pEvent->GetType() == CFWL_Event::Type::Validate) { - CFWL_EvtValidate* event = static_cast(pEvent); + CFWL_EventValidate* event = static_cast(pEvent); event->bValidate = OnValidate(m_pNormalWidget, event->wsInsert); return; } @@ -679,7 +680,8 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { - CFWL_EvtSelectChanged* event = static_cast(pEvent); + CFWL_EventSelectChanged* event = + static_cast(pEvent); OnSelectChanged(m_pNormalWidget, event->iYear, event->iMonth, event->iDay); return; } diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index 99333ba1dd..f46c6a0381 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -17,7 +17,7 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" -#include "xfa/fwl/core/fwl_widgethit.h" +#include "xfa/fwl/fwl_widgethit.h" #include "xfa/fxfa/app/xfa_textlayout.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/fxfa_widget.h" diff --git a/xfa/fxfa/app/xfa_fwladapter.h b/xfa/fxfa/app/xfa_fwladapter.h index 3aaa04e513..11181ddf36 100644 --- a/xfa/fxfa/app/xfa_fwladapter.h +++ b/xfa/fxfa/app/xfa_fwladapter.h @@ -9,7 +9,7 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/fwl_error.h" +#include "xfa/fwl/fwl_error.h" class CFWL_Widget; diff --git a/xfa/fxfa/app/xfa_fwltheme.cpp b/xfa/fxfa/app/xfa_fwltheme.cpp index 0222ddd7f7..2ca6237109 100644 --- a/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/xfa/fxfa/app/xfa_fwltheme.cpp @@ -9,19 +9,19 @@ #include "xfa/fde/tto/fde_textout.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fwl/core/cfwl_barcode.h" -#include "xfa/fwl/core/cfwl_caret.h" -#include "xfa/fwl/core/cfwl_checkbox.h" -#include "xfa/fwl/core/cfwl_combobox.h" -#include "xfa/fwl/core/cfwl_datetimepicker.h" -#include "xfa/fwl/core/cfwl_edit.h" -#include "xfa/fwl/core/cfwl_listbox.h" -#include "xfa/fwl/core/cfwl_monthcalendar.h" -#include "xfa/fwl/core/cfwl_picturebox.h" -#include "xfa/fwl/core/cfwl_pushbutton.h" -#include "xfa/fwl/core/cfwl_scrollbar.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" +#include "xfa/fwl/cfwl_barcode.h" +#include "xfa/fwl/cfwl_caret.h" +#include "xfa/fwl/cfwl_checkbox.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_monthcalendar.h" +#include "xfa/fwl/cfwl_picturebox.h" +#include "xfa/fwl/cfwl_pushbutton.h" +#include "xfa/fwl/cfwl_scrollbar.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" #include "xfa/fxfa/xfa_ffapp.h" #include "xfa/fxfa/xfa_ffwidget.h" #include "xfa/fxgraphics/cfx_color.h" diff --git a/xfa/fxfa/app/xfa_fwltheme.h b/xfa/fxfa/app/xfa_fwltheme.h index 257995094a..98fd74c315 100644 --- a/xfa/fxfa/app/xfa_fwltheme.h +++ b/xfa/fxfa/app/xfa_fwltheme.h @@ -9,7 +9,7 @@ #include -#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fwl/theme/cfwl_barcodetp.h" #include "xfa/fwl/theme/cfwl_carettp.h" #include "xfa/fwl/theme/cfwl_checkboxtp.h" diff --git a/xfa/fxfa/xfa_ffapp.h b/xfa/fxfa/xfa_ffapp.h index 5883be2279..bc6e948ebf 100644 --- a/xfa/fxfa/xfa_ffapp.h +++ b/xfa/fxfa/xfa_ffapp.h @@ -14,7 +14,7 @@ #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "xfa/fgas/font/cfgas_fontmgr.h" -#include "xfa/fwl/core/cfwl_app.h" +#include "xfa/fwl/cfwl_app.h" #include "xfa/fxfa/fxfa.h" class CXFA_DefFontMgr; diff --git a/xfa/fxfa/xfa_ffwidget.h b/xfa/fxfa/xfa_ffwidget.h index 031c35ba2b..f4ef8ce97b 100644 --- a/xfa/fxfa/xfa_ffwidget.h +++ b/xfa/fxfa/xfa_ffwidget.h @@ -11,7 +11,7 @@ #include "core/fxcodec/fx_codec_def.h" #include "core/fxge/cfx_graphstatedata.h" -#include "xfa/fwl/core/cfwl_app.h" +#include "xfa/fwl/cfwl_app.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" diff --git a/xfa/fxgraphics/cfx_graphics.h b/xfa/fxgraphics/cfx_graphics.h index 7d9fff3138..e18564bf6d 100644 --- a/xfa/fxgraphics/cfx_graphics.h +++ b/xfa/fxgraphics/cfx_graphics.h @@ -15,7 +15,7 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" -#include "xfa/fwl/core/fwl_error.h" +#include "xfa/fwl/fwl_error.h" class CFX_Color; class CFX_Path; -- cgit v1.2.3