From 633a3b7b908031ca0db12d7694d6a09715fc6143 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 2 Jun 2017 15:27:22 -0700 Subject: Rename PWL_FooBar files to cpwl_foo_bar. Change-Id: I7ed0ba0acbbee291e285555974ebf50c0073668f Reviewed-on: https://pdfium-review.googlesource.com/6250 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- BUILD.gn | 48 +- fpdfsdk/cpdfsdk_interform.cpp | 2 +- fpdfsdk/cpdfsdk_widget.cpp | 4 +- fpdfsdk/formfiller/cba_fontmap.h | 2 +- fpdfsdk/formfiller/cffl_checkbox.cpp | 2 +- fpdfsdk/formfiller/cffl_combobox.cpp | 2 +- fpdfsdk/formfiller/cffl_formfiller.cpp | 2 +- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 2 +- fpdfsdk/formfiller/cffl_interactiveformfiller.h | 2 +- fpdfsdk/formfiller/cffl_listbox.cpp | 2 +- fpdfsdk/formfiller/cffl_pushbutton.cpp | 2 +- fpdfsdk/formfiller/cffl_radiobutton.cpp | 2 +- fpdfsdk/fpdf_sysfontinfo.cpp | 2 +- fpdfsdk/fxedit/fxet_edit.cpp | 4 +- fpdfsdk/fxedit/fxet_list.cpp | 2 +- fpdfsdk/javascript/Field.h | 2 +- fpdfsdk/javascript/color.h | 2 +- fpdfsdk/pdfwindow/PWL_Button.cpp | 39 - fpdfsdk/pdfwindow/PWL_Button.h | 27 - fpdfsdk/pdfwindow/PWL_Caret.cpp | 147 --- fpdfsdk/pdfwindow/PWL_Caret.h | 53 - fpdfsdk/pdfwindow/PWL_ComboBox.cpp | 587 ---------- fpdfsdk/pdfwindow/PWL_ComboBox.h | 107 -- fpdfsdk/pdfwindow/PWL_Edit.cpp | 863 --------------- fpdfsdk/pdfwindow/PWL_Edit.h | 139 --- fpdfsdk/pdfwindow/PWL_EditCtrl.cpp | 483 --------- fpdfsdk/pdfwindow/PWL_EditCtrl.h | 108 -- fpdfsdk/pdfwindow/PWL_FontMap.cpp | 413 ------- fpdfsdk/pdfwindow/PWL_FontMap.h | 96 -- fpdfsdk/pdfwindow/PWL_Icon.cpp | 225 ---- fpdfsdk/pdfwindow/PWL_Icon.h | 58 - fpdfsdk/pdfwindow/PWL_ListBox.cpp | 461 -------- fpdfsdk/pdfwindow/PWL_ListBox.h | 118 -- fpdfsdk/pdfwindow/PWL_ScrollBar.cpp | 1186 --------------------- fpdfsdk/pdfwindow/PWL_ScrollBar.h | 185 ---- fpdfsdk/pdfwindow/PWL_SpecialButton.cpp | 80 -- fpdfsdk/pdfwindow/PWL_SpecialButton.h | 56 - fpdfsdk/pdfwindow/PWL_Utils.cpp | 1155 -------------------- fpdfsdk/pdfwindow/PWL_Utils.h | 162 --- fpdfsdk/pdfwindow/PWL_Wnd.cpp | 830 -------------- fpdfsdk/pdfwindow/PWL_Wnd.h | 370 ------- fpdfsdk/pdfwindow/cpwl_button.cpp | 39 + fpdfsdk/pdfwindow/cpwl_button.h | 27 + fpdfsdk/pdfwindow/cpwl_caret.cpp | 147 +++ fpdfsdk/pdfwindow/cpwl_caret.h | 53 + fpdfsdk/pdfwindow/cpwl_combo_box.cpp | 587 ++++++++++ fpdfsdk/pdfwindow/cpwl_combo_box.h | 107 ++ fpdfsdk/pdfwindow/cpwl_edit.cpp | 863 +++++++++++++++ fpdfsdk/pdfwindow/cpwl_edit.h | 139 +++ fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp | 483 +++++++++ fpdfsdk/pdfwindow/cpwl_edit_ctrl.h | 108 ++ fpdfsdk/pdfwindow/cpwl_font_map.cpp | 413 +++++++ fpdfsdk/pdfwindow/cpwl_font_map.h | 96 ++ fpdfsdk/pdfwindow/cpwl_icon.cpp | 225 ++++ fpdfsdk/pdfwindow/cpwl_icon.h | 58 + fpdfsdk/pdfwindow/cpwl_list_box.cpp | 460 ++++++++ fpdfsdk/pdfwindow/cpwl_list_box.h | 118 ++ fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp | 1186 +++++++++++++++++++++ fpdfsdk/pdfwindow/cpwl_scroll_bar.h | 185 ++++ fpdfsdk/pdfwindow/cpwl_special_button.cpp | 80 ++ fpdfsdk/pdfwindow/cpwl_special_button.h | 56 + fpdfsdk/pdfwindow/cpwl_utils.cpp | 1168 ++++++++++++++++++++ fpdfsdk/pdfwindow/cpwl_utils.h | 162 +++ fpdfsdk/pdfwindow/cpwl_wnd.cpp | 830 ++++++++++++++ fpdfsdk/pdfwindow/cpwl_wnd.h | 370 +++++++ 65 files changed, 8002 insertions(+), 7990 deletions(-) delete mode 100644 fpdfsdk/pdfwindow/PWL_Button.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_Button.h delete mode 100644 fpdfsdk/pdfwindow/PWL_Caret.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_Caret.h delete mode 100644 fpdfsdk/pdfwindow/PWL_ComboBox.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_ComboBox.h delete mode 100644 fpdfsdk/pdfwindow/PWL_Edit.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_Edit.h delete mode 100644 fpdfsdk/pdfwindow/PWL_EditCtrl.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_EditCtrl.h delete mode 100644 fpdfsdk/pdfwindow/PWL_FontMap.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_FontMap.h delete mode 100644 fpdfsdk/pdfwindow/PWL_Icon.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_Icon.h delete mode 100644 fpdfsdk/pdfwindow/PWL_ListBox.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_ListBox.h delete mode 100644 fpdfsdk/pdfwindow/PWL_ScrollBar.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_ScrollBar.h delete mode 100644 fpdfsdk/pdfwindow/PWL_SpecialButton.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_SpecialButton.h delete mode 100644 fpdfsdk/pdfwindow/PWL_Utils.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_Utils.h delete mode 100644 fpdfsdk/pdfwindow/PWL_Wnd.cpp delete mode 100644 fpdfsdk/pdfwindow/PWL_Wnd.h create mode 100644 fpdfsdk/pdfwindow/cpwl_button.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_button.h create mode 100644 fpdfsdk/pdfwindow/cpwl_caret.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_caret.h create mode 100644 fpdfsdk/pdfwindow/cpwl_combo_box.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_combo_box.h create mode 100644 fpdfsdk/pdfwindow/cpwl_edit.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_edit.h create mode 100644 fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_edit_ctrl.h create mode 100644 fpdfsdk/pdfwindow/cpwl_font_map.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_font_map.h create mode 100644 fpdfsdk/pdfwindow/cpwl_icon.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_icon.h create mode 100644 fpdfsdk/pdfwindow/cpwl_list_box.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_list_box.h create mode 100644 fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_scroll_bar.h create mode 100644 fpdfsdk/pdfwindow/cpwl_special_button.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_special_button.h create mode 100644 fpdfsdk/pdfwindow/cpwl_utils.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_utils.h create mode 100644 fpdfsdk/pdfwindow/cpwl_wnd.cpp create mode 100644 fpdfsdk/pdfwindow/cpwl_wnd.h diff --git a/BUILD.gn b/BUILD.gn index fec9063c01..49c79c3440 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1078,36 +1078,36 @@ static_library("fxedit") { static_library("pdfwindow") { sources = [ - "fpdfsdk/pdfwindow/PWL_Button.cpp", - "fpdfsdk/pdfwindow/PWL_Button.h", - "fpdfsdk/pdfwindow/PWL_Caret.cpp", - "fpdfsdk/pdfwindow/PWL_Caret.h", - "fpdfsdk/pdfwindow/PWL_ComboBox.cpp", - "fpdfsdk/pdfwindow/PWL_ComboBox.h", - "fpdfsdk/pdfwindow/PWL_Edit.cpp", - "fpdfsdk/pdfwindow/PWL_Edit.h", - "fpdfsdk/pdfwindow/PWL_EditCtrl.cpp", - "fpdfsdk/pdfwindow/PWL_EditCtrl.h", - "fpdfsdk/pdfwindow/PWL_FontMap.cpp", - "fpdfsdk/pdfwindow/PWL_FontMap.h", - "fpdfsdk/pdfwindow/PWL_Icon.cpp", - "fpdfsdk/pdfwindow/PWL_Icon.h", - "fpdfsdk/pdfwindow/PWL_ListBox.cpp", - "fpdfsdk/pdfwindow/PWL_ListBox.h", - "fpdfsdk/pdfwindow/PWL_ScrollBar.cpp", - "fpdfsdk/pdfwindow/PWL_ScrollBar.h", - "fpdfsdk/pdfwindow/PWL_SpecialButton.cpp", - "fpdfsdk/pdfwindow/PWL_SpecialButton.h", - "fpdfsdk/pdfwindow/PWL_Utils.cpp", - "fpdfsdk/pdfwindow/PWL_Utils.h", - "fpdfsdk/pdfwindow/PWL_Wnd.cpp", - "fpdfsdk/pdfwindow/PWL_Wnd.h", + "fpdfsdk/pdfwindow/cpwl_button.cpp", + "fpdfsdk/pdfwindow/cpwl_button.h", + "fpdfsdk/pdfwindow/cpwl_caret.cpp", + "fpdfsdk/pdfwindow/cpwl_caret.h", "fpdfsdk/pdfwindow/cpwl_color.cpp", "fpdfsdk/pdfwindow/cpwl_color.h", + "fpdfsdk/pdfwindow/cpwl_combo_box.cpp", + "fpdfsdk/pdfwindow/cpwl_combo_box.h", + "fpdfsdk/pdfwindow/cpwl_edit.cpp", + "fpdfsdk/pdfwindow/cpwl_edit.h", + "fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp", + "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h", + "fpdfsdk/pdfwindow/cpwl_font_map.cpp", + "fpdfsdk/pdfwindow/cpwl_font_map.h", + "fpdfsdk/pdfwindow/cpwl_icon.cpp", + "fpdfsdk/pdfwindow/cpwl_icon.h", + "fpdfsdk/pdfwindow/cpwl_list_box.cpp", + "fpdfsdk/pdfwindow/cpwl_list_box.h", + "fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp", + "fpdfsdk/pdfwindow/cpwl_scroll_bar.h", + "fpdfsdk/pdfwindow/cpwl_special_button.cpp", + "fpdfsdk/pdfwindow/cpwl_special_button.h", "fpdfsdk/pdfwindow/cpwl_timer.cpp", "fpdfsdk/pdfwindow/cpwl_timer.h", "fpdfsdk/pdfwindow/cpwl_timer_handler.cpp", "fpdfsdk/pdfwindow/cpwl_timer_handler.h", + "fpdfsdk/pdfwindow/cpwl_utils.cpp", + "fpdfsdk/pdfwindow/cpwl_utils.h", + "fpdfsdk/pdfwindow/cpwl_wnd.cpp", + "fpdfsdk/pdfwindow/cpwl_wnd.h", ] configs += [ ":pdfium_core_config" ] deps = [ diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 76cb6fdabf..c7f8e34a9e 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -32,7 +32,7 @@ #include "fpdfsdk/ipdfsdk_annothandler.h" #include "fpdfsdk/javascript/ijs_event_context.h" #include "fpdfsdk/javascript/ijs_runtime.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index bd586a999c..f2dad5c032 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -29,8 +29,8 @@ #include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" diff --git a/fpdfsdk/formfiller/cba_fontmap.h b/fpdfsdk/formfiller/cba_fontmap.h index 14aabe4d2a..17b7b4e989 100644 --- a/fpdfsdk/formfiller/cba_fontmap.h +++ b/fpdfsdk/formfiller/cba_fontmap.h @@ -8,7 +8,7 @@ #define FPDFSDK_FORMFILLER_CBA_FONTMAP_H_ #include "core/fxcrt/cfx_unowned_ptr.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" class CPDF_Dictionary; class CPDFSDK_Annot; diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp index 2a578aa686..d8227d8760 100644 --- a/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/fpdfsdk/formfiller/cffl_checkbox.cpp @@ -9,7 +9,7 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" #include "public/fpdf_fwlevent.h" CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_FormFillEnvironment* pApp, diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index 8e4efc453a..006828df75 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -12,7 +12,7 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/pdfwindow/PWL_ComboBox.h" +#include "fpdfsdk/pdfwindow/cpwl_combo_box.h" #include "third_party/base/ptr_util.h" CFFL_ComboBox::CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp, diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index f15efd2462..98a14e61af 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -13,7 +13,7 @@ #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" #define GetRed(rgb) ((uint8_t)(rgb)) #define GetGreen(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8)) diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index 2c75225283..2bf601d2f8 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -22,7 +22,7 @@ #include "fpdfsdk/formfiller/cffl_pushbutton.h" #include "fpdfsdk/formfiller/cffl_radiobutton.h" #include "fpdfsdk/formfiller/cffl_textfield.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" #include "third_party/base/stl_util.h" #define FFL_MAXLISTBOXHEIGHT 140.0f diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/fpdfsdk/formfiller/cffl_interactiveformfiller.h index d2f59bfe38..d84b8b8a98 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.h +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.h @@ -13,7 +13,7 @@ #include "core/fxcrt/cfx_unowned_ptr.h" #include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" class CFFL_FormFiller; class CPDFSDK_FormFillEnvironment; diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 55c0f3f2aa..11206e2b87 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -12,7 +12,7 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" #include "third_party/base/ptr_util.h" #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f diff --git a/fpdfsdk/formfiller/cffl_pushbutton.cpp b/fpdfsdk/formfiller/cffl_pushbutton.cpp index 15e15f597b..d0d51b7b37 100644 --- a/fpdfsdk/formfiller/cffl_pushbutton.cpp +++ b/fpdfsdk/formfiller/cffl_pushbutton.cpp @@ -7,7 +7,7 @@ #include "fpdfsdk/formfiller/cffl_pushbutton.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" CFFL_PushButton::CFFL_PushButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget) diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp index e264a3bf4d..e5a5a98b9a 100644 --- a/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -9,7 +9,7 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" #include "public/fpdf_fwlevent.h" CFFL_RadioButton::CFFL_RadioButton(CPDFSDK_FormFillEnvironment* pApp, diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index 28af1ac582..897f2a28d8 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp @@ -14,7 +14,7 @@ #include "core/fxge/fx_font.h" #include "core/fxge/ifx_systemfontinfo.h" #include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" #include "third_party/base/ptr_util.h" static_assert(FXFONT_ANSI_CHARSET == FX_CHARSET_ANSI, "Charset must match"); diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp index 0e86562044..130a81d335 100644 --- a/fpdfsdk/fxedit/fxet_edit.cpp +++ b/fpdfsdk/fxedit/fxet_edit.cpp @@ -27,8 +27,8 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cfx_systemhandler.h" #include "fpdfsdk/fxedit/fx_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fxedit/fxet_list.cpp b/fpdfsdk/fxedit/fxet_list.cpp index a3badf32fb..0b1a2ac532 100644 --- a/fpdfsdk/fxedit/fxet_list.cpp +++ b/fpdfsdk/fxedit/fxet_list.cpp @@ -12,7 +12,7 @@ #include "core/fpdfdoc/cpvt_word.h" #include "core/fxcrt/fx_extension.h" #include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" #include "third_party/base/stl_util.h" CFX_ListItem::CFX_ListItem() diff --git a/fpdfsdk/javascript/Field.h b/fpdfsdk/javascript/Field.h index 462c1271a1..688c5de9f4 100644 --- a/fpdfsdk/javascript/Field.h +++ b/fpdfsdk/javascript/Field.h @@ -13,7 +13,7 @@ #include "core/fxcrt/cfx_observable.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" // For CPWL_Color. +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" // For CPWL_Color. class CPDFSDK_Widget; class Document; diff --git a/fpdfsdk/javascript/color.h b/fpdfsdk/javascript/color.h index 8d6187a178..3e03dec730 100644 --- a/fpdfsdk/javascript/color.h +++ b/fpdfsdk/javascript/color.h @@ -10,7 +10,7 @@ #include #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class color : public CJS_EmbedObj { public: diff --git a/fpdfsdk/pdfwindow/PWL_Button.cpp b/fpdfsdk/pdfwindow/PWL_Button.cpp deleted file mode 100644 index 96be469454..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Button.cpp +++ /dev/null @@ -1,39 +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 "fpdfsdk/pdfwindow/PWL_Button.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -CPWL_Button::CPWL_Button() : m_bMouseDown(false) {} - -CPWL_Button::~CPWL_Button() {} - -CFX_ByteString CPWL_Button::GetClassName() const { - return "CPWL_Button"; -} - -void CPWL_Button::OnCreate(PWL_CREATEPARAM& cp) { - cp.eCursorType = FXCT_HAND; -} - -bool CPWL_Button::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - m_bMouseDown = true; - SetCapture(); - - return true; -} - -bool CPWL_Button::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - ReleaseCapture(); - m_bMouseDown = false; - - return true; -} diff --git a/fpdfsdk/pdfwindow/PWL_Button.h b/fpdfsdk/pdfwindow/PWL_Button.h deleted file mode 100644 index 2d1193f89d..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Button.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 FPDFSDK_PDFWINDOW_PWL_BUTTON_H_ -#define FPDFSDK_PDFWINDOW_PWL_BUTTON_H_ - -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPWL_Button : public CPWL_Wnd { - public: - CPWL_Button(); - ~CPWL_Button() override; - - // CPWL_Wnd - CFX_ByteString GetClassName() const override; - void OnCreate(PWL_CREATEPARAM& cp) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - - protected: - bool m_bMouseDown; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_BUTTON_H_ diff --git a/fpdfsdk/pdfwindow/PWL_Caret.cpp b/fpdfsdk/pdfwindow/PWL_Caret.cpp deleted file mode 100644 index 3658fbc23a..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Caret.cpp +++ /dev/null @@ -1,147 +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 "fpdfsdk/pdfwindow/PWL_Caret.h" - -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -#define PWL_CARET_FLASHINTERVAL 500 - -PWL_CARET_INFO::PWL_CARET_INFO() : bVisible(false) {} - -CPWL_Caret::CPWL_Caret() : m_bFlash(false), m_fWidth(0.4f), m_nDelay(0) {} - -CPWL_Caret::~CPWL_Caret() {} - -CFX_ByteString CPWL_Caret::GetClassName() const { - return "CPWL_Caret"; -} - -void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - GetCaretApp(sAppStream, CFX_PointF()); -} - -void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - if (IsVisible() && m_bFlash) { - CFX_FloatRect rcRect = GetCaretRect(); - CFX_FloatRect rcClip = GetClipRect(); - CFX_PathData path; - - float fCaretX = rcRect.left + m_fWidth * 0.5f; - float fCaretTop = rcRect.top; - float fCaretBottom = rcRect.bottom; - if (!rcClip.IsEmpty()) { - rcRect.Intersect(rcClip); - if (rcRect.IsEmpty()) - return; - - fCaretTop = rcRect.top; - fCaretBottom = rcRect.bottom; - } - - path.AppendPoint(CFX_PointF(fCaretX, fCaretBottom), FXPT_TYPE::MoveTo, - false); - path.AppendPoint(CFX_PointF(fCaretX, fCaretTop), FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = m_fWidth; - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), - FXFILL_ALTERNATE); - } -} - -void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf& sAppStream, - const CFX_PointF& ptOffset) { - if (IsVisible() && m_bFlash) { - CFX_ByteTextBuf sCaret; - - CFX_FloatRect rcRect = GetCaretRect(); - CFX_FloatRect rcClip = GetClipRect(); - - rcRect = CPWL_Utils::OffsetRect(rcRect, ptOffset.x, ptOffset.y); - rcClip = CPWL_Utils::OffsetRect(rcClip, ptOffset.x, ptOffset.y); - - sCaret << "q\n"; - if (!rcClip.IsEmpty()) { - sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " " - << rcClip.right - rcClip.left << " " - << rcClip.top - rcClip.bottom - 4.5f << " re W n\n"; - } - sCaret << m_fWidth << " w\n0 G\n"; - sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.bottom << " m\n"; - sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.top << " l S\nQ\n"; - - sAppStream << sCaret; - } -} - -CFX_ByteString CPWL_Caret::GetCaretAppearanceStream( - const CFX_PointF& ptOffset) { - CFX_ByteTextBuf sCaret; - GetCaretApp(sCaret, ptOffset); - return sCaret.MakeString(); -} - -void CPWL_Caret::TimerProc() { - if (m_nDelay > 0) { - m_nDelay--; - } else { - m_bFlash = !m_bFlash; - InvalidateRect(); - } -} - -CFX_FloatRect CPWL_Caret::GetCaretRect() const { - return CFX_FloatRect(m_ptFoot.x, m_ptFoot.y, m_ptHead.x + m_fWidth, - m_ptHead.y); -} - -void CPWL_Caret::SetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot) { - if (bVisible) { - if (IsVisible()) { - if (m_ptHead != ptHead || m_ptFoot != ptFoot) { - m_ptHead = ptHead; - m_ptFoot = ptFoot; - m_bFlash = true; - Move(m_rcInvalid, false, true); - } - } else { - m_ptHead = ptHead; - m_ptFoot = ptFoot; - EndTimer(); - BeginTimer(PWL_CARET_FLASHINTERVAL); - CPWL_Wnd::SetVisible(true); - m_bFlash = true; - Move(m_rcInvalid, false, true); - } - } else { - m_ptHead = CFX_PointF(); - m_ptFoot = CFX_PointF(); - m_bFlash = false; - if (IsVisible()) { - EndTimer(); - CPWL_Wnd::SetVisible(false); - } - } -} - -void CPWL_Caret::InvalidateRect(CFX_FloatRect* pRect) { - if (pRect) { - CFX_FloatRect rcRefresh = CPWL_Utils::InflateRect(*pRect, 0.5f); - rcRefresh.top += 1; - rcRefresh.bottom -= 1; - CPWL_Wnd::InvalidateRect(&rcRefresh); - } else { - CPWL_Wnd::InvalidateRect(pRect); - } -} diff --git a/fpdfsdk/pdfwindow/PWL_Caret.h b/fpdfsdk/pdfwindow/PWL_Caret.h deleted file mode 100644 index 7c041f4f5e..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Caret.h +++ /dev/null @@ -1,53 +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 FPDFSDK_PDFWINDOW_PWL_CARET_H_ -#define FPDFSDK_PDFWINDOW_PWL_CARET_H_ - -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -struct PWL_CARET_INFO { - public: - PWL_CARET_INFO(); - - bool bVisible; - CFX_PointF ptHead; - CFX_PointF ptFoot; -}; - -class CPWL_Caret : public CPWL_Wnd { - public: - CPWL_Caret(); - ~CPWL_Caret() override; - - // CPWL_Wnd - CFX_ByteString GetClassName() const override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; - void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - void InvalidateRect(CFX_FloatRect* pRect = nullptr) override; - void SetVisible(bool bVisible) override {} - void TimerProc() override; - - void SetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot); - CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset); - void SetInvalidRect(CFX_FloatRect rc) { m_rcInvalid = rc; } - - private: - void GetCaretApp(CFX_ByteTextBuf& sAppStream, const CFX_PointF& ptOffset); - CFX_FloatRect GetCaretRect() const; - - bool m_bFlash; - CFX_PointF m_ptHead; - CFX_PointF m_ptFoot; - float m_fWidth; - int32_t m_nDelay; - CFX_FloatRect m_rcInvalid; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_CARET_H_ diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp deleted file mode 100644 index a4dbeabacf..0000000000 --- a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp +++ /dev/null @@ -1,587 +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 "fpdfsdk/pdfwindow/PWL_ComboBox.h" - -#include - -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/fxedit/fxet_list.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" -#include "public/fpdf_fwlevent.h" - -#define PWLCB_DEFAULTFONTSIZE 12.0f - -bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (!m_bMouseDown) - return true; - - ReleaseCapture(); - m_bMouseDown = false; - - if (!ClientHitTest(point)) - return true; - if (CPWL_Wnd* pParent = GetParentWindow()) - pParent->OnNotify(this, PNM_LBUTTONUP, 0, PWL_MAKEDWORD(point.x, point.y)); - - bool bExit = false; - OnNotifySelChanged(false, bExit, nFlag); - - return !bExit; -} - -bool CPWL_CBListBox::OnKeyDownWithExit(uint16_t nChar, - bool& bExit, - uint32_t nFlag) { - switch (nChar) { - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_Left: - case FWL_VKEY_End: - case FWL_VKEY_Right: - break; - default: - return false; - } - - switch (nChar) { - case FWL_VKEY_Up: - m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Down: - m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Home: - m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Left: - m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_End: - m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Right: - m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Delete: - break; - } - - OnNotifySelChanged(true, bExit, nFlag); - - return true; -} - -bool CPWL_CBListBox::OnCharWithExit(uint16_t nChar, - bool& bExit, - uint32_t nFlag) { - if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) - return false; - if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) - pComboBox->SetSelectText(); - - OnNotifySelChanged(true, bExit, nFlag); - - return true; -} - -void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CFX_ByteTextBuf sButton; - - CFX_PointF ptCenter = GetCenterPoint(); - - CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, - ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - - if (IsFloatBigger(rectWnd.right - rectWnd.left, - PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && - IsFloatBigger(rectWnd.top - rectWnd.bottom, - PWL_CBBUTTON_TRIANGLE_HALFLEN)) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << "q\n" << sButton << "Q\n"; - } - } -} - -void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); - - CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CFX_PointF ptCenter = GetCenterPoint(); - - CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, - ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - - if (IsFloatBigger(rectWnd.right - rectWnd.left, - PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && - IsFloatBigger(rectWnd.top - rectWnd.bottom, - PWL_CBBUTTON_TRIANGLE_HALFLEN)) { - CFX_PathData path; - path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); - path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, - PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0, - FXFILL_ALTERNATE); - } - } -} - -bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - SetCapture(); - - if (CPWL_Wnd* pParent = GetParentWindow()) { - pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, - PWL_MAKEDWORD(point.x, point.y)); - } - - return true; -} - -bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - ReleaseCapture(); - - return true; -} - -CPWL_ComboBox::CPWL_ComboBox() - : m_pEdit(nullptr), - m_pButton(nullptr), - m_pList(nullptr), - m_bPopup(false), - m_bBottom(true), - m_nSelectItem(-1), - m_pFillerNotify(nullptr) {} - -CPWL_ComboBox::~CPWL_ComboBox() {} - -CFX_ByteString CPWL_ComboBox::GetClassName() const { - return "CPWL_ComboBox"; -} - -void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) { - cp.dwFlags &= ~PWS_HSCROLL; - cp.dwFlags &= ~PWS_VSCROLL; -} - -void CPWL_ComboBox::SetFocus() { - if (m_pEdit) - m_pEdit->SetFocus(); -} - -void CPWL_ComboBox::KillFocus() { - SetPopup(false); - CPWL_Wnd::KillFocus(); -} - -CFX_WideString CPWL_ComboBox::GetText() const { - if (m_pEdit) { - return m_pEdit->GetText(); - } - return CFX_WideString(); -} - -void CPWL_ComboBox::SetText(const CFX_WideString& text) { - if (m_pEdit) - m_pEdit->SetText(text); -} - -void CPWL_ComboBox::AddString(const CFX_WideString& str) { - if (m_pList) - m_pList->AddString(str); -} - -int32_t CPWL_ComboBox::GetSelect() const { - return m_nSelectItem; -} - -void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { - if (m_pList) - m_pList->Select(nItemIndex); - - m_pEdit->SetText(m_pList->GetText()); - m_nSelectItem = nItemIndex; -} - -void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { - if (m_pEdit) - m_pEdit->SetSel(nStartChar, nEndChar); -} - -void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { - nStartChar = -1; - nEndChar = -1; - - if (m_pEdit) - m_pEdit->GetSel(nStartChar, nEndChar); -} - -void CPWL_ComboBox::Clear() { - if (m_pEdit) - m_pEdit->Clear(); -} - -void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { - CreateEdit(cp); - CreateButton(cp); - CreateListBox(cp); -} - -void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { - if (m_pEdit) - return; - - m_pEdit = new CPWL_CBEdit(); - m_pEdit->AttachFFLData(m_pFormFiller.Get()); - - PWL_CREATEPARAM ecp = cp; - ecp.pParentWnd = this; - ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | - PES_AUTOSCROLL | PES_UNDO; - - if (HasFlag(PWS_AUTOFONTSIZE)) - ecp.dwFlags |= PWS_AUTOFONTSIZE; - - if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) - ecp.dwFlags |= PWS_READONLY; - - ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); - ecp.dwBorderWidth = 0; - ecp.nBorderStyle = BorderStyle::SOLID; - m_pEdit->Create(ecp); -} - -void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { - if (m_pButton) - return; - - m_pButton = new CPWL_CBButton; - - PWL_CREATEPARAM bcp = cp; - bcp.pParentWnd = this; - bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; - bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR; - bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; - bcp.dwBorderWidth = 2; - bcp.nBorderStyle = BorderStyle::BEVELED; - bcp.eCursorType = FXCT_ARROW; - m_pButton->Create(bcp); -} - -void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { - if (m_pList) - return; - - m_pList = new CPWL_CBListBox(); - m_pList->AttachFFLData(m_pFormFiller.Get()); - - PWL_CREATEPARAM lcp = cp; - lcp.pParentWnd = this; - lcp.dwFlags = - PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; - lcp.nBorderStyle = BorderStyle::SOLID; - lcp.dwBorderWidth = 1; - lcp.eCursorType = FXCT_ARROW; - lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); - - if (cp.dwFlags & PWS_AUTOFONTSIZE) - lcp.fFontSize = PWLCB_DEFAULTFONTSIZE; - else - lcp.fFontSize = cp.fFontSize; - - if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) - lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; - - if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) - lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - - m_pList->Create(lcp); -} - -void CPWL_ComboBox::RePosChildWnd() { - const CFX_FloatRect rcClient = GetClientRect(); - if (m_bPopup) { - const float fOldWindowHeight = m_rcOldWindow.Height(); - const float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; - - CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); - CFX_FloatRect rcButton = rcClient; - rcButton.left = - std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); - CFX_FloatRect rcEdit = rcClient; - rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); - if (m_bBottom) { - rcButton.bottom = rcButton.top - fOldClientHeight; - rcEdit.bottom = rcEdit.top - fOldClientHeight; - rcList.top -= fOldWindowHeight; - } else { - rcButton.top = rcButton.bottom + fOldClientHeight; - rcEdit.top = rcEdit.bottom + fOldClientHeight; - rcList.bottom += fOldWindowHeight; - } - - if (m_pButton) - m_pButton->Move(rcButton, true, false); - - if (m_pEdit) - m_pEdit->Move(rcEdit, true, false); - - if (m_pList) { - m_pList->SetVisible(true); - m_pList->Move(rcList, true, false); - m_pList->ScrollToListItem(m_nSelectItem); - } - return; - } - - CFX_FloatRect rcButton = rcClient; - rcButton.left = - std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); - - if (m_pButton) - m_pButton->Move(rcButton, true, false); - - CFX_FloatRect rcEdit = rcClient; - rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); - - if (m_pEdit) - m_pEdit->Move(rcEdit, true, false); - - if (m_pList) - m_pList->SetVisible(false); -} - -void CPWL_ComboBox::SelectAll() { - if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) - m_pEdit->SelectAll(); -} - -CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { - return CFX_FloatRect(); -} - -void CPWL_ComboBox::SetPopup(bool bPopup) { - if (!m_pList) - return; - if (bPopup == m_bPopup) - return; - float fListHeight = m_pList->GetContentRect().Height(); - if (!IsFloatBigger(fListHeight, 0.0f)) - return; - - if (!bPopup) { - m_bPopup = bPopup; - Move(m_rcOldWindow, true, true); - return; - } - - if (!m_pFillerNotify) - return; - -#ifdef PDF_ENABLE_XFA - bool bExit = false; - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0); - if (bExit) - return; -#endif // PDF_ENABLE_XFA - - float fBorderWidth = m_pList->GetBorderWidth() * 2; - float fPopupMin = 0.0f; - if (m_pList->GetCount() > 3) - fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth; - float fPopupMax = fListHeight + fBorderWidth; - - bool bBottom; - float fPopupRet; - m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, - &bBottom, &fPopupRet); - if (!IsFloatBigger(fPopupRet, 0.0f)) - return; - - m_rcOldWindow = CPWL_Wnd::GetWindowRect(); - m_bPopup = bPopup; - m_bBottom = bBottom; - - CFX_FloatRect rcWindow = m_rcOldWindow; - if (bBottom) - rcWindow.bottom -= fPopupRet; - else - rcWindow.top += fPopupRet; - - Move(rcWindow, true, true); -#ifdef PDF_ENABLE_XFA - bExit = false; - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0); -#endif // PDF_ENABLE_XFA -} - -bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { - if (!m_pList) - return false; - if (!m_pEdit) - return false; - - m_nSelectItem = -1; - - switch (nChar) { - case FWL_VKEY_Up: - if (m_pList->GetCurSel() > 0) { - bool bExit = false; -#ifdef PDF_ENABLE_XFA - if (m_pFillerNotify) { - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - bExit = false; - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - } -#endif // PDF_ENABLE_XFA - if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { - if (bExit) - return false; - SetSelectText(); - } - } - return true; - case FWL_VKEY_Down: - if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { - bool bExit = false; -#ifdef PDF_ENABLE_XFA - if (m_pFillerNotify) { - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - bExit = false; - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - } -#endif // PDF_ENABLE_XFA - if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { - if (bExit) - return false; - SetSelectText(); - } - } - return true; - } - - if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) - return m_pEdit->OnKeyDown(nChar, nFlag); - - return false; -} - -bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { - if (!m_pList) - return false; - - if (!m_pEdit) - return false; - - m_nSelectItem = -1; - if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) - return m_pEdit->OnChar(nChar, nFlag); - - bool bExit = false; -#ifdef PDF_ENABLE_XFA - if (m_pFillerNotify) { - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - } -#endif // PDF_ENABLE_XFA - return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : false; -} - -void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - switch (msg) { - case PNM_LBUTTONDOWN: - if (pWnd == m_pButton) { - SetPopup(!m_bPopup); - return; - } - break; - case PNM_LBUTTONUP: - if (m_pEdit && m_pList) { - if (pWnd == m_pList) { - SetSelectText(); - SelectAll(); - m_pEdit->SetFocus(); - SetPopup(false); - return; - } - } - break; - } - - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); -} - -bool CPWL_ComboBox::IsPopup() const { - return m_bPopup; -} - -void CPWL_ComboBox::SetSelectText() { - m_pEdit->SelectAll(); - m_pEdit->ReplaceSel(m_pList->GetText()); - m_pEdit->SelectAll(); - m_nSelectItem = m_pList->GetCurSel(); -} - -void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { - m_pFillerNotify = pNotify; - - if (m_pEdit) - m_pEdit->SetFillerNotify(pNotify); - - if (m_pList) - m_pList->SetFillerNotify(pNotify); -} diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.h b/fpdfsdk/pdfwindow/PWL_ComboBox.h deleted file mode 100644 index 9211777656..0000000000 --- a/fpdfsdk/pdfwindow/PWL_ComboBox.h +++ /dev/null @@ -1,107 +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 FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_ -#define FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_ - -#include - -#include "core/fxcrt/cfx_unowned_ptr.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPWL_CBEdit : public CPWL_Edit { - public: - CPWL_CBEdit() {} - ~CPWL_CBEdit() override {} -}; - -class CPWL_CBListBox : public CPWL_ListBox { - public: - CPWL_CBListBox() {} - ~CPWL_CBListBox() override {} - - // CPWL_ListBox - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - - bool OnKeyDownWithExit(uint16_t nChar, bool& bExit, uint32_t nFlag); - bool OnCharWithExit(uint16_t nChar, bool& bExit, uint32_t nFlag); -}; - -#define PWL_COMBOBOX_BUTTON_WIDTH 13 - -class CPWL_CBButton : public CPWL_Wnd { - public: - CPWL_CBButton() {} - ~CPWL_CBButton() override {} - - // CPWL_Wnd - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; - void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; -}; - -class CPWL_ComboBox : public CPWL_Wnd { - public: - CPWL_ComboBox(); - ~CPWL_ComboBox() override; - - CPWL_Edit* GetEdit() const { return m_pEdit.Get(); } - - // CPWL_Wnd: - CFX_ByteString GetClassName() const override; - void OnCreate(PWL_CREATEPARAM& cp) override; - bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; - bool OnChar(uint16_t nChar, uint32_t nFlag) override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; - void CreateChildWnd(const PWL_CREATEPARAM& cp) override; - void RePosChildWnd() override; - CFX_FloatRect GetFocusRect() const override; - void SetFocus() override; - void KillFocus() override; - - void SetFillerNotify(IPWL_Filler_Notify* pNotify); - - CFX_WideString GetText() const; - void SetText(const CFX_WideString& text); - void AddString(const CFX_WideString& str); - int32_t GetSelect() const; - void SetSelect(int32_t nItemIndex); - - void SetEditSel(int32_t nStartChar, int32_t nEndChar); - void GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const; - void Clear(); - void SelectAll(); - bool IsPopup() const; - - void SetSelectText(); - - void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } - - private: - void CreateEdit(const PWL_CREATEPARAM& cp); - void CreateButton(const PWL_CREATEPARAM& cp); - void CreateListBox(const PWL_CREATEPARAM& cp); - void SetPopup(bool bPopup); - - CFX_UnownedPtr m_pEdit; - CFX_UnownedPtr m_pButton; - CFX_UnownedPtr m_pList; - CFX_FloatRect m_rcOldWindow; - bool m_bPopup; - bool m_bBottom; - int32_t m_nSelectItem; - CFX_UnownedPtr m_pFillerNotify; - CFX_UnownedPtr m_pFormFiller; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_ diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp deleted file mode 100644 index a2f1c89a8a..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Edit.cpp +++ /dev/null @@ -1,863 +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 "fpdfsdk/pdfwindow/PWL_Edit.h" - -#include -#include -#include - -#include "core/fpdfapi/font/cpdf_font.h" -#include "core/fpdfdoc/cpvt_word.h" -#include "core/fxcrt/fx_safe_types.h" -#include "core/fxcrt/xml/cxml_content.h" -#include "core/fxcrt/xml/cxml_element.h" -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "core/fxge/fx_font.h" -#include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Caret.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" -#include "public/fpdf_fwlevent.h" -#include "third_party/base/stl_util.h" - -CPWL_Edit::CPWL_Edit() : m_bFocus(false) {} - -CPWL_Edit::~CPWL_Edit() { - ASSERT(!m_bFocus); -} - -CFX_ByteString CPWL_Edit::GetClassName() const { - return PWL_CLASSNAME_EDIT; -} - -void CPWL_Edit::OnDestroy() {} - -void CPWL_Edit::SetText(const CFX_WideString& csText) { - CFX_WideString swText = csText; - if (!HasFlag(PES_RICH)) { - m_pEdit->SetText(swText); - return; - } - - CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); - std::unique_ptr pXML( - CXML_Element::Parse(sValue.c_str(), sValue.GetLength())); - if (!pXML) { - m_pEdit->SetText(swText); - return; - } - swText.clear(); - - bool bFirst = true; - int32_t nCount = pXML->CountChildren(); - for (int32_t i = 0; i < nCount; i++) { - CXML_Element* pSubElement = ToElement(pXML->GetChild(i)); - if (!pSubElement || !pSubElement->GetTagName().EqualNoCase("p")) - continue; - - CFX_WideString swSection; - int nSubChild = pSubElement->CountChildren(); - for (int32_t j = 0; j < nSubChild; j++) { - CXML_Content* pSubContent = ToContent(pSubElement->GetChild(j)); - if (pSubContent) - swSection += pSubContent->m_Content; - } - if (bFirst) - bFirst = false; - else - swText += FWL_VKEY_Return; - swText += swSection; - } - - m_pEdit->SetText(swText); -} - -void CPWL_Edit::RePosChildWnd() { - if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { - CFX_FloatRect rcWindow = m_rcOldWindow; - CFX_FloatRect rcVScroll = - CFX_FloatRect(rcWindow.right, rcWindow.bottom, - rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top); - pVSB->Move(rcVScroll, true, false); - } - - if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) - m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( - GetClientRect(), 1.0f)); // +1 for caret beside border - - CPWL_EditCtrl::RePosChildWnd(); -} - -CFX_FloatRect CPWL_Edit::GetClientRect() const { - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); - - if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { - if (pVSB->IsVisible()) { - rcClient.right -= PWL_SCROLLBAR_WIDTH; - } - } - - return rcClient; -} - -void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) { - m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); -} - -bool CPWL_Edit::CanSelectAll() const { - return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); -} - -bool CPWL_Edit::CanClear() const { - return !IsReadOnly() && m_pEdit->IsSelected(); -} - -bool CPWL_Edit::CanCopy() const { - return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && - m_pEdit->IsSelected(); -} - -bool CPWL_Edit::CanCut() const { - return CanCopy() && !IsReadOnly(); -} -void CPWL_Edit::CutText() { - if (!CanCut()) - return; - m_pEdit->Clear(); -} - -void CPWL_Edit::OnCreated() { - CPWL_EditCtrl::OnCreated(); - - if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { - pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); - pScroll->SetTransparency(255); - } - - SetParamByFlag(); - - m_rcOldWindow = GetWindowRect(); - - m_pEdit->SetOprNotify(this); - m_pEdit->EnableOprNotify(true); -} - -void CPWL_Edit::SetParamByFlag() { - if (HasFlag(PES_RIGHT)) { - m_pEdit->SetAlignmentH(2, false); - } else if (HasFlag(PES_MIDDLE)) { - m_pEdit->SetAlignmentH(1, false); - } else { - m_pEdit->SetAlignmentH(0, false); - } - - if (HasFlag(PES_BOTTOM)) { - m_pEdit->SetAlignmentV(2, false); - } else if (HasFlag(PES_CENTER)) { - m_pEdit->SetAlignmentV(1, false); - } else { - m_pEdit->SetAlignmentV(0, false); - } - - if (HasFlag(PES_PASSWORD)) { - m_pEdit->SetPasswordChar('*', false); - } - - m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false); - m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false); - m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false); - m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false); - m_pEdit->EnableUndo(HasFlag(PES_UNDO)); - - if (HasFlag(PES_TEXTOVERFLOW)) { - SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); - m_pEdit->SetTextOverflow(true, false); - } else { - if (m_pEditCaret) { - m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( - GetClientRect(), 1.0f)); // +1 for caret beside border - } - } -} - -void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - CFX_FloatRect rcClient = GetClientRect(); - CFX_ByteTextBuf sLine; - - int32_t nCharArray = m_pEdit->GetCharArray(); - - if (nCharArray > 0) { - switch (GetBorderStyle()) { - case BorderStyle::SOLID: { - sLine << "q\n" - << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) - .AsStringC() - << " 2 J 0 j\n"; - - for (int32_t i = 1; i < nCharArray; i++) { - sLine << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.top << " l S\n"; - } - - sLine << "Q\n"; - break; - } - case BorderStyle::DASH: { - sLine << "q\n" - << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) - .AsStringC() - << " 2 J 0 j\n" - << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap - << "] " << GetBorderDash().nPhase << " d\n"; - - for (int32_t i = 1; i < nCharArray; i++) { - sLine << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.top << " l S\n"; - } - - sLine << "Q\n"; - break; - } - default: - break; - } - } - - sAppStream << sLine; - - CFX_ByteTextBuf sText; - CFX_PointF ptOffset; - CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); - CPVT_WordRange wrSelect = GetSelectWordRange(); - CPVT_WordRange wrVisible = - HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange(); - - CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); - CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); - CPVT_WordRange wrTemp = - CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); - CFX_ByteString sEditSel = - CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp); - - if (sEditSel.GetLength() > 0) - sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC() - << sEditSel.AsStringC(); - - wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); - CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( - m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), - m_pEdit->GetPasswordChar()); - - if (sEditBefore.GetLength() > 0) - sText << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sEditBefore.AsStringC() << "ET\n"; - - wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); - CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( - m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), - m_pEdit->GetPasswordChar()); - - if (sEditMid.GetLength() > 0) - sText << "BT\n" - << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) - .AsStringC() - << sEditMid.AsStringC() << "ET\n"; - - wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); - CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( - m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), - m_pEdit->GetPasswordChar()); - - if (sEditAfter.GetLength() > 0) - sText << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sEditAfter.AsStringC() << "ET\n"; - - if (sText.GetLength() > 0) { - CFX_FloatRect rect = GetClientRect(); - sAppStream << "q\n/Tx BMC\n"; - - if (!HasFlag(PES_TEXTOVERFLOW)) - sAppStream << rect.left << " " << rect.bottom << " " - << rect.right - rect.left << " " << rect.top - rect.bottom - << " re W n\n"; - - sAppStream << sText; - - sAppStream << "EMC\nQ\n"; - } -} - -void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); - - CFX_FloatRect rcClient = GetClientRect(); - CFX_ByteTextBuf sLine; - - int32_t nCharArray = m_pEdit->GetCharArray(); - FX_SAFE_INT32 nCharArraySafe = nCharArray; - nCharArraySafe -= 1; - nCharArraySafe *= 2; - - if (nCharArray > 0 && nCharArraySafe.IsValid()) { - switch (GetBorderStyle()) { - case BorderStyle::SOLID: { - CFX_GraphStateData gsd; - gsd.m_LineWidth = (float)GetBorderWidth(); - - CFX_PathData path; - - for (int32_t i = 0; i < nCharArray - 1; i++) { - path.AppendPoint( - CFX_PointF( - rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), - rcClient.bottom), - FXPT_TYPE::MoveTo, false); - path.AppendPoint( - CFX_PointF( - rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), - rcClient.top), - FXPT_TYPE::LineTo, false); - } - if (!path.GetPoints().empty()) { - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE); - } - break; - } - case BorderStyle::DASH: { - CFX_GraphStateData gsd; - gsd.m_LineWidth = (float)GetBorderWidth(); - - gsd.SetDashCount(2); - gsd.m_DashArray[0] = (float)GetBorderDash().nDash; - gsd.m_DashArray[1] = (float)GetBorderDash().nGap; - gsd.m_DashPhase = (float)GetBorderDash().nPhase; - - CFX_PathData path; - for (int32_t i = 0; i < nCharArray - 1; i++) { - path.AppendPoint( - CFX_PointF( - rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), - rcClient.bottom), - FXPT_TYPE::MoveTo, false); - path.AppendPoint( - CFX_PointF( - rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), - rcClient.top), - FXPT_TYPE::LineTo, false); - } - if (!path.GetPoints().empty()) { - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE); - } - break; - } - default: - break; - } - } - - CFX_FloatRect rcClip; - CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); - CPVT_WordRange* pRange = nullptr; - if (!HasFlag(PES_TEXTOVERFLOW)) { - rcClip = GetClientRect(); - pRange = &wrRange; - } - - CFX_SystemHandler* pSysHandler = GetSystemHandler(); - CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(), - GetTextColor().ToFXColor(GetTransparency()), rcClip, - CFX_PointF(), pRange, pSysHandler, m_pFormFiller.Get()); -} - -bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { - if (m_bMouseDown) - InvalidateRect(); - - m_bMouseDown = true; - SetCapture(); - - m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - } - - return true; -} - -bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDblClk(point, nFlag); - - if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { - m_pEdit->SelectAll(); - } - - return true; -} - -bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) { - if (m_bMouseDown) - return false; - - CPWL_Wnd::OnRButtonUp(point, nFlag); - - if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) - return true; - - CFX_SystemHandler* pSH = GetSystemHandler(); - if (!pSH) - return false; - - SetFocus(); - - return false; -} - -void CPWL_Edit::OnSetFocus() { - SetEditCaret(true); - if (!IsReadOnly()) { - if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) - pFocusHandler->OnSetFocus(this); - } - m_bFocus = true; -} - -void CPWL_Edit::OnKillFocus() { - ShowVScrollBar(false); - m_pEdit->SelectNone(); - SetCaret(false, CFX_PointF(), CFX_PointF()); - SetCharSet(FX_CHARSET_ANSI); - m_bFocus = false; -} - -void CPWL_Edit::SetCharSpace(float fCharSpace) { - m_pEdit->SetCharSpace(fCharSpace); -} - -CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( - const CFX_PointF& ptOffset) const { - CPVT_WordRange wr = GetSelectWordRange(); - return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr); -} - -CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { - if (m_pEdit->IsSelected()) { - int32_t nStart = -1; - int32_t nEnd = -1; - - m_pEdit->GetSel(nStart, nEnd); - - CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); - CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); - - return CPVT_WordRange(wpStart, wpEnd); - } - - return CPVT_WordRange(); -} - -CFX_ByteString CPWL_Edit::GetTextAppearanceStream( - const CFX_PointF& ptOffset) const { - CFX_ByteTextBuf sRet; - CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset); - if (sEdit.GetLength() > 0) { - sRet << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sEdit.AsStringC() << "ET\n"; - } - return sRet.MakeString(); -} - -CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( - const CFX_PointF& ptOffset) const { - if (m_pEditCaret) - return m_pEditCaret->GetCaretAppearanceStream(ptOffset); - - return CFX_ByteString(); -} - -CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) { - CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); - CPVT_WordPlace wpOld = pIterator->GetAt(); - pIterator->SetAt(wpWord); - - CFX_PointF pt; - CPVT_Word word; - if (pIterator->GetWord(word)) { - pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent); - } - pIterator->SetAt(wpOld); - return pt; -} - -bool CPWL_Edit::IsTextFull() const { - return m_pEdit->IsTextFull(); -} - -float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, - const CFX_FloatRect& rcPlate, - int32_t nCharArray) { - if (pFont && !pFont->IsStandardFont()) { - FX_RECT rcBBox; - pFont->GetFontBBox(rcBBox); - - CFX_FloatRect rcCell = rcPlate; - float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width(); - float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height(); - - return xdiv < ydiv ? xdiv : ydiv; - } - - return 0.0f; -} - -void CPWL_Edit::SetCharArray(int32_t nCharArray) { - if (HasFlag(PES_CHARARRAY) && nCharArray > 0) { - m_pEdit->SetCharArray(nCharArray); - m_pEdit->SetTextOverflow(true, true); - - if (HasFlag(PWS_AUTOFONTSIZE)) { - if (IPVT_FontMap* pFontMap = GetFontMap()) { - float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0), - GetClientRect(), nCharArray); - if (fFontSize > 0.0f) { - m_pEdit->SetAutoFontSize(false, true); - m_pEdit->SetFontSize(fFontSize); - } - } - } - } -} - -void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { - m_pEdit->SetLimitChar(nLimitChar); -} - -void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) { - m_pEdit->Clear(); - m_pEdit->InsertText(wsText, FX_CHARSET_Default); -} - -CFX_FloatRect CPWL_Edit::GetFocusRect() const { - return CFX_FloatRect(); -} - -void CPWL_Edit::ShowVScrollBar(bool bShow) { - if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { - if (bShow) { - if (!pScroll->IsVisible()) { - pScroll->SetVisible(true); - CFX_FloatRect rcWindow = GetWindowRect(); - m_rcOldWindow = rcWindow; - rcWindow.right += PWL_SCROLLBAR_WIDTH; - Move(rcWindow, true, true); - } - } else { - if (pScroll->IsVisible()) { - pScroll->SetVisible(false); - Move(m_rcOldWindow, true, true); - } - } - } -} - -bool CPWL_Edit::IsVScrollBarVisible() const { - if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { - return pScroll->IsVisible(); - } - - return false; -} - -bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { - if (m_bMouseDown) - return true; - - if (nChar == FWL_VKEY_Delete) { - if (m_pFillerNotify) { - bool bRC = true; - bool bExit = false; - CFX_WideString strChange; - CFX_WideString strChangeEx; - - int nSelStart = 0; - int nSelEnd = 0; - GetSel(nSelStart, nSelEnd); - - if (nSelStart == nSelEnd) - nSelEnd = nSelStart + 1; - m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange, - strChangeEx, nSelStart, nSelEnd, true, - bRC, bExit, nFlag); - if (!bRC) - return false; - if (bExit) - return false; - } - } - - bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); - - // In case of implementation swallow the OnKeyDown event. - if (IsProceedtoOnChar(nChar, nFlag)) - return true; - - return bRet; -} - -/** -*In case of implementation swallow the OnKeyDown event. -*If the event is swallowed, implementation may do other unexpected things, which -*is not the control means to do. -*/ -bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) { - bool bCtrl = IsCTRLpressed(nFlag); - bool bAlt = IsALTpressed(nFlag); - if (bCtrl && !bAlt) { - // hot keys for edit control. - switch (nKeyCode) { - case 'C': - case 'V': - case 'X': - case 'A': - case 'Z': - return true; - default: - break; - } - } - // control characters. - switch (nKeyCode) { - case FWL_VKEY_Escape: - case FWL_VKEY_Back: - case FWL_VKEY_Return: - case FWL_VKEY_Space: - return true; - default: - return false; - } -} - -bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) { - if (m_bMouseDown) - return true; - - bool bRC = true; - bool bExit = false; - - if (!IsCTRLpressed(nFlag)) { - if (m_pFillerNotify) { - CFX_WideString swChange; - - int nSelStart = 0; - int nSelEnd = 0; - GetSel(nSelStart, nSelEnd); - - switch (nChar) { - case FWL_VKEY_Back: - if (nSelStart == nSelEnd) - nSelStart = nSelEnd - 1; - break; - case FWL_VKEY_Return: - break; - default: - swChange += nChar; - break; - } - - CFX_WideString strChangeEx; - m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, - strChangeEx, nSelStart, nSelEnd, true, - bRC, bExit, nFlag); - } - } - - if (!bRC) - return true; - if (bExit) - return false; - - if (IPVT_FontMap* pFontMap = GetFontMap()) { - int32_t nOldCharSet = GetCharSet(); - int32_t nNewCharSet = - pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default); - if (nOldCharSet != nNewCharSet) { - SetCharSet(nNewCharSet); - } - } - - return CPWL_EditCtrl::OnChar(nChar, nFlag); -} - -bool CPWL_Edit::OnMouseWheel(short zDelta, - const CFX_PointF& point, - uint32_t nFlag) { - if (HasFlag(PES_MULTILINE)) { - CFX_PointF ptScroll = GetScrollPos(); - - if (zDelta > 0) { - ptScroll.y += GetFontSize(); - } else { - ptScroll.y -= GetFontSize(); - } - SetScrollPos(ptScroll); - - return true; - } - - return false; -} - -void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace) { - if (HasFlag(PES_SPELLCHECK)) { - m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), - GetLatinWordsRange(place))); - } -} - -void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace) { - if (HasFlag(PES_SPELLCHECK)) { - m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), - GetLatinWordsRange(place))); - } -} - -void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace) { - if (HasFlag(PES_SPELLCHECK)) { - m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), - GetLatinWordsRange(place))); - } -} - -void CPWL_Edit::OnClear(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace) { - if (HasFlag(PES_SPELLCHECK)) { - m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), - GetLatinWordsRange(place))); - } -} - -void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace) { - if (HasFlag(PES_SPELLCHECK)) { - m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), - GetLatinWordsRange(place))); - } -} - -void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace) { - if (HasFlag(PES_SPELLCHECK)) { - m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), - GetLatinWordsRange(place))); - } -} - -CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, - const CPVT_WordRange& wr2) { - return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos), - std::max(wr1.EndPos, wr2.EndPos)); -} - -CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const { - return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false); -} - -CPVT_WordRange CPWL_Edit::GetLatinWordsRange( - const CPVT_WordPlace& place) const { - return GetSameWordsRange(place, true, false); -} - -CPVT_WordRange CPWL_Edit::GetArabicWordsRange( - const CPVT_WordPlace& place) const { - return GetSameWordsRange(place, false, true); -} - -#define PWL_ISARABICWORD(word) \ - ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) - -CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, - bool bLatin, - bool bArabic) const { - CPVT_WordRange range; - - CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); - CPVT_Word wordinfo; - CPVT_WordPlace wpStart(place), wpEnd(place); - pIterator->SetAt(place); - - if (bLatin) { - while (pIterator->NextWord()) { - if (!pIterator->GetWord(wordinfo) || - !FX_EDIT_ISLATINWORD(wordinfo.Word)) { - break; - } - - wpEnd = pIterator->GetAt(); - } - } else if (bArabic) { - while (pIterator->NextWord()) { - if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) - break; - - wpEnd = pIterator->GetAt(); - } - } - - pIterator->SetAt(place); - - if (bLatin) { - do { - if (!pIterator->GetWord(wordinfo) || - !FX_EDIT_ISLATINWORD(wordinfo.Word)) { - break; - } - - wpStart = pIterator->GetAt(); - } while (pIterator->PrevWord()); - } else if (bArabic) { - do { - if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) - break; - - wpStart = pIterator->GetAt(); - } while (pIterator->PrevWord()); - } - - range.Set(wpStart, wpEnd); - return range; -} diff --git a/fpdfsdk/pdfwindow/PWL_Edit.h b/fpdfsdk/pdfwindow/PWL_Edit.h deleted file mode 100644 index 6fc02cae6f..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Edit.h +++ /dev/null @@ -1,139 +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 FPDFSDK_PDFWINDOW_PWL_EDIT_H_ -#define FPDFSDK_PDFWINDOW_PWL_EDIT_H_ - -#include "core/fpdfdoc/cpvt_wordrange.h" -#include "core/fxcrt/cfx_unowned_ptr.h" -#include "core/fxcrt/fx_basic.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" - -class IPWL_Filler_Notify { - public: - virtual ~IPWL_Filler_Notify() {} - - // Must write to |bBottom| and |fPopupRet|. - virtual void QueryWherePopup(void* pPrivateData, - float fPopupMin, - float fPopupMax, - bool* bBottom, - float* fPopupRet) = 0; - virtual void OnBeforeKeyStroke(void* pPrivateData, - CFX_WideString& strChange, - const CFX_WideString& strChangeEx, - int nSelStart, - int nSelEnd, - bool bKeyDown, - bool& bRC, - bool& bExit, - uint32_t nFlag) = 0; -#ifdef PDF_ENABLE_XFA - virtual void OnPopupPreOpen(void* pPrivateData, - bool& bExit, - uint32_t nFlag) = 0; - virtual void OnPopupPostOpen(void* pPrivateData, - bool& bExit, - uint32_t nFlag) = 0; -#endif // PDF_ENABLE_XFA -}; - -class CPWL_Edit : public CPWL_EditCtrl { - public: - CPWL_Edit(); - ~CPWL_Edit() override; - - // CPWL_EditCtrl - CFX_ByteString GetClassName() const override; - void OnDestroy() override; - void OnCreated() override; - void RePosChildWnd() override; - CFX_FloatRect GetClientRect() const override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; - void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) override; - bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnMouseWheel(short zDelta, - const CFX_PointF& point, - uint32_t nFlag) override; - bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; - bool OnChar(uint16_t nChar, uint32_t nFlag) override; - CFX_FloatRect GetFocusRect() const override; - void OnSetFocus() override; - void OnKillFocus() override; - - void SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat = PEAV_TOP, - bool bPaint = true); // 0:top 1:bottom 2:center - - void SetCharArray(int32_t nCharArray); - void SetLimitChar(int32_t nLimitChar); - - void SetCharSpace(float fCharSpace); - - bool CanSelectAll() const; - bool CanClear() const; - bool CanCopy() const; - bool CanCut() const; - - void CutText(); - - void SetText(const CFX_WideString& csText); - void ReplaceSel(const CFX_WideString& csText); - - CFX_ByteString GetTextAppearanceStream(const CFX_PointF& ptOffset) const; - CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset) const; - CFX_ByteString GetSelectAppearanceStream(const CFX_PointF& ptOffset) const; - - bool IsTextFull() const; - - static float GetCharArrayAutoFontSize(CPDF_Font* pFont, - const CFX_FloatRect& rcPlate, - int32_t nCharArray); - - void SetFillerNotify(IPWL_Filler_Notify* pNotify) { - m_pFillerNotify = pNotify; - } - - bool IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag); - void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } - - void OnInsertWord(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace); - void OnInsertReturn(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace); - void OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace); - void OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace); - void OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace); - void OnInsertText(const CPVT_WordPlace& place, - const CPVT_WordPlace& oldplace); - - private: - CPVT_WordRange GetSelectWordRange() const; - virtual void ShowVScrollBar(bool bShow); - bool IsVScrollBarVisible() const; - void SetParamByFlag(); - - float GetCharArrayAutoFontSize(int32_t nCharArray); - CFX_PointF GetWordRightBottomPoint(const CPVT_WordPlace& wpWord); - - CPVT_WordRange CombineWordRange(const CPVT_WordRange& wr1, - const CPVT_WordRange& wr2); - CPVT_WordRange GetLatinWordsRange(const CFX_PointF& point) const; - CPVT_WordRange GetLatinWordsRange(const CPVT_WordPlace& place) const; - CPVT_WordRange GetArabicWordsRange(const CPVT_WordPlace& place) const; - CPVT_WordRange GetSameWordsRange(const CPVT_WordPlace& place, - bool bLatin, - bool bArabic) const; - - bool m_bFocus; - CFX_FloatRect m_rcOldWindow; - CFX_UnownedPtr m_pFillerNotify; - CFX_UnownedPtr m_pFormFiller; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_EDIT_H_ diff --git a/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp b/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp deleted file mode 100644 index c149e80f14..0000000000 --- a/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp +++ /dev/null @@ -1,483 +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 "fpdfsdk/pdfwindow/PWL_EditCtrl.h" - -#include "core/fpdfdoc/cpvt_section.h" -#include "core/fpdfdoc/cpvt_word.h" -#include "core/fxge/fx_font.h" -#include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Caret.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" -#include "public/fpdf_fwlevent.h" - -CPWL_EditCtrl::CPWL_EditCtrl() - : m_pEdit(new CFX_Edit), - m_pEditCaret(nullptr), - m_bMouseDown(false), - m_nCharSet(FX_CHARSET_Default) {} - -CPWL_EditCtrl::~CPWL_EditCtrl() {} - -void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { - cp.eCursorType = FXCT_VBEAM; -} - -void CPWL_EditCtrl::OnCreated() { - SetFontSize(GetCreationParam().fFontSize); - - m_pEdit->SetFontMap(GetFontMap()); - m_pEdit->SetNotify(this); - m_pEdit->Initialize(); -} - -bool CPWL_EditCtrl::IsWndHorV() { - CFX_Matrix mt = GetWindowMatrix(); - return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y; -} - -void CPWL_EditCtrl::SetCursor() { - if (IsValid()) { - if (CFX_SystemHandler* pSH = GetSystemHandler()) { - if (IsWndHorV()) - pSH->SetCursor(FXCT_VBEAM); - else - pSH->SetCursor(FXCT_HBEAM); - } - } -} - -void CPWL_EditCtrl::RePosChildWnd() { - m_pEdit->SetPlateRect(GetClientRect()); -} - -void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); - - switch (msg) { - case PNM_SETSCROLLINFO: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); - } - break; - } - break; - case PNM_SETSCROLLPOS: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); - } - break; - } - break; - case PNM_SCROLLWINDOW: { - float fPos = *(float*)lParam; - switch (wParam) { - case SBT_VSCROLL: - m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos)); - break; - } - } break; - case PNM_SETCARETINFO: { - if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { - SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); - } - } break; - } -} - -void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { - if (!IsReadOnly()) - CreateEditCaret(cp); -} - -void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { - if (m_pEditCaret) - return; - - m_pEditCaret = new CPWL_Caret; - m_pEditCaret->SetInvalidRect(GetClientRect()); - - PWL_CREATEPARAM ecp = cp; - ecp.pParentWnd = this; - ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; - ecp.dwBorderWidth = 0; - ecp.nBorderStyle = BorderStyle::SOLID; - ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); - - m_pEditCaret->Create(ecp); -} - -void CPWL_EditCtrl::SetFontSize(float fFontSize) { - m_pEdit->SetFontSize(fFontSize); -} - -float CPWL_EditCtrl::GetFontSize() const { - return m_pEdit->GetFontSize(); -} - -bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) { - if (m_bMouseDown) - return true; - - bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag); - - // FILTER - switch (nChar) { - default: - return false; - case FWL_VKEY_Delete: - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Left: - case FWL_VKEY_Right: - case FWL_VKEY_Home: - case FWL_VKEY_End: - case FWL_VKEY_Insert: - case 'C': - case 'V': - case 'X': - case 'A': - case 'Z': - case 'c': - case 'v': - case 'x': - case 'a': - case 'z': - break; - } - - if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected()) - nChar = FWL_VKEY_Unknown; - - switch (nChar) { - case FWL_VKEY_Delete: - Delete(); - return true; - case FWL_VKEY_Insert: - if (IsSHIFTpressed(nFlag)) - PasteText(); - return true; - case FWL_VKEY_Up: - m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false); - return true; - case FWL_VKEY_Down: - m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false); - return true; - case FWL_VKEY_Left: - m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false); - return true; - case FWL_VKEY_Right: - m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false); - return true; - case FWL_VKEY_Home: - m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - return true; - case FWL_VKEY_End: - m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - return true; - case FWL_VKEY_Unknown: - if (!IsSHIFTpressed(nFlag)) - Clear(); - else - CutText(); - return true; - default: - break; - } - - return bRet; -} - -bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { - if (m_bMouseDown) - return true; - - CPWL_Wnd::OnChar(nChar, nFlag); - - // FILTER - switch (nChar) { - case 0x0A: - case 0x1B: - return false; - default: - break; - } - - bool bCtrl = IsCTRLpressed(nFlag); - bool bAlt = IsALTpressed(nFlag); - bool bShift = IsSHIFTpressed(nFlag); - - uint16_t word = nChar; - - if (bCtrl && !bAlt) { - switch (nChar) { - case 'C' - 'A' + 1: - CopyText(); - return true; - case 'V' - 'A' + 1: - PasteText(); - return true; - case 'X' - 'A' + 1: - CutText(); - return true; - case 'A' - 'A' + 1: - SelectAll(); - return true; - case 'Z' - 'A' + 1: - if (bShift) - Redo(); - else - Undo(); - return true; - default: - if (nChar < 32) - return false; - } - } - - if (IsReadOnly()) - return true; - - if (m_pEdit->IsSelected() && word == FWL_VKEY_Back) - word = FWL_VKEY_Unknown; - - Clear(); - - switch (word) { - case FWL_VKEY_Back: - Backspace(); - break; - case FWL_VKEY_Return: - InsertReturn(); - break; - case FWL_VKEY_Unknown: - break; - default: - InsertWord(word, GetCharSet()); - break; - } - - return true; -} - -bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (ClientHitTest(point)) { - if (m_bMouseDown) - InvalidateRect(); - - m_bMouseDown = true; - SetCapture(); - - m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - } - - return true; -} - -bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (m_bMouseDown) { - // can receive keybord message - if (ClientHitTest(point) && !IsFocused()) - SetFocus(); - - ReleaseCapture(); - m_bMouseDown = false; - } - - return true; -} - -bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnMouseMove(point, nFlag); - - if (m_bMouseDown) - m_pEdit->OnMouseMove(point, false, false); - - return true; -} - -void CPWL_EditCtrl::SetEditCaret(bool bVisible) { - CFX_PointF ptHead; - CFX_PointF ptFoot; - if (bVisible) - GetCaretInfo(&ptHead, &ptFoot); - - CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); - IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); -} - -void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const { - CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); - pIterator->SetAt(m_pEdit->GetCaret()); - CPVT_Word word; - CPVT_Line line; - if (pIterator->GetWord(word)) { - ptHead->x = word.ptWord.x + word.fWidth; - ptHead->y = word.ptWord.y + word.fAscent; - ptFoot->x = word.ptWord.x + word.fWidth; - ptFoot->y = word.ptWord.y + word.fDescent; - } else if (pIterator->GetLine(line)) { - ptHead->x = line.ptLine.x; - ptHead->y = line.ptLine.y + line.fLineAscent; - ptFoot->x = line.ptLine.x; - ptFoot->y = line.ptLine.y + line.fLineDescent; - } -} - -void CPWL_EditCtrl::SetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot) { - if (m_pEditCaret) { - if (!IsFocused() || m_pEdit->IsSelected()) - bVisible = false; - - m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); - } -} - -CFX_WideString CPWL_EditCtrl::GetText() const { - return m_pEdit->GetText(); -} - -void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) { - m_pEdit->SetSel(nStartChar, nEndChar); -} - -void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { - m_pEdit->GetSel(nStartChar, nEndChar); -} - -void CPWL_EditCtrl::Clear() { - if (!IsReadOnly()) - m_pEdit->Clear(); -} - -void CPWL_EditCtrl::SelectAll() { - m_pEdit->SelectAll(); -} - -void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) { - m_pEdit->SetScrollPos(point); -} - -CFX_PointF CPWL_EditCtrl::GetScrollPos() const { - return m_pEdit->GetScrollPos(); -} - -void CPWL_EditCtrl::CopyText() {} - -void CPWL_EditCtrl::PasteText() {} - -void CPWL_EditCtrl::CutText() {} - -void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {} - -void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { - if (!IsReadOnly()) - m_pEdit->InsertWord(word, nCharset); -} - -void CPWL_EditCtrl::InsertReturn() { - if (!IsReadOnly()) - m_pEdit->InsertReturn(); -} - -void CPWL_EditCtrl::Delete() { - if (!IsReadOnly()) - m_pEdit->Delete(); -} - -void CPWL_EditCtrl::Backspace() { - if (!IsReadOnly()) - m_pEdit->Backspace(); -} - -bool CPWL_EditCtrl::CanUndo() const { - return !IsReadOnly() && m_pEdit->CanUndo(); -} - -bool CPWL_EditCtrl::CanRedo() const { - return !IsReadOnly() && m_pEdit->CanRedo(); -} - -void CPWL_EditCtrl::Redo() { - if (CanRedo()) - m_pEdit->Redo(); -} - -void CPWL_EditCtrl::Undo() { - if (CanUndo()) - m_pEdit->Undo(); -} - -void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin, - float fPlateMax, - float fContentMin, - float fContentMax, - float fSmallStep, - float fBigStep) { - PWL_SCROLL_INFO Info; - - Info.fPlateWidth = fPlateMax - fPlateMin; - Info.fContentMin = fContentMin; - Info.fContentMax = fContentMax; - Info.fSmallStep = fSmallStep; - Info.fBigStep = fBigStep; - - OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); - - if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || - IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { - ShowVScrollBar(false); - } else { - ShowVScrollBar(true); - } -} - -void CPWL_EditCtrl::IOnSetScrollPosY(float fy) { - OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); -} - -void CPWL_EditCtrl::IOnSetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot, - const CPVT_WordPlace& place) { - PWL_CARET_INFO cInfo; - cInfo.bVisible = bVisible; - cInfo.ptHead = ptHead; - cInfo.ptFoot = ptFoot; - - OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr); -} - -void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { - InvalidateRect(pRect); -} - -int32_t CPWL_EditCtrl::GetCharSet() const { - return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet; -} - -void CPWL_EditCtrl::SetReadyToInput() { - if (m_bMouseDown) { - ReleaseCapture(); - m_bMouseDown = false; - } -} diff --git a/fpdfsdk/pdfwindow/PWL_EditCtrl.h b/fpdfsdk/pdfwindow/PWL_EditCtrl.h deleted file mode 100644 index 623079b3d9..0000000000 --- a/fpdfsdk/pdfwindow/PWL_EditCtrl.h +++ /dev/null @@ -1,108 +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 FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ -#define FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ - -#include - -#include "core/fxcrt/fx_string.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CFX_Edit; -class CPWL_Caret; -struct CPVT_WordPlace; - -enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT }; - -enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM }; - -class CPWL_EditCtrl : public CPWL_Wnd { - public: - CPWL_EditCtrl(); - ~CPWL_EditCtrl() override; - - CFX_WideString GetText() const; - void SetSel(int32_t nStartChar, int32_t nEndChar); - void GetSel(int32_t& nStartChar, int32_t& nEndChar) const; - void Clear(); - void SelectAll(); - - CFX_PointF GetScrollPos() const; - void SetScrollPos(const CFX_PointF& point); - - void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; } - int32_t GetCharSet() const; - - bool CanUndo() const; - bool CanRedo() const; - void Redo(); - void Undo(); - - void SetReadyToInput(); - - // CPWL_Wnd - void OnCreate(PWL_CREATEPARAM& cp) override; - void OnCreated() override; - bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; - bool OnChar(uint16_t nChar, uint32_t nFlag) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; - void CreateChildWnd(const PWL_CREATEPARAM& cp) override; - void RePosChildWnd() override; - void SetFontSize(float fFontSize) override; - float GetFontSize() const override; - void SetCursor() override; - - void IOnSetScrollInfoY(float fPlateMin, - float fPlateMax, - float fContentMin, - float fContentMax, - float fSmallStep, - float fBigStep); - void IOnSetScrollPosY(float fy); - void IOnSetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot, - const CPVT_WordPlace& place); - void IOnInvalidateRect(CFX_FloatRect* pRect); - - protected: - void CopyText(); - void PasteText(); - void CutText(); - void ShowVScrollBar(bool bShow); - void InsertWord(uint16_t word, int32_t nCharset); - void InsertReturn(); - - bool IsWndHorV(); - - void Delete(); - void Backspace(); - - void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const; - void SetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot); - - void SetEditCaret(bool bVisible); - - std::unique_ptr m_pEdit; - CPWL_Caret* m_pEditCaret; - bool m_bMouseDown; - - private: - void CreateEditCaret(const PWL_CREATEPARAM& cp); - - int32_t m_nCharSet; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp deleted file mode 100644 index c981f18705..0000000000 --- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp +++ /dev/null @@ -1,413 +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 "fpdfsdk/pdfwindow/PWL_FontMap.h" - -#include - -#include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/cpdf_font.h" -#include "core/fpdfapi/font/cpdf_fontencoding.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/parser/cpdf_parser.h" -#include "core/fpdfdoc/ipvt_fontmap.h" -#include "core/fxcrt/fx_codepage.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" - -namespace { - -const char kDefaultFontName[] = "Helvetica"; - -const char* const g_sDEStandardFontName[] = {"Courier", - "Courier-Bold", - "Courier-BoldOblique", - "Courier-Oblique", - "Helvetica", - "Helvetica-Bold", - "Helvetica-BoldOblique", - "Helvetica-Oblique", - "Times-Roman", - "Times-Bold", - "Times-Italic", - "Times-BoldItalic", - "Symbol", - "ZapfDingbats"}; - -} // namespace - -CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler) - : m_pSystemHandler(pSystemHandler) { - ASSERT(m_pSystemHandler); -} - -CPWL_FontMap::~CPWL_FontMap() { - Empty(); -} - -CPDF_Document* CPWL_FontMap::GetDocument() { - if (!m_pPDFDoc) { - if (CPDF_ModuleMgr::Get()) { - m_pPDFDoc = pdfium::MakeUnique(nullptr); - m_pPDFDoc->CreateNewDoc(); - } - } - return m_pPDFDoc.get(); -} - -CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) { - if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex]) - return m_Data[nFontIndex]->pFont; - - return nullptr; -} - -CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) { - if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex]) - return m_Data[nFontIndex]->sFontName; - - return CFX_ByteString(); -} - -bool CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) { - return pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex] && - CharCodeFromUnicode(nFontIndex, word) >= 0; -} - -int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word, - int32_t nCharset, - int32_t nFontIndex) { - if (nFontIndex > 0) { - if (KnowWord(nFontIndex, word)) - return nFontIndex; - } else { - if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) { - if (nCharset == FX_CHARSET_Default || - pData->nCharset == FX_CHARSET_Symbol || nCharset == pData->nCharset) { - if (KnowWord(0, word)) - return 0; - } - } - } - - int32_t nNewFontIndex = - GetFontIndex(GetNativeFontName(nCharset), nCharset, true); - if (nNewFontIndex >= 0) { - if (KnowWord(nNewFontIndex, word)) - return nNewFontIndex; - } - nNewFontIndex = GetFontIndex("Arial Unicode MS", FX_CHARSET_Default, false); - if (nNewFontIndex >= 0) { - if (KnowWord(nNewFontIndex, word)) - return nNewFontIndex; - } - return -1; -} - -int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) { - if (!pdfium::IndexInBounds(m_Data, nFontIndex)) - return -1; - - CPWL_FontMap_Data* pData = m_Data[nFontIndex].get(); - if (!pData || !pData->pFont) - return -1; - - if (pData->pFont->IsUnicodeCompatible()) - return pData->pFont->CharCodeFromUnicode(word); - - return word < 0xFF ? word : -1; -} - -CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) { - for (const auto& pData : m_NativeFont) { - if (pData && pData->nCharset == nCharset) - return pData->sFontName; - } - - CFX_ByteString sNew = GetNativeFont(nCharset); - if (sNew.IsEmpty()) - return CFX_ByteString(); - - auto pNewData = pdfium::MakeUnique(); - pNewData->nCharset = nCharset; - pNewData->sFontName = sNew; - m_NativeFont.push_back(std::move(pNewData)); - return sNew; -} - -void CPWL_FontMap::Empty() { - m_Data.clear(); - m_NativeFont.clear(); -} - -void CPWL_FontMap::Initialize() { - GetFontIndex(kDefaultFontName, FX_CHARSET_ANSI, false); -} - -bool CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) { - for (size_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) { - if (sFontName == g_sDEStandardFontName[i]) - return true; - } - - return false; -} - -int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, - int32_t nCharset) { - int32_t i = 0; - for (const auto& pData : m_Data) { - if (pData && - (nCharset == FX_CHARSET_Default || nCharset == pData->nCharset) && - (sFontName.IsEmpty() || pData->sFontName == sFontName)) { - return i; - } - ++i; - } - return -1; -} - -int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, - int32_t nCharset, - bool bFind) { - int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset); - if (nFontIndex >= 0) - return nFontIndex; - - CFX_ByteString sAlias; - CPDF_Font* pFont = bFind ? FindFontSameCharset(&sAlias, nCharset) : nullptr; - if (!pFont) { - CFX_ByteString sTemp = sFontName; - pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); - sAlias = EncodeFontAlias(sTemp, nCharset); - } - AddedFont(pFont, sAlias); - return AddFontData(pFont, sAlias, nCharset); -} - -CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString* sFontAlias, - int32_t nCharset) { - return nullptr; -} - -int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont, - const CFX_ByteString& sFontAlias, - int32_t nCharset) { - auto pNewData = pdfium::MakeUnique(); - pNewData->pFont = pFont; - pNewData->sFontName = sFontAlias; - pNewData->nCharset = nCharset; - m_Data.push_back(std::move(pNewData)); - return pdfium::CollectionSize(m_Data) - 1; -} - -void CPWL_FontMap::AddedFont(CPDF_Font* pFont, - const CFX_ByteString& sFontAlias) {} - -CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { - if (nCharset == FX_CHARSET_Default) - nCharset = GetNativeCharset(); - - CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); - if (!m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) - return CFX_ByteString(); - - return sFontName; -} - -CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, - CFX_ByteString& sFontName, - uint8_t nCharset) { - if (IsStandardFont(sFontName)) - return AddStandardFont(pDoc, sFontName); - - return AddSystemFont(pDoc, sFontName, nCharset); -} - -CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, - CFX_ByteString& sFontName) { - if (!pDoc) - return nullptr; - - CPDF_Font* pFont = nullptr; - - if (sFontName == "ZapfDingbats") { - pFont = pDoc->AddStandardFont(sFontName.c_str(), nullptr); - } else { - CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI); - pFont = pDoc->AddStandardFont(sFontName.c_str(), &fe); - } - - return pFont; -} - -CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, - CFX_ByteString& sFontName, - uint8_t nCharset) { - if (!pDoc) - return nullptr; - - if (sFontName.IsEmpty()) - sFontName = GetNativeFont(nCharset); - if (nCharset == FX_CHARSET_Default) - nCharset = GetNativeCharset(); - - return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, - nCharset); -} - -CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, - int32_t nCharset) { - CFX_ByteString sPostfix; - sPostfix.Format("_%02X", nCharset); - return EncodeFontAlias(sFontName) + sPostfix; -} - -CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { - CFX_ByteString sRet = sFontName; - sRet.Remove(' '); - return sRet; -} - -const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const { - return pdfium::IndexInBounds(m_Data, nIndex) ? m_Data[nIndex].get() : nullptr; -} - -int32_t CPWL_FontMap::GetNativeCharset() { - uint8_t nCharset = FX_CHARSET_ANSI; - int32_t iCodePage = FXSYS_GetACP(); - switch (iCodePage) { - case FX_CODEPAGE_ShiftJIS: - nCharset = FX_CHARSET_ShiftJIS; - break; - case FX_CODEPAGE_ChineseSimplified: - nCharset = FX_CHARSET_ChineseSimplified; - break; - case FX_CODEPAGE_ChineseTraditional: - nCharset = FX_CHARSET_ChineseTraditional; - break; - case FX_CODEPAGE_MSWin_WesternEuropean: - nCharset = FX_CHARSET_ANSI; - break; - case FX_CODEPAGE_MSDOS_Thai: - nCharset = FX_CHARSET_Thai; - break; - case FX_CODEPAGE_Hangul: - nCharset = FX_CHARSET_Hangul; - break; - case FX_CODEPAGE_UTF16LE: - nCharset = FX_CHARSET_ANSI; - break; - case FX_CODEPAGE_MSWin_EasternEuropean: - nCharset = FX_CHARSET_MSWin_EasternEuropean; - break; - case FX_CODEPAGE_MSWin_Cyrillic: - nCharset = FX_CHARSET_MSWin_Cyrillic; - break; - case FX_CODEPAGE_MSWin_Greek: - nCharset = FX_CHARSET_MSWin_Greek; - break; - case FX_CODEPAGE_MSWin_Turkish: - nCharset = FX_CHARSET_MSWin_Turkish; - break; - case FX_CODEPAGE_MSWin_Hebrew: - nCharset = FX_CHARSET_MSWin_Hebrew; - break; - case FX_CODEPAGE_MSWin_Arabic: - nCharset = FX_CHARSET_MSWin_Arabic; - break; - case FX_CODEPAGE_MSWin_Baltic: - nCharset = FX_CHARSET_MSWin_Baltic; - break; - case FX_CODEPAGE_MSWin_Vietnamese: - nCharset = FX_CHARSET_MSWin_Vietnamese; - break; - case FX_CODEPAGE_Johab: - nCharset = FX_CHARSET_Johab; - break; - } - return nCharset; -} - -const FPDF_CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { - {FX_CHARSET_ANSI, "Helvetica"}, - {FX_CHARSET_ChineseSimplified, "SimSun"}, - {FX_CHARSET_ChineseTraditional, "MingLiU"}, - {FX_CHARSET_ShiftJIS, "MS Gothic"}, - {FX_CHARSET_Hangul, "Batang"}, - {FX_CHARSET_MSWin_Cyrillic, "Arial"}, -#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - {FX_CHARSET_MSWin_EasternEuropean, "Arial"}, -#else - {FX_CHARSET_MSWin_EasternEuropean, "Tahoma"}, -#endif - {FX_CHARSET_MSWin_Arabic, "Arial"}, - {-1, nullptr}}; - -CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { - int i = 0; - while (defaultTTFMap[i].charset != -1) { - if (nCharset == defaultTTFMap[i].charset) - return defaultTTFMap[i].fontname; - ++i; - } - return ""; -} - -int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) { - // to avoid CJK Font to show ASCII - if (word < 0x7F) - return FX_CHARSET_ANSI; - // follow the old charset - if (nOldCharset != FX_CHARSET_Default) - return nOldCharset; - - // find new charset - if ((word >= 0x4E00 && word <= 0x9FA5) || - (word >= 0xE7C7 && word <= 0xE7F3) || - (word >= 0x3000 && word <= 0x303F) || - (word >= 0x2000 && word <= 0x206F)) { - return FX_CHARSET_ChineseSimplified; - } - - if (((word >= 0x3040) && (word <= 0x309F)) || - ((word >= 0x30A0) && (word <= 0x30FF)) || - ((word >= 0x31F0) && (word <= 0x31FF)) || - ((word >= 0xFF00) && (word <= 0xFFEF))) { - return FX_CHARSET_ShiftJIS; - } - - if (((word >= 0xAC00) && (word <= 0xD7AF)) || - ((word >= 0x1100) && (word <= 0x11FF)) || - ((word >= 0x3130) && (word <= 0x318F))) { - return FX_CHARSET_Hangul; - } - - if (word >= 0x0E00 && word <= 0x0E7F) - return FX_CHARSET_Thai; - - if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF)) - return FX_CHARSET_MSWin_Greek; - - if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) - return FX_CHARSET_MSWin_Arabic; - - if (word >= 0x0590 && word <= 0x05FF) - return FX_CHARSET_MSWin_Hebrew; - - if (word >= 0x0400 && word <= 0x04FF) - return FX_CHARSET_MSWin_Cyrillic; - - if (word >= 0x0100 && word <= 0x024F) - return FX_CHARSET_MSWin_EasternEuropean; - - if (word >= 0x1E00 && word <= 0x1EFF) - return FX_CHARSET_MSWin_Vietnamese; - - return FX_CHARSET_ANSI; -} diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.h b/fpdfsdk/pdfwindow/PWL_FontMap.h deleted file mode 100644 index ca3ab231bd..0000000000 --- a/fpdfsdk/pdfwindow/PWL_FontMap.h +++ /dev/null @@ -1,96 +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 FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_ -#define FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_ - -#include -#include - -#include "core/fpdfdoc/ipvt_fontmap.h" -#include "core/fxcrt/fx_codepage.h" -#include "core/fxge/fx_font.h" -#include "fpdfsdk/fxedit/fx_edit.h" -#include "public/fpdf_sysfontinfo.h" - -class CPDF_Document; -class CFX_SystemHandler; - -struct CPWL_FontMap_Data { - CPDF_Font* pFont; - int32_t nCharset; - CFX_ByteString sFontName; -}; - -struct CPWL_FontMap_Native { - int32_t nCharset; - CFX_ByteString sFontName; -}; - -class CPWL_FontMap : public IPVT_FontMap { - public: - explicit CPWL_FontMap(CFX_SystemHandler* pSystemHandler); - ~CPWL_FontMap() override; - - // IPVT_FontMap - CPDF_Font* GetPDFFont(int32_t nFontIndex) override; - CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) override; - int32_t GetWordFontIndex(uint16_t word, - int32_t nCharset, - int32_t nFontIndex) override; - int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override; - int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override; - - const CPWL_FontMap_Data* GetFontMapData(int32_t nIndex) const; - static int32_t GetNativeCharset(); - CFX_ByteString GetNativeFontName(int32_t nCharset); - - static CFX_ByteString GetDefaultFontByCharset(int32_t nCharset); - static const FPDF_CharsetFontMap defaultTTFMap[]; - - protected: - virtual void Initialize(); - virtual CPDF_Document* GetDocument(); - virtual CPDF_Font* FindFontSameCharset(CFX_ByteString* sFontAlias, - int32_t nCharset); - virtual void AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias); - - bool KnowWord(int32_t nFontIndex, uint16_t word); - - void Empty(); - int32_t GetFontIndex(const CFX_ByteString& sFontName, - int32_t nCharset, - bool bFind); - int32_t AddFontData(CPDF_Font* pFont, - const CFX_ByteString& sFontAlias, - int32_t nCharset = FX_CHARSET_Default); - - CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName, - int32_t nCharset); - CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName); - - std::vector> m_Data; - std::vector> m_NativeFont; - - private: - int32_t FindFont(const CFX_ByteString& sFontName, - int32_t nCharset = FX_CHARSET_Default); - - CFX_ByteString GetNativeFont(int32_t nCharset); - CPDF_Font* AddFontToDocument(CPDF_Document* pDoc, - CFX_ByteString& sFontName, - uint8_t nCharset); - bool IsStandardFont(const CFX_ByteString& sFontName); - CPDF_Font* AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName); - CPDF_Font* AddSystemFont(CPDF_Document* pDoc, - CFX_ByteString& sFontName, - uint8_t nCharset); - - std::unique_ptr m_pPDFDoc; - CFX_UnownedPtr const m_pSystemHandler; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_ diff --git a/fpdfsdk/pdfwindow/PWL_Icon.cpp b/fpdfsdk/pdfwindow/PWL_Icon.cpp deleted file mode 100644 index e1397bff0c..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Icon.cpp +++ /dev/null @@ -1,225 +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 "fpdfsdk/pdfwindow/PWL_Icon.h" - -#include - -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_stream.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -CPWL_Image::CPWL_Image() : m_pPDFStream(nullptr) {} - -CPWL_Image::~CPWL_Image() {} - -CFX_ByteString CPWL_Image::GetImageAppStream() { - CFX_ByteTextBuf sAppStream; - - CFX_ByteString sAlias = GetImageAlias(); - CFX_FloatRect rcPlate = GetClientRect(); - CFX_Matrix mt; - mt.SetReverse(GetImageMatrix()); - - float fHScale = 1.0f; - float fVScale = 1.0f; - GetScale(fHScale, fVScale); - - float fx = 0.0f; - float fy = 0.0f; - GetImageOffset(fx, fy); - - if (m_pPDFStream && sAlias.GetLength() > 0) { - sAppStream << "q\n"; - sAppStream << rcPlate.left << " " << rcPlate.bottom << " " - << rcPlate.right - rcPlate.left << " " - << rcPlate.top - rcPlate.bottom << " re W n\n"; - - sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx - << " " << rcPlate.bottom + fy << " cm\n"; - sAppStream << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " " - << mt.e << " " << mt.f << " cm\n"; - - sAppStream << "0 g 0 G 1 w /" << sAlias.AsStringC() << " Do\n" - << "Q\n"; - } - - return sAppStream.MakeString(); -} - -void CPWL_Image::SetPDFStream(CPDF_Stream* pStream) { - m_pPDFStream = pStream; -} - -CPDF_Stream* CPWL_Image::GetPDFStream() const { - return m_pPDFStream.Get(); -} - -void CPWL_Image::GetImageSize(float& fWidth, float& fHeight) { - fWidth = 0.0f; - fHeight = 0.0f; - - if (m_pPDFStream) { - if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { - CFX_FloatRect rect = pDict->GetRectFor("BBox"); - - fWidth = rect.right - rect.left; - fHeight = rect.top - rect.bottom; - } - } -} - -CFX_Matrix CPWL_Image::GetImageMatrix() { - if (m_pPDFStream) { - if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { - return pDict->GetMatrixFor("Matrix"); - } - } - - return CFX_Matrix(); -} - -CFX_ByteString CPWL_Image::GetImageAlias() { - if (!m_sImageAlias.IsEmpty()) - return m_sImageAlias; - - if (m_pPDFStream) { - if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { - return pDict->GetStringFor("Name"); - } - } - - return CFX_ByteString(); -} - -void CPWL_Image::SetImageAlias(const char* sImageAlias) { - m_sImageAlias = sImageAlias; -} - -void CPWL_Image::GetScale(float& fHScale, float& fVScale) { - fHScale = 1.0f; - fVScale = 1.0f; -} - -void CPWL_Image::GetImageOffset(float& x, float& y) { - x = 0.0f; - y = 0.0f; -} - -CPWL_Icon::CPWL_Icon() : m_pIconFit(nullptr) {} - -CPWL_Icon::~CPWL_Icon() {} - -CPDF_IconFit* CPWL_Icon::GetIconFit() const { - return m_pIconFit.Get(); -} - -int32_t CPWL_Icon::GetScaleMethod() { - if (m_pIconFit) - return m_pIconFit->GetScaleMethod(); - - return 0; -} - -bool CPWL_Icon::IsProportionalScale() { - if (m_pIconFit) - return m_pIconFit->IsProportionalScale(); - - return false; -} - -void CPWL_Icon::GetIconPosition(float& fLeft, float& fBottom) { - if (m_pIconFit) { - fLeft = 0.0f; - fBottom = 0.0f; - CPDF_Array* pA = m_pIconFit->GetDict() - ? m_pIconFit->GetDict()->GetArrayFor("A") - : nullptr; - if (pA) { - size_t dwCount = pA->GetCount(); - if (dwCount > 0) - fLeft = pA->GetNumberAt(0); - if (dwCount > 1) - fBottom = pA->GetNumberAt(1); - } - } else { - fLeft = 0.0f; - fBottom = 0.0f; - } -} - -void CPWL_Icon::GetScale(float& fHScale, float& fVScale) { - fHScale = 1.0f; - fVScale = 1.0f; - - if (m_pPDFStream) { - float fImageWidth, fImageHeight; - float fPlateWidth, fPlateHeight; - - CFX_FloatRect rcPlate = GetClientRect(); - fPlateWidth = rcPlate.right - rcPlate.left; - fPlateHeight = rcPlate.top - rcPlate.bottom; - - GetImageSize(fImageWidth, fImageHeight); - - int32_t nScaleMethod = GetScaleMethod(); - - switch (nScaleMethod) { - default: - case 0: - fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); - fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); - break; - case 1: - if (fPlateWidth < fImageWidth) - fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); - if (fPlateHeight < fImageHeight) - fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); - break; - case 2: - if (fPlateWidth > fImageWidth) - fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); - if (fPlateHeight > fImageHeight) - fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); - break; - case 3: - break; - } - - float fMinScale; - if (IsProportionalScale()) { - fMinScale = std::min(fHScale, fVScale); - fHScale = fMinScale; - fVScale = fMinScale; - } - } -} - -void CPWL_Icon::GetImageOffset(float& x, float& y) { - float fLeft, fBottom; - - GetIconPosition(fLeft, fBottom); - x = 0.0f; - y = 0.0f; - - float fImageWidth, fImageHeight; - GetImageSize(fImageWidth, fImageHeight); - - float fHScale, fVScale; - GetScale(fHScale, fVScale); - - float fImageFactWidth = fImageWidth * fHScale; - float fImageFactHeight = fImageHeight * fVScale; - - float fPlateWidth, fPlateHeight; - CFX_FloatRect rcPlate = GetClientRect(); - fPlateWidth = rcPlate.right - rcPlate.left; - fPlateHeight = rcPlate.top - rcPlate.bottom; - - x = (fPlateWidth - fImageFactWidth) * fLeft; - y = (fPlateHeight - fImageFactHeight) * fBottom; -} diff --git a/fpdfsdk/pdfwindow/PWL_Icon.h b/fpdfsdk/pdfwindow/PWL_Icon.h deleted file mode 100644 index c5d116be69..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Icon.h +++ /dev/null @@ -1,58 +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 FPDFSDK_PDFWINDOW_PWL_ICON_H_ -#define FPDFSDK_PDFWINDOW_PWL_ICON_H_ - -#include "core/fxcrt/cfx_unowned_ptr.h" -#include "core/fxcrt/fx_string.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPWL_Image : public CPWL_Wnd { - public: - CPWL_Image(); - ~CPWL_Image() override; - - virtual CFX_ByteString GetImageAppStream(); - - virtual void GetScale(float& fHScale, float& fVScale); - virtual void GetImageOffset(float& x, float& y); - virtual CPDF_Stream* GetPDFStream() const; - - public: - void SetPDFStream(CPDF_Stream* pStream); - void GetImageSize(float& fWidth, float& fHeight); - CFX_Matrix GetImageMatrix(); - CFX_ByteString GetImageAlias(); - void SetImageAlias(const char* sImageAlias); - - protected: - CFX_UnownedPtr m_pPDFStream; - CFX_ByteString m_sImageAlias; -}; - -class CPWL_Icon : public CPWL_Image { - public: - CPWL_Icon(); - ~CPWL_Icon() override; - - virtual CPDF_IconFit* GetIconFit() const; - - // CPWL_Image - void GetScale(float& fHScale, float& fVScale) override; - void GetImageOffset(float& x, float& y) override; - - int32_t GetScaleMethod(); - bool IsProportionalScale(); - void GetIconPosition(float& fLeft, float& fBottom); - - void SetIconFit(CPDF_IconFit* pIconFit) { m_pIconFit = pIconFit; } - - private: - CFX_UnownedPtr m_pIconFit; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_ICON_H_ diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/pdfwindow/PWL_ListBox.cpp deleted file mode 100644 index 09487c3314..0000000000 --- a/fpdfsdk/pdfwindow/PWL_ListBox.cpp +++ /dev/null @@ -1,461 +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 "fpdfsdk/pdfwindow/PWL_ListBox.h" - -#include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/fxedit/fxet_list.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" -#include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" - -CPWL_List_Notify::CPWL_List_Notify(CPWL_ListBox* pList) : m_pList(pList) { - ASSERT(m_pList); -} - -CPWL_List_Notify::~CPWL_List_Notify() {} - -void CPWL_List_Notify::IOnSetScrollInfoY(float fPlateMin, - float fPlateMax, - float fContentMin, - float fContentMax, - float fSmallStep, - float fBigStep) { - PWL_SCROLL_INFO Info; - - Info.fPlateWidth = fPlateMax - fPlateMin; - Info.fContentMin = fContentMin; - Info.fContentMax = fContentMax; - Info.fSmallStep = fSmallStep; - Info.fBigStep = fBigStep; - - m_pList->OnNotify(m_pList.Get(), PNM_SETSCROLLINFO, SBT_VSCROLL, - reinterpret_cast(&Info)); - - if (CPWL_ScrollBar* pScroll = m_pList->GetVScrollBar()) { - if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || - IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { - if (pScroll->IsVisible()) { - pScroll->SetVisible(false); - m_pList->RePosChildWnd(); - } - } else { - if (!pScroll->IsVisible()) { - pScroll->SetVisible(true); - m_pList->RePosChildWnd(); - } - } - } -} - -void CPWL_List_Notify::IOnSetScrollPosY(float fy) { - m_pList->OnNotify(m_pList.Get(), PNM_SETSCROLLPOS, SBT_VSCROLL, - reinterpret_cast(&fy)); -} - -void CPWL_List_Notify::IOnInvalidateRect(CFX_FloatRect* pRect) { - m_pList->InvalidateRect(pRect); -} - -CPWL_ListBox::CPWL_ListBox() - : m_pList(new CFX_ListCtrl), - m_bMouseDown(false), - m_bHoverSel(false), - m_pFillerNotify(nullptr) {} - -CPWL_ListBox::~CPWL_ListBox() { -} - -CFX_ByteString CPWL_ListBox::GetClassName() const { - return "CPWL_ListBox"; -} - -void CPWL_ListBox::OnCreated() { - m_pList->SetFontMap(GetFontMap()); - m_pListNotify = pdfium::MakeUnique(this); - m_pList->SetNotify(m_pListNotify.get()); - - SetHoverSel(HasFlag(PLBS_HOVERSEL)); - m_pList->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL)); - m_pList->SetFontSize(GetCreationParam().fFontSize); - - m_bHoverSel = HasFlag(PLBS_HOVERSEL); -} - -void CPWL_ListBox::OnDestroy() { - // Make sure the notifier is removed from the list as we are about to - // destroy the notifier and don't want to leave a dangling pointer. - m_pList->SetNotify(nullptr); - m_pListNotify.reset(); -} - -void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - CFX_ByteTextBuf sListItems; - - CFX_FloatRect rcPlate = m_pList->GetPlateRect(); - for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { - CFX_FloatRect rcItem = m_pList->GetItemRect(i); - - if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) - continue; - - CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); - if (m_pList->IsItemSelected(i)) { - sListItems << CPWL_Utils::GetRectFillAppStream(rcItem, - PWL_DEFAULT_SELBACKCOLOR) - .AsStringC(); - CFX_ByteString sItem = - CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset); - if (sItem.GetLength() > 0) { - sListItems << "BT\n" - << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELTEXTCOLOR) - .AsStringC() - << sItem.AsStringC() << "ET\n"; - } - } else { - CFX_ByteString sItem = - CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset); - if (sItem.GetLength() > 0) { - sListItems << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sItem.AsStringC() << "ET\n"; - } - } - } - - if (sListItems.GetLength() > 0) { - CFX_ByteTextBuf sClip; - CFX_FloatRect rcClient = GetClientRect(); - - sClip << "q\n"; - sClip << rcClient.left << " " << rcClient.bottom << " " - << rcClient.right - rcClient.left << " " - << rcClient.top - rcClient.bottom << " re W n\n"; - - sClip << sListItems << "Q\n"; - - sAppStream << "/Tx BMC\n" << sClip << "EMC\n"; - } -} - -void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); - - CFX_FloatRect rcPlate = m_pList->GetPlateRect(); - CFX_FloatRect rcList = GetListRect(); - CFX_FloatRect rcClient = GetClientRect(); - - for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { - CFX_FloatRect rcItem = m_pList->GetItemRect(i); - if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) - continue; - - CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); - if (CFX_Edit* pEdit = m_pList->GetItemEdit(i)) { - CFX_FloatRect rcContent = pEdit->GetContentRect(); - if (rcContent.Width() > rcClient.Width()) - rcItem.Intersect(rcList); - else - rcItem.Intersect(rcClient); - } - - if (m_pList->IsItemSelected(i)) { - CFX_SystemHandler* pSysHandler = GetSystemHandler(); - if (pSysHandler && pSysHandler->IsSelectionImplemented()) { - CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), - GetTextColor().ToFXColor(255), rcList, ptOffset, - nullptr, pSysHandler, m_pFormFiller.Get()); - pSysHandler->OutputSelectedRect(m_pFormFiller.Get(), rcItem); - } else { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, - ArgbEncode(255, 0, 51, 113)); - CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), - ArgbEncode(255, 255, 255, 255), rcList, ptOffset, - nullptr, pSysHandler, m_pFormFiller.Get()); - } - } else { - CFX_SystemHandler* pSysHandler = GetSystemHandler(); - CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), - GetTextColor().ToFXColor(255), rcList, ptOffset, - nullptr, pSysHandler, nullptr); - } - } -} - -bool CPWL_ListBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { - CPWL_Wnd::OnKeyDown(nChar, nFlag); - - switch (nChar) { - default: - return false; - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_Left: - case FWL_VKEY_End: - case FWL_VKEY_Right: - break; - } - - switch (nChar) { - case FWL_VKEY_Up: - m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Down: - m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Home: - m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Left: - m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_End: - m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Right: - m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Delete: - break; - } - - bool bExit = false; - OnNotifySelChanged(true, bExit, nFlag); - - return true; -} - -bool CPWL_ListBox::OnChar(uint16_t nChar, uint32_t nFlag) { - CPWL_Wnd::OnChar(nChar, nFlag); - - if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) - return false; - - bool bExit = false; - OnNotifySelChanged(true, bExit, nFlag); - - return true; -} - -bool CPWL_ListBox::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (ClientHitTest(point)) { - m_bMouseDown = true; - SetFocus(); - SetCapture(); - - m_pList->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - } - - return true; -} - -bool CPWL_ListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (m_bMouseDown) { - ReleaseCapture(); - m_bMouseDown = false; - } - - bool bExit = false; - OnNotifySelChanged(false, bExit, nFlag); - - return true; -} - -void CPWL_ListBox::SetHoverSel(bool bHoverSel) { - m_bHoverSel = bHoverSel; -} - -bool CPWL_ListBox::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnMouseMove(point, nFlag); - - if (m_bHoverSel && !IsCaptureMouse() && ClientHitTest(point)) - m_pList->Select(m_pList->GetItemIndex(point)); - if (m_bMouseDown) - m_pList->OnMouseMove(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - - return true; -} - -void CPWL_ListBox::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); - - float fPos; - - switch (msg) { - case PNM_SETSCROLLINFO: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); - } - break; - } - break; - case PNM_SETSCROLLPOS: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); - } - break; - } - break; - case PNM_SCROLLWINDOW: - fPos = *(float*)lParam; - switch (wParam) { - case SBT_VSCROLL: - m_pList->SetScrollPos(CFX_PointF(0, fPos)); - break; - } - break; - } -} - -void CPWL_ListBox::KillFocus() { - CPWL_Wnd::KillFocus(); -} - -void CPWL_ListBox::RePosChildWnd() { - CPWL_Wnd::RePosChildWnd(); - - m_pList->SetPlateRect(GetListRect()); -} - -void CPWL_ListBox::OnNotifySelChanged(bool bKeyDown, - bool& bExit, - uint32_t nFlag) { - if (!m_pFillerNotify) - return; - - bool bRC = true; - CFX_WideString swChange = GetText(); - CFX_WideString strChangeEx; - int nSelStart = 0; - int nSelEnd = swChange.GetLength(); - m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, strChangeEx, - nSelStart, nSelEnd, bKeyDown, bRC, bExit, - nFlag); -} - -CFX_FloatRect CPWL_ListBox::GetFocusRect() const { - if (m_pList->IsMultipleSel()) { - CFX_FloatRect rcCaret = m_pList->GetItemRect(m_pList->GetCaret()); - rcCaret.Intersect(GetClientRect()); - return rcCaret; - } - - return CPWL_Wnd::GetFocusRect(); -} - -void CPWL_ListBox::AddString(const CFX_WideString& str) { - m_pList->AddString(str); -} - -CFX_WideString CPWL_ListBox::GetText() const { - return m_pList->GetText(); -} - -void CPWL_ListBox::SetFontSize(float fFontSize) { - m_pList->SetFontSize(fFontSize); -} - -float CPWL_ListBox::GetFontSize() const { - return m_pList->GetFontSize(); -} - -void CPWL_ListBox::Select(int32_t nItemIndex) { - m_pList->Select(nItemIndex); -} - -void CPWL_ListBox::SetCaret(int32_t nItemIndex) { - m_pList->SetCaret(nItemIndex); -} - -void CPWL_ListBox::SetTopVisibleIndex(int32_t nItemIndex) { - m_pList->SetTopItem(nItemIndex); -} - -void CPWL_ListBox::ScrollToListItem(int32_t nItemIndex) { - m_pList->ScrollToListItem(nItemIndex); -} - -void CPWL_ListBox::ResetContent() { - m_pList->Empty(); -} - -void CPWL_ListBox::Reset() { - m_pList->Cancel(); -} - -bool CPWL_ListBox::IsMultipleSel() const { - return m_pList->IsMultipleSel(); -} - -int32_t CPWL_ListBox::GetCaretIndex() const { - return m_pList->GetCaret(); -} - -int32_t CPWL_ListBox::GetCurSel() const { - return m_pList->GetSelect(); -} - -bool CPWL_ListBox::IsItemSelected(int32_t nItemIndex) const { - return m_pList->IsItemSelected(nItemIndex); -} - -int32_t CPWL_ListBox::GetTopVisibleIndex() const { - m_pList->ScrollToListItem(m_pList->GetFirstSelected()); - return m_pList->GetTopItem(); -} - -int32_t CPWL_ListBox::GetCount() const { - return m_pList->GetCount(); -} - -int32_t CPWL_ListBox::FindNext(int32_t nIndex, wchar_t nChar) const { - return m_pList->FindNext(nIndex, nChar); -} - -CFX_FloatRect CPWL_ListBox::GetContentRect() const { - return m_pList->GetContentRect(); -} - -float CPWL_ListBox::GetFirstHeight() const { - return m_pList->GetFirstHeight(); -} - -CFX_FloatRect CPWL_ListBox::GetListRect() const { - return CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); -} - -bool CPWL_ListBox::OnMouseWheel(short zDelta, - const CFX_PointF& point, - uint32_t nFlag) { - if (zDelta < 0) - m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - else - m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - - bool bExit = false; - OnNotifySelChanged(false, bExit, nFlag); - return true; -} diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.h b/fpdfsdk/pdfwindow/PWL_ListBox.h deleted file mode 100644 index 75d23bb7c6..0000000000 --- a/fpdfsdk/pdfwindow/PWL_ListBox.h +++ /dev/null @@ -1,118 +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 FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_ -#define FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_ - -#include - -#include "core/fxcrt/cfx_unowned_ptr.h" -#include "fpdfsdk/fxedit/fx_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CFX_ListCtrl; -class CPWL_List_Notify; -class CPWL_ListBox; -class IPWL_Filler_Notify; -struct CPVT_SecProps; -struct CPVT_WordPlace; -struct CPVT_WordProps; - -class CPWL_List_Notify { - public: - explicit CPWL_List_Notify(CPWL_ListBox* pList); - ~CPWL_List_Notify(); - - void IOnSetScrollInfoY(float fPlateMin, - float fPlateMax, - float fContentMin, - float fContentMax, - float fSmallStep, - float fBigStep); - void IOnSetScrollPosY(float fy); - void IOnInvalidateRect(CFX_FloatRect* pRect); - - void IOnSetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot, - const CPVT_WordPlace& place); - - private: - CFX_UnownedPtr m_pList; -}; - -class CPWL_ListBox : public CPWL_Wnd { - public: - CPWL_ListBox(); - ~CPWL_ListBox() override; - - // CPWL_Wnd - CFX_ByteString GetClassName() const override; - void OnCreated() override; - void OnDestroy() override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; - void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; - bool OnChar(uint16_t nChar, uint32_t nFlag) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; - bool OnMouseWheel(short zDelta, - const CFX_PointF& point, - uint32_t nFlag) override; - void KillFocus() override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; - void RePosChildWnd() override; - CFX_FloatRect GetFocusRect() const override; - void SetFontSize(float fFontSize) override; - float GetFontSize() const override; - - virtual CFX_WideString GetText() const; - - void OnNotifySelChanged(bool bKeyDown, bool& bExit, uint32_t nFlag); - - void AddString(const CFX_WideString& str); - void SetTopVisibleIndex(int32_t nItemIndex); - void ScrollToListItem(int32_t nItemIndex); - void ResetContent(); - void Reset(); - void Select(int32_t nItemIndex); - void SetCaret(int32_t nItemIndex); - void SetHoverSel(bool bHoverSel); - - int32_t GetCount() const; - bool IsMultipleSel() const; - int32_t GetCaretIndex() const; - int32_t GetCurSel() const; - bool IsItemSelected(int32_t nItemIndex) const; - int32_t GetTopVisibleIndex() const; - int32_t FindNext(int32_t nIndex, wchar_t nChar) const; - CFX_FloatRect GetContentRect() const; - float GetFirstHeight() const; - CFX_FloatRect GetListRect() const; - - void SetFillerNotify(IPWL_Filler_Notify* pNotify) { - m_pFillerNotify = pNotify; - } - - void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } - - protected: - std::unique_ptr m_pList; - std::unique_ptr m_pListNotify; - bool m_bMouseDown; - bool m_bHoverSel; - CFX_UnownedPtr m_pFillerNotify; - - private: - CFX_UnownedPtr m_pFormFiller; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_ diff --git a/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp b/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp deleted file mode 100644 index 36ee5c762f..0000000000 --- a/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp +++ /dev/null @@ -1,1186 +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 "fpdfsdk/pdfwindow/PWL_ScrollBar.h" - -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -PWL_FLOATRANGE::PWL_FLOATRANGE() { - Default(); -} - -PWL_FLOATRANGE::PWL_FLOATRANGE(float min, float max) { - Set(min, max); -} - -void PWL_FLOATRANGE::Default() { - fMin = 0; - fMax = 0; -} - -void PWL_FLOATRANGE::Set(float min, float max) { - if (min > max) { - fMin = max; - fMax = min; - } else { - fMin = min; - fMax = max; - } -} - -bool PWL_FLOATRANGE::In(float x) const { - return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) && - (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax)); -} - -float PWL_FLOATRANGE::GetWidth() const { - return fMax - fMin; -} - -PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() { - Default(); -} - -void PWL_SCROLL_PRIVATEDATA::Default() { - ScrollRange.Default(); - fScrollPos = ScrollRange.fMin; - fClientWidth = 0; - fBigStep = 10; - fSmallStep = 1; -} - -void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { - ScrollRange.Set(min, max); - - if (IsFloatSmaller(fScrollPos, ScrollRange.fMin)) - fScrollPos = ScrollRange.fMin; - if (IsFloatBigger(fScrollPos, ScrollRange.fMax)) - fScrollPos = ScrollRange.fMax; -} - -void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { - fClientWidth = width; -} - -void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) { - fSmallStep = step; -} - -void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) { - fBigStep = step; -} - -bool PWL_SCROLL_PRIVATEDATA::SetPos(float pos) { - if (ScrollRange.In(pos)) { - fScrollPos = pos; - return true; - } - return false; -} - -void PWL_SCROLL_PRIVATEDATA::AddSmall() { - if (!SetPos(fScrollPos + fSmallStep)) - SetPos(ScrollRange.fMax); -} - -void PWL_SCROLL_PRIVATEDATA::SubSmall() { - if (!SetPos(fScrollPos - fSmallStep)) - SetPos(ScrollRange.fMin); -} - -void PWL_SCROLL_PRIVATEDATA::AddBig() { - if (!SetPos(fScrollPos + fBigStep)) - SetPos(ScrollRange.fMax); -} - -void PWL_SCROLL_PRIVATEDATA::SubBig() { - if (!SetPos(fScrollPos - fBigStep)) - SetPos(ScrollRange.fMin); -} - -CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, - PWL_SBBUTTON_TYPE eButtonType) { - m_eScrollBarType = eScrollBarType; - m_eSBButtonType = eButtonType; - - m_bMouseDown = false; -} - -CPWL_SBButton::~CPWL_SBButton() {} - -CFX_ByteString CPWL_SBButton::GetClassName() const { - return "CPWL_SBButton"; -} - -void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) { - cp.eCursorType = FXCT_ARROW; -} - -void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - if (!IsVisible()) - return; - - CFX_ByteTextBuf sButton; - - CFX_FloatRect rectWnd = GetWindowRect(); - - if (rectWnd.IsEmpty()) - return; - - sAppStream << "q\n"; - - CFX_PointF ptCenter = GetCenterPoint(); - - switch (m_eScrollBarType) { - case SBT_HSCROLL: - switch (m_eSBButtonType) { - case PSBT_MIN: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - case PSBT_MAX: { - CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - default: - break; - } - break; - case SBT_VSCROLL: - switch (m_eSBButtonType) { - case PSBT_MIN: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, - ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, - ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - case PSBT_MAX: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, - ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, - ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - default: - break; - } - break; - default: - break; - } - - sAppStream << "Q\n"; -} - -void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - if (!IsVisible()) - return; - - CFX_FloatRect rectWnd = GetWindowRect(); - if (rectWnd.IsEmpty()) - return; - - CFX_PointF ptCenter = GetCenterPoint(); - int32_t nTransparency = GetTransparency(); - - switch (m_eScrollBarType) { - case SBT_HSCROLL: - CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); - switch (m_eSBButtonType) { - case PSBT_MIN: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - CFX_PathData path; - path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); - path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, - PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), - 0, FXFILL_ALTERNATE); - } - } break; - case PSBT_MAX: { - CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - CFX_PathData path; - path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); - path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, - PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), - 0, FXFILL_ALTERNATE); - } - } break; - default: - break; - } - break; - case SBT_VSCROLL: - switch (m_eSBButtonType) { - case PSBT_MIN: { - // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 100, 100, 100), - 0.0f); - - // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 255, 255, 255), - 1.0f); - - // draw background - - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); - - if (IsEnabled()) - CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, - nTransparency, 80, 220); - else - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(255, 255, 255, 255)); - - // draw arrow - - if (rectWnd.top - rectWnd.bottom > 6.0f) { - float fX = rectWnd.left + 1.5f; - float fY = rectWnd.bottom; - CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 4.0f), - CFX_PointF(fX + 2.5f, fY + 3.0f), - CFX_PointF(fX + 4.5f, fY + 5.0f), - CFX_PointF(fX + 6.5f, fY + 3.0f), - CFX_PointF(fX + 6.5f, fY + 4.0f), - CFX_PointF(fX + 4.5f, fY + 6.0f), - CFX_PointF(fX + 2.5f, fY + 4.0f)}; - - if (IsEnabled()) - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - ArgbEncode(nTransparency, 255, 255, 255)); - else - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); - } - } break; - case PSBT_MAX: { - // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 100, 100, 100), - 0.0f); - - // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 255, 255, 255), - 1.0f); - - // draw background - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); - if (IsEnabled()) - CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, - nTransparency, 80, 220); - else - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(255, 255, 255, 255)); - - // draw arrow - - if (rectWnd.top - rectWnd.bottom > 6.0f) { - float fX = rectWnd.left + 1.5f; - float fY = rectWnd.bottom; - - CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 5.0f), - CFX_PointF(fX + 2.5f, fY + 6.0f), - CFX_PointF(fX + 4.5f, fY + 4.0f), - CFX_PointF(fX + 6.5f, fY + 6.0f), - CFX_PointF(fX + 6.5f, fY + 5.0f), - CFX_PointF(fX + 4.5f, fY + 3.0f), - CFX_PointF(fX + 2.5f, fY + 5.0f)}; - - if (IsEnabled()) - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - ArgbEncode(nTransparency, 255, 255, 255)); - else - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); - } - } break; - case PSBT_POS: { - // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 100, 100, 100), - 0.0f); - - // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 255, 255, 255), - 1.0f); - - if (IsEnabled()) { - // draw shadow effect - - CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f); - CFX_PointF ptBottom = - CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f); - - ptTop.x += 1.5f; - ptBottom.x += 1.5f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 210, 210, 210), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 220, 220, 220), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 240, 240, 240), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 240, 240, 240), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 210, 210, 210), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 180, 180, 180), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 150, 150, 150), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 150, 150, 150), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 180, 180, 180), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 210, 210, 210), - 1.0f); - } else { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(255, 255, 255, 255)); - } - - // draw friction - - if (rectWnd.Height() > 8.0f) { - FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); - if (!IsEnabled()) - crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255); - - float nFrictionWidth = 5.0f; - float nFrictionHeight = 5.5f; - - CFX_PointF ptLeft = - CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f, - ptCenter.y - nFrictionHeight / 2.0f + 0.5f); - CFX_PointF ptRight = - CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f, - ptCenter.y - nFrictionHeight / 2.0f + 0.5f); - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, - crStroke, 1.0f); - - ptLeft.y += 2.0f; - ptRight.y += 2.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, - crStroke, 1.0f); - - ptLeft.y += 2.0f; - ptRight.y += 2.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, - crStroke, 1.0f); - } - } break; - default: - break; - } - break; - default: - break; - } -} - -bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (CPWL_Wnd* pParent = GetParentWindow()) - pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point); - - m_bMouseDown = true; - SetCapture(); - - return true; -} - -bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (CPWL_Wnd* pParent = GetParentWindow()) - pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point); - - m_bMouseDown = false; - ReleaseCapture(); - - return true; -} - -bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnMouseMove(point, nFlag); - - if (CPWL_Wnd* pParent = GetParentWindow()) { - pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point); - } - - return true; -} - -CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType) - : m_sbType(sbType), - m_pMinButton(nullptr), - m_pMaxButton(nullptr), - m_pPosButton(nullptr), - m_bMouseDown(false), - m_bMinOrMax(false), - m_bNotifyForever(true) {} - -CPWL_ScrollBar::~CPWL_ScrollBar() {} - -CFX_ByteString CPWL_ScrollBar::GetClassName() const { - return "CPWL_ScrollBar"; -} - -void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) { - cp.eCursorType = FXCT_ARROW; -} - -void CPWL_ScrollBar::OnDestroy() { - // Until cleanup takes place in the virtual destructor for CPWL_Wnd - // subclasses, implement the virtual OnDestroy method that does the - // cleanup first, then invokes the superclass OnDestroy ... gee, - // like a dtor would. - m_pMinButton.Release(); - m_pMaxButton.Release(); - m_pPosButton.Release(); - CPWL_Wnd::OnDestroy(); -} - -void CPWL_ScrollBar::RePosChildWnd() { - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcMinButton, rcMaxButton; - float fBWidth = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - if (rcClient.right - rcClient.left > - PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + - 2) { - rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, - rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.top); - rcMaxButton = - CFX_FloatRect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.bottom, rcClient.right, rcClient.top); - } else { - fBWidth = (rcClient.right - rcClient.left - - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / - 2; - - if (fBWidth > 0) { - rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, - rcClient.left + fBWidth, rcClient.top); - rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom, - rcClient.right, rcClient.top); - } else { - SetVisible(false); - } - } - break; - case SBT_VSCROLL: - if (IsFloatBigger(rcClient.top - rcClient.bottom, - PWL_SCROLLBAR_BUTTON_WIDTH * 2 + - PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)) { - rcMinButton = CFX_FloatRect(rcClient.left, - rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.right, rcClient.top); - rcMaxButton = - CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, - rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH); - } else { - fBWidth = (rcClient.top - rcClient.bottom - - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / - 2; - - if (IsFloatBigger(fBWidth, 0)) { - rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth, - rcClient.right, rcClient.top); - rcMaxButton = - CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, - rcClient.bottom + fBWidth); - } else { - SetVisible(false); - } - } - break; - } - - if (m_pMinButton) - m_pMinButton->Move(rcMinButton, true, false); - if (m_pMaxButton) - m_pMaxButton->Move(rcMaxButton, true, false); - MovePosButton(false); -} - -void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CFX_FloatRect rectWnd = GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CFX_ByteTextBuf sButton; - - sButton << "q\n"; - sButton << "0 w\n" - << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), true) - .AsStringC(); - sButton << rectWnd.left << " " << rectWnd.bottom << " " - << rectWnd.right - rectWnd.left << " " - << rectWnd.top - rectWnd.bottom << " re b Q\n"; - - sAppStream << sButton; - } -} - -void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CFX_FloatRect rectWnd = GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd, - GetBackgroundColor(), GetTransparency()); - - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, - CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f), - CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f), - ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); - - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, - CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f), - CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f), - ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); - } -} - -bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (HasFlag(PWS_AUTOTRANSPARENT)) { - if (GetTransparency() != 255) { - SetTransparency(255); - InvalidateRect(); - } - } - - CFX_FloatRect rcMinArea, rcMaxArea; - - if (m_pPosButton && m_pPosButton->IsVisible()) { - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); - - switch (m_sbType) { - case SBT_HSCROLL: - rcMinArea = - CFX_FloatRect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.bottom, rcPosButton.left, rcClient.top); - rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom, - rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.top); - - break; - case SBT_VSCROLL: - rcMinArea = - CFX_FloatRect(rcClient.left, rcPosButton.top, rcClient.right, - rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH); - rcMaxArea = CFX_FloatRect(rcClient.left, - rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.right, rcPosButton.bottom); - break; - } - - rcMinArea.Normalize(); - rcMaxArea.Normalize(); - - if (rcMinArea.Contains(point)) { - m_sData.SubBig(); - MovePosButton(true); - NotifyScrollWindow(); - } - - if (rcMaxArea.Contains(point)) { - m_sData.AddBig(); - MovePosButton(true); - NotifyScrollWindow(); - } - } - - return true; -} - -bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (HasFlag(PWS_AUTOTRANSPARENT)) { - if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) { - SetTransparency(PWL_SCROLLBAR_TRANSPARENCY); - InvalidateRect(); - } - } - - EndTimer(); - m_bMouseDown = false; - - return true; -} - -void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); - - switch (msg) { - case PNM_LBUTTONDOWN: - if (pWnd == m_pMinButton) { - OnMinButtonLBDown(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pMaxButton) { - OnMaxButtonLBDown(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pPosButton) { - OnPosButtonLBDown(*(CFX_PointF*)lParam); - } - break; - case PNM_LBUTTONUP: - if (pWnd == m_pMinButton) { - OnMinButtonLBUp(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pMaxButton) { - OnMaxButtonLBUp(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pPosButton) { - OnPosButtonLBUp(*(CFX_PointF*)lParam); - } - break; - case PNM_MOUSEMOVE: - if (pWnd == m_pMinButton) { - OnMinButtonMouseMove(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pMaxButton) { - OnMaxButtonMouseMove(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pPosButton) { - OnPosButtonMouseMove(*(CFX_PointF*)lParam); - } - break; - case PNM_SETSCROLLINFO: { - PWL_SCROLL_INFO* pInfo = reinterpret_cast(lParam); - if (pInfo && *pInfo != m_OriginInfo) { - m_OriginInfo = *pInfo; - float fMax = - pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth; - fMax = fMax > 0.0f ? fMax : 0.0f; - SetScrollRange(0, fMax, pInfo->fPlateWidth); - SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep); - } - } break; - case PNM_SETSCROLLPOS: { - float fPos = *(float*)lParam; - switch (m_sbType) { - case SBT_HSCROLL: - fPos = fPos - m_OriginInfo.fContentMin; - break; - case SBT_VSCROLL: - fPos = m_OriginInfo.fContentMax - fPos; - break; - } - SetScrollPos(fPos); - } break; - } -} - -void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) { - PWL_CREATEPARAM scp = cp; - scp.pParentWnd = this; - scp.dwBorderWidth = 2; - scp.nBorderStyle = BorderStyle::BEVELED; - - scp.dwFlags = - PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; - - if (!m_pMinButton) { - m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN); - m_pMinButton->Create(scp); - } - - if (!m_pMaxButton) { - m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX); - m_pMaxButton->Create(scp); - } - - if (!m_pPosButton) { - m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS); - m_pPosButton->SetVisible(false); - m_pPosButton->Create(scp); - } -} - -float CPWL_ScrollBar::GetScrollBarWidth() const { - if (!IsVisible()) - return 0; - - return PWL_SCROLLBAR_WIDTH; -} - -void CPWL_ScrollBar::SetScrollRange(float fMin, - float fMax, - float fClientWidth) { - if (m_pPosButton) { - m_sData.SetScrollRange(fMin, fMax); - m_sData.SetClientWidth(fClientWidth); - - if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) { - m_pPosButton->SetVisible(false); - } else { - m_pPosButton->SetVisible(true); - MovePosButton(true); - } - } -} - -void CPWL_ScrollBar::SetScrollPos(float fPos) { - float fOldPos = m_sData.fScrollPos; - - m_sData.SetPos(fPos); - - if (!IsFloatEqual(m_sData.fScrollPos, fOldPos)) - MovePosButton(true); -} - -void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) { - m_sData.SetBigStep(fBigStep); - m_sData.SetSmallStep(fSmallStep); -} - -void CPWL_ScrollBar::MovePosButton(bool bRefresh) { - ASSERT(m_pMinButton); - ASSERT(m_pMaxButton); - - if (m_pPosButton->IsVisible()) { - CFX_FloatRect rcClient; - CFX_FloatRect rcPosArea, rcPosButton; - - rcClient = GetClientRect(); - rcPosArea = GetScrollArea(); - - float fLeft, fRight, fTop, fBottom; - - switch (m_sbType) { - case SBT_HSCROLL: - fLeft = TrueToFace(m_sData.fScrollPos); - fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); - - if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH) - fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - - if (fRight > rcPosArea.right) { - fRight = rcPosArea.right; - fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - } - - rcPosButton = - CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top); - - break; - case SBT_VSCROLL: - fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); - fTop = TrueToFace(m_sData.fScrollPos); - - if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH)) - fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - - if (IsFloatSmaller(fBottom, rcPosArea.bottom)) { - fBottom = rcPosArea.bottom; - fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - } - - rcPosButton = - CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop); - - break; - } - - m_pPosButton->Move(rcPosButton, true, bRefresh); - } -} - -void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { - m_sData.SubSmall(); - MovePosButton(true); - NotifyScrollWindow(); - - m_bMinOrMax = true; - - EndTimer(); - BeginTimer(100); -} - -void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { - m_sData.AddSmall(); - MovePosButton(true); - NotifyScrollWindow(); - - m_bMinOrMax = false; - - EndTimer(); - BeginTimer(100); -} - -void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) { - m_bMouseDown = true; - - if (m_pPosButton) { - CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); - - switch (m_sbType) { - case SBT_HSCROLL: - m_nOldPos = point.x; - m_fOldPosButton = rcPosButton.left; - break; - case SBT_VSCROLL: - m_nOldPos = point.y; - m_fOldPosButton = rcPosButton.top; - break; - } - } -} - -void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) { - if (m_bMouseDown) { - if (!m_bNotifyForever) - NotifyScrollWindow(); - } - m_bMouseDown = false; -} - -void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) { - float fOldScrollPos = m_sData.fScrollPos; - - float fNewPos = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - if (fabs(point.x - m_nOldPos) < 1) - return; - fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos); - break; - case SBT_VSCROLL: - if (fabs(point.y - m_nOldPos) < 1) - return; - fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos); - break; - } - - if (m_bMouseDown) { - switch (m_sbType) { - case SBT_HSCROLL: - - if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { - fNewPos = m_sData.ScrollRange.fMin; - } - - if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { - fNewPos = m_sData.ScrollRange.fMax; - } - - m_sData.SetPos(fNewPos); - - break; - case SBT_VSCROLL: - - if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { - fNewPos = m_sData.ScrollRange.fMin; - } - - if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { - fNewPos = m_sData.ScrollRange.fMax; - } - - m_sData.SetPos(fNewPos); - - break; - } - - if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) { - MovePosButton(true); - - if (m_bNotifyForever) - NotifyScrollWindow(); - } - } -} - -void CPWL_ScrollBar::NotifyScrollWindow() { - if (CPWL_Wnd* pParent = GetParentWindow()) { - float fPos; - switch (m_sbType) { - case SBT_HSCROLL: - fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos; - break; - case SBT_VSCROLL: - fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos; - break; - } - pParent->OnNotify(this, PNM_SCROLLWINDOW, (intptr_t)m_sbType, - (intptr_t)&fPos); - } -} - -CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const { - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcArea; - - if (!m_pMinButton || !m_pMaxButton) - return rcClient; - - CFX_FloatRect rcMin = m_pMinButton->GetWindowRect(); - CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect(); - - float fMinWidth = rcMin.right - rcMin.left; - float fMinHeight = rcMin.top - rcMin.bottom; - float fMaxWidth = rcMax.right - rcMax.left; - float fMaxHeight = rcMax.top - rcMax.bottom; - - switch (m_sbType) { - case SBT_HSCROLL: - if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) { - rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, - rcClient.right - fMaxWidth - 1, rcClient.top); - } else { - rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, - rcClient.left + fMinWidth + 1, rcClient.top); - } - break; - case SBT_VSCROLL: - if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) { - rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, - rcClient.right, rcClient.top - fMaxHeight - 1); - } else { - rcArea = - CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, - rcClient.right, rcClient.bottom + fMinHeight + 1); - } - break; - } - - rcArea.Normalize(); - - return rcArea; -} - -float CPWL_ScrollBar::TrueToFace(float fTrue) { - CFX_FloatRect rcPosArea; - rcPosArea = GetScrollArea(); - - float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; - fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; - - float fFace = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - fFace = rcPosArea.left + - fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth; - break; - case SBT_VSCROLL: - fFace = rcPosArea.top - - fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth; - break; - } - - return fFace; -} - -float CPWL_ScrollBar::FaceToTrue(float fFace) { - CFX_FloatRect rcPosArea; - rcPosArea = GetScrollArea(); - - float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; - fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; - - float fTrue = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - fTrue = (fFace - rcPosArea.left) * fFactWidth / - (rcPosArea.right - rcPosArea.left); - break; - case SBT_VSCROLL: - fTrue = (rcPosArea.top - fFace) * fFactWidth / - (rcPosArea.top - rcPosArea.bottom); - break; - } - - return fTrue; -} - -void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) { - CreateButtons(cp); -} - -void CPWL_ScrollBar::TimerProc() { - PWL_SCROLL_PRIVATEDATA sTemp = m_sData; - if (m_bMinOrMax) - m_sData.SubSmall(); - else - m_sData.AddSmall(); - - if (sTemp != m_sData) { - MovePosButton(true); - NotifyScrollWindow(); - } -} diff --git a/fpdfsdk/pdfwindow/PWL_ScrollBar.h b/fpdfsdk/pdfwindow/PWL_ScrollBar.h deleted file mode 100644 index 165d0e022c..0000000000 --- a/fpdfsdk/pdfwindow/PWL_ScrollBar.h +++ /dev/null @@ -1,185 +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 FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_ -#define FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_ - -#include "core/fxcrt/cfx_unowned_ptr.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPWL_SBButton; -class CPWL_ScrollBar; - -struct PWL_SCROLL_INFO { - public: - PWL_SCROLL_INFO() - : fContentMin(0.0f), - fContentMax(0.0f), - fPlateWidth(0.0f), - fBigStep(0.0f), - fSmallStep(0.0f) {} - - bool operator==(const PWL_SCROLL_INFO& that) const { - return fContentMin == that.fContentMin && fContentMax == that.fContentMax && - fPlateWidth == that.fPlateWidth && fBigStep == that.fBigStep && - fSmallStep == that.fSmallStep; - } - bool operator!=(const PWL_SCROLL_INFO& that) const { - return !(*this == that); - } - - float fContentMin; - float fContentMax; - float fPlateWidth; - float fBigStep; - float fSmallStep; -}; - -enum PWL_SCROLLBAR_TYPE { SBT_HSCROLL, SBT_VSCROLL }; - -enum PWL_SBBUTTON_TYPE { PSBT_MIN, PSBT_MAX, PSBT_POS }; - -class CPWL_SBButton : public CPWL_Wnd { - public: - CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, - PWL_SBBUTTON_TYPE eButtonType); - ~CPWL_SBButton() override; - - // CPWL_Wnd - CFX_ByteString GetClassName() const override; - void OnCreate(PWL_CREATEPARAM& cp) override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; - void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; - - protected: - PWL_SCROLLBAR_TYPE m_eScrollBarType; - PWL_SBBUTTON_TYPE m_eSBButtonType; - - bool m_bMouseDown; -}; - -struct PWL_FLOATRANGE { - public: - PWL_FLOATRANGE(); - PWL_FLOATRANGE(float min, float max); - - bool operator==(const PWL_FLOATRANGE& that) const { - return fMin == that.fMin && fMax == that.fMax; - } - bool operator!=(const PWL_FLOATRANGE& that) const { return !(*this == that); } - - void Default(); - void Set(float min, float max); - bool In(float x) const; - float GetWidth() const; - - float fMin; - float fMax; -}; - -struct PWL_SCROLL_PRIVATEDATA { - public: - PWL_SCROLL_PRIVATEDATA(); - - bool operator==(const PWL_SCROLL_PRIVATEDATA& that) const { - return ScrollRange == that.ScrollRange && - fClientWidth == that.fClientWidth && fScrollPos == that.fScrollPos && - fBigStep == that.fBigStep && fSmallStep == that.fSmallStep; - } - bool operator!=(const PWL_SCROLL_PRIVATEDATA& that) const { - return !(*this == that); - } - - void Default(); - void SetScrollRange(float min, float max); - void SetClientWidth(float width); - void SetSmallStep(float step); - void SetBigStep(float step); - bool SetPos(float pos); - - void AddSmall(); - void SubSmall(); - void AddBig(); - void SubBig(); - - PWL_FLOATRANGE ScrollRange; - float fClientWidth; - float fScrollPos; - float fBigStep; - float fSmallStep; -}; - -class CPWL_ScrollBar : public CPWL_Wnd { - public: - explicit CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType = SBT_HSCROLL); - ~CPWL_ScrollBar() override; - - // CPWL_Wnd - CFX_ByteString GetClassName() const override; - void OnCreate(PWL_CREATEPARAM& cp) override; - void OnDestroy() override; - void RePosChildWnd() override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; - void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; - void CreateChildWnd(const PWL_CREATEPARAM& cp) override; - void TimerProc() override; - - float GetScrollBarWidth() const; - PWL_SCROLLBAR_TYPE GetScrollBarType() const { return m_sbType; } - - void SetNotifyForever(bool bForever) { m_bNotifyForever = bForever; } - - protected: - void SetScrollRange(float fMin, float fMax, float fClientWidth); - void SetScrollPos(float fPos); - void MovePosButton(bool bRefresh); - void SetScrollStep(float fBigStep, float fSmallStep); - void NotifyScrollWindow(); - CFX_FloatRect GetScrollArea() const; - - private: - void CreateButtons(const PWL_CREATEPARAM& cp); - - void OnMinButtonLBDown(const CFX_PointF& point); - void OnMinButtonLBUp(const CFX_PointF& point); - void OnMinButtonMouseMove(const CFX_PointF& point); - - void OnMaxButtonLBDown(const CFX_PointF& point); - void OnMaxButtonLBUp(const CFX_PointF& point); - void OnMaxButtonMouseMove(const CFX_PointF& point); - - void OnPosButtonLBDown(const CFX_PointF& point); - void OnPosButtonLBUp(const CFX_PointF& point); - void OnPosButtonMouseMove(const CFX_PointF& point); - - float TrueToFace(float); - float FaceToTrue(float); - - PWL_SCROLLBAR_TYPE m_sbType; - PWL_SCROLL_INFO m_OriginInfo; - CFX_UnownedPtr m_pMinButton; - CFX_UnownedPtr m_pMaxButton; - CFX_UnownedPtr m_pPosButton; - PWL_SCROLL_PRIVATEDATA m_sData; - bool m_bMouseDown; - bool m_bMinOrMax; - bool m_bNotifyForever; - float m_nOldPos; - float m_fOldPosButton; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_ diff --git a/fpdfsdk/pdfwindow/PWL_SpecialButton.cpp b/fpdfsdk/pdfwindow/PWL_SpecialButton.cpp deleted file mode 100644 index d2a13219d2..0000000000 --- a/fpdfsdk/pdfwindow/PWL_SpecialButton.cpp +++ /dev/null @@ -1,80 +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 "fpdfsdk/pdfwindow/PWL_Button.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -CPWL_PushButton::CPWL_PushButton() {} - -CPWL_PushButton::~CPWL_PushButton() {} - -CFX_ByteString CPWL_PushButton::GetClassName() const { - return "CPWL_PushButton"; -} - -CFX_FloatRect CPWL_PushButton::GetFocusRect() const { - return CPWL_Utils::DeflateRect(GetWindowRect(), (float)GetBorderWidth()); -} - -CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(false) {} - -CPWL_CheckBox::~CPWL_CheckBox() {} - -CFX_ByteString CPWL_CheckBox::GetClassName() const { - return "CPWL_CheckBox"; -} - -void CPWL_CheckBox::SetCheck(bool bCheck) { - m_bChecked = bCheck; -} - -bool CPWL_CheckBox::IsChecked() const { - return m_bChecked; -} - -bool CPWL_CheckBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - if (IsReadOnly()) - return false; - - SetCheck(!IsChecked()); - return true; -} - -bool CPWL_CheckBox::OnChar(uint16_t nChar, uint32_t nFlag) { - SetCheck(!IsChecked()); - return true; -} - -CPWL_RadioButton::CPWL_RadioButton() : m_bChecked(false) {} - -CPWL_RadioButton::~CPWL_RadioButton() {} - -CFX_ByteString CPWL_RadioButton::GetClassName() const { - return "CPWL_RadioButton"; -} - -bool CPWL_RadioButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - if (IsReadOnly()) - return false; - - SetCheck(true); - return true; -} - -void CPWL_RadioButton::SetCheck(bool bCheck) { - m_bChecked = bCheck; -} - -bool CPWL_RadioButton::IsChecked() const { - return m_bChecked; -} - -bool CPWL_RadioButton::OnChar(uint16_t nChar, uint32_t nFlag) { - SetCheck(true); - return true; -} diff --git a/fpdfsdk/pdfwindow/PWL_SpecialButton.h b/fpdfsdk/pdfwindow/PWL_SpecialButton.h deleted file mode 100644 index 93f611b744..0000000000 --- a/fpdfsdk/pdfwindow/PWL_SpecialButton.h +++ /dev/null @@ -1,56 +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 FPDFSDK_PDFWINDOW_PWL_SPECIALBUTTON_H_ -#define FPDFSDK_PDFWINDOW_PWL_SPECIALBUTTON_H_ - -#include "fpdfsdk/pdfwindow/PWL_Button.h" - -class CPWL_PushButton : public CPWL_Button { - public: - CPWL_PushButton(); - ~CPWL_PushButton() override; - - // CPWL_Button - CFX_ByteString GetClassName() const override; - CFX_FloatRect GetFocusRect() const override; -}; - -class CPWL_CheckBox : public CPWL_Button { - public: - CPWL_CheckBox(); - ~CPWL_CheckBox() override; - - // CPWL_Button - CFX_ByteString GetClassName() const override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnChar(uint16_t nChar, uint32_t nFlag) override; - - void SetCheck(bool bCheck); - bool IsChecked() const; - - private: - bool m_bChecked; -}; - -class CPWL_RadioButton : public CPWL_Button { - public: - CPWL_RadioButton(); - ~CPWL_RadioButton() override; - - // CPWL_Button - CFX_ByteString GetClassName() const override; - bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnChar(uint16_t nChar, uint32_t nFlag) override; - - void SetCheck(bool bCheck); - bool IsChecked() const; - - private: - bool m_bChecked; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_SPECIALBUTTON_H_ diff --git a/fpdfsdk/pdfwindow/PWL_Utils.cpp b/fpdfsdk/pdfwindow/PWL_Utils.cpp deleted file mode 100644 index dbac6ad8bc..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Utils.cpp +++ /dev/null @@ -1,1155 +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 "fpdfsdk/pdfwindow/PWL_Utils.h" - -#include -#include - -#include "core/fpdfdoc/cpvt_word.h" -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Icon.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -CFX_FloatRect CPWL_Utils::OffsetRect(const CFX_FloatRect& rect, - float x, - float y) { - return CFX_FloatRect(rect.left + x, rect.bottom + y, rect.right + x, - rect.top + y); -} - -CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange& wr1, - const CPVT_WordRange& wr2) { - if (wr2.EndPos < wr1.BeginPos || wr2.BeginPos > wr1.EndPos || - wr1.EndPos < wr2.BeginPos || wr1.BeginPos > wr2.EndPos) { - return CPVT_WordRange(); - } - - return CPVT_WordRange(std::max(wr1.BeginPos, wr2.BeginPos), - std::min(wr1.EndPos, wr2.EndPos)); -} - -CFX_ByteString CPWL_Utils::GetAP_Check(const CFX_FloatRect& crBBox) { - const float fWidth = crBBox.right - crBBox.left; - const float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pts[8][3] = {{CFX_PointF(0.28f, 0.52f), CFX_PointF(0.27f, 0.48f), - CFX_PointF(0.29f, 0.40f)}, - {CFX_PointF(0.30f, 0.33f), CFX_PointF(0.31f, 0.29f), - CFX_PointF(0.31f, 0.28f)}, - {CFX_PointF(0.39f, 0.28f), CFX_PointF(0.49f, 0.29f), - CFX_PointF(0.77f, 0.67f)}, - {CFX_PointF(0.76f, 0.68f), CFX_PointF(0.78f, 0.69f), - CFX_PointF(0.76f, 0.75f)}, - {CFX_PointF(0.76f, 0.75f), CFX_PointF(0.73f, 0.80f), - CFX_PointF(0.68f, 0.75f)}, - {CFX_PointF(0.68f, 0.74f), CFX_PointF(0.68f, 0.74f), - CFX_PointF(0.44f, 0.47f)}, - {CFX_PointF(0.43f, 0.47f), CFX_PointF(0.40f, 0.47f), - CFX_PointF(0.41f, 0.58f)}, - {CFX_PointF(0.40f, 0.60f), CFX_PointF(0.28f, 0.66f), - CFX_PointF(0.30f, 0.56f)}}; - - for (size_t i = 0; i < FX_ArraySize(pts); ++i) { - for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) { - pts[i][j].x = pts[i][j].x * fWidth + crBBox.left; - pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom; - } - } - - CFX_ByteTextBuf csAP; - csAP << pts[0][0].x << " " << pts[0][0].y << " m\n"; - - for (size_t i = 0; i < FX_ArraySize(pts); ++i) { - size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0; - - float px1 = pts[i][1].x - pts[i][0].x; - float py1 = pts[i][1].y - pts[i][0].y; - float px2 = pts[i][2].x - pts[nNext][0].x; - float py2 = pts[i][2].y - pts[nNext][0].y; - - csAP << pts[i][0].x + px1 * FX_BEZIER << " " - << pts[i][0].y + py1 * FX_BEZIER << " " - << pts[nNext][0].x + px2 * FX_BEZIER << " " - << pts[nNext][0].y + py2 * FX_BEZIER << " " << pts[nNext][0].x << " " - << pts[nNext][0].y << " c\n"; - } - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Circle(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - float fWidth = crBBox.right - crBBox.left; - float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); - CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); - CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); - CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); - - csAP << pt1.x << " " << pt1.y << " m\n"; - - float px = pt2.x - pt1.x; - float py = pt2.y - pt1.y; - - csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " - << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y - << " c\n"; - - px = pt3.x - pt2.x; - py = pt2.y - pt3.y; - - csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " - << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; - - px = pt3.x - pt4.x; - py = pt3.y - pt4.y; - - csAP << pt3.x << " " << pt3.y - py * FX_BEZIER << " " - << pt4.x + px * FX_BEZIER << " " << pt4.y << " " << pt4.x << " " << pt4.y - << " c\n"; - - px = pt4.x - pt1.x; - py = pt1.y - pt4.y; - - csAP << pt4.x - px * FX_BEZIER << " " << pt4.y << " " << pt1.x << " " - << pt1.y - py * FX_BEZIER << " " << pt1.x << " " << pt1.y << " c\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Cross(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - csAP << crBBox.left << " " << crBBox.top << " m\n"; - csAP << crBBox.right << " " << crBBox.bottom << " l\n"; - csAP << crBBox.left << " " << crBBox.bottom << " m\n"; - csAP << crBBox.right << " " << crBBox.top << " l\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Diamond(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - float fWidth = crBBox.right - crBBox.left; - float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); - CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); - CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); - CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); - - csAP << pt1.x << " " << pt1.y << " m\n"; - csAP << pt2.x << " " << pt2.y << " l\n"; - csAP << pt3.x << " " << pt3.y << " l\n"; - csAP << pt4.x << " " << pt4.y << " l\n"; - csAP << pt1.x << " " << pt1.y << " l\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Square(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - csAP << crBBox.left << " " << crBBox.top << " m\n"; - csAP << crBBox.right << " " << crBBox.top << " l\n"; - csAP << crBBox.right << " " << crBBox.bottom << " l\n"; - csAP << crBBox.left << " " << crBBox.bottom << " l\n"; - csAP << crBBox.left << " " << crBBox.top << " l\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Star(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - float fRadius = (crBBox.top - crBBox.bottom) / (1 + (float)cos(FX_PI / 5.0f)); - CFX_PointF ptCenter = CFX_PointF((crBBox.left + crBBox.right) / 2.0f, - (crBBox.top + crBBox.bottom) / 2.0f); - - float px[5], py[5]; - - float fAngel = FX_PI / 10.0f; - - for (int32_t i = 0; i < 5; i++) { - px[i] = ptCenter.x + fRadius * (float)cos(fAngel); - py[i] = ptCenter.y + fRadius * (float)sin(fAngel); - - fAngel += FX_PI * 2 / 5.0f; - } - - csAP << px[0] << " " << py[0] << " m\n"; - - int32_t nNext = 0; - for (int32_t j = 0; j < 5; j++) { - nNext += 2; - if (nNext >= 5) - nNext -= 5; - csAP << px[nNext] << " " << py[nNext] << " l\n"; - } - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CFX_FloatRect& crBBox, - float fRotate) { - CFX_ByteTextBuf csAP; - - float fWidth = crBBox.right - crBBox.left; - float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pt1(-fWidth / 2, 0); - CFX_PointF pt2(0, fHeight / 2); - CFX_PointF pt3(fWidth / 2, 0); - - float px, py; - - csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " " - << cos(fRotate) << " " << crBBox.left + fWidth / 2 << " " - << crBBox.bottom + fHeight / 2 << " cm\n"; - - csAP << pt1.x << " " << pt1.y << " m\n"; - - px = pt2.x - pt1.x; - py = pt2.y - pt1.y; - - csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " - << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y - << " c\n"; - - px = pt3.x - pt2.x; - py = pt2.y - pt3.y; - - csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " - << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; - - return csAP.MakeString(); -} - -CFX_FloatRect CPWL_Utils::InflateRect(const CFX_FloatRect& rcRect, - float fSize) { - if (rcRect.IsEmpty()) - return rcRect; - - CFX_FloatRect rcNew(rcRect.left - fSize, rcRect.bottom - fSize, - rcRect.right + fSize, rcRect.top + fSize); - rcNew.Normalize(); - return rcNew; -} - -CFX_FloatRect CPWL_Utils::DeflateRect(const CFX_FloatRect& rcRect, - float fSize) { - if (rcRect.IsEmpty()) - return rcRect; - - CFX_FloatRect rcNew(rcRect.left + fSize, rcRect.bottom + fSize, - rcRect.right - fSize, rcRect.top - fSize); - rcNew.Normalize(); - return rcNew; -} - -CFX_FloatRect CPWL_Utils::ScaleRect(const CFX_FloatRect& rcRect, float fScale) { - float fHalfWidth = (rcRect.right - rcRect.left) / 2.0f; - float fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f; - - CFX_PointF ptCenter = CFX_PointF((rcRect.left + rcRect.right) / 2, - (rcRect.top + rcRect.bottom) / 2); - - return CFX_FloatRect( - ptCenter.x - fHalfWidth * fScale, ptCenter.y - fHalfHeight * fScale, - ptCenter.x + fHalfWidth * fScale, ptCenter.y + fHalfHeight * fScale); -} - -CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor = GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << sColor; - sAppStream << rect.left << " " << rect.bottom << " " - << rect.right - rect.left << " " << rect.top - rect.bottom - << " re f\nQ\n"; - } - - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor = GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n"; - } - return sAppStream.MakeString(); -} - -CFX_FloatRect CPWL_Utils::GetCenterSquare(const CFX_FloatRect& rect) { - float fWidth = rect.right - rect.left; - float fHeight = rect.top - rect.bottom; - - float fCenterX = (rect.left + rect.right) / 2.0f; - float fCenterY = (rect.top + rect.bottom) / 2.0f; - - float fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2; - - return CFX_FloatRect(fCenterX - fRadius, fCenterY - fRadius, - fCenterX + fRadius, fCenterY + fRadius); -} - -CFX_ByteString CPWL_Utils::GetEditAppStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange, - bool bContinuous, - uint16_t SubWord) { - return CFX_Edit::GetEditAppearanceStream(pEdit, ptOffset, pRange, bContinuous, - SubWord); -} - -CFX_ByteString CPWL_Utils::GetEditSelAppStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange) { - return CFX_Edit::GetSelectAppearanceStream(pEdit, ptOffset, pRange); -} - -CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, - IPVT_FontMap* pFontMap, - CPDF_Stream* pIconStream, - CPDF_IconFit& IconFit, - const CFX_WideString& sLabel, - const CPWL_Color& crText, - float fFontSize, - int32_t nLayOut) { - const float fAutoFontScale = 1.0f / 3.0f; - - auto pEdit = pdfium::MakeUnique(); - pEdit->SetFontMap(pFontMap); - pEdit->SetAlignmentH(1, true); - pEdit->SetAlignmentV(1, true); - pEdit->SetMultiLine(false, true); - pEdit->SetAutoReturn(false, true); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(true, true); - else - pEdit->SetFontSize(fFontSize); - - pEdit->Initialize(); - pEdit->SetText(sLabel); - - CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); - CPWL_Icon Icon; - PWL_CREATEPARAM cp; - cp.dwFlags = PWS_VISIBLE; - Icon.Create(cp); - Icon.SetIconFit(&IconFit); - Icon.SetPDFStream(pIconStream); - - CFX_FloatRect rcLabel = CFX_FloatRect(0, 0, 0, 0); - CFX_FloatRect rcIcon = CFX_FloatRect(0, 0, 0, 0); - float fWidth = 0.0f; - float fHeight = 0.0f; - - switch (nLayOut) { - case PPBL_LABEL: - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - break; - case PPBL_ICON: - rcIcon = rcBBox; - rcLabel = CFX_FloatRect(0, 0, 0, 0); - break; - case PPBL_ICONTOPLABELBOTTOM: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fHeight = rcBBox.top - rcBBox.bottom; - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcBBox.bottom + fHeight * fAutoFontScale); - rcIcon = - CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top); - } else { - fHeight = rcLabelContent.Height(); - - if (rcBBox.bottom + fHeight > rcBBox.top) { - rcIcon = CFX_FloatRect(0, 0, 0, 0); - rcLabel = rcBBox; - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcBBox.bottom + fHeight); - rcIcon = CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, - rcBBox.top); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_LABELTOPICONBOTTOM: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fHeight = rcBBox.top - rcBBox.bottom; - rcLabel = - CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight * fAutoFontScale, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcLabel.bottom); - } else { - fHeight = rcLabelContent.Height(); - - if (rcBBox.bottom + fHeight > rcBBox.top) { - rcIcon = CFX_FloatRect(0, 0, 0, 0); - rcLabel = rcBBox; - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcLabel.bottom); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_ICONLEFTLABELRIGHT: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fWidth = rcBBox.right - rcBBox.left; - rcLabel = CFX_FloatRect(rcBBox.right - fWidth * fAutoFontScale, - rcBBox.bottom, rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - - if (rcLabelContent.Width() < fWidth * fAutoFontScale) { - } else { - if (rcLabelContent.Width() < fWidth) { - rcLabel = CFX_FloatRect(rcBBox.right - rcLabelContent.Width(), - rcBBox.bottom, rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - } - } else { - fWidth = rcLabelContent.Width(); - - if (rcBBox.left + fWidth > rcBBox.right) { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } else { - rcLabel = CFX_FloatRect(rcBBox.right - fWidth, rcBBox.bottom, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_LABELLEFTICONRIGHT: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fWidth = rcBBox.right - rcBBox.left; - rcLabel = - CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + fWidth * fAutoFontScale, rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, - rcBBox.top); - - if (rcLabelContent.Width() < fWidth * fAutoFontScale) { - } else { - if (rcLabelContent.Width() < fWidth) { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + rcLabelContent.Width(), - rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, - rcBBox.top); - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - } - } else { - fWidth = rcLabelContent.Width(); - - if (rcBBox.left + fWidth > rcBBox.right) { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + fWidth, rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, - rcBBox.top); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_LABELOVERICON: - rcLabel = rcBBox; - rcIcon = rcBBox; - break; - } - - CFX_ByteTextBuf sAppStream, sTemp; - - if (!rcIcon.IsEmpty()) { - Icon.Move(rcIcon, false, false); - sTemp << Icon.GetImageAppStream(); - } - - Icon.Destroy(); - - if (!rcLabel.IsEmpty()) { - pEdit->SetPlateRect(rcLabel); - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, 0.0f)); - if (sEdit.GetLength() > 0) { - sTemp << "BT\n" - << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; - } - } - - if (sTemp.GetSize() > 0) { - sAppStream << "q\n" - << rcBBox.left << " " << rcBBox.bottom << " " - << rcBBox.right - rcBBox.left << " " - << rcBBox.top - rcBBox.bottom << " re W n\n"; - sAppStream << sTemp << "Q\n"; - } - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color, - const bool& bFillOrStroke) { - CFX_ByteTextBuf sColorStream; - - switch (color.nColorType) { - case COLORTYPE_RGB: - sColorStream << color.fColor1 << " " << color.fColor2 << " " - << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") - << "\n"; - break; - case COLORTYPE_GRAY: - sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") - << "\n"; - break; - case COLORTYPE_CMYK: - sColorStream << color.fColor1 << " " << color.fColor2 << " " - << color.fColor3 << " " << color.fColor4 << " " - << (bFillOrStroke ? "k" : "K") << "\n"; - break; - } - - return sColorStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetBorderAppStream(const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor; - - float fLeft = rect.left; - float fRight = rect.right; - float fTop = rect.top; - float fBottom = rect.bottom; - - if (fWidth > 0.0f) { - float fHalfWidth = fWidth / 2.0f; - - sAppStream << "q\n"; - - switch (nStyle) { - default: - case BorderStyle::SOLID: - sColor = CPWL_Utils::GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " - << fTop - fBottom << " re\n"; - sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " " - << fRight - fLeft - fWidth * 2 << " " - << fTop - fBottom - fWidth * 2 << " re\n"; - sAppStream << "f*\n"; - } - break; - case BorderStyle::DASH: - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fWidth << " w" - << " [" << dash.nDash << " " << dash.nGap << "] " - << dash.nPhase << " d\n"; - sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 - << " m\n"; - sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 - << " l\n"; - sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 - << " l\n"; - sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 - << " l\n"; - sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 - << " l S\n"; - } - break; - case BorderStyle::BEVELED: - case BorderStyle::INSET: - sColor = CPWL_Utils::GetColorAppStream(crLeftTop, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth - << " m\n"; - sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth - << " l\n"; - sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth - << " l\n"; - sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 - << " l\n"; - sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 - << " l\n"; - sAppStream << fLeft + fHalfWidth * 2 << " " - << fBottom + fHalfWidth * 2 << " l f\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crRightBottom, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth - << " m\n"; - sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth - << " l\n"; - sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth - << " l\n"; - sAppStream << fLeft + fHalfWidth * 2 << " " - << fBottom + fHalfWidth * 2 << " l\n"; - sAppStream << fRight - fHalfWidth * 2 << " " - << fBottom + fHalfWidth * 2 << " l\n"; - sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 - << " l f\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " - << fTop - fBottom << " re\n"; - sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " " - << fRight - fLeft - fHalfWidth * 2 << " " - << fTop - fBottom - fHalfWidth * 2 << " re f*\n"; - } - break; - case BorderStyle::UNDERLINE: - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fWidth << " w\n"; - sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; - sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; - } - break; - } - - sAppStream << "Q\n"; - } - - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor; - - if (fWidth > 0.0f) { - sAppStream << "q\n"; - - switch (nStyle) { - default: - case BorderStyle::SOLID: - case BorderStyle::UNDERLINE: { - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fWidth << " w\n" << sColor - << CPWL_Utils::GetAP_Circle( - CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) - << " S\nQ\n"; - } - } break; - case BorderStyle::DASH: { - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fWidth << " w\n" - << "[" << dash.nDash << " " << dash.nGap << "] " - << dash.nPhase << " d\n" << sColor - << CPWL_Utils::GetAP_Circle( - CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) - << " S\nQ\n"; - } - } break; - case BorderStyle::BEVELED: { - float fHalfWidth = fWidth / 2.0f; - - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crLeftTop, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI / 4.0f) - << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crRightBottom, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI * 5 / 4.0f) - << " S\nQ\n"; - } - } break; - case BorderStyle::INSET: { - float fHalfWidth = fWidth / 2.0f; - - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crLeftTop, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI / 4.0f) - << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crRightBottom, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI * 5 / 4.0f) - << " S\nQ\n"; - } - } break; - } - - sAppStream << "Q\n"; - } - - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Check(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, false) - << CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n1 w\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Square(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Star(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText) { - CFX_FloatRect rcCenter = GetCenterSquare(rcBBox); - switch (nStyle) { - default: - case PCS_CHECK: - return GetAppStream_Check(rcCenter, crText); - case PCS_CIRCLE: - return GetAppStream_Circle(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_CROSS: - return GetAppStream_Cross(rcCenter, crText); - case PCS_DIAMOND: - return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_SQUARE: - return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_STAR: - return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - } -} - -CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText) { - CFX_FloatRect rcCenter = GetCenterSquare(rcBBox); - switch (nStyle) { - default: - case PCS_CHECK: - return GetAppStream_Check(rcCenter, crText); - case PCS_CIRCLE: - return GetAppStream_Circle(ScaleRect(rcCenter, 1.0f / 2.0f), crText); - case PCS_CROSS: - return GetAppStream_Cross(rcCenter, crText); - case PCS_DIAMOND: - return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_SQUARE: - return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_STAR: - return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - } -} - -CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { - CFX_ByteTextBuf sAppStream; - - if (!rcBBox.IsEmpty()) { - sAppStream << "q\n" - << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, - 220.0f / 255.0f, 220.0f / 255.0f), - true); - sAppStream << rcBBox.left << " " << rcBBox.bottom << " " - << rcBBox.right - rcBBox.left << " " - << rcBBox.top - rcBBox.bottom << " re f\n"; - sAppStream << "Q\n"; - - sAppStream << "q\n" - << CPWL_Utils::GetBorderAppStream( - rcBBox, 2, CPWL_Color(COLORTYPE_GRAY, 0), - CPWL_Color(COLORTYPE_GRAY, 1), - CPWL_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED, - CPWL_Dash(3, 0, 0)) - << "Q\n"; - - CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2, - (rcBBox.top + rcBBox.bottom) / 2); - if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) && - IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) { - sAppStream << "q\n" - << " 0 g\n"; - sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; - sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; - sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; - sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; - sAppStream << "Q\n"; - } - } - - return sAppStream.MakeString(); -} - -void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color) { - CFX_PathData path; - CFX_FloatRect rcTemp(rect); - path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); - pDevice->DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_WINDING); -} - -void CPWL_Utils::DrawFillArea(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF* pPts, - int32_t nCount, - const FX_COLORREF& color) { - CFX_PathData path; - path.AppendPoint(pPts[0], FXPT_TYPE::MoveTo, false); - for (int32_t i = 1; i < nCount; i++) - path.AppendPoint(pPts[i], FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_ALTERNATE); -} - -void CPWL_Utils::DrawStrokeRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color, - float fWidth) { - CFX_PathData path; - CFX_FloatRect rcTemp(rect); - path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = fWidth; - - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); -} - -void CPWL_Utils::DrawStrokeLine(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF& ptMoveTo, - const CFX_PointF& ptLineTo, - const FX_COLORREF& color, - float fWidth) { - CFX_PathData path; - path.AppendPoint(ptMoveTo, FXPT_TYPE::MoveTo, false); - path.AppendPoint(ptLineTo, FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = fWidth; - - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); -} - -void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const CPWL_Color& color, - int32_t nTransparency) { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rect, - color.ToFXColor(nTransparency)); -} - -void CPWL_Utils::DrawShadow(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - bool bVertical, - bool bHorizontal, - CFX_FloatRect rect, - int32_t nTransparency, - int32_t nStartGray, - int32_t nEndGray) { - float fStepGray = 1.0f; - - if (bVertical) { - fStepGray = (nEndGray - nStartGray) / rect.Height(); - - for (float fy = rect.bottom + 0.5f; fy <= rect.top - 0.5f; fy += 1.0f) { - int32_t nGray = nStartGray + (int32_t)(fStepGray * (fy - rect.bottom)); - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, CFX_PointF(rect.left, fy), - CFX_PointF(rect.right, fy), - ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); - } - } - - if (bHorizontal) { - fStepGray = (nEndGray - nStartGray) / rect.Width(); - - for (float fx = rect.left + 0.5f; fx <= rect.right - 0.5f; fx += 1.0f) { - int32_t nGray = nStartGray + (int32_t)(fStepGray * (fx - rect.left)); - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, CFX_PointF(fx, rect.bottom), - CFX_PointF(fx, rect.top), - ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); - } - } -} - -void CPWL_Utils::DrawBorder(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - int32_t nTransparency) { - float fLeft = rect.left; - float fRight = rect.right; - float fTop = rect.top; - float fBottom = rect.bottom; - - if (fWidth > 0.0f) { - float fHalfWidth = fWidth / 2.0f; - - switch (nStyle) { - default: - case BorderStyle::SOLID: { - CFX_PathData path; - path.AppendRect(fLeft, fBottom, fRight, fTop); - path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, - fTop - fWidth); - pDevice->DrawPath(&path, pUser2Device, nullptr, - color.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); - break; - } - case BorderStyle::DASH: { - CFX_PathData path; - path.AppendPoint( - CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), - FXPT_TYPE::MoveTo, false); - path.AppendPoint( - CFX_PointF(fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - path.AppendPoint( - CFX_PointF(fRight - fWidth / 2.0f, fTop - fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - path.AppendPoint( - CFX_PointF(fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - path.AppendPoint( - CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.SetDashCount(2); - gsd.m_DashArray[0] = 3.0f; - gsd.m_DashArray[1] = 3.0f; - gsd.m_DashPhase = 0; - - gsd.m_LineWidth = fWidth; - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - color.ToFXColor(nTransparency), FXFILL_WINDING); - break; - } - case BorderStyle::BEVELED: - case BorderStyle::INSET: { - CFX_GraphStateData gsd; - gsd.m_LineWidth = fHalfWidth; - - CFX_PathData pathLT; - - pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::MoveTo, false); - pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint( - CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint( - CFX_PointF(fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint( - CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&pathLT, pUser2Device, &gsd, - crLeftTop.ToFXColor(nTransparency), 0, - FXFILL_ALTERNATE); - - CFX_PathData pathRB; - pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::MoveTo, false); - pathRB.AppendPoint( - CFX_PointF(fRight - fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint( - CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint( - CFX_PointF(fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint( - CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&pathRB, pUser2Device, &gsd, - crRightBottom.ToFXColor(nTransparency), 0, - FXFILL_ALTERNATE); - - CFX_PathData path; - - path.AppendRect(fLeft, fBottom, fRight, fTop); - path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, - fRight - fHalfWidth, fTop - fHalfWidth); - - pDevice->DrawPath(&path, pUser2Device, &gsd, - color.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); - break; - } - case BorderStyle::UNDERLINE: { - CFX_PathData path; - path.AppendPoint(CFX_PointF(fLeft, fBottom + fWidth / 2), - FXPT_TYPE::MoveTo, false); - path.AppendPoint(CFX_PointF(fRight, fBottom + fWidth / 2), - FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = fWidth; - - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - color.ToFXColor(nTransparency), FXFILL_ALTERNATE); - break; - } - } - } -} - diff --git a/fpdfsdk/pdfwindow/PWL_Utils.h b/fpdfsdk/pdfwindow/PWL_Utils.h deleted file mode 100644 index 29fe239635..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Utils.h +++ /dev/null @@ -1,162 +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 FPDFSDK_PDFWINDOW_PWL_UTILS_H_ -#define FPDFSDK_PDFWINDOW_PWL_UTILS_H_ - -#include "core/fpdfdoc/cpvt_wordrange.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CFX_Edit; -struct CPWL_Color; - -#define PWL_MAKEDWORD(low, high) \ - ((uint32_t)((uint16_t)(low) | (uint32_t)(((uint16_t)(high)) << 16))) - -// checkbox & radiobutton style -#define PCS_CHECK 0 -#define PCS_CIRCLE 1 -#define PCS_CROSS 2 -#define PCS_DIAMOND 3 -#define PCS_SQUARE 4 -#define PCS_STAR 5 - -// pushbutton layout style -#define PPBL_LABEL 0 -#define PPBL_ICON 1 -#define PPBL_ICONTOPLABELBOTTOM 2 -#define PPBL_LABELTOPICONBOTTOM 3 -#define PPBL_ICONLEFTLABELRIGHT 4 -#define PPBL_LABELLEFTICONRIGHT 5 -#define PPBL_LABELOVERICON 6 - -class CPWL_Utils { - public: - static CFX_FloatRect InflateRect(const CFX_FloatRect& rcRect, float fSize); - static CFX_FloatRect DeflateRect(const CFX_FloatRect& rcRect, float fSize); - - static CPVT_WordRange OverlapWordRange(const CPVT_WordRange& wr1, - const CPVT_WordRange& wr2); - static CFX_FloatRect GetCenterSquare(const CFX_FloatRect& rect); - - static CFX_FloatRect OffsetRect(const CFX_FloatRect& rect, float x, float y); - - static CFX_ByteString GetColorAppStream(const CPWL_Color& color, - const bool& bFillOrStroke = true); - static CFX_ByteString GetBorderAppStream(const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash); - static CFX_ByteString GetCircleBorderAppStream( - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash); - static CFX_ByteString GetRectFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color); - static CFX_ByteString GetCircleFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color); - static CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox, - IPVT_FontMap* pFontMap, - CPDF_Stream* pIconStream, - CPDF_IconFit& IconFit, - const CFX_WideString& sLabel, - const CPWL_Color& crText, - float fFontSize, - int32_t nLayOut); - static CFX_ByteString GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText); - static CFX_ByteString GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText); - static CFX_ByteString GetEditAppStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange = nullptr, - bool bContinuous = true, - uint16_t SubWord = 0); - static CFX_ByteString GetEditSelAppStream( - CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange = nullptr); - static CFX_ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox); - - static void DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const CPWL_Color& color, - int32_t nTransparency); - static void DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color); - static void DrawStrokeRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color, - float fWidth); - static void DrawStrokeLine(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF& ptMoveTo, - const CFX_PointF& ptLineTo, - const FX_COLORREF& color, - float fWidth); - static void DrawBorder(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - int32_t nTransparency); - static void DrawFillArea(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF* pPts, - int32_t nCount, - const FX_COLORREF& color); - static void DrawShadow(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - bool bVertical, - bool bHorizontal, - CFX_FloatRect rect, - int32_t nTransparency, - int32_t nStartGray, - int32_t nEndGray); - - private: - static CFX_FloatRect ScaleRect(const CFX_FloatRect& rcRect, float fScale); - - static CFX_ByteString GetAppStream_Check(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Circle(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Cross(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Diamond(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Square(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Star(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - - static CFX_ByteString GetAP_Check(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Circle(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Cross(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Diamond(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Square(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Star(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_HalfCircle(const CFX_FloatRect& crBBox, - float fRotate); -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_UTILS_H_ diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.cpp b/fpdfsdk/pdfwindow/PWL_Wnd.cpp deleted file mode 100644 index 151921bc8e..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Wnd.cpp +++ /dev/null @@ -1,830 +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 "fpdfsdk/pdfwindow/PWL_Wnd.h" - -#include -#include - -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" - -PWL_CREATEPARAM::PWL_CREATEPARAM() - : rcRectWnd(0, 0, 0, 0), - pSystemHandler(nullptr), - pFontMap(nullptr), - pProvider(nullptr), - pFocusHandler(nullptr), - dwFlags(0), - sBackgroundColor(), - pAttachedWidget(nullptr), - nBorderStyle(BorderStyle::SOLID), - dwBorderWidth(1), - sBorderColor(), - sTextColor(), - nTransparency(255), - fFontSize(PWL_DEFAULT_FONTSIZE), - sDash(3, 0, 0), - pAttachedData(nullptr), - pParentWnd(nullptr), - pMsgControl(nullptr), - eCursorType(FXCT_ARROW) {} - -PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default; - -class CPWL_MsgControl { - friend class CPWL_Wnd; - - public: - explicit CPWL_MsgControl(CPWL_Wnd* pWnd) { - m_pCreatedWnd = pWnd; - Default(); - } - - ~CPWL_MsgControl() { Default(); } - - void Default() { - m_aMousePath.clear(); - m_aKeyboardPath.clear(); - m_pMainMouseWnd = nullptr; - m_pMainKeyboardWnd = nullptr; - } - - bool IsWndCreated(const CPWL_Wnd* pWnd) const { - return m_pCreatedWnd == pWnd; - } - - bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const { - return pWnd == m_pMainMouseWnd; - } - - bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { - return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd); - } - - bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const { - return pWnd == m_pMainKeyboardWnd; - } - - bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { - return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd); - } - - void SetFocus(CPWL_Wnd* pWnd) { - m_aKeyboardPath.clear(); - if (pWnd) { - m_pMainKeyboardWnd = pWnd; - CPWL_Wnd* pParent = pWnd; - while (pParent) { - m_aKeyboardPath.push_back(pParent); - pParent = pParent->GetParentWindow(); - } - pWnd->OnSetFocus(); - } - } - - void KillFocus() { - if (!m_aKeyboardPath.empty()) - if (CPWL_Wnd* pWnd = m_aKeyboardPath[0]) - pWnd->OnKillFocus(); - - m_pMainKeyboardWnd = nullptr; - m_aKeyboardPath.clear(); - } - - void SetCapture(CPWL_Wnd* pWnd) { - m_aMousePath.clear(); - if (pWnd) { - m_pMainMouseWnd = pWnd; - CPWL_Wnd* pParent = pWnd; - while (pParent) { - m_aMousePath.push_back(pParent); - pParent = pParent->GetParentWindow(); - } - } - } - - void ReleaseCapture() { - m_pMainMouseWnd = nullptr; - m_aMousePath.clear(); - } - - private: - std::vector m_aMousePath; - std::vector m_aKeyboardPath; - CFX_UnownedPtr m_pCreatedWnd; - CFX_UnownedPtr m_pMainMouseWnd; - CFX_UnownedPtr m_pMainKeyboardWnd; -}; - -CPWL_Wnd::CPWL_Wnd() - : m_rcWindow(), - m_rcClip(), - m_bCreated(false), - m_bVisible(false), - m_bNotifying(false), - m_bEnabled(true) {} - -CPWL_Wnd::~CPWL_Wnd() { - ASSERT(!m_bCreated); -} - -CFX_ByteString CPWL_Wnd::GetClassName() const { - return "CPWL_Wnd"; -} - -void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { - if (IsValid()) - return; - - m_sPrivateParam = cp; - OnCreate(m_sPrivateParam); - - m_sPrivateParam.rcRectWnd.Normalize(); - m_rcWindow = m_sPrivateParam.rcRectWnd; - m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f); - CreateMsgControl(); - - if (m_sPrivateParam.pParentWnd) - m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD); - - PWL_CREATEPARAM ccp = m_sPrivateParam; - - ccp.dwFlags &= 0xFFFF0000L; // remove sub styles - CreateScrollBar(ccp); - CreateChildWnd(ccp); - - m_bVisible = HasFlag(PWS_VISIBLE); - OnCreated(); - - RePosChildWnd(); - m_bCreated = true; -} - -void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} - -void CPWL_Wnd::OnCreated() {} - -void CPWL_Wnd::OnDestroy() {} - -void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) { - if (m_sPrivateParam.pFocusHandler == handler) - m_sPrivateParam.pFocusHandler = nullptr; -} - -void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) { - if (m_sPrivateParam.pProvider.Get() == provider) - m_sPrivateParam.pProvider.Reset(); -} - -void CPWL_Wnd::Destroy() { - KillFocus(); - OnDestroy(); - if (m_bCreated) { - for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { - if (CPWL_Wnd* pChild = *it) { - *it = nullptr; - pChild->Destroy(); - delete pChild; - } - } - if (m_sPrivateParam.pParentWnd) - m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD); - - m_bCreated = false; - } - DestroyMsgControl(); - m_sPrivateParam.Reset(); - m_Children.clear(); - m_pVScrollBar = nullptr; -} - -void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) { - if (!IsValid()) - return; - - CFX_FloatRect rcOld = GetWindowRect(); - m_rcWindow = rcNew; - m_rcWindow.Normalize(); - - if (bReset) { - if (rcOld.left != rcNew.left || rcOld.right != rcNew.right || - rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) { - RePosChildWnd(); - } - } - if (bRefresh) - InvalidateRectMove(rcOld, rcNew); - - m_sPrivateParam.rcRectWnd = m_rcWindow; -} - -void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, - const CFX_FloatRect& rcNew) { - CFX_FloatRect rcUnion = rcOld; - rcUnion.Union(rcNew); - - InvalidateRect(&rcUnion); -} - -void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) { - if (IsValid() && IsVisible()) { - GetThisAppearanceStream(sAppStream); - GetChildAppearanceStream(sAppStream); - } -} - -// if don't set,Get default apperance stream -void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CFX_FloatRect rectWnd = GetWindowRect(); - if (rectWnd.IsEmpty()) - return; - - CFX_ByteTextBuf sThis; - - if (HasFlag(PWS_BACKGROUND)) - sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor()); - - if (HasFlag(PWS_BORDER)) { - sThis << CPWL_Utils::GetBorderAppStream( - rectWnd, (float)GetBorderWidth(), GetBorderColor(), - GetBorderLeftTopColor(GetBorderStyle()), - GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), - GetBorderDash()); - } - - sAppStream << sThis; -} - -void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) { - for (CPWL_Wnd* pChild : m_Children) { - if (pChild) - pChild->GetAppearanceStream(sAppStream); - } -} - -void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - if (IsValid() && IsVisible()) { - DrawThisAppearance(pDevice, pUser2Device); - DrawChildAppearance(pDevice, pUser2Device); - } -} - -void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CFX_FloatRect rectWnd = GetWindowRect(); - if (rectWnd.IsEmpty()) - return; - - if (HasFlag(PWS_BACKGROUND)) { - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth())); - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, - GetBackgroundColor(), GetTransparency()); - } - - if (HasFlag(PWS_BORDER)) { - CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd, - (float)GetBorderWidth(), GetBorderColor(), - GetBorderLeftTopColor(GetBorderStyle()), - GetBorderRightBottomColor(GetBorderStyle()), - GetBorderStyle(), GetTransparency()); - } -} - -void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - for (CPWL_Wnd* pChild : m_Children) { - if (!pChild) - continue; - - CFX_Matrix mt = pChild->GetChildMatrix(); - if (mt.IsIdentity()) { - pChild->DrawAppearance(pDevice, pUser2Device); - } else { - mt.Concat(*pUser2Device); - pChild->DrawAppearance(pDevice, &mt); - } - } -} - -void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { - if (!IsValid()) - return; - - CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); - - if (!HasFlag(PWS_NOREFRESHCLIP)) { - CFX_FloatRect rcClip = GetClipRect(); - if (!rcClip.IsEmpty()) { - rcRefresh.Intersect(rcClip); - } - } - - FX_RECT rcWin = PWLtoWnd(rcRefresh); - rcWin.left -= PWL_INVALIDATE_INFLATE; - rcWin.top -= PWL_INVALIDATE_INFLATE; - rcWin.right += PWL_INVALIDATE_INFLATE; - rcWin.bottom += PWL_INVALIDATE_INFLATE; - - if (CFX_SystemHandler* pSH = GetSystemHandler()) { - if (CPDFSDK_Widget* widget = static_cast( - m_sPrivateParam.pAttachedWidget.Get())) { - pSH->InvalidateRect(widget, rcWin); - } - } -} - -#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ - bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \ - if (!IsValid() || !IsVisible() || !IsEnabled()) \ - return false; \ - if (!IsWndCaptureKeyboard(this)) \ - return false; \ - for (auto* pChild : m_Children) { \ - if (pChild && IsWndCaptureKeyboard(pChild)) \ - return pChild->key_method_name(nChar, nFlag); \ - } \ - return false; \ - } - -PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) -PWL_IMPLEMENT_KEY_METHOD(OnChar) -#undef PWL_IMPLEMENT_KEY_METHOD - -#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ - bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \ - if (!IsValid() || !IsVisible() || !IsEnabled()) \ - return false; \ - if (IsWndCaptureMouse(this)) { \ - for (auto* pChild : m_Children) { \ - if (pChild && IsWndCaptureMouse(pChild)) { \ - return pChild->mouse_method_name(pChild->ParentToChild(point), \ - nFlag); \ - } \ - } \ - SetCursor(); \ - return false; \ - } \ - for (auto* pChild : m_Children) { \ - if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \ - return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \ - } \ - } \ - if (WndHitTest(point)) \ - SetCursor(); \ - return false; \ - } - -PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk) -PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown) -PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp) -PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown) -PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) -PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) -#undef PWL_IMPLEMENT_MOUSE_METHOD - -bool CPWL_Wnd::OnMouseWheel(short zDelta, - const CFX_PointF& point, - uint32_t nFlag) { - if (!IsValid() || !IsVisible() || !IsEnabled()) - return false; - - SetCursor(); - if (!IsWndCaptureKeyboard(this)) - return false; - - for (auto* pChild : m_Children) { - if (pChild && IsWndCaptureKeyboard(pChild)) - return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag); - } - return false; -} - -void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { - m_Children.push_back(pWnd); -} - -void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { - for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { - if (*it && *it == pWnd) { - m_Children.erase(std::next(it).base()); - break; - } - } -} - -void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - switch (msg) { - case PNM_ADDCHILD: - AddChild(pWnd); - break; - case PNM_REMOVECHILD: - RemoveChild(pWnd); - break; - default: - break; - } -} - -bool CPWL_Wnd::IsValid() const { - return m_bCreated; -} - -const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const { - return m_sPrivateParam; -} - -CPWL_Wnd* CPWL_Wnd::GetParentWindow() const { - return m_sPrivateParam.pParentWnd; -} - -CFX_FloatRect CPWL_Wnd::GetWindowRect() const { - return m_rcWindow; -} - -CFX_FloatRect CPWL_Wnd::GetClientRect() const { - CFX_FloatRect rcWindow = GetWindowRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth())); - if (CPWL_ScrollBar* pVSB = GetVScrollBar()) - rcClient.right -= pVSB->GetScrollBarWidth(); - - rcClient.Normalize(); - return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect(); -} - -CFX_PointF CPWL_Wnd::GetCenterPoint() const { - CFX_FloatRect rcClient = GetClientRect(); - return CFX_PointF((rcClient.left + rcClient.right) * 0.5f, - (rcClient.top + rcClient.bottom) * 0.5f); -} - -bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const { - return (m_sPrivateParam.dwFlags & dwFlags) != 0; -} - -void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) { - m_sPrivateParam.dwFlags &= ~dwFlags; -} - -void CPWL_Wnd::AddFlag(uint32_t dwFlags) { - m_sPrivateParam.dwFlags |= dwFlags; -} - -CPWL_Color CPWL_Wnd::GetBackgroundColor() const { - return m_sPrivateParam.sBackgroundColor; -} - -void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) { - m_sPrivateParam.sBackgroundColor = color; -} - -CPWL_Color CPWL_Wnd::GetTextColor() const { - return m_sPrivateParam.sTextColor; -} - -BorderStyle CPWL_Wnd::GetBorderStyle() const { - return m_sPrivateParam.nBorderStyle; -} - -void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) { - if (HasFlag(PWS_BORDER)) - m_sPrivateParam.nBorderStyle = nBorderStyle; -} - -int32_t CPWL_Wnd::GetBorderWidth() const { - return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0; -} - -int32_t CPWL_Wnd::GetInnerBorderWidth() const { - return 0; -} - -CPWL_Color CPWL_Wnd::GetBorderColor() const { - return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color(); -} - -const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { - return m_sPrivateParam.sDash; -} - -void* CPWL_Wnd::GetAttachedData() const { - return m_sPrivateParam.pAttachedData; -} - -CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { - return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr; -} - -void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { - CreateVScrollBar(cp); -} - -void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { - if (m_pVScrollBar || !HasFlag(PWS_VSCROLL)) - return; - - PWL_CREATEPARAM scp = cp; - - // flags - scp.dwFlags = - PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; - - scp.pParentWnd = this; - scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - scp.eCursorType = FXCT_ARROW; - scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; - - m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); - m_pVScrollBar->Create(scp); -} - -void CPWL_Wnd::SetCapture() { - if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) - pMsgCtrl->SetCapture(this); -} - -void CPWL_Wnd::ReleaseCapture() { - for (auto* pChild : m_Children) { - if (pChild) - pChild->ReleaseCapture(); - } - if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) - pMsgCtrl->ReleaseCapture(); -} - -void CPWL_Wnd::SetFocus() { - if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { - if (!pMsgCtrl->IsMainCaptureKeyboard(this)) - pMsgCtrl->KillFocus(); - pMsgCtrl->SetFocus(this); - } -} - -void CPWL_Wnd::KillFocus() { - if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { - if (pMsgCtrl->IsWndCaptureKeyboard(this)) - pMsgCtrl->KillFocus(); - } -} - -void CPWL_Wnd::OnSetFocus() {} - -void CPWL_Wnd::OnKillFocus() {} - -bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const { - return IsValid() && IsVisible() && GetWindowRect().Contains(point); -} - -bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const { - return IsValid() && IsVisible() && GetClientRect().Contains(point); -} - -const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { - auto* pParent = m_sPrivateParam.pParentWnd; - return pParent ? pParent->GetRootWnd() : this; -} - -void CPWL_Wnd::SetVisible(bool bVisible) { - if (!IsValid()) - return; - - for (auto* pChild : m_Children) { - if (pChild) - pChild->SetVisible(bVisible); - } - if (bVisible != m_bVisible) { - m_bVisible = bVisible; - RePosChildWnd(); - InvalidateRect(); - } -} - -void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) { - m_rcClip = rect; - m_rcClip.Normalize(); -} - -const CFX_FloatRect& CPWL_Wnd::GetClipRect() const { - return m_rcClip; -} - -bool CPWL_Wnd::IsReadOnly() const { - return HasFlag(PWS_READONLY); -} - -void CPWL_Wnd::RePosChildWnd() { - CPWL_ScrollBar* pVSB = GetVScrollBar(); - if (!pVSB) - return; - - CFX_FloatRect rcContent = CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); - CFX_FloatRect rcVScroll = - CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, - rcContent.right - 1.0f, rcContent.top); - pVSB->Move(rcVScroll, true, false); -} - -void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} - -void CPWL_Wnd::SetCursor() { - if (IsValid()) { - if (CFX_SystemHandler* pSH = GetSystemHandler()) { - int32_t nCursorType = GetCreationParam().eCursorType; - pSH->SetCursor(nCursorType); - } - } -} - -void CPWL_Wnd::CreateMsgControl() { - if (!m_sPrivateParam.pMsgControl) - m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); -} - -void CPWL_Wnd::DestroyMsgControl() { - CPWL_MsgControl* pMsgControl = GetMsgControl(); - if (pMsgControl && pMsgControl->IsWndCreated(this)) - delete pMsgControl; -} - -CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { - return m_sPrivateParam.pMsgControl; -} - -bool CPWL_Wnd::IsCaptureMouse() const { - return IsWndCaptureMouse(this); -} - -bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { - CPWL_MsgControl* pCtrl = GetMsgControl(); - return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false; -} - -bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { - CPWL_MsgControl* pCtrl = GetMsgControl(); - return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false; -} - -bool CPWL_Wnd::IsFocused() const { - CPWL_MsgControl* pCtrl = GetMsgControl(); - return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false; -} - -CFX_FloatRect CPWL_Wnd::GetFocusRect() const { - return CPWL_Utils::InflateRect(GetWindowRect(), 1); -} - -float CPWL_Wnd::GetFontSize() const { - return m_sPrivateParam.fFontSize; -} - -void CPWL_Wnd::SetFontSize(float fFontSize) { - m_sPrivateParam.fFontSize = fFontSize; -} - -CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { - return m_sPrivateParam.pSystemHandler; -} - -IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { - return m_sPrivateParam.pFocusHandler; -} - -IPWL_Provider* CPWL_Wnd::GetProvider() const { - return m_sPrivateParam.pProvider.Get(); -} - -IPVT_FontMap* CPWL_Wnd::GetFontMap() const { - return m_sPrivateParam.pFontMap; -} - -CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { - switch (nBorderStyle) { - case BorderStyle::BEVELED: - return CPWL_Color(COLORTYPE_GRAY, 1); - case BorderStyle::INSET: - return CPWL_Color(COLORTYPE_GRAY, 0.5f); - default: - return CPWL_Color(); - } -} - -CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { - switch (nBorderStyle) { - case BorderStyle::BEVELED: - return GetBackgroundColor() / 2.0f; - case BorderStyle::INSET: - return CPWL_Color(COLORTYPE_GRAY, 0.75f); - default: - return CPWL_Color(); - } -} - -int32_t CPWL_Wnd::GetTransparency() { - return m_sPrivateParam.nTransparency; -} - -void CPWL_Wnd::SetTransparency(int32_t nTransparency) { - for (auto* pChild : m_Children) { - if (pChild) - pChild->SetTransparency(nTransparency); - } - m_sPrivateParam.nTransparency = nTransparency; -} - -CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { - CFX_Matrix mt = GetChildToRoot(); - if (IPWL_Provider* pProvider = GetProvider()) - mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); - return mt; -} - -FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { - CFX_FloatRect rcTemp = rect; - CFX_Matrix mt = GetWindowMatrix(); - mt.TransformRect(rcTemp); - return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), - (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5)); -} - -CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const { - CFX_Matrix mt = GetChildMatrix(); - if (mt.IsIdentity()) - return point; - - mt.SetReverse(mt); - return mt.Transform(point); -} - -CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { - CFX_Matrix mt = GetChildMatrix(); - if (mt.IsIdentity()) - return rect; - - mt.SetReverse(mt); - CFX_FloatRect rc = rect; - mt.TransformRect(rc); - return rc; -} - -CFX_Matrix CPWL_Wnd::GetChildToRoot() const { - CFX_Matrix mt; - if (HasFlag(PWS_CHILD)) { - const CPWL_Wnd* pParent = this; - while (pParent) { - mt.Concat(pParent->GetChildMatrix()); - pParent = pParent->GetParentWindow(); - } - } - return mt; -} - -CFX_Matrix CPWL_Wnd::GetChildMatrix() const { - return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix(); -} - -void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { - m_sPrivateParam.mtChild = mt; -} - -const CPWL_Wnd* CPWL_Wnd::GetFocused() const { - CPWL_MsgControl* pMsgCtrl = GetMsgControl(); - return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr; -} - -void CPWL_Wnd::EnableWindow(bool bEnable) { - if (m_bEnabled == bEnable) - return; - - for (auto* pChild : m_Children) { - if (pChild) - pChild->EnableWindow(bEnable); - } - m_bEnabled = bEnable; -} - -bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const { - CFX_SystemHandler* pSystemHandler = GetSystemHandler(); - return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag); -} - -bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const { - CFX_SystemHandler* pSystemHandler = GetSystemHandler(); - return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag); -} - -bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const { - CFX_SystemHandler* pSystemHandler = GetSystemHandler(); - return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag); -} diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.h b/fpdfsdk/pdfwindow/PWL_Wnd.h deleted file mode 100644 index d9d2f8ed66..0000000000 --- a/fpdfsdk/pdfwindow/PWL_Wnd.h +++ /dev/null @@ -1,370 +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 FPDFSDK_PDFWINDOW_PWL_WND_H_ -#define FPDFSDK_PDFWINDOW_PWL_WND_H_ - -#include -#include - -#include "core/fpdfdoc/cpdf_formcontrol.h" -#include "core/fxcrt/cfx_observable.h" -#include "core/fxcrt/cfx_unowned_ptr.h" -#include "core/fxcrt/fx_basic.h" -#include "fpdfsdk/cpdfsdk_widget.h" -#include "fpdfsdk/pdfwindow/cpwl_color.h" -#include "fpdfsdk/pdfwindow/cpwl_timer.h" -#include "fpdfsdk/pdfwindow/cpwl_timer_handler.h" - -class CPWL_MsgControl; -class CPWL_ScrollBar; -class CPWL_Wnd; -class CFX_SystemHandler; -class IPVT_FontMap; -class IPWL_Provider; - -// window styles -#define PWS_CHILD 0x80000000L -#define PWS_BORDER 0x40000000L -#define PWS_BACKGROUND 0x20000000L -#define PWS_HSCROLL 0x10000000L -#define PWS_VSCROLL 0x08000000L -#define PWS_VISIBLE 0x04000000L -#define PWS_DISABLE 0x02000000L -#define PWS_READONLY 0x01000000L -#define PWS_AUTOFONTSIZE 0x00800000L -#define PWS_AUTOTRANSPARENT 0x00400000L -#define PWS_NOREFRESHCLIP 0x00200000L - -// edit and label styles -#define PES_MULTILINE 0x0001L -#define PES_PASSWORD 0x0002L -#define PES_LEFT 0x0004L -#define PES_RIGHT 0x0008L -#define PES_MIDDLE 0x0010L -#define PES_TOP 0x0020L -#define PES_BOTTOM 0x0040L -#define PES_CENTER 0x0080L -#define PES_CHARARRAY 0x0100L -#define PES_AUTOSCROLL 0x0200L -#define PES_AUTORETURN 0x0400L -#define PES_UNDO 0x0800L -#define PES_RICH 0x1000L -#define PES_SPELLCHECK 0x2000L -#define PES_TEXTOVERFLOW 0x4000L -#define PES_NOREAD 0x8000L - -// listbox styles -#define PLBS_MULTIPLESEL 0x0001L -#define PLBS_HOVERSEL 0x0008L - -// combobox styles -#define PCBS_ALLOWCUSTOMTEXT 0x0001L - -// richedit styles -#define PRES_MULTILINE 0x0001L -#define PRES_AUTORETURN 0x0002L -#define PRES_AUTOSCROLL 0x0004L -#define PRES_UNDO 0x0100L -#define PRES_MULTIPAGES 0x0200L -#define PRES_TEXTOVERFLOW 0x0400L - -// notification messages -#define PNM_ADDCHILD 0x00000000L -#define PNM_REMOVECHILD 0x00000001L -#define PNM_SETSCROLLINFO 0x00000002L -#define PNM_SETSCROLLPOS 0x00000003L -#define PNM_SCROLLWINDOW 0x00000004L -#define PNM_LBUTTONDOWN 0x00000005L -#define PNM_LBUTTONUP 0x00000006L -#define PNM_MOUSEMOVE 0x00000007L -#define PNM_NOTERESET 0x00000008L -#define PNM_SETCARETINFO 0x00000009L -#define PNM_SELCHANGED 0x0000000AL -#define PNM_NOTEEDITCHANGED 0x0000000BL - -#define PWL_CLASSNAME_EDIT "CPWL_Edit" - -struct CPWL_Dash { - CPWL_Dash() : nDash(0), nGap(0), nPhase(0) {} - CPWL_Dash(int32_t dash, int32_t gap, int32_t phase) - : nDash(dash), nGap(gap), nPhase(phase) {} - - void Reset() { - nDash = 0; - nGap = 0; - nPhase = 0; - } - - int32_t nDash; - int32_t nGap; - int32_t nPhase; -}; - -inline bool operator==(const CPWL_Color& c1, const CPWL_Color& c2) { - return c1.nColorType == c2.nColorType && c1.fColor1 - c2.fColor1 < 0.0001 && - c1.fColor1 - c2.fColor1 > -0.0001 && - c1.fColor2 - c2.fColor2 < 0.0001 && - c1.fColor2 - c2.fColor2 > -0.0001 && - c1.fColor3 - c2.fColor3 < 0.0001 && - c1.fColor3 - c2.fColor3 > -0.0001 && - c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001; -} - -inline bool operator!=(const CPWL_Color& c1, const CPWL_Color& c2) { - return !(c1 == c2); -} - -#define PWL_SCROLLBAR_WIDTH 12.0f -#define PWL_SCROLLBAR_BUTTON_WIDTH 9.0f -#define PWL_SCROLLBAR_POSBUTTON_MINWIDTH 2.0f -#define PWL_SCROLLBAR_TRANSPARENCY 150 -#define PWL_SCROLLBAR_BKCOLOR \ - CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f) -#define PWL_DEFAULT_SELTEXTCOLOR CPWL_Color(COLORTYPE_RGB, 1, 1, 1) -#define PWL_DEFAULT_SELBACKCOLOR \ - CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f) -#define PWL_DEFAULT_BACKCOLOR PWL_DEFAULT_SELTEXTCOLOR -#define PWL_DEFAULT_TEXTCOLOR CPWL_Color(COLORTYPE_RGB, 0, 0, 0) -#define PWL_DEFAULT_FONTSIZE 9.0f -#define PWL_DEFAULT_BLACKCOLOR CPWL_Color(COLORTYPE_GRAY, 0) -#define PWL_DEFAULT_WHITECOLOR CPWL_Color(COLORTYPE_GRAY, 1) -#define PWL_DEFAULT_HEAVYGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.50) -#define PWL_DEFAULT_LIGHTGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.75) -#define PWL_TRIANGLE_HALFLEN 2.0f -#define PWL_CBBUTTON_TRIANGLE_HALFLEN 3.0f -#define PWL_INVALIDATE_INFLATE 2 - -class IPWL_Provider : public CFX_Observable { - public: - virtual ~IPWL_Provider() {} - - // get a matrix which map user space to CWnd client space - virtual CFX_Matrix GetWindowMatrix(void* pAttachedData) = 0; -}; - -class IPWL_FocusHandler { - public: - virtual ~IPWL_FocusHandler() {} - virtual void OnSetFocus(CPWL_Wnd* pWnd) = 0; -}; - -struct PWL_CREATEPARAM { - public: - PWL_CREATEPARAM(); - PWL_CREATEPARAM(const PWL_CREATEPARAM& other); - - void Reset() { - rcRectWnd.Reset(); - pSystemHandler = nullptr; - pFontMap = nullptr; - pProvider.Reset(); - pFocusHandler = nullptr; - dwFlags = 0; - sBackgroundColor.Reset(); - pAttachedWidget.Reset(); - nBorderStyle = BorderStyle::SOLID; - dwBorderWidth = 0; - sBorderColor.Reset(); - sTextColor.Reset(); - nTransparency = 0; - fFontSize = 0.0f; - sDash.Reset(); - pAttachedData = nullptr; - pParentWnd = nullptr; - pMsgControl = nullptr; - eCursorType = 0; - mtChild.SetIdentity(); - } - - CFX_FloatRect rcRectWnd; // required - CFX_SystemHandler* pSystemHandler; // required - IPVT_FontMap* pFontMap; // required - IPWL_Provider::ObservedPtr pProvider; // required - IPWL_FocusHandler* pFocusHandler; // optional - uint32_t dwFlags; // optional - CPWL_Color sBackgroundColor; // optional - CPDFSDK_Widget::ObservedPtr pAttachedWidget; // required - BorderStyle nBorderStyle; // optional - int32_t dwBorderWidth; // optional - CPWL_Color sBorderColor; // optional - CPWL_Color sTextColor; // optional - int32_t nTransparency; // optional - float fFontSize; // optional - CPWL_Dash sDash; // optional - void* pAttachedData; // optional - CPWL_Wnd* pParentWnd; // ignore - CPWL_MsgControl* pMsgControl; // ignore - int32_t eCursorType; // ignore - CFX_Matrix mtChild; // ignore -}; - -class CPWL_Wnd : public CPWL_TimerHandler { - public: - CPWL_Wnd(); - ~CPWL_Wnd() override; - - virtual CFX_ByteString GetClassName() const; - virtual void InvalidateRect(CFX_FloatRect* pRect = nullptr); - - virtual bool OnKeyDown(uint16_t nChar, uint32_t nFlag); - virtual bool OnChar(uint16_t nChar, uint32_t nFlag); - virtual bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag); - virtual bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag); - virtual bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag); - virtual bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag); - virtual bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag); - virtual bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag); - virtual bool OnMouseWheel(short zDelta, - const CFX_PointF& point, - uint32_t nFlag); - virtual void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0); - virtual void SetFocus(); - virtual void KillFocus(); - virtual void SetCursor(); - virtual void SetVisible(bool bVisible); - virtual void SetFontSize(float fFontSize); - virtual float GetFontSize() const; - - virtual CFX_FloatRect GetFocusRect() const; - virtual CFX_FloatRect GetClientRect() const; - - void InvalidateFocusHandler(IPWL_FocusHandler* handler); - void InvalidateProvider(IPWL_Provider* provider); - void Create(const PWL_CREATEPARAM& cp); - void Destroy(); - void Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh); - - void SetCapture(); - void ReleaseCapture(); - - void DrawAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); - - CPWL_Color GetBackgroundColor() const; - void SetBackgroundColor(const CPWL_Color& color); - CPWL_Color GetBorderColor() const; - CPWL_Color GetTextColor() const; - void SetTextColor(const CPWL_Color& color); - CPWL_Color GetBorderLeftTopColor(BorderStyle nBorderStyle) const; - CPWL_Color GetBorderRightBottomColor(BorderStyle nBorderStyle) const; - - void SetBorderStyle(BorderStyle eBorderStyle); - BorderStyle GetBorderStyle() const; - const CPWL_Dash& GetBorderDash() const; - - int32_t GetBorderWidth() const; - int32_t GetInnerBorderWidth() const; - CFX_FloatRect GetWindowRect() const; - CFX_PointF GetCenterPoint() const; - - bool IsVisible() const { return m_bVisible; } - bool HasFlag(uint32_t dwFlags) const; - void AddFlag(uint32_t dwFlags); - void RemoveFlag(uint32_t dwFlags); - - void SetClipRect(const CFX_FloatRect& rect); - const CFX_FloatRect& GetClipRect() const; - - CPWL_Wnd* GetParentWindow() const; - void* GetAttachedData() const; - - bool WndHitTest(const CFX_PointF& point) const; - bool ClientHitTest(const CFX_PointF& point) const; - bool IsCaptureMouse() const; - - void EnableWindow(bool bEnable); - bool IsEnabled() const { return m_bEnabled; } - const CPWL_Wnd* GetFocused() const; - bool IsFocused() const; - bool IsReadOnly() const; - CPWL_ScrollBar* GetVScrollBar() const; - - IPVT_FontMap* GetFontMap() const; - IPWL_Provider* GetProvider() const; - IPWL_FocusHandler* GetFocusHandler() const; - - int32_t GetTransparency(); - void SetTransparency(int32_t nTransparency); - - CFX_Matrix GetChildToRoot() const; - CFX_Matrix GetChildMatrix() const; - void SetChildMatrix(const CFX_Matrix& mt); - CFX_Matrix GetWindowMatrix() const; - - protected: - friend class CPWL_MsgControl; - - // CPWL_TimerHandler - CFX_SystemHandler* GetSystemHandler() const override; - - virtual void CreateChildWnd(const PWL_CREATEPARAM& cp); - virtual void RePosChildWnd(); - virtual void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream); - - virtual void DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device); - - virtual void OnCreate(PWL_CREATEPARAM& cp); - virtual void OnCreated(); - virtual void OnDestroy(); - - virtual void OnSetFocus(); - virtual void OnKillFocus(); - - void GetAppearanceStream(CFX_ByteTextBuf& sAppStream); - void SetNotifyFlag(bool bNotifying = true) { m_bNotifying = bNotifying; } - - bool IsValid() const; - const PWL_CREATEPARAM& GetCreationParam() const; - bool IsNotifying() const { return m_bNotifying; } - - void InvalidateRectMove(const CFX_FloatRect& rcOld, - const CFX_FloatRect& rcNew); - - bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const; - bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const; - const CPWL_Wnd* GetRootWnd() const; - - bool IsCTRLpressed(uint32_t nFlag) const; - bool IsSHIFTpressed(uint32_t nFlag) const; - bool IsALTpressed(uint32_t nFlag) const; - - private: - CFX_PointF ParentToChild(const CFX_PointF& point) const; - CFX_FloatRect ParentToChild(const CFX_FloatRect& rect) const; - - void GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream); - void DrawChildAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); - - FX_RECT PWLtoWnd(const CFX_FloatRect& rect) const; - - void AddChild(CPWL_Wnd* pWnd); - void RemoveChild(CPWL_Wnd* pWnd); - - void CreateScrollBar(const PWL_CREATEPARAM& cp); - void CreateVScrollBar(const PWL_CREATEPARAM& cp); - - void AdjustStyle(); - void CreateMsgControl(); - void DestroyMsgControl(); - - CPWL_MsgControl* GetMsgControl() const; - - std::vector m_Children; - PWL_CREATEPARAM m_sPrivateParam; - CFX_UnownedPtr m_pVScrollBar; - CFX_FloatRect m_rcWindow; - CFX_FloatRect m_rcClip; - bool m_bCreated; - bool m_bVisible; - bool m_bNotifying; - bool m_bEnabled; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_WND_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_button.cpp b/fpdfsdk/pdfwindow/cpwl_button.cpp new file mode 100644 index 0000000000..de9054ae32 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_button.cpp @@ -0,0 +1,39 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_button.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +CPWL_Button::CPWL_Button() : m_bMouseDown(false) {} + +CPWL_Button::~CPWL_Button() {} + +CFX_ByteString CPWL_Button::GetClassName() const { + return "CPWL_Button"; +} + +void CPWL_Button::OnCreate(PWL_CREATEPARAM& cp) { + cp.eCursorType = FXCT_HAND; +} + +bool CPWL_Button::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + m_bMouseDown = true; + SetCapture(); + + return true; +} + +bool CPWL_Button::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + ReleaseCapture(); + m_bMouseDown = false; + + return true; +} diff --git a/fpdfsdk/pdfwindow/cpwl_button.h b/fpdfsdk/pdfwindow/cpwl_button.h new file mode 100644 index 0000000000..9f4a47733e --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_button.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 FPDFSDK_PDFWINDOW_CPWL_BUTTON_H_ +#define FPDFSDK_PDFWINDOW_CPWL_BUTTON_H_ + +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CPWL_Button : public CPWL_Wnd { + public: + CPWL_Button(); + ~CPWL_Button() override; + + // CPWL_Wnd + CFX_ByteString GetClassName() const override; + void OnCreate(PWL_CREATEPARAM& cp) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + + protected: + bool m_bMouseDown; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_BUTTON_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_caret.cpp b/fpdfsdk/pdfwindow/cpwl_caret.cpp new file mode 100644 index 0000000000..3275dd1b33 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_caret.cpp @@ -0,0 +1,147 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_caret.h" + +#include "core/fxge/cfx_graphstatedata.h" +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +#define PWL_CARET_FLASHINTERVAL 500 + +PWL_CARET_INFO::PWL_CARET_INFO() : bVisible(false) {} + +CPWL_Caret::CPWL_Caret() : m_bFlash(false), m_fWidth(0.4f), m_nDelay(0) {} + +CPWL_Caret::~CPWL_Caret() {} + +CFX_ByteString CPWL_Caret::GetClassName() const { + return "CPWL_Caret"; +} + +void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + GetCaretApp(sAppStream, CFX_PointF()); +} + +void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + if (IsVisible() && m_bFlash) { + CFX_FloatRect rcRect = GetCaretRect(); + CFX_FloatRect rcClip = GetClipRect(); + CFX_PathData path; + + float fCaretX = rcRect.left + m_fWidth * 0.5f; + float fCaretTop = rcRect.top; + float fCaretBottom = rcRect.bottom; + if (!rcClip.IsEmpty()) { + rcRect.Intersect(rcClip); + if (rcRect.IsEmpty()) + return; + + fCaretTop = rcRect.top; + fCaretBottom = rcRect.bottom; + } + + path.AppendPoint(CFX_PointF(fCaretX, fCaretBottom), FXPT_TYPE::MoveTo, + false); + path.AppendPoint(CFX_PointF(fCaretX, fCaretTop), FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = m_fWidth; + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), + FXFILL_ALTERNATE); + } +} + +void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf& sAppStream, + const CFX_PointF& ptOffset) { + if (IsVisible() && m_bFlash) { + CFX_ByteTextBuf sCaret; + + CFX_FloatRect rcRect = GetCaretRect(); + CFX_FloatRect rcClip = GetClipRect(); + + rcRect = CPWL_Utils::OffsetRect(rcRect, ptOffset.x, ptOffset.y); + rcClip = CPWL_Utils::OffsetRect(rcClip, ptOffset.x, ptOffset.y); + + sCaret << "q\n"; + if (!rcClip.IsEmpty()) { + sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " " + << rcClip.right - rcClip.left << " " + << rcClip.top - rcClip.bottom - 4.5f << " re W n\n"; + } + sCaret << m_fWidth << " w\n0 G\n"; + sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.bottom << " m\n"; + sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.top << " l S\nQ\n"; + + sAppStream << sCaret; + } +} + +CFX_ByteString CPWL_Caret::GetCaretAppearanceStream( + const CFX_PointF& ptOffset) { + CFX_ByteTextBuf sCaret; + GetCaretApp(sCaret, ptOffset); + return sCaret.MakeString(); +} + +void CPWL_Caret::TimerProc() { + if (m_nDelay > 0) { + m_nDelay--; + } else { + m_bFlash = !m_bFlash; + InvalidateRect(); + } +} + +CFX_FloatRect CPWL_Caret::GetCaretRect() const { + return CFX_FloatRect(m_ptFoot.x, m_ptFoot.y, m_ptHead.x + m_fWidth, + m_ptHead.y); +} + +void CPWL_Caret::SetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot) { + if (bVisible) { + if (IsVisible()) { + if (m_ptHead != ptHead || m_ptFoot != ptFoot) { + m_ptHead = ptHead; + m_ptFoot = ptFoot; + m_bFlash = true; + Move(m_rcInvalid, false, true); + } + } else { + m_ptHead = ptHead; + m_ptFoot = ptFoot; + EndTimer(); + BeginTimer(PWL_CARET_FLASHINTERVAL); + CPWL_Wnd::SetVisible(true); + m_bFlash = true; + Move(m_rcInvalid, false, true); + } + } else { + m_ptHead = CFX_PointF(); + m_ptFoot = CFX_PointF(); + m_bFlash = false; + if (IsVisible()) { + EndTimer(); + CPWL_Wnd::SetVisible(false); + } + } +} + +void CPWL_Caret::InvalidateRect(CFX_FloatRect* pRect) { + if (pRect) { + CFX_FloatRect rcRefresh = CPWL_Utils::InflateRect(*pRect, 0.5f); + rcRefresh.top += 1; + rcRefresh.bottom -= 1; + CPWL_Wnd::InvalidateRect(&rcRefresh); + } else { + CPWL_Wnd::InvalidateRect(pRect); + } +} diff --git a/fpdfsdk/pdfwindow/cpwl_caret.h b/fpdfsdk/pdfwindow/cpwl_caret.h new file mode 100644 index 0000000000..325f13b7eb --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_caret.h @@ -0,0 +1,53 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_CARET_H_ +#define FPDFSDK_PDFWINDOW_CPWL_CARET_H_ + +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +struct PWL_CARET_INFO { + public: + PWL_CARET_INFO(); + + bool bVisible; + CFX_PointF ptHead; + CFX_PointF ptFoot; +}; + +class CPWL_Caret : public CPWL_Wnd { + public: + CPWL_Caret(); + ~CPWL_Caret() override; + + // CPWL_Wnd + CFX_ByteString GetClassName() const override; + void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; + void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + void InvalidateRect(CFX_FloatRect* pRect = nullptr) override; + void SetVisible(bool bVisible) override {} + void TimerProc() override; + + void SetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot); + CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset); + void SetInvalidRect(CFX_FloatRect rc) { m_rcInvalid = rc; } + + private: + void GetCaretApp(CFX_ByteTextBuf& sAppStream, const CFX_PointF& ptOffset); + CFX_FloatRect GetCaretRect() const; + + bool m_bFlash; + CFX_PointF m_ptHead; + CFX_PointF m_ptFoot; + float m_fWidth; + int32_t m_nDelay; + CFX_FloatRect m_rcInvalid; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_CARET_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_combo_box.cpp b/fpdfsdk/pdfwindow/cpwl_combo_box.cpp new file mode 100644 index 0000000000..42786806d0 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_combo_box.cpp @@ -0,0 +1,587 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_combo_box.h" + +#include + +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/fxedit/fxet_list.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "public/fpdf_fwlevent.h" + +#define PWLCB_DEFAULTFONTSIZE 12.0f + +bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (!m_bMouseDown) + return true; + + ReleaseCapture(); + m_bMouseDown = false; + + if (!ClientHitTest(point)) + return true; + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->OnNotify(this, PNM_LBUTTONUP, 0, PWL_MAKEDWORD(point.x, point.y)); + + bool bExit = false; + OnNotifySelChanged(false, bExit, nFlag); + + return !bExit; +} + +bool CPWL_CBListBox::OnKeyDownWithExit(uint16_t nChar, + bool& bExit, + uint32_t nFlag) { + switch (nChar) { + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_Left: + case FWL_VKEY_End: + case FWL_VKEY_Right: + break; + default: + return false; + } + + switch (nChar) { + case FWL_VKEY_Up: + m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Down: + m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Home: + m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Left: + m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_End: + m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Right: + m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Delete: + break; + } + + OnNotifySelChanged(true, bExit, nFlag); + + return true; +} + +bool CPWL_CBListBox::OnCharWithExit(uint16_t nChar, + bool& bExit, + uint32_t nFlag) { + if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) + return false; + if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) + pComboBox->SetSelectText(); + + OnNotifySelChanged(true, bExit, nFlag); + + return true; +} + +void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + CPWL_Wnd::GetThisAppearanceStream(sAppStream); + + CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); + + if (IsVisible() && !rectWnd.IsEmpty()) { + CFX_ByteTextBuf sButton; + + CFX_PointF ptCenter = GetCenterPoint(); + + CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, + ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, + ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt3(ptCenter.x, + ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); + + if (IsFloatBigger(rectWnd.right - rectWnd.left, + PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && + IsFloatBigger(rectWnd.top - rectWnd.bottom, + PWL_CBBUTTON_TRIANGLE_HALFLEN)) { + sButton << "0 g\n"; + sButton << pt1.x << " " << pt1.y << " m\n"; + sButton << pt2.x << " " << pt2.y << " l\n"; + sButton << pt3.x << " " << pt3.y << " l\n"; + sButton << pt1.x << " " << pt1.y << " l f\n"; + + sAppStream << "q\n" << sButton << "Q\n"; + } + } +} + +void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); + + CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); + + if (IsVisible() && !rectWnd.IsEmpty()) { + CFX_PointF ptCenter = GetCenterPoint(); + + CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, + ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, + ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt3(ptCenter.x, + ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); + + if (IsFloatBigger(rectWnd.right - rectWnd.left, + PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && + IsFloatBigger(rectWnd.top - rectWnd.bottom, + PWL_CBBUTTON_TRIANGLE_HALFLEN)) { + CFX_PathData path; + path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); + path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&path, pUser2Device, nullptr, + PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0, + FXFILL_ALTERNATE); + } + } +} + +bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + SetCapture(); + + if (CPWL_Wnd* pParent = GetParentWindow()) { + pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, + PWL_MAKEDWORD(point.x, point.y)); + } + + return true; +} + +bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + ReleaseCapture(); + + return true; +} + +CPWL_ComboBox::CPWL_ComboBox() + : m_pEdit(nullptr), + m_pButton(nullptr), + m_pList(nullptr), + m_bPopup(false), + m_bBottom(true), + m_nSelectItem(-1), + m_pFillerNotify(nullptr) {} + +CPWL_ComboBox::~CPWL_ComboBox() {} + +CFX_ByteString CPWL_ComboBox::GetClassName() const { + return "CPWL_ComboBox"; +} + +void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) { + cp.dwFlags &= ~PWS_HSCROLL; + cp.dwFlags &= ~PWS_VSCROLL; +} + +void CPWL_ComboBox::SetFocus() { + if (m_pEdit) + m_pEdit->SetFocus(); +} + +void CPWL_ComboBox::KillFocus() { + SetPopup(false); + CPWL_Wnd::KillFocus(); +} + +CFX_WideString CPWL_ComboBox::GetText() const { + if (m_pEdit) { + return m_pEdit->GetText(); + } + return CFX_WideString(); +} + +void CPWL_ComboBox::SetText(const CFX_WideString& text) { + if (m_pEdit) + m_pEdit->SetText(text); +} + +void CPWL_ComboBox::AddString(const CFX_WideString& str) { + if (m_pList) + m_pList->AddString(str); +} + +int32_t CPWL_ComboBox::GetSelect() const { + return m_nSelectItem; +} + +void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { + if (m_pList) + m_pList->Select(nItemIndex); + + m_pEdit->SetText(m_pList->GetText()); + m_nSelectItem = nItemIndex; +} + +void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { + if (m_pEdit) + m_pEdit->SetSel(nStartChar, nEndChar); +} + +void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { + nStartChar = -1; + nEndChar = -1; + + if (m_pEdit) + m_pEdit->GetSel(nStartChar, nEndChar); +} + +void CPWL_ComboBox::Clear() { + if (m_pEdit) + m_pEdit->Clear(); +} + +void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { + CreateEdit(cp); + CreateButton(cp); + CreateListBox(cp); +} + +void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { + if (m_pEdit) + return; + + m_pEdit = new CPWL_CBEdit(); + m_pEdit->AttachFFLData(m_pFormFiller.Get()); + + PWL_CREATEPARAM ecp = cp; + ecp.pParentWnd = this; + ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | + PES_AUTOSCROLL | PES_UNDO; + + if (HasFlag(PWS_AUTOFONTSIZE)) + ecp.dwFlags |= PWS_AUTOFONTSIZE; + + if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) + ecp.dwFlags |= PWS_READONLY; + + ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); + ecp.dwBorderWidth = 0; + ecp.nBorderStyle = BorderStyle::SOLID; + m_pEdit->Create(ecp); +} + +void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { + if (m_pButton) + return; + + m_pButton = new CPWL_CBButton; + + PWL_CREATEPARAM bcp = cp; + bcp.pParentWnd = this; + bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; + bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR; + bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; + bcp.dwBorderWidth = 2; + bcp.nBorderStyle = BorderStyle::BEVELED; + bcp.eCursorType = FXCT_ARROW; + m_pButton->Create(bcp); +} + +void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { + if (m_pList) + return; + + m_pList = new CPWL_CBListBox(); + m_pList->AttachFFLData(m_pFormFiller.Get()); + + PWL_CREATEPARAM lcp = cp; + lcp.pParentWnd = this; + lcp.dwFlags = + PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; + lcp.nBorderStyle = BorderStyle::SOLID; + lcp.dwBorderWidth = 1; + lcp.eCursorType = FXCT_ARROW; + lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); + + if (cp.dwFlags & PWS_AUTOFONTSIZE) + lcp.fFontSize = PWLCB_DEFAULTFONTSIZE; + else + lcp.fFontSize = cp.fFontSize; + + if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) + lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; + + if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) + lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; + + m_pList->Create(lcp); +} + +void CPWL_ComboBox::RePosChildWnd() { + const CFX_FloatRect rcClient = GetClientRect(); + if (m_bPopup) { + const float fOldWindowHeight = m_rcOldWindow.Height(); + const float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; + + CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); + CFX_FloatRect rcButton = rcClient; + rcButton.left = + std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); + if (m_bBottom) { + rcButton.bottom = rcButton.top - fOldClientHeight; + rcEdit.bottom = rcEdit.top - fOldClientHeight; + rcList.top -= fOldWindowHeight; + } else { + rcButton.top = rcButton.bottom + fOldClientHeight; + rcEdit.top = rcEdit.bottom + fOldClientHeight; + rcList.bottom += fOldWindowHeight; + } + + if (m_pButton) + m_pButton->Move(rcButton, true, false); + + if (m_pEdit) + m_pEdit->Move(rcEdit, true, false); + + if (m_pList) { + m_pList->SetVisible(true); + m_pList->Move(rcList, true, false); + m_pList->ScrollToListItem(m_nSelectItem); + } + return; + } + + CFX_FloatRect rcButton = rcClient; + rcButton.left = + std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); + + if (m_pButton) + m_pButton->Move(rcButton, true, false); + + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); + + if (m_pEdit) + m_pEdit->Move(rcEdit, true, false); + + if (m_pList) + m_pList->SetVisible(false); +} + +void CPWL_ComboBox::SelectAll() { + if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) + m_pEdit->SelectAll(); +} + +CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { + return CFX_FloatRect(); +} + +void CPWL_ComboBox::SetPopup(bool bPopup) { + if (!m_pList) + return; + if (bPopup == m_bPopup) + return; + float fListHeight = m_pList->GetContentRect().Height(); + if (!IsFloatBigger(fListHeight, 0.0f)) + return; + + if (!bPopup) { + m_bPopup = bPopup; + Move(m_rcOldWindow, true, true); + return; + } + + if (!m_pFillerNotify) + return; + +#ifdef PDF_ENABLE_XFA + bool bExit = false; + m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0); + if (bExit) + return; +#endif // PDF_ENABLE_XFA + + float fBorderWidth = m_pList->GetBorderWidth() * 2; + float fPopupMin = 0.0f; + if (m_pList->GetCount() > 3) + fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth; + float fPopupMax = fListHeight + fBorderWidth; + + bool bBottom; + float fPopupRet; + m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, + &bBottom, &fPopupRet); + if (!IsFloatBigger(fPopupRet, 0.0f)) + return; + + m_rcOldWindow = CPWL_Wnd::GetWindowRect(); + m_bPopup = bPopup; + m_bBottom = bBottom; + + CFX_FloatRect rcWindow = m_rcOldWindow; + if (bBottom) + rcWindow.bottom -= fPopupRet; + else + rcWindow.top += fPopupRet; + + Move(rcWindow, true, true); +#ifdef PDF_ENABLE_XFA + bExit = false; + m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0); +#endif // PDF_ENABLE_XFA +} + +bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { + if (!m_pList) + return false; + if (!m_pEdit) + return false; + + m_nSelectItem = -1; + + switch (nChar) { + case FWL_VKEY_Up: + if (m_pList->GetCurSel() > 0) { + bool bExit = false; +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify) { + m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); + if (bExit) + return false; + bExit = false; + m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); + if (bExit) + return false; + } +#endif // PDF_ENABLE_XFA + if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { + if (bExit) + return false; + SetSelectText(); + } + } + return true; + case FWL_VKEY_Down: + if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { + bool bExit = false; +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify) { + m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); + if (bExit) + return false; + bExit = false; + m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); + if (bExit) + return false; + } +#endif // PDF_ENABLE_XFA + if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { + if (bExit) + return false; + SetSelectText(); + } + } + return true; + } + + if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) + return m_pEdit->OnKeyDown(nChar, nFlag); + + return false; +} + +bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { + if (!m_pList) + return false; + + if (!m_pEdit) + return false; + + m_nSelectItem = -1; + if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) + return m_pEdit->OnChar(nChar, nFlag); + + bool bExit = false; +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify) { + m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); + if (bExit) + return false; + + m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); + if (bExit) + return false; + } +#endif // PDF_ENABLE_XFA + return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : false; +} + +void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam, + intptr_t lParam) { + switch (msg) { + case PNM_LBUTTONDOWN: + if (pWnd == m_pButton) { + SetPopup(!m_bPopup); + return; + } + break; + case PNM_LBUTTONUP: + if (m_pEdit && m_pList) { + if (pWnd == m_pList) { + SetSelectText(); + SelectAll(); + m_pEdit->SetFocus(); + SetPopup(false); + return; + } + } + break; + } + + CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); +} + +bool CPWL_ComboBox::IsPopup() const { + return m_bPopup; +} + +void CPWL_ComboBox::SetSelectText() { + m_pEdit->SelectAll(); + m_pEdit->ReplaceSel(m_pList->GetText()); + m_pEdit->SelectAll(); + m_nSelectItem = m_pList->GetCurSel(); +} + +void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { + m_pFillerNotify = pNotify; + + if (m_pEdit) + m_pEdit->SetFillerNotify(pNotify); + + if (m_pList) + m_pList->SetFillerNotify(pNotify); +} diff --git a/fpdfsdk/pdfwindow/cpwl_combo_box.h b/fpdfsdk/pdfwindow/cpwl_combo_box.h new file mode 100644 index 0000000000..71bd1a9e1c --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_combo_box.h @@ -0,0 +1,107 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_COMBO_BOX_H_ +#define FPDFSDK_PDFWINDOW_CPWL_COMBO_BOX_H_ + +#include + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CPWL_CBEdit : public CPWL_Edit { + public: + CPWL_CBEdit() {} + ~CPWL_CBEdit() override {} +}; + +class CPWL_CBListBox : public CPWL_ListBox { + public: + CPWL_CBListBox() {} + ~CPWL_CBListBox() override {} + + // CPWL_ListBox + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + + bool OnKeyDownWithExit(uint16_t nChar, bool& bExit, uint32_t nFlag); + bool OnCharWithExit(uint16_t nChar, bool& bExit, uint32_t nFlag); +}; + +#define PWL_COMBOBOX_BUTTON_WIDTH 13 + +class CPWL_CBButton : public CPWL_Wnd { + public: + CPWL_CBButton() {} + ~CPWL_CBButton() override {} + + // CPWL_Wnd + void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; + void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; +}; + +class CPWL_ComboBox : public CPWL_Wnd { + public: + CPWL_ComboBox(); + ~CPWL_ComboBox() override; + + CPWL_Edit* GetEdit() const { return m_pEdit.Get(); } + + // CPWL_Wnd: + CFX_ByteString GetClassName() const override; + void OnCreate(PWL_CREATEPARAM& cp) override; + bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; + bool OnChar(uint16_t nChar, uint32_t nFlag) override; + void OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam = 0, + intptr_t lParam = 0) override; + void CreateChildWnd(const PWL_CREATEPARAM& cp) override; + void RePosChildWnd() override; + CFX_FloatRect GetFocusRect() const override; + void SetFocus() override; + void KillFocus() override; + + void SetFillerNotify(IPWL_Filler_Notify* pNotify); + + CFX_WideString GetText() const; + void SetText(const CFX_WideString& text); + void AddString(const CFX_WideString& str); + int32_t GetSelect() const; + void SetSelect(int32_t nItemIndex); + + void SetEditSel(int32_t nStartChar, int32_t nEndChar); + void GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const; + void Clear(); + void SelectAll(); + bool IsPopup() const; + + void SetSelectText(); + + void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } + + private: + void CreateEdit(const PWL_CREATEPARAM& cp); + void CreateButton(const PWL_CREATEPARAM& cp); + void CreateListBox(const PWL_CREATEPARAM& cp); + void SetPopup(bool bPopup); + + CFX_UnownedPtr m_pEdit; + CFX_UnownedPtr m_pButton; + CFX_UnownedPtr m_pList; + CFX_FloatRect m_rcOldWindow; + bool m_bPopup; + bool m_bBottom; + int32_t m_nSelectItem; + CFX_UnownedPtr m_pFillerNotify; + CFX_UnownedPtr m_pFormFiller; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_COMBO_BOX_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_edit.cpp b/fpdfsdk/pdfwindow/cpwl_edit.cpp new file mode 100644 index 0000000000..fd785e0603 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_edit.cpp @@ -0,0 +1,863 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_edit.h" + +#include +#include +#include + +#include "core/fpdfapi/font/cpdf_font.h" +#include "core/fpdfdoc/cpvt_word.h" +#include "core/fxcrt/fx_safe_types.h" +#include "core/fxcrt/xml/cxml_content.h" +#include "core/fxcrt/xml/cxml_element.h" +#include "core/fxge/cfx_graphstatedata.h" +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "core/fxge/fx_font.h" +#include "fpdfsdk/fxedit/fxet_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_caret.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "public/fpdf_fwlevent.h" +#include "third_party/base/stl_util.h" + +CPWL_Edit::CPWL_Edit() : m_bFocus(false) {} + +CPWL_Edit::~CPWL_Edit() { + ASSERT(!m_bFocus); +} + +CFX_ByteString CPWL_Edit::GetClassName() const { + return PWL_CLASSNAME_EDIT; +} + +void CPWL_Edit::OnDestroy() {} + +void CPWL_Edit::SetText(const CFX_WideString& csText) { + CFX_WideString swText = csText; + if (!HasFlag(PES_RICH)) { + m_pEdit->SetText(swText); + return; + } + + CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); + std::unique_ptr pXML( + CXML_Element::Parse(sValue.c_str(), sValue.GetLength())); + if (!pXML) { + m_pEdit->SetText(swText); + return; + } + swText.clear(); + + bool bFirst = true; + int32_t nCount = pXML->CountChildren(); + for (int32_t i = 0; i < nCount; i++) { + CXML_Element* pSubElement = ToElement(pXML->GetChild(i)); + if (!pSubElement || !pSubElement->GetTagName().EqualNoCase("p")) + continue; + + CFX_WideString swSection; + int nSubChild = pSubElement->CountChildren(); + for (int32_t j = 0; j < nSubChild; j++) { + CXML_Content* pSubContent = ToContent(pSubElement->GetChild(j)); + if (pSubContent) + swSection += pSubContent->m_Content; + } + if (bFirst) + bFirst = false; + else + swText += FWL_VKEY_Return; + swText += swSection; + } + + m_pEdit->SetText(swText); +} + +void CPWL_Edit::RePosChildWnd() { + if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { + CFX_FloatRect rcWindow = m_rcOldWindow; + CFX_FloatRect rcVScroll = + CFX_FloatRect(rcWindow.right, rcWindow.bottom, + rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top); + pVSB->Move(rcVScroll, true, false); + } + + if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) + m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( + GetClientRect(), 1.0f)); // +1 for caret beside border + + CPWL_EditCtrl::RePosChildWnd(); +} + +CFX_FloatRect CPWL_Edit::GetClientRect() const { + CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( + GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); + + if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { + if (pVSB->IsVisible()) { + rcClient.right -= PWL_SCROLLBAR_WIDTH; + } + } + + return rcClient; +} + +void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) { + m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); +} + +bool CPWL_Edit::CanSelectAll() const { + return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); +} + +bool CPWL_Edit::CanClear() const { + return !IsReadOnly() && m_pEdit->IsSelected(); +} + +bool CPWL_Edit::CanCopy() const { + return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && + m_pEdit->IsSelected(); +} + +bool CPWL_Edit::CanCut() const { + return CanCopy() && !IsReadOnly(); +} +void CPWL_Edit::CutText() { + if (!CanCut()) + return; + m_pEdit->Clear(); +} + +void CPWL_Edit::OnCreated() { + CPWL_EditCtrl::OnCreated(); + + if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { + pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); + pScroll->SetTransparency(255); + } + + SetParamByFlag(); + + m_rcOldWindow = GetWindowRect(); + + m_pEdit->SetOprNotify(this); + m_pEdit->EnableOprNotify(true); +} + +void CPWL_Edit::SetParamByFlag() { + if (HasFlag(PES_RIGHT)) { + m_pEdit->SetAlignmentH(2, false); + } else if (HasFlag(PES_MIDDLE)) { + m_pEdit->SetAlignmentH(1, false); + } else { + m_pEdit->SetAlignmentH(0, false); + } + + if (HasFlag(PES_BOTTOM)) { + m_pEdit->SetAlignmentV(2, false); + } else if (HasFlag(PES_CENTER)) { + m_pEdit->SetAlignmentV(1, false); + } else { + m_pEdit->SetAlignmentV(0, false); + } + + if (HasFlag(PES_PASSWORD)) { + m_pEdit->SetPasswordChar('*', false); + } + + m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false); + m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false); + m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false); + m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false); + m_pEdit->EnableUndo(HasFlag(PES_UNDO)); + + if (HasFlag(PES_TEXTOVERFLOW)) { + SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); + m_pEdit->SetTextOverflow(true, false); + } else { + if (m_pEditCaret) { + m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( + GetClientRect(), 1.0f)); // +1 for caret beside border + } + } +} + +void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + CPWL_Wnd::GetThisAppearanceStream(sAppStream); + + CFX_FloatRect rcClient = GetClientRect(); + CFX_ByteTextBuf sLine; + + int32_t nCharArray = m_pEdit->GetCharArray(); + + if (nCharArray > 0) { + switch (GetBorderStyle()) { + case BorderStyle::SOLID: { + sLine << "q\n" + << GetBorderWidth() << " w\n" + << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) + .AsStringC() + << " 2 J 0 j\n"; + + for (int32_t i = 1; i < nCharArray; i++) { + sLine << rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * i + << " " << rcClient.top << " l S\n"; + } + + sLine << "Q\n"; + break; + } + case BorderStyle::DASH: { + sLine << "q\n" + << GetBorderWidth() << " w\n" + << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) + .AsStringC() + << " 2 J 0 j\n" + << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap + << "] " << GetBorderDash().nPhase << " d\n"; + + for (int32_t i = 1; i < nCharArray; i++) { + sLine << rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * i + << " " << rcClient.top << " l S\n"; + } + + sLine << "Q\n"; + break; + } + default: + break; + } + } + + sAppStream << sLine; + + CFX_ByteTextBuf sText; + CFX_PointF ptOffset; + CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); + CPVT_WordRange wrSelect = GetSelectWordRange(); + CPVT_WordRange wrVisible = + HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange(); + + CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); + CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); + CPVT_WordRange wrTemp = + CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); + CFX_ByteString sEditSel = + CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp); + + if (sEditSel.GetLength() > 0) + sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC() + << sEditSel.AsStringC(); + + wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); + CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( + m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), + m_pEdit->GetPasswordChar()); + + if (sEditBefore.GetLength() > 0) + sText << "BT\n" + << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() + << sEditBefore.AsStringC() << "ET\n"; + + wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); + CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( + m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), + m_pEdit->GetPasswordChar()); + + if (sEditMid.GetLength() > 0) + sText << "BT\n" + << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) + .AsStringC() + << sEditMid.AsStringC() << "ET\n"; + + wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); + CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( + m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), + m_pEdit->GetPasswordChar()); + + if (sEditAfter.GetLength() > 0) + sText << "BT\n" + << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() + << sEditAfter.AsStringC() << "ET\n"; + + if (sText.GetLength() > 0) { + CFX_FloatRect rect = GetClientRect(); + sAppStream << "q\n/Tx BMC\n"; + + if (!HasFlag(PES_TEXTOVERFLOW)) + sAppStream << rect.left << " " << rect.bottom << " " + << rect.right - rect.left << " " << rect.top - rect.bottom + << " re W n\n"; + + sAppStream << sText; + + sAppStream << "EMC\nQ\n"; + } +} + +void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); + + CFX_FloatRect rcClient = GetClientRect(); + CFX_ByteTextBuf sLine; + + int32_t nCharArray = m_pEdit->GetCharArray(); + FX_SAFE_INT32 nCharArraySafe = nCharArray; + nCharArraySafe -= 1; + nCharArraySafe *= 2; + + if (nCharArray > 0 && nCharArraySafe.IsValid()) { + switch (GetBorderStyle()) { + case BorderStyle::SOLID: { + CFX_GraphStateData gsd; + gsd.m_LineWidth = (float)GetBorderWidth(); + + CFX_PathData path; + + for (int32_t i = 0; i < nCharArray - 1; i++) { + path.AppendPoint( + CFX_PointF( + rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), + rcClient.bottom), + FXPT_TYPE::MoveTo, false); + path.AppendPoint( + CFX_PointF( + rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), + rcClient.top), + FXPT_TYPE::LineTo, false); + } + if (!path.GetPoints().empty()) { + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, + GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE); + } + break; + } + case BorderStyle::DASH: { + CFX_GraphStateData gsd; + gsd.m_LineWidth = (float)GetBorderWidth(); + + gsd.SetDashCount(2); + gsd.m_DashArray[0] = (float)GetBorderDash().nDash; + gsd.m_DashArray[1] = (float)GetBorderDash().nGap; + gsd.m_DashPhase = (float)GetBorderDash().nPhase; + + CFX_PathData path; + for (int32_t i = 0; i < nCharArray - 1; i++) { + path.AppendPoint( + CFX_PointF( + rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), + rcClient.bottom), + FXPT_TYPE::MoveTo, false); + path.AppendPoint( + CFX_PointF( + rcClient.left + + ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), + rcClient.top), + FXPT_TYPE::LineTo, false); + } + if (!path.GetPoints().empty()) { + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, + GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE); + } + break; + } + default: + break; + } + } + + CFX_FloatRect rcClip; + CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); + CPVT_WordRange* pRange = nullptr; + if (!HasFlag(PES_TEXTOVERFLOW)) { + rcClip = GetClientRect(); + pRange = &wrRange; + } + + CFX_SystemHandler* pSysHandler = GetSystemHandler(); + CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(), + GetTextColor().ToFXColor(GetTransparency()), rcClip, + CFX_PointF(), pRange, pSysHandler, m_pFormFiller.Get()); +} + +bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { + if (m_bMouseDown) + InvalidateRect(); + + m_bMouseDown = true; + SetCapture(); + + m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + } + + return true; +} + +bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDblClk(point, nFlag); + + if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { + m_pEdit->SelectAll(); + } + + return true; +} + +bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) { + if (m_bMouseDown) + return false; + + CPWL_Wnd::OnRButtonUp(point, nFlag); + + if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) + return true; + + CFX_SystemHandler* pSH = GetSystemHandler(); + if (!pSH) + return false; + + SetFocus(); + + return false; +} + +void CPWL_Edit::OnSetFocus() { + SetEditCaret(true); + if (!IsReadOnly()) { + if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) + pFocusHandler->OnSetFocus(this); + } + m_bFocus = true; +} + +void CPWL_Edit::OnKillFocus() { + ShowVScrollBar(false); + m_pEdit->SelectNone(); + SetCaret(false, CFX_PointF(), CFX_PointF()); + SetCharSet(FX_CHARSET_ANSI); + m_bFocus = false; +} + +void CPWL_Edit::SetCharSpace(float fCharSpace) { + m_pEdit->SetCharSpace(fCharSpace); +} + +CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( + const CFX_PointF& ptOffset) const { + CPVT_WordRange wr = GetSelectWordRange(); + return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr); +} + +CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { + if (m_pEdit->IsSelected()) { + int32_t nStart = -1; + int32_t nEnd = -1; + + m_pEdit->GetSel(nStart, nEnd); + + CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); + CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); + + return CPVT_WordRange(wpStart, wpEnd); + } + + return CPVT_WordRange(); +} + +CFX_ByteString CPWL_Edit::GetTextAppearanceStream( + const CFX_PointF& ptOffset) const { + CFX_ByteTextBuf sRet; + CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset); + if (sEdit.GetLength() > 0) { + sRet << "BT\n" + << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() + << sEdit.AsStringC() << "ET\n"; + } + return sRet.MakeString(); +} + +CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( + const CFX_PointF& ptOffset) const { + if (m_pEditCaret) + return m_pEditCaret->GetCaretAppearanceStream(ptOffset); + + return CFX_ByteString(); +} + +CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) { + CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); + CPVT_WordPlace wpOld = pIterator->GetAt(); + pIterator->SetAt(wpWord); + + CFX_PointF pt; + CPVT_Word word; + if (pIterator->GetWord(word)) { + pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent); + } + pIterator->SetAt(wpOld); + return pt; +} + +bool CPWL_Edit::IsTextFull() const { + return m_pEdit->IsTextFull(); +} + +float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, + const CFX_FloatRect& rcPlate, + int32_t nCharArray) { + if (pFont && !pFont->IsStandardFont()) { + FX_RECT rcBBox; + pFont->GetFontBBox(rcBBox); + + CFX_FloatRect rcCell = rcPlate; + float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width(); + float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height(); + + return xdiv < ydiv ? xdiv : ydiv; + } + + return 0.0f; +} + +void CPWL_Edit::SetCharArray(int32_t nCharArray) { + if (HasFlag(PES_CHARARRAY) && nCharArray > 0) { + m_pEdit->SetCharArray(nCharArray); + m_pEdit->SetTextOverflow(true, true); + + if (HasFlag(PWS_AUTOFONTSIZE)) { + if (IPVT_FontMap* pFontMap = GetFontMap()) { + float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0), + GetClientRect(), nCharArray); + if (fFontSize > 0.0f) { + m_pEdit->SetAutoFontSize(false, true); + m_pEdit->SetFontSize(fFontSize); + } + } + } + } +} + +void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { + m_pEdit->SetLimitChar(nLimitChar); +} + +void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) { + m_pEdit->Clear(); + m_pEdit->InsertText(wsText, FX_CHARSET_Default); +} + +CFX_FloatRect CPWL_Edit::GetFocusRect() const { + return CFX_FloatRect(); +} + +void CPWL_Edit::ShowVScrollBar(bool bShow) { + if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { + if (bShow) { + if (!pScroll->IsVisible()) { + pScroll->SetVisible(true); + CFX_FloatRect rcWindow = GetWindowRect(); + m_rcOldWindow = rcWindow; + rcWindow.right += PWL_SCROLLBAR_WIDTH; + Move(rcWindow, true, true); + } + } else { + if (pScroll->IsVisible()) { + pScroll->SetVisible(false); + Move(m_rcOldWindow, true, true); + } + } + } +} + +bool CPWL_Edit::IsVScrollBarVisible() const { + if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { + return pScroll->IsVisible(); + } + + return false; +} + +bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { + if (m_bMouseDown) + return true; + + if (nChar == FWL_VKEY_Delete) { + if (m_pFillerNotify) { + bool bRC = true; + bool bExit = false; + CFX_WideString strChange; + CFX_WideString strChangeEx; + + int nSelStart = 0; + int nSelEnd = 0; + GetSel(nSelStart, nSelEnd); + + if (nSelStart == nSelEnd) + nSelEnd = nSelStart + 1; + m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange, + strChangeEx, nSelStart, nSelEnd, true, + bRC, bExit, nFlag); + if (!bRC) + return false; + if (bExit) + return false; + } + } + + bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); + + // In case of implementation swallow the OnKeyDown event. + if (IsProceedtoOnChar(nChar, nFlag)) + return true; + + return bRet; +} + +/** + *In case of implementation swallow the OnKeyDown event. + *If the event is swallowed, implementation may do other unexpected things, + *which is not the control means to do. + */ +bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) { + bool bCtrl = IsCTRLpressed(nFlag); + bool bAlt = IsALTpressed(nFlag); + if (bCtrl && !bAlt) { + // hot keys for edit control. + switch (nKeyCode) { + case 'C': + case 'V': + case 'X': + case 'A': + case 'Z': + return true; + default: + break; + } + } + // control characters. + switch (nKeyCode) { + case FWL_VKEY_Escape: + case FWL_VKEY_Back: + case FWL_VKEY_Return: + case FWL_VKEY_Space: + return true; + default: + return false; + } +} + +bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) { + if (m_bMouseDown) + return true; + + bool bRC = true; + bool bExit = false; + + if (!IsCTRLpressed(nFlag)) { + if (m_pFillerNotify) { + CFX_WideString swChange; + + int nSelStart = 0; + int nSelEnd = 0; + GetSel(nSelStart, nSelEnd); + + switch (nChar) { + case FWL_VKEY_Back: + if (nSelStart == nSelEnd) + nSelStart = nSelEnd - 1; + break; + case FWL_VKEY_Return: + break; + default: + swChange += nChar; + break; + } + + CFX_WideString strChangeEx; + m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, + strChangeEx, nSelStart, nSelEnd, true, + bRC, bExit, nFlag); + } + } + + if (!bRC) + return true; + if (bExit) + return false; + + if (IPVT_FontMap* pFontMap = GetFontMap()) { + int32_t nOldCharSet = GetCharSet(); + int32_t nNewCharSet = + pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default); + if (nOldCharSet != nNewCharSet) { + SetCharSet(nNewCharSet); + } + } + + return CPWL_EditCtrl::OnChar(nChar, nFlag); +} + +bool CPWL_Edit::OnMouseWheel(short zDelta, + const CFX_PointF& point, + uint32_t nFlag) { + if (HasFlag(PES_MULTILINE)) { + CFX_PointF ptScroll = GetScrollPos(); + + if (zDelta > 0) { + ptScroll.y += GetFontSize(); + } else { + ptScroll.y -= GetFontSize(); + } + SetScrollPos(ptScroll); + + return true; + } + + return false; +} + +void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace) { + if (HasFlag(PES_SPELLCHECK)) { + m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), + GetLatinWordsRange(place))); + } +} + +void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace) { + if (HasFlag(PES_SPELLCHECK)) { + m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), + GetLatinWordsRange(place))); + } +} + +void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace) { + if (HasFlag(PES_SPELLCHECK)) { + m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), + GetLatinWordsRange(place))); + } +} + +void CPWL_Edit::OnClear(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace) { + if (HasFlag(PES_SPELLCHECK)) { + m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), + GetLatinWordsRange(place))); + } +} + +void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace) { + if (HasFlag(PES_SPELLCHECK)) { + m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), + GetLatinWordsRange(place))); + } +} + +void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace) { + if (HasFlag(PES_SPELLCHECK)) { + m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), + GetLatinWordsRange(place))); + } +} + +CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, + const CPVT_WordRange& wr2) { + return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos), + std::max(wr1.EndPos, wr2.EndPos)); +} + +CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const { + return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false); +} + +CPVT_WordRange CPWL_Edit::GetLatinWordsRange( + const CPVT_WordPlace& place) const { + return GetSameWordsRange(place, true, false); +} + +CPVT_WordRange CPWL_Edit::GetArabicWordsRange( + const CPVT_WordPlace& place) const { + return GetSameWordsRange(place, false, true); +} + +#define PWL_ISARABICWORD(word) \ + ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) + +CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, + bool bLatin, + bool bArabic) const { + CPVT_WordRange range; + + CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); + CPVT_Word wordinfo; + CPVT_WordPlace wpStart(place), wpEnd(place); + pIterator->SetAt(place); + + if (bLatin) { + while (pIterator->NextWord()) { + if (!pIterator->GetWord(wordinfo) || + !FX_EDIT_ISLATINWORD(wordinfo.Word)) { + break; + } + + wpEnd = pIterator->GetAt(); + } + } else if (bArabic) { + while (pIterator->NextWord()) { + if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) + break; + + wpEnd = pIterator->GetAt(); + } + } + + pIterator->SetAt(place); + + if (bLatin) { + do { + if (!pIterator->GetWord(wordinfo) || + !FX_EDIT_ISLATINWORD(wordinfo.Word)) { + break; + } + + wpStart = pIterator->GetAt(); + } while (pIterator->PrevWord()); + } else if (bArabic) { + do { + if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) + break; + + wpStart = pIterator->GetAt(); + } while (pIterator->PrevWord()); + } + + range.Set(wpStart, wpEnd); + return range; +} diff --git a/fpdfsdk/pdfwindow/cpwl_edit.h b/fpdfsdk/pdfwindow/cpwl_edit.h new file mode 100644 index 0000000000..1ed01b9657 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_edit.h @@ -0,0 +1,139 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_EDIT_H_ +#define FPDFSDK_PDFWINDOW_CPWL_EDIT_H_ + +#include "core/fpdfdoc/cpvt_wordrange.h" +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_basic.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" + +class IPWL_Filler_Notify { + public: + virtual ~IPWL_Filler_Notify() {} + + // Must write to |bBottom| and |fPopupRet|. + virtual void QueryWherePopup(void* pPrivateData, + float fPopupMin, + float fPopupMax, + bool* bBottom, + float* fPopupRet) = 0; + virtual void OnBeforeKeyStroke(void* pPrivateData, + CFX_WideString& strChange, + const CFX_WideString& strChangeEx, + int nSelStart, + int nSelEnd, + bool bKeyDown, + bool& bRC, + bool& bExit, + uint32_t nFlag) = 0; +#ifdef PDF_ENABLE_XFA + virtual void OnPopupPreOpen(void* pPrivateData, + bool& bExit, + uint32_t nFlag) = 0; + virtual void OnPopupPostOpen(void* pPrivateData, + bool& bExit, + uint32_t nFlag) = 0; +#endif // PDF_ENABLE_XFA +}; + +class CPWL_Edit : public CPWL_EditCtrl { + public: + CPWL_Edit(); + ~CPWL_Edit() override; + + // CPWL_EditCtrl + CFX_ByteString GetClassName() const override; + void OnDestroy() override; + void OnCreated() override; + void RePosChildWnd() override; + CFX_FloatRect GetClientRect() const override; + void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; + void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) override; + bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + bool OnMouseWheel(short zDelta, + const CFX_PointF& point, + uint32_t nFlag) override; + bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; + bool OnChar(uint16_t nChar, uint32_t nFlag) override; + CFX_FloatRect GetFocusRect() const override; + void OnSetFocus() override; + void OnKillFocus() override; + + void SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat = PEAV_TOP, + bool bPaint = true); // 0:top 1:bottom 2:center + + void SetCharArray(int32_t nCharArray); + void SetLimitChar(int32_t nLimitChar); + + void SetCharSpace(float fCharSpace); + + bool CanSelectAll() const; + bool CanClear() const; + bool CanCopy() const; + bool CanCut() const; + + void CutText(); + + void SetText(const CFX_WideString& csText); + void ReplaceSel(const CFX_WideString& csText); + + CFX_ByteString GetTextAppearanceStream(const CFX_PointF& ptOffset) const; + CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset) const; + CFX_ByteString GetSelectAppearanceStream(const CFX_PointF& ptOffset) const; + + bool IsTextFull() const; + + static float GetCharArrayAutoFontSize(CPDF_Font* pFont, + const CFX_FloatRect& rcPlate, + int32_t nCharArray); + + void SetFillerNotify(IPWL_Filler_Notify* pNotify) { + m_pFillerNotify = pNotify; + } + + bool IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag); + void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } + + void OnInsertWord(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace); + void OnInsertReturn(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace); + void OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace); + void OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace); + void OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace); + void OnInsertText(const CPVT_WordPlace& place, + const CPVT_WordPlace& oldplace); + + private: + CPVT_WordRange GetSelectWordRange() const; + virtual void ShowVScrollBar(bool bShow); + bool IsVScrollBarVisible() const; + void SetParamByFlag(); + + float GetCharArrayAutoFontSize(int32_t nCharArray); + CFX_PointF GetWordRightBottomPoint(const CPVT_WordPlace& wpWord); + + CPVT_WordRange CombineWordRange(const CPVT_WordRange& wr1, + const CPVT_WordRange& wr2); + CPVT_WordRange GetLatinWordsRange(const CFX_PointF& point) const; + CPVT_WordRange GetLatinWordsRange(const CPVT_WordPlace& place) const; + CPVT_WordRange GetArabicWordsRange(const CPVT_WordPlace& place) const; + CPVT_WordRange GetSameWordsRange(const CPVT_WordPlace& place, + bool bLatin, + bool bArabic) const; + + bool m_bFocus; + CFX_FloatRect m_rcOldWindow; + CFX_UnownedPtr m_pFillerNotify; + CFX_UnownedPtr m_pFormFiller; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_EDIT_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp new file mode 100644 index 0000000000..9c22cead58 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp @@ -0,0 +1,483 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" + +#include "core/fpdfdoc/cpvt_section.h" +#include "core/fpdfdoc/cpvt_word.h" +#include "core/fxge/fx_font.h" +#include "fpdfsdk/fxedit/fxet_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_caret.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "public/fpdf_fwlevent.h" + +CPWL_EditCtrl::CPWL_EditCtrl() + : m_pEdit(new CFX_Edit), + m_pEditCaret(nullptr), + m_bMouseDown(false), + m_nCharSet(FX_CHARSET_Default) {} + +CPWL_EditCtrl::~CPWL_EditCtrl() {} + +void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { + cp.eCursorType = FXCT_VBEAM; +} + +void CPWL_EditCtrl::OnCreated() { + SetFontSize(GetCreationParam().fFontSize); + + m_pEdit->SetFontMap(GetFontMap()); + m_pEdit->SetNotify(this); + m_pEdit->Initialize(); +} + +bool CPWL_EditCtrl::IsWndHorV() { + CFX_Matrix mt = GetWindowMatrix(); + return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y; +} + +void CPWL_EditCtrl::SetCursor() { + if (IsValid()) { + if (CFX_SystemHandler* pSH = GetSystemHandler()) { + if (IsWndHorV()) + pSH->SetCursor(FXCT_VBEAM); + else + pSH->SetCursor(FXCT_HBEAM); + } + } +} + +void CPWL_EditCtrl::RePosChildWnd() { + m_pEdit->SetPlateRect(GetClientRect()); +} + +void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam, + intptr_t lParam) { + CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); + + switch (msg) { + case PNM_SETSCROLLINFO: + switch (wParam) { + case SBT_VSCROLL: + if (CPWL_Wnd* pChild = GetVScrollBar()) { + pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); + } + break; + } + break; + case PNM_SETSCROLLPOS: + switch (wParam) { + case SBT_VSCROLL: + if (CPWL_Wnd* pChild = GetVScrollBar()) { + pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); + } + break; + } + break; + case PNM_SCROLLWINDOW: { + float fPos = *(float*)lParam; + switch (wParam) { + case SBT_VSCROLL: + m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos)); + break; + } + } break; + case PNM_SETCARETINFO: { + if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { + SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); + } + } break; + } +} + +void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { + if (!IsReadOnly()) + CreateEditCaret(cp); +} + +void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { + if (m_pEditCaret) + return; + + m_pEditCaret = new CPWL_Caret; + m_pEditCaret->SetInvalidRect(GetClientRect()); + + PWL_CREATEPARAM ecp = cp; + ecp.pParentWnd = this; + ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; + ecp.dwBorderWidth = 0; + ecp.nBorderStyle = BorderStyle::SOLID; + ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); + + m_pEditCaret->Create(ecp); +} + +void CPWL_EditCtrl::SetFontSize(float fFontSize) { + m_pEdit->SetFontSize(fFontSize); +} + +float CPWL_EditCtrl::GetFontSize() const { + return m_pEdit->GetFontSize(); +} + +bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) { + if (m_bMouseDown) + return true; + + bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag); + + // FILTER + switch (nChar) { + default: + return false; + case FWL_VKEY_Delete: + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Left: + case FWL_VKEY_Right: + case FWL_VKEY_Home: + case FWL_VKEY_End: + case FWL_VKEY_Insert: + case 'C': + case 'V': + case 'X': + case 'A': + case 'Z': + case 'c': + case 'v': + case 'x': + case 'a': + case 'z': + break; + } + + if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected()) + nChar = FWL_VKEY_Unknown; + + switch (nChar) { + case FWL_VKEY_Delete: + Delete(); + return true; + case FWL_VKEY_Insert: + if (IsSHIFTpressed(nFlag)) + PasteText(); + return true; + case FWL_VKEY_Up: + m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false); + return true; + case FWL_VKEY_Down: + m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false); + return true; + case FWL_VKEY_Left: + m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false); + return true; + case FWL_VKEY_Right: + m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false); + return true; + case FWL_VKEY_Home: + m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + return true; + case FWL_VKEY_End: + m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + return true; + case FWL_VKEY_Unknown: + if (!IsSHIFTpressed(nFlag)) + Clear(); + else + CutText(); + return true; + default: + break; + } + + return bRet; +} + +bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { + if (m_bMouseDown) + return true; + + CPWL_Wnd::OnChar(nChar, nFlag); + + // FILTER + switch (nChar) { + case 0x0A: + case 0x1B: + return false; + default: + break; + } + + bool bCtrl = IsCTRLpressed(nFlag); + bool bAlt = IsALTpressed(nFlag); + bool bShift = IsSHIFTpressed(nFlag); + + uint16_t word = nChar; + + if (bCtrl && !bAlt) { + switch (nChar) { + case 'C' - 'A' + 1: + CopyText(); + return true; + case 'V' - 'A' + 1: + PasteText(); + return true; + case 'X' - 'A' + 1: + CutText(); + return true; + case 'A' - 'A' + 1: + SelectAll(); + return true; + case 'Z' - 'A' + 1: + if (bShift) + Redo(); + else + Undo(); + return true; + default: + if (nChar < 32) + return false; + } + } + + if (IsReadOnly()) + return true; + + if (m_pEdit->IsSelected() && word == FWL_VKEY_Back) + word = FWL_VKEY_Unknown; + + Clear(); + + switch (word) { + case FWL_VKEY_Back: + Backspace(); + break; + case FWL_VKEY_Return: + InsertReturn(); + break; + case FWL_VKEY_Unknown: + break; + default: + InsertWord(word, GetCharSet()); + break; + } + + return true; +} + +bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (ClientHitTest(point)) { + if (m_bMouseDown) + InvalidateRect(); + + m_bMouseDown = true; + SetCapture(); + + m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + } + + return true; +} + +bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (m_bMouseDown) { + // can receive keybord message + if (ClientHitTest(point) && !IsFocused()) + SetFocus(); + + ReleaseCapture(); + m_bMouseDown = false; + } + + return true; +} + +bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnMouseMove(point, nFlag); + + if (m_bMouseDown) + m_pEdit->OnMouseMove(point, false, false); + + return true; +} + +void CPWL_EditCtrl::SetEditCaret(bool bVisible) { + CFX_PointF ptHead; + CFX_PointF ptFoot; + if (bVisible) + GetCaretInfo(&ptHead, &ptFoot); + + CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); + IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); +} + +void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const { + CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); + pIterator->SetAt(m_pEdit->GetCaret()); + CPVT_Word word; + CPVT_Line line; + if (pIterator->GetWord(word)) { + ptHead->x = word.ptWord.x + word.fWidth; + ptHead->y = word.ptWord.y + word.fAscent; + ptFoot->x = word.ptWord.x + word.fWidth; + ptFoot->y = word.ptWord.y + word.fDescent; + } else if (pIterator->GetLine(line)) { + ptHead->x = line.ptLine.x; + ptHead->y = line.ptLine.y + line.fLineAscent; + ptFoot->x = line.ptLine.x; + ptFoot->y = line.ptLine.y + line.fLineDescent; + } +} + +void CPWL_EditCtrl::SetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot) { + if (m_pEditCaret) { + if (!IsFocused() || m_pEdit->IsSelected()) + bVisible = false; + + m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); + } +} + +CFX_WideString CPWL_EditCtrl::GetText() const { + return m_pEdit->GetText(); +} + +void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) { + m_pEdit->SetSel(nStartChar, nEndChar); +} + +void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { + m_pEdit->GetSel(nStartChar, nEndChar); +} + +void CPWL_EditCtrl::Clear() { + if (!IsReadOnly()) + m_pEdit->Clear(); +} + +void CPWL_EditCtrl::SelectAll() { + m_pEdit->SelectAll(); +} + +void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) { + m_pEdit->SetScrollPos(point); +} + +CFX_PointF CPWL_EditCtrl::GetScrollPos() const { + return m_pEdit->GetScrollPos(); +} + +void CPWL_EditCtrl::CopyText() {} + +void CPWL_EditCtrl::PasteText() {} + +void CPWL_EditCtrl::CutText() {} + +void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {} + +void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { + if (!IsReadOnly()) + m_pEdit->InsertWord(word, nCharset); +} + +void CPWL_EditCtrl::InsertReturn() { + if (!IsReadOnly()) + m_pEdit->InsertReturn(); +} + +void CPWL_EditCtrl::Delete() { + if (!IsReadOnly()) + m_pEdit->Delete(); +} + +void CPWL_EditCtrl::Backspace() { + if (!IsReadOnly()) + m_pEdit->Backspace(); +} + +bool CPWL_EditCtrl::CanUndo() const { + return !IsReadOnly() && m_pEdit->CanUndo(); +} + +bool CPWL_EditCtrl::CanRedo() const { + return !IsReadOnly() && m_pEdit->CanRedo(); +} + +void CPWL_EditCtrl::Redo() { + if (CanRedo()) + m_pEdit->Redo(); +} + +void CPWL_EditCtrl::Undo() { + if (CanUndo()) + m_pEdit->Undo(); +} + +void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin, + float fPlateMax, + float fContentMin, + float fContentMax, + float fSmallStep, + float fBigStep) { + PWL_SCROLL_INFO Info; + + Info.fPlateWidth = fPlateMax - fPlateMin; + Info.fContentMin = fContentMin; + Info.fContentMax = fContentMax; + Info.fSmallStep = fSmallStep; + Info.fBigStep = fBigStep; + + OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); + + if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || + IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { + ShowVScrollBar(false); + } else { + ShowVScrollBar(true); + } +} + +void CPWL_EditCtrl::IOnSetScrollPosY(float fy) { + OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); +} + +void CPWL_EditCtrl::IOnSetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot, + const CPVT_WordPlace& place) { + PWL_CARET_INFO cInfo; + cInfo.bVisible = bVisible; + cInfo.ptHead = ptHead; + cInfo.ptFoot = ptFoot; + + OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr); +} + +void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { + InvalidateRect(pRect); +} + +int32_t CPWL_EditCtrl::GetCharSet() const { + return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet; +} + +void CPWL_EditCtrl::SetReadyToInput() { + if (m_bMouseDown) { + ReleaseCapture(); + m_bMouseDown = false; + } +} diff --git a/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h new file mode 100644 index 0000000000..59bb623776 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h @@ -0,0 +1,108 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_EDIT_CTRL_H_ +#define FPDFSDK_PDFWINDOW_CPWL_EDIT_CTRL_H_ + +#include + +#include "core/fxcrt/fx_string.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CFX_Edit; +class CPWL_Caret; +struct CPVT_WordPlace; + +enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT }; + +enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM }; + +class CPWL_EditCtrl : public CPWL_Wnd { + public: + CPWL_EditCtrl(); + ~CPWL_EditCtrl() override; + + CFX_WideString GetText() const; + void SetSel(int32_t nStartChar, int32_t nEndChar); + void GetSel(int32_t& nStartChar, int32_t& nEndChar) const; + void Clear(); + void SelectAll(); + + CFX_PointF GetScrollPos() const; + void SetScrollPos(const CFX_PointF& point); + + void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; } + int32_t GetCharSet() const; + + bool CanUndo() const; + bool CanRedo() const; + void Redo(); + void Undo(); + + void SetReadyToInput(); + + // CPWL_Wnd + void OnCreate(PWL_CREATEPARAM& cp) override; + void OnCreated() override; + bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; + bool OnChar(uint16_t nChar, uint32_t nFlag) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; + void OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam = 0, + intptr_t lParam = 0) override; + void CreateChildWnd(const PWL_CREATEPARAM& cp) override; + void RePosChildWnd() override; + void SetFontSize(float fFontSize) override; + float GetFontSize() const override; + void SetCursor() override; + + void IOnSetScrollInfoY(float fPlateMin, + float fPlateMax, + float fContentMin, + float fContentMax, + float fSmallStep, + float fBigStep); + void IOnSetScrollPosY(float fy); + void IOnSetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot, + const CPVT_WordPlace& place); + void IOnInvalidateRect(CFX_FloatRect* pRect); + + protected: + void CopyText(); + void PasteText(); + void CutText(); + void ShowVScrollBar(bool bShow); + void InsertWord(uint16_t word, int32_t nCharset); + void InsertReturn(); + + bool IsWndHorV(); + + void Delete(); + void Backspace(); + + void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const; + void SetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot); + + void SetEditCaret(bool bVisible); + + std::unique_ptr m_pEdit; + CPWL_Caret* m_pEditCaret; + bool m_bMouseDown; + + private: + void CreateEditCaret(const PWL_CREATEPARAM& cp); + + int32_t m_nCharSet; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_EDIT_CTRL_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_font_map.cpp b/fpdfsdk/pdfwindow/cpwl_font_map.cpp new file mode 100644 index 0000000000..f0c74ba0ce --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_font_map.cpp @@ -0,0 +1,413 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_font_map.h" + +#include + +#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/font/cpdf_font.h" +#include "core/fpdfapi/font/cpdf_fontencoding.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_parser.h" +#include "core/fpdfdoc/ipvt_fontmap.h" +#include "core/fxcrt/fx_codepage.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" + +namespace { + +const char kDefaultFontName[] = "Helvetica"; + +const char* const g_sDEStandardFontName[] = {"Courier", + "Courier-Bold", + "Courier-BoldOblique", + "Courier-Oblique", + "Helvetica", + "Helvetica-Bold", + "Helvetica-BoldOblique", + "Helvetica-Oblique", + "Times-Roman", + "Times-Bold", + "Times-Italic", + "Times-BoldItalic", + "Symbol", + "ZapfDingbats"}; + +} // namespace + +CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler) + : m_pSystemHandler(pSystemHandler) { + ASSERT(m_pSystemHandler); +} + +CPWL_FontMap::~CPWL_FontMap() { + Empty(); +} + +CPDF_Document* CPWL_FontMap::GetDocument() { + if (!m_pPDFDoc) { + if (CPDF_ModuleMgr::Get()) { + m_pPDFDoc = pdfium::MakeUnique(nullptr); + m_pPDFDoc->CreateNewDoc(); + } + } + return m_pPDFDoc.get(); +} + +CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) { + if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex]) + return m_Data[nFontIndex]->pFont; + + return nullptr; +} + +CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) { + if (pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex]) + return m_Data[nFontIndex]->sFontName; + + return CFX_ByteString(); +} + +bool CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) { + return pdfium::IndexInBounds(m_Data, nFontIndex) && m_Data[nFontIndex] && + CharCodeFromUnicode(nFontIndex, word) >= 0; +} + +int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word, + int32_t nCharset, + int32_t nFontIndex) { + if (nFontIndex > 0) { + if (KnowWord(nFontIndex, word)) + return nFontIndex; + } else { + if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) { + if (nCharset == FX_CHARSET_Default || + pData->nCharset == FX_CHARSET_Symbol || nCharset == pData->nCharset) { + if (KnowWord(0, word)) + return 0; + } + } + } + + int32_t nNewFontIndex = + GetFontIndex(GetNativeFontName(nCharset), nCharset, true); + if (nNewFontIndex >= 0) { + if (KnowWord(nNewFontIndex, word)) + return nNewFontIndex; + } + nNewFontIndex = GetFontIndex("Arial Unicode MS", FX_CHARSET_Default, false); + if (nNewFontIndex >= 0) { + if (KnowWord(nNewFontIndex, word)) + return nNewFontIndex; + } + return -1; +} + +int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) { + if (!pdfium::IndexInBounds(m_Data, nFontIndex)) + return -1; + + CPWL_FontMap_Data* pData = m_Data[nFontIndex].get(); + if (!pData || !pData->pFont) + return -1; + + if (pData->pFont->IsUnicodeCompatible()) + return pData->pFont->CharCodeFromUnicode(word); + + return word < 0xFF ? word : -1; +} + +CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) { + for (const auto& pData : m_NativeFont) { + if (pData && pData->nCharset == nCharset) + return pData->sFontName; + } + + CFX_ByteString sNew = GetNativeFont(nCharset); + if (sNew.IsEmpty()) + return CFX_ByteString(); + + auto pNewData = pdfium::MakeUnique(); + pNewData->nCharset = nCharset; + pNewData->sFontName = sNew; + m_NativeFont.push_back(std::move(pNewData)); + return sNew; +} + +void CPWL_FontMap::Empty() { + m_Data.clear(); + m_NativeFont.clear(); +} + +void CPWL_FontMap::Initialize() { + GetFontIndex(kDefaultFontName, FX_CHARSET_ANSI, false); +} + +bool CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) { + for (size_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) { + if (sFontName == g_sDEStandardFontName[i]) + return true; + } + + return false; +} + +int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, + int32_t nCharset) { + int32_t i = 0; + for (const auto& pData : m_Data) { + if (pData && + (nCharset == FX_CHARSET_Default || nCharset == pData->nCharset) && + (sFontName.IsEmpty() || pData->sFontName == sFontName)) { + return i; + } + ++i; + } + return -1; +} + +int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, + int32_t nCharset, + bool bFind) { + int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset); + if (nFontIndex >= 0) + return nFontIndex; + + CFX_ByteString sAlias; + CPDF_Font* pFont = bFind ? FindFontSameCharset(&sAlias, nCharset) : nullptr; + if (!pFont) { + CFX_ByteString sTemp = sFontName; + pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); + sAlias = EncodeFontAlias(sTemp, nCharset); + } + AddedFont(pFont, sAlias); + return AddFontData(pFont, sAlias, nCharset); +} + +CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString* sFontAlias, + int32_t nCharset) { + return nullptr; +} + +int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont, + const CFX_ByteString& sFontAlias, + int32_t nCharset) { + auto pNewData = pdfium::MakeUnique(); + pNewData->pFont = pFont; + pNewData->sFontName = sFontAlias; + pNewData->nCharset = nCharset; + m_Data.push_back(std::move(pNewData)); + return pdfium::CollectionSize(m_Data) - 1; +} + +void CPWL_FontMap::AddedFont(CPDF_Font* pFont, + const CFX_ByteString& sFontAlias) {} + +CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { + if (nCharset == FX_CHARSET_Default) + nCharset = GetNativeCharset(); + + CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); + if (!m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) + return CFX_ByteString(); + + return sFontName; +} + +CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, + CFX_ByteString& sFontName, + uint8_t nCharset) { + if (IsStandardFont(sFontName)) + return AddStandardFont(pDoc, sFontName); + + return AddSystemFont(pDoc, sFontName, nCharset); +} + +CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, + CFX_ByteString& sFontName) { + if (!pDoc) + return nullptr; + + CPDF_Font* pFont = nullptr; + + if (sFontName == "ZapfDingbats") { + pFont = pDoc->AddStandardFont(sFontName.c_str(), nullptr); + } else { + CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI); + pFont = pDoc->AddStandardFont(sFontName.c_str(), &fe); + } + + return pFont; +} + +CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, + CFX_ByteString& sFontName, + uint8_t nCharset) { + if (!pDoc) + return nullptr; + + if (sFontName.IsEmpty()) + sFontName = GetNativeFont(nCharset); + if (nCharset == FX_CHARSET_Default) + nCharset = GetNativeCharset(); + + return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, + nCharset); +} + +CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, + int32_t nCharset) { + CFX_ByteString sPostfix; + sPostfix.Format("_%02X", nCharset); + return EncodeFontAlias(sFontName) + sPostfix; +} + +CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { + CFX_ByteString sRet = sFontName; + sRet.Remove(' '); + return sRet; +} + +const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const { + return pdfium::IndexInBounds(m_Data, nIndex) ? m_Data[nIndex].get() : nullptr; +} + +int32_t CPWL_FontMap::GetNativeCharset() { + uint8_t nCharset = FX_CHARSET_ANSI; + int32_t iCodePage = FXSYS_GetACP(); + switch (iCodePage) { + case FX_CODEPAGE_ShiftJIS: + nCharset = FX_CHARSET_ShiftJIS; + break; + case FX_CODEPAGE_ChineseSimplified: + nCharset = FX_CHARSET_ChineseSimplified; + break; + case FX_CODEPAGE_ChineseTraditional: + nCharset = FX_CHARSET_ChineseTraditional; + break; + case FX_CODEPAGE_MSWin_WesternEuropean: + nCharset = FX_CHARSET_ANSI; + break; + case FX_CODEPAGE_MSDOS_Thai: + nCharset = FX_CHARSET_Thai; + break; + case FX_CODEPAGE_Hangul: + nCharset = FX_CHARSET_Hangul; + break; + case FX_CODEPAGE_UTF16LE: + nCharset = FX_CHARSET_ANSI; + break; + case FX_CODEPAGE_MSWin_EasternEuropean: + nCharset = FX_CHARSET_MSWin_EasternEuropean; + break; + case FX_CODEPAGE_MSWin_Cyrillic: + nCharset = FX_CHARSET_MSWin_Cyrillic; + break; + case FX_CODEPAGE_MSWin_Greek: + nCharset = FX_CHARSET_MSWin_Greek; + break; + case FX_CODEPAGE_MSWin_Turkish: + nCharset = FX_CHARSET_MSWin_Turkish; + break; + case FX_CODEPAGE_MSWin_Hebrew: + nCharset = FX_CHARSET_MSWin_Hebrew; + break; + case FX_CODEPAGE_MSWin_Arabic: + nCharset = FX_CHARSET_MSWin_Arabic; + break; + case FX_CODEPAGE_MSWin_Baltic: + nCharset = FX_CHARSET_MSWin_Baltic; + break; + case FX_CODEPAGE_MSWin_Vietnamese: + nCharset = FX_CHARSET_MSWin_Vietnamese; + break; + case FX_CODEPAGE_Johab: + nCharset = FX_CHARSET_Johab; + break; + } + return nCharset; +} + +const FPDF_CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { + {FX_CHARSET_ANSI, "Helvetica"}, + {FX_CHARSET_ChineseSimplified, "SimSun"}, + {FX_CHARSET_ChineseTraditional, "MingLiU"}, + {FX_CHARSET_ShiftJIS, "MS Gothic"}, + {FX_CHARSET_Hangul, "Batang"}, + {FX_CHARSET_MSWin_Cyrillic, "Arial"}, +#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ + _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + {FX_CHARSET_MSWin_EasternEuropean, "Arial"}, +#else + {FX_CHARSET_MSWin_EasternEuropean, "Tahoma"}, +#endif + {FX_CHARSET_MSWin_Arabic, "Arial"}, + {-1, nullptr}}; + +CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { + int i = 0; + while (defaultTTFMap[i].charset != -1) { + if (nCharset == defaultTTFMap[i].charset) + return defaultTTFMap[i].fontname; + ++i; + } + return ""; +} + +int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) { + // to avoid CJK Font to show ASCII + if (word < 0x7F) + return FX_CHARSET_ANSI; + // follow the old charset + if (nOldCharset != FX_CHARSET_Default) + return nOldCharset; + + // find new charset + if ((word >= 0x4E00 && word <= 0x9FA5) || + (word >= 0xE7C7 && word <= 0xE7F3) || + (word >= 0x3000 && word <= 0x303F) || + (word >= 0x2000 && word <= 0x206F)) { + return FX_CHARSET_ChineseSimplified; + } + + if (((word >= 0x3040) && (word <= 0x309F)) || + ((word >= 0x30A0) && (word <= 0x30FF)) || + ((word >= 0x31F0) && (word <= 0x31FF)) || + ((word >= 0xFF00) && (word <= 0xFFEF))) { + return FX_CHARSET_ShiftJIS; + } + + if (((word >= 0xAC00) && (word <= 0xD7AF)) || + ((word >= 0x1100) && (word <= 0x11FF)) || + ((word >= 0x3130) && (word <= 0x318F))) { + return FX_CHARSET_Hangul; + } + + if (word >= 0x0E00 && word <= 0x0E7F) + return FX_CHARSET_Thai; + + if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF)) + return FX_CHARSET_MSWin_Greek; + + if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) + return FX_CHARSET_MSWin_Arabic; + + if (word >= 0x0590 && word <= 0x05FF) + return FX_CHARSET_MSWin_Hebrew; + + if (word >= 0x0400 && word <= 0x04FF) + return FX_CHARSET_MSWin_Cyrillic; + + if (word >= 0x0100 && word <= 0x024F) + return FX_CHARSET_MSWin_EasternEuropean; + + if (word >= 0x1E00 && word <= 0x1EFF) + return FX_CHARSET_MSWin_Vietnamese; + + return FX_CHARSET_ANSI; +} diff --git a/fpdfsdk/pdfwindow/cpwl_font_map.h b/fpdfsdk/pdfwindow/cpwl_font_map.h new file mode 100644 index 0000000000..de7a944425 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_font_map.h @@ -0,0 +1,96 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_FONT_MAP_H_ +#define FPDFSDK_PDFWINDOW_CPWL_FONT_MAP_H_ + +#include +#include + +#include "core/fpdfdoc/ipvt_fontmap.h" +#include "core/fxcrt/fx_codepage.h" +#include "core/fxge/fx_font.h" +#include "fpdfsdk/fxedit/fx_edit.h" +#include "public/fpdf_sysfontinfo.h" + +class CPDF_Document; +class CFX_SystemHandler; + +struct CPWL_FontMap_Data { + CPDF_Font* pFont; + int32_t nCharset; + CFX_ByteString sFontName; +}; + +struct CPWL_FontMap_Native { + int32_t nCharset; + CFX_ByteString sFontName; +}; + +class CPWL_FontMap : public IPVT_FontMap { + public: + explicit CPWL_FontMap(CFX_SystemHandler* pSystemHandler); + ~CPWL_FontMap() override; + + // IPVT_FontMap + CPDF_Font* GetPDFFont(int32_t nFontIndex) override; + CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) override; + int32_t GetWordFontIndex(uint16_t word, + int32_t nCharset, + int32_t nFontIndex) override; + int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override; + int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override; + + const CPWL_FontMap_Data* GetFontMapData(int32_t nIndex) const; + static int32_t GetNativeCharset(); + CFX_ByteString GetNativeFontName(int32_t nCharset); + + static CFX_ByteString GetDefaultFontByCharset(int32_t nCharset); + static const FPDF_CharsetFontMap defaultTTFMap[]; + + protected: + virtual void Initialize(); + virtual CPDF_Document* GetDocument(); + virtual CPDF_Font* FindFontSameCharset(CFX_ByteString* sFontAlias, + int32_t nCharset); + virtual void AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias); + + bool KnowWord(int32_t nFontIndex, uint16_t word); + + void Empty(); + int32_t GetFontIndex(const CFX_ByteString& sFontName, + int32_t nCharset, + bool bFind); + int32_t AddFontData(CPDF_Font* pFont, + const CFX_ByteString& sFontAlias, + int32_t nCharset = FX_CHARSET_Default); + + CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName, + int32_t nCharset); + CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName); + + std::vector> m_Data; + std::vector> m_NativeFont; + + private: + int32_t FindFont(const CFX_ByteString& sFontName, + int32_t nCharset = FX_CHARSET_Default); + + CFX_ByteString GetNativeFont(int32_t nCharset); + CPDF_Font* AddFontToDocument(CPDF_Document* pDoc, + CFX_ByteString& sFontName, + uint8_t nCharset); + bool IsStandardFont(const CFX_ByteString& sFontName); + CPDF_Font* AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName); + CPDF_Font* AddSystemFont(CPDF_Document* pDoc, + CFX_ByteString& sFontName, + uint8_t nCharset); + + std::unique_ptr m_pPDFDoc; + CFX_UnownedPtr const m_pSystemHandler; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_FONT_MAP_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_icon.cpp b/fpdfsdk/pdfwindow/cpwl_icon.cpp new file mode 100644 index 0000000000..1464a09348 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_icon.cpp @@ -0,0 +1,225 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_icon.h" + +#include + +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_stream.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +CPWL_Image::CPWL_Image() : m_pPDFStream(nullptr) {} + +CPWL_Image::~CPWL_Image() {} + +CFX_ByteString CPWL_Image::GetImageAppStream() { + CFX_ByteTextBuf sAppStream; + + CFX_ByteString sAlias = GetImageAlias(); + CFX_FloatRect rcPlate = GetClientRect(); + CFX_Matrix mt; + mt.SetReverse(GetImageMatrix()); + + float fHScale = 1.0f; + float fVScale = 1.0f; + GetScale(fHScale, fVScale); + + float fx = 0.0f; + float fy = 0.0f; + GetImageOffset(fx, fy); + + if (m_pPDFStream && sAlias.GetLength() > 0) { + sAppStream << "q\n"; + sAppStream << rcPlate.left << " " << rcPlate.bottom << " " + << rcPlate.right - rcPlate.left << " " + << rcPlate.top - rcPlate.bottom << " re W n\n"; + + sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx + << " " << rcPlate.bottom + fy << " cm\n"; + sAppStream << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " " + << mt.e << " " << mt.f << " cm\n"; + + sAppStream << "0 g 0 G 1 w /" << sAlias.AsStringC() << " Do\n" + << "Q\n"; + } + + return sAppStream.MakeString(); +} + +void CPWL_Image::SetPDFStream(CPDF_Stream* pStream) { + m_pPDFStream = pStream; +} + +CPDF_Stream* CPWL_Image::GetPDFStream() const { + return m_pPDFStream.Get(); +} + +void CPWL_Image::GetImageSize(float& fWidth, float& fHeight) { + fWidth = 0.0f; + fHeight = 0.0f; + + if (m_pPDFStream) { + if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { + CFX_FloatRect rect = pDict->GetRectFor("BBox"); + + fWidth = rect.right - rect.left; + fHeight = rect.top - rect.bottom; + } + } +} + +CFX_Matrix CPWL_Image::GetImageMatrix() { + if (m_pPDFStream) { + if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { + return pDict->GetMatrixFor("Matrix"); + } + } + + return CFX_Matrix(); +} + +CFX_ByteString CPWL_Image::GetImageAlias() { + if (!m_sImageAlias.IsEmpty()) + return m_sImageAlias; + + if (m_pPDFStream) { + if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { + return pDict->GetStringFor("Name"); + } + } + + return CFX_ByteString(); +} + +void CPWL_Image::SetImageAlias(const char* sImageAlias) { + m_sImageAlias = sImageAlias; +} + +void CPWL_Image::GetScale(float& fHScale, float& fVScale) { + fHScale = 1.0f; + fVScale = 1.0f; +} + +void CPWL_Image::GetImageOffset(float& x, float& y) { + x = 0.0f; + y = 0.0f; +} + +CPWL_Icon::CPWL_Icon() : m_pIconFit(nullptr) {} + +CPWL_Icon::~CPWL_Icon() {} + +CPDF_IconFit* CPWL_Icon::GetIconFit() const { + return m_pIconFit.Get(); +} + +int32_t CPWL_Icon::GetScaleMethod() { + if (m_pIconFit) + return m_pIconFit->GetScaleMethod(); + + return 0; +} + +bool CPWL_Icon::IsProportionalScale() { + if (m_pIconFit) + return m_pIconFit->IsProportionalScale(); + + return false; +} + +void CPWL_Icon::GetIconPosition(float& fLeft, float& fBottom) { + if (m_pIconFit) { + fLeft = 0.0f; + fBottom = 0.0f; + CPDF_Array* pA = m_pIconFit->GetDict() + ? m_pIconFit->GetDict()->GetArrayFor("A") + : nullptr; + if (pA) { + size_t dwCount = pA->GetCount(); + if (dwCount > 0) + fLeft = pA->GetNumberAt(0); + if (dwCount > 1) + fBottom = pA->GetNumberAt(1); + } + } else { + fLeft = 0.0f; + fBottom = 0.0f; + } +} + +void CPWL_Icon::GetScale(float& fHScale, float& fVScale) { + fHScale = 1.0f; + fVScale = 1.0f; + + if (m_pPDFStream) { + float fImageWidth, fImageHeight; + float fPlateWidth, fPlateHeight; + + CFX_FloatRect rcPlate = GetClientRect(); + fPlateWidth = rcPlate.right - rcPlate.left; + fPlateHeight = rcPlate.top - rcPlate.bottom; + + GetImageSize(fImageWidth, fImageHeight); + + int32_t nScaleMethod = GetScaleMethod(); + + switch (nScaleMethod) { + default: + case 0: + fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); + fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); + break; + case 1: + if (fPlateWidth < fImageWidth) + fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); + if (fPlateHeight < fImageHeight) + fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); + break; + case 2: + if (fPlateWidth > fImageWidth) + fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); + if (fPlateHeight > fImageHeight) + fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); + break; + case 3: + break; + } + + float fMinScale; + if (IsProportionalScale()) { + fMinScale = std::min(fHScale, fVScale); + fHScale = fMinScale; + fVScale = fMinScale; + } + } +} + +void CPWL_Icon::GetImageOffset(float& x, float& y) { + float fLeft, fBottom; + + GetIconPosition(fLeft, fBottom); + x = 0.0f; + y = 0.0f; + + float fImageWidth, fImageHeight; + GetImageSize(fImageWidth, fImageHeight); + + float fHScale, fVScale; + GetScale(fHScale, fVScale); + + float fImageFactWidth = fImageWidth * fHScale; + float fImageFactHeight = fImageHeight * fVScale; + + float fPlateWidth, fPlateHeight; + CFX_FloatRect rcPlate = GetClientRect(); + fPlateWidth = rcPlate.right - rcPlate.left; + fPlateHeight = rcPlate.top - rcPlate.bottom; + + x = (fPlateWidth - fImageFactWidth) * fLeft; + y = (fPlateHeight - fImageFactHeight) * fBottom; +} diff --git a/fpdfsdk/pdfwindow/cpwl_icon.h b/fpdfsdk/pdfwindow/cpwl_icon.h new file mode 100644 index 0000000000..c7b8cb4b56 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_icon.h @@ -0,0 +1,58 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_ICON_H_ +#define FPDFSDK_PDFWINDOW_CPWL_ICON_H_ + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_string.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CPWL_Image : public CPWL_Wnd { + public: + CPWL_Image(); + ~CPWL_Image() override; + + virtual CFX_ByteString GetImageAppStream(); + + virtual void GetScale(float& fHScale, float& fVScale); + virtual void GetImageOffset(float& x, float& y); + virtual CPDF_Stream* GetPDFStream() const; + + public: + void SetPDFStream(CPDF_Stream* pStream); + void GetImageSize(float& fWidth, float& fHeight); + CFX_Matrix GetImageMatrix(); + CFX_ByteString GetImageAlias(); + void SetImageAlias(const char* sImageAlias); + + protected: + CFX_UnownedPtr m_pPDFStream; + CFX_ByteString m_sImageAlias; +}; + +class CPWL_Icon : public CPWL_Image { + public: + CPWL_Icon(); + ~CPWL_Icon() override; + + virtual CPDF_IconFit* GetIconFit() const; + + // CPWL_Image + void GetScale(float& fHScale, float& fVScale) override; + void GetImageOffset(float& x, float& y) override; + + int32_t GetScaleMethod(); + bool IsProportionalScale(); + void GetIconPosition(float& fLeft, float& fBottom); + + void SetIconFit(CPDF_IconFit* pIconFit) { m_pIconFit = pIconFit; } + + private: + CFX_UnownedPtr m_pIconFit; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_ICON_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_list_box.cpp b/fpdfsdk/pdfwindow/cpwl_list_box.cpp new file mode 100644 index 0000000000..5c161bfdda --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_list_box.cpp @@ -0,0 +1,460 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_list_box.h" + +#include "fpdfsdk/fxedit/fxet_edit.h" +#include "fpdfsdk/fxedit/fxet_list.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "public/fpdf_fwlevent.h" +#include "third_party/base/ptr_util.h" + +CPWL_List_Notify::CPWL_List_Notify(CPWL_ListBox* pList) : m_pList(pList) { + ASSERT(m_pList); +} + +CPWL_List_Notify::~CPWL_List_Notify() {} + +void CPWL_List_Notify::IOnSetScrollInfoY(float fPlateMin, + float fPlateMax, + float fContentMin, + float fContentMax, + float fSmallStep, + float fBigStep) { + PWL_SCROLL_INFO Info; + + Info.fPlateWidth = fPlateMax - fPlateMin; + Info.fContentMin = fContentMin; + Info.fContentMax = fContentMax; + Info.fSmallStep = fSmallStep; + Info.fBigStep = fBigStep; + + m_pList->OnNotify(m_pList.Get(), PNM_SETSCROLLINFO, SBT_VSCROLL, + reinterpret_cast(&Info)); + + if (CPWL_ScrollBar* pScroll = m_pList->GetVScrollBar()) { + if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || + IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { + if (pScroll->IsVisible()) { + pScroll->SetVisible(false); + m_pList->RePosChildWnd(); + } + } else { + if (!pScroll->IsVisible()) { + pScroll->SetVisible(true); + m_pList->RePosChildWnd(); + } + } + } +} + +void CPWL_List_Notify::IOnSetScrollPosY(float fy) { + m_pList->OnNotify(m_pList.Get(), PNM_SETSCROLLPOS, SBT_VSCROLL, + reinterpret_cast(&fy)); +} + +void CPWL_List_Notify::IOnInvalidateRect(CFX_FloatRect* pRect) { + m_pList->InvalidateRect(pRect); +} + +CPWL_ListBox::CPWL_ListBox() + : m_pList(new CFX_ListCtrl), + m_bMouseDown(false), + m_bHoverSel(false), + m_pFillerNotify(nullptr) {} + +CPWL_ListBox::~CPWL_ListBox() {} + +CFX_ByteString CPWL_ListBox::GetClassName() const { + return "CPWL_ListBox"; +} + +void CPWL_ListBox::OnCreated() { + m_pList->SetFontMap(GetFontMap()); + m_pListNotify = pdfium::MakeUnique(this); + m_pList->SetNotify(m_pListNotify.get()); + + SetHoverSel(HasFlag(PLBS_HOVERSEL)); + m_pList->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL)); + m_pList->SetFontSize(GetCreationParam().fFontSize); + + m_bHoverSel = HasFlag(PLBS_HOVERSEL); +} + +void CPWL_ListBox::OnDestroy() { + // Make sure the notifier is removed from the list as we are about to + // destroy the notifier and don't want to leave a dangling pointer. + m_pList->SetNotify(nullptr); + m_pListNotify.reset(); +} + +void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + CPWL_Wnd::GetThisAppearanceStream(sAppStream); + + CFX_ByteTextBuf sListItems; + + CFX_FloatRect rcPlate = m_pList->GetPlateRect(); + for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { + CFX_FloatRect rcItem = m_pList->GetItemRect(i); + + if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) + continue; + + CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); + if (m_pList->IsItemSelected(i)) { + sListItems << CPWL_Utils::GetRectFillAppStream(rcItem, + PWL_DEFAULT_SELBACKCOLOR) + .AsStringC(); + CFX_ByteString sItem = + CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset); + if (sItem.GetLength() > 0) { + sListItems << "BT\n" + << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELTEXTCOLOR) + .AsStringC() + << sItem.AsStringC() << "ET\n"; + } + } else { + CFX_ByteString sItem = + CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset); + if (sItem.GetLength() > 0) { + sListItems << "BT\n" + << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() + << sItem.AsStringC() << "ET\n"; + } + } + } + + if (sListItems.GetLength() > 0) { + CFX_ByteTextBuf sClip; + CFX_FloatRect rcClient = GetClientRect(); + + sClip << "q\n"; + sClip << rcClient.left << " " << rcClient.bottom << " " + << rcClient.right - rcClient.left << " " + << rcClient.top - rcClient.bottom << " re W n\n"; + + sClip << sListItems << "Q\n"; + + sAppStream << "/Tx BMC\n" << sClip << "EMC\n"; + } +} + +void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); + + CFX_FloatRect rcPlate = m_pList->GetPlateRect(); + CFX_FloatRect rcList = GetListRect(); + CFX_FloatRect rcClient = GetClientRect(); + + for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { + CFX_FloatRect rcItem = m_pList->GetItemRect(i); + if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) + continue; + + CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); + if (CFX_Edit* pEdit = m_pList->GetItemEdit(i)) { + CFX_FloatRect rcContent = pEdit->GetContentRect(); + if (rcContent.Width() > rcClient.Width()) + rcItem.Intersect(rcList); + else + rcItem.Intersect(rcClient); + } + + if (m_pList->IsItemSelected(i)) { + CFX_SystemHandler* pSysHandler = GetSystemHandler(); + if (pSysHandler && pSysHandler->IsSelectionImplemented()) { + CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), + GetTextColor().ToFXColor(255), rcList, ptOffset, + nullptr, pSysHandler, m_pFormFiller.Get()); + pSysHandler->OutputSelectedRect(m_pFormFiller.Get(), rcItem); + } else { + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, + ArgbEncode(255, 0, 51, 113)); + CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), + ArgbEncode(255, 255, 255, 255), rcList, ptOffset, + nullptr, pSysHandler, m_pFormFiller.Get()); + } + } else { + CFX_SystemHandler* pSysHandler = GetSystemHandler(); + CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), + GetTextColor().ToFXColor(255), rcList, ptOffset, + nullptr, pSysHandler, nullptr); + } + } +} + +bool CPWL_ListBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { + CPWL_Wnd::OnKeyDown(nChar, nFlag); + + switch (nChar) { + default: + return false; + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_Left: + case FWL_VKEY_End: + case FWL_VKEY_Right: + break; + } + + switch (nChar) { + case FWL_VKEY_Up: + m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Down: + m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Home: + m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Left: + m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_End: + m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Right: + m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Delete: + break; + } + + bool bExit = false; + OnNotifySelChanged(true, bExit, nFlag); + + return true; +} + +bool CPWL_ListBox::OnChar(uint16_t nChar, uint32_t nFlag) { + CPWL_Wnd::OnChar(nChar, nFlag); + + if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) + return false; + + bool bExit = false; + OnNotifySelChanged(true, bExit, nFlag); + + return true; +} + +bool CPWL_ListBox::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (ClientHitTest(point)) { + m_bMouseDown = true; + SetFocus(); + SetCapture(); + + m_pList->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + } + + return true; +} + +bool CPWL_ListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (m_bMouseDown) { + ReleaseCapture(); + m_bMouseDown = false; + } + + bool bExit = false; + OnNotifySelChanged(false, bExit, nFlag); + + return true; +} + +void CPWL_ListBox::SetHoverSel(bool bHoverSel) { + m_bHoverSel = bHoverSel; +} + +bool CPWL_ListBox::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnMouseMove(point, nFlag); + + if (m_bHoverSel && !IsCaptureMouse() && ClientHitTest(point)) + m_pList->Select(m_pList->GetItemIndex(point)); + if (m_bMouseDown) + m_pList->OnMouseMove(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + + return true; +} + +void CPWL_ListBox::OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam, + intptr_t lParam) { + CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); + + float fPos; + + switch (msg) { + case PNM_SETSCROLLINFO: + switch (wParam) { + case SBT_VSCROLL: + if (CPWL_Wnd* pChild = GetVScrollBar()) { + pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); + } + break; + } + break; + case PNM_SETSCROLLPOS: + switch (wParam) { + case SBT_VSCROLL: + if (CPWL_Wnd* pChild = GetVScrollBar()) { + pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); + } + break; + } + break; + case PNM_SCROLLWINDOW: + fPos = *(float*)lParam; + switch (wParam) { + case SBT_VSCROLL: + m_pList->SetScrollPos(CFX_PointF(0, fPos)); + break; + } + break; + } +} + +void CPWL_ListBox::KillFocus() { + CPWL_Wnd::KillFocus(); +} + +void CPWL_ListBox::RePosChildWnd() { + CPWL_Wnd::RePosChildWnd(); + + m_pList->SetPlateRect(GetListRect()); +} + +void CPWL_ListBox::OnNotifySelChanged(bool bKeyDown, + bool& bExit, + uint32_t nFlag) { + if (!m_pFillerNotify) + return; + + bool bRC = true; + CFX_WideString swChange = GetText(); + CFX_WideString strChangeEx; + int nSelStart = 0; + int nSelEnd = swChange.GetLength(); + m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, strChangeEx, + nSelStart, nSelEnd, bKeyDown, bRC, bExit, + nFlag); +} + +CFX_FloatRect CPWL_ListBox::GetFocusRect() const { + if (m_pList->IsMultipleSel()) { + CFX_FloatRect rcCaret = m_pList->GetItemRect(m_pList->GetCaret()); + rcCaret.Intersect(GetClientRect()); + return rcCaret; + } + + return CPWL_Wnd::GetFocusRect(); +} + +void CPWL_ListBox::AddString(const CFX_WideString& str) { + m_pList->AddString(str); +} + +CFX_WideString CPWL_ListBox::GetText() const { + return m_pList->GetText(); +} + +void CPWL_ListBox::SetFontSize(float fFontSize) { + m_pList->SetFontSize(fFontSize); +} + +float CPWL_ListBox::GetFontSize() const { + return m_pList->GetFontSize(); +} + +void CPWL_ListBox::Select(int32_t nItemIndex) { + m_pList->Select(nItemIndex); +} + +void CPWL_ListBox::SetCaret(int32_t nItemIndex) { + m_pList->SetCaret(nItemIndex); +} + +void CPWL_ListBox::SetTopVisibleIndex(int32_t nItemIndex) { + m_pList->SetTopItem(nItemIndex); +} + +void CPWL_ListBox::ScrollToListItem(int32_t nItemIndex) { + m_pList->ScrollToListItem(nItemIndex); +} + +void CPWL_ListBox::ResetContent() { + m_pList->Empty(); +} + +void CPWL_ListBox::Reset() { + m_pList->Cancel(); +} + +bool CPWL_ListBox::IsMultipleSel() const { + return m_pList->IsMultipleSel(); +} + +int32_t CPWL_ListBox::GetCaretIndex() const { + return m_pList->GetCaret(); +} + +int32_t CPWL_ListBox::GetCurSel() const { + return m_pList->GetSelect(); +} + +bool CPWL_ListBox::IsItemSelected(int32_t nItemIndex) const { + return m_pList->IsItemSelected(nItemIndex); +} + +int32_t CPWL_ListBox::GetTopVisibleIndex() const { + m_pList->ScrollToListItem(m_pList->GetFirstSelected()); + return m_pList->GetTopItem(); +} + +int32_t CPWL_ListBox::GetCount() const { + return m_pList->GetCount(); +} + +int32_t CPWL_ListBox::FindNext(int32_t nIndex, wchar_t nChar) const { + return m_pList->FindNext(nIndex, nChar); +} + +CFX_FloatRect CPWL_ListBox::GetContentRect() const { + return m_pList->GetContentRect(); +} + +float CPWL_ListBox::GetFirstHeight() const { + return m_pList->GetFirstHeight(); +} + +CFX_FloatRect CPWL_ListBox::GetListRect() const { + return CPWL_Utils::DeflateRect( + GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); +} + +bool CPWL_ListBox::OnMouseWheel(short zDelta, + const CFX_PointF& point, + uint32_t nFlag) { + if (zDelta < 0) + m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + else + m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + + bool bExit = false; + OnNotifySelChanged(false, bExit, nFlag); + return true; +} diff --git a/fpdfsdk/pdfwindow/cpwl_list_box.h b/fpdfsdk/pdfwindow/cpwl_list_box.h new file mode 100644 index 0000000000..6cf37ae40c --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_list_box.h @@ -0,0 +1,118 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_LIST_BOX_H_ +#define FPDFSDK_PDFWINDOW_CPWL_LIST_BOX_H_ + +#include + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "fpdfsdk/fxedit/fx_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CFX_ListCtrl; +class CPWL_List_Notify; +class CPWL_ListBox; +class IPWL_Filler_Notify; +struct CPVT_SecProps; +struct CPVT_WordPlace; +struct CPVT_WordProps; + +class CPWL_List_Notify { + public: + explicit CPWL_List_Notify(CPWL_ListBox* pList); + ~CPWL_List_Notify(); + + void IOnSetScrollInfoY(float fPlateMin, + float fPlateMax, + float fContentMin, + float fContentMax, + float fSmallStep, + float fBigStep); + void IOnSetScrollPosY(float fy); + void IOnInvalidateRect(CFX_FloatRect* pRect); + + void IOnSetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot, + const CPVT_WordPlace& place); + + private: + CFX_UnownedPtr m_pList; +}; + +class CPWL_ListBox : public CPWL_Wnd { + public: + CPWL_ListBox(); + ~CPWL_ListBox() override; + + // CPWL_Wnd + CFX_ByteString GetClassName() const override; + void OnCreated() override; + void OnDestroy() override; + void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; + void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; + bool OnChar(uint16_t nChar, uint32_t nFlag) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; + bool OnMouseWheel(short zDelta, + const CFX_PointF& point, + uint32_t nFlag) override; + void KillFocus() override; + void OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam = 0, + intptr_t lParam = 0) override; + void RePosChildWnd() override; + CFX_FloatRect GetFocusRect() const override; + void SetFontSize(float fFontSize) override; + float GetFontSize() const override; + + virtual CFX_WideString GetText() const; + + void OnNotifySelChanged(bool bKeyDown, bool& bExit, uint32_t nFlag); + + void AddString(const CFX_WideString& str); + void SetTopVisibleIndex(int32_t nItemIndex); + void ScrollToListItem(int32_t nItemIndex); + void ResetContent(); + void Reset(); + void Select(int32_t nItemIndex); + void SetCaret(int32_t nItemIndex); + void SetHoverSel(bool bHoverSel); + + int32_t GetCount() const; + bool IsMultipleSel() const; + int32_t GetCaretIndex() const; + int32_t GetCurSel() const; + bool IsItemSelected(int32_t nItemIndex) const; + int32_t GetTopVisibleIndex() const; + int32_t FindNext(int32_t nIndex, wchar_t nChar) const; + CFX_FloatRect GetContentRect() const; + float GetFirstHeight() const; + CFX_FloatRect GetListRect() const; + + void SetFillerNotify(IPWL_Filler_Notify* pNotify) { + m_pFillerNotify = pNotify; + } + + void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } + + protected: + std::unique_ptr m_pList; + std::unique_ptr m_pListNotify; + bool m_bMouseDown; + bool m_bHoverSel; + CFX_UnownedPtr m_pFillerNotify; + + private: + CFX_UnownedPtr m_pFormFiller; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_LIST_BOX_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp b/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp new file mode 100644 index 0000000000..2f234b2432 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp @@ -0,0 +1,1186 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" + +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +PWL_FLOATRANGE::PWL_FLOATRANGE() { + Default(); +} + +PWL_FLOATRANGE::PWL_FLOATRANGE(float min, float max) { + Set(min, max); +} + +void PWL_FLOATRANGE::Default() { + fMin = 0; + fMax = 0; +} + +void PWL_FLOATRANGE::Set(float min, float max) { + if (min > max) { + fMin = max; + fMax = min; + } else { + fMin = min; + fMax = max; + } +} + +bool PWL_FLOATRANGE::In(float x) const { + return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) && + (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax)); +} + +float PWL_FLOATRANGE::GetWidth() const { + return fMax - fMin; +} + +PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() { + Default(); +} + +void PWL_SCROLL_PRIVATEDATA::Default() { + ScrollRange.Default(); + fScrollPos = ScrollRange.fMin; + fClientWidth = 0; + fBigStep = 10; + fSmallStep = 1; +} + +void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { + ScrollRange.Set(min, max); + + if (IsFloatSmaller(fScrollPos, ScrollRange.fMin)) + fScrollPos = ScrollRange.fMin; + if (IsFloatBigger(fScrollPos, ScrollRange.fMax)) + fScrollPos = ScrollRange.fMax; +} + +void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { + fClientWidth = width; +} + +void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) { + fSmallStep = step; +} + +void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) { + fBigStep = step; +} + +bool PWL_SCROLL_PRIVATEDATA::SetPos(float pos) { + if (ScrollRange.In(pos)) { + fScrollPos = pos; + return true; + } + return false; +} + +void PWL_SCROLL_PRIVATEDATA::AddSmall() { + if (!SetPos(fScrollPos + fSmallStep)) + SetPos(ScrollRange.fMax); +} + +void PWL_SCROLL_PRIVATEDATA::SubSmall() { + if (!SetPos(fScrollPos - fSmallStep)) + SetPos(ScrollRange.fMin); +} + +void PWL_SCROLL_PRIVATEDATA::AddBig() { + if (!SetPos(fScrollPos + fBigStep)) + SetPos(ScrollRange.fMax); +} + +void PWL_SCROLL_PRIVATEDATA::SubBig() { + if (!SetPos(fScrollPos - fBigStep)) + SetPos(ScrollRange.fMin); +} + +CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, + PWL_SBBUTTON_TYPE eButtonType) { + m_eScrollBarType = eScrollBarType; + m_eSBButtonType = eButtonType; + + m_bMouseDown = false; +} + +CPWL_SBButton::~CPWL_SBButton() {} + +CFX_ByteString CPWL_SBButton::GetClassName() const { + return "CPWL_SBButton"; +} + +void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) { + cp.eCursorType = FXCT_ARROW; +} + +void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + CPWL_Wnd::GetThisAppearanceStream(sAppStream); + + if (!IsVisible()) + return; + + CFX_ByteTextBuf sButton; + + CFX_FloatRect rectWnd = GetWindowRect(); + + if (rectWnd.IsEmpty()) + return; + + sAppStream << "q\n"; + + CFX_PointF ptCenter = GetCenterPoint(); + + switch (m_eScrollBarType) { + case SBT_HSCROLL: + switch (m_eSBButtonType) { + case PSBT_MIN: { + CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); + CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y + PWL_TRIANGLE_HALFLEN); + CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y - PWL_TRIANGLE_HALFLEN); + + if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && + rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { + sButton << "0 g\n"; + sButton << pt1.x << " " << pt1.y << " m\n"; + sButton << pt2.x << " " << pt2.y << " l\n"; + sButton << pt3.x << " " << pt3.y << " l\n"; + sButton << pt1.x << " " << pt1.y << " l f\n"; + + sAppStream << sButton; + } + } break; + case PSBT_MAX: { + CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); + CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y + PWL_TRIANGLE_HALFLEN); + CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y - PWL_TRIANGLE_HALFLEN); + + if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && + rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { + sButton << "0 g\n"; + sButton << pt1.x << " " << pt1.y << " m\n"; + sButton << pt2.x << " " << pt2.y << " l\n"; + sButton << pt3.x << " " << pt3.y << " l\n"; + sButton << pt1.x << " " << pt1.y << " l f\n"; + + sAppStream << sButton; + } + } break; + default: + break; + } + break; + case SBT_VSCROLL: + switch (m_eSBButtonType) { + case PSBT_MIN: { + CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, + ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, + ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt3(ptCenter.x, ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); + + if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && + rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { + sButton << "0 g\n"; + sButton << pt1.x << " " << pt1.y << " m\n"; + sButton << pt2.x << " " << pt2.y << " l\n"; + sButton << pt3.x << " " << pt3.y << " l\n"; + sButton << pt1.x << " " << pt1.y << " l f\n"; + + sAppStream << sButton; + } + } break; + case PSBT_MAX: { + CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, + ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, + ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); + CFX_PointF pt3(ptCenter.x, ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); + + if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && + rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { + sButton << "0 g\n"; + sButton << pt1.x << " " << pt1.y << " m\n"; + sButton << pt2.x << " " << pt2.y << " l\n"; + sButton << pt3.x << " " << pt3.y << " l\n"; + sButton << pt1.x << " " << pt1.y << " l f\n"; + + sAppStream << sButton; + } + } break; + default: + break; + } + break; + default: + break; + } + + sAppStream << "Q\n"; +} + +void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + if (!IsVisible()) + return; + + CFX_FloatRect rectWnd = GetWindowRect(); + if (rectWnd.IsEmpty()) + return; + + CFX_PointF ptCenter = GetCenterPoint(); + int32_t nTransparency = GetTransparency(); + + switch (m_eScrollBarType) { + case SBT_HSCROLL: + CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); + switch (m_eSBButtonType) { + case PSBT_MIN: { + CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); + CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y + PWL_TRIANGLE_HALFLEN); + CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y - PWL_TRIANGLE_HALFLEN); + + if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && + rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { + CFX_PathData path; + path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); + path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&path, pUser2Device, nullptr, + PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), + 0, FXFILL_ALTERNATE); + } + } break; + case PSBT_MAX: { + CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); + CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y + PWL_TRIANGLE_HALFLEN); + CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, + ptCenter.y - PWL_TRIANGLE_HALFLEN); + + if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && + rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { + CFX_PathData path; + path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); + path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&path, pUser2Device, nullptr, + PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), + 0, FXFILL_ALTERNATE); + } + } break; + default: + break; + } + break; + case SBT_VSCROLL: + switch (m_eSBButtonType) { + case PSBT_MIN: { + // draw border + CFX_FloatRect rcDraw = rectWnd; + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(nTransparency, 100, 100, 100), + 0.0f); + + // draw inner border + rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(nTransparency, 255, 255, 255), + 1.0f); + + // draw background + + rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); + + if (IsEnabled()) + CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, + nTransparency, 80, 220); + else + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(255, 255, 255, 255)); + + // draw arrow + + if (rectWnd.top - rectWnd.bottom > 6.0f) { + float fX = rectWnd.left + 1.5f; + float fY = rectWnd.bottom; + CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 4.0f), + CFX_PointF(fX + 2.5f, fY + 3.0f), + CFX_PointF(fX + 4.5f, fY + 5.0f), + CFX_PointF(fX + 6.5f, fY + 3.0f), + CFX_PointF(fX + 6.5f, fY + 4.0f), + CFX_PointF(fX + 4.5f, fY + 6.0f), + CFX_PointF(fX + 2.5f, fY + 4.0f)}; + + if (IsEnabled()) + CPWL_Utils::DrawFillArea( + pDevice, pUser2Device, pts, 7, + ArgbEncode(nTransparency, 255, 255, 255)); + else + CPWL_Utils::DrawFillArea( + pDevice, pUser2Device, pts, 7, + PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); + } + } break; + case PSBT_MAX: { + // draw border + CFX_FloatRect rcDraw = rectWnd; + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(nTransparency, 100, 100, 100), + 0.0f); + + // draw inner border + rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(nTransparency, 255, 255, 255), + 1.0f); + + // draw background + rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); + if (IsEnabled()) + CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, + nTransparency, 80, 220); + else + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(255, 255, 255, 255)); + + // draw arrow + + if (rectWnd.top - rectWnd.bottom > 6.0f) { + float fX = rectWnd.left + 1.5f; + float fY = rectWnd.bottom; + + CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 5.0f), + CFX_PointF(fX + 2.5f, fY + 6.0f), + CFX_PointF(fX + 4.5f, fY + 4.0f), + CFX_PointF(fX + 6.5f, fY + 6.0f), + CFX_PointF(fX + 6.5f, fY + 5.0f), + CFX_PointF(fX + 4.5f, fY + 3.0f), + CFX_PointF(fX + 2.5f, fY + 5.0f)}; + + if (IsEnabled()) + CPWL_Utils::DrawFillArea( + pDevice, pUser2Device, pts, 7, + ArgbEncode(nTransparency, 255, 255, 255)); + else + CPWL_Utils::DrawFillArea( + pDevice, pUser2Device, pts, 7, + PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); + } + } break; + case PSBT_POS: { + // draw border + CFX_FloatRect rcDraw = rectWnd; + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(nTransparency, 100, 100, 100), + 0.0f); + + // draw inner border + rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(nTransparency, 255, 255, 255), + 1.0f); + + if (IsEnabled()) { + // draw shadow effect + + CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f); + CFX_PointF ptBottom = + CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f); + + ptTop.x += 1.5f; + ptBottom.x += 1.5f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 210, 210, 210), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 220, 220, 220), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 240, 240, 240), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 240, 240, 240), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 210, 210, 210), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 180, 180, 180), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 150, 150, 150), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 150, 150, 150), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 180, 180, 180), + 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, + ArgbEncode(nTransparency, 210, 210, 210), + 1.0f); + } else { + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, + ArgbEncode(255, 255, 255, 255)); + } + + // draw friction + + if (rectWnd.Height() > 8.0f) { + FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); + if (!IsEnabled()) + crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255); + + float nFrictionWidth = 5.0f; + float nFrictionHeight = 5.5f; + + CFX_PointF ptLeft = + CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f, + ptCenter.y - nFrictionHeight / 2.0f + 0.5f); + CFX_PointF ptRight = + CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f, + ptCenter.y - nFrictionHeight / 2.0f + 0.5f); + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, + crStroke, 1.0f); + + ptLeft.y += 2.0f; + ptRight.y += 2.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, + crStroke, 1.0f); + + ptLeft.y += 2.0f; + ptRight.y += 2.0f; + + CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, + crStroke, 1.0f); + } + } break; + default: + break; + } + break; + default: + break; + } +} + +bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point); + + m_bMouseDown = true; + SetCapture(); + + return true; +} + +bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point); + + m_bMouseDown = false; + ReleaseCapture(); + + return true; +} + +bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnMouseMove(point, nFlag); + + if (CPWL_Wnd* pParent = GetParentWindow()) { + pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point); + } + + return true; +} + +CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType) + : m_sbType(sbType), + m_pMinButton(nullptr), + m_pMaxButton(nullptr), + m_pPosButton(nullptr), + m_bMouseDown(false), + m_bMinOrMax(false), + m_bNotifyForever(true) {} + +CPWL_ScrollBar::~CPWL_ScrollBar() {} + +CFX_ByteString CPWL_ScrollBar::GetClassName() const { + return "CPWL_ScrollBar"; +} + +void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) { + cp.eCursorType = FXCT_ARROW; +} + +void CPWL_ScrollBar::OnDestroy() { + // Until cleanup takes place in the virtual destructor for CPWL_Wnd + // subclasses, implement the virtual OnDestroy method that does the + // cleanup first, then invokes the superclass OnDestroy ... gee, + // like a dtor would. + m_pMinButton.Release(); + m_pMaxButton.Release(); + m_pPosButton.Release(); + CPWL_Wnd::OnDestroy(); +} + +void CPWL_ScrollBar::RePosChildWnd() { + CFX_FloatRect rcClient = GetClientRect(); + CFX_FloatRect rcMinButton, rcMaxButton; + float fBWidth = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + if (rcClient.right - rcClient.left > + PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + + 2) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, + rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, + rcClient.top); + rcMaxButton = + CFX_FloatRect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, + rcClient.bottom, rcClient.right, rcClient.top); + } else { + fBWidth = (rcClient.right - rcClient.left - + PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / + 2; + + if (fBWidth > 0) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, + rcClient.left + fBWidth, rcClient.top); + rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom, + rcClient.right, rcClient.top); + } else { + SetVisible(false); + } + } + break; + case SBT_VSCROLL: + if (IsFloatBigger(rcClient.top - rcClient.bottom, + PWL_SCROLLBAR_BUTTON_WIDTH * 2 + + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)) { + rcMinButton = CFX_FloatRect(rcClient.left, + rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH, + rcClient.right, rcClient.top); + rcMaxButton = + CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, + rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH); + } else { + fBWidth = (rcClient.top - rcClient.bottom - + PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / + 2; + + if (IsFloatBigger(fBWidth, 0)) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth, + rcClient.right, rcClient.top); + rcMaxButton = + CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, + rcClient.bottom + fBWidth); + } else { + SetVisible(false); + } + } + break; + } + + if (m_pMinButton) + m_pMinButton->Move(rcMinButton, true, false); + if (m_pMaxButton) + m_pMaxButton->Move(rcMaxButton, true, false); + MovePosButton(false); +} + +void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + CFX_FloatRect rectWnd = GetWindowRect(); + + if (IsVisible() && !rectWnd.IsEmpty()) { + CFX_ByteTextBuf sButton; + + sButton << "q\n"; + sButton << "0 w\n" + << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), true) + .AsStringC(); + sButton << rectWnd.left << " " << rectWnd.bottom << " " + << rectWnd.right - rectWnd.left << " " + << rectWnd.top - rectWnd.bottom << " re b Q\n"; + + sAppStream << sButton; + } +} + +void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CFX_FloatRect rectWnd = GetWindowRect(); + + if (IsVisible() && !rectWnd.IsEmpty()) { + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd, + GetBackgroundColor(), GetTransparency()); + + CPWL_Utils::DrawStrokeLine( + pDevice, pUser2Device, + CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f), + CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f), + ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); + + CPWL_Utils::DrawStrokeLine( + pDevice, pUser2Device, + CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f), + CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f), + ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); + } +} + +bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (HasFlag(PWS_AUTOTRANSPARENT)) { + if (GetTransparency() != 255) { + SetTransparency(255); + InvalidateRect(); + } + } + + CFX_FloatRect rcMinArea, rcMaxArea; + + if (m_pPosButton && m_pPosButton->IsVisible()) { + CFX_FloatRect rcClient = GetClientRect(); + CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); + + switch (m_sbType) { + case SBT_HSCROLL: + rcMinArea = + CFX_FloatRect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, + rcClient.bottom, rcPosButton.left, rcClient.top); + rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom, + rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, + rcClient.top); + + break; + case SBT_VSCROLL: + rcMinArea = + CFX_FloatRect(rcClient.left, rcPosButton.top, rcClient.right, + rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH); + rcMaxArea = CFX_FloatRect(rcClient.left, + rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH, + rcClient.right, rcPosButton.bottom); + break; + } + + rcMinArea.Normalize(); + rcMaxArea.Normalize(); + + if (rcMinArea.Contains(point)) { + m_sData.SubBig(); + MovePosButton(true); + NotifyScrollWindow(); + } + + if (rcMaxArea.Contains(point)) { + m_sData.AddBig(); + MovePosButton(true); + NotifyScrollWindow(); + } + } + + return true; +} + +bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (HasFlag(PWS_AUTOTRANSPARENT)) { + if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) { + SetTransparency(PWL_SCROLLBAR_TRANSPARENCY); + InvalidateRect(); + } + } + + EndTimer(); + m_bMouseDown = false; + + return true; +} + +void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam, + intptr_t lParam) { + CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); + + switch (msg) { + case PNM_LBUTTONDOWN: + if (pWnd == m_pMinButton) { + OnMinButtonLBDown(*(CFX_PointF*)lParam); + } + + if (pWnd == m_pMaxButton) { + OnMaxButtonLBDown(*(CFX_PointF*)lParam); + } + + if (pWnd == m_pPosButton) { + OnPosButtonLBDown(*(CFX_PointF*)lParam); + } + break; + case PNM_LBUTTONUP: + if (pWnd == m_pMinButton) { + OnMinButtonLBUp(*(CFX_PointF*)lParam); + } + + if (pWnd == m_pMaxButton) { + OnMaxButtonLBUp(*(CFX_PointF*)lParam); + } + + if (pWnd == m_pPosButton) { + OnPosButtonLBUp(*(CFX_PointF*)lParam); + } + break; + case PNM_MOUSEMOVE: + if (pWnd == m_pMinButton) { + OnMinButtonMouseMove(*(CFX_PointF*)lParam); + } + + if (pWnd == m_pMaxButton) { + OnMaxButtonMouseMove(*(CFX_PointF*)lParam); + } + + if (pWnd == m_pPosButton) { + OnPosButtonMouseMove(*(CFX_PointF*)lParam); + } + break; + case PNM_SETSCROLLINFO: { + PWL_SCROLL_INFO* pInfo = reinterpret_cast(lParam); + if (pInfo && *pInfo != m_OriginInfo) { + m_OriginInfo = *pInfo; + float fMax = + pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth; + fMax = fMax > 0.0f ? fMax : 0.0f; + SetScrollRange(0, fMax, pInfo->fPlateWidth); + SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep); + } + } break; + case PNM_SETSCROLLPOS: { + float fPos = *(float*)lParam; + switch (m_sbType) { + case SBT_HSCROLL: + fPos = fPos - m_OriginInfo.fContentMin; + break; + case SBT_VSCROLL: + fPos = m_OriginInfo.fContentMax - fPos; + break; + } + SetScrollPos(fPos); + } break; + } +} + +void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) { + PWL_CREATEPARAM scp = cp; + scp.pParentWnd = this; + scp.dwBorderWidth = 2; + scp.nBorderStyle = BorderStyle::BEVELED; + + scp.dwFlags = + PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; + + if (!m_pMinButton) { + m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN); + m_pMinButton->Create(scp); + } + + if (!m_pMaxButton) { + m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX); + m_pMaxButton->Create(scp); + } + + if (!m_pPosButton) { + m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS); + m_pPosButton->SetVisible(false); + m_pPosButton->Create(scp); + } +} + +float CPWL_ScrollBar::GetScrollBarWidth() const { + if (!IsVisible()) + return 0; + + return PWL_SCROLLBAR_WIDTH; +} + +void CPWL_ScrollBar::SetScrollRange(float fMin, + float fMax, + float fClientWidth) { + if (m_pPosButton) { + m_sData.SetScrollRange(fMin, fMax); + m_sData.SetClientWidth(fClientWidth); + + if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) { + m_pPosButton->SetVisible(false); + } else { + m_pPosButton->SetVisible(true); + MovePosButton(true); + } + } +} + +void CPWL_ScrollBar::SetScrollPos(float fPos) { + float fOldPos = m_sData.fScrollPos; + + m_sData.SetPos(fPos); + + if (!IsFloatEqual(m_sData.fScrollPos, fOldPos)) + MovePosButton(true); +} + +void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) { + m_sData.SetBigStep(fBigStep); + m_sData.SetSmallStep(fSmallStep); +} + +void CPWL_ScrollBar::MovePosButton(bool bRefresh) { + ASSERT(m_pMinButton); + ASSERT(m_pMaxButton); + + if (m_pPosButton->IsVisible()) { + CFX_FloatRect rcClient; + CFX_FloatRect rcPosArea, rcPosButton; + + rcClient = GetClientRect(); + rcPosArea = GetScrollArea(); + + float fLeft, fRight, fTop, fBottom; + + switch (m_sbType) { + case SBT_HSCROLL: + fLeft = TrueToFace(m_sData.fScrollPos); + fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); + + if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH) + fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; + + if (fRight > rcPosArea.right) { + fRight = rcPosArea.right; + fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; + } + + rcPosButton = + CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top); + + break; + case SBT_VSCROLL: + fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); + fTop = TrueToFace(m_sData.fScrollPos); + + if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH)) + fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; + + if (IsFloatSmaller(fBottom, rcPosArea.bottom)) { + fBottom = rcPosArea.bottom; + fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; + } + + rcPosButton = + CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop); + + break; + } + + m_pPosButton->Move(rcPosButton, true, bRefresh); + } +} + +void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { + m_sData.SubSmall(); + MovePosButton(true); + NotifyScrollWindow(); + + m_bMinOrMax = true; + + EndTimer(); + BeginTimer(100); +} + +void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { + m_sData.AddSmall(); + MovePosButton(true); + NotifyScrollWindow(); + + m_bMinOrMax = false; + + EndTimer(); + BeginTimer(100); +} + +void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) { + m_bMouseDown = true; + + if (m_pPosButton) { + CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); + + switch (m_sbType) { + case SBT_HSCROLL: + m_nOldPos = point.x; + m_fOldPosButton = rcPosButton.left; + break; + case SBT_VSCROLL: + m_nOldPos = point.y; + m_fOldPosButton = rcPosButton.top; + break; + } + } +} + +void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) { + if (m_bMouseDown) { + if (!m_bNotifyForever) + NotifyScrollWindow(); + } + m_bMouseDown = false; +} + +void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) { + float fOldScrollPos = m_sData.fScrollPos; + + float fNewPos = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + if (fabs(point.x - m_nOldPos) < 1) + return; + fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos); + break; + case SBT_VSCROLL: + if (fabs(point.y - m_nOldPos) < 1) + return; + fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos); + break; + } + + if (m_bMouseDown) { + switch (m_sbType) { + case SBT_HSCROLL: + + if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { + fNewPos = m_sData.ScrollRange.fMin; + } + + if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { + fNewPos = m_sData.ScrollRange.fMax; + } + + m_sData.SetPos(fNewPos); + + break; + case SBT_VSCROLL: + + if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { + fNewPos = m_sData.ScrollRange.fMin; + } + + if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { + fNewPos = m_sData.ScrollRange.fMax; + } + + m_sData.SetPos(fNewPos); + + break; + } + + if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) { + MovePosButton(true); + + if (m_bNotifyForever) + NotifyScrollWindow(); + } + } +} + +void CPWL_ScrollBar::NotifyScrollWindow() { + if (CPWL_Wnd* pParent = GetParentWindow()) { + float fPos; + switch (m_sbType) { + case SBT_HSCROLL: + fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos; + break; + case SBT_VSCROLL: + fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos; + break; + } + pParent->OnNotify(this, PNM_SCROLLWINDOW, (intptr_t)m_sbType, + (intptr_t)&fPos); + } +} + +CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const { + CFX_FloatRect rcClient = GetClientRect(); + CFX_FloatRect rcArea; + + if (!m_pMinButton || !m_pMaxButton) + return rcClient; + + CFX_FloatRect rcMin = m_pMinButton->GetWindowRect(); + CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect(); + + float fMinWidth = rcMin.right - rcMin.left; + float fMinHeight = rcMin.top - rcMin.bottom; + float fMaxWidth = rcMax.right - rcMax.left; + float fMaxHeight = rcMax.top - rcMax.bottom; + + switch (m_sbType) { + case SBT_HSCROLL: + if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) { + rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, + rcClient.right - fMaxWidth - 1, rcClient.top); + } else { + rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, + rcClient.left + fMinWidth + 1, rcClient.top); + } + break; + case SBT_VSCROLL: + if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) { + rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, + rcClient.right, rcClient.top - fMaxHeight - 1); + } else { + rcArea = + CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, + rcClient.right, rcClient.bottom + fMinHeight + 1); + } + break; + } + + rcArea.Normalize(); + + return rcArea; +} + +float CPWL_ScrollBar::TrueToFace(float fTrue) { + CFX_FloatRect rcPosArea; + rcPosArea = GetScrollArea(); + + float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; + fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; + + float fFace = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + fFace = rcPosArea.left + + fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth; + break; + case SBT_VSCROLL: + fFace = rcPosArea.top - + fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth; + break; + } + + return fFace; +} + +float CPWL_ScrollBar::FaceToTrue(float fFace) { + CFX_FloatRect rcPosArea; + rcPosArea = GetScrollArea(); + + float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; + fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; + + float fTrue = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + fTrue = (fFace - rcPosArea.left) * fFactWidth / + (rcPosArea.right - rcPosArea.left); + break; + case SBT_VSCROLL: + fTrue = (rcPosArea.top - fFace) * fFactWidth / + (rcPosArea.top - rcPosArea.bottom); + break; + } + + return fTrue; +} + +void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) { + CreateButtons(cp); +} + +void CPWL_ScrollBar::TimerProc() { + PWL_SCROLL_PRIVATEDATA sTemp = m_sData; + if (m_bMinOrMax) + m_sData.SubSmall(); + else + m_sData.AddSmall(); + + if (sTemp != m_sData) { + MovePosButton(true); + NotifyScrollWindow(); + } +} diff --git a/fpdfsdk/pdfwindow/cpwl_scroll_bar.h b/fpdfsdk/pdfwindow/cpwl_scroll_bar.h new file mode 100644 index 0000000000..0ab2928f2a --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_scroll_bar.h @@ -0,0 +1,185 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_SCROLL_BAR_H_ +#define FPDFSDK_PDFWINDOW_CPWL_SCROLL_BAR_H_ + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CPWL_SBButton; +class CPWL_ScrollBar; + +struct PWL_SCROLL_INFO { + public: + PWL_SCROLL_INFO() + : fContentMin(0.0f), + fContentMax(0.0f), + fPlateWidth(0.0f), + fBigStep(0.0f), + fSmallStep(0.0f) {} + + bool operator==(const PWL_SCROLL_INFO& that) const { + return fContentMin == that.fContentMin && fContentMax == that.fContentMax && + fPlateWidth == that.fPlateWidth && fBigStep == that.fBigStep && + fSmallStep == that.fSmallStep; + } + bool operator!=(const PWL_SCROLL_INFO& that) const { + return !(*this == that); + } + + float fContentMin; + float fContentMax; + float fPlateWidth; + float fBigStep; + float fSmallStep; +}; + +enum PWL_SCROLLBAR_TYPE { SBT_HSCROLL, SBT_VSCROLL }; + +enum PWL_SBBUTTON_TYPE { PSBT_MIN, PSBT_MAX, PSBT_POS }; + +class CPWL_SBButton : public CPWL_Wnd { + public: + CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, + PWL_SBBUTTON_TYPE eButtonType); + ~CPWL_SBButton() override; + + // CPWL_Wnd + CFX_ByteString GetClassName() const override; + void OnCreate(PWL_CREATEPARAM& cp) override; + void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; + void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; + + protected: + PWL_SCROLLBAR_TYPE m_eScrollBarType; + PWL_SBBUTTON_TYPE m_eSBButtonType; + + bool m_bMouseDown; +}; + +struct PWL_FLOATRANGE { + public: + PWL_FLOATRANGE(); + PWL_FLOATRANGE(float min, float max); + + bool operator==(const PWL_FLOATRANGE& that) const { + return fMin == that.fMin && fMax == that.fMax; + } + bool operator!=(const PWL_FLOATRANGE& that) const { return !(*this == that); } + + void Default(); + void Set(float min, float max); + bool In(float x) const; + float GetWidth() const; + + float fMin; + float fMax; +}; + +struct PWL_SCROLL_PRIVATEDATA { + public: + PWL_SCROLL_PRIVATEDATA(); + + bool operator==(const PWL_SCROLL_PRIVATEDATA& that) const { + return ScrollRange == that.ScrollRange && + fClientWidth == that.fClientWidth && fScrollPos == that.fScrollPos && + fBigStep == that.fBigStep && fSmallStep == that.fSmallStep; + } + bool operator!=(const PWL_SCROLL_PRIVATEDATA& that) const { + return !(*this == that); + } + + void Default(); + void SetScrollRange(float min, float max); + void SetClientWidth(float width); + void SetSmallStep(float step); + void SetBigStep(float step); + bool SetPos(float pos); + + void AddSmall(); + void SubSmall(); + void AddBig(); + void SubBig(); + + PWL_FLOATRANGE ScrollRange; + float fClientWidth; + float fScrollPos; + float fBigStep; + float fSmallStep; +}; + +class CPWL_ScrollBar : public CPWL_Wnd { + public: + explicit CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType = SBT_HSCROLL); + ~CPWL_ScrollBar() override; + + // CPWL_Wnd + CFX_ByteString GetClassName() const override; + void OnCreate(PWL_CREATEPARAM& cp) override; + void OnDestroy() override; + void RePosChildWnd() override; + void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; + void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + void OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam = 0, + intptr_t lParam = 0) override; + void CreateChildWnd(const PWL_CREATEPARAM& cp) override; + void TimerProc() override; + + float GetScrollBarWidth() const; + PWL_SCROLLBAR_TYPE GetScrollBarType() const { return m_sbType; } + + void SetNotifyForever(bool bForever) { m_bNotifyForever = bForever; } + + protected: + void SetScrollRange(float fMin, float fMax, float fClientWidth); + void SetScrollPos(float fPos); + void MovePosButton(bool bRefresh); + void SetScrollStep(float fBigStep, float fSmallStep); + void NotifyScrollWindow(); + CFX_FloatRect GetScrollArea() const; + + private: + void CreateButtons(const PWL_CREATEPARAM& cp); + + void OnMinButtonLBDown(const CFX_PointF& point); + void OnMinButtonLBUp(const CFX_PointF& point); + void OnMinButtonMouseMove(const CFX_PointF& point); + + void OnMaxButtonLBDown(const CFX_PointF& point); + void OnMaxButtonLBUp(const CFX_PointF& point); + void OnMaxButtonMouseMove(const CFX_PointF& point); + + void OnPosButtonLBDown(const CFX_PointF& point); + void OnPosButtonLBUp(const CFX_PointF& point); + void OnPosButtonMouseMove(const CFX_PointF& point); + + float TrueToFace(float); + float FaceToTrue(float); + + PWL_SCROLLBAR_TYPE m_sbType; + PWL_SCROLL_INFO m_OriginInfo; + CFX_UnownedPtr m_pMinButton; + CFX_UnownedPtr m_pMaxButton; + CFX_UnownedPtr m_pPosButton; + PWL_SCROLL_PRIVATEDATA m_sData; + bool m_bMouseDown; + bool m_bMinOrMax; + bool m_bNotifyForever; + float m_nOldPos; + float m_fOldPosButton; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_SCROLL_BAR_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_special_button.cpp b/fpdfsdk/pdfwindow/cpwl_special_button.cpp new file mode 100644 index 0000000000..56aa739545 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_special_button.cpp @@ -0,0 +1,80 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_special_button.h" +#include "fpdfsdk/pdfwindow/cpwl_button.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +CPWL_PushButton::CPWL_PushButton() {} + +CPWL_PushButton::~CPWL_PushButton() {} + +CFX_ByteString CPWL_PushButton::GetClassName() const { + return "CPWL_PushButton"; +} + +CFX_FloatRect CPWL_PushButton::GetFocusRect() const { + return CPWL_Utils::DeflateRect(GetWindowRect(), (float)GetBorderWidth()); +} + +CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(false) {} + +CPWL_CheckBox::~CPWL_CheckBox() {} + +CFX_ByteString CPWL_CheckBox::GetClassName() const { + return "CPWL_CheckBox"; +} + +void CPWL_CheckBox::SetCheck(bool bCheck) { + m_bChecked = bCheck; +} + +bool CPWL_CheckBox::IsChecked() const { + return m_bChecked; +} + +bool CPWL_CheckBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + if (IsReadOnly()) + return false; + + SetCheck(!IsChecked()); + return true; +} + +bool CPWL_CheckBox::OnChar(uint16_t nChar, uint32_t nFlag) { + SetCheck(!IsChecked()); + return true; +} + +CPWL_RadioButton::CPWL_RadioButton() : m_bChecked(false) {} + +CPWL_RadioButton::~CPWL_RadioButton() {} + +CFX_ByteString CPWL_RadioButton::GetClassName() const { + return "CPWL_RadioButton"; +} + +bool CPWL_RadioButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + if (IsReadOnly()) + return false; + + SetCheck(true); + return true; +} + +void CPWL_RadioButton::SetCheck(bool bCheck) { + m_bChecked = bCheck; +} + +bool CPWL_RadioButton::IsChecked() const { + return m_bChecked; +} + +bool CPWL_RadioButton::OnChar(uint16_t nChar, uint32_t nFlag) { + SetCheck(true); + return true; +} diff --git a/fpdfsdk/pdfwindow/cpwl_special_button.h b/fpdfsdk/pdfwindow/cpwl_special_button.h new file mode 100644 index 0000000000..ed80d31639 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_special_button.h @@ -0,0 +1,56 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_SPECIAL_BUTTON_H_ +#define FPDFSDK_PDFWINDOW_CPWL_SPECIAL_BUTTON_H_ + +#include "fpdfsdk/pdfwindow/cpwl_button.h" + +class CPWL_PushButton : public CPWL_Button { + public: + CPWL_PushButton(); + ~CPWL_PushButton() override; + + // CPWL_Button + CFX_ByteString GetClassName() const override; + CFX_FloatRect GetFocusRect() const override; +}; + +class CPWL_CheckBox : public CPWL_Button { + public: + CPWL_CheckBox(); + ~CPWL_CheckBox() override; + + // CPWL_Button + CFX_ByteString GetClassName() const override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + bool OnChar(uint16_t nChar, uint32_t nFlag) override; + + void SetCheck(bool bCheck); + bool IsChecked() const; + + private: + bool m_bChecked; +}; + +class CPWL_RadioButton : public CPWL_Button { + public: + CPWL_RadioButton(); + ~CPWL_RadioButton() override; + + // CPWL_Button + CFX_ByteString GetClassName() const override; + bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; + bool OnChar(uint16_t nChar, uint32_t nFlag) override; + + void SetCheck(bool bCheck); + bool IsChecked() const; + + private: + bool m_bChecked; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_SPECIAL_BUTTON_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_utils.cpp b/fpdfsdk/pdfwindow/cpwl_utils.cpp new file mode 100644 index 0000000000..0a3591923a --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_utils.cpp @@ -0,0 +1,1168 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_utils.h" + +#include +#include + +#include "core/fpdfdoc/cpvt_word.h" +#include "core/fxge/cfx_graphstatedata.h" +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/fxedit/fxet_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_icon.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +CFX_FloatRect CPWL_Utils::OffsetRect(const CFX_FloatRect& rect, + float x, + float y) { + return CFX_FloatRect(rect.left + x, rect.bottom + y, rect.right + x, + rect.top + y); +} + +CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange& wr1, + const CPVT_WordRange& wr2) { + if (wr2.EndPos < wr1.BeginPos || wr2.BeginPos > wr1.EndPos || + wr1.EndPos < wr2.BeginPos || wr1.BeginPos > wr2.EndPos) { + return CPVT_WordRange(); + } + + return CPVT_WordRange(std::max(wr1.BeginPos, wr2.BeginPos), + std::min(wr1.EndPos, wr2.EndPos)); +} + +CFX_ByteString CPWL_Utils::GetAP_Check(const CFX_FloatRect& crBBox) { + const float fWidth = crBBox.right - crBBox.left; + const float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pts[8][3] = {{CFX_PointF(0.28f, 0.52f), CFX_PointF(0.27f, 0.48f), + CFX_PointF(0.29f, 0.40f)}, + {CFX_PointF(0.30f, 0.33f), CFX_PointF(0.31f, 0.29f), + CFX_PointF(0.31f, 0.28f)}, + {CFX_PointF(0.39f, 0.28f), CFX_PointF(0.49f, 0.29f), + CFX_PointF(0.77f, 0.67f)}, + {CFX_PointF(0.76f, 0.68f), CFX_PointF(0.78f, 0.69f), + CFX_PointF(0.76f, 0.75f)}, + {CFX_PointF(0.76f, 0.75f), CFX_PointF(0.73f, 0.80f), + CFX_PointF(0.68f, 0.75f)}, + {CFX_PointF(0.68f, 0.74f), CFX_PointF(0.68f, 0.74f), + CFX_PointF(0.44f, 0.47f)}, + {CFX_PointF(0.43f, 0.47f), CFX_PointF(0.40f, 0.47f), + CFX_PointF(0.41f, 0.58f)}, + {CFX_PointF(0.40f, 0.60f), CFX_PointF(0.28f, 0.66f), + CFX_PointF(0.30f, 0.56f)}}; + + for (size_t i = 0; i < FX_ArraySize(pts); ++i) { + for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) { + pts[i][j].x = pts[i][j].x * fWidth + crBBox.left; + pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom; + } + } + + CFX_ByteTextBuf csAP; + csAP << pts[0][0].x << " " << pts[0][0].y << " m\n"; + + for (size_t i = 0; i < FX_ArraySize(pts); ++i) { + size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0; + + float px1 = pts[i][1].x - pts[i][0].x; + float py1 = pts[i][1].y - pts[i][0].y; + float px2 = pts[i][2].x - pts[nNext][0].x; + float py2 = pts[i][2].y - pts[nNext][0].y; + + csAP << pts[i][0].x + px1 * FX_BEZIER << " " + << pts[i][0].y + py1 * FX_BEZIER << " " + << pts[nNext][0].x + px2 * FX_BEZIER << " " + << pts[nNext][0].y + py2 * FX_BEZIER << " " << pts[nNext][0].x << " " + << pts[nNext][0].y << " c\n"; + } + + return csAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAP_Circle(const CFX_FloatRect& crBBox) { + CFX_ByteTextBuf csAP; + + float fWidth = crBBox.right - crBBox.left; + float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); + CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); + CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); + CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); + + csAP << pt1.x << " " << pt1.y << " m\n"; + + float px = pt2.x - pt1.x; + float py = pt2.y - pt1.y; + + csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " + << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y + << " c\n"; + + px = pt3.x - pt2.x; + py = pt2.y - pt3.y; + + csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " + << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; + + px = pt3.x - pt4.x; + py = pt3.y - pt4.y; + + csAP << pt3.x << " " << pt3.y - py * FX_BEZIER << " " + << pt4.x + px * FX_BEZIER << " " << pt4.y << " " << pt4.x << " " << pt4.y + << " c\n"; + + px = pt4.x - pt1.x; + py = pt1.y - pt4.y; + + csAP << pt4.x - px * FX_BEZIER << " " << pt4.y << " " << pt1.x << " " + << pt1.y - py * FX_BEZIER << " " << pt1.x << " " << pt1.y << " c\n"; + + return csAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAP_Cross(const CFX_FloatRect& crBBox) { + CFX_ByteTextBuf csAP; + + csAP << crBBox.left << " " << crBBox.top << " m\n"; + csAP << crBBox.right << " " << crBBox.bottom << " l\n"; + csAP << crBBox.left << " " << crBBox.bottom << " m\n"; + csAP << crBBox.right << " " << crBBox.top << " l\n"; + + return csAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAP_Diamond(const CFX_FloatRect& crBBox) { + CFX_ByteTextBuf csAP; + + float fWidth = crBBox.right - crBBox.left; + float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); + CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); + CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); + CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); + + csAP << pt1.x << " " << pt1.y << " m\n"; + csAP << pt2.x << " " << pt2.y << " l\n"; + csAP << pt3.x << " " << pt3.y << " l\n"; + csAP << pt4.x << " " << pt4.y << " l\n"; + csAP << pt1.x << " " << pt1.y << " l\n"; + + return csAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAP_Square(const CFX_FloatRect& crBBox) { + CFX_ByteTextBuf csAP; + + csAP << crBBox.left << " " << crBBox.top << " m\n"; + csAP << crBBox.right << " " << crBBox.top << " l\n"; + csAP << crBBox.right << " " << crBBox.bottom << " l\n"; + csAP << crBBox.left << " " << crBBox.bottom << " l\n"; + csAP << crBBox.left << " " << crBBox.top << " l\n"; + + return csAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAP_Star(const CFX_FloatRect& crBBox) { + CFX_ByteTextBuf csAP; + + float fRadius = (crBBox.top - crBBox.bottom) / (1 + (float)cos(FX_PI / 5.0f)); + CFX_PointF ptCenter = CFX_PointF((crBBox.left + crBBox.right) / 2.0f, + (crBBox.top + crBBox.bottom) / 2.0f); + + float px[5], py[5]; + + float fAngel = FX_PI / 10.0f; + + for (int32_t i = 0; i < 5; i++) { + px[i] = ptCenter.x + fRadius * (float)cos(fAngel); + py[i] = ptCenter.y + fRadius * (float)sin(fAngel); + + fAngel += FX_PI * 2 / 5.0f; + } + + csAP << px[0] << " " << py[0] << " m\n"; + + int32_t nNext = 0; + for (int32_t j = 0; j < 5; j++) { + nNext += 2; + if (nNext >= 5) + nNext -= 5; + csAP << px[nNext] << " " << py[nNext] << " l\n"; + } + + return csAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CFX_FloatRect& crBBox, + float fRotate) { + CFX_ByteTextBuf csAP; + + float fWidth = crBBox.right - crBBox.left; + float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pt1(-fWidth / 2, 0); + CFX_PointF pt2(0, fHeight / 2); + CFX_PointF pt3(fWidth / 2, 0); + + float px, py; + + csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " " + << cos(fRotate) << " " << crBBox.left + fWidth / 2 << " " + << crBBox.bottom + fHeight / 2 << " cm\n"; + + csAP << pt1.x << " " << pt1.y << " m\n"; + + px = pt2.x - pt1.x; + py = pt2.y - pt1.y; + + csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " + << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y + << " c\n"; + + px = pt3.x - pt2.x; + py = pt2.y - pt3.y; + + csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " + << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; + + return csAP.MakeString(); +} + +CFX_FloatRect CPWL_Utils::InflateRect(const CFX_FloatRect& rcRect, + float fSize) { + if (rcRect.IsEmpty()) + return rcRect; + + CFX_FloatRect rcNew(rcRect.left - fSize, rcRect.bottom - fSize, + rcRect.right + fSize, rcRect.top + fSize); + rcNew.Normalize(); + return rcNew; +} + +CFX_FloatRect CPWL_Utils::DeflateRect(const CFX_FloatRect& rcRect, + float fSize) { + if (rcRect.IsEmpty()) + return rcRect; + + CFX_FloatRect rcNew(rcRect.left + fSize, rcRect.bottom + fSize, + rcRect.right - fSize, rcRect.top - fSize); + rcNew.Normalize(); + return rcNew; +} + +CFX_FloatRect CPWL_Utils::ScaleRect(const CFX_FloatRect& rcRect, float fScale) { + float fHalfWidth = (rcRect.right - rcRect.left) / 2.0f; + float fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f; + + CFX_PointF ptCenter = CFX_PointF((rcRect.left + rcRect.right) / 2, + (rcRect.top + rcRect.bottom) / 2); + + return CFX_FloatRect( + ptCenter.x - fHalfWidth * fScale, ptCenter.y - fHalfHeight * fScale, + ptCenter.x + fHalfWidth * fScale, ptCenter.y + fHalfHeight * fScale); +} + +CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CFX_FloatRect& rect, + const CPWL_Color& color) { + CFX_ByteTextBuf sAppStream; + CFX_ByteString sColor = GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" << sColor; + sAppStream << rect.left << " " << rect.bottom << " " + << rect.right - rect.left << " " << rect.top - rect.bottom + << " re f\nQ\n"; + } + + return sAppStream.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CFX_FloatRect& rect, + const CPWL_Color& color) { + CFX_ByteTextBuf sAppStream; + CFX_ByteString sColor = GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n"; + } + return sAppStream.MakeString(); +} + +CFX_FloatRect CPWL_Utils::GetCenterSquare(const CFX_FloatRect& rect) { + float fWidth = rect.right - rect.left; + float fHeight = rect.top - rect.bottom; + + float fCenterX = (rect.left + rect.right) / 2.0f; + float fCenterY = (rect.top + rect.bottom) / 2.0f; + + float fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2; + + return CFX_FloatRect(fCenterX - fRadius, fCenterY - fRadius, + fCenterX + fRadius, fCenterY + fRadius); +} + +CFX_ByteString CPWL_Utils::GetEditAppStream(CFX_Edit* pEdit, + const CFX_PointF& ptOffset, + const CPVT_WordRange* pRange, + bool bContinuous, + uint16_t SubWord) { + return CFX_Edit::GetEditAppearanceStream(pEdit, ptOffset, pRange, bContinuous, + SubWord); +} + +CFX_ByteString CPWL_Utils::GetEditSelAppStream(CFX_Edit* pEdit, + const CFX_PointF& ptOffset, + const CPVT_WordRange* pRange) { + return CFX_Edit::GetSelectAppearanceStream(pEdit, ptOffset, pRange); +} + +CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, + IPVT_FontMap* pFontMap, + CPDF_Stream* pIconStream, + CPDF_IconFit& IconFit, + const CFX_WideString& sLabel, + const CPWL_Color& crText, + float fFontSize, + int32_t nLayOut) { + const float fAutoFontScale = 1.0f / 3.0f; + + auto pEdit = pdfium::MakeUnique(); + pEdit->SetFontMap(pFontMap); + pEdit->SetAlignmentH(1, true); + pEdit->SetAlignmentV(1, true); + pEdit->SetMultiLine(false, true); + pEdit->SetAutoReturn(false, true); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(true, true); + else + pEdit->SetFontSize(fFontSize); + + pEdit->Initialize(); + pEdit->SetText(sLabel); + + CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); + CPWL_Icon Icon; + PWL_CREATEPARAM cp; + cp.dwFlags = PWS_VISIBLE; + Icon.Create(cp); + Icon.SetIconFit(&IconFit); + Icon.SetPDFStream(pIconStream); + + CFX_FloatRect rcLabel = CFX_FloatRect(0, 0, 0, 0); + CFX_FloatRect rcIcon = CFX_FloatRect(0, 0, 0, 0); + float fWidth = 0.0f; + float fHeight = 0.0f; + + switch (nLayOut) { + case PPBL_LABEL: + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + break; + case PPBL_ICON: + rcIcon = rcBBox; + rcLabel = CFX_FloatRect(0, 0, 0, 0); + break; + case PPBL_ICONTOPLABELBOTTOM: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fHeight = rcBBox.top - rcBBox.bottom; + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcBBox.bottom + fHeight * fAutoFontScale); + rcIcon = + CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top); + } else { + fHeight = rcLabelContent.Height(); + + if (rcBBox.bottom + fHeight > rcBBox.top) { + rcIcon = CFX_FloatRect(0, 0, 0, 0); + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcBBox.bottom + fHeight); + rcIcon = CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, + rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } + + break; + case PPBL_LABELTOPICONBOTTOM: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fHeight = rcBBox.top - rcBBox.bottom; + rcLabel = + CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight * fAutoFontScale, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcLabel.bottom); + } else { + fHeight = rcLabelContent.Height(); + + if (rcBBox.bottom + fHeight > rcBBox.top) { + rcIcon = CFX_FloatRect(0, 0, 0, 0); + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcLabel.bottom); + } + } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } + + break; + case PPBL_ICONLEFTLABELRIGHT: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fWidth = rcBBox.right - rcBBox.left; + rcLabel = CFX_FloatRect(rcBBox.right - fWidth * fAutoFontScale, + rcBBox.bottom, rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); + + if (rcLabelContent.Width() < fWidth * fAutoFontScale) { + } else { + if (rcLabelContent.Width() < fWidth) { + rcLabel = CFX_FloatRect(rcBBox.right - rcLabelContent.Width(), + rcBBox.bottom, rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } + } + } else { + fWidth = rcLabelContent.Width(); + + if (rcBBox.left + fWidth > rcBBox.right) { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } else { + rcLabel = CFX_FloatRect(rcBBox.right - fWidth, rcBBox.bottom, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } + + break; + case PPBL_LABELLEFTICONRIGHT: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fWidth = rcBBox.right - rcBBox.left; + rcLabel = + CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + fWidth * fAutoFontScale, rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + + if (rcLabelContent.Width() < fWidth * fAutoFontScale) { + } else { + if (rcLabelContent.Width() < fWidth) { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + rcLabelContent.Width(), + rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } + } + } else { + fWidth = rcLabelContent.Width(); + + if (rcBBox.left + fWidth > rcBBox.right) { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + fWidth, rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } + + break; + case PPBL_LABELOVERICON: + rcLabel = rcBBox; + rcIcon = rcBBox; + break; + } + + CFX_ByteTextBuf sAppStream, sTemp; + + if (!rcIcon.IsEmpty()) { + Icon.Move(rcIcon, false, false); + sTemp << Icon.GetImageAppStream(); + } + + Icon.Destroy(); + + if (!rcLabel.IsEmpty()) { + pEdit->SetPlateRect(rcLabel); + CFX_ByteString sEdit = + CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, 0.0f)); + if (sEdit.GetLength() > 0) { + sTemp << "BT\n" + << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; + } + } + + if (sTemp.GetSize() > 0) { + sAppStream << "q\n" + << rcBBox.left << " " << rcBBox.bottom << " " + << rcBBox.right - rcBBox.left << " " + << rcBBox.top - rcBBox.bottom << " re W n\n"; + sAppStream << sTemp << "Q\n"; + } + return sAppStream.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color, + const bool& bFillOrStroke) { + CFX_ByteTextBuf sColorStream; + + switch (color.nColorType) { + case COLORTYPE_RGB: + sColorStream << color.fColor1 << " " << color.fColor2 << " " + << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") + << "\n"; + break; + case COLORTYPE_GRAY: + sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") + << "\n"; + break; + case COLORTYPE_CMYK: + sColorStream << color.fColor1 << " " << color.fColor2 << " " + << color.fColor3 << " " << color.fColor4 << " " + << (bFillOrStroke ? "k" : "K") << "\n"; + break; + } + + return sColorStream.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetBorderAppStream(const CFX_FloatRect& rect, + float fWidth, + const CPWL_Color& color, + const CPWL_Color& crLeftTop, + const CPWL_Color& crRightBottom, + BorderStyle nStyle, + const CPWL_Dash& dash) { + CFX_ByteTextBuf sAppStream; + CFX_ByteString sColor; + + float fLeft = rect.left; + float fRight = rect.right; + float fTop = rect.top; + float fBottom = rect.bottom; + + if (fWidth > 0.0f) { + float fHalfWidth = fWidth / 2.0f; + + sAppStream << "q\n"; + + switch (nStyle) { + default: + case BorderStyle::SOLID: + sColor = CPWL_Utils::GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " + << fTop - fBottom << " re\n"; + sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " " + << fRight - fLeft - fWidth * 2 << " " + << fTop - fBottom - fWidth * 2 << " re\n"; + sAppStream << "f*\n"; + } + break; + case BorderStyle::DASH: + sColor = CPWL_Utils::GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fWidth << " w" + << " [" << dash.nDash << " " << dash.nGap << "] " + << dash.nPhase << " d\n"; + sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 + << " m\n"; + sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 + << " l\n"; + sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 + << " l\n"; + sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 + << " l\n"; + sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 + << " l S\n"; + } + break; + case BorderStyle::BEVELED: + case BorderStyle::INSET: + sColor = CPWL_Utils::GetColorAppStream(crLeftTop, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth + << " m\n"; + sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth + << " l\n"; + sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth + << " l\n"; + sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 + << " l\n"; + sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 + << " l\n"; + sAppStream << fLeft + fHalfWidth * 2 << " " + << fBottom + fHalfWidth * 2 << " l f\n"; + } + + sColor = CPWL_Utils::GetColorAppStream(crRightBottom, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth + << " m\n"; + sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth + << " l\n"; + sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth + << " l\n"; + sAppStream << fLeft + fHalfWidth * 2 << " " + << fBottom + fHalfWidth * 2 << " l\n"; + sAppStream << fRight - fHalfWidth * 2 << " " + << fBottom + fHalfWidth * 2 << " l\n"; + sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 + << " l f\n"; + } + + sColor = CPWL_Utils::GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " + << fTop - fBottom << " re\n"; + sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " " + << fRight - fLeft - fHalfWidth * 2 << " " + << fTop - fBottom - fHalfWidth * 2 << " re f*\n"; + } + break; + case BorderStyle::UNDERLINE: + sColor = CPWL_Utils::GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fWidth << " w\n"; + sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; + sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; + } + break; + } + + sAppStream << "Q\n"; + } + + return sAppStream.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( + const CFX_FloatRect& rect, + float fWidth, + const CPWL_Color& color, + const CPWL_Color& crLeftTop, + const CPWL_Color& crRightBottom, + BorderStyle nStyle, + const CPWL_Dash& dash) { + CFX_ByteTextBuf sAppStream; + CFX_ByteString sColor; + + if (fWidth > 0.0f) { + sAppStream << "q\n"; + + switch (nStyle) { + default: + case BorderStyle::SOLID: + case BorderStyle::UNDERLINE: { + sColor = CPWL_Utils::GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fWidth << " w\n" + << sColor + << CPWL_Utils::GetAP_Circle( + CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) + << " S\nQ\n"; + } + } break; + case BorderStyle::DASH: { + sColor = CPWL_Utils::GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fWidth << " w\n" + << "[" << dash.nDash << " " << dash.nGap << "] " + << dash.nPhase << " d\n" + << sColor + << CPWL_Utils::GetAP_Circle( + CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) + << " S\nQ\n"; + } + } break; + case BorderStyle::BEVELED: { + float fHalfWidth = fWidth / 2.0f; + + sColor = CPWL_Utils::GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n"; + } + + sColor = CPWL_Utils::GetColorAppStream(crLeftTop, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor + << CPWL_Utils::GetAP_HalfCircle( + CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), + FX_PI / 4.0f) + << " S\nQ\n"; + } + + sColor = CPWL_Utils::GetColorAppStream(crRightBottom, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor + << CPWL_Utils::GetAP_HalfCircle( + CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), + FX_PI * 5 / 4.0f) + << " S\nQ\n"; + } + } break; + case BorderStyle::INSET: { + float fHalfWidth = fWidth / 2.0f; + + sColor = CPWL_Utils::GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n"; + } + + sColor = CPWL_Utils::GetColorAppStream(crLeftTop, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor + << CPWL_Utils::GetAP_HalfCircle( + CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), + FX_PI / 4.0f) + << " S\nQ\n"; + } + + sColor = CPWL_Utils::GetColorAppStream(crRightBottom, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor + << CPWL_Utils::GetAP_HalfCircle( + CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), + FX_PI * 5 / 4.0f) + << " S\nQ\n"; + } + } break; + } + + sAppStream << "Q\n"; + } + + return sAppStream.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAppStream_Check(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText) { + CFX_ByteTextBuf sAP; + sAP << "q\n" + << CPWL_Utils::GetColorAppStream(crText, true) + << CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n"; + return sAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText) { + CFX_ByteTextBuf sAP; + sAP << "q\n" + << CPWL_Utils::GetColorAppStream(crText, true) + << CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n"; + return sAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText) { + CFX_ByteTextBuf sAP; + sAP << "q\n" + << CPWL_Utils::GetColorAppStream(crText, false) + << CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n"; + return sAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText) { + CFX_ByteTextBuf sAP; + sAP << "q\n1 w\n" + << CPWL_Utils::GetColorAppStream(crText, true) + << CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n"; + return sAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAppStream_Square(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText) { + CFX_ByteTextBuf sAP; + sAP << "q\n" + << CPWL_Utils::GetColorAppStream(crText, true) + << CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n"; + return sAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetAppStream_Star(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText) { + CFX_ByteTextBuf sAP; + sAP << "q\n" + << CPWL_Utils::GetColorAppStream(crText, true) + << CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n"; + return sAP.MakeString(); +} + +CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, + int32_t nStyle, + const CPWL_Color& crText) { + CFX_FloatRect rcCenter = GetCenterSquare(rcBBox); + switch (nStyle) { + default: + case PCS_CHECK: + return GetAppStream_Check(rcCenter, crText); + case PCS_CIRCLE: + return GetAppStream_Circle(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + case PCS_CROSS: + return GetAppStream_Cross(rcCenter, crText); + case PCS_DIAMOND: + return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + case PCS_SQUARE: + return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + case PCS_STAR: + return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + } +} + +CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, + int32_t nStyle, + const CPWL_Color& crText) { + CFX_FloatRect rcCenter = GetCenterSquare(rcBBox); + switch (nStyle) { + default: + case PCS_CHECK: + return GetAppStream_Check(rcCenter, crText); + case PCS_CIRCLE: + return GetAppStream_Circle(ScaleRect(rcCenter, 1.0f / 2.0f), crText); + case PCS_CROSS: + return GetAppStream_Cross(rcCenter, crText); + case PCS_DIAMOND: + return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + case PCS_SQUARE: + return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + case PCS_STAR: + return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText); + } +} + +CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { + CFX_ByteTextBuf sAppStream; + + if (!rcBBox.IsEmpty()) { + sAppStream << "q\n" + << CPWL_Utils::GetColorAppStream( + CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, + 220.0f / 255.0f, 220.0f / 255.0f), + true); + sAppStream << rcBBox.left << " " << rcBBox.bottom << " " + << rcBBox.right - rcBBox.left << " " + << rcBBox.top - rcBBox.bottom << " re f\n"; + sAppStream << "Q\n"; + + sAppStream << "q\n" + << CPWL_Utils::GetBorderAppStream( + rcBBox, 2, CPWL_Color(COLORTYPE_GRAY, 0), + CPWL_Color(COLORTYPE_GRAY, 1), + CPWL_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED, + CPWL_Dash(3, 0, 0)) + << "Q\n"; + + CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2, + (rcBBox.top + rcBBox.bottom) / 2); + if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) && + IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) { + sAppStream << "q\n" + << " 0 g\n"; + sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; + sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; + sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; + sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; + sAppStream << "Q\n"; + } + } + + return sAppStream.MakeString(); +} + +void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color) { + CFX_PathData path; + CFX_FloatRect rcTemp(rect); + path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); + pDevice->DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_WINDING); +} + +void CPWL_Utils::DrawFillArea(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_PointF* pPts, + int32_t nCount, + const FX_COLORREF& color) { + CFX_PathData path; + path.AppendPoint(pPts[0], FXPT_TYPE::MoveTo, false); + for (int32_t i = 1; i < nCount; i++) + path.AppendPoint(pPts[i], FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_ALTERNATE); +} + +void CPWL_Utils::DrawStrokeRect(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color, + float fWidth) { + CFX_PathData path; + CFX_FloatRect rcTemp(rect); + path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); +} + +void CPWL_Utils::DrawStrokeLine(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_PointF& ptMoveTo, + const CFX_PointF& ptLineTo, + const FX_COLORREF& color, + float fWidth) { + CFX_PathData path; + path.AppendPoint(ptMoveTo, FXPT_TYPE::MoveTo, false); + path.AppendPoint(ptLineTo, FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); +} + +void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const CPWL_Color& color, + int32_t nTransparency) { + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rect, + color.ToFXColor(nTransparency)); +} + +void CPWL_Utils::DrawShadow(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + bool bVertical, + bool bHorizontal, + CFX_FloatRect rect, + int32_t nTransparency, + int32_t nStartGray, + int32_t nEndGray) { + float fStepGray = 1.0f; + + if (bVertical) { + fStepGray = (nEndGray - nStartGray) / rect.Height(); + + for (float fy = rect.bottom + 0.5f; fy <= rect.top - 0.5f; fy += 1.0f) { + int32_t nGray = nStartGray + (int32_t)(fStepGray * (fy - rect.bottom)); + CPWL_Utils::DrawStrokeLine( + pDevice, pUser2Device, CFX_PointF(rect.left, fy), + CFX_PointF(rect.right, fy), + ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); + } + } + + if (bHorizontal) { + fStepGray = (nEndGray - nStartGray) / rect.Width(); + + for (float fx = rect.left + 0.5f; fx <= rect.right - 0.5f; fx += 1.0f) { + int32_t nGray = nStartGray + (int32_t)(fStepGray * (fx - rect.left)); + CPWL_Utils::DrawStrokeLine( + pDevice, pUser2Device, CFX_PointF(fx, rect.bottom), + CFX_PointF(fx, rect.top), + ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); + } + } +} + +void CPWL_Utils::DrawBorder(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + float fWidth, + const CPWL_Color& color, + const CPWL_Color& crLeftTop, + const CPWL_Color& crRightBottom, + BorderStyle nStyle, + int32_t nTransparency) { + float fLeft = rect.left; + float fRight = rect.right; + float fTop = rect.top; + float fBottom = rect.bottom; + + if (fWidth > 0.0f) { + float fHalfWidth = fWidth / 2.0f; + + switch (nStyle) { + default: + case BorderStyle::SOLID: { + CFX_PathData path; + path.AppendRect(fLeft, fBottom, fRight, fTop); + path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, + fTop - fWidth); + pDevice->DrawPath(&path, pUser2Device, nullptr, + color.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); + break; + } + case BorderStyle::DASH: { + CFX_PathData path; + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::MoveTo, false); + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fRight - fWidth / 2.0f, fTop - fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.SetDashCount(2); + gsd.m_DashArray[0] = 3.0f; + gsd.m_DashArray[1] = 3.0f; + gsd.m_DashPhase = 0; + + gsd.m_LineWidth = fWidth; + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, + color.ToFXColor(nTransparency), FXFILL_WINDING); + break; + } + case BorderStyle::BEVELED: + case BorderStyle::INSET: { + CFX_GraphStateData gsd; + gsd.m_LineWidth = fHalfWidth; + + CFX_PathData pathLT; + + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::MoveTo, false); + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&pathLT, pUser2Device, &gsd, + crLeftTop.ToFXColor(nTransparency), 0, + FXFILL_ALTERNATE); + + CFX_PathData pathRB; + pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::MoveTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&pathRB, pUser2Device, &gsd, + crRightBottom.ToFXColor(nTransparency), 0, + FXFILL_ALTERNATE); + + CFX_PathData path; + + path.AppendRect(fLeft, fBottom, fRight, fTop); + path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, + fRight - fHalfWidth, fTop - fHalfWidth); + + pDevice->DrawPath(&path, pUser2Device, &gsd, + color.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); + break; + } + case BorderStyle::UNDERLINE: { + CFX_PathData path; + path.AppendPoint(CFX_PointF(fLeft, fBottom + fWidth / 2), + FXPT_TYPE::MoveTo, false); + path.AppendPoint(CFX_PointF(fRight, fBottom + fWidth / 2), + FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, + color.ToFXColor(nTransparency), FXFILL_ALTERNATE); + break; + } + } + } +} diff --git a/fpdfsdk/pdfwindow/cpwl_utils.h b/fpdfsdk/pdfwindow/cpwl_utils.h new file mode 100644 index 0000000000..297eb89b6e --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_utils.h @@ -0,0 +1,162 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_UTILS_H_ +#define FPDFSDK_PDFWINDOW_CPWL_UTILS_H_ + +#include "core/fpdfdoc/cpvt_wordrange.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CFX_Edit; +struct CPWL_Color; + +#define PWL_MAKEDWORD(low, high) \ + ((uint32_t)((uint16_t)(low) | (uint32_t)(((uint16_t)(high)) << 16))) + +// checkbox & radiobutton style +#define PCS_CHECK 0 +#define PCS_CIRCLE 1 +#define PCS_CROSS 2 +#define PCS_DIAMOND 3 +#define PCS_SQUARE 4 +#define PCS_STAR 5 + +// pushbutton layout style +#define PPBL_LABEL 0 +#define PPBL_ICON 1 +#define PPBL_ICONTOPLABELBOTTOM 2 +#define PPBL_LABELTOPICONBOTTOM 3 +#define PPBL_ICONLEFTLABELRIGHT 4 +#define PPBL_LABELLEFTICONRIGHT 5 +#define PPBL_LABELOVERICON 6 + +class CPWL_Utils { + public: + static CFX_FloatRect InflateRect(const CFX_FloatRect& rcRect, float fSize); + static CFX_FloatRect DeflateRect(const CFX_FloatRect& rcRect, float fSize); + + static CPVT_WordRange OverlapWordRange(const CPVT_WordRange& wr1, + const CPVT_WordRange& wr2); + static CFX_FloatRect GetCenterSquare(const CFX_FloatRect& rect); + + static CFX_FloatRect OffsetRect(const CFX_FloatRect& rect, float x, float y); + + static CFX_ByteString GetColorAppStream(const CPWL_Color& color, + const bool& bFillOrStroke = true); + static CFX_ByteString GetBorderAppStream(const CFX_FloatRect& rect, + float fWidth, + const CPWL_Color& color, + const CPWL_Color& crLeftTop, + const CPWL_Color& crRightBottom, + BorderStyle nStyle, + const CPWL_Dash& dash); + static CFX_ByteString GetCircleBorderAppStream( + const CFX_FloatRect& rect, + float fWidth, + const CPWL_Color& color, + const CPWL_Color& crLeftTop, + const CPWL_Color& crRightBottom, + BorderStyle nStyle, + const CPWL_Dash& dash); + static CFX_ByteString GetRectFillAppStream(const CFX_FloatRect& rect, + const CPWL_Color& color); + static CFX_ByteString GetCircleFillAppStream(const CFX_FloatRect& rect, + const CPWL_Color& color); + static CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox, + IPVT_FontMap* pFontMap, + CPDF_Stream* pIconStream, + CPDF_IconFit& IconFit, + const CFX_WideString& sLabel, + const CPWL_Color& crText, + float fFontSize, + int32_t nLayOut); + static CFX_ByteString GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, + int32_t nStyle, + const CPWL_Color& crText); + static CFX_ByteString GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, + int32_t nStyle, + const CPWL_Color& crText); + static CFX_ByteString GetEditAppStream(CFX_Edit* pEdit, + const CFX_PointF& ptOffset, + const CPVT_WordRange* pRange = nullptr, + bool bContinuous = true, + uint16_t SubWord = 0); + static CFX_ByteString GetEditSelAppStream( + CFX_Edit* pEdit, + const CFX_PointF& ptOffset, + const CPVT_WordRange* pRange = nullptr); + static CFX_ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox); + + static void DrawFillRect(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const CPWL_Color& color, + int32_t nTransparency); + static void DrawFillRect(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color); + static void DrawStrokeRect(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color, + float fWidth); + static void DrawStrokeLine(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_PointF& ptMoveTo, + const CFX_PointF& ptLineTo, + const FX_COLORREF& color, + float fWidth); + static void DrawBorder(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + float fWidth, + const CPWL_Color& color, + const CPWL_Color& crLeftTop, + const CPWL_Color& crRightBottom, + BorderStyle nStyle, + int32_t nTransparency); + static void DrawFillArea(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_PointF* pPts, + int32_t nCount, + const FX_COLORREF& color); + static void DrawShadow(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + bool bVertical, + bool bHorizontal, + CFX_FloatRect rect, + int32_t nTransparency, + int32_t nStartGray, + int32_t nEndGray); + + private: + static CFX_FloatRect ScaleRect(const CFX_FloatRect& rcRect, float fScale); + + static CFX_ByteString GetAppStream_Check(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText); + static CFX_ByteString GetAppStream_Circle(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText); + static CFX_ByteString GetAppStream_Cross(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText); + static CFX_ByteString GetAppStream_Diamond(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText); + static CFX_ByteString GetAppStream_Square(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText); + static CFX_ByteString GetAppStream_Star(const CFX_FloatRect& rcBBox, + const CPWL_Color& crText); + + static CFX_ByteString GetAP_Check(const CFX_FloatRect& crBBox); + static CFX_ByteString GetAP_Circle(const CFX_FloatRect& crBBox); + static CFX_ByteString GetAP_Cross(const CFX_FloatRect& crBBox); + static CFX_ByteString GetAP_Diamond(const CFX_FloatRect& crBBox); + static CFX_ByteString GetAP_Square(const CFX_FloatRect& crBBox); + static CFX_ByteString GetAP_Star(const CFX_FloatRect& crBBox); + static CFX_ByteString GetAP_HalfCircle(const CFX_FloatRect& crBBox, + float fRotate); +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_UTILS_H_ diff --git a/fpdfsdk/pdfwindow/cpwl_wnd.cpp b/fpdfsdk/pdfwindow/cpwl_wnd.cpp new file mode 100644 index 0000000000..57e2643220 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_wnd.cpp @@ -0,0 +1,830 @@ +// 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 "fpdfsdk/pdfwindow/cpwl_wnd.h" + +#include +#include + +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_utils.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" + +PWL_CREATEPARAM::PWL_CREATEPARAM() + : rcRectWnd(0, 0, 0, 0), + pSystemHandler(nullptr), + pFontMap(nullptr), + pProvider(nullptr), + pFocusHandler(nullptr), + dwFlags(0), + sBackgroundColor(), + pAttachedWidget(nullptr), + nBorderStyle(BorderStyle::SOLID), + dwBorderWidth(1), + sBorderColor(), + sTextColor(), + nTransparency(255), + fFontSize(PWL_DEFAULT_FONTSIZE), + sDash(3, 0, 0), + pAttachedData(nullptr), + pParentWnd(nullptr), + pMsgControl(nullptr), + eCursorType(FXCT_ARROW) {} + +PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default; + +class CPWL_MsgControl { + friend class CPWL_Wnd; + + public: + explicit CPWL_MsgControl(CPWL_Wnd* pWnd) { + m_pCreatedWnd = pWnd; + Default(); + } + + ~CPWL_MsgControl() { Default(); } + + void Default() { + m_aMousePath.clear(); + m_aKeyboardPath.clear(); + m_pMainMouseWnd = nullptr; + m_pMainKeyboardWnd = nullptr; + } + + bool IsWndCreated(const CPWL_Wnd* pWnd) const { + return m_pCreatedWnd == pWnd; + } + + bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const { + return pWnd == m_pMainMouseWnd; + } + + bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { + return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd); + } + + bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const { + return pWnd == m_pMainKeyboardWnd; + } + + bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { + return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd); + } + + void SetFocus(CPWL_Wnd* pWnd) { + m_aKeyboardPath.clear(); + if (pWnd) { + m_pMainKeyboardWnd = pWnd; + CPWL_Wnd* pParent = pWnd; + while (pParent) { + m_aKeyboardPath.push_back(pParent); + pParent = pParent->GetParentWindow(); + } + pWnd->OnSetFocus(); + } + } + + void KillFocus() { + if (!m_aKeyboardPath.empty()) + if (CPWL_Wnd* pWnd = m_aKeyboardPath[0]) + pWnd->OnKillFocus(); + + m_pMainKeyboardWnd = nullptr; + m_aKeyboardPath.clear(); + } + + void SetCapture(CPWL_Wnd* pWnd) { + m_aMousePath.clear(); + if (pWnd) { + m_pMainMouseWnd = pWnd; + CPWL_Wnd* pParent = pWnd; + while (pParent) { + m_aMousePath.push_back(pParent); + pParent = pParent->GetParentWindow(); + } + } + } + + void ReleaseCapture() { + m_pMainMouseWnd = nullptr; + m_aMousePath.clear(); + } + + private: + std::vector m_aMousePath; + std::vector m_aKeyboardPath; + CFX_UnownedPtr m_pCreatedWnd; + CFX_UnownedPtr m_pMainMouseWnd; + CFX_UnownedPtr m_pMainKeyboardWnd; +}; + +CPWL_Wnd::CPWL_Wnd() + : m_rcWindow(), + m_rcClip(), + m_bCreated(false), + m_bVisible(false), + m_bNotifying(false), + m_bEnabled(true) {} + +CPWL_Wnd::~CPWL_Wnd() { + ASSERT(!m_bCreated); +} + +CFX_ByteString CPWL_Wnd::GetClassName() const { + return "CPWL_Wnd"; +} + +void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { + if (IsValid()) + return; + + m_sPrivateParam = cp; + OnCreate(m_sPrivateParam); + + m_sPrivateParam.rcRectWnd.Normalize(); + m_rcWindow = m_sPrivateParam.rcRectWnd; + m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f); + CreateMsgControl(); + + if (m_sPrivateParam.pParentWnd) + m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD); + + PWL_CREATEPARAM ccp = m_sPrivateParam; + + ccp.dwFlags &= 0xFFFF0000L; // remove sub styles + CreateScrollBar(ccp); + CreateChildWnd(ccp); + + m_bVisible = HasFlag(PWS_VISIBLE); + OnCreated(); + + RePosChildWnd(); + m_bCreated = true; +} + +void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} + +void CPWL_Wnd::OnCreated() {} + +void CPWL_Wnd::OnDestroy() {} + +void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) { + if (m_sPrivateParam.pFocusHandler == handler) + m_sPrivateParam.pFocusHandler = nullptr; +} + +void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) { + if (m_sPrivateParam.pProvider.Get() == provider) + m_sPrivateParam.pProvider.Reset(); +} + +void CPWL_Wnd::Destroy() { + KillFocus(); + OnDestroy(); + if (m_bCreated) { + for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { + if (CPWL_Wnd* pChild = *it) { + *it = nullptr; + pChild->Destroy(); + delete pChild; + } + } + if (m_sPrivateParam.pParentWnd) + m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD); + + m_bCreated = false; + } + DestroyMsgControl(); + m_sPrivateParam.Reset(); + m_Children.clear(); + m_pVScrollBar = nullptr; +} + +void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) { + if (!IsValid()) + return; + + CFX_FloatRect rcOld = GetWindowRect(); + m_rcWindow = rcNew; + m_rcWindow.Normalize(); + + if (bReset) { + if (rcOld.left != rcNew.left || rcOld.right != rcNew.right || + rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) { + RePosChildWnd(); + } + } + if (bRefresh) + InvalidateRectMove(rcOld, rcNew); + + m_sPrivateParam.rcRectWnd = m_rcWindow; +} + +void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, + const CFX_FloatRect& rcNew) { + CFX_FloatRect rcUnion = rcOld; + rcUnion.Union(rcNew); + + InvalidateRect(&rcUnion); +} + +void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) { + if (IsValid() && IsVisible()) { + GetThisAppearanceStream(sAppStream); + GetChildAppearanceStream(sAppStream); + } +} + +// if don't set,Get default apperance stream +void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { + CFX_FloatRect rectWnd = GetWindowRect(); + if (rectWnd.IsEmpty()) + return; + + CFX_ByteTextBuf sThis; + + if (HasFlag(PWS_BACKGROUND)) + sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor()); + + if (HasFlag(PWS_BORDER)) { + sThis << CPWL_Utils::GetBorderAppStream( + rectWnd, (float)GetBorderWidth(), GetBorderColor(), + GetBorderLeftTopColor(GetBorderStyle()), + GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), + GetBorderDash()); + } + + sAppStream << sThis; +} + +void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) { + for (CPWL_Wnd* pChild : m_Children) { + if (pChild) + pChild->GetAppearanceStream(sAppStream); + } +} + +void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + if (IsValid() && IsVisible()) { + DrawThisAppearance(pDevice, pUser2Device); + DrawChildAppearance(pDevice, pUser2Device); + } +} + +void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CFX_FloatRect rectWnd = GetWindowRect(); + if (rectWnd.IsEmpty()) + return; + + if (HasFlag(PWS_BACKGROUND)) { + CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( + rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth())); + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, + GetBackgroundColor(), GetTransparency()); + } + + if (HasFlag(PWS_BORDER)) { + CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd, + (float)GetBorderWidth(), GetBorderColor(), + GetBorderLeftTopColor(GetBorderStyle()), + GetBorderRightBottomColor(GetBorderStyle()), + GetBorderStyle(), GetTransparency()); + } +} + +void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + for (CPWL_Wnd* pChild : m_Children) { + if (!pChild) + continue; + + CFX_Matrix mt = pChild->GetChildMatrix(); + if (mt.IsIdentity()) { + pChild->DrawAppearance(pDevice, pUser2Device); + } else { + mt.Concat(*pUser2Device); + pChild->DrawAppearance(pDevice, &mt); + } + } +} + +void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { + if (!IsValid()) + return; + + CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); + + if (!HasFlag(PWS_NOREFRESHCLIP)) { + CFX_FloatRect rcClip = GetClipRect(); + if (!rcClip.IsEmpty()) { + rcRefresh.Intersect(rcClip); + } + } + + FX_RECT rcWin = PWLtoWnd(rcRefresh); + rcWin.left -= PWL_INVALIDATE_INFLATE; + rcWin.top -= PWL_INVALIDATE_INFLATE; + rcWin.right += PWL_INVALIDATE_INFLATE; + rcWin.bottom += PWL_INVALIDATE_INFLATE; + + if (CFX_SystemHandler* pSH = GetSystemHandler()) { + if (CPDFSDK_Widget* widget = static_cast( + m_sPrivateParam.pAttachedWidget.Get())) { + pSH->InvalidateRect(widget, rcWin); + } + } +} + +#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ + bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \ + if (!IsValid() || !IsVisible() || !IsEnabled()) \ + return false; \ + if (!IsWndCaptureKeyboard(this)) \ + return false; \ + for (auto* pChild : m_Children) { \ + if (pChild && IsWndCaptureKeyboard(pChild)) \ + return pChild->key_method_name(nChar, nFlag); \ + } \ + return false; \ + } + +PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) +PWL_IMPLEMENT_KEY_METHOD(OnChar) +#undef PWL_IMPLEMENT_KEY_METHOD + +#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ + bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \ + if (!IsValid() || !IsVisible() || !IsEnabled()) \ + return false; \ + if (IsWndCaptureMouse(this)) { \ + for (auto* pChild : m_Children) { \ + if (pChild && IsWndCaptureMouse(pChild)) { \ + return pChild->mouse_method_name(pChild->ParentToChild(point), \ + nFlag); \ + } \ + } \ + SetCursor(); \ + return false; \ + } \ + for (auto* pChild : m_Children) { \ + if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \ + return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \ + } \ + } \ + if (WndHitTest(point)) \ + SetCursor(); \ + return false; \ + } + +PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk) +PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown) +PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp) +PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown) +PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) +PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) +#undef PWL_IMPLEMENT_MOUSE_METHOD + +bool CPWL_Wnd::OnMouseWheel(short zDelta, + const CFX_PointF& point, + uint32_t nFlag) { + if (!IsValid() || !IsVisible() || !IsEnabled()) + return false; + + SetCursor(); + if (!IsWndCaptureKeyboard(this)) + return false; + + for (auto* pChild : m_Children) { + if (pChild && IsWndCaptureKeyboard(pChild)) + return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag); + } + return false; +} + +void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { + m_Children.push_back(pWnd); +} + +void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { + for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { + if (*it && *it == pWnd) { + m_Children.erase(std::next(it).base()); + break; + } + } +} + +void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam, + intptr_t lParam) { + switch (msg) { + case PNM_ADDCHILD: + AddChild(pWnd); + break; + case PNM_REMOVECHILD: + RemoveChild(pWnd); + break; + default: + break; + } +} + +bool CPWL_Wnd::IsValid() const { + return m_bCreated; +} + +const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const { + return m_sPrivateParam; +} + +CPWL_Wnd* CPWL_Wnd::GetParentWindow() const { + return m_sPrivateParam.pParentWnd; +} + +CFX_FloatRect CPWL_Wnd::GetWindowRect() const { + return m_rcWindow; +} + +CFX_FloatRect CPWL_Wnd::GetClientRect() const { + CFX_FloatRect rcWindow = GetWindowRect(); + CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( + rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth())); + if (CPWL_ScrollBar* pVSB = GetVScrollBar()) + rcClient.right -= pVSB->GetScrollBarWidth(); + + rcClient.Normalize(); + return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect(); +} + +CFX_PointF CPWL_Wnd::GetCenterPoint() const { + CFX_FloatRect rcClient = GetClientRect(); + return CFX_PointF((rcClient.left + rcClient.right) * 0.5f, + (rcClient.top + rcClient.bottom) * 0.5f); +} + +bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const { + return (m_sPrivateParam.dwFlags & dwFlags) != 0; +} + +void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) { + m_sPrivateParam.dwFlags &= ~dwFlags; +} + +void CPWL_Wnd::AddFlag(uint32_t dwFlags) { + m_sPrivateParam.dwFlags |= dwFlags; +} + +CPWL_Color CPWL_Wnd::GetBackgroundColor() const { + return m_sPrivateParam.sBackgroundColor; +} + +void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) { + m_sPrivateParam.sBackgroundColor = color; +} + +CPWL_Color CPWL_Wnd::GetTextColor() const { + return m_sPrivateParam.sTextColor; +} + +BorderStyle CPWL_Wnd::GetBorderStyle() const { + return m_sPrivateParam.nBorderStyle; +} + +void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) { + if (HasFlag(PWS_BORDER)) + m_sPrivateParam.nBorderStyle = nBorderStyle; +} + +int32_t CPWL_Wnd::GetBorderWidth() const { + return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0; +} + +int32_t CPWL_Wnd::GetInnerBorderWidth() const { + return 0; +} + +CPWL_Color CPWL_Wnd::GetBorderColor() const { + return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color(); +} + +const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { + return m_sPrivateParam.sDash; +} + +void* CPWL_Wnd::GetAttachedData() const { + return m_sPrivateParam.pAttachedData; +} + +CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { + return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr; +} + +void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { + CreateVScrollBar(cp); +} + +void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { + if (m_pVScrollBar || !HasFlag(PWS_VSCROLL)) + return; + + PWL_CREATEPARAM scp = cp; + + // flags + scp.dwFlags = + PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; + + scp.pParentWnd = this; + scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; + scp.eCursorType = FXCT_ARROW; + scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; + + m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); + m_pVScrollBar->Create(scp); +} + +void CPWL_Wnd::SetCapture() { + if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) + pMsgCtrl->SetCapture(this); +} + +void CPWL_Wnd::ReleaseCapture() { + for (auto* pChild : m_Children) { + if (pChild) + pChild->ReleaseCapture(); + } + if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) + pMsgCtrl->ReleaseCapture(); +} + +void CPWL_Wnd::SetFocus() { + if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { + if (!pMsgCtrl->IsMainCaptureKeyboard(this)) + pMsgCtrl->KillFocus(); + pMsgCtrl->SetFocus(this); + } +} + +void CPWL_Wnd::KillFocus() { + if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { + if (pMsgCtrl->IsWndCaptureKeyboard(this)) + pMsgCtrl->KillFocus(); + } +} + +void CPWL_Wnd::OnSetFocus() {} + +void CPWL_Wnd::OnKillFocus() {} + +bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const { + return IsValid() && IsVisible() && GetWindowRect().Contains(point); +} + +bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const { + return IsValid() && IsVisible() && GetClientRect().Contains(point); +} + +const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { + auto* pParent = m_sPrivateParam.pParentWnd; + return pParent ? pParent->GetRootWnd() : this; +} + +void CPWL_Wnd::SetVisible(bool bVisible) { + if (!IsValid()) + return; + + for (auto* pChild : m_Children) { + if (pChild) + pChild->SetVisible(bVisible); + } + if (bVisible != m_bVisible) { + m_bVisible = bVisible; + RePosChildWnd(); + InvalidateRect(); + } +} + +void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) { + m_rcClip = rect; + m_rcClip.Normalize(); +} + +const CFX_FloatRect& CPWL_Wnd::GetClipRect() const { + return m_rcClip; +} + +bool CPWL_Wnd::IsReadOnly() const { + return HasFlag(PWS_READONLY); +} + +void CPWL_Wnd::RePosChildWnd() { + CPWL_ScrollBar* pVSB = GetVScrollBar(); + if (!pVSB) + return; + + CFX_FloatRect rcContent = CPWL_Utils::DeflateRect( + GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); + CFX_FloatRect rcVScroll = + CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, + rcContent.right - 1.0f, rcContent.top); + pVSB->Move(rcVScroll, true, false); +} + +void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} + +void CPWL_Wnd::SetCursor() { + if (IsValid()) { + if (CFX_SystemHandler* pSH = GetSystemHandler()) { + int32_t nCursorType = GetCreationParam().eCursorType; + pSH->SetCursor(nCursorType); + } + } +} + +void CPWL_Wnd::CreateMsgControl() { + if (!m_sPrivateParam.pMsgControl) + m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); +} + +void CPWL_Wnd::DestroyMsgControl() { + CPWL_MsgControl* pMsgControl = GetMsgControl(); + if (pMsgControl && pMsgControl->IsWndCreated(this)) + delete pMsgControl; +} + +CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { + return m_sPrivateParam.pMsgControl; +} + +bool CPWL_Wnd::IsCaptureMouse() const { + return IsWndCaptureMouse(this); +} + +bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { + CPWL_MsgControl* pCtrl = GetMsgControl(); + return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false; +} + +bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { + CPWL_MsgControl* pCtrl = GetMsgControl(); + return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false; +} + +bool CPWL_Wnd::IsFocused() const { + CPWL_MsgControl* pCtrl = GetMsgControl(); + return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false; +} + +CFX_FloatRect CPWL_Wnd::GetFocusRect() const { + return CPWL_Utils::InflateRect(GetWindowRect(), 1); +} + +float CPWL_Wnd::GetFontSize() const { + return m_sPrivateParam.fFontSize; +} + +void CPWL_Wnd::SetFontSize(float fFontSize) { + m_sPrivateParam.fFontSize = fFontSize; +} + +CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { + return m_sPrivateParam.pSystemHandler; +} + +IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { + return m_sPrivateParam.pFocusHandler; +} + +IPWL_Provider* CPWL_Wnd::GetProvider() const { + return m_sPrivateParam.pProvider.Get(); +} + +IPVT_FontMap* CPWL_Wnd::GetFontMap() const { + return m_sPrivateParam.pFontMap; +} + +CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { + switch (nBorderStyle) { + case BorderStyle::BEVELED: + return CPWL_Color(COLORTYPE_GRAY, 1); + case BorderStyle::INSET: + return CPWL_Color(COLORTYPE_GRAY, 0.5f); + default: + return CPWL_Color(); + } +} + +CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { + switch (nBorderStyle) { + case BorderStyle::BEVELED: + return GetBackgroundColor() / 2.0f; + case BorderStyle::INSET: + return CPWL_Color(COLORTYPE_GRAY, 0.75f); + default: + return CPWL_Color(); + } +} + +int32_t CPWL_Wnd::GetTransparency() { + return m_sPrivateParam.nTransparency; +} + +void CPWL_Wnd::SetTransparency(int32_t nTransparency) { + for (auto* pChild : m_Children) { + if (pChild) + pChild->SetTransparency(nTransparency); + } + m_sPrivateParam.nTransparency = nTransparency; +} + +CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { + CFX_Matrix mt = GetChildToRoot(); + if (IPWL_Provider* pProvider = GetProvider()) + mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); + return mt; +} + +FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { + CFX_FloatRect rcTemp = rect; + CFX_Matrix mt = GetWindowMatrix(); + mt.TransformRect(rcTemp); + return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), + (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5)); +} + +CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const { + CFX_Matrix mt = GetChildMatrix(); + if (mt.IsIdentity()) + return point; + + mt.SetReverse(mt); + return mt.Transform(point); +} + +CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { + CFX_Matrix mt = GetChildMatrix(); + if (mt.IsIdentity()) + return rect; + + mt.SetReverse(mt); + CFX_FloatRect rc = rect; + mt.TransformRect(rc); + return rc; +} + +CFX_Matrix CPWL_Wnd::GetChildToRoot() const { + CFX_Matrix mt; + if (HasFlag(PWS_CHILD)) { + const CPWL_Wnd* pParent = this; + while (pParent) { + mt.Concat(pParent->GetChildMatrix()); + pParent = pParent->GetParentWindow(); + } + } + return mt; +} + +CFX_Matrix CPWL_Wnd::GetChildMatrix() const { + return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix(); +} + +void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { + m_sPrivateParam.mtChild = mt; +} + +const CPWL_Wnd* CPWL_Wnd::GetFocused() const { + CPWL_MsgControl* pMsgCtrl = GetMsgControl(); + return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr; +} + +void CPWL_Wnd::EnableWindow(bool bEnable) { + if (m_bEnabled == bEnable) + return; + + for (auto* pChild : m_Children) { + if (pChild) + pChild->EnableWindow(bEnable); + } + m_bEnabled = bEnable; +} + +bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const { + CFX_SystemHandler* pSystemHandler = GetSystemHandler(); + return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag); +} + +bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const { + CFX_SystemHandler* pSystemHandler = GetSystemHandler(); + return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag); +} + +bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const { + CFX_SystemHandler* pSystemHandler = GetSystemHandler(); + return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag); +} diff --git a/fpdfsdk/pdfwindow/cpwl_wnd.h b/fpdfsdk/pdfwindow/cpwl_wnd.h new file mode 100644 index 0000000000..86b0c66272 --- /dev/null +++ b/fpdfsdk/pdfwindow/cpwl_wnd.h @@ -0,0 +1,370 @@ +// 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 FPDFSDK_PDFWINDOW_CPWL_WND_H_ +#define FPDFSDK_PDFWINDOW_CPWL_WND_H_ + +#include +#include + +#include "core/fpdfdoc/cpdf_formcontrol.h" +#include "core/fxcrt/cfx_observable.h" +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_basic.h" +#include "fpdfsdk/cpdfsdk_widget.h" +#include "fpdfsdk/pdfwindow/cpwl_color.h" +#include "fpdfsdk/pdfwindow/cpwl_timer.h" +#include "fpdfsdk/pdfwindow/cpwl_timer_handler.h" + +class CPWL_MsgControl; +class CPWL_ScrollBar; +class CPWL_Wnd; +class CFX_SystemHandler; +class IPVT_FontMap; +class IPWL_Provider; + +// window styles +#define PWS_CHILD 0x80000000L +#define PWS_BORDER 0x40000000L +#define PWS_BACKGROUND 0x20000000L +#define PWS_HSCROLL 0x10000000L +#define PWS_VSCROLL 0x08000000L +#define PWS_VISIBLE 0x04000000L +#define PWS_DISABLE 0x02000000L +#define PWS_READONLY 0x01000000L +#define PWS_AUTOFONTSIZE 0x00800000L +#define PWS_AUTOTRANSPARENT 0x00400000L +#define PWS_NOREFRESHCLIP 0x00200000L + +// edit and label styles +#define PES_MULTILINE 0x0001L +#define PES_PASSWORD 0x0002L +#define PES_LEFT 0x0004L +#define PES_RIGHT 0x0008L +#define PES_MIDDLE 0x0010L +#define PES_TOP 0x0020L +#define PES_BOTTOM 0x0040L +#define PES_CENTER 0x0080L +#define PES_CHARARRAY 0x0100L +#define PES_AUTOSCROLL 0x0200L +#define PES_AUTORETURN 0x0400L +#define PES_UNDO 0x0800L +#define PES_RICH 0x1000L +#define PES_SPELLCHECK 0x2000L +#define PES_TEXTOVERFLOW 0x4000L +#define PES_NOREAD 0x8000L + +// listbox styles +#define PLBS_MULTIPLESEL 0x0001L +#define PLBS_HOVERSEL 0x0008L + +// combobox styles +#define PCBS_ALLOWCUSTOMTEXT 0x0001L + +// richedit styles +#define PRES_MULTILINE 0x0001L +#define PRES_AUTORETURN 0x0002L +#define PRES_AUTOSCROLL 0x0004L +#define PRES_UNDO 0x0100L +#define PRES_MULTIPAGES 0x0200L +#define PRES_TEXTOVERFLOW 0x0400L + +// notification messages +#define PNM_ADDCHILD 0x00000000L +#define PNM_REMOVECHILD 0x00000001L +#define PNM_SETSCROLLINFO 0x00000002L +#define PNM_SETSCROLLPOS 0x00000003L +#define PNM_SCROLLWINDOW 0x00000004L +#define PNM_LBUTTONDOWN 0x00000005L +#define PNM_LBUTTONUP 0x00000006L +#define PNM_MOUSEMOVE 0x00000007L +#define PNM_NOTERESET 0x00000008L +#define PNM_SETCARETINFO 0x00000009L +#define PNM_SELCHANGED 0x0000000AL +#define PNM_NOTEEDITCHANGED 0x0000000BL + +#define PWL_CLASSNAME_EDIT "CPWL_Edit" + +struct CPWL_Dash { + CPWL_Dash() : nDash(0), nGap(0), nPhase(0) {} + CPWL_Dash(int32_t dash, int32_t gap, int32_t phase) + : nDash(dash), nGap(gap), nPhase(phase) {} + + void Reset() { + nDash = 0; + nGap = 0; + nPhase = 0; + } + + int32_t nDash; + int32_t nGap; + int32_t nPhase; +}; + +inline bool operator==(const CPWL_Color& c1, const CPWL_Color& c2) { + return c1.nColorType == c2.nColorType && c1.fColor1 - c2.fColor1 < 0.0001 && + c1.fColor1 - c2.fColor1 > -0.0001 && + c1.fColor2 - c2.fColor2 < 0.0001 && + c1.fColor2 - c2.fColor2 > -0.0001 && + c1.fColor3 - c2.fColor3 < 0.0001 && + c1.fColor3 - c2.fColor3 > -0.0001 && + c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001; +} + +inline bool operator!=(const CPWL_Color& c1, const CPWL_Color& c2) { + return !(c1 == c2); +} + +#define PWL_SCROLLBAR_WIDTH 12.0f +#define PWL_SCROLLBAR_BUTTON_WIDTH 9.0f +#define PWL_SCROLLBAR_POSBUTTON_MINWIDTH 2.0f +#define PWL_SCROLLBAR_TRANSPARENCY 150 +#define PWL_SCROLLBAR_BKCOLOR \ + CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f) +#define PWL_DEFAULT_SELTEXTCOLOR CPWL_Color(COLORTYPE_RGB, 1, 1, 1) +#define PWL_DEFAULT_SELBACKCOLOR \ + CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f) +#define PWL_DEFAULT_BACKCOLOR PWL_DEFAULT_SELTEXTCOLOR +#define PWL_DEFAULT_TEXTCOLOR CPWL_Color(COLORTYPE_RGB, 0, 0, 0) +#define PWL_DEFAULT_FONTSIZE 9.0f +#define PWL_DEFAULT_BLACKCOLOR CPWL_Color(COLORTYPE_GRAY, 0) +#define PWL_DEFAULT_WHITECOLOR CPWL_Color(COLORTYPE_GRAY, 1) +#define PWL_DEFAULT_HEAVYGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.50) +#define PWL_DEFAULT_LIGHTGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.75) +#define PWL_TRIANGLE_HALFLEN 2.0f +#define PWL_CBBUTTON_TRIANGLE_HALFLEN 3.0f +#define PWL_INVALIDATE_INFLATE 2 + +class IPWL_Provider : public CFX_Observable { + public: + virtual ~IPWL_Provider() {} + + // get a matrix which map user space to CWnd client space + virtual CFX_Matrix GetWindowMatrix(void* pAttachedData) = 0; +}; + +class IPWL_FocusHandler { + public: + virtual ~IPWL_FocusHandler() {} + virtual void OnSetFocus(CPWL_Wnd* pWnd) = 0; +}; + +struct PWL_CREATEPARAM { + public: + PWL_CREATEPARAM(); + PWL_CREATEPARAM(const PWL_CREATEPARAM& other); + + void Reset() { + rcRectWnd.Reset(); + pSystemHandler = nullptr; + pFontMap = nullptr; + pProvider.Reset(); + pFocusHandler = nullptr; + dwFlags = 0; + sBackgroundColor.Reset(); + pAttachedWidget.Reset(); + nBorderStyle = BorderStyle::SOLID; + dwBorderWidth = 0; + sBorderColor.Reset(); + sTextColor.Reset(); + nTransparency = 0; + fFontSize = 0.0f; + sDash.Reset(); + pAttachedData = nullptr; + pParentWnd = nullptr; + pMsgControl = nullptr; + eCursorType = 0; + mtChild.SetIdentity(); + } + + CFX_FloatRect rcRectWnd; // required + CFX_SystemHandler* pSystemHandler; // required + IPVT_FontMap* pFontMap; // required + IPWL_Provider::ObservedPtr pProvider; // required + IPWL_FocusHandler* pFocusHandler; // optional + uint32_t dwFlags; // optional + CPWL_Color sBackgroundColor; // optional + CPDFSDK_Widget::ObservedPtr pAttachedWidget; // required + BorderStyle nBorderStyle; // optional + int32_t dwBorderWidth; // optional + CPWL_Color sBorderColor; // optional + CPWL_Color sTextColor; // optional + int32_t nTransparency; // optional + float fFontSize; // optional + CPWL_Dash sDash; // optional + void* pAttachedData; // optional + CPWL_Wnd* pParentWnd; // ignore + CPWL_MsgControl* pMsgControl; // ignore + int32_t eCursorType; // ignore + CFX_Matrix mtChild; // ignore +}; + +class CPWL_Wnd : public CPWL_TimerHandler { + public: + CPWL_Wnd(); + ~CPWL_Wnd() override; + + virtual CFX_ByteString GetClassName() const; + virtual void InvalidateRect(CFX_FloatRect* pRect = nullptr); + + virtual bool OnKeyDown(uint16_t nChar, uint32_t nFlag); + virtual bool OnChar(uint16_t nChar, uint32_t nFlag); + virtual bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag); + virtual bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag); + virtual bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag); + virtual bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag); + virtual bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag); + virtual bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag); + virtual bool OnMouseWheel(short zDelta, + const CFX_PointF& point, + uint32_t nFlag); + virtual void OnNotify(CPWL_Wnd* pWnd, + uint32_t msg, + intptr_t wParam = 0, + intptr_t lParam = 0); + virtual void SetFocus(); + virtual void KillFocus(); + virtual void SetCursor(); + virtual void SetVisible(bool bVisible); + virtual void SetFontSize(float fFontSize); + virtual float GetFontSize() const; + + virtual CFX_FloatRect GetFocusRect() const; + virtual CFX_FloatRect GetClientRect() const; + + void InvalidateFocusHandler(IPWL_FocusHandler* handler); + void InvalidateProvider(IPWL_Provider* provider); + void Create(const PWL_CREATEPARAM& cp); + void Destroy(); + void Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh); + + void SetCapture(); + void ReleaseCapture(); + + void DrawAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); + + CPWL_Color GetBackgroundColor() const; + void SetBackgroundColor(const CPWL_Color& color); + CPWL_Color GetBorderColor() const; + CPWL_Color GetTextColor() const; + void SetTextColor(const CPWL_Color& color); + CPWL_Color GetBorderLeftTopColor(BorderStyle nBorderStyle) const; + CPWL_Color GetBorderRightBottomColor(BorderStyle nBorderStyle) const; + + void SetBorderStyle(BorderStyle eBorderStyle); + BorderStyle GetBorderStyle() const; + const CPWL_Dash& GetBorderDash() const; + + int32_t GetBorderWidth() const; + int32_t GetInnerBorderWidth() const; + CFX_FloatRect GetWindowRect() const; + CFX_PointF GetCenterPoint() const; + + bool IsVisible() const { return m_bVisible; } + bool HasFlag(uint32_t dwFlags) const; + void AddFlag(uint32_t dwFlags); + void RemoveFlag(uint32_t dwFlags); + + void SetClipRect(const CFX_FloatRect& rect); + const CFX_FloatRect& GetClipRect() const; + + CPWL_Wnd* GetParentWindow() const; + void* GetAttachedData() const; + + bool WndHitTest(const CFX_PointF& point) const; + bool ClientHitTest(const CFX_PointF& point) const; + bool IsCaptureMouse() const; + + void EnableWindow(bool bEnable); + bool IsEnabled() const { return m_bEnabled; } + const CPWL_Wnd* GetFocused() const; + bool IsFocused() const; + bool IsReadOnly() const; + CPWL_ScrollBar* GetVScrollBar() const; + + IPVT_FontMap* GetFontMap() const; + IPWL_Provider* GetProvider() const; + IPWL_FocusHandler* GetFocusHandler() const; + + int32_t GetTransparency(); + void SetTransparency(int32_t nTransparency); + + CFX_Matrix GetChildToRoot() const; + CFX_Matrix GetChildMatrix() const; + void SetChildMatrix(const CFX_Matrix& mt); + CFX_Matrix GetWindowMatrix() const; + + protected: + friend class CPWL_MsgControl; + + // CPWL_TimerHandler + CFX_SystemHandler* GetSystemHandler() const override; + + virtual void CreateChildWnd(const PWL_CREATEPARAM& cp); + virtual void RePosChildWnd(); + virtual void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream); + + virtual void DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device); + + virtual void OnCreate(PWL_CREATEPARAM& cp); + virtual void OnCreated(); + virtual void OnDestroy(); + + virtual void OnSetFocus(); + virtual void OnKillFocus(); + + void GetAppearanceStream(CFX_ByteTextBuf& sAppStream); + void SetNotifyFlag(bool bNotifying = true) { m_bNotifying = bNotifying; } + + bool IsValid() const; + const PWL_CREATEPARAM& GetCreationParam() const; + bool IsNotifying() const { return m_bNotifying; } + + void InvalidateRectMove(const CFX_FloatRect& rcOld, + const CFX_FloatRect& rcNew); + + bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const; + bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const; + const CPWL_Wnd* GetRootWnd() const; + + bool IsCTRLpressed(uint32_t nFlag) const; + bool IsSHIFTpressed(uint32_t nFlag) const; + bool IsALTpressed(uint32_t nFlag) const; + + private: + CFX_PointF ParentToChild(const CFX_PointF& point) const; + CFX_FloatRect ParentToChild(const CFX_FloatRect& rect) const; + + void GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream); + void DrawChildAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); + + FX_RECT PWLtoWnd(const CFX_FloatRect& rect) const; + + void AddChild(CPWL_Wnd* pWnd); + void RemoveChild(CPWL_Wnd* pWnd); + + void CreateScrollBar(const PWL_CREATEPARAM& cp); + void CreateVScrollBar(const PWL_CREATEPARAM& cp); + + void AdjustStyle(); + void CreateMsgControl(); + void DestroyMsgControl(); + + CPWL_MsgControl* GetMsgControl() const; + + std::vector m_Children; + PWL_CREATEPARAM m_sPrivateParam; + CFX_UnownedPtr m_pVScrollBar; + CFX_FloatRect m_rcWindow; + CFX_FloatRect m_rcClip; + bool m_bCreated; + bool m_bVisible; + bool m_bNotifying; + bool m_bEnabled; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_WND_H_ -- cgit v1.2.3