Source code of Windows XP (NT5)
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.

509 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992-2001 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 HasEditableProperties();
  94. virtual BOOL EditProperties();
  95. virtual HMENU GetContextMenu(void);
  96. virtual void OnContextMenuSelection(UINT Item);
  97. virtual BOOL CanGotoLine(void);
  98. virtual void GotoLine(ULONG Line);
  99. virtual void Find(PTSTR Text, ULONG Flags);
  100. virtual BOOL CodeExprAtCaret(PSTR Expr, PULONG64 Offset);
  101. virtual void ToggleBpAtCaret(void);
  102. // Functions called in response to WM messages
  103. virtual BOOL OnCreate(void);
  104. virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
  105. virtual void OnSetFocus(void);
  106. virtual void OnSize(void);
  107. virtual void OnButtonDown(ULONG Button);
  108. virtual void OnButtonUp(ULONG Button);
  109. virtual void OnMouseMove(ULONG Modifiers, ULONG X, ULONG Y);
  110. virtual void OnTimer(WPARAM TimerId);
  111. virtual LRESULT OnGetMinMaxInfo(LPMINMAXINFO Info);
  112. virtual LRESULT OnVKeyToItem(WPARAM wParam, LPARAM lParam);
  113. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  114. virtual void OnUpdate(UpdateType Type);
  115. virtual void OnDestroy(void);
  116. virtual LRESULT OnOwnerDraw(UINT uMsg, WPARAM wParam, LPARAM lParam);
  117. virtual ULONG GetWorkspaceSize(void);
  118. virtual PUCHAR SetWorkspace(PUCHAR Data);
  119. virtual PUCHAR ApplyWorkspace1(PUCHAR Data, PUCHAR End);
  120. virtual void UpdateColors(void);
  121. void UpdateSize(ULONG Width, ULONG Height);
  122. void SetShowToolbar(BOOL Show);
  123. static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg,
  124. WPARAM wParam, LPARAM lParam);
  125. };
  126. typedef COMMONWIN_DATA *PCOMMONWIN_DATA;
  127. //
  128. // Data common to all window structures
  129. // that only have one child
  130. //
  131. class SINGLE_CHILDWIN_DATA : public COMMONWIN_DATA
  132. {
  133. public:
  134. HWND m_hwndChild;
  135. SINGLE_CHILDWIN_DATA(ULONG ChangeBy);
  136. virtual void Validate();
  137. virtual void SetFont(ULONG FontIndex);
  138. virtual BOOL CanCopy();
  139. virtual BOOL CanCut();
  140. virtual BOOL CanPaste();
  141. virtual void Copy();
  142. virtual void Cut();
  143. virtual void Paste();
  144. // Functions called in response to WM messages
  145. virtual void OnSetFocus(void);
  146. virtual void OnSize(void);
  147. };
  148. typedef SINGLE_CHILDWIN_DATA *PSINGLE_CHILDWIN_DATA;
  149. #define IDC_PROCESS_TREE 1234
  150. class PROCESS_THREAD_DATA : public SINGLE_CHILDWIN_DATA
  151. {
  152. public:
  153. // Set in ReadState.
  154. ULONG m_NumProcesses, m_TotalThreads;
  155. PROCESS_THREAD_DATA();
  156. virtual void Validate();
  157. virtual HRESULT ReadState(void);
  158. virtual BOOL OnCreate(void);
  159. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  160. virtual void OnUpdate(UpdateType Type);
  161. void SetCurThreadFromProcessTreeItem(HWND Tree, HTREEITEM Sel);
  162. };
  163. typedef PROCESS_THREAD_DATA *PPROCESS_THREAD_DATA;
  164. #define EHL_CURRENT_LINE 0x00000001
  165. #define EHL_ENABLED_BP 0x00000002
  166. #define EHL_DISABLED_BP 0x00000004
  167. #define EHL_ANY_BP (EHL_ENABLED_BP | EHL_DISABLED_BP)
  168. struct EDIT_HIGHLIGHT
  169. {
  170. EDIT_HIGHLIGHT* Next;
  171. ULONG64 Data;
  172. ULONG Line;
  173. ULONG Flags;
  174. };
  175. class EDITWIN_DATA : public SINGLE_CHILDWIN_DATA
  176. {
  177. public:
  178. // Total number of lines in the edit window.
  179. ULONG m_TextLines;
  180. EDIT_HIGHLIGHT* m_Highlights;
  181. EDITWIN_DATA(ULONG ChangeBy);
  182. virtual void Validate();
  183. virtual void SetFont(ULONG FontIndex);
  184. virtual BOOL CanSelectAll();
  185. virtual void SelectAll();
  186. virtual BOOL OnCreate(void);
  187. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  188. virtual void OnDestroy(void);
  189. virtual void UpdateColors(void);
  190. void SetCurrentLineHighlight(ULONG Line);
  191. void RemoveCurrentLineHighlight(void)
  192. {
  193. SetCurrentLineHighlight(ULONG_MAX);
  194. }
  195. EDIT_HIGHLIGHT* GetLineHighlighting(ULONG Line);
  196. void ApplyHighlight(EDIT_HIGHLIGHT* Hl);
  197. EDIT_HIGHLIGHT* AddHighlight(ULONG Line, ULONG Flags);
  198. void RemoveHighlight(ULONG Line, ULONG Flags);
  199. void RemoveAllHighlights(ULONG Flags);
  200. static void RemoveActiveWinHighlights(ULONG Types, ULONG Flags);
  201. // Base implementation does nothing.
  202. virtual void UpdateBpMarks(void);
  203. int CheckForFileChanges(PCSTR File, FILETIME* LastWrite);
  204. };
  205. typedef EDITWIN_DATA *PEDITWIN_DATA;
  206. class SCRATCH_PAD_DATA : public EDITWIN_DATA
  207. {
  208. public:
  209. SCRATCH_PAD_DATA();
  210. virtual void Validate();
  211. virtual void Cut();
  212. virtual void Paste();
  213. virtual BOOL OnCreate(void);
  214. };
  215. typedef SCRATCH_PAD_DATA *PSCRATCH_PAD_DATA;
  216. #define IDC_DISASM_PREVIOUS 1234
  217. #define IDC_DISASM_NEXT 1235
  218. class DISASMWIN_DATA : public EDITWIN_DATA
  219. {
  220. public:
  221. char m_OffsetExpr[MAX_OFFSET_EXPR];
  222. BOOL m_UpdateExpr;
  223. HWND m_PreviousButton;
  224. HWND m_NextButton;
  225. // Set in ReadState.
  226. ULONG64 m_FirstInstr;
  227. ULONG64 m_PrimaryInstr;
  228. ULONG64 m_LastInstr;
  229. ULONG m_PrimaryLine;
  230. ULONG m_TextOffset;
  231. DISASMWIN_DATA();
  232. virtual void Validate();
  233. virtual HRESULT ReadState(void);
  234. virtual BOOL CodeExprAtCaret(PSTR Expr, PULONG64 Offset);
  235. virtual BOOL OnCreate(void);
  236. virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
  237. virtual void OnSize(void);
  238. virtual void OnTimer(WPARAM TimerId);
  239. virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  240. virtual void OnUpdate(UpdateType Type);
  241. virtual void UpdateBpMarks(void);
  242. void SetCurInstr(ULONG64 Offset);
  243. void ScrollLower(void)
  244. {
  245. if (m_FirstInstr != 0)
  246. {
  247. SetCurInstr(m_FirstInstr);
  248. }
  249. }
  250. void ScrollHigher(void)
  251. {
  252. if (m_LastInstr != 0)
  253. {
  254. SetCurInstr(m_LastInstr);
  255. }
  256. }
  257. };
  258. typedef DISASMWIN_DATA *PDISASMWIN_DATA;
  259. // Array of active commonwin's indexed by WIN_TYPES.
  260. extern PCOMMONWIN_DATA g_IndexedWin[];
  261. extern HWND g_IndexedHwnd[];
  262. #define GetWatchHwnd() g_IndexedHwnd[WATCH_WINDOW]
  263. #define GetLocalsHwnd() g_IndexedHwnd[LOCALS_WINDOW]
  264. #define GetCpuHwnd() g_IndexedHwnd[CPU_WINDOW]
  265. #define GetDisasmHwnd() g_IndexedHwnd[DISASM_WINDOW]
  266. #define GetCmdHwnd() g_IndexedHwnd[CMD_WINDOW]
  267. #define GetScratchHwnd() g_IndexedHwnd[SCRATCH_PAD_WINDOW]
  268. #define GetCallsHwnd() g_IndexedHwnd[CALLS_WINDOW]
  269. #define GetQuickWatchHwnd() g_IndexedHwnd[QUICKW_WINDOW]
  270. #define GetProcessThreadHwnd() g_IndexedHwnd[PROCESS_THREAD_WINDOW]
  271. // Size of caption bar plus window frame.
  272. #define WIN_EXTRA_HEIGHT \
  273. (2 * GetSystemMetrics(SM_CYBORDER) + 3 * GetSystemMetrics(SM_CYFRAME) + \
  274. GetSystemMetrics(SM_CYCAPTION))
  275. // Attempt to make most text windows 80 chars wide by default.
  276. // Most windows end up with a scroll bar so add that in on top.
  277. #define WIDTH_80 \
  278. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 80 + GetSystemMetrics(SM_CXVSCROLL))
  279. // Make all the left-side windows (command, stack, ...) 80 columns.
  280. #define LEFT_SIDE_WIDTH WIDTH_80
  281. // Require some space for left-side windows.
  282. #define LEFT_SIDE_MIN_WIDTH \
  283. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 15 + GetSystemMetrics(SM_CXVSCROLL))
  284. #define LEFT_SIDE_MIN_HEIGHT \
  285. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 5 + WIN_EXTRA_HEIGHT)
  286. // Make all the right-side windows (cpu, ...) narrow.
  287. #define RIGHT_SIDE_MIN_WIDTH_32 \
  288. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 15 + GetSystemMetrics(SM_CXVSCROLL))
  289. #define RIGHT_SIDE_DESIRED_WIDTH_32 \
  290. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 25 + GetSystemMetrics(SM_CXVSCROLL))
  291. #define RIGHT_SIDE_MIN_WIDTH_64 \
  292. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 20 + GetSystemMetrics(SM_CXVSCROLL))
  293. #define RIGHT_SIDE_DESIRED_WIDTH_64 \
  294. (g_Fonts[FONT_FIXED].Metrics.tmAveCharWidth * 30 + GetSystemMetrics(SM_CXVSCROLL))
  295. #define DOC_WIDTH WIDTH_80
  296. #define DISASM_WIDTH WIDTH_80
  297. #define CMD_WIDTH WIDTH_80
  298. #define CALLS_WIDTH WIDTH_80
  299. // Give plenty of room for the command window.
  300. #define CMD_HEIGHT \
  301. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 38)
  302. #define CMD_MIN_HEIGHT \
  303. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 25)
  304. #define CPU_WIDTH_32 RIGHT_SIDE_DESIRED_WIDTH_32
  305. #define CPU_WIDTH_64 RIGHT_SIDE_DESIRED_WIDTH_64
  306. #define CPU_HEIGHT g_MdiHeight
  307. // Keep the calls window short but with enough lines to be useful.
  308. #define CALLS_MIN_HEIGHT LEFT_SIDE_MIN_HEIGHT
  309. #define CALLS_HEIGHT \
  310. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 10 + WIN_EXTRA_HEIGHT)
  311. // Give the code windows enough lines to provide useful context.
  312. #define DISASM_HEIGHT \
  313. (g_Fonts[FONT_FIXED].Metrics.tmHeight * 30 + WIN_EXTRA_HEIGHT)
  314. #define DOC_HEIGHT DISASM_HEIGHT
  315. void Arrange(void);
  316. BOOL IsAutoArranged(WIN_TYPES Type);
  317. void DisplayAutoArrangeWarning(PCOMMONWIN_DATA CmnWin);
  318. void UpdateSourceOverlay(void);
  319. void SetAllFonts(ULONG FontIndex);
  320. void CloseAllWindows(void);
  321. void UpdateAllColors(void);
  322. PCOMMONWIN_DATA FindNthWindow(ULONG Nth, ULONG Types);
  323. void RicheditFind(HWND Edit,
  324. PTSTR Text, ULONG Flags,
  325. CHARRANGE* SaveSel, PULONG SaveFlags,
  326. BOOL HideSel);
  327. #define NTH_OPEN_ALWAYS 0xffffffff
  328. HWND
  329. New_OpenDebugWindow(
  330. WIN_TYPES winType,
  331. BOOL bUserActivated,
  332. ULONG Nth
  333. );
  334. HWND
  335. New_CreateWindow(
  336. HWND hwndParent,
  337. WIN_TYPES Type,
  338. UINT uClassId,
  339. UINT uWinTitle,
  340. PRECT pRect
  341. );
  342. HWND
  343. NewCmd_CreateWindow(
  344. HWND
  345. );
  346. HWND
  347. NewWatch_CreateWindow(
  348. HWND
  349. );
  350. HWND
  351. NewLocals_CreateWindow(
  352. HWND
  353. );
  354. HWND
  355. NewCpu_CreateWindow(
  356. HWND
  357. );
  358. HWND
  359. NewDisasm_CreateWindow(
  360. HWND
  361. );
  362. HWND
  363. NewQuickWatch_CreateWindow(
  364. HWND
  365. );
  366. HWND
  367. NewCalls_CreateWindow(
  368. HWND
  369. );
  370. HWND
  371. NewDoc_CreateWindow(
  372. HWND
  373. );
  374. HWND
  375. NewMemory_CreateWindow(
  376. HWND
  377. );
  378. HWND
  379. NewScratch_CreateWindow(
  380. HWND
  381. );
  382. HWND
  383. NewProcessThread_CreateWindow(
  384. HWND
  385. );
  386. #undef DEFINE_GET_WINDATA
  387. #define DEFINE_GET_WINDATA(ClassType, FuncName) \
  388. class ClassType * Get##FuncName##WinData(HWND);
  389. #include "fncdefs.h"
  390. #undef DEFINE_GET_WINDATA