/*
 * File:	minimal.cc
 * Purpose:	Minimal wxWindows app
 * Author:	Julian Smart
 * Created:	1993
 * Updated:	
 * Copyright:	(c) 1993, AIAI, University of Edinburgh
 */

/* static const char sccsid[] = "%W% %G%"; */

#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif

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

#ifdef __BORLANDC__
#pragma hdrstop
#endif

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

// Define a new application type
class MyApp: public wxApp
{ public:
    wxFrame *OnInit(void);
};

// Define a new frame type
class MyFrame: public wxFrame
{ public:
    MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
    void OnMenuCommand(int id);
    Bool OnClose(void) { return TRUE; }
};


class MyDialog: public wxDialogBox
{
	private:
		// Widgets which will be on the dialog
		wxButton		*OkBtn;
		wxButton		*CancelBtn;
		wxListBox	*NameList;

	public:
		MyDialog(wxWindow *parent, char *title, Bool modalState, int x, int y, int w, int h, long style, char *name);
		
		Bool	OnClose(void);
		void	OnCommand(wxWindow& win, wxCommandEvent& event);
 		void	OnActivate(Bool) {};  // necessary for accelerators to work
};


// ID for the menu quit command
#define MINIMAL_QUIT 1

// This statement initializes the whole application and calls OnInit
MyApp myApp;



// A macro needed for some compilers (AIX) that need 'main' to be defined
// in the application itself.
IMPLEMENT_WXWIN_MAIN

// `Main program' equivalent, creating windows and returning main app frame
wxFrame *MyApp::OnInit(void)
{
  // Create the main frame window
	MyFrame *frame = new MyFrame(NULL, "Minimal wxWindows App", 50, 50, 400, 300);

  // Give it an icon
#ifdef wx_msw
  frame->SetIcon(new wxIcon("mondrian"));
#endif
#ifdef wx_x
  frame->SetIcon(new wxIcon("aiai.xbm"));
#endif

  // Make a menubar
  wxMenu *file_menu = new wxMenu;

  file_menu->Append(MINIMAL_QUIT, "E&xit");
  wxMenuBar *menu_bar = new wxMenuBar;
  menu_bar->Append(file_menu, "File");
  frame->SetMenuBar(menu_bar);

  // Make a panel with a message
  wxPanel *panel = new wxPanel(frame, 0, 0, 400, 400);

  panel->SetLabelPosition(wxHORIZONTAL) ;
  wxMessage *msg = new wxMessage(panel, "Hello, this is a minimal wxWindows program!", 5, 5);

  MyDialog *dialog = new MyDialog(frame, "This is my dialog", FALSE, 50, 50, 250, 200, wxDEFAULT_DIALOG_STYLE, "MyDialogWindow");

  // Show the frame
  frame->Show(TRUE);

  // Return the main frame window
  return frame;
}

// My frame constructor
MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
  wxFrame(frame, title, x, y, w, h)
{}

// Intercept menu commands
void MyFrame::OnMenuCommand(int id)
{
  switch (id) {
    case MINIMAL_QUIT:
      delete this;
    break;
  }
}



// My dialog constructor
MyDialog::MyDialog(wxWindow *parent, char *title, Bool modalState, int x, int y, int w, int h, long style, char *name):
  wxDialogBox(parent, title, modalState, x, y, w, h, style, name)
{
	  wxButton	*OkBtn		= new wxButton(this, (wxFunction)NULL, "&Ok",30,19,60,23,0,"OkBtn");
	  wxButton	*CancelBtn	= new wxButton(this, (wxFunction)NULL, "&Cancel",30,69,60,23,0,"CancelBtn");;

	  wxListBox	*NameList	= new wxListBox(this, (wxFunction)NULL, "&Valid names",
                                  wxSINGLE, 10, 10, 150, 100);

	  Show(TRUE);
}  // MyDialog constructor


Bool MyDialog::OnClose()
{
	return TRUE;
}  // MyDialog::OnClose()


void MyDialog::OnCommand(wxWindow& win, wxCommandEvent& event)
{
	char *widgetName = win.GetName();
	if (strcmp(win.GetName(), OkBtn->GetName())==0)
	{
		wxMessageBox("The <OK> button was pressed","Button pressed....");
		return;
	}

	if (strcmp(win.GetName(), CancelBtn->GetName())==0)
	{
		wxMessageBox("The <Cancel> button was pressed","Button pressed....");
		return;
	}
}  // MyDialog::OnCommand()