00001 namespace InPlaceEdit {
00002
00003 enum {
00004 KEditAborted = 0,
00005 KEditTab,
00006 KEditShiftTab,
00007 KEditEnter,
00008 KEditLostFocus,
00009
00010 KEditMaskReason = 0xFF,
00011 KEditFlagContentChanged = 0x100,
00012
00013 KFlagReadOnly = 1 << 0,
00014 KFlagMultiLine = 1 << 1,
00015 };
00016
00017 void Start(HWND p_parentwnd,const RECT & p_rect,bool p_multiline,pfc::rcptr_t<pfc::string_base> p_content,completion_notify_ptr p_notify);
00018
00019 void StartEx(HWND p_parentwnd,const RECT & p_rect,unsigned p_flags,pfc::rcptr_t<pfc::string_base> p_content,completion_notify_ptr p_notify);
00020
00021 void Start_FromListView(HWND p_listview,unsigned p_item,unsigned p_subitem,unsigned p_linecount,pfc::rcptr_t<pfc::string_base> p_content,completion_notify_ptr p_notify);
00022 void Start_FromListViewEx(HWND p_listview,unsigned p_item,unsigned p_subitem,unsigned p_linecount,unsigned p_flags,pfc::rcptr_t<pfc::string_base> p_content,completion_notify_ptr p_notify);
00023
00024 bool TableEditAdvance(unsigned & p_item,unsigned & p_column, unsigned p_item_count,unsigned p_column_count, unsigned p_whathappened);
00025
00026
00027 class CTableEditHelper {
00028 public:
00029 void TableEdit_Start(HWND p_listview,unsigned p_item,unsigned p_column,unsigned p_itemcount,unsigned p_columncount,unsigned p_basecolumn,unsigned p_flags = 0) {
00030 if (m_notify.is_valid()) return;
00031 m_listview = p_listview;
00032 m_item = p_item;
00033 m_column = p_column;
00034 m_itemcount = p_itemcount;
00035 m_columncount = p_columncount;
00036 m_basecolumn = p_basecolumn;
00037 m_flags = p_flags;
00038 __Start();
00039 }
00040
00041 void TableEdit_Abort(bool p_forwardcontent) {
00042 if (m_notify.is_valid()) {
00043 m_notify->orphan();
00044 m_notify.release();
00045
00046 if (p_forwardcontent) {
00047 if (m_content.is_valid()) {
00048 pfc::string8 temp(*m_content);
00049 m_content.release();
00050 TableEdit_SetItemText(m_item,m_column,temp);
00051 }
00052 } else {
00053 m_content.release();
00054 }
00055 SetFocus(NULL);
00056 }
00057 }
00058
00059
00060 bool TableEdit_IsActive() const {
00061 return m_notify.is_valid();
00062 }
00063
00064 virtual bool TableEdit_GetItemText(unsigned p_item,unsigned p_column,pfc::string_base & p_out,unsigned & p_linecount) {
00065 listview_helper::get_item_text(m_listview,p_item,p_column + m_basecolumn,p_out);
00066 p_linecount = pfc::is_multiline(p_out) ? 5 : 1;
00067 return true;
00068 }
00069 virtual void TableEdit_SetItemText(unsigned p_item,unsigned p_column,const char * p_text) {
00070 listview_helper::set_item_text(m_listview,p_item,p_column + m_basecolumn,p_text);
00071 }
00072
00073 void on_task_completion(unsigned p_taskid,unsigned p_state) {
00074 if (p_taskid == KTaskID) {
00075 m_notify.release();
00076 if (m_content.is_valid()) {
00077 if (p_state & InPlaceEdit::KEditFlagContentChanged) {
00078 TableEdit_SetItemText(m_item,m_column,*m_content);
00079 }
00080 m_content.release();
00081 }
00082 if (InPlaceEdit::TableEditAdvance(m_item,m_column,m_itemcount,m_columncount,p_state)) {
00083 __Start();
00084 }
00085 }
00086 }
00087
00088 ~CTableEditHelper() {
00089 if (m_notify.is_valid()) {
00090 m_notify->orphan();
00091 m_notify.release();
00092 }
00093 }
00094 protected:
00095 HWND TableEdit_GetListView() const {return m_listview;}
00096 private:
00097 void __Start() {
00098 listview_helper::select_single_item(m_listview,m_item);
00099 m_content.new_t();
00100 unsigned linecount = 1;
00101 if (!TableEdit_GetItemText(m_item,m_column,*m_content,linecount)) return;
00102 m_notify = completion_notify_create(this,KTaskID);
00103 InPlaceEdit::Start_FromListViewEx(m_listview,m_item,m_column+m_basecolumn,linecount,m_flags,m_content,m_notify);
00104 }
00105 enum {
00106 KTaskID = 0xc0ffee
00107 };
00108 HWND m_listview;
00109 unsigned m_item,m_column;
00110 unsigned m_itemcount,m_columncount,m_basecolumn;
00111 unsigned m_flags;
00112 pfc::rcptr_t<pfc::string8> m_content;
00113 service_ptr_t<completion_notify_orphanable> m_notify;
00114 };
00115
00116 }