1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_ 8 #define FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_ 9 10 #include "core/include/fpdfdoc/fpdf_doc.h" 11 #include "core/include/fxcrt/fx_basic.h" 12 #include "fpdfsdk/include/fx_systemhandler.h" 13 14 class CPWL_MsgControl; 15 class CPWL_ScrollBar; 16 class CPWL_Timer; 17 class CPWL_TimerHandler; 18 class CPWL_Wnd; 19 class IFX_Edit_FontMap; 20 class IFX_SystemHandler; 21 class IPWL_Provider; 22 class IPWL_SpellCheck; 23 24 // window styles 25 #define PWS_CHILD 0x80000000L 26 #define PWS_BORDER 0x40000000L 27 #define PWS_BACKGROUND 0x20000000L 28 #define PWS_HSCROLL 0x10000000L 29 #define PWS_VSCROLL 0x08000000L 30 #define PWS_VISIBLE 0x04000000L 31 #define PWS_DISABLE 0x02000000L 32 #define PWS_READONLY 0x01000000L 33 #define PWS_AUTOFONTSIZE 0x00800000L 34 #define PWS_AUTOTRANSPARENT 0x00400000L 35 #define PWS_NOREFRESHCLIP 0x00200000L 36 37 // edit and label styles 38 #define PES_MULTILINE 0x0001L 39 #define PES_PASSWORD 0x0002L 40 #define PES_LEFT 0x0004L 41 #define PES_RIGHT 0x0008L 42 #define PES_MIDDLE 0x0010L 43 #define PES_TOP 0x0020L 44 #define PES_BOTTOM 0x0040L 45 #define PES_CENTER 0x0080L 46 #define PES_CHARARRAY 0x0100L 47 #define PES_AUTOSCROLL 0x0200L 48 #define PES_AUTORETURN 0x0400L 49 #define PES_UNDO 0x0800L 50 #define PES_RICH 0x1000L 51 #define PES_SPELLCHECK 0x2000L 52 #define PES_TEXTOVERFLOW 0x4000L 53 #define PES_NOREAD 0x8000L 54 55 // listbox styles 56 #define PLBS_MULTIPLESEL 0x0001L 57 #define PLBS_HOVERSEL 0x0008L 58 59 // combobox styles 60 #define PCBS_ALLOWCUSTOMTEXT 0x0001L 61 62 // richedit styles 63 #define PRES_MULTILINE 0x0001L 64 #define PRES_AUTORETURN 0x0002L 65 #define PRES_AUTOSCROLL 0x0004L 66 #define PRES_SPELLCHECK 0x0008L 67 #define PRES_UNDO 0x0100L 68 #define PRES_MULTIPAGES 0x0200L 69 #define PRES_TEXTOVERFLOW 0x0400L 70 71 // border style 72 #define PBS_SOLID 0 73 #define PBS_DASH 1 74 #define PBS_BEVELED 2 75 #define PBS_INSET 3 76 #define PBS_UNDERLINED 4 77 #define PBS_SHADOW 5 78 79 // notification messages 80 #define PNM_ADDCHILD 0x00000000L 81 #define PNM_REMOVECHILD 0x00000001L 82 #define PNM_SETSCROLLINFO 0x00000002L 83 #define PNM_SETSCROLLPOS 0x00000003L 84 #define PNM_SCROLLWINDOW 0x00000004L 85 #define PNM_LBUTTONDOWN 0x00000005L 86 #define PNM_LBUTTONUP 0x00000006L 87 #define PNM_MOUSEMOVE 0x00000007L 88 #define PNM_NOTERESET 0x00000008L 89 #define PNM_SETCARETINFO 0x00000009L 90 #define PNM_SELCHANGED 0x0000000AL 91 #define PNM_NOTEEDITCHANGED 0x0000000BL 92 93 #define PWL_CLASSNAME_EDIT "CPWL_Edit" 94 95 struct CPWL_Dash { CPWL_DashCPWL_Dash96 CPWL_Dash(int32_t dash, int32_t gap, int32_t phase) 97 : nDash(dash), nGap(gap), nPhase(phase) {} 98 99 int32_t nDash; 100 int32_t nGap; 101 int32_t nPhase; 102 }; 103 104 struct CPWL_Color { 105 CPWL_Color(int32_t type = COLORTYPE_TRANSPARENT, 106 FX_FLOAT color1 = 0.0f, 107 FX_FLOAT color2 = 0.0f, 108 FX_FLOAT color3 = 0.0f, 109 FX_FLOAT color4 = 0.0f) nColorTypeCPWL_Color110 : nColorType(type), 111 fColor1(color1), 112 fColor2(color2), 113 fColor3(color3), 114 fColor4(color4) {} 115 CPWL_ColorCPWL_Color116 CPWL_Color(int32_t r, int32_t g, int32_t b) 117 : nColorType(COLORTYPE_RGB), 118 fColor1(r / 255.0f), 119 fColor2(g / 255.0f), 120 fColor3(b / 255.0f), 121 fColor4(0) {} 122 123 void ConvertColorType(int32_t other_nColorType); 124 125 /* 126 COLORTYPE_TRANSPARENT 127 COLORTYPE_RGB 128 COLORTYPE_CMYK 129 COLORTYPE_GRAY 130 */ 131 int32_t nColorType; 132 FX_FLOAT fColor1, fColor2, fColor3, fColor4; 133 }; 134 135 inline FX_BOOL operator==(const CPWL_Color& c1, const CPWL_Color& c2) { 136 return c1.nColorType == c2.nColorType && c1.fColor1 - c2.fColor1 < 0.0001 && 137 c1.fColor1 - c2.fColor1 > -0.0001 && 138 c1.fColor2 - c2.fColor2 < 0.0001 && 139 c1.fColor2 - c2.fColor2 > -0.0001 && 140 c1.fColor3 - c2.fColor3 < 0.0001 && 141 c1.fColor3 - c2.fColor3 > -0.0001 && 142 c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001; 143 } 144 145 inline FX_BOOL operator!=(const CPWL_Color& c1, const CPWL_Color& c2) { 146 return !operator==(c1, c2); 147 } 148 149 #define PWL_SCROLLBAR_WIDTH 12.0f 150 #define PWL_SCROLLBAR_BUTTON_WIDTH 9.0f 151 #define PWL_SCROLLBAR_POSBUTTON_MINWIDTH 2.0f 152 #define PWL_SCROLLBAR_TRANSPARANCY 150 153 #define PWL_SCROLLBAR_BKCOLOR \ 154 CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f) 155 #define PWL_DEFAULT_SELTEXTCOLOR CPWL_Color(COLORTYPE_RGB, 1, 1, 1) 156 #define PWL_DEFAULT_SELBACKCOLOR \ 157 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f) 158 #define PWL_DEFAULT_BACKCOLOR PWL_DEFAULT_SELTEXTCOLOR 159 #define PWL_DEFAULT_TEXTCOLOR CPWL_Color(COLORTYPE_RGB, 0, 0, 0) 160 #define PWL_DEFAULT_FONTSIZE 9.0f 161 #define PWL_DEFAULT_BLACKCOLOR CPWL_Color(COLORTYPE_GRAY, 0) 162 #define PWL_DEFAULT_WHITECOLOR CPWL_Color(COLORTYPE_GRAY, 1) 163 #define PWL_DEFAULT_HEAVYGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.50) 164 #define PWL_DEFAULT_LIGHTGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.75) 165 #define PWL_TRIANGLE_HALFLEN 2.0f 166 #define PWL_CBBUTTON_TRIANGLE_HALFLEN 3.0f 167 #define PWL_INVALIDATE_INFLATE 2 168 169 class IPWL_SpellCheck { 170 public: ~IPWL_SpellCheck()171 virtual ~IPWL_SpellCheck() {} 172 virtual FX_BOOL CheckWord(const FX_CHAR* sWord) = 0; 173 virtual void SuggestWords(const FX_CHAR* sWord, 174 CFX_ByteStringArray& sSuggest) = 0; 175 }; 176 177 class IPWL_Provider { 178 public: ~IPWL_Provider()179 virtual ~IPWL_Provider() {} 180 181 // get a matrix which map user space to CWnd client space 182 virtual CFX_Matrix GetWindowMatrix(void* pAttachedData) = 0; 183 184 /* 185 0 L"&Undo\tCtrl+Z" 186 1 L"&Redo\tCtrl+Shift+Z" 187 2 L"Cu&t\tCtrl+X" 188 3 L"&Copy\tCtrl+C" 189 4 L"&Paste\tCtrl+V" 190 5 L"&Delete" 191 6 L"&Select All\tCtrl+A" 192 */ 193 virtual CFX_WideString LoadPopupMenuString(int32_t nIndex) = 0; 194 }; 195 196 class IPWL_FocusHandler { 197 public: ~IPWL_FocusHandler()198 virtual ~IPWL_FocusHandler() {} 199 virtual void OnSetFocus(CPWL_Wnd* pWnd) = 0; 200 virtual void OnKillFocus(CPWL_Wnd* pWnd) = 0; 201 }; 202 203 struct PWL_CREATEPARAM { 204 public: PWL_CREATEPARAMPWL_CREATEPARAM205 PWL_CREATEPARAM() 206 : rcRectWnd(0, 0, 0, 0), 207 pSystemHandler(NULL), 208 pFontMap(NULL), 209 pProvider(NULL), 210 pFocusHandler(NULL), 211 dwFlags(0), 212 sBackgroundColor(), 213 hAttachedWnd(NULL), 214 pSpellCheck(NULL), 215 nBorderStyle(PBS_SOLID), 216 dwBorderWidth(1), 217 sBorderColor(), 218 sTextColor(), 219 sTextStrokeColor(), 220 nTransparency(255), 221 fFontSize(PWL_DEFAULT_FONTSIZE), 222 sDash(3, 0, 0), 223 pAttachedData(NULL), 224 pParentWnd(NULL), 225 pMsgControl(NULL), 226 eCursorType(FXCT_ARROW), 227 mtChild(1, 0, 0, 1, 0, 0) {} 228 229 CPDF_Rect rcRectWnd; // required 230 IFX_SystemHandler* pSystemHandler; // required 231 IFX_Edit_FontMap* pFontMap; // required for text window 232 IPWL_Provider* pProvider; // required for self coordinate 233 IPWL_FocusHandler* pFocusHandler; // optional 234 FX_DWORD dwFlags; // optional 235 CPWL_Color sBackgroundColor; // optional 236 FX_HWND hAttachedWnd; // required for no-reader framework 237 IPWL_SpellCheck* pSpellCheck; // required for spellchecking 238 int32_t nBorderStyle; // optional 239 int32_t dwBorderWidth; // optional 240 CPWL_Color sBorderColor; // optional 241 CPWL_Color sTextColor; // optional 242 CPWL_Color sTextStrokeColor; // optional 243 int32_t nTransparency; // optional 244 FX_FLOAT fFontSize; // optional 245 CPWL_Dash sDash; // optional 246 void* pAttachedData; // optional 247 CPWL_Wnd* pParentWnd; // ignore 248 CPWL_MsgControl* pMsgControl; // ignore 249 int32_t eCursorType; // ignore 250 CFX_Matrix mtChild; // ignore 251 }; 252 253 class CPWL_Timer { 254 public: 255 CPWL_Timer(CPWL_TimerHandler* pAttached, IFX_SystemHandler* pSystemHandler); 256 virtual ~CPWL_Timer(); 257 258 int32_t SetPWLTimer(int32_t nElapse); 259 void KillPWLTimer(); 260 static void TimerProc(int32_t idEvent); 261 262 private: 263 int32_t m_nTimerID; 264 CPWL_TimerHandler* m_pAttached; 265 IFX_SystemHandler* m_pSystemHandler; 266 }; 267 268 class CPWL_TimerHandler { 269 public: 270 CPWL_TimerHandler(); 271 virtual ~CPWL_TimerHandler(); 272 273 void BeginTimer(int32_t nElapse); 274 void EndTimer(); 275 virtual void TimerProc(); 276 virtual IFX_SystemHandler* GetSystemHandler() const = 0; 277 278 private: 279 CPWL_Timer* m_pTimer; 280 }; 281 282 class CPWL_Wnd : public CPWL_TimerHandler { 283 friend class CPWL_MsgControl; 284 285 public: 286 CPWL_Wnd(); 287 ~CPWL_Wnd() override; 288 289 void Create(const PWL_CREATEPARAM& cp); 290 virtual CFX_ByteString GetClassName() const; 291 void InvalidateFocusHandler(IPWL_FocusHandler* handler); 292 void InvalidateProvider(IPWL_Provider* provider); 293 void Destroy(); 294 void Move(const CPDF_Rect& rcNew, FX_BOOL bReset, FX_BOOL bRefresh); 295 virtual void InvalidateRect(CPDF_Rect* pRect = NULL); 296 297 void DrawAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); 298 299 virtual FX_BOOL OnKeyDown(FX_WORD nChar, FX_DWORD nFlag); 300 virtual FX_BOOL OnKeyUp(FX_WORD nChar, FX_DWORD nFlag); 301 virtual FX_BOOL OnChar(FX_WORD nChar, FX_DWORD nFlag); 302 virtual FX_BOOL OnLButtonDblClk(const CPDF_Point& point, FX_DWORD nFlag); 303 virtual FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag); 304 virtual FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag); 305 virtual FX_BOOL OnMButtonDblClk(const CPDF_Point& point, FX_DWORD nFlag); 306 virtual FX_BOOL OnMButtonDown(const CPDF_Point& point, FX_DWORD nFlag); 307 virtual FX_BOOL OnMButtonUp(const CPDF_Point& point, FX_DWORD nFlag); 308 virtual FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_DWORD nFlag); 309 virtual FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_DWORD nFlag); 310 virtual FX_BOOL OnMouseMove(const CPDF_Point& point, FX_DWORD nFlag); 311 virtual FX_BOOL OnMouseWheel(short zDelta, 312 const CPDF_Point& point, 313 FX_DWORD nFlag); 314 315 virtual void SetFocus(); 316 virtual void KillFocus(); 317 void SetCapture(); 318 void ReleaseCapture(); 319 320 virtual void OnNotify(CPWL_Wnd* pWnd, 321 FX_DWORD msg, 322 intptr_t wParam = 0, 323 intptr_t lParam = 0); 324 virtual void SetTextColor(const CPWL_Color& color); 325 virtual void SetTextStrokeColor(const CPWL_Color& color); 326 virtual void SetVisible(FX_BOOL bVisible); 327 328 virtual CPDF_Rect GetFocusRect() const; 329 virtual CPWL_Color GetBackgroundColor() const; 330 virtual CPWL_Color GetBorderColor() const; 331 virtual CPWL_Color GetTextColor() const; 332 virtual CPWL_Color GetTextStrokeColor() const; 333 virtual FX_FLOAT GetFontSize() const; 334 virtual int32_t GetInnerBorderWidth() const; 335 virtual CPWL_Color GetBorderLeftTopColor(int32_t nBorderStyle) const; 336 virtual CPWL_Color GetBorderRightBottomColor(int32_t nBorderStyle) const; 337 338 virtual void SetFontSize(FX_FLOAT fFontSize); 339 340 void SetBackgroundColor(const CPWL_Color& color); 341 void SetClipRect(const CPDF_Rect& rect); 342 void SetBorderStyle(int32_t eBorderStyle); 343 344 virtual CPDF_Rect GetWindowRect() const; 345 virtual CPDF_Rect GetClientRect() const; 346 CPDF_Point GetCenterPoint() const; 347 int32_t GetBorderWidth() const; IsVisible()348 FX_BOOL IsVisible() const { return m_bVisible; } 349 FX_BOOL HasFlag(FX_DWORD dwFlags) const; 350 void AddFlag(FX_DWORD dwFlags); 351 void RemoveFlag(FX_DWORD dwFlags); 352 const CPDF_Rect& GetClipRect() const; 353 CPWL_Wnd* GetParentWindow() const; 354 int32_t GetBorderStyle() const; 355 const CPWL_Dash& GetBorderDash() const; 356 void* GetAttachedData() const; 357 358 FX_BOOL WndHitTest(const CPDF_Point& point) const; 359 FX_BOOL ClientHitTest(const CPDF_Point& point) const; 360 FX_BOOL IsCaptureMouse() const; 361 362 const CPWL_Wnd* GetFocused() const; 363 FX_BOOL IsFocused() const; 364 FX_BOOL IsReadOnly() const; 365 CPWL_ScrollBar* GetVScrollBar() const; 366 367 IFX_Edit_FontMap* GetFontMap() const; 368 IPWL_Provider* GetProvider() const; 369 IPWL_FocusHandler* GetFocusHandler() const; 370 371 int32_t GetTransparency(); 372 void SetTransparency(int32_t nTransparency); 373 374 CFX_Matrix GetChildToRoot() const; 375 CFX_Matrix GetChildMatrix() const; 376 void SetChildMatrix(const CFX_Matrix& mt); 377 CFX_Matrix GetWindowMatrix() const; 378 379 virtual CPDF_Point ChildToParent(const CPDF_Point& point) const; 380 virtual CPDF_Rect ChildToParent(const CPDF_Rect& rect) const; 381 virtual CPDF_Point ParentToChild(const CPDF_Point& point) const; 382 virtual CPDF_Rect ParentToChild(const CPDF_Rect& rect) const; 383 384 // those methods only implemented by listctrl item GetItemHeight(FX_FLOAT fLimitWidth)385 virtual FX_FLOAT GetItemHeight(FX_FLOAT fLimitWidth) { return 0; } GetItemLeftMargin()386 virtual FX_FLOAT GetItemLeftMargin() { return 0; } GetItemRightMargin()387 virtual FX_FLOAT GetItemRightMargin() { return 0; } 388 389 void EnableWindow(FX_BOOL bEnable); 390 FX_BOOL IsEnabled(); 391 virtual void SetCursor(); 392 393 protected: 394 // CPWL_TimerHandler 395 IFX_SystemHandler* GetSystemHandler() const override; 396 397 virtual void CreateChildWnd(const PWL_CREATEPARAM& cp); 398 virtual void RePosChildWnd(); 399 void GetAppearanceStream(CFX_ByteTextBuf& sAppStream); 400 virtual void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream); 401 virtual void GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream); 402 403 virtual void DrawThisAppearance(CFX_RenderDevice* pDevice, 404 CFX_Matrix* pUser2Device); 405 virtual void DrawChildAppearance(CFX_RenderDevice* pDevice, 406 CFX_Matrix* pUser2Device); 407 408 virtual void OnCreate(PWL_CREATEPARAM& cp); 409 virtual void OnCreated(); 410 virtual void OnDestroy(); 411 412 virtual void OnSetFocus(); 413 virtual void OnKillFocus(); 414 415 virtual void OnEnabled(); 416 virtual void OnDisabled(); 417 418 void SetNotifyFlag(FX_BOOL bNotifying = TRUE) { m_bNotifying = bNotifying; } 419 420 FX_BOOL IsValid() const; 421 const PWL_CREATEPARAM& GetCreationParam() const; IsNotifying()422 FX_BOOL IsNotifying() const { return m_bNotifying; } 423 424 void InvalidateRectMove(const CPDF_Rect& rcOld, const CPDF_Rect& rcNew); 425 426 void PWLtoWnd(const CPDF_Point& point, int32_t& x, int32_t& y) const; 427 FX_RECT PWLtoWnd(const CPDF_Rect& rect) const; 428 FX_HWND GetAttachedHWnd() const; 429 430 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const; 431 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const; 432 const CPWL_Wnd* GetRootWnd() const; 433 434 FX_BOOL IsCTRLpressed(FX_DWORD nFlag) const; 435 FX_BOOL IsSHIFTpressed(FX_DWORD nFlag) const; 436 FX_BOOL IsALTpressed(FX_DWORD nFlag) const; 437 FX_BOOL IsINSERTpressed(FX_DWORD nFlag) const; 438 439 private: 440 void AddChild(CPWL_Wnd* pWnd); 441 void RemoveChild(CPWL_Wnd* pWnd); 442 443 void CreateScrollBar(const PWL_CREATEPARAM& cp); 444 void CreateVScrollBar(const PWL_CREATEPARAM& cp); 445 446 void AdjustStyle(); 447 void CreateMsgControl(); 448 void DestroyMsgControl(); 449 450 CPWL_MsgControl* GetMsgControl() const; 451 452 protected: 453 CFX_ArrayTemplate<CPWL_Wnd*> m_aChildren; 454 455 private: 456 PWL_CREATEPARAM m_sPrivateParam; 457 458 CPWL_ScrollBar* m_pVScrollBar; 459 460 CPDF_Rect m_rcWindow; 461 CPDF_Rect m_rcClip; 462 463 FX_BOOL m_bCreated; 464 FX_BOOL m_bVisible; 465 FX_BOOL m_bNotifying; 466 FX_BOOL m_bEnabled; 467 }; 468 469 #endif // FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_ 470