////////////////////////////////////////////////////////////////////////////////
// GLComboBox.h
// Copyright Björn Ganster
// Developed since 2007
////////////////////////////////////////////////////////////////////////////////

#ifndef GLComboBox__H
#define GLComboBox__H

#include "BGBase.h"
#include "BGCPString.h"
#include "GLLineEdit.h"
#include "GLButton.h"
#include "GLWindowContainer.h"
#include "GLContextMenu.h"

#include <vector>

////////////////////////////////////////////////////////////////////////////////
// Base class for a button

class GLComboBox: public GLWindowContainer {
public:
   Color textColor;

   // Constructor
   GLComboBox (GLWindow* _parent = NULL, int _left = 0, int _top = 0, 
             int _width = 0, int _height = 0);

   // Destructor
	~GLComboBox() OVERRIDE;

   // Text access
   inline const BGCPString& getText () const
   { return edit.getText(); }
   inline void setText (const BGCPString& newText) 
   { edit.setText(newText); }

   // Button state changed over a window: returns child that was clicked
	virtual GLWindow* buttonStateChanged (int button, bool down, int x, int y) OVERRIDE
   { return GLWindowContainer::buttonStateChanged(button, down, x, y); }

	virtual void setGeometry (int _left, int _top, int _width, int _height) OVERRIDE
   //{ left = _left, top = _top, width = _width, height = _height; }
   {
      GLWindow::setGeometry(_left, _top, _width, _height);
      edit.setGeometry (0, 0, _width-_height, _height);
      button.setGeometry (edit.getWidth(), 0, _height, _height);
   }

   // Access choices
   size_t getChoicesCount() const
   { return choices.size(); }
   const BGCPString& getChoice(size_t i)
   { return choices[i]; }
   void addChoice (const BGCPString& newChoice)
   { choices.push_back (newChoice); }

   // Receive a message from edit, button, or the context menu
	void receiveMessage (VirtualClass* sender, int MessageType, VirtualClass* data = nullptr)
		OVERRIDE;

   void setListener (MessageListener* _listener)
   { 
      edit.setListener (_listener); 
      listener = _listener;
   }
protected:
   GLLineEdit edit;
   GLButton button;
   GLContextMenu* menu;
   std::vector<BGCPString> choices;

   // Show context menu
   void showContextMenu ();
};

#endif
