/* Copyright 2015-2017, Stephen Fryatt (info@stevefryatt.org.uk)
 *
 * This file is part of Wimp Programming In C:
 *
 *   http://www.stevefryatt.org.uk/risc-os/wimp-prog
 *
 * Licensed under the EUPL, Version 1.2 only (the "Licence");
 * You may not use this work except in compliance with the
 * Licence.
 *
 * You may obtain a copy of the Licence at:
 *
 *   http://joinup.ec.europa.eu/software/page/eupl
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the Licence for the specific language governing
 * permissions and limitations under the Licence.
 */

/**
 * File: ibar.c
 */

#include "oslib/wimp.h"
#include "sflib/event.h"
#include <string.h>

#include "ibar.h"

#include "main.h"
#include "repbox.h"

/* Function Prototypes. */

static void ibar_mouse_click(wimp_pointer *pointer);

/* Iconbar Initialisation. */

void ibar_initialise(void)
{
	wimp_icon_create icon_bar;

	icon_bar.w = wimp_ICON_BAR_RIGHT;
	icon_bar.icon.extent.x0 = 0;
	icon_bar.icon.extent.y0 = 0;
	icon_bar.icon.extent.x1 = 68;
	icon_bar.icon.extent.y1 = 68;
	icon_bar.icon.flags = wimp_ICON_SPRITE | (wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT);
	strncpy(icon_bar.icon.data.sprite, "application", osspriteop_NAME_LIMIT);

	wimp_create_icon(&icon_bar);

	event_add_window_mouse_event(wimp_ICON_BAR, ibar_mouse_click);
}

/* Mouse Click event handler */

static void ibar_mouse_click(wimp_pointer *pointer)
{
	switch (pointer->buttons) {
	case wimp_CLICK_SELECT:
		repbox_message("Hello World!");
		break;
	case wimp_CLICK_ADJUST:
		main_quit_flag = TRUE;
		break;
	}
}
