HTMLayout滚动条behavior源码示例

来源:互联网 发布:java语言程序设计 下载 编辑:程序博客网 时间:2024/06/07 00:48

1.核心API:get_scroll_info() 和 set_scroll_pos()

       该效果的显示主要是控制内外区域的协调显示问题.多说无益看代码

2.相关代码.h文件

                 

#include "..\behaviors\behavior_aux.h"/***************************************************垂直滚动条自动滚动示例:<div Backandforth style="behavior:UDB_V_Autoscroller;width:100px;height:200px; border:1px solid red;margin:*;overflow:hidden;padding:5px;">       <option style="margin-top:5px;border:1px solid gray;height:20px;">1</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">2</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">3</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">4</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">5</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">6</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">7</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">8</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">9</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">10</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">11</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">12</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">13</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">14</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">15</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">16</option>       <option style="margin-top:5px;border:1px solid gray;height:20px;">17</option></div>属性:Backandforth 这个属性表示上下弹性展示内部元素,如果没有这个属性则一一循环展示内部元素***************************************************/namespace htmlayout {struct UDB_V_Autoscroller: public behavior{UDB_V_Autoscroller(const char* name = "UDB_V_Autoscroller");virtual void attached  (HELEMENT he );virtual void detached  (HELEMENT he );virtual BOOL on_mouse  (HELEMENT he, HELEMENT target, UINT event_type, POINT pt, UINT mouseButtons, UINT keyboardStates );virtual BOOL on_timer  (HELEMENT he );};UDB_V_Autoscroller     UDB_V_Autoscroller_instance;}

3.cpp文件

                 

#include "stdafx.h"#include <time.h>#include "UDB_V_Autoscroller.h"namespace htmlayout {UDB_V_Autoscroller::UDB_V_Autoscroller(const char* name ): behavior(HANDLE_TIMER|HANDLE_MOUSE, name) {}void UDB_V_Autoscroller::attached  (HELEMENT he ) { HTMLayoutSetTimer( he, 30); } void UDB_V_Autoscroller::detached  (HELEMENT he ) { HTMLayoutSetTimer( he, 0 ); } BOOL UDB_V_Autoscroller::on_mouse(HELEMENT he, HELEMENT target, UINT event_type, POINT pt, UINT mouseButtons, UINT keyboardStates ){if( event_type == MOUSE_ENTER )HTMLayoutSetTimer( he, 0 );if( event_type == MOUSE_LEAVE)HTMLayoutSetTimer( he, 30 );return 0;}BOOL UDB_V_Autoscroller::on_timer  (HELEMENT he ) { POINT scroll_pos;//滚动条当前位置RECT  view_rect; //滚动条当前区域SIZE  content_size;//滚动条最大区域dom::element el = he;el.get_scroll_info(scroll_pos, view_rect, content_size);const wchar_t* cw = el.get_attribute("Backandforth");if(NULL != cw){static bool bDown = 0;if(content_size.cy - view_rect.bottom < scroll_pos.y)bDown=0;else if(scroll_pos.y==0)bDown=1;if(!bDown)scroll_pos.y -= 2;elsescroll_pos.y += 2;el.set_scroll_pos(scroll_pos, false);}else{if(scroll_pos.y > content_size.cy)scroll_pos.y = 0 - view_rect.bottom;scroll_pos.y += 2;el.set_scroll_pos(scroll_pos, false);}return 1; }} // htmlayout namespace

剩下的 事情就是自己加进工程自个看咯

原创粉丝点击