diff --git a/tutorial/Core01/init b/tutorial/Core01/init new file mode 100644 index 000000000..a9a869aa6 --- /dev/null +++ b/tutorial/Core01/init @@ -0,0 +1,4 @@ +#ifndef _Core01_icpp_init_stub +#define _Core01_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl03/Ntl03.cpp b/tutorial/Ntl03/Ntl03.cpp index dd8f22a55..e721fe034 100644 --- a/tutorial/Ntl03/Ntl03.cpp +++ b/tutorial/Ntl03/Ntl03.cpp @@ -9,15 +9,15 @@ CONSOLE_APP_MAIN v.Add(2); DUMPC(v); - Vector v1 = v; + Vector v1 = pick(v); DUMPC(v1); // DUMPC(v); -> v is picked, this would crash with runtime error - v <<= v1; + v = clone(v1); DUMPC(v1); DUMPC(v); - Vector v2(v, 0); + Vector v2 = clone(v); DUMPC(v2); DUMPC(v); } diff --git a/tutorial/Ntl03/init b/tutorial/Ntl03/init new file mode 100644 index 000000000..412108e8e --- /dev/null +++ b/tutorial/Ntl03/init @@ -0,0 +1,4 @@ +#ifndef _Ntl03_icpp_init_stub +#define _Ntl03_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl04/Ntl04.cpp b/tutorial/Ntl04/Ntl04.cpp index aedec992d..e36dd7946 100644 --- a/tutorial/Ntl04/Ntl04.cpp +++ b/tutorial/Ntl04/Ntl04.cpp @@ -13,7 +13,7 @@ Distribution CreateDist(int n) d.text << "Test (create) " << n; for(int i = 0; i < 10000; i++) d.data.At(rand() % n, 0)++; - return d; + return pick(d); } void Dump(const Vector& dist) diff --git a/tutorial/Ntl04/init b/tutorial/Ntl04/init new file mode 100644 index 000000000..816402c5e --- /dev/null +++ b/tutorial/Ntl04/init @@ -0,0 +1,4 @@ +#ifndef _Ntl04_icpp_init_stub +#define _Ntl04_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl05/init b/tutorial/Ntl05/init new file mode 100644 index 000000000..bdd969e86 --- /dev/null +++ b/tutorial/Ntl05/init @@ -0,0 +1,4 @@ +#ifndef _Ntl05_icpp_init_stub +#define _Ntl05_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl06/Ntl06.cpp b/tutorial/Ntl06/Ntl06.cpp index 54d682f2e..9b88740f0 100644 --- a/tutorial/Ntl06/Ntl06.cpp +++ b/tutorial/Ntl06/Ntl06.cpp @@ -6,20 +6,22 @@ struct Number { virtual double Get() const = 0; String ToString() const { return AsString(Get()); } + + virtual ~Number() {} }; struct Integer : public Number { int n; virtual double Get() const { return n; } - Integer(int n) : n(n) {} + Integer() {} }; struct Double : public Number { double n; virtual double Get() const { return n; } - Double(double n) : n(n) {} + Double() {} }; bool operator<(const Number& a, const Number& b) @@ -30,12 +32,8 @@ bool operator<(const Number& a, const Number& b) CONSOLE_APP_MAIN { Array num; - num.Add(new Integer(3)); - num.Add(new Double(15.5)); - num.Add(new Double(2.23)); - num.Add(new Integer(2)); - num.Add(new Integer(20)); - num.Add(new Double(-2.333)); + num.Create().n = 15.5; + num.Create().n = 3; DUMPC(num); Sort(num); DUMPC(num); diff --git a/tutorial/Ntl06/init b/tutorial/Ntl06/init new file mode 100644 index 000000000..cddeeceba --- /dev/null +++ b/tutorial/Ntl06/init @@ -0,0 +1,4 @@ +#ifndef _Ntl06_icpp_init_stub +#define _Ntl06_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl07/Ntl07.cpp b/tutorial/Ntl07/Ntl07.cpp index a3e52f174..c6a622032 100644 --- a/tutorial/Ntl07/Ntl07.cpp +++ b/tutorial/Ntl07/Ntl07.cpp @@ -6,22 +6,29 @@ struct Number { virtual double Get() const = 0; String ToString() const { return AsString(Get()); } + + virtual ~Number() {} }; struct Integer : public Number { int n; virtual double Get() const { return n; } - Integer(int n) : n(n) {} + Integer() {} }; struct Double : public Number { double n; virtual double Get() const { return n; } - Double(double n) : n(n) {} + Double() {} }; +bool operator<(const Number& a, const Number& b) +{ + return a.Get() < b.Get(); +} + CONSOLE_APP_MAIN { BiVector n; @@ -38,11 +45,9 @@ CONSOLE_APP_MAIN DUMPC(n); BiArray num; - num.AddHead(new Integer(3)); - num.AddTail(new Double(15.5)); - num.AddHead(new Double(2.23)); - num.AddTail(new Integer(2)); - num.AddHead(new Integer(20)); - num.AddTail(new Double(-2.333)); + num.CreateHead().n = 3; + num.CreateTail().n = 15.5; + num.CreateHead().n = 2.23; + num.CreateTail().n = 2; DUMPC(num); } diff --git a/tutorial/Ntl07/init b/tutorial/Ntl07/init new file mode 100644 index 000000000..21d19fac5 --- /dev/null +++ b/tutorial/Ntl07/init @@ -0,0 +1,4 @@ +#ifndef _Ntl07_icpp_init_stub +#define _Ntl07_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl08/init b/tutorial/Ntl08/init new file mode 100644 index 000000000..9cbbe9f62 --- /dev/null +++ b/tutorial/Ntl08/init @@ -0,0 +1,4 @@ +#ifndef _Ntl08_icpp_init_stub +#define _Ntl08_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl09/Ntl09.cpp b/tutorial/Ntl09/Ntl09.cpp index 9e71eebc7..8e828f7f6 100644 --- a/tutorial/Ntl09/Ntl09.cpp +++ b/tutorial/Ntl09/Ntl09.cpp @@ -6,50 +6,13 @@ struct Person : Moveable { String name; String surname; + unsigned GetHashValue() const { return CombineHash(name, surname); } + bool operator==(const Person& b) const { return name == b.name && surname == b.surname; } + Person(String name, String surname) : name(name), surname(surname) {} Person() {} }; -unsigned GetHashValue(const Person& p) -{ - return CombineHash(p.name, p.surname); -} - -bool operator==(const Person& a, const Person& b) -{ - return a.name == b.name && a.surname == b.surname; -} - -struct Number { - virtual double Get() const = 0; - - String ToString() const { return AsString(Get()); } -}; - -struct Integer : public Number { - int n; - virtual double Get() const { return n; } - - Integer(int n) : n(n) {} -}; - -struct Double : public Number { - double n; - virtual double Get() const { return n; } - - Double(double n) : n(n) {} -}; - -unsigned GetHashValue(const Number& n) -{ - return GetHashValue(n.Get()); -} - -bool operator==(const Number& a, const Number& b) -{ - return a.Get() == b.Get(); -} - CONSOLE_APP_MAIN { Index p; @@ -58,12 +21,4 @@ CONSOLE_APP_MAIN p.Add(Person("Carl", "Engles")); DUMP(p.Find(Person("Paul", "Carpenter"))); - - ArrayIndex n; - n.Add(new Integer(100)); - n.Add(new Double(10.5)); - n.Add(new Integer(200)); - n.Add(new Double(20.5)); - - DUMP(n.Find(Double(10.5))); } diff --git a/tutorial/Ntl09/init b/tutorial/Ntl09/init new file mode 100644 index 000000000..cfb349c24 --- /dev/null +++ b/tutorial/Ntl09/init @@ -0,0 +1,4 @@ +#ifndef _Ntl09_icpp_init_stub +#define _Ntl09_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl10/Ntl10.cpp b/tutorial/Ntl10/Ntl10.cpp index 5fe2f70ca..308561042 100644 --- a/tutorial/Ntl10/Ntl10.cpp +++ b/tutorial/Ntl10/Ntl10.cpp @@ -21,22 +21,29 @@ struct Number { virtual double Get() const = 0; String ToString() const { return AsString(Get()); } + + virtual ~Number() {} }; struct Integer : public Number { int n; virtual double Get() const { return n; } - Integer(int n) : n(n) {} + Integer() {} }; struct Double : public Number { double n; virtual double Get() const { return n; } - Double(double n) : n(n) {} + Double() {} }; +bool operator<(const Number& a, const Number& b) +{ + return a.Get() < b.Get(); +} + CONSOLE_APP_MAIN { VectorMap m; @@ -89,8 +96,8 @@ CONSOLE_APP_MAIN DUMPC(ps); ArrayMap am; - am.Add("A", new Integer(1)); - am.Add("B", new Double(2.0)); + am.Create("A").n = 1; + am.Create("B").n = 2.1; DUMPC(am.GetKeys()); DUMPC(am.GetValues()); diff --git a/tutorial/Ntl10/init b/tutorial/Ntl10/init new file mode 100644 index 000000000..cac4fc406 --- /dev/null +++ b/tutorial/Ntl10/init @@ -0,0 +1,4 @@ +#ifndef _Ntl10_icpp_init_stub +#define _Ntl10_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl11/Ntl11.cpp b/tutorial/Ntl11/Ntl11.cpp new file mode 100644 index 000000000..1e0aaf743 --- /dev/null +++ b/tutorial/Ntl11/Ntl11.cpp @@ -0,0 +1,60 @@ +#include + +using namespace Upp; + +struct Base { + virtual String Get() = 0; + virtual ~Base() {} +}; + +struct Derived1 : Base { + virtual String Get() { return "Derived1"; } +}; + +struct Derived2 : Base { + virtual String Get() { return "Derived2"; } +}; + +void MakeDerived1(One& t) +{ + t.Create(); +} + +void MakeDerived2(One& t) +{ + t.Create(); +} + +VectorMap&)> factories; + +INITBLOCK { + factories.Add(0, MakeDerived1); + factories.Add(1, MakeDerived2); +}; + +void Create(One& t, int what) +{ + (*factories.Get(what))(t); +} + +CONSOLE_APP_MAIN +{ + One s; + + DUMP((bool)s); + + s.Create(); + + DUMP((bool)s); + DUMP(s->Get()); + + s.Create(); + DUMP((bool)s); + DUMP(s->Get()); + + s.Clear(); + DUMP((bool)s); + + Create(s, 0); + DUMP(s->Get()); +} diff --git a/tutorial/Ntl11/Ntl11.upp b/tutorial/Ntl11/Ntl11.upp new file mode 100644 index 000000000..95d807c87 --- /dev/null +++ b/tutorial/Ntl11/Ntl11.upp @@ -0,0 +1,11 @@ +description "One\377"; + +uses + Core; + +file + Ntl11.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/tutorial/Ntl11/init b/tutorial/Ntl11/init new file mode 100644 index 000000000..7f9dbb96c --- /dev/null +++ b/tutorial/Ntl11/init @@ -0,0 +1,4 @@ +#ifndef _Ntl11_icpp_init_stub +#define _Ntl11_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl12/Ntl12.cpp b/tutorial/Ntl12/Ntl12.cpp new file mode 100644 index 000000000..2b546ff82 --- /dev/null +++ b/tutorial/Ntl12/Ntl12.cpp @@ -0,0 +1,27 @@ +#include + +using namespace Upp; + +void Do(Any& x) +{ + if(x.Is()) + LOG("String: " << x.Get()); + if(x.Is()) { + LOG("--- File: "); + LOG(LoadStream(x.Get())); + LOG("----------"); + } + if(x.IsEmpty()) + LOG("empty"); +} + +CONSOLE_APP_MAIN +{ + Any x; + x.Create() = "Hello!"; + Do(x); + x.Create().Open(GetDataFile("Ntl12.cpp")); + Do(x); + x.Clear(); + Do(x); +} diff --git a/tutorial/Ntl12/Ntl12.upp b/tutorial/Ntl12/Ntl12.upp new file mode 100644 index 000000000..9e7e8b208 --- /dev/null +++ b/tutorial/Ntl12/Ntl12.upp @@ -0,0 +1,11 @@ +description "Any\377"; + +uses + Core; + +file + Ntl12.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/tutorial/Ntl12/init b/tutorial/Ntl12/init new file mode 100644 index 000000000..2825e52f4 --- /dev/null +++ b/tutorial/Ntl12/init @@ -0,0 +1,4 @@ +#ifndef _Ntl12_icpp_init_stub +#define _Ntl12_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl13/Ntl13.cpp b/tutorial/Ntl13/Ntl13.cpp new file mode 100644 index 000000000..c265822b5 --- /dev/null +++ b/tutorial/Ntl13/Ntl13.cpp @@ -0,0 +1,14 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + InVector v; + for(int i = 0; i < 1000000; i++) + v.Add(i); + v.Insert(0, -1); // This is fast + DUMP(v[0]); + DUMP(v[1]); + DUMP(v.FindLowerBound(55)); +} diff --git a/tutorial/Ntl13/Ntl13.upp b/tutorial/Ntl13/Ntl13.upp new file mode 100644 index 000000000..263f6a83f --- /dev/null +++ b/tutorial/Ntl13/Ntl13.upp @@ -0,0 +1,11 @@ +description "InVector, InArray\377"; + +uses + Core; + +file + Ntl13.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/tutorial/Ntl13/init b/tutorial/Ntl13/init new file mode 100644 index 000000000..2171822d1 --- /dev/null +++ b/tutorial/Ntl13/init @@ -0,0 +1,4 @@ +#ifndef _Ntl13_icpp_init_stub +#define _Ntl13_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl14/Ntl14.cpp b/tutorial/Ntl14/Ntl14.cpp new file mode 100644 index 000000000..1cc579d9f --- /dev/null +++ b/tutorial/Ntl14/Ntl14.cpp @@ -0,0 +1,25 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + SortedIndex x; + x.Add(5); + x.Add(3); + x.Add(7); + x.Add(1); + + DUMPC(x); + DUMP(x.Find(3)); + DUMP(x.FindLowerBound(3)); + DUMP(x.FindUpperBound(6)); + + SortedVectorMap m; + m.Add("zulu", 11); + m.Add("frank", 12); + m.Add("alfa", 13); + + DUMPM(m); + DUMP(m.Get("zulu")); +} diff --git a/tutorial/Ntl14/Ntl14.upp b/tutorial/Ntl14/Ntl14.upp new file mode 100644 index 000000000..43e199a40 --- /dev/null +++ b/tutorial/Ntl14/Ntl14.upp @@ -0,0 +1,11 @@ +description "SortedIndex, SortedVectorMap, SortedArrayMap\377"; + +uses + Core; + +file + Ntl14.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/tutorial/Ntl14/init b/tutorial/Ntl14/init new file mode 100644 index 000000000..b5bfdbf63 --- /dev/null +++ b/tutorial/Ntl14/init @@ -0,0 +1,4 @@ +#ifndef _Ntl14_icpp_init_stub +#define _Ntl14_icpp_init_stub +#include "Core/init" +#endif diff --git a/tutorial/Ntl15/Ntl15.cpp b/tutorial/Ntl15/Ntl15.cpp new file mode 100644 index 000000000..2eecd3159 --- /dev/null +++ b/tutorial/Ntl15/Ntl15.cpp @@ -0,0 +1,36 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + Tuple3 x = MakeTuple(12, "hello", "world"); + + DUMP(x.a); + DUMP(x.b); + DUMP(x.c); + + DUMP(x); + + DUMP(GetHashValue(x)); + + Tuple3 y = x; + + DUMP(x != y); + DUMP(x.Compare(y)); + + y.b = "a"; + + DUMP(SgnCompare(y)); + DUMP(x < y); + + static Tuple2 map[] = { + { 1, "one" }, + { 2, "one" }, + { 3, "one" }, + }; + + Tuple2 *f = FindTuple(map, __countof(map), 2); + if(f) + DUMP(f->b); +} diff --git a/tutorial/Ntl15/Ntl15.upp b/tutorial/Ntl15/Ntl15.upp new file mode 100644 index 000000000..c469c88ed --- /dev/null +++ b/tutorial/Ntl15/Ntl15.upp @@ -0,0 +1,11 @@ +description "Tuples\377"; + +uses + Core; + +file + Ntl15.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/tutorial/Ntl15/init b/tutorial/Ntl15/init new file mode 100644 index 000000000..04e6937fb --- /dev/null +++ b/tutorial/Ntl15/init @@ -0,0 +1,4 @@ +#ifndef _Ntl15_icpp_init_stub +#define _Ntl15_icpp_init_stub +#include "Core/init" +#endif diff --git a/uppbox/uppweb/uppweb.upp b/uppbox/uppweb/uppweb.upp index 47ffb78f7..1284bcf28 100644 --- a/uppbox/uppweb/uppweb.upp +++ b/uppbox/uppweb/uppweb.upp @@ -54,5 +54,5 @@ file www.t; mainconfig - "" = "MT SKELETON RAINBOW"; + "" = "MT SKELETON RAINBOW NOGTK"; diff --git a/uppbox/uppweb/www.cpp b/uppbox/uppweb/www.cpp index 9438f9cf3..5128c2eb9 100644 --- a/uppbox/uppweb/www.cpp +++ b/uppbox/uppweb/www.cpp @@ -669,8 +669,11 @@ void ExportPage(int i) .BgColor(bg) .Alink(Red).Link(Black).Vlink(Blue) / html; - SaveFile(AppendFileName(targetdir, links[i]), content); - RLOG("Exported page " << links[i]); + if(!SaveFile(AppendFileName(targetdir, links[i]), content)) { + RLOG("SaveFile failed!"); + abort(); + } + RLOG("Exported page " << AppendFileName(targetdir, links[i])); } String Downloads() diff --git a/uppdev/ArrayOne/ArrayOne.cpp b/uppdev/ArrayOne/ArrayOne.cpp index 4e5a8f468..4b162d75d 100644 --- a/uppdev/ArrayOne/ArrayOne.cpp +++ b/uppdev/ArrayOne/ArrayOne.cpp @@ -2,17 +2,18 @@ using namespace Upp; -struct ArrayOneHelper { - Array array; - One one; - -public: - operator One&(); - - ~ArrayOneHelper() { array.Add(one.Detach()); } -}; - CONSOLE_APP_MAIN { - Test(array.AddOne()); + Array< Vector > a; + a.Add() << 1 << 2 << 3; + + auto b = clone(a); + + DUMPCC(a); + DUMPCC(b); + + Vector h; + h.Insert(0, {1, 2, 3}); + h.Insert(1, {5, 4, 3}); + DDUMPC(h); } diff --git a/uppdev/ArrayOne/init b/uppdev/ArrayOne/init new file mode 100644 index 000000000..bd8dceb52 --- /dev/null +++ b/uppdev/ArrayOne/init @@ -0,0 +1,4 @@ +#ifndef _ArrayOne_icpp_init_stub +#define _ArrayOne_icpp_init_stub +#include "Core/init" +#endif diff --git a/uppdev/RichEditTest/main.cpp b/uppdev/RichEditTest/main.cpp index fdb5fe9ed..ba4883c82 100644 --- a/uppdev/RichEditTest/main.cpp +++ b/uppdev/RichEditTest/main.cpp @@ -16,6 +16,7 @@ struct MyApp : TopWindow { GUI_APP_MAIN { + StdLogSetup(LOG_FILE|LOG_COUT); // ChClassicSkin(); // ChStdSkin(); // SetLanguage(LNG_('P','L','P','L')); diff --git a/uppdev/TabBar/TabBar.cpp b/uppdev/TabBar/TabBar.cpp deleted file mode 100644 index 8fb4a8ea2..000000000 --- a/uppdev/TabBar/TabBar.cpp +++ /dev/null @@ -1,1870 +0,0 @@ -$uvs: PENDING CONFLICT -#include "TabBar.h" - -#define IMAGECLASS TabBarImg -#define IMAGEFILE -#include - -// AlignedFrame -void AlignedFrame::FrameLayout(Rect &r) -{ - switch(layout) - { - case LEFT: - LayoutFrameLeft(r, this, framesize); - break; - case TOP: - LayoutFrameTop(r, this, framesize); - break; - case RIGHT: - LayoutFrameRight(r, this, framesize); - break; - case BOTTOM: - LayoutFrameBottom(r, this, framesize); - break; - } - r.top += border; - r.left += border; - r.right -= border; - r.bottom -= border; -} - -void AlignedFrame::FrameAddSize(Size& sz) -{ - sz += border * 2; -$uvs: REPOSITORY INSERT - IsVert() ? sz.cx += framesize : sz.cy += framesize; -$uvs: END REPOSITORY INSERT -$uvs: REPOSITORY DELETE - switch(layout) - { - case LEFT: - sz.cx += framesize; - break; - case TOP: - sz.cy += framesize; - break; - case RIGHT: - sz.cx -= framesize; - break; - case BOTTOM: - sz.cy -= framesize; - break; - } -$uvs: END REPOSITORY DELETE -} - -void AlignedFrame::FramePaint(Draw& w, const Rect& r) -{ - if(border > 0) - { - Rect n = r; - switch(layout) - { - case LEFT: - n.left += framesize; - break; - case TOP: - n.top += framesize; - break; - case RIGHT: - n.right -= framesize; - break; - case BOTTOM: - n.bottom -= framesize; - break; - } - FieldFrame().FramePaint(w, n); - } - else - FrameCtrl::FramePaint(w, r); -} - -AlignedFrame& AlignedFrame::SetFrameSize(int sz, bool refresh) -{ - framesize = sz; - if (refresh) RefreshParentLayout(); - return *this; -} - -void AlignedFrame::Fix(Size& sz) -{ - if(IsVert()) - Swap(sz.cx, sz.cy); -} - -void AlignedFrame::Fix(Point& p) -{ - if(IsVert()) - Swap(p.x, p.y); -} - -// TabScrollBar -TabScrollBar::TabScrollBar() -{ - Clear(); -} - -void TabScrollBar::Clear() -{ - total = 0; - pos = 0; - ps = 0; - start_pos = 0; - new_pos = 0; - old_pos = 0; - ready = false; -} - -void TabScrollBar::UpdatePos(bool update) -{ - sz = GetSize(); - Fix(sz); - if(total <= 0 || sz.cx <= 0) - cs = ics = 0; - else - { - cs = sz.cx / ((double) total + 0.5); - ics = total / ((double) sz.cx); - } - size = sz.cx * cs; - if(update) - pos = new_pos - start_pos; - if(pos < 0) - pos = 0; - else if(pos + size > sz.cx) - pos = sz.cx - size; - - ps = total > sz.cx ? pos * ics : 0; -} - -void TabScrollBar::Paint(Draw &w) -{ - if(!ready) - { - UpdatePos(); - ready = true; - } - Size rsz = GetSize(); - w.DrawRect(rsz, White); - Point p; - - if(total > sz.cx) { - p = Point(ffloor(pos), 1); - rsz = Size(fceil(size), 2); - } - else { - p = Point(0, 1); - rsz = Size(sz.cx, 2); - } - Fix(p); - Fix(rsz); - w.DrawRect(p.x, p.y, rsz.cx, rsz.cy, Blue); -} - -void TabScrollBar::Layout() -{ - UpdatePos(false); -} - -void TabScrollBar::LeftDown(Point p, dword keyflags) -{ - SetCapture(); - Fix(p); - old_pos = new_pos = p.x; - if(p.x < pos || p.x > pos + size) - start_pos = size / 2; - else - start_pos = tabs(p.x - pos); - UpdatePos(); - UpdateActionRefresh(); -} - -void TabScrollBar::LeftUp(Point p, dword keyflags) -{ - ReleaseCapture(); - Fix(p); - old_pos = p.x; -} - -void TabScrollBar::MouseMove(Point p, dword keyflags) -{ - if(!HasCapture()) - return; - - Fix(p); - new_pos = p.x; - UpdatePos(); - UpdateActionRefresh(); -} - -void TabScrollBar::MouseWheel(Point p, int zdelta, dword keyflags) -{ - AddPos(-zdelta / 4, true); - UpdateActionRefresh(); -} - -int TabScrollBar::GetPos() const -{ - return ffloor(ps); -} - -void TabScrollBar::SetPos(int p, bool dontscale) -{ - pos = total > 0 ? dontscale ? p : iscale(p, sz.cx, total) : 0; - UpdatePos(false); - Refresh(); -} - -void TabScrollBar::AddPos(int p, bool dontscale) -{ - pos += total > 0 ? dontscale ? p : iscale(p, sz.cx, total) : 0; - UpdatePos(false); - Refresh(); -} - -int TabScrollBar::GetTotal() const -{ - return total; -} - -void TabScrollBar::SetTotal(int t) -{ - bool upd = total < t; - total = t; - UpdatePos(upd); - Refresh(); -} - -void TabScrollBar::AddTotal(int t) -{ - total += t; - UpdatePos(); - Refresh(); -} - -void TabScrollBar::GoEnd() -{ - pos = total; - UpdatePos(false); - Refresh(); -} - -void TabScrollBar::GoBegin() -{ - pos = 0; - UpdatePos(false); - Refresh(); -} - -void TabScrollBar::Set(const TabScrollBar& t) -{ - total = t.total; - pos = t.pos; - ps = t.ps; - Refresh(); -} - -bool TabScrollBar::IsScrollable() const -{ - return IsHorz() && total > sz.cx && sz.cx > 0 - || IsVert() && total > sz.cy && sz.cy > 0; -} - -// TabBar -TabBar::Style TabBar::leftstyle; -TabBar::Style TabBar::rightstyle; -TabBar::Style TabBar::bottomstyle; - -TabBar::TabBar() -{ - Clear(); - display = NULL; - crosses = true; - grouping = true; - isctrl = false; - isdrag = false; - inactiveshadow = true; - autoscrollhide = true; - neverempty = 1; - - style[0] = style[1] = style[2] = style[3] = NULL; - SetAlign(TOP); - SetFrameSize(GetHeight()); - BackPaint(); -} - -void TabBar::CloseAll() -{ - for(int i = tabs.GetCount() - 1; i >= 0; i--) - if(i != active) - tabs.Remove(i); - - SyncScrollBar(tabs[0].cx); - MakeGroups(); - Repos(); - SetCursor(0); -$uvs: REPOSITORY INSERT - WhenCloseAll(); -$uvs: END REPOSITORY INSERT -} - -int TabBar::GetNextId() -{ - return ++id; -} - -void TabBar::ContextMenu(Bar& bar) -{ - if (highlight >= 0) { - bar.Add(tabs.GetCount() > 1, "Close", THISBACK1(Close, highlight)); - bar.Separator(); - } - int cnt = groups.GetCount(); - for(int i = 0; i < cnt; i++) - { - String name = Format("%s (%d)", groups[i].name, groups[i].count); - Bar::Item &it = i > 0 ? bar.Add(name, THISBACK1(GroupMenu, i)) - : bar.Add(name, THISBACK1(DoGrouping, i)); - if(i == group) - it.Image(TabBarImg::CHK); - if(i == 0 && cnt > 1) - bar.Separator(); - } - bar.Separator(); - - bar.Add("Close all tabs except current", THISBACK(CloseAll)); -} - -void TabBar::GroupMenu(Bar &bar, int n) -{ - bar.Add("Set active", THISBACK1(DoGrouping, n)); - bar.Add("Close", THISBACK1(DoCloseGroup, n)); -} - -bool TabBar::Tab::HasMouse(const Point& p) const -{ - return visible && p.x >= x && p.x < x + cx; -} - -bool TabBar::Tab::HasMouseCross(const Point& p, int h, int type) const -{ - if(!visible) - return false; - - Size isz = TabBarImg::CR0().GetSize(); - int iy = (h - isz.cy) / 2; - int ix = x + (type ? cx - isz.cx - QT_MARGIN : QT_MARGIN); - - return p.x >= ix && p.x < ix + isz.cx && - p.y >= iy && p.y < iy + isz.cy; -} - -int TabBar::FindGroup(const String& g) const -{ - for(int i = 0; i < groups.GetCount(); i++) - if(groups[i].name == g) - return i; - return -1; -} - -void TabBar::MakeGroups() -{ - groups[0].count = tabs.GetCount(); - groups[0].first = 0; - groups[0].last = tabs.GetCount() - 1; - - for(int i = 1; i < groups.GetCount(); i++) - { - groups[i].count = 0; - groups[i].first = 10000000; - groups[i].last = 0; - } - - for(int i = 0; i < tabs.GetCount(); i++) - { - Tab &tab = tabs[i]; - int n = FindGroup(tab.group); - ASSERT(n >= 0); - if (n != 0) { - if(groups[n].active < 0) - groups[n].active = tab.id; - groups[n].count++; - groups[n].last = i; - - if(i < groups[n].first) - groups[n].first = i; - if(i > groups[n].last) - groups[n].last = i; - } - } - - int removed = 0; - for(int i = 1; i < groups.GetCount(); i++) - if(groups[i].count == 0) - { - groups.Remove(i - removed); - removed++; - } - if(group > groups.GetCount() - 1 && group > 0) - group--; -} - -void TabBar::DoGrouping(int n) -{ - group = n; - Repos(); - SyncScrollBar(GetWidth()); - SetCursor(-1); -} - -void TabBar::DoCloseGroup(int n) -{ - int cnt = groups.GetCount(); - if(cnt <= 0) - return; - if (cnt == n) - --group; - - String group = groups[n].name; - - for(int i = tabs.GetCount() - 1; i >= 0; i--) - { - if(group == tabs[i].group && tabs.GetCount() > 1) { - Value v = tabs[i].data; - tabs.Remove(i); - WhenClose(v); - } - } - if(cnt > 1) - groups.Remove(n); - MakeGroups(); - Repos(); - SetCursor(-1); - WhenCursor(); -} - -void TabBar::NewGroup(const String &name, const Value &data) -{ - Group &g = groups.Add(); - g.name = name; - g.data = data; - g.count = 0; - g.first = 10000000; - g.last = 0; - g.active = -1; -} - -Value TabBar::AlignValue(int align, const Value &v, const Size &isz) -{ - if (align == TOP) return v; - if (IsTypeRaw(v)) { - switch(align) { - case AlignedFrame::LEFT: return RotateAntiClockwise((Image)v); - case AlignedFrame::RIGHT: return RotateClockwise((Image)v); - case AlignedFrame::BOTTOM: return MirrorVert((Image)v); - } - } - else if (!IsTypeRaw(v)) { - ImageDraw w(isz.cx, isz.cy); - ChPaint(w, isz, v); - ImageBuffer img; - Image temp = (Image)w; - switch(align) { - case AlignedFrame::LEFT: - temp = RotateAntiClockwise(temp); - img = temp; // GCC - img.SetHotSpot(Point(1, 5)); - img.Set2ndSpot(Point(0, isz.cx/2)); - break; - case AlignedFrame::RIGHT: - temp = RotateClockwise(temp); - img = temp; - img.SetHotSpot(Point(isz.cy-10, isz.cx-10)); - img.Set2ndSpot(Point(isz.cy/2, isz.cx/2)); - break; - case AlignedFrame::BOTTOM: - temp = MirrorVert(temp); - img = temp; - img.SetHotSpot(Point(10, 10)); - img.Set2ndSpot(Point(isz.cx/2, isz.cy/2)); - break; - - } - return (Image)img; - } - return v; -} - -void TabBar::TabCenter(Point &p, const Size &sz, int h) -{ - if (IsHorz()) - p.y += (sz.cy - h) / 2; - else - p.x += (sz.cx - h) / 2 * ((GetAlign() == LEFT) ? 1 : -1); -} - -void TabBar::DrawTabData(Draw& w, Point p, const Size &sz, const Value& q, const Font &font, Color ink, dword style) -{ - WString txt; - Font f = font; - Color i = ink; - int a = TextAngle(); - - if(IsType(q)) { - const AttrText& t = ValueTo(q); - txt = t.text; - if(!IsNull(t.font)) - f = t.font; - i = IsNull(t.ink) ? ink : t.ink; - } - else - txt = IsString(q) ? q : StdConvert().Format(q); - TabCenterText(p, sz, font); - w.DrawText(p.x, p.y, TextAngle(), txt, f, i); -} - -void TabBar::DrawTab(Draw &w, const Style &s, const Size &sz, int n, bool enable) -{ - TabBar::Tab &t = tabs[n]; - int cnt = tabs.GetCount(); - Size tsz, isz(0, 0); - Point p; - int align = GetAlign(); - bool ac = n == active; - bool hl = n == highlight; - - int ndx = !enable ? CTRL_DISABLED : - ac ? CTRL_PRESSED : - hl ? CTRL_HOT : CTRL_NORMAL; - - const Value& sv = (cnt == 1 ? s.both : n == 0 ? s.first : n == cnt - 1 ? s.last : s.normal)[ndx]; - - if (ac) { - p = Point(t.x - sc.GetPos() + s.margin - s.extendleft - s.sel.left, 0); - tsz = Size(t.cx + s.sel.right + s.sel.left, t.cy + s.sel.bottom); - if (align == LEFT) { - p.x += s.sel.left; - tsz.cx += s.sel.left; - } - } - else { - p = Point(t.x - sc.GetPos() + s.margin - s.extendleft, (IsBR() ? s.sel.bottom : s.sel.top)); - tsz = Size(t.cx + s.sel.right + s.sel.left, t.cy - s.sel.top); - } - - if (IsVert()) - ChPaint(w, p.y, p.x, tsz.cy, tsz.cx, sv); - else - ChPaint(w, p.x, p.y, tsz.cx, tsz.cy, sv); - - if(crosses && cnt > neverempty) { - Point cp; - const Image &cimg = TabBarImg::CR0(); // Use style? - isz = cimg.GetSize(); - Fix(isz); - if (align == LEFT) - cp.x = p.x + QT_MARGIN; - else - cp.x = p.x + tsz.cx - isz.cx - QT_MARGIN; - cp.y = p.y + (tsz.cy - isz.cy) / 2; - Fix(cp); - w.DrawImage(cp.x, cp.y, (ac || hl) ? (cross == n ? TabBarImg::CR2 : ac ? TabBarImg::CR1 : TabBarImg::CR0) : TabBarImg::CR0); - isz.cx += 2; - } - - p.x += QT_MARGIN; - tsz.cx -= QT_MARGIN * 2; - switch (align) { - case BOTTOM: - if (ac) p.y -= s.sel.top; break; - case RIGHT: p.y = sz.cx - p.y; break; - case LEFT: p.x += tsz.cx; - } - tsz.cx -= isz.cx; - Fix(p); - Fix(tsz); - if (display) - display->Paint(w, Rect(p, tsz), t.data, s.text_color[ndx], SColorDisabled(), ndx); - else { - DrawTabData(w, p, tsz, - t.data, s.font, - s.text_color[ndx], ndx); - } -} -void TabBar::Paint(Draw &w) -{ - const Style &st = *style[GetAlign()]; - Size sz = GetSize(); - - w.DrawRect(sz, SColorFace()); - - IsVert() ? - w.DrawRect((GetAlign() == LEFT) ? sz.cx -1 : 1, 0, 1, sz.cy, Color(128, 128, 128)) : - w.DrawRect(0, (GetAlign() == TOP) ? sz.cy - 1 : 1, sz.cx, 1, Color(128, 128, 128)); - - if (!tabs.GetCount()) return; - int cxy = IsVert() ? sz.cy : sz.cx; - for(int i = 0; i < tabs.GetCount(); i++) - if(tabs[i].visible && i != active) { - DrawTab(w, st, sz, i, IsEnabled()); - if (tabs[i].x > cxy) break; - } - if (inactiveshadow) - for(int i = 0; i < tabs.GetCount() && tabs[i].x < cxy; i++) - if(!tabs[i].visible && i != active) - DrawTab(w, st, sz, i, false); - if(active >= 0) - DrawTab(w, st, sz, active, true); - - if(target >= 0) - { - int dragtab = isctrl ? highlight : active; - if(target != dragtab && target != dragtab + 1) - { - Tab &tab = tabs[dragtab]; - Size tsz(tab.cx, IsVert() ? sz.cx : sz.cy); - Fix(tsz); - if (dragimg.IsEmpty()) { - int alpha = 180; - ImageDraw img(tsz); - img.Alpha().DrawRect(tsz, Color(alpha, alpha, alpha)); - img.DrawRect(tsz, SColorFace()); - Point temp = Point(tab.x, tab.y); - tab.x = tab.y = 0; - DrawTab(img, st, sz, dragtab, true); - dragimg = img; - tab.x = temp.x; - tab.y = temp.y; - } - int last = GetLast(); - int first = GetFirst(); - int x = (target == last + 1 ? tabs[last].Right() : tabs[target].x) - - sc.GetPos() - (target <= first ? 1 : 2) - + st.margin - (target > 0 ? st.extendleft : 0); - if (IsVert()) - w.DrawImage(0, x - tsz.cx/2, tsz.cy, tsz.cx, dragimg); - else - w.DrawImage(x - tsz.cx/2, 0, tsz.cx, tsz.cy, dragimg); -/* int y = st.sel.top; - Color c(255, 0, 0); - int cy = sz.cy - y; - if (IsHorz()) { - w.DrawRect(x + 1, y, 2, cy, c); - w.DrawRect(x, y, 4, 1, c); - w.DrawRect(x, y + cy - 1, 4, 1, c); - } - else{ - w.DrawRect(y, x + 1, cy, 2, c); - w.DrawRect(y, x, 1, 4, c); - w.DrawRect(y + cy - 1, x, 1, 4, c); - } -*/ } - - } -} - -void TabBar::Scroll() -{ -$uvs: REPOSITORY DELETE - if (IsVisible()) scroller.Scroll(*this, IsVert() ? Point(0, sc.GetPos()) : Point(sc.GetPos(), 0)); -} - -int TabBar::GetWidth(int n) -{ - Tab &t = tabs[n]; - t.tsz = GetStdSize(t.data); - return QT_MARGIN * 2 + t.tsz.cx + (QT_SPACE + TabBarImg::CR0().GetSize().cx) * crosses; -} - -Size TabBar::GetStdSize(Value &q) -{ - if (display) - return display->GetStdSize(q); - else if (q.GetType() == STRING_V) - return GetTextSize((String)q, StdFont()); - else if (q.GetType() == WSTRING_V) - return GetTextSize((WString)q, StdFont()); - return GetTextSize("A Tab", StdFont()); -} - -TabBar& TabBar::Add(const Value &data, String group, bool make_active) -{ - return Insert(tabs.GetCount(), data, group, make_active); -} - -TabBar& TabBar::Insert(int ix, const Value &data, String group, bool make_active) -{ - Tab &t = tabs.Insert(ix); - - int cnt = tabs.GetCount() - 1; - t.data = data; - t.id = GetNextId(); - - int g = 0; - if (!group.IsEmpty()) { - g = FindGroup(group); - if (g < 0) { - NewGroup(group); - g = groups.GetCount() - 1; - } - } - t.group = groups[g].name; - MakeGroups(); - Repos(); - active = -1; - SetCursor(minmax(ix, 0, cnt)); - return *this; -} - -int TabBar::GetWidth()const -{ - if (!tabs.GetCount()) return 0; - int j = GetLast(); - return tabs[GetLast()].Right() + style[GetAlign()]->margin * 2; -} - -int TabBar::GetStyleHeight(const Style &s) -{ - return s.tabheight + s.sel.top /*+ style->sel.bottom */ + QT_SBSEPARATOR; -} - -void TabBar::Repos() -{ - if(!tabs.GetCount()) - return; - - String g = GetGroupName(); - - int j; - bool first = true; - j = 0; - for(int i = 0; i < tabs.GetCount(); i++) - j = TabPos(g, first, i, j, false); - if (inactiveshadow) - for(int i = 0; i < tabs.GetCount(); i++) - if (!tabs[i].visible) - j = TabPos(g, first, i, j, true); - SyncScrollBar(GetWidth()); -} - -int TabBar::TabPos(const String &g, bool &first, int i, int j, bool inactive) -{ - bool v = IsNull(g) ? true : g == tabs[i].group; - if(v) - { - tabs[i].x = first ? 0 : tabs[j].Right(); - j = i; - first = false; - } - else { - tabs[i].x = 0; - if (inactive) { - tabs[i].x = tabs[j].Right(); - return (j = i); - } - } - - tabs[i].visible = v; - tabs[i].y = 0; - tabs[i].cx = GetWidth(i); - tabs[i].cy = style[1]->tabheight + style[1]->sel.top; - return j; -} - -void TabBar::SyncScrollBar(int total) -{ - if (total > 0) - sc.SetTotal(total); - if (autoscrollhide) { - int h = GetHeight(); - bool v = GetFrameSize() > h; - bool nv = sc.IsScrollable(); - sc.Show(nv); - if (v != nv) - SetFrameSize((nv ? sc.GetFrameSize() : 0) + h, false); - } - else - sc.Show(); -} - -int TabBar::FindId(int id) const -{ - for(int i = 0; i < tabs.GetCount(); i++) - if(tabs[i].id == id) - return i; - return -1; -} - -int TabBar::GetNext(int n) const -{ - for(int i = n + 1; i < tabs.GetCount(); i++) - if(tabs[i].visible) - return i; - return -1; -} - -int TabBar::GetPrev(int n) const -{ - for(int i = n - 1; i >= 0; i--) - if(tabs[i].visible) - return i; - return -1; -} - -void TabBar::Clear() -{ - highlight = -1; - active = -1; - target = -1; - id = -1; - tabs.Clear(); - groups.Clear(); - NewGroup("All"); - group = 0; -$uvs: END REPOSITORY DELETE - Refresh(); -} - -$uvs: REPOSITORY INSERT -int TabBar::GetWidth(int n) -{ - Tab &t = tabs[n]; - t.tsz = GetStdSize(t.data); - return QT_MARGIN * 2 + t.tsz.cx + (QT_SPACE + TabBarImg::CR0().GetSize().cx) * crosses; -} - -Size TabBar::GetStdSize(Value &q) -{ - if (display) - return display->GetStdSize(q); - else if (q.GetType() == STRING_V) - return GetTextSize((String)q, StdFont()); - else if (q.GetType() == WSTRING_V) - return GetTextSize((WString)q, StdFont()); - return GetTextSize("A Tab", StdFont()); -} - -TabBar& TabBar::Add(const Value &data, String group, bool make_active) -{ - return Insert(tabs.GetCount(), data, group, make_active); -} - -TabBar& TabBar::Insert(int ix, const Value &data, String group, bool make_active) -{ - Tab &t = tabs.Insert(ix); - - int cnt = tabs.GetCount() - 1; - t.data = data; - t.id = GetNextId(); - - int g = 0; - if (!group.IsEmpty()) { - g = FindGroup(group); - if (g < 0) { - NewGroup(group); - g = groups.GetCount() - 1; -$uvs: END REPOSITORY INSERT -$uvs: REPOSITORY DELETE -TabBar& TabBar::Crosses(bool b) -{ - crosses = b; - Repos(); - return *this; -} - -TabBar& TabBar::Grouping(bool b) -{ - grouping = b; - return *this; -} - -TabBar& TabBar::AutoScrollHide(bool b) -{ - autoscrollhide = b; - SyncScrollBar(GetWidth()); - return *this; -} - -TabBar& TabBar::InactiveShadow(bool b) -{ - inactiveshadow = b; - if (b) Repos(); - return *this; -} - -void TabBar::FrameSet() -{ - int al = GetAlign(); - Ctrl::ClearFrames(); - sc.Clear(); - sc.SetFrameSize(QT_SBHEIGHT).SetAlign((al >= 2) ? al - 2 : al + 2); - sc <<= THISBACK(Scroll); - if (!sc.IsChild()) - AddFrame(sc); - - style[0] = &StyleLeft(); - style[1] = &StyleDefault(); - style[2] = &StyleRight(); - style[3] = &StyleBottom(); - - SyncScrollBar(0); -} - -void TabBar::ResetStyles() -{ - StyleLeft(); - StyleRight(); - StyleBottom(); -} - -void TabBar::FrameLayout(Rect& r) -{ - if (autoscrollhide && tabs.GetCount()) - SyncScrollBar(-1); - AlignedFrame::FrameLayout(r); -} - -int TabBar::Find(const Value &v) const -{ - for (int i = 0; i < tabs.GetCount(); i++) - if (tabs[i].data == v) - return i; - return -1; -} - -void TabBar::Set(int n, const Value &data, const String &group) -{ - ASSERT(n >= 0 && n < tabs.GetCount()); - tabs[n].data = data; - if (!IsNull(data)) - SetTabGroup(n, group); - else - Repos(); -} - -void TabBar::LeftDown(Point p, dword keyflags) -{ - if(keyflags & K_SHIFT) - { - highlight = -1; - Refresh(); - SetCapture(); - Fix(p); - oldp = p; - return; - } - - isctrl = keyflags & K_CTRL; - if(isctrl) - return; - - if(cross != -1) { - Value v = tabs[cross].data; - Close(cross); - WhenClose(v); - } - else if(highlight >= 0) { - SetCursor(highlight); - WhenCursor(); - } -} - -void TabBar::LeftUp(Point p, dword keyflags) -{ - ReleaseCapture(); -} - -void TabBar::RightDown(Point p, dword keyflags) -{ - MenuBar::Execute(THISBACK(ContextMenu), GetMousePos()); -} - -void TabBar::MiddleDown(Point p, dword keyflags) -{ - Close(highlight); -} - -void TabBar::MiddleUp(Point p, dword keyflags) -{ -} - -int TabBar::GetTargetTab(Point p) -{ - p.x += sc.GetPos(); - - int f = GetFirst(); - int l = GetLast(); - - if(tabs[f].visible && p.x < tabs[f].x + tabs[f].cx / 2) - return f; - - for(int i = l; i >= f; i--) - if(tabs[i].visible && p.x >= tabs[i].x + tabs[i].cx / 2) - return i == l ? i + 1 : GetNext(i); -// if(tabs[i].visible && p.x >= tabs[i].x && p.x <= tabs[i].x + tabs[i].cx) -// return i; - return -1; -} - -void TabBar::MouseWheel(Point p, int zdelta, dword keyflags) -{ - sc.AddPos(-zdelta / 4, true); - Scroll(); - MouseMove(p, 0); -} - -void TabBar::MouseMove(Point p, dword keyflags) -{ - Fix(p); - if(HasCapture()) - { - sc.AddPos(p.x - oldp.x, true); - oldp = p; - return; - } - - p.x += sc.GetPos() - style[1]->margin; - Size sz = GetSize(); - Fix(sz); - - int h = highlight; - bool iscross = false; - bool istab = false; - for(int i = 0; i < tabs.GetCount(); i++) - { - Point np(p.x + (i > 0 ? style[1]->extendleft : 0), p.y); - if(tabs[i].HasMouse(np)) - { - istab = true; - int h = sz.cy + (active == i ? 0 : style[1]->sel.top); - iscross = crosses ? tabs[i].HasMouseCross(np, h, GetAlign()) : false; - if(highlight != i || (iscross && cross != i)) - { - cross = iscross ? i : -1; - highlight = i; - WhenHighlight(); - Refresh(); - return; - } -$uvs: END REPOSITORY DELETE - } - } -$uvs: REPOSITORY INSERT - t.group = groups[g].name; -$uvs: END REPOSITORY INSERT -$uvs: REPOSITORY DELETE - - if(!istab && h >= 0) - { - highlight = -1; - WhenHighlight(); - Refresh(); - } - - if(!iscross && cross >= 0) - { - cross = -1; - Refresh(); - } -} - -void TabBar::MouseLeave() -{ - if(isdrag) - return; - highlight = -1; - cross = -1; - Refresh(); -} - -void TabBar::DragAndDrop(Point p, PasteClip& d) -{ - Fix(p); - int c = GetTargetTab(p); - int tab = isctrl ? highlight : active; - - if (&GetInternal(d) != this) return; - - bool sametab = c == tab || c == tab + 1; - bool internal = AcceptInternal(d, "tabs"); - - if(!sametab && d.IsAccepted()) - { - if(internal) - { - int id = tabs[active].id; - Tab t = tabs[tab]; - tabs.Insert(c, t); - tabs.Remove(tab + int(c < tab)); - active = FindId(id); - isdrag = false; - MakeGroups(); - Repos(); - return; - } - else if(d.IsPaste()) - { - CancelMode(); - return; - } - } - else - { - //d.Reject(); - //unfortunately after Reject DragLeave stops working until d is accepted - } - - if(c != target) - { - target = c; - Refresh(); - } -} - -void TabBar::CancelMode() -{ - isdrag = false; - dragimg.Clear(); - target = -1; - Refresh(); -} - -void TabBar::LeftDrag(Point p, dword keyflags) -{ - if(keyflags & K_SHIFT) - return; - if(highlight < 0) - return; - - isdrag = true; - DoDragAndDrop(InternalClip(*this, "tabs")); -} - -void TabBar::DragEnter() -{ -} - -void TabBar::DragLeave() -{ - target = -1; - dragimg.Clear(); - Refresh(); -} - -void TabBar::DragRepeat(Point p) -{ - if(target >= 0) - { - int dx = GetDragScroll(this, p, 16).x; - if(dx != 0) - sc.AddPos(dx); - } -} - -void TabBar::SetCursor(int n) -{ - if(tabs.GetCount() == 0) - return; - - if(n < 0) - { - n = max(0, FindId(GetGroupActive())); - active = -1; - } - - bool is_all = IsGroupAll(); - bool same_group = tabs[n].group == GetGroupName(); - - if((same_group || is_all) && active == n) - return; - - active = n; - - if(!is_all && !same_group) - { - SetGroup(tabs[n].group); - Repos(); - } - - SetGroupActive(tabs[n].id); - - int cx = tabs[n].x - sc.GetPos(); - if(cx < 0) - sc.AddPos(cx - 10); - else - { - Size sz = Ctrl::GetSize(); - Fix(sz); - cx = tabs[n].x + tabs[n].cx - sz.cx - sc.GetPos(); - if(cx > 0) - sc.AddPos(cx + 10); - } - if(HasMouse()) - MouseMove(GetMouseViewPos(), 0); - - UpdateActionRefresh(); -} - -void TabBar::SetTabGroup(int n, const String &group) -{ - ASSERT(n >= 0 && n < tabs.GetCount()); - int g = FindGroup(group); - if (g <= 0) - NewGroup(group); - else if (groups[g].active == tabs[n].id) - SetGroupActive(tabs[n].id); - tabs[n].group = group; -$uvs: END REPOSITORY DELETE - MakeGroups(); - Repos(); -$uvs: REPOSITORY INSERT - active = -1; - SetCursor(minmax(ix, 0, cnt)); - return *this; -} - -int TabBar::GetWidth()const -{ - if (!tabs.GetCount()) return 0; - int j = GetLast(); - return tabs[GetLast()].Right() + style[GetAlign()]->margin * 2; -} - -int TabBar::GetStyleHeight(const Style &s) -{ - return s.tabheight + s.sel.top /*+ style->sel.bottom */ + QT_SBSEPARATOR; -} - -void TabBar::Repos() -{ - if(!tabs.GetCount()) - return; - - String g = GetGroupName(); - - int j; - bool first = true; - j = 0; - for(int i = 0; i < tabs.GetCount(); i++) - j = TabPos(g, first, i, j, false); - if (inactiveshadow) - for(int i = 0; i < tabs.GetCount(); i++) - if (!tabs[i].visible) - j = TabPos(g, first, i, j, true); - SyncScrollBar(GetWidth()); -} - -int TabBar::TabPos(const String &g, bool &first, int i, int j, bool inactive) -{ - bool v = IsNull(g) ? true : g == tabs[i].group; - if(v) - { - tabs[i].x = first ? 0 : tabs[j].Right(); - j = i; - first = false; -$uvs: END REPOSITORY INSERT -$uvs: REPOSITORY DELETE -} - -void TabBar::Close(int n) -{ - if(tabs.GetCount() <= neverempty) - return; - - if(n == active) - { - int c = FindId(tabs[n].id); - int nc = GetNext(c); - if(nc < 0) - nc = max(0, GetPrev(c)); - SetGroupActive(tabs[nc].id); - } - sc.AddTotal(-tabs[n].cx); - tabs.Remove(n); - MakeGroups(); - Repos(); - SetCursor(-1); -} - -const TabBar::Style& TabBar::AlignStyle(int align, Style &s) -{ - Size sz(30, GetStyleHeight(s)); - for (int i = 0; i < 4; i++) s.first[i] = AlignValue(align, s.first[i], sz); - for (int i = 0; i < 4; i++) s.last[i] = AlignValue(align, s.last[i], sz); - for (int i = 0; i < 4; i++) s.normal[i] = AlignValue(align, s.normal[i], sz); - for (int i = 0; i < 4; i++) s.both[i] = AlignValue(align, s.both[i], sz); - return s; -} - -const TabBar::Style& TabBar::StyleLeft() -{ - leftstyle = StyleDefault(); - return AlignStyle(AlignedFrame::LEFT, leftstyle); -} - -const TabBar::Style& TabBar::StyleRight() -{ - rightstyle = StyleDefault(); - return AlignStyle(AlignedFrame::RIGHT, rightstyle); -} - -const TabBar::Style& TabBar::StyleBottom() -{ - bottomstyle = StyleDefault(); - return AlignStyle(AlignedFrame::BOTTOM, bottomstyle); -} - -void TabBar::Serialize(Stream& s) -{ - int version = 0x00; - int cnt; - if (s.IsLoading()) Clear(); - - s / version / group / highlight / active; - - if (s.IsLoading()) { - cnt = groups.GetCount(); - s / cnt; - for (int i = 1; i < groups.GetCount(); i++) { - Group &g = groups[i]; - s % g.data / g.active; - } - cnt = tabs.GetCount(); - s / cnt; - for (int i = 0; i < tabs.GetCount(); i++) { - Tab &t = tabs[i]; - int g = FindGroup(t.group); - s % t.data / t.id / g; - } -$uvs: END REPOSITORY DELETE - } - else { -$uvs: REPOSITORY INSERT - tabs[i].x = 0; - if (inactive) { - tabs[i].x = tabs[j].Right(); - return (j = i); - } - } - - tabs[i].visible = v; - tabs[i].y = 0; - tabs[i].cx = GetWidth(i); - tabs[i].cy = style[1]->tabheight + style[1]->sel.top; - return j; -} - -void TabBar::SyncScrollBar(int total) -{ - if (total > 0) - sc.SetTotal(total); - if (autoscrollhide) { - int h = GetHeight(); - bool v = GetFrameSize() > h; - bool nv = sc.IsScrollable(); - sc.Show(nv); - if (v != nv) - SetFrameSize((nv ? sc.GetFrameSize() : 0) + h, false); - } - else - sc.Show(); -} - -int TabBar::FindId(int id) const -{ - for(int i = 0; i < tabs.GetCount(); i++) - if(tabs[i].id == id) - return i; - return -1; -} - -int TabBar::GetNext(int n) const -{ - for(int i = n + 1; i < tabs.GetCount(); i++) - if(tabs[i].visible) - return i; - return -1; -} - -int TabBar::GetPrev(int n) const -{ - for(int i = n - 1; i >= 0; i--) - if(tabs[i].visible) - return i; - return -1; -} - -void TabBar::Clear() -{ - highlight = -1; - active = -1; - target = -1; - id = -1; - tabs.Clear(); - groups.Clear(); - NewGroup("All"); - group = 0; - Refresh(); -} - -TabBar& TabBar::Crosses(bool b) -{ - crosses = b; - Repos(); - return *this; -} - -TabBar& TabBar::Grouping(bool b) -{ - grouping = b; - return *this; -} - -TabBar& TabBar::AutoScrollHide(bool b) -{ - autoscrollhide = b; - SyncScrollBar(GetWidth()); - return *this; -} - -TabBar& TabBar::InactiveShadow(bool b) -{ - inactiveshadow = b; - if (b) Repos(); - return *this; -} - -void TabBar::FrameSet() -{ - int al = GetAlign(); - Ctrl::ClearFrames(); - sc.Clear(); - sc.SetFrameSize(QT_SBHEIGHT).SetAlign((al >= 2) ? al - 2 : al + 2); - sc <<= THISBACK(Scroll); - if (!sc.IsChild()) - AddFrame(sc); - - style[0] = &StyleLeft(); - style[1] = &StyleDefault(); - style[2] = &StyleRight(); - style[3] = &StyleBottom(); - - SyncScrollBar(0); -} - -void TabBar::ResetStyles() -{ - StyleLeft(); - StyleRight(); - StyleBottom(); -} - -void TabBar::FrameLayout(Rect& r) -{ - if (autoscrollhide && tabs.GetCount()) - SyncScrollBar(-1); - AlignedFrame::FrameLayout(r); -} - -int TabBar::Find(const Value &v) const -{ - for (int i = 0; i < tabs.GetCount(); i++) - if (tabs[i].data == v) - return i; - return -1; -} - -void TabBar::Set(int n, const Value &data, const String &group) -{ - ASSERT(n >= 0 && n < tabs.GetCount()); - tabs[n].data = data; - if (!IsNull(data)) - SetTabGroup(n, group); - else - Repos(); -} - -void TabBar::LeftDown(Point p, dword keyflags) -{ - if(keyflags & K_SHIFT) - { - highlight = -1; - Refresh(); - SetCapture(); - Fix(p); - oldp = p; - return; - } - - isctrl = keyflags & K_CTRL; - if(isctrl) - return; - - if(cross != -1) { - Value v = tabs[cross].data; - Close(cross); - WhenClose(v); - } - else if(highlight >= 0) { - SetCursor(highlight); - WhenCursor(); -$uvs: END REPOSITORY INSERT -$uvs: REPOSITORY DELETE - s / cnt; - groups.SetCount(cnt); - for (int i = 1; i < cnt; i++) { - Group &g = groups[i]; - s % g.data / g.active; - } - s / cnt; - tabs.SetCount(cnt); - for (int i = 0; i < tabs.GetCount(); i++) { - int g; - Tab &t = tabs[i]; - s % t.data / t.id / g; - t.group = groups[g].name; - } - MakeGroups(); - Repos(); -$uvs: END REPOSITORY DELETE - } -} - -$uvs: REPOSITORY INSERT -void TabBar::LeftUp(Point p, dword keyflags) -{ - ReleaseCapture(); -} - -void TabBar::RightDown(Point p, dword keyflags) -{ - MenuBar::Execute(THISBACK(ContextMenu), GetMousePos()); -} - -void TabBar::MiddleDown(Point p, dword keyflags) -{ - Close(highlight); -} - -void TabBar::MiddleUp(Point p, dword keyflags) -{ -} - -int TabBar::GetTargetTab(Point p) -{ - p.x += sc.GetPos(); - - int f = GetFirst(); - int l = GetLast(); - - if(tabs[f].visible && p.x < tabs[f].x + tabs[f].cx / 2) - return f; - - for(int i = l; i >= f; i--) - if(tabs[i].visible && p.x >= tabs[i].x + tabs[i].cx / 2) - return i == l ? i + 1 : GetNext(i); -// if(tabs[i].visible && p.x >= tabs[i].x && p.x <= tabs[i].x + tabs[i].cx) -// return i; - return -1; -} - -void TabBar::MouseWheel(Point p, int zdelta, dword keyflags) -{ - sc.AddPos(-zdelta / 4, true); - Scroll(); - MouseMove(p, 0); -} - -void TabBar::MouseMove(Point p, dword keyflags) -{ - Fix(p); - if(HasCapture()) - { - sc.AddPos(p.x - oldp.x, true); - oldp = p; - return; - } - - p.x += sc.GetPos() - style[1]->margin; - Size sz = GetSize(); - Fix(sz); - - int h = highlight; - bool iscross = false; - bool istab = false; - for(int i = 0; i < tabs.GetCount(); i++) - { - Point np(p.x + (i > 0 ? style[1]->extendleft : 0), p.y); - if(tabs[i].HasMouse(np)) - { - istab = true; - int h = sz.cy + (active == i ? 0 : style[1]->sel.top); - iscross = crosses ? tabs[i].HasMouseCross(np, h, GetAlign()) : false; - if(highlight != i || (iscross && cross != i)) - { - cross = iscross ? i : -1; - highlight = i; - WhenHighlight(); - Refresh(); - return; - } - } - } - - if(!istab && h >= 0) - { - highlight = -1; - WhenHighlight(); - Refresh(); - } - - if(!iscross && cross >= 0) - { - cross = -1; - Refresh(); - } -} - -void TabBar::MouseLeave() -{ - if(isdrag) - return; - highlight = -1; - cross = -1; - Refresh(); -} - -void TabBar::DragAndDrop(Point p, PasteClip& d) -{ - Fix(p); - int c = GetTargetTab(p); - int tab = isctrl ? highlight : active; - - if (&GetInternal(d) != this) return; - - bool sametab = c == tab || c == tab + 1; - bool internal = AcceptInternal(d, "tabs"); - - if(!sametab && d.IsAccepted()) - { - if(internal) - { - int id = tabs[active].id; - Tab t = tabs[tab]; - tabs.Insert(c, t); - tabs.Remove(tab + int(c < tab)); - active = FindId(id); - isdrag = false; - MakeGroups(); - Repos(); - return; - } - else if(d.IsPaste()) - { - CancelMode(); - return; - } - } - else - { - //d.Reject(); - //unfortunately after Reject DragLeave stops working until d is accepted - } - - if(c != target) - { - target = c; - Refresh(); - } -} - -void TabBar::CancelMode() -{ - isdrag = false; - dragimg.Clear(); - target = -1; - Refresh(); -} - -void TabBar::LeftDrag(Point p, dword keyflags) -{ - if(keyflags & K_SHIFT) - return; - if(highlight < 0) - return; - - isdrag = true; - DoDragAndDrop(InternalClip(*this, "tabs")); -} - -void TabBar::DragEnter() -{ -} - -void TabBar::DragLeave() -{ - target = -1; - dragimg.Clear(); - Refresh(); -} - -void TabBar::DragRepeat(Point p) -{ - if(target >= 0) - { - int dx = GetDragScroll(this, p, 16).x; - if(dx != 0) - sc.AddPos(dx); - } -} - -void TabBar::SetCursor(int n) -{ - if(tabs.GetCount() == 0) - return; - - if(n < 0) - { - n = max(0, FindId(GetGroupActive())); - active = -1; - } - - bool is_all = IsGroupAll(); - bool same_group = tabs[n].group == GetGroupName(); - - if((same_group || is_all) && active == n) - return; - - active = n; - - if(!is_all && !same_group) - { - SetGroup(tabs[n].group); - Repos(); - } - - SetGroupActive(tabs[n].id); - - int cx = tabs[n].x - sc.GetPos(); - if(cx < 0) - sc.AddPos(cx - 10); - else - { - Size sz = Ctrl::GetSize(); - Fix(sz); - cx = tabs[n].x + tabs[n].cx - sz.cx - sc.GetPos(); - if(cx > 0) - sc.AddPos(cx + 10); - } - if(HasMouse()) - MouseMove(GetMouseViewPos(), 0); - - UpdateActionRefresh(); -} - -void TabBar::SetTabGroup(int n, const String &group) -{ - ASSERT(n >= 0 && n < tabs.GetCount()); - int g = FindGroup(group); - if (g <= 0) - NewGroup(group); - else if (groups[g].active == tabs[n].id) - SetGroupActive(tabs[n].id); - tabs[n].group = group; - MakeGroups(); - Repos(); -} - -void TabBar::Close(int n) -{ - if(tabs.GetCount() <= neverempty) - return; - - if(n == active) - { - int c = FindId(tabs[n].id); - int nc = GetNext(c); - if(nc < 0) - nc = max(0, GetPrev(c)); - SetGroupActive(tabs[nc].id); - } - sc.AddTotal(-tabs[n].cx); - tabs.Remove(n); - MakeGroups(); - Repos(); - SetCursor(-1); -} - -const TabBar::Style& TabBar::AlignStyle(int align, Style &s) -{ - Size sz(30, GetStyleHeight(s)); - for (int i = 0; i < 4; i++) s.first[i] = AlignValue(align, s.first[i], sz); - for (int i = 0; i < 4; i++) s.last[i] = AlignValue(align, s.last[i], sz); - for (int i = 0; i < 4; i++) s.normal[i] = AlignValue(align, s.normal[i], sz); - for (int i = 0; i < 4; i++) s.both[i] = AlignValue(align, s.both[i], sz); - return s; -} - -const TabBar::Style& TabBar::StyleLeft() -{ - leftstyle = StyleDefault(); - return AlignStyle(AlignedFrame::LEFT, leftstyle); -} - -const TabBar::Style& TabBar::StyleRight() -{ - rightstyle = StyleDefault(); - return AlignStyle(AlignedFrame::RIGHT, rightstyle); -} - -const TabBar::Style& TabBar::StyleBottom() -{ - bottomstyle = StyleDefault(); - return AlignStyle(AlignedFrame::BOTTOM, bottomstyle); -} - -void TabBar::Serialize(Stream& s) -{ - int version = 0x00; - int cnt; - if (s.IsLoading()) Clear(); - - s / version / group / highlight / active; - - if (s.IsLoading()) { - cnt = groups.GetCount(); - s / cnt; - for (int i = 1; i < groups.GetCount(); i++) { - Group &g = groups[i]; - s % g.data / g.active; - } - cnt = tabs.GetCount(); - s / cnt; - for (int i = 0; i < tabs.GetCount(); i++) { - Tab &t = tabs[i]; - int g = FindGroup(t.group); - s % t.data / t.id / g; - } - } - else { - s / cnt; - groups.SetCount(cnt); - for (int i = 1; i < cnt; i++) { - Group &g = groups[i]; - s % g.data / g.active; - } - s / cnt; - tabs.SetCount(cnt); - for (int i = 0; i < tabs.GetCount(); i++) { - int g; - Tab &t = tabs[i]; - s % t.data / t.id / g; - t.group = groups[g].name; - } - MakeGroups(); - Repos(); - } -} - -$uvs: END REPOSITORY INSERT diff --git a/uppdev/TabBar/TabBar.h b/uppdev/TabBar/TabBar.h deleted file mode 100644 index 63a591944..000000000 --- a/uppdev/TabBar/TabBar.h +++ /dev/null @@ -1,304 +0,0 @@ -$uvs: PENDING CONFLICT -#ifndef _TabBar_TabBar_h_ -#define _TabBar_TabBar_h_ - -#include -using namespace Upp; - -#define IMAGECLASS TabBarImg -#define IMAGEFILE -#include - -struct AlignedFrame : FrameCtrl -{ - int layout; - int framesize; - int border; -public: - enum - { - LEFT = 0, - TOP = 1, - RIGHT = 2, - BOTTOM = 3 - }; - - AlignedFrame() : border(0), framesize(0), layout(TOP) {} - - virtual void FrameLayout(Rect &r); - virtual void FrameAddSize(Size& sz); - virtual void FramePaint(Draw& w, const Rect& r); - - bool IsVert() const { return (layout & 1) == 0; } - bool IsHorz() const { return layout & 1; } - bool IsTL() const { return layout < 2; } - bool IsBR() const { return layout >= 2; } - - AlignedFrame& SetAlign(int align) { layout = align; FrameSet(); RefreshParentLayout(); return *this; } - AlignedFrame& SetLeft() { return SetAlign(LEFT); } - AlignedFrame& SetTop() { return SetAlign(TOP); } - AlignedFrame& SetRight() { return SetAlign(RIGHT); } - AlignedFrame& SetBottom() { return SetAlign(BOTTOM); } - AlignedFrame& SetFrameSize(int sz, bool refresh = true); - - int GetAlign() const { return layout; } - int GetFrameSize() const { return framesize; } - int GetBorder() const { return border; } -protected: - void Fix(Size& sz); - void Fix(Point& p); - - bool HasBorder() { return border >= 0; } - AlignedFrame& SetBorder(int _border) { border = _border; } - - virtual void FrameSet() { } -}; - -class TabScrollBar : public AlignedFrame -{ - private: - int total; - double pos, ps; - int new_pos; - int old_pos; - double start_pos; - double size; - double cs, ics; - virtual void UpdatePos(bool update = true); - void RefreshScroll(); - bool ready; - Size sz; - - public: - TabScrollBar(); - - virtual void Paint(Draw &w); - virtual void LeftDown(Point p, dword keyflags); - virtual void LeftUp(Point p, dword keyflags); - virtual void MouseMove(Point p, dword keyflags); - virtual void MouseWheel(Point p, int zdelta, dword keyflags); - virtual void Layout(); - - int GetPos() const; - void SetPos(int p, bool dontscale = false); - void AddPos(int p, bool dontscale = false); - int GetTotal() const; - void AddTotal(int t); - void SetTotal(int t); - void GoEnd(); - void GoBegin(); - void Clear(); - void Set(const TabScrollBar& t); - bool IsScrollable() const; - Callback WhenScroll; -}; - -class TabBar : public AlignedFrame -{ -public: - struct Style : public TabCtrl::Style { }; - -protected: - enum - { - QT_MARGIN = 6, - QT_SPACE = 10, - QT_SBHEIGHT = 4, - QT_SBSEPARATOR = 1, - QT_FILEICON = 16, - QT_SPACEICON = 5 - }; - struct Tab : Moveable - { - Value data; - String group; - bool visible; - int x, cx; - int y, cy; - int id; - Size tsz; - Tab() : visible(true), id(-1) - {} - int Right() const { return x + cx; } - bool HasMouse(const Point& p) const; - bool HasMouseCross(const Point& p, int h, int type) const; - }; - - struct Group : Moveable - { - Group() {} - String name; - Value data; - int active; - int count; - int first; - int last; - }; -private: - int id; - TabScrollBar sc; -$uvs: REPOSITORY DELETE - Scroller scroller; - void Scroll(); -$uvs: END REPOSITORY DELETE - - Vector groups; - Vector tabs; - int highlight; - int active; - int target; - int cross; - bool crosses:1; - bool isctrl:1; - bool isdrag:1; - bool grouping:1; - bool autoscrollhide:1; - bool nosel:1; - bool nohl:1; - bool inactiveshadow:1; - int neverempty; - Point mouse, oldp; - int group; - const Display *display; - Image dragimg; - - static Style leftstyle, rightstyle, bottomstyle; - const Style *style[4]; - - void DrawTab(Draw &w, const Style &s, const Size &sz, int i, bool enable); - int TabPos(const String &g, bool &first, int i, int j, bool inactive); - void SyncScrollBar(int total); -$uvs: REPOSITORY INSERT - void Scroll(); -$uvs: END REPOSITORY INSERT - - int FindId(int id) const; - int GetNext(int n) const; - int GetPrev(int n) const; - - int GetWidth(int n); - int GetWidth() const; - int GetHeight() const { return TabBar::GetStyleHeight(*style[TOP]); } - static int GetStyleHeight(const Style& s); - - int GetNextId(); - int GetScrollPos() { return sc.GetPos(); } - - static Value AlignValue(int align, const Value &v, const Size &isz); -protected: - virtual void Paint(Draw &w); - virtual void LeftDown(Point p, dword keysflags); - virtual void LeftUp(Point p, dword keysflags); - virtual void RightDown(Point p, dword keyflags); - virtual void MiddleDown(Point p, dword keyflags); - virtual void MiddleUp(Point p, dword keyflags); - virtual void MouseMove(Point p, dword keysflags); - virtual void MouseLeave(); - virtual void DragAndDrop(Point p, PasteClip& d); - virtual void LeftDrag(Point p, dword keyflags); - virtual void DragEnter(); - virtual void DragLeave(); - virtual void DragRepeat(Point p); - virtual void CancelMode(); - virtual void MouseWheel(Point p, int zdelta, dword keyflags); - virtual void FrameSet(); - virtual void FrameLayout(Rect& r); - - void Repos(); - void MakeGroups(); - int FindGroup(const String& g) const; - void CloseAll(); - void DoGrouping(int n); - void DoCloseGroup(int n); - void NewGroup(const String &name, const Value &data = Value()); - - // Sub-class display overide & helpers - virtual void DrawTabData(Draw& w, Point p, const Size &sz, const Value& q, const Font &font, - Color ink, dword style); - virtual Size GetStdSize(Value &q); - - int TextAngle() { return AlignedFrame::IsVert() ? (GetAlign() == LEFT ? 900 : 2700) : 0; } - void TabCenterText(Point &p, const Size &sz, const Font &f) { TabCenter(p, sz, f.GetHeight()); } - void TabCenter(Point &p, const Size &sz, const Size &hsz) { TabCenter(p, sz, IsVert() ? sz.cx : sz.cy); } - void TabCenter(Point &p, const Size &sz, int h); - - int GetTargetTab(Point p); - - const Style &GetStyle() { return *style[GetAlign()]; } - - // Sub-class menu overrides - virtual void ContextMenu(Bar& bar); - virtual void GroupMenu(Bar &bar, int n); -public: - typedef TabBar CLASSNAME; - - Callback WhenHighlight; - Callback WhenCursor; - Callback1 WhenClose; -$uvs: REPOSITORY INSERT - Callback WhenCloseAll; -$uvs: END REPOSITORY INSERT - - TabBar(); - - TabBar& Add(const Value &data, bool make_active = false) { return Add(data, Null, make_active); } - TabBar& Add(const Value &data, String group = Null, bool make_active = false); - TabBar& Insert(int ix, const Value &data, bool make_active = false) { return Insert(ix, data, Null, make_active); } - TabBar& Insert(int ix, const Value &data, String group = Null, bool make_active = false); - void Close(int n); - void Clear(); - - TabBar& Crosses(bool b = true); - TabBar& Grouping(bool b = true); - TabBar& AutoScrollHide(bool b = true); - TabBar& InactiveShadow(bool b = true); - - TabBar& SetDisplay(const Display &d) { display = &d; Refresh(); } - - int Find(const Value &v) const; - - Value Get(int n) const { ASSERT(n >= 0 && n < tabs.GetCount()); return tabs[n].data;} - void Set(int n, const Value &data, const String &group = Null); - virtual Value GetData() const { return HasCursor() ? Get(active) : Value(); } - virtual void SetData(const Value &data) { int n = Find(data); if (n >= 0) SetCursor(n); } - - Value GetGroupData(const String &s) const { return GetGroupData(FindGroup(s)); } - void SetGroupData(const String &s, const Value &data) { SetGroupData(FindGroup(s), data); } - Value GetGroupData(int n) const { ASSERT(n >= 0 && n < groups.GetCount()); return groups[n].data; } - void SetGroupData(int n, const Value &data) { ASSERT(n >= 0 && n < groups.GetCount()); groups[n].data = data;} - - String GetGroupName() const { return group == 0 ? Null : groups[group].name; } - int SetGroup(const String &s) { group = max(0, FindGroup(s)); return group; } - int SetGroup(int c) { group = c; return group; } - int GetGroup() const { return group; } - void SetGroupActive(int id) { groups[group].active = id; } - int GetGroupActive() const { return groups[group].active; } - int GetFirst() const { return groups[group].first; } - int GetLast() const { return groups[group].last; } - bool IsGroupAll() const { return group == 0; } - int GetCount() const { return tabs.GetCount(); } - int GetCursor() const { return active; } - int GetHighlight() const { return highlight; } - void SetCursor(int n); - void SetTabGroup(int n, const String &group); - - bool HasCursor() const { return active >= 0; } - bool HasHighlight() const { return highlight >= 0; } - - TabBar& NeverEmpty(int limit = 1) { neverempty = max(limit, 1); Refresh(); return *this; } - TabBar& CanEmpty() { neverempty = 0; Refresh(); return *this; } - - TabBar& SetStyle(int align, const Style& s) { ASSERT(align >= 0 && align < 4); style[align] = &s; Refresh(); return *this; } - static const Style& StyleDefault(); - static const Style& StyleLeft(); - static const Style& StyleRight(); - static const Style& StyleBottom(); - static const Style& AlignStyle(int align, Style &s); - static void ResetStyles(); - - virtual void Serialize(Stream& s); -}; - - -#endif - diff --git a/uppdev/TabBar/TabBar.iml b/uppdev/TabBar/TabBar.iml deleted file mode 100644 index 163010da5..000000000 --- a/uppdev/TabBar/TabBar.iml +++ /dev/null @@ -1,55 +0,0 @@ -PREMULTIPLIED -IMAGE_ID(CR0) -IMAGE_ID(CR1) -IMAGE_ID(CR2) -IMAGE_ID(CHK) - -IMAGE_BEGIN_DATA -IMAGE_DATA(120,156,133,149,121,76,84,87,20,198,95,210,52,53,68,77,91,180,166,105,82,109,83,211,63,154,52,237,63,141,166,168) -IMAGE_DATA(129,56,196,193,48,136,138,45,24,132,68,17,65,193,22,44,21,171,6,37,197,165,165,173,184,212,186,33,251,38,235,176) -IMAGE_DATA(200,206,12,251,32,195,34,219,12,195,148,89,217,247,34,139,166,95,207,189,48,8,41,226,157,252,114,206,123,231,251,238) -IMAGE_DATA(254,50,194,90,97,173,176,70,120,79,96,205,223,239,120,200,205,235,17,210,178,210,98,20,21,230,175,72,105,113,33,152) -IMAGE_DATA(214,226,145,203,74,161,234,104,131,182,171,19,93,26,245,178,176,90,167,186,3,76,59,55,78,17,26,27,158,160,185,73) -IMAGE_DATA(137,166,198,250,21,177,104,138,139,242,57,204,215,160,172,227,212,63,169,229,53,101,189,98,225,221,98,152,86,46,43,89) -IMAGE_DATA(226,99,218,238,191,53,232,49,27,22,188,38,163,142,195,52,22,100,101,197,200,205,149,162,158,234,79,104,28,37,121,141) -IMAGE_DATA(164,49,147,143,69,157,78,203,115,134,66,81,13,25,141,83,87,87,131,34,26,43,61,53,5,117,181,213,168,173,174,68) -IMAGE_DATA(77,85,5,143,250,110,45,140,250,238,5,216,62,102,103,101,32,47,71,202,201,202,72,67,74,114,2,106,107,42,81,93) -IMAGE_DATA(85,206,169,170,148,211,254,169,160,167,177,24,108,222,133,5,121,200,127,156,195,99,81,225,99,164,167,165,32,62,46,154) -IMAGE_DATA(235,43,43,100,220,211,169,110,167,61,87,115,44,57,235,199,178,23,165,37,133,72,125,148,132,152,232,72,174,175,40,47) -IMAGE_DATA(227,181,167,205,13,92,207,250,205,150,102,208,185,182,114,216,121,49,15,139,108,142,49,81,145,168,144,151,161,156,206,179) -IMAGE_DATA(48,63,143,175,151,69,182,14,22,115,179,179,32,205,76,71,81,193,99,148,149,20,65,70,247,234,81,114,34,18,19,98) -IMAGE_DATA(249,248,37,197,5,200,163,189,205,201,206,68,110,78,22,95,15,27,147,189,103,117,203,120,236,12,226,98,163,248,157,73) -IMAGE_DATA(74,140,227,207,139,231,194,158,217,188,203,229,165,75,200,204,72,93,114,71,19,227,99,249,122,151,35,45,53,153,147,16) -IMAGE_DATA(31,179,224,17,216,199,177,184,5,29,57,28,162,58,236,141,86,71,231,21,105,63,232,1,166,181,120,212,190,126,24,174) -IMAGE_DATA(168,197,120,107,39,198,91,84,203,67,181,81,69,3,212,62,39,184,183,195,235,24,204,49,169,232,73,206,134,57,49,107) -IMAGE_DATA(142,248,204,151,121,194,60,148,247,36,73,41,74,209,230,226,134,150,61,46,48,197,100,192,120,63,137,163,255,51,150,116) -IMAGE_DATA(153,48,220,77,128,225,94,34,140,15,146,57,60,103,154,168,84,116,28,243,67,235,158,253,228,75,167,26,121,110,199,226) -IMAGE_DATA(31,173,14,207,167,167,168,223,76,122,142,193,244,232,24,199,248,144,252,15,83,96,140,78,131,202,235,56,170,36,78,252) -IMAGE_DATA(217,112,55,14,198,184,52,204,76,61,195,243,231,179,152,165,56,53,56,200,115,134,246,175,104,104,252,206,195,120,43,10) -IMAGE_DATA(202,163,62,200,18,59,192,116,39,14,250,155,145,232,142,184,143,214,168,88,76,79,78,98,118,102,102,1,121,216,175,80) -IMAGE_DATA(218,56,66,189,237,0,52,54,251,81,236,224,140,104,145,61,204,215,110,67,31,126,157,136,128,238,82,56,134,77,38,76) -IMAGE_DATA(61,155,226,140,143,140,160,205,205,11,134,237,180,30,145,43,250,8,169,88,130,8,59,59,244,144,86,31,122,25,250,159) -IMAGE_DATA(175,160,95,167,71,255,192,16,6,135,70,208,99,50,99,128,242,129,158,62,12,122,5,98,84,228,130,113,177,43,146,119) -IMAGE_DATA(57,32,116,187,13,122,130,207,65,31,20,12,109,224,105,180,42,155,160,39,125,193,217,80,228,126,115,8,218,110,29,52) -IMAGE_DATA(132,214,235,36,198,68,7,48,65,190,7,59,69,8,217,97,131,190,227,254,48,208,121,182,57,123,34,89,36,65,118,240) -IMAGE_DATA(121,52,219,56,241,185,229,122,120,35,197,253,40,140,118,206,24,19,127,59,231,19,137,112,197,201,17,90,103,119,232,157) -IMAGE_DATA(61,208,184,205,21,138,173,174,80,126,237,66,123,224,10,147,173,43,134,236,14,160,143,24,163,117,141,18,19,98,55,132) -IMAGE_DATA(217,218,242,59,115,195,222,22,3,251,157,209,235,43,129,201,95,130,190,239,36,24,10,144,96,44,80,130,201,31,28,241) -IMAGE_DATA(204,194,41,39,164,237,19,45,185,163,23,197,34,220,219,45,194,157,221,59,113,199,113,39,238,82,188,47,177,195,3,199) -IMAGE_DATA(57,30,82,30,182,195,118,193,243,191,143,227,86,96,64,124,237,71,155,32,19,132,21,169,92,191,30,76,107,241,40,86) -IMAGE_DATA(175,67,111,124,6,134,229,117,24,46,85,44,15,213,6,50,242,161,176,178,230,222,154,77,155,160,9,12,69,215,185,223) -IMAGE_DATA(208,117,230,151,57,78,95,125,153,7,207,195,242,179,225,20,195,81,110,101,5,57,141,175,9,188,4,149,207,89,78,187) -IMAGE_DATA(199,41,210,93,69,135,87,48,125,4,63,65,229,123,142,195,115,170,171,191,15,69,205,170,117,40,183,248,168,214,238,249) -IMAGE_DATA(35,38,154,218,241,239,204,44,239,191,221,51,8,179,195,35,28,181,127,8,212,39,47,64,29,16,6,197,27,214,72,37) -IMAGE_DATA(95,23,245,161,242,14,134,230,244,37,188,160,75,205,26,243,206,244,246,195,210,154,143,4,161,113,195,22,116,121,4,34) -IMAGE_DATA(255,205,183,241,59,249,180,62,103,160,242,12,64,187,187,31,42,233,242,89,188,150,150,184,107,15,10,72,215,64,52,17) -IMAGE_DATA(145,68,16,209,125,208,11,170,125,135,160,218,235,142,14,241,62,12,233,186,233,3,124,193,153,24,25,67,181,176,10,93) -IMAGE_DATA(172,127,194,68,252,65,184,17,122,241,94,168,236,28,160,178,119,132,89,77,255,140,253,67,232,167,53,233,117,6,244,82) -IMAGE_DATA(222,107,52,163,111,213,102,140,144,118,130,184,64,216,18,134,47,183,64,253,217,151,120,186,249,115,84,22,203,160,38,253) -IMAGE_DATA(189,175,236,112,131,106,45,29,106,52,17,173,86,27,49,78,207,147,196,73,194,134,141,189,225,67,104,172,223,71,13,229) -IMAGE_DATA(23,137,107,95,108,229,247,131,205,237,166,176,6,161,194,106,158,47,246,237,94,103,141,22,138,106,162,132,200,37,44,123) -IMAGE_DATA(192,214,51,48,191,38,230,25,153,247,217,19,236,206,28,162,216,75,24,223,37,237,7,164,219,72,250,143,73,251,137,128) -IMAGE_DATA(233,79,5,204,88,216,44,224,242,188,199,114,71,183,211,221,241,165,119,222,196,49,194,135,56,65,248,207,207,43,128,16) -IMAGE_DATA(45,242,8,111,209,111,173,240,142,240,154,134,21,222,99,153,58,150,97,57,253,171,116,175,235,255,149,243,250,15,56,206) -IMAGE_DATA(131,36,0,0,0,0,0,0,0,0,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(1504, 4) diff --git a/uppdev/TabBar/TabBar.upp b/uppdev/TabBar/TabBar.upp deleted file mode 100644 index c2eabb90f..000000000 --- a/uppdev/TabBar/TabBar.upp +++ /dev/null @@ -1,5 +0,0 @@ -file - TabBar.h, - TabBar.cpp, - TabBar.iml; - diff --git a/uppdev/TabBar/init b/uppdev/TabBar/init deleted file mode 100644 index 30f5d2c3f..000000000 --- a/uppdev/TabBar/init +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef _TabBar_icpp_init_stub -#define _TabBar_icpp_init_stub -#endif diff --git a/uppdev/TextDiff/main.cpp b/uppdev/TextDiff/main.cpp index eaf9d4cc0..c29e7b1c2 100644 --- a/uppdev/TextDiff/main.cpp +++ b/uppdev/TextDiff/main.cpp @@ -4,9 +4,7 @@ using namespace Upp; GUI_APP_MAIN { - TopWindow win; - TextDiffCtrl ctrl; - win.Add(ctrl.SizePos()); - ctrl.Set(LoadFile("C:/u/upp.src/uppdev/AssistTest/main.cpp"), LoadFile("C:/u/upp.src/uppdev/ArrayCtrl/main.cpp")); - win.Run(); + DirDiffDlg dlg; + + dlg.Run(); } diff --git a/uppdev/Vector/Vector.cpp b/uppdev/Vector/Vector.cpp index 22b392f86..b5d8f9749 100644 --- a/uppdev/Vector/Vector.cpp +++ b/uppdev/Vector/Vector.cpp @@ -1,5 +1,14 @@ #include +using namespace Upp; + +Vector Test() +{ + Vector x; + x << 1 << 2 << 3; + return pick(x); +} + CONSOLE_APP_MAIN { Vector test; @@ -9,4 +18,15 @@ CONSOLE_APP_MAIN test.Add("5"); test.Add("4"); DUMPC(test); + + Vector b = pick(test); + + for(auto x: b) + DLOG(x); + + DDUMP(__cplusplus); + +#ifdef CPP_11 + LOG("C++ 11 active"); +#endif } diff --git a/uppdev/Vector/Vector.upp b/uppdev/Vector/Vector.upp index 9d87e9c87..d4f03b91f 100644 --- a/uppdev/Vector/Vector.upp +++ b/uppdev/Vector/Vector.upp @@ -1,7 +1,9 @@ -uses Core; - -file - "Vector.cpp"; - -mainconfig - "" = "CONSOLE ST"; +uses + Core; + +file + Vector.cpp; + +mainconfig + "" = "CONSOLE ST"; + diff --git a/uppdev/Vector/init b/uppdev/Vector/init new file mode 100644 index 000000000..afdc93a8d --- /dev/null +++ b/uppdev/Vector/init @@ -0,0 +1,4 @@ +#ifndef _Vector_icpp_init_stub +#define _Vector_icpp_init_stub +#include "Core/init" +#endif diff --git a/uppsrc/Core/InMap.hpp b/uppsrc/Core/InMap.hpp new file mode 100644 index 000000000..8dc5f9d7d --- /dev/null +++ b/uppsrc/Core/InMap.hpp @@ -0,0 +1,262 @@ +template +int SortedIndex::FindAdd(const T& key) +{ + int i = FindLowerBound(key); + if(i == GetCount() || Less()(key, iv[i])) + iv.Insert(i, key); + return i; +} + +template +int SortedIndex::FindNext(int i) const +{ + return i + 1 < iv.GetCount() && !Less()(iv[i], iv[i + 1]) ? i + 1 : -1; +} + +template +int SortedIndex::FindLast(const T& x) const +{ + int i = iv.FindUpperBound(x, Less()); + return i > 0 && !Less()(iv[i - 1], x) ? i - 1 : -1; +} + +template +int SortedIndex::FindPrev(int i) const +{ + return i > 0 && !Less()(iv[i - 1], iv[i]) ? i - 1 : -1; +} + +template +int SortedIndex::RemoveKey(const T& x) +{ + int l = FindLowerBound(x); + int count = FindUpperBound(x) - l; + Remove(l, count); + return count; +} + +template +String SortedIndex::ToString() const +{ + return AsStringArray(*this); +} + +template +void Slaved_InVector__::Insert(int blki, int pos) +{ + data.data[blki].Insert(pos); + res = &data.data[blki][pos]; +} + +template +void Slaved_InVector__::Split(int blki, int nextsize) +{ + Vector& x = data.data.Insert(blki + 1); + x.InsertSplit(0, data.data[blki], nextsize); + data.data[blki].Shrink(); +} + +template +void Slaved_InVector__::AddFirst() +{ + data.data.Add().Add(); + res = &data.data[0][0]; +} + +template +String SortedAMap::ToString() const +{ + String r; + r = "{"; + for(int i = 0; i < GetCount(); i++) { + if(i) + r << ", "; + r << GetKey(i) << ": " << (*this)[i]; + } + r << '}'; + return r; +} + +template +SortedVectorMap::SortedVectorMap(SortedVectorMap rval_ s) +{ + B::key = pick(s.key); + B::value.data = pick(s.value.data); + B::SetSlave(); +} + +template +SortedVectorMap& SortedVectorMap::operator=(SortedVectorMap rval_ s) +{ + B::key = pick(s.key); + B::value.data = pick(s.value.data); + B::SetSlave(); + return *this; +} + +template +SortedVectorMap::SortedVectorMap(const SortedVectorMap& s, int) +{ + B::key = clone(s.key); + B::value.data = clone(s.value.data); + B::SetSlave(); +} + +template +int SortedVectorMap::FindAdd(const K& k, const T& init) +{ + B::value.res = NULL; + int q = B::key.FindAdd(k); + if(B::value.res) + *B::value.res = init; + return q; +} + +template +void SortedVectorMap::Swap(SortedVectorMap& x) +{ + B::value.data.Swap(x.value.data); + B::key.Swap(x.B::key); + B::SetSlave(); + x.SetSlave(); +} + +template +void Slaved_InArray__::Insert(int blki, int pos) +{ + if(!res) + res = new T; + data.iv.data[blki].Insert(pos, res); +} + +template +void Slaved_InArray__::Split(int blki, int nextsize) +{ + Vector< typename InArray::PointerType >& x = data.iv.data.Insert(blki + 1); + x.InsertSplit(0, data.iv.data[blki], nextsize); +} + +template +void Slaved_InArray__::Remove(int blki, int pos, int n) +{ + Vector< typename InArray::PointerType >& b = data.iv.data[blki]; + for(int i = 0; i < n; i++) + if(b[i + pos]) + delete (T *)b[i + pos]; + b.Remove(pos, n); +} + +template +void Slaved_InArray__::AddFirst() +{ + if(res) + data.iv.data.Add().Add(res); + else + data.iv.data.Add().Add(); +} + +template +int SortedArrayMap::FindAdd(const K& k, const T& init) +{ + B::value.res = NULL; + int q = B::key.FindAdd(k); + if(B::value.res) + *B::value.res = init; + return q; +} + +template +SortedArrayMap::SortedArrayMap(SortedArrayMap rval_ s) +{ + B::key = pick(s.key); + B::value.data = pick(s.value.data); + B::SetSlave(); +} + +template +SortedArrayMap& SortedArrayMap::operator=(SortedArrayMap rval_ s) +{ + B::key = pick(s.key); + B::value.data = pick(s.value.data); + B::SetSlave(); + return *this; +} + +template +SortedArrayMap::SortedArrayMap(const SortedArrayMap& s, int) +{ + B::key = clone(s.key); + B::value.data = clone(s.value.data); + B::SetSlave(); +} + +template +void SortedArrayMap::Swap(SortedArrayMap& x) +{ + B::value.data.Swap(x.value.data); + B::key.Swap(x.B::key); + B::SetSlave(); + x.SetSlave(); +} + +#ifdef UPP +template +void StreamSortedMap(Stream& s, T& cont) +{ + int n = cont.GetCount(); + s / n; + if(n < 0) { + s.LoadError(); + return; + } + if(s.IsLoading()) { + cont.Clear(); + while(n--) { + K key; + s % key; + s % cont.Add(key); + } + } + else + for(int i = 0; i < cont.GetCount(); i++) { + K key = cont.GetKey(i); + s % key; + s % cont[i]; + } +} + +template +void SortedVectorMap::Serialize(Stream& s) { + StreamSortedMap >(s, *this); +} + +template +void SortedVectorMap::Xmlize(XmlIO& xio) +{ + XmlizeSortedMap >(xio, "key", "value", *this); +} + +template +void SortedVectorMap::Jsonize(JsonIO& jio) +{ + JsonizeSortedMap, K, T>(jio, *this, "key", "value"); +} + +template +void SortedArrayMap::Serialize(Stream& s) { + StreamSortedMap >(s, *this); +} + +template +void SortedArrayMap::Xmlize(XmlIO& xio) +{ + XmlizeSortedMap >(xio, "key", "value", *this); +} + +template +void SortedArrayMap::Jsonize(JsonIO& jio) +{ + JsonizeSortedMap, K, T>(jio, *this, "key", "value"); +} + +#endif diff --git a/upptst/CompareContainer/CompareContainer.cpp b/upptst/CompareContainer/CompareContainer.cpp new file mode 100644 index 000000000..8ab17929d --- /dev/null +++ b/upptst/CompareContainer/CompareContainer.cpp @@ -0,0 +1,107 @@ +#include + +using namespace Upp; + +template +void CompareArray() +{ + T a; + a.Add(1); + a.Add(2); + T b = clone(a); + ASSERT(a == b); + b.At(1) = 3; + ASSERT(a != b); + ASSERT(b > a); + + b = clone(a); + b.Add(10); + ASSERT(a != b); + ASSERT(b > a); +} + +template +void CompareBiArray() +{ + T a; + a.AddTail(1); + a.AddTail(2); + T b = clone(a); + ASSERT(a == b); + b[1] = 3; + ASSERT(a != b); + ASSERT(b > a); + + b = clone(a); + b.AddTail(10); + ASSERT(a != b); + ASSERT(b > a); +} + +template +void CompareIndex() +{ + T a; + a.Add(1); + a.Add(2); + T b = clone(a); + ASSERT(a == b); + b.Add(3); + ASSERT(a != b); + ASSERT(b > a); + b.Clear(); + b.Add(1); + b.Add(3); + ASSERT(a != b); + ASSERT(b > a); +} + +template +void CompareMap() +{ + T a; + a.Add(1, 2); + a.Add(3, 4); + + T b = clone(a); + + ASSERT(a == b); + b.Add(4, 4); + ASSERT(a != b); + ASSERT(b > a); + + b.Clear(); + b.Add(2, 2); + b.Add(3, 4); + ASSERT(b > a); + + b.Clear(); + b.Add(1, 2); + b.Add(3, 5); + ASSERT(b > a); +} + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + CompareArray< Vector >(); + CompareArray< Array >(); + CompareArray< InVector >(); + CompareArray< InArray >(); + + CompareBiArray< BiVector >(); + CompareBiArray< BiArray >(); + + CompareIndex< Index >(); + CompareIndex< ArrayIndex >(); + CompareIndex< SortedIndex >(); + + CompareMap >(); + CompareMap >(); + + CompareMap >(); + CompareMap >(); + + LOG("===== OK"); +} diff --git a/upptst/CompareContainer/CompareContainer.upp b/upptst/CompareContainer/CompareContainer.upp new file mode 100644 index 000000000..acc0f5b68 --- /dev/null +++ b/upptst/CompareContainer/CompareContainer.upp @@ -0,0 +1,11 @@ +description "Comparison for containers\377"; + +uses + Core; + +file + CompareContainer.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/CompareContainer/init b/upptst/CompareContainer/init new file mode 100644 index 000000000..99fce0aed --- /dev/null +++ b/upptst/CompareContainer/init @@ -0,0 +1,4 @@ +#ifndef _CompareContainer_icpp_init_stub +#define _CompareContainer_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/Core11/Core11.cpp b/upptst/Core11/Core11.cpp new file mode 100644 index 000000000..23f26bd26 --- /dev/null +++ b/upptst/Core11/Core11.cpp @@ -0,0 +1,183 @@ +#include + +using namespace Upp; + +template +void TestTransfer() +{ + T a, b; + a = pick(b); + ASSERT(b.IsPicked()); + ASSERT(!a.IsPicked()); + + b = clone(a); + ASSERT(!b.IsPicked()); + ASSERT(!a.IsPicked()); + + T c = pick(b); + T d = clone(c); + + Swap(c, d); +} + +template +void TestTransfers() +{ + TestTransfer< Vector >(); + TestTransfer< Array >(); + TestTransfer< Index >(); + TestTransfer< ArrayIndex >(); + TestTransfer< VectorMap >(); + TestTransfer< ArrayMap >(); + + TestTransfer< FixedVectorMap >(); + TestTransfer< FixedArrayMap >(); + + TestTransfer< InVector >(); + TestTransfer< InArray >(); + TestTransfer< SortedIndex >(); + TestTransfer< SortedVectorMap >(); + TestTransfer< SortedArrayMap >(); +} + +template +void TestInMap() +{ + InMap m; + + m.Add(1, "hello"); + ASSERT(m.GetCount() == 1); + ASSERT(m[0] == "hello"); + ASSERT(m.Get(1) == "hello"); + + m.Add(2, "world"); + ASSERT(m.GetCount() == 2); + ASSERT(m[0] == "hello"); + ASSERT(m[1] == "world"); + ASSERT(m.Get(1) == "hello"); + ASSERT(m.Get(2) == "world"); + + ASSERT(m.FindAdd(1) == 0); + ASSERT(m.FindAdd(2) == 1); + ASSERT(m.FindAdd(3) == 2); + + ASSERT(m.FindAdd(0) == 0); + + ASSERT(m.FindAdd(4, "four") == 4); + ASSERT(m.GetCount() == 5); + + ASSERT(m[4] == "four"); + + ASSERT(m.GetAdd(3) == ""); + ASSERT(m.GetAdd(2) == "world"); + ASSERT(m.GetAdd(5) == ""); + ASSERT(m.GetCount() == 6); + + m.GetAdd(6) = "six"; + ASSERT(m.GetCount() == 7); + ASSERT(m.Get(6) == "six"); + + m.GetAdd(7, "seven"); + ASSERT(m[7] == "seven"); + ASSERT(m.Get(7) == "seven"); + + ASSERT(m.Get(8, "no") == "no"); + + ASSERT(m.FindPtr(99) == NULL); + ASSERT(*m.FindPtr(7) == "seven"); + + m.Shrink(); + + InMap h; + h.Add(1, "1"); + ASSERT(h.GetCount() == 1); + h.Clear(); + ASSERT(h.GetCount() == 0); + + const Val& vv = m.GetValues(); + ASSERT(vv.GetCount() == vv.GetCount()); + ASSERT(vv[7] == "seven"); + + InMap mm = pick(m); + ASSERT(m.IsPicked()); + ASSERT(!mm.IsPicked()); + + m = clone(mm); + ASSERT(!m.IsPicked()); + ASSERT(!mm.IsPicked()); + + mm = pick(m); + m = pick(mm); + mm.Clear(); + + mm.Swap(m); + m.Swap(mm); + + ASSERT(mm.IsEmpty()); + ASSERT(mm.GetCount() == 0); + ASSERT(!m.IsPicked()); + ASSERT(!mm.IsPicked()); + + ASSERT(m.FindLowerBound(6) == 6); + ASSERT(m.FindUpperBound(6) == 7); + ASSERT(m.Find(6) == 6); + + m.Add(6, "another six"); + ASSERT(m.GetCount() == 9); + ASSERT(m.FindNext(6) == 7); + ASSERT(m.FindLast(6) == 7); + ASSERT(m.FindPrev(7) == 6); + + ASSERT(m.GetKey(7) == 6); + + m.Remove(0); + ASSERT(m.GetCount() == 8); + m.RemoveKey(6); + ASSERT(m.GetCount() == 6); + m.Remove(1, 2); + ASSERT(m.GetCount() == 4); +} + +struct HasClone : MoveableAndDeepCopyOption { + Vector a; + +#ifdef CPP_11 + HasClone(HasClone rval_ x) = default; + HasClone& operator=(HasClone rval_ x) = default; +#endif + HasClone(const HasClone& x, int) : a(x.a, 0) {} + HasClone() {} +}; + +struct NoClone : Moveable { + Vector a; +}; + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + TestTransfers(); + TestTransfers(); + TestTransfers(); + + TestInMap< SortedVectorMap, InVector >(); + TestInMap< SortedArrayMap, InArray >(); + + SortedArrayMap x; + x.Create(1).a.Add(1); + + { + SortedVectorMap mm; + mm.GetAdd(1).a.Add(12); + mm.GetAdd(1).a.Add(13); + } + + { + SortedVectorMap mm; + mm.GetAdd(1).a.Add(12); + mm.GetAdd(1).a.Add(13); + } + + LOG("=========== OK"); +} diff --git a/upptst/Core11/Core11.upp b/upptst/Core11/Core11.upp new file mode 100644 index 000000000..6d7b2396a --- /dev/null +++ b/upptst/Core11/Core11.upp @@ -0,0 +1,11 @@ +description "Core tests for C+11\377"; + +uses + Core; + +file + Core11.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/Core11/init b/upptst/Core11/init new file mode 100644 index 000000000..d4f925c9b --- /dev/null +++ b/upptst/Core11/init @@ -0,0 +1,4 @@ +#ifndef _Core11_icpp_init_stub +#define _Core11_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/NTLAsString/NTLAsString.cpp b/upptst/NTLAsString/NTLAsString.cpp new file mode 100644 index 000000000..bbe7c4713 --- /dev/null +++ b/upptst/NTLAsString/NTLAsString.cpp @@ -0,0 +1,88 @@ +#include + +using namespace Upp; + +template +void ArrayTest() +{ + T array; + array.Add(1); + array.Add(2); + array.Add(3); + DUMP(array); +} + +template +void BiArrayTest() +{ + T array; + array.AddTail(1); + array.AddTail(2); + array.AddTail(3); + DUMP(array); +} + +template +void MapTest() +{ + T map; + map.Add(1, "one"); + map.Add(2, "two"); + map.Add(3, "three"); + DUMP(map); + map.Unlink(1); + DUMP(map); +} + +template +void SortedMapTest() +{ + T map; + map.Add(1, "one"); + map.Add(2, "two"); + map.Add(3, "three"); + DUMP(map); +} + +template +void FixedMapTest() +{ + T map; + map.Add(1, "one"); + map.Add(2, "two"); + map.Add(3, "three"); + map.Finish(); + DUMP(map); +} + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_FILE|LOG_COUT); + + ArrayTest< Vector > (); + ArrayTest< Array > (); + ArrayTest< InVector > (); + ArrayTest< InArray > (); + ArrayTest< Index > (); + ArrayTest< ArrayIndex > (); + ArrayTest< SortedIndex > (); + + BiArrayTest< BiVector > (); + BiArrayTest< BiArray > (); + + MapTest< VectorMap >(); + MapTest< ArrayMap >(); + + SortedMapTest< SortedVectorMap >(); + SortedMapTest< SortedArrayMap >(); + + FixedMapTest< FixedVectorMap >(); + FixedMapTest< FixedArrayMap >(); + + One x; + DUMP(x); + x.Create() = 1; + DUMP(x); + + LOG("======== OK"); +} diff --git a/upptst/NTLAsString/NTLAsString.upp b/upptst/NTLAsString/NTLAsString.upp new file mode 100644 index 000000000..c99e95cd4 --- /dev/null +++ b/upptst/NTLAsString/NTLAsString.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + NTLAsString.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/NTLAsString/init b/upptst/NTLAsString/init new file mode 100644 index 000000000..35c352213 --- /dev/null +++ b/upptst/NTLAsString/init @@ -0,0 +1,4 @@ +#ifndef _NTLAsString_icpp_init_stub +#define _NTLAsString_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/SortedAMap/main.cpp b/upptst/SortedAMap/main.cpp index f613688a9..ca701b4ad 100644 --- a/upptst/SortedAMap/main.cpp +++ b/upptst/SortedAMap/main.cpp @@ -149,6 +149,10 @@ void Test(T& map) } } +struct Foo : Moveable { + Vector a; +}; + CONSOLE_APP_MAIN { StdLogSetup(LOG_COUT|LOG_FILE); @@ -208,4 +212,10 @@ CONSOLE_APP_MAIN RDUMP(sizeof(InArray)); RDUMP(sizeof(SortedIndex)); RDUMP(sizeof(SortedVectorMap)); + + { // Test that this compiles + SortedVectorMap mm; + Foo& x = mm.Add(1); + x.a.Add(12); + } } diff --git a/upptst/ValueCompare/ValueCompare.cpp b/upptst/ValueCompare/ValueCompare.cpp new file mode 100644 index 000000000..b47e36c6c --- /dev/null +++ b/upptst/ValueCompare/ValueCompare.cpp @@ -0,0 +1,99 @@ +#include + +using namespace Upp; + +template +void TestCompareT(T a, T b) +{ + LOG("==== TestCompare(" << a << " " << b << "): " << a.Compare(b)); + + ASSERT(sgn(a.Compare(b)) == -1); + ASSERT(sgn(b.Compare(a)) == 1); + ASSERT(a.Compare(a) == 0); + ASSERT(b.Compare(b) == 0); + + ASSERT(a > Null); + ASSERT(b > Null); + + ASSERT(a < b); + ASSERT(a <= a); + ASSERT(b <= b); + ASSERT(a <= b); + + ASSERT(b > a); + ASSERT(b >= a); + ASSERT(a >= a); + ASSERT(b >= b); + + ASSERT(a != b); + ASSERT(a == a); + ASSERT(b == b); +} + +void TestCompare(Value a, Value b) +{ + TestCompareT(a, b); +} + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_FILE|LOG_COUT); + + TestCompare("ahoj", "ahoj1"); + TestCompare(WString("ahoj"), WString("ahoj1")); + TestCompare(1, 2); + TestCompare(1.1, 1.2); + TestCompare(false, true); + TestCompare((int64)1, (int64)2); + TestCompare(GetSysTime(), GetSysTime() + 1); + TestCompare(GetSysDate(), GetSysDate() + 1); + + ValueArray va1; va1 << 1 << 2 << 3; + ValueArray va2; va2 << 1 << 2 << 4; + + TestCompareT(va1, va2); + TestCompare(va1, va2); + va2 = va1; + va2 << 0; + TestCompareT(va1, va2); + TestCompare(va1, va2); + + ValueMap m1; m1("a", 1)("b", 2); + ValueMap m2; m2("a", 1)("c", 2); + + TestCompareT(m1, m2); + + Value a = m1; + Value b = m2; + a.Compare(b); + + TestCompare(m1, m2); + + m2 = m1; + m2("b", 2); + + TestCompareT(m1, m2); + TestCompare(m1, m2); + + TestCompare((bool)false, 123); + TestCompare((bool)false, (int64)123); + TestCompare((bool)false, (double)123); + TestCompare((bool)false, (bool)true); + + TestCompare(12, 123); + TestCompare(12, (int64)123); + TestCompare(12, (double)123); + TestCompare(0, (bool)true); + + TestCompare((int64)12, 123); + TestCompare((int64)12, (int64)123); + TestCompare((int64)12, (double)123); + TestCompare((int64)0, (bool)true); + + TestCompare((double)12, 123); + TestCompare((double)12, (int64)123); + TestCompare((double)12, (double)123); + TestCompare((double)0, (bool)true); + + LOG("===== Everything is OK"); +} diff --git a/upptst/ValueCompare/ValueCompare.upp b/upptst/ValueCompare/ValueCompare.upp new file mode 100644 index 000000000..dde042b82 --- /dev/null +++ b/upptst/ValueCompare/ValueCompare.upp @@ -0,0 +1,11 @@ +description "Test of Value::Compare\377"; + +uses + Core; + +file + ValueCompare.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/ValueCompare/init b/upptst/ValueCompare/init new file mode 100644 index 000000000..d60caeddc --- /dev/null +++ b/upptst/ValueCompare/init @@ -0,0 +1,4 @@ +#ifndef _ValueCompare_icpp_init_stub +#define _ValueCompare_icpp_init_stub +#include "Core/init" +#endif