Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.6 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _URLSUP.H URL detection support |
  5. *
  6. * Author: alexgo (4/1/96)
  7. *
  8. * Copyright (c) 1995-2000, Microsoft Corporation. All rights reserved.
  9. */
  10. #ifndef _URLSUP_H_
  11. #define _URLSUP_H_
  12. #include "_dfreeze.h"
  13. #include "_notmgr.h"
  14. #include "_range.h"
  15. class CTxtEdit;
  16. class IUndoBuilder;
  17. // Maximum URL length. It's a good thing to have a protection like
  18. // this to make sure we don't select the whole document; and we really
  19. // need this for space-containing URLs.
  20. // Note (keithcu). I bumped these values up because of RAID 7210. I thought about
  21. // removing this support altogether, but it's nice to have and speeds up
  22. // performance when you are inserting angle brackets inside URLs and you
  23. // do the left one first.
  24. #define URL_MAX_SIZE 4096
  25. // for MoveByDelimiter
  26. #define URL_EATWHITESPACE 32
  27. #define URL_STOPATWHITESPACE 1
  28. #define URL_EATNONWHITESPACE 0
  29. #define URL_STOPATNONWHITESPACE 2
  30. #define URL_EATPUNCT 0
  31. #define URL_STOPATPUNCT 4
  32. #define URL_EATNONPUNCT 0
  33. #define URL_STOPATNONPUNCT 8
  34. #define URL_STOPATCHAR 16
  35. // need this one to initialize a scan with something invalid
  36. #define URL_INVALID_DELIMITER TEXT(' ')
  37. #define LEFTANGLEBRACKET TEXT('<')
  38. #define RIGHTANGLEBRACKET TEXT('>')
  39. /*
  40. * CDetectURL
  41. *
  42. * @class This class watches edit changes and automatically
  43. * changes detected URL's into links (see CFE_LINK && EN_LINK)
  44. */
  45. class CDetectURL : public ITxNotify
  46. {
  47. //@access Public Methods
  48. public:
  49. // constructor/destructor
  50. CDetectURL(CTxtEdit *ped); //@cmember constructor
  51. ~CDetectURL(); //@cmember destructor
  52. // ITxNotify methods
  53. //@cmember Called before a change
  54. virtual void OnPreReplaceRange( LONG cp, LONG cchDel, LONG cchNew,
  55. LONG cpFormatMin, LONG cpFormatMax, NOTIFY_DATA *pNotifyData );
  56. //@cmember Called after a change
  57. virtual void OnPostReplaceRange( LONG cp, LONG cchDel, LONG cchNew,
  58. LONG cpFormatMin, LONG cpFormatMax, NOTIFY_DATA *pNotifyData );
  59. virtual void Zombie(); //@cmember Turn into a zombie
  60. // useful methods
  61. void ScanAndUpdate(IUndoBuilder *publdr);//@cmember Scan changed area
  62. // & update link status
  63. //@cmember Return TRUE if text is a URL
  64. BOOL IsURL(CTxtPtr &tp, LONG cch, BOOL *pfURLLeadin);
  65. //@access Private Methods and Data
  66. private:
  67. // Worker routines for ScanAndUpdate
  68. BOOL GetScanRegion(LONG& cpStart, LONG& cpEnd);//@cmember Get region to
  69. // check & clear accumulator
  70. static void ExpandToURL(CTxtRange& rg, LONG &cchAdvance);
  71. //@cmember Expand range to next
  72. // URL candidate
  73. static void SetURLEffects(CTxtRange& rg, IUndoBuilder *publdr); //@cmember Set
  74. // desired URL effects
  75. //@cmember Remove URL effects if
  76. // appropriate
  77. void CheckAndCleanBogusURL(CTxtRange& rg, BOOL &fDidClean, IUndoBuilder *publdr);
  78. //@cmember Scan along for white
  79. // space / not whitespace,
  80. // punctuation / non punctuation
  81. // and remember what stopped scan
  82. static LONG MoveByDelimiters(const CTxtPtr& tp, LONG iDir, DWORD grfDelimiters,
  83. WCHAR *pchStopChar);
  84. static LONG GetAngleBracket(CTxtPtr &tp, LONG cch = 0);
  85. static WCHAR BraceMatch(WCHAR chEnclosing);
  86. CTxtEdit * _ped; //@cmember Edit context
  87. CAccumDisplayChanges _adc; //@cmember Change accumulator
  88. // FUTURE (alexgo): we may want to add more options to detection,
  89. // such as the charformat to use on detection, etc.
  90. };
  91. #endif // _URLSUP_H_