/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     2000/02/08
// RCS-ID:      $Id: hellosvc.cpp,v 1.2 2001/04/04 12:42:37 aleksandras Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:   	GPL (version 2.0 or later)
/////////////////////////////////////////////////////////////////////////////

#ifdef __GNUG__
    #pragma implementation "hellosvc.cpp"
    #pragma interface "hellosvc.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "hellosvc.h"

/***** Implementation for class HelloService *****/

static wxCommandInfo gHelloCommands[] = {

	wxCommandInfo( HelloService::ID_SAY_HELLO,  // id
				  "Say it!", 					// menu-item title
				  "says hello", 				// help string
				  "Alt+F10"					// short-key
				), 

	wxCommandInfo( 0, "" ) // list-terminator
};

static wxPMMergableMenuChain gHelloChains[] = {

	wxPMMergableMenuChain( "/&Hello/", gHelloCommands ),

	wxPMMergableMenuChain( "", NULL ) // list-terminator
};

IMPLEMENT_DYNAMIC_CLASS( HelloService, wxEvtHandler )

BEGIN_EVENT_TABLE( HelloService, wxEvtHandler )

	EVT_MENU( ID_SAY_HELLO, HelloService::OnSayHello )

END_EVENT_TABLE()

HelloService::HelloService()
{
	// this hack is absolutely a must for each service. Using the 
	// ref-data member of wxObject, PMF can safely cast any wxObject 
	// back to wxPMService (see API-spec for more comments)

	SetRefData( (wxObjectRefData*)(wxPMService*)this );
}

HelloService::~HelloService()
{
	SetRefData( NULL ); // part of the above hack..
}


wxPMMergableMenuChain* HelloService::GetMergableMenuChain()
{
	return gHelloChains;
}

bool HelloService::Start()
{
	// do whatever you like here

	return TRUE; // started ok
}

void HelloService::OnSayHello( wxCommandEvent& event )
{
	wxMessageBox( "\"Hello\" from HelloServce!" );
}

// also needed by PMF. By calling this method, PMF can safely
// cast any given service back to wxObject, but the "cast" should
// always occure inside the service class, only in this section
// compiler "knows" how to do it properly, taking into account
// multiple base classes (v-mtd-tables)

wxObject* HelloService::GetWxObject()
{
	return (wxObject*)this;
}