标签:style blog ar io color os sp for on
1 //Scrolling2.cpp 2 3 /* 4 Copyright 2000-2004 The VCF Project. 5 Please see License.txt in the top level directory 6 where you installed the VCF. 7 */ 8 9 10 #include "vcf/ApplicationKit/ApplicationKit.h" 11 #include "vcf/ApplicationKit/ControlsKit.h" 12 #include "vcf/ApplicationKit/EtchedBorder.h" 13 14 #include "vcf/ApplicationKit/ListItem.h" 15 16 using namespace VCF; 17 18 19 20 21 22 class Scrolling2Window : public Window { 23 public: 24 Scrolling2Window() { 25 setCaption( "Scrolling 2" ); 26 27 //lets create a menu 28 29 //create the menu bar - this will hold the menu items 30 MenuBar* menuBar = new MenuBar(); 31 32 //set the window‘s menu bar 33 setMenuBar( menuBar ); 34 35 //add the menu to this window‘s components 36 addComponent( menuBar ); 37 38 /** 39 create menu items, first arguemtn is the menu item name, 40 then the parent, 41 then the owning menu bar 42 */ 43 44 //add our event handler to the menu item 45 46 // Scrollbar menu 47 MenuItem* scrollMenu = new DefaultMenuItem( "FrameScrollbars", menuBar->getRootMenuItem(), menuBar ); 48 hasHorzScrollbarMenu_ = new DefaultMenuItem( "Horizontal", scrollMenu, menuBar ); 49 hasVertScrollbarMenu_ = new DefaultMenuItem( "Vertical", scrollMenu, menuBar ); 50 MenuItem* separator = new DefaultMenuItem( "", scrollMenu, menuBar ); 51 separator->setSeparator(true); 52 separator->setEnabled( true ); 53 keepHorzScrollbarVisibleMenu_ = new DefaultMenuItem( "Keep horizontal visible", scrollMenu, menuBar ); 54 keepVertScrollbarVisibleMenu_ = new DefaultMenuItem( "Keep vertical visible", scrollMenu, menuBar ); 55 56 //add our event handler to the scrollbar menu 57 hasHorzScrollbarMenu_->MenuItemClicked += 58 new ClassProcedure1<MenuItemEvent*,Scrolling2Window>( this, &Scrolling2Window::hasHorzScrollbar, "Scrolling2Window::hasHorzScrollbar" ); 59 hasVertScrollbarMenu_->MenuItemClicked += 60 new ClassProcedure1<MenuItemEvent*,Scrolling2Window>( this, &Scrolling2Window::hasVertScrollbar, "Scrolling2Window::hasVertScrollbar" ); 61 keepHorzScrollbarVisibleMenu_->MenuItemClicked += 62 new ClassProcedure1<MenuItemEvent*,Scrolling2Window>( this, &Scrolling2Window::keepHorzScrollbarVisible, "Scrolling2Window::keepHorzScrollbarVisible" ); 63 keepVertScrollbarVisibleMenu_->MenuItemClicked += 64 new ClassProcedure1<MenuItemEvent*,Scrolling2Window>( this, &Scrolling2Window::keepVertScrollbarVisible, "Scrolling2Window::keepVertScrollbarVisible" ); 65 66 67 ListBoxControl* listBox = new ListBoxControl(); 68 listBox->setBorder( new Basic3DBorder( true ) ); 69 listBox->setAllowsMultiSelect( false ); 70 //add scrollbar to listBox 71 scrollBarMgr_ = new ScrollbarManager(this); 72 73 scrollBarMgr_->setHasVerticalScrollbar( true ); 74 scrollBarMgr_->setHasHorizontalScrollbar( true ); 75 scrollBarMgr_->setTarget( listBox ); 76 scrollBarMgr_->setKeepScrollbarsVisible( true, true ); 77 78 this->add( listBox, AlignClient ); 79 80 //add some items to listBox 81 ListModel* listBoxModel = listBox->getListModel(); 82 for(int j=0; j<20; j++){ 83 String indx = StringUtils::toString(j); 84 String capt = L"Very Ultra Hyper Extra Long ListItem " + indx; 85 listBoxModel->add( capt ); 86 } 87 88 updateMenuHasHorzScrollbar(); 89 updateMenuHasVertScrollbar(); 90 updateMenuKeepHorzScrollbarVisible(); 91 updateMenuKeepVertScrollbarVisible(); 92 } 93 94 95 96 void hasHorzScrollbar( MenuItemEvent* e ) { 97 scrollBarMgr_->setHasHorizontalScrollbar( !scrollBarMgr_->hasHorizontalScrollBar() ); 98 updateMenuHasHorzScrollbar(); 99 repaint(); 100 } 101 102 void hasVertScrollbar( MenuItemEvent* e ) { 103 scrollBarMgr_->setHasVerticalScrollbar( !scrollBarMgr_->hasVerticalScrollBar() ); 104 updateMenuHasVertScrollbar(); 105 repaint(); 106 } 107 108 void keepHorzScrollbarVisible( MenuItemEvent* e ) { 109 scrollBarMgr_->setKeepScrollbarsVisible( !scrollBarMgr_->getKeepHorzScrollbarVisible(), scrollBarMgr_->getKeepVertScrollbarVisible() ); 110 updateMenuKeepHorzScrollbarVisible(); 111 repaint(); 112 } 113 114 void keepVertScrollbarVisible( MenuItemEvent* e ) { 115 scrollBarMgr_->setKeepScrollbarsVisible( scrollBarMgr_->getKeepHorzScrollbarVisible(), !scrollBarMgr_->getKeepVertScrollbarVisible() ); 116 updateMenuKeepVertScrollbarVisible(); 117 repaint(); 118 } 119 120 void updateMenuHasHorzScrollbar() { 121 bool has = scrollBarMgr_->hasHorizontalScrollBar(); 122 hasHorzScrollbarMenu_->setChecked( has ); 123 keepHorzScrollbarVisibleMenu_->setEnabled( has ); 124 } 125 126 void updateMenuHasVertScrollbar() { 127 bool has = scrollBarMgr_->hasVerticalScrollBar(); 128 hasVertScrollbarMenu_->setChecked( has ); 129 keepVertScrollbarVisibleMenu_->setEnabled( has ); 130 } 131 132 void updateMenuKeepHorzScrollbarVisible() { 133 bool visible = scrollBarMgr_->getKeepHorzScrollbarVisible(); 134 keepHorzScrollbarVisibleMenu_->setChecked( visible ); 135 } 136 137 void updateMenuKeepVertScrollbarVisible() { 138 bool visible = scrollBarMgr_->getKeepVertScrollbarVisible(); 139 keepVertScrollbarVisibleMenu_->setChecked( visible ); 140 } 141 142 public: 143 ScrollbarManager* scrollBarMgr_; 144 145 MenuItem* hasHorzScrollbarMenu_; 146 MenuItem* hasVertScrollbarMenu_; 147 MenuItem* keepHorzScrollbarVisibleMenu_; 148 MenuItem* keepVertScrollbarVisibleMenu_; 149 150 151 }; 152 153 154 155 156 class Scrolling2Application : public Application { 157 public: 158 159 Scrolling2Application( int argc, char** argv ) : Application(argc, argv) { 160 161 } 162 163 virtual bool initRunningApplication(){ 164 bool result = Application::initRunningApplication(); 165 166 Window* mainWindow = new Scrolling2Window(); 167 setMainWindow(mainWindow); 168 mainWindow->setBounds( &Rect( 100.0, 100.0, 500.0, 500.0 ) ); 169 mainWindow->show(); 170 171 return result; 172 } 173 174 }; 175 176 177 int main(int argc, char *argv[]) 178 { 179 Application* app = new Scrolling2Application( argc, argv ); 180 181 182 Application::main(); 183 184 return 0; 185 } 186 187 188 /** 189 $Id: Scrolling2.cpp 3625 2008-06-22 02:47:47Z ddiego $ 190 */
标签:style blog ar io color os sp for on
原文地址:http://www.cnblogs.com/elitiwin/p/4171783.html