Update list of wide characters
[centerim5.git] / cppconsui / MenuWindow.h
blob141a8934de836cfd1c7148f2bf7dac49ee40fca7
1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 //
4 // This file is part of CenterIM.
5 //
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/>.
19 /// @file
20 /// MenuWindow class.
21 ///
22 /// @ingroup cppconsui
24 #ifndef MENUWINDOW_H
25 #define MENUWINDOW_H
27 #include "ListBox.h"
28 #include "Window.h"
30 #define MENU_WINDOW_WISH_WIDTH 40
32 namespace CppConsUI {
34 class MenuWindow : public Window {
35 public:
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;
40 // Widget
41 virtual void onAbsolutePositionChange(Widget &widget) override;
43 // Window
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);
96 protected:
97 ListBox *listbox_;
98 int wish_height_;
100 Widget *ref_;
101 int xshift_, yshift_;
102 sigc::connection ref_visible_conn_;
104 bool hide_on_close_;
106 // Container
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();
122 return nullptr;
124 virtual void onReferenceWidgetDestroy();
126 private:
127 CONSUI_DISABLE_COPY(MenuWindow);
130 } // namespace CppConsUI
132 #endif // MENUWINDOW_H
134 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: