mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
CtrlCore: Fixed X11, upptst
This commit is contained in:
parent
f6fd99f4b0
commit
1396c7ed51
6 changed files with 342 additions and 14 deletions
|
|
@ -382,13 +382,14 @@ void TopWindow::Open(Ctrl *owner)
|
|||
PropModeReplace, (byte *) &curr_pid, 1);
|
||||
}
|
||||
|
||||
XChangeProperty(Xdisplay, xwin, XAtom("_NET_WM_PID"), XA_CARDINAL, 32,
|
||||
Window win = GetWindow();
|
||||
XChangeProperty(Xdisplay, win, XAtom("_NET_WM_PID"), XA_CARDINAL, 32,
|
||||
PropModeReplace, (byte *) &curr_pid, 1);
|
||||
XChangeProperty(Xdisplay, xwin, XAtom("WM_CLIENT_LEADER"),
|
||||
XChangeProperty(Xdisplay, win, XAtom("WM_CLIENT_LEADER"),
|
||||
XA_WINDOW, 32, PropModeReplace, (byte *)&wm_client_leader, 1);
|
||||
|
||||
int version = 5;
|
||||
XChangeProperty(Xdisplay, xwin, XAtom("XdndAware"), XA_ATOM, 32,
|
||||
XChangeProperty(Xdisplay, win, XAtom("XdndAware"), XA_ATOM, 32,
|
||||
0, (byte *)&version, 1);
|
||||
|
||||
SyncState();
|
||||
|
|
|
|||
|
|
@ -134,9 +134,9 @@ Window Ctrl::GetParentWindow(void) const
|
|||
Ctrl *Ctrl::GetParentWindowCtrl(void) const
|
||||
{
|
||||
GuiLock __;
|
||||
Ctrl *q = uparent;
|
||||
Ctrl *q = GetParent();
|
||||
while(q && !q->utop)
|
||||
q = q->uparent;
|
||||
q = q->GetParent();
|
||||
return q;
|
||||
|
||||
} // END Ctrl::GetParentWindowCtrl()
|
||||
|
|
@ -146,9 +146,9 @@ Rect Ctrl::GetRectInParentWindow(void) const
|
|||
{
|
||||
GuiLock __;
|
||||
Rect r = GetScreenRect();
|
||||
Ctrl *q = uparent;
|
||||
Ctrl *q = GetParent();
|
||||
while(q && !q->utop)
|
||||
q = q->uparent;
|
||||
q = q->GetParent();
|
||||
if(q)
|
||||
{
|
||||
Rect pr = q->GetScreenRect();
|
||||
|
|
@ -443,6 +443,7 @@ void Ctrl::EventLoop(Ctrl *ctrl)
|
|||
while(IsWaitingEvent()) {
|
||||
LTIMING("XNextEvent");
|
||||
XNextEvent(Xdisplay, &event);
|
||||
DDUMP(event.type);
|
||||
ProcessEvent(&event);
|
||||
}
|
||||
TimerAndPaint();
|
||||
|
|
@ -594,7 +595,7 @@ Vector<Ctrl *> Ctrl::GetTopCtrls()
|
|||
Vector<Ctrl *> v;
|
||||
const ArrayMap<Window, Ctrl::XWindow>& w = Xwindow();
|
||||
for(int i = 0; i < w.GetCount(); i++)
|
||||
if(w.GetKey(i) && w[i].ctrl && !w[i].ctrl->uparent) //aris002 might be owner here?
|
||||
if(w.GetKey(i) && w[i].ctrl && !w[i].ctrl->GetParent())
|
||||
v.Add(w[i].ctrl);
|
||||
return v;
|
||||
}
|
||||
|
|
@ -929,16 +930,18 @@ Window Ctrl::GetXServerFocusWindow()
|
|||
GuiLock __;
|
||||
Window w;
|
||||
int dummy;
|
||||
DLOG("XGetInputFocus");
|
||||
XGetInputFocus(Xdisplay, &w, &dummy);
|
||||
return w;
|
||||
}
|
||||
|
||||
void Ctrl::FocusSync()
|
||||
{
|
||||
DLOG("FocusSync");
|
||||
GuiLock __;
|
||||
Window fw = GetXServerFocusWindow();
|
||||
if(fw != focusWindow) {
|
||||
LLOG("FocusSync to " << FormatIntHex(fw));
|
||||
DLOG("FocusSync to " << FormatIntHex(fw));
|
||||
if(fw) {
|
||||
int q = Xwindow().Find(fw);
|
||||
if(q >= 0) {
|
||||
|
|
@ -1103,7 +1106,7 @@ void Ctrl::SyncNativeWindows(void)
|
|||
{
|
||||
XWindow &xw = xwindows[i];
|
||||
Window w = xwindows.GetKey(i);
|
||||
if(xw.ctrl && xw.ctrl->uparent && w)
|
||||
if(xw.ctrl && xw.ctrl->GetParent() && w)
|
||||
{
|
||||
Window dummy;
|
||||
int x, y;
|
||||
|
|
|
|||
299
upptst/UWordNOGTK/UWord.cpp
Normal file
299
upptst/UWordNOGTK/UWord.cpp
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
#include <RichEdit/RichEdit.h>
|
||||
#include <PdfDraw/PdfDraw.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define IMAGECLASS UWordImg
|
||||
#define IMAGEFILE <UWordNOGTK/UWord.iml>
|
||||
#include <Draw/iml.h>
|
||||
|
||||
FileSel& UWordFs()
|
||||
{
|
||||
static FileSel fs;
|
||||
return fs;
|
||||
}
|
||||
|
||||
FileSel& PdfFs()
|
||||
{
|
||||
static FileSel fs;
|
||||
return fs;
|
||||
}
|
||||
|
||||
class UWord : public TopWindow {
|
||||
public:
|
||||
virtual void DragAndDrop(Point, PasteClip& d);
|
||||
virtual void FrameDragAndDrop(Point, PasteClip& d);
|
||||
|
||||
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 Pdf();
|
||||
void About();
|
||||
void Destroy();
|
||||
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");
|
||||
bar.Add("Export to PDF..", UWordImg::pdf(), THISBACK(Pdf))
|
||||
.Help("Export document to PDF file");
|
||||
if(bar.IsMenuBar()) {
|
||||
if(lrufile().GetCount())
|
||||
lrufile()(bar, THISBACK(OpenFile));
|
||||
bar.Separator();
|
||||
bar.Add("Exit", THISBACK(Destroy));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool IsRTF(const char *fn)
|
||||
{
|
||||
return ToLower(GetFileExt(fn)) == ".rtf";
|
||||
}
|
||||
|
||||
void UWord::Load(const String& name)
|
||||
{
|
||||
lrufile().NewEntry(name);
|
||||
if(IsRTF(name))
|
||||
editor.Pick(ParseRTF(LoadFile(name)));
|
||||
else
|
||||
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(IsAvailableFiles(d)) {
|
||||
Vector<String> fn = GetFiles(d);
|
||||
for(int open = 0; open < 2; open++) {
|
||||
for(int i = 0; i < fn.GetCount(); i++) {
|
||||
String ext = GetFileExt(fn[i]);
|
||||
if(FileExists(fn[i]) && (ext == ".rtf" || ext == ".qtf")) {
|
||||
if(open)
|
||||
OpenFile(fn[i]);
|
||||
else {
|
||||
if(d.Accept())
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!d.IsAccepted())
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UWord::FrameDragAndDrop(Point p, PasteClip& d)
|
||||
{
|
||||
DragAndDrop(p, d);
|
||||
}
|
||||
|
||||
void UWord::Save0()
|
||||
{
|
||||
lrufile().NewEntry(filename);
|
||||
if(filename.IsEmpty())
|
||||
SaveAs();
|
||||
else {
|
||||
if(SaveFile(filename, IsRTF(filename) ? EncodeRTF(editor.Get()) : 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::Pdf()
|
||||
{
|
||||
FileSel& fs = PdfFs();
|
||||
if(!fs.ExecuteSaveAs("Output PDF file"))
|
||||
return;
|
||||
Size page = Size(3968, 6074);
|
||||
PdfDraw pdf;
|
||||
UPP::Print(pdf, editor.Get(), page);
|
||||
SaveFile(~fs, pdf.Finish());
|
||||
}
|
||||
|
||||
void UWord::About()
|
||||
{
|
||||
PromptOK("[A5 uWord]&Using [*^www://upp.sf.net^ U`+`+] technology.");
|
||||
}
|
||||
|
||||
void UWord::Destroy()
|
||||
{
|
||||
if(editor.IsModified()) {
|
||||
switch(PromptYesNoCancel("Do you want to save the changes to the document?")) {
|
||||
case 1:
|
||||
Save();
|
||||
break;
|
||||
case -1:
|
||||
return;
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void UWord::MainBar(Bar& bar)
|
||||
{
|
||||
FileBar(bar);
|
||||
bar.Separator();
|
||||
editor.DefaultBar(bar);
|
||||
}
|
||||
|
||||
void UWord::SetBar()
|
||||
{
|
||||
toolbar.Set(THISBACK(MainBar));
|
||||
}
|
||||
|
||||
UWord::UWord()
|
||||
{
|
||||
#ifdef PLATFORM_COCOA
|
||||
SetMainMenu(THISBACK(MainMenu));
|
||||
#else
|
||||
AddFrame(menubar);
|
||||
#endif
|
||||
AddFrame(TopSeparatorFrame());
|
||||
AddFrame(toolbar);
|
||||
AddFrame(statusbar);
|
||||
Add(editor.SizePos());
|
||||
menubar.Set(THISBACK(MainMenu));
|
||||
Sizeable().Zoomable();
|
||||
WhenClose = THISBACK(Destroy);
|
||||
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()
|
||||
% PdfFs();
|
||||
if(version >= 1)
|
||||
s % lrufile();
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_FILE|LOG_ELAPSED);
|
||||
SetLanguage(LNG_ENGLISH);
|
||||
SetDefaultCharset(CHARSET_UTF8);
|
||||
|
||||
UWordFs().Type("QTF files", "*.qtf")
|
||||
.Type("RTF files", "*.rtf")
|
||||
.AllFilesType()
|
||||
.DefaultExt("qtf");
|
||||
PdfFs().Type("PDF files", "*.pdf")
|
||||
.AllFilesType()
|
||||
.DefaultExt("pdf");
|
||||
|
||||
LoadFromFile(callback(UWord::SerializeApp));
|
||||
new UWord;
|
||||
Ctrl::EventLoop();
|
||||
StoreToFile(callback(UWord::SerializeApp));
|
||||
}
|
||||
10
upptst/UWordNOGTK/UWord.iml
Normal file
10
upptst/UWordNOGTK/UWord.iml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(pdf)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,157,146,129,13,192,32,8,4,29,193,1,216,67,23,113,16,55,112,186,14,226,34,212,198,154,98,85,16,63,33)
|
||||
IMAGE_DATA(132,196,227,5,53,214,88,195,8,149,49,240,184,25,75,190,41,198,122,118,81,179,188,247,237,80,205,0,125,173,245,255)
|
||||
IMAGE_DATA(231,222,31,6,158,206,42,251,103,210,99,206,79,238,67,120,36,61,242,193,254,145,244,240,111,214,254,131,22,151,115,206)
|
||||
IMAGE_DATA(227,134,86,254,185,232,128,255,230,223,208,99,193,238,95,96,161,188,39,251,254,2,27,66,144,255,31,195,166,148,150,188)
|
||||
IMAGE_DATA(38,110,182,2,234,21,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(160, 1)
|
||||
15
upptst/UWordNOGTK/UWordNOGTK.upp
Normal file
15
upptst/UWordNOGTK/UWordNOGTK.upp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
description "Wordprocessor application\377";
|
||||
|
||||
uses
|
||||
CtrlLib,
|
||||
RichEdit,
|
||||
PdfDraw,
|
||||
plugin\jpg;
|
||||
|
||||
file
|
||||
UWord.cpp,
|
||||
UWord.iml;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI NOGTK";
|
||||
|
||||
BIN
upptst/UWordNOGTK/icon.ico
Normal file
BIN
upptst/UWordNOGTK/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6 B |
Loading…
Add table
Add a link
Reference in a new issue