Cross-Platform GUI Programming With WxWidgets

Transcription

Smart FMf.qxd6/10/051:52 PMPage iCross-Platform GUI Programmingwith wxWidgets

Smart FMf.qxd6/10/051:52 PMPage iiBRUCE P ERENS ’ O PEN SOURCE SERIEShttp://www.phptr.com/perensJava Application Development on Linux Carl Albing and Michael SchwarzC GUI Programming with Qt 3Jasmin Blanchette and Mark SummerfieldManaging Linux Systems with Webmin: System Administration and Module DevelopmentJamie CameronThe Linux BookDavid ElbothUnderstanding the Linux Virtual Memory ManagerMel GormanPHP 5 Power ProgrammingAndi Gutmans, Stig Bakken, and Derick RethansLinux Quick Fix NotebookPeter HarrisonLinux Desk Reference, Second EditionScott HawkinsImplementing CIFS: The Common Internet File SystemChristopher HertelOpen Source Security Tools: A Practical Guide to Security ApplicationsTony HowlettApache Jakarta CommonsReusable Java ComponentsWill IversonEmbedded Software Development with eCosAnthony MassaRapid Application Development with MozillaNigel McFarlaneSubversion Version Control: Using the Subversion Version Control System in DevelopmentProjectsWilliam NagelLinux Assembly Language ProgrammingBob NevelnIntrusion Detection with SNORT: Advanced IDS Techniques Using SNORT, Apache, MySQL,PHP, and ACIDRafeeq Ur RehmanCross-Platform GUI Programming with wxWidgetsJulian Smart and Kevin Hock with Stefan CsomorSamba-3 by Example: Practical Exercises to Successful DeploymentJohn H. TerpstraThe Official Samba-3 HOWTO and Reference GuideJohn H. Terpstra and Jelmer R. Vernooij, EditorsReal World Linux Security, Second EditionBob Toxen

Smart FMf.qxd6/10/051:52 PMPage iiiCross-Platform GUI Programmingwith wxWidgetsJulian Smart and Kevin Hockwith Stefan CsomorUpper Saddle River, NJ Boston Indianapolis San FranciscoNew York Toronto Montreal London Munich ParisMadrid Capetown Sydney Tokyo Singapore Mexico City

Smart FMf.qxd6/10/051:52 PMPage ivMany of the designations used by manufacturers and sellers to distinguish their products are claimed astrademarks. Where those designations appear in this book, and the publisher was aware of a trademarkclaim, the designations have been printed with initial capital letters or in all capitals.The authors and publisher have taken care in the preparation of this book, but make no expressed orimplied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumedfor incidental or consequential damages in connection with or arising out of the use of the information orprograms contained herein.The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or specialsales, which may include electronic versions and/or custom covers and content particular to your business,training goals, marketing focus, and branding interests. For more information, please contact:U. S. Corporate and Government Sales(800) 382-3419corpsales@pearsontechgroup.comFor sales outside the U. S., please contact:International Salesinternational@pearsoned.comThis Book Is Safari EnabledThe Safari Enabled icon on the cover of your favorite technology book means the book isavailable through Safari Bookshelf. When you buy this book, you get free access to theonline edition for 45 days. Safari Bookshelf is an electronic reference library that lets youeasily search thousands of technical books, find code samples, download chapters, andaccess technical information when ever and wherever you need it.To gain 45-day Safari Enabled access to this book: Go to http://www.awprofessional.com/safarienabled Complete the brief registration form Enter the coupon code 33G2-XGSI-ZFYZ-D7IV-B9HEIf you have difficulty registering on Safari Bookshelf or accessing the online edition, please e-mail customerservice@safaribooksonline.com.Visit us on the Web: www.phptr.comLibrary of Congress Catalog Number: 2005924108Copyright 2006 Pearson Education, Inc.Printed in the United States of America.This material may be distributed only subject to the terms and conditions set forth in the Open PublicationLicense, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/).ISBN 0-13-147381-6Text printed in the United States on recycled paper at R.R. Donnelley & Sons in Crawfordsville, Indiana.First printing, July 2005

Smart FMf.qxd6/10/051:52 PMPage v

Smart FMf.qxd6/10/051:52 PMPage vi

Smart FMf.qxd6/10/051:52 PMPage viiContentsForeword by Mitch Kapor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiiiPreface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvAcknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxxiiiAbout the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxxv1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1What Is wxWidgets? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1Why Use wxWidgets? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2A Brief History of wxWidgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5The wxWidgets Community . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6wxWidgets and Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . .7License Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7The wxWidgets Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8wxMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8wxGTK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8wxX11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9wxMotif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10wxMac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10wxCocoa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10wxWinCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10wxPalmOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12wxOS2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12wxMGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12Internal Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15A Small wxWidgets Sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15The Application Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16vii

Smart FMf.qxdviii6/10/051:52 PMPage viiiContentsThe Frame Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17The Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18The Frame Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19The Whole Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20Compiling and Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22Program Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .233 Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25Event-Driven Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25Event Tables and Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26Skipping Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29Pluggable Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29Dynamic Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30Window Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31Defining Custom Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .374 Window Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39Anatomy of a Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39The Concept of a Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40Client and Non-Client Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40Scrollbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41Caret and Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41Top-Level Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41Painting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41Color and Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Window Variant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Sizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Idle Time Processing and UI Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Window Creation and Deletion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43Window Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44A Quick Guide to the Window Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44Base Window Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45Top-Level Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45Container Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45Non-Static Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45Static Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46Control Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46Base Window Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46wxWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47wxWindow Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47wxWindow Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49

Smart FMf.qxd6/10/05Contents1:52 PMPage ixixwxWindow Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50wxControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54wxControlWithItems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54wxControlWithItems Member Functions . . . . . . . . . . . . . . . . . . . . . . . . .54Top-Level Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55wxFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55wxFrame Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58wxFrame Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59wxFrame Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60Non-Rectangular Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61Mini-Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63wxMDIParentFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63wxMDIParentFrame Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .64wxMDIParentFrame Member Functions . . . . . . . . . . . . . . . . . . . . . . . . .65wxMDIChildFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65wxMDIChildFrame Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65wxMDIChildFrame Member Functions . . . . . . . . . . . . . . . . . . . . . . . . .66wxDialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66wxDialog Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69wxDialog Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70wxDialog Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71wxPopupWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71Container Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72wxPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72wxPanel Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72wxPanel Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72wxNotebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72Notebook Theme Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74wxNotebook Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74wxNotebook Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75wxNotebook Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75Alternatives to wxNotebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76wxScrolledWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76wxScrolledWindow Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78wxScrolledWindow Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78wxScrolledWindow Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . .79Scrolling Without Using wxScrolledWindow . . . . . . . . . . . . . . . . . . . . .80wxSplitterWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81wxSplitterWindow Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83wxSplitterWindow Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83wxSplitterWindow Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . .84Sizing Issues with wxSplitterWindow . . . . . . . . . . . . . . . . . . . . . . . . . . .84Alternatives to wxSplitterWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .85Non-Static Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86wxButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86

Smart FMf.qxdx6/10/051:52 PMPage xContentswxButton Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86wxButton Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87wxButton Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87wxButton Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87wxBitmapButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89wxBitmapButton Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90wxBitmapButton Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90wxBitmapButton Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .90wxChoice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90wxChoice Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91wxChoice Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91wxChoice Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91wxComboBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91wxComboBox Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92wxComboBox Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93wxComboBox Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93wxCheckBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93wxCheckBox Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94wxCheckBox Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95wxCheckBox Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95wxListBox and wxCheckListBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95wxListBox and wxCheckListBox Styles . . . . . . . . . . . . . . . . . . . . . . . . . .97wxListBox and wxCheckListBox Events . . . . . . . . . . . . . . . . . . . . . . . . .97wxListBox Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98wxCheckListBox Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . .98wxRadioBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98wxRadioBox Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99wxRadioBox Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100wxRadioBox Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100wxRadioButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100wxRadioButton Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101wxRadioButton Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101wxRadioButton Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . .101wxScrollBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101wxScrollBar Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102wxScrollBar Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102wxScrollBar Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103wxSpinButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103wxSpinButton Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104wxSpinButton Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104wxSpinButton Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104wxSpinCtrl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104wxSpinCtrl Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105wxSpinCtrl Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105wxSpinCtrl Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106wxSlider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106

Smart FMf.qxd6/10/05Contents1:52 PMPage xixiwxSlider Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106wxSlider Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107wxSlider Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107wxTextCtrl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107wxTextCtrl Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109wxTextCtrl Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110wxTextCtrl Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110wxToggleButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111wxToggleButton Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112wxToggleButton Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112wxToggleButton Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .112Static Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112wxGauge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112wxGauge Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113wxGauge Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113wxGauge Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113wxStaticText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113wxStaticText Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114wxStaticText Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114wxStaticBitmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114wxStaticBitmap Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115wxStaticBitmap Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .115wxStaticLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115wxStaticLine Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115wxStaticLine Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116wxStaticBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116wxStaticBox Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116wxStaticBox Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116wxMenu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117wxMenu Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .118wxMenu Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120Control Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122wxMenuBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122wxMenuBar Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123wxMenuBar Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123wxMenuBar Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123wxToolBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124Tool Bitmap Colors Under Windows . . . . . . . . . . . . . . . . . . . . . . . . . . .125wxToolBar Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126wxToolBar Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126wxToolBar Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127wxStatusBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128wxStatusBar Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129wxStatusBar Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129wxStatusBar Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .130

Smart FMf.qxdxii6/10/051:52 PMPage xiiContents5 Drawing and Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31Understanding Device Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131Available Device Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132Drawing on Windows with wxClientDC . . . . . . . . . . . . . . . . . . . . . . . . . . .133Erasing Window Backgrounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134Drawing on Windows with wxPaintDC . . . . . . . . . . . . . . . . . . . . . . . . . . .135Drawing on Bitmaps with wxMemoryDC . . . . . . . . . . . . . . . . . . . . . . . . .138Creating Metafiles with wxMetafileDC . . . . . . . . . . . . . . . . . . . . . . . . . . .138Accessing the Screen with wxScreenDC . . . . . . . . . . . . . . . . . . . . . . . . . .139Printing with wxPrinterDC and wxPostScriptDC . . . . . . . . . . . . . . . . . . .139Drawing Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140wxColour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141wxPen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .142wxBrush . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143wxFont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145wxPalette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147Device Context Drawing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148Drawing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .150Drawing Lines and Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152Drawing Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156Drawing Bitmaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157Filling Arbitrary Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159Logical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159Using the Printing Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .161More on wxPrintout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163Scaling for Printing and Previewing . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165Printing under Unix with GTK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1673D Graphics with wxGLCanvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1706 Handling Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171Mouse Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171Handling Button and Motion Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173Handling Mouse Wheel Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174Handling Keyboard Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .175An Example Character Event Handler . . . . . . . . . . . . . . . . . . . . . .

When you buy this book, you get free access to the online edition for 45 days. Safari Bookshelf is an electronic reference library that lets you easily search thousands of technical books, find code samples, download chapters, and access technical information when ever and wherever you need it. To gain 45-day Safari Enabled access to this book: