Listing 1: LBWE class definition
// ListBoxWithExtras.h
#ifndef LISTBOXWITHEXTRAS_H
#define LISTBOXWITHEXTRAS_H
// stop some useless STL verbosity
#pragma warning (disable : 4146 4018)
#include <new.h>
#include <fstream.h>
namespace std {
#include <stack.h>
#include <deque.h>
}
#include "EditBox.h"
#include "LbweRep.h"
//This next structure will hold the list box previous states
//so they can be undone. Since we are going to add these
//objects themselves to an STL container, we MUST define
//a constructor.
enum Action {DELETE_STRING, EDIT_STRING, INSERT_STRING};
struct ListBoxState
{
ListBoxState() {}
int positionLBS;
CString valueLBS;
Action actionLBS;
CWnd* boxInFocus;
};
class ListBoxWithExtras : public CListBox
{
public:
ListBoxWithExtras();
~ListBoxWithExtras();
//Now come extensions to the CListBox control
void EditEntry();
void InsertEntry();
void DeleteEntry();
void AppendEntry();
void Undo(); //Undoes last change
void ResetUndo(); //Clears the Undo Buffer
void SortList(); //Useless for sorted box
//Data transfer available via lbweBuffer
LbweRep lbweBuffer;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(ListBoxWithExtras)
protected:
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam,
LPARAM lParam);
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(ListBoxWithExtras)
afx_msg void OnDblclk();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnParentNotify(UINT message, LPARAM lParam);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
EditBox* pEditBox;
BOOL IsSortedBox();
void CrankUpTheEdit(int position, Action action);
std::stack<std::deque<ListBoxState> > undoStack;
ListBoxState currentState;
BOOL lbweInitialized;
//next private structure is for a "function object"
//for std::sort()
//MFC less than for CStrings isn't understood by STL.
struct CompareCStrings {
operator() (const CString& a, const CString& b)
{return a < b;}
};
};
#endif
// End of File