From 0062f23db948341f7912ad7401d90a10da0f3bfe Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 7 Mar 2009 10:46:36 +0000 Subject: Moving dnd data generation into the generic ColorDef class. (bzr r7433) --- src/widgets/eek-color-def.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/widgets/eek-color-def.h | 3 +++ 2 files changed, 41 insertions(+) (limited to 'src/widgets') 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 #endif +#include + #if !defined(_) #define _(s) gettext(s) #endif // !defined(_) @@ -125,6 +127,42 @@ public: void* _data; }; + +std::vector ColorDef::getMIMETypes() +{ + std::vector 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(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 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; } -- cgit v1.2.3