cppAdaptive2
view release on metacpan or search on metacpan
src/dlib/gui_core/gui_core_kernel_1.cpp view on Meta::CPAN
) const
{
auto_mutex M(wm);
width = 0;
height = 0;
if (has_been_destroyed == true)
return;
RECT r;
GetClientRect(hwnd,&r);
width = r.right - r.left;
height = r.bottom - r.top;
}
// ----------------------------------------------------------------------------------------
void base_window::
invalidate_rectangle (
const rectangle& rect
)
{
auto_mutex M(wm);
if (rect.is_empty() == false && !has_been_destroyed)
{
RECT info;
info.top = rect.top();
info.left = rect.left();
info.right = rect.right()+1;
info.bottom = rect.bottom()+1;
InvalidateRect(hwnd,&info,FALSE);
}
}
// ----------------------------------------------------------------------------------------
void base_window::
set_im_pos (
long x,
long y
)
{
auto_mutex M(wm);
if (has_been_destroyed == true)
return;
HIMC hImc = ImmGetContext(hwnd);
COMPOSITIONFORM cf;
cf.dwStyle = CFS_POINT;
cf.ptCurrentPos.x = x;
cf.ptCurrentPos.y = y;
ImmSetCompositionWindow(hImc, &cf);
ImmReleaseContext(hwnd, hImc);
}
// ----------------------------------------------------------------------------------------
void put_on_clipboard (
const std::string& str
)
{
put_on_clipboard(convert_mbstring_to_wstring(str));
}
void put_on_clipboard (
const dlib::ustring& str
)
{
put_on_clipboard(convert_utf32_to_wstring(str));
}
void put_on_clipboard (
const std::wstring& str
)
{
using namespace gui_core_kernel_1_globals;
using namespace std;
shared_ptr_thread_safe<event_handler_thread> globals(global_data());
if (OpenClipboard(globals->helper_window))
{
EmptyClipboard();
auto_mutex M(globals->window_table.get_mutex());
const unsigned long newlines = count(str.begin(),str.end(),L'\n');
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,(str.size()+newlines+1)*sizeof(wchar_t));
if (mem != NULL)
{
wchar_t* buf = reinterpret_cast<wchar_t*>(GlobalLock(mem));
if (buf != NULL)
{
// copy str into buf while also replacing all the \n with \r\n
for (wstring::size_type i = 0; i < str.size(); ++i)
{
if (str[i] != L'\n')
{
*buf = str[i];
++buf;
}
else
{
*buf = L'\r';
++buf;
*buf = L'\n';
++buf;
}
}
*buf = L'\0';
GlobalUnlock(mem);
SetClipboardData(CF_UNICODETEXT,mem);
}
}
CloseClipboard();
}
}
// ----------------------------------------------------------------------------------------
void get_from_clipboard (
std::string& str
)
{
std::wstring wstr;
get_from_clipboard(wstr);
str = convert_wstring_to_mbstring(wstr);
}
void get_from_clipboard (
dlib::ustring& str
)
{
std::wstring wstr;
get_from_clipboard(wstr);
str = convert_wstring_to_utf32(wstr);
}
void get_from_clipboard (
std::wstring& str
)
{
using namespace gui_core_kernel_1_globals;
using namespace std;
shared_ptr_thread_safe<event_handler_thread> globals(global_data());
auto_mutex M(globals->window_table.get_mutex());
if (OpenClipboard(globals->helper_window))
{
HANDLE data = GetClipboardData(CF_UNICODETEXT);
if (data != NULL)
{
wchar_t* buf = reinterpret_cast<wchar_t*>(GlobalLock(data));
if (buf != 0)
{
str.clear();
// copy the data from buf into str while also removing any '\r'
// characters.
while (*buf != L'\0')
{
if (*buf != L'\r')
str += *buf;
++buf;
}
GlobalUnlock(data);
}
else
{
Beep(500,500);
}
}
CloseClipboard();
}
}
// ----------------------------------------------------------------------------------------
}
#endif // WIN32
#endif // DLIB_GUI_CORE_KERNEL_1_CPp_
( run in 1.074 second using v1.01-cache-2.11-cpan-81fc1098f69 )