2012-04-15 16:54:38 +00:00
|
|
|
// This file is part of Notepad++ project
|
|
|
|
// Copyright (C)2003 Don HO <don.h@free.fr>
|
2009-04-24 23:34:47 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
2009-04-24 23:34:47 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// Note that the GPL places important restrictions on "derived works", yet
|
2015-08-04 11:36:22 +00:00
|
|
|
// it does not provide a detailed definition of that term. To avoid
|
|
|
|
// misunderstandings, we consider an application to constitute a
|
2012-04-15 16:54:38 +00:00
|
|
|
// "derivative work" for the purpose of this license if it does any of the
|
2015-08-04 11:36:22 +00:00
|
|
|
// following:
|
2012-04-15 16:54:38 +00:00
|
|
|
// 1. Integrates source code from Notepad++.
|
|
|
|
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
|
|
|
|
// installer, such as those produced by InstallShield.
|
|
|
|
// 3. Links to a library or executes a program that does any of the above.
|
2009-04-24 23:34:47 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2009-04-24 23:34:47 +00:00
|
|
|
|
2015-06-02 16:01:47 +00:00
|
|
|
|
2009-04-24 23:34:47 +00:00
|
|
|
#include "DocTabView.h"
|
2009-09-04 00:10:01 +00:00
|
|
|
#include "ScintillaEditView.h"
|
2009-04-24 23:34:47 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32_IE
|
|
|
|
#define _WIN32_IE 0x0600
|
|
|
|
#endif //_WIN32_IE
|
|
|
|
|
|
|
|
|
|
|
|
bool DocTabView::_hideTabBarStatus = false;
|
|
|
|
|
2014-04-06 22:22:54 +00:00
|
|
|
void DocTabView::addBuffer(BufferID buffer)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
if (buffer == BUFFER_INVALID) //valid only
|
|
|
|
return;
|
|
|
|
if (this->getIndexByBuffer(buffer) != -1) //no duplicates
|
|
|
|
return;
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(buffer);
|
2015-08-04 11:36:22 +00:00
|
|
|
TCITEM tie;
|
2009-04-24 23:34:47 +00:00
|
|
|
tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM;
|
|
|
|
|
|
|
|
int index = -1;
|
|
|
|
if (_hasImgLst)
|
|
|
|
index = 0;
|
2015-08-04 11:36:22 +00:00
|
|
|
tie.iImage = index;
|
2016-08-09 22:22:45 +00:00
|
|
|
tie.pszText = const_cast<TCHAR *>(buf->getFileName());
|
|
|
|
tie.lParam = reinterpret_cast<LPARAM>(buffer);
|
2009-04-24 23:34:47 +00:00
|
|
|
::SendMessage(_hSelf, TCM_INSERTITEM, _nbItem++, reinterpret_cast<LPARAM>(&tie));
|
|
|
|
bufferUpdated(buf, BufferChangeMask);
|
|
|
|
|
|
|
|
::SendMessage(_hParent, WM_SIZE, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
|
|
|
void DocTabView::closeBuffer(BufferID buffer)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
int indexToClose = getIndexByBuffer(buffer);
|
2009-07-04 11:33:17 +00:00
|
|
|
deletItemAt((size_t)indexToClose);
|
2009-04-24 23:34:47 +00:00
|
|
|
::SendMessage(_hParent, WM_SIZE, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
|
|
|
bool DocTabView::activateBuffer(BufferID buffer)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
int indexToActivate = getIndexByBuffer(buffer);
|
|
|
|
if (indexToActivate == -1)
|
|
|
|
return false; //cannot activate
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2009-04-24 23:34:47 +00:00
|
|
|
activateAt(indexToActivate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
|
|
|
BufferID DocTabView::activeBuffer()
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
int index = getCurrentTabIndex();
|
2016-07-10 00:21:15 +00:00
|
|
|
return static_cast<BufferID>(getBufferByIndex(index));
|
2009-04-24 23:34:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
|
|
|
BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) //-1 if not found, something else otherwise
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
TCITEM tie;
|
|
|
|
tie.lParam = -1;
|
|
|
|
tie.mask = TCIF_PARAM;
|
2013-07-08 00:12:50 +00:00
|
|
|
for(size_t i = 0; i < _nbItem; ++i)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tie));
|
2016-07-10 00:21:15 +00:00
|
|
|
BufferID id = reinterpret_cast<BufferID>(tie.lParam);
|
2009-04-24 23:34:47 +00:00
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
2013-07-08 00:12:50 +00:00
|
|
|
if (!lstrcmp(fullfilename, buf->getFullPathName()))
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BUFFER_INVALID;
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
|
|
|
int DocTabView::getIndexByBuffer(BufferID id)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
TCITEM tie;
|
|
|
|
tie.lParam = -1;
|
|
|
|
tie.mask = TCIF_PARAM;
|
2016-07-23 09:37:58 +00:00
|
|
|
for(size_t i = 0; i < _nbItem; ++i)
|
2013-07-08 00:12:50 +00:00
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tie));
|
2016-07-10 00:21:15 +00:00
|
|
|
if (reinterpret_cast<BufferID>(tie.lParam) == id)
|
2016-07-23 09:37:58 +00:00
|
|
|
return static_cast<int>(i);
|
2009-04-24 23:34:47 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2016-06-05 18:29:21 +00:00
|
|
|
BufferID DocTabView::getBufferByIndex(size_t index)
|
2015-08-04 11:36:22 +00:00
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
TCITEM tie;
|
|
|
|
tie.lParam = -1;
|
|
|
|
tie.mask = TCIF_PARAM;
|
|
|
|
::SendMessage(_hSelf, TCM_GETITEM, index, reinterpret_cast<LPARAM>(&tie));
|
|
|
|
|
2016-07-10 00:21:15 +00:00
|
|
|
return reinterpret_cast<BufferID>(tie.lParam);
|
2009-04-24 23:34:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2014-04-06 22:22:54 +00:00
|
|
|
void DocTabView::bufferUpdated(Buffer * buffer, int mask)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
int index = getIndexByBuffer(buffer->getID());
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TCITEM tie;
|
|
|
|
tie.lParam = -1;
|
|
|
|
tie.mask = 0;
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2014-04-06 22:22:54 +00:00
|
|
|
if (mask & BufferChangeReadonly || mask & BufferChangeDirty)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
tie.mask |= TCIF_IMAGE;
|
|
|
|
tie.iImage = buffer->isDirty()?UNSAVED_IMG_INDEX:SAVED_IMG_INDEX;
|
2016-04-24 03:29:05 +00:00
|
|
|
if (buffer->isMonitoringOn())
|
|
|
|
{
|
|
|
|
tie.iImage = MONITORING_IMG_INDEX;
|
|
|
|
}
|
|
|
|
else if (buffer->isReadOnly())
|
2014-04-06 22:22:54 +00:00
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
tie.iImage = REDONLY_IMG_INDEX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-28 13:17:37 +00:00
|
|
|
//We must make space for the added ampersand characters.
|
|
|
|
TCHAR encodedLabel[2 * MAX_PATH];
|
|
|
|
|
2014-04-06 22:22:54 +00:00
|
|
|
if (mask & BufferChangeFilename)
|
|
|
|
{
|
2009-04-24 23:34:47 +00:00
|
|
|
tie.mask |= TCIF_TEXT;
|
2016-08-09 22:22:45 +00:00
|
|
|
tie.pszText = const_cast<TCHAR *>(encodedLabel);
|
2015-02-28 13:17:37 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const TCHAR* in = buffer->getFileName();
|
|
|
|
TCHAR* out = encodedLabel;
|
|
|
|
|
|
|
|
//This code will read in one character at a time and duplicate every first ampersand(&).
|
|
|
|
//ex. If input is "test & test && test &&&" then output will be "test && test &&& test &&&&".
|
|
|
|
//Tab's caption must be encoded like this because otherwise tab control would make tab too small or too big for the text.
|
|
|
|
|
|
|
|
while (*in != 0)
|
|
|
|
if (*in == '&')
|
|
|
|
{
|
|
|
|
*out++ = '&';
|
|
|
|
*out++ = '&';
|
|
|
|
while (*(++in) == '&')
|
|
|
|
*out++ = '&';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*out++ = *in++;
|
|
|
|
*out = '\0';
|
|
|
|
}
|
2009-04-24 23:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::SendMessage(_hSelf, TCM_SETITEM, index, reinterpret_cast<LPARAM>(&tie));
|
|
|
|
|
2012-07-07 10:15:25 +00:00
|
|
|
// send WM_SIZE only when change tab
|
|
|
|
// It is needed while a tab is closed (so tab changed) in multi-line tab mode
|
|
|
|
if (mask & BufferChangeRecentTag)
|
|
|
|
::SendMessage(_hParent, WM_SIZE, 0, 0);
|
2009-04-24 23:34:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2016-07-23 09:37:58 +00:00
|
|
|
void DocTabView::setBuffer(size_t index, BufferID id)
|
2014-04-06 22:22:54 +00:00
|
|
|
{
|
2016-07-23 09:37:58 +00:00
|
|
|
if (index < 0 || index >= _nbItem)
|
2009-04-24 23:34:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
TCITEM tie;
|
2016-07-23 09:37:58 +00:00
|
|
|
tie.lParam = reinterpret_cast<LPARAM>(id);
|
2009-04-24 23:34:47 +00:00
|
|
|
tie.mask = TCIF_PARAM;
|
|
|
|
::SendMessage(_hSelf, TCM_SETITEM, index, reinterpret_cast<LPARAM>(&tie));
|
|
|
|
|
|
|
|
bufferUpdated(MainFileManager->getBufferByID(id), BufferChangeMask); //update tab, everything has changed
|
|
|
|
|
|
|
|
::SendMessage(_hParent, WM_SIZE, 0, 0);
|
|
|
|
}
|
2009-09-04 00:10:01 +00:00
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
|
|
|
|
void DocTabView::reSizeTo(RECT & rc)
|
2009-09-04 00:10:01 +00:00
|
|
|
{
|
2011-11-22 01:15:03 +00:00
|
|
|
int borderWidth = ((NppParameters::getInstance())->getSVP())._borderWidth;
|
2009-09-04 00:10:01 +00:00
|
|
|
if (_hideTabBarStatus)
|
|
|
|
{
|
|
|
|
RECT rcTmp = rc;
|
|
|
|
TabBar::reSizeTo(rcTmp);
|
|
|
|
_pView->reSizeTo(rc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TabBar::reSizeTo(rc);
|
2011-11-22 01:15:03 +00:00
|
|
|
rc.left += borderWidth;
|
2015-08-04 11:36:22 +00:00
|
|
|
rc.right -= borderWidth * 2;
|
2011-11-22 01:15:03 +00:00
|
|
|
rc.top += borderWidth;
|
2015-08-04 11:36:22 +00:00
|
|
|
rc.bottom -= (borderWidth * 2);
|
2009-09-04 00:10:01 +00:00
|
|
|
_pView->reSizeTo(rc);
|
|
|
|
}
|
2017-04-17 23:31:41 +00:00
|
|
|
}
|
|
|
|
|