.Developing WebWord

git-svn-id: svn://ultimatepp.org/upp/trunk@6797 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-01-19 19:08:03 +00:00
parent 4f3ea6642f
commit 223fffc785
10 changed files with 125 additions and 74 deletions

View file

@ -4,7 +4,6 @@ public:
~ViewDraw();
};
/*
class ViewDraw : public SystemDraw {
Vector<Rect> dummy;
@ -12,35 +11,5 @@ public:
ViewDraw(Ctrl *) : SystemDraw(Ctrl::framebuffer, dummy) { dummy.Add(Rect(10, 10, 100, 100)); }
};
*/
class DHCtrl : Ctrl {};
#ifdef PLATFORM_WIN32
#define GUI_APP_MAIN \
void GuiMainFn_(); \
\
extern "C" int main(int argc, const char **argv, const char **envptr) { \
UPP::AppInitEnvironment__(); \
UPP::Ctrl::InitTelpp(); \
GuiMainFn_(); \
UPP::Ctrl::CloseTopCtrls(); \
return UPP::GetExitCode(); \
} \
\
void GuiMainFn_()
#endif
#ifdef PLATFORM_POSIX
#define GUI_APP_MAIN \
void GuiMainFn_(); \
\
extern "C" int main(int argc, const char **argv, const char **envptr) { \
UPP::AppInit__(argc, argv, envptr); \
UPP::Ctrl::InitTelpp(); \
GuiMainFn_(); \
UPP::Ctrl::CloseTopCtrls(); \
return UPP::GetExitCode(); \
} \
\
void GuiMainFn_()
#endif

View file

@ -60,7 +60,7 @@ public:
static bool DoKeyFB(dword key, int cnt);
static void InitTelpp(const String& host = Null);
static void Exit();
static void ExitTurtle();
static void EndSession();

View file

@ -6,8 +6,8 @@ NAMESPACE_UPP
void SystemDraw::Put16(int x)
{
result.Cat(LOBYTE(x));
result.Cat(HIBYTE(x));
Put8(LOBYTE(x));
Put8(HIBYTE(x));
}
void SystemDraw::Put32(int x)
@ -36,7 +36,7 @@ void SystemDraw::Put(const Rect& r)
void SystemDraw::Put(const String& s)
{
Put32(s.GetLength());
result.Cat(s);
turtle_stream.Put(s);
}
Index<int64> SystemDraw::img_index[3];

View file

@ -6,7 +6,7 @@
NAMESPACE_UPP
#define LLOG(x) // RLOG(x)
#define LLOG(x) // LLOG(x)
#define LDUMP(x) // RDUMP(x)
#define LTIMING(x)
@ -26,7 +26,6 @@ TcpSocket socket;
WebSocket websocket;
BiVector<String> event_queue;
String content;
String hostname;
@ -37,20 +36,29 @@ void SetHostName(const String& h)
bool Ctrl::Connect()
{
RLOG("Connect");
LLOG("Connect");
if(!server.Listen(8088, 10)) {
RLOG("Cannot open server port for listening\r\n");
return false;
LLOG("Cannot open server port for listening\r\n");
Exit(1);
}
RLOG("Starting to listen on 8088");
LLOG("Starting to listen on 8088");
socket.Timeout(20000);
for(;;) {
if(socket.Accept(server)) {
if(http.Read(socket)) {
RLOG("Accepted, header read");
LLOG("Accepted, header read");
if(websocket.WebAccept(socket, http))
#ifdef _DEBUG
break;
RLOG("Sending HTML");
#else
if(fork() == 0)
break;
else {
socket.Close();
continue;
}
#endif
LLOG("Sending HTML");
String html = String(turtle_html, turtle_html_length);
#ifdef _DEBUG
html.Replace("%%host%%", Nvl(GetIniKey("turtle_host"), Nvl(hostname, "ws://localhost:8088")));
@ -62,15 +70,16 @@ bool Ctrl::Connect()
socket.Close();
}
}
RLOG("Connection established");
LLOG("Connection established");
server.Close();
if(socket.IsError())
RLOG("CONNECT ERROR: " << socket.GetErrorDesc());
LLOG("CONNECT ERROR: " << socket.GetErrorDesc());
return true;
}
void Ctrl::InitTelpp(const String& hostname_)
{
RLOG("InitTelpp");
LLOG("InitTelpp");
hostname = hostname_;
@ -100,12 +109,12 @@ void Ctrl::TimerAndPaint()
SyncTopWindows();
SweepMkImageCache();
DoPaint();
String s = ZCompress(content);
if(content.GetCount() > 10)
RLOG("Sending " << s.GetLength());
socket.Timeout(20000);
websocket.SendBinary(ZCompress(String(SystemDraw::DISABLESENDING, 1))); // Do not send events until data transfered and processed
String s = turtle_stream.FlushStream();
if(s.GetCount() > 10)
LLOG("Sending " << s.GetLength());
websocket.SendBinary(s);
content.Clear();
}
bool Ctrl::IsWaitingEvent()
@ -114,14 +123,14 @@ bool Ctrl::IsWaitingEvent()
while(socket.Timeout(0).WaitRead()) {
socket.Timeout(20000);
String s = websocket.Recieve();
RLOG("Recieved data " << s);
LLOG("Recieved data " << s);
StringStream ss(s);
while(!ss.IsEof())
event_queue.AddTail(ss.GetLine());
}
socket.Timeout(20000);
if(socket.IsError())
RLOG("ERROR: " << socket.GetErrorDesc());
LLOG("ERROR: " << socket.GetErrorDesc());
return event_queue.GetCount();
}
@ -276,7 +285,6 @@ void Ctrl::DoPaint()
SystemDraw draw;
PaintScene(draw);
PaintCaretCursor(draw);
content << String(draw.result);
}
}
}
@ -408,7 +416,7 @@ void Ctrl::DoMouseButton(int event, CParser& p)
bool Ctrl::ProcessEvent(const String& event)
{
RLOG("Processing event " << event);
LLOG("Processing event " << event);
CParser p(event);
try {
if(p.Id("I"))

35
rainbow/Turtle/Stream.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "Local.h"
#ifdef GUI_TURTLE
NAMESPACE_UPP
#define LLOG(x) // LLOG(x)
#define LDUMP(x) // RDUMP(x)
#define LTIMING(x)
TurtleStream turtle_stream;
void TurtleStream::Reset()
{
zlib.Clear();
zlib.Compress();
}
void TurtleStream::Out(const void *data, dword size)
{
zlib.Put(data, (int)size);
}
String TurtleStream::FlushStream()
{
Flush();
zlib.End();
String s = zlib.Get();
Reset();
return s;
}
END_UPP_NAMESPACE
#endif

View file

@ -14,6 +14,23 @@ NAMESPACE_UPP
#define IMAGEFILE <Turtle/FB.iml>
#include <Draw/iml_header.h>
class TurtleStream : public OutStream {
public:
virtual void Out(const void *data, dword size);
private:
Zlib zlib;
void Reset();
public:
String FlushStream();
TurtleStream() { Reset(); }
};
extern TurtleStream turtle_stream;
class SystemDraw : public SDraw {
public:
virtual void PutImage(Point p, const Image& img, const Rect& src);
@ -28,6 +45,7 @@ public:
STD_CURSORIMAGE = 4,
SETCURSORIMAGE = 5,
CURSORIMAGE = 6,
DISABLESENDING = 7,
};
static Index<int64> img_index[3];
@ -36,9 +54,7 @@ public:
int GetImageI(const Image& img);
static void ResetI() { for(int i = 0; i < 3; i++) img_index[i].Clear(); }
StringBuffer result;
void Put8(int x) { result.Cat(x); }
void Put8(int x) { turtle_stream.Put(x); }
void Put16(int x);
void Put32(int x);
void Put(Point p);

View file

@ -40,8 +40,8 @@ U.prototype.k=function(){var b=this.input,d,a;d=this.q.k();this.a=this.q.a;if(th
function Log(msg)
{
if (window.console && console.log)
console.log(msg); //for firebug
// if (window.console && console.log)
// console.log(msg); //for firebug
}
function Char(p, ch)
@ -81,6 +81,8 @@ function GetString(p)
return s;
}
var SendingEnabled = true;
function ProcessDraw(s)
{
// console.clear();
@ -92,6 +94,8 @@ function ProcessDraw(s)
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
SendingEnabled = true;
while(p.pos < p.data.length) {
// Log(p.pos + ": " + p.data[p.pos]);
if(Char(p, 0)) { // RECT
@ -193,7 +197,13 @@ function ProcessDraw(s)
canvas.style.cursor = window.cursor_cache[i];
// Log(cursor_cache[i]);
}
}
else
if(Char(p, 7)) { // DISABLESENDING
SendingEnabled = true;
}
}
if(SendingEnabled && event_queue.length)
ScheduleSend();
}
window.img_cache = {};
@ -282,20 +292,24 @@ ws.binaryType = "arraybuffer";
function ScheduleSend()
{
if(timerID != undefined)
clearTimeout(timerID);
timerID = setTimeout(SendEvents, 0);
if(SendingEnabled) {
if(timerID != undefined)
clearTimeout(timerID);
timerID = setTimeout(SendEvents, 0);
}
}
function SendEvents()
{
if(event_queue.length)
Log("Sending " + event_queue);
ws.send(event_queue);
event_queue = "";
if(timerID != undefined)
clearTimeout(timerID);
timerID = setTimeout(SendEvents, 20);
if(SendingEnabled) {
if(event_queue.length)
Log("Sending " + event_queue);
ws.send(event_queue);
event_queue = "";
if(timerID != undefined)
clearTimeout(timerID);
timerID = setTimeout(SendEvents, 20);
}
}
ws.onopen = function()

View file

@ -17,6 +17,7 @@ file
Ctrl.cpp,
Wnd.cpp,
Cursor.cpp,
Stream.cpp,
Event.cpp,
Top.h,
TopFrame.cpp,

View file

@ -41,7 +41,7 @@ void Ctrl::EndSession()
EndSessionLoopNo = EventLoopNo;
}
void Ctrl::Exit()
void Ctrl::ExitTurtle()
{
TopWindow::ShutdownWindows();
Ctrl::CloseTopCtrls();

View file

@ -61,6 +61,7 @@ public:
void UWord::FileBar(Bar& bar)
{
/*
bar.Add("New", CtrlImg::new_doc(), THISBACK(New))
.Key(K_CTRL_N)
.Help("Open new window");
@ -85,6 +86,7 @@ void UWord::FileBar(Bar& bar)
bar.Separator();
bar.Add("Exit", THISBACK1(Destroy, false));
}
*/
}
void UWord::AboutMenu(Bar& bar)
@ -94,7 +96,7 @@ void UWord::AboutMenu(Bar& bar)
void UWord::MainMenu(Bar& bar)
{
bar.Add("File", THISBACK(FileBar));
// bar.Add("File", THISBACK(FileBar));
bar.Add("Window", callback(WindowsMenu));
bar.Add("Help", THISBACK(AboutMenu));
}
@ -311,7 +313,9 @@ CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
RLOG("APP_MAIN");
#ifdef _DEBUG
MemoryLimitKb(10000);
#endif
UPP::Ctrl::InitTelpp();
@ -326,7 +330,11 @@ CONSOLE_APP_MAIN
.DefaultExt("pdf");
LoadFromFile(callback(UWord::SerializeApp));
#ifdef _DEBUG
(new UWord)->editor.SetQTF(LoadFile(GetDataFile("test.qtf")));
#else
new UWord;
#endif
Ctrl::EventLoop();
StoreToFile(callback(UWord::SerializeApp));