///////////////////////////////////////////////////////////////////////////////////////////
// Authors: Eva Bunodiere, Yasmin Kossak
// languageDialog.cpp
// Language Class Function Definitions
// JPC36 Wx-View 
// July 25th 2000
// Technical Advisor : Carlos Moreno
///////////////////////////////////////////////////////////////////////////////////////////

#include "languageDialog.h"

#include "wx-view.h"

#include <cmath>
#include <string>
#include <cctype>
using namespace std;

const int LANGUAGES = 3;
static wxString Choices [LANGUAGES];

/******************************************************************************************
	Function: Language_Dialog::Language_Dialog
	Receives: N/A (constructor)
	Returns: N/A (constructor)
	Description: 
		Creates a new Language selection dialog box. Calls the wxDialog constructor to create a
		new dialog, and adds a new wxChoice to contains a list of languages for the user to 
		select. Resizes the Dialog after placing the controls to ensure correct positioning. 
		Adds Cancel and OK buttons to dismiss the dialog.
*******************************************************************************************/
Language_Dialog::Language_Dialog(wxWindow * parent, wxWindowID id, const wxString &title)
    : wxDialog (parent, id, title, wxDefaultPosition, wxSize(225, 150))
{
    const int margin = 20;

    Choices[0] = translation["English"];
    Choices[1] = translation["French"];
    Choices[2] = translation["Spanish"];

    language_choices = new wxChoice(this, -1, wxPoint(10, margin), wxSize(-1, -1), LANGUAGES, Choices, 0,
		                         wxDefaultValidator, translation["Select a Language"]);
	
    string current_lang = translation.return_language();
    current_lang[0] = toupper(current_lang[0]);
    current_lang = translation[current_lang];

    for (int i = 0; i < LANGUAGES; i++)
    {
        string lower_case (const string &);

        if (lower_case(Choices[i].c_str()) == lower_case(current_lang))
        {
            language_choices->SetSelection(i);
            break;
        }
    }
	
	// Place all controls in positions relative to the previously created controls

	const int x_ok = language_choices->GetRect().GetRight() + 20;
    ok = new wxButton(this, wxID_OK, translation["OK"], wxPoint(x_ok, margin));
    const int y_cancel = ok->GetRect().GetBottom() + 15;
	cancel = new wxButton(this, wxID_CANCEL, translation["Cancel"], wxPoint(x_ok, y_cancel));
	
	const int y_label = cancel->GetRect().GetBottom() + 15;
	restart_label = new wxStaticText(this, -1, translation["Restart_Wx-View"], wxPoint(margin, y_label));
	
	int w, h, client_w, client_h;
	GetSize (&w, &h);
	GetClientSize (&client_w, &client_h);
	
	const int dx = w - client_w;
	const int dy = h - client_h;
	
	const int width = ok->GetRect().GetRight() + margin + dx;
	const int height = restart_label->GetRect().GetBottom() + margin + dy;
	
	SetSize (width, height);
	CentreOnParent(wxBOTH);
}

/******************************************************************************************
	Function: Language_Dialog::language_selected
	Receives: N/A
	Returns: wxString
	Description: 
		Gets the language selected from the wxChoice and returns it as a wxString. 
*******************************************************************************************/
wxString Language_Dialog::language_selected() const
{
    wxString lang = language_choices->GetStringSelection();

    if (lang == translation["French"])
    {
        return "french";
    }
    else if (lang == translation["Spanish"])
    {
        return "spanish";
    }
    else    // by default, English
    {
        return "english";
    }
}
