1 // =================================
 2 // Copyright (c) 2021 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         public ushort RegisterWindowClass(const char* windowClassNameWindowClassStyle windowClassStyleint windowClassBackgroundColor)
21         {
22             string className = windowClassName;
23             HashMap<stringushort>.ConstIterator it = registeredWindowClasses.CFind(className);
24             if (it != registeredWindowClasses.CEnd())
25             {
26                 return it->second;
27             }
28             else
29             {
30                 ushort windowClass = System.Windows.API.RegisterWindowClass(windowClassNamewindowClassStylewindowClassBackgroundColor);
31                 registeredWindowClasses[className] = windowClass;
32                 return windowClass;
33             }
34         }
35         public nothrow bool IsSystemClassName(const char* windowClassName)
36         {
37             string className = windowClassName;
38             HashSet<string>.ConstIterator it = systemClassNames.CFind(className);
39             if (it != systemClassNames.CEnd())
40             {
41                 return true;
42             }
43             return false;
44         }
45         public nothrow void AddWindow(Control* window)
46         {
47             windowMap[window->Handle()] = window;
48         }
49         public nothrow void RemoveWindow(Control* window)
50         {
51             windowMap.Remove(window->Handle());
52         }
53         public nothrow Control* GetWindow(void* handle) const
54         {
55             HashMap<void*Control*>.ConstIterator it = windowMap.CFind(handle);
56             if (it != windowMap.CEnd())
57             {
58                 return it->second;
59             }
60             else
61             {
62                 return null;
63             }
64         }
65         private HashMap<stringushort> registeredWindowClasses;
66         private HashMap<void*Control*> windowMap;
67         private HashSet<string> systemClassNames;
68     }
69 }