libyui  3.12.1
YMenuButton.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
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: YMenuButton.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 "YMenuButton.h"
31 #include "YMenuItem.h"
32 
33 using std::string;
34 
35 
37 {
39  {}
40 
41  int dummy;
42 };
43 
44 
45 
46 
47 YMenuButton::YMenuButton( YWidget * parent, const string & label )
48  : YMenuWidget( parent, label )
49  , priv( new YMenuButtonPrivate() )
50 {
51  YUI_CHECK_NEW( priv );
52 }
53 
54 
56 {
57  // NOP
58 }
59 
60 
61 YMenuItem *
62 YMenuButton::addItem( const std::string & label,
63  const std::string & iconName )
64 {
65  YMenuItem * item = new YMenuItem( label, iconName );
66  YMenuWidget::addItem( item );
67 
68  return item;
69 }
70 
71 
72 YMenuItem *
73 YMenuButton::addMenu( const std::string & label,
74  const std::string & iconName )
75 {
76  YMenuItem * menu = new YMenuItem( label, iconName );
77  YMenuWidget::addItem( menu );
78 
79  return menu;
80 }
81 
82 
83 YMenuItem *
85 {
86  YMenuItem * separator = new YMenuItem( "" );
87  YMenuWidget::addItem( separator );
88 
89  return separator;
90 }
91 
92 
93 const YPropertySet &
95 {
96  static YPropertySet propSet;
97 
98  if ( propSet.isEmpty() )
99  {
100  /*
101  * @property string Label Label on the menu button
102  * @property itemList Items All menu items and submenus
103  * @property string IconPath Base path for icons (on menu items)
104  */
105  propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
106  propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
107  propSet.add( YProperty( YUIProperty_IconPath, YStringProperty ) );
108  propSet.add( YWidget::propertySet() );
109  }
110 
111  return propSet;
112 }
113 
114 
115 bool
116 YMenuButton::setProperty( const string & propertyName, const YPropertyValue & val )
117 {
118  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
119 
120  if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
121  else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
122  else if ( propertyName == YUIProperty_IconPath ) setIconBasePath( val.stringVal() );
123  else
124  {
125  return YWidget::setProperty( propertyName, val );
126  }
127 
128  return true; // success -- no special processing necessary
129 }
130 
131 
133 YMenuButton::getProperty( const string & propertyName )
134 {
135  propertySet().check( propertyName ); // throws exceptions if not found
136 
137  if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
138  else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
139  else if ( propertyName == YUIProperty_IconPath ) return YPropertyValue( iconBasePath() );
140  else
141  {
142  return YWidget::getProperty( propertyName );
143  }
144 }
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
YMenuButton::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YMenuButton.cc:94
YMenuButton::addMenu
YMenuItem * addMenu(const std::string &label, const std::string &iconName="")
Create a new submenu and add it.
Definition: YMenuButton.cc:73
YMenuButton::~YMenuButton
virtual ~YMenuButton()
Destructor.
Definition: YMenuButton.cc:55
YPropertySet
A set of properties to check names and types against.
Definition: YProperty.h:198
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
YMenuButton::addItem
YMenuItem * addItem(const std::string &label, const std::string &iconName="")
Create a new menu item and add it.
Definition: YMenuButton.cc:62
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
YSelectionWidget::setLabel
virtual void setLabel(const std::string &newLabel)
Change this widget's label (the caption above the item list).
Definition: YSelectionWidget.cc:105
YMenuButton::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YMenuButton.cc:116
YSelectionWidget::setIconBasePath
void setIconBasePath(const std::string &basePath)
Set this widget's base path where to look up icons.
Definition: YSelectionWidget.cc:150
YMenuButton::YMenuButton
YMenuButton(YWidget *parent, const std::string &label)
Constructor.
Definition: YMenuButton.cc:47
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
YMenuButton::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YMenuButton.cc:133
YMenuButton::addSeparator
YMenuItem * addSeparator()
Create a new menu separator and add it.
Definition: YMenuButton.cc:84
YMenuButtonPrivate
Definition: YMenuButton.cc:37
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