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.

595 lines
18 KiB

  1. // Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1993 Microsoft Corporation,
  3. // All rights reserved.
  4. // This source code is only intended as a supplement to the
  5. // Microsoft Foundation Classes Reference and Microsoft
  6. // QuickHelp and/or WinHelp documentation provided with the library.
  7. // See these sources for detailed information regarding the
  8. // Microsoft Foundation Classes product.
  9. #ifndef __AFXDLGS_H__
  10. #define __AFXDLGS_H__
  11. #ifndef __AFXWIN_H__
  12. #include <afxwin.h>
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // AFXDLGS - MFC Standard dialogs
  16. // Classes declared in this file
  17. // CDialog
  18. // modeless dialogs
  19. class CFindReplaceDialog; // Find/FindReplace dialog
  20. // modal dialogs
  21. class CFileDialog; // FileOpen/FileSaveAs dialogs
  22. class CColorDialog; // Color picker dialog
  23. class CFontDialog; // Font chooser dialog
  24. class CPrintDialog; // Print/PrintSetup dialogs
  25. /////////////////////////////////////////////////////////////////////////////
  26. #include <commdlg.h> // common dialog APIs
  27. #include <print.h> // printer specific APIs (DEVMODE)
  28. // AFXDLL support
  29. #undef AFXAPP_DATA
  30. #define AFXAPP_DATA AFXAPI_DATA
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CFileDialog - used for FileOpen... or FileSaveAs...
  33. class CFileDialog : public CDialog
  34. {
  35. DECLARE_DYNAMIC(CFileDialog)
  36. public:
  37. // Attributes
  38. // open file parameter block
  39. OPENFILENAME m_ofn;
  40. // Constructors
  41. CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
  42. LPCSTR lpszDefExt = NULL,
  43. LPCSTR lpszFileName = NULL,
  44. DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
  45. LPCSTR lpszFilter = NULL,
  46. CWnd* pParentWnd = NULL);
  47. // Operations
  48. virtual int DoModal();
  49. // Helpers for parsing file name after successful return
  50. CString GetPathName() const; // return full path name
  51. CString GetFileName() const; // return only filename
  52. CString GetFileExt() const; // return only ext
  53. CString GetFileTitle() const; // return file title
  54. BOOL GetReadOnlyPref() const; // return TRUE if readonly checked
  55. // Overridable callbacks
  56. protected:
  57. friend UINT CALLBACK AFX_EXPORT _AfxCommDlgProc(HWND, UINT, WPARAM, LPARAM);
  58. virtual UINT OnShareViolation(LPCSTR lpszPathName);
  59. virtual BOOL OnFileNameOK();
  60. virtual void OnLBSelChangedNotify(UINT nIDBox, UINT iCurSel, UINT nCode);
  61. // Implementation
  62. #ifdef _DEBUG
  63. public:
  64. virtual void Dump(CDumpContext& dc) const;
  65. #endif
  66. protected:
  67. virtual void OnOK();
  68. virtual void OnCancel();
  69. BOOL m_bOpenFileDialog; // TRUE for file open, FALSE for file save
  70. CString m_strFilter; // filter string
  71. // separate fields with '|', terminate with '||\0'
  72. char m_szFileTitle[64]; // contains file title after return
  73. char m_szFileName[_MAX_PATH]; // contains full path name after return
  74. };
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CFontDialog - used to select a font
  77. class CFontDialog : public CDialog
  78. {
  79. DECLARE_DYNAMIC(CFontDialog)
  80. public:
  81. // Attributes
  82. // font choosing parameter block
  83. CHOOSEFONT m_cf;
  84. // Constructors
  85. CFontDialog(LPLOGFONT lplfInitial = NULL,
  86. DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,
  87. CDC* pdcPrinter = NULL,
  88. CWnd* pParentWnd = NULL);
  89. // Operations
  90. virtual int DoModal();
  91. // Retrieve the currently selected font while dialog is displayed
  92. void GetCurrentFont(LPLOGFONT lplf);
  93. // Helpers for parsing information after successful return
  94. CString GetFaceName() const; // return the face name of the font
  95. CString GetStyleName() const; // return the style name of the font
  96. int GetSize() const; // return the pt size of the font
  97. COLORREF GetColor() const; // return the color of the font
  98. int GetWeight() const; // return the chosen font weight
  99. BOOL IsStrikeOut() const; // return TRUE if strikeout
  100. BOOL IsUnderline() const; // return TRUE if underline
  101. BOOL IsBold() const; // return TRUE if bold font
  102. BOOL IsItalic() const; // return TRUE if italic font
  103. // Implementation
  104. LOGFONT m_lf; // default LOGFONT to store the info
  105. #ifdef _DEBUG
  106. public:
  107. virtual void Dump(CDumpContext& dc) const;
  108. #endif
  109. protected:
  110. virtual void OnOK();
  111. virtual void OnCancel();
  112. char m_szStyleName[64]; // contains style name after return
  113. };
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CColorDialog - used to select a color
  116. class CColorDialog : public CDialog
  117. {
  118. DECLARE_DYNAMIC(CColorDialog)
  119. public:
  120. // Attributes
  121. // color chooser parameter block
  122. CHOOSECOLOR m_cc;
  123. // Constructors
  124. CColorDialog(COLORREF clrInit = 0, DWORD dwFlags = 0,
  125. CWnd* pParentWnd = NULL);
  126. // Operations
  127. virtual int DoModal();
  128. // Set the current color while dialog is displayed
  129. void SetCurrentColor(COLORREF clr);
  130. // Helpers for parsing information after successful return
  131. COLORREF GetColor() const;
  132. // Custom colors are held here and saved between calls
  133. static COLORREF AFXAPI_DATA clrSavedCustom[16];
  134. // Overridable callbacks
  135. protected:
  136. friend UINT CALLBACK AFX_EXPORT _AfxCommDlgProc(HWND, UINT, WPARAM, LPARAM);
  137. virtual BOOL OnColorOK(); // validate color
  138. // Implementation
  139. #ifdef _DEBUG
  140. public:
  141. virtual void Dump(CDumpContext& dc) const;
  142. #endif
  143. protected:
  144. virtual void OnOK();
  145. virtual void OnCancel();
  146. //{{AFX_MSG(CColorDialog)
  147. afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  148. //}}AFX_MSG
  149. DECLARE_MESSAGE_MAP()
  150. };
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CPrintDialog - used for Print... and PrintSetup...
  153. class CPrintDialog : public CDialog
  154. {
  155. DECLARE_DYNAMIC(CPrintDialog)
  156. public:
  157. // Attributes
  158. // print dialog parameter block (note this is a reference)
  159. #ifdef AFX_CLASS_MODEL
  160. PRINTDLG FAR& m_pd;
  161. #else
  162. PRINTDLG& m_pd;
  163. #endif
  164. // Constructors
  165. CPrintDialog(BOOL bPrintSetupOnly,
  166. // TRUE for Print Setup, FALSE for Print Dialog
  167. DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS
  168. | PD_HIDEPRINTTOFILE | PD_NOSELECTION,
  169. CWnd* pParentWnd = NULL);
  170. // Operations
  171. virtual int DoModal();
  172. // GetDefaults will not display a dialog but will get
  173. // device defaults
  174. BOOL GetDefaults();
  175. // Helpers for parsing information after successful return
  176. int GetCopies() const; // num. copies requested
  177. BOOL PrintCollate() const; // TRUE if collate checked
  178. BOOL PrintSelection() const; // TRUE if printing selection
  179. BOOL PrintAll() const; // TRUE if printing all pages
  180. BOOL PrintRange() const; // TRUE if printing page range
  181. int GetFromPage() const; // starting page if valid
  182. int GetToPage() const; // starting page if valid
  183. LPDEVMODE GetDevMode() const; // return DEVMODE
  184. CString GetDriverName() const; // return driver name
  185. CString GetDeviceName() const; // return device name
  186. CString GetPortName() const; // return output port name
  187. HDC GetPrinterDC() const; // return HDC (caller must delete)
  188. // This helper creates a DC based on the DEVNAMES and DEVMODE structures.
  189. // This DC is returned, but also stored in m_pd.hDC as though it had been
  190. // returned by CommDlg. It is assumed that any previously obtained DC
  191. // has been/will be deleted by the user. This may be
  192. // used without ever invoking the print/print setup dialogs.
  193. HDC CreatePrinterDC();
  194. // Implementation
  195. #ifdef _DEBUG
  196. public:
  197. virtual void Dump(CDumpContext& dc) const;
  198. #endif
  199. private:
  200. PRINTDLG m_pdActual; // the Print/Print Setup need to share this
  201. protected:
  202. virtual void OnOK();
  203. virtual void OnCancel();
  204. // The following handle the case of print setup... from the print dialog
  205. #ifdef AFX_CLASS_MODEL
  206. CPrintDialog(PRINTDLG FAR& pdInit);
  207. #else
  208. CPrintDialog(PRINTDLG& pdInit);
  209. #endif
  210. virtual CPrintDialog* AttachOnSetup();
  211. //{{AFX_MSG(CPrintDialog)
  212. afx_msg void OnPrintSetup();
  213. //}}AFX_MSG
  214. DECLARE_MESSAGE_MAP()
  215. };
  216. /////////////////////////////////////////////////////////////////////////////
  217. // Find/FindReplace modeless dialogs
  218. class CFindReplaceDialog : public CDialog
  219. {
  220. DECLARE_DYNAMIC(CFindReplaceDialog)
  221. public:
  222. // Attributes
  223. FINDREPLACE m_fr;
  224. // Constructors
  225. CFindReplaceDialog();
  226. // NOTE: you must allocate these on the heap.
  227. // If you do not, you must derive and override PostNcDestroy()
  228. BOOL Create(BOOL bFindDialogOnly, // TRUE for Find, FALSE for FindReplace
  229. LPCSTR lpszFindWhat,
  230. LPCSTR lpszReplaceWith = NULL,
  231. DWORD dwFlags = FR_DOWN,
  232. CWnd* pParentWnd = NULL);
  233. // find/replace parameter block
  234. static CFindReplaceDialog* PASCAL GetNotifier(LPARAM lParam);
  235. // Operations
  236. // Helpers for parsing information after successful return
  237. CString GetReplaceString() const;// get replacement string
  238. CString GetFindString() const; // get find string
  239. BOOL SearchDown() const; // TRUE if search down, FALSE is up
  240. BOOL FindNext() const; // TRUE if command is find next
  241. BOOL MatchCase() const; // TRUE if matching case
  242. BOOL MatchWholeWord() const; // TRUE if matching whole words only
  243. BOOL ReplaceCurrent() const; // TRUE if replacing current string
  244. BOOL ReplaceAll() const; // TRUE if replacing all occurrences
  245. BOOL IsTerminating() const; // TRUE if terminating dialog
  246. // Implementation
  247. protected:
  248. virtual void OnOK();
  249. virtual void OnCancel();
  250. virtual void PostNcDestroy();
  251. #ifdef _DEBUG
  252. public:
  253. virtual void Dump(CDumpContext& dc) const;
  254. #endif
  255. protected:
  256. char m_szFindWhat[128];
  257. char m_szReplaceWith[128];
  258. };
  259. ////////////////////////////////////////////////////////////////////////////
  260. // CPropertyPage -- one page of a tabbed dialog
  261. class CPropertyPage : public CDialog
  262. {
  263. DECLARE_DYNAMIC(CPropertyPage)
  264. // Construction
  265. public:
  266. CPropertyPage(UINT nIDTemplate, UINT nIDCaption = 0);
  267. CPropertyPage(LPCTSTR lpszTemplateName, UINT nIDCaption = 0);
  268. // Operations
  269. public:
  270. void CancelToClose(); // called when the property sheet should display close instead of cancel
  271. // lets the property sheet activate the apply now button
  272. void SetModified(BOOL bChanged = TRUE);
  273. // Overridables
  274. public:
  275. virtual BOOL OnSetActive(); // called when this page gets the focus
  276. virtual BOOL OnKillActive(); // perform validation here
  277. virtual void OnOK(); // ok or apply now pressed -- KillActive is called first
  278. virtual void OnCancel(); // cancel pressed
  279. // Implementation
  280. public:
  281. virtual ~CPropertyPage();
  282. virtual BOOL PreTranslateMessage(MSG* pMsg); // handle tab, enter, and escape keys
  283. #ifdef _DEBUG
  284. virtual void AssertValid() const;
  285. virtual void Dump(CDumpContext& dc) const;
  286. // EndDialog is provided to generate an assert if it is called
  287. void EndDialog(int nEndID);
  288. #endif
  289. protected:
  290. CString m_strCaption;
  291. BOOL m_bChanged;
  292. void CommonConstruct(LPCTSTR lpszTemplateName, UINT nIDCaption);
  293. // loads the resource indicated by CDialog::m_lpDialogTemplate
  294. BOOL PreTranslateKeyDown(MSG* pMsg);
  295. BOOL ProcessTab(MSG* pMsg); // handles tab key from PreTranslateMessage
  296. BOOL CreatePage(); // called from CPropertySheet to create the dialog
  297. // by loading the dialog resource into memory and
  298. // turning off WS_CAPTION before creating
  299. void LoadCaption();
  300. // gets the caption of the dialog from the resource and puts it in m_strCaption
  301. // Generated message map functions
  302. //{{AFX_MSG(CPropertyPage)
  303. afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpcs);
  304. afx_msg int OnCreate(LPCREATESTRUCT lpcs);
  305. afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  306. afx_msg void OnClose();
  307. //}}AFX_MSG
  308. DECLARE_MESSAGE_MAP()
  309. friend class CPropertySheet;
  310. };
  311. ////////////////////////////////////////////////////////////////////////////
  312. // CTabControl -- internal use only
  313. // Implementation for a generic row of tabs along the top of dialog
  314. // Future versions of MFC may or may not include this exact class.
  315. class CTabItem; // private to CTabControl implementation
  316. // TCN_ messages are tab control notifications
  317. #define TCN_TABCHANGING 1
  318. #define TCN_TABCHANGED 2
  319. class CTabControl : public CWnd
  320. {
  321. DECLARE_DYNAMIC(CTabControl)
  322. public:
  323. // Construction
  324. CTabControl();
  325. // Attributes
  326. BOOL m_bInSize;
  327. int m_nHeight;
  328. BOOL SetCurSel(int nTab);
  329. int GetCurSel() const;
  330. int GetItemCount() const;
  331. // Operations
  332. BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  333. void AddTab(LPCTSTR lpszCaption);
  334. void RemoveTab(int nTab);
  335. // Implementation
  336. public:
  337. virtual ~CTabControl();
  338. BOOL NextTab(BOOL bNext);
  339. protected:
  340. void Scroll(int nDirection);
  341. void ScrollIntoView(int nTab);
  342. void DrawFocusRect(CDC* pDC = NULL);
  343. void InvalidateTab(int nTab, BOOL bInflate = TRUE);
  344. int TabFromPoint(CPoint pt);
  345. void Capture(int nDirection);
  346. void LayoutTabsStacked(int nTab);
  347. void LayoutTabsSingle(int nTab);
  348. enum
  349. {
  350. SCROLL_LEFT = -5, // all the SCROLL_ items must be less
  351. SCROLL_RIGHT = -6, // than -1 to avoid ID conflict
  352. SCROLL_NULL = -7,
  353. TIMER_ID = 15, // timer constants
  354. TIMER_DELAY = 500
  355. };
  356. void DrawScrollers(CDC* pDC);
  357. BOOL CanScroll();
  358. void SetFirstTab(int nTab);
  359. CTabItem* GetTabItem(int nTab) const;
  360. BOOL IsTabVisible(int nTab, BOOL bComplete = FALSE) const;
  361. // Member variables
  362. HFONT m_hBoldFont;
  363. HFONT m_hThinFont;
  364. CRect m_rectScroll; // location of scroll buttons
  365. int m_nCurTab; // index of current selected tab
  366. int m_nFirstTab; // index of leftmost visible tab
  367. int m_nScrollState; // shows whether left or right scroll btn is down
  368. BOOL m_bScrollPause;// if we have capture, has the mouse wandered off btn?
  369. CPtrArray m_tabs; // list of CTabItems, in order
  370. // Generated message map functions
  371. //{{AFX_MSG(CTabControl)
  372. afx_msg void OnPaint();
  373. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  374. afx_msg UINT OnGetDlgCode();
  375. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  376. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  377. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  378. afx_msg void OnTimer(UINT nIDEvent);
  379. afx_msg void OnSetFocus(CWnd* pOldWnd);
  380. afx_msg void OnKillFocus(CWnd* pNewWnd);
  381. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  382. afx_msg void OnSize(UINT nType, int cx, int cy);
  383. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  384. //}}AFX_MSG
  385. DECLARE_MESSAGE_MAP()
  386. };
  387. ////////////////////////////////////////////////////////////////////////////
  388. // CPropertySheet -- a tabbed "dialog" (really a popup-window)
  389. class CPropertySheet : public CWnd
  390. {
  391. DECLARE_DYNAMIC(CPropertySheet)
  392. // Construction
  393. public:
  394. CPropertySheet(UINT nIDCaption, CWnd* pParentWnd = NULL,
  395. UINT iSelectPage = 0);
  396. CPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL,
  397. UINT iSelectPage = 0);
  398. // for modeless creation
  399. BOOL Create(CWnd* pParentWnd = NULL, DWORD dwStyle =
  400. WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME | WS_VISIBLE,
  401. DWORD dwExStyle = WS_EX_DLGMODALFRAME);
  402. // Attributes
  403. public:
  404. int GetPageCount() const;
  405. CPropertyPage* GetPage(int nPage) const;
  406. // Operations
  407. public:
  408. int DoModal();
  409. void AddPage(CPropertyPage* pPage);
  410. void RemovePage(CPropertyPage* pPage);
  411. void RemovePage(int nPage);
  412. void EndDialog(int nEndID); // used to terminate a modal dialog
  413. // Implementation
  414. public:
  415. virtual ~CPropertySheet();
  416. #ifdef _DEBUG
  417. virtual void AssertValid() const;
  418. virtual void Dump(CDumpContext& dc) const;
  419. #endif
  420. void EnableStackedTabs(BOOL bStacked);
  421. virtual BOOL PreTranslateMessage(MSG* pMsg);
  422. virtual BOOL DestroyWindow();
  423. BOOL SetActivePage(int nPage);
  424. protected:
  425. HWND FindNextControl(HWND hWnd, TCHAR ch);
  426. void GotoControl(HWND hWnd, TCHAR ch);
  427. BOOL ProcessChars(MSG* pMsg);
  428. BOOL ProcessTab(MSG* pMsg);
  429. BOOL CreateStandardButtons();
  430. BOOL PumpMessage();
  431. void PageChanged();
  432. void CancelToClose();
  433. void CommonConstruct(CWnd* pParent, UINT iSelectPage);
  434. void RecalcLayout();
  435. CPropertyPage* GetActivePage() const;
  436. void CheckDefaultButton(HWND hFocusBefore, HWND hFocusAfter);
  437. void CheckFocusChange();
  438. // implementation data members
  439. HFONT m_hFont; // sizes below dependent on this font
  440. CSize m_sizeButton;
  441. CSize m_sizeTabMargin;
  442. int m_cxButtonGap;
  443. BOOL m_bModeless;
  444. BOOL m_bStacked;
  445. int m_nCurPage;
  446. int m_nID; // ID passed to EndDialog and returned from DoModal
  447. CPtrArray m_pages; // array of CPropertyPage pointers
  448. HWND m_hWndDefault; // current default push button if there is one
  449. HWND m_hFocusWnd; // focus when we lost activation
  450. HWND m_hLastFocus; // tracks last window with focus
  451. CWnd* m_pParentWnd; // owner of the tabbed dialog
  452. CString m_strCaption; // caption of the pseudo-dialog
  453. CTabControl m_tabRow; // entire row of tabs at top of dialog
  454. BOOL m_bParentDisabled; // TRUE if parent was disabled by DoModal
  455. // Generated message map functions
  456. //{{AFX_MSG(CPropertySheet)
  457. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  458. afx_msg void OnPaint();
  459. afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
  460. afx_msg void OnClose();
  461. afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  462. afx_msg void OnSetFocus(CWnd* pOldWnd);
  463. afx_msg void OnOK();
  464. afx_msg void OnCancel();
  465. afx_msg void OnApply();
  466. afx_msg LRESULT OnTabChanged(WPARAM, LPARAM);
  467. afx_msg LRESULT OnTabChanging(WPARAM, LPARAM);
  468. afx_msg LRESULT OnGetFont(WPARAM, LPARAM);
  469. afx_msg LRESULT OnCommandHelp(WPARAM, LPARAM);
  470. //}}AFX_MSG
  471. DECLARE_MESSAGE_MAP()
  472. friend class CPropertyPage; // for tab handler
  473. };
  474. /////////////////////////////////////////////////////////////////////////////
  475. // Inline function declarations
  476. #ifdef _AFX_ENABLE_INLINES
  477. #define _AFXDLGS_INLINE inline
  478. #include <afxdlgs.inl>
  479. #endif
  480. #undef AFXAPP_DATA
  481. #define AFXAPP_DATA NEAR
  482. /////////////////////////////////////////////////////////////////////////////
  483. #endif //__AFXDLGS_H__