/* Copyright 2026, 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: results.c
 */

#include "oslib/wimp.h"

#include "sflib/errors.h"
#include "sflib/event.h"
#include "sflib/windows.h"

#include "results.h"

#include "menu.h"

/* Results Menu Entries. */

#define RESULTS_MENU_CLEAR 0

/* Global Variables. */

static wimp_w results_handle = NULL;
static wimp_menu *results_menu = NULL;

/* Function Prototypes. */

static void results_menu_selection(wimp_w window, wimp_menu *menu, wimp_selection *selection);

/* Results Window Initialisation. */

void results_initialise(void)
{
	wimp_window		*window_definition;

	/* Load and create the window. */

	window_definition = windows_load_template("Results");
	if (window_definition == NULL) {
		error_msgs_report_error("BadResultsTempl");
		return;
	}

	results_handle = wimp_create_window(window_definition);
	free(window_definition);

	/* Window Menu. */

	results_menu = menu_create("ResultsMenu", 1);
	if (results_menu == NULL) {
		error_msgs_report_error("BadResultsMenu");
		return;
	}

	menu_entry(results_menu, RESULTS_MENU_CLEAR, "ResultsMenu0", NULL);

	/* Register event handlers. */

	event_add_window_menu(results_handle, results_menu);
	event_add_window_menu_selection(results_handle, results_menu_selection);
}

/* Open the Window. */

void results_open(void)
{
	windows_open_centred_on_screen(results_handle);
}

/* Menu Selection event handler. */

static void results_menu_selection(wimp_w window, wimp_menu *menu, wimp_selection *selection)
{
	if (menu != results_menu)
		return;

	switch (selection->items[0]) {
	case RESULTS_MENU_CLEAR:
		break;
	}
}
