use std::ops::{Deref, DerefMut};
use crate::decl::*;
use crate::guard::*;
use crate::prelude::*;
use crate::shell::ffi;
pub struct DestroyIconShfiGuard {
shfi: SHFILEINFO,
}
impl Drop for DestroyIconShfiGuard {
fn drop(&mut self) {
if let Some(h) = self.shfi.hIcon.as_opt() {
let _ = unsafe { DestroyIconGuard::new(h.raw_copy()) };
}
}
}
impl Deref for DestroyIconShfiGuard {
type Target = SHFILEINFO;
fn deref(&self) -> &Self::Target {
&self.shfi
}
}
impl DerefMut for DestroyIconShfiGuard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.shfi
}
}
impl DestroyIconShfiGuard {
#[must_use]
pub const unsafe fn new(shfi: SHFILEINFO) -> Self {
Self { shfi }
}
#[must_use]
pub fn leak(&mut self) -> SHFILEINFO {
std::mem::take(&mut self.shfi)
}
}
pub struct DestroyIconSiiGuard {
sii: SHSTOCKICONINFO,
}
impl Drop for DestroyIconSiiGuard {
fn drop(&mut self) {
if let Some(h) = self.sii.hIcon.as_opt() {
let _ = unsafe { DestroyIconGuard::new(h.raw_copy()) };
}
}
}
impl Deref for DestroyIconSiiGuard {
type Target = SHSTOCKICONINFO;
fn deref(&self) -> &Self::Target {
&self.sii
}
}
impl DerefMut for DestroyIconSiiGuard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.sii
}
}
impl DestroyIconSiiGuard {
#[must_use]
pub const unsafe fn new(sii: SHSTOCKICONINFO) -> Self {
Self { sii }
}
#[must_use]
pub fn leak(&mut self) -> SHSTOCKICONINFO {
std::mem::take(&mut self.sii)
}
}
handle_guard! { DragFinishGuard: HDROP;
ffi::DragFinish;
}
pub struct CoTaskMemFreePidlGuard {
pidl: PIDL,
}
impl Drop for CoTaskMemFreePidlGuard {
fn drop(&mut self) {
let ptr = self.pidl.ptr();
if !ptr.is_null() {
let _ = unsafe { CoTaskMemFreeGuard::new(ptr as _, 0) };
}
}
}
impl Deref for CoTaskMemFreePidlGuard {
type Target = PIDL;
fn deref(&self) -> &Self::Target {
&self.pidl
}
}
impl CoTaskMemFreePidlGuard {
#[must_use]
pub const unsafe fn new(pidl: PIDL) -> Self {
Self { pidl }
}
}