Some more messing around with [osx]

This commit is contained in:
Hylke Bons 2010-12-17 00:38:51 +01:00
parent 0e2472cd79
commit 7a60042c48
7 changed files with 452 additions and 3141 deletions

View file

@ -20,6 +20,6 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSBackgroundOnly</key>
<true/>
<false/>
</dict>
</plist>

View file

@ -0,0 +1,298 @@
//
// Layout.cs
//
// Author:
// Michael Hutchinson <mhutchinson@novell.com>
//
// Copyright (c) 2010 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Drawing;
using MonoMac.AppKit;
using System.Linq;
namespace MonoDevelop.Platform.Mac
{
interface ILayout
{
LayoutRequest BeginLayout ();
void EndLayout (LayoutRequest request, PointF origin, SizeF allocation);
}
class LayoutRequest
{
public SizeF Size { get; set; }
public bool Visible { get; set; }
public bool ExpandWidth { get; set; }
public bool ExpandHeight { get; set; }
}
abstract class LayoutBox : IEnumerable<ILayout>, ILayout
{
List<ILayout> children = new List<ILayout> ();
public float Spacing { get; set; }
public float PadLeft { get; set; }
public float PadRight { get; set; }
public float PadTop { get; set; }
public float PadBottom { get; set; }
public LayoutAlign Align { get; set; }
public LayoutDirection Direction { get; set; }
public LayoutBox (LayoutDirection direction, float spacing) : this (direction, spacing, 0)
{
}
public LayoutBox (LayoutDirection direction, float spacing, float padding)
{
PadLeft = PadRight = PadTop = PadBottom = padding;
this.Direction = direction;
this.Spacing = spacing;
this.Align = LayoutAlign.Center;
}
public int Count { get { return children.Count; } }
bool IsHorizontal { get { return Direction == LayoutDirection.Horizontal; } }
public IEnumerator<ILayout> GetEnumerator ()
{
return children.GetEnumerator ();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
return children.GetEnumerator ();
}
public void Add (ILayout child)
{
children.Add (child);
OnChildAdded (child);
}
ContainerLayoutRequest request = new ContainerLayoutRequest ();
public virtual LayoutRequest BeginLayout ()
{
float width = 0;
float height = 0;
request.ChildRequests.Clear ();
request.ChildRequests.AddRange (children.Select (c => c.BeginLayout ()));
foreach (var r in request.ChildRequests) {
if (!r.Visible)
continue;
request.Visible = true;
if (r.ExpandWidth)
request.ExpandWidth = true;
if (r.ExpandHeight)
request.ExpandHeight = true;
if (IsHorizontal) {
if (width != 0)
width += Spacing;
width += r.Size.Width;
height = Math.Max (height, r.Size.Height);
} else {
if (height != 0)
height += Spacing;
height += r.Size.Height;
width = Math.Max (width, r.Size.Width);
}
}
request.Size = new SizeF (width + PadLeft + PadRight, height + PadTop + PadBottom);
return request;
}
public virtual void EndLayout (LayoutRequest request, PointF origin, SizeF allocation)
{
var childRequests = ((ContainerLayoutRequest) request).ChildRequests;
allocation = new SizeF (allocation.Width - PadLeft - PadRight, allocation.Height - PadBottom - PadTop);
origin = new PointF (origin.X + PadLeft, origin.Y + PadBottom);
var size = request.Size;
size.Height -= (PadTop + PadBottom);
size.Width -= (PadLeft + PadRight);
int wExpandCount = 0;
int hExpandCount = 0;
int visibleCount = 0;
foreach (var childRequest in childRequests) {
if (childRequest.Visible)
visibleCount++;
else
continue;
if (childRequest.ExpandWidth)
wExpandCount++;
if (childRequest.ExpandHeight)
hExpandCount++;
}
float wExpand = 0;
if (allocation.Width > size.Width) {
wExpand = allocation.Width - size.Width;
if (wExpandCount > 0)
wExpand /= wExpandCount;
}
float hExpand = 0;
if (allocation.Height > size.Height) {
hExpand = allocation.Height - size.Height;
if (hExpandCount > 0)
hExpand /= hExpandCount;
}
if (Direction == LayoutDirection.Horizontal) {
float pos = PadLeft;
if (wExpandCount == 0) {
if (Align == LayoutAlign.End)
pos += wExpand;
else if (Align == LayoutAlign.Center)
pos += wExpand / 2;
}
for (int i = 0; i < childRequests.Count; i++) {
var child = children[i];
var childReq = childRequests[i];
if (!childReq.Visible)
continue;
var childSize = new SizeF (childReq.Size.Width, allocation.Height);
if (childReq.ExpandWidth) {
childSize.Width += wExpand;
} else if (hExpandCount == 0 && Align == LayoutAlign.Fill) {
childSize.Width += wExpand / visibleCount;
}
child.EndLayout (childReq, new PointF (pos, origin.Y), childSize);
pos += childSize.Width + Spacing;
}
} else {
float pos = PadBottom;
if (hExpandCount == 0) {
if (Align == LayoutAlign.End)
pos += hExpand;
else if (Align == LayoutAlign.Center)
pos += hExpand / 2;
}
for (int i = 0; i < childRequests.Count; i++) {
var child = children[i];
var childReq = childRequests[i];
if (!childReq.Visible)
continue;
var childSize = new SizeF (allocation.Width, childReq.Size.Height);
if (childReq.ExpandHeight) {
childSize.Height += hExpand;
} else if (hExpandCount == 0 && Align == LayoutAlign.Fill) {
childSize.Height += hExpand / visibleCount;
}
child.EndLayout (childReq, new PointF (origin.X, pos), childSize);
pos += childSize.Height + Spacing;
}
}
}
protected abstract void OnChildAdded (ILayout child);
class ContainerLayoutRequest : LayoutRequest
{
public List<LayoutRequest> ChildRequests = new List<LayoutRequest> ();
}
}
public enum LayoutAlign
{
Begin, Center, End, Fill
}
public enum LayoutDirection
{
Horizontal, Vertical
}
abstract class LayoutAlignment : ILayout
{
public LayoutAlignment ()
{
XAlign = YAlign = LayoutAlign.Center;
}
public LayoutAlign XAlign { get; set; }
public LayoutAlign YAlign { get; set; }
public bool ExpandHeight { get; set; }
public bool ExpandWidth { get; set; }
public float MinHeight { get; set; }
public float MinWidth { get; set; }
public float PadLeft { get; set; }
public float PadRight { get; set; }
public float PadTop { get; set; }
public float PadBottom { get; set; }
public bool Visible { get; set; }
LayoutRequest request = new LayoutRequest ();
public virtual LayoutRequest BeginLayout ()
{
request.Size = new SizeF (MinWidth + PadLeft + PadRight, MinHeight + PadTop + PadBottom);
request.ExpandHeight = this.ExpandHeight;
request.ExpandWidth = this.ExpandWidth;
request.Visible = this.Visible;
return request;
}
public virtual void EndLayout (LayoutRequest request, PointF origin, SizeF allocation)
{
var frame = new RectangleF (origin.X + PadLeft, origin.Y + PadBottom,
allocation.Width - PadLeft - PadRight, allocation.Height - PadTop - PadBottom);
if (allocation.Height > request.Size.Height) {
if (YAlign != LayoutAlign.Fill) {
frame.Height = request.Size.Height - PadTop - PadBottom;
if (YAlign == LayoutAlign.Center) {
frame.Y += (allocation.Height - request.Size.Height) / 2;
} else if (YAlign == LayoutAlign.End) {
frame.Y += (allocation.Height - request.Size.Height);
}
}
}
if (allocation.Width > request.Size.Width) {
if (XAlign != LayoutAlign.Fill) {
frame.Width = request.Size.Width - PadLeft - PadRight;
if (XAlign == LayoutAlign.Center) {
frame.X += (allocation.Width - request.Size.Width) / 2;
} else if (XAlign == LayoutAlign.End) {
frame.X += (allocation.Width - request.Size.Width);
}
}
}
OnLayoutEnded (frame);
}
protected abstract void OnLayoutEnded (RectangleF frame);
}
}

View file

@ -1,9 +1,11 @@
using System;
using System.Drawing;
using System.Timers;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
using MonoMac.Growl;
namespace SparkleShare
{
@ -13,15 +15,16 @@ namespace SparkleShare
{
NSApplication.Init ();
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
NSApplication.SharedApplication.applicationIconImage = NSImage.ImageNamed ("sparkleshare.icns");
NSApplication.Main (args);
}
}
[MonoMac.Foundation.Register("AppDelegate")]
public partial class AppDelegate : NSApplicationDelegate
{
//MainWindowController mainWindowController;
NSStatusItem StatusItem;
@ -33,25 +36,37 @@ namespace SparkleShare
NSMenuItem AboutMenuItem;
NSMenuItem QuitMenuItem;
NSTextField text;
NSWindow window;
NSButton button;
NSButton button2;
WebView web_view;
NSDockTile tile;
int i = 0;
/* public override NSMenu ApplicationDockMenu (NSApplication app)
{
return (NSMenu) Menu;
}
*/
public AppDelegate ()
{
}
public override void FinishedLaunching (NSObject notification)
{
/* tile = NSApplication.SharedApplication.DockTile;
tile.BadgeLabel = "!";
tile.Display ();
*/
// mainWindowController = new MainWindowController ();
// mainWindowController.Window.MakeKeyAndOrderFront (this);
@ -59,7 +74,7 @@ namespace SparkleShare
// SparkleRepo repo = new SparkleRepo ("/Users/hbons/SparkleShare/SparkleShare-Test");
StatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (32);
StatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (28);
StatusItem.Enabled = true;
StatusItem.Image = NSImage.ImageNamed ("sparkleshare-idle.png");
@ -75,11 +90,33 @@ namespace SparkleShare
Menu.AddItem (NSMenuItem.SeparatorItem);
Timer timer = new Timer () {
Interval = 500
};
FolderMenuItem = new NSMenuItem () {
Title="SparkleShare", Enabled = true,
Action = new Selector ("ddd")
};
timer.Elapsed += delegate {
FolderMenuItem.InvokeOnMainThread (delegate {
if (i == 0){
StatusItem.Image = NSImage.ImageNamed ("sparkleshare-idle-focus.png");
i = 1;
}else{
StatusItem.Image = NSImage.ImageNamed ("sparkleshare-idle.png");
i = 0;
}
/*FolderMenuItem.Title+="Z";Menu.Update ();*/});
};
timer.Start ();
FolderMenuItem.Activated += delegate {
Console.WriteLine ("DDDD");
};
@ -90,7 +127,7 @@ namespace SparkleShare
Menu.AddItem (FolderMenuItem);
FolderMenuItems = new NSMenuItem [2] {
new NSMenuItem () { Title = "gnome-design" },
new NSMenuItem () { Title = "gnome-design (2)" },
new NSMenuItem () { Title = "tango-icons" }
};
@ -139,29 +176,36 @@ window = new NSWindow (new RectangleF (0, 0, 480, 640),
window.Title = "Recent Events in 'gnome-design'";
window.HasShadow = true;
window.DefaultButtonCell = button2.Cell;
//window.DefaultButtonCell = button2.Cell;
window.BackingType = NSBackingStore.Buffered;
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
window.MakeKeyAndOrderFront (this);
window.Center ();
};
item.Image = NSImage.ImageNamed ("NSFolder");
Menu.AddItem (item);
};
Menu.AddItem (NSMenuItem.SeparatorItem);
SyncMenuItem = new NSMenuItem () {
Title = "Sync Remote Folder..."
Title = "Add Remote Folder..."
};
SyncMenuItem.Activated += delegate {
@ -209,7 +253,7 @@ window = new NSWindow (new RectangleF (0, 0, 480, 640),
Menu.AddItem (AboutMenuItem);
Menu.AddItem (NSMenuItem.SeparatorItem);
// Menu.AddItem (NSMenuItem.SeparatorItem);
QuitMenuItem = new NSMenuItem () {
@ -220,11 +264,20 @@ window = new NSWindow (new RectangleF (0, 0, 480, 640),
Environment.Exit (0);
};
Menu.AddItem (QuitMenuItem);
//Menu.AddItem (QuitMenuItem);
StatusItem.Menu = Menu;
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -10,4 +10,9 @@
namespace SparkleShare {
// Should subclass MonoMac.AppKit.NSResponder
[MonoMac.Foundation.Register("AppDelegate")]
public partial class AppDelegate {
}
}

View file

@ -50,6 +50,7 @@
<Compile Include="MainMenu.xib.designer.cs">
<DependentUpon>MainMenu.xib</DependentUpon>
</Compile>
<Compile Include="Layout.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />
@ -62,6 +63,7 @@
<ItemGroup>
<Content Include="sparkleshare-idle-focus.png" />
<Content Include="sparkleshare-idle.png" />
<Content Include="sparkleshare.icns" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\SparkleLib\SparkleLib.csproj">

Binary file not shown.