Globals.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * Globals.h
  3. * ---------
  4. * Purpose: Implementation of various views of the tracker interface.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. OPENMPT_NAMESPACE_BEGIN
  12. #ifndef WM_HELPHITTEST
  13. #define WM_HELPHITTEST 0x366
  14. #endif
  15. #ifndef HID_BASE_COMMAND
  16. #define HID_BASE_COMMAND 0x10000
  17. #endif
  18. #define ID_EDIT_MIXPASTE ID_EDIT_PASTE_SPECIAL //rewbs.mixPaste
  19. class CModControlView;
  20. class CModControlBar;
  21. class CModDoc;
  22. class CModControlBar: public CToolBarCtrl
  23. {
  24. public:
  25. BOOL Init(CImageList &icons, CImageList &disabledIcons);
  26. void UpdateStyle();
  27. BOOL AddButton(UINT nID, int iImage=0, UINT nStyle=TBSTYLE_BUTTON, UINT nState=TBSTATE_ENABLED);
  28. afx_msg LRESULT OnHelpHitTest(WPARAM, LPARAM);
  29. DECLARE_MESSAGE_MAP()
  30. };
  31. class CModControlDlg: public CDialog
  32. {
  33. protected:
  34. CModDoc &m_modDoc;
  35. CSoundFile &m_sndFile;
  36. CModControlView &m_parent;
  37. HWND m_hWndView;
  38. LONG m_nLockCount;
  39. int m_nDPIx, m_nDPIy; // Cached DPI settings
  40. BOOL m_bInitialized;
  41. public:
  42. CModControlDlg(CModControlView &parent, CModDoc &document);
  43. virtual ~CModControlDlg();
  44. public:
  45. void SetViewWnd(HWND hwndView) { m_hWndView = hwndView; }
  46. HWND GetViewWnd() const { return m_hWndView; }
  47. LRESULT SendViewMessage(UINT uMsg, LPARAM lParam=0) const;
  48. BOOL PostViewMessage(UINT uMsg, LPARAM lParam=0) const;
  49. LRESULT SwitchToView() const { return SendViewMessage(VIEWMSG_SETACTIVE); }
  50. void LockControls() { m_nLockCount++; }
  51. void UnlockControls() { PostMessage(WM_MOD_UNLOCKCONTROLS); }
  52. bool IsLocked() const { return (m_nLockCount > 0); }
  53. virtual Setting<LONG> &GetSplitPosRef() = 0; //rewbs.varWindowSize
  54. afx_msg void OnEditCut() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_CUT, 0); }
  55. afx_msg void OnEditCopy() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_COPY, 0); }
  56. afx_msg void OnEditPaste() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_PASTE, 0); }
  57. afx_msg void OnEditMixPaste() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_MIXPASTE, 0); }
  58. afx_msg void OnEditMixPasteITStyle() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_MIXPASTE_ITSTYLE, 0); }
  59. afx_msg void OnEditPasteFlood() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_PASTEFLOOD, 0); }
  60. afx_msg void OnEditPushForwardPaste() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_PUSHFORWARDPASTE, 0); }
  61. afx_msg void OnEditFind() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_FIND, 0); }
  62. afx_msg void OnEditFindNext() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_FINDNEXT, 0); }
  63. afx_msg void OnSwitchToView() { if (m_hWndView) ::PostMessage(m_hWndView, WM_MOD_VIEWMSG, VIEWMSG_SETFOCUS, 0); }
  64. //{{AFX_VIRTUAL(CModControlDlg)
  65. void OnOK() override {}
  66. void OnCancel() override {}
  67. virtual void RecalcLayout() = 0;
  68. virtual void UpdateView(UpdateHint, CObject *) = 0;
  69. virtual CRuntimeClass *GetAssociatedViewClass() { return nullptr; }
  70. virtual LRESULT OnModCtrlMsg(WPARAM wParam, LPARAM lParam);
  71. virtual void OnActivatePage(LPARAM) {}
  72. virtual void OnDeactivatePage() {}
  73. BOOL OnInitDialog() override;
  74. INT_PTR OnToolHitTest(CPoint point, TOOLINFO *pTI) const override;
  75. virtual BOOL GetToolTipText(UINT, LPTSTR) { return FALSE; }
  76. //}}AFX_VIRTUAL
  77. //{{AFX_MSG(CModControlDlg)
  78. afx_msg void OnSize(UINT nType, int cx, int cy);
  79. afx_msg LRESULT OnUnlockControls(WPARAM, LPARAM) { if (m_nLockCount > 0) m_nLockCount--; return 0; }
  80. afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
  81. afx_msg LRESULT OnDPIChanged(WPARAM = 0, LPARAM = 0);
  82. //}}AFX_MSG
  83. DECLARE_MESSAGE_MAP()
  84. };
  85. class CModTabCtrl: public CTabCtrl
  86. {
  87. public:
  88. BOOL InsertItem(int nIndex, LPCTSTR pszText, LPARAM lParam=0, int iImage=-1);
  89. BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  90. LPARAM GetItemData(int nIndex);
  91. };
  92. class CModControlView: public CView
  93. {
  94. public:
  95. enum Views
  96. {
  97. VIEW_UNKNOWN = -1,
  98. VIEW_GLOBALS = 0,
  99. VIEW_PATTERNS,
  100. VIEW_SAMPLES,
  101. VIEW_INSTRUMENTS,
  102. VIEW_COMMENTS,
  103. VIEW_PLUGINS,
  104. MAX_PAGES
  105. };
  106. protected:
  107. CModTabCtrl m_TabCtrl;
  108. CModControlDlg *m_Pages[MAX_PAGES];
  109. int m_nActiveDlg, m_nInstrumentChanged;
  110. HWND m_hWndView, m_hWndMDI;
  111. protected: // create from serialization only
  112. CModControlView();
  113. DECLARE_DYNCREATE(CModControlView)
  114. public:
  115. virtual ~CModControlView() {}
  116. CModDoc* GetDocument() const { return (CModDoc *)m_pDocument; }
  117. void SampleChanged(SAMPLEINDEX smp);
  118. void InstrumentChanged(int nInstr=-1) { m_nInstrumentChanged = nInstr; }
  119. int GetInstrumentChange() const { return m_nInstrumentChanged; }
  120. void SetMDIParentFrame(HWND hwnd) { m_hWndMDI = hwnd; }
  121. void ForceRefresh();
  122. CModControlDlg *GetCurrentControlDlg() { return m_Pages[m_nActiveDlg]; }
  123. protected:
  124. void RecalcLayout();
  125. void UpdateView(UpdateHint hint, CObject *pHint = nullptr);
  126. BOOL SetActivePage(int nIndex = -1, LPARAM lParam=-1);
  127. public:
  128. int GetActivePage() const { return m_nActiveDlg; }
  129. protected:
  130. //{{AFX_VIRTUAL(CModControlView)
  131. public:
  132. BOOL PreCreateWindow(CREATESTRUCT& cs) override;
  133. protected:
  134. void OnInitialUpdate() override; // called first time after construct
  135. void OnDraw(CDC *) override {}
  136. void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) override;
  137. //}}AFX_VIRTUAL
  138. protected:
  139. //{{AFX_MSG(CModControlView)
  140. afx_msg void OnSize(UINT nType, int cx, int cy);
  141. afx_msg void OnDestroy();
  142. afx_msg void OnTabSelchange(NMHDR* pNMHDR, LRESULT* pResult);
  143. afx_msg void OnEditCut() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_CUT, 0); }
  144. afx_msg void OnEditCopy() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_COPY, 0); }
  145. afx_msg void OnEditPaste() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_PASTE, 0); }
  146. afx_msg void OnEditMixPaste() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_MIXPASTE, 0); } //rewbs.mixPaste
  147. afx_msg void OnEditMixPasteITStyle() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_MIXPASTE_ITSTYLE, 0); }
  148. afx_msg void OnEditFind() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_FIND, 0); }
  149. afx_msg void OnEditFindNext() { if (m_hWndView) ::SendMessage(m_hWndView, WM_COMMAND, ID_EDIT_FINDNEXT, 0); }
  150. afx_msg void OnSwitchToView() { if (m_hWndView) ::PostMessage(m_hWndView, WM_MOD_VIEWMSG, VIEWMSG_SETFOCUS, 0); }
  151. afx_msg LRESULT OnActivateModView(WPARAM, LPARAM);
  152. afx_msg LRESULT OnModCtrlMsg(WPARAM wParam, LPARAM lParam);
  153. afx_msg LRESULT OnGetToolTipText(WPARAM, LPARAM);
  154. //}}AFX_MSG
  155. DECLARE_MESSAGE_MAP()
  156. };
  157. // Non-client button attributes
  158. #define NCBTNS_MOUSEOVER 0x01
  159. #define NCBTNS_CHECKED 0x02
  160. #define NCBTNS_DISABLED 0x04
  161. #define NCBTNS_PUSHED 0x08
  162. class CModScrollView: public CScrollView
  163. {
  164. protected:
  165. HWND m_hWndCtrl;
  166. int m_nScrollPosX, m_nScrollPosY;
  167. int m_nDPIx, m_nDPIy; // Cached DPI settings
  168. public:
  169. DECLARE_SERIAL(CModScrollView)
  170. CModScrollView() : m_hWndCtrl(nullptr), m_nScrollPosX(0), m_nScrollPosY(0) { }
  171. virtual ~CModScrollView() {}
  172. public:
  173. CModDoc* GetDocument() const { return (CModDoc *)m_pDocument; }
  174. LRESULT SendCtrlMessage(UINT uMsg, LPARAM lParam=0) const;
  175. void SendCtrlCommand(int id) const;
  176. BOOL PostCtrlMessage(UINT uMsg, LPARAM lParam=0) const;
  177. void UpdateIndicator(LPCTSTR lpszText = nullptr);
  178. public:
  179. //{{AFX_VIRTUAL(CModScrollView)
  180. void OnInitialUpdate() override;
  181. void OnDraw(CDC *) override {}
  182. void OnPrepareDC(CDC*, CPrintInfo*) override {}
  183. void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) override;
  184. virtual void UpdateView(UpdateHint, CObject *) {}
  185. virtual LRESULT OnModViewMsg(WPARAM wParam, LPARAM lParam);
  186. virtual BOOL OnDragonDrop(BOOL, const DRAGONDROP *) { return FALSE; }
  187. virtual LRESULT OnPlayerNotify(Notification *) { return 0; }
  188. //}}AFX_VIRTUAL
  189. CModControlDlg *GetControlDlg() { return static_cast<CModControlView *>(CWnd::FromHandle(m_hWndCtrl))->GetCurrentControlDlg(); }
  190. protected:
  191. //{{AFX_MSG(CModScrollView)
  192. afx_msg void OnDestroy();
  193. afx_msg LRESULT OnReceiveModViewMsg(WPARAM wParam, LPARAM lParam);
  194. afx_msg BOOL OnMouseWheel(UINT fFlags, short zDelta, CPoint point);
  195. afx_msg void OnMouseHWheel(UINT fFlags, short zDelta, CPoint point);
  196. afx_msg LRESULT OnDragonDropping(WPARAM bDoDrop, LPARAM lParam) { return OnDragonDrop((BOOL)bDoDrop, (const DRAGONDROP *)lParam); }
  197. afx_msg LRESULT OnUpdatePosition(WPARAM, LPARAM);
  198. afx_msg LRESULT OnDPIChanged(WPARAM = 0, LPARAM = 0);
  199. // Fixes for 16-bit limitation in MFC's CScrollView
  200. BOOL OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll = TRUE) override;
  201. BOOL OnScrollBy(CSize sizeScroll, BOOL bDoScroll = TRUE) override;
  202. int SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE);
  203. void SetScrollSizes(int nMapMode, SIZE sizeTotal, const SIZE& sizePage = CScrollView::sizeDefault, const SIZE& sizeLine = CScrollView::sizeDefault);
  204. BOOL OnGesturePan(CPoint ptFrom, CPoint ptTo) override;
  205. //}}AFX_MSG
  206. DECLARE_MESSAGE_MAP()
  207. };
  208. /////////////////////////////////////////////////////////////////////////////
  209. //{{AFX_INSERT_LOCATION}}
  210. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  211. OPENMPT_NAMESPACE_END