diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2009-03-07 10:46:36 +0000 |
|---|---|---|
| committer | joncruz <joncruz@users.sourceforge.net> | 2009-03-07 10:46:36 +0000 |
| commit | 0062f23db948341f7912ad7401d90a10da0f3bfe (patch) | |
| tree | f571d1b1645c2e10db49aa6c23e39a3917ca396a /src/widgets | |
| parent | Updated Dutch and Russian translations (diff) | |
| download | inkscape-0062f23db948341f7912ad7401d90a10da0f3bfe.tar.gz inkscape-0062f23db948341f7912ad7401d90a10da0f3bfe.zip | |
Moving dnd data generation into the generic ColorDef class.
(bzr r7433)
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/eek-color-def.cpp | 38 | ||||
| -rw-r--r-- | src/widgets/eek-color-def.h | 3 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/widgets/eek-color-def.cpp b/src/widgets/eek-color-def.cpp index 6334061c2..8c8d240c6 100644 --- a/src/widgets/eek-color-def.cpp +++ b/src/widgets/eek-color-def.cpp @@ -43,6 +43,8 @@ #include <libintl.h> #endif +#include <stdint.h> + #if !defined(_) #define _(s) gettext(s) #endif // !defined(_) @@ -125,6 +127,42 @@ public: void* _data; }; + +std::vector<std::string> ColorDef::getMIMETypes() +{ + std::vector<std::string> listing; + if ( getType() != eek::ColorDef::RGB ) { + listing.push_back("application/x-oswb-nocolor"); + } + listing.push_back("application/x-color"); + listing.push_back("text/plain"); + return listing; +} + +void ColorDef::getMIMEData(std::string const & type, char*& dest, int& len, int& format) +{ + if ( type == "text/plain" ) { + dest = new char[8]; + snprintf( dest, 8, "#%02x%02x%02x", getR(), getG(), getB() ); + dest[7] = 0; + len = 8; + format = 8; + } else if ( (type == "application/x-color") || (type == "application/x-oswb-nocolor") ) { + uint16_t* tmp = new uint16_t[4]; + tmp[0] = (getR() << 8) | getR(); + tmp[1] = (getG() << 8) | getG(); + tmp[2] = (getB() << 8) | getB(); + tmp[3] = 0xffff; + dest = reinterpret_cast<char*>(tmp); + len = 8; + format = 16; + } else { + // nothing + dest = 0; + len = 0; + } +} + void ColorDef::setRGB( unsigned int r, unsigned int g, unsigned int b ) { if ( r != this->r || g != this->g || b != this->b ) { diff --git a/src/widgets/eek-color-def.h b/src/widgets/eek-color-def.h index 7e54182d6..39d69d5d1 100644 --- a/src/widgets/eek-color-def.h +++ b/src/widgets/eek-color-def.h @@ -64,6 +64,9 @@ public: ColorType getType() const { return type; } + std::vector<std::string> getMIMETypes(); + void getMIMEData(std::string const & type, char*& dest, int& len, int& format); + void setRGB( unsigned int r, unsigned int g, unsigned int b ); unsigned int getR() const { return r; } unsigned int getG() const { return g; } |
