/////////////////////////////////////////////////////////////////////////////
// Name:        MenuObject.h
// Purpose:     The class to store a DVD Menu Object
// Author:      Alex Thuering
// Created:	04.11.2006
// RCS-ID:      $Id: MenuObject.h,v 1.12 2009/12/30 16:56:48 ntalex Exp $
// Copyright:   (c) Alex Thuering
// Licence:     GPL
/////////////////////////////////////////////////////////////////////////////

#ifndef MENU_OBJECT_H
#define MENU_OBJECT_H

#include "DVDAction.h"
#include <wx/image.h>
#include <wx/dynarray.h>

class wxSvgXmlNode;
class wxSVGDocument;
class wxSVGElement;
class wxSVGUseElement;
class wxSVGSVGElement;
class Menu;
class DVD;

enum MenuButtonState { mbsNORMAL, mbsHIGHLIGHTED, mbsSELECTED };

struct MenuObjectParam {
  wxString name;
  wxString title;
  wxString type;
  wxString element; // id of element
  wxString attribute; // attribute name
  bool changeable; // changed if select the button
  wxColour normalColour;
  wxColour highlightedColour;
  wxColour selectedColour;
};

WX_DEFINE_ARRAY(MenuObjectParam*, MenuObjectParams);

struct MenuObjectSize {
	unsigned int value;
	unsigned int valueInc;
	unsigned int valuePercent;
	wxArrayString elements;
};

class MenuObject {
  public:
	MenuObject(Menu* menu, bool vmg, wxString fileName = wxT(""), int x = 0, int y = 0,
			wxString param = wxT(""));
	virtual ~MenuObject();
	
	virtual wxString GetId(bool translate = false);
	inline bool IsButton() { return m_button; }
	inline DVDAction& GetAction() { return m_action; }
    
    inline wxString GetFileName() { return m_fileName; }
    inline wxString GetTitle() { return m_title; }
    
    int  GetX();
    void SetX(int value);
    int  GetY();
    void SetY(int value);
    int  GetWidth();
    void SetWidth(int value);
    int  GetHeight();
    void SetHeight(int value);
    
    inline wxRect GetBBox() { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
	
	inline bool IsDefaultSize() { return m_defaultSize; }
	inline void SetDefaultSize(bool value = true) { m_defaultSize = value; }
    void FixSize(int& width, int& height);
    void UpdateSize();
    
    int GetObjectParamsCount() { return m_params.Count(); }
    MenuObjectParam* GetObjectParam(int index) { return m_params[index]; }
    MenuObjectParam* GetObjectParam(wxString name);
    MenuObjectParam* GetInitParam();
    
    wxString GetParam(wxString name, wxString attrSuffix = wxEmptyString);
	void SetParam(wxString name, wxString value, wxString attrSuffix = wxEmptyString);
    int GetParamInt(wxString name);
	void SetParamInt(wxString name, int value);
	double GetParamDouble(wxString name);
	void SetParamDouble(wxString name, double value);
	wxFont GetParamFont(wxString name);
	void SetParamFont(wxString name, wxFont value);
	wxColour GetParamColour(wxString name, MenuButtonState state = mbsNORMAL);
	void SetParamColour(wxString name, wxColour value, MenuButtonState state = mbsNORMAL);
    
    void ToFront();
    void Forward();
    void Backward();
    void ToBack();
    bool IsFirst();
    bool IsLast();
	
	wxString GetDirection(int dir) { return m_direction[dir]; }
	void SetDirection(int dir, wxString value) { m_direction[dir] = value; }
	
	wxImage GetImage(int maxWidth, int maxHeight);
	
	virtual wxSvgXmlNode* GetXML(DVDFileType type, DVD* dvd, bool withSVG = false, int playAllRegister = -1);
	virtual bool PutXML(wxSvgXmlNode* node);
	
  private:
	wxString m_id;
	bool m_button;
	DVDAction m_action;
    wxString m_fileName;
    wxString m_title;
    bool m_previewHighlighted;
    
	wxString m_direction[4]; // left, right, up, down button names
    
    MenuObjectParams m_params;
    wxString m_initParameter;
	
    bool m_defaultSize;
    MenuObjectSize m_defaultWidth;
    MenuObjectSize m_defaultHeight;
    
    MenuObjectSize m_minWidth;
    MenuObjectSize m_minHeight;
    
    bool m_deleteSVG;
    wxSVGDocument* m_svg;
    wxSVGUseElement* m_use;
    wxSVGSVGElement* m_symbol;
    wxSVGSVGElement* AddSymol(wxString id, wxSVGElement* content);
    void AddUse(wxString id, int x, int y, int width, int height);
    
    bool Init(wxString filename, int x = 0, int y = 0, wxString param = wxT(""));
    bool LoadSVG(wxSVGDocument& svg, wxSvgXmlNode* node);
    wxString GenerateId(wxString prefix);
    void InitSize(wxString value, MenuObjectSize& size);
    unsigned int CalcSize(MenuObjectSize& size, bool width);
};

#endif // MENU_OBJECT_H
