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.

534 lines
14 KiB

  1. /*++
  2. Copyright (c) 1992-2002 Microsoft Corporation
  3. Module Name:
  4. cmnwin.h
  5. Abstract:
  6. Header for common window architecture functions.
  7. Environment:
  8. Win32, User Mode
  9. --*/
  10. // Millisecond delay value before evaluating input in
  11. // edit boxes. Required because there's only a per-character
  12. // change notification and we don't want to reevaluate on
  13. // every character.
  14. #define EDIT_DELAY 500
  15. // Several windows have edit boxes for entering offset
  16. // expressions.
  17. #define MAX_OFFSET_EXPR (MAX_PATH + 64)
  18. //
  19. // Window-related options.
  20. //
  21. #define WOPT_AUTO_ARRANGE 0x00000001
  22. #define WOPT_ARRANGE_ALL 0x00000002
  23. #define WOPT_AUTO_DISASM 0x00000004
  24. #define WOPT_OVERLAY_SOURCE 0x00000008
  25. extern ULONG g_WinOptions;
  26. extern ULONG g_AutoArrangeWarningCount;
  27. enum
  28. {
  29. FONT_FIXED,
  30. FONT_VARIABLE,
  31. FONT_COUNT
  32. };
  33. struct INDEXED_FONT
  34. {
  35. HFONT Font;
  36. TEXTMETRIC Metrics;
  37. LOGFONT LogFont;
  38. BOOL LogFontSet;
  39. };
  40. extern INDEXED_FONT g_Fonts[];
  41. #define LINE_MARKERS 2
  42. extern BOOL g_LineMarkers;
  43. //----------------------------------------------------------------------------
  44. //
  45. // COMMONWIN_DATA and family.
  46. //
  47. //----------------------------------------------------------------------------
  48. // List of all commonwin's still associated with an HWND.
  49. // This list entry is a member of the commonwin and is
  50. // different from the derivation list entry. Use
  51. // the ACTIVE_WIN_ENTRY macro to get from an entry to
  52. // the actual commonwin.
  53. extern LIST_ENTRY g_ActiveWin;
  54. #define ACTIVE_WIN_ENTRY(Entry) \
  55. ((PCOMMONWIN_DATA) \
  56. ((PUCHAR)(Entry) - FIELD_OFFSET(COMMONWIN_DATA, m_ActiveWin)))
  57. struct COMMONWIN_CREATE_DATA
  58. {
  59. WIN_TYPES Type;
  60. };
  61. //
  62. // Data common to all window structures
  63. //
  64. class COMMONWIN_DATA : public StateBuffer
  65. {
  66. public:
  67. LIST_ENTRY m_ActiveWin;
  68. SIZEL m_Size;
  69. ULONG m_CausedArrange;
  70. ULONG m_InAutoOp;
  71. INDEXED_FONT* m_Font;
  72. // Height of current font.
  73. ULONG m_FontHeight;
  74. // Height of window in lines of the current font, rounded down.
  75. ULONG m_LineHeight;
  76. // Toolbar if this window has one.
  77. HWND m_Toolbar;
  78. BOOL m_ShowToolbar;
  79. int m_ToolbarHeight;
  80. int m_MinToolbarWidth;
  81. HWND m_ToolbarEdit;
  82. COMMONWIN_DATA(ULONG ChangeBy);
  83. virtual void Validate();
  84. virtual void SetFont(ULONG FontIndex);
  85. virtual BOOL CanCopy();
  86. virtual BOOL CanCut();
  87. virtual BOOL CanPaste();
  88. virtual void Copy();
  89. virtual void Cut();
  90. virtual void Paste();
  91. virtual BOOL CanSelectAll();
  92. virtual void SelectAll();
  93. virtual BOOL SelectedText(PTSTR Buffer, ULONG BufferChars);
  94. virtual BOOL CanWriteTextToFile(void);
  95. virtual HRESULT WriteTextToFile(HANDLE File);
  96. virtual BOOL HasEditableProperties();
  97. virtual BOOL EditProperties();
  98. virtual HMENU GetContextMenu(void);
  99. virtual void OnContextMenuSelection(UINT Item);
  100. virtual BOOL CanGotoLine(void);
  101. virtual void GotoLine(ULONG Line);
  102. virtual void Find(PTSTR Text, ULONG Flags, BOOL FromDlg);
  103. virtual HRESULT CodeExprAtCaret(PSTR Expr, ULONG ExprSize,
  104. PULONG64 Offset);
  105. virtual void ToggleBpAtCaret(void);
  106. // Functions called in response to WM messages
  107. virtual BOOL OnCreate(void);
  108. virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
  109. virtual void OnSetFocus(void);
  110. virtual void OnSize(void);
  111. virtual void OnButtonDown(ULONG Button);
  112. virtual void OnButtonUp(ULONG Button);
  113. virtual void OnMouseMove(ULONG Modifiers, ULONG X, ULONG Y);
  114. virtual void OnTimer(WPARAM TimerId);
  115. virtual LRESULT OnGetMinMaxInfo(LPMINMAXINFO Info);
  116. virtual LRESULT OnVKeyToItem(WPARAM wParam, LPARAM lParam);
  117. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  118. virtual void OnUpdate(UpdateType Type);
  119. virtual void OnDestroy(void);
  120. virtual LRESULT OnOwnerDraw(UINT uMsg, WPARAM wParam, LPARAM lParam);
  121. virtual ULONG GetWorkspaceSize(void);
  122. virtual PUCHAR SetWorkspace(PUCHAR Data);
  123. virtual PUCHAR ApplyWorkspace1(PUCHAR Data, PUCHAR End);
  124. virtual void UpdateColors(void);
  125. void UpdateSize(ULONG Width, ULONG Height);
  126. void SetShowToolbar(BOOL Show);
  127. static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg,
  128. WPARAM wParam, LPARAM lParam);
  129. };
  130. typedef COMMONWIN_DATA *PCOMMONWIN_DATA;
  131. //
  132. // Data common to all window structures
  133. // that only have one child
  134. //
  135. class SINGLE_CHILDWIN_DATA : public COMMONWIN_DATA
  136. {
  137. public:
  138. HWND m_hwndChild;
  139. SINGLE_CHILDWIN_DATA(ULONG ChangeBy);
  140. virtual void Validate();
  141. virtual void SetFont(ULONG FontIndex);
  142. virtual BOOL CanCopy();
  143. virtual BOOL CanCut();
  144. virtual BOOL CanPaste();
  145. virtual void Copy();
  146. virtual void Cut();
  147. virtual void Paste();
  148. // Functions called in response to WM messages
  149. virtual void OnSetFocus(void);
  150. virtual void OnSize(void);
  151. virtual void UpdateColors(void);
  152. };
  153. typedef SINGLE_CHILDWIN_DATA *PSINGLE_CHILDWIN_DATA;
  154. #define IDC_PROCESS_TREE 1234
  155. class PROCESS_THREAD_DATA : public SINGLE_CHILDWIN_DATA
  156. {
  157. public:
  158. // Set in ReadState.
  159. ULONG m_TotalSystems, m_NamesOffset;
  160. PROCESS_THREAD_DATA();
  161. virtual void Validate();
  162. HRESULT ReadProcess(ULONG ProcId, PULONG Offset);
  163. HRESULT ReadSystem(ULONG SysId, PULONG Offset);
  164. virtual HRESULT ReadState(void);
  165. virtual BOOL OnCreate(void);
  166. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  167. virtual void OnUpdate(UpdateType Type);
  168. virtual void UpdateColors(void);
  169. void SetCurThreadFromProcessTreeItem(HWND Tree, HTREEITEM Sel);
  170. };
  171. typedef PROCESS_THREAD_DATA *PPROCESS_THREAD_DATA;
  172. #define EHL_CURRENT_LINE 0x00000001
  173. #define EHL_ENABLED_BP 0x00000002
  174. #define EHL_DISABLED_BP 0x00000004
  175. #define EHL_ANY_BP (EHL_ENABLED_BP | EHL_DISABLED_BP)
  176. struct EDIT_HIGHLIGHT
  177. {
  178. EDIT_HIGHLIGHT* Next;
  179. ULONG64 Data;
  180. ULONG Line;
  181. ULONG Flags;
  182. };
  183. class EDITWIN_DATA : public SINGLE_CHILDWIN_DATA
  184. {
  185. public:
  186. // Total number of lines in the edit window.
  187. ULONG m_TextLines;
  188. EDIT_HIGHLIGHT* m_Highlights;
  189. EDITWIN_DATA(ULONG ChangeBy);
  190. virtual void Validate();
  191. virtual void SetFont(ULONG FontIndex);
  192. virtual BOOL CanSelectAll();
  193. virtual void SelectAll();
  194. virtual BOOL OnCreate(void);
  195. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  196. virtual void OnDestroy(void);
  197. virtual void UpdateColors(void);
  198. void SetCurrentLineHighlight(ULONG Line);
  199. void RemoveCurrentLineHighlight(void)
  200. {
  201. SetCurrentLineHighlight(ULONG_MAX);
  202. }
  203. void UpdateCurrentLineHighlight(void);
  204. EDIT_HIGHLIGHT* GetLineHighlighting(ULONG Line);
  205. void ApplyHighlight(EDIT_HIGHLIGHT* Hl);
  206. EDIT_HIGHLIGHT* AddHighlight(ULONG Line, ULONG Flags);
  207. void RemoveHighlight(ULONG Line, ULONG Flags);
  208. void RemoveAllHighlights(ULONG Flags);
  209. static void RemoveActiveWinHighlights(ULONG Types, ULONG Flags);
  210. // Base implementation does nothing.
  211. virtual void UpdateBpMarks(void);
  212. int CheckForFileChanges(PCSTR File, FILETIME* LastWrite);
  213. };
  214. typedef EDITWIN_DATA *PEDITWIN_DATA;
  215. class SCRATCH_PAD_DATA : public EDITWIN_DATA
  216. {
  217. public:
  218. SCRATCH_PAD_DATA();
  219. virtual void Validate();
  220. virtual void Cut();
  221. virtual void Paste();
  222. virtual BOOL CanWriteTextToFile(void);
  223. virtual HRESULT WriteTextToFile(HANDLE File);
  224. virtual BOOL OnCreate(void);
  225. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  226. };
  227. typedef SCRATCH_PAD_DATA *PSCRATCH_PAD_DATA;
  228. #define IDC_DISASM_PREVIOUS 1234
  229. #define IDC_DISASM_NEXT 1235
  230. class DISASMWIN_DATA : public EDITWIN_DATA
  231. {
  232. public:
  233. char m_OffsetExpr[MAX_OFFSET_EXPR];
  234. BOOL m_UpdateExpr;
  235. HWND m_PreviousButton;
  236. HWND m_NextButton;
  237. // Set in ReadState.
  238. ULONG64 m_FirstInstr;
  239. ULONG64 m_PrimaryInstr;
  240. ULONG64 m_LastInstr;
  241. ULONG m_PrimaryLine;
  242. ULONG m_TextOffset;
  243. DISASMWIN_DATA();
  244. virtual void Validate();
  245. virtual HRESULT ReadState(void);
  246. virtual HRESULT CodeExprAtCaret(PSTR Expr, ULONG ExprSize,
  247. PULONG64 Offset);
  248. virtual BOOL OnCreate(void);
  249. virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
  250. virtual void OnSize(void);
  251. virtual void OnTimer(WPARAM TimerId);
  252. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  253. virtual void OnUpdate(UpdateType Type);
  254. virtual void UpdateBpMarks(void);
  255. void SetCurInstr(ULONG64 Offset);
  256. void ScrollLower(void)
  257. {
  258. if (m_FirstInstr != 0)
  259. {
  260. SetCurInstr(m_FirstInstr);
  261. }
  262. }
  263. void ScrollHigher(void)
  264. {
  265. if (m_LastInstr != 0)
  266. {
  267. SetCurInstr(m_LastInstr);
  268. }
  269. }
  270. };
  271. typedef DISASMWIN_DATA *PDISASMWIN_DATA;
  272. // Array of active commonwin's indexed by WIN_TYPES.
  273. extern PCOMMONWIN_DATA g_IndexedWin[];
  274. extern HWND g_IndexedHwnd[];
  275. #define GetWatchHwnd() g_IndexedHwnd[WATCH_WINDOW]
  276. #define GetLocalsHwnd() g_IndexedHwnd[LOCALS_WINDOW]
  277. #define GetCpuHwnd() g_IndexedHwnd[CPU_WINDOW]
  278. #define GetDisasmHwnd() g_IndexedHwnd[DISASM_WINDOW]
  279. #define GetCmdHwnd() g_IndexedHwnd[CMD_WINDOW]
  280. #define GetScratchHwnd() g_IndexedHwnd[SCRATCH_PAD_WINDOW]
  281. #define GetCallsHwnd() g_IndexedHwnd[CALLS_WINDOW]
  282. #define GetQuickWatchHwnd() g_IndexedHwnd[QUICKW_WINDOW]
  283. #define GetProcessThreadHwnd() g_IndexedHwnd[PROCESS_THREAD_WINDOW]
  284. // Size of caption bar plus window frame.
  285. #define WIN_EXTRA_HEIGHT \
  286. (2 * GetSystemMetrics(SM_CYBORDER) + 3 * GetSystemMetrics(SM_CYFRAME) + \
  287. GetSystemMetrics(SM_CYCAPTION))
  288. // Attempt to make most text windows 80 chars wide by default.
  289. // Most windows end up with a scroll bar so add that in on top.
  290. #define WIDTH_80 \
  291. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 80 + GetSystemMetrics(SM_CXVSCROLL))
  292. // Make all the left-side windows (command, stack, ...) 80 columns.
  293. #define LEFT_SIDE_WIDTH WIDTH_80
  294. // Require some space for left-side windows.
  295. #define LEFT_SIDE_MIN_WIDTH \
  296. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 15 + GetSystemMetrics(SM_CXVSCROLL))
  297. #define LEFT_SIDE_MIN_HEIGHT \
  298. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 5 + WIN_EXTRA_HEIGHT)
  299. // Make all the right-side windows (cpu, ...) narrow.
  300. #define RIGHT_SIDE_MIN_WIDTH_32 \
  301. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 15 + GetSystemMetrics(SM_CXVSCROLL))
  302. #define RIGHT_SIDE_DESIRED_WIDTH_32 \
  303. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 25 + GetSystemMetrics(SM_CXVSCROLL))
  304. #define RIGHT_SIDE_MIN_WIDTH_64 \
  305. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 20 + GetSystemMetrics(SM_CXVSCROLL))
  306. #define RIGHT_SIDE_DESIRED_WIDTH_64 \
  307. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 30 + GetSystemMetrics(SM_CXVSCROLL))
  308. #define DOC_WIDTH WIDTH_80
  309. #define DISASM_WIDTH WIDTH_80
  310. #define CMD_WIDTH WIDTH_80
  311. #define CALLS_WIDTH WIDTH_80
  312. // Give plenty of room for the command window.
  313. #define CMD_HEIGHT \
  314. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 38)
  315. #define CMD_MIN_HEIGHT \
  316. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 25)
  317. #define CPU_WIDTH_32 RIGHT_SIDE_DESIRED_WIDTH_32
  318. #define CPU_WIDTH_64 RIGHT_SIDE_DESIRED_WIDTH_64
  319. #define CPU_HEIGHT g_MdiHeight
  320. // Keep the calls window short but with enough lines to be useful.
  321. #define CALLS_MIN_HEIGHT LEFT_SIDE_MIN_HEIGHT
  322. #define CALLS_HEIGHT \
  323. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 10 + WIN_EXTRA_HEIGHT)
  324. // Give the code windows enough lines to provide useful context.
  325. #define DISASM_HEIGHT \
  326. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 30 + WIN_EXTRA_HEIGHT)
  327. #define DOC_HEIGHT DISASM_HEIGHT
  328. void Arrange(void);
  329. BOOL IsAutoArranged(WIN_TYPES Type);
  330. void DisplayAutoArrangeWarning(PCOMMONWIN_DATA CmnWin);
  331. void UpdateSourceOverlay(void);
  332. void SetAllFonts(ULONG FontIndex);
  333. void CloseAllWindows(ULONG TypeMask);
  334. void UpdateAllColors(void);
  335. PCOMMONWIN_DATA FindNthWindow(ULONG Nth, ULONG Types);
  336. void RicheditFind(HWND Edit,
  337. PTSTR Text, ULONG Flags,
  338. CHARRANGE* SaveSel, PULONG SaveFlags,
  339. BOOL HideSel);
  340. HRESULT RicheditWriteToFile(HWND Edit, HANDLE File);
  341. void RicheditUpdateColors(HWND Edit,
  342. COLORREF Fg, BOOL UpdateFg,
  343. COLORREF Bg, BOOL UpdateBg);
  344. void RicheditScrollToLine(HWND Edit, ULONG Line, ULONG VisLines);
  345. ULONG RicheditGetSelectionText(HWND Edit, PTSTR Buffer, ULONG BufferChars);
  346. ULONG RicheditGetSourceToken(HWND Edit, PTSTR Buffer, ULONG BufferChars,
  347. CHARRANGE* Range);
  348. #define NTH_OPEN_ALWAYS 0xffffffff
  349. HWND
  350. New_OpenDebugWindow(
  351. WIN_TYPES winType,
  352. BOOL bUserActivated,
  353. ULONG Nth
  354. );
  355. HWND
  356. New_CreateWindow(
  357. HWND hwndParent,
  358. WIN_TYPES Type,
  359. UINT uClassId,
  360. UINT uWinTitle,
  361. PRECT pRect
  362. );
  363. HWND
  364. NewCmd_CreateWindow(
  365. HWND
  366. );
  367. HWND
  368. NewWatch_CreateWindow(
  369. HWND
  370. );
  371. HWND
  372. NewLocals_CreateWindow(
  373. HWND
  374. );
  375. HWND
  376. NewCpu_CreateWindow(
  377. HWND
  378. );
  379. HWND
  380. NewDisasm_CreateWindow(
  381. HWND
  382. );
  383. HWND
  384. NewQuickWatch_CreateWindow(
  385. HWND
  386. );
  387. HWND
  388. NewCalls_CreateWindow(
  389. HWND
  390. );
  391. HWND
  392. NewDoc_CreateWindow(
  393. HWND
  394. );
  395. HWND
  396. NewMemory_CreateWindow(
  397. HWND
  398. );
  399. HWND
  400. NewScratch_CreateWindow(
  401. HWND
  402. );
  403. HWND
  404. NewProcessThread_CreateWindow(
  405. HWND
  406. );
  407. #undef DEFINE_GET_WINDATA
  408. #define DEFINE_GET_WINDATA(ClassType, FuncName) \
  409. class ClassType * Get##FuncName##WinData(HWND);
  410. #include "fncdefs.h"
  411. #undef DEFINE_GET_WINDATA