1 using System;
2 using System.Windows;
3
4 namespace FileExplorer
5 {
6 public nothrow System.Windows.Color DefaultParentPathSelectorBackgroundColor()
7 {
8 return System.Windows.Color.White();
9 }
10
11 public nothrow System.Windows.Color DefaultParentPathSelectorMouseOverColor()
12 {
13 return System.Windows.Color(230u, 243u, 255u);
14 }
15
16 public nothrow System.Windows.Color DefaultParentPathSelectorMouseClickColor()
17 {
18 return System.Windows.Color(204u, 232u, 255u);
19 }
20
21 public nothrow Padding DefaultParentPathSelectorImagePadding()
22 {
23 return Padding(2, 7, 2, 7);
24 }
25
26 public nothrow ControlCreateParams& ParentPathSelectorControlCreateParams(ControlCreateParams& controlCreateParams)
27 {
28 return controlCreateParams.SetWindowClassName("FileExplorer.ParentPathSelector").
29 SetWindowClassBackgroundColor(SystemColor.COLOR_WINDOW).
30 SetBackgroundColor(DefaultParentPathSelectorBackgroundColor()).
31 SetSize(Size(20, 0)).SetDock(Dock.left);
32 }
33
34 public class ParentPathSelectorCreateParams
35 {
36 public nothrow ParentPathSelectorCreateParams(ControlCreateParams& controlCreateParams_, ImageList* imageList_) :
37 controlCreateParams(controlCreateParams_),
38 imageList(imageList_),
39 mouseOverColor(DefaultParentPathSelectorMouseOverColor()),
40 mouseClickColor(DefaultParentPathSelectorMouseClickColor()),
41 imagePadding(DefaultParentPathSelectorImagePadding())
42 {
43 }
44 public nothrow ParentPathSelectorCreateParams& Defaults()
45 {
46 return *this;
47 }
48 public nothrow ParentPathSelectorCreateParams& SetMouseOverColor(const System.Windows.Color& mouseOverColor_)
49 {
50 mouseOverColor = mouseOverColor_;
51 return *this;
52 }
53 public nothrow ParentPathSelectorCreateParams& SetMouseClickColor(const System.Windows.Color& mouseClickColor_)
54 {
55 mouseClickColor = mouseClickColor_;
56 return *this;
57 }
58 public nothrow ParentPathSelectorCreateParams& SetImagePadding(const Padding& imagePadding_)
59 {
60 imagePadding = imagePadding_;
61 return *this;
62 }
63 public ControlCreateParams& controlCreateParams;
64 public ImageList* imageList;
65 public System.Windows.Color mouseOverColor;
66 public System.Windows.Color mouseClickColor;
67 public Padding imagePadding;
68 }
69
70 public class ParentPathSelector : Control
71 {
72 public enum State
73 {
74 idle, mouseOver, clicked
75 }
76 public nothrow ParentPathSelector(ParentPathSelectorCreateParams& createParams) :
77 base(createParams.controlCreateParams),
78 state(State.idle),
79 mouseOverBrush(createParams.mouseOverColor),
80 mouseClickBrush(createParams.mouseClickColor),
81 imagePadding(createParams.imagePadding)
82 {
83 ImageList* imageList = createParams.imageList;
84 bitmap = imageList->GetImage(imageList->GetImageIndex("up.arrow.bitmap"));
85 }
86 public nothrow void SetState(State state_)
87 {
88 if (state != state_)
89 {
90 state = state_;
91 Invalidate();
92 }
93 }
94 protected override void OnPaint(PaintEventArgs& args)
95 {
96 args.graphics.Clear(BackgroundColor());
97 if (state == State.mouseOver)
98 {
99 Point loc;
100 Rect rect(loc, GetSize());
101 args.graphics.FillRectangleChecked(mouseOverBrush, rect);
102 }
103 else if (state == State.clicked)
104 {
105 Point loc;
106 Rect rect(loc, GetSize());
107 args.graphics.FillRectangleChecked(mouseClickBrush, rect);
108 }
109 Point loc;
110 Size sz = GetSize();
111 Rect rect(loc, sz);
112 if (sz.w > 0 && sz.h > 0)
113 {
114 PointF imageLoc(imagePadding.left, imagePadding.top);
115 RectF r(imageLoc, SizeF(bitmap->GetWidth() + imagePadding.Horizontal(), bitmap->GetHeight() + imagePadding.Vertical()));
116 RectF s(PointF(0, 0), SizeF(bitmap->GetWidth() + imagePadding.Horizontal(), bitmap->GetHeight() + imagePadding.Vertical()));
117 ImageAttributes attributes;
118 attributes.SetColorKeyChecked(System.Windows.Color.DefaultBitmapTransparent(), System.Windows.Color.DefaultBitmapTransparent(),
119 ColorAdjustType.default_);
120 args.graphics.DrawImageChecked(*bitmap, r, s, Unit.pixel, attributes);
121 }
122 }
123 protected override void OnMouseEnter()
124 {
125 base->OnMouseEnter();
126 SetState(State.mouseOver);
127 }
128 protected override void OnMouseLeave()
129 {
130 base->OnMouseLeave();
131 SetState(State.idle);
132 }
133 protected override void OnMouseDown(MouseEventArgs& args)
134 {
135 base->OnMouseDown(args);
136 SetState(State.clicked);
137 }
138 protected override void OnMouseUp(MouseEventArgs& args)
139 {
140 base->OnMouseUp(args);
141 SetState(State.mouseOver);
142 }
143 private State state;
144 private Bitmap* bitmap;
145 private SolidBrush mouseOverBrush;
146 private SolidBrush mouseClickBrush;
147 private Padding imagePadding;
148 }
149 }