1 // =========================================================================== 2 // Purpose: wxClipboard and drag & drop and their wxDataFormat 3 // Author: J Winwood, John Labenski 4 // Created: 14/11/2001 5 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. 6 // Licence: wxWidgets licence 7 // wxWidgets: Updated to 2.8.4 8 // =========================================================================== 9 10 // --------------------------------------------------------------------------- 11 // wxClipboard 12 13 #if wxLUA_USE_wxClipboard && wxUSE_CLIPBOARD 14 15 #include "wx/clipbrd.h" 16 17 class wxClipboard : public wxObject 18 { 19 !%wxchkver_2_6 #define_pointer wxTheClipboard 20 %wxchkver_2_6 static wxClipboard *Get(); 21 22 // No constructor, use global clipboard from static Get() function only 23 24 bool AddData(%ungc wxDataObject *data); 25 void Clear(); 26 void Close(); 27 bool Flush(); 28 bool GetData(wxDataObject& data); 29 bool IsOpened() const; 30 bool IsSupported(const wxDataFormat& format); 31 bool Open(); 32 bool SetData(%ungc wxDataObject *data); 33 void UsePrimarySelection(bool primary = true); 34 }; 35 36 // --------------------------------------------------------------------------- 37 // wxClipboardLocker 38 39 class %delete wxClipboardLocker 40 { 41 // NOTE: ALWAYS delete() this when done since Lua's gc may not delete it soon enough 42 wxClipboardLocker(wxClipboard *clipboard = NULL); 43 44 bool operator!() const; 45 }; 46 47 // --------------------------------------------------------------------------- 48 // wxClipboardTextEvent 49 50 #if %wxchkver_2_8 51 52 #include "wx/event.h" 53 54 class %delete wxClipboardTextEvent : public wxCommandEvent 55 { 56 %wxEventType wxEVT_COMMAND_TEXT_COPY // EVT_TEXT_COPY(winid, func); 57 %wxEventType wxEVT_COMMAND_TEXT_CUT // EVT_TEXT_CUT(winid, func); 58 %wxEventType wxEVT_COMMAND_TEXT_PASTE // EVT_TEXT_PASTE(winid, func); 59 %wxchkver_3_0_0 %wxEventType wxEVT_TEXT_COPY // wx3.0 alias for wxEVT_COMMAND_TEXT_COPY 60 %wxchkver_3_0_0 %wxEventType wxEVT_TEXT_CUT // wx3.0 alias for wxEVT_COMMAND_TEXT_CUT 61 %wxchkver_3_0_0 %wxEventType wxEVT_TEXT_PASTE // wx3.0 alias for wxEVT_COMMAND_TEXT_PASTE 62 63 wxClipboardTextEvent(wxEventType type = wxEVT_NULL, wxWindowID winid = 0); 64 }; 65 66 #endif //%wxchkver_2_8 67 68 #endif //wxLUA_USE_wxClipboard && wxUSE_CLIPBOARD 69 70 // --------------------------------------------------------------------------- 71 // wxDataFormat 72 73 #if wxLUA_USE_wxDataObject && wxUSE_DATAOBJ 74 75 #include "wx/dataobj.h" 76 77 enum wxDataFormatId 78 { 79 wxDF_INVALID, 80 wxDF_TEXT, 81 wxDF_BITMAP, 82 wxDF_METAFILE, 83 wxDF_SYLK, 84 wxDF_DIF, 85 wxDF_TIFF, 86 wxDF_OEMTEXT, 87 wxDF_DIB, 88 wxDF_PALETTE, 89 wxDF_PENDATA, 90 wxDF_RIFF, 91 wxDF_WAVE, 92 wxDF_UNICODETEXT, 93 wxDF_ENHMETAFILE, 94 wxDF_FILENAME, 95 wxDF_LOCALE, 96 wxDF_PRIVATE, 97 wxDF_HTML, 98 wxDF_MAX 99 }; 100 101 class %delete wxDataFormat 102 { 103 #define_object wxFormatInvalid 104 105 wxDataFormat(wxDataFormatId format = wxDF_INVALID); 106 wxDataFormat(const wxString &format); 107 108 wxString GetId() const; 109 int GetType() const; // returns wxDataFormatId, but it's just an int and msw differs 110 void SetId(const wxString &format); 111 void SetType(wxDataFormatId format); 112 113 bool operator==(const wxDataFormat& format) const; 114 }; 115 116 // --------------------------------------------------------------------------- 117 // wxDataObject 118 119 class wxDataObject 120 { 121 enum Direction 122 { 123 Get, 124 Set 125 }; 126 127 //wxDataObject() this is a base class, use simplified derived classes 128 129 // %override [Lua table of wxDataFormat objects] wxDataObject::GetAllFormats(wxDataObject::Direction dir = wxDataObject); 130 // C++ Func: virtual void GetAllFormats(wxDataFormat *formats, wxDataObject::Direction dir = wxDataObject::Get) const; 131 virtual void GetAllFormats(wxDataObject::Direction dir = wxDataObject::Get) const; 132 133 // %override [bool, Lua string] wxDataObject::GetDataHere(const wxDataFormat& format); 134 // C++ Func: virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; 135 virtual bool GetDataHere(const wxDataFormat& format) const; 136 137 virtual int GetDataSize(const wxDataFormat& format) const; 138 virtual int GetFormatCount(wxDataObject::Direction dir = wxDataObject::Get) const; 139 virtual wxDataFormat GetPreferredFormat(wxDataObject::Direction dir = wxDataObject::Get) const; 140 141 // %override bool wxDataObject::SetData(const wxDataFormat& format, Lua string); 142 // C++ Func: virtual bool SetData(const wxDataFormat& format, int len, const void *buf); 143 virtual bool SetData(const wxDataFormat& format, const wxString& str); 144 }; 145 146 // --------------------------------------------------------------------------- 147 // wxDataObjectSimple 148 149 class %delete wxDataObjectSimple : public wxDataObject 150 { 151 wxDataObjectSimple(const wxDataFormat& format = wxFormatInvalid); 152 153 const wxDataFormat& GetFormat() const; 154 void SetFormat(const wxDataFormat& format); 155 156 // This must be overridden in wxLuaDataObjectSimple, this function returns 0. 157 virtual size_t GetDataSize() const; 158 159 // This must be overridden in wxLuaDataObjectSimple, this function returns false. 160 virtual bool GetDataHere() const; 161 162 // This must be overridden in wxLuaDataObjectSimple, this function returns false. 163 virtual bool SetData(const wxString& str); 164 }; 165 166 // --------------------------------------------------------------------------- 167 // wxLuaDataObjectSimple 168 169 class %delete wxLuaDataObjectSimple : public wxDataObjectSimple 170 { 171 wxLuaDataObjectSimple(const wxDataFormat& format = wxFormatInvalid); 172 173 // The functions below are all virtual functions that you MUST override in Lua 174 // for this class to work. 175 176 // Override this function to return the size of the data for GetDataHere(). 177 //virtual size_t GetDataSize() const; 178 179 // Create a Lua function that returns a [bool, Lua string (of exact length GetDataSize())]. 180 // %override [bool, Lua string] wxLuaDataObjectSimple::GetDataHere(); 181 // C++ Func: virtual bool GetDataHere(void *buf) const; 182 //virtual bool GetDataHere() const; 183 184 // Create a Lua function that takes a Lua string as the input data. 185 // %override bool wxLuaDataObjectSimple::SetData(Lua string); 186 // C++ Func: virtual bool SetData(size_t len, const void *buf); 187 //virtual bool SetData(const wxString& str); 188 }; 189 190 // --------------------------------------------------------------------------- 191 // wxDataObjectComposite 192 193 class %delete wxDataObjectComposite : public wxDataObject 194 { 195 wxDataObjectComposite(); 196 197 void Add(%ungc wxDataObjectSimple *dataObject, bool preferred = false); 198 %wxchkver_2_8 wxDataFormat GetReceivedFormat() const; 199 wxDataObjectSimple *GetObject(const wxDataFormat& format /*, wxDataObject::Direction dir = Get*/) const; 200 }; 201 202 // --------------------------------------------------------------------------- 203 // wxFileDataObject 204 205 class %delete wxFileDataObject : public wxDataObjectSimple 206 { 207 wxFileDataObject(); 208 209 virtual void AddFile(const wxString& file); 210 wxArrayString GetFilenames() const; 211 }; 212 213 // --------------------------------------------------------------------------- 214 // wxTextDataObject 215 216 class %delete wxTextDataObject : public wxDataObjectSimple 217 { 218 wxTextDataObject(const wxString& text = ""); 219 220 virtual size_t GetTextLength() const; 221 virtual wxString GetText() const; 222 virtual void SetText(const wxString& text); 223 }; 224 225 // --------------------------------------------------------------------------- 226 // wxBitmapDataObject 227 228 class %delete wxBitmapDataObject : public wxDataObjectSimple 229 { 230 wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap); 231 232 virtual wxBitmap GetBitmap() const; 233 virtual void SetBitmap(const wxBitmap& bitmap); 234 }; 235 236 // --------------------------------------------------------------------------- 237 // wxCustomDataObject - FIXME implement this? 238 239 //class wxCustomDataObject : public wxDataObjectSimple 240 //{ 241 // wxCustomDataObject(const wxDataFormat& format = wxFormatInvalid); 242 // 243 // virtual void *Alloc(size_t size); 244 // virtual void Free(); 245 // virtual size_t GetSize() const; 246 // virtual void *GetData() const; 247 // virtual void SetData(size_t size, const void *data); 248 // virtual void TakeData(size_t size, void *data); 249 //}; 250 251 // --------------------------------------------------------------------------- 252 // wxURLDataObject - is simply wxTextDataObject with a different name 253 254 #if %wxchkver_2_8 255 256 class %delete wxURLDataObject : public wxTextDataObject 257 { 258 wxURLDataObject(const wxString& url = ""); 259 260 wxString GetURL() const; 261 void SetURL(const wxString& url); 262 }; 263 264 #endif //%wxchkver_2_8 265 266 #endif //wxLUA_USE_wxDataObject && wxUSE_DATAOBJ 267 268 // --------------------------------------------------------------------------- 269 // wxDropTarget 270 271 #if wxLUA_USE_wxDragDrop && wxUSE_DRAG_AND_DROP 272 273 #include "wx/dnd.h" 274 275 enum 276 { 277 wxDrag_CopyOnly, 278 wxDrag_AllowMove, 279 wxDrag_DefaultMove 280 }; 281 282 enum wxDragResult 283 { 284 wxDragError, 285 wxDragNone, 286 wxDragCopy, 287 wxDragMove, 288 wxDragLink, 289 wxDragCancel 290 }; 291 292 bool wxIsDragResultOk(wxDragResult res); 293 294 class wxDropTarget 295 { 296 //wxDropTarget(wxDataObject* data = NULL) pure virtual functions in MSW 297 298 virtual bool GetData(); 299 300 //virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 301 //virtual bool OnDrop(wxCoord x, wxCoord y); 302 //virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); 303 //virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); 304 //virtual void OnLeave(); 305 306 wxDataObject *GetDataObject() const; 307 void SetDataObject(%ungc wxDataObject* data); 308 309 wxDragResult GetDefaultAction(); 310 void SetDefaultAction(wxDragResult action); 311 }; 312 313 // --------------------------------------------------------------------------- 314 // wxFileDropTarget - Base class only, use a wxLuaFileDropTarget and override the virtuals 315 316 class wxFileDropTarget : public wxDropTarget 317 { 318 //wxFileDropTarget(); 319 //virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 320 //virtual bool OnDrop(long x, long y, const void *data, size_t size); 321 //virtual bool OnDropFiles(wxCoord x, wxCoord y,const wxArrayString& filenames); 322 }; 323 324 // --------------------------------------------------------------------------- 325 // wxLuaFileDropTarget 326 327 class wxLuaFileDropTarget : public wxFileDropTarget 328 { 329 wxLuaFileDropTarget(); 330 331 // Create a Lua function that returns a wxDragResult. 332 // %override wxDragResult wxLuaFileDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def); 333 // C++ Func: virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 334 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 335 336 // Create a Lua function that returns a bool. 337 // %override bool OnDropFiles(wxCoord x, wxCoord y,const wxArrayString& filenames); 338 // C++ Func: virtual bool OnDropFiles(wxCoord x, wxCoord y,const wxArrayString& filenames); 339 virtual bool OnDropFiles(wxCoord x, wxCoord y,const wxArrayString& filenames); 340 }; 341 342 // --------------------------------------------------------------------------- 343 // wxTextDropTarget - Base class only, use a wxLuaTextDropTarget and override the virtuals 344 345 class wxTextDropTarget : public wxDropTarget 346 { 347 //wxTextDropTarget(); 348 //virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text); 349 //virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 350 }; 351 352 // --------------------------------------------------------------------------- 353 // wxLuaTextDropTarget 354 355 class wxLuaTextDropTarget : public wxTextDropTarget 356 { 357 wxLuaTextDropTarget(); 358 359 // Create a Lua function that returns a wxDragResult. 360 // %override wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 361 // C++ Func: virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 362 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 363 364 // Create a Lua function that returns a bool. 365 // %override bool OnDropText(wxCoord x, wxCoord y, const wxString& text); 366 // C++ Func: virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text); 367 virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text); 368 369 // Create a Lua function that returns a wxDragResult. 370 // %override wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); 371 // C++ Func: virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); 372 virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); 373 374 // Create a Lua function that returns a void. 375 // %override void OnLeave(); 376 // C++ Func: virtual void OnLeave(); 377 virtual void OnLeave(); 378 379 // Create a Lua function that returns a wxDragResult. 380 // %override wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); 381 // C++ Func: virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); 382 virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); 383 }; 384 385 // --------------------------------------------------------------------------- 386 // wxLuaURLDropTarget - wxLua added class, see wxWidgets/samples/dnd 387 388 class wxLuaURLDropTarget : public wxDropTarget 389 { 390 wxLuaURLDropTarget(); 391 392 // Create a Lua function that returns a wxDragResult. 393 // %override wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 394 // C++ Func: virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 395 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); 396 397 // Create a Lua function that returns a bool. 398 // %override bool OnDropURL(wxCoord x, wxCoord y, const wxString& text); 399 // C++ Func: virtual bool OnDropURL(wxCoord x, wxCoord y, const wxString& text); 400 virtual bool OnDropURL(wxCoord x, wxCoord y, const wxString& text); 401 }; 402 403 // --------------------------------------------------------------------------- 404 // wxDropSource 405 406 class %delete wxDropSource // FIXME implement virtual 407 { 408 %win|%mac wxDropSource(wxWindow* win = NULL, const wxCursor& cursorCopy = wxNullCursor, const wxCursor& cursorMove = wxNullCursor, const wxCursor& cursorStop = wxNullCursor); 409 %gtk wxDropSource(wxWindow* win = NULL, const wxIcon& iconCopy = wxNullIcon, const wxIcon& iconMove = wxNullIcon, const wxIcon& iconStop = wxNullIcon); 410 %win wxDropSource(wxDataObject& data, wxWindow* win = NULL, const wxCursor& cursorCopy = wxNullCursor, const wxCursor& cursorMove = wxNullCursor, const wxCursor& cursorStop = wxNullCursor); 411 %gtk wxDropSource(wxDataObject& data, wxWindow* win = NULL, const wxIcon& iconCopy = wxNullIcon, const wxIcon& iconMove = wxNullIcon, const wxIcon& iconStop = wxNullIcon); 412 413 void SetData(wxDataObject& data); 414 virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); 415 wxDataObject* GetDataObject(); 416 virtual bool GiveFeedback(wxDragResult effect); 417 void SetCursor(wxDragResult res, const wxCursor& cursor); 418 }; 419 420 // --------------------------------------------------------------------------- 421 // wxDropFilesEvent 422 423 #include "wx/event.h" 424 425 class %delete wxDropFilesEvent : public wxEvent 426 { 427 %wxEventType wxEVT_DROP_FILES // EVT_DROP_FILES(func); 428 429 // wxDropFilesEvent(WXTYPE id = 0, int noFiles = 0, wxString* files = NULL) only handle this event 430 431 // %override [Lua table of strings] wxDropFilesEvent::GetFiles(); 432 // C++ Func: wxString* GetFiles() const; 433 wxString* GetFiles() const; 434 435 int GetNumberOfFiles() const; 436 wxPoint GetPosition() const; 437 }; 438 439 #endif //wxLUA_USE_wxDragDrop && wxUSE_DRAG_AND_DROP 440 441 // --------------------------------------------------------------------------- 442 // wxMetafile 443 444 #if wxLUA_USE_wxMetafile && wxUSE_METAFILE && (%msw|%mac|%os2); 445 446 #include "wx/metafile.h" 447 448 //bool wxMakeMetafilePlaceable(const wxString& filename, int minX, int minY, int maxX, int maxY, float scale = 1.0); 449 450 class %delete wxMetafile : public wxObject 451 { 452 wxMetafile(const wxString& filename = ""); 453 454 bool Ok(); 455 bool Play(wxDC *dc); 456 bool SetClipboard(int width = 0, int height = 0); 457 }; 458 459 // --------------------------------------------------------------------------- 460 // wxMetafileDC 461 class %delete wxMetafileDC : public wxDC 462 { 463 wxMetafileDC(const wxString& filename = ""); 464 465 %win %gc wxMetafile* Close(); 466 }; 467 468 #endif 469 470 #endif //wxLUA_USE_wxMetafile && wxUSE_METAFILE && (%msw|%mac|%os2); 471