Commit fd88a4c2b784865200e96a16b6dc359cce708202

Authored by perry.werneck@gmail.com
1 parent b9c3bf72

Implementando metodos de clipboard no windows

src/classlib/remote.cc
... ... @@ -1040,14 +1040,14 @@
1040 1040  
1041 1041 }
1042 1042  
1043   - int set_clipboard(const char *text)
  1043 +#if defined(HAVE_DBUS)
  1044 + string * get_clipboard(void)
1044 1045 {
1045   -#if defined(WIN32)
1046   -
1047   - return -1;
1048   -
1049   -#elif defined(HAVE_DBUS)
  1046 + return query_string("getClipboard");
  1047 + }
1050 1048  
  1049 + int set_clipboard(const char *text)
  1050 + {
1051 1051 DBusMessage * msg = create_message("setClipboard");
1052 1052 if(msg)
1053 1053 {
... ... @@ -1056,30 +1056,8 @@
1056 1056 }
1057 1057  
1058 1058 return -1;
1059   -
1060   -#else
1061   -
1062   - return -1;
1063   -
1064   -#endif
1065   -
1066   - }
1067   -
1068   - string * get_clipboard(void)
1069   - {
1070   -#if defined(WIN32)
1071   -
1072   - return NULL;
1073   -
1074   -#elif defined(HAVE_DBUS)
1075   -
1076   - trace("%s",__FUNCTION__);
1077   - return query_string("getClipboard");
1078   -
1079   -#endif
1080   -
1081   - return NULL;
1082 1059 }
  1060 +#endif // HAVE_DBUS
1083 1061  
1084 1062 };
1085 1063  
... ...
src/classlib/session.cc
... ... @@ -214,13 +214,75 @@
214 214  
215 215 string * session::get_clipboard(void)
216 216 {
  217 +#if defined(WIN32)
  218 +
  219 + if (! OpenClipboard(0))
  220 + {
  221 + throw exception(GetLastError(),"%s","Can´t open system clipboard");
  222 + return NULL;
  223 + }
  224 +
  225 + HANDLE hData = GetClipboardData(CF_TEXT);
  226 + if(!hData)
  227 + {
  228 + throw exception(GetLastError(),"%s","Can´t get clipboard data");
  229 + return NULL;
  230 + }
  231 +
  232 + char * pszText = static_cast<char*>( GlobalLock(hData) );
  233 + if(!pszText)
  234 + {
  235 + throw exception(GetLastError(),"%s","Can´t lock clipboard");
  236 + return NULL;
  237 + }
  238 +
  239 + string *text = new string ( pszText );
  240 +
  241 + GlobalUnlock( hData );
  242 +
  243 + CloseClipboard();
  244 +
  245 + return text;
  246 +
  247 +#else
217 248 errno = EINVAL;
218 249 return NULL;
  250 +
  251 +#endif // WIN32
219 252 }
220 253  
221 254 int session::set_clipboard(const char *text)
222 255 {
  256 +#if defined(WIN32)
  257 + if (! OpenClipboard(0))
  258 + {
  259 + throw exception(GetLastError(),"%s","Can´t open system clipboard");
  260 + return -1;
  261 + }
  262 +
  263 + EmptyClipboard();
  264 +
  265 + size_t size = strlen(text)+1;
  266 + HGLOBAL hClipboardData = GlobalAlloc(GMEM_MOVEABLE , size);
  267 +
  268 + strcpy((char *) GlobalLock(hClipboardData), text);
  269 +
  270 + if(!SetClipboardData(CF_TEXT, hClipboardData))
  271 + {
  272 + GlobalUnlock(hClipboardData);
  273 + CloseClipboard();
  274 + throw exception(GetLastError(),"%s","Can´t set system clipboard");
  275 + }
  276 +
  277 + GlobalUnlock(hClipboardData);
  278 + CloseClipboard();
  279 +
  280 + return 0;
  281 +#else
  282 +
223 283 return EINVAL;
  284 +
  285 +#endif // WIN32
224 286 }
225 287  
226 288  
... ...
src/classlib/testprogram.cc
... ... @@ -50,6 +50,13 @@
50 50 cout << "\tSession state: " << session->get_cstate() << endl;
51 51 cout << "\tCharset: " << session->get_charset() << endl;
52 52  
  53 + string *str = session->get_clipboard();
  54 + cout << "\nClipboard: " << str->c_str();
  55 +
  56 + delete str;
  57 +
  58 + session->set_clipboard("Teste de clipboard");
  59 +
53 60 delete session;
54 61 return 0;
55 62 }
... ...