Bug 1232181 - Add a few win resource helpers. r?aklotz draft
authorJim Mathies <jmathies@mozilla.com>
Fri, 26 Feb 2016 08:58:01 -0600
changeset 334924 fb9c550d86c20531c12c35614e50750520d51e5e
parent 334923 90f700ab99fe479f110b035a2cce445f953d17cd
child 334925 226eba46982223f3d81421fd748e502bab0b216d
push id11672
push userjmathies@mozilla.com
push dateFri, 26 Feb 2016 14:58:31 +0000
reviewersaklotz
bugs1232181
milestone47.0a1
Bug 1232181 - Add a few win resource helpers. r?aklotz MozReview-Commit-ID: EN3GE8waLCz
xpcom/base/nsWindowsHelpers.h
--- a/xpcom/base/nsWindowsHelpers.h
+++ b/xpcom/base/nsWindowsHelpers.h
@@ -45,16 +45,88 @@ public:
   {
     if (aFD != Void()) {
       RegCloseKey(aFD);
     }
   }
 };
 
 template<>
+class nsAutoRefTraits<HDC>
+{
+public:
+  typedef HDC RawRef;
+  static HDC Void()
+  {
+    return nullptr;
+  }
+
+  static void Release(RawRef aFD)
+  {
+    if (aFD != Void()) {
+      ::DeleteDC(aFD);
+    }
+  }
+};
+
+template<>
+class nsAutoRefTraits<HBRUSH>
+{
+public:
+  typedef HBRUSH RawRef;
+  static HBRUSH Void()
+  {
+    return nullptr;
+  }
+
+  static void Release(RawRef aFD)
+  {
+    if (aFD != Void()) {
+      ::DeleteObject(aFD);
+    }
+  }
+};
+
+template<>
+class nsAutoRefTraits<HRGN>
+{
+public:
+  typedef HRGN RawRef;
+  static HRGN Void()
+  {
+    return nullptr;
+  }
+
+  static void Release(RawRef aFD)
+  {
+    if (aFD != Void()) {
+      ::DeleteObject(aFD);
+    }
+  }
+};
+
+template<>
+class nsAutoRefTraits<HBITMAP>
+{
+public:
+  typedef HBITMAP RawRef;
+  static HBITMAP Void()
+  {
+    return nullptr;
+  }
+
+  static void Release(RawRef aFD)
+  {
+    if (aFD != Void()) {
+      ::DeleteObject(aFD);
+    }
+  }
+};
+
+template<>
 class nsAutoRefTraits<SC_HANDLE>
 {
 public:
   typedef SC_HANDLE RawRef;
   static SC_HANDLE Void()
   {
     return nullptr;
   }
@@ -135,16 +207,20 @@ public:
   {
     if (aDevMode != Void()) {
       ::HeapFree(::GetProcessHeap(), 0, aDevMode);
     }
   }
 };
 
 typedef nsAutoRef<HKEY> nsAutoRegKey;
+typedef nsAutoRef<HDC> nsAutoHDC;
+typedef nsAutoRef<HBRUSH> nsAutoBrush;
+typedef nsAutoRef<HRGN> nsAutoRegion;
+typedef nsAutoRef<HBITMAP> nsAutoBitmap;
 typedef nsAutoRef<SC_HANDLE> nsAutoServiceHandle;
 typedef nsAutoRef<HANDLE> nsAutoHandle;
 typedef nsAutoRef<HMODULE> nsModuleHandle;
 typedef nsAutoRef<DEVMODEW*> nsAutoDevMode;
 
 namespace {
 
 HMODULE inline