dialogs.cpp 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dialogs.cpp
  3. // Purpose: Common dialogs demo
  4. // Author: Julian Smart, Vadim Zeitlin, ABX
  5. // Created: 04/01/98
  6. // Copyright: (c) Julian Smart
  7. // (c) 2004 ABX
  8. // (c) Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. // For compilers that support precompilation, includes "wx/wx.h".
  12. #include "wx/wxprec.h"
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. #ifndef WX_PRECOMP
  17. #include "wx/wx.h"
  18. #endif
  19. #include "../sample.xpm"
  20. #include "wx/apptrait.h"
  21. #include "wx/datetime.h"
  22. #include "wx/filename.h"
  23. #include "wx/image.h"
  24. #include "wx/bookctrl.h"
  25. #include "wx/artprov.h"
  26. #include "wx/imaglist.h"
  27. #include "wx/minifram.h"
  28. #include "wx/sysopt.h"
  29. #include "wx/notifmsg.h"
  30. #include "wx/modalhook.h"
  31. #if wxUSE_RICHMSGDLG
  32. #include "wx/richmsgdlg.h"
  33. #endif // wxUSE_RICHMSGDLG
  34. #if wxUSE_COLOURDLG
  35. #include "wx/colordlg.h"
  36. #endif // wxUSE_COLOURDLG
  37. #if wxUSE_CHOICEDLG
  38. #include "wx/choicdlg.h"
  39. #endif // wxUSE_CHOICEDLG
  40. #include "wx/rearrangectrl.h"
  41. #if wxUSE_STARTUP_TIPS
  42. #include "wx/tipdlg.h"
  43. #endif // wxUSE_STARTUP_TIPS
  44. #if wxUSE_PROGRESSDLG
  45. #if wxUSE_STOPWATCH && wxUSE_LONGLONG
  46. #include "wx/datetime.h" // wxDateTime
  47. #endif
  48. #include "wx/progdlg.h"
  49. #endif // wxUSE_PROGRESSDLG
  50. #if wxUSE_ABOUTDLG
  51. #include "wx/aboutdlg.h"
  52. // these headers are only needed for custom about dialog
  53. #include "wx/statline.h"
  54. #include "wx/generic/aboutdlgg.h"
  55. #endif // wxUSE_ABOUTDLG
  56. #if wxUSE_BUSYINFO
  57. #include "wx/busyinfo.h"
  58. #endif // wxUSE_BUSYINFO
  59. #if wxUSE_NUMBERDLG
  60. #include "wx/numdlg.h"
  61. #endif // wxUSE_NUMBERDLG
  62. #if wxUSE_FILEDLG
  63. #include "wx/filedlg.h"
  64. #endif // wxUSE_FILEDLG
  65. #if wxUSE_DIRDLG
  66. #include "wx/dirdlg.h"
  67. #endif // wxUSE_DIRDLG
  68. #if wxUSE_FONTDLG
  69. #include "wx/fontdlg.h"
  70. #endif // wxUSE_FONTDLG
  71. #if wxUSE_FINDREPLDLG
  72. #include "wx/fdrepdlg.h"
  73. #endif // wxUSE_FINDREPLDLG
  74. #if wxUSE_INFOBAR
  75. #include "wx/infobar.h"
  76. #endif // wxUSE_INFOBAR
  77. #include "wx/spinctrl.h"
  78. #include "wx/propdlg.h"
  79. #include "dialogs.h"
  80. #if USE_COLOURDLG_GENERIC
  81. #include "wx/generic/colrdlgg.h"
  82. #endif // USE_COLOURDLG_GENERIC
  83. #if USE_DIRDLG_GENERIC
  84. #include "wx/generic/dirdlgg.h"
  85. #endif // USE_DIRDLG_GENERIC
  86. #if USE_FILEDLG_GENERIC
  87. #include "wx/generic/filedlgg.h"
  88. #endif // USE_FILEDLG_GENERIC
  89. #if USE_FONTDLG_GENERIC
  90. #include "wx/generic/fontdlgg.h"
  91. #endif // USE_FONTDLG_GENERIC
  92. IMPLEMENT_APP(MyApp)
  93. wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
  94. EVT_PAINT(MyCanvas::OnPaint)
  95. wxEND_EVENT_TABLE()
  96. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  97. #if wxUSE_MSGDLG
  98. EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
  99. EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, MyFrame::MessageBoxWindowModal)
  100. EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog)
  101. EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo)
  102. #endif // wxUSE_MSGDLG
  103. #if wxUSE_RICHMSGDLG
  104. EVT_MENU(DIALOGS_RICH_MESSAGE_DIALOG, MyFrame::RichMessageDialog)
  105. #endif // wxUSE_RICHMSGDLG
  106. #if wxUSE_COLOURDLG
  107. EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
  108. EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour)
  109. #endif // wxUSE_COLOURDLG
  110. #if wxUSE_FONTDLG
  111. EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
  112. #endif // wxUSE_FONTDLG
  113. #if wxUSE_LOG_DIALOG
  114. EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
  115. #endif // wxUSE_LOG_DIALOG
  116. #if wxUSE_INFOBAR
  117. EVT_MENU(DIALOGS_INFOBAR_SIMPLE, MyFrame::InfoBarSimple)
  118. EVT_MENU(DIALOGS_INFOBAR_ADVANCED, MyFrame::InfoBarAdvanced)
  119. #endif // wxUSE_INFOBAR
  120. #if wxUSE_TEXTDLG
  121. EVT_MENU(DIALOGS_LINE_ENTRY, MyFrame::LineEntry)
  122. EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
  123. EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
  124. #endif // wxUSE_TEXTDLG
  125. #if wxUSE_NUMBERDLG
  126. EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
  127. #endif // wxUSE_NUMBERDLG
  128. #if wxUSE_CHOICEDLG
  129. EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
  130. EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
  131. #endif // wxUSE_CHOICEDLG
  132. #if wxUSE_REARRANGECTRL
  133. EVT_MENU(DIALOGS_REARRANGE, MyFrame::Rearrange)
  134. #endif // wxUSE_REARRANGECTRL
  135. #if wxUSE_FILEDLG
  136. EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
  137. EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
  138. EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
  139. EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
  140. #endif // wxUSE_FILEDLG
  141. #if USE_FILEDLG_GENERIC
  142. EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
  143. EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
  144. EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
  145. #endif // USE_FILEDLG_GENERIC
  146. #if wxUSE_DIRDLG
  147. EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
  148. EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
  149. #endif // wxUSE_DIRDLG
  150. #if USE_MODAL_PRESENTATION
  151. EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
  152. #endif // USE_MODAL_PRESENTATION
  153. EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
  154. EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen)
  155. EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent)
  156. #if wxUSE_MINIFRAME
  157. EVT_MENU(DIALOGS_MINIFRAME, MyFrame::MiniFrame)
  158. #endif // wxUSE_MINIFRAME
  159. EVT_MENU(DIALOGS_ONTOP, MyFrame::DlgOnTop)
  160. #if wxUSE_STARTUP_TIPS
  161. EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
  162. #endif // wxUSE_STARTUP_TIPS
  163. #if USE_FONTDLG_GENERIC
  164. EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
  165. #endif // USE_FONTDLG_GENERIC
  166. #if USE_DIRDLG_GENERIC
  167. EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
  168. #endif // wxMSW || wxMAC
  169. #if USE_COLOURDLG_GENERIC
  170. EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
  171. #endif // USE_COLOURDLG_GENERIC
  172. #if wxUSE_PROGRESSDLG
  173. EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
  174. #endif // wxUSE_PROGRESSDLG
  175. #if wxUSE_ABOUTDLG
  176. EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog)
  177. EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog)
  178. EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog)
  179. EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog)
  180. #endif // wxUSE_ABOUTDLG
  181. #if wxUSE_BUSYINFO
  182. EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
  183. #endif // wxUSE_BUSYINFO
  184. #if wxUSE_FINDREPLDLG
  185. EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
  186. EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
  187. EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
  188. EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
  189. EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
  190. EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
  191. EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
  192. #endif // wxUSE_FINDREPLDLG
  193. #if USE_SETTINGS_DIALOG
  194. EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet)
  195. EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet)
  196. EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet)
  197. #endif // USE_SETTINGS_DIALOG
  198. EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
  199. EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog)
  200. EVT_MENU(DIALOGS_MODAL_HOOK, MyFrame::OnModalHook)
  201. EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
  202. #if wxUSE_NOTIFICATION_MESSAGE
  203. EVT_MENU(DIALOGS_NOTIFY_AUTO, MyFrame::OnNotifMsgAuto)
  204. EVT_MENU(DIALOGS_NOTIFY_SHOW, MyFrame::OnNotifMsgShow)
  205. EVT_MENU(DIALOGS_NOTIFY_HIDE, MyFrame::OnNotifMsgHide)
  206. #endif // wxUSE_NOTIFICATION_MESSAGE
  207. #if wxUSE_RICHTOOLTIP
  208. EVT_MENU(DIALOGS_RICHTIP_DIALOG, MyFrame::OnRichTipDialog)
  209. #endif // wxUSE_RICHTOOLTIP
  210. EVT_MENU(wxID_EXIT, MyFrame::OnExit)
  211. wxEND_EVENT_TABLE()
  212. #if USE_MODAL_PRESENTATION
  213. wxBEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
  214. EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
  215. wxEND_EVENT_TABLE()
  216. wxBEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
  217. EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
  218. EVT_CLOSE(MyModelessDialog::OnClose)
  219. wxEND_EVENT_TABLE()
  220. #endif // USE_MODAL_PRESENTATION
  221. wxBEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
  222. EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent)
  223. EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
  224. wxEND_EVENT_TABLE()
  225. #if wxUSE_CMDLINE_PARSER
  226. #include "wx/cmdline.h"
  227. static const char *PROGRESS_SWITCH = "progress";
  228. void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
  229. {
  230. wxApp::OnInitCmdLine(parser);
  231. parser.AddOption("", PROGRESS_SWITCH,
  232. "Style for the startup progress dialog (wxPD_XXX)",
  233. wxCMD_LINE_VAL_NUMBER);
  234. }
  235. bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
  236. {
  237. if ( !wxApp::OnCmdLineParsed(parser) )
  238. return false;
  239. parser.Found(PROGRESS_SWITCH, &m_startupProgressStyle);
  240. return true;
  241. }
  242. #endif // wxUSE_CMDLINE_PARSER
  243. // `Main program' equivalent, creating windows and returning main app frame
  244. bool MyApp::OnInit()
  245. {
  246. if ( !wxApp::OnInit() )
  247. return false;
  248. #if wxUSE_PROGRESSDLG
  249. if ( m_startupProgressStyle != -1 )
  250. {
  251. // Show a test progress dialog before the main event loop is started:
  252. // it should still work.
  253. const int PROGRESS_COUNT = 100;
  254. wxProgressDialog dlg
  255. (
  256. "Progress in progress",
  257. "Please wait, starting...",
  258. PROGRESS_COUNT,
  259. NULL,
  260. m_startupProgressStyle
  261. );
  262. for ( int i = 0; i <= PROGRESS_COUNT; i++ )
  263. {
  264. if ( !dlg.Update(i) )
  265. break;
  266. wxMilliSleep(50);
  267. }
  268. }
  269. #endif // wxUSE_PROGRESSDLG
  270. #if wxUSE_IMAGE
  271. wxInitAllImageHandlers();
  272. #endif
  273. // Create the main frame window
  274. MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example"));
  275. // Make a menubar
  276. wxMenu *menuDlg = new wxMenu;
  277. menuDlg->Append(DIALOGS_MESSAGE_BOX, wxT("&Message box\tCtrl-M"));
  278. menuDlg->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, wxT("Window-Modal Message box "));
  279. menuDlg->Append(DIALOGS_MESSAGE_DIALOG, wxT("Message dialog\tShift-Ctrl-M"));
  280. #if wxUSE_RICHMSGDLG
  281. menuDlg->Append(DIALOGS_RICH_MESSAGE_DIALOG, wxT("Rich message dialog"));
  282. #endif // wxUSE_RICHMSGDLG
  283. #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
  284. wxMenu *choices_menu = new wxMenu;
  285. #if wxUSE_COLOURDLG
  286. choices_menu->Append(DIALOGS_CHOOSE_COLOUR, wxT("&Choose bg colour"));
  287. choices_menu->Append(DIALOGS_GET_COLOUR, wxT("&Choose fg colour"));
  288. #endif // wxUSE_COLOURDLG
  289. #if wxUSE_FONTDLG
  290. choices_menu->Append(DIALOGS_CHOOSE_FONT, wxT("Choose &font"));
  291. #endif // wxUSE_FONTDLG
  292. #if wxUSE_CHOICEDLG
  293. choices_menu->Append(DIALOGS_SINGLE_CHOICE, wxT("&Single choice\tCtrl-C"));
  294. choices_menu->Append(DIALOGS_MULTI_CHOICE, wxT("M&ultiple choice\tCtrl-U"));
  295. #endif // wxUSE_CHOICEDLG
  296. #if wxUSE_REARRANGECTRL
  297. choices_menu->Append(DIALOGS_REARRANGE, wxT("&Rearrange dialog\tCtrl-R"));
  298. #endif // wxUSE_REARRANGECTRL
  299. #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
  300. choices_menu->AppendSeparator();
  301. #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
  302. #if USE_COLOURDLG_GENERIC
  303. choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, wxT("&Choose colour (generic)"));
  304. #endif // USE_COLOURDLG_GENERIC
  305. #if USE_FONTDLG_GENERIC
  306. choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, wxT("Choose &font (generic)"));
  307. #endif // USE_FONTDLG_GENERIC
  308. menuDlg->Append(wxID_ANY,wxT("&Choices and selectors"),choices_menu);
  309. #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
  310. #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
  311. wxMenu *entry_menu = new wxMenu;
  312. #if wxUSE_TEXTDLG
  313. entry_menu->Append(DIALOGS_LINE_ENTRY, wxT("Single line &entry\tCtrl-E"));
  314. entry_menu->Append(DIALOGS_TEXT_ENTRY, wxT("Multi line text &entry\tShift-Ctrl-E"));
  315. entry_menu->Append(DIALOGS_PASSWORD_ENTRY, wxT("&Password entry\tCtrl-P"));
  316. #endif // wxUSE_TEXTDLG
  317. #if wxUSE_NUMBERDLG
  318. entry_menu->Append(DIALOGS_NUM_ENTRY, wxT("&Numeric entry\tCtrl-N"));
  319. #endif // wxUSE_NUMBERDLG
  320. menuDlg->Append(wxID_ANY,wxT("&Entry dialogs"),entry_menu);
  321. #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
  322. #if wxUSE_FILEDLG
  323. wxMenu *filedlg_menu = new wxMenu;
  324. filedlg_menu->Append(DIALOGS_FILE_OPEN, wxT("&Open file\tCtrl-O"));
  325. filedlg_menu->Append(DIALOGS_FILE_OPEN2, wxT("&Second open file\tCtrl-2"));
  326. filedlg_menu->Append(DIALOGS_FILES_OPEN, wxT("Open &files\tCtrl-Q"));
  327. filedlg_menu->Append(DIALOGS_FILE_SAVE, wxT("Sa&ve file\tCtrl-S"));
  328. #if USE_FILEDLG_GENERIC
  329. filedlg_menu->AppendSeparator();
  330. filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, wxT("&Open file (generic)"));
  331. filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, wxT("Open &files (generic)"));
  332. filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, wxT("Sa&ve file (generic)"));
  333. #endif // USE_FILEDLG_GENERIC
  334. menuDlg->Append(wxID_ANY,wxT("&File operations"),filedlg_menu);
  335. #endif // wxUSE_FILEDLG
  336. #if wxUSE_DIRDLG
  337. wxMenu *dir_menu = new wxMenu;
  338. dir_menu->Append(DIALOGS_DIR_CHOOSE, wxT("&Choose a directory\tCtrl-D"));
  339. dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
  340. menuDlg->Append(wxID_ANY,wxT("&Directory operations"),dir_menu);
  341. #if USE_DIRDLG_GENERIC
  342. dir_menu->AppendSeparator();
  343. dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, wxT("&Choose a directory (generic)"));
  344. #endif // USE_DIRDLG_GENERIC
  345. #endif // wxUSE_DIRDLG
  346. #if wxUSE_STARTUP_TIPS || \
  347. wxUSE_PROGRESSDLG || \
  348. wxUSE_BUSYINFO || \
  349. wxUSE_LOG_DIALOG || \
  350. wxUSE_MSGDLG
  351. wxMenu *info_menu = new wxMenu;
  352. #if wxUSE_STARTUP_TIPS
  353. info_menu->Append(DIALOGS_TIP, wxT("&Tip of the day\tCtrl-T"));
  354. #endif // wxUSE_STARTUP_TIPS
  355. #if wxUSE_PROGRESSDLG
  356. info_menu->Append(DIALOGS_PROGRESS, wxT("Pro&gress dialog\tCtrl-G"));
  357. #endif // wxUSE_PROGRESSDLG
  358. #if wxUSE_BUSYINFO
  359. info_menu->Append(DIALOGS_BUSYINFO, wxT("&Busy info dialog\tCtrl-B"));
  360. #endif // wxUSE_BUSYINFO
  361. #if wxUSE_LOG_DIALOG
  362. info_menu->Append(DIALOGS_LOG_DIALOG, wxT("&Log dialog\tCtrl-L"));
  363. #endif // wxUSE_LOG_DIALOG
  364. #if wxUSE_INFOBAR
  365. info_menu->Append(DIALOGS_INFOBAR_SIMPLE, "Simple &info bar\tCtrl-I");
  366. info_menu->Append(DIALOGS_INFOBAR_ADVANCED, "&Advanced info bar\tShift-Ctrl-I");
  367. #endif // wxUSE_INFOBAR
  368. #if wxUSE_MSGDLG
  369. info_menu->Append(DIALOGS_MESSAGE_BOX_WXINFO,
  370. wxT("&wxWidgets information\tCtrl-W"));
  371. #endif // wxUSE_MSGDLG
  372. menuDlg->Append(wxID_ANY,wxT("&Informative dialogs"),info_menu);
  373. #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
  374. #if wxUSE_FINDREPLDLG
  375. wxMenu *find_menu = new wxMenu;
  376. find_menu->AppendCheckItem(DIALOGS_FIND, wxT("&Find dialog\tCtrl-F"));
  377. find_menu->AppendCheckItem(DIALOGS_REPLACE, wxT("Find and &replace dialog\tShift-Ctrl-F"));
  378. menuDlg->Append(wxID_ANY,wxT("&Searching"),find_menu);
  379. #endif // wxUSE_FINDREPLDLG
  380. wxMenu *dialogs_menu = new wxMenu;
  381. #if USE_MODAL_PRESENTATION
  382. dialogs_menu->Append(DIALOGS_MODAL, wxT("&Modal dialog\tShift-Ctrl-W"));
  383. #endif // USE_MODAL_PRESENTATION
  384. dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, wxT("Mode&less dialog\tShift-Ctrl-Z"));
  385. dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, wxT("Centered on &screen\tShift-Ctrl-1"));
  386. dialogs_menu->Append(DIALOGS_CENTRE_PARENT, wxT("Centered on &parent\tShift-Ctrl-2"));
  387. #if wxUSE_MINIFRAME
  388. dialogs_menu->Append(DIALOGS_MINIFRAME, wxT("&Mini frame"));
  389. #endif // wxUSE_MINIFRAME
  390. dialogs_menu->Append(DIALOGS_ONTOP, wxT("Dialog staying on &top"));
  391. menuDlg->Append(wxID_ANY, wxT("&Generic dialogs"), dialogs_menu);
  392. #if USE_SETTINGS_DIALOG
  393. wxMenu *sheet_menu = new wxMenu;
  394. sheet_menu->Append(DIALOGS_PROPERTY_SHEET, wxT("&Standard property sheet\tShift-Ctrl-P"));
  395. sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, wxT("&Toolbook sheet\tShift-Ctrl-T"));
  396. if (wxPlatformIs(wxPORT_MAC))
  397. sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
  398. /*
  399. #ifdef __WXMAC__
  400. sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
  401. #endif
  402. */
  403. menuDlg->Append(wxID_ANY, wxT("&Property sheets"), sheet_menu);
  404. #endif // USE_SETTINGS_DIALOG
  405. wxMenu *menuNotif = new wxMenu;
  406. menuNotif->Append(DIALOGS_REQUEST, wxT("&Request user attention\tCtrl-Shift-R"));
  407. #if wxUSE_NOTIFICATION_MESSAGE
  408. menuNotif->Append(DIALOGS_NOTIFY_AUTO, "&Automatically hidden notification");
  409. menuNotif->Append(DIALOGS_NOTIFY_SHOW, "&Show manual notification");
  410. menuNotif->Append(DIALOGS_NOTIFY_HIDE, "&Hide manual notification");
  411. #endif // wxUSE_NOTIFICATION_MESSAGE
  412. menuDlg->AppendSubMenu(menuNotif, "&User notifications");
  413. #if wxUSE_RICHTOOLTIP
  414. menuDlg->Append(DIALOGS_RICHTIP_DIALOG, "Rich &tooltip dialog...\tCtrl-H");
  415. menuDlg->AppendSeparator();
  416. #endif // wxUSE_RICHTOOLTIP
  417. menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, wxT("&Standard Buttons Sizer Dialog"));
  418. menuDlg->Append(DIALOGS_TEST_DEFAULT_ACTION, wxT("&Test dialog default action"));
  419. menuDlg->AppendCheckItem(DIALOGS_MODAL_HOOK, "Enable modal dialog hook");
  420. menuDlg->AppendSeparator();
  421. menuDlg->Append(wxID_EXIT, wxT("E&xit\tAlt-X"));
  422. #if wxUSE_ABOUTDLG
  423. wxMenu *menuHelp = new wxMenu;
  424. menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, wxT("&About (simple)...\tF1"));
  425. menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, wxT("About (&fancy)...\tShift-F1"));
  426. menuHelp->Append(DIALOGS_ABOUTDLG_FULL, wxT("About (f&ull)...\tCtrl-F1"));
  427. menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, wxT("About (&custom)...\tCtrl-Shift-F1"));
  428. #endif // wxUSE_ABOUTDLG
  429. wxMenu* editMenu = new wxMenu;
  430. editMenu->Append(wxID_UNDO, _("&Undo\tCtrl+Z"));
  431. editMenu->Append(wxID_REDO, _("&Redo\tCtrl+Y"));
  432. editMenu->AppendSeparator();
  433. editMenu->Append(wxID_CUT, _("Cu&t\tCtrl+X"));
  434. editMenu->Append(wxID_COPY, _("&Copy\tCtrl+C"));
  435. editMenu->Append(wxID_PASTE, _("&Paste\tCtrl+V"));
  436. editMenu->Append(wxID_CLEAR, _("&Delete"));
  437. editMenu->AppendSeparator();
  438. editMenu->Append(wxID_SELECTALL, _("Select All\tCtrl+A"));
  439. wxMenuBar *menubar = new wxMenuBar;
  440. menubar->Append(menuDlg, wxT("&Dialogs"));
  441. menubar->Append(editMenu, wxT("&Edit"));
  442. #if wxUSE_ABOUTDLG
  443. menubar->Append(menuHelp, wxT("&Help"));
  444. #endif // wxUSE_ABOUTDLG
  445. frame->SetMenuBar(menubar);
  446. frame->Centre(wxBOTH);
  447. frame->Show(true);
  448. return true;
  449. }
  450. // My frame constructor
  451. MyFrame::MyFrame(const wxString& title)
  452. : wxFrame(NULL, wxID_ANY, title)
  453. {
  454. SetIcon(wxICON(sample));
  455. #if USE_MODAL_PRESENTATION
  456. m_dialog = (MyModelessDialog *)NULL;
  457. #endif // USE_MODAL_PRESENTATION
  458. #if wxUSE_FINDREPLDLG
  459. m_dlgFind =
  460. m_dlgReplace = NULL;
  461. #endif
  462. #if wxUSE_COLOURDLG
  463. m_clrData.SetChooseFull(true);
  464. for (int i = 0; i < wxColourData::NUM_CUSTOM; i++)
  465. {
  466. unsigned char n = i*16;
  467. m_clrData.SetCustomColour(i, wxColour(n, n, n));
  468. }
  469. #endif // wxUSE_COLOURDLG
  470. #if wxUSE_NOTIFICATION_MESSAGE
  471. m_notifMsg = NULL;
  472. #endif // wxUSE_NOTIFICATION_MESSAGE
  473. #if wxUSE_STATUSBAR
  474. CreateStatusBar();
  475. #endif // wxUSE_STATUSBAR
  476. m_canvas = new MyCanvas(this);
  477. #if wxUSE_INFOBAR
  478. // an info bar can be created very simply and used without any extra effort
  479. m_infoBarSimple = new wxInfoBar(this);
  480. // or it can also be customized by
  481. m_infoBarAdvanced = new wxInfoBar(this);
  482. // ... adding extra buttons (but more than two will usually be too many)
  483. m_infoBarAdvanced->AddButton(wxID_UNDO);
  484. m_infoBarAdvanced->AddButton(wxID_REDO);
  485. m_infoBarAdvanced->Connect(wxID_REDO, wxEVT_BUTTON,
  486. wxCommandEventHandler(MyFrame::OnInfoBarRedo),
  487. NULL,
  488. this);
  489. // adding and removing a button immediately doesn't make sense here, of
  490. // course, it's done just to show that it is possible
  491. m_infoBarAdvanced->AddButton(wxID_EXIT);
  492. m_infoBarAdvanced->RemoveButton(wxID_EXIT);
  493. // ... changing the colours and/or fonts
  494. m_infoBarAdvanced->SetOwnBackgroundColour(0xc8ffff);
  495. m_infoBarAdvanced->SetFont(GetFont().Bold().Larger());
  496. // ... and changing the effect (only does anything under MSW currently)
  497. m_infoBarAdvanced->SetShowHideEffects(wxSHOW_EFFECT_EXPAND,
  498. wxSHOW_EFFECT_EXPAND);
  499. m_infoBarAdvanced->SetEffectDuration(1500);
  500. // to use the info bars we need to use sizer for the window layout
  501. wxBoxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
  502. sizer->Add(m_infoBarSimple, wxSizerFlags().Expand());
  503. sizer->Add(m_canvas, wxSizerFlags(1).Expand());
  504. sizer->Add(m_infoBarAdvanced, wxSizerFlags().Expand());
  505. SetSizer(sizer);
  506. // final touch: under MSW the info bars are shown progressively and parts
  507. // of the parent window can be seen during the process, so use the same
  508. // background colour for our background as for the canvas window which
  509. // covers our entire client area to avoid jarring colour jumps
  510. SetOwnBackgroundColour(m_canvas->GetBackgroundColour());
  511. #endif // wxUSE_INFOBAR
  512. #ifdef __WXMSW__
  513. // Test MSW-specific function allowing to access the "system" menu.
  514. wxMenu * const menu = MSWGetSystemMenu();
  515. if ( menu )
  516. {
  517. menu->AppendSeparator();
  518. // The ids of the menu commands in MSW system menu must be multiple of
  519. // 16 so we can't use DIALOGS_ABOUTDLG_SIMPLE here because it might not
  520. // satisfy this condition and need to define and connect a separate id.
  521. static const int DIALOGS_SYSTEM_ABOUT = 0x4010;
  522. menu->Append(DIALOGS_SYSTEM_ABOUT, "&About");
  523. Connect(DIALOGS_SYSTEM_ABOUT, wxEVT_MENU,
  524. wxCommandEventHandler(MyFrame::ShowSimpleAboutDialog));
  525. }
  526. #endif // __WXMSW__
  527. }
  528. MyFrame::~MyFrame()
  529. {
  530. #if wxUSE_NOTIFICATION_MESSAGE
  531. delete m_notifMsg;
  532. #endif // wxUSE_NOTIFICATION_MESSAGE
  533. }
  534. #if wxUSE_COLOURDLG
  535. void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event))
  536. {
  537. m_clrData.SetColour(m_canvas->GetBackgroundColour());
  538. wxColourDialog dialog(this, &m_clrData);
  539. dialog.SetTitle(_("Please choose the background colour"));
  540. if ( dialog.ShowModal() == wxID_OK )
  541. {
  542. m_clrData = dialog.GetColourData();
  543. m_canvas->SetBackgroundColour(m_clrData.GetColour());
  544. m_canvas->ClearBackground();
  545. m_canvas->Refresh();
  546. }
  547. }
  548. void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
  549. {
  550. wxColour clr = wxGetColourFromUser
  551. (
  552. this,
  553. m_canvas->GetForegroundColour(),
  554. "Please choose the foreground colour"
  555. );
  556. if ( clr.IsOk() )
  557. {
  558. m_canvas->SetForegroundColour(clr);
  559. m_canvas->Refresh();
  560. }
  561. //else: dialog cancelled by user
  562. }
  563. #endif // wxUSE_COLOURDLG
  564. #if USE_COLOURDLG_GENERIC
  565. void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
  566. {
  567. m_clrData.SetColour(m_canvas->GetBackgroundColour());
  568. //FIXME:TODO:This has no effect...
  569. m_clrData.SetChooseFull(true);
  570. for (int i = 0; i < 16; i++)
  571. {
  572. wxColour colour(
  573. (unsigned char)(i*16),
  574. (unsigned char)(i*16),
  575. (unsigned char)(i*16)
  576. );
  577. m_clrData.SetCustomColour(i, colour);
  578. }
  579. wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
  580. if (dialog->ShowModal() == wxID_OK)
  581. {
  582. m_clrData = dialog->GetColourData();
  583. m_canvas->SetBackgroundColour(m_clrData.GetColour());
  584. m_canvas->ClearBackground();
  585. m_canvas->Refresh();
  586. }
  587. dialog->Destroy();
  588. }
  589. #endif // USE_COLOURDLG_GENERIC
  590. #if wxUSE_FONTDLG
  591. void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
  592. {
  593. wxFontData data;
  594. data.SetInitialFont(m_canvas->GetFont());
  595. data.SetColour(m_canvas->GetForegroundColour());
  596. // you might also do this:
  597. //
  598. // wxFontDialog dialog;
  599. // if ( !dialog.Create(this, data) { ... error ... }
  600. //
  601. wxFontDialog dialog(this, data);
  602. if (dialog.ShowModal() == wxID_OK)
  603. {
  604. wxFontData retData = dialog.GetFontData();
  605. m_canvas->SetFont(retData.GetChosenFont());
  606. m_canvas->SetForegroundColour(retData.GetColour());
  607. m_canvas->Refresh();
  608. }
  609. //else: cancelled by the user, don't change the font
  610. }
  611. #endif // wxUSE_FONTDLG
  612. #if USE_FONTDLG_GENERIC
  613. void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
  614. {
  615. wxFontData data;
  616. data.SetInitialFont(m_canvas->GetFont());
  617. data.SetColour(m_canvas->GetForegroundColour());
  618. wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
  619. if (dialog->ShowModal() == wxID_OK)
  620. {
  621. wxFontData retData = dialog->GetFontData();
  622. m_canvas->SetFont(retData.GetChosenFont());
  623. m_canvas->SetForegroundColour(retData.GetColour());
  624. m_canvas->Refresh();
  625. }
  626. dialog->Destroy();
  627. }
  628. #endif // USE_FONTDLG_GENERIC
  629. #if wxUSE_LOG_DIALOG
  630. void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
  631. {
  632. // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
  633. // being flushed -- test it
  634. {
  635. wxBusyCursor bc;
  636. wxLogMessage(wxT("This is some message - everything is ok so far."));
  637. wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
  638. wxLogWarning(wxT("And then something went wrong!"));
  639. // and if ~wxBusyCursor doesn't do it, then call it manually
  640. wxYield();
  641. }
  642. wxLogError(wxT("Intermediary error handler decided to abort."));
  643. wxLogError(wxT("The top level caller detected an unrecoverable error."));
  644. wxLog::FlushActive();
  645. wxLogMessage(wxT("And this is the same dialog but with only one message."));
  646. }
  647. #endif // wxUSE_LOG_DIALOG
  648. #if wxUSE_INFOBAR
  649. void MyFrame::InfoBarSimple(wxCommandEvent& WXUNUSED(event))
  650. {
  651. static int s_count = 0;
  652. m_infoBarSimple->ShowMessage
  653. (
  654. wxString::Format("Message #%d in the info bar.", ++s_count)
  655. );
  656. }
  657. void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event))
  658. {
  659. m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING);
  660. }
  661. void MyFrame::OnInfoBarRedo(wxCommandEvent& WXUNUSED(event))
  662. {
  663. m_infoBarAdvanced->ShowMessage("Still no, sorry again.", wxICON_ERROR);
  664. }
  665. #endif // wxUSE_INFOBAR
  666. #if wxUSE_MSGDLG
  667. void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
  668. {
  669. wxMessageDialog dialog(this,
  670. "This is a message box\n"
  671. "This is a long, long string to test out if the message box "
  672. "is laid out properly.",
  673. "Message box text",
  674. wxCENTER |
  675. wxNO_DEFAULT | wxYES_NO | wxCANCEL |
  676. wxICON_INFORMATION);
  677. wxString extmsg;
  678. if ( dialog.SetYesNoCancelLabels
  679. (
  680. "Answer &Yes",
  681. "Answer &No",
  682. "Refuse to answer"
  683. ) )
  684. {
  685. extmsg = "This platform supports custom button labels,\n"
  686. "so you should see the descriptive labels below.";
  687. }
  688. else
  689. {
  690. extmsg = "Custom button labels are not supported on this platform,\n"
  691. "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
  692. }
  693. dialog.SetExtendedMessage(extmsg);
  694. switch ( dialog.ShowModal() )
  695. {
  696. case wxID_YES:
  697. wxLogStatus(wxT("You pressed \"Yes\""));
  698. break;
  699. case wxID_NO:
  700. wxLogStatus(wxT("You pressed \"No\""));
  701. break;
  702. case wxID_CANCEL:
  703. wxLogStatus(wxT("You pressed \"Cancel\""));
  704. break;
  705. default:
  706. wxLogError(wxT("Unexpected wxMessageDialog return code!"));
  707. }
  708. }
  709. void MyFrame::MessageBoxWindowModal(wxCommandEvent& WXUNUSED(event))
  710. {
  711. wxMessageDialog* dialog = new wxMessageDialog(this,
  712. "This is a message box\n"
  713. "This is a long, long string to test out if the message box "
  714. "is laid out properly.",
  715. "Message box text",
  716. wxCENTER |
  717. wxNO_DEFAULT | wxYES_NO | wxCANCEL |
  718. wxICON_INFORMATION);
  719. wxString extmsg;
  720. if ( dialog->SetYesNoCancelLabels
  721. (
  722. "Answer &Yes",
  723. "Answer &No",
  724. "Refuse to answer"
  725. ) )
  726. {
  727. extmsg = "This platform supports custom button labels,\n"
  728. "so you should see the descriptive labels below.";
  729. }
  730. else
  731. {
  732. extmsg = "Custom button labels are not supported on this platform,\n"
  733. "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
  734. }
  735. dialog->SetExtendedMessage(extmsg);
  736. dialog->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed), NULL, this );
  737. dialog->ShowWindowModal();
  738. }
  739. void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event)
  740. {
  741. wxDialog* dialog = event.GetDialog();
  742. switch ( dialog->GetReturnCode() )
  743. {
  744. case wxID_YES:
  745. wxLogStatus(wxT("You pressed \"Yes\""));
  746. break;
  747. case wxID_NO:
  748. wxLogStatus(wxT("You pressed \"No\""));
  749. break;
  750. case wxID_CANCEL:
  751. wxLogStatus(wxT("You pressed \"Cancel\""));
  752. break;
  753. default:
  754. wxLogError(wxT("Unexpected wxMessageDialog return code!"));
  755. }
  756. delete dialog;
  757. }
  758. void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
  759. {
  760. TestMessageBoxDialog dlg(this);
  761. dlg.Create();
  762. dlg.ShowModal();
  763. }
  764. void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event))
  765. {
  766. ::wxInfoMessageBox(this);
  767. }
  768. #endif // wxUSE_MSGDLG
  769. #if wxUSE_RICHMSGDLG
  770. void MyFrame::RichMessageDialog(wxCommandEvent& WXUNUSED(event))
  771. {
  772. TestRichMessageDialog dlg(this);
  773. dlg.Create();
  774. dlg.ShowModal();
  775. }
  776. #endif // wxUSE_RICHMSGDLG
  777. #if wxUSE_NUMBERDLG
  778. void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event))
  779. {
  780. long res = wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
  781. wxT("Even two rows of text."),
  782. wxT("Enter a number:"), wxT("Numeric input test"),
  783. 50, 0, 100, this );
  784. wxString msg;
  785. int icon;
  786. if ( res == -1 )
  787. {
  788. msg = wxT("Invalid number entered or dialog cancelled.");
  789. icon = wxICON_HAND;
  790. }
  791. else
  792. {
  793. msg.Printf(wxT("You've entered %lu"), res );
  794. icon = wxICON_INFORMATION;
  795. }
  796. wxMessageBox(msg, wxT("Numeric test result"), wxOK | icon, this);
  797. }
  798. #endif // wxUSE_NUMBERDLG
  799. #if wxUSE_TEXTDLG
  800. void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
  801. {
  802. wxString pwd = wxGetPasswordFromUser(wxT("Enter password:"),
  803. wxT("Password entry dialog"),
  804. wxEmptyString,
  805. this);
  806. if ( !pwd.empty() )
  807. {
  808. wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
  809. wxT("Got password"), wxOK | wxICON_INFORMATION, this);
  810. }
  811. }
  812. void MyFrame::LineEntry(wxCommandEvent& WXUNUSED(event))
  813. {
  814. wxTextEntryDialog dialog(this,
  815. wxT("This is a small sample\n")
  816. wxT("A long, long string to test out the text entrybox"),
  817. wxT("Please enter a string"),
  818. wxT("Default value"),
  819. wxOK | wxCANCEL);
  820. if (dialog.ShowModal() == wxID_OK)
  821. {
  822. wxMessageBox(dialog.GetValue(), wxT("Got string"), wxOK | wxICON_INFORMATION, this);
  823. }
  824. }
  825. void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
  826. {
  827. wxTextEntryDialog dialog(this, "You can enter a multiline string here.",
  828. "Please enter some text",
  829. "First line\nSecond one\nAnd another one too",
  830. wxOK | wxCANCEL | wxTE_MULTILINE);
  831. if (dialog.ShowModal() == wxID_OK)
  832. {
  833. wxMessageBox(dialog.GetValue(), wxT("Got text"), wxOK | wxICON_INFORMATION, this);
  834. }
  835. }
  836. #endif // wxUSE_TEXTDLG
  837. #if wxUSE_CHOICEDLG
  838. void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
  839. {
  840. const wxString choices[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
  841. wxSingleChoiceDialog dialog(this,
  842. wxT("This is a small sample\n")
  843. wxT("A single-choice convenience dialog"),
  844. wxT("Please select a value"),
  845. WXSIZEOF(choices), choices);
  846. dialog.SetSelection(2);
  847. if (dialog.ShowModal() == wxID_OK)
  848. {
  849. wxMessageDialog dialog2(this, dialog.GetStringSelection(), wxT("Got string"));
  850. dialog2.ShowModal();
  851. }
  852. }
  853. void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
  854. {
  855. const wxString choices[] =
  856. {
  857. wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
  858. wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
  859. wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
  860. };
  861. wxArrayInt selections;
  862. const int count = wxGetSelectedChoices(selections,
  863. wxT("This is a small sample\n")
  864. wxT("A multi-choice convenience dialog"),
  865. wxT("Please select a value"),
  866. WXSIZEOF(choices), choices,
  867. this);
  868. if ( count >= 0 )
  869. {
  870. wxString msg;
  871. if ( count == 0 )
  872. {
  873. msg = wxT("You did not select any items");
  874. }
  875. else
  876. {
  877. msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
  878. for ( int n = 0; n < count; n++ )
  879. {
  880. msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
  881. (unsigned)n, (unsigned)selections[n],
  882. choices[selections[n]].c_str());
  883. }
  884. }
  885. wxLogMessage(msg);
  886. }
  887. //else: cancelled
  888. }
  889. #endif // wxUSE_CHOICEDLG
  890. #if wxUSE_REARRANGECTRL
  891. // custom rearrange dialog: it adds the possibility to rename an item to the
  892. // base class functionality
  893. class MyRearrangeDialog : public wxRearrangeDialog
  894. {
  895. public:
  896. MyRearrangeDialog(wxWindow *parent,
  897. wxArrayInt& order,
  898. wxArrayString& labels,
  899. wxArrayString& labelsOrig)
  900. : wxRearrangeDialog
  901. (
  902. parent,
  903. "Configure the columns shown:",
  904. "wxRearrangeDialog example",
  905. order,
  906. labels
  907. ),
  908. m_order(order),
  909. m_labels(labels),
  910. m_labelsOrig(labelsOrig)
  911. {
  912. m_sel = wxNOT_FOUND;
  913. wxPanel * const panel = new wxPanel(this);
  914. wxSizer * const sizer = new wxBoxSizer(wxHORIZONTAL);
  915. m_labelOrig = new wxStaticText(panel, wxID_ANY, "");
  916. sizer->Add(m_labelOrig, wxSizerFlags().Centre().Border(wxRIGHT));
  917. m_text = new wxTextCtrl(panel, wxID_ANY, "",
  918. wxDefaultPosition, wxDefaultSize,
  919. wxTE_PROCESS_ENTER);
  920. sizer->Add(m_text, wxSizerFlags().Centre().Border(wxRIGHT));
  921. sizer->Add(new wxButton(panel, wxID_APPLY, "&Rename"),
  922. wxSizerFlags().Centre());
  923. panel->SetSizer(sizer);
  924. // call this first to ensure that the controls have a reasonable best
  925. // size before they're added
  926. DoUpdateExtraControls(GetList()->GetSelection());
  927. AddExtraControls(panel);
  928. // another customization not directly supported by the dialog: add a
  929. // custom button
  930. wxWindow * const btnOk = FindWindow(wxID_OK);
  931. wxCHECK_RET( btnOk, "no Ok button?" );
  932. wxSizer * const sizerBtns = btnOk->GetContainingSizer();
  933. wxCHECK_RET( sizerBtns, "no buttons sizer?" );
  934. sizerBtns->Add(new wxButton(this, wxID_RESET, "&Reset all"),
  935. wxSizerFlags().Border(wxLEFT));
  936. }
  937. // call this instead of ShowModal() to update order and labels array in
  938. // case the dialog was not cancelled
  939. bool Rearrange()
  940. {
  941. switch ( ShowModal() )
  942. {
  943. case wxID_CANCEL:
  944. return false;
  945. case wxID_OK:
  946. m_order = GetOrder();
  947. break;
  948. case wxID_RESET:
  949. // order already reset
  950. break;
  951. }
  952. return true;
  953. }
  954. private:
  955. void OnSelChange(wxCommandEvent& event)
  956. {
  957. DoUpdateExtraControls(event.GetInt());
  958. }
  959. void OnUpdateUIRename(wxUpdateUIEvent& event)
  960. {
  961. event.Enable( CanRename() );
  962. }
  963. void OnRename(wxCommandEvent& WXUNUSED(event))
  964. {
  965. if ( !CanRename() )
  966. return;
  967. m_labels[m_sel] = m_text->GetValue();
  968. GetList()->SetString(m_sel, m_labels[m_sel]);
  969. }
  970. void OnReset(wxCommandEvent& WXUNUSED(event))
  971. {
  972. // in a real program we should probably ask if the user really wants to
  973. // do this but here we just go ahead and reset all columns labels and
  974. // their order without confirmation
  975. const unsigned count = m_order.size();
  976. for ( unsigned n = 0; n < count; n++ )
  977. {
  978. m_order[n] = n;
  979. m_labels[n] = m_labelsOrig[n];
  980. }
  981. EndModal(wxID_RESET);
  982. }
  983. bool CanRename() const
  984. {
  985. // only allow renaming if the user modified the currently selected item
  986. // text (which presupposes that we do have a current item)
  987. return m_sel != wxNOT_FOUND && m_text->GetValue() != m_labels[m_sel];
  988. }
  989. void DoUpdateExtraControls(int sel)
  990. {
  991. m_sel = sel;
  992. if ( m_sel == wxNOT_FOUND )
  993. {
  994. m_labelOrig->SetLabel("<no selection>");
  995. m_text->Clear();
  996. m_text->Disable();
  997. }
  998. else // have valid item
  999. {
  1000. m_labelOrig->SetLabelText(m_labelsOrig[m_sel]);
  1001. m_text->Enable();
  1002. m_text->SetValue(m_labels[m_sel]);
  1003. }
  1004. }
  1005. wxArrayInt& m_order;
  1006. wxArrayString& m_labels,
  1007. m_labelsOrig;
  1008. int m_sel;
  1009. wxStaticText *m_labelOrig;
  1010. wxTextCtrl *m_text;
  1011. wxDECLARE_EVENT_TABLE();
  1012. wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog);
  1013. };
  1014. wxBEGIN_EVENT_TABLE(MyRearrangeDialog, wxRearrangeDialog)
  1015. EVT_LISTBOX(wxID_ANY, MyRearrangeDialog::OnSelChange)
  1016. EVT_UPDATE_UI(wxID_APPLY, MyRearrangeDialog::OnUpdateUIRename)
  1017. EVT_TEXT_ENTER(wxID_ANY, MyRearrangeDialog::OnRename)
  1018. EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename)
  1019. EVT_BUTTON(wxID_RESET, MyRearrangeDialog::OnReset)
  1020. wxEND_EVENT_TABLE()
  1021. void MyFrame::Rearrange(wxCommandEvent& WXUNUSED(event))
  1022. {
  1023. // the arrays are static so that we preserve the items order between calls
  1024. // to this function
  1025. static wxArrayInt s_order;
  1026. static wxArrayString s_labels,
  1027. s_labelsOrig;
  1028. // initialize them on the first call
  1029. if ( s_labelsOrig.empty() )
  1030. {
  1031. static const struct ItemInfo
  1032. {
  1033. const char *label;
  1034. const char *labelOrig;
  1035. int order;
  1036. } items[] =
  1037. {
  1038. { "File name", "Name", 0 },
  1039. { "File type", "Ext", 1 },
  1040. { "Size", "Size", 2 },
  1041. { "Creation time", "Ctime", ~3 }, // negated so hidden
  1042. { "Last accessed", "Atime", ~4 },
  1043. { "Last modified", "Mtime", 5 },
  1044. };
  1045. s_order.reserve(WXSIZEOF(items));
  1046. s_labels.reserve(WXSIZEOF(items));
  1047. s_labelsOrig.reserve(WXSIZEOF(items));
  1048. for ( unsigned n = 0; n < WXSIZEOF(items); n++ )
  1049. {
  1050. const ItemInfo& item = items[n];
  1051. s_order.push_back(item.order);
  1052. s_labels.push_back(item.label);
  1053. s_labelsOrig.push_back(item.labelOrig);
  1054. }
  1055. }
  1056. MyRearrangeDialog dlg(this, s_order, s_labels, s_labelsOrig);
  1057. if ( !dlg.Rearrange() )
  1058. return;
  1059. wxString columns;
  1060. for ( unsigned n = 0; n < s_order.size(); n++ )
  1061. {
  1062. columns += wxString::Format("\n %u: ", n);
  1063. int idx = s_order[n];
  1064. if ( idx < 0 )
  1065. {
  1066. columns += "[hidden] ";
  1067. idx = ~idx;
  1068. }
  1069. columns += s_labels[idx];
  1070. if ( s_labels[idx] != s_labelsOrig[idx] )
  1071. {
  1072. columns += wxString::Format(" (original label: \"%s\")",
  1073. s_labelsOrig[idx]);
  1074. }
  1075. }
  1076. wxLogMessage("The columns order now is:%s", columns);
  1077. }
  1078. #endif // wxUSE_REARRANGECTRL
  1079. #if wxUSE_FILEDLG
  1080. // panel with custom controls for file dialog
  1081. class MyExtraPanel : public wxPanel
  1082. {
  1083. public:
  1084. MyExtraPanel(wxWindow *parent);
  1085. wxString GetInfo() const
  1086. {
  1087. return wxString::Format("checkbox value = %d", (int) m_cb->GetValue());
  1088. }
  1089. private:
  1090. void OnCheckBox(wxCommandEvent& event) { m_btn->Enable(event.IsChecked()); }
  1091. void OnUpdateLabelUI(wxUpdateUIEvent& event)
  1092. {
  1093. wxFileDialog* const dialog = wxStaticCast(GetParent(), wxFileDialog);
  1094. const wxString fn = dialog->GetCurrentlySelectedFilename();
  1095. wxString msg;
  1096. if ( fn.empty() )
  1097. msg = "Nothing";
  1098. else if ( wxFileName::FileExists(fn) )
  1099. msg = "File";
  1100. else if ( wxFileName::DirExists(fn) )
  1101. msg = "Directory";
  1102. else
  1103. msg = "Something else";
  1104. event.SetText(msg + " selected");
  1105. }
  1106. wxButton *m_btn;
  1107. wxCheckBox *m_cb;
  1108. wxStaticText *m_label;
  1109. };
  1110. MyExtraPanel::MyExtraPanel(wxWindow *parent)
  1111. : wxPanel(parent)
  1112. {
  1113. m_btn = new wxButton(this, -1, wxT("Custom Button"));
  1114. m_btn->Enable(false);
  1115. m_cb = new wxCheckBox(this, -1, wxT("Enable Custom Button"));
  1116. m_cb->Connect(wxEVT_CHECKBOX,
  1117. wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this);
  1118. m_label = new wxStaticText(this, wxID_ANY, "Nothing selected");
  1119. m_label->Connect(wxEVT_UPDATE_UI,
  1120. wxUpdateUIEventHandler(MyExtraPanel::OnUpdateLabelUI),
  1121. NULL, this);
  1122. wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
  1123. sizerTop->Add(m_cb, wxSizerFlags().Centre().Border());
  1124. sizerTop->AddStretchSpacer();
  1125. sizerTop->Add(m_btn, wxSizerFlags().Centre().Border());
  1126. sizerTop->AddStretchSpacer();
  1127. sizerTop->Add(m_label, wxSizerFlags().Centre().Border());
  1128. SetSizerAndFit(sizerTop);
  1129. }
  1130. // a static method can be used instead of a function with most of compilers
  1131. static wxWindow* createMyExtraPanel(wxWindow *parent)
  1132. {
  1133. return new MyExtraPanel(parent);
  1134. }
  1135. void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
  1136. {
  1137. wxFileDialog dialog
  1138. (
  1139. this,
  1140. wxT("Testing open file dialog"),
  1141. wxEmptyString,
  1142. wxEmptyString,
  1143. #ifdef __WXMOTIF__
  1144. wxT("C++ files (*.cpp)|*.cpp")
  1145. #else
  1146. wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
  1147. #endif
  1148. );
  1149. dialog.SetExtraControlCreator(&createMyExtraPanel);
  1150. dialog.CentreOnParent();
  1151. dialog.SetDirectory(wxGetHomeDir());
  1152. if (dialog.ShowModal() == wxID_OK)
  1153. {
  1154. wxString info;
  1155. wxWindow * const extra = dialog.GetExtraControl();
  1156. info.Printf(wxT("Full file name: %s\n")
  1157. wxT("Path: %s\n")
  1158. wxT("Name: %s\n")
  1159. wxT("Custom window: %s"),
  1160. dialog.GetPath().c_str(),
  1161. dialog.GetDirectory().c_str(),
  1162. dialog.GetFilename().c_str(),
  1163. extra ? static_cast<MyExtraPanel*>(extra)->GetInfo()
  1164. : wxString("None"));
  1165. wxMessageDialog dialog2(this, info, wxT("Selected file"));
  1166. dialog2.ShowModal();
  1167. }
  1168. }
  1169. // this shows how to take advantage of specifying a default extension in the
  1170. // call to wxFileSelector: it is remembered after each new call and the next
  1171. // one will use it by default
  1172. void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
  1173. {
  1174. static wxString s_extDef;
  1175. wxString path = wxFileSelector(
  1176. wxT("Select the file to load"),
  1177. wxEmptyString, wxEmptyString,
  1178. s_extDef,
  1179. wxString::Format
  1180. (
  1181. wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
  1182. wxFileSelectorDefaultWildcardStr,
  1183. wxFileSelectorDefaultWildcardStr
  1184. ),
  1185. wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW,
  1186. this
  1187. );
  1188. if ( !path )
  1189. return;
  1190. // it is just a sample, would use wxSplitPath in real program
  1191. s_extDef = path.AfterLast(wxT('.'));
  1192. wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
  1193. path, s_extDef);
  1194. }
  1195. void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
  1196. {
  1197. wxString wildcards =
  1198. #ifdef __WXMOTIF__
  1199. wxT("C++ files (*.cpp)|*.cpp");
  1200. #else
  1201. wxString::Format
  1202. (
  1203. wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
  1204. wxFileSelectorDefaultWildcardStr,
  1205. wxFileSelectorDefaultWildcardStr
  1206. );
  1207. #endif
  1208. wxFileDialog dialog(this, wxT("Testing open multiple file dialog"),
  1209. wxEmptyString, wxEmptyString, wildcards,
  1210. wxFD_OPEN|wxFD_MULTIPLE);
  1211. if (dialog.ShowModal() == wxID_OK)
  1212. {
  1213. wxArrayString paths, filenames;
  1214. dialog.GetPaths(paths);
  1215. dialog.GetFilenames(filenames);
  1216. wxString msg, s;
  1217. size_t count = paths.GetCount();
  1218. for ( size_t n = 0; n < count; n++ )
  1219. {
  1220. s.Printf(wxT("File %d: %s (%s)\n"),
  1221. (int)n, paths[n].c_str(), filenames[n].c_str());
  1222. msg += s;
  1223. }
  1224. s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex());
  1225. msg += s;
  1226. wxMessageDialog dialog2(this, msg, wxT("Selected files"));
  1227. dialog2.ShowModal();
  1228. }
  1229. }
  1230. void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
  1231. {
  1232. wxFileDialog dialog(this,
  1233. wxT("Testing save file dialog"),
  1234. wxEmptyString,
  1235. wxT("myletter.doc"),
  1236. wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
  1237. wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
  1238. dialog.SetFilterIndex(1);
  1239. if (dialog.ShowModal() == wxID_OK)
  1240. {
  1241. wxLogMessage(wxT("%s, filter %d"),
  1242. dialog.GetPath().c_str(), dialog.GetFilterIndex());
  1243. }
  1244. }
  1245. #endif // wxUSE_FILEDLG
  1246. #if USE_FILEDLG_GENERIC
  1247. void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
  1248. {
  1249. wxGenericFileDialog dialog
  1250. (
  1251. this,
  1252. wxT("Testing open file dialog"),
  1253. wxEmptyString,
  1254. wxEmptyString,
  1255. wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
  1256. );
  1257. dialog.SetExtraControlCreator(&createMyExtraPanel);
  1258. dialog.SetDirectory(wxGetHomeDir());
  1259. if (dialog.ShowModal() == wxID_OK)
  1260. {
  1261. wxString info;
  1262. info.Printf(wxT("Full file name: %s\n")
  1263. wxT("Path: %s\n")
  1264. wxT("Name: %s"),
  1265. dialog.GetPath().c_str(),
  1266. dialog.GetDirectory().c_str(),
  1267. dialog.GetFilename().c_str());
  1268. wxMessageDialog dialog2(this, info, wxT("Selected file"));
  1269. dialog2.ShowModal();
  1270. }
  1271. }
  1272. void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
  1273. {
  1274. // On PocketPC you can disable OK-only dialogs policy using system option
  1275. int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
  1276. wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
  1277. wxString wildcards = wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
  1278. wxGenericFileDialog dialog(this, wxT("Testing open multiple file dialog"),
  1279. wxEmptyString, wxEmptyString, wildcards,
  1280. wxFD_MULTIPLE);
  1281. if (dialog.ShowModal() == wxID_OK)
  1282. {
  1283. wxArrayString paths, filenames;
  1284. dialog.GetPaths(paths);
  1285. dialog.GetFilenames(filenames);
  1286. wxString msg, s;
  1287. size_t count = paths.GetCount();
  1288. for ( size_t n = 0; n < count; n++ )
  1289. {
  1290. s.Printf(wxT("File %d: %s (%s)\n"),
  1291. (int)n, paths[n].c_str(), filenames[n].c_str());
  1292. msg += s;
  1293. }
  1294. s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex());
  1295. msg += s;
  1296. wxMessageDialog dialog2(this, msg, wxT("Selected files"));
  1297. dialog2.ShowModal();
  1298. }
  1299. // restore system option
  1300. wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons);
  1301. }
  1302. void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
  1303. {
  1304. wxGenericFileDialog dialog(this,
  1305. wxT("Testing save file dialog"),
  1306. wxEmptyString,
  1307. wxT("myletter.doc"),
  1308. wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
  1309. wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
  1310. dialog.SetFilterIndex(1);
  1311. if (dialog.ShowModal() == wxID_OK)
  1312. {
  1313. wxLogMessage(wxT("%s, filter %d"),
  1314. dialog.GetPath().c_str(), dialog.GetFilterIndex());
  1315. }
  1316. }
  1317. #endif // USE_FILEDLG_GENERIC
  1318. #if wxUSE_DIRDLG
  1319. void MyFrame::DoDirChoose(int style)
  1320. {
  1321. // pass some initial dir to wxDirDialog
  1322. wxString dirHome;
  1323. wxGetHomeDir(&dirHome);
  1324. wxDirDialog dialog(this, wxT("Testing directory picker"), dirHome, style);
  1325. if (dialog.ShowModal() == wxID_OK)
  1326. {
  1327. wxLogMessage(wxT("Selected path: %s"), dialog.GetPath().c_str());
  1328. }
  1329. }
  1330. void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
  1331. {
  1332. DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
  1333. }
  1334. void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
  1335. {
  1336. DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST);
  1337. }
  1338. #endif // wxUSE_DIRDLG
  1339. #if USE_DIRDLG_GENERIC
  1340. void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
  1341. {
  1342. // pass some initial dir to wxDirDialog
  1343. wxString dirHome;
  1344. wxGetHomeDir(&dirHome);
  1345. wxGenericDirDialog dialog(this, wxT("Testing generic directory picker"), dirHome);
  1346. if (dialog.ShowModal() == wxID_OK)
  1347. {
  1348. wxMessageDialog dialog2(this, dialog.GetPath(), wxT("Selected path"));
  1349. dialog2.ShowModal();
  1350. }
  1351. }
  1352. #endif // USE_DIRDLG_GENERIC
  1353. #if USE_MODAL_PRESENTATION
  1354. void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
  1355. {
  1356. MyModalDialog dlg(this);
  1357. dlg.ShowModal();
  1358. }
  1359. #endif // USE_MODAL_PRESENTATION
  1360. void MyFrame::ModelessDlg(wxCommandEvent& event)
  1361. {
  1362. bool show = GetMenuBar()->IsChecked(event.GetId());
  1363. if ( show )
  1364. {
  1365. if ( !m_dialog )
  1366. {
  1367. m_dialog = new MyModelessDialog(this);
  1368. }
  1369. m_dialog->Show(true);
  1370. }
  1371. else // hide
  1372. {
  1373. // If m_dialog is NULL, then possibly the system
  1374. // didn't report the checked menu item status correctly.
  1375. // It should be true just after the menu item was selected,
  1376. // if there was no modeless dialog yet.
  1377. wxASSERT( m_dialog != NULL );
  1378. if (m_dialog)
  1379. m_dialog->Hide();
  1380. }
  1381. }
  1382. void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event))
  1383. {
  1384. wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on screen"),
  1385. wxDefaultPosition, wxSize(200, 100));
  1386. (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
  1387. dlg.CentreOnScreen();
  1388. dlg.ShowModal();
  1389. }
  1390. void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event))
  1391. {
  1392. wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on parent"),
  1393. wxDefaultPosition, wxSize(200, 100));
  1394. (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
  1395. dlg.CentreOnParent();
  1396. dlg.ShowModal();
  1397. }
  1398. #if wxUSE_MINIFRAME
  1399. void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event))
  1400. {
  1401. wxFrame *frame = new wxMiniFrame(this, wxID_ANY, wxT("Mini frame"),
  1402. wxDefaultPosition, wxSize(300, 100),
  1403. wxCAPTION | wxCLOSE_BOX);
  1404. new wxStaticText(frame,
  1405. wxID_ANY,
  1406. wxT("Mini frames have slightly different appearance"),
  1407. wxPoint(5, 5));
  1408. new wxStaticText(frame,
  1409. wxID_ANY,
  1410. wxT("from the normal frames but that's the only difference."),
  1411. wxPoint(5, 25));
  1412. frame->CentreOnParent();
  1413. frame->Show();
  1414. }
  1415. #endif // wxUSE_MINIFRAME
  1416. void MyFrame::DlgOnTop(wxCommandEvent& WXUNUSED(event))
  1417. {
  1418. wxDialog dlg(this, wxID_ANY, wxT("Dialog staying on top of other windows"),
  1419. wxDefaultPosition, wxSize(300, 100),
  1420. wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP);
  1421. (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
  1422. dlg.ShowModal();
  1423. }
  1424. #if wxUSE_STARTUP_TIPS
  1425. void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
  1426. {
  1427. static size_t s_index = (size_t)-1;
  1428. if ( s_index == (size_t)-1 )
  1429. {
  1430. srand(time(NULL));
  1431. // this is completely bogus, we don't know how many lines are there
  1432. // in the file, but who cares, it's a demo only...
  1433. s_index = rand() % 5;
  1434. }
  1435. wxTipProvider *tipProvider = wxCreateFileTipProvider(wxT("tips.txt"), s_index);
  1436. bool showAtStartup = wxShowTip(this, tipProvider);
  1437. if ( showAtStartup )
  1438. {
  1439. wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
  1440. wxOK | wxICON_INFORMATION, this);
  1441. }
  1442. s_index = tipProvider->GetCurrentTip();
  1443. delete tipProvider;
  1444. }
  1445. #endif // wxUSE_STARTUP_TIPS
  1446. #if USE_SETTINGS_DIALOG
  1447. void MyFrame::OnPropertySheet(wxCommandEvent& event)
  1448. {
  1449. SettingsDialog dialog(this, event.GetId());
  1450. dialog.ShowModal();
  1451. }
  1452. #endif // USE_SETTINGS_DIALOG
  1453. void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
  1454. {
  1455. wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
  1456. wxSleep(3);
  1457. RequestUserAttention(wxUSER_ATTENTION_ERROR);
  1458. }
  1459. #if wxUSE_NOTIFICATION_MESSAGE
  1460. void MyFrame::OnNotifMsgAuto(wxCommandEvent& WXUNUSED(event))
  1461. {
  1462. // Notice that the notification remains shown even after the
  1463. // wxNotificationMessage object itself is destroyed so we can show simple
  1464. // notifications using temporary objects.
  1465. if ( !wxNotificationMessage
  1466. (
  1467. "Automatic Notification",
  1468. "Nothing important has happened\n"
  1469. "this notification will disappear soon."
  1470. ).Show() )
  1471. {
  1472. wxLogStatus("Failed to show notification message");
  1473. }
  1474. // But it doesn't have to be a temporary, of course.
  1475. wxNotificationMessage n("Dummy Warning", "Example of a warning notification.");
  1476. n.SetFlags(wxICON_ERROR);
  1477. n.Show(5); // Just for testing, use 5 second delay.
  1478. }
  1479. void MyFrame::OnNotifMsgShow(wxCommandEvent& WXUNUSED(event))
  1480. {
  1481. if ( !m_notifMsg )
  1482. {
  1483. m_notifMsg = new wxNotificationMessage
  1484. (
  1485. "wxWidgets Manual Notification",
  1486. "You can hide this notification from the menu",
  1487. this
  1488. );
  1489. }
  1490. if ( !m_notifMsg->Show(wxNotificationMessage::Timeout_Never) )
  1491. {
  1492. wxLogStatus("Failed to show manual notification message");
  1493. }
  1494. }
  1495. void MyFrame::OnNotifMsgHide(wxCommandEvent& WXUNUSED(event))
  1496. {
  1497. if ( m_notifMsg && !m_notifMsg->Close() )
  1498. {
  1499. wxLogStatus("Failed to hide manual notification message");
  1500. }
  1501. }
  1502. #endif // wxUSE_NOTIFICATION_MESSAGE
  1503. #if wxUSE_RICHTOOLTIP
  1504. #include "wx/richtooltip.h"
  1505. #include "tip.xpm"
  1506. class RichTipDialog : public wxDialog
  1507. {
  1508. public:
  1509. RichTipDialog(wxWindow* parent)
  1510. : wxDialog(parent, wxID_ANY, "wxRichToolTip Test",
  1511. wxDefaultPosition, wxDefaultSize,
  1512. wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
  1513. {
  1514. // Create the controls.
  1515. m_textTitle = new wxTextCtrl(this, wxID_ANY, "Tooltip title");
  1516. m_textBody = new wxTextCtrl(this, wxID_ANY, "Main tooltip text\n"
  1517. "possibly on several\n"
  1518. "lines.",
  1519. wxDefaultPosition, wxDefaultSize,
  1520. wxTE_MULTILINE);
  1521. wxButton* btnShowText = new wxButton(this, wxID_ANY, "Show for &text");
  1522. wxButton* btnShowBtn = new wxButton(this, wxID_ANY, "Show for &button");
  1523. const wxString icons[] =
  1524. {
  1525. "&None",
  1526. "&Information",
  1527. "&Warning",
  1528. "&Error",
  1529. "&Custom"
  1530. };
  1531. wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == Icon_Max, IconMismatch );
  1532. m_icons = new wxRadioBox(this, wxID_ANY, "&Icon choice:",
  1533. wxDefaultPosition, wxDefaultSize,
  1534. WXSIZEOF(icons), icons,
  1535. 1, wxRA_SPECIFY_ROWS);
  1536. m_icons->SetSelection(Icon_Info);
  1537. const wxString tipKinds[] =
  1538. {
  1539. "&None", "Top left", "Top", "Top right",
  1540. "Bottom left", "Bottom", "Bottom right", "&Auto"
  1541. };
  1542. m_tipKinds = new wxRadioBox(this, wxID_ANY, "Tip &kind:",
  1543. wxDefaultPosition, wxDefaultSize,
  1544. WXSIZEOF(tipKinds), tipKinds,
  1545. 4, wxRA_SPECIFY_COLS);
  1546. m_tipKinds->SetSelection(wxTipKind_Auto);
  1547. const wxString bgStyles[] =
  1548. {
  1549. "&Default", "&Solid", "&Gradient",
  1550. };
  1551. wxCOMPILE_TIME_ASSERT( WXSIZEOF(bgStyles) == Bg_Max, BgMismatch );
  1552. m_bgStyles = new wxRadioBox(this, wxID_ANY, "Background style:",
  1553. wxDefaultPosition, wxDefaultSize,
  1554. WXSIZEOF(bgStyles), bgStyles,
  1555. 1, wxRA_SPECIFY_ROWS);
  1556. const wxString timeouts[] = { "&None", "&Default (no delay)", "&3 seconds" };
  1557. wxCOMPILE_TIME_ASSERT( WXSIZEOF(timeouts) == Timeout_Max, TmMismatch );
  1558. m_timeouts = new wxRadioBox(this, wxID_ANY, "Timeout:",
  1559. wxDefaultPosition, wxDefaultSize,
  1560. WXSIZEOF(timeouts), timeouts,
  1561. 1, wxRA_SPECIFY_ROWS);
  1562. m_timeouts->SetSelection(Timeout_Default);
  1563. m_timeDelay = new wxCheckBox(this, wxID_ANY, "Delay show" );
  1564. // Lay them out.
  1565. m_textBody->SetMinSize(wxSize(300, 200));
  1566. wxBoxSizer* const sizer = new wxBoxSizer(wxVERTICAL);
  1567. sizer->Add(m_textTitle, wxSizerFlags().Expand().Border());
  1568. sizer->Add(m_textBody, wxSizerFlags(1).Expand().Border());
  1569. sizer->Add(m_icons, wxSizerFlags().Expand().Border());
  1570. sizer->Add(m_tipKinds, wxSizerFlags().Centre().Border());
  1571. sizer->Add(m_bgStyles, wxSizerFlags().Centre().Border());
  1572. sizer->Add(m_timeouts, wxSizerFlags().Centre().Border());
  1573. sizer->Add(m_timeDelay, wxSizerFlags().Centre().Border());
  1574. wxBoxSizer* const sizerBtns = new wxBoxSizer(wxHORIZONTAL);
  1575. sizerBtns->Add(btnShowText, wxSizerFlags().Border(wxRIGHT));
  1576. sizerBtns->Add(btnShowBtn, wxSizerFlags().Border(wxLEFT));
  1577. sizer->Add(sizerBtns, wxSizerFlags().Centre().Border());
  1578. sizer->Add(CreateStdDialogButtonSizer(wxOK),
  1579. wxSizerFlags().Expand().Border());
  1580. SetSizerAndFit(sizer);
  1581. // And connect the event handlers.
  1582. btnShowText->Connect
  1583. (
  1584. wxEVT_BUTTON,
  1585. wxCommandEventHandler(RichTipDialog::OnShowTipForText),
  1586. NULL,
  1587. this
  1588. );
  1589. btnShowBtn->Connect
  1590. (
  1591. wxEVT_BUTTON,
  1592. wxCommandEventHandler(RichTipDialog::OnShowTipForBtn),
  1593. NULL,
  1594. this
  1595. );
  1596. }
  1597. private:
  1598. enum
  1599. {
  1600. Icon_None,
  1601. Icon_Info,
  1602. Icon_Warning,
  1603. Icon_Error,
  1604. Icon_Custom,
  1605. Icon_Max
  1606. };
  1607. enum
  1608. {
  1609. Bg_Default,
  1610. Bg_Solid,
  1611. Bg_Gradient,
  1612. Bg_Max
  1613. };
  1614. enum
  1615. {
  1616. Timeout_None,
  1617. Timeout_Default,
  1618. Timeout_3sec,
  1619. Timeout_Max
  1620. };
  1621. void OnShowTipForText(wxCommandEvent& WXUNUSED(event))
  1622. {
  1623. DoShowTip(m_textTitle);
  1624. }
  1625. void OnShowTipForBtn(wxCommandEvent& WXUNUSED(event))
  1626. {
  1627. DoShowTip(FindWindow(wxID_OK));
  1628. }
  1629. void DoShowTip(wxWindow* win)
  1630. {
  1631. wxRichToolTip tip(m_textTitle->GetValue(), m_textBody->GetValue());
  1632. const int iconSel = m_icons->GetSelection();
  1633. if ( iconSel == Icon_Custom )
  1634. {
  1635. tip.SetIcon(tip_xpm);
  1636. }
  1637. else // Use a standard icon.
  1638. {
  1639. static const int stdIcons[] =
  1640. {
  1641. wxICON_NONE,
  1642. wxICON_INFORMATION,
  1643. wxICON_WARNING,
  1644. wxICON_ERROR,
  1645. };
  1646. tip.SetIcon(stdIcons[iconSel]);
  1647. }
  1648. switch ( m_bgStyles->GetSelection() )
  1649. {
  1650. case Bg_Default:
  1651. break;
  1652. case Bg_Solid:
  1653. tip.SetBackgroundColour(*wxLIGHT_GREY);
  1654. break;
  1655. case Bg_Gradient:
  1656. tip.SetBackgroundColour(*wxWHITE, wxColour(0xe4, 0xe5, 0xf0));
  1657. break;
  1658. }
  1659. int delay = m_timeDelay->IsChecked() ? 500 : 0;
  1660. switch ( m_timeouts->GetSelection() )
  1661. {
  1662. case Timeout_None:
  1663. // Don't call SetTimeout unnecessarily
  1664. // or msw will show generic impl
  1665. if ( delay )
  1666. tip.SetTimeout(0, delay);
  1667. break;
  1668. case Timeout_Default:
  1669. break;
  1670. case Timeout_3sec:
  1671. tip.SetTimeout(3000, delay);
  1672. break;
  1673. }
  1674. tip.SetTipKind(static_cast<wxTipKind>(m_tipKinds->GetSelection()));
  1675. tip.ShowFor(win);
  1676. }
  1677. wxTextCtrl* m_textTitle;
  1678. wxTextCtrl* m_textBody;
  1679. wxRadioBox* m_icons;
  1680. wxRadioBox* m_tipKinds;
  1681. wxRadioBox* m_bgStyles;
  1682. wxRadioBox* m_timeouts;
  1683. wxCheckBox* m_timeDelay;
  1684. };
  1685. void MyFrame::OnRichTipDialog(wxCommandEvent& WXUNUSED(event))
  1686. {
  1687. RichTipDialog dialog(this);
  1688. dialog.ShowModal();
  1689. }
  1690. #endif // wxUSE_RICHTOOLTIP
  1691. void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
  1692. {
  1693. StdButtonSizerDialog dialog(this);
  1694. dialog.ShowModal();
  1695. }
  1696. // TestDefaultAction
  1697. #define ID_CATCH_LISTBOX_DCLICK 100
  1698. #define ID_LISTBOX 101
  1699. #define ID_DISABLE_OK 102
  1700. #define ID_DISABLE_CANCEL 103
  1701. wxBEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
  1702. EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick)
  1703. EVT_CHECKBOX(ID_DISABLE_OK, TestDefaultActionDialog::OnDisableOK)
  1704. EVT_CHECKBOX(ID_DISABLE_CANCEL, TestDefaultActionDialog::OnDisableCancel)
  1705. EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick)
  1706. EVT_TEXT_ENTER(wxID_ANY, TestDefaultActionDialog::OnTextEnter)
  1707. wxEND_EVENT_TABLE()
  1708. TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
  1709. wxDialog( parent, -1, "Test default action" )
  1710. {
  1711. m_catchListBoxDClick = false;
  1712. wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
  1713. wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 );
  1714. #if wxUSE_LISTBOX
  1715. wxListBox *listbox = new wxListBox( this, ID_LISTBOX );
  1716. listbox->Append( "String 1" );
  1717. listbox->Append( "String 2" );
  1718. listbox->Append( "String 3" );
  1719. listbox->Append( "String 4" );
  1720. grid_sizer->Add( listbox );
  1721. #endif // wxUSE_LISTBOX
  1722. grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL );
  1723. grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL );
  1724. grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
  1725. grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
  1726. grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
  1727. grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_OK, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL );
  1728. grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_CANCEL, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL );
  1729. main_sizer->Add( grid_sizer, 0, wxALL, 10 );
  1730. wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
  1731. if (button_sizer)
  1732. main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 );
  1733. SetSizerAndFit( main_sizer );
  1734. }
  1735. void TestDefaultActionDialog::OnDisableOK(wxCommandEvent& event)
  1736. {
  1737. FindWindow(wxID_OK)->Enable(!event.IsChecked());
  1738. }
  1739. void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent& event)
  1740. {
  1741. FindWindow(wxID_CANCEL)->Enable(!event.IsChecked());
  1742. }
  1743. void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
  1744. {
  1745. event.Skip( !m_catchListBoxDClick );
  1746. }
  1747. void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event))
  1748. {
  1749. m_catchListBoxDClick = !m_catchListBoxDClick;
  1750. }
  1751. void TestDefaultActionDialog::OnTextEnter(wxCommandEvent& event)
  1752. {
  1753. wxLogMessage("Text \"%s\" entered.", event.GetString());
  1754. }
  1755. void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
  1756. {
  1757. TestDefaultActionDialog dialog( this );
  1758. dialog.ShowModal();
  1759. }
  1760. void MyFrame::OnModalHook(wxCommandEvent& event)
  1761. {
  1762. class TestModalHook : public wxModalDialogHook
  1763. {
  1764. protected:
  1765. virtual int Enter(wxDialog* dialog)
  1766. {
  1767. wxLogStatus("Showing %s modal dialog",
  1768. dialog->GetClassInfo()->GetClassName());
  1769. return wxID_NONE;
  1770. }
  1771. virtual void Exit(wxDialog* dialog)
  1772. {
  1773. wxLogStatus("Leaving %s modal dialog",
  1774. dialog->GetClassInfo()->GetClassName());
  1775. }
  1776. };
  1777. static TestModalHook s_hook;
  1778. if ( event.IsChecked() )
  1779. s_hook.Register();
  1780. else
  1781. s_hook.Unregister();
  1782. }
  1783. void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
  1784. {
  1785. Close(true);
  1786. }
  1787. #if wxUSE_PROGRESSDLG
  1788. void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
  1789. {
  1790. static const int max = 100;
  1791. wxProgressDialog dialog("Progress dialog example",
  1792. // "Reserve" enough space for the multiline
  1793. // messages below, we'll change it anyhow
  1794. // immediately in the loop below
  1795. wxString(' ', 100) + "\n\n\n\n",
  1796. max, // range
  1797. this, // parent
  1798. wxPD_CAN_ABORT |
  1799. wxPD_CAN_SKIP |
  1800. wxPD_APP_MODAL |
  1801. //wxPD_AUTO_HIDE | // -- try this as well
  1802. wxPD_ELAPSED_TIME |
  1803. wxPD_ESTIMATED_TIME |
  1804. wxPD_REMAINING_TIME |
  1805. wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
  1806. );
  1807. bool cont = true;
  1808. for ( int i = 0; i <= max; i++ )
  1809. {
  1810. wxString msg;
  1811. // test both modes of wxProgressDialog behaviour: start in
  1812. // indeterminate mode but switch to the determinate one later
  1813. const bool determinate = i > max/2;
  1814. if ( i == max )
  1815. {
  1816. msg = "That's all, folks!\n"
  1817. "\n"
  1818. "Nothing to see here any more.";
  1819. }
  1820. else if ( !determinate )
  1821. {
  1822. msg = "Testing indeterminate mode\n"
  1823. "\n"
  1824. "This mode allows you to show to the user\n"
  1825. "that something is going on even if you don't know\n"
  1826. "when exactly will you finish.";
  1827. }
  1828. else if ( determinate )
  1829. {
  1830. msg = "Now in standard determinate mode\n"
  1831. "\n"
  1832. "This is the standard usage mode in which you\n"
  1833. "update the dialog after performing each new step of work.\n"
  1834. "It requires knowing the total number of steps in advance.";
  1835. }
  1836. // will be set to true if "Skip" button was pressed
  1837. bool skip = false;
  1838. if ( determinate )
  1839. {
  1840. cont = dialog.Update(i, msg, &skip);
  1841. }
  1842. else
  1843. {
  1844. cont = dialog.Pulse(msg, &skip);
  1845. }
  1846. // each skip will move progress about quarter forward
  1847. if ( skip )
  1848. {
  1849. i += max/4;
  1850. if ( i >= 100 )
  1851. i = 99;
  1852. }
  1853. if ( !cont )
  1854. {
  1855. if ( wxMessageBox(wxT("Do you really want to cancel?"),
  1856. wxT("Progress dialog question"), // caption
  1857. wxYES_NO | wxICON_QUESTION) == wxYES )
  1858. break;
  1859. cont = true;
  1860. dialog.Resume();
  1861. }
  1862. wxMilliSleep(200);
  1863. }
  1864. if ( !cont )
  1865. {
  1866. wxLogStatus(wxT("Progress dialog aborted!"));
  1867. }
  1868. else
  1869. {
  1870. wxLogStatus(wxT("Countdown from %d finished"), max);
  1871. }
  1872. }
  1873. #endif // wxUSE_PROGRESSDLG
  1874. #if wxUSE_ABOUTDLG
  1875. static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
  1876. {
  1877. info.SetName(wxT("Dialogs Sample"));
  1878. info.SetVersion(wxVERSION_NUM_DOT_STRING,
  1879. wxString::Format
  1880. (
  1881. "%s version %s",
  1882. wxMINOR_VERSION % 2 ? "Development" : "Stable",
  1883. wxVERSION_NUM_DOT_STRING
  1884. ));
  1885. info.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
  1886. info.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
  1887. info.AddDeveloper(wxT("Vadim Zeitlin"));
  1888. }
  1889. static void InitAboutInfoWebsite(wxAboutDialogInfo& info)
  1890. {
  1891. InitAboutInfoMinimal(info);
  1892. info.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
  1893. }
  1894. static void InitAboutInfoAll(wxAboutDialogInfo& info)
  1895. {
  1896. InitAboutInfoWebsite(info);
  1897. // we can add a second developer
  1898. info.AddDeveloper(wxT("A.N. Other"));
  1899. // or we can add several persons at once like this
  1900. static const wxChar *docwriters[] =
  1901. {
  1902. wxT("First D. Writer"),
  1903. wxT("Second One"),
  1904. };
  1905. info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters));
  1906. info.SetLicence(wxString::FromAscii(
  1907. " wxWindows Library Licence, Version 3.1\n"
  1908. " ======================================\n"
  1909. "\n"
  1910. " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
  1911. "\n"
  1912. " Everyone is permitted to copy and distribute verbatim copies\n"
  1913. " of this licence document, but changing it is not allowed.\n"
  1914. "\n"
  1915. " WXWINDOWS LIBRARY LICENCE\n"
  1916. " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
  1917. "\n"
  1918. " ...and so on and so forth...\n"
  1919. ));
  1920. info.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
  1921. }
  1922. void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
  1923. {
  1924. wxAboutDialogInfo info;
  1925. InitAboutInfoMinimal(info);
  1926. wxAboutBox(info, this);
  1927. }
  1928. void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
  1929. {
  1930. wxAboutDialogInfo info;
  1931. InitAboutInfoWebsite(info);
  1932. wxAboutBox(info, this);
  1933. }
  1934. void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event))
  1935. {
  1936. wxAboutDialogInfo info;
  1937. InitAboutInfoAll(info);
  1938. wxAboutBox(info, this);
  1939. }
  1940. // a trivial example of a custom dialog class
  1941. class MyAboutDialog : public wxGenericAboutDialog
  1942. {
  1943. public:
  1944. MyAboutDialog(const wxAboutDialogInfo& info, wxWindow* parent)
  1945. {
  1946. Create(info, parent);
  1947. }
  1948. // add some custom controls
  1949. virtual void DoAddCustomControls()
  1950. {
  1951. AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
  1952. AddText(wxT("Some custom text"));
  1953. AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
  1954. }
  1955. };
  1956. void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event))
  1957. {
  1958. wxAboutDialogInfo info;
  1959. InitAboutInfoAll(info);
  1960. MyAboutDialog dlg(info, this);
  1961. dlg.ShowModal();
  1962. }
  1963. #endif // wxUSE_ABOUTDLG
  1964. #if wxUSE_BUSYINFO
  1965. void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
  1966. {
  1967. wxWindowDisabler disableAll;
  1968. wxBusyInfo info(wxT("Working, please wait..."), this);
  1969. for ( int i = 0; i < 18; i++ )
  1970. {
  1971. wxMilliSleep(100);
  1972. wxTheApp->Yield();
  1973. }
  1974. wxSleep(2);
  1975. //wxWakeUpIdle();
  1976. }
  1977. #endif // wxUSE_BUSYINFO
  1978. #if wxUSE_FINDREPLDLG
  1979. void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
  1980. {
  1981. if ( m_dlgReplace )
  1982. {
  1983. wxDELETE(m_dlgReplace);
  1984. }
  1985. else
  1986. {
  1987. m_dlgReplace = new wxFindReplaceDialog
  1988. (
  1989. this,
  1990. &m_findData,
  1991. wxT("Find and replace dialog"),
  1992. wxFR_REPLACEDIALOG
  1993. );
  1994. m_dlgReplace->Show(true);
  1995. }
  1996. }
  1997. void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
  1998. {
  1999. if ( m_dlgFind )
  2000. {
  2001. wxDELETE(m_dlgFind);
  2002. }
  2003. else
  2004. {
  2005. m_dlgFind = new wxFindReplaceDialog
  2006. (
  2007. this,
  2008. &m_findData,
  2009. wxT("Find dialog"),
  2010. // just for testing
  2011. wxFR_NOWHOLEWORD
  2012. );
  2013. m_dlgFind->Show(true);
  2014. }
  2015. }
  2016. static wxString DecodeFindDialogEventFlags(int flags)
  2017. {
  2018. wxString str;
  2019. str << (flags & wxFR_DOWN ? wxT("down") : wxT("up")) << wxT(", ")
  2020. << (flags & wxFR_WHOLEWORD ? wxT("whole words only, ") : wxT(""))
  2021. << (flags & wxFR_MATCHCASE ? wxT("") : wxT("not "))
  2022. << wxT("case sensitive");
  2023. return str;
  2024. }
  2025. void MyFrame::OnFindDialog(wxFindDialogEvent& event)
  2026. {
  2027. wxEventType type = event.GetEventType();
  2028. if ( type == wxEVT_FIND || type == wxEVT_FIND_NEXT )
  2029. {
  2030. wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
  2031. type == wxEVT_FIND_NEXT ? wxT("next ") : wxT(""),
  2032. event.GetFindString().c_str(),
  2033. DecodeFindDialogEventFlags(event.GetFlags()).c_str());
  2034. }
  2035. else if ( type == wxEVT_FIND_REPLACE ||
  2036. type == wxEVT_FIND_REPLACE_ALL )
  2037. {
  2038. wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
  2039. type == wxEVT_FIND_REPLACE_ALL ? wxT("all ") : wxT(""),
  2040. event.GetFindString().c_str(),
  2041. event.GetReplaceString().c_str(),
  2042. DecodeFindDialogEventFlags(event.GetFlags()).c_str());
  2043. }
  2044. else if ( type == wxEVT_FIND_CLOSE )
  2045. {
  2046. wxFindReplaceDialog *dlg = event.GetDialog();
  2047. int idMenu;
  2048. const wxChar *txt;
  2049. if ( dlg == m_dlgFind )
  2050. {
  2051. txt = wxT("Find");
  2052. idMenu = DIALOGS_FIND;
  2053. m_dlgFind = NULL;
  2054. }
  2055. else if ( dlg == m_dlgReplace )
  2056. {
  2057. txt = wxT("Replace");
  2058. idMenu = DIALOGS_REPLACE;
  2059. m_dlgReplace = NULL;
  2060. }
  2061. else
  2062. {
  2063. txt = wxT("Unknown");
  2064. idMenu = wxID_ANY;
  2065. wxFAIL_MSG( wxT("unexpected event") );
  2066. }
  2067. wxLogMessage(wxT("%s dialog is being closed."), txt);
  2068. if ( idMenu != wxID_ANY )
  2069. {
  2070. GetMenuBar()->Check(idMenu, false);
  2071. }
  2072. dlg->Destroy();
  2073. }
  2074. else
  2075. {
  2076. wxLogError(wxT("Unknown find dialog event!"));
  2077. }
  2078. }
  2079. #endif // wxUSE_FINDREPLDLG
  2080. // ----------------------------------------------------------------------------
  2081. // MyCanvas
  2082. // ----------------------------------------------------------------------------
  2083. void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
  2084. {
  2085. wxPaintDC dc(this);
  2086. dc.SetBackgroundMode(wxTRANSPARENT);
  2087. dc.DrawText(
  2088. wxT("wxWidgets common dialogs")
  2089. #if !defined(__SMARTPHONE__)
  2090. wxT(" test application")
  2091. #endif
  2092. , 10, 10);
  2093. }
  2094. #if USE_MODAL_PRESENTATION
  2095. // ----------------------------------------------------------------------------
  2096. // MyModelessDialog
  2097. // ----------------------------------------------------------------------------
  2098. MyModelessDialog::MyModelessDialog(wxWindow *parent)
  2099. : wxDialog(parent, wxID_ANY, wxString(wxT("Modeless dialog")))
  2100. {
  2101. wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
  2102. wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, wxT("Press me"));
  2103. wxCheckBox *check = new wxCheckBox(this, wxID_ANY, wxT("Should be disabled"));
  2104. check->Disable();
  2105. sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
  2106. sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
  2107. SetSizerAndFit(sizerTop);
  2108. }
  2109. void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
  2110. {
  2111. wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
  2112. wxOK | wxICON_INFORMATION, this);
  2113. }
  2114. void MyModelessDialog::OnClose(wxCloseEvent& event)
  2115. {
  2116. if ( event.CanVeto() )
  2117. {
  2118. wxMessageBox(wxT("Use the menu item to close this dialog"),
  2119. wxT("Modeless dialog"),
  2120. wxOK | wxICON_INFORMATION, this);
  2121. event.Veto();
  2122. }
  2123. }
  2124. // ----------------------------------------------------------------------------
  2125. // MyModalDialog
  2126. // ----------------------------------------------------------------------------
  2127. MyModalDialog::MyModalDialog(wxWindow *parent)
  2128. : wxDialog(parent, wxID_ANY, wxString(wxT("Modal dialog")))
  2129. {
  2130. wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
  2131. m_btnModal = new wxButton(this, wxID_ANY, wxT("&Modal dialog..."));
  2132. m_btnModeless = new wxButton(this, wxID_ANY, wxT("Mode&less dialog"));
  2133. m_btnDelete = new wxButton(this, wxID_ANY, wxT("&Delete button"));
  2134. sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
  2135. sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
  2136. sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
  2137. sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5);
  2138. SetSizerAndFit(sizerTop);
  2139. SetEscapeId(wxID_CLOSE);
  2140. m_btnModal->SetFocus();
  2141. m_btnModal->SetDefault();
  2142. }
  2143. void MyModalDialog::OnButton(wxCommandEvent& event)
  2144. {
  2145. if ( event.GetEventObject() == m_btnDelete )
  2146. {
  2147. wxDELETE(m_btnModal);
  2148. m_btnDelete->Disable();
  2149. }
  2150. else if ( event.GetEventObject() == m_btnModal )
  2151. {
  2152. #if wxUSE_TEXTDLG
  2153. wxGetTextFromUser(wxT("Dummy prompt"),
  2154. wxT("Modal dialog called from dialog"),
  2155. wxEmptyString, this);
  2156. #else
  2157. wxMessageBox(wxT("Modal dialog called from dialog"));
  2158. #endif // wxUSE_TEXTDLG
  2159. }
  2160. else if ( event.GetEventObject() == m_btnModeless )
  2161. {
  2162. (new MyModelessDialog(this))->Show();
  2163. }
  2164. else
  2165. {
  2166. event.Skip();
  2167. }
  2168. }
  2169. #endif // USE_MODAL_PRESENTATION
  2170. // ----------------------------------------------------------------------------
  2171. // StdButtonSizerDialog
  2172. // ----------------------------------------------------------------------------
  2173. StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
  2174. : wxDialog(parent, wxID_ANY, wxString(wxT("StdButtonSizer dialog")),
  2175. wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
  2176. m_buttonsSizer(NULL)
  2177. {
  2178. wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL);
  2179. wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL);
  2180. wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL);
  2181. m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button"));
  2182. wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button"));
  2183. m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
  2184. m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes"));
  2185. wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL);
  2186. m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button"));
  2187. wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button"));
  2188. m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
  2189. m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close"));
  2190. wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL);
  2191. m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No"));
  2192. m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help"));
  2193. m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply"));
  2194. m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default"));
  2195. sizer1->Add(m_radiobtnOk, 0, wxALL, 5);
  2196. sizer1->Add(m_radiobtnYes, 0, wxALL, 5);
  2197. sizer->Add(sizerInside1, 0, 0, 0);
  2198. sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5);
  2199. sizerInside1->Add(sizer1, 0, wxALL, 5);
  2200. sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
  2201. sizer2->Add(m_radiobtnCancel, 0, wxALL, 5);
  2202. sizer2->Add(m_radiobtnClose, 0, wxALL, 5);
  2203. sizer->Add(sizerInside2, 0, 0, 0);
  2204. sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5);
  2205. sizerInside2->Add(sizer2, 0, wxALL, 5);
  2206. sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
  2207. sizerTop->Add(sizer, 0, wxALL, 5);
  2208. sizer3->Add(m_chkboxNo, 0, wxALL, 5);
  2209. sizer3->Add(m_chkboxHelp, 0, wxALL, 5);
  2210. sizer3->Add(m_chkboxApply, 0, wxALL, 5);
  2211. sizerTop->Add(sizer3, 0, wxALL, 5);
  2212. sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10);
  2213. EnableDisableControls();
  2214. SetSizerAndFit(sizerTop);
  2215. wxCommandEvent ev;
  2216. OnEvent(ev);
  2217. }
  2218. void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event))
  2219. {
  2220. if (m_buttonsSizer)
  2221. {
  2222. m_buttonsSizer->DeleteWindows();
  2223. GetSizer()->Remove(m_buttonsSizer);
  2224. }
  2225. EnableDisableControls();
  2226. long flags = 0;
  2227. unsigned long numButtons = 0;
  2228. if (m_chkboxAffirmativeButton->IsChecked())
  2229. {
  2230. if (m_radiobtnOk->GetValue())
  2231. {
  2232. flags |= wxOK;
  2233. numButtons ++;
  2234. }
  2235. else if (m_radiobtnYes->GetValue())
  2236. {
  2237. flags |= wxYES;
  2238. numButtons ++;
  2239. }
  2240. }
  2241. if (m_chkboxDismissButton->IsChecked())
  2242. {
  2243. if (m_radiobtnCancel->GetValue())
  2244. {
  2245. flags |= wxCANCEL;
  2246. numButtons ++;
  2247. }
  2248. else if (m_radiobtnClose->GetValue())
  2249. {
  2250. flags |= wxCLOSE;
  2251. numButtons ++;
  2252. }
  2253. }
  2254. if (m_chkboxApply->IsChecked())
  2255. {
  2256. flags |= wxAPPLY;
  2257. numButtons ++;
  2258. }
  2259. if (m_chkboxNo->IsChecked())
  2260. {
  2261. flags |= wxNO;
  2262. numButtons ++;
  2263. }
  2264. if (m_chkboxHelp->IsChecked())
  2265. {
  2266. flags |= wxHELP;
  2267. numButtons ++;
  2268. }
  2269. if (m_chkboxNoDefault->IsChecked())
  2270. {
  2271. flags |= wxNO_DEFAULT;
  2272. }
  2273. m_buttonsSizer = CreateStdDialogButtonSizer(flags);
  2274. GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5);
  2275. Layout();
  2276. GetSizer()->SetSizeHints(this);
  2277. }
  2278. void StdButtonSizerDialog::EnableDisableControls()
  2279. {
  2280. const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked();
  2281. m_radiobtnOk->Enable(affButtonEnabled);
  2282. m_radiobtnYes->Enable(affButtonEnabled);
  2283. const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked();
  2284. m_radiobtnCancel->Enable(dismissButtonEnabled);
  2285. m_radiobtnClose->Enable(dismissButtonEnabled);
  2286. }
  2287. #if USE_SETTINGS_DIALOG
  2288. // ----------------------------------------------------------------------------
  2289. // SettingsDialog
  2290. // ----------------------------------------------------------------------------
  2291. IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
  2292. wxBEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
  2293. wxEND_EVENT_TABLE()
  2294. SettingsDialog::SettingsDialog(wxWindow* win, int dialogType)
  2295. {
  2296. SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
  2297. int tabImage1 = -1;
  2298. int tabImage2 = -1;
  2299. bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK);
  2300. int resizeBorder = wxRESIZE_BORDER;
  2301. if (useToolBook)
  2302. {
  2303. resizeBorder = 0;
  2304. tabImage1 = 0;
  2305. tabImage2 = 1;
  2306. int sheetStyle = wxPROPSHEET_SHRINKTOFIT;
  2307. if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK)
  2308. sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK;
  2309. else
  2310. sheetStyle |= wxPROPSHEET_TOOLBOOK;
  2311. SetSheetStyle(sheetStyle);
  2312. SetSheetInnerBorder(0);
  2313. SetSheetOuterBorder(0);
  2314. // create a dummy image list with a few icons
  2315. const wxSize imageSize(32, 32);
  2316. m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
  2317. m_imageList->
  2318. Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
  2319. m_imageList->
  2320. Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
  2321. m_imageList->
  2322. Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
  2323. m_imageList->
  2324. Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
  2325. }
  2326. else
  2327. m_imageList = NULL;
  2328. Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
  2329. wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder)
  2330. );
  2331. // If using a toolbook, also follow Mac style and don't create buttons
  2332. if (!useToolBook)
  2333. CreateButtons(wxOK | wxCANCEL |
  2334. (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP)
  2335. );
  2336. wxBookCtrlBase* notebook = GetBookCtrl();
  2337. notebook->SetImageList(m_imageList);
  2338. wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
  2339. wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
  2340. notebook->AddPage(generalSettings, _("General"), true, tabImage1);
  2341. notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2);
  2342. LayoutDialog();
  2343. }
  2344. SettingsDialog::~SettingsDialog()
  2345. {
  2346. delete m_imageList;
  2347. }
  2348. wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
  2349. {
  2350. wxPanel* panel = new wxPanel(parent, wxID_ANY);
  2351. wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
  2352. wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
  2353. //// LOAD LAST FILE
  2354. wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
  2355. wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
  2356. itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2357. item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
  2358. //// AUTOSAVE
  2359. wxString autoSaveLabel = _("&Auto-save every");
  2360. wxString minsLabel = _("mins");
  2361. wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
  2362. wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
  2363. #if wxUSE_SPINCTRL
  2364. wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
  2365. wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
  2366. #endif
  2367. itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2368. #if wxUSE_SPINCTRL
  2369. itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2370. #endif
  2371. itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2372. item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
  2373. //// TOOLTIPS
  2374. wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
  2375. wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
  2376. itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2377. item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
  2378. topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
  2379. panel->SetSizerAndFit(topSizer);
  2380. return panel;
  2381. }
  2382. wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
  2383. {
  2384. wxPanel* panel = new wxPanel(parent, wxID_ANY);
  2385. wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
  2386. wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
  2387. //// PROJECT OR GLOBAL
  2388. wxString globalOrProjectChoices[2];
  2389. globalOrProjectChoices[0] = _("&New projects");
  2390. globalOrProjectChoices[1] = _("&This project");
  2391. wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
  2392. wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
  2393. item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
  2394. projectOrGlobal->SetSelection(0);
  2395. //// BACKGROUND STYLE
  2396. wxArrayString backgroundStyleChoices;
  2397. backgroundStyleChoices.Add(wxT("Colour"));
  2398. backgroundStyleChoices.Add(wxT("Image"));
  2399. wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
  2400. wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
  2401. item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
  2402. wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
  2403. wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
  2404. itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2405. itemSizer2->Add(5, 5, 1, wxALL, 0);
  2406. itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
  2407. styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
  2408. #if wxUSE_SPINCTRL
  2409. //// FONT SIZE SELECTION
  2410. wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
  2411. wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
  2412. wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
  2413. wxSize(80, wxDefaultCoord));
  2414. itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
  2415. item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
  2416. #endif
  2417. topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
  2418. topSizer->AddSpacer(5);
  2419. panel->SetSizerAndFit(topSizer);
  2420. return panel;
  2421. }
  2422. #endif // USE_SETTINGS_DIALOG
  2423. #if wxUSE_MSGDLG
  2424. // ----------------------------------------------------------------------------
  2425. // TestMessageBoxDialog
  2426. // ----------------------------------------------------------------------------
  2427. /* static */
  2428. const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
  2429. {
  2430. { wxYES, "&Yes" },
  2431. { wxNO, "&No" },
  2432. { wxOK, "&Ok" },
  2433. { wxCANCEL, "&Cancel" },
  2434. { wxHELP, "&Help" },
  2435. };
  2436. wxBEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
  2437. EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply)
  2438. EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose)
  2439. wxEND_EVENT_TABLE()
  2440. TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent)
  2441. : wxDialog(parent, wxID_ANY, "Message Box Test Dialog",
  2442. wxDefaultPosition, wxDefaultSize,
  2443. wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
  2444. {
  2445. }
  2446. bool TestMessageBoxDialog::Create()
  2447. {
  2448. wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
  2449. // this sizer allows to configure the messages shown in the message box
  2450. wxSizer * const
  2451. sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages");
  2452. sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Title:"));
  2453. m_textTitle = new wxTextCtrl(this, wxID_ANY, "Test Message Box");
  2454. sizerMsgs->Add(m_textTitle, wxSizerFlags().Expand().Border(wxBOTTOM));
  2455. sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:"));
  2456. m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!",
  2457. wxDefaultPosition, wxDefaultSize,
  2458. wxTE_MULTILINE);
  2459. sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM));
  2460. sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:"));
  2461. m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "",
  2462. wxDefaultPosition, wxDefaultSize,
  2463. wxTE_MULTILINE);
  2464. sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand());
  2465. sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
  2466. // if a derived class provides more message configurations, add these.
  2467. AddAdditionalTextOptions(sizerTop);
  2468. // this one is for configuring the buttons
  2469. wxSizer * const
  2470. sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons");
  2471. wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5);
  2472. sizerBtns->AddGrowableCol(1);
  2473. sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)"));
  2474. sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label"));
  2475. for ( int n = 0; n < Btn_Max; n++ )
  2476. {
  2477. m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name);
  2478. sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left());
  2479. m_labels[n] = new wxTextCtrl(this, wxID_ANY);
  2480. sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand());
  2481. m_labels[n]->Connect(wxEVT_UPDATE_UI,
  2482. wxUpdateUIEventHandler(
  2483. TestMessageBoxDialog::OnUpdateLabelUI),
  2484. NULL,
  2485. this);
  2486. }
  2487. sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand());
  2488. sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border());
  2489. // icon choice
  2490. const wxString icons[] =
  2491. {
  2492. "&Not specified",
  2493. "E&xplicitly none",
  2494. "&Information icon",
  2495. "&Question icon",
  2496. "&Warning icon",
  2497. "&Error icon",
  2498. "A&uth needed icon"
  2499. };
  2500. wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch );
  2501. m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style",
  2502. wxDefaultPosition, wxDefaultSize,
  2503. WXSIZEOF(icons), icons,
  2504. 2, wxRA_SPECIFY_ROWS);
  2505. // Make the 'Information' icon the default one:
  2506. m_icons->SetSelection(MsgDlgIcon_Info);
  2507. sizerTop->Add(m_icons, wxSizerFlags().Expand().Border());
  2508. // miscellaneous other stuff
  2509. wxSizer * const
  2510. sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags");
  2511. m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default");
  2512. m_chkNoDefault->Connect(wxEVT_UPDATE_UI,
  2513. wxUpdateUIEventHandler(
  2514. TestMessageBoxDialog::OnUpdateNoDefaultUI),
  2515. NULL,
  2516. this);
  2517. sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border());
  2518. m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent");
  2519. sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border());
  2520. // add any additional flag from subclasses
  2521. AddAdditionalFlags(sizerFlags);
  2522. sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border());
  2523. // finally buttons to show the resulting message box and close this dialog
  2524. sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE),
  2525. wxSizerFlags().Right().Border());
  2526. SetSizerAndFit(sizerTop);
  2527. m_buttons[Btn_Ok]->SetValue(true);
  2528. return true;
  2529. }
  2530. void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event)
  2531. {
  2532. for ( int n = 0; n < Btn_Max; n++ )
  2533. {
  2534. if ( event.GetEventObject() == m_labels[n] )
  2535. {
  2536. event.Enable( m_buttons[n]->IsChecked() );
  2537. return;
  2538. }
  2539. }
  2540. wxFAIL_MSG( "called for unknown label" );
  2541. }
  2542. void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event)
  2543. {
  2544. event.Enable( m_buttons[Btn_No]->IsChecked() );
  2545. }
  2546. long TestMessageBoxDialog::GetStyle()
  2547. {
  2548. long style = 0;
  2549. for ( int n = 0; n < Btn_Max; n++ )
  2550. {
  2551. if ( m_buttons[n]->IsChecked() )
  2552. style |= ms_btnInfo[n].flag;
  2553. }
  2554. switch ( m_icons->GetSelection() )
  2555. {
  2556. case MsgDlgIcon_Max:
  2557. wxFAIL_MSG( "unexpected selection" );
  2558. case MsgDlgIcon_No:
  2559. break;
  2560. case MsgDlgIcon_None:
  2561. style |= wxICON_NONE;
  2562. break;
  2563. case MsgDlgIcon_Info:
  2564. style |= wxICON_INFORMATION;
  2565. break;
  2566. case MsgDlgIcon_Question:
  2567. style |= wxICON_QUESTION;
  2568. break;
  2569. case MsgDlgIcon_Warning:
  2570. style |= wxICON_WARNING;
  2571. break;
  2572. case MsgDlgIcon_Error:
  2573. style |= wxICON_ERROR;
  2574. break;
  2575. case MsgDlgIcon_AuthNeeded:
  2576. style |= wxICON_AUTH_NEEDED;
  2577. break;
  2578. }
  2579. if ( m_chkCentre->IsChecked() )
  2580. style |= wxCENTRE;
  2581. if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() )
  2582. style |= wxNO_DEFAULT;
  2583. return style;
  2584. }
  2585. void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase &dlg)
  2586. {
  2587. long style = dlg.GetMessageDialogStyle();
  2588. if ( !m_textExtMsg->IsEmpty() )
  2589. dlg.SetExtendedMessage(m_textExtMsg->GetValue());
  2590. if ( style & wxYES_NO )
  2591. {
  2592. if ( style & wxCANCEL )
  2593. {
  2594. dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(),
  2595. m_labels[Btn_No]->GetValue(),
  2596. m_labels[Btn_Cancel]->GetValue());
  2597. }
  2598. else
  2599. {
  2600. dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(),
  2601. m_labels[Btn_No]->GetValue());
  2602. }
  2603. }
  2604. else
  2605. {
  2606. if ( style & wxCANCEL )
  2607. {
  2608. dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(),
  2609. m_labels[Btn_Cancel]->GetValue());
  2610. }
  2611. else
  2612. {
  2613. dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
  2614. }
  2615. }
  2616. if ( style & wxHELP )
  2617. {
  2618. dlg.SetHelpLabel(m_labels[Btn_Help]->GetValue());
  2619. }
  2620. }
  2621. void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
  2622. {
  2623. wxMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
  2624. PrepareMessageDialog(dlg);
  2625. wxString btnName;
  2626. switch ( dlg.ShowModal() )
  2627. {
  2628. case wxID_OK:
  2629. btnName = "OK";
  2630. break;
  2631. case wxID_CANCEL:
  2632. // Avoid the extra message box if the dialog was cancelled.
  2633. return;
  2634. case wxID_YES:
  2635. btnName = "Yes";
  2636. break;
  2637. case wxID_NO:
  2638. btnName = "No";
  2639. break;
  2640. case wxID_HELP:
  2641. btnName = "Help";
  2642. break;
  2643. default:
  2644. btnName = "Unknown";
  2645. }
  2646. wxLogMessage("Dialog was closed with the \"%s\" button.", btnName);
  2647. }
  2648. void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))
  2649. {
  2650. EndModal(wxID_CANCEL);
  2651. }
  2652. #endif // wxUSE_MSGDLG
  2653. #if wxUSE_RICHMSGDLG
  2654. // ----------------------------------------------------------------------------
  2655. // TestRichMessageDialog
  2656. // ----------------------------------------------------------------------------
  2657. wxBEGIN_EVENT_TABLE(TestRichMessageDialog, TestMessageBoxDialog)
  2658. EVT_BUTTON(wxID_APPLY, TestRichMessageDialog::OnApply)
  2659. wxEND_EVENT_TABLE()
  2660. TestRichMessageDialog::TestRichMessageDialog(wxWindow *parent)
  2661. : TestMessageBoxDialog(parent)
  2662. {
  2663. SetTitle("Rich Message Dialog Test Dialog");
  2664. }
  2665. void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer *sizer)
  2666. {
  2667. wxSizer * const sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this,
  2668. "&Additional Elements");
  2669. // add a option to show a check box.
  2670. wxFlexGridSizer * const sizerCheckBox = new wxFlexGridSizer(2, 5, 5);
  2671. sizerCheckBox->AddGrowableCol(1);
  2672. sizerCheckBox->Add(new wxStaticText(this, wxID_ANY, "&Check box:"));
  2673. m_textCheckBox = new wxTextCtrl(this, wxID_ANY);
  2674. sizerCheckBox->Add(m_textCheckBox, wxSizerFlags(1).Expand().Border(wxBOTTOM));
  2675. sizerMsgs->Add(sizerCheckBox, wxSizerFlags(1).Expand());
  2676. // add option to show a detailed text.
  2677. sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Detailed message:"));
  2678. m_textDetailed = new wxTextCtrl(this, wxID_ANY, "",
  2679. wxDefaultPosition, wxDefaultSize,
  2680. wxTE_MULTILINE);
  2681. sizerMsgs->Add(m_textDetailed, wxSizerFlags(1).Expand());
  2682. sizer->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
  2683. }
  2684. void TestRichMessageDialog::AddAdditionalFlags(wxSizer *sizer)
  2685. {
  2686. // add checkbox to set the initial state for the checkbox shown
  2687. // in the dialog.
  2688. m_initialValueCheckBox =
  2689. new wxCheckBox(this, wxID_ANY, "Checkbox initially checked");
  2690. sizer->Add(m_initialValueCheckBox, wxSizerFlags(1).Border());
  2691. }
  2692. void TestRichMessageDialog::OnApply(wxCommandEvent& WXUNUSED(event))
  2693. {
  2694. wxRichMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
  2695. PrepareMessageDialog(dlg);
  2696. dlg.ShowCheckBox(m_textCheckBox->GetValue(),
  2697. m_initialValueCheckBox->GetValue());
  2698. dlg.ShowDetailedText(m_textDetailed->GetValue());
  2699. dlg.ShowModal();
  2700. }
  2701. #endif // wxUSE_RICHMSGDLG
  2702. #if wxUSE_LOG
  2703. // ----------------------------------------------------------------------------
  2704. // custom log target
  2705. // ----------------------------------------------------------------------------
  2706. class MyLogGui : public wxLogGui
  2707. {
  2708. private:
  2709. virtual void DoShowSingleLogMessage(const wxString& message,
  2710. const wxString& title,
  2711. int style)
  2712. {
  2713. wxMessageDialog dlg(NULL, message, title,
  2714. wxOK | wxCANCEL | wxCANCEL_DEFAULT | style);
  2715. dlg.SetOKCancelLabels(wxID_COPY, wxID_OK);
  2716. dlg.SetExtendedMessage("Note that this is a custom log dialog.");
  2717. dlg.ShowModal();
  2718. }
  2719. };
  2720. wxLog *MyAppTraits::CreateLogTarget()
  2721. {
  2722. return new MyLogGui;
  2723. }
  2724. #endif // wxUSE_LOG