// This file is part of Notepad++ project
// Copyright (C)2021 Don HO <don.h@free.fr>

// 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 3 of the License, or
// at your option any later version.
//
// 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, see <https://www.gnu.org/licenses/>.




//该类继承自TabBarPlus类。该类负责管理文档选项卡视图，并提供一系列方法用于添加、关闭、激活缓冲区以及设置选项卡的个性化选项等功能。
#pragma once

#include "TabBar.h"
#include "Buffer.h"
// 定义一些常量用作图片索引
const int SAVED_IMG_INDEX = 0;
const int UNSAVED_IMG_INDEX = 1;
const int REDONLY_IMG_INDEX = 2;
const int MONITORING_IMG_INDEX = 3;

class DocTabView : public TabBarPlus
{
public:
	DocTabView() :TabBarPlus(), _pView(NULL) {};
	virtual ~DocTabView() {};

	void destroy() override {
		TabBarPlus::destroy();
	};
	//初始化函数，传入实例句柄、父窗口句柄、ScintillaEditView指针、以及图片列表和选择的图片索引
	void init(HINSTANCE hInst, HWND parent, ScintillaEditView* pView, std::vector<IconList*> pIconListVector, unsigned char indexChoice) {
		TabBarPlus::init(hInst, parent);
		_pView = pView;

		if (!pIconListVector.empty())
		{
			_pIconListVector = pIconListVector;

			if (indexChoice >= pIconListVector.size())
				_iconListIndexChoice = 0;
			else
				_iconListIndexChoice = indexChoice;
		}

		if (_iconListIndexChoice != -1)
			TabBar::setImageList(_pIconListVector[_iconListIndexChoice]->getHandle());
		return;
	};
	// 改变选中的图片列表
	void changeIcons(unsigned char choice) {
		if (choice >= _pIconListVector.size())
			return;
		_iconListIndexChoice = choice;
		TabBar::setImageList(_pIconListVector[_iconListIndexChoice]->getHandle());
	};
	// 添加缓冲区
	void addBuffer(BufferID buffer);
	// 关闭缓冲区
	void closeBuffer(BufferID buffer);
	// 缓冲区更新
	void bufferUpdated(Buffer* buffer, int mask);
	// 激活缓冲区
	bool activateBuffer(BufferID buffer);
	// 获取当前激活的缓冲区
	BufferID activeBuffer();
	// 根据文件名查找缓冲区，返回索引值，如果未找到则返回-1
	BufferID findBufferByName(const TCHAR* fullfilename);	//-1 if not found, something else otherwise
	// 根据缓冲区获取索引值
	int getIndexByBuffer(BufferID id);
	// 根据索引值获取缓冲区
	BufferID getBufferByIndex(size_t index);
	// 设置指定索引位置的缓冲区
	void setBuffer(size_t index, BufferID id);
	// 静态函数，用于设置隐藏或显示选项卡栏的状态
	static bool setHideTabBarStatus(bool hideOrNot) {
		bool temp = _hideTabBarStatus;
		_hideTabBarStatus = hideOrNot;
		return temp;
	};
	// 静态函数，获取隐藏或显示选项卡栏的状态
	static bool getHideTabBarStatus() {
		return _hideTabBarStatus;
	};
	// 重写父类的reSizeTo方法
	void reSizeTo(RECT& rc) override;
	// 获取ScintillaEditView指针
	const ScintillaEditView* getScintillaEditView() const {
		return _pView;
	};
	// 设置指定缓冲区的个性化选项卡颜色
	void setIndividualTabColour(BufferID bufferId, int colorId);
	// 获取指定索引位置的个性化选项卡颜色
	int getIndividualTabColour(int tabIndex) override;

private:
	ScintillaEditView* _pView = nullptr;
	static bool _hideTabBarStatus;

	std::vector<IconList*> _pIconListVector;
	int _iconListIndexChoice = -1;
};
