00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef selectionwindowH
00022 #define selectionwindowH
00023
00024 #include <algorithm>
00025 #include <vector>
00026
00027 #include <paragui.h>
00028 #include <pgwidget.h>
00029 #include <pgwidgetlist.h>
00030 #include <pgwindow.h>
00031 #include <pgapplication.h>
00032 #include <pglineedit.h>
00033
00034 #include "../libs/loki/Functor.h"
00035
00036 #include "../paradialog.h"
00037 #include "../global.h"
00038 #include "../ascstring.h"
00039
00040
00041 class SelectionWidget : public PG_Widget {
00042 protected:
00043 SelectionWidget ( PG_Widget *parent, const PG_Rect &rect ) : PG_Widget( parent, rect ), selectionCallBack(NULL ) {};
00044
00045 public:
00046 typedef Loki::Functor<bool, TYPELIST_1(const SelectionWidget*) > SelectionCallBack;
00047
00048 private:
00049 SelectionCallBack* selectionCallBack;
00050 public:
00051
00052 void setSelectionCallback ( SelectionCallBack* callBack ) {
00053 selectionCallBack = callBack;
00054 }
00055
00056 virtual ~SelectionWidget() {};
00057
00058 virtual ASCString getName() const = 0;
00059
00060
00061 SigC::Signal1<void,const SelectionWidget*> itemSelected;
00062 SigC::Signal1<void,const SelectionWidget*> itemMarked;
00063
00064 protected:
00065
00066 bool eventMouseButtonUp (const SDL_MouseButtonEvent *button);
00067 bool eventMouseButtonDown (const SDL_MouseButtonEvent *button);
00068 void eventBlit ( SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst );
00069
00070 virtual void display( SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst ) = 0;
00071 };
00072
00073 class ItemSelectorWidget;
00074
00075 class SelectionItemFactory{
00076 public:
00077 virtual void restart() = 0;
00078 virtual SelectionWidget* spawnNextItem( PG_Widget* parent, const PG_Point& pos ) = 0;
00079
00080 virtual void itemSelected( const SelectionWidget* widget, bool mouse ) = 0;
00081 virtual void itemMarked ( const SelectionWidget* widget ) {};
00082 virtual SelectionWidget* getDefaultItem() { return NULL; };
00083 virtual ~SelectionItemFactory() {};
00084 };
00085
00086
00087
00088 class ItemSelectorWidget : public PG_Widget {
00089
00090 bool namesConstrained;
00091
00092 typedef vector<SelectionWidget*> WidgetList;
00093 WidgetList widgets;
00094
00095 int rowCount;
00096 PG_ScrollWidget* scrollWidget;
00097 static const int gapWidth = 5;
00098
00099 PG_LineEdit* nameSearch;
00100 const SelectionWidget* selectedItem;
00101
00102 SelectionItemFactory* factory;
00103 int columnCount;
00104 int visibleRowCount;
00105
00106 SelectionWidget::SelectionCallBack selectionCallBack;
00107
00108 protected:
00109 bool moveSelection( int amount ) ;
00110 bool eventKeyDown(const SDL_KeyboardEvent* key);
00111 void itemSelected( const SelectionWidget* w, bool mouse );
00112 void markItem( const SelectionWidget* w );
00113 bool isItemMarked( const SelectionWidget* w );
00114 bool locateObject( const ASCString& name );
00115 bool nameMatch( const SelectionWidget* selection, const ASCString& name );
00116
00117 public:
00118
00119 ItemSelectorWidget( PG_Widget *parent, const PG_Rect &r , SelectionItemFactory* itemFactory ) ;
00120
00121 SigC::Signal1<void,const SelectionWidget*> sigItemSelected;
00122 SigC::Signal1<void,ASCString> nameEntered;
00123 SigC::Signal0<bool> sigQuitModal;
00124
00125 void constrainNames( bool constrain );
00126 int getItemNum() const { return widgets.size(); };
00127
00128 void reLoad( bool show = false );
00129 void resetNamesearch();
00130 ~ItemSelectorWidget();
00131 };
00132
00133
00134 class ItemSelectorWindow: public ASC_PG_Dialog {
00135 ItemSelectorWidget* itemSelector;
00136 virtual void itemSelected( const SelectionWidget* );
00137 protected:
00138 bool eventKeyDown(const SDL_KeyboardEvent* key);
00139
00140 public:
00141
00142 ItemSelectorWindow( PG_Widget *parent, const PG_Rect &r , const ASCString& title, SelectionItemFactory* itemFactory ) ;
00143
00144 int RunModal();
00145 void reLoad();
00146
00147 };
00148
00149
00150 #endif