Skip to content

Commit 1953801

Browse files
committed
Added YMenuSeparator management
1 parent ddbc784 commit 1953801

File tree

2 files changed

+89
-62
lines changed

2 files changed

+89
-62
lines changed

src/NCMGAPopupMenu.cc

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,36 @@ NCMGAPopupMenu::NCMGAPopupMenu( const wpos & at, YItemIterator begin, YItemItera
6464
defsze = wsze(1, 1);
6565
for ( YItemIterator it = begin; it != end; ++it )
6666
{
67-
YMGAMenuItem * item = dynamic_cast<YMGAMenuItem *>( *it );
68-
YUI_CHECK_PTR( item );
69-
70-
std::string label = item->hasChildren() ? item->label() + " ..." : item->label();
71-
YMGAMenuItem *menuItem = new YMGAMenuItem ( label, item->iconName() );
72-
menuItem->enable(item->enabled());
73-
menuItem->hide(item->hidden());
74-
75-
d->menu->addItem( menuItem );
76-
d->itemsMap[menuItem] = item;
77-
78-
if (d->maxlen < label.length()+1)
79-
d->maxlen = label.length()+1;
80-
// let's assume to have a menu enable scrolling for more than 10 lines
81-
int h = defsze.H > 9 ? 10 : defsze.H + 1;
82-
// let's assume to have a menu enable scrolling for more than 40 columns
83-
int w = d->maxlen > 40 ? 40 : d->maxlen;
84-
85-
defsze = wsze( h, w );
86-
yuiDebug() << "Add Item: " << item->label() << " len: "<< label.length() << " HxW "<< h << "x" << w << std::endl;
67+
YMenuSeparator *separator = dynamic_cast<YMenuSeparator *>( *it );
68+
if (separator)
69+
{
70+
YMenuSeparator * sep = new YMenuSeparator(NULL);
71+
d->menu->addItem( sep );
72+
defsze.H = defsze.H > 9 ? 10 : defsze.H + 1;
73+
}
74+
else
75+
{
76+
YMGAMenuItem * item = dynamic_cast<YMGAMenuItem *>( *it );
77+
YUI_CHECK_PTR( item );
78+
79+
std::string label = item->hasChildren() ? item->label() + " ..." : item->label();
80+
YMGAMenuItem *menuItem = new YMGAMenuItem ( label, item->iconName() );
81+
menuItem->enable(item->enabled());
82+
menuItem->hide(item->hidden());
83+
84+
d->menu->addItem( menuItem );
85+
d->itemsMap[menuItem] = item;
86+
87+
if (d->maxlen < label.length()+1)
88+
d->maxlen = label.length()+1;
89+
// let's assume to have a menu enable scrolling for more than 10 lines
90+
int h = defsze.H > 9 ? 10 : defsze.H + 1;
91+
// let's assume to have a menu enable scrolling for more than 40 columns
92+
int w = d->maxlen > 40 ? 40 : d->maxlen;
93+
94+
defsze = wsze( h, w );
95+
yuiDebug() << "Add Item: " << item->label() << " len: "<< label.length() << " HxW "<< h << "x" << w << std::endl;
96+
}
8797
}
8898
yuiDebug() << "defsze: " << defsze << "line length: " << d->maxlen << std::endl;
8999

src/NCMenu.cc

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,44 @@ class NCMenuLine : public NCTableLine
5656
, fchild( 0 )
5757
, prefix( 0 )
5858
{
59-
YMGAMenuItem *mi = dynamic_cast<YMGAMenuItem*> (yitem);
60-
if ( mi->hidden())
61-
{
62-
yuiDebug() << mi->label() << " hidden" << std::endl;
63-
SetState(S_HIDDEN);
64-
}
65-
else if ( !mi->enabled() )
66-
{
67-
yuiDebug() << mi->label() << " disabled" << std::endl;
68-
SetState( S_DISABELED );
6959

70-
}
71-
72-
// leaving next even if managed into MGAPopupMenu
73-
if ( yitem->hasChildren() )
74-
{
60+
YMenuSeparator *separator = dynamic_cast<YMenuSeparator *>(yitem);
61+
if (separator)
62+
{
63+
//Append( new NCTableCol( "", NCTableCol::SEPARATOR ) );
64+
SetState( S_DISABELED );
65+
}
66+
else
67+
{
68+
YMGAMenuItem *mi = dynamic_cast<YMGAMenuItem*> (yitem);
69+
YUI_CHECK_PTR(mi);
70+
71+
if ( mi->hidden())
72+
{
73+
yuiDebug() << mi->label() << " hidden" << std::endl;
74+
SetState(S_HIDDEN);
75+
}
76+
else if ( !mi->enabled() )
77+
{
78+
yuiDebug() << mi->label() << " disabled" << std::endl;
79+
SetState( S_DISABELED );
80+
}
81+
else
82+
{
7583
SetState(S_HEADLINE);
76-
yuiDebug() << mi->label() << " has submenu" << std::endl;
77-
Append( new NCTableCol( NCstring( yitem->label() + " ..." ) ) );
78-
}
79-
else
80-
{
81-
SetState(S_HEADLINE);
82-
Append( new NCTableCol( NCstring( yitem->label() ) ) );
83-
}
84-
stripHotkeys();
84+
}
85+
86+
// leaving next even if managed into MGAPopupMenu
87+
if ( yitem->hasChildren() )
88+
{ yuiDebug() << mi->label() << " has submenu" << std::endl;
89+
Append( new NCTableCol( NCstring( yitem->label() + " ..." ) ) );
90+
}
91+
else
92+
{
93+
Append( new NCTableCol( NCstring( yitem->label() ) ) );
94+
}
95+
stripHotkeys();
96+
}
8597
}
8698

8799
virtual ~NCMenuLine() {
@@ -100,28 +112,33 @@ class NCMenuLine : public NCTableLine
100112
NCTableStyle & tableStyle,
101113
bool active ) const
102114
{
103-
NClabel l(NCstring(yitem->label()));
104-
l.stripHotkey();
105-
yuiDebug() << yitem->label() << " hotcol: "<< l.hotpos() << " hotkey: " << l.hotkey() << std::endl;
106-
107-
if ( !isSpecial() )
108-
w.bkgdset( tableStyle.hotBG( vstate, NCTableCol::PLAIN ) );
115+
YMenuSeparator *separator = dynamic_cast<YMenuSeparator *>(yitem);
116+
if (separator)
117+
{
118+
w.move( at.Pos.L, at.Pos.C );
119+
w.hline(ACS_HLINE, 0);
120+
}
121+
else
122+
{
123+
NClabel l(NCstring(yitem->label()));
124+
l.stripHotkey();
125+
yuiDebug() << yitem->label() << " hotcol: "<< l.hotpos() << " hotkey: " << l.hotkey() << std::endl;
109126

110-
//tableStyle.highlightBG( vstate, NCTableCol::HINT);
127+
if ( !isSpecial() )
128+
w.bkgdset( tableStyle.hotBG( vstate, NCTableCol::PLAIN ) );
111129

112-
yuiDebug() << "tableStyle hotcol: " << tableStyle.listStyle().title << " bg: " << tableStyle.hotBG(vstate, tableStyle.HotCol()) << std::endl;
130+
yuiDebug() << "tableStyle hotcol: " << tableStyle.listStyle().title << " bg: " << tableStyle.hotBG(vstate, tableStyle.HotCol()) << std::endl;
113131

114132

115-
NCTableLine::DrawAt( w, at, tableStyle, active );
116-
// NOTE I couldn't be able to fix hot char representation, so i had to force it
117-
if (l.hasHotkey())
118-
{
119-
w.move(at.Pos.L, l.hotpos());
120-
w.addch(l.hotkey() | A_UNDERLINE);
133+
NCTableLine::DrawAt( w, at, tableStyle, active );
134+
// NOTE I couldn't be able to fix hot char representation, so i had to force it
135+
if (l.hasHotkey())
136+
{
137+
w.move(at.Pos.L, l.hotpos());
138+
w.addch(l.hotkey() | A_UNDERLINE);
139+
}
140+
//w.move( at.Pos.L, at.Pos.C );
121141
}
122-
123-
w.move( at.Pos.L, at.Pos.C );
124-
125142
}
126143
};
127144

@@ -210,7 +227,7 @@ YMenuItem * NCMenu::getCurrentItem() const
210227
{
211228
const NCMenuLine * cline = dynamic_cast<const NCMenuLine *>( myPad()->GetCurrentLine() );
212229

213-
if ( cline )
230+
if ( cline && cline->isEnabeled())
214231
yitem = cline->YItem();
215232
}
216233

0 commit comments

Comments
 (0)