00001
00002
00003
00004 #include <algorithm>
00005
00006 #include "markable.h"
00007
00008 namespace Dedupe
00009 {
00010 namespace GUI
00011 {
00012 void Markable::List::Remove( Markable & markable )
00013 {
00014 std::list< Markable * >::iterator it;
00015
00016 it = std::find( Elements.begin(), Elements.end(), &markable );
00017
00018 if( it != Elements.end() )
00019 {
00020 Elements.erase( it );
00021 }
00022 }
00023
00024 Markable * Markable::List::GetNext( Markable & markable )
00025 {
00026 std::list< Markable * >::iterator it;
00027
00028 it = std::find( Elements.begin(), Elements.end(), &markable );
00029
00030 if( it != Elements.end() )
00031 {
00032 it++;
00033 if( it == Elements.end() )
00034 it = Elements.begin();
00035
00036 return *it;
00037 }
00038
00039 return NULL;
00040 }
00041 Markable * Markable::List::GetPrev( Markable & markable )
00042 {
00043 std::list< Markable * >::reverse_iterator it;
00044
00045 it = std::find( Elements.rbegin(), Elements.rend(), &markable );
00046
00047 if( it != Elements.rend() )
00048 {
00049 it++;
00050 if( it == Elements.rend() )
00051 it = Elements.rbegin();
00052
00053 return *it;
00054 }
00055
00056 return NULL;
00057 }
00058
00059
00060 Markable::Markable( Markable::List & list, bool marked )
00061 : Owner( list )
00062 {
00063 list.Add( *this );
00064
00065 if( marked )
00066 list.SetCurrent( *this );
00067 }
00068
00069 Markable::~Markable()
00070 {
00071 Owner.Remove( *this );
00072 }
00073
00074 void Markable::List::ClearCurrent()
00075 {
00076 Markable * oldCurrent = Current;
00077
00078 Current = NULL;
00079
00080 if( oldCurrent )
00081 oldCurrent->RefreshMark();
00082 }
00083
00084 Markable * Markable::List::SetCurrent( Markable & newCurrent )
00085 {
00086 std::list< Markable * >::iterator it;
00087 it = std::find( Elements.begin(), Elements.end(), &newCurrent );
00088
00089 if( it != Elements.end() )
00090 {
00091 Markable * oldCurrent = Current;
00092
00093 Current = &newCurrent;
00094
00095 if( oldCurrent )
00096 oldCurrent->RefreshMark();
00097
00098 Current->RefreshMark();
00099 }
00100
00101 return Current;
00102 }
00103
00104 void NCursesDialog::MarkNextControl()
00105 {
00106 Markable * current = Controls.GetCurrent();
00107
00108 if( current )
00109 {
00110 Markable * next = Controls.GetNext( *current );
00111
00112 if( next != current )
00113 Controls.SetCurrent( *next );
00114 }
00115 else
00116 if( Controls.Size() > 0 )
00117 Controls.SetCurrent( *Controls.GetFirst() );
00118 }
00119
00120 void NCursesDialog::MarkPrevControl()
00121 {
00122 Markable * current = Controls.GetCurrent();
00123
00124 if( current )
00125 {
00126 Markable * next = Controls.GetPrev( *current );
00127
00128 if( next != current )
00129 Controls.SetCurrent( *next );
00130 }
00131 else
00132 if( Controls.Size() > 0 )
00133 Controls.SetCurrent( *Controls.GetFirst() );
00134 }
00135 }
00136 }
00137