/*
 * This file is part of libtqtvd_astronav
 *
 * Copyright (C) 2008-2017 TQTVD Software
 * Copyright (C) 2017 Mirakulo Software (mirakulo@mirakulo.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

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

#include "IGraphicManagerAdapter.h"

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


using namespace BAL;				/* getBIGraphicsDevice() */


namespace WebCore {

Cursor::Cursor(const Cursor& other)
    : m_impl(other.m_impl)
{
	getBIGraphicsDevice();
}

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_t data[4 * height];
	uint8_t 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();
}

}

