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 _PWL_WND_H_ 8 #define _PWL_WND_H_ 9 10 class IPWL_Provider; 11 class CPWL_Wnd; 12 class CPWL_MsgControl; 13 class CPWL_Wnd; 14 class CPWL_ScrollBar; 15 class CPWL_Timer; 16 class CPWL_TimerHandler; 17 class IPWL_SpellCheck; 18 class IFX_SystemHandler; 19 20 #ifdef FX_READER_DLL 21 #ifdef PWL_EXPORT 22 #define PWL_CLASS __declspec(dllexport) 23 #define PWL_FUNCTION PWL_CLASS 24 #else 25 #define PWL_CLASS 26 #define PWL_FUNCTION 27 #endif 28 #else 29 #define PWL_CLASS 30 #define PWL_FUNCTION 31 #endif 32 33 //window styles 34 #define PWS_CHILD 0x80000000L 35 #define PWS_BORDER 0x40000000L 36 #define PWS_BACKGROUND 0x20000000L 37 #define PWS_HSCROLL 0x10000000L 38 #define PWS_VSCROLL 0x08000000L 39 #define PWS_VISIBLE 0x04000000L 40 #define PWS_DISABLE 0x02000000L 41 #define PWS_READONLY 0x01000000L 42 #define PWS_AUTOFONTSIZE 0x00800000L 43 #define PWS_AUTOTRANSPARENT 0x00400000L 44 #define PWS_NOREFRESHCLIP 0x00200000L 45 46 //edit and label styles 47 #define PES_MULTILINE 0x0001L 48 #define PES_PASSWORD 0x0002L 49 #define PES_LEFT 0x0004L 50 #define PES_RIGHT 0x0008L 51 #define PES_MIDDLE 0x0010L 52 #define PES_TOP 0x0020L 53 #define PES_BOTTOM 0x0040L 54 #define PES_CENTER 0x0080L 55 #define PES_CHARARRAY 0x0100L 56 #define PES_AUTOSCROLL 0x0200L 57 #define PES_AUTORETURN 0x0400L 58 #define PES_UNDO 0x0800L 59 #define PES_RICH 0x1000L 60 #define PES_SPELLCHECK 0x2000L 61 #define PES_TEXTOVERFLOW 0x4000L 62 #define PES_NOREAD 0x8000L 63 64 //listbox styles 65 #define PLBS_MULTIPLESEL 0x0001L 66 #define PLBS_HOVERSEL 0x0008L 67 68 //combobox styles 69 #define PCBS_ALLOWCUSTOMTEXT 0x0001L 70 71 //richedit styles 72 #define PRES_MULTILINE 0x0001L 73 #define PRES_AUTORETURN 0x0002L 74 #define PRES_AUTOSCROLL 0x0004L 75 #define PRES_SPELLCHECK 0x0008L 76 #define PRES_UNDO 0x0100L 77 #define PRES_MULTIPAGES 0x0200L 78 #define PRES_TEXTOVERFLOW 0x0400L 79 80 //border style 81 #define PBS_SOLID 0 82 #define PBS_DASH 1 83 #define PBS_BEVELED 2 84 #define PBS_INSET 3 85 #define PBS_UNDERLINED 4 86 #define PBS_SHADOW 5 87 88 //notification messages 89 #define PNM_ADDCHILD 0x00000000L 90 #define PNM_REMOVECHILD 0x00000001L 91 #define PNM_SETSCROLLINFO 0x00000002L 92 #define PNM_SETSCROLLPOS 0x00000003L 93 #define PNM_SCROLLWINDOW 0x00000004L 94 #define PNM_LBUTTONDOWN 0x00000005L 95 #define PNM_LBUTTONUP 0x00000006L 96 #define PNM_MOUSEMOVE 0x00000007L 97 #define PNM_NOTERESET 0x00000008L 98 #define PNM_SETCARETINFO 0x00000009L 99 #define PNM_SELCHANGED 0x0000000AL 100 #define PNM_NOTEEDITCHANGED 0x0000000BL 101 102 #define PWL_CLASSNAME_EDIT "CPWL_Edit" 103 104 struct CPWL_Dash 105 { 106 CPWL_Dash(FX_INT32 dash, FX_INT32 gap, FX_INT32 phase) : nDash(dash), nGap(gap), nPhase(phase) 107 {} 108 109 FX_INT32 nDash; 110 FX_INT32 nGap; 111 FX_INT32 nPhase; 112 }; 113 114 struct PWL_CLASS CPWL_Color 115 { 116 CPWL_Color(FX_INT32 type = COLORTYPE_TRANSPARENT, FX_FLOAT color1 = 0.0f, FX_FLOAT color2 = 0.0f, FX_FLOAT color3 = 0.0f, FX_FLOAT color4 = 0.0f) 117 : nColorType(type), fColor1(color1), fColor2(color2), fColor3(color3), fColor4(color4) 118 {} 119 120 CPWL_Color(FX_INT32 r, FX_INT32 g, FX_INT32 b) : 121 nColorType(COLORTYPE_RGB), fColor1(r/255.0f), fColor2(g/255.0f), fColor3(b/255.0f), fColor4(0) 122 {} 123 124 void ConvertColorType(FX_INT32 nColorType); 125 126 /* 127 COLORTYPE_TRANSPARENT 128 COLORTYPE_RGB 129 COLORTYPE_CMYK 130 COLORTYPE_GRAY 131 */ 132 FX_INT32 nColorType; 133 FX_FLOAT fColor1,fColor2,fColor3,fColor4; 134 }; 135 136 inline FX_BOOL operator == (const CPWL_Color &c1, const CPWL_Color &c2) 137 { 138 return c1.nColorType == c2.nColorType && 139 c1.fColor1 - c2.fColor1 < 0.0001 && c1.fColor1 - c2.fColor1 > -0.0001 && 140 c1.fColor2 - c2.fColor2 < 0.0001 && c1.fColor2 - c2.fColor2 > -0.0001 && 141 c1.fColor3 - c2.fColor3 < 0.0001 && 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 { 147 return !operator == (c1, c2); 148 } 149 150 #define PWL_SCROLLBAR_WIDTH 12.0f 151 #define PWL_SCROLLBAR_BUTTON_WIDTH 9.0f 152 #define PWL_SCROLLBAR_POSBUTTON_MINWIDTH 2.0f 153 #define PWL_SCROLLBAR_TRANSPARANCY 150 154 #define PWL_SCROLLBAR_BKCOLOR 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 CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f) 157 #define PWL_DEFAULT_BACKCOLOR PWL_DEFAULT_SELTEXTCOLOR 158 #define PWL_DEFAULT_TEXTCOLOR CPWL_Color(COLORTYPE_RGB,0,0,0) 159 #define PWL_DEFAULT_FONTSIZE 9.0f 160 #define PWL_DEFAULT_BLACKCOLOR CPWL_Color(COLORTYPE_GRAY,0) 161 #define PWL_DEFAULT_WHITECOLOR CPWL_Color(COLORTYPE_GRAY,1) 162 #define PWL_DEFAULT_HEAVYGRAYCOLOR CPWL_Color(COLORTYPE_GRAY,0.50) 163 #define PWL_DEFAULT_LIGHTGRAYCOLOR CPWL_Color(COLORTYPE_GRAY,0.75) 164 #define PWL_TRIANGLE_HALFLEN 2.0f 165 #define PWL_CBBUTTON_TRIANGLE_HALFLEN 3.0f 166 #define PWL_INVALIDATE_INFLATE 2 167 168 class IPWL_SpellCheck 169 { 170 public: 171 virtual FX_BOOL CheckWord(FX_LPCSTR sWord) = 0; 172 virtual void SuggestWords(FX_LPCSTR sWord, CFX_ByteStringArray & sSuggest) = 0; 173 }; 174 175 class IPWL_Provider 176 { 177 public: 178 //get a matrix which map user space to CWnd client space 179 virtual CPDF_Matrix GetWindowMatrix(void* pAttachedData) = 0; 180 181 /* 182 0 L"&Undo\tCtrl+Z" 183 1 L"&Redo\tCtrl+Shift+Z" 184 2 L"Cu&t\tCtrl+X" 185 3 L"&Copy\tCtrl+C" 186 4 L"&Paste\tCtrl+V" 187 5 L"&Delete" 188 6 L"&Select All\tCtrl+A" 189 */ 190 virtual CFX_WideString LoadPopupMenuString(FX_INT32 nIndex) = 0; 191 }; 192 193 class IPWL_FocusHandler 194 { 195 public: 196 virtual void OnSetFocus(CPWL_Wnd* pWnd) = 0; 197 virtual void OnKillFocus(CPWL_Wnd* pWnd) = 0; 198 }; 199 200 struct PWL_CREATEPARAM 201 { 202 public: 203 PWL_CREATEPARAM() : rcRectWnd(0,0,0,0), 204 pSystemHandler(NULL), 205 pFontMap(NULL), 206 pProvider(NULL), 207 pFocusHandler(NULL), 208 dwFlags(0), 209 sBackgroundColor(), 210 hAttachedWnd(NULL), 211 pSpellCheck(NULL), 212 nBorderStyle(PBS_SOLID), 213 dwBorderWidth(1), 214 sBorderColor(), 215 sTextColor(), 216 sTextStrokeColor(), 217 nTransparency(255), 218 fFontSize(PWL_DEFAULT_FONTSIZE), 219 sDash(3,0,0), 220 pAttachedData(NULL), 221 pParentWnd(NULL), 222 pMsgControl(NULL), 223 eCursorType(FXCT_ARROW), 224 mtChild(1,0,0,1,0,0) 225 { 226 } 227 228 CPDF_Rect rcRectWnd; //required 229 IFX_SystemHandler* pSystemHandler; //required 230 IFX_Edit_FontMap* pFontMap; //required for text window 231 IPWL_Provider* pProvider; //required for self coordinate 232 IPWL_FocusHandler* pFocusHandler; //optional 233 FX_DWORD dwFlags; //optional 234 CPWL_Color sBackgroundColor; //optional 235 FX_HWND hAttachedWnd; //required for no-reader framework 236 IPWL_SpellCheck* pSpellCheck; //required for spellchecking 237 FX_INT32 nBorderStyle; //optional 238 FX_INT32 dwBorderWidth; //optional 239 CPWL_Color sBorderColor; //optional 240 CPWL_Color sTextColor; //optional 241 CPWL_Color sTextStrokeColor; //optional 242 FX_INT32 nTransparency; //optional 243 FX_FLOAT fFontSize; //optional 244 CPWL_Dash sDash; //optional 245 void* pAttachedData; //optional 246 CPWL_Wnd* pParentWnd; //ignore 247 CPWL_MsgControl* pMsgControl; //ignore 248 FX_INT32 eCursorType; //ignore 249 CPDF_Matrix mtChild; //ignore 250 }; 251 252 class CPWL_Timer 253 { 254 public: 255 CPWL_Timer(CPWL_TimerHandler* pAttached, IFX_SystemHandler* pSystemHandler); 256 virtual ~CPWL_Timer(); 257 258 FX_INT32 SetPWLTimer(FX_INT32 nElapse); 259 void KillPWLTimer(); 260 static void TimerProc(FX_INT32 idEvent); 261 262 private: 263 FX_INT32 m_nTimerID; 264 CPWL_TimerHandler* m_pAttached; 265 IFX_SystemHandler* m_pSystemHandler; 266 }; 267 268 class PWL_CLASS CPWL_TimerHandler 269 { 270 public: 271 CPWL_TimerHandler(); 272 virtual ~CPWL_TimerHandler(); 273 274 void BeginTimer(FX_INT32 nElapse); 275 void EndTimer(); 276 virtual void TimerProc(); 277 virtual IFX_SystemHandler* GetSystemHandler() const = 0; 278 279 private: 280 CPWL_Timer* m_pTimer; 281 }; 282 283 class PWL_CLASS CPWL_Wnd : public CPWL_TimerHandler 284 { 285 friend class CPWL_MsgControl; 286 public: 287 CPWL_Wnd(); 288 virtual ~CPWL_Wnd(); 289 290 void Create(const PWL_CREATEPARAM & cp); 291 virtual CFX_ByteString GetClassName() const; 292 void Destroy(); 293 void Move(const CPDF_Rect & rcNew,FX_BOOL bReset,FX_BOOL bRefresh); 294 virtual void InvalidateRect(CPDF_Rect* pRect = NULL); 295 296 void GetAppearanceStream(CFX_ByteString & sAppStream); 297 void DrawAppearance(CFX_RenderDevice* pDevice, CPDF_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 OnRButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag); 309 virtual FX_BOOL OnRButtonDown(const CPDF_Point & point, FX_DWORD nFlag); 310 virtual FX_BOOL OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag); 311 virtual FX_BOOL OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag); 312 virtual FX_BOOL OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag); 313 314 virtual void SetFocus(); 315 virtual void KillFocus(); 316 void SetCapture(); 317 void ReleaseCapture(); 318 319 virtual void OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0); 320 virtual void SetTextColor(const CPWL_Color & color); 321 virtual void SetTextStrokeColor(const CPWL_Color & color); 322 virtual void SetVisible(FX_BOOL bVisible); 323 324 virtual CPDF_Rect GetFocusRect() const; 325 virtual CPWL_Color GetBackgroundColor() const; 326 virtual CPWL_Color GetBorderColor() const; 327 virtual CPWL_Color GetTextColor() const; 328 virtual CPWL_Color GetTextStrokeColor() const; 329 virtual FX_FLOAT GetFontSize() const; 330 virtual FX_INT32 GetInnerBorderWidth() const; 331 virtual CPWL_Color GetBorderLeftTopColor(FX_INT32 nBorderStyle) const; 332 virtual CPWL_Color GetBorderRightBottomColor(FX_INT32 nBorderStyle) const; 333 334 virtual FX_BOOL IsModified() const {return FALSE;} 335 336 virtual void SetFontSize(FX_FLOAT fFontSize); 337 338 void SetBackgroundColor(const CPWL_Color & color); 339 void SetBorderColor(const CPWL_Color & color); 340 void SetBorderWidth(FX_INT32 nBorderWidth); 341 void SetClipRect(const CPDF_Rect & rect); 342 void SetBorderStyle(FX_INT32 eBorderStyle); 343 void SetBorderDash(const CPWL_Dash & sDash); 344 345 CPDF_Rect GetOriginWindowRect() const; 346 virtual CPDF_Rect GetWindowRect() const; 347 virtual CPDF_Rect GetClientRect() const; 348 CPDF_Point GetCenterPoint() const; 349 CPDF_Rect GetClientCenterSquare() const; 350 CPDF_Rect GetWindowCenterSquare() const; 351 FX_INT32 GetBorderWidth() const; 352 FX_BOOL IsVisible() const {return m_bVisible;} 353 FX_BOOL HasFlag(FX_DWORD dwFlags) const; 354 void AddFlag(FX_DWORD dwFlags); 355 void RemoveFlag(FX_DWORD dwFlags); 356 CPDF_Rect GetClipRect() const; 357 CPWL_Wnd* GetParentWindow() const; 358 FX_INT32 GetBorderStyle() const; 359 CPWL_Dash GetBorderDash() const; 360 void* GetAttachedData() const; 361 362 FX_BOOL WndHitTest(const CPDF_Point & point) const; 363 FX_BOOL ClientHitTest(const CPDF_Point & point) const; 364 FX_BOOL IsCaptureMouse() const; 365 366 const CPWL_Wnd* GetFocused() const; 367 FX_BOOL IsFocused() const; 368 FX_BOOL IsReadOnly() const; 369 CPWL_ScrollBar* GetVScrollBar() const; 370 371 IFX_Edit_FontMap* GetFontMap() const; 372 IPWL_Provider* GetProvider() const; 373 virtual IFX_SystemHandler* GetSystemHandler() const; 374 IPWL_FocusHandler* GetFocusHandler() const; 375 376 FX_INT32 GetTransparency(); 377 void SetTransparency(FX_INT32 nTransparency); 378 379 CPDF_Matrix GetChildToRoot() const; 380 CPDF_Matrix GetChildMatrix() const; 381 void SetChildMatrix(const CPDF_Matrix& mt); 382 CPDF_Matrix GetWindowMatrix() const; 383 384 virtual CPDF_Point ChildToParent(const CPDF_Point& point) const; 385 virtual CPDF_Rect ChildToParent(const CPDF_Rect& rect) const; 386 virtual CPDF_Point ParentToChild(const CPDF_Point& point) const; 387 virtual CPDF_Rect ParentToChild(const CPDF_Rect& rect) const; 388 389 //those methods only implemented by listctrl item 390 virtual FX_FLOAT GetItemHeight(FX_FLOAT fLimitWidth) {return 0;} 391 virtual FX_FLOAT GetItemLeftMargin() {return 0;} 392 virtual FX_FLOAT GetItemRightMargin() {return 0;} 393 394 void EnableWindow(FX_BOOL bEnable); 395 FX_BOOL IsEnabled(); 396 virtual void SetCursor(); 397 398 protected: 399 virtual void CreateChildWnd(const PWL_CREATEPARAM & cp); 400 virtual void RePosChildWnd(); 401 void GetAppearanceStream(CFX_ByteTextBuf & sAppStream); 402 virtual void GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream); 403 virtual void GetChildAppearanceStream(CFX_ByteTextBuf & sAppStream); 404 405 virtual void DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device); 406 virtual void DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_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 PWL_CREATEPARAM GetCreationParam() const; 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, FX_INT32& x, FX_INT32& 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 AjustStyle(); 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 // #ifndef VK_END 470 // 471 // #define VK_END 0x23 472 // #define VK_HOME 0x24 473 // #define VK_LEFT 0x25 474 // #define VK_UP 0x26 475 // #define VK_RIGHT 0x27 476 // #define VK_DOWN 0x28 477 // #define VK_INSERT 0x2D 478 // #define VK_DELETE 0x2E 479 // 480 // #define VK_BACK 0x08 481 // #define VK_TAB 0x09 482 // 483 // #define VK_CLEAR 0x0C 484 // #define VK_RETURN 0x0D 485 // #define VK_ESCAPE 0x1B 486 // #define VK_SPACE 0x20 487 // #endif 488 // 489 // #define VK_NONE 0 490 491 #endif // !defined(AFX_PWL_WND_H__D32812AD_A875_4E08_9D3C_0A57020987C6__INCLUDED_) 492 493 494