wxDataObject(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

✨ NAME ✨

wxDataObject β€” bestie, it's a whole data object πŸ’– one that can be copied to or from the clipboard, or dragged and dropped. Slay.


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the main character detail here? wxDataObject is 'smart' data. not like those 'dumb' data containers you've met before (memory buffers? files? yeah. those). being 'smart' here means the data object itself knows what data formats it supports, and it knows how to render itself in every one of those formats. it's self-aware, it's giving main character energy fr fr πŸ’…

a supported format, incidentally, is exactly the format in which the data can be requested from a data object, or from which the data object may be set. and in the general case? an object may support totally different formats on 'input' and 'output' β€” i.e. it may be able to render itself in a given format but not be created from data in that format, or the other way around. wxDataObject defines the wxDataObject::Direction (not implemented in wx) enumeration type which distinguishes between them. πŸŽ€

hit up the wxDataFormat (not implemented in wx) docs for more about formats, iykyk.

not surprisingly, being 'smart' comes at a price of added complexity 😭 which is reasonable for the situations where you really need to support multiple formats… but honestly it can be lowkey annoying if you just want to do something simple like cut and paste text.

so to provide a solution for both cases, wxWidgets has two predefined classes that derive from wxDataObject:

  • wxDataObjectSimple (not implemented in wx) β€” the simplest wxDataObject possible. it only holds data in a single format (such as HTML or text). minimal, unbothered, moisturized ✨
  • wxDataObjectComposite (not implemented in wx) β€” the simplest way to implement a wxDataObject that does support multiple formats, because it achieves this by simply holding several wxDataObjectSimple (not implemented in wx) objects. iconic behavior honestly πŸ‘‘

so, you have several solutions when you need a wxDataObject class (and you need one as soon as you want to transfer data via the clipboard or drag and drop):

πŸ’€ pls note: the easiest way to use drag and drop and the clipboard with multiple formats is by using wxDataObjectComposite (not implemented in wx) β€” but it is not the most efficient one, because each wxDataObjectSimple (not implemented in wx) would contain the whole data in its respective formats.

now imagine you want to paste 200 pages of text in your proprietary format, as well as Word, RTF, HTML, Unicode and plain text to the clipboard… bestie, even today's computers are in trouble. πŸ™ˆ for this case, you will have to derive from wxDataObject directly and make it enumerate its formats and provide the data in the requested format on demand.

alsoooo β€” note that neither the GTK+ data transfer mechanisms for clipboard and drag and drop, nor OLE data transfer, copies any data until another application actually requests the data. this is in contrast to the 'feel' offered to the user of a program who would normally think that the data resides in the clipboard after having pressed 'Copy' β€” in reality it is only declared to be available. not the clipboard lying to you… just vibes 🌈

you may also derive your own data object classes from wxCustomDataObject (not implemented in wx) for user-defined types. the format of user-defined data is given as a mime-type string literal, such as "application/word" or "image/png". these strings are used as they are under Unix (so far only GTK+) to identify a format, and are translated into their Windows equivalent under Win32 (using the OLE IDataObject for data exchange to and from the clipboard and for drag and drop). note that the format string translation under Windows is not yet finished. 🚧

each class derived directly from wxDataObject must override and implement all of its functions which are pure virtual in the base class. and the data objects which only render their data or only set it (i.e. work in only one direction) should return 0 from GetFormatCount() (not implemented in wx). periodt. 🎯

see also, bestie:

  • Overview dnd
  • Examples
  • wxFileDataObject
  • wxTextDataObject
  • wxBitmapDataObject

wxWidgets docs: wxDataObject


🌸 DATA TYPES 🌸

okay so the one and only type on this page, no notes:

wxDataObject() :: wx:wx_object().

she's literally just a wx:wx_object() 🫢


⭐ FUNCTIONS ⭐

crickets πŸ¦—βœ¨

no cap, this section is just sitting here looking pretty β€” the page lists the heading and nothing else. the good stuff lives up in DESCRIPTION. πŸ’œ


that's the whole vibe check, bestie πŸŽ€ this lil gem ships with wx 2.6 and it's brought to you by Ericsson AB β€” ty for coming to my ted talk, go forth and copy/paste responsibly, mwah πŸ’‹

πŸ“¦ where this page comes from