| 148 | } |
| 149 | |
| 150 | void Notebook::RemovePage( IndexType page_number ) { |
| 151 | if( GetPageCount() <= 1 ) { |
| 152 | #if defined( SFGUI_DEBUG ) |
| 153 | std::cerr << "SFGUI warning: Cannot remove the only remaining page of a Notebook.\n"; |
| 154 | #endif |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | if( page_number == GetCurrentPage() ) { |
| 159 | // We need to change the page before removing. |
| 160 | if( page_number == GetPageCount() - 1 ) { |
| 161 | // If the requested page is the last one, flip to previous page. |
| 162 | PreviousPage(); |
| 163 | } |
| 164 | else { |
| 165 | // Else flip to the next page. |
| 166 | NextPage(); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if( ( page_number < 0 ) || ( page_number >= GetPageCount() ) ) { |
| 171 | Remove( m_children.back().child ); |
| 172 | } |
| 173 | else { |
| 174 | Remove( ( m_children.begin() + page_number )->child ); |
| 175 | } |
| 176 | |
| 177 | RecalculateSize(); |
| 178 | |
| 179 | auto old_page = m_current_page; |
| 180 | |
| 181 | // Correct m_current_page if the removed page was before the current page. |
| 182 | // It can't be the current page because we took care of that already. |
| 183 | if( page_number < GetCurrentPage() ) { |
| 184 | m_current_page--; |
| 185 | } |
| 186 | |
| 187 | // The same for the displayed tabs |
| 188 | m_first_tab = std::max( m_first_tab - 1, 0 ); |
| 189 | |
| 190 | if( m_current_page != old_page ) { |
| 191 | GetSignals().Emit( OnTabChange ); |
| 192 | } |
| 193 | |
| 194 | Invalidate(); |
| 195 | } |
| 196 | |
| 197 | Notebook::IndexType Notebook::GetPageOf( Widget::Ptr widget ) const { |
| 198 | ChildrenList::const_iterator iter( std::find( m_children.begin(), m_children.end(), ChildLabelPair( widget, Widget::Ptr() ) ) ); |