在这个函数里,首先文档对象先把所添加的视图指针加到自己的视图链表里,然后指向自己的指针赋給了所添加的视图的m_pdocument成员。
众所周知,文档与视图进行通信的方式先调用文档的updateallviews函数,从而调用视图的onupdate函数:
void cdocument::updateallviews(cview* psender, lparam lhint, cobject* phint)
// walk through all views
{
//视图链表不能为空且发送者不能为空
assert(psender == null || !m_viewlist.isempty());
position pos = getfirstviewposition();
while (pos != null)
{
cview* pview = getnextview(pos);
assert_valid(pview);
//不调用发送者的onupdate函数
if (pview != psender)
pview->onupdate(psender, lhint, phint);
}
}
在视图的onupdate函数里默认的实现仅是通知视图进行重画:
invalidate(true);
我们一般重载这个更新视图的某些数据或进行其他操作,比如更新视图滚动条的滚动范围。
(四)框架窗口与文档、视图之间的联系