1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
4 // This file is part of CenterIM.
6 // CenterIM is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // CenterIM is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
22 /// @ingroup cppconsui
30 #define MENU_WINDOW_WISH_WIDTH 40
34 class MenuWindow
: public Window
{
36 MenuWindow(int x
, int y
, int w
, int h
, const char *title
= nullptr);
37 MenuWindow(Widget
&ref
, int w
, int h
, const char *title
= nullptr);
38 virtual ~MenuWindow() override
;
41 virtual void onAbsolutePositionChange(Widget
&widget
) override
;
44 virtual void show() override
;
45 virtual void hide() override
;
46 virtual void close() override
;
47 virtual void onScreenResized() override
;
49 virtual Button
*insertItem(std::size_t pos
, const char *title
,
50 const sigc::slot
<void, Button
&> &callback
)
52 return listbox_
->insertItem(pos
, title
, callback
);
54 virtual Button
*appendItem(
55 const char *title
, const sigc::slot
<void, Button
&> &callback
)
57 return listbox_
->appendItem(title
, callback
);
59 virtual AbstractLine
*insertSeparator(std::size_t pos
)
61 return listbox_
->insertSeparator(pos
);
63 virtual AbstractLine
*appendSeparator()
65 return listbox_
->appendSeparator();
67 virtual Button
*insertSubMenu(
68 std::size_t pos
, const char *title
, MenuWindow
&submenu
);
69 virtual Button
*appendSubMenu(const char *title
, MenuWindow
&submenu
);
70 virtual void insertWidget(std::size_t pos
, Widget
&widget
)
72 listbox_
->insertWidget(pos
, widget
);
74 virtual void appendWidget(Widget
&widget
) { listbox_
->appendWidget(widget
); }
76 virtual void setHideOnClose(bool new_hide_on_close
);
77 virtual int getHideOnClose() const { return hide_on_close_
; }
79 /// Assigns a reference widget which is used to calculate on-screen position
80 /// of this MenuWindow. Note that if the reference widget is destroyed then
81 /// the MenuWindow dies too.
82 virtual void setReferenceWidget(Widget
&new_ref
);
84 /// Removes any reference widget assignment.
85 virtual void cleanReferenceWidget();
87 /// Returns the currently set reference widget.
88 virtual Widget
*getReferenceWidget() const { return ref_
; }
90 virtual int getLeftShift() const { return xshift_
; }
91 virtual int getTopShift() const { return yshift_
; }
93 virtual void setLeftShift(int x
);
94 virtual void setTopShift(int y
);
101 int xshift_
, yshift_
;
102 sigc::connection ref_visible_conn_
;
107 virtual void addWidget(Widget
&widget
, int x
, int y
) override
;
109 virtual Button
*prepareSubMenu(const char *title
, MenuWindow
&submenu
);
111 /// Recalculates desired on-screen position and size of this window. This
112 /// handles mainly autosize magic.
113 virtual void updatePositionAndSize();
115 virtual void onChildrenHeightChange(ListBox
&activator
, int new_height
);
117 virtual void onReferenceWidgetVisible(Widget
&activator
, bool visible
);
119 static void *onReferenceWidgetDestroy_(void *win
)
121 reinterpret_cast<MenuWindow
*>(win
)->onReferenceWidgetDestroy();
124 virtual void onReferenceWidgetDestroy();
127 CONSUI_DISABLE_COPY(MenuWindow
);
130 } // namespace CppConsUI
132 #endif // MENUWINDOW_H
134 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: