
#include "kjs/wk_config.h"
#include "BALConfiguration.h"			/* getBIGraphicsDevice() */
#include "BCGraphicsDeviceDirectFB.h"
#include "Cursor.h"

#include <directfb.h>

static char *m_pointerCursor[] = {
/* columns rows colors chars-per-pixel */
"16 24 3 1",
". c #ffffff",
"X c #000000",
"  c None",
/* pixels */
" XX             ",
" X.X            ",
" X..X           ",
" X...X          ",
" X....X         ",
" X.....X        ",
" X......X       ",
" X.......X      ",
" X........X     ",
" X.....XXXXX    ",
" X..X..X        ",
" X.X X..X       ",
" XX  X..X       ",
" X    X..X      ",
"      X..X      ",
"       X..X     ",
"       X..X     ",
"        XX      ",
"                ",
"                ",
"                ",
"                ",
"                ",
"                ",
"0,0",
};


using namespace BAL;				/* getBIGraphicsDevice() */


namespace WebCore {

Cursor::Cursor(const Cursor& other)
    : m_impl(other.m_impl)
{
	BCGraphicsDeviceDirectFB* device = static_cast<BCGraphicsDeviceDirectFB*>(getBIGraphicsDevice());

#if 1
	IDirectFB* directfb = (IDirectFB*) device->getSuperInterface();

	IDirectFBDisplayLayer  *layer;

	directfb->GetDisplayLayer( directfb, DLID_PRIMARY, &layer );

	layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE );
	layer->EnableCursor ( layer, 1 );
#endif
}

Cursor::Cursor(Image*, const IntPoint&)
{
	// Yet not implemented.
}

Cursor::Cursor(PlatformCursor c)
    : m_impl(c)
{
	// Yet not implemented.
	m_impl = c;
}

Cursor::Cursor(char* xpmCursor[])
{
	int width = 16, height = 24;
	int i, row, col;
	Uint8 data[4 * height];
	Uint8 mask[4 * height];
	int hot_x, hot_y;

	i = -1;
	for (row = 0; row < height; ++row) {
	    for (col = 0; col < width; ++col) {
	        if (col % 8) {
	            data[i] <<= 1;
	            mask[i] <<= 1;
	        } else {
	            ++i;
	            data[i] = mask[i] = 0;
	        }
	        switch (xpmCursor[4+row][col]) {
	            case 'X':
	                data[i] |= 0x01;
	                mask[i] |= 0x01;
	                break;
	            case '.':
	                mask[i] |= 0x01;
	                break;
	            case ' ':
	                break;
	        }
	    }
	}
	sscanf(xpmCursor[4+row], "%d,%d", &hot_x, &hot_y);
	
	// m_impl = SDL_CreateCursor(data, mask, width, height, hot_x, hot_y);
	m_impl = NULL;
}

Cursor::~Cursor()
{
}

Cursor& Cursor::operator=(const Cursor& other)
{
	// Yet not implemented.
	return *this;
}

const Cursor& pointerCursor()
{
	// Yet not implemented.
	static Cursor c(m_pointerCursor);
	return c;
}

const Cursor& crossCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& handCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& moveCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& iBeamCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& waitCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& helpCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& eastResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& northResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& northEastResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& northWestResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& southResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& southEastResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& southWestResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& westResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& northSouthResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& eastWestResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& northEastSouthWestResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& northWestSouthEastResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& columnResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& rowResizeCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

// FIXME: should find better GDK cursors for those than a generic GDK_LEFT_PTR
const Cursor& verticalTextCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& cellCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& contextMenuCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& noDropCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& copyCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& progressCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& aliasCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& noneCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& notAllowedCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& zoomInCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

const Cursor& zoomOutCursor()
{
	// Yet not implemented.
	return pointerCursor();
}

}

