1 using System;
  2 using System.Windows;
  3 
  4 namespace FileExplorer
  5 {
  6     public System.Windows.Color DefaultContentViewFrameColor()
  7     {
  8         return System.Windows.Color(204u206u219u);
  9     }
 10 
 11     public class ContentView : ContainerControl
 12     {
 13         public ContentView(ImageList* imageList_) : base(ControlCreateParams().SetWindowClassName("FileExplorer.ContentView").
 14             SetWindowClassBackgroundColor(SystemColor.COLOR_WINDOW).SetBackgroundColor(Color.White()).SetDock(Dock.fill))
 15             imageList(imageList_)
 16         {
 17             auto framedControlResult = MakeFramedControl(new EmptyView(EmptyViewControlCreateParams(ControlCreateParams().Defaults())));
 18             if (framedControlResult.Error())
 19             {
 20                 SetErrorId(framedControlResult.GetErrorId());
 21                 return;
 22             }
 23             auto result = AddChild(framedControlResult.Value().Release());
 24             if (result.Error())
 25             {
 26                 SetErrorId(result.GetErrorId());
 27                 return;
 28             }
 29         }
 30         public void SetMainWindow(MainWindow* mainWindow_)
 31         {
 32             mainWindow = mainWindow_;
 33         }
 34         [nodiscard]
 35         public Result<bool> ViewContent(Node* node)
 36         {
 37             if (framedChild != null)
 38             {
 39                 auto removeResult = RemoveChild(framedChild);
 40                 if (removeResult.Error())
 41                 {
 42                     return Result<bool>(ErrorId(removeResult.GetErrorId()));
 43                 }
 44                 framedChild = null;
 45                 child = null;
 46             }
 47             Result<Control*> viewResult = node->CreateView(imageList);
 48             if (viewResult.Error()) return Result<bool>(ErrorId(viewResult.GetErrorId()));
 49             Control* view = viewResult.Value();
 50             if (view == null)
 51             {
 52                 view = new EmptyView(EmptyViewControlCreateParams(ControlCreateParams().Defaults()));
 53                 if (view->Error())
 54                 {
 55                     return Result<bool>(ErrorId(view->GetErrorId()));
 56                 }
 57             }
 58             auto framedControlResult = MakeFramedControl(view);
 59             if (framedControlResult.Error())
 60             {
 61                 return Result<bool>(ErrorId(framedControlResult.GetErrorId()));
 62             }
 63             auto result = AddChild(framedControlResult.Value().Release());
 64             if (result.Error()) return result;
 65             return Result<bool>(true);
 66         }
 67         [nodiscard]
 68         protected override Result<bool> OnPaint(PaintEventArgs& args)
 69         {
 70             auto result = child->Invalidate();
 71             if (result.Error()) return result;
 72             result = framedChild->Invalidate();
 73             if (result.Error()) return result;
 74             return base->OnPaint(args);
 75         }
 76         [nodiscard]
 77         private Result<UniquePtr<Control>> MakeFramedControl(Control* child_)
 78         {
 79             child = child_;
 80             if (child->Error())
 81             {
 82                 return Result<UniquePtr<Control>>(ErrorId(child->GetErrorId()));
 83             }
 84             child->SetScrollSubject();
 85             PaddedControl* paddedControl = new PaddedControl(PaddedControlCreateParams(PaddedControlControlCreateParams(
 86                 ControlCreateParams().Defaults()child)child).Defaults());
 87             if (paddedControl->Error())
 88             {
 89                 return Result<UniquePtr<Control>>(ErrorId(paddedControl->GetErrorId()));
 90             }
 91             BorderedControl* borderedControl = new BorderedControl(BorderedControlCreateParams(BorderedControlControlCreateParams(
 92                 ControlCreateParams().Defaults()paddedControl)paddedControl).SetNormalBorderColor(DefaultContentViewFrameColor()));
 93             if (borderedControl->Error())
 94             {
 95                 return Result<UniquePtr<Control>>(ErrorId(borderedControl->GetErrorId()));
 96             }
 97             ScrollableControl* scrollableControl = new ScrollableControl(ScrollableControlCreateParams(ScrollableControlControlCreateParams(
 98                 ControlCreateParams().SetDock(Dock.fill)borderedControl)borderedControl).Defaults());
 99             if (scrollableControl->Error())
100             {
101                 return Result<UniquePtr<Control>>(ErrorId(scrollableControl->GetErrorId()));
102             }
103             framedChild = scrollableControl;
104             return Result<UniquePtr<Control>>(UniquePtr<Control>(scrollableControl));
105         }
106         private ImageList* imageList;
107         private MainWindow* mainWindow;
108         private Control* framedChild;
109         private Control* child;
110     }
111 }
112