libyui  3.12.1
YMenuBar.cc
1 /*
2  Copyright (c) [2020] SUSE LLC
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YMenuBar.cc
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YShortcut.h"
31 #include "YMenuBar.h"
32 
33 
34 using std::string;
35 
36 
38 {
40  {}
41 
42  int dummy;
43 };
44 
45 
46 
47 
49  : YMenuWidget( parent,
50  "" ) // label
51  , priv( new YMenuBarPrivate() )
52 {
53  YUI_CHECK_NEW( priv );
54 
55  setStretchable( YD_HORIZ, true );
56  setStretchable( YD_VERT, false );
57 }
58 
59 
61 {
62  // NOP
63 }
64 
65 
66 YMenuItem *
67 YMenuBar::addMenu( const std::string & label,
68  const std::string & iconName )
69 {
70  YMenuItem * menu = new YMenuItem( label, iconName );
71  addItem( menu );
72 
73  return menu;
74 }
75 
76 
77 const YPropertySet &
79 {
80  static YPropertySet propSet;
81 
82  if ( propSet.isEmpty() )
83  {
84  /*
85  * @property itemList Items All menu items and submenus
86  * @property itemList EnabledItems Enabled or disabled status for items
87  * @property string IconPath Base path for icons (on menu items)
88  */
89  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
90  propSet.add( YProperty( YUIProperty_EnabledItems, YOtherProperty ) );
91  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
92  propSet.add( YWidget::propertySet() );
93  }
94 
95  return propSet;
96 }
97 
98 
99 bool
100 YMenuBar::setProperty( const string & propertyName, const YPropertyValue & val )
101 {
102  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
103 
104  if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
105  else if ( propertyName == YUIProperty_EnabledItems ) return false; // Needs special handling
106  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
107  else
108  {
109  return YWidget::setProperty( propertyName, val );
110  }
111 
112  return true; // success -- no special processing necessary
113 }
114 
115 
117 YMenuBar::getProperty( const string & propertyName )
118 {
119  propertySet().check( propertyName ); // throws exceptions if not found
120 
121  if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
122  else if ( propertyName == YUIProperty_EnabledItems ) return YPropertyValue( YOtherProperty );
123  else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() );
124  else
125  {
126  return YWidget::getProperty( propertyName );
127  }
128 }
129 
YMenuBar::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YMenuBar.cc:100
YPropertySet::add
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:146
YWidget
Abstract base class of all UI widgets.
Definition: YWidget.h:55
YMenuBar::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YMenuBar.cc:78
YMenuBar::YMenuBar
YMenuBar(YWidget *parent)
Constructor.
Definition: YMenuBar.cc:48
YMenuBarPrivate
Definition: YMenuBar.cc:38
YPropertySet
A set of properties to check names and types against.
Definition: YProperty.h:198
YMenuBar::~YMenuBar
virtual ~YMenuBar()
Destructor.
Definition: YMenuBar.cc:60
YMenuWidget::addItem
virtual void addItem(YItem *item_disown)
Add one item.
Definition: YMenuWidget.cc:77
YPropertySet::isEmpty
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
YPropertyValue::stringVal
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
YSelectionWidget::label
std::string label() const
Return this widget's label (the caption above the item list).
Definition: YSelectionWidget.cc:99
YPropertyValue::type
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
YSelectionWidget::iconBasePath
std::string iconBasePath() const
Return this widget's base path where to look up icons as set with setIconBasePath().
Definition: YSelectionWidget.cc:156
YMenuWidget
Abstract base class for widgets that handle menus, e.g.
Definition: YMenuWidget.h:39
YWidget::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:457
YProperty
Class for widget properties.
Definition: YProperty.h:52
YWidget::setStretchable
void setStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch" regardless of any hstretch or vstretch options.
Definition: YWidget.cc:560
YSelectionWidget::setIconBasePath
void setIconBasePath(const std::string &basePath)
Set this widget's base path where to look up icons.
Definition: YSelectionWidget.cc:150
YPropertySet::check
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
Definition: YProperty.cc:88
YPropertyValue
Transport class for the value of simple properties.
Definition: YProperty.h:105
YMenuItem
Item class for menu items.
Definition: YMenuItem.h:44
YMenuBar::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YMenuBar.cc:117
YMenuBar::addMenu
YMenuItem * addMenu(const std::string &label, const std::string &iconName="")
Create a new menu and add it.
Definition: YMenuBar.cc:67
YWidget::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:432
YWidget::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:395