00001
00002
00003 #include "interface.h"
00004
00005 #ifndef ORG_PROGGEN_DEDUPE_GUI_NCURSES_MARKABLE
00006 #define ORG_PROGGEN_DEDUPE_GUI_NCURSES_MARKABLE
00007
00008 #include <list>
00009 #include <curses.h>
00010
00011 namespace Dedupe
00012 {
00013 namespace GUI
00014 {
00015 class Markable
00016 {
00017 public:
00018 class List
00019 {
00020 std::list< Markable * > Elements;
00021
00022 Markable * Current;
00023 public:
00024 Markable * SetCurrent( Markable & newCurrent );
00025 void ClearCurrent();
00026 inline Markable * GetCurrent() { return Current; }
00027
00028 List() : Current( NULL ) {}
00029
00030 inline void Add( Markable & markable ) { Elements.push_back( &markable ); }
00031 void Remove( Markable & markable );
00032
00033 Markable * GetNext( Markable & markable );
00034 Markable * GetPrev( Markable & markable );
00035
00036 inline unsigned int Size() { return Elements.size(); }
00037 inline Markable * GetFirst() { return ( Elements.size() > 0 ) ? *Elements.begin() : NULL; }
00038 };
00039
00040 protected:
00041 Markable::List & Owner;
00042
00043 Markable( Markable::List & list, bool marked = false );
00044 ~Markable();
00045 virtual void RefreshMark() = 0;
00046
00047 public:
00048
00049 inline bool SetMark( bool mark )
00050 {
00051 if( mark && this != Owner.GetCurrent() )
00052 Owner.SetCurrent( *this );
00053 else
00054 if( !mark && this == Owner.GetCurrent() )
00055 Owner.ClearCurrent();
00056 }
00057
00058 inline bool Marked()
00059 {
00060 return this == Owner.GetCurrent();
00061 }
00062 };
00063
00064 class NCursesDialog
00065 {
00066 protected:
00067 WINDOW * Window;
00068
00069 public:
00070 Markable::List Controls;
00071
00072 inline WINDOW * GetWindow() { return Window; }
00073
00074 void MarkNextControl();
00075 void MarkPrevControl();
00076 };
00077 }
00078 }
00079
00080 #endif
00081