////////////////////////////////
// Win32 Clipboard

MR4TH_SYMBOL B32
w32_clipboard_set_str8(String8 text){
  B32 result = 0;
  if (OpenClipboard((HWND)0)){
    if (EmptyClipboard()){
      HANDLE memhandle = GlobalAlloc(GMEM_MOVEABLE, text.size + 1);
      if (memhandle != 0){
        void *dst = GlobalLock(memhandle);
        MemoryCopy(dst, text.str, text.size);
        ((U8*)dst)[text.size] = 0;
        GlobalUnlock(memhandle);
        SetClipboardData(CF_TEXT, memhandle);
        result = 1;
      }
    }
    CloseClipboard();
  }
  return(result);
}

MR4TH_SYMBOL String8
w32_clipboard_get_str8(Arena *arena){
  String8 result = {0};
  if (OpenClipboard((HWND)0)){
    HANDLE clip_data = GetClipboardData(CF_UNICODETEXT);
    if (clip_data != 0){
      U16 *src16 = (U16*)GlobalLock(clip_data);
      if (src16 != 0){
        result = str8_from_str16(arena, str16_cstring(src16));
      }
      GlobalUnlock(clip_data);
    }
    if (result.size == 0){
      HANDLE clip_data = GetClipboardData(CF_TEXT);
      if (clip_data != 0){
        U8 *src8 = (U8*)GlobalLock(clip_data);
        if (src8 != 0){
          result = str8_push_copy(arena, str8_cstring(src8));
        }
        GlobalUnlock(clip_data);
      }
    }
    CloseClipboard();
  }
  return(result);
}
