New test.
[mono.git] / mcs / class / Mono.Cairo / snippets / SnippetsSwf.cs
1 using System;
2 using Cairo;
3 using System.Windows.Forms;
4 using System.Drawing;
5
6 namespace Cairo.Snippets
7 {
8         class CairoSnippetsSwf
9         {
10                 int width = 400;
11                 int height = 200;
12
13                 DrawingArea da;
14
15                 static void Main ()
16                 {
17                         new CairoSnippetsSwf ();
18                         Application.Run ();
19                 }
20
21                 CairoSnippetsSwf ()
22                 {
23                         Form f = new Form ();
24                         f.ClientSize = new Size (width, height);
25                         f.Closed += OnClosed;
26
27                         Splitter split = new Splitter ();
28                         split.Dock = DockStyle.Left;
29                         split.SplitPosition = width / 2;
30                         ListView lv = new ListView ();
31                         foreach (string s in Snippets.snippets)
32                                 lv.Items.Add (new ListViewItem (s));
33                         lv.Dock = DockStyle.Left;
34                         lv.SelectedIndexChanged += OnSelected;
35
36                         da = new DrawingArea ();
37                         da.Dock = DockStyle.Right;
38                         f.Controls.AddRange (new Control[] {split, lv, da});
39                         
40                         f.Show ();
41                 }
42
43                 void OnClosed (object sender, EventArgs e)
44                 {
45                         Application.Exit ();
46                 }
47
48                 void OnSelected (object sender, EventArgs e)
49                 {
50                         ListView lv = sender as ListView;
51                         if (lv.SelectedItems.Count > 0)
52                                 da.Draw (lv.SelectedItems[0].Text, width / 2, height);
53                 }
54         }
55
56         public class DrawingArea : Panel
57         {
58                 string name = "arc";
59                 Snippets snips = new Snippets ();
60                 int w, h;
61                         
62                 public void Draw (string snippet, int width, int height)
63                 {
64                         name = snippet;
65                         w = width;
66                         h = height;
67                         Invalidate ();
68                 }
69                         
70                 protected override void OnPaint (PaintEventArgs e)
71                 {
72                         IntPtr hdc = e.Graphics.GetHdc ();
73                         // will only work on win32
74                         Win32Surface s = new Win32Surface (hdc);
75                         Context cr = new Context (s);
76                         Snippets.InvokeSnippet (snips, name, cr, w, h);
77                         e.Graphics.ReleaseHdc (hdc);
78                 }
79         }
80 }
81