Globals.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /*
  2. * globals.cpp
  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. #include "stdafx.h"
  10. #include "Mptrack.h"
  11. #include "Mainfrm.h"
  12. #include "Moddoc.h"
  13. #include "Childfrm.h"
  14. #include "Globals.h"
  15. #include "Ctrl_gen.h"
  16. #include "Ctrl_pat.h"
  17. #include "Ctrl_smp.h"
  18. #include "Ctrl_ins.h"
  19. #include "Ctrl_com.h"
  20. #include "ImageLists.h"
  21. #include "../soundlib/mod_specifications.h"
  22. OPENMPT_NAMESPACE_BEGIN
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CModControlDlg
  25. BEGIN_MESSAGE_MAP(CModControlDlg, CDialog)
  26. //{{AFX_MSG_MAP(CModControlDlg)
  27. ON_WM_SIZE()
  28. #if !defined(MPT_BUILD_RETRO)
  29. ON_MESSAGE(WM_DPICHANGED, &CModControlDlg::OnDPIChanged)
  30. #endif
  31. ON_MESSAGE(WM_MOD_UNLOCKCONTROLS, &CModControlDlg::OnUnlockControls)
  32. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CModControlDlg::OnToolTipText)
  33. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &CModControlDlg::OnToolTipText)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. CModControlDlg::CModControlDlg(CModControlView &parent, CModDoc &document) : m_modDoc(document), m_sndFile(document.GetSoundFile()), m_parent(parent)
  37. {
  38. m_bInitialized = FALSE;
  39. m_hWndView = NULL;
  40. m_nLockCount = 0;
  41. }
  42. CModControlDlg::~CModControlDlg()
  43. {
  44. ASSERT(m_hWnd == NULL);
  45. }
  46. BOOL CModControlDlg::OnInitDialog()
  47. {
  48. CDialog::OnInitDialog();
  49. m_nDPIx = Util::GetDPIx(m_hWnd);
  50. m_nDPIy = Util::GetDPIy(m_hWnd);
  51. EnableToolTips(TRUE);
  52. return TRUE;
  53. }
  54. LRESULT CModControlDlg::OnDPIChanged(WPARAM wParam, LPARAM)
  55. {
  56. m_nDPIx = LOWORD(wParam);
  57. m_nDPIy = HIWORD(wParam);
  58. return 0;
  59. }
  60. void CModControlDlg::OnSize(UINT nType, int cx, int cy)
  61. {
  62. CDialog::OnSize(nType, cx, cy);
  63. if (((nType == SIZE_RESTORED) || (nType == SIZE_MAXIMIZED)) && (cx > 0) && (cy > 0))
  64. {
  65. RecalcLayout();
  66. }
  67. }
  68. LRESULT CModControlDlg::OnModCtrlMsg(WPARAM wParam, LPARAM lParam)
  69. {
  70. switch(wParam)
  71. {
  72. case CTRLMSG_SETVIEWWND:
  73. m_hWndView = (HWND)lParam;
  74. break;
  75. case CTRLMSG_ACTIVATEPAGE:
  76. OnActivatePage(lParam);
  77. break;
  78. case CTRLMSG_DEACTIVATEPAGE:
  79. OnDeactivatePage();
  80. break;
  81. case CTRLMSG_SETFOCUS:
  82. GetParentFrame()->SetActiveView(&m_parent);
  83. SetFocus();
  84. break;
  85. }
  86. return 0;
  87. }
  88. LRESULT CModControlDlg::SendViewMessage(UINT uMsg, LPARAM lParam) const
  89. {
  90. if (m_hWndView) return ::SendMessage(m_hWndView, WM_MOD_VIEWMSG, uMsg, lParam);
  91. return 0;
  92. }
  93. BOOL CModControlDlg::PostViewMessage(UINT uMsg, LPARAM lParam) const
  94. {
  95. if (m_hWndView) return ::PostMessage(m_hWndView, WM_MOD_VIEWMSG, uMsg, lParam);
  96. return FALSE;
  97. }
  98. INT_PTR CModControlDlg::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
  99. {
  100. INT_PTR nHit = CDialog::OnToolHitTest(point, pTI);
  101. if ((nHit >= 0) && (pTI))
  102. {
  103. if ((pTI->lpszText == LPSTR_TEXTCALLBACK) && (pTI->hwnd == m_hWnd))
  104. {
  105. CFrameWnd *pMDIParent = GetParentFrame();
  106. if (pMDIParent) pTI->hwnd = pMDIParent->m_hWnd;
  107. }
  108. }
  109. return nHit;
  110. }
  111. BOOL CModControlDlg::OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult)
  112. {
  113. CChildFrame *pChildFrm = (CChildFrame *)GetParentFrame();
  114. if (pChildFrm) return pChildFrm->OnToolTipText(nID, pNMHDR, pResult);
  115. if (pResult) *pResult = 0;
  116. return FALSE;
  117. }
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CModControlView
  120. BOOL CModTabCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  121. {
  122. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  123. if (!pMainFrm) return FALSE;
  124. if (!CTabCtrl::Create(dwStyle, rect, pParentWnd, nID)) return FALSE;
  125. SendMessage(WM_SETFONT, (WPARAM)pMainFrm->GetGUIFont());
  126. SetImageList(&pMainFrm->m_MiscIcons);
  127. return TRUE;
  128. }
  129. BOOL CModTabCtrl::InsertItem(int nIndex, LPCTSTR pszText, LPARAM lParam, int iImage)
  130. {
  131. TC_ITEM tci;
  132. tci.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
  133. tci.pszText = const_cast<LPTSTR>(pszText);
  134. tci.lParam = lParam;
  135. tci.iImage = iImage;
  136. return CTabCtrl::InsertItem(nIndex, &tci);
  137. }
  138. LPARAM CModTabCtrl::GetItemData(int nIndex)
  139. {
  140. TC_ITEM tci;
  141. tci.mask = TCIF_PARAM;
  142. tci.lParam = 0;
  143. if (!GetItem(nIndex, &tci)) return 0;
  144. return tci.lParam;
  145. }
  146. /////////////////////////////////////////////////////////////////////////////////
  147. // CModControlView
  148. IMPLEMENT_DYNCREATE(CModControlView, CView)
  149. BEGIN_MESSAGE_MAP(CModControlView, CView)
  150. //{{AFX_MSG_MAP(CModControlView)
  151. ON_WM_SIZE()
  152. ON_WM_DESTROY()
  153. ON_NOTIFY(TCN_SELCHANGE, IDC_TABCTRL1, &CModControlView::OnTabSelchange)
  154. ON_MESSAGE(WM_MOD_ACTIVATEVIEW, &CModControlView::OnActivateModView)
  155. ON_MESSAGE(WM_MOD_CTRLMSG, &CModControlView::OnModCtrlMsg)
  156. ON_MESSAGE(WM_MOD_GETTOOLTIPTEXT, &CModControlView::OnGetToolTipText)
  157. ON_COMMAND(ID_EDIT_CUT, &CModControlView::OnEditCut)
  158. ON_COMMAND(ID_EDIT_COPY, &CModControlView::OnEditCopy)
  159. ON_COMMAND(ID_EDIT_PASTE, &CModControlView::OnEditPaste)
  160. ON_COMMAND(ID_EDIT_MIXPASTE, &CModControlView::OnEditMixPaste)
  161. ON_COMMAND(ID_EDIT_MIXPASTE_ITSTYLE, &CModControlView::OnEditMixPasteITStyle)
  162. ON_COMMAND(ID_EDIT_FIND, &CModControlView::OnEditFind)
  163. ON_COMMAND(ID_EDIT_FINDNEXT, &CModControlView::OnEditFindNext)
  164. //}}AFX_MSG_MAP
  165. END_MESSAGE_MAP()
  166. CModControlView::CModControlView()
  167. {
  168. MemsetZero(m_Pages);
  169. m_nActiveDlg = -1;
  170. m_nInstrumentChanged = -1;
  171. m_hWndView = NULL;
  172. m_hWndMDI = NULL;
  173. }
  174. BOOL CModControlView::PreCreateWindow(CREATESTRUCT& cs)
  175. {
  176. return CView::PreCreateWindow(cs);
  177. }
  178. void CModControlView::OnInitialUpdate() // called first time after construct
  179. {
  180. CView::OnInitialUpdate();
  181. CRect rect;
  182. CChildFrame *pParentFrame = (CChildFrame *)GetParentFrame();
  183. if (pParentFrame) m_hWndView = pParentFrame->GetHwndView();
  184. GetClientRect(&rect);
  185. m_TabCtrl.Create(WS_CHILD|WS_VISIBLE|TCS_FOCUSNEVER|TCS_FORCELABELLEFT, rect, this, IDC_TABCTRL1);
  186. UpdateView(UpdateHint().ModType());
  187. SetActivePage(0);
  188. }
  189. void CModControlView::OnSize(UINT nType, int cx, int cy)
  190. {
  191. CView::OnSize(nType, cx, cy);
  192. if (((nType == SIZE_RESTORED) || (nType == SIZE_MAXIMIZED)) && (cx > 0) && (cy > 0))
  193. {
  194. RecalcLayout();
  195. }
  196. }
  197. void CModControlView::RecalcLayout()
  198. {
  199. CRect rcClient;
  200. if (m_TabCtrl.m_hWnd == NULL) return;
  201. GetClientRect(&rcClient);
  202. if ((m_nActiveDlg >= 0) && (m_nActiveDlg < MAX_PAGES) && (m_Pages[m_nActiveDlg]))
  203. {
  204. CWnd *pDlg = m_Pages[m_nActiveDlg];
  205. CRect rect = rcClient;
  206. m_TabCtrl.AdjustRect(FALSE, &rect);
  207. HDWP hdwp = BeginDeferWindowPos(2);
  208. DeferWindowPos(hdwp, m_TabCtrl.m_hWnd, NULL, rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), SWP_NOZORDER);
  209. DeferWindowPos(hdwp, pDlg->m_hWnd, NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER);
  210. EndDeferWindowPos(hdwp);
  211. } else
  212. {
  213. m_TabCtrl.MoveWindow(&rcClient);
  214. }
  215. }
  216. void CModControlView::OnUpdate(CView *, LPARAM lHint, CObject *pHint)
  217. {
  218. UpdateView(UpdateHint::FromLPARAM(lHint), pHint);
  219. }
  220. void CModControlView::ForceRefresh()
  221. {
  222. SetActivePage(GetActivePage());
  223. }
  224. BOOL CModControlView::SetActivePage(int nIndex, LPARAM lParam)
  225. {
  226. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  227. CModControlDlg *pDlg = NULL;
  228. if (nIndex == -1) nIndex = m_TabCtrl.GetCurSel();
  229. const UINT nID = static_cast<UINT>(m_TabCtrl.GetItemData(nIndex));
  230. if(nID == 0) return FALSE;
  231. switch(nID)
  232. {
  233. //rewbs.graph
  234. case IDD_CONTROL_GRAPH:
  235. nIndex = 5;
  236. break;
  237. //end rewbs.graph
  238. case IDD_CONTROL_COMMENTS:
  239. nIndex = 4;
  240. break;
  241. case IDD_CONTROL_GLOBALS:
  242. nIndex = 0;
  243. break;
  244. case IDD_CONTROL_PATTERNS:
  245. nIndex = 1;
  246. break;
  247. case IDD_CONTROL_SAMPLES:
  248. nIndex = 2;
  249. break;
  250. case IDD_CONTROL_INSTRUMENTS:
  251. nIndex = 3;
  252. break;
  253. default:
  254. return FALSE;
  255. }
  256. if ((nIndex < 0) || (nIndex >= MAX_PAGES) || (!pMainFrm)) return FALSE;
  257. if (m_Pages[m_nActiveDlg])
  258. m_Pages[m_nActiveDlg]->GetSplitPosRef() = ((CChildFrame *)GetParentFrame())->GetSplitterHeight();
  259. if (nIndex == m_nActiveDlg)
  260. {
  261. pDlg = m_Pages[m_nActiveDlg];
  262. PostMessage(WM_MOD_CTRLMSG, CTRLMSG_ACTIVATEPAGE, lParam);
  263. return TRUE;
  264. }
  265. if ((m_nActiveDlg >= 0) && (m_nActiveDlg < MAX_PAGES))
  266. {
  267. if (m_Pages[m_nActiveDlg])
  268. {
  269. OnModCtrlMsg(CTRLMSG_DEACTIVATEPAGE, 0);
  270. m_Pages[m_nActiveDlg]->ShowWindow(SW_HIDE);
  271. }
  272. m_nActiveDlg = -1;
  273. }
  274. if (m_Pages[nIndex]) //Ctrl window already created?
  275. {
  276. m_nActiveDlg = nIndex;
  277. pDlg = m_Pages[nIndex];
  278. } else //Ctrl window is not created yet - creating one.
  279. {
  280. MPT_ASSERT_ALWAYS(GetDocument() != nullptr);
  281. switch(nID)
  282. {
  283. //rewbs.graph
  284. case IDD_CONTROL_GRAPH:
  285. //pDlg = new CCtrlGraph();
  286. break;
  287. //end rewbs.graph
  288. case IDD_CONTROL_COMMENTS:
  289. pDlg = new CCtrlComments(*this, *GetDocument());
  290. break;
  291. case IDD_CONTROL_GLOBALS:
  292. pDlg = new CCtrlGeneral(*this, *GetDocument());
  293. break;
  294. case IDD_CONTROL_PATTERNS:
  295. pDlg = new CCtrlPatterns(*this, *GetDocument());
  296. break;
  297. case IDD_CONTROL_SAMPLES:
  298. pDlg = new CCtrlSamples(*this, *GetDocument());
  299. break;
  300. case IDD_CONTROL_INSTRUMENTS:
  301. pDlg = new CCtrlInstruments(*this, *GetDocument());
  302. break;
  303. default:
  304. return FALSE;
  305. }
  306. if (!pDlg) return FALSE;
  307. pDlg->SetViewWnd(m_hWndView);
  308. BOOL bStatus = pDlg->Create(nID, this);
  309. if(bStatus == 0) // Creation failed.
  310. {
  311. delete pDlg;
  312. return FALSE;
  313. }
  314. m_nActiveDlg = nIndex;
  315. m_Pages[nIndex] = pDlg;
  316. }
  317. RecalcLayout();
  318. pMainFrm->SetUserText(_T(""));
  319. pMainFrm->SetInfoText(_T(""));
  320. pMainFrm->SetXInfoText(_T("")); //rewbs.xinfo
  321. pDlg->ShowWindow(SW_SHOW);
  322. ((CChildFrame *)GetParentFrame())->SetSplitterHeight(pDlg->GetSplitPosRef());
  323. if (m_hWndMDI) ::PostMessage(m_hWndMDI, WM_MOD_CHANGEVIEWCLASS, (WPARAM)lParam, (LPARAM)pDlg);
  324. return TRUE;
  325. }
  326. void CModControlView::OnDestroy()
  327. {
  328. m_nActiveDlg = -1;
  329. for (UINT nIndex=0; nIndex<MAX_PAGES; nIndex++)
  330. {
  331. CModControlDlg *pDlg = m_Pages[nIndex];
  332. if (pDlg)
  333. {
  334. m_Pages[nIndex] = NULL;
  335. pDlg->DestroyWindow();
  336. delete pDlg;
  337. }
  338. }
  339. CView::OnDestroy();
  340. }
  341. void CModControlView::UpdateView(UpdateHint lHint, CObject *pObject)
  342. {
  343. CWnd *pActiveDlg = NULL;
  344. CModDoc *pDoc = GetDocument();
  345. if (!pDoc) return;
  346. // Module type changed: update tabs
  347. if (lHint.GetType()[HINT_MODTYPE])
  348. {
  349. UINT nCount = 4;
  350. UINT mask = 1 | 2 | 4 | 16;
  351. if(pDoc->GetSoundFile().GetModSpecifications().instrumentsMax > 0 || pDoc->GetNumInstruments() > 0)
  352. {
  353. mask |= 8;
  354. //mask |= 32; //rewbs.graph
  355. nCount++;
  356. }
  357. if (nCount != (UINT)m_TabCtrl.GetItemCount())
  358. {
  359. UINT count = 0;
  360. if ((m_nActiveDlg >= 0) && (m_nActiveDlg < MAX_PAGES))
  361. {
  362. pActiveDlg = m_Pages[m_nActiveDlg];
  363. if (pActiveDlg) pActiveDlg->ShowWindow(SW_HIDE);
  364. }
  365. m_TabCtrl.DeleteAllItems();
  366. if (mask & 1) m_TabCtrl.InsertItem(count++, _T("General"), IDD_CONTROL_GLOBALS, IMAGE_GENERAL);
  367. if (mask & 2) m_TabCtrl.InsertItem(count++, _T("Patterns"), IDD_CONTROL_PATTERNS, IMAGE_PATTERNS);
  368. if (mask & 4) m_TabCtrl.InsertItem(count++, _T("Samples"), IDD_CONTROL_SAMPLES, IMAGE_SAMPLES);
  369. if (mask & 8) m_TabCtrl.InsertItem(count++, _T("Instruments"), IDD_CONTROL_INSTRUMENTS, IMAGE_INSTRUMENTS);
  370. //if (mask & 32) m_TabCtrl.InsertItem(count++, _T("Graph"), IDD_CONTROL_GRAPH, IMAGE_GRAPH); //rewbs.graph
  371. if (mask & 16) m_TabCtrl.InsertItem(count++, _T("Comments"), IDD_CONTROL_COMMENTS, IMAGE_COMMENTS);
  372. }
  373. }
  374. // Update child dialogs
  375. for (UINT nIndex=0; nIndex<MAX_PAGES; nIndex++)
  376. {
  377. CModControlDlg *pDlg = m_Pages[nIndex];
  378. if ((pDlg) && (pObject != pDlg)) pDlg->UpdateView(UpdateHint(lHint), pObject);
  379. }
  380. // Restore the displayed child dialog
  381. if (pActiveDlg) pActiveDlg->ShowWindow(SW_SHOW);
  382. }
  383. void CModControlView::OnTabSelchange(NMHDR*, LRESULT* pResult)
  384. {
  385. SetActivePage(m_TabCtrl.GetCurSel());
  386. if (pResult) *pResult = 0;
  387. }
  388. LRESULT CModControlView::OnActivateModView(WPARAM nIndex, LPARAM lParam)
  389. {
  390. if(::GetActiveWindow() != CMainFrame::GetMainFrame()->m_hWnd)
  391. {
  392. // If we are in a dialog (e.g. Amplify Sample), do not allow to switch to a different tab. Otherwise, watch the tracker crash!
  393. return 0;
  394. }
  395. if (m_TabCtrl.m_hWnd)
  396. {
  397. if (nIndex < 100)
  398. {
  399. m_TabCtrl.SetCurSel(static_cast<int>(nIndex));
  400. SetActivePage(static_cast<int>(nIndex), lParam);
  401. } else
  402. // Might be a dialog id IDD_XXXX
  403. {
  404. int nItems = m_TabCtrl.GetItemCount();
  405. for (int i=0; i<nItems; i++)
  406. {
  407. if ((WPARAM)m_TabCtrl.GetItemData(i) == nIndex)
  408. {
  409. m_TabCtrl.SetCurSel(i);
  410. SetActivePage(i, lParam);
  411. break;
  412. }
  413. }
  414. }
  415. }
  416. return 0;
  417. }
  418. LRESULT CModControlView::OnModCtrlMsg(WPARAM wParam, LPARAM lParam)
  419. {
  420. if ((m_nActiveDlg >= 0) && (m_nActiveDlg < MAX_PAGES))
  421. {
  422. CModControlDlg *pActiveDlg = m_Pages[m_nActiveDlg];
  423. if (pActiveDlg)
  424. {
  425. switch(wParam)
  426. {
  427. case CTRLMSG_SETVIEWWND:
  428. {
  429. m_hWndView = (HWND)lParam;
  430. for (UINT i=0; i<MAX_PAGES; i++)
  431. {
  432. if (m_Pages[i]) m_Pages[i]->SetViewWnd(m_hWndView);
  433. }
  434. }
  435. break;
  436. }
  437. return pActiveDlg->OnModCtrlMsg(wParam, lParam);
  438. }
  439. }
  440. return 0;
  441. }
  442. LRESULT CModControlView::OnGetToolTipText(WPARAM uId, LPARAM pszText)
  443. {
  444. if ((m_nActiveDlg >= 0) && (m_nActiveDlg < MAX_PAGES))
  445. {
  446. CModControlDlg *pActiveDlg = m_Pages[m_nActiveDlg];
  447. if (pActiveDlg) return (LRESULT)pActiveDlg->GetToolTipText(static_cast<UINT>(uId), (LPTSTR)pszText);
  448. }
  449. return 0;
  450. }
  451. void CModControlView::SampleChanged(SAMPLEINDEX smp)
  452. {
  453. const CModDoc *modDoc = GetDocument();
  454. if(modDoc && modDoc->GetNumInstruments())
  455. {
  456. INSTRUMENTINDEX k = static_cast<INSTRUMENTINDEX>(GetInstrumentChange());
  457. if(!modDoc->IsChildSample(k, smp))
  458. {
  459. INSTRUMENTINDEX nins = modDoc->FindSampleParent(smp);
  460. if(nins != INSTRUMENTINDEX_INVALID)
  461. {
  462. InstrumentChanged(nins);
  463. }
  464. }
  465. } else
  466. {
  467. InstrumentChanged(smp);
  468. }
  469. }
  470. //////////////////////////////////////////////////////////////////
  471. // CModScrollView
  472. #ifndef WM_MOUSEHWHEEL
  473. #define WM_MOUSEHWHEEL 0x20E // Only available on Vista and newer
  474. #endif
  475. IMPLEMENT_SERIAL(CModScrollView, CScrollView, 0)
  476. BEGIN_MESSAGE_MAP(CModScrollView, CScrollView)
  477. //{{AFX_MSG_MAP(CModScrollView)
  478. ON_WM_DESTROY()
  479. ON_WM_MOUSEWHEEL()
  480. ON_WM_MOUSEHWHEEL()
  481. #if !defined(MPT_BUILD_RETRO)
  482. ON_MESSAGE(WM_DPICHANGED, &CModScrollView::OnDPIChanged)
  483. #endif
  484. ON_MESSAGE(WM_MOD_VIEWMSG, &CModScrollView::OnReceiveModViewMsg)
  485. ON_MESSAGE(WM_MOD_DRAGONDROPPING, &CModScrollView::OnDragonDropping)
  486. ON_MESSAGE(WM_MOD_UPDATEPOSITION, &CModScrollView::OnUpdatePosition)
  487. //}}AFX_MSG_MAP
  488. END_MESSAGE_MAP()
  489. LRESULT CModScrollView::SendCtrlMessage(UINT uMsg, LPARAM lParam) const
  490. {
  491. if (m_hWndCtrl) return ::SendMessage(m_hWndCtrl, WM_MOD_CTRLMSG, uMsg, lParam);
  492. return 0;
  493. }
  494. void CModScrollView::SendCtrlCommand(int id) const
  495. {
  496. ::SendMessage(m_hWndCtrl, WM_COMMAND, id, 0);
  497. }
  498. BOOL CModScrollView::PostCtrlMessage(UINT uMsg, LPARAM lParam) const
  499. {
  500. if (m_hWndCtrl) return ::PostMessage(m_hWndCtrl, WM_MOD_CTRLMSG, uMsg, lParam);
  501. return FALSE;
  502. }
  503. LRESULT CModScrollView::OnReceiveModViewMsg(WPARAM wParam, LPARAM lParam)
  504. {
  505. return OnModViewMsg(wParam, lParam);
  506. }
  507. void CModScrollView::OnUpdate(CView* pView, LPARAM lHint, CObject*pHint)
  508. {
  509. if (pView != this) UpdateView(UpdateHint::FromLPARAM(lHint), pHint);
  510. }
  511. LRESULT CModScrollView::OnModViewMsg(WPARAM wParam, LPARAM lParam)
  512. {
  513. switch(wParam)
  514. {
  515. case VIEWMSG_SETCTRLWND:
  516. m_hWndCtrl = (HWND)lParam;
  517. break;
  518. case VIEWMSG_SETFOCUS:
  519. case VIEWMSG_SETACTIVE:
  520. GetParentFrame()->SetActiveView(this);
  521. SetFocus();
  522. break;
  523. }
  524. return 0;
  525. }
  526. void CModScrollView::OnInitialUpdate()
  527. {
  528. CScrollView::OnInitialUpdate();
  529. m_nDPIx = Util::GetDPIx(m_hWnd);
  530. m_nDPIy = Util::GetDPIy(m_hWnd);
  531. }
  532. LRESULT CModScrollView::OnDPIChanged(WPARAM wParam, LPARAM)
  533. {
  534. m_nDPIx = LOWORD(wParam);
  535. m_nDPIy = HIWORD(wParam);
  536. return 0;
  537. }
  538. void CModScrollView::UpdateIndicator(LPCTSTR lpszText)
  539. {
  540. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  541. if (pMainFrm) pMainFrm->SetUserText((lpszText) ? lpszText : _T(""));
  542. }
  543. BOOL CModScrollView::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
  544. {
  545. // we don't handle anything but scrolling just now
  546. if (fFlags & (MK_SHIFT | MK_CONTROL)) return FALSE;
  547. //if the parent is a splitter, it will handle the message
  548. //if (GetParentSplitter(this, TRUE)) return FALSE;
  549. // we can't get out of it--perform the scroll ourselves
  550. return DoMouseWheel(fFlags, zDelta, point);
  551. }
  552. void CModScrollView::OnMouseHWheel(UINT fFlags, short zDelta, CPoint point)
  553. {
  554. // we don't handle anything but scrolling just now
  555. if (fFlags & (MK_SHIFT | MK_CONTROL))
  556. {
  557. CScrollView::OnMouseHWheel(fFlags, zDelta, point);
  558. return;
  559. }
  560. if (OnScrollBy(CSize(zDelta * m_lineDev.cx / WHEEL_DELTA, 0), TRUE))
  561. UpdateWindow();
  562. }
  563. void CModScrollView::OnDestroy()
  564. {
  565. CModDoc *pModDoc = GetDocument();
  566. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  567. if ((pMainFrm) && (pModDoc))
  568. {
  569. if (pMainFrm->GetFollowSong(pModDoc) == m_hWnd)
  570. {
  571. pModDoc->SetNotifications(Notification::Default);
  572. pModDoc->SetFollowWnd(NULL);
  573. }
  574. if (pMainFrm->GetMidiRecordWnd() == m_hWnd)
  575. {
  576. pMainFrm->SetMidiRecordWnd(NULL);
  577. }
  578. }
  579. CScrollView::OnDestroy();
  580. }
  581. LRESULT CModScrollView::OnUpdatePosition(WPARAM, LPARAM lParam)
  582. {
  583. Notification *pnotify = (Notification *)lParam;
  584. if (pnotify) return OnPlayerNotify(pnotify);
  585. return 0;
  586. }
  587. BOOL CModScrollView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
  588. {
  589. SCROLLINFO info;
  590. if(LOBYTE(nScrollCode) == SB_THUMBTRACK)
  591. {
  592. if(GetScrollInfo(SB_HORZ, &info, SIF_TRACKPOS))
  593. nPos = info.nTrackPos;
  594. m_nScrollPosX = nPos;
  595. } else if(HIBYTE(nScrollCode) == SB_THUMBTRACK)
  596. {
  597. if(GetScrollInfo(SB_VERT, &info, SIF_TRACKPOS))
  598. nPos = info.nTrackPos;
  599. m_nScrollPosY = nPos;
  600. }
  601. return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
  602. }
  603. BOOL CModScrollView::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
  604. {
  605. BOOL ret = CScrollView::OnScrollBy(sizeScroll, bDoScroll);
  606. if(ret)
  607. {
  608. SCROLLINFO info;
  609. if(sizeScroll.cx)
  610. {
  611. if(GetScrollInfo(SB_HORZ, &info, SIF_POS))
  612. m_nScrollPosX = info.nPos;
  613. }
  614. if(sizeScroll.cy)
  615. {
  616. if(GetScrollInfo(SB_VERT, &info, SIF_POS))
  617. m_nScrollPosY = info.nPos;
  618. }
  619. }
  620. return ret;
  621. }
  622. int CModScrollView::SetScrollPos(int nBar, int nPos, BOOL bRedraw)
  623. {
  624. if(nBar == SB_HORZ)
  625. m_nScrollPosX = nPos;
  626. else if(nBar == SB_VERT)
  627. m_nScrollPosY = nPos;
  628. return CScrollView::SetScrollPos(nBar, nPos, bRedraw);
  629. }
  630. void CModScrollView::SetScrollSizes(int nMapMode, SIZE sizeTotal, const SIZE& sizePage, const SIZE& sizeLine)
  631. {
  632. CScrollView::SetScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine);
  633. // Fix scroll positions
  634. SCROLLINFO info;
  635. if(GetScrollInfo(SB_HORZ, &info, SIF_POS))
  636. m_nScrollPosX = info.nPos;
  637. if(GetScrollInfo(SB_VERT, &info, SIF_POS))
  638. m_nScrollPosY = info.nPos;
  639. }
  640. BOOL CModScrollView::OnGesturePan(CPoint ptFrom, CPoint ptTo)
  641. {
  642. // On Windows 8 and later, panning with touch gestures does not generate sensible WM_*SCROLL messages.
  643. // OnScrollBy is only ever called with a size of 0/0 in this case.
  644. // WM_GESTURE on the other hand gives us sensible data to work with.
  645. OnScrollBy(ptTo - ptFrom, TRUE);
  646. return TRUE;
  647. }
  648. ////////////////////////////////////////////////////////////////////////////
  649. // CModControlBar
  650. BEGIN_MESSAGE_MAP(CModControlBar, CToolBarCtrl)
  651. ON_MESSAGE(WM_HELPHITTEST, &CModControlBar::OnHelpHitTest)
  652. END_MESSAGE_MAP()
  653. BOOL CModControlBar::Init(CImageList &icons, CImageList &disabledIcons)
  654. {
  655. const int imgSize = Util::ScalePixels(16, m_hWnd), btnSizeX = Util::ScalePixels(26, m_hWnd), btnSizeY = Util::ScalePixels(24, m_hWnd);
  656. SetButtonStructSize(sizeof(TBBUTTON));
  657. SetBitmapSize(CSize(imgSize, imgSize));
  658. SetButtonSize(CSize(btnSizeX, btnSizeY));
  659. // Add bitmaps
  660. SetImageList(&icons);
  661. SetDisabledImageList(&disabledIcons);
  662. UpdateStyle();
  663. return TRUE;
  664. }
  665. BOOL CModControlBar::AddButton(UINT nID, int iImage, UINT nStyle, UINT nState)
  666. {
  667. TBBUTTON btn;
  668. btn.iBitmap = iImage;
  669. btn.idCommand = nID;
  670. btn.fsStyle = (BYTE)nStyle;
  671. btn.fsState = (BYTE)nState;
  672. btn.dwData = 0;
  673. btn.iString = 0;
  674. return AddButtons(1, &btn);
  675. }
  676. void CModControlBar::UpdateStyle()
  677. {
  678. if (m_hWnd)
  679. {
  680. LONG lStyleOld = GetWindowLong(m_hWnd, GWL_STYLE);
  681. if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_FLATBUTTONS)
  682. lStyleOld |= TBSTYLE_FLAT;
  683. else
  684. lStyleOld &= ~TBSTYLE_FLAT;
  685. lStyleOld |= CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER | TBSTYLE_TOOLTIPS;
  686. SetWindowLong(m_hWnd, GWL_STYLE, lStyleOld);
  687. Invalidate();
  688. }
  689. }
  690. LRESULT CModControlBar::OnHelpHitTest(WPARAM, LPARAM lParam)
  691. {
  692. TBBUTTON tbbn;
  693. POINT point;
  694. point.x = GET_X_LPARAM(lParam);
  695. point.y = GET_Y_LPARAM(lParam);
  696. int ndx = HitTest(&point);
  697. if ((ndx >= 0) && (GetButton(ndx, &tbbn)))
  698. {
  699. return HID_BASE_COMMAND + tbbn.idCommand;
  700. }
  701. return 0;
  702. }
  703. OPENMPT_NAMESPACE_END