A brief warning to Win32 API people: This is intended for a non-technical audience. I'm going to simplify a bit. A hard technical writeup would (hint, hint) be a nice addition to this node. Writeups about other clipboard implementations in MacOS or whatever would be even more welcome: That's why I didn't specify an OS in the node title.

When you "copy" something in MS Windows, it usually goes in something called the "clipboard".

Okay, what's that? And why "usually"?

In Windows, the "clipboard" is a facility provided by the operating system (let's not quibble about how loosely I'm using that term here :)1. Simply put, it's a "place" where any program can put data, and where it or any other program can access that data. As for "usually", a program is not required to use the system clipboard. It can set aside its own little "place" and do the same thing with that. The problem is that other programs won't be able to access what's there. If you copy something in Notepad, it's nice to be able to paste it into Word, Netscape, or whatever. The system clipboard makes that possible.

When a program puts something in the clipboard, it provides two things: The data itself, and a "name" identifying what kind of data it is: Each kind of data is called a "clipboard format". It could be plain text, or an image, or formatted text, or just about anything. Several of these are defined by the operating system, but a program can define its own and "register" them with the operating system.

When some program wants to retrieve something from the clipboard, it can ask the operating system what formats are currently available, and then request the data for a particular format.

A program can put several different kinds of data in there at the same time if it wants to. For example, when you copy text in Word 97, it's stored in each of the following clipboard formats:

"DataObject", "Object Descriptor", "Rich Text Format", "TEXT", "UNICODETEXT", "METAFILEPICT", "Embed Source", "Native", "OwnerLink", "Link Source", "Link Source Descriptor", "ObjectLink", "Hyperlink", "OLE Private Data", "LOCALE", "OEMTEXT", and "ENHMETAFILE"

I'm not perfectly certain what half of those are for, but they're all different sorts of information about what you copied: Rich Text Format preserves the boldface, italics and so forth; "TEXT" has only the text, with no formatting. And so on and so forth. Some of them, at least, are probably specific to Word, in which case there may be no documentation available to me (barring industrial espionage) which explains what's in there .

From where the user sits, what this means is that if you copy something from Word and try to paste it into Notepad, Notepad will query the operating system and ask it if there's any "TEXT" in the clipboard. If there is, Notepad will then ask the operating system for the "TEXT" data. Now, if you try to paste into Photoshop instead, Photoshop doesn't know or care about text: It wants a picture. So Photoshop will ask the operating system about each of the image formats that Photoshop understands. If it finds one it likes, it'll request the clipboard data for that particular format, and then do the pasting as it sees fit. Try it: You can copy text from Word and paste it into Photoshop as an image. The results are crappy, but it works.

There you have the essentials. There's more: While a program is writing to the clipboard or reading from it, it "locks" the clipboard so no other program can access it at the same time. This is required because Windows is a multitasking2 operating system; if you had two programs writing to the clipboard at the same time, they'd step on each other and create a mess.

There's also usually a lot of fiddle-faddle about getting the data in the form expected for a given clipboard format. The clipboard itself doesn't care: All it sees is zeroes and ones -- but when you put random crap in the clipboard and claim that it's a "bitmap"3, it should actually be what you claim; otherwise, when a user copies an image out of your program and tries to paste it into Photoshop, Photoshop will sadly tell the user that clipboard is full of crap.




1 Not all operating systems do this (BeOS does, MacOS does; Unices don't). There are valid questions to be asked about whether an operating system has any business getting involved with it at all. I will not address those questions here2. One thing at a time.

2 If somebody wants to add a writeup discussing the issue in a reasonably even-handed and informative way, that'd be great. Don't just tell us that Microsoft sucks. Tell us why, or better yet, inform us enough that we can decide for ourselves.

3 Don't get into coding that one if you don't have some time to kill.

The physical object called a clipboard is a flat sheet of some material stiff enough to press down on, with a clip of metal or plastic at one end (or occasionally one side) to hold papers. Clipboards are wonderful for writing in situations where you don't have a desk or table surface to press down on. You can often tuck writing implements into the clip and carry the clipboard and its contents easily from one place to another.

Log in or register to write something here or to contact authors.