|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZ_POPUPMENU_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_POPUPMENU_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tw/action.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tw/popup.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tw/button.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TWIN_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TPopupMenu;
|
|
Toshihiro Shimizu |
890ddd |
class TPopupMenuItem;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TPopupMenuListener
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenuListener() {}
|
|
Toshihiro Shimizu |
890ddd |
virtual ~TPopupMenuListener() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual void onMenuSelect(TPopupMenuItem *item) = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TPopupMenuItem : public TButton
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
wstring m_title;
|
|
Toshihiro Shimizu |
890ddd |
bool m_selected;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenuItem(TPopupMenu *parent, string name);
|
|
Toshihiro Shimizu |
890ddd |
void repaint();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void enter(const TPoint &);
|
|
Toshihiro Shimizu |
890ddd |
void leave(const TPoint &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonDown(const TMouseEvent &e);
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonUp(const TMouseEvent &e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setTitle(wstring title);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenu *getPopup();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void select(bool on);
|
|
Toshihiro Shimizu |
890ddd |
bool isSelected() const { return m_selected; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual int getWidth();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TPopupMenuSeparator : public TWidget
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenuSeparator(TPopupMenu *parent);
|
|
Toshihiro Shimizu |
890ddd |
void repaint();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Note: to implement right-mouse-bottom menu use
|
|
Toshihiro Shimizu |
890ddd |
// the class TContextMenu (see below)
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TPopupMenu : public TPopup
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenuItem *m_currentItem;
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenuListener *m_listener;
|
|
Toshihiro Shimizu |
890ddd |
int m_firstVisibleItem;
|
|
Toshihiro Shimizu |
890ddd |
int m_visibleItemCount;
|
|
Toshihiro Shimizu |
890ddd |
bool m_leftAlignment;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenu(TWidget *parent, string name = "popupMenu");
|
|
Toshihiro Shimizu |
890ddd |
void draw();
|
|
Toshihiro Shimizu |
890ddd |
void configureNotify(const TDimension &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonDrag(const TPoint &, UCHAR);
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonUp(const TPoint &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void popup(const TPoint &pos, int width = 120);
|
|
Toshihiro Shimizu |
890ddd |
void close();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPopupMenuItem *getCurrentItem() { return m_currentItem; }
|
|
Toshihiro Shimizu |
890ddd |
void setListener(TPopupMenuListener *);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static TPopupMenu *getCurrentMenu();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setLeftAlignment(bool a)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_leftAlignment = a;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
void updateItemsVisibility();
|
|
Toshihiro Shimizu |
890ddd |
void updateSize();
|
|
Toshihiro Shimizu |
890ddd |
void computeSize(TPoint &pos, int maxY);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
friend class TPopupMenuArrow;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TContextMenu :
|
|
Toshihiro Shimizu |
890ddd |
// a class specifically dedicated to
|
|
Toshihiro Shimizu |
890ddd |
// right-mouse-button popup menu (aka Context Menu)
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Note: DON'T use the method popup() (inherited from TPopupMenu)
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Note: the context menu will be automatically destroyed
|
|
Toshihiro Shimizu |
890ddd |
// DON'T keep a reference to the context menu
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// see examples below
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---- Example 1 (position indipendent) ----
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Pluto::rightButtonUp(const TMouseEvent &e) {
|
|
Toshihiro Shimizu |
890ddd |
TContextMenu *menu = new TContextMenu(this);
|
|
Toshihiro Shimizu |
890ddd |
menu->addCommand("MI_Cut");
|
|
Toshihiro Shimizu |
890ddd |
menu->addCommand("MI_Copy");
|
|
Toshihiro Shimizu |
890ddd |
menu->addCommand("MI_Paste");
|
|
Toshihiro Shimizu |
890ddd |
menu->addCommand("MI_Clear");
|
|
Toshihiro Shimizu |
890ddd |
TContextMenu::open(menu, e.m_pos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
---- Example 2 (position dependent) ----
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class MyContextMenu : public TContextMenu {
|
|
Toshihiro Shimizu |
890ddd |
int m_myValue;
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
MyContextMenu(TWidget*parent, int myValue)
|
|
Toshihiro Shimizu |
890ddd |
: TContextMenu(parent), m_myValue(myValue), m_col(col) {
|
|
Toshihiro Shimizu |
890ddd |
tconnect(this, "foo", this, &CellContextMenu::onFoo);
|
|
Toshihiro Shimizu |
890ddd |
tconnect(this, "bar", this, &CellContextMenu::onBar);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void onFoo() { ... }
|
|
Toshihiro Shimizu |
890ddd |
void onBar() { ... }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Pluto::rightButtonUp(const TMouseEvent &e) {
|
|
Toshihiro Shimizu |
890ddd |
int row = ....
|
|
Toshihiro Shimizu |
890ddd |
int col = ....
|
|
Toshihiro Shimizu |
890ddd |
TContextMenu::open(new CellContextMenu(this, row, col), e.m_pos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
-----------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TContextMenu : public TPopupMenu
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
class CommandFilter
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
virtual bool check(string cmdName) const = 0;
|
|
Toshihiro Shimizu |
890ddd |
virtual ~CommandFilter() {}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TContextMenu(TWidget *parent);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void add(string name, TGenericCommandAction *action);
|
|
Toshihiro Shimizu |
890ddd |
void addCommand(string cmdName);
|
|
Toshihiro Shimizu |
890ddd |
void addCommand(string cmdName, TGenericCommandAction *action);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addSeparator() { new TPopupMenuSeparator(this); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline void addCommand(string cmdName, T*target, void (T::*method)()) {
|
|
Toshihiro Shimizu |
890ddd |
//addCommand(cmdName, new TCommandAction<t>(target, method));</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static void open(TContextMenu *menu, const TPoint &pos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static void setCommandFilter(CommandFilter *filter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void onTimer(int);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline void tconnect(TContextMenu *menu, string cmdName, T *target, void (T::*method)())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
menu->addCommand(cmdName, new TCommandAction<t>(target, method));</t>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class arg="" class="" t,=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline void tconnect(
|
|
Toshihiro Shimizu |
890ddd |
TContextMenu *menu, string cmdName,
|
|
Toshihiro Shimizu |
890ddd |
T *target, void (T::*method)(Arg), Arg arg)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
menu->addCommand(cmdName, new TCommandAction1<t, arg="">(target, method, arg));</t,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|