/********************************************************************************
*                                                                               *
*                             O p t i o n   M e n u                             *
*                                                                               *
*********************************************************************************
* Copyright (C) 1997,2026 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#ifndef FXOPTIONMENU_H
#define FXOPTIONMENU_H

#ifndef FXLABEL_H
#include "FXLabel.h"
#endif

namespace FX {


class FXPopup;


/// Option Menu Button flags
enum {
  OPTIONMENU_TOOLBAR   = 0x00800000,  /// Toolbar style button [flat look]
  OPTIONMENU_NOGLYPH   = 0x01000000,  /// Do not display a glyph
  };


/// Option Menu Button
class FXAPI FXOption : public FXLabel {
  FXDECLARE(FXOption)
protected:
  FXColor selbackColor;
  FXColor seltextColor;
protected:
  FXOption();
private:
  FXOption(const FXOption&);
  FXOption &operator=(const FXOption&);
public:
  long onPaint(FXObject*,FXSelector,void*);
  long onEnter(FXObject*,FXSelector,void*);
  long onLeave(FXObject*,FXSelector,void*);
  long onLeftBtnPress(FXObject*,FXSelector,void*);
  long onLeftBtnRelease(FXObject*,FXSelector,void*);
  long onKeyPress(FXObject*,FXSelector,void*);
  long onKeyRelease(FXObject*,FXSelector,void*);
  long onHotKeyPress(FXObject*,FXSelector,void*);
  long onHotKeyRelease(FXObject*,FXSelector,void*);
public:

  /// Constructor
  FXOption(FXComposite* p,const FXString& text,FXIcon* ic=nullptr,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=JUSTIFY_NORMAL|ICON_BEFORE_TEXT,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);

  /// Return default width
  virtual FXint getDefaultWidth() override;

  /// Return default height
  virtual FXint getDefaultHeight() override;

  /// Returns true because a menu button can receive focus
  virtual FXbool canFocus() const override;

  /// Set focus to this window
  virtual void setFocus() override;

  /// Remove the focus from this window
  virtual void killFocus() override;

  /// Return the selection background color
  void setSelBackColor(FXColor clr);

  /// Return the selection background color
  FXColor getSelBackColor() const { return selbackColor; }

  /// Return the selection text color
  void setSelTextColor(FXColor clr);

  /// Return the selection text color
  FXColor getSelTextColor() const { return seltextColor; }

  /// Destructor
  virtual ~FXOption();
  };



/// Option Menu
class FXAPI FXOptionMenu : public FXLabel {
  FXDECLARE(FXOptionMenu)
protected:
  FXPopup  *pane;
  FXOption *current;
protected:
  FXOptionMenu(){}
private:
  FXOptionMenu(const FXOptionMenu&);
  FXOptionMenu &operator=(const FXOptionMenu&);
public:
  long onPaint(FXObject*,FXSelector,void*);
  long onLeftBtnPress(FXObject*,FXSelector,void*);
  long onLeftBtnRelease(FXObject*,FXSelector,void*);
  long onEnter(FXObject*,FXSelector,void*);
  long onLeave(FXObject*,FXSelector,void*);
  long onFocusIn(FXObject*,FXSelector,void*);
  long onFocusOut(FXObject*,FXSelector,void*);
  long onMotion(FXObject*,FXSelector,void*);
  long onKeyPress(FXObject*,FXSelector,void*);
  long onKeyRelease(FXObject*,FXSelector,void*);
  long onCmdPost(FXObject*,FXSelector,void*);
  long onCmdUnpost(FXObject*,FXSelector,void*);
  long onQueryHelp(FXObject*,FXSelector,void*);
  long onQueryTip(FXObject*,FXSelector,void*);
  long onCmdSetValue(FXObject*,FXSelector,void*);
  long onCmdSetIntValue(FXObject*,FXSelector,void*);
  long onCmdGetIntValue(FXObject*,FXSelector,void*);
  long onMouseWheel(FXObject*,FXSelector,void*);
public:

  /// Constructor
  FXOptionMenu(FXComposite* p,FXPopup* pup=nullptr,FXuint opts=JUSTIFY_NORMAL|ICON_BEFORE_TEXT,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);

  /// Create server-side resources
  virtual void create() override;

  /// Detach server-side resources
  virtual void detach() override;

  /// Delete server-side resources
  virtual void destroy() override;

  /// Perform layout
  virtual void layout() override;

  /// Remove the focus from this window
  virtual void killFocus() override;

  /// Return default width
  virtual FXint getDefaultWidth() override;

  /// Return default height
  virtual FXint getDefaultHeight() override;

  /// Return true if the position is logically in the pane
  virtual FXbool contains(FXint parentx,FXint parenty) const override;

  /// Return the option item at the given index
  FXOption *getItem(FXint index) const;

  /// Set the current option
  void setCurrent(FXOption *win,FXbool notify=false);

  /// Return the current option
  FXOption* getCurrent() const { return current; }

  /// Set the current option number
  void setCurrentNo(FXint no,FXbool notify=false);

  /// Get the current option number
  FXint getCurrentNo() const;

  /// Get number of options
  FXint getNumOptions() const;

  /// Set the pane which will be popped up
  void setMenu(FXPopup *pup);

  /// Return the pane which is poppup up
  FXPopup* getMenu() const { return pane; }

  /// Returns true because a option menu can receive focus
  virtual FXbool canFocus() const override;

  /// Return true if popped up
  FXbool isPopped() const;

  /// Save option menu to a stream
  virtual void save(FXStream& store) const override;

  /// Load option menu from a stream
  virtual void load(FXStream& store) override;

  /// Destructor
  virtual ~FXOptionMenu();
  };

}

#endif
