From 4024cb26d13e6a54cb9ff2cf83365a3bccb1e557 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 23 Feb 2014 18:22:07 +0000 Subject: [PATCH] .uppdev git-svn-id: svn://ultimatepp.org/upp/trunk@6945 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/FileSel/main.cpp | 3 ++ uppdev/FileView/FileView.upp | 9 ++++ uppdev/FileView/init | 4 ++ uppdev/FileView/main.cpp | 101 +++++++++++++++++++++++++++++++++++ uppdev/TextDiff/main.cpp | 2 +- 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 uppdev/FileView/FileView.upp create mode 100644 uppdev/FileView/init create mode 100644 uppdev/FileView/main.cpp diff --git a/uppdev/FileSel/main.cpp b/uppdev/FileSel/main.cpp index e13af7d83..b43d07272 100644 --- a/uppdev/FileSel/main.cpp +++ b/uppdev/FileSel/main.cpp @@ -8,6 +8,9 @@ GUI_APP_MAIN FileSel fs; String fn; fs.Type("jpeg", "*.jpg"); + fs.ExecuteOpen(); + return; + for(;0;) { if(!fs.ExecuteSaveAs()) break; diff --git a/uppdev/FileView/FileView.upp b/uppdev/FileView/FileView.upp new file mode 100644 index 000000000..78afc12a4 --- /dev/null +++ b/uppdev/FileView/FileView.upp @@ -0,0 +1,9 @@ +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI SSE2"; + diff --git a/uppdev/FileView/init b/uppdev/FileView/init new file mode 100644 index 000000000..cb6d73bcc --- /dev/null +++ b/uppdev/FileView/init @@ -0,0 +1,4 @@ +#ifndef _FileView_icpp_init_stub +#define _FileView_icpp_init_stub +#include "CtrlLib/init" +#endif diff --git a/uppdev/FileView/main.cpp b/uppdev/FileView/main.cpp new file mode 100644 index 000000000..1bdb1b1a0 --- /dev/null +++ b/uppdev/FileView/main.cpp @@ -0,0 +1,101 @@ +#include + +using namespace Upp; + +struct TextViewCtrl : Ctrl { + virtual void Paint(Draw& w); + virtual bool Key(dword key, int count); + + int64 pagepos; + Stream *in; + + int Get(int64 pos); + int64 Next(int64 pos); + int64 Prev(int64 pos); +}; + +int TextViewCtrl::Get(int64 pos) +{ + in->Seek(pos); + return in->Term(); +} + +int64 TextViewCtrl::Next(int64 pos) +{ + for(;;) { + int c = Get(pos); + if(c < 0) + return in->GetSize(); + if(c == '\n') + return pos + 1; + pos++; + } +} + +int64 TextViewCtrl::Prev(int64 pos) +{ + --pos; + for(;;) { + if(pos <= 0) + return 0; + if(Get(pos - 1) == '\n') + return pos; + pos--; + } +} + +void TextViewCtrl::Paint(Draw& w) +{ + Font font = Monospace(14); + Size sz = GetSize(); + w.DrawRect(sz, White()); + int64 pos = pagepos; + int y = 0; + int x = 0; + int n = 0; + while(y < sz.cy && pos < in->GetSize()) { + DDUMP(y); + DDUMP(sz.cy); + DDUMP(pos); + wchar c = Get(pos); + if(c == '\n') { + y += max(font.GetCy(), 1); + x = 0; + n = 0; + } + else { + w.DrawText(x, y, &c, font, Black(), 1); + x += font['M']; + if(++n > 200) { + y += max(font.GetCy(), 1); + x = 0; + n = 0; + } + } + pos++; + } +} + +bool TextViewCtrl::Key(dword key, int count) +{ + switch(key) { + case K_DOWN: + pagepos = Next(pagepos); + return true; + case K_UP: + pagepos = Prev(pagepos); + return true; + } +} + +GUI_APP_MAIN +{ + FileIn in("C:/xxx/20131116_ST_ZZSZ.xml"); + TextViewCtrl txt; + txt.in = ∈ + txt.pagepos = 0; + + TopWindow win; + win.Add(txt.SizePos()); + win.Run(); +} diff --git a/uppdev/TextDiff/main.cpp b/uppdev/TextDiff/main.cpp index 554abc2f8..eaf9d4cc0 100644 --- a/uppdev/TextDiff/main.cpp +++ b/uppdev/TextDiff/main.cpp @@ -7,6 +7,6 @@ GUI_APP_MAIN TopWindow win; TextDiffCtrl ctrl; win.Add(ctrl.SizePos()); - ctrl.Set(LoadFile("u:/file1.txt"), LoadFile("u:/file2.txt")); + ctrl.Set(LoadFile("C:/u/upp.src/uppdev/AssistTest/main.cpp"), LoadFile("C:/u/upp.src/uppdev/ArrayCtrl/main.cpp")); win.Run(); }