mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-16 11:34:47 +02:00
2004-06-01 Jeroen Zwartepoorte <jeroen@xs4all.nl>
* sample/CustomWidget.cs: Add custom widget sample. * sample/Makefile.am: Idem. svn path=/trunk/gtk-sharp/; revision=28649
This commit is contained in:
parent
070eb3cc64
commit
03df165143
@ -1,3 +1,8 @@
|
|||||||
|
2004-06-01 Jeroen Zwartepoorte <jeroen@xs4all.nl>
|
||||||
|
|
||||||
|
* sample/CustomWidget.cs: Add custom widget sample.
|
||||||
|
* sample/Makefile.am: Idem.
|
||||||
|
|
||||||
2004-06-01 Mike Kestner <mkestner@ximian.com>
|
2004-06-01 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* generator/ObjectGen.cs : generate protected ctor () for all
|
* generator/ObjectGen.cs : generate protected ctor () for all
|
||||||
|
182
sample/CustomWidget.cs
Normal file
182
sample/CustomWidget.cs
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
using GLib;
|
||||||
|
using Gtk;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
class CustomWidgetTest {
|
||||||
|
public static int Main (string[] args)
|
||||||
|
{
|
||||||
|
Application.Init ();
|
||||||
|
Window win = new Window ("Custom Widget Test");
|
||||||
|
win.DeleteEvent += new DeleteEventHandler (OnQuit);
|
||||||
|
|
||||||
|
VPaned paned = new VPaned ();
|
||||||
|
CustomWidget cw = new CustomWidget ();
|
||||||
|
cw.Label = "This one contains a button";
|
||||||
|
Button button = new Button ("Ordinary button");
|
||||||
|
cw.Add (button);
|
||||||
|
paned.Pack1 (cw, true, false);
|
||||||
|
|
||||||
|
cw = new CustomWidget ();
|
||||||
|
cw.Label = "And this one a TextView";
|
||||||
|
cw.StockId = Stock.JustifyLeft;
|
||||||
|
ScrolledWindow sw = new ScrolledWindow (null, null);
|
||||||
|
sw.ShadowType = ShadowType.In;
|
||||||
|
sw.HscrollbarPolicy = PolicyType.Automatic;
|
||||||
|
sw.VscrollbarPolicy = PolicyType.Automatic;
|
||||||
|
TextView textView = new TextView ();
|
||||||
|
sw.Add (textView);
|
||||||
|
cw.Add (sw);
|
||||||
|
paned.Pack2 (cw, true, false);
|
||||||
|
|
||||||
|
win.Add (paned);
|
||||||
|
win.ShowAll ();
|
||||||
|
Application.Run ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnQuit (object sender, DeleteEventArgs args)
|
||||||
|
{
|
||||||
|
Application.Quit ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomWidget : Bin {
|
||||||
|
internal static GType customWidgetGType;
|
||||||
|
private Gdk.Pixbuf icon;
|
||||||
|
private string label;
|
||||||
|
private Pango.Layout layout;
|
||||||
|
private string stockid;
|
||||||
|
|
||||||
|
public CustomWidget () : base ()
|
||||||
|
{
|
||||||
|
icon = null;
|
||||||
|
label = "CustomWidget";
|
||||||
|
layout = null;
|
||||||
|
stockid = Stock.Execute;
|
||||||
|
|
||||||
|
Flags |= (int)WidgetFlags.NoWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gdk.Pixbuf Icon {
|
||||||
|
get {
|
||||||
|
if (icon == null)
|
||||||
|
icon = RenderIcon (stockid, IconSize.Menu, "");
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Label {
|
||||||
|
get {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
label = value;
|
||||||
|
Layout.SetText (label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pango.Layout Layout {
|
||||||
|
get {
|
||||||
|
if (layout == null)
|
||||||
|
layout = CreatePangoLayout (label);
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string StockId {
|
||||||
|
get {
|
||||||
|
return stockid;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
stockid = value;
|
||||||
|
icon = RenderIcon (stockid, IconSize.Menu, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gdk.Rectangle TitleArea {
|
||||||
|
get {
|
||||||
|
Gdk.Rectangle area;
|
||||||
|
area.X = Allocation.X + (int)BorderWidth;
|
||||||
|
area.Y = Allocation.Y + (int)BorderWidth;
|
||||||
|
area.Width = (Allocation.Width - 2 * (int)BorderWidth);
|
||||||
|
|
||||||
|
int layoutWidth, layoutHeight;
|
||||||
|
Layout.GetPixelSize (out layoutWidth, out layoutHeight);
|
||||||
|
area.Height = Math.Max (layoutHeight, icon.Height);
|
||||||
|
|
||||||
|
return area;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnExposeEvent (Gdk.EventExpose args)
|
||||||
|
{
|
||||||
|
Gdk.Rectangle exposeArea;
|
||||||
|
Gdk.Rectangle titleArea = TitleArea;
|
||||||
|
|
||||||
|
if (args.Area.Intersect (titleArea, out exposeArea))
|
||||||
|
GdkWindow.DrawPixbuf (Style.BackgroundGC (State), Icon, 0, 0,
|
||||||
|
titleArea.X, titleArea.Y, Icon.Width,
|
||||||
|
Icon.Height, Gdk.RgbDither.None, 0, 0);
|
||||||
|
|
||||||
|
titleArea.X += icon.Width + 1;
|
||||||
|
titleArea.Width -= icon.Width - 1;
|
||||||
|
|
||||||
|
if (args.Area.Intersect (titleArea, out exposeArea)) {
|
||||||
|
int layoutWidth, layoutHeight;
|
||||||
|
Layout.GetPixelSize (out layoutWidth, out layoutHeight);
|
||||||
|
|
||||||
|
titleArea.Y += (titleArea.Height - layoutHeight) / 2;
|
||||||
|
|
||||||
|
Style.PaintLayout (Style, GdkWindow, State,
|
||||||
|
true, exposeArea, this, null,
|
||||||
|
titleArea.X, titleArea.Y, Layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.OnExposeEvent (args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnRealized ()
|
||||||
|
{
|
||||||
|
Flags |= (int)WidgetFlags.Realized;
|
||||||
|
|
||||||
|
GdkWindow = ParentWindow;
|
||||||
|
Style = Style.Attach (GdkWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
|
||||||
|
{
|
||||||
|
base.OnSizeAllocated (allocation);
|
||||||
|
|
||||||
|
int bw = (int)BorderWidth;
|
||||||
|
|
||||||
|
Gdk.Rectangle titleArea = TitleArea;
|
||||||
|
|
||||||
|
if (Child != null) {
|
||||||
|
Gdk.Rectangle childAllocation;
|
||||||
|
childAllocation.X = allocation.X + bw;
|
||||||
|
childAllocation.Y = allocation.Y + bw + titleArea.Height;
|
||||||
|
childAllocation.Width = allocation.Width - 2 * bw;
|
||||||
|
childAllocation.Height = allocation.Height - 2 * bw - titleArea.Height;
|
||||||
|
Child.SizeAllocate (childAllocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnSizeRequested (ref Requisition requisition)
|
||||||
|
{
|
||||||
|
requisition.Width = requisition.Height = (int)BorderWidth * 2;
|
||||||
|
requisition.Width += Icon.Width + 1;
|
||||||
|
|
||||||
|
int layoutWidth, layoutHeight;
|
||||||
|
Layout.GetPixelSize (out layoutWidth, out layoutHeight);
|
||||||
|
requisition.Height += layoutHeight;
|
||||||
|
|
||||||
|
if (Child != null && Child.Visible) {
|
||||||
|
Requisition childReq = Child.SizeRequest ();
|
||||||
|
requisition.Height += childReq.Height;
|
||||||
|
|
||||||
|
requisition.Width += Math.Max (layoutWidth, childReq.Width);
|
||||||
|
} else {
|
||||||
|
requisition.Width += layoutWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ VTE_TARGETS=
|
|||||||
VTE_ASSEMBLY=
|
VTE_ASSEMBLY=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TARGETS = custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe drawing-sample.exe $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS)
|
TARGETS = custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe drawing-sample.exe custom-widget.exe $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS)
|
||||||
|
|
||||||
assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY)
|
assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY)
|
||||||
references=$(addprefix -r , $(assemblies))
|
references=$(addprefix -r , $(assemblies))
|
||||||
@ -92,6 +92,9 @@ custom-cellrenderer.exe: $(srcdir)/CustomCellRenderer.cs $(assemblies)
|
|||||||
drawing-sample.exe: $(srcdir)/DrawingSample.cs $(srcdir)/sysdraw.cs $(assemblies)
|
drawing-sample.exe: $(srcdir)/DrawingSample.cs $(srcdir)/sysdraw.cs $(assemblies)
|
||||||
$(CSC) -debug+ -out:drawing-sample.exe $(references) $(srcdir)/DrawingSample.cs $(srcdir)/sysdraw.cs -r:System.Drawing
|
$(CSC) -debug+ -out:drawing-sample.exe $(references) $(srcdir)/DrawingSample.cs $(srcdir)/sysdraw.cs -r:System.Drawing
|
||||||
|
|
||||||
|
custom-widget.exe: $(srcdir)/CustomWidget.cs $(assemblies)
|
||||||
|
$(CSC) -debug+ -out:custom-widget.exe $(references) $(srcdir)/CustomWidget.cs
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
HelloWorld.cs \
|
HelloWorld.cs \
|
||||||
GnomeHelloWorld.cs \
|
GnomeHelloWorld.cs \
|
||||||
@ -115,4 +118,5 @@ EXTRA_DIST = \
|
|||||||
CustomCellRenderer.cs \
|
CustomCellRenderer.cs \
|
||||||
DrawingSample.cs \
|
DrawingSample.cs \
|
||||||
sysdraw.cs \
|
sysdraw.cs \
|
||||||
drawing-sample.exe.config
|
drawing-sample.exe.config \
|
||||||
|
CustomWidget.cs
|
||||||
|
Loading…
Reference in New Issue
Block a user