mirror of https://github.com/aseprite/aseprite.git
				
				
				
			Move ComPtr class to laf-base library
This commit is contained in:
		
							parent
							
								
									5811bba2b1
								
							
						
					
					
						commit
						d1e9abf85c
					
				
							
								
								
									
										2
									
								
								laf
								
								
								
								
							
							
								
								
								
								
								
								
							
						
						
									
										2
									
								
								laf
								
								
								
								
							| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
Subproject commit 9ed243c1c653a5bada12d83b9075d3753b5e42c9
 | 
					Subproject commit de578c1e6cc636d00b806051d338bf196712885f
 | 
				
			||||||
| 
						 | 
					@ -1,37 +0,0 @@
 | 
				
			||||||
// SHE library
 | 
					 | 
				
			||||||
// Copyright (C) 2017  David Capello
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// This file is released under the terms of the MIT license.
 | 
					 | 
				
			||||||
// Read LICENSE.txt for more information.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef SHE_WIN_COMPTR_H_INCLUDED
 | 
					 | 
				
			||||||
#define SHE_WIN_COMPTR_H_INCLUDED
 | 
					 | 
				
			||||||
#pragma once
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "base/disable_copying.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace she {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  template<class T>
 | 
					 | 
				
			||||||
  class ComPtr {
 | 
					 | 
				
			||||||
  public:
 | 
					 | 
				
			||||||
    ComPtr() : m_ptr(nullptr) { }
 | 
					 | 
				
			||||||
    ~ComPtr() {
 | 
					 | 
				
			||||||
      if (m_ptr) {
 | 
					 | 
				
			||||||
        m_ptr->Release();       // Call IUnknown::Release() automatically
 | 
					 | 
				
			||||||
#ifdef _DEBUG
 | 
					 | 
				
			||||||
        m_ptr = nullptr;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    T** operator&() { return &m_ptr; }
 | 
					 | 
				
			||||||
    T* operator->() { return m_ptr; }
 | 
					 | 
				
			||||||
  private:
 | 
					 | 
				
			||||||
    T* m_ptr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    DISABLE_COPYING(ComPtr);
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
} // namespace she
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
| 
						 | 
					@ -12,10 +12,10 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "base/fs.h"
 | 
					#include "base/fs.h"
 | 
				
			||||||
#include "base/string.h"
 | 
					#include "base/string.h"
 | 
				
			||||||
 | 
					#include "base/win/comptr.h"
 | 
				
			||||||
#include "she/common/file_dialog.h"
 | 
					#include "she/common/file_dialog.h"
 | 
				
			||||||
#include "she/display.h"
 | 
					#include "she/display.h"
 | 
				
			||||||
#include "she/error.h"
 | 
					#include "she/error.h"
 | 
				
			||||||
#include "she/win/comptr.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <windows.h>
 | 
					#include <windows.h>
 | 
				
			||||||
#include <shobjidl.h>
 | 
					#include <shobjidl.h>
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ public:
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  HRESULT showWithNewAPI(Display* parent, bool& result, bool& shown) {
 | 
					  HRESULT showWithNewAPI(Display* parent, bool& result, bool& shown) {
 | 
				
			||||||
    ComPtr<IFileDialog> dlg;
 | 
					    base::ComPtr<IFileDialog> dlg;
 | 
				
			||||||
    HRESULT hr = CoCreateInstance(
 | 
					    HRESULT hr = CoCreateInstance(
 | 
				
			||||||
      (m_type == Type::SaveFile ? CLSID_FileSaveDialog:
 | 
					      (m_type == Type::SaveFile ? CLSID_FileSaveDialog:
 | 
				
			||||||
                                  CLSID_FileOpenDialog),
 | 
					                                  CLSID_FileOpenDialog),
 | 
				
			||||||
| 
						 | 
					@ -141,9 +141,9 @@ private:
 | 
				
			||||||
    shown = true;
 | 
					    shown = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_type == Type::OpenFiles) {
 | 
					    if (m_type == Type::OpenFiles) {
 | 
				
			||||||
      ComPtr<IFileOpenDialog> odlg;
 | 
					      base::ComPtr<IFileOpenDialog> odlg;
 | 
				
			||||||
      hr = dlg->QueryInterface(IID_IFileOpenDialog, (void**)&odlg);
 | 
					      hr = dlg->QueryInterface(IID_IFileOpenDialog, (void**)&odlg);
 | 
				
			||||||
      ComPtr<IShellItemArray> items;
 | 
					      base::ComPtr<IShellItemArray> items;
 | 
				
			||||||
      hr = odlg->GetResults(&items);
 | 
					      hr = odlg->GetResults(&items);
 | 
				
			||||||
      if (FAILED(hr))
 | 
					      if (FAILED(hr))
 | 
				
			||||||
        return hr;
 | 
					        return hr;
 | 
				
			||||||
| 
						 | 
					@ -154,7 +154,7 @@ private:
 | 
				
			||||||
        return hr;
 | 
					        return hr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      for (DWORD i=0; i<nitems; ++i) {
 | 
					      for (DWORD i=0; i<nitems; ++i) {
 | 
				
			||||||
        ComPtr<IShellItem> item;
 | 
					        base::ComPtr<IShellItem> item;
 | 
				
			||||||
        hr = items->GetItemAt(i, &item);
 | 
					        hr = items->GetItemAt(i, &item);
 | 
				
			||||||
        if (FAILED(hr))
 | 
					        if (FAILED(hr))
 | 
				
			||||||
          return hr;
 | 
					          return hr;
 | 
				
			||||||
| 
						 | 
					@ -168,7 +168,7 @@ private:
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
      ComPtr<IShellItem> item;
 | 
					      base::ComPtr<IShellItem> item;
 | 
				
			||||||
      hr = dlg->GetResult(&item);
 | 
					      hr = dlg->GetResult(&item);
 | 
				
			||||||
      if (FAILED(hr))
 | 
					      if (FAILED(hr))
 | 
				
			||||||
        return hr;
 | 
					        return hr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue