65.9K
CodeProject 正在变化。 阅读更多。
Home

选项卡控件和分割器 - 添加一些可停靠和浮动的糖

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.76/5 (36投票s)

2004年1月7日

3分钟阅读

viewsIcon

220736

downloadIcon

8441

另一种实现可停靠、浮动、选项卡和拆分环境的方法。

Tab Controls And Splitters - Adding Some Dockable And Floating Sugar

引言

在上一个文章中,我介绍了SplitPane类,该类管理带有分隔符和选项卡窗格的客户端视图窗口,并提供与所有者类的交互接口。在本文中,我想介绍Frame类,它通过可停靠和浮动功能扩展了SplitPane的功能。另外,我将假设您知道什么是可停靠窗口和浮动窗口。当然,最好的例子是Visual Studio .NET IDE。我想您也知道Sergey Klimov所做的出色工作以及Daniel Bowen的进一步改进。本文只是一个尝试,为特定情况提供一个更简单的接口,采用略有不同的范例。我希望我已经成功了。

它的作用

简而言之:Frame类为客户端视图提供可停靠和浮动环境。这个环境有三个部分:主窗格、停靠窗格和浮动框架。它们都是SplitPane的所有者,因此您可以拆分和选项卡化所有客户端视图。此外,客户端视图被分成两组:可停靠视图和文档视图。区别很简单。可停靠视图不能附加到主窗格,但可以停靠在其中一个停靠侧。文档视图与它们不同,它们可以附加到主窗格,但不能停靠。它们都可以变为浮动状态。这与Visual Studio .NET IDE不同。要阻止浮动窗口停靠在任何位置,请在拖动它时按住CTRL键。

使用代码

使用Frame类可能像使用SplitPane类一样简单。它也为SDI应用程序设计。我不会重复所有步骤,但会提到几点。使用其中提到的所有包含文件,您将希望使用包含Frame类实现的DockTabFrame.h。它也位于DockSplitTab命名空间中。有一个ClientView类,它具有客户端视图窗口的所有必要属性。Frame类提供了与所有者或父类通信的接口。这就是FrameListener抽象类。clientDetached是迄今为止为该接口提供的唯一函数。当用户关闭停靠窗格、浮动框架或选项卡时,Frame类会调用它。换句话说,当他按下关闭按钮时。对于Frame类,有一个detachClientView函数,它执行类似的操作,但不会引发clientDetached事件。在适当的情况下,Frame会将WM_CONTEXTMENU Windows消息发送到客户端视图。例如,当您右键单击选项卡时。

Frame类

公共方法

// creates a new Split Pane window with parentWnd and rect parameters
HWND create( parentWnd, rect);

// sets the keyboard focus to the specified client view window
bool setFocusTo( clientViewWnd) {

// retrieves the client view window that receives the keyboard focus
HWND focusedClientView();

// toggles client view state and move
// the client view to an appropriate pane
bool toggleClientViewState( clientViewWnd, ClientView::State);

// retrieves client view properties with client view window handle
ClientView* getClientView( clientViewWnd);

// adds a new client view
bool addClientView( clientView);

// adds a new client view and attach it to the specified dock pane
bool dockClientView( dockSide, clientView);

// shows/hides the specified dock pane
bool showDockPane( dockSide, show);

// retrieves the visibility state of the specified dock pane
bool dockPaneVisible( dockSide);

// retrieves the existence state of the specified dock pane
bool dockPaneExists( dockSide);

// float frame iterator functions
POSITION floatFrameStart()
HWND floatFrameNext( &position);

// adds a new client view and attach it to a new float frame
// with the specified location
HWND floatClientView( rect, clientView);

// retrieves the visibility state of the specified float frame
bool showFloatFrame( floatFrameWnd, show);

// check if a float frame is visible
bool floatFrameVisible( floatFrameWnd)

// check if a float frame exists
bool checkFloatFrame( floatFrameWnd);

// reattach the client view. the function uses
// the last location object propertes
void attachClientView( clientView);

// detaches the client view window 
// This method changes the parent window of the client
// view window to the Frame's parent.
ClientView* detachClientView( clientViewWnd);

// retrieves the visibility state of the specified client view window handle
bool clientViewVisible( clientViewWnd);

// checks if client view window is attached.
bool clientViewAttached( clientViewWnd);

// set and get Image List
void setImageList( imgList);
HIMAGELIST getImageList();

Frame类内部

Frame类有两个非常重要类的实现。它们是DockPane类和FloatFrame类。它们每个都有自己的SplitPane成员。因此,您可以在每个DockPaneFloatFrame实例中拆分和选项卡化客户端视图。Frame类本身也拥有SplitPane实例。该实例的目的是保存文档视图。Frame类通过FloatDockFrameListener接口类与浮动框架、停靠窗格和主窗格通信,该类扩展了CallBackListener接口。

class DockPane - 包含停靠的客户端视图。
class FloatFrame - 包含浮动的客户端视图。
class FloatDockFrameListener - 浮动框架、停靠窗格及其所有者(Frame类)之间的通信接口。
class SplitPaneWrapper

- 封装了分隔窗格容器的通用数据和方法。

FloatFrame类和DockPane类使用。

class FloatFrameDragContext - 存储拖放上下文。继承自RectTracker类。
class DropParcel - 拖放操作的结果。
class LayoutManager - Frame类的布局实现。

下一步

还有两件事要做:序列化和自动隐藏窗格。

参考文献

© . All rights reserved.