event.h 163 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/event.h
  3. // Purpose: Event classes
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_EVENT_H_
  11. #define _WX_EVENT_H_
  12. #include "wx/defs.h"
  13. #include "wx/cpp.h"
  14. #include "wx/object.h"
  15. #include "wx/clntdata.h"
  16. #if wxUSE_GUI
  17. #include "wx/gdicmn.h"
  18. #include "wx/cursor.h"
  19. #include "wx/mousestate.h"
  20. #endif
  21. #include "wx/dynarray.h"
  22. #include "wx/thread.h"
  23. #include "wx/tracker.h"
  24. #include "wx/typeinfo.h"
  25. #include "wx/any.h"
  26. #ifdef wxHAS_EVENT_BIND
  27. #include "wx/meta/convertible.h"
  28. #endif
  29. // Currently VC6 and VC7 are known to not be able to compile CallAfter() code,
  30. // so disable it for them.
  31. #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(8)
  32. #include "wx/meta/removeref.h"
  33. #define wxHAS_CALL_AFTER
  34. #endif
  35. // ----------------------------------------------------------------------------
  36. // forward declarations
  37. // ----------------------------------------------------------------------------
  38. class WXDLLIMPEXP_FWD_BASE wxList;
  39. class WXDLLIMPEXP_FWD_BASE wxEvent;
  40. class WXDLLIMPEXP_FWD_BASE wxEventFilter;
  41. #if wxUSE_GUI
  42. class WXDLLIMPEXP_FWD_CORE wxDC;
  43. class WXDLLIMPEXP_FWD_CORE wxMenu;
  44. class WXDLLIMPEXP_FWD_CORE wxWindow;
  45. class WXDLLIMPEXP_FWD_CORE wxWindowBase;
  46. #endif // wxUSE_GUI
  47. // We operate with pointer to members of wxEvtHandler (such functions are used
  48. // as event handlers in the event tables or as arguments to Connect()) but by
  49. // default MSVC uses a restricted (but more efficient) representation of
  50. // pointers to members which can't deal with multiple base classes. To avoid
  51. // mysterious (as the compiler is not good enough to detect this and give a
  52. // sensible error message) errors in the user code as soon as it defines
  53. // classes inheriting from both wxEvtHandler (possibly indirectly, e.g. via
  54. // wxWindow) and something else (including our own wxTrackable but not limited
  55. // to it), we use the special MSVC keyword telling the compiler to use a more
  56. // general pointer to member representation for the classes inheriting from
  57. // wxEvtHandler.
  58. #ifdef __VISUALC__
  59. #define wxMSVC_FWD_MULTIPLE_BASES __multiple_inheritance
  60. #else
  61. #define wxMSVC_FWD_MULTIPLE_BASES
  62. #endif
  63. class WXDLLIMPEXP_FWD_BASE wxMSVC_FWD_MULTIPLE_BASES wxEvtHandler;
  64. class wxEventConnectionRef;
  65. // ----------------------------------------------------------------------------
  66. // Event types
  67. // ----------------------------------------------------------------------------
  68. typedef int wxEventType;
  69. #define wxEVT_ANY ((wxEventType)-1)
  70. // this is used to make the event table entry type safe, so that for an event
  71. // handler only a function with proper parameter list can be given. See also
  72. // the wxEVENT_HANDLER_CAST-macro.
  73. #define wxStaticCastEvent(type, val) static_cast<type>(val)
  74. #define wxDECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
  75. wxEventTableEntry(type, winid, idLast, wxNewEventTableFunctor(type, fn), obj)
  76. #define wxDECLARE_EVENT_TABLE_TERMINATOR() \
  77. wxEventTableEntry(wxEVT_NULL, 0, 0, 0, 0)
  78. // generate a new unique event type
  79. extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
  80. // define macros to create new event types:
  81. #ifdef wxHAS_EVENT_BIND
  82. // events are represented by an instance of wxEventTypeTag and the
  83. // corresponding type must be specified for type-safety checks
  84. // define a new custom event type, can be used alone or after event
  85. // declaration in the header using one of the macros below
  86. #define wxDEFINE_EVENT( name, type ) \
  87. const wxEventTypeTag< type > name( wxNewEventType() )
  88. // the general version allowing exporting the event type from DLL, used by
  89. // wxWidgets itself
  90. #define wxDECLARE_EXPORTED_EVENT( expdecl, name, type ) \
  91. extern const expdecl wxEventTypeTag< type > name
  92. // this is the version which will normally be used in the user code
  93. #define wxDECLARE_EVENT( name, type ) \
  94. wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
  95. // these macros are only used internally for backwards compatibility and
  96. // allow to define an alias for an existing event type (this is used by
  97. // wxEVT_SPIN_XXX)
  98. #define wxDEFINE_EVENT_ALIAS( name, type, value ) \
  99. const wxEventTypeTag< type > name( value )
  100. #define wxDECLARE_EXPORTED_EVENT_ALIAS( expdecl, name, type ) \
  101. extern const expdecl wxEventTypeTag< type > name
  102. #else // !wxHAS_EVENT_BIND
  103. // the macros are the same ones as above but defined differently as we only
  104. // use the integer event type values to identify events in this case
  105. #define wxDEFINE_EVENT( name, type ) \
  106. const wxEventType name( wxNewEventType() )
  107. #define wxDECLARE_EXPORTED_EVENT( expdecl, name, type ) \
  108. extern const expdecl wxEventType name
  109. #define wxDECLARE_EVENT( name, type ) \
  110. wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
  111. #define wxDEFINE_EVENT_ALIAS( name, type, value ) \
  112. const wxEventType name = value
  113. #define wxDECLARE_EXPORTED_EVENT_ALIAS( expdecl, name, type ) \
  114. extern const expdecl wxEventType name
  115. #endif // wxHAS_EVENT_BIND/!wxHAS_EVENT_BIND
  116. // Try to cast the given event handler to the correct handler type:
  117. #define wxEVENT_HANDLER_CAST( functype, func ) \
  118. ( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
  119. #ifdef wxHAS_EVENT_BIND
  120. // The tag is a type associated to the event type (which is an integer itself,
  121. // in spite of its name) value. It exists in order to be used as a template
  122. // parameter and provide a mapping between the event type values and their
  123. // corresponding wxEvent-derived classes.
  124. template <typename T>
  125. class wxEventTypeTag
  126. {
  127. public:
  128. // The class of wxEvent-derived class carried by the events of this type.
  129. typedef T EventClass;
  130. wxEventTypeTag(wxEventType type) { m_type = type; }
  131. // Return a wxEventType reference for the initialization of the static
  132. // event tables. See wxEventTableEntry::m_eventType for a more thorough
  133. // explanation.
  134. operator const wxEventType&() const { return m_type; }
  135. private:
  136. wxEventType m_type;
  137. };
  138. #endif // wxHAS_EVENT_BIND
  139. // These are needed for the functor definitions
  140. typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
  141. // We had some trouble (specifically with eVC for ARM WinCE build) with using
  142. // wxEventFunction in the past so we had introduced wxObjectEventFunction which
  143. // used to be a typedef for a member of wxObject and not wxEvtHandler to work
  144. // around this but as eVC is not really supported any longer we now only keep
  145. // this for backwards compatibility and, despite its name, this is a typedef
  146. // for wxEvtHandler member now -- but if we have the same problem with another
  147. // compiler we can restore its old definition for it.
  148. typedef wxEventFunction wxObjectEventFunction;
  149. // The event functor which is stored in the static and dynamic event tables:
  150. class WXDLLIMPEXP_BASE wxEventFunctor
  151. {
  152. public:
  153. virtual ~wxEventFunctor();
  154. // Invoke the actual event handler:
  155. virtual void operator()(wxEvtHandler *, wxEvent&) = 0;
  156. // this function tests whether this functor is matched, for the purpose of
  157. // finding it in an event table in Unbind(), by the given functor:
  158. virtual bool IsMatching(const wxEventFunctor& functor) const = 0;
  159. // If the functor holds an wxEvtHandler, then get access to it and track
  160. // its lifetime with wxEventConnectionRef:
  161. virtual wxEvtHandler *GetEvtHandler() const
  162. { return NULL; }
  163. // This is only used to maintain backward compatibility in
  164. // wxAppConsoleBase::CallEventHandler and ensures that an overwritten
  165. // wxAppConsoleBase::HandleEvent is still called for functors which hold an
  166. // wxEventFunction:
  167. virtual wxEventFunction GetEvtMethod() const
  168. { return NULL; }
  169. private:
  170. WX_DECLARE_ABSTRACT_TYPEINFO(wxEventFunctor)
  171. };
  172. // A plain method functor for the untyped legacy event types:
  173. class WXDLLIMPEXP_BASE wxObjectEventFunctor : public wxEventFunctor
  174. {
  175. public:
  176. wxObjectEventFunctor(wxObjectEventFunction method, wxEvtHandler *handler)
  177. : m_handler( handler ), m_method( method )
  178. { }
  179. virtual void operator()(wxEvtHandler *handler, wxEvent& event);
  180. virtual bool IsMatching(const wxEventFunctor& functor) const
  181. {
  182. if ( wxTypeId(functor) == wxTypeId(*this) )
  183. {
  184. const wxObjectEventFunctor &other =
  185. static_cast< const wxObjectEventFunctor & >( functor );
  186. // FIXME-VC6: amazing but true: replacing "m_method == 0" here
  187. // with "!m_method" makes VC6 crash with an ICE in DLL build (only!)
  188. // Also notice that using "NULL" instead of "0" results in warnings
  189. // about "using NULL in arithmetics" from arm-linux-androideabi-g++
  190. // 4.4.3 used for wxAndroid build.
  191. return ( m_method == other.m_method || other.m_method == 0 ) &&
  192. ( m_handler == other.m_handler || other.m_handler == NULL );
  193. }
  194. else
  195. return false;
  196. }
  197. virtual wxEvtHandler *GetEvtHandler() const
  198. { return m_handler; }
  199. virtual wxEventFunction GetEvtMethod() const
  200. { return m_method; }
  201. private:
  202. wxEvtHandler *m_handler;
  203. wxEventFunction m_method;
  204. // Provide a dummy default ctor for type info purposes
  205. wxObjectEventFunctor() { }
  206. WX_DECLARE_TYPEINFO_INLINE(wxObjectEventFunctor)
  207. };
  208. // Create a functor for the legacy events: used by Connect()
  209. inline wxObjectEventFunctor *
  210. wxNewEventFunctor(const wxEventType& WXUNUSED(evtType),
  211. wxObjectEventFunction method,
  212. wxEvtHandler *handler)
  213. {
  214. return new wxObjectEventFunctor(method, handler);
  215. }
  216. // This version is used by wxDECLARE_EVENT_TABLE_ENTRY()
  217. inline wxObjectEventFunctor *
  218. wxNewEventTableFunctor(const wxEventType& WXUNUSED(evtType),
  219. wxObjectEventFunction method)
  220. {
  221. return new wxObjectEventFunctor(method, NULL);
  222. }
  223. inline wxObjectEventFunctor
  224. wxMakeEventFunctor(const wxEventType& WXUNUSED(evtType),
  225. wxObjectEventFunction method,
  226. wxEvtHandler *handler)
  227. {
  228. return wxObjectEventFunctor(method, handler);
  229. }
  230. #ifdef wxHAS_EVENT_BIND
  231. namespace wxPrivate
  232. {
  233. // helper template defining nested "type" typedef as the event class
  234. // corresponding to the given event type
  235. template <typename T> struct EventClassOf;
  236. // the typed events provide the information about the class of the events they
  237. // carry themselves:
  238. template <typename T>
  239. struct EventClassOf< wxEventTypeTag<T> >
  240. {
  241. typedef typename wxEventTypeTag<T>::EventClass type;
  242. };
  243. // for the old untyped events we don't have information about the exact event
  244. // class carried by them
  245. template <>
  246. struct EventClassOf<wxEventType>
  247. {
  248. typedef wxEvent type;
  249. };
  250. // helper class defining operations different for method functors using an
  251. // object of wxEvtHandler-derived class as handler and the others
  252. template <typename T, typename A, bool> struct HandlerImpl;
  253. // specialization for handlers deriving from wxEvtHandler
  254. template <typename T, typename A>
  255. struct HandlerImpl<T, A, true>
  256. {
  257. static bool IsEvtHandler()
  258. { return true; }
  259. static T *ConvertFromEvtHandler(wxEvtHandler *p)
  260. { return static_cast<T *>(p); }
  261. static wxEvtHandler *ConvertToEvtHandler(T *p)
  262. { return p; }
  263. static wxEventFunction ConvertToEvtMethod(void (T::*f)(A&))
  264. { return static_cast<wxEventFunction>(
  265. reinterpret_cast<void (T::*)(wxEvent&)>(f)); }
  266. };
  267. // specialization for handlers not deriving from wxEvtHandler
  268. template <typename T, typename A>
  269. struct HandlerImpl<T, A, false>
  270. {
  271. static bool IsEvtHandler()
  272. { return false; }
  273. static T *ConvertFromEvtHandler(wxEvtHandler *)
  274. { return NULL; }
  275. static wxEvtHandler *ConvertToEvtHandler(T *)
  276. { return NULL; }
  277. static wxEventFunction ConvertToEvtMethod(void (T::*)(A&))
  278. { return NULL; }
  279. };
  280. } // namespace wxPrivate
  281. // functor forwarding the event to a method of the given object
  282. //
  283. // notice that the object class may be different from the class in which the
  284. // method is defined but it must be convertible to this class
  285. //
  286. // also, the type of the handler parameter doesn't need to be exactly the same
  287. // as EventTag::EventClass but it must be its base class -- this is explicitly
  288. // allowed to handle different events in the same handler taking wxEvent&, for
  289. // example
  290. template
  291. <typename EventTag, typename Class, typename EventArg, typename EventHandler>
  292. class wxEventFunctorMethod
  293. : public wxEventFunctor,
  294. private wxPrivate::HandlerImpl
  295. <
  296. Class,
  297. EventArg,
  298. wxConvertibleTo<Class, wxEvtHandler>::value != 0
  299. >
  300. {
  301. private:
  302. static void CheckHandlerArgument(EventArg *) { }
  303. public:
  304. // the event class associated with the given event tag
  305. typedef typename wxPrivate::EventClassOf<EventTag>::type EventClass;
  306. wxEventFunctorMethod(void (Class::*method)(EventArg&), EventHandler *handler)
  307. : m_handler( handler ), m_method( method )
  308. {
  309. wxASSERT_MSG( handler || this->IsEvtHandler(),
  310. "handlers defined in non-wxEvtHandler-derived classes "
  311. "must be connected with a valid sink object" );
  312. // if you get an error here it means that the signature of the handler
  313. // you're trying to use is not compatible with (i.e. is not the same as
  314. // or a base class of) the real event class used for this event type
  315. CheckHandlerArgument(static_cast<EventClass *>(NULL));
  316. }
  317. virtual void operator()(wxEvtHandler *handler, wxEvent& event)
  318. {
  319. Class * realHandler = m_handler;
  320. if ( !realHandler )
  321. {
  322. realHandler = this->ConvertFromEvtHandler(handler);
  323. // this is not supposed to happen but check for it nevertheless
  324. wxCHECK_RET( realHandler, "invalid event handler" );
  325. }
  326. // the real (run-time) type of event is EventClass and we checked in
  327. // the ctor that EventClass can be converted to EventArg, so this cast
  328. // is always valid
  329. (realHandler->*m_method)(static_cast<EventArg&>(event));
  330. }
  331. virtual bool IsMatching(const wxEventFunctor& functor) const
  332. {
  333. if ( wxTypeId(functor) != wxTypeId(*this) )
  334. return false;
  335. typedef wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>
  336. ThisFunctor;
  337. // the cast is valid because wxTypeId()s matched above
  338. const ThisFunctor& other = static_cast<const ThisFunctor &>(functor);
  339. return (m_method == other.m_method || other.m_method == NULL) &&
  340. (m_handler == other.m_handler || other.m_handler == NULL);
  341. }
  342. virtual wxEvtHandler *GetEvtHandler() const
  343. { return this->ConvertToEvtHandler(m_handler); }
  344. virtual wxEventFunction GetEvtMethod() const
  345. { return this->ConvertToEvtMethod(m_method); }
  346. private:
  347. EventHandler *m_handler;
  348. void (Class::*m_method)(EventArg&);
  349. // Provide a dummy default ctor for type info purposes
  350. wxEventFunctorMethod() { }
  351. typedef wxEventFunctorMethod<EventTag, Class,
  352. EventArg, EventHandler> thisClass;
  353. WX_DECLARE_TYPEINFO_INLINE(thisClass)
  354. };
  355. // functor forwarding the event to function (function, static method)
  356. template <typename EventTag, typename EventArg>
  357. class wxEventFunctorFunction : public wxEventFunctor
  358. {
  359. private:
  360. static void CheckHandlerArgument(EventArg *) { }
  361. public:
  362. // the event class associated with the given event tag
  363. typedef typename wxPrivate::EventClassOf<EventTag>::type EventClass;
  364. wxEventFunctorFunction( void ( *handler )( EventArg & ))
  365. : m_handler( handler )
  366. {
  367. // if you get an error here it means that the signature of the handler
  368. // you're trying to use is not compatible with (i.e. is not the same as
  369. // or a base class of) the real event class used for this event type
  370. CheckHandlerArgument(static_cast<EventClass *>(NULL));
  371. }
  372. virtual void operator()(wxEvtHandler *WXUNUSED(handler), wxEvent& event)
  373. {
  374. // If you get an error here like "must use .* or ->* to call
  375. // pointer-to-member function" then you probably tried to call
  376. // Bind/Unbind with a method pointer but without a handler pointer or
  377. // NULL as a handler e.g.:
  378. // Unbind( wxEVT_XXX, &EventHandler::method );
  379. // or
  380. // Unbind( wxEVT_XXX, &EventHandler::method, NULL )
  381. m_handler(static_cast<EventArg&>(event));
  382. }
  383. virtual bool IsMatching(const wxEventFunctor &functor) const
  384. {
  385. if ( wxTypeId(functor) != wxTypeId(*this) )
  386. return false;
  387. typedef wxEventFunctorFunction<EventTag, EventArg> ThisFunctor;
  388. const ThisFunctor& other = static_cast<const ThisFunctor&>( functor );
  389. return m_handler == other.m_handler;
  390. }
  391. private:
  392. void (*m_handler)(EventArg&);
  393. // Provide a dummy default ctor for type info purposes
  394. wxEventFunctorFunction() { }
  395. typedef wxEventFunctorFunction<EventTag, EventArg> thisClass;
  396. WX_DECLARE_TYPEINFO_INLINE(thisClass)
  397. };
  398. template <typename EventTag, typename Functor>
  399. class wxEventFunctorFunctor : public wxEventFunctor
  400. {
  401. public:
  402. typedef typename EventTag::EventClass EventArg;
  403. wxEventFunctorFunctor(const Functor& handler)
  404. : m_handler(handler), m_handlerAddr(&handler)
  405. { }
  406. virtual void operator()(wxEvtHandler *WXUNUSED(handler), wxEvent& event)
  407. {
  408. // If you get an error here like "must use '.*' or '->*' to call
  409. // pointer-to-member function" then you probably tried to call
  410. // Bind/Unbind with a method pointer but without a handler pointer or
  411. // NULL as a handler e.g.:
  412. // Unbind( wxEVT_XXX, &EventHandler::method );
  413. // or
  414. // Unbind( wxEVT_XXX, &EventHandler::method, NULL )
  415. m_handler(static_cast<EventArg&>(event));
  416. }
  417. virtual bool IsMatching(const wxEventFunctor &functor) const
  418. {
  419. if ( wxTypeId(functor) != wxTypeId(*this) )
  420. return false;
  421. typedef wxEventFunctorFunctor<EventTag, Functor> FunctorThis;
  422. const FunctorThis& other = static_cast<const FunctorThis&>(functor);
  423. // The only reliable/portable way to compare two functors is by
  424. // identity:
  425. return m_handlerAddr == other.m_handlerAddr;
  426. }
  427. private:
  428. // Store a copy of the functor to prevent using/calling an already
  429. // destroyed instance:
  430. Functor m_handler;
  431. // Use the address of the original functor for comparison in IsMatching:
  432. const void *m_handlerAddr;
  433. // Provide a dummy default ctor for type info purposes
  434. wxEventFunctorFunctor() { }
  435. typedef wxEventFunctorFunctor<EventTag, Functor> thisClass;
  436. WX_DECLARE_TYPEINFO_INLINE(thisClass)
  437. };
  438. // Create functors for the templatized events, either allocated on the heap for
  439. // wxNewXXX() variants (this is needed in wxEvtHandler::Bind<>() to store them
  440. // in dynamic event table) or just by returning them as temporary objects (this
  441. // is enough for Unbind<>() and we avoid unnecessary heap allocation like this).
  442. // Create functors wrapping functions:
  443. template <typename EventTag, typename EventArg>
  444. inline wxEventFunctorFunction<EventTag, EventArg> *
  445. wxNewEventFunctor(const EventTag&, void (*func)(EventArg &))
  446. {
  447. return new wxEventFunctorFunction<EventTag, EventArg>(func);
  448. }
  449. template <typename EventTag, typename EventArg>
  450. inline wxEventFunctorFunction<EventTag, EventArg>
  451. wxMakeEventFunctor(const EventTag&, void (*func)(EventArg &))
  452. {
  453. return wxEventFunctorFunction<EventTag, EventArg>(func);
  454. }
  455. // Create functors wrapping other functors:
  456. template <typename EventTag, typename Functor>
  457. inline wxEventFunctorFunctor<EventTag, Functor> *
  458. wxNewEventFunctor(const EventTag&, const Functor &func)
  459. {
  460. return new wxEventFunctorFunctor<EventTag, Functor>(func);
  461. }
  462. template <typename EventTag, typename Functor>
  463. inline wxEventFunctorFunctor<EventTag, Functor>
  464. wxMakeEventFunctor(const EventTag&, const Functor &func)
  465. {
  466. return wxEventFunctorFunctor<EventTag, Functor>(func);
  467. }
  468. // Create functors wrapping methods:
  469. template
  470. <typename EventTag, typename Class, typename EventArg, typename EventHandler>
  471. inline wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler> *
  472. wxNewEventFunctor(const EventTag&,
  473. void (Class::*method)(EventArg&),
  474. EventHandler *handler)
  475. {
  476. return new wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>(
  477. method, handler);
  478. }
  479. template
  480. <typename EventTag, typename Class, typename EventArg, typename EventHandler>
  481. inline wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>
  482. wxMakeEventFunctor(const EventTag&,
  483. void (Class::*method)(EventArg&),
  484. EventHandler *handler)
  485. {
  486. return wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>(
  487. method, handler);
  488. }
  489. // Create an event functor for the event table via wxDECLARE_EVENT_TABLE_ENTRY:
  490. // in this case we don't have the handler (as it's always the same as the
  491. // object which generated the event) so we must use Class as its type
  492. template <typename EventTag, typename Class, typename EventArg>
  493. inline wxEventFunctorMethod<EventTag, Class, EventArg, Class> *
  494. wxNewEventTableFunctor(const EventTag&, void (Class::*method)(EventArg&))
  495. {
  496. return new wxEventFunctorMethod<EventTag, Class, EventArg, Class>(
  497. method, NULL);
  498. }
  499. #endif // wxHAS_EVENT_BIND
  500. // many, but not all, standard event types
  501. // some generic events
  502. extern WXDLLIMPEXP_BASE const wxEventType wxEVT_NULL;
  503. extern WXDLLIMPEXP_BASE const wxEventType wxEVT_FIRST;
  504. extern WXDLLIMPEXP_BASE const wxEventType wxEVT_USER_FIRST;
  505. // Need events declared to do this
  506. class WXDLLIMPEXP_FWD_BASE wxIdleEvent;
  507. class WXDLLIMPEXP_FWD_BASE wxThreadEvent;
  508. class WXDLLIMPEXP_FWD_BASE wxAsyncMethodCallEvent;
  509. class WXDLLIMPEXP_FWD_CORE wxCommandEvent;
  510. class WXDLLIMPEXP_FWD_CORE wxMouseEvent;
  511. class WXDLLIMPEXP_FWD_CORE wxFocusEvent;
  512. class WXDLLIMPEXP_FWD_CORE wxChildFocusEvent;
  513. class WXDLLIMPEXP_FWD_CORE wxKeyEvent;
  514. class WXDLLIMPEXP_FWD_CORE wxNavigationKeyEvent;
  515. class WXDLLIMPEXP_FWD_CORE wxSetCursorEvent;
  516. class WXDLLIMPEXP_FWD_CORE wxScrollEvent;
  517. class WXDLLIMPEXP_FWD_CORE wxSpinEvent;
  518. class WXDLLIMPEXP_FWD_CORE wxScrollWinEvent;
  519. class WXDLLIMPEXP_FWD_CORE wxSizeEvent;
  520. class WXDLLIMPEXP_FWD_CORE wxMoveEvent;
  521. class WXDLLIMPEXP_FWD_CORE wxCloseEvent;
  522. class WXDLLIMPEXP_FWD_CORE wxActivateEvent;
  523. class WXDLLIMPEXP_FWD_CORE wxWindowCreateEvent;
  524. class WXDLLIMPEXP_FWD_CORE wxWindowDestroyEvent;
  525. class WXDLLIMPEXP_FWD_CORE wxShowEvent;
  526. class WXDLLIMPEXP_FWD_CORE wxIconizeEvent;
  527. class WXDLLIMPEXP_FWD_CORE wxMaximizeEvent;
  528. class WXDLLIMPEXP_FWD_CORE wxMouseCaptureChangedEvent;
  529. class WXDLLIMPEXP_FWD_CORE wxMouseCaptureLostEvent;
  530. class WXDLLIMPEXP_FWD_CORE wxPaintEvent;
  531. class WXDLLIMPEXP_FWD_CORE wxEraseEvent;
  532. class WXDLLIMPEXP_FWD_CORE wxNcPaintEvent;
  533. class WXDLLIMPEXP_FWD_CORE wxMenuEvent;
  534. class WXDLLIMPEXP_FWD_CORE wxContextMenuEvent;
  535. class WXDLLIMPEXP_FWD_CORE wxSysColourChangedEvent;
  536. class WXDLLIMPEXP_FWD_CORE wxDisplayChangedEvent;
  537. class WXDLLIMPEXP_FWD_CORE wxQueryNewPaletteEvent;
  538. class WXDLLIMPEXP_FWD_CORE wxPaletteChangedEvent;
  539. class WXDLLIMPEXP_FWD_CORE wxJoystickEvent;
  540. class WXDLLIMPEXP_FWD_CORE wxDropFilesEvent;
  541. class WXDLLIMPEXP_FWD_CORE wxInitDialogEvent;
  542. class WXDLLIMPEXP_FWD_CORE wxUpdateUIEvent;
  543. class WXDLLIMPEXP_FWD_CORE wxClipboardTextEvent;
  544. class WXDLLIMPEXP_FWD_CORE wxHelpEvent;
  545. // Command events
  546. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_BUTTON, wxCommandEvent);
  547. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHECKBOX, wxCommandEvent);
  548. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHOICE, wxCommandEvent);
  549. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LISTBOX, wxCommandEvent);
  550. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LISTBOX_DCLICK, wxCommandEvent);
  551. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHECKLISTBOX, wxCommandEvent);
  552. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU, wxCommandEvent);
  553. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SLIDER, wxCommandEvent);
  554. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RADIOBOX, wxCommandEvent);
  555. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RADIOBUTTON, wxCommandEvent);
  556. // wxEVT_SCROLLBAR is deprecated, use wxEVT_SCROLL... events
  557. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLBAR, wxCommandEvent);
  558. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_VLBOX, wxCommandEvent);
  559. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX, wxCommandEvent);
  560. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_RCLICKED, wxCommandEvent);
  561. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_DROPDOWN, wxCommandEvent);
  562. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_ENTER, wxCommandEvent);
  563. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX_DROPDOWN, wxCommandEvent);
  564. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX_CLOSEUP, wxCommandEvent);
  565. // Thread and asynchronous method call events
  566. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_BASE, wxEVT_THREAD, wxThreadEvent);
  567. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_BASE, wxEVT_ASYNC_METHOD_CALL, wxAsyncMethodCallEvent);
  568. // Mouse event types
  569. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DOWN, wxMouseEvent);
  570. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_UP, wxMouseEvent);
  571. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_DOWN, wxMouseEvent);
  572. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_UP, wxMouseEvent);
  573. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_DOWN, wxMouseEvent);
  574. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_UP, wxMouseEvent);
  575. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOTION, wxMouseEvent);
  576. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ENTER_WINDOW, wxMouseEvent);
  577. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEAVE_WINDOW, wxMouseEvent);
  578. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DCLICK, wxMouseEvent);
  579. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_DCLICK, wxMouseEvent);
  580. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_DCLICK, wxMouseEvent);
  581. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_FOCUS, wxFocusEvent);
  582. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KILL_FOCUS, wxFocusEvent);
  583. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHILD_FOCUS, wxChildFocusEvent);
  584. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSEWHEEL, wxMouseEvent);
  585. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_DOWN, wxMouseEvent);
  586. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_UP, wxMouseEvent);
  587. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_DCLICK, wxMouseEvent);
  588. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DOWN, wxMouseEvent);
  589. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_UP, wxMouseEvent);
  590. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DCLICK, wxMouseEvent);
  591. // Character input event type
  592. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR, wxKeyEvent);
  593. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR_HOOK, wxKeyEvent);
  594. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent);
  595. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_DOWN, wxKeyEvent);
  596. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_UP, wxKeyEvent);
  597. #if wxUSE_HOTKEY
  598. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HOTKEY, wxKeyEvent);
  599. #endif
  600. // This is a private event used by wxMSW code only and subject to change or
  601. // disappear in the future. Don't use.
  602. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AFTER_CHAR, wxKeyEvent);
  603. // Set cursor event
  604. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_CURSOR, wxSetCursorEvent);
  605. // wxScrollBar and wxSlider event identifiers
  606. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_TOP, wxScrollEvent);
  607. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_BOTTOM, wxScrollEvent);
  608. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_LINEUP, wxScrollEvent);
  609. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_LINEDOWN, wxScrollEvent);
  610. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_PAGEUP, wxScrollEvent);
  611. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_PAGEDOWN, wxScrollEvent);
  612. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_THUMBTRACK, wxScrollEvent);
  613. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent);
  614. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_CHANGED, wxScrollEvent);
  615. // Due to a bug in older wx versions, wxSpinEvents were being sent with type of
  616. // wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But
  617. // with the type-safe events in place, these event types are associated with
  618. // wxScrollEvent. To allow handling of spin events, new event types have been
  619. // defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility
  620. // the spin event types are being initialized with the scroll event types.
  621. #if wxUSE_SPINBTN
  622. wxDECLARE_EXPORTED_EVENT_ALIAS( WXDLLIMPEXP_CORE, wxEVT_SPIN_UP, wxSpinEvent );
  623. wxDECLARE_EXPORTED_EVENT_ALIAS( WXDLLIMPEXP_CORE, wxEVT_SPIN_DOWN, wxSpinEvent );
  624. wxDECLARE_EXPORTED_EVENT_ALIAS( WXDLLIMPEXP_CORE, wxEVT_SPIN, wxSpinEvent );
  625. #endif
  626. // Scroll events from wxWindow
  627. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_TOP, wxScrollWinEvent);
  628. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent);
  629. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent);
  630. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent);
  631. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent);
  632. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent);
  633. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent);
  634. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent);
  635. // System events
  636. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZE, wxSizeEvent);
  637. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE, wxMoveEvent);
  638. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CLOSE_WINDOW, wxCloseEvent);
  639. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_END_SESSION, wxCloseEvent);
  640. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_END_SESSION, wxCloseEvent);
  641. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ACTIVATE_APP, wxActivateEvent);
  642. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ACTIVATE, wxActivateEvent);
  643. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CREATE, wxWindowCreateEvent);
  644. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DESTROY, wxWindowDestroyEvent);
  645. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SHOW, wxShowEvent);
  646. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ICONIZE, wxIconizeEvent);
  647. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MAXIMIZE, wxMaximizeEvent);
  648. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent);
  649. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent);
  650. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PAINT, wxPaintEvent);
  651. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ERASE_BACKGROUND, wxEraseEvent);
  652. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_NC_PAINT, wxNcPaintEvent);
  653. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_OPEN, wxMenuEvent);
  654. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_CLOSE, wxMenuEvent);
  655. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_HIGHLIGHT, wxMenuEvent);
  656. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CONTEXT_MENU, wxContextMenuEvent);
  657. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent);
  658. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent);
  659. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent);
  660. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent);
  661. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent);
  662. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_UP, wxJoystickEvent);
  663. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_MOVE, wxJoystickEvent);
  664. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_ZMOVE, wxJoystickEvent);
  665. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DROP_FILES, wxDropFilesEvent);
  666. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_INIT_DIALOG, wxInitDialogEvent);
  667. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_BASE, wxEVT_IDLE, wxIdleEvent);
  668. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_UPDATE_UI, wxUpdateUIEvent);
  669. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZING, wxSizeEvent);
  670. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVING, wxMoveEvent);
  671. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_START, wxMoveEvent);
  672. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_END, wxMoveEvent);
  673. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HIBERNATE, wxActivateEvent);
  674. // Clipboard events
  675. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_COPY, wxClipboardTextEvent);
  676. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_CUT, wxClipboardTextEvent);
  677. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_PASTE, wxClipboardTextEvent);
  678. // Generic command events
  679. // Note: a click is a higher-level event than button down/up
  680. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent);
  681. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent);
  682. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent);
  683. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent);
  684. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SET_FOCUS, wxCommandEvent);
  685. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent);
  686. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_ENTER, wxCommandEvent);
  687. // Help events
  688. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HELP, wxHelpEvent);
  689. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DETAILED_HELP, wxHelpEvent);
  690. // these 2 events are the same
  691. #define wxEVT_TOOL wxEVT_MENU
  692. // ----------------------------------------------------------------------------
  693. // Compatibility
  694. // ----------------------------------------------------------------------------
  695. // this event is also used by wxComboBox and wxSpinCtrl which don't include
  696. // wx/textctrl.h in all ports [yet], so declare it here as well
  697. //
  698. // still, any new code using it should include wx/textctrl.h explicitly
  699. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT, wxCommandEvent);
  700. // ----------------------------------------------------------------------------
  701. // wxEvent(-derived) classes
  702. // ----------------------------------------------------------------------------
  703. // the predefined constants for the number of times we propagate event
  704. // upwards window child-parent chain
  705. enum wxEventPropagation
  706. {
  707. // don't propagate it at all
  708. wxEVENT_PROPAGATE_NONE = 0,
  709. // propagate it until it is processed
  710. wxEVENT_PROPAGATE_MAX = INT_MAX
  711. };
  712. // The different categories for a wxEvent; see wxEvent::GetEventCategory.
  713. // NOTE: they are used as OR-combinable flags by wxEventLoopBase::YieldFor
  714. enum wxEventCategory
  715. {
  716. // this is the category for those events which are generated to update
  717. // the appearance of the GUI but which (usually) do not comport data
  718. // processing, i.e. which do not provide input or output data
  719. // (e.g. size events, scroll events, etc).
  720. // They are events NOT directly generated by the user's input devices.
  721. wxEVT_CATEGORY_UI = 1,
  722. // this category groups those events which are generated directly from the
  723. // user through input devices like mouse and keyboard and usually result in
  724. // data to be processed from the application.
  725. // (e.g. mouse clicks, key presses, etc)
  726. wxEVT_CATEGORY_USER_INPUT = 2,
  727. // this category is for wxSocketEvent
  728. wxEVT_CATEGORY_SOCKET = 4,
  729. // this category is for wxTimerEvent
  730. wxEVT_CATEGORY_TIMER = 8,
  731. // this category is for any event used to send notifications from the
  732. // secondary threads to the main one or in general for notifications among
  733. // different threads (which may or may not be user-generated)
  734. wxEVT_CATEGORY_THREAD = 16,
  735. // implementation only
  736. // used in the implementations of wxEventLoopBase::YieldFor
  737. wxEVT_CATEGORY_UNKNOWN = 32,
  738. // a special category used as an argument to wxEventLoopBase::YieldFor to indicate that
  739. // Yield() should leave all wxEvents on the queue while emptying the native event queue
  740. // (native events will be processed but the wxEvents they generate will be queued)
  741. wxEVT_CATEGORY_CLIPBOARD = 64,
  742. // shortcut masks
  743. // this category groups those events which are emitted in response to
  744. // events of the native toolkit and which typically are not-"delayable".
  745. wxEVT_CATEGORY_NATIVE_EVENTS = wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT,
  746. // used in wxEventLoopBase::YieldFor to specify all event categories should be processed:
  747. wxEVT_CATEGORY_ALL =
  748. wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT|wxEVT_CATEGORY_SOCKET| \
  749. wxEVT_CATEGORY_TIMER|wxEVT_CATEGORY_THREAD|wxEVT_CATEGORY_UNKNOWN| \
  750. wxEVT_CATEGORY_CLIPBOARD
  751. };
  752. /*
  753. * wxWidgets events, covering all interesting things that might happen
  754. * (button clicking, resizing, setting text in widgets, etc.).
  755. *
  756. * For each completely new event type, derive a new event class.
  757. * An event CLASS represents a C++ class defining a range of similar event TYPES;
  758. * examples are canvas events, panel item command events.
  759. * An event TYPE is a unique identifier for a particular system event,
  760. * such as a button press or a listbox deselection.
  761. *
  762. */
  763. class WXDLLIMPEXP_BASE wxEvent : public wxObject
  764. {
  765. public:
  766. wxEvent(int winid = 0, wxEventType commandType = wxEVT_NULL );
  767. void SetEventType(wxEventType typ) { m_eventType = typ; }
  768. wxEventType GetEventType() const { return m_eventType; }
  769. wxObject *GetEventObject() const { return m_eventObject; }
  770. void SetEventObject(wxObject *obj) { m_eventObject = obj; }
  771. long GetTimestamp() const { return m_timeStamp; }
  772. void SetTimestamp(long ts = 0) { m_timeStamp = ts; }
  773. int GetId() const { return m_id; }
  774. void SetId(int Id) { m_id = Id; }
  775. // Returns the user data optionally associated with the event handler when
  776. // using Connect() or Bind().
  777. wxObject *GetEventUserData() const { return m_callbackUserData; }
  778. // Can instruct event processor that we wish to ignore this event
  779. // (treat as if the event table entry had not been found): this must be done
  780. // to allow the event processing by the base classes (calling event.Skip()
  781. // is the analog of calling the base class version of a virtual function)
  782. void Skip(bool skip = true) { m_skipped = skip; }
  783. bool GetSkipped() const { return m_skipped; }
  784. // This function is used to create a copy of the event polymorphically and
  785. // all derived classes must implement it because otherwise wxPostEvent()
  786. // for them wouldn't work (it needs to do a copy of the event)
  787. virtual wxEvent *Clone() const = 0;
  788. // this function is used to selectively process events in wxEventLoopBase::YieldFor
  789. // NOTE: by default it returns wxEVT_CATEGORY_UI just because the major
  790. // part of wxWidgets events belong to that category.
  791. virtual wxEventCategory GetEventCategory() const
  792. { return wxEVT_CATEGORY_UI; }
  793. // Implementation only: this test is explicitly anti OO and this function
  794. // exists only for optimization purposes.
  795. bool IsCommandEvent() const { return m_isCommandEvent; }
  796. // Determine if this event should be propagating to the parent window.
  797. bool ShouldPropagate() const
  798. { return m_propagationLevel != wxEVENT_PROPAGATE_NONE; }
  799. // Stop an event from propagating to its parent window, returns the old
  800. // propagation level value
  801. int StopPropagation()
  802. {
  803. int propagationLevel = m_propagationLevel;
  804. m_propagationLevel = wxEVENT_PROPAGATE_NONE;
  805. return propagationLevel;
  806. }
  807. // Resume the event propagation by restoring the propagation level
  808. // (returned by StopPropagation())
  809. void ResumePropagation(int propagationLevel)
  810. {
  811. m_propagationLevel = propagationLevel;
  812. }
  813. // This method is for internal use only and allows to get the object that
  814. // is propagating this event upwards the window hierarchy, if any.
  815. wxEvtHandler* GetPropagatedFrom() const { return m_propagatedFrom; }
  816. // This is for internal use only and is only called by
  817. // wxEvtHandler::ProcessEvent() to check whether it's the first time this
  818. // event is being processed
  819. bool WasProcessed()
  820. {
  821. if ( m_wasProcessed )
  822. return true;
  823. m_wasProcessed = true;
  824. return false;
  825. }
  826. // This is for internal use only and is used for setting, testing and
  827. // resetting of m_willBeProcessedAgain flag.
  828. void SetWillBeProcessedAgain()
  829. {
  830. m_willBeProcessedAgain = true;
  831. }
  832. bool WillBeProcessedAgain()
  833. {
  834. if ( m_willBeProcessedAgain )
  835. {
  836. m_willBeProcessedAgain = false;
  837. return true;
  838. }
  839. return false;
  840. }
  841. // This is also used only internally by ProcessEvent() to check if it
  842. // should process the event normally or only restrict the search for the
  843. // event handler to this object itself.
  844. bool ShouldProcessOnlyIn(wxEvtHandler *h) const
  845. {
  846. return h == m_handlerToProcessOnlyIn;
  847. }
  848. // Called to indicate that the result of ShouldProcessOnlyIn() wasn't taken
  849. // into account. The existence of this function may seem counterintuitive
  850. // but unfortunately it's needed by wxScrollHelperEvtHandler, see comments
  851. // there. Don't even think of using this in your own code, this is a gross
  852. // hack and is only needed because of wx complicated history and should
  853. // never be used anywhere else.
  854. void DidntHonourProcessOnlyIn()
  855. {
  856. m_handlerToProcessOnlyIn = NULL;
  857. }
  858. protected:
  859. wxObject* m_eventObject;
  860. wxEventType m_eventType;
  861. long m_timeStamp;
  862. int m_id;
  863. public:
  864. // m_callbackUserData is for internal usage only
  865. wxObject* m_callbackUserData;
  866. private:
  867. // If this handler
  868. wxEvtHandler *m_handlerToProcessOnlyIn;
  869. protected:
  870. // the propagation level: while it is positive, we propagate the event to
  871. // the parent window (if any)
  872. int m_propagationLevel;
  873. // The object that the event is being propagated from, initially NULL and
  874. // only set by wxPropagateOnce.
  875. wxEvtHandler* m_propagatedFrom;
  876. bool m_skipped;
  877. bool m_isCommandEvent;
  878. // initially false but becomes true as soon as WasProcessed() is called for
  879. // the first time, as this is done only by ProcessEvent() it explains the
  880. // variable name: it becomes true after ProcessEvent() was called at least
  881. // once for this event
  882. bool m_wasProcessed;
  883. // This one is initially false too, but can be set to true to indicate that
  884. // the event will be passed to another handler if it's not processed in
  885. // this one.
  886. bool m_willBeProcessedAgain;
  887. protected:
  888. wxEvent(const wxEvent&); // for implementing Clone()
  889. wxEvent& operator=(const wxEvent&); // for derived classes operator=()
  890. private:
  891. // It needs to access our m_propagationLevel and m_propagatedFrom fields.
  892. friend class WXDLLIMPEXP_FWD_BASE wxPropagateOnce;
  893. // and this one needs to access our m_handlerToProcessOnlyIn
  894. friend class WXDLLIMPEXP_FWD_BASE wxEventProcessInHandlerOnly;
  895. DECLARE_ABSTRACT_CLASS(wxEvent)
  896. };
  897. /*
  898. * Helper class to temporarily change an event not to propagate.
  899. */
  900. class WXDLLIMPEXP_BASE wxPropagationDisabler
  901. {
  902. public:
  903. wxPropagationDisabler(wxEvent& event) : m_event(event)
  904. {
  905. m_propagationLevelOld = m_event.StopPropagation();
  906. }
  907. ~wxPropagationDisabler()
  908. {
  909. m_event.ResumePropagation(m_propagationLevelOld);
  910. }
  911. private:
  912. wxEvent& m_event;
  913. int m_propagationLevelOld;
  914. wxDECLARE_NO_COPY_CLASS(wxPropagationDisabler);
  915. };
  916. /*
  917. * Helper used to indicate that an event is propagated upwards the window
  918. * hierarchy by the given window.
  919. */
  920. class WXDLLIMPEXP_BASE wxPropagateOnce
  921. {
  922. public:
  923. // The handler argument should normally be non-NULL to allow the parent
  924. // event handler to know that it's being used to process an event coming
  925. // from the child, it's only NULL by default for backwards compatibility.
  926. wxPropagateOnce(wxEvent& event, wxEvtHandler* handler = NULL)
  927. : m_event(event),
  928. m_propagatedFromOld(event.m_propagatedFrom)
  929. {
  930. wxASSERT_MSG( m_event.m_propagationLevel > 0,
  931. wxT("shouldn't be used unless ShouldPropagate()!") );
  932. m_event.m_propagationLevel--;
  933. m_event.m_propagatedFrom = handler;
  934. }
  935. ~wxPropagateOnce()
  936. {
  937. m_event.m_propagatedFrom = m_propagatedFromOld;
  938. m_event.m_propagationLevel++;
  939. }
  940. private:
  941. wxEvent& m_event;
  942. wxEvtHandler* const m_propagatedFromOld;
  943. wxDECLARE_NO_COPY_CLASS(wxPropagateOnce);
  944. };
  945. // A helper object used to temporarily make wxEvent::ShouldProcessOnlyIn()
  946. // return true for the handler passed to its ctor.
  947. class wxEventProcessInHandlerOnly
  948. {
  949. public:
  950. wxEventProcessInHandlerOnly(wxEvent& event, wxEvtHandler *handler)
  951. : m_event(event),
  952. m_handlerToProcessOnlyInOld(event.m_handlerToProcessOnlyIn)
  953. {
  954. m_event.m_handlerToProcessOnlyIn = handler;
  955. }
  956. ~wxEventProcessInHandlerOnly()
  957. {
  958. m_event.m_handlerToProcessOnlyIn = m_handlerToProcessOnlyInOld;
  959. }
  960. private:
  961. wxEvent& m_event;
  962. wxEvtHandler * const m_handlerToProcessOnlyInOld;
  963. wxDECLARE_NO_COPY_CLASS(wxEventProcessInHandlerOnly);
  964. };
  965. class WXDLLIMPEXP_BASE wxEventBasicPayloadMixin
  966. {
  967. public:
  968. wxEventBasicPayloadMixin()
  969. : m_commandInt(0),
  970. m_extraLong(0)
  971. {
  972. }
  973. void SetString(const wxString& s) { m_cmdString = s; }
  974. const wxString& GetString() const { return m_cmdString; }
  975. void SetInt(int i) { m_commandInt = i; }
  976. int GetInt() const { return m_commandInt; }
  977. void SetExtraLong(long extraLong) { m_extraLong = extraLong; }
  978. long GetExtraLong() const { return m_extraLong; }
  979. protected:
  980. // Note: these variables have "cmd" or "command" in their name for backward compatibility:
  981. // they used to be part of wxCommandEvent, not this mixin.
  982. wxString m_cmdString; // String event argument
  983. int m_commandInt;
  984. long m_extraLong; // Additional information (e.g. select/deselect)
  985. wxDECLARE_NO_ASSIGN_CLASS(wxEventBasicPayloadMixin);
  986. };
  987. class WXDLLIMPEXP_BASE wxEventAnyPayloadMixin : public wxEventBasicPayloadMixin
  988. {
  989. public:
  990. wxEventAnyPayloadMixin() : wxEventBasicPayloadMixin() {}
  991. #if wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7))
  992. template<typename T>
  993. void SetPayload(const T& payload)
  994. {
  995. m_payload = payload;
  996. }
  997. template<typename T>
  998. T GetPayload() const
  999. {
  1000. return m_payload.As<T>();
  1001. }
  1002. protected:
  1003. wxAny m_payload;
  1004. #endif // wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7))
  1005. wxDECLARE_NO_ASSIGN_CLASS(wxEventBasicPayloadMixin);
  1006. };
  1007. // Idle event
  1008. /*
  1009. wxEVT_IDLE
  1010. */
  1011. // Whether to always send idle events to windows, or
  1012. // to only send update events to those with the
  1013. // wxWS_EX_PROCESS_IDLE style.
  1014. enum wxIdleMode
  1015. {
  1016. // Send idle events to all windows
  1017. wxIDLE_PROCESS_ALL,
  1018. // Send idle events to windows that have
  1019. // the wxWS_EX_PROCESS_IDLE flag specified
  1020. wxIDLE_PROCESS_SPECIFIED
  1021. };
  1022. class WXDLLIMPEXP_BASE wxIdleEvent : public wxEvent
  1023. {
  1024. public:
  1025. wxIdleEvent()
  1026. : wxEvent(0, wxEVT_IDLE),
  1027. m_requestMore(false)
  1028. { }
  1029. wxIdleEvent(const wxIdleEvent& event)
  1030. : wxEvent(event),
  1031. m_requestMore(event.m_requestMore)
  1032. { }
  1033. void RequestMore(bool needMore = true) { m_requestMore = needMore; }
  1034. bool MoreRequested() const { return m_requestMore; }
  1035. virtual wxEvent *Clone() const { return new wxIdleEvent(*this); }
  1036. // Specify how wxWidgets will send idle events: to
  1037. // all windows, or only to those which specify that they
  1038. // will process the events.
  1039. static void SetMode(wxIdleMode mode) { sm_idleMode = mode; }
  1040. // Returns the idle event mode
  1041. static wxIdleMode GetMode() { return sm_idleMode; }
  1042. protected:
  1043. bool m_requestMore;
  1044. static wxIdleMode sm_idleMode;
  1045. private:
  1046. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIdleEvent)
  1047. };
  1048. // Thread event
  1049. class WXDLLIMPEXP_BASE wxThreadEvent : public wxEvent,
  1050. public wxEventAnyPayloadMixin
  1051. {
  1052. public:
  1053. wxThreadEvent(wxEventType eventType = wxEVT_THREAD, int id = wxID_ANY)
  1054. : wxEvent(id, eventType)
  1055. { }
  1056. wxThreadEvent(const wxThreadEvent& event)
  1057. : wxEvent(event),
  1058. wxEventAnyPayloadMixin(event)
  1059. {
  1060. // make sure our string member (which uses COW, aka refcounting) is not
  1061. // shared by other wxString instances:
  1062. SetString(GetString().Clone());
  1063. }
  1064. virtual wxEvent *Clone() const
  1065. {
  1066. return new wxThreadEvent(*this);
  1067. }
  1068. // this is important to avoid that calling wxEventLoopBase::YieldFor thread events
  1069. // gets processed when this is unwanted:
  1070. virtual wxEventCategory GetEventCategory() const
  1071. { return wxEVT_CATEGORY_THREAD; }
  1072. private:
  1073. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThreadEvent)
  1074. };
  1075. // Asynchronous method call events: these event are processed by wxEvtHandler
  1076. // itself and result in a call to its Execute() method which simply calls the
  1077. // specified method. The difference with a simple method call is that this is
  1078. // done asynchronously, i.e. at some later time, instead of immediately when
  1079. // the event object is constructed.
  1080. #ifdef wxHAS_CALL_AFTER
  1081. // This is a base class used to process all method calls.
  1082. class wxAsyncMethodCallEvent : public wxEvent
  1083. {
  1084. public:
  1085. wxAsyncMethodCallEvent(wxObject* object)
  1086. : wxEvent(wxID_ANY, wxEVT_ASYNC_METHOD_CALL)
  1087. {
  1088. SetEventObject(object);
  1089. }
  1090. wxAsyncMethodCallEvent(const wxAsyncMethodCallEvent& other)
  1091. : wxEvent(other)
  1092. {
  1093. }
  1094. virtual void Execute() = 0;
  1095. };
  1096. // This is a version for calling methods without parameters.
  1097. template <typename T>
  1098. class wxAsyncMethodCallEvent0 : public wxAsyncMethodCallEvent
  1099. {
  1100. public:
  1101. typedef T ObjectType;
  1102. typedef void (ObjectType::*MethodType)();
  1103. wxAsyncMethodCallEvent0(ObjectType* object,
  1104. MethodType method)
  1105. : wxAsyncMethodCallEvent(object),
  1106. m_object(object),
  1107. m_method(method)
  1108. {
  1109. }
  1110. wxAsyncMethodCallEvent0(const wxAsyncMethodCallEvent0& other)
  1111. : wxAsyncMethodCallEvent(other),
  1112. m_object(other.m_object),
  1113. m_method(other.m_method)
  1114. {
  1115. }
  1116. virtual wxEvent *Clone() const
  1117. {
  1118. return new wxAsyncMethodCallEvent0(*this);
  1119. }
  1120. virtual void Execute()
  1121. {
  1122. (m_object->*m_method)();
  1123. }
  1124. private:
  1125. ObjectType* const m_object;
  1126. const MethodType m_method;
  1127. };
  1128. // This is a version for calling methods with a single parameter.
  1129. template <typename T, typename T1>
  1130. class wxAsyncMethodCallEvent1 : public wxAsyncMethodCallEvent
  1131. {
  1132. public:
  1133. typedef T ObjectType;
  1134. typedef void (ObjectType::*MethodType)(T1 x1);
  1135. typedef typename wxRemoveRef<T1>::type ParamType1;
  1136. wxAsyncMethodCallEvent1(ObjectType* object,
  1137. MethodType method,
  1138. const ParamType1& x1)
  1139. : wxAsyncMethodCallEvent(object),
  1140. m_object(object),
  1141. m_method(method),
  1142. m_param1(x1)
  1143. {
  1144. }
  1145. wxAsyncMethodCallEvent1(const wxAsyncMethodCallEvent1& other)
  1146. : wxAsyncMethodCallEvent(other),
  1147. m_object(other.m_object),
  1148. m_method(other.m_method),
  1149. m_param1(other.m_param1)
  1150. {
  1151. }
  1152. virtual wxEvent *Clone() const
  1153. {
  1154. return new wxAsyncMethodCallEvent1(*this);
  1155. }
  1156. virtual void Execute()
  1157. {
  1158. (m_object->*m_method)(m_param1);
  1159. }
  1160. private:
  1161. ObjectType* const m_object;
  1162. const MethodType m_method;
  1163. const ParamType1 m_param1;
  1164. };
  1165. // This is a version for calling methods with two parameters.
  1166. template <typename T, typename T1, typename T2>
  1167. class wxAsyncMethodCallEvent2 : public wxAsyncMethodCallEvent
  1168. {
  1169. public:
  1170. typedef T ObjectType;
  1171. typedef void (ObjectType::*MethodType)(T1 x1, T2 x2);
  1172. typedef typename wxRemoveRef<T1>::type ParamType1;
  1173. typedef typename wxRemoveRef<T2>::type ParamType2;
  1174. wxAsyncMethodCallEvent2(ObjectType* object,
  1175. MethodType method,
  1176. const ParamType1& x1,
  1177. const ParamType2& x2)
  1178. : wxAsyncMethodCallEvent(object),
  1179. m_object(object),
  1180. m_method(method),
  1181. m_param1(x1),
  1182. m_param2(x2)
  1183. {
  1184. }
  1185. wxAsyncMethodCallEvent2(const wxAsyncMethodCallEvent2& other)
  1186. : wxAsyncMethodCallEvent(other),
  1187. m_object(other.m_object),
  1188. m_method(other.m_method),
  1189. m_param1(other.m_param1),
  1190. m_param2(other.m_param2)
  1191. {
  1192. }
  1193. virtual wxEvent *Clone() const
  1194. {
  1195. return new wxAsyncMethodCallEvent2(*this);
  1196. }
  1197. virtual void Execute()
  1198. {
  1199. (m_object->*m_method)(m_param1, m_param2);
  1200. }
  1201. private:
  1202. ObjectType* const m_object;
  1203. const MethodType m_method;
  1204. const ParamType1 m_param1;
  1205. const ParamType2 m_param2;
  1206. };
  1207. // This is a version for calling any functors
  1208. template <typename T>
  1209. class wxAsyncMethodCallEventFunctor : public wxAsyncMethodCallEvent
  1210. {
  1211. public:
  1212. typedef T FunctorType;
  1213. wxAsyncMethodCallEventFunctor(wxObject *object, const FunctorType& fn)
  1214. : wxAsyncMethodCallEvent(object),
  1215. m_fn(fn)
  1216. {
  1217. }
  1218. wxAsyncMethodCallEventFunctor(const wxAsyncMethodCallEventFunctor& other)
  1219. : wxAsyncMethodCallEvent(other),
  1220. m_fn(other.m_fn)
  1221. {
  1222. }
  1223. virtual wxEvent *Clone() const
  1224. {
  1225. return new wxAsyncMethodCallEventFunctor(*this);
  1226. }
  1227. virtual void Execute()
  1228. {
  1229. m_fn();
  1230. }
  1231. private:
  1232. FunctorType m_fn;
  1233. };
  1234. #endif // wxHAS_CALL_AFTER
  1235. #if wxUSE_GUI
  1236. // Item or menu event class
  1237. /*
  1238. wxEVT_BUTTON
  1239. wxEVT_CHECKBOX
  1240. wxEVT_CHOICE
  1241. wxEVT_LISTBOX
  1242. wxEVT_LISTBOX_DCLICK
  1243. wxEVT_TEXT
  1244. wxEVT_TEXT_ENTER
  1245. wxEVT_MENU
  1246. wxEVT_SLIDER
  1247. wxEVT_RADIOBOX
  1248. wxEVT_RADIOBUTTON
  1249. wxEVT_SCROLLBAR
  1250. wxEVT_VLBOX
  1251. wxEVT_COMBOBOX
  1252. wxEVT_TOGGLEBUTTON
  1253. */
  1254. class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent,
  1255. public wxEventBasicPayloadMixin
  1256. {
  1257. public:
  1258. wxCommandEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
  1259. wxCommandEvent(const wxCommandEvent& event)
  1260. : wxEvent(event),
  1261. wxEventBasicPayloadMixin(event),
  1262. m_clientData(event.m_clientData),
  1263. m_clientObject(event.m_clientObject)
  1264. {
  1265. // Because GetString() can retrieve the string text only on demand, we
  1266. // need to copy it explicitly.
  1267. if ( m_cmdString.empty() )
  1268. m_cmdString = event.GetString();
  1269. }
  1270. // Set/Get client data from controls
  1271. void SetClientData(void* clientData) { m_clientData = clientData; }
  1272. void *GetClientData() const { return m_clientData; }
  1273. // Set/Get client object from controls
  1274. void SetClientObject(wxClientData* clientObject) { m_clientObject = clientObject; }
  1275. wxClientData *GetClientObject() const { return m_clientObject; }
  1276. // Note: this shadows wxEventBasicPayloadMixin::GetString(), because it does some
  1277. // GUI-specific hacks
  1278. wxString GetString() const;
  1279. // Get listbox selection if single-choice
  1280. int GetSelection() const { return m_commandInt; }
  1281. // Get checkbox value
  1282. bool IsChecked() const { return m_commandInt != 0; }
  1283. // true if the listbox event was a selection.
  1284. bool IsSelection() const { return (m_extraLong != 0); }
  1285. virtual wxEvent *Clone() const { return new wxCommandEvent(*this); }
  1286. virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
  1287. protected:
  1288. void* m_clientData; // Arbitrary client data
  1289. wxClientData* m_clientObject; // Arbitrary client object
  1290. private:
  1291. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCommandEvent)
  1292. };
  1293. // this class adds a possibility to react (from the user) code to a control
  1294. // notification: allow or veto the operation being reported.
  1295. class WXDLLIMPEXP_CORE wxNotifyEvent : public wxCommandEvent
  1296. {
  1297. public:
  1298. wxNotifyEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
  1299. : wxCommandEvent(commandType, winid)
  1300. { m_bAllow = true; }
  1301. wxNotifyEvent(const wxNotifyEvent& event)
  1302. : wxCommandEvent(event)
  1303. { m_bAllow = event.m_bAllow; }
  1304. // veto the operation (usually it's allowed by default)
  1305. void Veto() { m_bAllow = false; }
  1306. // allow the operation if it was disabled by default
  1307. void Allow() { m_bAllow = true; }
  1308. // for implementation code only: is the operation allowed?
  1309. bool IsAllowed() const { return m_bAllow; }
  1310. virtual wxEvent *Clone() const { return new wxNotifyEvent(*this); }
  1311. private:
  1312. bool m_bAllow;
  1313. private:
  1314. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNotifyEvent)
  1315. };
  1316. // Scroll event class, derived form wxCommandEvent. wxScrollEvents are
  1317. // sent by wxSlider and wxScrollBar.
  1318. /*
  1319. wxEVT_SCROLL_TOP
  1320. wxEVT_SCROLL_BOTTOM
  1321. wxEVT_SCROLL_LINEUP
  1322. wxEVT_SCROLL_LINEDOWN
  1323. wxEVT_SCROLL_PAGEUP
  1324. wxEVT_SCROLL_PAGEDOWN
  1325. wxEVT_SCROLL_THUMBTRACK
  1326. wxEVT_SCROLL_THUMBRELEASE
  1327. wxEVT_SCROLL_CHANGED
  1328. */
  1329. class WXDLLIMPEXP_CORE wxScrollEvent : public wxCommandEvent
  1330. {
  1331. public:
  1332. wxScrollEvent(wxEventType commandType = wxEVT_NULL,
  1333. int winid = 0, int pos = 0, int orient = 0);
  1334. int GetOrientation() const { return (int) m_extraLong; }
  1335. int GetPosition() const { return m_commandInt; }
  1336. void SetOrientation(int orient) { m_extraLong = (long) orient; }
  1337. void SetPosition(int pos) { m_commandInt = pos; }
  1338. virtual wxEvent *Clone() const { return new wxScrollEvent(*this); }
  1339. private:
  1340. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxScrollEvent)
  1341. };
  1342. // ScrollWin event class, derived fom wxEvent. wxScrollWinEvents
  1343. // are sent by wxWindow.
  1344. /*
  1345. wxEVT_SCROLLWIN_TOP
  1346. wxEVT_SCROLLWIN_BOTTOM
  1347. wxEVT_SCROLLWIN_LINEUP
  1348. wxEVT_SCROLLWIN_LINEDOWN
  1349. wxEVT_SCROLLWIN_PAGEUP
  1350. wxEVT_SCROLLWIN_PAGEDOWN
  1351. wxEVT_SCROLLWIN_THUMBTRACK
  1352. wxEVT_SCROLLWIN_THUMBRELEASE
  1353. */
  1354. class WXDLLIMPEXP_CORE wxScrollWinEvent : public wxEvent
  1355. {
  1356. public:
  1357. wxScrollWinEvent(wxEventType commandType = wxEVT_NULL,
  1358. int pos = 0, int orient = 0);
  1359. wxScrollWinEvent(const wxScrollWinEvent& event) : wxEvent(event)
  1360. { m_commandInt = event.m_commandInt;
  1361. m_extraLong = event.m_extraLong; }
  1362. int GetOrientation() const { return (int) m_extraLong; }
  1363. int GetPosition() const { return m_commandInt; }
  1364. void SetOrientation(int orient) { m_extraLong = (long) orient; }
  1365. void SetPosition(int pos) { m_commandInt = pos; }
  1366. virtual wxEvent *Clone() const { return new wxScrollWinEvent(*this); }
  1367. protected:
  1368. int m_commandInt;
  1369. long m_extraLong;
  1370. private:
  1371. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxScrollWinEvent)
  1372. };
  1373. // Mouse event class
  1374. /*
  1375. wxEVT_LEFT_DOWN
  1376. wxEVT_LEFT_UP
  1377. wxEVT_MIDDLE_DOWN
  1378. wxEVT_MIDDLE_UP
  1379. wxEVT_RIGHT_DOWN
  1380. wxEVT_RIGHT_UP
  1381. wxEVT_MOTION
  1382. wxEVT_ENTER_WINDOW
  1383. wxEVT_LEAVE_WINDOW
  1384. wxEVT_LEFT_DCLICK
  1385. wxEVT_MIDDLE_DCLICK
  1386. wxEVT_RIGHT_DCLICK
  1387. */
  1388. enum wxMouseWheelAxis
  1389. {
  1390. wxMOUSE_WHEEL_VERTICAL,
  1391. wxMOUSE_WHEEL_HORIZONTAL
  1392. };
  1393. class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent,
  1394. public wxMouseState
  1395. {
  1396. public:
  1397. wxMouseEvent(wxEventType mouseType = wxEVT_NULL);
  1398. wxMouseEvent(const wxMouseEvent& event)
  1399. : wxEvent(event),
  1400. wxMouseState(event)
  1401. {
  1402. Assign(event);
  1403. }
  1404. // Was it a button event? (*doesn't* mean: is any button *down*?)
  1405. bool IsButton() const { return Button(wxMOUSE_BTN_ANY); }
  1406. // Was it a down event from this (or any) button?
  1407. bool ButtonDown(int but = wxMOUSE_BTN_ANY) const;
  1408. // Was it a dclick event from this (or any) button?
  1409. bool ButtonDClick(int but = wxMOUSE_BTN_ANY) const;
  1410. // Was it a up event from this (or any) button?
  1411. bool ButtonUp(int but = wxMOUSE_BTN_ANY) const;
  1412. // Was this event generated by the given button?
  1413. bool Button(int but) const;
  1414. // Get the button which is changing state (wxMOUSE_BTN_NONE if none)
  1415. int GetButton() const;
  1416. // Find which event was just generated
  1417. bool LeftDown() const { return (m_eventType == wxEVT_LEFT_DOWN); }
  1418. bool MiddleDown() const { return (m_eventType == wxEVT_MIDDLE_DOWN); }
  1419. bool RightDown() const { return (m_eventType == wxEVT_RIGHT_DOWN); }
  1420. bool Aux1Down() const { return (m_eventType == wxEVT_AUX1_DOWN); }
  1421. bool Aux2Down() const { return (m_eventType == wxEVT_AUX2_DOWN); }
  1422. bool LeftUp() const { return (m_eventType == wxEVT_LEFT_UP); }
  1423. bool MiddleUp() const { return (m_eventType == wxEVT_MIDDLE_UP); }
  1424. bool RightUp() const { return (m_eventType == wxEVT_RIGHT_UP); }
  1425. bool Aux1Up() const { return (m_eventType == wxEVT_AUX1_UP); }
  1426. bool Aux2Up() const { return (m_eventType == wxEVT_AUX2_UP); }
  1427. bool LeftDClick() const { return (m_eventType == wxEVT_LEFT_DCLICK); }
  1428. bool MiddleDClick() const { return (m_eventType == wxEVT_MIDDLE_DCLICK); }
  1429. bool RightDClick() const { return (m_eventType == wxEVT_RIGHT_DCLICK); }
  1430. bool Aux1DClick() const { return (m_eventType == wxEVT_AUX1_DCLICK); }
  1431. bool Aux2DClick() const { return (m_eventType == wxEVT_AUX2_DCLICK); }
  1432. // True if a button is down and the mouse is moving
  1433. bool Dragging() const
  1434. {
  1435. return (m_eventType == wxEVT_MOTION) && ButtonIsDown(wxMOUSE_BTN_ANY);
  1436. }
  1437. // True if the mouse is moving, and no button is down
  1438. bool Moving() const
  1439. {
  1440. return (m_eventType == wxEVT_MOTION) && !ButtonIsDown(wxMOUSE_BTN_ANY);
  1441. }
  1442. // True if the mouse is just entering the window
  1443. bool Entering() const { return (m_eventType == wxEVT_ENTER_WINDOW); }
  1444. // True if the mouse is just leaving the window
  1445. bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); }
  1446. // Returns the number of mouse clicks associated with this event.
  1447. int GetClickCount() const { return m_clickCount; }
  1448. // Find the logical position of the event given the DC
  1449. wxPoint GetLogicalPosition(const wxDC& dc) const;
  1450. // Get wheel rotation, positive or negative indicates direction of
  1451. // rotation. Current devices all send an event when rotation is equal to
  1452. // +/-WheelDelta, but this allows for finer resolution devices to be
  1453. // created in the future. Because of this you shouldn't assume that one
  1454. // event is equal to 1 line or whatever, but you should be able to either
  1455. // do partial line scrolling or wait until +/-WheelDelta rotation values
  1456. // have been accumulated before scrolling.
  1457. int GetWheelRotation() const { return m_wheelRotation; }
  1458. // Get wheel delta, normally 120. This is the threshold for action to be
  1459. // taken, and one such action (for example, scrolling one increment)
  1460. // should occur for each delta.
  1461. int GetWheelDelta() const { return m_wheelDelta; }
  1462. // Gets the axis the wheel operation concerns; wxMOUSE_WHEEL_VERTICAL
  1463. // (most common case) or wxMOUSE_WHEEL_HORIZONTAL (for horizontal scrolling
  1464. // using e.g. a trackpad).
  1465. wxMouseWheelAxis GetWheelAxis() const { return m_wheelAxis; }
  1466. // Returns the configured number of lines (or whatever) to be scrolled per
  1467. // wheel action. Defaults to three.
  1468. int GetLinesPerAction() const { return m_linesPerAction; }
  1469. // Returns the configured number of columns (or whatever) to be scrolled per
  1470. // wheel action. Defaults to three.
  1471. int GetColumnsPerAction() const { return m_columnsPerAction; }
  1472. // Is the system set to do page scrolling?
  1473. bool IsPageScroll() const { return ((unsigned int)m_linesPerAction == UINT_MAX); }
  1474. virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
  1475. virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
  1476. wxMouseEvent& operator=(const wxMouseEvent& event)
  1477. {
  1478. if (&event != this)
  1479. Assign(event);
  1480. return *this;
  1481. }
  1482. public:
  1483. int m_clickCount;
  1484. wxMouseWheelAxis m_wheelAxis;
  1485. int m_wheelRotation;
  1486. int m_wheelDelta;
  1487. int m_linesPerAction;
  1488. int m_columnsPerAction;
  1489. protected:
  1490. void Assign(const wxMouseEvent& evt);
  1491. private:
  1492. DECLARE_DYNAMIC_CLASS(wxMouseEvent)
  1493. };
  1494. // Cursor set event
  1495. /*
  1496. wxEVT_SET_CURSOR
  1497. */
  1498. class WXDLLIMPEXP_CORE wxSetCursorEvent : public wxEvent
  1499. {
  1500. public:
  1501. wxSetCursorEvent(wxCoord x = 0, wxCoord y = 0)
  1502. : wxEvent(0, wxEVT_SET_CURSOR),
  1503. m_x(x), m_y(y), m_cursor()
  1504. { }
  1505. wxSetCursorEvent(const wxSetCursorEvent& event)
  1506. : wxEvent(event),
  1507. m_x(event.m_x),
  1508. m_y(event.m_y),
  1509. m_cursor(event.m_cursor)
  1510. { }
  1511. wxCoord GetX() const { return m_x; }
  1512. wxCoord GetY() const { return m_y; }
  1513. void SetCursor(const wxCursor& cursor) { m_cursor = cursor; }
  1514. const wxCursor& GetCursor() const { return m_cursor; }
  1515. bool HasCursor() const { return m_cursor.IsOk(); }
  1516. virtual wxEvent *Clone() const { return new wxSetCursorEvent(*this); }
  1517. private:
  1518. wxCoord m_x, m_y;
  1519. wxCursor m_cursor;
  1520. private:
  1521. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSetCursorEvent)
  1522. };
  1523. // Keyboard input event class
  1524. /*
  1525. wxEVT_CHAR
  1526. wxEVT_CHAR_HOOK
  1527. wxEVT_KEY_DOWN
  1528. wxEVT_KEY_UP
  1529. wxEVT_HOTKEY
  1530. */
  1531. // key categories: the bit flags for IsKeyInCategory() function
  1532. //
  1533. // the enum values used may change in future version of wx
  1534. // use the named constants only, or bitwise combinations thereof
  1535. enum wxKeyCategoryFlags
  1536. {
  1537. // arrow keys, on and off numeric keypads
  1538. WXK_CATEGORY_ARROW = 1,
  1539. // page up and page down keys, on and off numeric keypads
  1540. WXK_CATEGORY_PAGING = 2,
  1541. // home and end keys, on and off numeric keypads
  1542. WXK_CATEGORY_JUMP = 4,
  1543. // tab key, on and off numeric keypads
  1544. WXK_CATEGORY_TAB = 8,
  1545. // backspace and delete keys, on and off numeric keypads
  1546. WXK_CATEGORY_CUT = 16,
  1547. // all keys usually used for navigation
  1548. WXK_CATEGORY_NAVIGATION = WXK_CATEGORY_ARROW |
  1549. WXK_CATEGORY_PAGING |
  1550. WXK_CATEGORY_JUMP
  1551. };
  1552. class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent,
  1553. public wxKeyboardState
  1554. {
  1555. public:
  1556. wxKeyEvent(wxEventType keyType = wxEVT_NULL);
  1557. // Normal copy ctor and a ctor creating a new event for the same key as the
  1558. // given one but a different event type (this is used in implementation
  1559. // code only, do not use outside of the library).
  1560. wxKeyEvent(const wxKeyEvent& evt);
  1561. wxKeyEvent(wxEventType eventType, const wxKeyEvent& evt);
  1562. // get the key code: an ASCII7 char or an element of wxKeyCode enum
  1563. int GetKeyCode() const { return (int)m_keyCode; }
  1564. // returns true iff this event's key code is of a certain type
  1565. bool IsKeyInCategory(int category) const;
  1566. #if wxUSE_UNICODE
  1567. // get the Unicode character corresponding to this key
  1568. wxChar GetUnicodeKey() const { return m_uniChar; }
  1569. #endif // wxUSE_UNICODE
  1570. // get the raw key code (platform-dependent)
  1571. wxUint32 GetRawKeyCode() const { return m_rawCode; }
  1572. // get the raw key flags (platform-dependent)
  1573. wxUint32 GetRawKeyFlags() const { return m_rawFlags; }
  1574. // Find the position of the event
  1575. void GetPosition(wxCoord *xpos, wxCoord *ypos) const
  1576. {
  1577. if (xpos)
  1578. *xpos = GetX();
  1579. if (ypos)
  1580. *ypos = GetY();
  1581. }
  1582. // This version if provided only for backwards compatiblity, don't use.
  1583. void GetPosition(long *xpos, long *ypos) const
  1584. {
  1585. if (xpos)
  1586. *xpos = GetX();
  1587. if (ypos)
  1588. *ypos = GetY();
  1589. }
  1590. wxPoint GetPosition() const
  1591. { return wxPoint(GetX(), GetY()); }
  1592. // Get X position
  1593. wxCoord GetX() const;
  1594. // Get Y position
  1595. wxCoord GetY() const;
  1596. // Can be called from wxEVT_CHAR_HOOK handler to allow generation of normal
  1597. // key events even though the event had been handled (by default they would
  1598. // not be generated in this case).
  1599. void DoAllowNextEvent() { m_allowNext = true; }
  1600. // Return the value of the "allow next" flag, for internal use only.
  1601. bool IsNextEventAllowed() const { return m_allowNext; }
  1602. virtual wxEvent *Clone() const { return new wxKeyEvent(*this); }
  1603. virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
  1604. // we do need to copy wxKeyEvent sometimes (in wxTreeCtrl code, for
  1605. // example)
  1606. wxKeyEvent& operator=(const wxKeyEvent& evt)
  1607. {
  1608. if ( &evt != this )
  1609. {
  1610. wxEvent::operator=(evt);
  1611. // Borland C++ 5.82 doesn't compile an explicit call to an
  1612. // implicitly defined operator=() so need to do it this way:
  1613. *static_cast<wxKeyboardState *>(this) = evt;
  1614. DoAssignMembers(evt);
  1615. }
  1616. return *this;
  1617. }
  1618. public:
  1619. // Do not use these fields directly, they are initialized on demand, so
  1620. // call GetX() and GetY() or GetPosition() instead.
  1621. wxCoord m_x, m_y;
  1622. long m_keyCode;
  1623. #if wxUSE_UNICODE
  1624. // This contains the full Unicode character
  1625. // in a character events in Unicode mode
  1626. wxChar m_uniChar;
  1627. #endif
  1628. // these fields contain the platform-specific information about
  1629. // key that was pressed
  1630. wxUint32 m_rawCode;
  1631. wxUint32 m_rawFlags;
  1632. private:
  1633. // Set the event to propagate if necessary, i.e. if it's of wxEVT_CHAR_HOOK
  1634. // type. This is used by all ctors.
  1635. void InitPropagation()
  1636. {
  1637. if ( m_eventType == wxEVT_CHAR_HOOK )
  1638. m_propagationLevel = wxEVENT_PROPAGATE_MAX;
  1639. m_allowNext = false;
  1640. }
  1641. // Copy only the event data present in this class, this is used by
  1642. // AssignKeyData() and copy ctor.
  1643. void DoAssignMembers(const wxKeyEvent& evt)
  1644. {
  1645. m_x = evt.m_x;
  1646. m_y = evt.m_y;
  1647. m_hasPosition = evt.m_hasPosition;
  1648. m_keyCode = evt.m_keyCode;
  1649. m_rawCode = evt.m_rawCode;
  1650. m_rawFlags = evt.m_rawFlags;
  1651. #if wxUSE_UNICODE
  1652. m_uniChar = evt.m_uniChar;
  1653. #endif
  1654. }
  1655. // Initialize m_x and m_y using the current mouse cursor position if
  1656. // necessary.
  1657. void InitPositionIfNecessary() const;
  1658. // If this flag is true, the normal key events should still be generated
  1659. // even if wxEVT_CHAR_HOOK had been handled. By default it is false as
  1660. // handling wxEVT_CHAR_HOOK suppresses all the subsequent events.
  1661. bool m_allowNext;
  1662. // If true, m_x and m_y were already initialized. If false, try to get them
  1663. // when they're requested.
  1664. bool m_hasPosition;
  1665. DECLARE_DYNAMIC_CLASS(wxKeyEvent)
  1666. };
  1667. // Size event class
  1668. /*
  1669. wxEVT_SIZE
  1670. */
  1671. class WXDLLIMPEXP_CORE wxSizeEvent : public wxEvent
  1672. {
  1673. public:
  1674. wxSizeEvent() : wxEvent(0, wxEVT_SIZE)
  1675. { }
  1676. wxSizeEvent(const wxSize& sz, int winid = 0)
  1677. : wxEvent(winid, wxEVT_SIZE),
  1678. m_size(sz)
  1679. { }
  1680. wxSizeEvent(const wxSizeEvent& event)
  1681. : wxEvent(event),
  1682. m_size(event.m_size), m_rect(event.m_rect)
  1683. { }
  1684. wxSizeEvent(const wxRect& rect, int id = 0)
  1685. : m_size(rect.GetSize()), m_rect(rect)
  1686. { m_eventType = wxEVT_SIZING; m_id = id; }
  1687. wxSize GetSize() const { return m_size; }
  1688. void SetSize(wxSize size) { m_size = size; }
  1689. wxRect GetRect() const { return m_rect; }
  1690. void SetRect(const wxRect& rect) { m_rect = rect; }
  1691. virtual wxEvent *Clone() const { return new wxSizeEvent(*this); }
  1692. public:
  1693. // For internal usage only. Will be converted to protected members.
  1694. wxSize m_size;
  1695. wxRect m_rect; // Used for wxEVT_SIZING
  1696. private:
  1697. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSizeEvent)
  1698. };
  1699. // Move event class
  1700. /*
  1701. wxEVT_MOVE
  1702. */
  1703. class WXDLLIMPEXP_CORE wxMoveEvent : public wxEvent
  1704. {
  1705. public:
  1706. wxMoveEvent()
  1707. : wxEvent(0, wxEVT_MOVE)
  1708. { }
  1709. wxMoveEvent(const wxPoint& pos, int winid = 0)
  1710. : wxEvent(winid, wxEVT_MOVE),
  1711. m_pos(pos)
  1712. { }
  1713. wxMoveEvent(const wxMoveEvent& event)
  1714. : wxEvent(event),
  1715. m_pos(event.m_pos)
  1716. { }
  1717. wxMoveEvent(const wxRect& rect, int id = 0)
  1718. : m_pos(rect.GetPosition()), m_rect(rect)
  1719. { m_eventType = wxEVT_MOVING; m_id = id; }
  1720. wxPoint GetPosition() const { return m_pos; }
  1721. void SetPosition(const wxPoint& pos) { m_pos = pos; }
  1722. wxRect GetRect() const { return m_rect; }
  1723. void SetRect(const wxRect& rect) { m_rect = rect; }
  1724. virtual wxEvent *Clone() const { return new wxMoveEvent(*this); }
  1725. protected:
  1726. wxPoint m_pos;
  1727. wxRect m_rect;
  1728. private:
  1729. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMoveEvent)
  1730. };
  1731. // Paint event class
  1732. /*
  1733. wxEVT_PAINT
  1734. wxEVT_NC_PAINT
  1735. */
  1736. #if wxDEBUG_LEVEL && (defined(__WXMSW__) || defined(__WXPM__))
  1737. #define wxHAS_PAINT_DEBUG
  1738. // see comments in src/msw|os2/dcclient.cpp where g_isPainting is defined
  1739. extern WXDLLIMPEXP_CORE int g_isPainting;
  1740. #endif // debug
  1741. class WXDLLIMPEXP_CORE wxPaintEvent : public wxEvent
  1742. {
  1743. public:
  1744. wxPaintEvent(int Id = 0)
  1745. : wxEvent(Id, wxEVT_PAINT)
  1746. {
  1747. #ifdef wxHAS_PAINT_DEBUG
  1748. // set the internal flag for the duration of redrawing
  1749. g_isPainting++;
  1750. #endif // debug
  1751. }
  1752. // default copy ctor and dtor are normally fine, we only need them to keep
  1753. // g_isPainting updated in debug build
  1754. #ifdef wxHAS_PAINT_DEBUG
  1755. wxPaintEvent(const wxPaintEvent& event)
  1756. : wxEvent(event)
  1757. {
  1758. g_isPainting++;
  1759. }
  1760. virtual ~wxPaintEvent()
  1761. {
  1762. g_isPainting--;
  1763. }
  1764. #endif // debug
  1765. virtual wxEvent *Clone() const { return new wxPaintEvent(*this); }
  1766. private:
  1767. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPaintEvent)
  1768. };
  1769. class WXDLLIMPEXP_CORE wxNcPaintEvent : public wxEvent
  1770. {
  1771. public:
  1772. wxNcPaintEvent(int winid = 0)
  1773. : wxEvent(winid, wxEVT_NC_PAINT)
  1774. { }
  1775. virtual wxEvent *Clone() const { return new wxNcPaintEvent(*this); }
  1776. private:
  1777. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNcPaintEvent)
  1778. };
  1779. // Erase background event class
  1780. /*
  1781. wxEVT_ERASE_BACKGROUND
  1782. */
  1783. class WXDLLIMPEXP_CORE wxEraseEvent : public wxEvent
  1784. {
  1785. public:
  1786. wxEraseEvent(int Id = 0, wxDC *dc = NULL)
  1787. : wxEvent(Id, wxEVT_ERASE_BACKGROUND),
  1788. m_dc(dc)
  1789. { }
  1790. wxEraseEvent(const wxEraseEvent& event)
  1791. : wxEvent(event),
  1792. m_dc(event.m_dc)
  1793. { }
  1794. wxDC *GetDC() const { return m_dc; }
  1795. virtual wxEvent *Clone() const { return new wxEraseEvent(*this); }
  1796. protected:
  1797. wxDC *m_dc;
  1798. private:
  1799. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxEraseEvent)
  1800. };
  1801. // Focus event class
  1802. /*
  1803. wxEVT_SET_FOCUS
  1804. wxEVT_KILL_FOCUS
  1805. */
  1806. class WXDLLIMPEXP_CORE wxFocusEvent : public wxEvent
  1807. {
  1808. public:
  1809. wxFocusEvent(wxEventType type = wxEVT_NULL, int winid = 0)
  1810. : wxEvent(winid, type)
  1811. { m_win = NULL; }
  1812. wxFocusEvent(const wxFocusEvent& event)
  1813. : wxEvent(event)
  1814. { m_win = event.m_win; }
  1815. // The window associated with this event is the window which had focus
  1816. // before for SET event and the window which will have focus for the KILL
  1817. // one. NB: it may be NULL in both cases!
  1818. wxWindow *GetWindow() const { return m_win; }
  1819. void SetWindow(wxWindow *win) { m_win = win; }
  1820. virtual wxEvent *Clone() const { return new wxFocusEvent(*this); }
  1821. private:
  1822. wxWindow *m_win;
  1823. private:
  1824. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFocusEvent)
  1825. };
  1826. // wxChildFocusEvent notifies the parent that a child has got the focus: unlike
  1827. // wxFocusEvent it is propagated upwards the window chain
  1828. class WXDLLIMPEXP_CORE wxChildFocusEvent : public wxCommandEvent
  1829. {
  1830. public:
  1831. wxChildFocusEvent(wxWindow *win = NULL);
  1832. wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
  1833. virtual wxEvent *Clone() const { return new wxChildFocusEvent(*this); }
  1834. private:
  1835. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxChildFocusEvent)
  1836. };
  1837. // Activate event class
  1838. /*
  1839. wxEVT_ACTIVATE
  1840. wxEVT_ACTIVATE_APP
  1841. wxEVT_HIBERNATE
  1842. */
  1843. class WXDLLIMPEXP_CORE wxActivateEvent : public wxEvent
  1844. {
  1845. public:
  1846. // Type of activation. For now we can only detect if it was by mouse or by
  1847. // some other method and even this is only available under wxMSW.
  1848. enum Reason
  1849. {
  1850. Reason_Mouse,
  1851. Reason_Unknown
  1852. };
  1853. wxActivateEvent(wxEventType type = wxEVT_NULL, bool active = true,
  1854. int Id = 0, Reason activationReason = Reason_Unknown)
  1855. : wxEvent(Id, type),
  1856. m_activationReason(activationReason)
  1857. {
  1858. m_active = active;
  1859. }
  1860. wxActivateEvent(const wxActivateEvent& event)
  1861. : wxEvent(event)
  1862. {
  1863. m_active = event.m_active;
  1864. m_activationReason = event.m_activationReason;
  1865. }
  1866. bool GetActive() const { return m_active; }
  1867. Reason GetActivationReason() const { return m_activationReason;}
  1868. virtual wxEvent *Clone() const { return new wxActivateEvent(*this); }
  1869. private:
  1870. bool m_active;
  1871. Reason m_activationReason;
  1872. private:
  1873. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxActivateEvent)
  1874. };
  1875. // InitDialog event class
  1876. /*
  1877. wxEVT_INIT_DIALOG
  1878. */
  1879. class WXDLLIMPEXP_CORE wxInitDialogEvent : public wxEvent
  1880. {
  1881. public:
  1882. wxInitDialogEvent(int Id = 0)
  1883. : wxEvent(Id, wxEVT_INIT_DIALOG)
  1884. { }
  1885. virtual wxEvent *Clone() const { return new wxInitDialogEvent(*this); }
  1886. private:
  1887. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxInitDialogEvent)
  1888. };
  1889. // Miscellaneous menu event class
  1890. /*
  1891. wxEVT_MENU_OPEN,
  1892. wxEVT_MENU_CLOSE,
  1893. wxEVT_MENU_HIGHLIGHT,
  1894. */
  1895. class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent
  1896. {
  1897. public:
  1898. wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL)
  1899. : wxEvent(winid, type)
  1900. { m_menuId = winid; m_menu = menu; }
  1901. wxMenuEvent(const wxMenuEvent& event)
  1902. : wxEvent(event)
  1903. { m_menuId = event.m_menuId; m_menu = event.m_menu; }
  1904. // only for wxEVT_MENU_HIGHLIGHT
  1905. int GetMenuId() const { return m_menuId; }
  1906. // only for wxEVT_MENU_OPEN/CLOSE
  1907. bool IsPopup() const { return m_menuId == wxID_ANY; }
  1908. // only for wxEVT_MENU_OPEN/CLOSE
  1909. wxMenu* GetMenu() const { return m_menu; }
  1910. virtual wxEvent *Clone() const { return new wxMenuEvent(*this); }
  1911. private:
  1912. int m_menuId;
  1913. wxMenu* m_menu;
  1914. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMenuEvent)
  1915. };
  1916. // Window close or session close event class
  1917. /*
  1918. wxEVT_CLOSE_WINDOW,
  1919. wxEVT_END_SESSION,
  1920. wxEVT_QUERY_END_SESSION
  1921. */
  1922. class WXDLLIMPEXP_CORE wxCloseEvent : public wxEvent
  1923. {
  1924. public:
  1925. wxCloseEvent(wxEventType type = wxEVT_NULL, int winid = 0)
  1926. : wxEvent(winid, type),
  1927. m_loggingOff(true),
  1928. m_veto(false), // should be false by default
  1929. m_canVeto(true) {}
  1930. wxCloseEvent(const wxCloseEvent& event)
  1931. : wxEvent(event),
  1932. m_loggingOff(event.m_loggingOff),
  1933. m_veto(event.m_veto),
  1934. m_canVeto(event.m_canVeto) {}
  1935. void SetLoggingOff(bool logOff) { m_loggingOff = logOff; }
  1936. bool GetLoggingOff() const
  1937. {
  1938. // m_loggingOff flag is only used by wxEVT_[QUERY_]END_SESSION, it
  1939. // doesn't make sense for wxEVT_CLOSE_WINDOW
  1940. wxASSERT_MSG( m_eventType != wxEVT_CLOSE_WINDOW,
  1941. wxT("this flag is for end session events only") );
  1942. return m_loggingOff;
  1943. }
  1944. void Veto(bool veto = true)
  1945. {
  1946. // GetVeto() will return false anyhow...
  1947. wxCHECK_RET( m_canVeto,
  1948. wxT("call to Veto() ignored (can't veto this event)") );
  1949. m_veto = veto;
  1950. }
  1951. void SetCanVeto(bool canVeto) { m_canVeto = canVeto; }
  1952. bool CanVeto() const { return m_canVeto; }
  1953. bool GetVeto() const { return m_canVeto && m_veto; }
  1954. virtual wxEvent *Clone() const { return new wxCloseEvent(*this); }
  1955. protected:
  1956. bool m_loggingOff,
  1957. m_veto,
  1958. m_canVeto;
  1959. private:
  1960. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCloseEvent)
  1961. };
  1962. /*
  1963. wxEVT_SHOW
  1964. */
  1965. class WXDLLIMPEXP_CORE wxShowEvent : public wxEvent
  1966. {
  1967. public:
  1968. wxShowEvent(int winid = 0, bool show = false)
  1969. : wxEvent(winid, wxEVT_SHOW)
  1970. { m_show = show; }
  1971. wxShowEvent(const wxShowEvent& event)
  1972. : wxEvent(event)
  1973. { m_show = event.m_show; }
  1974. void SetShow(bool show) { m_show = show; }
  1975. // return true if the window was shown, false if hidden
  1976. bool IsShown() const { return m_show; }
  1977. #if WXWIN_COMPATIBILITY_2_8
  1978. wxDEPRECATED( bool GetShow() const { return IsShown(); } )
  1979. #endif
  1980. virtual wxEvent *Clone() const { return new wxShowEvent(*this); }
  1981. protected:
  1982. bool m_show;
  1983. private:
  1984. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxShowEvent)
  1985. };
  1986. /*
  1987. wxEVT_ICONIZE
  1988. */
  1989. class WXDLLIMPEXP_CORE wxIconizeEvent : public wxEvent
  1990. {
  1991. public:
  1992. wxIconizeEvent(int winid = 0, bool iconized = true)
  1993. : wxEvent(winid, wxEVT_ICONIZE)
  1994. { m_iconized = iconized; }
  1995. wxIconizeEvent(const wxIconizeEvent& event)
  1996. : wxEvent(event)
  1997. { m_iconized = event.m_iconized; }
  1998. #if WXWIN_COMPATIBILITY_2_8
  1999. wxDEPRECATED( bool Iconized() const { return IsIconized(); } )
  2000. #endif
  2001. // return true if the frame was iconized, false if restored
  2002. bool IsIconized() const { return m_iconized; }
  2003. virtual wxEvent *Clone() const { return new wxIconizeEvent(*this); }
  2004. protected:
  2005. bool m_iconized;
  2006. private:
  2007. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIconizeEvent)
  2008. };
  2009. /*
  2010. wxEVT_MAXIMIZE
  2011. */
  2012. class WXDLLIMPEXP_CORE wxMaximizeEvent : public wxEvent
  2013. {
  2014. public:
  2015. wxMaximizeEvent(int winid = 0)
  2016. : wxEvent(winid, wxEVT_MAXIMIZE)
  2017. { }
  2018. virtual wxEvent *Clone() const { return new wxMaximizeEvent(*this); }
  2019. private:
  2020. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMaximizeEvent)
  2021. };
  2022. // Joystick event class
  2023. /*
  2024. wxEVT_JOY_BUTTON_DOWN,
  2025. wxEVT_JOY_BUTTON_UP,
  2026. wxEVT_JOY_MOVE,
  2027. wxEVT_JOY_ZMOVE
  2028. */
  2029. // Which joystick? Same as Windows ids so no conversion necessary.
  2030. enum
  2031. {
  2032. wxJOYSTICK1,
  2033. wxJOYSTICK2
  2034. };
  2035. // Which button is down?
  2036. enum
  2037. {
  2038. wxJOY_BUTTON_ANY = -1,
  2039. wxJOY_BUTTON1 = 1,
  2040. wxJOY_BUTTON2 = 2,
  2041. wxJOY_BUTTON3 = 4,
  2042. wxJOY_BUTTON4 = 8
  2043. };
  2044. class WXDLLIMPEXP_CORE wxJoystickEvent : public wxEvent
  2045. {
  2046. protected:
  2047. wxPoint m_pos;
  2048. int m_zPosition;
  2049. int m_buttonChange; // Which button changed?
  2050. int m_buttonState; // Which buttons are down?
  2051. int m_joyStick; // Which joystick?
  2052. public:
  2053. wxJoystickEvent(wxEventType type = wxEVT_NULL,
  2054. int state = 0,
  2055. int joystick = wxJOYSTICK1,
  2056. int change = 0)
  2057. : wxEvent(0, type),
  2058. m_pos(),
  2059. m_zPosition(0),
  2060. m_buttonChange(change),
  2061. m_buttonState(state),
  2062. m_joyStick(joystick)
  2063. {
  2064. }
  2065. wxJoystickEvent(const wxJoystickEvent& event)
  2066. : wxEvent(event),
  2067. m_pos(event.m_pos),
  2068. m_zPosition(event.m_zPosition),
  2069. m_buttonChange(event.m_buttonChange),
  2070. m_buttonState(event.m_buttonState),
  2071. m_joyStick(event.m_joyStick)
  2072. { }
  2073. wxPoint GetPosition() const { return m_pos; }
  2074. int GetZPosition() const { return m_zPosition; }
  2075. int GetButtonState() const { return m_buttonState; }
  2076. int GetButtonChange() const { return m_buttonChange; }
  2077. int GetJoystick() const { return m_joyStick; }
  2078. void SetJoystick(int stick) { m_joyStick = stick; }
  2079. void SetButtonState(int state) { m_buttonState = state; }
  2080. void SetButtonChange(int change) { m_buttonChange = change; }
  2081. void SetPosition(const wxPoint& pos) { m_pos = pos; }
  2082. void SetZPosition(int zPos) { m_zPosition = zPos; }
  2083. // Was it a button event? (*doesn't* mean: is any button *down*?)
  2084. bool IsButton() const { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) ||
  2085. (GetEventType() == wxEVT_JOY_BUTTON_UP)); }
  2086. // Was it a move event?
  2087. bool IsMove() const { return (GetEventType() == wxEVT_JOY_MOVE); }
  2088. // Was it a zmove event?
  2089. bool IsZMove() const { return (GetEventType() == wxEVT_JOY_ZMOVE); }
  2090. // Was it a down event from button 1, 2, 3, 4 or any?
  2091. bool ButtonDown(int but = wxJOY_BUTTON_ANY) const
  2092. { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) &&
  2093. ((but == wxJOY_BUTTON_ANY) || (but == m_buttonChange))); }
  2094. // Was it a up event from button 1, 2, 3 or any?
  2095. bool ButtonUp(int but = wxJOY_BUTTON_ANY) const
  2096. { return ((GetEventType() == wxEVT_JOY_BUTTON_UP) &&
  2097. ((but == wxJOY_BUTTON_ANY) || (but == m_buttonChange))); }
  2098. // Was the given button 1,2,3,4 or any in Down state?
  2099. bool ButtonIsDown(int but = wxJOY_BUTTON_ANY) const
  2100. { return (((but == wxJOY_BUTTON_ANY) && (m_buttonState != 0)) ||
  2101. ((m_buttonState & but) == but)); }
  2102. virtual wxEvent *Clone() const { return new wxJoystickEvent(*this); }
  2103. private:
  2104. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxJoystickEvent)
  2105. };
  2106. // Drop files event class
  2107. /*
  2108. wxEVT_DROP_FILES
  2109. */
  2110. class WXDLLIMPEXP_CORE wxDropFilesEvent : public wxEvent
  2111. {
  2112. public:
  2113. int m_noFiles;
  2114. wxPoint m_pos;
  2115. wxString* m_files;
  2116. wxDropFilesEvent(wxEventType type = wxEVT_NULL,
  2117. int noFiles = 0,
  2118. wxString *files = NULL)
  2119. : wxEvent(0, type),
  2120. m_noFiles(noFiles),
  2121. m_pos(),
  2122. m_files(files)
  2123. { }
  2124. // we need a copy ctor to avoid deleting m_files pointer twice
  2125. wxDropFilesEvent(const wxDropFilesEvent& other)
  2126. : wxEvent(other),
  2127. m_noFiles(other.m_noFiles),
  2128. m_pos(other.m_pos),
  2129. m_files(NULL)
  2130. {
  2131. m_files = new wxString[m_noFiles];
  2132. for ( int n = 0; n < m_noFiles; n++ )
  2133. {
  2134. m_files[n] = other.m_files[n];
  2135. }
  2136. }
  2137. virtual ~wxDropFilesEvent()
  2138. {
  2139. delete [] m_files;
  2140. }
  2141. wxPoint GetPosition() const { return m_pos; }
  2142. int GetNumberOfFiles() const { return m_noFiles; }
  2143. wxString *GetFiles() const { return m_files; }
  2144. virtual wxEvent *Clone() const { return new wxDropFilesEvent(*this); }
  2145. private:
  2146. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDropFilesEvent)
  2147. };
  2148. // Update UI event
  2149. /*
  2150. wxEVT_UPDATE_UI
  2151. */
  2152. // Whether to always send update events to windows, or
  2153. // to only send update events to those with the
  2154. // wxWS_EX_PROCESS_UI_UPDATES style.
  2155. enum wxUpdateUIMode
  2156. {
  2157. // Send UI update events to all windows
  2158. wxUPDATE_UI_PROCESS_ALL,
  2159. // Send UI update events to windows that have
  2160. // the wxWS_EX_PROCESS_UI_UPDATES flag specified
  2161. wxUPDATE_UI_PROCESS_SPECIFIED
  2162. };
  2163. class WXDLLIMPEXP_CORE wxUpdateUIEvent : public wxCommandEvent
  2164. {
  2165. public:
  2166. wxUpdateUIEvent(wxWindowID commandId = 0)
  2167. : wxCommandEvent(wxEVT_UPDATE_UI, commandId)
  2168. {
  2169. m_checked =
  2170. m_enabled =
  2171. m_shown =
  2172. m_setEnabled =
  2173. m_setShown =
  2174. m_setText =
  2175. m_setChecked = false;
  2176. }
  2177. wxUpdateUIEvent(const wxUpdateUIEvent& event)
  2178. : wxCommandEvent(event),
  2179. m_checked(event.m_checked),
  2180. m_enabled(event.m_enabled),
  2181. m_shown(event.m_shown),
  2182. m_setEnabled(event.m_setEnabled),
  2183. m_setShown(event.m_setShown),
  2184. m_setText(event.m_setText),
  2185. m_setChecked(event.m_setChecked),
  2186. m_text(event.m_text)
  2187. { }
  2188. bool GetChecked() const { return m_checked; }
  2189. bool GetEnabled() const { return m_enabled; }
  2190. bool GetShown() const { return m_shown; }
  2191. wxString GetText() const { return m_text; }
  2192. bool GetSetText() const { return m_setText; }
  2193. bool GetSetChecked() const { return m_setChecked; }
  2194. bool GetSetEnabled() const { return m_setEnabled; }
  2195. bool GetSetShown() const { return m_setShown; }
  2196. void Check(bool check) { m_checked = check; m_setChecked = true; }
  2197. void Enable(bool enable) { m_enabled = enable; m_setEnabled = true; }
  2198. void Show(bool show) { m_shown = show; m_setShown = true; }
  2199. void SetText(const wxString& text) { m_text = text; m_setText = true; }
  2200. // Sets the interval between updates in milliseconds.
  2201. // Set to -1 to disable updates, or to 0 to update as frequently as possible.
  2202. static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; }
  2203. // Returns the current interval between updates in milliseconds
  2204. static long GetUpdateInterval() { return sm_updateInterval; }
  2205. // Can we update this window?
  2206. static bool CanUpdate(wxWindowBase *win);
  2207. // Reset the update time to provide a delay until the next
  2208. // time we should update
  2209. static void ResetUpdateTime();
  2210. // Specify how wxWidgets will send update events: to
  2211. // all windows, or only to those which specify that they
  2212. // will process the events.
  2213. static void SetMode(wxUpdateUIMode mode) { sm_updateMode = mode; }
  2214. // Returns the UI update mode
  2215. static wxUpdateUIMode GetMode() { return sm_updateMode; }
  2216. virtual wxEvent *Clone() const { return new wxUpdateUIEvent(*this); }
  2217. protected:
  2218. bool m_checked;
  2219. bool m_enabled;
  2220. bool m_shown;
  2221. bool m_setEnabled;
  2222. bool m_setShown;
  2223. bool m_setText;
  2224. bool m_setChecked;
  2225. wxString m_text;
  2226. #if wxUSE_LONGLONG
  2227. static wxLongLong sm_lastUpdate;
  2228. #endif
  2229. static long sm_updateInterval;
  2230. static wxUpdateUIMode sm_updateMode;
  2231. private:
  2232. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxUpdateUIEvent)
  2233. };
  2234. /*
  2235. wxEVT_SYS_COLOUR_CHANGED
  2236. */
  2237. // TODO: shouldn't all events record the window ID?
  2238. class WXDLLIMPEXP_CORE wxSysColourChangedEvent : public wxEvent
  2239. {
  2240. public:
  2241. wxSysColourChangedEvent()
  2242. : wxEvent(0, wxEVT_SYS_COLOUR_CHANGED)
  2243. { }
  2244. virtual wxEvent *Clone() const { return new wxSysColourChangedEvent(*this); }
  2245. private:
  2246. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSysColourChangedEvent)
  2247. };
  2248. /*
  2249. wxEVT_MOUSE_CAPTURE_CHANGED
  2250. The window losing the capture receives this message
  2251. (even if it released the capture itself).
  2252. */
  2253. class WXDLLIMPEXP_CORE wxMouseCaptureChangedEvent : public wxEvent
  2254. {
  2255. public:
  2256. wxMouseCaptureChangedEvent(wxWindowID winid = 0, wxWindow* gainedCapture = NULL)
  2257. : wxEvent(winid, wxEVT_MOUSE_CAPTURE_CHANGED),
  2258. m_gainedCapture(gainedCapture)
  2259. { }
  2260. wxMouseCaptureChangedEvent(const wxMouseCaptureChangedEvent& event)
  2261. : wxEvent(event),
  2262. m_gainedCapture(event.m_gainedCapture)
  2263. { }
  2264. virtual wxEvent *Clone() const { return new wxMouseCaptureChangedEvent(*this); }
  2265. wxWindow* GetCapturedWindow() const { return m_gainedCapture; }
  2266. private:
  2267. wxWindow* m_gainedCapture;
  2268. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMouseCaptureChangedEvent)
  2269. };
  2270. /*
  2271. wxEVT_MOUSE_CAPTURE_LOST
  2272. The window losing the capture receives this message, unless it released it
  2273. it itself or unless wxWindow::CaptureMouse was called on another window
  2274. (and so capture will be restored when the new capturer releases it).
  2275. */
  2276. class WXDLLIMPEXP_CORE wxMouseCaptureLostEvent : public wxEvent
  2277. {
  2278. public:
  2279. wxMouseCaptureLostEvent(wxWindowID winid = 0)
  2280. : wxEvent(winid, wxEVT_MOUSE_CAPTURE_LOST)
  2281. {}
  2282. wxMouseCaptureLostEvent(const wxMouseCaptureLostEvent& event)
  2283. : wxEvent(event)
  2284. {}
  2285. virtual wxEvent *Clone() const { return new wxMouseCaptureLostEvent(*this); }
  2286. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMouseCaptureLostEvent)
  2287. };
  2288. /*
  2289. wxEVT_DISPLAY_CHANGED
  2290. */
  2291. class WXDLLIMPEXP_CORE wxDisplayChangedEvent : public wxEvent
  2292. {
  2293. private:
  2294. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDisplayChangedEvent)
  2295. public:
  2296. wxDisplayChangedEvent()
  2297. : wxEvent(0, wxEVT_DISPLAY_CHANGED)
  2298. { }
  2299. virtual wxEvent *Clone() const { return new wxDisplayChangedEvent(*this); }
  2300. };
  2301. /*
  2302. wxEVT_PALETTE_CHANGED
  2303. */
  2304. class WXDLLIMPEXP_CORE wxPaletteChangedEvent : public wxEvent
  2305. {
  2306. public:
  2307. wxPaletteChangedEvent(wxWindowID winid = 0)
  2308. : wxEvent(winid, wxEVT_PALETTE_CHANGED),
  2309. m_changedWindow(NULL)
  2310. { }
  2311. wxPaletteChangedEvent(const wxPaletteChangedEvent& event)
  2312. : wxEvent(event),
  2313. m_changedWindow(event.m_changedWindow)
  2314. { }
  2315. void SetChangedWindow(wxWindow* win) { m_changedWindow = win; }
  2316. wxWindow* GetChangedWindow() const { return m_changedWindow; }
  2317. virtual wxEvent *Clone() const { return new wxPaletteChangedEvent(*this); }
  2318. protected:
  2319. wxWindow* m_changedWindow;
  2320. private:
  2321. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPaletteChangedEvent)
  2322. };
  2323. /*
  2324. wxEVT_QUERY_NEW_PALETTE
  2325. Indicates the window is getting keyboard focus and should re-do its palette.
  2326. */
  2327. class WXDLLIMPEXP_CORE wxQueryNewPaletteEvent : public wxEvent
  2328. {
  2329. public:
  2330. wxQueryNewPaletteEvent(wxWindowID winid = 0)
  2331. : wxEvent(winid, wxEVT_QUERY_NEW_PALETTE),
  2332. m_paletteRealized(false)
  2333. { }
  2334. wxQueryNewPaletteEvent(const wxQueryNewPaletteEvent& event)
  2335. : wxEvent(event),
  2336. m_paletteRealized(event.m_paletteRealized)
  2337. { }
  2338. // App sets this if it changes the palette.
  2339. void SetPaletteRealized(bool realized) { m_paletteRealized = realized; }
  2340. bool GetPaletteRealized() const { return m_paletteRealized; }
  2341. virtual wxEvent *Clone() const { return new wxQueryNewPaletteEvent(*this); }
  2342. protected:
  2343. bool m_paletteRealized;
  2344. private:
  2345. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryNewPaletteEvent)
  2346. };
  2347. /*
  2348. Event generated by dialog navigation keys
  2349. wxEVT_NAVIGATION_KEY
  2350. */
  2351. // NB: don't derive from command event to avoid being propagated to the parent
  2352. class WXDLLIMPEXP_CORE wxNavigationKeyEvent : public wxEvent
  2353. {
  2354. public:
  2355. wxNavigationKeyEvent()
  2356. : wxEvent(0, wxEVT_NAVIGATION_KEY),
  2357. m_flags(IsForward | FromTab), // defaults are for TAB
  2358. m_focus(NULL)
  2359. {
  2360. m_propagationLevel = wxEVENT_PROPAGATE_NONE;
  2361. }
  2362. wxNavigationKeyEvent(const wxNavigationKeyEvent& event)
  2363. : wxEvent(event),
  2364. m_flags(event.m_flags),
  2365. m_focus(event.m_focus)
  2366. { }
  2367. // direction: forward (true) or backward (false)
  2368. bool GetDirection() const
  2369. { return (m_flags & IsForward) != 0; }
  2370. void SetDirection(bool bForward)
  2371. { if ( bForward ) m_flags |= IsForward; else m_flags &= ~IsForward; }
  2372. // it may be a window change event (MDI, notebook pages...) or a control
  2373. // change event
  2374. bool IsWindowChange() const
  2375. { return (m_flags & WinChange) != 0; }
  2376. void SetWindowChange(bool bIs)
  2377. { if ( bIs ) m_flags |= WinChange; else m_flags &= ~WinChange; }
  2378. // Set to true under MSW if the event was generated using the tab key.
  2379. // This is required for proper navogation over radio buttons
  2380. bool IsFromTab() const
  2381. { return (m_flags & FromTab) != 0; }
  2382. void SetFromTab(bool bIs)
  2383. { if ( bIs ) m_flags |= FromTab; else m_flags &= ~FromTab; }
  2384. // the child which has the focus currently (may be NULL - use
  2385. // wxWindow::FindFocus then)
  2386. wxWindow* GetCurrentFocus() const { return m_focus; }
  2387. void SetCurrentFocus(wxWindow *win) { m_focus = win; }
  2388. // Set flags
  2389. void SetFlags(long flags) { m_flags = flags; }
  2390. virtual wxEvent *Clone() const { return new wxNavigationKeyEvent(*this); }
  2391. enum wxNavigationKeyEventFlags
  2392. {
  2393. IsBackward = 0x0000,
  2394. IsForward = 0x0001,
  2395. WinChange = 0x0002,
  2396. FromTab = 0x0004
  2397. };
  2398. long m_flags;
  2399. wxWindow *m_focus;
  2400. private:
  2401. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNavigationKeyEvent)
  2402. };
  2403. // Window creation/destruction events: the first is sent as soon as window is
  2404. // created (i.e. the underlying GUI object exists), but when the C++ object is
  2405. // fully initialized (so virtual functions may be called). The second,
  2406. // wxEVT_DESTROY, is sent right before the window is destroyed - again, it's
  2407. // still safe to call virtual functions at this moment
  2408. /*
  2409. wxEVT_CREATE
  2410. wxEVT_DESTROY
  2411. */
  2412. class WXDLLIMPEXP_CORE wxWindowCreateEvent : public wxCommandEvent
  2413. {
  2414. public:
  2415. wxWindowCreateEvent(wxWindow *win = NULL);
  2416. wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
  2417. virtual wxEvent *Clone() const { return new wxWindowCreateEvent(*this); }
  2418. private:
  2419. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowCreateEvent)
  2420. };
  2421. class WXDLLIMPEXP_CORE wxWindowDestroyEvent : public wxCommandEvent
  2422. {
  2423. public:
  2424. wxWindowDestroyEvent(wxWindow *win = NULL);
  2425. wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
  2426. virtual wxEvent *Clone() const { return new wxWindowDestroyEvent(*this); }
  2427. private:
  2428. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowDestroyEvent)
  2429. };
  2430. // A help event is sent when the user clicks on a window in context-help mode.
  2431. /*
  2432. wxEVT_HELP
  2433. wxEVT_DETAILED_HELP
  2434. */
  2435. class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent
  2436. {
  2437. public:
  2438. // how was this help event generated?
  2439. enum Origin
  2440. {
  2441. Origin_Unknown, // unrecognized event source
  2442. Origin_Keyboard, // event generated from F1 key press
  2443. Origin_HelpButton // event from [?] button on the title bar (Windows)
  2444. };
  2445. wxHelpEvent(wxEventType type = wxEVT_NULL,
  2446. wxWindowID winid = 0,
  2447. const wxPoint& pt = wxDefaultPosition,
  2448. Origin origin = Origin_Unknown)
  2449. : wxCommandEvent(type, winid),
  2450. m_pos(pt),
  2451. m_origin(GuessOrigin(origin))
  2452. { }
  2453. wxHelpEvent(const wxHelpEvent& event)
  2454. : wxCommandEvent(event),
  2455. m_pos(event.m_pos),
  2456. m_target(event.m_target),
  2457. m_link(event.m_link),
  2458. m_origin(event.m_origin)
  2459. { }
  2460. // Position of event (in screen coordinates)
  2461. const wxPoint& GetPosition() const { return m_pos; }
  2462. void SetPosition(const wxPoint& pos) { m_pos = pos; }
  2463. // Optional link to further help
  2464. const wxString& GetLink() const { return m_link; }
  2465. void SetLink(const wxString& link) { m_link = link; }
  2466. // Optional target to display help in. E.g. a window specification
  2467. const wxString& GetTarget() const { return m_target; }
  2468. void SetTarget(const wxString& target) { m_target = target; }
  2469. virtual wxEvent *Clone() const { return new wxHelpEvent(*this); }
  2470. // optional indication of the event source
  2471. Origin GetOrigin() const { return m_origin; }
  2472. void SetOrigin(Origin origin) { m_origin = origin; }
  2473. protected:
  2474. wxPoint m_pos;
  2475. wxString m_target;
  2476. wxString m_link;
  2477. Origin m_origin;
  2478. // we can try to guess the event origin ourselves, even if none is
  2479. // specified in the ctor
  2480. static Origin GuessOrigin(Origin origin);
  2481. private:
  2482. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHelpEvent)
  2483. };
  2484. // A Clipboard Text event is sent when a window intercepts text copy/cut/paste
  2485. // message, i.e. the user has cut/copied/pasted data from/into a text control
  2486. // via ctrl-C/X/V, ctrl/shift-del/insert, a popup menu command, etc.
  2487. // NOTE : under windows these events are *NOT* generated automatically
  2488. // for a Rich Edit text control.
  2489. /*
  2490. wxEVT_TEXT_COPY
  2491. wxEVT_TEXT_CUT
  2492. wxEVT_TEXT_PASTE
  2493. */
  2494. class WXDLLIMPEXP_CORE wxClipboardTextEvent : public wxCommandEvent
  2495. {
  2496. public:
  2497. wxClipboardTextEvent(wxEventType type = wxEVT_NULL,
  2498. wxWindowID winid = 0)
  2499. : wxCommandEvent(type, winid)
  2500. { }
  2501. wxClipboardTextEvent(const wxClipboardTextEvent& event)
  2502. : wxCommandEvent(event)
  2503. { }
  2504. virtual wxEvent *Clone() const { return new wxClipboardTextEvent(*this); }
  2505. private:
  2506. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardTextEvent)
  2507. };
  2508. // A Context event is sent when the user right clicks on a window or
  2509. // presses Shift-F10
  2510. // NOTE : Under windows this is a repackaged WM_CONTETXMENU message
  2511. // Under other systems it may have to be generated from a right click event
  2512. /*
  2513. wxEVT_CONTEXT_MENU
  2514. */
  2515. class WXDLLIMPEXP_CORE wxContextMenuEvent : public wxCommandEvent
  2516. {
  2517. public:
  2518. wxContextMenuEvent(wxEventType type = wxEVT_NULL,
  2519. wxWindowID winid = 0,
  2520. const wxPoint& pt = wxDefaultPosition)
  2521. : wxCommandEvent(type, winid),
  2522. m_pos(pt)
  2523. { }
  2524. wxContextMenuEvent(const wxContextMenuEvent& event)
  2525. : wxCommandEvent(event),
  2526. m_pos(event.m_pos)
  2527. { }
  2528. // Position of event (in screen coordinates)
  2529. const wxPoint& GetPosition() const { return m_pos; }
  2530. void SetPosition(const wxPoint& pos) { m_pos = pos; }
  2531. virtual wxEvent *Clone() const { return new wxContextMenuEvent(*this); }
  2532. protected:
  2533. wxPoint m_pos;
  2534. private:
  2535. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxContextMenuEvent)
  2536. };
  2537. /* TODO
  2538. wxEVT_MOUSE_CAPTURE_CHANGED,
  2539. wxEVT_SETTING_CHANGED, // WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
  2540. // wxEVT_FONT_CHANGED, // WM_FONTCHANGE: roll into wxEVT_SETTING_CHANGED, but remember to propagate
  2541. // wxEVT_FONT_CHANGED to all other windows (maybe).
  2542. wxEVT_DRAW_ITEM, // Leave these three as virtual functions in wxControl?? Platform-specific.
  2543. wxEVT_MEASURE_ITEM,
  2544. wxEVT_COMPARE_ITEM
  2545. */
  2546. #endif // wxUSE_GUI
  2547. // ============================================================================
  2548. // event handler and related classes
  2549. // ============================================================================
  2550. // struct containing the members common to static and dynamic event tables
  2551. // entries
  2552. struct WXDLLIMPEXP_BASE wxEventTableEntryBase
  2553. {
  2554. wxEventTableEntryBase(int winid, int idLast,
  2555. wxEventFunctor* fn, wxObject *data)
  2556. : m_id(winid),
  2557. m_lastId(idLast),
  2558. m_fn(fn),
  2559. m_callbackUserData(data)
  2560. {
  2561. wxASSERT_MSG( idLast == wxID_ANY || winid <= idLast,
  2562. "invalid IDs range: lower bound > upper bound" );
  2563. }
  2564. wxEventTableEntryBase( const wxEventTableEntryBase &entry )
  2565. : m_id( entry.m_id ),
  2566. m_lastId( entry.m_lastId ),
  2567. m_fn( entry.m_fn ),
  2568. m_callbackUserData( entry.m_callbackUserData )
  2569. {
  2570. // This is a 'hack' to ensure that only one instance tries to delete
  2571. // the functor pointer. It is safe as long as the only place where the
  2572. // copy constructor is being called is when the static event tables are
  2573. // being initialized (a temporary instance is created and then this
  2574. // constructor is called).
  2575. const_cast<wxEventTableEntryBase&>( entry ).m_fn = NULL;
  2576. }
  2577. ~wxEventTableEntryBase()
  2578. {
  2579. delete m_fn;
  2580. }
  2581. // the range of ids for this entry: if m_lastId == wxID_ANY, the range
  2582. // consists only of m_id, otherwise it is m_id..m_lastId inclusive
  2583. int m_id,
  2584. m_lastId;
  2585. // function/method/functor to call
  2586. wxEventFunctor* m_fn;
  2587. // arbitrary user data associated with the callback
  2588. wxObject* m_callbackUserData;
  2589. private:
  2590. wxDECLARE_NO_ASSIGN_CLASS(wxEventTableEntryBase);
  2591. };
  2592. // an entry from a static event table
  2593. struct WXDLLIMPEXP_BASE wxEventTableEntry : public wxEventTableEntryBase
  2594. {
  2595. wxEventTableEntry(const int& evType, int winid, int idLast,
  2596. wxEventFunctor* fn, wxObject *data)
  2597. : wxEventTableEntryBase(winid, idLast, fn, data),
  2598. m_eventType(evType)
  2599. { }
  2600. // the reference to event type: this allows us to not care about the
  2601. // (undefined) order in which the event table entries and the event types
  2602. // are initialized: initially the value of this reference might be
  2603. // invalid, but by the time it is used for the first time, all global
  2604. // objects will have been initialized (including the event type constants)
  2605. // and so it will have the correct value when it is needed
  2606. const int& m_eventType;
  2607. private:
  2608. wxDECLARE_NO_ASSIGN_CLASS(wxEventTableEntry);
  2609. };
  2610. // an entry used in dynamic event table managed by wxEvtHandler::Connect()
  2611. struct WXDLLIMPEXP_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase
  2612. {
  2613. wxDynamicEventTableEntry(int evType, int winid, int idLast,
  2614. wxEventFunctor* fn, wxObject *data)
  2615. : wxEventTableEntryBase(winid, idLast, fn, data),
  2616. m_eventType(evType)
  2617. { }
  2618. // not a reference here as we can't keep a reference to a temporary int
  2619. // created to wrap the constant value typically passed to Connect() - nor
  2620. // do we need it
  2621. int m_eventType;
  2622. private:
  2623. wxDECLARE_NO_ASSIGN_CLASS(wxDynamicEventTableEntry);
  2624. };
  2625. // ----------------------------------------------------------------------------
  2626. // wxEventTable: an array of event entries terminated with {0, 0, 0, 0, 0}
  2627. // ----------------------------------------------------------------------------
  2628. struct WXDLLIMPEXP_BASE wxEventTable
  2629. {
  2630. const wxEventTable *baseTable; // base event table (next in chain)
  2631. const wxEventTableEntry *entries; // bottom of entry array
  2632. };
  2633. // ----------------------------------------------------------------------------
  2634. // wxEventHashTable: a helper of wxEvtHandler to speed up wxEventTable lookups.
  2635. // ----------------------------------------------------------------------------
  2636. WX_DEFINE_ARRAY_PTR(const wxEventTableEntry*, wxEventTableEntryPointerArray);
  2637. class WXDLLIMPEXP_BASE wxEventHashTable
  2638. {
  2639. private:
  2640. // Internal data structs
  2641. struct EventTypeTable
  2642. {
  2643. wxEventType eventType;
  2644. wxEventTableEntryPointerArray eventEntryTable;
  2645. };
  2646. typedef EventTypeTable* EventTypeTablePointer;
  2647. public:
  2648. // Constructor, needs the event table it needs to hash later on.
  2649. // Note: hashing of the event table is not done in the constructor as it
  2650. // can be that the event table is not yet full initialize, the hash
  2651. // will gets initialized when handling the first event look-up request.
  2652. wxEventHashTable(const wxEventTable &table);
  2653. // Destructor.
  2654. ~wxEventHashTable();
  2655. // Handle the given event, in other words search the event table hash
  2656. // and call self->ProcessEvent() if a match was found.
  2657. bool HandleEvent(wxEvent& event, wxEvtHandler *self);
  2658. // Clear table
  2659. void Clear();
  2660. #if wxUSE_MEMORY_TRACING
  2661. // Clear all tables: only used to work around problems in memory tracing
  2662. // code
  2663. static void ClearAll();
  2664. #endif // wxUSE_MEMORY_TRACING
  2665. protected:
  2666. // Init the hash table with the entries of the static event table.
  2667. void InitHashTable();
  2668. // Helper function of InitHashTable() to insert 1 entry into the hash table.
  2669. void AddEntry(const wxEventTableEntry &entry);
  2670. // Allocate and init with null pointers the base hash table.
  2671. void AllocEventTypeTable(size_t size);
  2672. // Grow the hash table in size and transfer all items currently
  2673. // in the table to the correct location in the new table.
  2674. void GrowEventTypeTable();
  2675. protected:
  2676. const wxEventTable &m_table;
  2677. bool m_rebuildHash;
  2678. size_t m_size;
  2679. EventTypeTablePointer *m_eventTypeTable;
  2680. static wxEventHashTable* sm_first;
  2681. wxEventHashTable* m_previous;
  2682. wxEventHashTable* m_next;
  2683. wxDECLARE_NO_COPY_CLASS(wxEventHashTable);
  2684. };
  2685. // ----------------------------------------------------------------------------
  2686. // wxEvtHandler: the base class for all objects handling wxWidgets events
  2687. // ----------------------------------------------------------------------------
  2688. class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject
  2689. , public wxTrackable
  2690. {
  2691. public:
  2692. wxEvtHandler();
  2693. virtual ~wxEvtHandler();
  2694. // Event handler chain
  2695. // -------------------
  2696. wxEvtHandler *GetNextHandler() const { return m_nextHandler; }
  2697. wxEvtHandler *GetPreviousHandler() const { return m_previousHandler; }
  2698. virtual void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; }
  2699. virtual void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; }
  2700. void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
  2701. bool GetEvtHandlerEnabled() const { return m_enabled; }
  2702. void Unlink();
  2703. bool IsUnlinked() const;
  2704. // Global event filters
  2705. // --------------------
  2706. // Add an event filter whose FilterEvent() method will be called for each
  2707. // and every event processed by wxWidgets. The filters are called in LIFO
  2708. // order and wxApp is registered as an event filter by default. The pointer
  2709. // must remain valid until it's removed with RemoveFilter() and is not
  2710. // deleted by wxEvtHandler.
  2711. static void AddFilter(wxEventFilter* filter);
  2712. // Remove a filter previously installed with AddFilter().
  2713. static void RemoveFilter(wxEventFilter* filter);
  2714. // Event queuing and processing
  2715. // ----------------------------
  2716. // Process an event right now: this can only be called from the main
  2717. // thread, use QueueEvent() for scheduling the events for
  2718. // processing from other threads.
  2719. virtual bool ProcessEvent(wxEvent& event);
  2720. // Process an event by calling ProcessEvent and handling any exceptions
  2721. // thrown by event handlers. It's mostly useful when processing wx events
  2722. // when called from C code (e.g. in GTK+ callback) when the exception
  2723. // wouldn't correctly propagate to wxEventLoop.
  2724. bool SafelyProcessEvent(wxEvent& event);
  2725. // NOTE: uses ProcessEvent()
  2726. // This method tries to process the event in this event handler, including
  2727. // any preprocessing done by TryBefore() and all the handlers chained to
  2728. // it, but excluding the post-processing done in TryAfter().
  2729. //
  2730. // It is meant to be called from ProcessEvent() only and is not virtual,
  2731. // additional event handlers can be hooked into the normal event processing
  2732. // logic using TryBefore() and TryAfter() hooks.
  2733. //
  2734. // You can also call it yourself to forward an event to another handler but
  2735. // without propagating it upwards if it's unhandled (this is usually
  2736. // unwanted when forwarding as the original handler would already do it if
  2737. // needed normally).
  2738. bool ProcessEventLocally(wxEvent& event);
  2739. // Schedule the given event to be processed later. It takes ownership of
  2740. // the event pointer, i.e. it will be deleted later. This is safe to call
  2741. // from multiple threads although you still need to ensure that wxString
  2742. // fields of the event object are deep copies and not use the same string
  2743. // buffer as other wxString objects in this thread.
  2744. virtual void QueueEvent(wxEvent *event);
  2745. // Add an event to be processed later: notice that this function is not
  2746. // safe to call from threads other than main, use QueueEvent()
  2747. virtual void AddPendingEvent(const wxEvent& event)
  2748. {
  2749. // notice that the thread-safety problem comes from the fact that
  2750. // Clone() doesn't make deep copies of wxString fields of wxEvent
  2751. // object and so the same wxString could be used from both threads when
  2752. // the event object is destroyed in this one -- QueueEvent() avoids
  2753. // this problem as the event pointer is not used any more in this
  2754. // thread at all after it is called.
  2755. QueueEvent(event.Clone());
  2756. }
  2757. void ProcessPendingEvents();
  2758. // NOTE: uses ProcessEvent()
  2759. void DeletePendingEvents();
  2760. #if wxUSE_THREADS
  2761. bool ProcessThreadEvent(const wxEvent& event);
  2762. // NOTE: uses AddPendingEvent(); call only from secondary threads
  2763. #endif
  2764. #ifdef wxHAS_CALL_AFTER
  2765. // Asynchronous method calls: these methods schedule the given method
  2766. // pointer for a later call (during the next idle event loop iteration).
  2767. //
  2768. // Notice that the method is called on this object itself, so the object
  2769. // CallAfter() is called on must have the correct dynamic type.
  2770. //
  2771. // These method can be used from another thread.
  2772. template <typename T>
  2773. void CallAfter(void (T::*method)())
  2774. {
  2775. QueueEvent(
  2776. new wxAsyncMethodCallEvent0<T>(static_cast<T*>(this), method)
  2777. );
  2778. }
  2779. // Notice that we use P1 and not T1 for the parameter to allow passing
  2780. // parameters that are convertible to the type taken by the method
  2781. // instead of being exactly the same, to be closer to the usual method call
  2782. // semantics.
  2783. template <typename T, typename T1, typename P1>
  2784. void CallAfter(void (T::*method)(T1 x1), P1 x1)
  2785. {
  2786. QueueEvent(
  2787. new wxAsyncMethodCallEvent1<T, T1>(
  2788. static_cast<T*>(this), method, x1)
  2789. );
  2790. }
  2791. template <typename T, typename T1, typename T2, typename P1, typename P2>
  2792. void CallAfter(void (T::*method)(T1 x1, T2 x2), P1 x1, P2 x2)
  2793. {
  2794. QueueEvent(
  2795. new wxAsyncMethodCallEvent2<T, T1, T2>(
  2796. static_cast<T*>(this), method, x1, x2)
  2797. );
  2798. }
  2799. template <typename T>
  2800. void CallAfter(const T& fn)
  2801. {
  2802. QueueEvent(new wxAsyncMethodCallEventFunctor<T>(this, fn));
  2803. }
  2804. #endif // wxHAS_CALL_AFTER
  2805. // Connecting and disconnecting
  2806. // ----------------------------
  2807. // These functions are used for old, untyped, event handlers and don't
  2808. // check that the type of the function passed to them actually matches the
  2809. // type of the event. They also only allow connecting events to methods of
  2810. // wxEvtHandler-derived classes.
  2811. //
  2812. // The template Connect() methods below are safer and allow connecting
  2813. // events to arbitrary functions or functors -- but require compiler
  2814. // support for templates.
  2815. // Dynamic association of a member function handler with the event handler,
  2816. // winid and event type
  2817. void Connect(int winid,
  2818. int lastId,
  2819. wxEventType eventType,
  2820. wxObjectEventFunction func,
  2821. wxObject *userData = NULL,
  2822. wxEvtHandler *eventSink = NULL)
  2823. {
  2824. DoBind(winid, lastId, eventType,
  2825. wxNewEventFunctor(eventType, func, eventSink),
  2826. userData);
  2827. }
  2828. // Convenience function: take just one id
  2829. void Connect(int winid,
  2830. wxEventType eventType,
  2831. wxObjectEventFunction func,
  2832. wxObject *userData = NULL,
  2833. wxEvtHandler *eventSink = NULL)
  2834. { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
  2835. // Even more convenient: without id (same as using id of wxID_ANY)
  2836. void Connect(wxEventType eventType,
  2837. wxObjectEventFunction func,
  2838. wxObject *userData = NULL,
  2839. wxEvtHandler *eventSink = NULL)
  2840. { Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); }
  2841. bool Disconnect(int winid,
  2842. int lastId,
  2843. wxEventType eventType,
  2844. wxObjectEventFunction func = NULL,
  2845. wxObject *userData = NULL,
  2846. wxEvtHandler *eventSink = NULL)
  2847. {
  2848. return DoUnbind(winid, lastId, eventType,
  2849. wxMakeEventFunctor(eventType, func, eventSink),
  2850. userData );
  2851. }
  2852. bool Disconnect(int winid = wxID_ANY,
  2853. wxEventType eventType = wxEVT_NULL,
  2854. wxObjectEventFunction func = NULL,
  2855. wxObject *userData = NULL,
  2856. wxEvtHandler *eventSink = NULL)
  2857. { return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); }
  2858. bool Disconnect(wxEventType eventType,
  2859. wxObjectEventFunction func,
  2860. wxObject *userData = NULL,
  2861. wxEvtHandler *eventSink = NULL)
  2862. { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
  2863. #ifdef wxHAS_EVENT_BIND
  2864. // Bind functions to an event:
  2865. template <typename EventTag, typename EventArg>
  2866. void Bind(const EventTag& eventType,
  2867. void (*function)(EventArg &),
  2868. int winid = wxID_ANY,
  2869. int lastId = wxID_ANY,
  2870. wxObject *userData = NULL)
  2871. {
  2872. DoBind(winid, lastId, eventType,
  2873. wxNewEventFunctor(eventType, function),
  2874. userData);
  2875. }
  2876. template <typename EventTag, typename EventArg>
  2877. bool Unbind(const EventTag& eventType,
  2878. void (*function)(EventArg &),
  2879. int winid = wxID_ANY,
  2880. int lastId = wxID_ANY,
  2881. wxObject *userData = NULL)
  2882. {
  2883. return DoUnbind(winid, lastId, eventType,
  2884. wxMakeEventFunctor(eventType, function),
  2885. userData);
  2886. }
  2887. // Bind functors to an event:
  2888. template <typename EventTag, typename Functor>
  2889. void Bind(const EventTag& eventType,
  2890. const Functor &functor,
  2891. int winid = wxID_ANY,
  2892. int lastId = wxID_ANY,
  2893. wxObject *userData = NULL)
  2894. {
  2895. DoBind(winid, lastId, eventType,
  2896. wxNewEventFunctor(eventType, functor),
  2897. userData);
  2898. }
  2899. template <typename EventTag, typename Functor>
  2900. bool Unbind(const EventTag& eventType,
  2901. const Functor &functor,
  2902. int winid = wxID_ANY,
  2903. int lastId = wxID_ANY,
  2904. wxObject *userData = NULL)
  2905. {
  2906. return DoUnbind(winid, lastId, eventType,
  2907. wxMakeEventFunctor(eventType, functor),
  2908. userData);
  2909. }
  2910. // Bind a method of a class (called on the specified handler which must
  2911. // be convertible to this class) object to an event:
  2912. template <typename EventTag, typename Class, typename EventArg, typename EventHandler>
  2913. void Bind(const EventTag &eventType,
  2914. void (Class::*method)(EventArg &),
  2915. EventHandler *handler,
  2916. int winid = wxID_ANY,
  2917. int lastId = wxID_ANY,
  2918. wxObject *userData = NULL)
  2919. {
  2920. DoBind(winid, lastId, eventType,
  2921. wxNewEventFunctor(eventType, method, handler),
  2922. userData);
  2923. }
  2924. template <typename EventTag, typename Class, typename EventArg, typename EventHandler>
  2925. bool Unbind(const EventTag &eventType,
  2926. void (Class::*method)(EventArg&),
  2927. EventHandler *handler,
  2928. int winid = wxID_ANY,
  2929. int lastId = wxID_ANY,
  2930. wxObject *userData = NULL )
  2931. {
  2932. return DoUnbind(winid, lastId, eventType,
  2933. wxMakeEventFunctor(eventType, method, handler),
  2934. userData);
  2935. }
  2936. #endif // wxHAS_EVENT_BIND
  2937. wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
  2938. // User data can be associated with each wxEvtHandler
  2939. void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
  2940. wxClientData *GetClientObject() const { return DoGetClientObject(); }
  2941. void SetClientData( void *data ) { DoSetClientData(data); }
  2942. void *GetClientData() const { return DoGetClientData(); }
  2943. // implementation from now on
  2944. // --------------------------
  2945. // check if the given event table entry matches this event by id (the check
  2946. // for the event type should be done by caller) and call the handler if it
  2947. // does
  2948. //
  2949. // return true if the event was processed, false otherwise (no match or the
  2950. // handler decided to skip the event)
  2951. static bool ProcessEventIfMatchesId(const wxEventTableEntryBase& tableEntry,
  2952. wxEvtHandler *handler,
  2953. wxEvent& event);
  2954. virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
  2955. bool SearchDynamicEventTable( wxEvent& event );
  2956. // Avoid problems at exit by cleaning up static hash table gracefully
  2957. void ClearEventHashTable() { GetEventHashTable().Clear(); }
  2958. void OnSinkDestroyed( wxEvtHandler *sink );
  2959. private:
  2960. void DoBind(int winid,
  2961. int lastId,
  2962. wxEventType eventType,
  2963. wxEventFunctor *func,
  2964. wxObject* userData = NULL);
  2965. bool DoUnbind(int winid,
  2966. int lastId,
  2967. wxEventType eventType,
  2968. const wxEventFunctor& func,
  2969. wxObject *userData = NULL);
  2970. static const wxEventTableEntry sm_eventTableEntries[];
  2971. protected:
  2972. // hooks for wxWindow used by ProcessEvent()
  2973. // -----------------------------------------
  2974. // this one is called before trying our own event table to allow plugging
  2975. // in the event handlers overriding the default logic, this is used by e.g.
  2976. // validators.
  2977. virtual bool TryBefore(wxEvent& event);
  2978. // This one is not a hook but just a helper which looks up the handler in
  2979. // this object itself.
  2980. //
  2981. // It is called from ProcessEventLocally() and normally shouldn't be called
  2982. // directly as doing it would ignore any chained event handlers
  2983. bool TryHereOnly(wxEvent& event);
  2984. // Another helper which simply calls pre-processing hook and then tries to
  2985. // handle the event at this handler level.
  2986. bool TryBeforeAndHere(wxEvent& event)
  2987. {
  2988. return TryBefore(event) || TryHereOnly(event);
  2989. }
  2990. // this one is called after failing to find the event handle in our own
  2991. // table to give a chance to the other windows to process it
  2992. //
  2993. // base class implementation passes the event to wxTheApp
  2994. virtual bool TryAfter(wxEvent& event);
  2995. #if WXWIN_COMPATIBILITY_2_8
  2996. // deprecated method: override TryBefore() instead of this one
  2997. wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
  2998. virtual bool TryValidator(wxEvent& WXUNUSED(event)), return false; )
  2999. wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
  3000. virtual bool TryParent(wxEvent& event), return DoTryApp(event); )
  3001. #endif // WXWIN_COMPATIBILITY_2_8
  3002. static const wxEventTable sm_eventTable;
  3003. virtual const wxEventTable *GetEventTable() const;
  3004. static wxEventHashTable sm_eventHashTable;
  3005. virtual wxEventHashTable& GetEventHashTable() const;
  3006. wxEvtHandler* m_nextHandler;
  3007. wxEvtHandler* m_previousHandler;
  3008. wxList* m_dynamicEvents;
  3009. wxList* m_pendingEvents;
  3010. #if wxUSE_THREADS
  3011. // critical section protecting m_pendingEvents
  3012. wxCriticalSection m_pendingEventsLock;
  3013. #endif // wxUSE_THREADS
  3014. // Is event handler enabled?
  3015. bool m_enabled;
  3016. // The user data: either an object which will be deleted by the container
  3017. // when it's deleted or some raw pointer which we do nothing with - only
  3018. // one type of data can be used with the given window (i.e. you cannot set
  3019. // the void data and then associate the container with wxClientData or vice
  3020. // versa)
  3021. union
  3022. {
  3023. wxClientData *m_clientObject;
  3024. void *m_clientData;
  3025. };
  3026. // what kind of data do we have?
  3027. wxClientDataType m_clientDataType;
  3028. // client data accessors
  3029. virtual void DoSetClientObject( wxClientData *data );
  3030. virtual wxClientData *DoGetClientObject() const;
  3031. virtual void DoSetClientData( void *data );
  3032. virtual void *DoGetClientData() const;
  3033. // Search tracker objects for event connection with this sink
  3034. wxEventConnectionRef *FindRefInTrackerList(wxEvtHandler *handler);
  3035. private:
  3036. // pass the event to wxTheApp instance, called from TryAfter()
  3037. bool DoTryApp(wxEvent& event);
  3038. // try to process events in all handlers chained to this one
  3039. bool DoTryChain(wxEvent& event);
  3040. // Head of the event filter linked list.
  3041. static wxEventFilter* ms_filterList;
  3042. DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler)
  3043. };
  3044. WX_DEFINE_ARRAY_WITH_DECL_PTR(wxEvtHandler *, wxEvtHandlerArray, class WXDLLIMPEXP_BASE);
  3045. // Define an inline method of wxObjectEventFunctor which couldn't be defined
  3046. // before wxEvtHandler declaration: at least Sun CC refuses to compile function
  3047. // calls through pointer to member for forward-declared classes (see #12452).
  3048. inline void wxObjectEventFunctor::operator()(wxEvtHandler *handler, wxEvent& event)
  3049. {
  3050. wxEvtHandler * const realHandler = m_handler ? m_handler : handler;
  3051. (realHandler->*m_method)(event);
  3052. }
  3053. // ----------------------------------------------------------------------------
  3054. // wxEventConnectionRef represents all connections between two event handlers
  3055. // and enables automatic disconnect when an event handler sink goes out of
  3056. // scope. Each connection/disconnect increases/decreases ref count, and
  3057. // when it reaches zero the node goes out of scope.
  3058. // ----------------------------------------------------------------------------
  3059. class wxEventConnectionRef : public wxTrackerNode
  3060. {
  3061. public:
  3062. wxEventConnectionRef() : m_src(NULL), m_sink(NULL), m_refCount(0) { }
  3063. wxEventConnectionRef(wxEvtHandler *src, wxEvtHandler *sink)
  3064. : m_src(src), m_sink(sink), m_refCount(1)
  3065. {
  3066. m_sink->AddNode(this);
  3067. }
  3068. // The sink is being destroyed
  3069. virtual void OnObjectDestroy( )
  3070. {
  3071. if ( m_src )
  3072. m_src->OnSinkDestroyed( m_sink );
  3073. delete this;
  3074. }
  3075. virtual wxEventConnectionRef *ToEventConnection() { return this; }
  3076. void IncRef() { m_refCount++; }
  3077. void DecRef()
  3078. {
  3079. if ( !--m_refCount )
  3080. {
  3081. // The sink holds the only external pointer to this object
  3082. if ( m_sink )
  3083. m_sink->RemoveNode(this);
  3084. delete this;
  3085. }
  3086. }
  3087. private:
  3088. wxEvtHandler *m_src,
  3089. *m_sink;
  3090. int m_refCount;
  3091. friend class wxEvtHandler;
  3092. wxDECLARE_NO_ASSIGN_CLASS(wxEventConnectionRef);
  3093. };
  3094. // Post a message to the given event handler which will be processed during the
  3095. // next event loop iteration.
  3096. //
  3097. // Notice that this one is not thread-safe, use wxQueueEvent()
  3098. inline void wxPostEvent(wxEvtHandler *dest, const wxEvent& event)
  3099. {
  3100. wxCHECK_RET( dest, "need an object to post event to" );
  3101. dest->AddPendingEvent(event);
  3102. }
  3103. // Wrapper around wxEvtHandler::QueueEvent(): adds an event for later
  3104. // processing, unlike wxPostEvent it is safe to use from different thread even
  3105. // for events with wxString members
  3106. inline void wxQueueEvent(wxEvtHandler *dest, wxEvent *event)
  3107. {
  3108. wxCHECK_RET( dest, "need an object to queue event for" );
  3109. dest->QueueEvent(event);
  3110. }
  3111. typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
  3112. typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&);
  3113. typedef void (wxEvtHandler::*wxThreadEventFunction)(wxThreadEvent&);
  3114. #define wxEventHandler(func) \
  3115. wxEVENT_HANDLER_CAST(wxEventFunction, func)
  3116. #define wxIdleEventHandler(func) \
  3117. wxEVENT_HANDLER_CAST(wxIdleEventFunction, func)
  3118. #define wxThreadEventHandler(func) \
  3119. wxEVENT_HANDLER_CAST(wxThreadEventFunction, func)
  3120. #if wxUSE_GUI
  3121. // ----------------------------------------------------------------------------
  3122. // wxEventBlocker: helper class to temporarily disable event handling for a window
  3123. // ----------------------------------------------------------------------------
  3124. class WXDLLIMPEXP_CORE wxEventBlocker : public wxEvtHandler
  3125. {
  3126. public:
  3127. wxEventBlocker(wxWindow *win, wxEventType type = wxEVT_ANY);
  3128. virtual ~wxEventBlocker();
  3129. void Block(wxEventType type)
  3130. {
  3131. m_eventsToBlock.push_back(type);
  3132. }
  3133. virtual bool ProcessEvent(wxEvent& event);
  3134. protected:
  3135. wxArrayInt m_eventsToBlock;
  3136. wxWindow *m_window;
  3137. wxDECLARE_NO_COPY_CLASS(wxEventBlocker);
  3138. };
  3139. typedef void (wxEvtHandler::*wxCommandEventFunction)(wxCommandEvent&);
  3140. typedef void (wxEvtHandler::*wxScrollEventFunction)(wxScrollEvent&);
  3141. typedef void (wxEvtHandler::*wxScrollWinEventFunction)(wxScrollWinEvent&);
  3142. typedef void (wxEvtHandler::*wxSizeEventFunction)(wxSizeEvent&);
  3143. typedef void (wxEvtHandler::*wxMoveEventFunction)(wxMoveEvent&);
  3144. typedef void (wxEvtHandler::*wxPaintEventFunction)(wxPaintEvent&);
  3145. typedef void (wxEvtHandler::*wxNcPaintEventFunction)(wxNcPaintEvent&);
  3146. typedef void (wxEvtHandler::*wxEraseEventFunction)(wxEraseEvent&);
  3147. typedef void (wxEvtHandler::*wxMouseEventFunction)(wxMouseEvent&);
  3148. typedef void (wxEvtHandler::*wxCharEventFunction)(wxKeyEvent&);
  3149. typedef void (wxEvtHandler::*wxFocusEventFunction)(wxFocusEvent&);
  3150. typedef void (wxEvtHandler::*wxChildFocusEventFunction)(wxChildFocusEvent&);
  3151. typedef void (wxEvtHandler::*wxActivateEventFunction)(wxActivateEvent&);
  3152. typedef void (wxEvtHandler::*wxMenuEventFunction)(wxMenuEvent&);
  3153. typedef void (wxEvtHandler::*wxJoystickEventFunction)(wxJoystickEvent&);
  3154. typedef void (wxEvtHandler::*wxDropFilesEventFunction)(wxDropFilesEvent&);
  3155. typedef void (wxEvtHandler::*wxInitDialogEventFunction)(wxInitDialogEvent&);
  3156. typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&);
  3157. typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&);
  3158. typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&);
  3159. typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&);
  3160. typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&);
  3161. typedef void (wxEvtHandler::*wxIconizeEventFunction)(wxIconizeEvent&);
  3162. typedef void (wxEvtHandler::*wxMaximizeEventFunction)(wxMaximizeEvent&);
  3163. typedef void (wxEvtHandler::*wxNavigationKeyEventFunction)(wxNavigationKeyEvent&);
  3164. typedef void (wxEvtHandler::*wxPaletteChangedEventFunction)(wxPaletteChangedEvent&);
  3165. typedef void (wxEvtHandler::*wxQueryNewPaletteEventFunction)(wxQueryNewPaletteEvent&);
  3166. typedef void (wxEvtHandler::*wxWindowCreateEventFunction)(wxWindowCreateEvent&);
  3167. typedef void (wxEvtHandler::*wxWindowDestroyEventFunction)(wxWindowDestroyEvent&);
  3168. typedef void (wxEvtHandler::*wxSetCursorEventFunction)(wxSetCursorEvent&);
  3169. typedef void (wxEvtHandler::*wxNotifyEventFunction)(wxNotifyEvent&);
  3170. typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
  3171. typedef void (wxEvtHandler::*wxContextMenuEventFunction)(wxContextMenuEvent&);
  3172. typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureChangedEvent&);
  3173. typedef void (wxEvtHandler::*wxMouseCaptureLostEventFunction)(wxMouseCaptureLostEvent&);
  3174. typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&);
  3175. #define wxCommandEventHandler(func) \
  3176. wxEVENT_HANDLER_CAST(wxCommandEventFunction, func)
  3177. #define wxScrollEventHandler(func) \
  3178. wxEVENT_HANDLER_CAST(wxScrollEventFunction, func)
  3179. #define wxScrollWinEventHandler(func) \
  3180. wxEVENT_HANDLER_CAST(wxScrollWinEventFunction, func)
  3181. #define wxSizeEventHandler(func) \
  3182. wxEVENT_HANDLER_CAST(wxSizeEventFunction, func)
  3183. #define wxMoveEventHandler(func) \
  3184. wxEVENT_HANDLER_CAST(wxMoveEventFunction, func)
  3185. #define wxPaintEventHandler(func) \
  3186. wxEVENT_HANDLER_CAST(wxPaintEventFunction, func)
  3187. #define wxNcPaintEventHandler(func) \
  3188. wxEVENT_HANDLER_CAST(wxNcPaintEventFunction, func)
  3189. #define wxEraseEventHandler(func) \
  3190. wxEVENT_HANDLER_CAST(wxEraseEventFunction, func)
  3191. #define wxMouseEventHandler(func) \
  3192. wxEVENT_HANDLER_CAST(wxMouseEventFunction, func)
  3193. #define wxCharEventHandler(func) \
  3194. wxEVENT_HANDLER_CAST(wxCharEventFunction, func)
  3195. #define wxKeyEventHandler(func) wxCharEventHandler(func)
  3196. #define wxFocusEventHandler(func) \
  3197. wxEVENT_HANDLER_CAST(wxFocusEventFunction, func)
  3198. #define wxChildFocusEventHandler(func) \
  3199. wxEVENT_HANDLER_CAST(wxChildFocusEventFunction, func)
  3200. #define wxActivateEventHandler(func) \
  3201. wxEVENT_HANDLER_CAST(wxActivateEventFunction, func)
  3202. #define wxMenuEventHandler(func) \
  3203. wxEVENT_HANDLER_CAST(wxMenuEventFunction, func)
  3204. #define wxJoystickEventHandler(func) \
  3205. wxEVENT_HANDLER_CAST(wxJoystickEventFunction, func)
  3206. #define wxDropFilesEventHandler(func) \
  3207. wxEVENT_HANDLER_CAST(wxDropFilesEventFunction, func)
  3208. #define wxInitDialogEventHandler(func) \
  3209. wxEVENT_HANDLER_CAST(wxInitDialogEventFunction, func)
  3210. #define wxSysColourChangedEventHandler(func) \
  3211. wxEVENT_HANDLER_CAST(wxSysColourChangedEventFunction, func)
  3212. #define wxDisplayChangedEventHandler(func) \
  3213. wxEVENT_HANDLER_CAST(wxDisplayChangedEventFunction, func)
  3214. #define wxUpdateUIEventHandler(func) \
  3215. wxEVENT_HANDLER_CAST(wxUpdateUIEventFunction, func)
  3216. #define wxCloseEventHandler(func) \
  3217. wxEVENT_HANDLER_CAST(wxCloseEventFunction, func)
  3218. #define wxShowEventHandler(func) \
  3219. wxEVENT_HANDLER_CAST(wxShowEventFunction, func)
  3220. #define wxIconizeEventHandler(func) \
  3221. wxEVENT_HANDLER_CAST(wxIconizeEventFunction, func)
  3222. #define wxMaximizeEventHandler(func) \
  3223. wxEVENT_HANDLER_CAST(wxMaximizeEventFunction, func)
  3224. #define wxNavigationKeyEventHandler(func) \
  3225. wxEVENT_HANDLER_CAST(wxNavigationKeyEventFunction, func)
  3226. #define wxPaletteChangedEventHandler(func) \
  3227. wxEVENT_HANDLER_CAST(wxPaletteChangedEventFunction, func)
  3228. #define wxQueryNewPaletteEventHandler(func) \
  3229. wxEVENT_HANDLER_CAST(wxQueryNewPaletteEventFunction, func)
  3230. #define wxWindowCreateEventHandler(func) \
  3231. wxEVENT_HANDLER_CAST(wxWindowCreateEventFunction, func)
  3232. #define wxWindowDestroyEventHandler(func) \
  3233. wxEVENT_HANDLER_CAST(wxWindowDestroyEventFunction, func)
  3234. #define wxSetCursorEventHandler(func) \
  3235. wxEVENT_HANDLER_CAST(wxSetCursorEventFunction, func)
  3236. #define wxNotifyEventHandler(func) \
  3237. wxEVENT_HANDLER_CAST(wxNotifyEventFunction, func)
  3238. #define wxHelpEventHandler(func) \
  3239. wxEVENT_HANDLER_CAST(wxHelpEventFunction, func)
  3240. #define wxContextMenuEventHandler(func) \
  3241. wxEVENT_HANDLER_CAST(wxContextMenuEventFunction, func)
  3242. #define wxMouseCaptureChangedEventHandler(func) \
  3243. wxEVENT_HANDLER_CAST(wxMouseCaptureChangedEventFunction, func)
  3244. #define wxMouseCaptureLostEventHandler(func) \
  3245. wxEVENT_HANDLER_CAST(wxMouseCaptureLostEventFunction, func)
  3246. #define wxClipboardTextEventHandler(func) \
  3247. wxEVENT_HANDLER_CAST(wxClipboardTextEventFunction, func)
  3248. #endif // wxUSE_GUI
  3249. // N.B. In GNU-WIN32, you *have* to take the address of a member function
  3250. // (use &) or the compiler crashes...
  3251. #define wxDECLARE_EVENT_TABLE() \
  3252. private: \
  3253. static const wxEventTableEntry sm_eventTableEntries[]; \
  3254. protected: \
  3255. static const wxEventTable sm_eventTable; \
  3256. virtual const wxEventTable* GetEventTable() const; \
  3257. static wxEventHashTable sm_eventHashTable; \
  3258. virtual wxEventHashTable& GetEventHashTable() const
  3259. // N.B.: when building DLL with Borland C++ 5.5 compiler, you must initialize
  3260. // sm_eventTable before using it in GetEventTable() or the compiler gives
  3261. // E2233 (see http://groups.google.com/groups?selm=397dcc8a%241_2%40dnews)
  3262. #define wxBEGIN_EVENT_TABLE(theClass, baseClass) \
  3263. const wxEventTable theClass::sm_eventTable = \
  3264. { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \
  3265. const wxEventTable *theClass::GetEventTable() const \
  3266. { return &theClass::sm_eventTable; } \
  3267. wxEventHashTable theClass::sm_eventHashTable(theClass::sm_eventTable); \
  3268. wxEventHashTable &theClass::GetEventHashTable() const \
  3269. { return theClass::sm_eventHashTable; } \
  3270. const wxEventTableEntry theClass::sm_eventTableEntries[] = { \
  3271. #define wxBEGIN_EVENT_TABLE_TEMPLATE1(theClass, baseClass, T1) \
  3272. template<typename T1> \
  3273. const wxEventTable theClass<T1>::sm_eventTable = \
  3274. { &baseClass::sm_eventTable, &theClass<T1>::sm_eventTableEntries[0] }; \
  3275. template<typename T1> \
  3276. const wxEventTable *theClass<T1>::GetEventTable() const \
  3277. { return &theClass<T1>::sm_eventTable; } \
  3278. template<typename T1> \
  3279. wxEventHashTable theClass<T1>::sm_eventHashTable(theClass<T1>::sm_eventTable); \
  3280. template<typename T1> \
  3281. wxEventHashTable &theClass<T1>::GetEventHashTable() const \
  3282. { return theClass<T1>::sm_eventHashTable; } \
  3283. template<typename T1> \
  3284. const wxEventTableEntry theClass<T1>::sm_eventTableEntries[] = { \
  3285. #define wxBEGIN_EVENT_TABLE_TEMPLATE2(theClass, baseClass, T1, T2) \
  3286. template<typename T1, typename T2> \
  3287. const wxEventTable theClass<T1, T2>::sm_eventTable = \
  3288. { &baseClass::sm_eventTable, &theClass<T1, T2>::sm_eventTableEntries[0] }; \
  3289. template<typename T1, typename T2> \
  3290. const wxEventTable *theClass<T1, T2>::GetEventTable() const \
  3291. { return &theClass<T1, T2>::sm_eventTable; } \
  3292. template<typename T1, typename T2> \
  3293. wxEventHashTable theClass<T1, T2>::sm_eventHashTable(theClass<T1, T2>::sm_eventTable); \
  3294. template<typename T1, typename T2> \
  3295. wxEventHashTable &theClass<T1, T2>::GetEventHashTable() const \
  3296. { return theClass<T1, T2>::sm_eventHashTable; } \
  3297. template<typename T1, typename T2> \
  3298. const wxEventTableEntry theClass<T1, T2>::sm_eventTableEntries[] = { \
  3299. #define wxBEGIN_EVENT_TABLE_TEMPLATE3(theClass, baseClass, T1, T2, T3) \
  3300. template<typename T1, typename T2, typename T3> \
  3301. const wxEventTable theClass<T1, T2, T3>::sm_eventTable = \
  3302. { &baseClass::sm_eventTable, &theClass<T1, T2, T3>::sm_eventTableEntries[0] }; \
  3303. template<typename T1, typename T2, typename T3> \
  3304. const wxEventTable *theClass<T1, T2, T3>::GetEventTable() const \
  3305. { return &theClass<T1, T2, T3>::sm_eventTable; } \
  3306. template<typename T1, typename T2, typename T3> \
  3307. wxEventHashTable theClass<T1, T2, T3>::sm_eventHashTable(theClass<T1, T2, T3>::sm_eventTable); \
  3308. template<typename T1, typename T2, typename T3> \
  3309. wxEventHashTable &theClass<T1, T2, T3>::GetEventHashTable() const \
  3310. { return theClass<T1, T2, T3>::sm_eventHashTable; } \
  3311. template<typename T1, typename T2, typename T3> \
  3312. const wxEventTableEntry theClass<T1, T2, T3>::sm_eventTableEntries[] = { \
  3313. #define wxBEGIN_EVENT_TABLE_TEMPLATE4(theClass, baseClass, T1, T2, T3, T4) \
  3314. template<typename T1, typename T2, typename T3, typename T4> \
  3315. const wxEventTable theClass<T1, T2, T3, T4>::sm_eventTable = \
  3316. { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4>::sm_eventTableEntries[0] }; \
  3317. template<typename T1, typename T2, typename T3, typename T4> \
  3318. const wxEventTable *theClass<T1, T2, T3, T4>::GetEventTable() const \
  3319. { return &theClass<T1, T2, T3, T4>::sm_eventTable; } \
  3320. template<typename T1, typename T2, typename T3, typename T4> \
  3321. wxEventHashTable theClass<T1, T2, T3, T4>::sm_eventHashTable(theClass<T1, T2, T3, T4>::sm_eventTable); \
  3322. template<typename T1, typename T2, typename T3, typename T4> \
  3323. wxEventHashTable &theClass<T1, T2, T3, T4>::GetEventHashTable() const \
  3324. { return theClass<T1, T2, T3, T4>::sm_eventHashTable; } \
  3325. template<typename T1, typename T2, typename T3, typename T4> \
  3326. const wxEventTableEntry theClass<T1, T2, T3, T4>::sm_eventTableEntries[] = { \
  3327. #define wxBEGIN_EVENT_TABLE_TEMPLATE5(theClass, baseClass, T1, T2, T3, T4, T5) \
  3328. template<typename T1, typename T2, typename T3, typename T4, typename T5> \
  3329. const wxEventTable theClass<T1, T2, T3, T4, T5>::sm_eventTable = \
  3330. { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4, T5>::sm_eventTableEntries[0] }; \
  3331. template<typename T1, typename T2, typename T3, typename T4, typename T5> \
  3332. const wxEventTable *theClass<T1, T2, T3, T4, T5>::GetEventTable() const \
  3333. { return &theClass<T1, T2, T3, T4, T5>::sm_eventTable; } \
  3334. template<typename T1, typename T2, typename T3, typename T4, typename T5> \
  3335. wxEventHashTable theClass<T1, T2, T3, T4, T5>::sm_eventHashTable(theClass<T1, T2, T3, T4, T5>::sm_eventTable); \
  3336. template<typename T1, typename T2, typename T3, typename T4, typename T5> \
  3337. wxEventHashTable &theClass<T1, T2, T3, T4, T5>::GetEventHashTable() const \
  3338. { return theClass<T1, T2, T3, T4, T5>::sm_eventHashTable; } \
  3339. template<typename T1, typename T2, typename T3, typename T4, typename T5> \
  3340. const wxEventTableEntry theClass<T1, T2, T3, T4, T5>::sm_eventTableEntries[] = { \
  3341. #define wxBEGIN_EVENT_TABLE_TEMPLATE7(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7) \
  3342. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
  3343. const wxEventTable theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTable = \
  3344. { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTableEntries[0] }; \
  3345. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
  3346. const wxEventTable *theClass<T1, T2, T3, T4, T5, T6, T7>::GetEventTable() const \
  3347. { return &theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTable; } \
  3348. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
  3349. wxEventHashTable theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventHashTable(theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTable); \
  3350. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
  3351. wxEventHashTable &theClass<T1, T2, T3, T4, T5, T6, T7>::GetEventHashTable() const \
  3352. { return theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventHashTable; } \
  3353. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
  3354. const wxEventTableEntry theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTableEntries[] = { \
  3355. #define wxBEGIN_EVENT_TABLE_TEMPLATE8(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7, T8) \
  3356. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
  3357. const wxEventTable theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTable = \
  3358. { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTableEntries[0] }; \
  3359. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
  3360. const wxEventTable *theClass<T1, T2, T3, T4, T5, T6, T7, T8>::GetEventTable() const \
  3361. { return &theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTable; } \
  3362. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
  3363. wxEventHashTable theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventHashTable(theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTable); \
  3364. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
  3365. wxEventHashTable &theClass<T1, T2, T3, T4, T5, T6, T7, T8>::GetEventHashTable() const \
  3366. { return theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventHashTable; } \
  3367. template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
  3368. const wxEventTableEntry theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTableEntries[] = { \
  3369. #define wxEND_EVENT_TABLE() \
  3370. wxDECLARE_EVENT_TABLE_TERMINATOR() };
  3371. /*
  3372. * Event table macros
  3373. */
  3374. // helpers for writing shorter code below: declare an event macro taking 2, 1
  3375. // or none ids (the missing ids default to wxID_ANY)
  3376. //
  3377. // macro arguments:
  3378. // - evt one of wxEVT_XXX constants
  3379. // - id1, id2 ids of the first/last id
  3380. // - fn the function (should be cast to the right type)
  3381. #define wx__DECLARE_EVT2(evt, id1, id2, fn) \
  3382. wxDECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL),
  3383. #define wx__DECLARE_EVT1(evt, id, fn) \
  3384. wx__DECLARE_EVT2(evt, id, wxID_ANY, fn)
  3385. #define wx__DECLARE_EVT0(evt, fn) \
  3386. wx__DECLARE_EVT1(evt, wxID_ANY, fn)
  3387. // Generic events
  3388. #define EVT_CUSTOM(event, winid, func) \
  3389. wx__DECLARE_EVT1(event, winid, wxEventHandler(func))
  3390. #define EVT_CUSTOM_RANGE(event, id1, id2, func) \
  3391. wx__DECLARE_EVT2(event, id1, id2, wxEventHandler(func))
  3392. // EVT_COMMAND
  3393. #define EVT_COMMAND(winid, event, func) \
  3394. wx__DECLARE_EVT1(event, winid, wxCommandEventHandler(func))
  3395. #define EVT_COMMAND_RANGE(id1, id2, event, func) \
  3396. wx__DECLARE_EVT2(event, id1, id2, wxCommandEventHandler(func))
  3397. #define EVT_NOTIFY(event, winid, func) \
  3398. wx__DECLARE_EVT1(event, winid, wxNotifyEventHandler(func))
  3399. #define EVT_NOTIFY_RANGE(event, id1, id2, func) \
  3400. wx__DECLARE_EVT2(event, id1, id2, wxNotifyEventHandler(func))
  3401. // Miscellaneous
  3402. #define EVT_SIZE(func) wx__DECLARE_EVT0(wxEVT_SIZE, wxSizeEventHandler(func))
  3403. #define EVT_SIZING(func) wx__DECLARE_EVT0(wxEVT_SIZING, wxSizeEventHandler(func))
  3404. #define EVT_MOVE(func) wx__DECLARE_EVT0(wxEVT_MOVE, wxMoveEventHandler(func))
  3405. #define EVT_MOVING(func) wx__DECLARE_EVT0(wxEVT_MOVING, wxMoveEventHandler(func))
  3406. #define EVT_MOVE_START(func) wx__DECLARE_EVT0(wxEVT_MOVE_START, wxMoveEventHandler(func))
  3407. #define EVT_MOVE_END(func) wx__DECLARE_EVT0(wxEVT_MOVE_END, wxMoveEventHandler(func))
  3408. #define EVT_CLOSE(func) wx__DECLARE_EVT0(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(func))
  3409. #define EVT_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_END_SESSION, wxCloseEventHandler(func))
  3410. #define EVT_QUERY_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_QUERY_END_SESSION, wxCloseEventHandler(func))
  3411. #define EVT_PAINT(func) wx__DECLARE_EVT0(wxEVT_PAINT, wxPaintEventHandler(func))
  3412. #define EVT_NC_PAINT(func) wx__DECLARE_EVT0(wxEVT_NC_PAINT, wxNcPaintEventHandler(func))
  3413. #define EVT_ERASE_BACKGROUND(func) wx__DECLARE_EVT0(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(func))
  3414. #define EVT_CHAR(func) wx__DECLARE_EVT0(wxEVT_CHAR, wxCharEventHandler(func))
  3415. #define EVT_KEY_DOWN(func) wx__DECLARE_EVT0(wxEVT_KEY_DOWN, wxKeyEventHandler(func))
  3416. #define EVT_KEY_UP(func) wx__DECLARE_EVT0(wxEVT_KEY_UP, wxKeyEventHandler(func))
  3417. #if wxUSE_HOTKEY
  3418. #define EVT_HOTKEY(winid, func) wx__DECLARE_EVT1(wxEVT_HOTKEY, winid, wxCharEventHandler(func))
  3419. #endif
  3420. #define EVT_CHAR_HOOK(func) wx__DECLARE_EVT0(wxEVT_CHAR_HOOK, wxCharEventHandler(func))
  3421. #define EVT_MENU_OPEN(func) wx__DECLARE_EVT0(wxEVT_MENU_OPEN, wxMenuEventHandler(func))
  3422. #define EVT_MENU_CLOSE(func) wx__DECLARE_EVT0(wxEVT_MENU_CLOSE, wxMenuEventHandler(func))
  3423. #define EVT_MENU_HIGHLIGHT(winid, func) wx__DECLARE_EVT1(wxEVT_MENU_HIGHLIGHT, winid, wxMenuEventHandler(func))
  3424. #define EVT_MENU_HIGHLIGHT_ALL(func) wx__DECLARE_EVT0(wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler(func))
  3425. #define EVT_SET_FOCUS(func) wx__DECLARE_EVT0(wxEVT_SET_FOCUS, wxFocusEventHandler(func))
  3426. #define EVT_KILL_FOCUS(func) wx__DECLARE_EVT0(wxEVT_KILL_FOCUS, wxFocusEventHandler(func))
  3427. #define EVT_CHILD_FOCUS(func) wx__DECLARE_EVT0(wxEVT_CHILD_FOCUS, wxChildFocusEventHandler(func))
  3428. #define EVT_ACTIVATE(func) wx__DECLARE_EVT0(wxEVT_ACTIVATE, wxActivateEventHandler(func))
  3429. #define EVT_ACTIVATE_APP(func) wx__DECLARE_EVT0(wxEVT_ACTIVATE_APP, wxActivateEventHandler(func))
  3430. #define EVT_HIBERNATE(func) wx__DECLARE_EVT0(wxEVT_HIBERNATE, wxActivateEventHandler(func))
  3431. #define EVT_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_END_SESSION, wxCloseEventHandler(func))
  3432. #define EVT_QUERY_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_QUERY_END_SESSION, wxCloseEventHandler(func))
  3433. #define EVT_DROP_FILES(func) wx__DECLARE_EVT0(wxEVT_DROP_FILES, wxDropFilesEventHandler(func))
  3434. #define EVT_INIT_DIALOG(func) wx__DECLARE_EVT0(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(func))
  3435. #define EVT_SYS_COLOUR_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler(func))
  3436. #define EVT_DISPLAY_CHANGED(func) wx__DECLARE_EVT0(wxEVT_DISPLAY_CHANGED, wxDisplayChangedEventHandler(func))
  3437. #define EVT_SHOW(func) wx__DECLARE_EVT0(wxEVT_SHOW, wxShowEventHandler(func))
  3438. #define EVT_MAXIMIZE(func) wx__DECLARE_EVT0(wxEVT_MAXIMIZE, wxMaximizeEventHandler(func))
  3439. #define EVT_ICONIZE(func) wx__DECLARE_EVT0(wxEVT_ICONIZE, wxIconizeEventHandler(func))
  3440. #define EVT_NAVIGATION_KEY(func) wx__DECLARE_EVT0(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(func))
  3441. #define EVT_PALETTE_CHANGED(func) wx__DECLARE_EVT0(wxEVT_PALETTE_CHANGED, wxPaletteChangedEventHandler(func))
  3442. #define EVT_QUERY_NEW_PALETTE(func) wx__DECLARE_EVT0(wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEventHandler(func))
  3443. #define EVT_WINDOW_CREATE(func) wx__DECLARE_EVT0(wxEVT_CREATE, wxWindowCreateEventHandler(func))
  3444. #define EVT_WINDOW_DESTROY(func) wx__DECLARE_EVT0(wxEVT_DESTROY, wxWindowDestroyEventHandler(func))
  3445. #define EVT_SET_CURSOR(func) wx__DECLARE_EVT0(wxEVT_SET_CURSOR, wxSetCursorEventHandler(func))
  3446. #define EVT_MOUSE_CAPTURE_CHANGED(func) wx__DECLARE_EVT0(wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEventHandler(func))
  3447. #define EVT_MOUSE_CAPTURE_LOST(func) wx__DECLARE_EVT0(wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEventHandler(func))
  3448. // Mouse events
  3449. #define EVT_LEFT_DOWN(func) wx__DECLARE_EVT0(wxEVT_LEFT_DOWN, wxMouseEventHandler(func))
  3450. #define EVT_LEFT_UP(func) wx__DECLARE_EVT0(wxEVT_LEFT_UP, wxMouseEventHandler(func))
  3451. #define EVT_MIDDLE_DOWN(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(func))
  3452. #define EVT_MIDDLE_UP(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_UP, wxMouseEventHandler(func))
  3453. #define EVT_RIGHT_DOWN(func) wx__DECLARE_EVT0(wxEVT_RIGHT_DOWN, wxMouseEventHandler(func))
  3454. #define EVT_RIGHT_UP(func) wx__DECLARE_EVT0(wxEVT_RIGHT_UP, wxMouseEventHandler(func))
  3455. #define EVT_MOTION(func) wx__DECLARE_EVT0(wxEVT_MOTION, wxMouseEventHandler(func))
  3456. #define EVT_LEFT_DCLICK(func) wx__DECLARE_EVT0(wxEVT_LEFT_DCLICK, wxMouseEventHandler(func))
  3457. #define EVT_MIDDLE_DCLICK(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(func))
  3458. #define EVT_RIGHT_DCLICK(func) wx__DECLARE_EVT0(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(func))
  3459. #define EVT_LEAVE_WINDOW(func) wx__DECLARE_EVT0(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(func))
  3460. #define EVT_ENTER_WINDOW(func) wx__DECLARE_EVT0(wxEVT_ENTER_WINDOW, wxMouseEventHandler(func))
  3461. #define EVT_MOUSEWHEEL(func) wx__DECLARE_EVT0(wxEVT_MOUSEWHEEL, wxMouseEventHandler(func))
  3462. #define EVT_MOUSE_AUX1_DOWN(func) wx__DECLARE_EVT0(wxEVT_AUX1_DOWN, wxMouseEventHandler(func))
  3463. #define EVT_MOUSE_AUX1_UP(func) wx__DECLARE_EVT0(wxEVT_AUX1_UP, wxMouseEventHandler(func))
  3464. #define EVT_MOUSE_AUX1_DCLICK(func) wx__DECLARE_EVT0(wxEVT_AUX1_DCLICK, wxMouseEventHandler(func))
  3465. #define EVT_MOUSE_AUX2_DOWN(func) wx__DECLARE_EVT0(wxEVT_AUX2_DOWN, wxMouseEventHandler(func))
  3466. #define EVT_MOUSE_AUX2_UP(func) wx__DECLARE_EVT0(wxEVT_AUX2_UP, wxMouseEventHandler(func))
  3467. #define EVT_MOUSE_AUX2_DCLICK(func) wx__DECLARE_EVT0(wxEVT_AUX2_DCLICK, wxMouseEventHandler(func))
  3468. // All mouse events
  3469. #define EVT_MOUSE_EVENTS(func) \
  3470. EVT_LEFT_DOWN(func) \
  3471. EVT_LEFT_UP(func) \
  3472. EVT_LEFT_DCLICK(func) \
  3473. EVT_MIDDLE_DOWN(func) \
  3474. EVT_MIDDLE_UP(func) \
  3475. EVT_MIDDLE_DCLICK(func) \
  3476. EVT_RIGHT_DOWN(func) \
  3477. EVT_RIGHT_UP(func) \
  3478. EVT_RIGHT_DCLICK(func) \
  3479. EVT_MOUSE_AUX1_DOWN(func) \
  3480. EVT_MOUSE_AUX1_UP(func) \
  3481. EVT_MOUSE_AUX1_DCLICK(func) \
  3482. EVT_MOUSE_AUX2_DOWN(func) \
  3483. EVT_MOUSE_AUX2_UP(func) \
  3484. EVT_MOUSE_AUX2_DCLICK(func) \
  3485. EVT_MOTION(func) \
  3486. EVT_LEAVE_WINDOW(func) \
  3487. EVT_ENTER_WINDOW(func) \
  3488. EVT_MOUSEWHEEL(func)
  3489. // Scrolling from wxWindow (sent to wxScrolledWindow)
  3490. #define EVT_SCROLLWIN_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_TOP, wxScrollWinEventHandler(func))
  3491. #define EVT_SCROLLWIN_BOTTOM(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEventHandler(func))
  3492. #define EVT_SCROLLWIN_LINEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_LINEUP, wxScrollWinEventHandler(func))
  3493. #define EVT_SCROLLWIN_LINEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEventHandler(func))
  3494. #define EVT_SCROLLWIN_PAGEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEventHandler(func))
  3495. #define EVT_SCROLLWIN_PAGEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEventHandler(func))
  3496. #define EVT_SCROLLWIN_THUMBTRACK(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(func))
  3497. #define EVT_SCROLLWIN_THUMBRELEASE(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEventHandler(func))
  3498. #define EVT_SCROLLWIN(func) \
  3499. EVT_SCROLLWIN_TOP(func) \
  3500. EVT_SCROLLWIN_BOTTOM(func) \
  3501. EVT_SCROLLWIN_LINEUP(func) \
  3502. EVT_SCROLLWIN_LINEDOWN(func) \
  3503. EVT_SCROLLWIN_PAGEUP(func) \
  3504. EVT_SCROLLWIN_PAGEDOWN(func) \
  3505. EVT_SCROLLWIN_THUMBTRACK(func) \
  3506. EVT_SCROLLWIN_THUMBRELEASE(func)
  3507. // Scrolling from wxSlider and wxScrollBar
  3508. #define EVT_SCROLL_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_TOP, wxScrollEventHandler(func))
  3509. #define EVT_SCROLL_BOTTOM(func) wx__DECLARE_EVT0(wxEVT_SCROLL_BOTTOM, wxScrollEventHandler(func))
  3510. #define EVT_SCROLL_LINEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_LINEUP, wxScrollEventHandler(func))
  3511. #define EVT_SCROLL_LINEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLL_LINEDOWN, wxScrollEventHandler(func))
  3512. #define EVT_SCROLL_PAGEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_PAGEUP, wxScrollEventHandler(func))
  3513. #define EVT_SCROLL_PAGEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLL_PAGEDOWN, wxScrollEventHandler(func))
  3514. #define EVT_SCROLL_THUMBTRACK(func) wx__DECLARE_EVT0(wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(func))
  3515. #define EVT_SCROLL_THUMBRELEASE(func) wx__DECLARE_EVT0(wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(func))
  3516. #define EVT_SCROLL_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SCROLL_CHANGED, wxScrollEventHandler(func))
  3517. #define EVT_SCROLL(func) \
  3518. EVT_SCROLL_TOP(func) \
  3519. EVT_SCROLL_BOTTOM(func) \
  3520. EVT_SCROLL_LINEUP(func) \
  3521. EVT_SCROLL_LINEDOWN(func) \
  3522. EVT_SCROLL_PAGEUP(func) \
  3523. EVT_SCROLL_PAGEDOWN(func) \
  3524. EVT_SCROLL_THUMBTRACK(func) \
  3525. EVT_SCROLL_THUMBRELEASE(func) \
  3526. EVT_SCROLL_CHANGED(func)
  3527. // Scrolling from wxSlider and wxScrollBar, with an id
  3528. #define EVT_COMMAND_SCROLL_TOP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_TOP, winid, wxScrollEventHandler(func))
  3529. #define EVT_COMMAND_SCROLL_BOTTOM(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_BOTTOM, winid, wxScrollEventHandler(func))
  3530. #define EVT_COMMAND_SCROLL_LINEUP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_LINEUP, winid, wxScrollEventHandler(func))
  3531. #define EVT_COMMAND_SCROLL_LINEDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_LINEDOWN, winid, wxScrollEventHandler(func))
  3532. #define EVT_COMMAND_SCROLL_PAGEUP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_PAGEUP, winid, wxScrollEventHandler(func))
  3533. #define EVT_COMMAND_SCROLL_PAGEDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_PAGEDOWN, winid, wxScrollEventHandler(func))
  3534. #define EVT_COMMAND_SCROLL_THUMBTRACK(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_THUMBTRACK, winid, wxScrollEventHandler(func))
  3535. #define EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_THUMBRELEASE, winid, wxScrollEventHandler(func))
  3536. #define EVT_COMMAND_SCROLL_CHANGED(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_CHANGED, winid, wxScrollEventHandler(func))
  3537. #define EVT_COMMAND_SCROLL(winid, func) \
  3538. EVT_COMMAND_SCROLL_TOP(winid, func) \
  3539. EVT_COMMAND_SCROLL_BOTTOM(winid, func) \
  3540. EVT_COMMAND_SCROLL_LINEUP(winid, func) \
  3541. EVT_COMMAND_SCROLL_LINEDOWN(winid, func) \
  3542. EVT_COMMAND_SCROLL_PAGEUP(winid, func) \
  3543. EVT_COMMAND_SCROLL_PAGEDOWN(winid, func) \
  3544. EVT_COMMAND_SCROLL_THUMBTRACK(winid, func) \
  3545. EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) \
  3546. EVT_COMMAND_SCROLL_CHANGED(winid, func)
  3547. #if WXWIN_COMPATIBILITY_2_6
  3548. // compatibility macros for the old name, deprecated in 2.8
  3549. #define wxEVT_SCROLL_ENDSCROLL wxEVT_SCROLL_CHANGED
  3550. #define EVT_COMMAND_SCROLL_ENDSCROLL EVT_COMMAND_SCROLL_CHANGED
  3551. #define EVT_SCROLL_ENDSCROLL EVT_SCROLL_CHANGED
  3552. #endif // WXWIN_COMPATIBILITY_2_6
  3553. // Convenience macros for commonly-used commands
  3554. #define EVT_CHECKBOX(winid, func) wx__DECLARE_EVT1(wxEVT_CHECKBOX, winid, wxCommandEventHandler(func))
  3555. #define EVT_CHOICE(winid, func) wx__DECLARE_EVT1(wxEVT_CHOICE, winid, wxCommandEventHandler(func))
  3556. #define EVT_LISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_LISTBOX, winid, wxCommandEventHandler(func))
  3557. #define EVT_LISTBOX_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_LISTBOX_DCLICK, winid, wxCommandEventHandler(func))
  3558. #define EVT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_MENU, winid, wxCommandEventHandler(func))
  3559. #define EVT_MENU_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_MENU, id1, id2, wxCommandEventHandler(func))
  3560. #if defined(__SMARTPHONE__)
  3561. # define EVT_BUTTON(winid, func) EVT_MENU(winid, func)
  3562. #else
  3563. # define EVT_BUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_BUTTON, winid, wxCommandEventHandler(func))
  3564. #endif
  3565. #define EVT_SLIDER(winid, func) wx__DECLARE_EVT1(wxEVT_SLIDER, winid, wxCommandEventHandler(func))
  3566. #define EVT_RADIOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_RADIOBOX, winid, wxCommandEventHandler(func))
  3567. #define EVT_RADIOBUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_RADIOBUTTON, winid, wxCommandEventHandler(func))
  3568. // EVT_SCROLLBAR is now obsolete since we use EVT_COMMAND_SCROLL... events
  3569. #define EVT_SCROLLBAR(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLLBAR, winid, wxCommandEventHandler(func))
  3570. #define EVT_VLBOX(winid, func) wx__DECLARE_EVT1(wxEVT_VLBOX, winid, wxCommandEventHandler(func))
  3571. #define EVT_COMBOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX, winid, wxCommandEventHandler(func))
  3572. #define EVT_TOOL(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL, winid, wxCommandEventHandler(func))
  3573. #define EVT_TOOL_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_DROPDOWN, winid, wxCommandEventHandler(func))
  3574. #define EVT_TOOL_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_TOOL, id1, id2, wxCommandEventHandler(func))
  3575. #define EVT_TOOL_RCLICKED(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_RCLICKED, winid, wxCommandEventHandler(func))
  3576. #define EVT_TOOL_RCLICKED_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_TOOL_RCLICKED, id1, id2, wxCommandEventHandler(func))
  3577. #define EVT_TOOL_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_ENTER, winid, wxCommandEventHandler(func))
  3578. #define EVT_CHECKLISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_CHECKLISTBOX, winid, wxCommandEventHandler(func))
  3579. #define EVT_COMBOBOX_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX_DROPDOWN, winid, wxCommandEventHandler(func))
  3580. #define EVT_COMBOBOX_CLOSEUP(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX_CLOSEUP, winid, wxCommandEventHandler(func))
  3581. // Generic command events
  3582. #define EVT_COMMAND_LEFT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_CLICK, winid, wxCommandEventHandler(func))
  3583. #define EVT_COMMAND_LEFT_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_DCLICK, winid, wxCommandEventHandler(func))
  3584. #define EVT_COMMAND_RIGHT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RIGHT_CLICK, winid, wxCommandEventHandler(func))
  3585. #define EVT_COMMAND_RIGHT_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RIGHT_DCLICK, winid, wxCommandEventHandler(func))
  3586. #define EVT_COMMAND_SET_FOCUS(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SET_FOCUS, winid, wxCommandEventHandler(func))
  3587. #define EVT_COMMAND_KILL_FOCUS(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_KILL_FOCUS, winid, wxCommandEventHandler(func))
  3588. #define EVT_COMMAND_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_ENTER, winid, wxCommandEventHandler(func))
  3589. // Joystick events
  3590. #define EVT_JOY_BUTTON_DOWN(func) wx__DECLARE_EVT0(wxEVT_JOY_BUTTON_DOWN, wxJoystickEventHandler(func))
  3591. #define EVT_JOY_BUTTON_UP(func) wx__DECLARE_EVT0(wxEVT_JOY_BUTTON_UP, wxJoystickEventHandler(func))
  3592. #define EVT_JOY_MOVE(func) wx__DECLARE_EVT0(wxEVT_JOY_MOVE, wxJoystickEventHandler(func))
  3593. #define EVT_JOY_ZMOVE(func) wx__DECLARE_EVT0(wxEVT_JOY_ZMOVE, wxJoystickEventHandler(func))
  3594. // All joystick events
  3595. #define EVT_JOYSTICK_EVENTS(func) \
  3596. EVT_JOY_BUTTON_DOWN(func) \
  3597. EVT_JOY_BUTTON_UP(func) \
  3598. EVT_JOY_MOVE(func) \
  3599. EVT_JOY_ZMOVE(func)
  3600. // Idle event
  3601. #define EVT_IDLE(func) wx__DECLARE_EVT0(wxEVT_IDLE, wxIdleEventHandler(func))
  3602. // Update UI event
  3603. #define EVT_UPDATE_UI(winid, func) wx__DECLARE_EVT1(wxEVT_UPDATE_UI, winid, wxUpdateUIEventHandler(func))
  3604. #define EVT_UPDATE_UI_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_UPDATE_UI, id1, id2, wxUpdateUIEventHandler(func))
  3605. // Help events
  3606. #define EVT_HELP(winid, func) wx__DECLARE_EVT1(wxEVT_HELP, winid, wxHelpEventHandler(func))
  3607. #define EVT_HELP_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_HELP, id1, id2, wxHelpEventHandler(func))
  3608. #define EVT_DETAILED_HELP(winid, func) wx__DECLARE_EVT1(wxEVT_DETAILED_HELP, winid, wxHelpEventHandler(func))
  3609. #define EVT_DETAILED_HELP_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_DETAILED_HELP, id1, id2, wxHelpEventHandler(func))
  3610. // Context Menu Events
  3611. #define EVT_CONTEXT_MENU(func) wx__DECLARE_EVT0(wxEVT_CONTEXT_MENU, wxContextMenuEventHandler(func))
  3612. #define EVT_COMMAND_CONTEXT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_CONTEXT_MENU, winid, wxContextMenuEventHandler(func))
  3613. // Clipboard text Events
  3614. #define EVT_TEXT_CUT(winid, func) wx__DECLARE_EVT1(wxEVT_TEXT_CUT, winid, wxClipboardTextEventHandler(func))
  3615. #define EVT_TEXT_COPY(winid, func) wx__DECLARE_EVT1(wxEVT_TEXT_COPY, winid, wxClipboardTextEventHandler(func))
  3616. #define EVT_TEXT_PASTE(winid, func) wx__DECLARE_EVT1(wxEVT_TEXT_PASTE, winid, wxClipboardTextEventHandler(func))
  3617. // Thread events
  3618. #define EVT_THREAD(id, func) wx__DECLARE_EVT1(wxEVT_THREAD, id, wxThreadEventHandler(func))
  3619. // ----------------------------------------------------------------------------
  3620. // Helper functions
  3621. // ----------------------------------------------------------------------------
  3622. // This is an ugly hack to allow the use of Bind() instead of Connect() inside
  3623. // the library code if the library was built with support for it, here is how
  3624. // it is used:
  3625. //
  3626. // class SomeEventHandlingClass : wxBIND_OR_CONNECT_HACK_BASE_CLASS
  3627. // public SomeBaseClass
  3628. // {
  3629. // public:
  3630. // SomeEventHandlingClass(wxWindow *win)
  3631. // {
  3632. // // connect to the event for the given window
  3633. // wxBIND_OR_CONNECT_HACK(win, wxEVT_SOMETHING, wxSomeEventHandler,
  3634. // SomeEventHandlingClass::OnSomeEvent, this);
  3635. // }
  3636. //
  3637. // private:
  3638. // void OnSomeEvent(wxSomeEvent&) { ... }
  3639. // };
  3640. //
  3641. // This is *not* meant to be used by library users, it is only defined here
  3642. // (and not in a private header) because the base class must be visible from
  3643. // other public headers, please do NOT use this in your code, it will be
  3644. // removed from future wx versions without warning.
  3645. #ifdef wxHAS_EVENT_BIND
  3646. #define wxBIND_OR_CONNECT_HACK_BASE_CLASS
  3647. #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
  3648. #define wxBIND_OR_CONNECT_HACK(win, evt, handler, func, obj) \
  3649. win->Bind(evt, &func, obj)
  3650. #else // wxHAS_EVENT_BIND
  3651. #define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler,
  3652. #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler
  3653. #define wxBIND_OR_CONNECT_HACK(win, evt, handler, func, obj) \
  3654. win->Connect(evt, handler(func), NULL, obj)
  3655. #endif // wxHAS_EVENT_BIND
  3656. #if wxUSE_GUI
  3657. // Find a window with the focus, that is also a descendant of the given window.
  3658. // This is used to determine the window to initially send commands to.
  3659. WXDLLIMPEXP_CORE wxWindow* wxFindFocusDescendant(wxWindow* ancestor);
  3660. #endif // wxUSE_GUI
  3661. // ----------------------------------------------------------------------------
  3662. // Compatibility macro aliases
  3663. // ----------------------------------------------------------------------------
  3664. // deprecated variants _not_ requiring a semicolon after them and without wx prefix
  3665. // (note that also some wx-prefixed macro do _not_ require a semicolon because
  3666. // it's not always possible to force the compire to require it)
  3667. #define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
  3668. wxDECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj)
  3669. #define DECLARE_EVENT_TABLE_TERMINATOR() wxDECLARE_EVENT_TABLE_TERMINATOR()
  3670. #define DECLARE_EVENT_TABLE() wxDECLARE_EVENT_TABLE();
  3671. #define BEGIN_EVENT_TABLE(a,b) wxBEGIN_EVENT_TABLE(a,b)
  3672. #define BEGIN_EVENT_TABLE_TEMPLATE1(a,b,c) wxBEGIN_EVENT_TABLE_TEMPLATE1(a,b,c)
  3673. #define BEGIN_EVENT_TABLE_TEMPLATE2(a,b,c,d) wxBEGIN_EVENT_TABLE_TEMPLATE2(a,b,c,d)
  3674. #define BEGIN_EVENT_TABLE_TEMPLATE3(a,b,c,d,e) wxBEGIN_EVENT_TABLE_TEMPLATE3(a,b,c,d,e)
  3675. #define BEGIN_EVENT_TABLE_TEMPLATE4(a,b,c,d,e,f) wxBEGIN_EVENT_TABLE_TEMPLATE4(a,b,c,d,e,f)
  3676. #define BEGIN_EVENT_TABLE_TEMPLATE5(a,b,c,d,e,f,g) wxBEGIN_EVENT_TABLE_TEMPLATE5(a,b,c,d,e,f,g)
  3677. #define BEGIN_EVENT_TABLE_TEMPLATE6(a,b,c,d,e,f,g,h) wxBEGIN_EVENT_TABLE_TEMPLATE6(a,b,c,d,e,f,g,h)
  3678. #define END_EVENT_TABLE() wxEND_EVENT_TABLE()
  3679. // other obsolete event declaration/definition macros; we don't need them any longer
  3680. // but we keep them for compatibility as it doesn't cost us anything anyhow
  3681. #define BEGIN_DECLARE_EVENT_TYPES()
  3682. #define END_DECLARE_EVENT_TYPES()
  3683. #define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \
  3684. extern expdecl const wxEventType name;
  3685. #define DECLARE_EVENT_TYPE(name, value) \
  3686. DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, name, value)
  3687. #define DECLARE_LOCAL_EVENT_TYPE(name, value) \
  3688. DECLARE_EXPORTED_EVENT_TYPE(wxEMPTY_PARAMETER_VALUE, name, value)
  3689. #define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType();
  3690. #define DEFINE_LOCAL_EVENT_TYPE(name) DEFINE_EVENT_TYPE(name)
  3691. // alias for backward compatibility with 2.9.0:
  3692. #define wxEVT_COMMAND_THREAD wxEVT_THREAD
  3693. // other old wxEVT_COMMAND_* constants
  3694. #define wxEVT_COMMAND_BUTTON_CLICKED wxEVT_BUTTON
  3695. #define wxEVT_COMMAND_CHECKBOX_CLICKED wxEVT_CHECKBOX
  3696. #define wxEVT_COMMAND_CHOICE_SELECTED wxEVT_CHOICE
  3697. #define wxEVT_COMMAND_LISTBOX_SELECTED wxEVT_LISTBOX
  3698. #define wxEVT_COMMAND_LISTBOX_DOUBLECLICKED wxEVT_LISTBOX_DCLICK
  3699. #define wxEVT_COMMAND_CHECKLISTBOX_TOGGLED wxEVT_CHECKLISTBOX
  3700. #define wxEVT_COMMAND_MENU_SELECTED wxEVT_MENU
  3701. #define wxEVT_COMMAND_TOOL_CLICKED wxEVT_TOOL
  3702. #define wxEVT_COMMAND_SLIDER_UPDATED wxEVT_SLIDER
  3703. #define wxEVT_COMMAND_RADIOBOX_SELECTED wxEVT_RADIOBOX
  3704. #define wxEVT_COMMAND_RADIOBUTTON_SELECTED wxEVT_RADIOBUTTON
  3705. #define wxEVT_COMMAND_SCROLLBAR_UPDATED wxEVT_SCROLLBAR
  3706. #define wxEVT_COMMAND_VLBOX_SELECTED wxEVT_VLBOX
  3707. #define wxEVT_COMMAND_COMBOBOX_SELECTED wxEVT_COMBOBOX
  3708. #define wxEVT_COMMAND_TOOL_RCLICKED wxEVT_TOOL_RCLICKED
  3709. #define wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED wxEVT_TOOL_DROPDOWN
  3710. #define wxEVT_COMMAND_TOOL_ENTER wxEVT_TOOL_ENTER
  3711. #define wxEVT_COMMAND_COMBOBOX_DROPDOWN wxEVT_COMBOBOX_DROPDOWN
  3712. #define wxEVT_COMMAND_COMBOBOX_CLOSEUP wxEVT_COMBOBOX_CLOSEUP
  3713. #define wxEVT_COMMAND_TEXT_COPY wxEVT_TEXT_COPY
  3714. #define wxEVT_COMMAND_TEXT_CUT wxEVT_TEXT_CUT
  3715. #define wxEVT_COMMAND_TEXT_PASTE wxEVT_TEXT_PASTE
  3716. #define wxEVT_COMMAND_TEXT_UPDATED wxEVT_TEXT
  3717. #endif // _WX_EVENT_H_