1 // =================================
 2 // Copyright (c) 2024 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System;
 7 using System.Collections;
 8 
 9 namespace System.Windows
10 {
11     internal class WindowManager
12     {
13         public WindowManager()
14         {
15             systemClassNames.Insert("BUTTON");
16             systemClassNames.Insert("STATIC");
17             systemClassNames.Insert("EDIT");
18             systemClassNames.Insert("LISTBOX");
19         }
20         [nodiscard]
21         public Result<ushort> RegisterWindowClass(const char* windowClassNameWindowClassStyle windowClassStyleint windowClassBackgroundColor)
22         {
23             string className = windowClassName;
24             auto it = registeredWindowClasses.Find(className);
25             if (it != registeredWindowClasses.End())
26             {
27                 return it->second;
28             }
29             else
30             {
31                 Result<ushort> windowClassResult = System.Windows.API.RegisterWindowClass(windowClassNamewindowClassStylewindowClassBackgroundColor);
32                 if (windowClassResult.Error())
33                 {
34                     return windowClassResult;
35                 }
36                 ushort windowClass = windowClassResult.Value();
37                 registeredWindowClasses[className] = windowClass;
38                 return Result<ushort>(windowClass);
39             }
40         }
41         public bool IsSystemClassName(const char* windowClassName)
42         {
43             string className = windowClassName;
44             auto it = systemClassNames.Find(className);
45             if (it != systemClassNames.End())
46             {
47                 return true;
48             }
49             return false;
50         }
51         public void AddWindow(Control* window)
52         {
53             windowMap[window->Handle()] = window;
54         }
55         public void RemoveWindow(Control* window)
56         {
57             windowMap.Remove(window->Handle());
58         }
59         public Control* GetWindow(void* handle) const
60         {
61             auto it = windowMap.Find(handle);
62             if (it != windowMap.End())
63             {
64                 return it->second;
65             }
66             else
67             {
68                 return null;
69             }
70         }
71         private HashMap<stringushort> registeredWindowClasses;
72         private HashMap<void*Control*> windowMap;
73         private HashSet<string> systemClassNames;
74     }