00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00051 #ifndef WINSTL_INCL_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE
00052 #define WINSTL_INCL_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE
00053
00054 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00055 # define WINSTL_VER_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE_MAJOR 2
00056 # define WINSTL_VER_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE_MINOR 0
00057 # define WINSTL_VER_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE_REVISION 7
00058 # define WINSTL_VER_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE_EDIT 34
00059 #endif
00060
00061
00062
00063
00064
00065 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00066 # include <winstl/winstl.h>
00067 #endif
00068 #ifndef WINSTL_INCL_WINSTL_CLIPBOARD_ERROR_HPP_EXCEPTIONS
00069 # include <winstl/clipboard/error/exceptions.hpp>
00070 #endif
00071 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_GLOBAL_ALLOCATOR
00072 # include <winstl/memory/global_allocator.hpp>
00073 #endif
00074 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
00075 # include <stlsoft/memory/allocator_base.hpp>
00076 #endif
00077 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CSTRING_FUNCTIONS
00078 # include <stlsoft/string/cstring_functions.hpp>
00079 #endif
00080
00081
00082
00083
00084
00085 #ifndef _WINSTL_NO_NAMESPACE
00086 # if defined(_STLSOFT_NO_NAMESPACE) || \
00087 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00088
00089 namespace winstl
00090 {
00091 # else
00092
00093
00094 namespace stlsoft
00095 {
00096
00097 namespace winstl_project
00098 {
00099
00100 # endif
00101 #endif
00102
00103
00104
00105
00106
00113 class clipboard_scope_exception
00114 : public clipboard_exception
00115 {
00118 public:
00119 typedef clipboard_exception parent_class_type;
00120 typedef clipboard_scope_exception class_type;
00122
00125 public:
00126 clipboard_scope_exception(char const* reason, error_code_type err)
00127 : clipboard_exception(reason, err)
00128 {}
00130
00133 private:
00134 class_type& operator =(class_type const&);
00136
00137 };
00138
00181 class clipboard_scope
00182 #if defined(STLSOFT_COMPILER_IS_DMC)
00183 : protected global_allocator<void>
00184 #else
00185 : private global_allocator<void>
00186 #endif
00187 {
00190 private:
00191 typedef global_allocator<void> parent_class_type;
00192 public:
00193 typedef clipboard_scope class_type;
00194 typedef global_allocator<void> allocator_type;
00196
00199 public:
00204 ss_explicit_k clipboard_scope(HWND hwndOwner = NULL) stlsoft_throw_1(clipboard_scope_exception);
00206 ~clipboard_scope() stlsoft_throw_0();
00208
00211 public:
00213 allocator_type get_allocator() const;
00215
00218 public:
00220 void clear() stlsoft_throw_1(clipboard_scope_exception);
00221
00223 HWND owner() const;
00224
00226 ws_bool_t is_fmt_available(UINT fmt) const;
00227
00229 void set_data(UINT fmt, HANDLE hData) stlsoft_throw_1(clipboard_scope_exception);
00230
00232 void set_data(char const* str) stlsoft_throw_1(clipboard_scope_exception);
00234 void set_data(char const* str, ws_size_t n) stlsoft_throw_1(clipboard_scope_exception);
00235
00237 void set_data(wchar_t const* str) stlsoft_throw_1(clipboard_scope_exception);
00239 void set_data(wchar_t const* str, ws_size_t n) stlsoft_throw_1(clipboard_scope_exception);
00240
00242 void set_data(HBITMAP hBmp) stlsoft_throw_1(clipboard_scope_exception);
00244 void set_data(HDROP hDrop) stlsoft_throw_1(clipboard_scope_exception);
00246 void set_data(HENHMETAFILE hEmf) stlsoft_throw_1(clipboard_scope_exception);
00248 void set_data(HPALETTE hPal) stlsoft_throw_1(clipboard_scope_exception);
00249
00254 HANDLE get_data(UINT fmt) const stlsoft_throw_1(clipboard_scope_exception);
00255
00260 void get_data(char const*& str) const stlsoft_throw_1(clipboard_scope_exception);
00261
00266 void get_data(wchar_t const*& str) const stlsoft_throw_1(clipboard_scope_exception);
00267
00272 void get_data(HBITMAP& hBmp) const stlsoft_throw_1(clipboard_scope_exception);
00277 void get_data(HDROP& hDrop) const stlsoft_throw_1(clipboard_scope_exception);
00282 void get_data(HENHMETAFILE& hEmf) const stlsoft_throw_1(clipboard_scope_exception);
00287 void get_data(HPALETTE& hPal) const stlsoft_throw_1(clipboard_scope_exception);
00289
00292 private:
00293 template< ss_typename_param_k A
00294 , ss_typename_param_k T
00295 >
00296 void set_data_or_deallocate_and_throw_(UINT fmt, T* memory, A& ator) stlsoft_throw_1(clipboard_scope_exception)
00297 {
00298 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00299 try
00300 {
00301 #endif
00302
00303 set_data(fmt, static_cast<HANDLE>(memory));
00304
00305 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00306 }
00307 catch(...)
00308 {
00309 ator.deallocate(memory);
00310
00311 throw;
00312 }
00313 #endif
00314 }
00316
00319 private:
00320 clipboard_scope(class_type const&);
00321 class_type& operator =(class_type const&);
00323 };
00324
00326
00327
00328 #ifdef STLSOFT_UNITTEST
00329 # include "./unittest/clipboard_scope_unittest_.h"
00330 #endif
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00343
00344 inline clipboard_scope::clipboard_scope(HWND hwndOwner ) stlsoft_throw_1(clipboard_scope_exception)
00345 {
00346 if(!::OpenClipboard(hwndOwner))
00347 {
00348 STLSOFT_THROW_X(clipboard_scope_exception("Cannot open clipboard", ::GetLastError()));
00349 }
00350 }
00351
00352 inline clipboard_scope::~clipboard_scope() stlsoft_throw_0()
00353 {
00354 ::CloseClipboard();
00355 }
00356
00357 inline clipboard_scope::allocator_type clipboard_scope::get_allocator() const
00358 {
00359 allocator_type const& ator = *this;
00360
00361 return ator;
00362 }
00363
00364 inline void clipboard_scope::clear() stlsoft_throw_1(clipboard_scope_exception)
00365 {
00366 if(!::EmptyClipboard())
00367 {
00368 STLSOFT_THROW_X(clipboard_scope_exception("Cannot empty clipboard", ::GetLastError()));
00369 }
00370 }
00371
00372 inline HWND clipboard_scope::owner() const
00373 {
00374 HWND hwnd = ::GetClipboardOwner();
00375
00376 if( NULL == hwnd &&
00377 ERROR_SUCCESS != ::GetLastError())
00378 {
00379 STLSOFT_THROW_X(clipboard_scope_exception("Cannot get clipboard owner", ::GetLastError()));
00380 }
00381
00382 return hwnd;
00383 }
00384
00385 inline ws_bool_t clipboard_scope::is_fmt_available(UINT fmt) const
00386 {
00387 return BOOL2bool(::IsClipboardFormatAvailable(fmt));
00388 }
00389
00390 inline void clipboard_scope::set_data(UINT fmt, HANDLE hData) stlsoft_throw_1(clipboard_scope_exception)
00391 {
00392 if(NULL == ::SetClipboardData(fmt, hData))
00393 {
00394 STLSOFT_THROW_X(clipboard_scope_exception("Cannot set clipboard data", ::GetLastError()));
00395 }
00396 }
00397
00398 inline void clipboard_scope::set_data(char const* str) stlsoft_throw_1(clipboard_scope_exception)
00399 {
00400 #ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
00401 allocator_type::rebind<char>::other ator(*this);
00402 #else
00403 global_allocator<char> ator;
00404 #endif
00405 char* memory = stlsoft_ns_qual(string_dup)(str, ator);
00406
00407 set_data_or_deallocate_and_throw_(CF_TEXT, memory, ator);
00408 }
00409
00410 inline void clipboard_scope::set_data(char const* str, ws_size_t n) stlsoft_throw_1(clipboard_scope_exception)
00411 {
00412 #ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
00413 allocator_type::rebind<char>::other ator(*this);
00414 #else
00415 global_allocator<char> ator;
00416 #endif
00417 char* memory = stlsoft_ns_qual(string_dup)(str, n, ator);
00418
00419 set_data_or_deallocate_and_throw_(CF_TEXT, memory, ator);
00420 }
00421
00422 inline void clipboard_scope::set_data(wchar_t const* str) stlsoft_throw_1(clipboard_scope_exception)
00423 {
00424 #ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
00425 allocator_type::rebind<wchar_t>::other ator(*this);
00426 #else
00427 global_allocator<wchar_t> ator;
00428 #endif
00429 wchar_t* memory = stlsoft_ns_qual(string_dup)(str, ator);
00430
00431 set_data_or_deallocate_and_throw_(CF_UNICODETEXT, memory, ator);
00432 }
00433
00434 inline void clipboard_scope::set_data(wchar_t const* str, ws_size_t n) stlsoft_throw_1(clipboard_scope_exception)
00435 {
00436 #ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
00437 allocator_type::rebind<wchar_t>::other ator(*this);
00438 #else
00439 global_allocator<wchar_t> ator;
00440 #endif
00441 wchar_t* memory = stlsoft_ns_qual(string_dup)(str, n, ator);
00442
00443 set_data_or_deallocate_and_throw_(CF_UNICODETEXT, memory, ator);
00444 }
00445
00446 inline void clipboard_scope::set_data(HBITMAP hBmp) stlsoft_throw_1(clipboard_scope_exception)
00447 {
00448 set_data(CF_BITMAP, hBmp);
00449 }
00450
00451 inline void clipboard_scope::set_data(HDROP hDrop) stlsoft_throw_1(clipboard_scope_exception)
00452 {
00453 set_data(CF_HDROP, hDrop);
00454 }
00455
00456 inline void clipboard_scope::set_data(HENHMETAFILE hEmf) stlsoft_throw_1(clipboard_scope_exception)
00457 {
00458 set_data(CF_ENHMETAFILE, hEmf);
00459 }
00460
00461 inline void clipboard_scope::set_data(HPALETTE hPal) stlsoft_throw_1(clipboard_scope_exception)
00462 {
00463 set_data(CF_PALETTE, hPal);
00464 }
00465
00466 inline HANDLE clipboard_scope::get_data(UINT fmt) const stlsoft_throw_1(clipboard_scope_exception)
00467 {
00468 HANDLE hData = ::GetClipboardData(fmt);
00469
00470 if( NULL == hData &&
00471 ERROR_SUCCESS != ::GetLastError())
00472 {
00473 STLSOFT_THROW_X(clipboard_scope_exception("Cannot get clipboard data", ::GetLastError()));
00474 }
00475
00476 return hData;
00477 }
00478
00479 inline void clipboard_scope::get_data(char const*& str) const stlsoft_throw_1(clipboard_scope_exception)
00480 {
00481 str = static_cast<char const*>(get_data(CF_TEXT));
00482 }
00483
00484 inline void clipboard_scope::get_data(wchar_t const*& str) const stlsoft_throw_1(clipboard_scope_exception)
00485 {
00486 str = static_cast<wchar_t const*>(get_data(CF_UNICODETEXT));
00487 }
00488
00489 inline void clipboard_scope::get_data(HBITMAP& hBmp) const stlsoft_throw_1(clipboard_scope_exception)
00490 {
00491 hBmp = static_cast<HBITMAP>(get_data(CF_BITMAP));
00492 }
00493
00494 inline void clipboard_scope::get_data(HDROP& hDrop) const stlsoft_throw_1(clipboard_scope_exception)
00495 {
00496 hDrop = static_cast<HDROP>(get_data(CF_HDROP));
00497 }
00498
00499 inline void clipboard_scope::get_data(HENHMETAFILE& hEmf) const stlsoft_throw_1(clipboard_scope_exception)
00500 {
00501 hEmf = static_cast<HENHMETAFILE>(get_data(CF_ENHMETAFILE));
00502 }
00503
00504 inline void clipboard_scope::get_data(HPALETTE& hPal) const stlsoft_throw_1(clipboard_scope_exception)
00505 {
00506 hPal = static_cast<HPALETTE>(get_data(CF_PALETTE));
00507 }
00508
00509 #endif
00510
00511
00512
00513
00514
00515 #ifndef _WINSTL_NO_NAMESPACE
00516 # if defined(_STLSOFT_NO_NAMESPACE) || \
00517 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00518 }
00519 # else
00520 }
00521 }
00522 # endif
00523
00524 #endif
00525
00526
00527
00528 #endif
00529
00530