mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
CtrLib: Developing MacOS local menu
git-svn-id: svn://ultimatepp.org/upp/trunk@12344 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b87b538f58
commit
5efc767b82
7 changed files with 93 additions and 13 deletions
|
|
@ -684,6 +684,8 @@ Array <NetAdapter> GetAdapterInfo() {
|
|||
}
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_OSX
|
||||
|
||||
Array<NetAdapter> GetAdapterInfo() {
|
||||
Array<NetAdapter> res;
|
||||
|
||||
|
|
@ -819,7 +821,7 @@ Array<NetAdapter> GetAdapterInfo() {
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Not implemented yet in Linux
|
||||
String GetHDSerial() {
|
||||
|
|
@ -1589,6 +1591,7 @@ bool GetDriveSpace(String drive,
|
|||
return true;
|
||||
}
|
||||
|
||||
#ifndef PLATFORM_OSX
|
||||
// return true if mounted
|
||||
bool GetDriveInformation(String drive, String &type, String &volume, /*uint64 &serial, */int &maxName, String &fileSystem)
|
||||
{
|
||||
|
|
@ -1625,6 +1628,7 @@ bool GetDriveInformation(String drive, String &type, String &volume, /*uint64 &s
|
|||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1688,7 +1692,7 @@ bool Shutdown(String action) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
#ifdef PLATFORM_LINUX
|
||||
bool Shutdown(String action) {
|
||||
if (action == "logoff") {
|
||||
kill(1, SIGTSTP);
|
||||
|
|
@ -1992,7 +1996,9 @@ void SystemSignature::Load() {
|
|||
GetSystemInfo(manufacturer, productName, version, numberOfProcessors, mbSerial);
|
||||
hdSerial = GetHDSerial();
|
||||
userName = GetUserName();
|
||||
#ifndef PLATFORM_OSX
|
||||
netAdapters = GetAdapterInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@
|
|||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#ifndef PLATFORM_OSX
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
#include <sys/utsname.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
|
|
|
|||
|
|
@ -14,20 +14,23 @@ GUI_APP_MAIN
|
|||
Font fnt;
|
||||
fnt.FaceName(f);
|
||||
dword l = 0;
|
||||
int n = 0;
|
||||
for(int ch = 32; ch < 4096; ch++) {
|
||||
if(GetGlyphInfo(fnt, ch).IsNormal()) {
|
||||
l |= (0x80000000 >> (ch / 128));
|
||||
ch = (ch + 127) & ~127;
|
||||
// ch = (ch + 127) & ~127;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
dword h = 0;
|
||||
for(int ch = 32; ch < 65536; ch++) {
|
||||
if(GetGlyphInfo(fnt, ch).IsNormal()) {
|
||||
h |= (0x80000000 >> (ch / 2048));
|
||||
ch = (ch + 2047) & ~2047;
|
||||
// ch = (ch + 2047) & ~2047;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
LOG("{ " << AsCString(f) << ", 0x" << FormatIntHex(l) << ", 0x" << FormatIntHex(h) << " },");
|
||||
LOG("{ " << AsCString(f) << ", 0x" << FormatIntHex(l) << ", 0x" << FormatIntHex(h) << " }, // " << n);
|
||||
}
|
||||
PromptOK("OK");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
sooner:
|
||||
|
||||
- cursor problem after local menu invocation
|
||||
|
||||
- support bundle icons
|
||||
|
||||
- correctly reload plist
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ protected:
|
|||
virtual void AddCtrl(Ctrl *ctrl, Size sz) = 0;
|
||||
|
||||
class ScanKeys;
|
||||
|
||||
friend class MenuBar;
|
||||
|
||||
public:
|
||||
virtual bool IsEmpty() const = 0;
|
||||
|
|
@ -296,9 +298,10 @@ public:
|
|||
virtual bool IsMenuBar() const { return true; }
|
||||
|
||||
protected:
|
||||
virtual Item& AddItem(Event<> cb);
|
||||
virtual Item& AddItem(Event<> cb);
|
||||
virtual Item& AddSubMenu(Event<Bar&> proc);
|
||||
virtual Value GetBackground() const;
|
||||
virtual bool IsEmpty() const;
|
||||
|
||||
public:
|
||||
struct Style : ChStyle<Style> {
|
||||
|
|
@ -332,6 +335,12 @@ private:
|
|||
LookFrame frame;
|
||||
bool nodarkadjust;
|
||||
|
||||
#ifdef PLATFORM_COCOA
|
||||
One<Bar> host_bar;
|
||||
void ExecuteHostBar(Ctrl *owner, Point p);
|
||||
void CreateHostBar(One<Bar>& bar);
|
||||
#endif
|
||||
|
||||
friend class MenuItemBase;
|
||||
friend class SubMenuBase;
|
||||
friend class TopSubMenuItem;
|
||||
|
|
@ -381,7 +390,6 @@ public:
|
|||
static void Execute(Event<Bar&> proc, Point p) { Execute(GetActiveCtrl(), proc, p); }
|
||||
static void Execute(Event<Bar&> proc) { Execute(proc, GetMousePos()); }
|
||||
|
||||
bool IsEmpty() const { return item.IsEmpty(); }
|
||||
void Clear();
|
||||
|
||||
static const Style& StyleDefault();
|
||||
|
|
@ -394,6 +402,9 @@ public:
|
|||
MenuBar& MaxIconSize(Size sz) { maxiconsize = sz; return *this; }
|
||||
Size GetMaxIconSize() const { return maxiconsize; }
|
||||
MenuBar& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; }
|
||||
#ifdef PLATFORM_COCOA
|
||||
MenuBar& UppMenu() { host_bar.Clear(); return *this; }
|
||||
#endif
|
||||
|
||||
typedef MenuBar CLASSNAME;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <CtrlCore/CocoMM.h>
|
||||
|
||||
#ifdef PLATFORM_COCOA
|
||||
|
||||
namespace Upp {
|
||||
|
||||
struct CocoMenuBar;
|
||||
|
|
@ -243,4 +245,31 @@ void TopWindow::SyncMainMenu(bool force)
|
|||
}
|
||||
}
|
||||
|
||||
};
|
||||
void MenuBar::ExecuteHostBar(Ctrl *owner, Point p)
|
||||
{
|
||||
if(host_bar) {
|
||||
CocoMenuBar& bar = *(CocoMenuBar *)~host_bar;
|
||||
|
||||
owner = owner->GetTopCtrl();
|
||||
|
||||
p -= owner->GetScreenRect().TopLeft();
|
||||
|
||||
double scale = 1.0 / DPI(1);
|
||||
NSPoint np;
|
||||
np.x = scale * p.x;
|
||||
np.y = scale * p.y;
|
||||
|
||||
[bar.cocomenu popUpMenuPositioningItem:bar.item[0].nsitem
|
||||
atLocation:np
|
||||
inView:(NSView *)owner->GetNSView()];
|
||||
}
|
||||
}
|
||||
|
||||
void MenuBar::CreateHostBar(One<Bar>& bar)
|
||||
{
|
||||
host_bar.Create<CocoMenuBar>();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ MenuBar::MenuBar()
|
|||
arealook = -1;
|
||||
maxiconsize = Null;
|
||||
nodarkadjust = false;
|
||||
#ifdef PLATFORM_COCOA
|
||||
CreateHostBar(host_bar);
|
||||
#endif
|
||||
}
|
||||
|
||||
MenuBar& MenuBar::SetStyle(const Style& s)
|
||||
|
|
@ -116,9 +119,13 @@ void MenuBar::Clear()
|
|||
lock--;
|
||||
}
|
||||
|
||||
Bar::Item& MenuBar::AddItem(Event<> cb)
|
||||
Bar::Item& MenuBar::AddItem(Event<> cb)
|
||||
{
|
||||
LLOG("MenuBar::AddItem " << Name());
|
||||
#ifdef PLATFORM_COCOA
|
||||
if(host_bar)
|
||||
return host_bar->AddItem(cb);
|
||||
#endif
|
||||
MenuItemBase *q;
|
||||
if(IsChild())
|
||||
q = new TopMenuItem;
|
||||
|
|
@ -139,6 +146,10 @@ Bar::Item& MenuBar::AddItem(Event<> cb)
|
|||
Bar::Item& MenuBar::AddSubMenu(Event<Bar&> proc)
|
||||
{
|
||||
LLOG("MenuBar::AddSubMenu " << Name());
|
||||
#ifdef PLATFORM_COCOA
|
||||
if(host_bar)
|
||||
return host_bar->AddSubMenu(proc);
|
||||
#endif
|
||||
SubMenuBase *w;
|
||||
MenuItemBase *q;
|
||||
if(IsChild()) {
|
||||
|
|
@ -573,6 +584,15 @@ void MenuBar::PopUp(Ctrl *owner, Point p, Size rsz)
|
|||
Animate(*this, p.x, p.y, sz.cx, sz.cy);
|
||||
}
|
||||
|
||||
bool MenuBar::IsEmpty() const
|
||||
{
|
||||
#ifdef PLATFORM_COCOA
|
||||
if(host_bar)
|
||||
return host_bar->IsEmpty();
|
||||
#endif
|
||||
return item.IsEmpty();
|
||||
}
|
||||
|
||||
void MenuBar::Execute(Ctrl *owner, Point p)
|
||||
{
|
||||
static Vector<Ctrl *> ows; // Used to prevent another open local menu for single owner to be opened (repeated right-click)
|
||||
|
|
@ -580,9 +600,16 @@ void MenuBar::Execute(Ctrl *owner, Point p)
|
|||
if(IsEmpty() || FindIndex(ows, owner) >= 0)
|
||||
return;
|
||||
ows.Add(owner);
|
||||
PopUp(owner, p);
|
||||
EventLoop(this);
|
||||
CloseMenu();
|
||||
#ifdef PLATFORM_COCOA
|
||||
if(host_bar)
|
||||
ExecuteHostBar(owner, p);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
PopUp(owner, p);
|
||||
EventLoop(this);
|
||||
CloseMenu();
|
||||
}
|
||||
ows.SetCount(level);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue