Added QuickTabs package (TabBar version)

Removed redundant TabBarTest
Added missing file from previous update
TaBar bug fixes

git-svn-id: svn://ultimatepp.org/upp/trunk@1280 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
mrjt 2009-06-05 09:02:58 +00:00
parent 717ce0f5cd
commit 11592adacb
14 changed files with 505 additions and 138 deletions

21
bazaar/QuickTabs/Copying Normal file
View file

@ -0,0 +1,21 @@
Copyright 1998-2008 The U++ Project. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE U++ PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -0,0 +1,55 @@
#include "QuickTabs.h"
QuickTabs::QuickTabs()
{
Stacking(true);
GroupSort(true);
GroupSeparators(true);
FileTabs::FileIcons(false, false, true);
FileTabs::WhenCloseAll <<= THISBACK(OnCloseAll);
}
void QuickTabs::ContextMenu(Bar& bar)
{
bar.Add("Settings", THISBACK(OnSettingsMenu));
FileTabs::ContextMenu(bar);
}
void QuickTabs::SettingsMenu(Bar &bar)
{
bar.Add("Stacking", IsStacking() ? TabBarImg::CHK() : Image(), THISBACK1(ToggleStacking));
bar.Add("Sort by group", IsGroupSort() ? TabBarImg::CHK() : Image(), THISBACK1(ToggleGroupSort));
bar.Add("Group separators", HasGroupSeparators() ? TabBarImg::CHK() : Image(), THISBACK1(ToggleGroupSeparators));
bar.Add("Show inactive", IsShowInactive ? TabBarImg::CHK() : Image(), THISBACK1(ToggleInactive));
}
void QuickTabs::Add(const char *name, bool make_active)
{
FileTabs::AddFile(name, make_active);
}
bool QuickTabs::FindSetFile(const String& fn)
{
int n = FindKey(fn.ToWString())
if (n >= 0) SetCursor(n);
return n >= 0;
}
void QuickTabs::SetAddFile(const String& fn)
{
if (IsNull(fn)) return;
if (!FindSetFile(fn))
FileTabs::AddFile(tn.ToWString());
}
void QuickTabs::RenameFile(const String& fn, const String& nn)
{
FileTabs::RenameFile(fn.ToWString(), nn.ToWString());
}
void QuickTabs::Set(const QuickTabs& t)
{
*this << t;
}

View file

@ -0,0 +1,36 @@
#ifndef _QuickTabs_QuickTabs_h
#define _QuickTabs_QuickTabs_h
#include <TabBar/TabBar.h>
using namespace Upp;
class QuickTabs : public FileTabs
{
void OnCloseAll() { WhenCloseRest(); }
virtual void ContextMenu(Bar& bar);
void SettingsMenu(Bar &bar);
public:
typedef QuickTabs CLASSNAME;
Callback WhenCloseRest;
QuickTabs();
void Add(const char *name, bool make_active = false);
QuickTabs& FileIcons(bool b = true) { TabBar::Icons(b); return *this; }
int GetCount() const { return tabs.GetCount(); }
int GetCursor() const { return active; }
String GetFile(int n) const { return tabs[n].key; }
bool FindSetFile(const String& fn);
void SetAddFile(const String& fn);
void RenameFile(const String& fn, const String& nn);
void Set(const QuickTabs& t);
void ToggleStacking() { Stacking(!IsStacking()); }
void ToggleGroupSort() { GroupSort(!IsGroupSort()); }
void ToggleGroupSeparators() { GroupSeparators(!HasGroupSeparators()); }
void ToggleInactive() { InactiveDisabled(!IsShowInactive()); }
};
#endif

View file

@ -0,0 +1,101 @@
PREMULTIPLIED
IMAGE_ID(BA)
IMAGE_ID(BH)
IMAGE_ID(BN)
IMAGE_ID(LA)
IMAGE_ID(LH)
IMAGE_ID(RA)
IMAGE_ID(RH)
IMAGE_ID(RN)
IMAGE_ID(DND)
IMAGE_ID(LN)
IMAGE_ID(CR0)
IMAGE_ID(CR1)
IMAGE_ID(CR2)
IMAGE_ID(UD)
IMAGE_ID(UD2)
IMAGE_ID(CHK)
IMAGE_ID(AD)
IMAGE_ID(AR)
IMAGE_ID(ARH)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,154,9,108,84,215,21,134,71,74,147,32,148,86,81,33,138,186,168,161,85,81,165,86,170,26,85,170,18,213)
IMAGE_DATA(144,218,98,80,12,178,193,1,146,154,136,69,74,28,182,0,45,78,41,78,33,114,98,21,146,180,180,13,9,105,138,205)
IMAGE_DATA(226,221,216,120,55,54,222,247,109,12,6,19,140,61,227,241,224,89,188,239,118,241,70,212,191,231,92,124,135,251,134,177)
IMAGE_DATA(141,52,173,70,145,252,208,167,119,255,119,207,121,239,190,247,223,227,123,109,161,123,90,247,93,157,60,190,159,92,7,79)
IMAGE_DATA(24,27,27,243,136,153,153,25,143,152,158,158,254,90,51,53,53,229,17,147,147,147,94,101,98,98,194,171,12,15,15,123)
IMAGE_DATA(68,79,79,143,87,233,237,237,245,42,222,30,127,127,127,191,87,25,24,24,240,136,193,193,65,143,24,26,26,242,8,79)
IMAGE_DATA(231,191,183,209,169,139,81,84,84,20,60,97,113,49,90,92,140,22,23,163,197,197,104,113,49,90,92,140,60,94,140,202)
IMAGE_DATA(202,202,224,9,163,163,163,30,97,183,219,61,194,102,179,121,21,171,213,250,181,198,219,223,207,83,44,22,139,71,24,141)
IMAGE_DATA(70,143,48,153,76,30,209,214,214,230,17,102,179,217,35,218,219,219,189,202,157,59,119,60,194,219,243,223,225,112,120,68)
IMAGE_DATA(103,103,167,71,120,123,49,9,15,15,247,8,221,55,148,197,200,245,207,117,178,221,210,210,34,86,110,110,183,82,123,124)
IMAGE_DATA(124,92,236,228,89,115,155,119,229,188,51,149,127,170,187,123,247,174,56,75,205,49,140,140,231,133,71,246,75,205,72,61)
IMAGE_DATA(50,50,34,144,154,95,212,85,51,82,247,245,245,9,164,230,137,193,139,147,170,153,185,250,229,98,166,106,158,28,82,115)
IMAGE_DATA(91,237,151,19,71,106,110,119,117,117,57,53,183,93,117,119,119,183,83,203,157,164,170,121,103,200,90,53,215,85,187,53)
IMAGE_DATA(75,254,90,202,237,164,164,36,167,89,201,201,201,26,179,162,163,163,53,102,197,198,196,104,204,138,139,139,213,152,21,31)
IMAGE_DATA(31,167,49,43,41,49,81,99,22,223,95,53,235,82,74,138,198,172,212,75,151,52,102,165,165,165,106,204,74,79,79,215)
IMAGE_DATA(152,145,153,145,161,49,43,39,59,91,211,159,147,147,163,49,43,247,114,174,198,172,188,188,60,141,89,249,249,249,26,179)
IMAGE_DATA(164,150,102,21,20,20,104,204,42,44,44,212,152,85,82,82,162,49,171,112,54,94,154,197,90,53,199,85,107,204,82,43)
IMAGE_DATA(138,15,54,136,141,146,215,216,32,190,121,235,236,53,54,136,141,146,85,227,90,85,210,36,181,202,216,20,25,47,77,146)
IMAGE_DATA(90,154,164,106,30,164,212,114,208,82,75,147,164,150,91,61,169,165,73,115,245,75,147,164,150,166,168,253,124,77,106,54)
IMAGE_DATA(69,213,108,2,95,83,53,35,53,27,164,106,105,146,212,242,247,60,215,247,115,87,85,194,3,213,172,200,200,72,49,219)
IMAGE_DATA(93,205,226,234,114,53,139,171,64,53,139,171,76,53,139,171,76,53,75,86,153,52,135,171,76,53,139,159,171,154,197,247)
IMAGE_DATA(87,205,226,42,83,205,226,42,83,205,226,42,83,205,224,42,83,205,226,42,83,251,185,202,84,179,184,202,84,179,184,202)
IMAGE_DATA(84,179,184,202,84,179,184,170,84,179,164,150,230,112,149,169,102,113,149,169,102,113,149,169,102,45,84,85,172,53,102,149)
IMAGE_DATA(150,150,162,170,170,202,105,22,255,134,200,27,203,242,242,114,113,173,163,163,67,124,112,190,86,83,83,227,252,24,124,173)
IMAGE_DATA(130,98,84,93,89,89,233,220,152,184,211,85,85,90,93,77,207,85,243,107,170,171,181,186,198,85,215,56,55,190,172,107)
IMAGE_DATA(73,203,141,172,208,181,181,206,141,41,235,58,210,114,163,201,186,190,190,222,185,113,148,90,110,228,220,105,131,193,224,220)
IMAGE_DATA(168,177,110,104,104,208,140,191,193,208,160,25,31,107,185,49,146,241,143,162,165,57,172,231,221,96,212,252,84,7,21,245)
IMAGE_DATA(154,107,204,162,254,255,235,135,252,112,183,193,224,234,226,42,227,54,87,21,207,94,174,50,57,155,121,38,112,149,113,53)
IMAGE_DATA(113,91,206,40,174,30,119,90,206,64,174,38,85,115,53,169,154,171,73,205,231,106,210,234,26,141,174,157,213,178,194,184)
IMAGE_DATA(154,88,203,10,171,155,213,178,194,184,90,88,203,10,147,90,86,152,212,178,162,184,154,84,205,179,157,181,172,48,174,30)
IMAGE_DATA(117,252,82,203,241,201,120,89,65,143,162,101,101,177,126,168,178,190,69,255,228,113,96,255,190,240,211,159,158,202,46,43)
IMAGE_DATA(45,70,81,97,254,188,148,22,23,130,99,101,78,69,121,41,140,173,183,97,105,111,67,187,217,228,22,238,107,51,181,130)
IMAGE_DATA(99,239,63,167,8,55,174,95,197,205,166,70,52,221,184,54,47,50,166,184,40,95,192,121,215,27,27,4,215,174,214,139)
IMAGE_DATA(190,198,107,6,231,53,21,142,173,40,47,209,228,113,108,199,29,51,186,187,236,206,220,78,135,85,192,49,146,242,178,98)
IMAGE_DATA(228,230,102,227,26,245,95,165,231,52,54,242,143,43,43,173,69,118,113,182,90,45,162,205,24,12,181,180,100,148,208,71)
IMAGE_DATA(175,67,17,61,43,61,53,5,13,245,181,168,175,173,70,93,77,149,56,219,58,44,112,216,58,156,240,119,204,201,202,64)
IMAGE_DATA(222,229,108,65,86,70,26,82,146,19,81,95,87,77,147,177,82,80,83,93,65,223,207,8,27,61,139,225,113,23,22,228)
IMAGE_DATA(33,255,202,101,113,46,42,188,130,244,180,20,36,196,199,136,248,234,170,114,145,211,102,106,161,111,110,18,200,54,223,71)
IMAGE_DATA(126,139,210,146,66,90,251,47,210,254,226,188,136,175,170,44,19,125,95,222,188,46,226,249,190,57,217,25,228,107,179,128)
IMAGE_DATA(253,226,28,62,243,24,99,163,207,163,170,162,12,149,228,103,97,126,158,120,95,62,243,123,240,57,55,39,11,217,153,233)
IMAGE_DATA(40,42,184,130,178,146,34,148,211,188,186,148,156,68,251,147,56,241,252,146,226,2,228,209,183,189,156,147,73,123,132,44)
IMAGE_DATA(241,62,252,76,190,206,253,242,121,236,65,124,92,180,152,51,23,147,226,133,86,199,194,154,199,93,89,81,170,33,51,35)
IMAGE_DATA(85,51,71,147,18,226,196,251,186,35,45,53,89,144,152,16,235,204,209,20,7,31,135,223,124,35,220,248,198,46,52,7)
IMAGE_DATA(4,205,75,203,235,59,192,177,50,199,180,119,63,134,170,232,39,65,51,173,193,183,140,238,161,190,17,195,117,152,246,188)
IMAGE_DATA(45,114,91,67,118,163,43,54,21,221,201,57,232,74,202,186,79,66,230,131,118,226,44,212,238,190,152,77,231,108,220,222)
IMAGE_DATA(178,21,183,54,110,65,103,108,6,28,103,47,10,108,255,140,163,184,76,216,35,19,97,143,74,130,227,92,178,64,180,57)
IMAGE_DATA(38,58,21,173,187,247,163,121,227,102,202,75,167,62,202,249,34,14,255,182,88,113,111,106,146,238,155,73,58,22,83,35)
IMAGE_DATA(163,2,199,5,202,191,144,2,71,76,26,140,33,251,80,19,184,65,104,123,100,60,28,241,105,152,158,156,192,189,123,51)
IMAGE_DATA(152,161,243,228,192,128,104,51,150,127,197,192,188,255,61,56,62,143,70,227,91,123,144,229,191,14,157,103,226,97,59,125)
IMAGE_DATA(30,29,167,206,162,57,58,14,83,180,225,157,161,141,177,164,226,248,95,209,232,19,0,211,170,87,97,246,217,140,226,117)
IMAGE_DATA(65,136,209,175,69,215,39,95,192,118,242,83,226,20,172,39,78,98,136,54,142,147,19,147,130,49,250,73,119,123,107,8)
IMAGE_DATA(236,171,233,125,244,193,232,37,178,253,3,113,202,207,15,221,20,107,139,248,16,182,63,127,132,62,171,13,125,253,131,24)
IMAGE_DATA(24,28,70,119,103,23,250,169,221,223,221,139,129,144,80,140,232,183,96,204,63,24,201,47,175,67,196,106,31,116,135,29)
IMAGE_DATA(131,237,112,24,44,161,71,208,220,216,4,27,197,23,28,141,64,238,107,219,97,233,176,194,76,88,66,14,98,84,255,42)
IMAGE_DATA(198,41,239,220,26,61,194,95,242,65,239,190,3,176,147,159,183,131,118,34,89,31,136,156,176,247,112,211,103,131,24,91)
IMAGE_DATA(238,142,93,72,217,246,22,28,126,65,24,245,255,237,253,60,189,30,31,109,8,128,37,104,27,108,65,59,112,99,85,48)
IMAGE_DATA(12,47,6,163,241,215,91,232,27,4,163,211,55,24,131,126,175,162,151,24,165,247,26,33,198,253,183,226,184,175,175,152)
IMAGE_DATA(51,159,173,245,69,255,230,32,244,236,13,68,231,129,64,244,254,46,16,131,135,2,49,26,26,136,187,127,8,192,132,228)
IMAGE_DATA(157,13,72,219,164,215,204,209,15,252,245,136,90,175,199,153,245,107,112,38,96,13,34,233,124,54,208,15,231,2,238,115)
IMAGE_DATA(129,218,199,95,242,117,230,60,84,28,159,135,30,74,168,255,225,10,148,235,116,243,82,253,204,51,224,88,153,99,120,106)
IMAGE_DATA(57,122,18,50,48,84,209,128,161,82,131,123,168,175,63,35,31,134,165,203,68,110,221,138,21,48,135,70,160,253,216,223)
IMAGE_DATA(208,254,238,95,238,115,228,227,7,237,176,89,184,125,244,36,157,79,162,114,233,82,84,208,243,205,161,39,96,220,115,84)
IMAGE_DATA(208,178,227,29,138,251,24,173,33,97,84,4,127,130,113,239,49,129,104,83,191,233,247,17,168,91,178,28,149,50,143,250)
IMAGE_DATA(90,118,254,17,227,77,45,248,207,244,140,184,127,203,206,195,152,25,26,22,152,14,132,195,116,240,125,152,14,29,135,225)
IMAGE_DATA(177,101,72,165,188,118,186,135,113,87,24,204,71,78,224,43,154,212,124,112,238,116,79,31,228,113,243,205,195,184,241,236)
IMAGE_DATA(11,104,223,17,138,252,199,159,198,223,41,207,178,231,93,24,119,30,66,203,182,253,168,166,201,39,115,229,145,244,242,70)
IMAGE_DATA(20,80,220,117,162,137,56,79,28,38,58,94,15,129,113,211,118,24,95,217,134,86,255,77,24,180,118,80,1,126,37,24)
IMAGE_DATA(31,30,69,173,110,9,218,249,254,68,39,241,15,98,43,97,243,127,5,70,191,117,48,174,13,64,151,137,86,198,190,65)
IMAGE_DATA(244,209,59,217,172,118,244,80,187,199,209,133,222,37,43,49,76,177,227,196,251,132,47,97,127,254,5,152,126,246,60,190)
IMAGE_DATA(92,249,115,84,23,151,195,68,241,81,191,242,195,103,212,119,171,213,132,38,162,121,233,115,24,35,125,151,56,72,248,240)
IMAGE_DATA(179,159,253,1,204,203,190,131,58,106,127,64,124,242,139,23,197,252,224,177,157,214,125,19,17,186,167,68,91,205,91,191)
IMAGE_DATA(124,25,110,209,217,68,148,16,185,132,252,6,252,62,253,179,239,196,57,195,179,121,107,9,158,51,219,233,220,67,56,190)
IMAGE_DATA(77,177,223,163,184,231,40,254,71,20,251,99,29,166,126,162,195,180,100,165,14,31,206,230,200,57,186,154,230,206,94,186)
IMAGE_DATA(182,139,216,77,236,33,222,38,14,204,142,235,16,161,87,114,104,15,252,152,179,48,104,196,112,199,170,95,234,86,51,178)
IMAGE_DATA(29,240,27,93,160,72,120,156,210,23,74,86,81,227,212,138,116,213,226,120,146,254,61,194,241,112,226,131,235,112,211,15)
IMAGE_DATA(55,184,139,159,43,110,161,251,207,61,174,39,117,79,204,17,59,239,224,23,26,236,255,102,112,115,29,79,60,236,194,66)
IMAGE_DATA(95,124,174,235,11,57,241,168,241,11,143,199,117,208,234,31,35,93,175,187,235,83,255,55,238,92,215,213,190,133,226,221)
IMAGE_DATA(221,223,245,218,127,1,218,41,220,130,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(2496, 19)

View file

@ -0,0 +1,11 @@
uses
CtrlLib,
TabBar;
file
QuickTabs.h,
QuickTabs.cpp,
QuickTabs.iml,
Info readonly separator,
Copying;

5
bazaar/QuickTabs/init Normal file
View file

@ -0,0 +1,5 @@
#ifndef _QuickTabs_icpp_init_stub
#define _QuickTabs_icpp_init_stub
#include "CtrlLib/init"
#include "TabBar/init"
#endif

181
bazaar/TabBar/FileTabs.cpp Normal file
View file

@ -0,0 +1,181 @@
#include "TabBar.h"
String FileTabs::GetFileGroup(const String &file)
{
return GetFileDirectory(file);
}
String FileTabs::GetStackId(const Tab &a)
{
String s = a.value;
return GetFileTitle(s);
}
unsigned FileTabs::GetStackSortOrder(const Tab &a)
{
String s = a.value;
return GetFileExt(s).GetHashValue();
}
void FileTabs::PaintTab(Draw& w, const Rect &r, const Tab& tab, const Font &font, Color ink, dword style)
{
const Value &q = tab.value;
WString txt = IsString(q) ? q : StdConvert().Format(q);
Point p;
int text_offset = TB_MARGIN;
if (PaintIcons() && tab.HasIcon()) {
Size isz = min(tab.img.GetSize(), Size(TB_ICON, TB_ICON));
p = GetImagePosition(r, isz.cx, isz.cy, text_offset, LEFT);
w.DrawImage(p.x, p.y, isz.cx, isz.cy, tab.img);
text_offset += TB_ICON + 2;
}
int extpos = txt.ReverseFind('.');
Size tsz = GetTextSize(txt, font, extpos);
int ang = GetTextAngle();
p = GetTextPosition(r, tsz.cy, text_offset);
w.DrawText(p.x, p.y, ang, txt, font, filecolor, extpos);
if (extpos >= 0) {
int extlen = txt.GetLength() - extpos;
p = GetTextPosition(r, tsz.cy, tsz.cx + text_offset);
w.DrawText(p.x, p.y, ang, txt.GetIter(extpos), font, extcolor, extlen);
}
}
void FileTabs::PaintStackedTab(Draw& w, const Rect &r, const Tab& tab, const Font &font, Color ink, dword style)
{
Point p;
int ang = GetTextAngle();
int tcy = GetTextSize("|", font, 1).cy;
p = GetTextPosition(r, tcy, 0);
w.DrawText(p.x, p.y, ang, "|", font, ink, 1);
if (stackedicons && tab.HasIcon()) {
Size isz = min(tab.img.GetSize(), Size(TB_ICON, TB_ICON));
p = GetImagePosition(r, isz.cx, isz.cy, TB_SPACEICON, LEFT);
w.DrawImage(p.x, p.y, isz.cx, isz.cy, (style == CTRL_HOT) ? tab.img : (greyedicons ? DisabledImage(tab.img) : tab.img));
}
else {
const Value &q = tab.value;
WString txt = IsString(q) ? q : StdConvert().Format(q);
int extpos = txt.ReverseFind('.');
if (extpos >= 0) {
int extlen = txt.GetLength() - extpos;
p = GetTextPosition(r, tcy, TB_SPACEICON);
w.DrawText(p.x, p.y, ang, txt.GetIter(extpos), font, (style == CTRL_HOT) ? extcolor : SColorDisabled(), extlen);
}
}
}
Size FileTabs::GetStackedSize(const Tab &t)
{
if (stackedicons && t.HasIcon())
return min(t.img.GetSize(), Size(TB_ICON, TB_ICON)) + Size(TB_SPACEICON, 0);
String s = t.value;
s = GetFileExt(s);
return GetTextSize(s.ToWString(), GetStyle().font) + Size(TB_SPACEICON, 0);
}
void FileTabs::AddFile(const WString &file, bool make_active)
{
AddFile(file, NativePathIcon(file.ToString()), make_active);
}
void FileTabs::AddFile(const WString &file, Image img, bool make_active)
{
InsertFile(GetCount(), file, img, make_active);
}
void FileTabs::InsertFile(int ix, const WString &file, bool make_active)
{
InsertFile(ix, file, NativePathIcon(file.ToString()), make_active);
}
void FileTabs::InsertFile(int ix, const WString &file, Image img, bool make_active)
{
String s = file.ToString();
TabBar::InsertKey(ix, file, GetFileName(s), img, GetFileGroup(s), make_active);
}
void FileTabs::AddFiles(const Vector<String> &files, bool make_active)
{
AddFiles(files, Vector<Image>(), make_active);
}
void FileTabs::AddFiles(const Vector<String> &files, const Vector<Image> &img, bool make_active)
{
InsertFiles(GetCount(), files, img, make_active);
}
void FileTabs::InsertFiles(int ix, const Vector<String> &files, bool make_active)
{
InsertFiles(ix, files, Vector<Image>(), make_active);
}
void FileTabs::InsertFiles(int ix, const Vector<String> &files, const Vector<Image> &img, bool make_active)
{
if (!files.GetCount()) return;
bool useimg = img.GetCount() == files.GetCount();
for (int i = files.GetCount()-1; i > 0; i--) {
TabBar::InsertKey0(ix, files[i].ToWString(), GetFileName(files[i]),
useimg ? img[i] : NativePathIcon(files[i]), GetFileGroup(files[i]));
}
InsertFile(ix, files[0].ToWString(), useimg ? img[0] : NativePathIcon(files[0]), make_active);
}
void FileTabs::RenameFile(WString &from, WString &to, Image icon)
{
int n = FindKey(from);
if (n >= 0)
Set(n, to, GetFileName(to.ToString()), IsNull(icon) ? NativePathIcon(to.ToString()) : icon);
}
FileTabs& FileTabs::FileIcons(bool normal, bool stacked, bool stacked_greyedout)
{
stackedicons = stacked;
greyedicons = stacked_greyedout;
TabBar::Icons(normal);
return *this;
}
Vector<String> FileTabs::GetFiles() const
{
Vector<String> files;
files.SetCount(tabs.GetCount());
for (int i = 0; i < tabs.GetCount(); i++)
files[i] = tabs[i].key;
return files;
}
FileTabs& FileTabs::operator<<(const FileTabs &src)
{
Clear();
Stacking(false);
GroupSort(false);
Grouping(false);
AddFiles(src.GetFiles(), src.GetIcons(), false);
CopySettings(src);
stackedicons = src.stackedicons;
greyedicons = src.greyedicons;
if (src.HasCursor())
SetData(~src);
sc.SetPos(src.GetScrollPos());
Refresh();
return *this;
}
FileTabs::FileTabs() :
normalicons(true),
stackedicons(false),
greyedicons(true),
filecolor(SColorText),
extcolor(LtBlue)
{
}

45
bazaar/TabBar/FileTabs.h Normal file
View file

@ -0,0 +1,45 @@
#include "TabBar.h"
class FileTabs : public TabBar
{
private:
bool normalicons:1;
bool stackedicons:1;
bool greyedicons:1;
Color filecolor;
Color extcolor;
protected:
// Overload this to change grouping behaviour
virtual String GetFileGroup(const String &file);
// Overload this to change stacking behaviour
virtual String GetStackId(const Tab &a);
virtual unsigned GetStackSortOrder(const Tab &a);
virtual void PaintTab(Draw& w, const Rect &r, const Tab& tab, const Font &font,
Color ink, dword style);
virtual void PaintStackedTab(Draw& w, const Rect &r, const Tab& tab, const Font &font,
Color ink, dword style);
virtual Size GetStackedSize(const Tab &t);
public:
FileTabs();
void AddFile(const WString &file, bool make_active = true);
void AddFile(const WString &file, Image img, bool make_active = true);
void InsertFile(int ix, const WString &file, bool make_active = true);
void InsertFile(int ix, const WString &file, Image img, bool make_active = true);
void AddFiles(const Vector<String> &files, bool make_active = true);
void AddFiles(const Vector<String> &files, const Vector<Image> &img, bool make_active = true);
void InsertFiles(int ix, const Vector<String> &files, bool make_active = true);
void InsertFiles(int ix, const Vector<String> &files, const Vector<Image> &img, bool make_active = true);
void RenameFile(WString &from, WString &to, Image icon = Null);
FileTabs& FileColor(Color c) { filecolor = c; Refresh(); return *this; }
FileTabs& ExtColor(Color c) { extcolor = c; Refresh(); return *this; }
FileTabs& FileIcons(bool normal = true, bool stacked = true, bool stacked_greyedout = true);
Vector<String> GetFiles() const;
FileTabs& operator<<(const FileTabs &src);
};

View file

@ -605,17 +605,17 @@ Point TabBar::GetTextPosition(const Rect& r, int cy, int space) const
if(align == LEFT)
{
p.y = r.bottom - space;
p.x = r.left + (r.GetWidth() - cy) / 2 + 2;
p.x = r.left + (r.GetWidth() - cy) / 2;
}
else if(align == RIGHT)
{
p.y = r.top + space;
p.x = r.right - (r.GetWidth() - cy) / 2 - 2;
p.x = r.right - (r.GetWidth() - cy) / 2;
}
else
{
p.x = r.left + space;
p.y = r.top + (r.GetHeight() - cy) / 2 + (align == TOP ? 2 : -2);
p.y = r.top + (r.GetHeight() - cy) / 2;
}
return p;
}
@ -948,17 +948,17 @@ TabBar& TabBar::AddKey(const Value &key, const Value &value, Image icon, String
TabBar& TabBar::InsertKey(int ix, const Value &key, const Value &value, Image icon, String group, bool make_active)
{
InsertKey0(ix, key, value, icon, group);
int id = InsertKey0(ix, key, value, icon, group);
MakeGroups();
Repos();
active = -1;
if (make_active || (!allownullcursor && active < 0))
SetCursor(minmax(ix, 0, tabs.GetCount() - 1));
SetCursor((groupsort || stacking) ? FindId(id) : ( minmax(ix, 0, tabs.GetCount() - 1)));
return *this;
}
void TabBar::InsertKey0(int ix, const Value &key, const Value &value, Image icon, String group)
int TabBar::InsertKey0(int ix, const Value &key, const Value &value, Image icon, String group)
{
ASSERT(ix >= 0);
int g = 0;
@ -991,8 +991,8 @@ void TabBar::InsertKey0(int ix, const Value &key, const Value &value, Image icon
t.stack = tabs[tail].stack;
tail++;
}
else if (ix < tabs.GetCount()) {
ix = FindStackHead(tabs[ix].stack);
else {
ix = (ix < tabs.GetCount()) ? FindStackHead(tabs[ix].stack) : ix;
t.stack = stackcount++;
}
tabs.Insert(ix, t);
@ -1000,19 +1000,15 @@ void TabBar::InsertKey0(int ix, const Value &key, const Value &value, Image icon
int head = FindStackHead(t.stack);
int headid = tabs[head].id;
Sort(tabs.GetIter(head), tabs.GetIter(tail+1), TabStackSort());
for (int i = head; i <= tail; i++)
if (tabs[i].id == headid) {
SetStackHead(tabs[i]);
break;
}
while (tabs[head].id != headid)
CycleTabStack(head, t.stack);
}
}
else
tabs.Insert(ix, t);
return t.id;
}
int TabBar::GetWidth() const
{
if (!tabs.GetCount()) return 0;
@ -1361,24 +1357,42 @@ void TabBar::SetData(const Value &key)
}
}
void TabBar::Set(int n, const Value &newkey, const Value &newvalue)
void TabBar::Set(int n, const Value &newkey, const Value &newvalue, Image icon)
{
ASSERT(n >= 0 && n < tabs.GetCount());
tabs[n].key = newkey;
tabs[n].value = newkey;
DoStacking();
if (IsNull(icon))
tabs[n].img = icon;
if (stacking) {
Tab t = tabs[n];
tabs[n].stackid = GetStackId(tabs[n]);
tabs[n].sort_order = GetStackSortOrder(tabs[n]);
if (t.stackid != tabs[n].stackid || t.sort_order != tabs[n].sort_order) {
tabs.Remove(n);
InsertKey0(GetCount(), t.key, t.value, t.img, t.group);
}
}
Repos();
Refresh();
}
void TabBar::Set(const Value &key, const Value &newvalue)
void TabBar::Set(const Value &key, const Value &newvalue, Image icon)
{
Set(FindKey(key), key, newvalue);
}
void TabBar::Set(int n, const Value &newvalue)
void TabBar::Set(int n, const Value &newvalue, Image icon)
{
Set(n, tabs[n].key, newvalue);
}
void TabBar::SetIcon(int n, Image icon)
{
ASSERT(n >= 0 && n < tabs.GetCount());
Set(n, tabs[n].key, newvalue);
tabs[n].img = icon;
Repos();
Refresh();
}
void TabBar::LeftDown(Point p, dword keyflags)
@ -1434,9 +1448,10 @@ void TabBar::RightDown(Point p, dword keyflags)
void TabBar::MiddleDown(Point p, dword keyflags)
{
if (highlight >= 0)
if (!CancelClose(tabs[highlight].key)) {
if (!CancelClose(tabs[highlight].key)) {
Value v = tabs[highlight].key;
Close(highlight);
WhenClose(tabs[highlight].key);
WhenClose(v);
}
}

View file

@ -260,7 +260,7 @@ protected:
void NewGroup(const String &name);
// Insertion without repos/refresh - for batch actions
void InsertKey0(int ix, const Value &key, const Value &value, Image icon = Null, String group = Null);
int InsertKey0(int ix, const Value &key, const Value &value, Image icon = Null, String group = Null);
// Sub-class Paint override
virtual void PaintTab(Draw& w, const Rect &r, const Tab& tab, const Font &font,
@ -312,13 +312,17 @@ public:
TabBar& Grouping(bool b = true);
TabBar& GroupSort(bool b = true);
TabBar& GroupSeparators(bool b = true);
TabBar& Stacking(bool b = true);
TabBar& AutoScrollHide(bool b = true);
TabBar& InactiveDisabled(bool b = true);
TabBar& AllowNullCursor(bool b = true);
TabBar& Icons(bool v = true);
TabBar& Stacking(bool b = true);
bool IsStacking() { return stacking; }
bool IsGrouping() const { return grouping; }
bool IsGroupSort() const { return grouping; }
bool HasGroupSeparators() const { return grouping; }
bool IsStacking() const { return stacking; }
bool IsShowInactive() const { return inactivedisabled; }
TabBar& NeverEmpty() { MinTabCount(1); }
TabBar& MinTabCount(int cnt) { mintabcount = max(cnt, 0); Refresh(); return *this; }
@ -331,9 +335,10 @@ public:
Value GetKey(int n) const { ASSERT(n >= 0 && n < tabs.GetCount()); return tabs[n].key;}
Value GetValue(int n) const { ASSERT(n >= 0 && n < tabs.GetCount()); return tabs[n].value;}
Value Get(const Value &key) const { return GetValue(FindKey(key)); }
void Set(int n, const Value &newkey, const Value &newvalue);
void Set(const Value &key, const Value &newvalue);
void Set(int n, const Value &newvalue);
void Set(int n, const Value &newkey, const Value &newvalue, Image icon = Null);
void Set(const Value &key, const Value &newvalue, Image icon = Null);
void Set(int n, const Value &newvalue, Image icon = Null);
void SetIcon(int n, Image icon);
void SetTabGroup(int n, const String &group);
virtual Value GetData() const { return (HasCursor() && active < GetCount()) ? GetKey(active) : Value(); }
@ -365,6 +370,7 @@ public:
Vector<Value> GetKeys() const;
Vector<Image> GetIcons() const;
int GetScrollPos() const { return sc.GetPos(); }
TabBar& CopySettings(const TabBar &src);
TabBar& SetStyle(int align, const Style& s) { ASSERT(align >= 0 && align < 4); style[align] = &s; Refresh(); return *this; }

View file

@ -4,9 +4,9 @@ uses
CtrlLib;
file
TabBar.cpp,
TabBar.h,
FileTabs.h,
TabBar.cpp,
FileTabs.cpp,
TabBar.iml;

View file

@ -1,96 +0,0 @@
#include <CtrlLib/CtrlLib.h>
#include <TabBar/TabBar.h>
using namespace Upp;
struct TabBarTest : TopWindow
{
TabBar l_tabs;
TabBar r_tabs;
TabBar t_tabs;
TabBar b_tabs;
typedef TabBarTest CLASSNAME;
bool Stack(Value a, Value b)
{
String as = a;
String bs = b;
as = as.Left(as.Find('.'));
bs = bs.Left(bs.Find('.'));
return as == bs;
}
TabBarTest()
{
l_tabs.Crosses(true);
l_tabs.Add("/ala/Test.cpp");
l_tabs.Add("/ala/Test.h");
l_tabs.Add("/ala/SuperProgram.cpp", true);
l_tabs.Add("/kasia/SuperProgram.h");
l_tabs.Add("/kasia/Synchronize.cpp");
l_tabs.Add("/kasia/Synchronize.h");
l_tabs.Add("/test/Test.cpp");
l_tabs.Add("/test/Test.h");
l_tabs.Grouping(true);
r_tabs.Crosses(true);
r_tabs.Add("/ala/Test.cpp");
r_tabs.Add("/ala/Test.h");
r_tabs.Add("/ala/SuperProgram.cpp", true);
r_tabs.Add("/kasia/SuperProgram.h");
r_tabs.Add("/kasia/Synchronize.cpp");
r_tabs.Add("/kasia/Synchronize.h");
r_tabs.Add("/test/Test.cpp");
r_tabs.Add("/test/Test.h");
r_tabs.Grouping(true);
t_tabs.Crosses(true);
t_tabs.Add("Test.cpp");
t_tabs.Add("Test.h");
t_tabs.Add("/ala/SuperProgram.cpp", true);
t_tabs.Add("/kasia/SuperProgram.h");
t_tabs.Add("/kasia/Synchronize.cpp");
t_tabs.Add("/kasia/Synchronize.h");
t_tabs.Add("/test/Test.cpp");
t_tabs.Add("/test/Test.h");
t_tabs.StackingFunc(THISBACK(Stack));
//t_tabs.Grouping(true);
//t_tabs.Stacking(true);
b_tabs.Crosses(true);
b_tabs.Add("/ala/Test.cpp");
b_tabs.Add("/ala/Test.h");
b_tabs.Add("/ala/SuperProgram.cpp", true);
b_tabs.Add("/kasia/SuperProgram.h");
b_tabs.Add("/kasia/Synchronize.cpp");
b_tabs.Add("/kasia/Synchronize.h");
b_tabs.Add("/test/Test.cpp");
b_tabs.Add("/test/Test.h");
b_tabs.Grouping(true);
AddFrame(t_tabs);
AddFrame(l_tabs);
AddFrame(r_tabs);
AddFrame(b_tabs);
l_tabs.SetLeft();
l_tabs.AutoScrollHide();
r_tabs.SetRight();
r_tabs.AutoScrollHide(); //FIXME: Doesn't work
b_tabs.SetBottom();
b_tabs.AutoScrollHide(); //FIXME: If not called bottom scrollbar is not shown
Sizeable().Zoomable();
}
virtual void Paint(Draw& w)
{
w.DrawRect(GetSize(), White);
}
};
GUI_APP_MAIN
{
TabBarTest().Run();
}

View file

@ -1,9 +0,0 @@
uses
TabBar;
file
TabBarTest.cpp;
mainconfig
"" = "GUI";

View file

@ -1,4 +0,0 @@
#ifndef _TabBarTest_icpp_init_stub
#define _TabBarTest_icpp_init_stub
#include "TabBar/init"
#endif