(转)ListBox详解一

转自:http://www.newlc.com/article.php3?id_article=136

 

1.1. The ListBox MVC Paradigm

The Symbian ListBox control is, like many other Symbian controls, an implementation of the Model-View-Controller paradigm:
-  the MListBoxModel class represents the model (the data). It is an abstract class that only specifies an interface to access concrete model implementation.
-  the CListBoxView and CListItemDrawer classes represents the view (all the things the user can see).
-  the CEikListBox is the controller which connects the model and the view.

lb.png

1.2 The Model

lbmodel.pngThe MListBoxModel provides the bare bones of what a list box requires, it contains only two methods:
- NumberOfItems() which returns the number of items in the model
- MatchableTextArray() shall return an array of strings which is used by the list box for matching user keypresses incrementally.

//<eiklbm.h>
class MListBoxModel
{
public:
  IMPORT_C virtual ~MListBoxModel();
  virtual TInt NumberOfItems() const = 0;
  virtual const MDesCArray* MatchableTextArray() const = 0;
};

MListBoxModel is a completely generic class. A more specialised class is MTextListBoxModel. This interface, that inherits from MListBoxModel, represents a text based list model. It adds an abstract method, ItemText that returns the item content as a string:

//<eiklbm.h>
class MTextListBoxModel : public MListBoxModel
{
public:
  IMPORT_C ~MTextListBoxModel();
  virtual TPtrC ItemText(TInt aItemIndex) const = 0;
};

Symbian provides a default MTextListBoxModel implementation: CTextListBoxModel.

1.3 The View

The Listbox View takes care of the appearance of listbox items, maintaining and displaying a list of currently visible items. To display items, View uses concrete implementation of the Item Drawer and concrete implementation of the Model. Its members are, among others, a pointer to MListBoxModel-derived data source and a pointer to CListItemDrawer-derived drawer.

View also implements concepts like item selection and current item.

Unlike Model and Item Drawer, base CListBoxView class is directly used in text-based listboxes, without having to derive and implement text-specific variant. However, UIKON also offers a few specific CListBoxView implementations.

lbview.png

posted @ 2010-04-20 18:12  秋天的风  阅读(450)  评论(0)    收藏  举报