CtrlCore: Refactored multimonitor support

This commit is contained in:
Mirek Fidler 2023-03-15 15:26:59 +01:00
parent 05765c5193
commit 24de794907
13 changed files with 79 additions and 27 deletions

View file

@ -250,7 +250,7 @@ void WakeUpGuiThread(void)
Rect Ctrl::GetWorkArea() const
{
return GetWorkArea(GetScreenRect().TopLeft());
return StdGetWorkArea();
}
Rect MakeScreenRect(NSScreen *screen, CGRect r)

View file

@ -820,6 +820,8 @@ protected:
static void TimerProc(dword time);
Ctrl& Unicode() { unicode = true; return *this; }
Rect StdGetWorkArea() const;
enum {
ATTR_LAYOUT_ID,

View file

@ -437,4 +437,18 @@ Rect Ctrl::GetWorkArea(Point pt)
return GetPrimaryWorkArea();
}
Rect Ctrl::StdGetWorkArea() const
{
GuiLock __;
static Array<Rect> rc;
if(rc.IsEmpty())
GetWorkArea(rc);
const Ctrl *top = GetTopCtrl();
if(top && top->IsOpen())
return GetWorkArea(top->GetScreenRect().TopLeft());
return GetPrimaryWorkArea();
}
}

View file

@ -53,7 +53,7 @@ void Ctrl::Create(Ctrl *owner, bool popup)
Rect r = GetRect();
gtk_window_set_default_size (gtk(), LSC(r.GetWidth()), LSC(r.GetHeight()));
gtk_window_move(gtk(), LSC(r.left), LSC(r.top));
gtk_window_resize(gtk(), LSC(r.GetWidth()), LSC(r.GetHeight()));

View file

@ -74,7 +74,7 @@ void TopWindow::CenterRect(Ctrl *owner)
if(owner && center == 1 || center == 2) {
Size sz = GetRect().Size();
Rect r, wr;
wr = Ctrl::GetWorkArea();
wr = Ctrl::GetPrimaryWorkArea();
Rect fm = GetFrameMargins();
if(center == 1)
r = owner->GetRect();

View file

@ -189,16 +189,7 @@ void Ctrl::SetAlpha(byte alpha)
Rect Ctrl::GetWorkArea() const
{
GuiLock __;
static Array<Rect> rc;
if(rc.IsEmpty())
GetWorkArea(rc);
Point pt = GetScreenRect().TopLeft();
for (int i = 0; i < rc.GetCount(); i++)
if(rc[i].Contains(pt))
return rc[i];
return GetPrimaryWorkArea();
return StdGetWorkArea();
}
void Ctrl::GetWorkArea(Array<Rect>& rc)

View file

@ -156,7 +156,7 @@ void TopWindow::SetupRect(Ctrl *owner)
r.SetSize(max(r.GetSize(), GetMinSize()));
SetRect(r);
if(r.left == 0 && r.top == 0 && center == 1) {
Rect area = owner ? owner->GetWorkArea() : Ctrl::GetWorkArea();
Rect area = owner ? owner->GetWorkArea() : Ctrl::GetPrimaryWorkArea();
SetRect(area.CenterRect(min(area.Size(), r.Size())));
}
}

View file

@ -539,16 +539,7 @@ void Ctrl::GetWorkArea(Array<Rect>& out)
Rect Ctrl::GetWorkArea() const
{
GuiLock __;
static Array<Rect> rc;
if (rc.IsEmpty())
GetWorkArea(rc);
Point pt = GetScreenRect().TopLeft();
for (int i = 0; i < rc.GetCount(); i++)
if(rc[i].Contains(pt))
return rc[i];
return GetPrimaryWorkArea();
return StdGetWorkArea();
}
Rect Ctrl::GetVirtualWorkArea()

View file

@ -23,7 +23,6 @@ private:
Zoom zoom;
int cx;
ScrollBar sb;
Scroller scroller;
RichText text;
bool sizetracking;
bool vcenter;

View file

@ -58,7 +58,6 @@ void RichTextView::Paint(Draw& w)
pi.zoom = GetZoom();
pi.textcolor = textcolor;
int q = sb * pi.zoom;
scroller.Set(q);
w.Offset(0, -q);
SimplePageDraw pw(w);
pi.top = PageY(0, sb);
@ -317,7 +316,7 @@ void RichTextView::SetData(const Value& v)
void RichTextView::Scroll()
{
scroller.Scroll(*this, Rect(GetSize()).Deflated(margin), sb * GetZoom());
Refresh();
}
bool RichTextView::GotoLabel(Gate<const WString&> match, bool dohighlight, bool find_last)

View file

@ -795,6 +795,7 @@ String SelectPackage(String& nest, const char *title, const char *startwith, boo
LoadFromGlobal(dlg, c);
dlg.SyncBrief();
dlg.SyncFilter();
dlg.CenterScreen();
String b = dlg.Run(nest, startwith);
StoreToGlobal(dlg, c);
return b;

9
upptst/MultiMon/GUI.upp Normal file
View file

@ -0,0 +1,9 @@
uses
CtrlLib;
file
main.cpp;
mainconfig
"" = "GUI";

46
upptst/MultiMon/main.cpp Normal file
View file

@ -0,0 +1,46 @@
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MyApp : TopWindow {
RichTextCtrl view;
void Layout() {
Array<Rect> a;
GetWorkArea(a);
String text = "[g \1"
"Rect: " << GetRect() << "\n" <<
"ScreenRect: " << GetScreenRect() << "\n" <<
"WorkArea: " << GetWorkArea() << "\n" <<
"WorkAreas: " << a << "\n" <<
"PrimaryWorkArea: " << GetPrimaryWorkArea() << "\n"
;
for(int i = 0; i < 200; i++)
text << "\n";
view.SetQTF(text);
}
void Serialize(Stream& s)
{
SerializePlacement(s);
}
MyApp() {
Sizeable().Zoomable();
Add(view.SizePos());
view.WhenLeftClick = [=] {
PromptOK("Test");
};
}
};
GUI_APP_MAIN
{
MyApp app;
LoadFromFile(app);
app.Run();
Rect r = app.GetRect();
StoreToFile(app);
PromptOK("OK \1" + AsString(r));
}