| 1 |
// TabDockWnd.cpp : implementation file |
|---|
| 2 |
// |
|---|
| 3 |
|
|---|
| 4 |
#include "stdafx.h" |
|---|
| 5 |
#include "Elephant.h" |
|---|
| 6 |
#include "TabDockWnd.h" |
|---|
| 7 |
|
|---|
| 8 |
#ifdef _DEBUG |
|---|
| 9 |
#define new DEBUG_NEW |
|---|
| 10 |
#undef THIS_FILE |
|---|
| 11 |
static char THIS_FILE[] = __FILE__; |
|---|
| 12 |
#endif |
|---|
| 13 |
|
|---|
| 14 |
///////////////////////////////////////////////////////////////////////////// |
|---|
| 15 |
// CTabDockWnd |
|---|
| 16 |
|
|---|
| 17 |
CTabDockWnd::CTabDockWnd() |
|---|
| 18 |
{ |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
CTabDockWnd::~CTabDockWnd() |
|---|
| 22 |
{ |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
#define IDC_FILE_TREE 0xfff |
|---|
| 26 |
|
|---|
| 27 |
BEGIN_MESSAGE_MAP(CTabDockWnd, CXTTabCtrlBar) |
|---|
| 28 |
//{{AFX_MSG_MAP(CTabDockWnd) |
|---|
| 29 |
ON_WM_CREATE() |
|---|
| 30 |
//}}AFX_MSG_MAP |
|---|
| 31 |
ON_WM_QUERYDRAGICON() |
|---|
| 32 |
ON_NOTIFY(TVN_BEGINDRAG, IDC_FILE_TREE , OnBegindragTree1) |
|---|
| 33 |
ON_WM_MOUSEMOVE() |
|---|
| 34 |
ON_WM_CANCELMODE() |
|---|
| 35 |
ON_WM_LBUTTONUP() |
|---|
| 36 |
END_MESSAGE_MAP() |
|---|
| 37 |
|
|---|
| 38 |
///////////////////////////////////////////////////////////////////////////// |
|---|
| 39 |
// CTabDockWnd message handlers |
|---|
| 40 |
|
|---|
| 41 |
int CTabDockWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) |
|---|
| 42 |
{ |
|---|
| 43 |
if (CXTTabCtrlBar::OnCreate(lpCreateStruct) == -1) |
|---|
| 44 |
return -1; |
|---|
| 45 |
|
|---|
| 46 |
if (!m_wndTreeCtrl.Create( WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS, |
|---|
| 47 |
CRect(0,0,0,0), this, IDC_FILE_TREE )) |
|---|
| 48 |
{ |
|---|
| 49 |
TRACE0( "Unable to create tree control.\n" ); |
|---|
| 50 |
return -1; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
m_wndTreeCtrl.ModifyStyle(TVS_EDITLABELS,0); |
|---|
| 54 |
|
|---|
| 55 |
AddControl( _T( "Files" ), &m_wndTreeCtrl, 0 ); |
|---|
| 56 |
|
|---|
| 57 |
if (!m_imageList.Create(IDB_IMGLIST_TAB, 16, 1, RGB(0x00,0xff,0x00))) |
|---|
| 58 |
{ |
|---|
| 59 |
TRACE0("Failed to create image list.\n"); |
|---|
| 60 |
return -1; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
if ( !m_codeBrowser.Create(IDD_WORKSPACE_CHILD_DLG,this ) ) |
|---|
| 64 |
{ |
|---|
| 65 |
TRACE0("Failed to create Code Browesr.\n"); |
|---|
| 66 |
return -1; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
AddControl( _T( "Source Browser" ), &m_codeBrowser, 1 ); |
|---|
| 71 |
|
|---|
| 72 |
if ( !m_fileHistory.Create(IDD_FILEHISTORY_DLG,this ) ) |
|---|
| 73 |
{ |
|---|
| 74 |
TRACE0("Failed to create Code Browesr.\n"); |
|---|
| 75 |
return -1; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
AddControl( _T( "File History" ), &m_fileHistory, 2 ); |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
if ( !m_logTab.Create(IDD_LOG_DLG , this ) ) |
|---|
| 83 |
{ |
|---|
| 84 |
|
|---|
| 85 |
TRACE0("Failed to create log tab .\n"); |
|---|
| 86 |
return -1; |
|---|
| 87 |
|
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
AddControl( _T( "Log" ), &m_logTab, 3,2); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
SetTabImageList(&m_imageList); |
|---|
| 94 |
|
|---|
| 95 |
SetActiveView(0); |
|---|
| 96 |
|
|---|
| 97 |
return 0; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
HCURSOR CTabDockWnd::OnQueryDragIcon() |
|---|
| 102 |
{ |
|---|
| 103 |
return (HCURSOR) m_hIcon; |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
void CTabDockWnd::OnBegindragTree1(NMHDR* pNMHDR, LRESULT* pResult) |
|---|
| 107 |
{ |
|---|
| 108 |
// HTREEITEM hCurSel = m_wndTreeCtrl.GetNextItem(TVI_ROOT, TVGN_CARET); |
|---|
| 109 |
// if ( !m_wndTreeCtrl.IsNotFolder(hCurSel ) ) return ; |
|---|
| 110 |
|
|---|
| 111 |
LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)pNMHDR; |
|---|
| 112 |
*pResult = 0; // allow drag |
|---|
| 113 |
|
|---|
| 114 |
CImageList* piml = NULL; /* handle of image list */ |
|---|
| 115 |
POINT ptOffset; |
|---|
| 116 |
RECT rcItem; |
|---|
| 117 |
|
|---|
| 118 |
if ((piml = m_wndTreeCtrl.CreateDragImage(lpnmtv->itemNew.hItem)) == NULL) |
|---|
| 119 |
return; |
|---|
| 120 |
|
|---|
| 121 |
/* get the bounding rectangle of the item being dragged (rel to top-left of control) */ |
|---|
| 122 |
if (m_wndTreeCtrl.GetItemRect(lpnmtv->itemNew.hItem, &rcItem, TRUE)) |
|---|
| 123 |
{ |
|---|
| 124 |
CPoint ptDragBegin; |
|---|
| 125 |
int nX, nY; |
|---|
| 126 |
/* get offset into image that the mouse is at */ |
|---|
| 127 |
/* item rect doesn't include the image */ |
|---|
| 128 |
ptDragBegin = lpnmtv->ptDrag; |
|---|
| 129 |
ImageList_GetIconSize(piml->GetSafeHandle(), &nX, &nY); |
|---|
| 130 |
ptOffset.x = (ptDragBegin.x - rcItem.left) + (nX - (rcItem.right - rcItem.left)); |
|---|
| 131 |
ptOffset.y = (ptDragBegin.y - rcItem.top) + (nY - (rcItem.bottom - rcItem.top)); |
|---|
| 132 |
/* convert the item rect to screen co-ords, for use later */ |
|---|
| 133 |
MapWindowPoints(NULL, &rcItem); |
|---|
| 134 |
} |
|---|
| 135 |
else |
|---|
| 136 |
{ |
|---|
| 137 |
GetWindowRect(&rcItem); |
|---|
| 138 |
ptOffset.x = ptOffset.y = 8; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
BOOL bDragBegun = piml->BeginDrag(0, ptOffset); |
|---|
| 142 |
if (! bDragBegun) |
|---|
| 143 |
{ |
|---|
| 144 |
delete piml; |
|---|
| 145 |
return; |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
CPoint ptDragEnter = lpnmtv->ptDrag; |
|---|
| 149 |
ClientToScreen(&ptDragEnter); |
|---|
| 150 |
if (!piml->DragEnter(NULL, ptDragEnter)) |
|---|
| 151 |
{ |
|---|
| 152 |
delete piml; |
|---|
| 153 |
return; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
delete piml; |
|---|
| 157 |
|
|---|
| 158 |
/* set the focus here, so we get a WM_CANCELMODE if needed */ |
|---|
| 159 |
SetFocus(); |
|---|
| 160 |
|
|---|
| 161 |
/* redraw item being dragged, otherwise it remains (looking) selected */ |
|---|
| 162 |
InvalidateRect(&rcItem, TRUE); |
|---|
| 163 |
UpdateWindow(); |
|---|
| 164 |
|
|---|
| 165 |
/* Hide the mouse cursor, and direct mouse input to this window */ |
|---|
| 166 |
SetCapture(); |
|---|
| 167 |
m_hItemDrag = lpnmtv->itemNew.hItem; |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
void CTabDockWnd::OnMouseMove(UINT nFlags, CPoint point) |
|---|
| 171 |
{ |
|---|
| 172 |
if (m_hItemDrag != NULL) |
|---|
| 173 |
{ |
|---|
| 174 |
CPoint pt; |
|---|
| 175 |
|
|---|
| 176 |
/* drag the item to the current position */ |
|---|
| 177 |
pt = point; |
|---|
| 178 |
ClientToScreen(&pt); |
|---|
| 179 |
|
|---|
| 180 |
CImageList::DragMove(pt); |
|---|
| 181 |
CImageList::DragShowNolock(FALSE); |
|---|
| 182 |
|
|---|
| 183 |
if (CWnd::WindowFromPoint(pt) != &m_wndTreeCtrl) |
|---|
| 184 |
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_NO)); |
|---|
| 185 |
else |
|---|
| 186 |
{ |
|---|
| 187 |
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); |
|---|
| 188 |
TVHITTESTINFO tvhti; |
|---|
| 189 |
tvhti.pt = pt; |
|---|
| 190 |
m_wndTreeCtrl.ScreenToClient(&tvhti.pt); |
|---|
| 191 |
HTREEITEM hItemSel = m_wndTreeCtrl.HitTest(&tvhti); |
|---|
| 192 |
m_wndTreeCtrl.SelectDropTarget(tvhti.hItem); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
CImageList::DragShowNolock(TRUE); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
CWnd::OnMouseMove(nFlags, point); |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
void CTabDockWnd::OnCancelMode() |
|---|
| 202 |
{ |
|---|
| 203 |
/* stop dragging */ |
|---|
| 204 |
FinishDragging(TRUE); |
|---|
| 205 |
// redraw |
|---|
| 206 |
RedrawWindow(); |
|---|
| 207 |
|
|---|
| 208 |
CWnd::OnCancelMode(); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
void CTabDockWnd::OnLButtonUp(UINT nFlags, CPoint point) |
|---|
| 212 |
{ |
|---|
| 213 |
if (m_hItemDrag != NULL) |
|---|
| 214 |
OnEndDrag(nFlags, point); |
|---|
| 215 |
else |
|---|
| 216 |
CWnd::OnLButtonUp(nFlags, point); |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
void CTabDockWnd::FinishDragging(BOOL bDraggingImageList) |
|---|
| 220 |
{ |
|---|
| 221 |
if (m_hItemDrag != NULL) |
|---|
| 222 |
{ |
|---|
| 223 |
if (bDraggingImageList) |
|---|
| 224 |
{ |
|---|
| 225 |
CImageList::DragLeave(NULL); |
|---|
| 226 |
CImageList::EndDrag(); |
|---|
| 227 |
} |
|---|
| 228 |
ReleaseCapture(); |
|---|
| 229 |
ShowCursor(TRUE); |
|---|
| 230 |
m_hItemDrag = NULL; |
|---|
| 231 |
m_wndTreeCtrl.SelectDropTarget(NULL); |
|---|
| 232 |
} |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
void CTabDockWnd::OnEndDrag(UINT nFlags, CPoint point) |
|---|
| 236 |
{ |
|---|
| 237 |
try |
|---|
| 238 |
{ |
|---|
| 239 |
|
|---|
| 240 |
string file = "" , dir = ""; |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
if (m_hItemDrag == NULL) |
|---|
| 247 |
return; |
|---|
| 248 |
|
|---|
| 249 |
if ( m_wndTreeCtrl.IsFolder(m_hItemDrag)) { |
|---|
| 250 |
|
|---|
| 251 |
FinishDragging(TRUE); |
|---|
| 252 |
return; |
|---|
| 253 |
} |
|---|
| 254 |
|
|---|
| 255 |
CPoint pt; |
|---|
| 256 |
|
|---|
| 257 |
pt = point; |
|---|
| 258 |
ClientToScreen(&pt); |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
// do drop |
|---|
| 262 |
HTREEITEM hItemDrop = m_wndTreeCtrl.GetDropHilightItem(); |
|---|
| 263 |
if (! m_wndTreeCtrl.IsFolder(hItemDrop) ) { |
|---|
| 264 |
HTREEITEM parent = m_wndTreeCtrl.GetParentItem(hItemDrop); |
|---|
| 265 |
if ( ! m_wndTreeCtrl.IsFolder(parent ) ) return; |
|---|
| 266 |
else hItemDrop = parent; |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
if (hItemDrop == NULL || m_hItemDrag == NULL ) { |
|---|
| 272 |
return; |
|---|
| 273 |
} |
|---|
| 274 |
else { |
|---|
| 275 |
file = m_wndTreeCtrl.GetItemText(m_hItemDrag ); |
|---|
| 276 |
dir = m_wndTreeCtrl.GetItemText(hItemDrop ); |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
if ( !Globals::currentProject ) return; |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
m_wndTreeCtrl.SelectDropTarget(NULL); |
|---|
| 283 |
MoveTreeItem(m_wndTreeCtrl, m_hItemDrag, hItemDrop , false , CopyData); |
|---|
| 284 |
|
|---|
| 285 |
FinishDragging(TRUE); |
|---|
| 286 |
|
|---|
| 287 |
RedrawWindow(); |
|---|
| 288 |
//ElephantMessageBox(file.c_str()); |
|---|
| 289 |
|
|---|
| 290 |
Globals::currentProject->ChangeFolderForFile(Globals::currentProject->PathForFile(file),dir); |
|---|
| 291 |
//globals.currentProject->ChangeDirForFile(globals.currentProject->GetPathFromFile(file) ,dir); |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|
| 294 |
catch ( ... ) // keep this fucker from crashing |
|---|
| 295 |
{ |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
} |
|---|