diff --git a/rainbow/SDL20/Event.cpp b/rainbow/SDL20/Event.cpp index 407a115dd..d2aaf625a 100644 --- a/rainbow/SDL20/Event.cpp +++ b/rainbow/SDL20/Event.cpp @@ -186,4 +186,4 @@ void Ctrl::SetMouseCursor(const Image& image) END_UPP_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/rainbow/SDL20/Local.h b/rainbow/SDL20/Local.h index 72309c85d..ad85d7871 100644 --- a/rainbow/SDL20/Local.h +++ b/rainbow/SDL20/Local.h @@ -1,5 +1,7 @@ #include +#ifdef GUI_SDL20 + NAMESPACE_UPP class TopWindowFrame : public Ctrl { @@ -63,3 +65,5 @@ extern Size screen_size; extern SDLWindow screen; END_UPP_NAMESPACE + +#endif \ No newline at end of file diff --git a/rainbow/SDL20/SDL.cpp b/rainbow/SDL20/SDL.cpp index 03be470ba..fe1519131 100644 --- a/rainbow/SDL20/SDL.cpp +++ b/rainbow/SDL20/SDL.cpp @@ -1,5 +1,7 @@ #include "Local.h" +#ifdef GUI_SDL20 + NAMESPACE_UPP #define LLOG(x) //LOG(x) @@ -156,3 +158,5 @@ void FBDeInit() } END_UPP_NAMESPACE + +#endif \ No newline at end of file diff --git a/rainbow/SDL20/SDLProc.cpp b/rainbow/SDL20/SDLProc.cpp index 8ff56b081..798e60686 100644 --- a/rainbow/SDL20/SDLProc.cpp +++ b/rainbow/SDL20/SDLProc.cpp @@ -1,5 +1,7 @@ #include "Local.h" +#ifdef GUI_SDL20 + NAMESPACE_UPP #define LLOG(x) //LOG(x) @@ -56,7 +58,7 @@ dword lastbdowntime[8] = {0}; dword isdblclick[8] = {0}; void HandleSDLEvent(SDL_Event* event) { - DLOG("HandleSDLEvent"); + DLOG("HandleSDLEvent " << event->type); switch(event->type) { // case SDL_ACTIVEEVENT: //SDL_ActiveEvent // break; @@ -202,3 +204,5 @@ void HandleUserEvent(SDL_Event* event) } END_UPP_NAMESPACE + +#endif diff --git a/rainbow/SDL20/Window.cpp b/rainbow/SDL20/Window.cpp index 4b3bb1c98..de15e4156 100644 --- a/rainbow/SDL20/Window.cpp +++ b/rainbow/SDL20/Window.cpp @@ -1,5 +1,7 @@ #include "Local.h" +#ifdef GUI_SDL20 + NAMESPACE_UPP bool SDLWindow::Create(const Rect& rect, const char *title) @@ -52,3 +54,5 @@ SDLWindow::~SDLWindow() } END_UPP_NAMESPACE + +#endif \ No newline at end of file diff --git a/rainbow/SDL20Uword/SDL20Uword.upp b/rainbow/SDL20Uword/SDL20Uword.upp index fc3e23243..432a04688 100644 --- a/rainbow/SDL20Uword/SDL20Uword.upp +++ b/rainbow/SDL20Uword/SDL20Uword.upp @@ -1,6 +1,7 @@ uses CtrlLib, - SDL20; + SDL20, + RichEdit; file main.cpp; diff --git a/rainbow/SDL20Uword/init b/rainbow/SDL20Uword/init index 9673b14f9..11b71eee9 100644 --- a/rainbow/SDL20Uword/init +++ b/rainbow/SDL20Uword/init @@ -2,4 +2,5 @@ #define _SDL20Uword_icpp_init_stub #include "CtrlLib/init" #include "SDL20/init" +#include "RichEdit/init" #endif diff --git a/rainbow/SDL20Uword/main.cpp b/rainbow/SDL20Uword/main.cpp index b722a7cda..7889a403e 100644 --- a/rainbow/SDL20Uword/main.cpp +++ b/rainbow/SDL20Uword/main.cpp @@ -1,8 +1,254 @@ -#include +#include +#include using namespace Upp; +#define IMAGECLASS UWordImg +#define IMAGEFILE +#include + +FileSel& UWordFs() +{ + static FileSel fs; + return fs; +} + +class UWord : public TopWindow { +public: + virtual void DragAndDrop(Point, PasteClip& d); + virtual void FrameDragAndDrop(Point, PasteClip& d); + + virtual void ShutdownWindow(); + +protected: + RichEdit editor; + MenuBar menubar; + ToolBar toolbar; + StatusBar statusbar; + String filename; + + static LRUList& lrufile() { static LRUList l; return l; } + + void Load(const String& filename); + void OpenFile(const String& fn); + void New(); + void Open(); + void Save0(); + void Save(); + void SaveAs(); + void Print(); + void About(); + void Destroy(bool shutdown); + void SetBar(); + void FileBar(Bar& bar); + void AboutMenu(Bar& bar); + void MainMenu(Bar& bar); + void MainBar(Bar& bar); + +public: + typedef UWord CLASSNAME; + + static void SerializeApp(Stream& s); + + UWord(); +}; + +void UWord::FileBar(Bar& bar) +{ + bar.Add("New", CtrlImg::new_doc(), THISBACK(New)) + .Key(K_CTRL_N) + .Help("Open new window"); + bar.Add("Open..", CtrlImg::open(), THISBACK(Open)) + .Key(K_CTRL_O) + .Help("Open existing document"); + bar.Add(editor.IsModified(), "Save", CtrlImg::save(), THISBACK(Save)) + .Key(K_CTRL_S) + .Help("Save current document"); + bar.Add("SaveAs", CtrlImg::save_as(), THISBACK(SaveAs)) + .Help("Save current document with a new name"); + bar.ToolGap(); + bar.MenuSeparator(); + bar.Add("Print..", CtrlImg::print(), THISBACK(Print)) + .Key(K_CTRL_P) + .Help("Print document"); + if(bar.IsMenuBar()) { + if(lrufile().GetCount()) + lrufile()(bar, THISBACK(OpenFile)); + bar.Separator(); + bar.Add("Exit", THISBACK1(Destroy, false)); + } +} + +void UWord::AboutMenu(Bar& bar) +{ + bar.Add("About..", THISBACK(About)); +} + +void UWord::MainMenu(Bar& bar) +{ + bar.Add("File", THISBACK(FileBar)); + bar.Add("Window", callback(WindowsMenu)); + bar.Add("Help", THISBACK(AboutMenu)); +} + +void UWord::New() +{ + new UWord; +} + +void UWord::Load(const String& name) +{ + lrufile().NewEntry(name); + editor.SetQTF(LoadFile(name)); + filename = name; + editor.ClearModify(); + Title(filename); +} + +void UWord::OpenFile(const String& fn) +{ + if(filename.IsEmpty() && !editor.IsModified()) + Load(fn); + else + (new UWord)->Load(fn); +} + +void UWord::Open() +{ + FileSel& fs = UWordFs(); + if(fs.ExecuteOpen()) + OpenFile(fs); + else + statusbar.Temporary("Loading aborted."); +} + +void UWord::DragAndDrop(Point, PasteClip& d) +{ + if(AcceptFiles(d)) { + Vector fn = GetFiles(d); + for(int i = 0; i < fn.GetCount(); i++) + if(FileExists(fn[i])) + OpenFile(fn[i]); + } +} + +void UWord::FrameDragAndDrop(Point p, PasteClip& d) +{ + DragAndDrop(p, d); +} + +void UWord::Save0() +{ + lrufile().NewEntry(filename); + if(filename.IsEmpty()) + SaveAs(); + else + if(SaveFile(filename, editor.GetQTF())) { + statusbar.Temporary("File " + filename + " was saved."); + ClearModify(); + } + else + Exclamation("Error saving the file [* " + DeQtf(filename) + "]!"); +} + +void UWord::Save() +{ + if(!editor.IsModified()) return; + Save0(); +} + +void UWord::SaveAs() +{ + FileSel& fs = UWordFs(); + if(fs.ExecuteSaveAs()) { + filename = fs; + Title(filename); + Save0(); + } +} + +void UWord::Print() +{ + editor.Print(); +} + +void UWord::About() +{ + PromptOK("[A5 uWord]&Using [*^www://upp.sf.net^ Ultimate`+`+] technology."); +} + +void UWord::Destroy(bool shutdown) +{ + if(editor.IsModified()) { + switch((shutdown ? PromptYesNo : PromptYesNoCancel)("Do you want to save the changes to the document?")) { + case 1: + Save(); + break; + case -1: + return; + } + } + delete this; +} + +void UWord::ShutdownWindow() +{ + Destroy(true); +} + +void UWord::MainBar(Bar& bar) +{ + FileBar(bar); + bar.Separator(); + editor.DefaultBar(bar); +} + +void UWord::SetBar() +{ + toolbar.Set(THISBACK(MainBar)); +} + +UWord::UWord() +{ + AddFrame(menubar); + AddFrame(TopSeparatorFrame()); + AddFrame(toolbar); + AddFrame(statusbar); + Add(editor.SizePos()); + menubar.Set(THISBACK(MainMenu)); + Sizeable().Zoomable(); + WhenClose = THISBACK1(Destroy, false); + menubar.WhenHelp = toolbar.WhenHelp = statusbar; + static int doc; + Title(Format("Document%d", ++doc)); + Icon(CtrlImg::File()); + editor.ClearModify(); + SetBar(); + editor.WhenRefreshBar = THISBACK(SetBar); + OpenMain(); + ActiveFocus(editor); +} + +void UWord::SerializeApp(Stream& s) +{ + int version = 1; + s / version; + s % UWordFs(); + if(version >= 1) + s % lrufile(); +} + GUI_APP_MAIN { - PromptOK("Hello!"); + SetLanguage(LNG_ENGLISH); + SetDefaultCharset(CHARSET_UTF8); + + UWordFs().Type("QTF files", "*.qtf") + .AllFilesType() + .DefaultExt("qtf"); + + LoadFromFile(callback(UWord::SerializeApp)); + new UWord; + Ctrl::EventLoop(); + StoreToFile(callback(UWord::SerializeApp)); }