TabsDlg.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "QE3.H"
  23. #include "TabsDlg.h"
  24. // CTabsDlg dialog
  25. //IMPLEMENT_DYNAMIC ( CTabsDlg , CDialog )
  26. CTabsDlg::CTabsDlg(UINT ID , CWnd* pParent /*=NULL*/)
  27. : CDialog(ID, pParent)
  28. {
  29. m_DragTabActive = false;
  30. }
  31. BEGIN_MESSAGE_MAP(CTabsDlg, CDialog)
  32. //}}AFX_MSG_MAP
  33. // ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTcnSelchangeTab1)
  34. ON_WM_LBUTTONDOWN()
  35. ON_WM_LBUTTONUP()
  36. ON_WM_MOUSEMOVE()
  37. ON_WM_DESTROY()
  38. END_MESSAGE_MAP()
  39. void CTabsDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. DDX_Control(pDX, IDC_TAB_INSPECTOR, m_Tabs);
  43. }
  44. // CTabsDlg message handlers
  45. BOOL CTabsDlg::OnInitDialog()
  46. {
  47. CDialog::OnInitDialog();
  48. return TRUE; // return TRUE unless you set the focus to a control
  49. }
  50. void CTabsDlg::OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult)
  51. {
  52. int ID = TabCtrl_GetCurSel ( pNMHDR->hwndFrom );
  53. if ( ID >= 0 )
  54. {
  55. TCITEM item;
  56. item.mask = TCIF_PARAM;
  57. ShowAllWindows ( FALSE );
  58. TabCtrl_GetItem (m_Tabs.GetSafeHwnd() , ID , &item);
  59. DockedWindowInfo* info = (DockedWindowInfo*)item.lParam;
  60. ASSERT ( info );
  61. info->m_TabControlIndex = ID;
  62. info->m_Window->ShowWindow(TRUE);
  63. }
  64. }
  65. void CTabsDlg::DockWindow ( int ID , bool dock )
  66. {
  67. DockedWindowInfo* info = NULL;
  68. m_Windows.Lookup ( (WORD)ID , (void*&)info );
  69. ASSERT ( info );
  70. ASSERT ( m_Tabs.GetSafeHwnd() );
  71. ShowAllWindows ( FALSE );
  72. if ( !dock )
  73. {
  74. //make a containing window and assign the dialog to it
  75. CRect rect;
  76. CString classname = AfxRegisterWndClass ( CS_DBLCLKS , 0 , 0 , 0 );
  77. info->m_State = DockedWindowInfo::FLOATING;
  78. info->m_Window->GetWindowRect(rect);
  79. info->m_Container.CreateEx ( WS_EX_TOOLWINDOW , classname , info->m_Title , WS_THICKFRAME | WS_SYSMENU | WS_POPUP | WS_CAPTION, rect , this , 0 );
  80. info->m_Window->SetParent ( &info->m_Container );
  81. info->m_Window->ShowWindow(TRUE);
  82. info->m_Container.SetDockManager(this);
  83. info->m_Container.ShowWindow(TRUE);
  84. info->m_Container.SetDialog ( info->m_Window , info->m_ID );
  85. if (info->m_TabControlIndex >= 0 )
  86. {
  87. m_Tabs.DeleteItem( info->m_TabControlIndex );
  88. }
  89. if ( m_Tabs.GetItemCount() > 0 )
  90. {
  91. m_Tabs.SetCurFocus( 0 );
  92. }
  93. CString placementName = info->m_Title + "Placement";
  94. LoadWindowPlacement(info->m_Container , placementName);
  95. }
  96. else
  97. {
  98. info->m_State = DockedWindowInfo::DOCKED;
  99. info->m_TabControlIndex = m_Tabs.InsertItem( TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM , 0 , info->m_Title , info->m_ImageID , (LPARAM)info);
  100. info->m_Window->SetParent ( this );
  101. info->m_Window->ShowWindow (TRUE);
  102. info->m_Container.SetDockManager( NULL ); //so it doesn't try to call back and redock this window
  103. info->m_Container.DestroyWindow ();
  104. CRect rect;
  105. GetWindowRect ( rect );
  106. //stupid hack to get the window reitself properly
  107. rect.DeflateRect(0,0,0,1);
  108. MoveWindow(rect);
  109. rect.InflateRect(0,0,0,1);
  110. MoveWindow(rect);
  111. }
  112. UpdateTabControlIndices ();
  113. FocusWindow ( ID );
  114. if ( info->m_DockCallback )
  115. {
  116. info->m_DockCallback ( dock , info->m_ID , info->m_Window );
  117. }
  118. SaveWindowPlacement ();
  119. }
  120. int CTabsDlg::PreTranslateMessage ( MSG* msg )
  121. {
  122. if ( msg->message == WM_LBUTTONDBLCLK && msg->hwnd == m_Tabs.GetSafeHwnd() )
  123. {
  124. HandleUndock ();
  125. return TRUE;
  126. }
  127. //steal lbutton clicks for the main dialog too, but let the tabs do their default thing as well
  128. if ( msg->message == WM_LBUTTONDOWN && msg->hwnd == m_Tabs.GetSafeHwnd()) {
  129. m_Tabs.SendMessage ( msg->message , msg->wParam , msg->lParam );
  130. m_DragTabActive = true;
  131. }
  132. else if ( msg->message == WM_LBUTTONUP && msg->hwnd == m_Tabs.GetSafeHwnd()) {
  133. m_Tabs.SendMessage ( msg->message , msg->wParam , msg->lParam );
  134. m_DragTabActive = false;
  135. }
  136. return CDialog::PreTranslateMessage(msg);
  137. }
  138. bool CTabsDlg::RectWithinDockManager ( CRect& rect )
  139. {
  140. CRect tabsRect,intersectionRect;
  141. m_Tabs.GetWindowRect ( tabsRect );
  142. intersectionRect.IntersectRect( tabsRect , rect );
  143. return !(intersectionRect.IsRectEmpty());
  144. }
  145. void CTabsDlg::OnLButtonDown(UINT nFlags, CPoint point)
  146. {
  147. CDialog::OnLButtonDown(nFlags, point);
  148. }
  149. void CTabsDlg::OnLButtonUp(UINT nFlags, CPoint point)
  150. {
  151. if ( m_DragTabActive && ((abs ( point.x - m_DragDownPoint.x ) > 50) || (abs ( point.y - m_DragDownPoint.y ) > 50)))
  152. {
  153. HandleUndock();
  154. m_DragTabActive = false;
  155. }
  156. CDialog::OnLButtonUp(nFlags, point);
  157. }
  158. void CTabsDlg::HandleUndock ()
  159. {
  160. TCITEM item;
  161. item.mask = TCIF_PARAM;
  162. int curSel = TabCtrl_GetCurSel ( m_Tabs.GetSafeHwnd());
  163. TabCtrl_GetItem (m_Tabs.GetSafeHwnd() , curSel , &item);
  164. DockedWindowInfo* info = (DockedWindowInfo*)item.lParam;
  165. ASSERT ( info );
  166. DockWindow ( info->m_ID , false );
  167. }
  168. void CTabsDlg::OnMouseMove(UINT nFlags, CPoint point)
  169. {
  170. CDialog::OnMouseMove(nFlags, point);
  171. }
  172. void CTabsDlg::AddDockedWindow ( CWnd* wnd , int ID , int imageID , const CString& title , bool dock , pfnOnDockEvent dockCallback )
  173. {
  174. DockedWindowInfo* info = NULL;
  175. m_Windows.Lookup( (WORD)ID , (void*&)info);
  176. ASSERT ( wnd );
  177. ASSERT ( info == NULL );
  178. info = new DockedWindowInfo ( wnd , ID , imageID , title , dockCallback);
  179. m_Windows.SetAt ( (WORD)ID , info );
  180. DockWindow ( ID , dock );
  181. UpdateTabControlIndices ();
  182. }
  183. void CTabsDlg::ShowAllWindows ( bool show )
  184. {
  185. POSITION pos;
  186. WORD ID;
  187. DockedWindowInfo* info = NULL;
  188. for( pos = m_Windows.GetStartPosition(); pos != NULL ; )
  189. {
  190. m_Windows.GetNextAssoc( pos, ID, (void*&)info );
  191. ASSERT ( info->m_Window );
  192. if ( info->m_State == DockedWindowInfo::DOCKED )
  193. {
  194. info->m_Window->ShowWindow( show );
  195. }
  196. }
  197. }
  198. void CTabsDlg::FocusWindow ( int ID )
  199. {
  200. DockedWindowInfo* info = NULL;
  201. m_Windows.Lookup( (WORD)ID , (void*&)info);
  202. ASSERT ( info );
  203. ASSERT ( info->m_Window );
  204. if ( info->m_State == DockedWindowInfo::DOCKED )
  205. {
  206. TabCtrl_SetCurFocus ( m_Tabs.GetSafeHwnd() , info->m_TabControlIndex );
  207. }
  208. else
  209. {
  210. info->m_Container.SetFocus();
  211. }
  212. }
  213. void CTabsDlg::UpdateTabControlIndices ()
  214. {
  215. TCITEM item;
  216. item.mask = TCIF_PARAM;
  217. DockedWindowInfo* info = NULL;
  218. int itemCount = m_Tabs.GetItemCount();
  219. for ( int i = 0 ; i < itemCount ; i ++ )
  220. {
  221. if ( !m_Tabs.GetItem( i , &item ) )
  222. {
  223. Sys_Error ( "UpdateTabControlIndices(): GetItem failed!\n" );
  224. }
  225. info = (DockedWindowInfo*)item.lParam;
  226. info->m_TabControlIndex = i;
  227. }
  228. }
  229. void CTabsDlg::OnDestroy()
  230. {
  231. TCITEM item;
  232. item.mask = TCIF_PARAM;
  233. DockedWindowInfo* info = NULL;
  234. for ( int i = 0 ; i < m_Tabs.GetItemCount() ; i ++ )
  235. {
  236. m_Tabs.GetItem( i , &item );
  237. info = (DockedWindowInfo*)item.lParam;
  238. ASSERT( info );
  239. delete info;
  240. }
  241. CDialog::OnDestroy();
  242. }
  243. bool CTabsDlg::IsDocked ( CWnd* wnd )
  244. {
  245. bool docked = false;
  246. DockedWindowInfo* info = NULL;
  247. CString placementName;
  248. POSITION pos;
  249. WORD wID;
  250. for( pos = m_Windows.GetStartPosition(); pos != NULL ; )
  251. {
  252. m_Windows.GetNextAssoc( pos, wID, (void*&)info );
  253. if ( info->m_Window == wnd ) {
  254. docked = (info->m_State == DockedWindowInfo::DOCKED);
  255. break;
  256. }
  257. }
  258. return docked;
  259. }
  260. void CTabsDlg::SaveWindowPlacement( int ID )
  261. {
  262. DockedWindowInfo* info = NULL;
  263. CString placementName;
  264. POSITION pos;
  265. WORD wID = ID;
  266. for( pos = m_Windows.GetStartPosition(); pos != NULL ; )
  267. {
  268. m_Windows.GetNextAssoc( pos, wID, (void*&)info );
  269. if ( (info->m_State == DockedWindowInfo::FLOATING) && ((ID == -1) || (ID == info->m_ID))) {
  270. placementName = info->m_Title + "Placement";
  271. ::SaveWindowPlacement(info->m_Container.GetSafeHwnd() , placementName);
  272. }
  273. }
  274. }